Add BT avail mode check logic 27/95827/2
authorWootak Jung <wootak.jung@samsung.com>
Mon, 7 Nov 2016 01:36:46 +0000 (10:36 +0900)
committerWootak Jung <wootak.jung@samsung.com>
Mon, 7 Nov 2016 04:09:34 +0000 (13:09 +0900)
- To use bt voice, need to check bt avail mode

Change-Id: I4c2eb8272090cd9ed4f8dd94f9547e12eeae3929

module/src/callmgr-audio.c
packaging/call-manager.spec
service/src/callmgr-core.c

index c5651a4..45244a5 100644 (file)
@@ -100,28 +100,76 @@ static void __callmgr_audio_available_route_changed_cb(sound_device_h device, bo
        sound_device_type_e device_type = SOUND_DEVICE_BUILTIN_RECEIVER;
 
        sound_manager_get_device_type(device, &device_type);
+       info("Device connected cb invoked!! [%s] is [%s]",
+               __callmgr_audio_convert_device_type_to_string(device_type),
+               is_connected ? "Connected" : "Disconnected");
+
+       /* Set current device list */
        if (device_type == SOUND_DEVICE_AUDIO_JACK) {
                if (is_connected)
                        audio_handle->current_device_list |= CALLMGR_AUDIO_DEVICE_EARJACK_E;
-               else
+               else if (audio_handle->current_device_list & CALLMGR_AUDIO_DEVICE_EARJACK_E)
                        audio_handle->current_device_list -= CALLMGR_AUDIO_DEVICE_EARJACK_E;
        } else if (device_type == SOUND_DEVICE_BLUETOOTH) {
-               if (is_connected)
-                       audio_handle->current_device_list |= CALLMGR_AUDIO_DEVICE_BT_E;
-               else
-                       audio_handle->current_device_list -= CALLMGR_AUDIO_DEVICE_BT_E;
+               if (is_connected) {
+                       int modes;
+                       sound_manager_get_bt_device_avail_modes(device, &modes);
+                       if (modes & SOUND_DEVICE_BLUETOOTH_MODE_VOICE) {
+                               dbg("BT device is connected and BT Voice is enabled.");
+                               audio_handle->current_device_list |= CALLMGR_AUDIO_DEVICE_BT_E;
+                       } else {
+                               dbg("BT device is connected. But, BT Voice is disabled.");
+                               is_connected = FALSE;
+                       }
+               } else {
+                       if (audio_handle->current_device_list & CALLMGR_AUDIO_DEVICE_BT_E)
+                               audio_handle->current_device_list -= CALLMGR_AUDIO_DEVICE_BT_E;
+               }
        }
 
-       info("[%s] is [%s], current device list [0x%x]",
-               __callmgr_audio_convert_device_type_to_string(device_type),
-               is_connected ? "Connected" : "Disconnected", audio_handle->current_device_list);
-
+       /* Invoke device changed cb */
        if (device_type == SOUND_DEVICE_AUDIO_JACK)
                audio_handle->cb_fn(CM_AUDIO_EVENT_EARJACK_CHANGED_E, (void *)is_connected, audio_handle->user_data);
        else if (device_type == SOUND_DEVICE_BLUETOOTH)
                audio_handle->cb_fn(CM_AUDIO_EVENT_BT_CHANGED_E, (void *)is_connected, audio_handle->user_data);
 }
 
