webrtc_test: Add sub-menu to apply echo-cancellation 69/275569/6
authorSangchul Lee <sc11.lee@samsung.com>
Thu, 19 May 2022 03:22:13 +0000 (12:22 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 31 May 2022 05:59:45 +0000 (14:59 +0900)
It is possible to choose to enable or disable AEC
when adding mic source.

[Version] 0.3.113
[Issue Type] Add

Change-Id: I6567d40df032813b8f374f8a060575e056433228
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
packaging/capi-media-webrtc.spec
test/webrtc_test.c
test/webrtc_test_menu.c
test/webrtc_test_priv.h

index 15e3e0e6a2c9dd852e14c5c7f485a90749821dd8..7abe32ceb709ac6ff4d97bce091d657717d1ee3d 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.112
+Version:    0.3.113
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 22b1041f6598908957f5526b87aa9681fdbd0fda..acd96f0686eae5a0834c5eb3d52a788f457b4782 100644 (file)
@@ -561,11 +561,69 @@ static int _find_packet_sources_index(int index, unsigned int source_id)
        return -1;
 }
 
-static int __get_sound_stream_info(sound_stream_info_h *stream_info)
+static void __set_aec_reference_device(sound_stream_info_h stream_info)
 {
        int ret;
        sound_device_list_h device_list = NULL;
-       sound_stream_info_h _stream_info;
+       sound_device_h device;
+       sound_device_type_e cur_playback_device_type;
+       bool found = false;
+
+       RET_IF(stream_info == NULL, "stream_info is NULL");
+
+       ret = sound_manager_get_current_media_playback_device_type(&cur_playback_device_type);
+       if (ret != SOUND_MANAGER_ERROR_NONE) {
+               g_printerr("failed to sound_manager_get_current_media_playback_device_type()\n");
+               return;
+       }
+
+       ret = sound_manager_get_device_list(SOUND_DEVICE_IO_DIRECTION_OUT_MASK, &device_list);
+       if (ret != SOUND_MANAGER_ERROR_NONE && ret != SOUND_MANAGER_ERROR_NO_DATA) {
+               g_printerr("failed to sound_manager_get_device_list()\n");
+               return;
+       }
+
+       while (sound_manager_get_next_device(device_list, &device) == SOUND_MANAGER_ERROR_NONE) {
+               sound_device_type_e device_type;
+               int device_id;
+
+               ret = sound_manager_get_device_type(device, &device_type);
+               if (ret != SOUND_MANAGER_ERROR_NONE) {
+                       g_printerr("failed to sound_manager_get_device_type()\n");
+                       break;
+               }
+
+               if (cur_playback_device_type != device_type)
+                       continue;
+
+               ret = sound_manager_get_device_id(device, &device_id);
+               if (ret != SOUND_MANAGER_ERROR_NONE) {
+                       g_printerr("failed to sound_manager_get_device_id()\n");
+                       break;
+               }
+
+               found = true;
+
+               ret = sound_manager_set_echo_cancel_reference_device(stream_info, device);
+               if (ret != SOUND_MANAGER_ERROR_NONE) {
+                       g_printerr("failed to sound_manager_set_echo_cancel_reference_device()\n");
+               } else {
+                       g_print("set a reference device[type:%u, id:%d]\n", device_type, device_id);
+                       break;
+               }
+       }
+
+       sound_manager_free_device_list(device_list);
+
+       if (!found)
+               g_printerr("could not find a candidate for reference device\n");
+}
+
+static int __get_mic_sound_stream_info(bool aec, sound_stream_info_h *stream_info)
+{
+       int ret;
+       sound_device_list_h device_list = NULL;
+       sound_stream_info_h _stream_info = NULL;
 
        if (!stream_info) {
                g_printerr("stream_info is NULL\n");
@@ -582,7 +640,7 @@ static int __get_sound_stream_info(sound_stream_info_h *stream_info)
                ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA, NULL, NULL, &_stream_info);
                if (ret != SOUND_MANAGER_ERROR_NONE) {
                        g_printerr("failed to sound_manager_create_stream_information()\n");
-                       return -1;
+                       goto error;
                }
 
        } else {
@@ -591,31 +649,38 @@ static int __get_sound_stream_info(sound_stream_info_h *stream_info)
                ret = sound_manager_create_stream_information(SOUND_STREAM_TYPE_MEDIA_EXTERNAL_ONLY, NULL, NULL, &_stream_info);
                if (ret != SOUND_MANAGER_ERROR_NONE) {
                        g_printerr("failed to sound_manager_create_stream_information()\n");
-                       return -1;
+                       goto error;
                }
                ret = sound_manager_get_next_device(device_list, &device);
                if (ret != SOUND_MANAGER_ERROR_NONE) {
                        g_printerr("failed to get device\n");
-                       sound_manager_destroy_stream_information(_stream_info);
-                       return -1;
+                       goto error;
                }
                ret |= sound_manager_add_device_for_stream_routing(_stream_info, device);
                ret |= sound_manager_apply_stream_routing(_stream_info);
                if (ret != SOUND_MANAGER_ERROR_NONE) {
                        g_printerr("failed to apply stream routing\n");
-                       sound_manager_destroy_stream_information(_stream_info);
-                       return -1;
+                       goto error;
                }
                sound_manager_get_device_name(device, &device_name);
                g_print("device[%s] is applied.\n", device_name);
        }
 
