From: Mok Jeongho Date: Thu, 1 Sep 2016 10:34:24 +0000 (+0900) Subject: Add new API to get avail-mode(media/voice) of Bluetooth devices X-Git-Tag: submit/tizen/20160928.043825~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d81f3c18917dabeb7331138fa0026f7c912c33d5;p=platform%2Fcore%2Fapi%2Fsound-manager.git Add new API to get avail-mode(media/voice) of Bluetooth devices [Version] 0.3.69 [Profile] Common [Issue Type] API Change-Id: Ib5710cf070e04deb04ab69234928adf40f7c7b85 --- diff --git a/include/sound_manager.h b/include/sound_manager.h index 42fc09b..329645e 100644 --- a/include/sound_manager.h +++ b/include/sound_manager.h @@ -294,6 +294,19 @@ typedef enum { SOUND_DEVICE_STATE_ACTIVATED, /**< Activated state */ } sound_device_state_e; +/** + * @brief Enumeration for Bluetooth sound device modes. + * @since_tizen 3.0 + * + * @remarks This enumeration is only for Bluetooth devices.\n + * These values can be combined with bitwise 'or'. + */ + +typedef enum { + SOUND_DEVICE_BLUETOOTH_MODE_MEDIA = 0x01, /**< Media mode (for music, system, and so on) */ + SOUND_DEVICE_BLUETOOTH_MODE_VOICE = 0x02, /**< Voice mode (for call, voip, voice-recognition, and so on) */ +} sound_device_bluetooth_mode_e; + /** * @brief Enumeration for sound device mask. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif @@ -314,8 +327,9 @@ typedef enum { * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ typedef enum { - SOUND_DEVICE_CHANGED_INFO_STATE, /**< State of the device was changed */ - SOUND_DEVICE_CHANGED_INFO_IO_DIRECTION, /**< IO direction of the device was changed */ + SOUND_DEVICE_CHANGED_INFO_STATE, /**< State of the device was changed */ + SOUND_DEVICE_CHANGED_INFO_IO_DIRECTION, /**< IO direction of the device was changed */ + SOUND_DEVICE_CHANGED_INFO_BT_AVAIL_MODES /**< Available modes of a Bluetooth device were changed (Since 3.0) */ } sound_device_changed_info_e; /** @@ -1379,6 +1393,29 @@ int sound_manager_get_device_name(sound_device_h device, char **name); */ int sound_manager_get_device_state(sound_device_h device, sound_device_state_e *state); +/** + * @brief Gets the available modes of a Bluetooth device. + * @since_tizen 3.0 + * + * @remarks This function is only for Bluetooth devices. + * + * @param[in] device The device of #SOUND_DEVICE_BLUETOOTH type + * @param[out] modes The available modes of the Bluetooth device, values of #sound_device_bluetooth_mode_e combined with bitwise 'or' + * @return @c 0 on success, + * otherwise a negative error value + * @retval #SOUND_MANAGER_ERROR_NONE Success + * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @see sound_manager_get_current_device_list() + * @see sound_manager_get_next_device() + * @see sound_manager_get_prev_device() + * @see sound_manager_get_device_type() + * @see sound_manager_get_device_io_direction() + * @see sound_manager_get_device_id() + * @see sound_manager_get_device_name() + * @see sound_manager_free_device_list() + */ +int sound_manager_get_bt_device_avail_modes(sound_device_h device, int *modes); + /** * @brief Registers a callback function to be invoked when the state of connection of a sound device was changed. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif diff --git a/include/sound_manager_private.h b/include/sound_manager_private.h index 45f7c90..3951f80 100644 --- a/include/sound_manager_private.h +++ b/include/sound_manager_private.h @@ -244,6 +244,8 @@ int _convert_device_type(sound_device_type_e device_type_enum, char **device_typ int _convert_device_io_direction(mm_sound_device_io_direction_e io_direction, sound_device_io_direction_e *sound_io_direction); +int _convert_avail_mode(int avail_mode); + const char* _convert_api_name(native_api_e api_name); int _get_stream_conf_info(const char *stream_type, stream_conf_info_s *info); diff --git a/packaging/capi-media-sound-manager.spec b/packaging/capi-media-sound-manager.spec index ccef4c3..eb8bfe2 100755 --- a/packaging/capi-media-sound-manager.spec +++ b/packaging/capi-media-sound-manager.spec @@ -1,6 +1,6 @@ Name: capi-media-sound-manager Summary: Sound Manager library -Version: 0.3.68 +Version: 0.3.69 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/sound_manager.c b/src/sound_manager.c index 4cc48b1..37e8efc 100644 --- a/src/sound_manager.c +++ b/src/sound_manager.c @@ -1197,6 +1197,40 @@ int sound_manager_get_device_state(sound_device_h device, sound_device_state_e * return _convert_sound_manager_error_code(__func__, ret); } +int sound_manager_get_bt_device_avail_modes(sound_device_h device, int *modes) +{ + int ret = MM_ERROR_NONE; + int mm_avail_mode; + int _avail_mode; + sound_device_type_e device_type; + + if (!device || !modes) + return _convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT); + + ret = mm_sound_get_device_type(device, (mm_sound_device_type_e*)&device_type); + if (ret != MM_ERROR_NONE) + goto LEAVE; + if (device_type != SOUND_DEVICE_BLUETOOTH) { + ret = MM_ERROR_INVALID_ARGUMENT; + goto LEAVE; + } + + ret = mm_sound_get_device_bt_avail_mode(device, &mm_avail_mode); + if (ret != MM_ERROR_NONE) + goto LEAVE; + + if ((_avail_mode = _convert_avail_mode(mm_avail_mode)) < 0) { + LOGE("Invalid avail mode %d", mm_avail_mode); + ret = MM_ERROR_SOUND_INTERNAL; + goto LEAVE; + } + + *modes = _avail_mode; + +LEAVE: + return _convert_sound_manager_error_code(__func__, ret); +} + int sound_manager_set_device_connected_cb(sound_device_mask_e device_mask, sound_device_connected_cb callback, void *user_data) { int ret = MM_ERROR_NONE; diff --git a/src/sound_manager_private.c b/src/sound_manager_private.c index a3e8704..87a07ae 100644 --- a/src/sound_manager_private.c +++ b/src/sound_manager_private.c @@ -423,6 +423,21 @@ int _convert_device_io_direction(mm_sound_device_io_direction_e io_direction, so return MM_ERROR_NONE; } +int _convert_avail_mode(int avail_mode) +{ + int _avail_mode = 0; + + if ((avail_mode < 0) || (avail_mode > (MM_SOUND_DEVICE_BT_MODE_MEDIA | MM_SOUND_DEVICE_BT_MODE_VOICE))) + return -1; + + if (avail_mode & MM_SOUND_DEVICE_BT_MODE_MEDIA) + _avail_mode |= SOUND_DEVICE_BLUETOOTH_MODE_MEDIA; + if (avail_mode & MM_SOUND_DEVICE_BT_MODE_VOICE) + _avail_mode |= SOUND_DEVICE_BLUETOOTH_MODE_VOICE; + + return _avail_mode; +} + const char* _convert_api_name(native_api_e api_name) { const char* name = NULL; diff --git a/test/sound_manager_test.c b/test/sound_manager_test.c index 700e692..69b46f2 100644 --- a/test/sound_manager_test.c +++ b/test/sound_manager_test.c @@ -19,12 +19,14 @@ #include #include +#include #include #include #include #include #define MAX_STRING_LEN 2048 +#define NOT_AVAIL "N/A"; enum { CURRENT_STATUS_MAINMENU, @@ -97,6 +99,14 @@ sound_device_mask_e g_device_mask = SOUND_DEVICE_ALL_MASK; sound_stream_info_h g_stream_info_h = NULL; virtual_sound_stream_h g_vstream_h = NULL; +static const char *g_device_direction_str[] = {"IN", "OUT", "BOTH"}; +static const char *g_device_state_str[] = {"De-Activated", "Activated"}; +static const char *g_device_avail_modes_str[] = { + [SOUND_DEVICE_BLUETOOTH_MODE_MEDIA] = "Media", + [SOUND_DEVICE_BLUETOOTH_MODE_VOICE] = "Voice", + [SOUND_DEVICE_BLUETOOTH_MODE_MEDIA | SOUND_DEVICE_BLUETOOTH_MODE_VOICE] = "Media & Voice" +}; + void focus_callback(sound_stream_info_h stream_info, sound_stream_focus_change_reason_e reason, const char *extra_info, void *user_data) { int ret = SOUND_MANAGER_ERROR_NONE; @@ -543,54 +553,86 @@ void _set_session_interrupted_cb(sound_session_interrupted_code_e code, void *us g_print("***your session has been interrupted by (%d)\n", code); } -void _set_device_connected_cb(sound_device_h device, bool is_connected, void *user_data) +/* If failed to get some property, just give some default value */ +void _get_device_props_simple(sound_device_h device, int *id, char **type, char **name, + const char **direc, const char **state, const char **avail_modes) { - sound_device_type_e type; - sound_device_io_direction_e io_direction; - sound_device_state_e state; - int id; - char *name; - int ret = SOUND_MANAGER_ERROR_NONE; + int ret; + sound_device_type_e _type; + sound_device_io_direction_e _direc; + sound_device_state_e _state; + int _avail_modes; + + if ((ret = sound_manager_get_device_type(device, &_type))) { + g_print("failed to get device type, ret[0x%x]\n", ret); + } else { + _convert_device_type(_type, type); + } + + if ((ret = sound_manager_get_device_id(device, id))) { + g_print("failed to get device id, ret[0x%x]\n", ret); + *id = -1; + } - g_print("***device connected callback is called, is_connected[%d]\n", is_connected); + if (_type == SOUND_DEVICE_BLUETOOTH || _type == SOUND_DEVICE_USB_AUDIO) { + if ((ret = sound_manager_get_device_name(device, name))) { + g_print("failed to get device name, ret[0x%x]\n", ret); + *name = NOT_AVAIL; + } + } else { + *name = ""; + } - if ((ret = sound_manager_get_device_type(device, &type))) - g_print("failed to get device type, ret[0x%x]\n", ret); - if ((ret = sound_manager_get_device_io_direction(device, &io_direction))) + if ((ret = sound_manager_get_device_io_direction(device, &_direc))) { g_print("failed to get device io direction, ret[0x%x]\n", ret); - if ((ret = sound_manager_get_device_id(device, &id))) - g_print("failed to get device id, ret[0x%x]\n", ret); - if ((ret = sound_manager_get_device_name(device, &name))) - g_print("failed to get device name, ret[0x%x]\n", ret); - if ((ret = sound_manager_get_device_state(device, &state))) + *direc = NOT_AVAIL; + } else { + *direc = g_device_direction_str[_direc]; + } + + if ((ret = sound_manager_get_device_state(device, &_state))) { g_print("failed to get device state, ret[0x%x]\n", ret); - if (!ret) - g_print(" -- device type[%d], io_direction[%d], id[%d], name[%s], state[%d]\n", type, io_direction, id, name, state); + *state = NOT_AVAIL; + } else { + *state = g_device_state_str[_state]; + } + + if (_type == SOUND_DEVICE_BLUETOOTH) { + if ((ret = sound_manager_get_bt_device_avail_modes(device, &_avail_modes))) { + g_print("failed to get device avail_mode, ret[0x%x]\n", ret); + *avail_modes = NOT_AVAIL; + } else { + *avail_modes = g_device_avail_modes_str[_avail_modes]; + } + } else { + *avail_modes = NOT_AVAIL; + } +} + +void _set_device_connected_cb(sound_device_h device, bool is_connected, void *user_data) +{ + int id = -1; + char *type, *name; + const char *direc, *state, *avail_modes; + + _get_device_props_simple(device, &id, &type, &name, &direc, &state, &avail_modes); + + g_print("[ Device #%d %s %s ] %s\n", id, type, name, is_connected ? "Connected" : "Disconnected"); + g_print(" Direc[ %-4s ] State[ %-12s ] Avail-Modes[ %s ]\n", direc, state, avail_modes); } void _set_device_info_changed_cb(sound_device_h device, sound_device_changed_info_e changed_info, void *user_data) { - sound_device_type_e type; - sound_device_io_direction_e io_direction; - sound_device_state_e state; - int id; - char *name; - int ret = SOUND_MANAGER_ERROR_NONE; - g_print("***device information changed callback is called, changed_info[%d](0:STATE 1:IO_DIRECTION)\n", changed_info); + int id = -1; + char *type, *name; + const char *direc, *state, *avail_modes; + const char *changed_info_str[] = {"State", "Direction", "Avail-Mode"}; - if ((ret = sound_manager_get_device_type(device, &type))) - g_print("failed to get device type, ret[0x%x]\n", ret); - if ((ret = sound_manager_get_device_io_direction(device, &io_direction))) - g_print("failed to get device io direction, ret[0x%x]\n", ret); - if ((ret = sound_manager_get_device_id(device, &id))) - g_print("failed to get device id, ret[0x%x]\n", ret); - if ((ret = sound_manager_get_device_name(device, &name))) - g_print("failed to get device name, ret[0x%x]\n", ret); - if ((ret = sound_manager_get_device_state(device, &state))) - g_print("failed to get device state, ret[0x%x]\n", ret); - if (!ret) - g_print(" -- device type[%d], io_direction[%d], id[%d], name[%s], state[%d]\n", type, io_direction, id, name, state); + _get_device_props_simple(device, &id, &type, &name, &direc, &state, &avail_modes); + + g_print("[Device #%d %s %s] %s changed\n", id, type, name, changed_info_str[changed_info]); + g_print(" Direc[ %-4s ] State[ %-12s ] Avail-Modes[ %s ]\n", direc, state, avail_modes); } void reset_menu_state(void)