#define VCONF_PATH_PREFIX_VOLUME "file/private/sound/volume/"
#define VCONF_PATH_MAX 64
+#define CHECK_AND_SET_DEVICE(x_dst_device1, x_dst_device2, x_src_device) \
+do { \
+ if (!x_dst_device1) \
+ x_dst_device1 = x_src_device; \
+ else if (!x_dst_device2) \
+ x_dst_device2 = x_src_device; \
+ else { \
+ LOGE("all dst devices are already set"); \
+ goto ERROR_CASE; \
+ } \
+} while (0) \
+
extern _session_interrupt_info_s g_session_interrupt_cb_table;
extern _session_mode_e g_cached_session_mode;
extern int g_cached_voip_device_id;
+extern int g_cached_voip_device_id2;
extern _focus_watch_info_s focus_watch_info_arr[SOUND_STREAM_INFO_ARR_MAX];
sound_stream_info_s *sound_stream_info_arr[SOUND_STREAM_INFO_ARR_MAX];
sound_stream_info_s *g_voip_stream_info = NULL;
int _set_session_mode(_session_mode_e mode)
{
int ret = MM_ERROR_NONE;
- int w_ret = MM_ERROR_NONE;
- int i_ret = SOUND_MANAGER_ERROR_NONE;
- bool is_found = false;
- MMSoundDeviceList_t device_list;
+ MMSoundDeviceList_t device_list = NULL;
MMSoundDevice_t tmp_device = NULL;
MMSoundDevice_t proper_device = NULL;
+ MMSoundDevice_t proper_device2 = NULL;
MMSoundDevice_t prev_device = NULL;
+ MMSoundDevice_t prev_device2 = NULL;
mm_sound_device_type_e type;
int id = -1;
}
/* create stream info and acquire focus for rintone-voip stream */
g_voip_stream_info->stream_type = "ringtone-voip";
- ret = _make_pa_connection_and_register_focus(g_voip_stream_info, true, _voip_focus_state_change_callback, NULL);
- if (ret != MM_ERROR_NONE) {
+ if ((ret = _make_pa_connection_and_register_focus(g_voip_stream_info, true, _voip_focus_state_change_callback, NULL))) {
SM_SAFE_FREE(g_voip_stream_info);
goto ERROR_CASE;
- } else {
- /* acquire focus */
- ret = mm_sound_acquire_focus(g_voip_stream_info->index, FOCUS_FOR_BOTH, "for voip session");
- if (ret == MM_ERROR_NONE) {
- g_voip_stream_info->acquired_focus |= FOCUS_FOR_BOTH;
- _update_focus_status(g_voip_stream_info->index, (unsigned int)g_voip_stream_info->acquired_focus);
- } else
- goto ERROR_CASE;
-
}
+
+ /* acquire focus */
+ if ((ret = mm_sound_acquire_focus(g_voip_stream_info->index, FOCUS_FOR_BOTH, "for voip session")))
+ goto ERROR_CASE;
+
+ g_voip_stream_info->acquired_focus |= FOCUS_FOR_BOTH;
+ _update_focus_status(g_voip_stream_info->index, (unsigned int)g_voip_stream_info->acquired_focus);
+
/* create virtual stream for ringtone-voip */
- i_ret = _create_virtual_stream(g_voip_stream_info, &g_voip_vstream_h);
- if (i_ret == SOUND_MANAGER_ERROR_NONE) {
- i_ret = _start_virtual_stream(g_voip_vstream_h);
- if (i_ret != SOUND_MANAGER_ERROR_NONE)
- goto ERROR_CASE;
- } else {
+ if ((ret = _create_virtual_stream(g_voip_stream_info, &g_voip_vstream_h))) {
ret = MM_ERROR_SOUND_INTERNAL;
goto ERROR_CASE;
}
+
+ if ((ret = _start_virtual_stream(g_voip_vstream_h)))
+ goto ERROR_CASE;
+
break;
case _SESSION_MODE_VOICE_WITH_BUILTIN_RECEIVER: /* Built-in RCV and Built-in MIC */
case _SESSION_MODE_VOICE_WITH_BUILTIN_SPEAKER: /* Built-in SPK and Built-in MIC */
case _SESSION_MODE_VOICE_WITH_AUDIO_JACK: /* Earphone spk & mic */
case _SESSION_MODE_VOICE_WITH_BLUETOOTH_SCO: /* Bluetooth spk & mic */
/* check if the device is available now */
- ret = mm_sound_get_device_list(MM_SOUND_DEVICE_ALL_FLAG, &device_list);
- if (ret != MM_ERROR_NONE) {
+ if ((ret = mm_sound_get_device_list(MM_SOUND_DEVICE_ALL_FLAG, &device_list))) {
LOGE("failed to get current device list");
goto ERROR_CASE;
- } else {
- while (!is_found && ((w_ret = mm_sound_get_next_device(device_list, &tmp_device)) == MM_ERROR_NONE)) {
- ret = mm_sound_get_device_type(tmp_device, &type);
- if (ret != MM_ERROR_NONE)
- goto ERROR_CASE;
- ret = mm_sound_get_device_id(tmp_device, &id);
- if (ret != MM_ERROR_NONE)
- goto ERROR_CASE;
- else {
- if (g_cached_voip_device_id != -1 && g_cached_voip_device_id == id)
- prev_device = tmp_device;
- }
- switch (mode) {
- case _SESSION_MODE_VOICE_WITH_BUILTIN_RECEIVER:
- if (type == MM_SOUND_DEVICE_TYPE_BUILTIN_RECEIVER) {
- is_found = true;
- proper_device = tmp_device;
- break;
- }
- case _SESSION_MODE_VOICE_WITH_BUILTIN_SPEAKER:
- if (type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER) {
- is_found = true;
- proper_device = tmp_device;
- break;
- }
- case _SESSION_MODE_VOICE_WITH_AUDIO_JACK:
- if (type == MM_SOUND_DEVICE_TYPE_AUDIOJACK) {
- is_found = true;
- proper_device = tmp_device;
- break;
- }
- break;
- case _SESSION_MODE_VOICE_WITH_BLUETOOTH_SCO:
- if (type == MM_SOUND_DEVICE_TYPE_BLUETOOTH_SCO) {
- is_found = true;
- proper_device = tmp_device;
- break;
- }
- default:
- break;
- }
- }
- if (!is_found) {
- LOGE("could not found a proper connected device for this mode(%d)", mode);
- ret = MM_ERROR_SOUND_INTERNAL;
- goto ERROR_CASE_NO_DESTROY;
+ }
+
+ while ((mm_sound_get_next_device(device_list, &tmp_device) == MM_ERROR_NONE)) {
+ if ((ret = mm_sound_get_device_type(tmp_device, &type)))
+ goto ERROR_CASE;
+ if ((ret = mm_sound_get_device_id(tmp_device, &id)))
+ goto ERROR_CASE;
+
+ if (g_cached_voip_device_id == id)
+ CHECK_AND_SET_DEVICE(prev_device, prev_device2, tmp_device);
+ else if (g_cached_voip_device_id2 == id)
+ CHECK_AND_SET_DEVICE(prev_device, prev_device2, tmp_device);
+
+
+ switch (mode) {
+ case _SESSION_MODE_VOICE_WITH_BUILTIN_RECEIVER:
+ if (type == MM_SOUND_DEVICE_TYPE_BUILTIN_RECEIVER)
+ CHECK_AND_SET_DEVICE(proper_device, proper_device2, tmp_device);
+ else if (type == MM_SOUND_DEVICE_TYPE_BUILTIN_MIC)
+ CHECK_AND_SET_DEVICE(proper_device, proper_device2, tmp_device);
+ break;
+ case _SESSION_MODE_VOICE_WITH_BUILTIN_SPEAKER:
+ if (type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER)
+ CHECK_AND_SET_DEVICE(proper_device, proper_device2, tmp_device);
+ else if (type == MM_SOUND_DEVICE_TYPE_BUILTIN_MIC)
+ CHECK_AND_SET_DEVICE(proper_device, proper_device2, tmp_device);
+ break;
+ case _SESSION_MODE_VOICE_WITH_AUDIO_JACK:
+ if (type == MM_SOUND_DEVICE_TYPE_AUDIOJACK)
+ CHECK_AND_SET_DEVICE(proper_device, proper_device2, tmp_device);
+ break;
+ case _SESSION_MODE_VOICE_WITH_BLUETOOTH_SCO:
+ if (type == MM_SOUND_DEVICE_TYPE_BLUETOOTH_SCO)
+ CHECK_AND_SET_DEVICE(proper_device, proper_device2, tmp_device);
+ break;
+ default:
+ break;
}
}
- /* if ok for the device, go below */
+
+ if (!proper_device && !proper_device2) {
+ LOGE("failed to find any proper device");
+ goto ERROR_CASE_NO_DESTROY;
+ }
+
if (g_cached_session_mode == _SESSION_MODE_RINGTONE) {
/* stop vstream and destroy vstream */
_stop_virtual_stream(g_voip_vstream_h);
if (!g_voip_stream_info) {
g_voip_stream_info = malloc(sizeof(sound_stream_info_s));
if (!g_voip_stream_info) {
- ret = MM_ERROR_OUT_OF_MEMORY;
+ LOGE("failed to malloc for g_voip_stream_info");
goto ERROR_CASE;
}
memset(g_voip_stream_info, 0, sizeof(sound_stream_info_s));
+ LOGI("g_voip_stream_info(%p) is newly created", g_voip_stream_info);
}
g_voip_stream_info->stream_type = "voip";
- ret = _make_pa_connection_and_register_focus(g_voip_stream_info, true, _voip_focus_state_change_callback, NULL);
- if (ret != MM_ERROR_NONE) {
+ if ((ret = _make_pa_connection_and_register_focus(g_voip_stream_info, true, _voip_focus_state_change_callback, NULL))) {
SM_SAFE_FREE(g_voip_stream_info);
goto ERROR_CASE;
}
- /* set device for routing to the device */
- i_ret = _add_device_for_stream_routing(g_voip_stream_info, proper_device);
- if (i_ret == SOUND_MANAGER_ERROR_NONE) {
- i_ret = _apply_stream_routing(g_voip_stream_info);
- if (i_ret != SOUND_MANAGER_ERROR_NONE)
+ if (proper_device) {
+ if ((ret = _add_device_for_stream_routing(g_voip_stream_info, proper_device)))
+ goto ERROR_CASE;
+ }
+ if (proper_device2) {
+ if ((ret = _add_device_for_stream_routing(g_voip_stream_info, proper_device2)))
goto ERROR_CASE;
- } else
+ }
+
+ if ((ret = _apply_stream_routing(g_voip_stream_info)))
goto ERROR_CASE;
/* acquire focus */
- ret = mm_sound_acquire_focus(g_voip_stream_info->index, FOCUS_FOR_BOTH, "for voip session");
- if (ret == MM_ERROR_NONE) {
- g_voip_stream_info->acquired_focus |= FOCUS_FOR_BOTH;
- _update_focus_status(g_voip_stream_info->index, (unsigned int)g_voip_stream_info->acquired_focus);
- } else
+ if ((ret = mm_sound_acquire_focus(g_voip_stream_info->index, FOCUS_FOR_BOTH, "for voip session")))
goto ERROR_CASE;
+ g_voip_stream_info->acquired_focus |= FOCUS_FOR_BOTH;
+ _update_focus_status(g_voip_stream_info->index, (unsigned int)g_voip_stream_info->acquired_focus);
+
/* create virtual stream for voip */
- i_ret = _create_virtual_stream(g_voip_stream_info, &g_voip_vstream_h);
- if (i_ret == SOUND_MANAGER_ERROR_NONE) {
- i_ret = _start_virtual_stream(g_voip_vstream_h);
- if (i_ret != SOUND_MANAGER_ERROR_NONE)
- goto ERROR_CASE;
- } else
+ if ((ret = _create_virtual_stream(g_voip_stream_info, &g_voip_vstream_h)))
goto ERROR_CASE;
- } else {
- if (g_cached_voip_device_id != -1 && prev_device) {
- /* remove cached device */
- i_ret = _remove_device_for_stream_routing(g_voip_stream_info, prev_device);
- if (i_ret != SOUND_MANAGER_ERROR_NONE)
- goto ERROR_CASE;
- /* set device for routing to the device */
- i_ret = _add_device_for_stream_routing(g_voip_stream_info, proper_device);
- if (i_ret == SOUND_MANAGER_ERROR_NONE) {
- i_ret = _apply_stream_routing(g_voip_stream_info);
- if (i_ret != SOUND_MANAGER_ERROR_NONE)
- goto ERROR_CASE;
- } else
- goto ERROR_CASE;
- } else
+ if ((ret = _start_virtual_stream(g_voip_vstream_h)))
goto ERROR_CASE;
+
+ } else {
+ if (prev_device) {
+ if ((ret = _remove_device_for_stream_routing(g_voip_stream_info, prev_device)))
+ goto ERROR_CASE_NO_DESTROY;
+ }
+ if (prev_device2) {
+ if ((ret = _remove_device_for_stream_routing(g_voip_stream_info, prev_device2)))
+ goto ERROR_CASE_NO_DESTROY;
+ }
+ if (proper_device) {
+ if ((ret = _add_device_for_stream_routing(g_voip_stream_info, proper_device)))
+ goto ERROR_CASE_NO_DESTROY;
+ }
+ if (proper_device2) {
+ if ((ret = _add_device_for_stream_routing(g_voip_stream_info, proper_device2)))
+ goto ERROR_CASE_NO_DESTROY;
+ }
+ if ((ret = _apply_stream_routing(g_voip_stream_info)))
+ goto ERROR_CASE_NO_DESTROY;
}
- mm_sound_free_device_list(device_list);
break;
}
g_cached_session_mode = mode;
- g_cached_voip_device_id = id;
+ g_cached_voip_device_id = -1;
+ g_cached_voip_device_id2 = -1;
+ if (proper_device)
+ mm_sound_get_device_id(proper_device, &g_cached_voip_device_id);
+ if (proper_device2)
+ mm_sound_get_device_id(proper_device2, &g_cached_voip_device_id2);
return ret;
ERROR_CASE:
/* destroy virtual stream handle */
_destroy_virtual_stream(g_voip_vstream_h);
g_voip_vstream_h = NULL;
- ret = MM_ERROR_SOUND_INTERNAL;
}
if (g_voip_stream_info) {
/* destroy stream info */
SM_SAFE_FREE(g_voip_stream_info);
}
ERROR_CASE_NO_DESTROY:
+ if (device_list)
+ mm_sound_free_device_list(device_list);
+ ret = MM_ERROR_SOUND_INTERNAL;
return ret;
}
if (!added_successfully)
ret = MM_ERROR_POLICY_INTERNAL;
+ LOGI("*** add device(type[%s],id[%d]), ret(0x%x)", device_type_str, device_id, ret);
+
return ret;
}
if (!removed_successfully)
ret = MM_ERROR_INVALID_ARGUMENT;
+ LOGI("*** remove device(type[%s],id[%d]), ret(0x%x)", device_type_str, device_id, ret);
+
return ret;
}