From: Sangchul Lee Date: Thu, 8 Jul 2021 09:48:15 +0000 (+0900) Subject: webrtc_source: Add callback parmeter to __add_probe_to_pad() X-Git-Tag: submit/tizen/20210729.023123~24 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8a45ea365934627427abaa3c58e233467563a681;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_source: Add callback parmeter to __add_probe_to_pad() Ordering of parameters are changed. __remove_probe_from_pad() is also added. [Version] 0.2.36 [Issue Type] Refactoring Change-Id: Ief06006b2ad8cbbf0a9fef958da3fb5706734844 Signed-off-by: Sangchul Lee --- diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 6d780db7..21008970 100644 --- a/packaging/capi-media-webrtc.spec +++ b/packaging/capi-media-webrtc.spec @@ -1,6 +1,6 @@ Name: capi-media-webrtc Summary: A WebRTC library in Tizen Native API -Version: 0.2.35 +Version: 0.2.36 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_source.c b/src/webrtc_source.c index 7c239c9e..d06a8cde 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -868,7 +868,7 @@ static const char *__get_source_element(webrtc_s *webrtc, int type) return source->source_element; } -static GstPadProbeReturn __source_bin_pad_probe_cb(GstPad *pad, GstPadProbeInfo *info, gpointer user_data) +static GstPadProbeReturn __payloaded_data_probe_cb(GstPad *pad, GstPadProbeInfo *info, gpointer user_data) { probe_userdata_s *probe_data = (probe_userdata_s *)user_data; GstBuffer *buffer; @@ -897,21 +897,39 @@ static GstPadProbeReturn __source_bin_pad_probe_cb(GstPad *pad, GstPadProbeInfo return GST_PAD_PROBE_OK; } -static void __add_probe_to_pad(GstPad *pad, media_type_e media_type, webrtc_gst_slot_s *source) +static void __add_probe_to_pad(webrtc_gst_slot_s *source, unsigned int idx, GstPad *pad, void *probe_cb) { probe_userdata_s *probe_userdata; - RET_IF(pad == NULL, "pad is NULL"); RET_IF(source == NULL, "source is NULL"); + RET_IF(idx >= AV_IDX_MAX, "invalid idx(%u)", idx); + RET_IF(pad == NULL, "pad is NULL"); + RET_IF(probe_cb == NULL, "probe_cb is NULL"); probe_userdata = g_new0(probe_userdata_s, 1); - probe_userdata->av_idx = (media_type == MEDIA_TYPE_AUDIO) ? AV_IDX_AUDIO : AV_IDX_VIDEO; probe_userdata->source = source; - source->av[probe_userdata->av_idx].src_pad_probe_id = gst_pad_add_probe(pad, GST_PAD_PROBE_TYPE_BUFFER, - __source_bin_pad_probe_cb, probe_userdata, g_free); + probe_userdata->av_idx = idx; + source->av[idx].src_pad = pad; + source->av[idx].src_pad_probe_id = gst_pad_add_probe(pad, GST_PAD_PROBE_TYPE_BUFFER, + probe_cb, probe_userdata, g_free); - LOG_DEBUG("probe[id:%lu] is added to pad[%p] for av_idx[%d] in source[%p]", - source->av[probe_userdata->av_idx].src_pad_probe_id, pad, probe_userdata->av_idx, source); + LOG_DEBUG("source[id:%u, av_idx:%u] pad[%p] probe[id:%lu, callback:%p]", + source->id, idx, pad, source->av[idx].src_pad_probe_id, probe_cb); +} + +static void __remove_probe_from_pad(webrtc_gst_slot_s *source, unsigned int idx) +{ + RET_IF(source == NULL, "source is NULL"); + RET_IF(idx >= AV_IDX_MAX, "invalid idx(%u)", idx); + + if (source->av[idx].src_pad_probe_id == 0) + return; + + LOG_DEBUG("source[id:%u, av_idx:%u] pad[%p] probe_id[%lu]", + source->id, idx, source->av[idx].src_pad, source->av[idx].src_pad_probe_id); + gst_pad_remove_probe(source->av[idx].src_pad, source->av[idx].src_pad_probe_id); + source->av[idx].src_pad_probe_id = 0; + source->av[idx].src_pad = NULL; } static bool __add_elements_to_bin(GstBin *bin, GList *element_list) @@ -1048,12 +1066,13 @@ static int __build_screensrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) GstElement *capsfilter; GList *switch_src_list = NULL; GList *element_list = NULL; + GstPad *src_pad; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); - ret = _add_no_target_ghostpad_to_slot(source, true, &source->av[AV_IDX_VIDEO].src_pad); + ret = _add_no_target_ghostpad_to_slot(source, true, &src_pad); RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()"); source->media_types = MEDIA_TYPE_VIDEO; @@ -1102,11 +1121,11 @@ static int __build_screensrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) ret = WEBRTC_ERROR_INVALID_OPERATION; goto exit_with_remove_from_bin; } - ret = _set_ghost_pad_target(source->av[AV_IDX_VIDEO].src_pad, capsfilter, true); + ret = _set_ghost_pad_target(src_pad, capsfilter, true); if (ret != WEBRTC_ERROR_NONE) goto exit_with_remove_from_bin; - __add_probe_to_pad(source->av[AV_IDX_VIDEO].src_pad, MEDIA_TYPE_VIDEO, source); + __add_probe_to_pad(source, AV_IDX_VIDEO, src_pad, __payloaded_data_probe_cb); SAFE_G_LIST_FREE(switch_src_list); SAFE_G_LIST_FREE(element_list); @@ -1134,12 +1153,13 @@ static int __build_camerasrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) GstElement *camerasrc; GstElement *capsfilter; GList *element_list = NULL; + GstPad *src_pad; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); - ret = _add_no_target_ghostpad_to_slot(source, true, &source->av[AV_IDX_VIDEO].src_pad); + ret = _add_no_target_ghostpad_to_slot(source, true, &src_pad); RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()"); source->media_types = MEDIA_TYPE_VIDEO; @@ -1174,11 +1194,11 @@ static int __build_camerasrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) ret = WEBRTC_ERROR_INVALID_OPERATION; goto exit_with_remove_from_bin; } - ret = _set_ghost_pad_target(source->av[AV_IDX_VIDEO].src_pad, capsfilter, true); + ret = _set_ghost_pad_target(src_pad, capsfilter, true); if (ret != WEBRTC_ERROR_NONE) goto exit_with_remove_from_bin; - __add_probe_to_pad(source->av[AV_IDX_VIDEO].src_pad, MEDIA_TYPE_VIDEO, source); + __add_probe_to_pad(source, AV_IDX_VIDEO, src_pad, __payloaded_data_probe_cb); SAFE_G_LIST_FREE(element_list); @@ -1203,12 +1223,13 @@ static int __build_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source, bool us GstElement *volume; GstElement *capsfilter; GList *element_list = NULL; + GstPad *src_pad; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); - ret = _add_no_target_ghostpad_to_slot(source, true, &source->av[AV_IDX_AUDIO].src_pad); + ret = _add_no_target_ghostpad_to_slot(source, true, &src_pad); RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()"); source->media_types = MEDIA_TYPE_AUDIO; @@ -1241,11 +1262,11 @@ static int __build_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source, bool us ret = WEBRTC_ERROR_INVALID_OPERATION; goto exit_with_remove_from_bin; } - ret = _set_ghost_pad_target(source->av[AV_IDX_AUDIO].src_pad, capsfilter, true); + ret = _set_ghost_pad_target(src_pad, capsfilter, true); if (ret != WEBRTC_ERROR_NONE) goto exit_with_remove_from_bin; - __add_probe_to_pad(source->av[AV_IDX_AUDIO].src_pad, MEDIA_TYPE_AUDIO, source); + __add_probe_to_pad(source, AV_IDX_AUDIO, src_pad, __payloaded_data_probe_cb); SAFE_G_LIST_FREE(element_list); @@ -1268,12 +1289,13 @@ static int __build_videotestsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) GstElement *videotestsrc; GstElement *capsfilter; GList *element_list = NULL; + GstPad *src_pad; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); - ret = _add_no_target_ghostpad_to_slot(source, true, &source->av[AV_IDX_VIDEO].src_pad); + ret = _add_no_target_ghostpad_to_slot(source, true, &src_pad); RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()"); source->media_types = MEDIA_TYPE_VIDEO; @@ -1300,11 +1322,11 @@ static int __build_videotestsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) ret = WEBRTC_ERROR_INVALID_OPERATION; goto exit_with_remove_from_bin; } - ret = _set_ghost_pad_target(source->av[AV_IDX_VIDEO].src_pad, capsfilter, true); + ret = _set_ghost_pad_target(src_pad, capsfilter, true); if (ret != WEBRTC_ERROR_NONE) goto exit_with_remove_from_bin; - __add_probe_to_pad(source->av[AV_IDX_VIDEO].src_pad, MEDIA_TYPE_VIDEO, source); + __add_probe_to_pad(source, AV_IDX_VIDEO, src_pad, __payloaded_data_probe_cb); SAFE_G_LIST_FREE(element_list); @@ -1327,12 +1349,13 @@ static int __build_custom_videosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) GstElement *custom_videosrc; GstElement *capsfilter; GList *element_list = NULL; + GstPad *src_pad; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); - ret = _add_no_target_ghostpad_to_slot(source, true, &source->av[AV_IDX_VIDEO].src_pad); + ret = _add_no_target_ghostpad_to_slot(source, true, &src_pad); RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()"); source->media_types = MEDIA_TYPE_VIDEO; @@ -1357,11 +1380,11 @@ static int __build_custom_videosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) ret = WEBRTC_ERROR_INVALID_OPERATION; goto exit_with_remove_from_bin; } - ret = _set_ghost_pad_target(source->av[AV_IDX_VIDEO].src_pad, capsfilter, true); + ret = _set_ghost_pad_target(src_pad, capsfilter, true); if (ret != WEBRTC_ERROR_NONE) goto exit_with_remove_from_bin; - __add_probe_to_pad(source->av[AV_IDX_VIDEO].src_pad, MEDIA_TYPE_VIDEO, source); + __add_probe_to_pad(source, AV_IDX_VIDEO, src_pad, __payloaded_data_probe_cb); SAFE_G_LIST_FREE(element_list); @@ -1386,12 +1409,13 @@ static int __build_custom_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) GstElement *volume; GstElement *capsfilter; GList *element_list = NULL; + GstPad *src_pad; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); - ret = _add_no_target_ghostpad_to_slot(source, true, &source->av[AV_IDX_AUDIO].src_pad); + ret = _add_no_target_ghostpad_to_slot(source, true, &src_pad); RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()"); source->media_types = MEDIA_TYPE_AUDIO; @@ -1421,11 +1445,11 @@ static int __build_custom_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) ret = WEBRTC_ERROR_INVALID_OPERATION; goto exit_with_remove_from_bin; } - ret = _set_ghost_pad_target(source->av[AV_IDX_AUDIO].src_pad, capsfilter, true); + ret = _set_ghost_pad_target(src_pad, capsfilter, true); if (ret != WEBRTC_ERROR_NONE) goto exit_with_remove_from_bin; - __add_probe_to_pad(source->av[AV_IDX_AUDIO].src_pad, MEDIA_TYPE_AUDIO, source); + __add_probe_to_pad(source, AV_IDX_AUDIO, src_pad, __payloaded_data_probe_cb); SAFE_G_LIST_FREE(element_list); @@ -1723,10 +1747,8 @@ void _source_slot_destroy_cb(gpointer data) gst_element_foreach_src_pad(GST_ELEMENT(source->bin), __foreach_src_pad_cb, source); for (i = 0; i < AV_IDX_MAX; i++) { - if (source->av[i].src_pad_probe_id) { - gst_pad_remove_probe(source->av[i].src_pad, source->av[i].src_pad_probe_id); - source->av[i].src_pad_probe_id = 0; - } + __remove_probe_from_pad(source, i); + if (source->av[i].payload_id > 0) __return_payload_id(source->webrtc, source->av[i].payload_id); }