From: Sangchul Lee Date: Wed, 8 Jun 2022 08:18:02 +0000 (+0900) Subject: webrtc_source: Save video mute value if it does not meet the required condition X-Git-Tag: submit/tizen/20220613.225802~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F00%2F276000%2F3;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_source: Save video mute value if it does not meet the required condition This is a preparation for setting option values regardless of elements creation or linking pads. [Version] 0.3.119 [Issue Type] Improvement Change-Id: Ifbac64fd9c7300e5887840dcf556378387286e5d Signed-off-by: Sangchul Lee --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index cd9dfd71..f6c1cbc3 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -495,6 +495,7 @@ typedef struct _webrtc_gst_slot_s { GstPad *src_pad; gulong src_pad_probe_id; bool pause; + bool mute; bool inbandfec; int packet_loss_percentage; unsigned int pt; @@ -523,7 +524,6 @@ typedef struct _webrtc_gst_slot_s { webrtc_callbacks_s buffer_state_changed_cb; webrtc_callbacks_s *encoded_frame_cb; gulong camerasrc_probe_id; - bool video_muted; GstElement *filesrc_pipeline; GstBus *filesrc_bus; diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 1f4ef8e3..3163f109 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.118 +Version: 0.3.119 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_source.c b/src/webrtc_source.c index 307f008d..fed43ab3 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -1387,6 +1387,14 @@ static int __build_screensrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) if (!__link_switch_srcs(videoswitch, switch_src_list)) goto exit_with_remove_from_bin; + if (source->av[AV_IDX_VIDEO].mute) { + GstPad *pad = gst_element_get_static_pad(videoswitch, "sink_1"); + if (!pad) + goto exit_with_remove_from_bin; + g_object_set(G_OBJECT(videoswitch), "active-pad", pad, NULL); + gst_object_unref(pad); + } + if (!__link_elements(element_list)) goto exit_with_remove_from_bin; @@ -1435,6 +1443,10 @@ static int __build_rest_of_videosrc(webrtc_s *webrtc, GstPad *src_pad, GstElemen } _gst_set_element_properties(videosrc_element, ini_source->source_element_properties); + /* NOTE: in case of videotestsrc with mute operation */ + if (g_object_class_find_property(G_OBJECT_GET_CLASS(videosrc_element), "pattern") && source->av[AV_IDX_VIDEO].mute) + g_object_set(G_OBJECT(videosrc_element), "pattern", 2, NULL); /* 2: black */ + /* NOTE: in case of an element that supports tizen zerocopy format, not to emit an error in GST_STATE_PLAYING * without buffer consumption before finishing negotiation, set this property to 0 here. */ if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(videosrc_element)), "empty-buffer-timeout")) @@ -3593,42 +3605,35 @@ static GstPadProbeReturn __camerasrc_probe_cb(GstPad *pad, GstPadProbeInfo *inf static int __mute_camerasrc(webrtc_gst_slot_s *source, bool mute) { - int ret = WEBRTC_ERROR_NONE; GstElement *camerasrc = NULL; - GstPad *src_pad = NULL; - - LOG_DEBUG_ENTER(); + g_autoptr(GstPad) src_pad = NULL; RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); - RET_VAL_IF(source->video_muted == mute, WEBRTC_ERROR_NONE, "Already %s", mute ? "muted" : "unmuted"); + RET_VAL_IF(source->av[AV_IDX_VIDEO].mute == mute, WEBRTC_ERROR_NONE, "Already %s", mute ? "muted" : "unmuted"); - camerasrc = gst_bin_get_by_name(source->bin, ELEMENT_NAME_VIDEO_SRC); - src_pad = gst_element_get_static_pad(camerasrc, "src"); + if ((camerasrc = gst_bin_get_by_name(source->bin, ELEMENT_NAME_VIDEO_SRC))) { + src_pad = gst_element_get_static_pad(camerasrc, "src"); - if (mute) { - if (source->camerasrc_probe_id != 0) { - LOG_ERROR("fail to change to mute"); - ret = WEBRTC_ERROR_INVALID_OPERATION; - } else { + if (mute && source->camerasrc_probe_id == 0) { source->camerasrc_probe_id = gst_pad_add_probe(src_pad, GST_PAD_PROBE_TYPE_BUFFER, __camerasrc_probe_cb, NULL, NULL); if (source->camerasrc_probe_id == 0) { LOG_ERROR("failed to gst_pad_add_probe()"); - ret = WEBRTC_ERROR_INVALID_OPERATION; + return WEBRTC_ERROR_INVALID_OPERATION; } - } - } else { - if (source->camerasrc_probe_id == 0) { - LOG_ERROR("fail to change to unmute"); - ret = WEBRTC_ERROR_INVALID_OPERATION; - } else { + + } else if (!mute && source->camerasrc_probe_id != 0) { gst_pad_remove_probe(src_pad, source->camerasrc_probe_id); source->camerasrc_probe_id = 0; + + } else { + LOG_ERROR("failed to change mute to (%d)", mute); + return WEBRTC_ERROR_INVALID_OPERATION; } } - gst_object_unref(src_pad); + source->av[AV_IDX_VIDEO].mute = mute; - return ret; + return WEBRTC_ERROR_NONE; } static int __mute_videosrc(webrtc_gst_slot_s *source, bool mute) @@ -3637,15 +3642,17 @@ static int __mute_videosrc(webrtc_gst_slot_s *source, bool mute) GstPad *new_pad = NULL; RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); - RET_VAL_IF(source->video_muted == mute, WEBRTC_ERROR_NONE, "Already %s", mute ? "muted" : "unmuted"); + RET_VAL_IF(source->av[AV_IDX_VIDEO].mute == mute, WEBRTC_ERROR_NONE, "Already %s", mute ? "muted" : "unmuted"); - video_switch = gst_bin_get_by_name(source->bin, ELEMENT_NAME_VIDEO_SWITCH); + if ((video_switch = gst_bin_get_by_name(source->bin, ELEMENT_NAME_VIDEO_SWITCH))) { + new_pad = gst_element_get_static_pad(video_switch, mute ? "sink_1" : "sink_0"); + RET_VAL_IF(new_pad == NULL, WEBRTC_ERROR_INVALID_OPERATION, "new_pad is NULL"); - new_pad = gst_element_get_static_pad(video_switch, mute ? "sink_1" : "sink_0"); - RET_VAL_IF(new_pad == NULL, WEBRTC_ERROR_INVALID_OPERATION, "new_pad is NULL"); + g_object_set(G_OBJECT(video_switch), "active-pad", new_pad, NULL); + gst_object_unref(new_pad); + } - g_object_set(G_OBJECT(video_switch), "active-pad", new_pad, NULL); - gst_object_unref(new_pad); + source->av[AV_IDX_VIDEO].mute = mute; return WEBRTC_ERROR_NONE; } @@ -3656,17 +3663,18 @@ static int __mute_videotestsrc(webrtc_gst_slot_s *source, bool mute) GstElement *src_element = NULL; RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); - RET_VAL_IF(source->video_muted == mute, WEBRTC_ERROR_NONE, "Already %s", mute ? "muted" : "unmuted"); + RET_VAL_IF(source->av[AV_IDX_VIDEO].mute == mute, WEBRTC_ERROR_NONE, "Already %s", mute ? "muted" : "unmuted"); - src_element = gst_bin_get_by_name(source->bin, ELEMENT_NAME_VIDEO_SRC); - RET_VAL_IF(src_element == NULL, WEBRTC_ERROR_INVALID_OPERATION, "src_element is NULL"); - - if (!g_object_class_find_property(G_OBJECT_GET_CLASS(src_element), "pattern")) { - LOG_ERROR("there is no pattern property"); - return WEBRTC_ERROR_INVALID_OPERATION; + if ((src_element = gst_bin_get_by_name(source->bin, ELEMENT_NAME_VIDEO_SRC))) { + if (!g_object_class_find_property(G_OBJECT_GET_CLASS(src_element), "pattern")) { + LOG_ERROR("there is no pattern property"); + return WEBRTC_ERROR_INVALID_OPERATION; + } + /* FIXME: get original value from ini file */ + g_object_set(G_OBJECT(src_element), "pattern", mute ? 2 : 18, NULL); /* 2: black 18: ball */ } - g_object_set(G_OBJECT(src_element), "pattern", mute ? 2 : 18, NULL); /* 2: black 18: ball */ + source->av[AV_IDX_VIDEO].mute = mute; return WEBRTC_ERROR_NONE; } @@ -3717,10 +3725,7 @@ int _set_video_mute(webrtc_s *webrtc, unsigned int source_id, bool mute) LOG_DEBUG("webrtc[%p] source_id[%u] mute[%d]", webrtc, source_id, mute); - if ((ret = (videosrc_mute_funcs[source->type])(source, mute)) == WEBRTC_ERROR_NONE) - source->video_muted = mute; - - return ret; + return (videosrc_mute_funcs[source->type])(source, mute); } //LCOV_EXCL_START @@ -3787,7 +3792,7 @@ int _get_video_mute(webrtc_s *webrtc, unsigned int source_id, bool *muted) if ((ret = __validate_video_source_for_mute(webrtc, source_id, &source)) != WEBRTC_ERROR_NONE) return ret; - *muted = source->video_muted; + *muted = source->av[AV_IDX_VIDEO].mute; LOG_INFO("webrtc[%p] source_id[%u] muted[%d]", webrtc, source_id, *muted);