-       if (device_list)
-               sound_manager_free_device_list(device_list);
+       sound_manager_free_device_list(device_list);
 
        *stream_info = _stream_info;
 
+       if (aec)
+               __set_aec_reference_device(*stream_info);
+
        return 0;
+
+error:
+       if (device_list)
+               sound_manager_free_device_list(device_list);
+       if (_stream_info)
+               sound_manager_destroy_stream_information(_stream_info);
+       return -1;
 }
 
 static void _webrtc_add_media_source(int index, int type, unsigned int *source_id)
@@ -625,7 +690,12 @@ static void _webrtc_add_media_source(int index, int type, unsigned int *source_i
        int i;
 
        switch (type) {
-       case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST ... WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET:
+       case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
+               g_printerr("please use _webrtc_add_mic_source() for mic source\n");
+               break;
+       case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST:
+       case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
+       case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA ... WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET:
                if (type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET) {
                        i = _get_empty_packet_sources_index(index);
                        RET_IF(i == -1, "media packet source can be added up to %d", MAX_MEDIA_PACKET_SOURCE_LEN);
@@ -633,21 +703,7 @@ static void _webrtc_add_media_source(int index, int type, unsigned int *source_i
                ret = webrtc_add_media_source(g_conns[index].webrtc, type, &_source_id);
                RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret);
 
-               if (type == WEBRTC_MEDIA_SOURCE_TYPE_MIC) {
-                       if (g_conns[index].source.stream_info) {
-                               sound_manager_destroy_stream_information(g_conns[index].source.stream_info);
-                               g_conns[index].source.stream_info = NULL;
-                       }
-
-                       if (__get_sound_stream_info(&g_conns[index].source.stream_info) < 0) {
-                               g_printerr("failed to __get_sound_stream_info()\n");
-                       } else {
-                               ret = webrtc_mic_source_set_sound_stream_info(g_conns[index].webrtc, _source_id, g_conns[index].source.stream_info);
-                               if (ret != WEBRTC_ERROR_NONE)
-                                       g_printerr("failed to webrtc_mic_source_set_sound_stream_info(), ret[0x%x]\n", ret);
-                       }
-
-               } else if (type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET) {
+               if (type == WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET) {
                        g_conns[index].packet_sources[i].source_id = _source_id;
                        g_mutex_init(&g_conns[index].packet_sources[i].mutex);
                        g_cond_init(&g_conns[index].packet_sources[i].cond);
@@ -667,6 +723,32 @@ static void _webrtc_add_media_source(int index, int type, unsigned int *source_i
                *source_id = _source_id;
 }
 
+static void _webrtc_add_mic_source(int index, bool aec, unsigned int *source_id)
+{
+       int ret = WEBRTC_ERROR_NONE;
+       unsigned int _source_id = 0;
+
+       ret = webrtc_add_media_source(g_conns[index].webrtc, WEBRTC_MEDIA_SOURCE_TYPE_MIC, &_source_id);
+       RET_IF(ret != WEBRTC_ERROR_NONE, "ret[0x%x]", ret);
+
+       if (g_conns[index].source.stream_info) {
+               sound_manager_destroy_stream_information(g_conns[index].source.stream_info);
+               g_conns[index].source.stream_info = NULL;
+       }
+
+       if (__get_mic_sound_stream_info(aec, &g_conns[index].source.stream_info) < 0) {
+               g_printerr("failed to __get_mic_sound_stream_info()\n");
+       } else {
+               ret = webrtc_mic_source_set_sound_stream_info(g_conns[index].webrtc, _source_id, g_conns[index].source.stream_info);
+               if (ret != WEBRTC_ERROR_NONE)
+                       g_printerr("failed to webrtc_mic_source_set_sound_stream_info(), ret[0x%x]\n", ret);
+       }
+
+       g_print("_webrtc_add_mic_source() success, aec[%s], source_id[%u]\n", aec ? "enabled" : "disabled", _source_id);
+       if (source_id)
+               *source_id = _source_id;
+}
+
 static void _webrtc_remove_media_source(int index, unsigned int source_id)
 {
        int ret = WEBRTC_ERROR_NONE;
@@ -3696,13 +3778,13 @@ static void __auto_configure_add_peer(gchar *peer_id, bool is_offer)
                                _webrtc_media_source_set_video_loopback(i, source_id);
                        break;
                case 2:
-                       _webrtc_add_media_source(i, WEBRTC_MEDIA_SOURCE_TYPE_MIC, NULL);
+                       _webrtc_add_mic_source(i, false, NULL);
                        _webrtc_add_media_source(i, WEBRTC_MEDIA_SOURCE_TYPE_CAMERA, &source_id);
                        if (i == 0) /* only set loopback video of the first one */
                                _webrtc_media_source_set_video_loopback(i, source_id);
                        break;
                case 3:
-                       _webrtc_add_media_source(i, WEBRTC_MEDIA_SOURCE_TYPE_MIC, NULL);
+                       _webrtc_add_mic_source(i, false, NULL);
                        break;
                default:
                        return;
@@ -4254,8 +4336,22 @@ static void test_webrtc_media_source(char *cmd)
        switch (g_menu_status) {
        case CURRENT_STATUS_ADD_MEDIA_SOURCE: {
                value = atoi(cmd);
-               _webrtc_add_media_source(0, value - 1, NULL);
-               reset_menu_state();
+
+               switch (g_cnt) {
+               case 0:
+                       if (value == 3) { /* mic source */
+                               g_cnt++;
+                       } else {
+                               _webrtc_add_media_source(0, value - 1, NULL);
+                               reset_menu_state();
+                       }
+                       break;
+               case 1:
+                       _webrtc_add_mic_source(0, !(value == 0), NULL);
+                       g_cnt = 0;
+                       reset_menu_state();
+                       break;
+               }
                break;
        }
        case CURRENT_STATUS_REMOVE_MEDIA_SOURCE: {
index 9575eff9d0af82596d4d415de8fb1146faafd644..cb60ab58b1380602aa81763ccc8afa879ae73a4c 100644 (file)
@@ -297,7 +297,10 @@ void display_menu_webrtc_media_source(void)
 {
        switch (g_menu_status) {
        case CURRENT_STATUS_ADD_MEDIA_SOURCE:
-               g_print("*** input media source type.(1:audiotest, 2:videotest, 3:mic, 4:camera, 5:screen, 6:file, 7:media packet, 8:custom audio, 9:custom video)\n");
+        if (g_cnt == 0)
+                   g_print("*** input media source type.(1:audiotest, 2:videotest, 3:mic, 4:camera, 5:screen, 6:file, 7:media packet, 8:custom audio, 9:custom video)\n");
+               else if (g_cnt == 1)
+                       g_print("*** input value to enable AEC. (1:enable 0:disable)\n");
                break;
        case CURRENT_STATUS_REMOVE_MEDIA_SOURCE:
                g_print("*** input media source id to remove.\n");
index 989fff25bd3b16ef611acda939794b14a34f2c4d..8ef90e461ab1ea49fee9308e2c1a2aad2cc7010d 100644 (file)
@@ -20,7 +20,7 @@
 #include <webrtc_internal.h>
 #include <media_format.h>
 #include <media_packet_internal.h>
-#include <sound_manager.h>
+#include <sound_manager_internal.h>
 #ifndef TIZEN_TV
 #include <esplusplayer_capi.h>
 #endif