From: Sangchul Lee Date: Fri, 30 Sep 2022 07:51:39 +0000 (+0900) Subject: webrtc_internal: Add functions for audio track mute X-Git-Tag: accepted/tizen/unified/20221109.171125^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F63%2F282363%2F7;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_internal: Add functions for audio track mute It's cherry-picked from tizen_6.5 branch. [Version] 0.3.262 [Issue Type] Internal API Change-Id: Ia942f612e126c7a5a2bc6b44dcd52bd41be7816a Signed-off-by: Sangchul Lee --- diff --git a/include/webrtc_internal.h b/include/webrtc_internal.h index d05906fc..1e5338ec 100644 --- a/include/webrtc_internal.h +++ b/include/webrtc_internal.h @@ -102,6 +102,42 @@ typedef void (*webrtc_signaling_message_cb)(webrtc_signaling_message_type_e type */ int webrtc_set_ecore_wl_display(webrtc_h webrtc, unsigned int track_id, void *ecore_wl_window); +/** + * @internal + * @brief Sets mute to the audio track. + * @since_tizen 6.5 + * @remarks If @a mute is set to @c true, playback of audio track received from a remote peer will be muted. + * @param[in] webrtc WebRTC handle + * @param[in] track_id The track id + * @param[in] mute Mute or not (@c true = mute, @c false = not mute) + * @return @c 0 on success, + * otherwise a negative error value + * @retval #WEBRTC_ERROR_NONE Successful + * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WEBRTC_ERROR_INVALID_OPERATION Invalid operation + * @pre Call webrtc_set_sound_stream_info() before calling this function. + * @see webrtc_get_audio_mute() + */ +int webrtc_set_audio_mute(webrtc_h webrtc, unsigned int track_id, bool mute); + +/** + * @internal + * @brief Gets the mute state of the audio track. + * @since_tizen 6.5 + * @remarks The default value is @c false. + * @param[in] webrtc WebRTC handle + * @param[in] track_id The track id + * @param[out] muted Muted or not (@c true = muted, @c false = not muted) + * @return @c 0 on success, + * otherwise a negative error value + * @retval #WEBRTC_ERROR_NONE Successful + * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WEBRTC_ERROR_INVALID_OPERATION Invalid operation + * @pre Call webrtc_set_sound_stream_info() before calling this function. + * @see webrtc_set_audio_mute() + */ +int webrtc_get_audio_mute(webrtc_h webrtc, unsigned int track_id, bool *muted); + /** * @internal * @brief Sets a video loopback to render the video frames of the media source to an ecore wayland display. diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 6d3abae8..082b7580 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -760,6 +760,8 @@ int _set_display_mode_to_sink(webrtc_s *webrtc, unsigned int track_id, webrtc_di int _get_display_mode_from_sink(webrtc_s *webrtc, unsigned int track_id, webrtc_display_mode_e *mode); int _set_display_visible_to_sink(webrtc_s *webrtc, unsigned int track_id, bool visible); int _get_display_visible_from_sink(webrtc_s *webrtc, unsigned int track_id, bool *visible); +int _set_audio_mute_to_sink(webrtc_s *webrtc, unsigned int track_id, bool mute); +int _get_audio_mute_from_sink(webrtc_s *webrtc, unsigned int track_id, bool *muted); /* sink dump */ GstPadProbeReturn _depayloaded_data_probe_cb(GstPad *pad, GstPadProbeInfo *info, gpointer user_data); diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 755b6e7f..f59c3028 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.261 +Version: 0.3.262 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_internal.c b/src/webrtc_internal.c index d7dc3529..bea9050f 100644 --- a/src/webrtc_internal.c +++ b/src/webrtc_internal.c @@ -41,6 +41,35 @@ int webrtc_set_ecore_wl_display(webrtc_h webrtc, unsigned int track_id, void *ec return ret; } +int webrtc_set_audio_mute(webrtc_h webrtc, unsigned int track_id, bool mute) +{ + g_autoptr(GMutexLocker) locker = NULL; + webrtc_s *_webrtc = (webrtc_s *)webrtc; + + RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + + locker = g_mutex_locker_new(&_webrtc->mutex); + + RET_VAL_IF(_webrtc->track_added_cb.callback == NULL, WEBRTC_ERROR_INVALID_OPERATION, "track added callback was not set"); + + return _set_audio_mute_to_sink(_webrtc, track_id, mute); +} + +int webrtc_get_audio_mute(webrtc_h webrtc, unsigned int track_id, bool *muted) +{ + g_autoptr(GMutexLocker) locker = NULL; + webrtc_s *_webrtc = (webrtc_s *)webrtc; + + RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(muted == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "muted is NULL"); + + locker = g_mutex_locker_new(&_webrtc->mutex); + + RET_VAL_IF(_webrtc->track_added_cb.callback == NULL, WEBRTC_ERROR_INVALID_OPERATION, "track added callback was not set"); + + return _get_audio_mute_from_sink(_webrtc, track_id, muted); +} + int webrtc_media_source_set_video_loopback_to_ecore_wl(webrtc_h webrtc, unsigned int source_id, void *ecore_wl_window, unsigned int *track_id) { int ret = WEBRTC_ERROR_NONE; diff --git a/src/webrtc_sink.c b/src/webrtc_sink.c index 08cfb6bf..56fea11d 100644 --- a/src/webrtc_sink.c +++ b/src/webrtc_sink.c @@ -20,6 +20,8 @@ #include #include +#define ELEMENT_NAME_AUDIO_SINK "audioSink" + //LCOV_EXCL_START bool _is_owner_of_track_build_context(webrtc_s *webrtc, unsigned int track_id) { @@ -271,7 +273,7 @@ static int __build_audiosink(webrtc_s *webrtc, GstElement *decodebin, GstPad *sr sink->media_types = MEDIA_TYPE_AUDIO; stream_info_is_set = !!sink->sound_stream_info.type; - if (!(audiosink = _create_element(stream_info_is_set ? webrtc->ini.rendering_sink.a_sink_element : DEFAULT_ELEMENT_FAKESINK, NULL))) + if (!(audiosink = _create_element(stream_info_is_set ? webrtc->ini.rendering_sink.a_sink_element : DEFAULT_ELEMENT_FAKESINK, ELEMENT_NAME_AUDIO_SINK))) return WEBRTC_ERROR_INVALID_OPERATION; APPEND_ELEMENT(element_list, audiosink); link_to = audiosink; @@ -1081,7 +1083,7 @@ int _set_stream_info_to_sink(webrtc_s *webrtc, unsigned int track_id, sound_stre RET_VAL_IF(sink == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "sink is NULL"); RET_VAL_IF(sink->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); RET_VAL_IF(sink->encoded_frame_cb != NULL, WEBRTC_ERROR_INVALID_OPERATION, "it may be a forwarding sink for encoded frame callback"); - RET_VAL_IF((sink->media_types & MEDIA_TYPE_AUDIO) == 0x0, WEBRTC_ERROR_INVALID_OPERATION, "it's not a audio track"); + RET_VAL_IF((sink->media_types & MEDIA_TYPE_AUDIO) == 0x0, WEBRTC_ERROR_INVALID_OPERATION, "it's not an audio track"); RET_VAL_IF(strcmp(webrtc->ini.rendering_sink.a_sink_element, DEFAULT_AUDIO_SINK_ELEMENT), WEBRTC_ERROR_INVALID_OPERATION, "it requires [%s] as an audio renderer", DEFAULT_AUDIO_SINK_ELEMENT); @@ -1202,4 +1204,52 @@ int _get_display_visible_from_sink(webrtc_s *webrtc, unsigned int track_id, bool return WEBRTC_ERROR_NONE; } + +int _set_audio_mute_to_sink(webrtc_s *webrtc, unsigned int track_id, bool mute) +{ + webrtc_gst_slot_s *sink; + GstElement *audiosink; + + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(track_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "track id is 0"); + + sink = __find_sink_slot_by_id(webrtc, track_id); + RET_VAL_IF(sink == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "sink is NULL"); + RET_VAL_IF(sink->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); + RET_VAL_IF(sink->encoded_frame_cb != NULL, WEBRTC_ERROR_INVALID_OPERATION, "it may be a forwarding sink for encoded frame callback"); + RET_VAL_IF((sink->media_types & MEDIA_TYPE_AUDIO) == 0x0, WEBRTC_ERROR_INVALID_OPERATION, "it's not an audio track"); + RET_VAL_IF(sink->sound_stream_info.type == NULL, WEBRTC_ERROR_INVALID_OPERATION, "sound_stream_info is not set"); + RET_VAL_IF(!(audiosink = gst_bin_get_by_name(sink->bin, ELEMENT_NAME_AUDIO_SINK)), WEBRTC_ERROR_INVALID_OPERATION, "could not find audio sink element"); + + g_object_set(G_OBJECT(audiosink), "mute", mute, NULL); + + LOG_INFO("webrtc[%p] track_id[%u] mute[%u]", webrtc, track_id, mute); + + return WEBRTC_ERROR_NONE; +} + +int _get_audio_mute_from_sink(webrtc_s *webrtc, unsigned int track_id, bool *muted) +{ + webrtc_gst_slot_s *sink; + GstElement *audiosink; + + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(track_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "track id is 0"); + RET_VAL_IF(muted == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "muted is NULL"); + + sink = __find_sink_slot_by_id(webrtc, track_id); + RET_VAL_IF(sink == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "sink is NULL"); + RET_VAL_IF(sink->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); + RET_VAL_IF(sink->encoded_frame_cb != NULL, WEBRTC_ERROR_INVALID_OPERATION, "it may be a forwarding sink for encoded frame callback"); + RET_VAL_IF((sink->media_types & MEDIA_TYPE_AUDIO) == 0x0, WEBRTC_ERROR_INVALID_OPERATION, "it's not an audio track"); + RET_VAL_IF(sink->sound_stream_info.type == NULL, WEBRTC_ERROR_INVALID_OPERATION, "sound_stream_info is not set"); + RET_VAL_IF(!(audiosink = gst_bin_get_by_name(sink->bin, ELEMENT_NAME_AUDIO_SINK)), WEBRTC_ERROR_INVALID_OPERATION, "could not find audio sink element"); + + g_object_get(G_OBJECT(audiosink), "mute", muted, NULL); + + LOG_INFO("webrtc[%p] track_id[%u] muted[%u]", webrtc, track_id, *muted); + + return WEBRTC_ERROR_NONE; +} + //LCOV_EXCL_STOP