+static void __callmgr_audio_device_information_changed_cb(sound_device_h device, sound_device_changed_info_e changed_info, void *user_data)
+{
+       CM_RETURN_IF_FAIL(user_data);
+       CM_RETURN_IF_FAIL(device);
+       callmgr_audio_handle_h audio_handle = (callmgr_audio_handle_h)user_data;
+       sound_device_type_e device_type = SOUND_DEVICE_BUILTIN_RECEIVER;
+       int ret = SOUND_MANAGER_ERROR_NONE;
+
+       ret = sound_manager_get_device_type(device, &device_type);
+       if (ret != SOUND_MANAGER_ERROR_NONE) {
+               err("sound_manager_get_device_type() get failed with err[0x%x][%s]", ret, get_error_message(ret));
+               return;
+       }
+
+       if (device_type == SOUND_DEVICE_BLUETOOTH) {
+               int modes;
+               bool is_connected;
+               sound_manager_get_bt_device_avail_modes(device, &modes);
+
+               /* Set current device list */
+               if (modes & SOUND_DEVICE_BLUETOOTH_MODE_VOICE) {
+                       dbg("BT Voice is enabled");
+                       audio_handle->current_device_list |= CALLMGR_AUDIO_DEVICE_BT_E;
+                       is_connected = TRUE;
+               } else {
+                       dbg("BT Voice is disabled");
+                       if (audio_handle->current_device_list & CALLMGR_AUDIO_DEVICE_BT_E)
+                               audio_handle->current_device_list -= CALLMGR_AUDIO_DEVICE_BT_E;
+                       is_connected = FALSE;
+               }
+
+               /* Invoke device changed cb */
+               audio_handle->cb_fn(CM_AUDIO_EVENT_BT_CHANGED_E, (void *)is_connected, audio_handle->user_data);
+       }
+}
+
 int _callmgr_audio_init(callmgr_audio_handle_h *audio_handle, audio_event_cb cb_fn, void *user_data)
 {
        struct __audio_data *handle = NULL;
@@ -161,10 +209,18 @@ int _callmgr_audio_init(callmgr_audio_handle_h *audio_handle, audio_event_cb cb_
        /* Set current device list */
        while (sound_manager_get_next_device(device_list, &device) == SOUND_MANAGER_ERROR_NONE) {
                sound_manager_get_device_type(device, &device_type);
-               if (device_type == SOUND_DEVICE_AUDIO_JACK)
+               if (device_type == SOUND_DEVICE_AUDIO_JACK) {
                        handle->current_device_list |= CALLMGR_AUDIO_DEVICE_EARJACK_E;
-               else if (device_type == SOUND_DEVICE_BLUETOOTH)
-                       handle->current_device_list |= CALLMGR_AUDIO_DEVICE_BT_E;
+               } else if (device_type == SOUND_DEVICE_BLUETOOTH) {
+                       int modes;
+                       sound_manager_get_bt_device_avail_modes(device, &modes);
+                       if (modes & SOUND_DEVICE_BLUETOOTH_MODE_VOICE) {
+                               dbg("BT device is connected and BT Voice is enabled.");
+                               handle->current_device_list |= CALLMGR_AUDIO_DEVICE_BT_E;
+                       } else {
+                               dbg("BT device is connected. But, BT Voice is disabled.");
+                       }
+               }
        }
        dbg("Current device list [0x%x]", handle->current_device_list);
 
@@ -175,6 +231,13 @@ int _callmgr_audio_init(callmgr_audio_handle_h *audio_handle, audio_event_cb cb_
                return -1;
        }
 
+       /* Set device information changed cb */
+       ret = sound_manager_set_device_information_changed_cb(SOUND_DEVICE_ALL_MASK, __callmgr_audio_device_information_changed_cb, handle);
+       if (ret != SOUND_MANAGER_ERROR_NONE) {
+               err("sound_manager_set_device_information_changed_cb() failed. [%d][%s]", ret, get_error_message(ret));
+               return -1;
+       }
+
        dbg("Audio init done");
        return 0;
 }
@@ -186,71 +249,13 @@ int _callmgr_audio_deinit(callmgr_audio_handle_h audio_handle)
        /* TODO: Release all handles */
 
        sound_manager_unset_device_connected_cb();
+       sound_manager_unset_device_information_changed_cb();
        _callmgr_audio_destroy_call_sound_session(audio_handle);
        g_free(audio_handle);
 
        return 0;
 }
 
