MMSoundDevice_t tmp_device = NULL;
MMSoundDevice_t proper_device = NULL;
MMSoundDevice_t proper_device2 = NULL;
+ MMSoundDevice_t proper_device_builtin_mic = NULL;
MMSoundDevice_t prev_device = NULL;
MMSoundDevice_t prev_device2 = NULL;
mm_sound_device_type_e type;
return ret;
}
- switch (mode) {
- case _SESSION_MODE_RINGTONE:
+ if (mode == _SESSION_MODE_RINGTONE) {
if (g_voip_vstream_h) {
/* stop vstream and destroy vstream */
_stop_virtual_stream(g_voip_vstream_h);
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 */
+ } else {
+ /* _SESSION_MODE_VOICE_WITH_BUILTIN_RECEIVER: Built-in RCV and Built-in MIC
+ * _SESSION_MODE_VOICE_WITH_BUILTIN_SPEAKER : Built-in SPK and Built-in MIC
+ * _SESSION_MODE_VOICE_WITH_AUDIO_JACK : Earphone SPK & MIC(4P) or Earphone SPK & Built-in MIC(3P)
+ * _SESSION_MODE_VOICE_WITH_BLUETOOTH_SCO : Bluetooth SPK & MIC */
+
/* check if the device is available now */
if ((ret = mm_sound_get_device_list(MM_SOUND_DEVICE_ALL_FLAG, &device_list))) {
LOGE("failed to get current device list");
if ((ret = mm_sound_get_device_id(tmp_device, &id)))
goto ERROR_CASE;
- if (g_cached_voip_device_id == id)
+ if (g_cached_voip_device_id == id || g_cached_voip_device_id2 == 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)
+ if (type == MM_SOUND_DEVICE_TYPE_BUILTIN_RECEIVER || 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)
+ if (type == MM_SOUND_DEVICE_TYPE_BUILTIN_SPEAKER || 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);
+ if (type == MM_SOUND_DEVICE_TYPE_BUILTIN_MIC)
+ proper_device_builtin_mic = tmp_device;
+
+ if (type == MM_SOUND_DEVICE_TYPE_AUDIOJACK) {
+ mm_sound_device_io_direction_e direction;
+ if ((ret = mm_sound_get_device_io_direction(tmp_device, &direction)))
+ goto ERROR_CASE;
+ if (direction == MM_SOUND_DEVICE_IO_DIRECTION_BOTH) { /* 4P earpiece */
+ CHECK_AND_SET_DEVICE(proper_device, proper_device2, tmp_device);
+ } else if (direction == MM_SOUND_DEVICE_IO_DIRECTION_OUT) { /* 3P earpiece */
+ proper_device = proper_device_builtin_mic;
+ proper_device2 = tmp_device;
+ } else {
+ LOGE("invalid direction[%d] for audiojack device", direction);
+ goto ERROR_CASE;
+ }
+ }
break;
case _SESSION_MODE_VOICE_WITH_BLUETOOTH_SCO:
if (type == MM_SOUND_DEVICE_TYPE_BLUETOOTH_SCO)
if ((ret = _apply_stream_routing(g_voip_stream_info)))
goto ERROR_CASE_NO_DESTROY;
}
- break;
}
g_cached_session_mode = mode;
g_cached_voip_device_id = -1;