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");
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 {
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)
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);
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);
*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;
_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;
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: {