-static void __callmgr_audio_active_device_changed_cb(sound_device_h device, sound_device_changed_info_e changed_info, void *user_data)
-{
-       CM_RETURN_IF_FAIL(user_data);
-       CM_RETURN_IF_FAIL(device);
-       callmgr_audio_handle_h audio_handle = (callmgr_audio_handle_h)user_data;
-       sound_device_io_direction_e io_direction = SOUND_DEVICE_IO_DIRECTION_BOTH;
-       sound_device_type_e device_type = SOUND_DEVICE_BUILTIN_RECEIVER;
-       sound_device_state_e state = SOUND_DEVICE_STATE_DEACTIVATED;
-       callmgr_audio_device_e cm_device = CALLMGR_AUDIO_DEVICE_NONE_E;
-       int ret = SOUND_MANAGER_ERROR_NONE;
-
-       ret = sound_manager_get_device_io_direction(device, &io_direction);
-       if (ret != SOUND_MANAGER_ERROR_NONE)
-               err("sound_manager_get_device_io_direction() get failed with err[0x%x]", ret);
-
-       ret = sound_manager_get_device_state(device, &state);
-       if (ret != SOUND_MANAGER_ERROR_NONE)
-               err("sound_manager_get_device_state() get failed with err[0x%x]", ret);
-
-       ret = sound_manager_get_device_type(device, &device_type);
-       if (ret != SOUND_MANAGER_ERROR_NONE)
-               err("sound_manager_get_device_type() get failed with err[0x%x]", ret);
-
-       info("Active device[%s], IO direction[%s], State[%s]",
-               __callmgr_audio_convert_device_type_to_string(device_type),
-               __callmgr_audio_convert_io_direction_to_string(io_direction),
-               __callmgr_audio_convert_device_state_to_string(state));
-
-       if ((io_direction == SOUND_DEVICE_IO_DIRECTION_IN) || (state == SOUND_DEVICE_STATE_DEACTIVATED)) {
-               info("No need to inform callmgr-core of this change");
-               return;
-       }
-
-       switch (device_type) {
-       case SOUND_DEVICE_BUILTIN_SPEAKER:
-               cm_device = CALLMGR_AUDIO_DEVICE_SPEAKER_E;
-               break;
-       case SOUND_DEVICE_BUILTIN_RECEIVER:
-               cm_device = CALLMGR_AUDIO_DEVICE_RECEIVER_E;
-               break;
-       case SOUND_DEVICE_AUDIO_JACK:
-               cm_device = CALLMGR_AUDIO_DEVICE_EARJACK_E;
-               break;
-       case SOUND_DEVICE_BLUETOOTH:
-               cm_device = CALLMGR_AUDIO_DEVICE_BT_E;
-               break;
-       default:
-               warn("Not available : %d", device_type);
-               break;
-       }
-
-       if ((cm_device == audio_handle->current_device) || cm_device == CALLMGR_AUDIO_DEVICE_NONE_E) {
-               warn("Do not update");
-       } else {
-               //audio_handle->current_device = cm_device;
-               //audio_handle->cb_fn(CM_AUDIO_EVENT_PATH_CHANGED_E, (void*)cm_device, audio_handle->user_data);
-       }
-}
-
 static void __callmgr_audio_call_stream_focus_state_cb(sound_stream_info_h stream_info,
        sound_stream_focus_change_reason_e reason_for_change, const char *additional_info, void *user_data)
 {
@@ -316,13 +321,6 @@ int _callmgr_audio_create_call_sound_session(callmgr_audio_handle_h audio_handle
                return -1;
        }
 
-       /* Path is changed by other modules */
-       ret = sound_manager_set_device_information_changed_cb(SOUND_DEVICE_ALL_MASK, __callmgr_audio_active_device_changed_cb, audio_handle);
-       if (ret != SOUND_MANAGER_ERROR_NONE) {
-               err("sound_manager_set_device_information_changed_cb() failed. [%d]", ret);
-               return -1;
-       }
-
        return 0;
 }
 
@@ -352,7 +350,6 @@ int _callmgr_audio_destroy_call_sound_session(callmgr_audio_handle_h audio_handl
        CM_RETURN_VAL_IF_FAIL(audio_handle->sound_stream_handle, -1);
 
        sound_manager_unset_volume_changed_cb();
-       sound_manager_unset_device_information_changed_cb();
 
        ret = sound_manager_release_focus(audio_handle->sound_stream_handle, SOUND_STREAM_FOCUS_FOR_PLAYBACK|SOUND_STREAM_FOCUS_FOR_RECORDING, NULL);
        if (ret != SOUND_MANAGER_ERROR_NONE) {
index cb6cc2c..8457763 100755 (executable)
@@ -1,6 +1,6 @@
 %define major 0
 %define minor 1
-%define patchlevel 78
+%define patchlevel 79
 %define ext_feature 0
 
 Name:           call-manager
index 9027f33..e1864cc 100644 (file)
@@ -2837,9 +2837,15 @@ int _callmgr_core_process_bluetooth_on(callmgr_core_data_t *core_data)
        dbg(">>");
        CM_RETURN_VAL_IF_FAIL(core_data, -1);
        int ret = -1;
-       ret = _callmgr_audio_set_audio_route(core_data->audio_handle, CALLMGR_AUDIO_ROUTE_BT_E);
-       if (ret < 0) {
-               err("_callmgr_audio_set_audio_route() get failed");
+       gboolean is_bt_connected = FALSE;
+
+       _callmgr_audio_is_sound_device_available(core_data->audio_handle, CALLMGR_AUDIO_DEVICE_BT_E, &is_bt_connected);
+       if (is_bt_connected) {
+               ret = _callmgr_audio_set_audio_route(core_data->audio_handle, CALLMGR_AUDIO_ROUTE_BT_E);
+               if (ret < 0)
+                       err("_callmgr_audio_set_audio_route() get failed");
+       } else {
+               err("BT device is not available");
        }
 
        return ret;