webrtc_internal: Add functions for audio track mute 86/282486/2 accepted/tizen_6.5_unified tizen_6.5 accepted/tizen/6.5/unified/20221005.103630 submit/tizen_6.5/20221004.110139
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 4 Oct 2022 07:24:33 +0000 (16:24 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 4 Oct 2022 07:37:58 +0000 (16:37 +0900)
[Version] 0.2.184
[Issue Type] Internal API

Change-Id: Iebd221fe10f32f8a6ab5ccb7c20d70d475d1dee2
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/webrtc_internal.h
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc_internal.c
src/webrtc_sink.c

index c61c53f0369842e2b221f8867ce6f35b56708f88..e009f6e20986b581c775737535a20cfc6af1e44a 100644 (file)
@@ -159,6 +159,42 @@ int webrtc_get_bundle_policy(webrtc_h webrtc, webrtc_bundle_policy_e *policy);
  */
 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.
index cd2b07e530338178bfdb8e1306fc2907d86179b4..bb25fe53d698699e227bd157f05bc8bd68c15b4c 100644 (file)
@@ -643,6 +643,8 @@ int _set_display_visible_to_sink(webrtc_s *webrtc, unsigned int track_id, bool v
 int _get_display_visible_from_sink(webrtc_s *webrtc, unsigned int track_id, bool *visible);
 int _set_display_visible_to_loopback(webrtc_s *webrtc, unsigned int track_id, bool visible);
 int _get_display_visible_from_loopback(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);
 int _set_audio_loopback(webrtc_s *webrtc, unsigned int source_id, sound_stream_info_h stream_info, unsigned int *track_id);
 int _set_video_loopback(webrtc_s *webrtc, unsigned int source_id, unsigned int type, void *display, unsigned int *track_id);
 int _decodebin_autoplug_select_cb(GstElement *decodebin, GstPad *pad, GstCaps *caps, GstElementFactory *factory, gpointer user_data);
index bdb6af664aadbe4603a4e2fe4a0c6ea951a2700f..83e798a82eb839216c9347328f7d84b1d2b563ba 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.2.183
+Version:    0.2.184
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 56d467c463c1c483d97fda8174fb15eb1b090757..e09247f78a7e003434298d1b80e2a528705a7340 100644 (file)
@@ -90,6 +90,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;
index 1a8269a23ab969120e65195331b6b48abfb60086..8bd37b1d1cefdd78c8580b49d094209376aba21c 100644 (file)
@@ -19,6 +19,8 @@
 #include <gst/video/videooverlay.h>
 #include <media_packet_internal.h>
 
+#define ELEMENT_NAME_AUDIO_SINK          "audioSink"
+
 //LCOV_EXCL_START
 bool _is_owner_of_track_build_context(webrtc_s *webrtc, unsigned int track_id)
 {
@@ -246,7 +248,7 @@ static int __build_audiosink(webrtc_s *webrtc, GstElement *decodebin, GstPad *sr
                if (!(audioresample = _create_element(DEFAULT_ELEMENT_AUDIORESAMPLE, NULL)))
                        return WEBRTC_ERROR_INVALID_OPERATION;
 
-               if (!(audiosink = _create_element(webrtc->ini.rendering_sink.a_sink_element, NULL)))
+               if (!(audiosink = _create_element(webrtc->ini.rendering_sink.a_sink_element, ELEMENT_NAME_AUDIO_SINK)))
                        return WEBRTC_ERROR_INVALID_OPERATION;
 
                if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(audiosink)), "stream-properties")) {
@@ -962,7 +964,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);
 
@@ -1083,4 +1085,51 @@ 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