Add new API for getting the sound type of the stream info handle 75/50875/1
authorSangchul Lee <sc11.lee@samsung.com>
Tue, 3 Nov 2015 07:04:30 +0000 (16:04 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Tue, 3 Nov 2015 07:05:50 +0000 (16:05 +0900)
[Version] Release 0.3.23
[profile] Common
[Issue Type] New API

Change-Id: I826879d8725a54bcd6d06c52c334c977563aeb1d
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
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 73f33e9238c265eab8c52fee17044e19004e093a..fb0a110bb37635e6f79b3a52bee9d251d31fe583 100644 (file)
@@ -685,6 +685,25 @@ int sound_manager_release_focus(sound_stream_info_h stream_info, sound_stream_fo
  */
 int sound_manager_get_focus_state(sound_stream_info_h stream_info, sound_stream_focus_state_e *state_for_playback, sound_stream_focus_state_e *state_for_recording);
 
+/**
+ * @brief Gets the sound type of the stream information.
+ * @since_tizen 3.0
+ * @param[in]  stream_info     The handle of stream information
+ * @param[out] sound_type      The sound type
+  *
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #SOUND_MANAGER_ERROR_NONE Success
+ * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre Call sound_manager_create_stream_information() before calling this function.
+ * @see sound_manager_create_stream_information()
+ * @see sound_manager_destroy_stream_information()
+ * @see sound_manager_set_volume()
+ * @see sound_manager_get_max_volume()
+ * @see sound_manager_get_volume()
+ */
+int sound_manager_get_sound_type(sound_stream_info_h stream_info, sound_type_e *sound_type);
+
 /**
  * @brief Registers the watch callback function to be invoked when the focus state for each sound stream type is changed regardless of the process.
  * @since_tizen 3.0
index 104bac8eac865f3f8ed3319c0b37537ab2b7d665..f17d48fa398773a899502bc6ae066cf992ef3c65 100644 (file)
@@ -135,6 +135,7 @@ typedef enum stream_route_type {
 typedef struct _stream_conf_info_s {
        int priority;
        int route_type;
+       const gchar *volume_type;
        gchar *avail_in_devices[AVAIL_DEVICES_MAX];
        gchar *avail_out_devices[AVAIL_DEVICES_MAX];
        gchar *avail_frameworks[AVAIL_FRAMEWORKS_MAX];
@@ -244,7 +245,7 @@ int _set_route_option(unsigned int index, const char *key, int value);
 
 int _convert_sound_type(sound_type_e sound_type, const char **volume_type);
 
-int _convert_sound_type_to_enum(char *sound_type, sound_type_e *sound_type_enum);
+int _convert_sound_type_to_enum(const char *sound_type, sound_type_e *sound_type_enum);
 
 int _get_volume_max_level(const char *direction, const char *volume_type, unsigned int *max_level);
 
index 87fc84c0e428296d66d0e7cb25c1e37505f4a803..eacef379eb76434e0be25513fad6bd698dd1aaea 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-media-sound-manager
 Summary:    Sound Manager library
-Version:    0.3.22
+Version:    0.3.23
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index e4b4bcfd1464fe969d95393c47682dc180bbb7e4..6d69a96b07857abb9b984e1a3d255b04e784f9f0 100644 (file)
@@ -116,10 +116,8 @@ int sound_manager_get_current_sound_type(sound_type_e *type)
                if (mm_sound_vol_type == VOLUME_TYPE_UNKNOWN) {
                        /* get the volume type of the current playing stream */
                        ret = _get_current_volume_type("out", &volume_type);
-                       if (ret == MM_ERROR_NONE) {
-                               ret = _convert_sound_type_to_enum(volume_type, type);
-                               free(volume_type);
-                       }
+                       if (ret == MM_ERROR_NONE)
+                               ret = _convert_sound_type_to_enum((const char*)volume_type, type);
                } else {
                        *type = mm_sound_vol_type;
                }
@@ -338,6 +336,23 @@ int sound_manager_get_focus_state(sound_stream_info_h stream_info, sound_stream_
        return _convert_sound_manager_error_code(__func__, ret);
 }
 
+int sound_manager_get_sound_type(sound_stream_info_h stream_info, sound_type_e *sound_type)
+{
+       int ret = MM_ERROR_NONE;
+       sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
+
+       LOGI(">> enter");
+
+       SM_INSTANCE_CHECK(stream_h);
+       SM_NULL_ARG_CHECK(sound_type);
+
+       ret = _convert_sound_type_to_enum(stream_h->stream_conf_info.volume_type, sound_type);
+
+       LOGI("<< leave : sound type(%d)", *sound_type);
+
+       return _convert_sound_manager_error_code(__func__, ret);
+}
+
 int sound_manager_set_focus_state_watch_cb(sound_stream_focus_mask_e focus_mask, sound_stream_focus_state_watch_cb callback, void *user_data)
 {
        int ret = MM_ERROR_NONE;
index 84d593ad485fc35027704b6b1b94422f077f15a8..a6350b3232051f16f669fbc625cce98b38ed3d34 100644 (file)
@@ -308,7 +308,7 @@ int _convert_sound_type(sound_type_e sound_type, const char **volume_type)
        return ret;
 }
 
-int _convert_sound_type_to_enum(char *sound_type, sound_type_e *sound_type_enum)
+int _convert_sound_type_to_enum(const char *sound_type, sound_type_e *sound_type_enum)
 {
        int ret = MM_ERROR_NONE;
 
@@ -535,7 +535,7 @@ int _get_stream_conf_info(const char *stream_type, stream_conf_info_s *info)
                                                        PA_STREAM_MANAGER_INTERFACE,
                                                        PA_STREAM_MANAGER_METHOD_NAME_GET_STREAM_INFO,
                                                        g_variant_new("(s)", stream_type),
-                                                       G_VARIANT_TYPE("(vvvvv)"),
+                                                       G_VARIANT_TYPE("(vvvvvv)"),
                                                        G_DBUS_CALL_FLAGS_NONE,
                                                        2000,
                                                        NULL,
@@ -567,9 +567,29 @@ int _get_stream_conf_info(const char *stream_type, stream_conf_info_s *info)
                g_variant_unref(child);
                LOGI("route_type(%d)", info->route_type);
 
-               /* get availabe in-devices */
+               /* get volume types */
                child = g_variant_get_child_value(result, 2);
                item = g_variant_get_variant(child);
+               g_variant_iter_init(&iter, item);
+               while (g_variant_iter_loop(&iter, "&s", &name)) {
+                       if (!strncmp(name, "none", strlen("none"))) {
+                               /* skip it */
+                       } else {
+                               /* we use volume type only for out direction */
+                               if (name) {
+                                       LOGI(" volume-type : %s", name);
+                                       info->volume_type = strdup(name);
+                                       break;
+                               }
+                       }
+               }
+               g_variant_iter_free(&iter);
+               g_variant_unref(item);
+               g_variant_unref(child);
+
+               /* get availabe in-devices */
+               child = g_variant_get_child_value(result, 3);
+               item = g_variant_get_variant(child);
                size = g_variant_n_children(item);
                LOGI("num of avail-in-devices are %d", size);
                g_variant_iter_init(&iter, item);
@@ -588,7 +608,7 @@ int _get_stream_conf_info(const char *stream_type, stream_conf_info_s *info)
                g_variant_unref(child);
 
                /* get available out-devices */
-               child = g_variant_get_child_value(result, 3);
+               child = g_variant_get_child_value(result, 4);
                item = g_variant_get_variant(child);
                size = g_variant_n_children(item);
                LOGI("num of avail-out-devices are %d", size);
@@ -608,7 +628,7 @@ int _get_stream_conf_info(const char *stream_type, stream_conf_info_s *info)
                g_variant_unref(child);
 
                /* get available frameworks */
-               child = g_variant_get_child_value(result, 4);
+               child = g_variant_get_child_value(result, 5);
                item = g_variant_get_variant(child);
                size = g_variant_n_children(item);
                LOGI("num of avail-frameworks are %d", size);
index 336aa5c6a9afddef62b664e3ac7c7b0cfecdb8f7..69db7d5216f415913b2e51193669728701f05624 100644 (file)
@@ -64,6 +64,7 @@ enum {
        CURRENT_STATUS_ACQUIRE_FOCUS,
        CURRENT_STATUS_RELEASE_FOCUS,
        CURRENT_STATUS_GET_ACQUIRED_FOCUS,
+       CURRENT_STATUS_GET_SOUND_TYPE,
        CURRENT_STATUS_DESTROY_STREAM_INFO,
        CURRENT_STATUS_SET_FOCUS_WATCH_CB,
        CURRENT_STATUS_UNSET_FOCUS_WATCH_CB,
@@ -194,6 +195,8 @@ void _interpret_main_menu(char *cmd)
                g_menu_state = CURRENT_STATUS_RELEASE_FOCUS;
        else if (strncmp(cmd, "gfs", 3) == 0)
                g_menu_state = CURRENT_STATUS_GET_ACQUIRED_FOCUS;
+       else if (strncmp(cmd, "gst", 3) == 0)
+               g_menu_state = CURRENT_STATUS_GET_SOUND_TYPE;
        else if (strncmp(cmd, "sfw", 3) == 0)
                g_menu_state = CURRENT_STATUS_SET_FOCUS_WATCH_CB;
        else if (strncmp(cmd, "ufw", 3) == 0)
@@ -261,6 +264,7 @@ void display_sub_basic()
        g_print("-----------------------------------------------------------------------------------------\n");
        g_print("csi. Create Stream Info\t");
        g_print("dsi. Destroy Stream Info\n");
+       g_print("gst. Get Sound Type\n");
        g_print("ads. Add device for stream routing\t");
        g_print("rds. Remove device for stream routing\t");
        g_print("aps. Apply devices for stream routing\n");
@@ -362,6 +366,8 @@ static void displaymenu()
                g_print("*** input focus type to release (0:playback, 1:recording, 2:both)\n");
        else if (g_menu_state == CURRENT_STATUS_GET_ACQUIRED_FOCUS)
                g_print("*** press enter to get focus state\n");
+       else if (g_menu_state == CURRENT_STATUS_GET_SOUND_TYPE)
+               g_print("*** press enter to get sound type\n");
        else if (g_menu_state == CURRENT_STATUS_DESTROY_STREAM_INFO)
                g_print("*** press enter to destroy stream information\n");
        else if (g_menu_state == CURRENT_STATUS_SET_FOCUS_WATCH_CB)
@@ -1195,6 +1201,22 @@ static void interpret(char *cmd)
                reset_menu_state();
                break;
        }
+       case CURRENT_STATUS_GET_SOUND_TYPE: {
+               int ret = SOUND_MANAGER_ERROR_NONE;
+               sound_type_e sound_type;
+               if (g_stream_info_h) {
+                       ret = sound_manager_get_sound_type(g_stream_info_h, &sound_type);
+                       if (ret)
+                               g_print("fail to sound_manager_get_sound_type(), ret(0x%x)\n", ret);
+                       else
+                               g_print("sound_type(%d)\n", sound_type);
+
+               } else
+                       g_print("please create stream info. first\n");
+
+               reset_menu_state();
+               break;
+       }
        case CURRENT_STATUS_DESTROY_STREAM_INFO: {
                int ret = SOUND_MANAGER_ERROR_NONE;
                ret = sound_manager_destroy_stream_information(g_stream_info_h);