From: Sangchul Lee Date: Thu, 26 May 2022 06:05:57 +0000 (+0900) Subject: webrtc_sink/source: Replace MALLOC_AND_INIT_SLOT() with functions X-Git-Tag: submit/tizen/20220602.125915~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fb43de37f4d824b53243469e5c008531bc828cdb;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_sink/source: Replace MALLOC_AND_INIT_SLOT() with functions Unnecessary variables are also removed. [Version] 0.3.109 [Issue Type] Refactoring Change-Id: I3a1f6f69bf89801064b6cba8b4b2bac103166e2d Signed-off-by: Sangchul Lee --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index e7c030c8..a1e560fd 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -194,14 +194,6 @@ do { \ gst_caps_unref(x_elem_info.src_caps); \ } while (0) -#define MALLOC_AND_INIT_SLOT(x_slot, x_id, x_bin_name, x_webrtc) \ -do { \ - x_slot = g_new0(webrtc_gst_slot_s, 1); \ - x_slot->id = x_id; \ - x_slot->bin = GST_BIN(gst_bin_new(x_bin_name)); \ - x_slot->webrtc = x_webrtc; \ -} while (0) - #define GENERATE_DOT(x_webrtc, x_pipeline, x_fmt, x_arg...) \ do { \ gchar *dot_name; \ diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 5186e853..49cdc0c0 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.3.108 +Version: 0.3.109 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_sink.c b/src/webrtc_sink.c index be983f55..11b0077b 100644 --- a/src/webrtc_sink.c +++ b/src/webrtc_sink.c @@ -520,10 +520,32 @@ void _sink_slot_destroy_cb(gpointer data) g_free(sink); } -int _add_rendering_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio) +static int __alloc_sink_slot(webrtc_s *webrtc, const gchar *pad_name, bool forward, webrtc_gst_slot_s **sink, gchar **name) { - int ret = WEBRTC_ERROR_NONE; unsigned int id; + + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(pad_name == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "pad_name is NULL"); + RET_VAL_IF(sink == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); + RET_VAL_IF(name == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "name is NULL"); + RET_VAL_IF(webrtc->gst.sink_slots == NULL, WEBRTC_ERROR_INVALID_OPERATION, "sink_slots is NULL"); + + /* name/sink will be freed by function which is set to g_hash_table_new_full() */ + id = __get_id_from_name(pad_name); + *name = g_strdup_printf(forward ? "forwarding_%u" : "rendering_%u", ++id); + + *sink = g_new0(webrtc_gst_slot_s, 1); + (*sink)->id = id; + (*sink)->bin = GST_BIN(gst_bin_new(*name)); + (*sink)->webrtc = webrtc; + + LOG_DEBUG("webrtc[%p] sink[%p, id:%u, name:%s]", webrtc, *sink, id, *name); + + return WEBRTC_ERROR_NONE; +} + +int _add_rendering_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio) +{ gchar *bin_name; gchar *track_name; webrtc_gst_slot_s *sink; @@ -533,12 +555,10 @@ int _add_rendering_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio) RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(src_pad == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "src_pad is NULL"); - /* track_name/sink will be freed by function which is set to g_hash_table_new_full() */ - id = __get_id_from_name(GST_PAD_NAME(src_pad)); - bin_name = g_strdup_printf("rendering_%u", ++id); - track_name = g_strdup_printf("track_%u", id); + if (__alloc_sink_slot(webrtc, GST_PAD_NAME(src_pad), false, &sink, &bin_name) != WEBRTC_ERROR_NONE) + return WEBRTC_ERROR_INVALID_OPERATION; - MALLOC_AND_INIT_SLOT(sink, id, bin_name, webrtc); + track_name = g_strdup_printf("track_%u", sink->id); g_free(bin_name); @@ -554,12 +574,10 @@ int _add_rendering_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio) g_signal_connect(decodebin, "autoplug-select", G_CALLBACK(_decodebin_autoplug_select_cb), webrtc); g_signal_connect(decodebin, "element-added", G_CALLBACK(__decodebin_element_added_cb), sink); - ret = _add_no_target_ghostpad_to_slot(sink, false, &sink_pad); - if (ret != WEBRTC_ERROR_NONE) + if (_add_no_target_ghostpad_to_slot(sink, false, &sink_pad) != WEBRTC_ERROR_NONE) goto error_before_insert; - ret = _set_ghost_pad_target(sink_pad, decodebin, false); - if (ret != WEBRTC_ERROR_NONE) + if (_set_ghost_pad_target(sink_pad, decodebin, false) != WEBRTC_ERROR_NONE) goto error_before_insert; if (!gst_bin_add(GST_BIN(webrtc->gst.pipeline), GST_ELEMENT(sink->bin))) { @@ -865,8 +883,6 @@ static GstCaps* __make_caps_if_h264_or_h265(GstPad *pad) int _add_forwarding_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio) { - int ret = WEBRTC_ERROR_NONE; - unsigned int id; gchar *bin_name; gchar *track_name; element_info_s elem_info; @@ -880,13 +896,10 @@ int _add_forwarding_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio) RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(src_pad == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "src_pad is NULL"); - /* track_name/sink will be freed by function which is set to g_hash_table_new_full() */ - id = __get_id_from_name(GST_PAD_NAME(src_pad)); - bin_name = g_strdup_printf("forwarding_%u", ++id); - track_name = g_strdup_printf("track_%u", id); - - MALLOC_AND_INIT_SLOT(sink, id, bin_name, webrtc); + if (__alloc_sink_slot(webrtc, GST_PAD_NAME(src_pad), true, &sink, &bin_name) != WEBRTC_ERROR_NONE) + return WEBRTC_ERROR_INVALID_OPERATION; + track_name = g_strdup_printf("track_%u", sink->id); g_free(bin_name); CREATE_ELEMENT_FROM_REGISTRY(elem_info, GST_KLASS_NAME_DEPAYLOADER_RTP, gst_pad_get_current_caps(src_pad), NULL, NULL, depayloader); @@ -913,12 +926,10 @@ int _add_forwarding_sink_bin(webrtc_s *webrtc, GstPad *src_pad, bool is_audio) gst_bin_add_many(sink->bin, depayloader, capsfilter, fakesink, NULL); - ret = _add_no_target_ghostpad_to_slot(sink, false, &sink_pad); - if (ret != WEBRTC_ERROR_NONE) + if (_add_no_target_ghostpad_to_slot(sink, false, &sink_pad) != WEBRTC_ERROR_NONE) goto error_before_insert; - ret = _set_ghost_pad_target(sink_pad, depayloader, false); - if (ret != WEBRTC_ERROR_NONE) + if (_set_ghost_pad_target(sink_pad, depayloader, false) != WEBRTC_ERROR_NONE) goto error_before_insert; if (!gst_element_link_many(depayloader, capsfilter, fakesink, NULL)) { diff --git a/src/webrtc_source.c b/src/webrtc_source.c index 74445951..00f23495 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -2622,31 +2622,45 @@ exit: return ret; } -static int __add_media_source(webrtc_s *webrtc, int type, unsigned int *source_id) +static int __alloc_source_slot(webrtc_s *webrtc, int type, webrtc_gst_slot_s **source, gchar **name) { - int ret = WEBRTC_ERROR_NONE; unsigned int id; - webrtc_gst_slot_s *source = NULL; - gchar *bin_name = NULL; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); - RET_VAL_IF(source_id == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is NULL"); + RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); + RET_VAL_IF(name == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "name is NULL"); RET_VAL_IF(webrtc->gst.source_slots == NULL, WEBRTC_ERROR_INVALID_OPERATION, "source_slots is NULL"); - /* bin_name/source will be freed by function which is set to g_hash_table_new_full() */ + /* name/source will be freed by function which is set to g_hash_table_new_full() */ id = __get_unoccupied_id(webrtc->gst.source_slots); RET_VAL_IF(id == 0, WEBRTC_ERROR_INVALID_OPERATION, "source_slots are full"); - bin_name = g_strdup_printf("media_source_%u", id); + *name = g_strdup_printf("media_source_%u", id); - MALLOC_AND_INIT_SLOT(source, id, bin_name, webrtc); - source->type = type; + *source = g_new0(webrtc_gst_slot_s, 1); + (*source)->id = id; + (*source)->bin = GST_BIN(gst_bin_new(*name)); + (*source)->type = type; + (*source)->webrtc = webrtc; - ret = __build_source_bin(webrtc, source); - if (ret != WEBRTC_ERROR_NONE) { - LOG_ERROR("failed to __build_source_bin()"); + LOG_DEBUG("webrtc[%p] source[%p, id:%u, type:%d, name:%s]", webrtc, *source, id, type, *name); + + return WEBRTC_ERROR_NONE; +} + +static int __add_media_source(webrtc_s *webrtc, int type, unsigned int *source_id) +{ + webrtc_gst_slot_s *source = NULL; + gchar *bin_name = NULL; + + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(source_id == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is NULL"); + + if (__alloc_source_slot(webrtc, type, &source, &bin_name) != WEBRTC_ERROR_NONE) + goto error; + + if (__build_source_bin(webrtc, source) != WEBRTC_ERROR_NONE) goto error; - } if (!gst_bin_add(GST_BIN(webrtc->gst.pipeline), GST_ELEMENT(source->bin))) { LOG_ERROR("failed to gst_bin_add(), [%s] -> [%s] pipeline", GST_ELEMENT_NAME(source->bin), GST_ELEMENT_NAME(webrtc->gst.pipeline)); @@ -2667,7 +2681,7 @@ static int __add_media_source(webrtc_s *webrtc, int type, unsigned int *source_i goto error_after_insert; } - *source_id = id; + *source_id = source->id; LOG_INFO("added a source slot[%p, id:%u]", source, source->id);