Add new API to get avail-mode(media/voice) of Bluetooth devices 71/86571/17
authorMok Jeongho <jho.mok@samsung.com>
Thu, 1 Sep 2016 10:34:24 +0000 (19:34 +0900)
committerMok Jeongho <jho.mok@samsung.com>
Tue, 27 Sep 2016 06:30:50 +0000 (15:30 +0900)
[Version] 0.3.69
[Profile] Common
[Issue Type] API

Change-Id: Ib5710cf070e04deb04ab69234928adf40f7c7b85

include/sound_manager.h
include/sound_manager_private.h
packaging/capi-media-sound-manager.spec
src/sound_manager.c
src/sound_manager_private.c
test/sound_manager_test.c

index 42fc09befd6cef53afea4acd674ca00cb3a8f44b..329645edcfa877f15032a7fa3a25545b63ce972b 100644 (file)
@@ -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
index 45f7c90a2a90114c31277c834c29518aa0bece36..3951f801047d4b73f63f936d533dcd0c47ce92ce 100644 (file)
@@ -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);
index ccef4c3c6bc379843e67d034043fe161cbf7cd50..eb8bfe2f40a61598d6007c23a6fe43ae6d6ee40d 100755 (executable)
@@ -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
index 4cc48b1599dff92283b0ed847c2ca6905d789579..37e8efc7d61262538698495e1f68eff7fdb19c24 100644 (file)
@@ -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;
index a3e87047e2b5fbba5675712692fbfe98a6fa9efe..87a07ae119d14c7ab82c9c93e7af8d13731fcd77 100644 (file)
@@ -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;
index 700e69273c1898048a4e007bc07e85bfc100b5a6..69b46f222950c651eb0a4b26f85ae366e37d803c 100644 (file)
 #include <stdlib.h>
 
 #include <sound_manager.h>
+#include <sound_manager_private.h>
 #include <sound_manager_internal.h>
 #include <mm_sound.h>
 #include <pthread.h>
 #include <glib.h>
 
 #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)