Add support for mic source echo cancellation 68/275568/6
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 19 May 2022 03:21:27 +0000 (12:21 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 31 May 2022 05:59:20 +0000 (14:59 +0900)
[Version] 0.3.112
[Issue Type] New feature

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

index a1e560fdad4a03f0449e24417d97e9ba65c9c2db..ed1de41f1849f9873750b05c59c6a82f6f876dcd 100644 (file)
@@ -626,7 +626,7 @@ int _set_video_resolution(webrtc_s *webrtc, unsigned int source_id, int width, i
 int _get_video_resolution(webrtc_s *webrtc, unsigned int source_id, int *width, int *height);
 int _set_video_framerate(webrtc_s *webrtc, unsigned int source_id, int framerate);
 int _get_video_framerate(webrtc_s *webrtc, unsigned int source_id, int *framerate);
-int _apply_stream_info(GstElement *element, const char *stream_type, int stream_index);
+int _apply_stream_info(GstElement *element, const char *stream_type, int stream_index, int aec_ref_device_id);
 int _set_sound_stream_info(webrtc_s *webrtc, unsigned int source_id, sound_stream_info_h stream_info);
 int _set_media_format(webrtc_s *webrtc, unsigned int source_id, media_format_h format);
 bool _check_if_format_is_set_to_packet_sources(webrtc_s *webrtc);
index ea3c57e2bc9017f40bfaef4227c69e635dd65a03..15e3e0e6a2c9dd852e14c5c7f485a90749821dd8 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.111
+Version:    0.3.112
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 85276d8c0160cc24d9be7d2f45c1e2a462ac6e7f..5c93d947827225e5a583c8ce2144d6d6eecdc2c5 100644 (file)
@@ -2199,21 +2199,28 @@ int _webrtc_stop(webrtc_s *webrtc)
        return ret;
 }
 
-int _apply_stream_info(GstElement *element, const char *stream_type, int stream_index)
+int _apply_stream_info(GstElement *element, const char *stream_type, int stream_index, int aec_ref_device_id)
 {
        GstStructure *structure;
-       char values[64] = {'\0',};
+       g_autofree gchar *prop = NULL;
+       g_autofree gchar *prop_with_aec = NULL;
+       bool aec = (aec_ref_device_id != SOUND_MANAGER_STREAM_NO_REFERENCE_DEVICE);
 
        RET_VAL_IF(element == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "element is NULL");
        RET_VAL_IF(stream_type == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "stream_type is NULL");
        RET_VAL_IF(!g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(element)), "stream-properties"),
                WEBRTC_ERROR_INVALID_OPERATION, "could not find 'stream-properties'");
 
-       snprintf(values, sizeof(values) - 1, "props,%s=%s, %s=%d", PA_PROP_MEDIA_ROLE, stream_type, PA_PROP_MEDIA_PARENT_ID, stream_index);
-       RET_VAL_IF(!(structure = gst_structure_from_string(values, NULL)),
-               WEBRTC_ERROR_INVALID_OPERATION, "failed to gst_structure_from_string(), [%s]", values);
+       prop = g_strdup_printf("props,%s=%s, %s=%d", PA_PROP_MEDIA_ROLE, stream_type, PA_PROP_MEDIA_PARENT_ID, stream_index);
+       if (aec) {
+               prop_with_aec = g_strdup_printf("%s, %s=%s, %s=%d",
+                       prop, PA_PROP_MEDIA_ECHO_CANCEL_METHOD, "default", PA_PROP_MEDIA_ECHO_CANCEL_REFERENCE_DEVICE, aec_ref_device_id);
+       }
+
+       RET_VAL_IF(!(structure = gst_structure_from_string(aec ? prop_with_aec : prop, NULL)),
+               WEBRTC_ERROR_INVALID_OPERATION, "failed to gst_structure_from_string(), [%s]", aec ? prop_with_aec : prop);
 
-       LOG_INFO("stream-properties[%s]", values);
+       LOG_INFO("stream-properties[%s]", aec ? prop_with_aec : prop);
 
        g_object_set(G_OBJECT(element), "stream-properties", structure, NULL);
        gst_structure_free(structure);
index 11b0077b6882ae63e03d969f4a6417d8e6210167..9c1feb229334d66a6e164cd5bae90fd4818933da 100644 (file)
@@ -250,7 +250,8 @@ static int __build_audiosink(webrtc_s *webrtc, GstElement *decodebin, GstPad *sr
 
                if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(audiosink)), "stream-properties")) {
                        if (sink->sound_stream_info.type) {
-                               ret = _apply_stream_info(audiosink, sink->sound_stream_info.type, sink->sound_stream_info.index);
+                               ret = _apply_stream_info(audiosink, sink->sound_stream_info.type, sink->sound_stream_info.index,
+                                       SOUND_MANAGER_STREAM_NO_REFERENCE_DEVICE);
                                if (ret != WEBRTC_ERROR_NONE) /* FIXME: unref all the created elements */
                                        return WEBRTC_ERROR_INVALID_OPERATION;
                        }
index c96352a76b60485b9703af0f4ca94d216fdc990a..239c4f0720aadbaf51cc6943216f71eb33989d3d 100644 (file)
@@ -2993,6 +2993,7 @@ int _set_sound_stream_info(webrtc_s *webrtc, unsigned int source_id, sound_strea
        bool available = false;
        char *stream_type;
        int stream_index;
+       int aec_ref_device_id = 0;
 
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
        RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "could not find source");
@@ -3004,6 +3005,7 @@ int _set_sound_stream_info(webrtc_s *webrtc, unsigned int source_id, sound_strea
 
        sound_manager_get_type_from_stream_information(stream_info, &stream_type);
        sound_manager_get_index_from_stream_information(stream_info, &stream_index);
+       sound_manager_get_echo_cancel_reference_device(stream_info, &aec_ref_device_id);
 
        ret = sound_manager_is_available_stream_information(stream_info, NATIVE_API_WEBRTC, &available);
        if (ret != SOUND_MANAGER_ERROR_NONE) {
@@ -3016,9 +3018,10 @@ int _set_sound_stream_info(webrtc_s *webrtc, unsigned int source_id, sound_strea
                return WEBRTC_ERROR_INVALID_PARAMETER;
        }
 
-       LOG_INFO("webrtc[%p], source_id[%u], stream_info[%p, type:%s, index:%d]", webrtc, source_id, stream_info, stream_type, stream_index);
+       LOG_INFO("webrtc[%p], source_id[%u], stream_info[%p, type:%s, index:%d, aec_ref_device_id:%d]",
+               webrtc, source_id, stream_info, stream_type, stream_index, aec_ref_device_id);
 
-       return _apply_stream_info(element, stream_type, stream_index);
+       return _apply_stream_info(element, stream_type, stream_index, aec_ref_device_id);
 }
 
 int _set_media_format(webrtc_s *webrtc, unsigned int source_id, media_format_h format)
@@ -3826,7 +3829,8 @@ static int __build_loopback_audiosink(webrtc_gst_slot_s *source, GstElement *lin
 
        if (g_object_class_find_property(G_OBJECT_GET_CLASS(G_OBJECT(audiosink)), "stream-properties")) {
                if (source->sound_stream_info.type) {
-                       ret = _apply_stream_info(audiosink, source->sound_stream_info.type, source->sound_stream_info.index);
+                       ret = _apply_stream_info(audiosink, source->sound_stream_info.type, source->sound_stream_info.index,
+                               SOUND_MANAGER_STREAM_NO_REFERENCE_DEVICE);
                        if (ret != WEBRTC_ERROR_NONE)
                                goto exit;
                }