Modify internal API for setting routing option 72/43872/2 accepted/tizen/mobile/20150717.002853 accepted/tizen/tv/20150717.002908 accepted/tizen/wearable/20150717.002922 submit/tizen/20150715.092047 submit/tizen/20150716.043920
authorSangchul Lee <sc11.lee@samsung.com>
Wed, 15 Jul 2015 01:02:02 +0000 (10:02 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Wed, 15 Jul 2015 02:38:35 +0000 (11:38 +0900)
[Version] Release 0.3.13
[profile] Common
[Issue Type] Revise API

Change-Id: I69ef98f5e3d42ff1ec185018fd118722704a858f

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

index a1725aac4ededf36a7574c92df60a3dc5030a0eb..8582078c997c6da355e2c10bffa5aae490bb4c01 100644 (file)
@@ -96,52 +96,11 @@ int sound_manager_create_stream_information_internal (sound_stream_type_internal
 
 /**
  * @internal
- * @brief Adds the option to the stream information for the stream routing.
- * @since_tizen 3.0
- * @param[in]  stream_info     The handle of stream information
- * @param[in]  option          The option for the stream routing
- *
- * @return @c 0 on success,
- *         otherwise a negative error value
- * @retval #SOUND_MANAGER_ERROR_NONE Success
- * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
- * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
- * @pre Call sound_manager_create_stream_information() or sound_manager_create_stream_information_internal() before calling this function.
- * @post You can apply this setting by calling sound_manager_apply_stream_routing_options().
- * @see sound_manager_create_stream_information()
- * @see sound_manager_create_stream_information_internal()
- * @see sound_manager_destroy_stream_information()
- * @see sound_manager_remove_option_for_stream_routing()
- * @see sound_manager_apply_stream_routing_options()
- */
-int sound_manager_add_option_for_stream_routing (sound_stream_info_h stream_info, const char *option);
-
-/**
- * @internal
- * @brief Removes the option to the stream information for the stream routing.
- * @since_tizen 3.0
- * @param[in]  stream_info     The handle of stream information
- * @param[in]  option          The option for the stream routing
- *
- * @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()/sound_manager_add_option_for_stream_routing() before calling this function.
- * @post You can apply this setting by calling sound_manager_apply_stream_routing_options().
- * @see sound_manager_create_stream_information()
- * @see sound_manager_create_stream_information_internal()
- * @see sound_manager_destroy_stream_information()
- * @see sound_manager_remove_option_for_stream_routing()
- * @see sound_manager_apply_stream_routing_options()
- */
-int sound_manager_remove_option_for_stream_routing (sound_stream_info_h stream_info, const char *option);
-
-/**
- * @internal
- * @brief Applies the stream routing options.
+ * @brief Sets the stream routing option.
  * @since_tizen 3.0
  * @param[in]  stream_info     The handle of stream information
+ * @param[in]  name    The name of option
+ * @param[in]  value   The value of option
  *
  * @remarks    @a If the stream has not been made yet, this setting will be applied when the stream starts to play.\n
  *
@@ -149,15 +108,14 @@ int sound_manager_remove_option_for_stream_routing (sound_stream_info_h stream_i
  *         otherwise a negative error value
  * @retval #SOUND_MANAGER_ERROR_NONE Success
  * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @retval #SOUND_MANAGER_ERROR_INVALID_STATE Invalid state
  * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
- * @pre Call sound_manager_create_stream_information()/sound_manager_add_option_for_stream_routing() before calling this function.
+ * @pre Call sound_manager_create_stream_information() before calling this function.
  * @see sound_manager_create_stream_information()
  * @see sound_manager_create_stream_information_internal()
  * @see sound_manager_destroy_stream_information()
- * @see sound_manager_add_option_for_stream_routing()
- * @see sound_manager_remove_option_for_stream_routing()
  */
-int sound_manager_apply_stream_routing_options (sound_stream_info_h stream_info);
+int sound_manager_set_stream_routing_option (sound_stream_info_h stream_info, const char *name, int value);
 
 /**
  * @internal
index b6148b2d30f0a5538ebecea82fc40950dc7ec000..756860ebe54b3468bdbc3e355df091c5c934a596 100644 (file)
@@ -136,7 +136,6 @@ typedef enum stream_route_type {
 } stream_route_type;
 #define AVAIL_DEVICES_MAX 16
 #define AVAIL_FRAMEWORKS_MAX 16
-#define ROUTE_OPTIONS_MAX 16
 
 typedef struct _stream_conf_info_s {
        int priority;
@@ -161,7 +160,6 @@ typedef struct _sound_stream_info_s {
        sound_stream_focus_state_changed_cb user_cb;
        void *user_data;
        manual_route_info_s manual_route_info;
-       char *route_options[ROUTE_OPTIONS_MAX];
 } sound_stream_info_s;
 sound_stream_info_s *sound_stream_info_arr[SOUND_STREAM_INFO_ARR_MAX];
 
@@ -239,7 +237,7 @@ int __get_stream_conf_info (const char *stream_type, stream_conf_info_s *info);
 
 int __set_manual_route_info (unsigned int index, manual_route_info_s *info);
 
-int __set_route_options (unsigned int index, char **route_options);
+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);
 
index 31cb6e10d50921698e03ca163bc3713d7ef62af9..b1ebace86e18dd3bf4c6f962589447870dc8ad7c 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       capi-media-sound-manager
 Summary:    Sound Manager library
-Version:    0.3.12
+Version:    0.3.13
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index d058f9fff669d3afc3c619b8632420f3417c8109..be80ac45fc85620ea212415e66446cc8a690aea9 100644 (file)
@@ -46,71 +46,7 @@ int sound_manager_create_stream_information_internal (sound_stream_type_internal
        return __convert_sound_manager_error_code(__func__, ret);
 }
 
-int sound_manager_add_option_for_stream_routing (sound_stream_info_h stream_info, const char *option)
-{
-       int ret = MM_ERROR_NONE;
-       int i = 0;
-       bool added_successfully = false;
-       sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
-
-       LOGI(">> enter");
-
-       SM_INSTANCE_CHECK(stream_h);
-       SM_NULL_ARG_CHECK(option);
-
-       for (i = 0; i < ROUTE_OPTIONS_MAX; i++) {
-               if (stream_h->route_options[i]) {
-                       if (!strncmp (stream_h->route_options[i], option, strlen(option))) {
-                               return __convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT);
-                       }
-                       continue;
-               } else {
-                       stream_h->route_options[i] = strdup(option);
-                       added_successfully = true;
-                       break;
-               }
-       }
-
-       if (!added_successfully) {
-               ret = MM_ERROR_SOUND_INTERNAL;
-       }
-
-       LOGI("<< leave : ret(%p)", ret);
-
-       return __convert_sound_manager_error_code(__func__, ret);
-}
-
-int sound_manager_remove_option_for_stream_routing (sound_stream_info_h stream_info, const char *option)
-{
-       int ret = MM_ERROR_NONE;
-       int i = 0;
-       bool removed_successfully = false;
-       sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
-
-       LOGI(">> enter");
-
-       SM_INSTANCE_CHECK(stream_h);
-       SM_NULL_ARG_CHECK(option);
-
-       for (i = 0; i < ROUTE_OPTIONS_MAX; i++) {
-               if (stream_h->route_options[i] && !strncmp (stream_h->route_options[i], option, strlen(option))) {
-                       free(stream_h->route_options[i]);
-                       stream_h->route_options[i] = NULL;
-                       removed_successfully = true;
-                       break;
-               }
-       }
-
-       if (!removed_successfully) {
-               ret = MM_ERROR_INVALID_ARGUMENT;
-       }
-
-       LOGI("<< leave : ret(%p)", ret);
-
-       return __convert_sound_manager_error_code(__func__, ret);
-}
-
-int sound_manager_apply_stream_routing_options (sound_stream_info_h stream_info)
+int sound_manager_set_stream_routing_option (sound_stream_info_h stream_info, const char *name, int value)
 {
        int ret = MM_ERROR_NONE;
        int i = 0;
@@ -120,18 +56,9 @@ int sound_manager_apply_stream_routing_options (sound_stream_info_h stream_info)
        LOGI(">> enter");
 
        SM_INSTANCE_CHECK(stream_h);
+       SM_NULL_ARG_CHECK(name);
 
-       for (i = 0; i < ROUTE_OPTIONS_MAX; i++) {
-               if (stream_h->route_options[i]) {
-                       need_to_apply = true;
-                       break;
-               }
-       }
-       if (need_to_apply) {
-               ret = __set_route_options(stream_h->index, stream_h->route_options);
-       } else {
-               __convert_sound_manager_error_code(__func__, MM_ERROR_SOUND_INTERNAL);
-       }
+       ret = __set_route_option(stream_h->index, name, value);
 
        LOGI("<< leave : ret(%p)", ret);
 
index f53c2572b71bde3b61ffca262e13a3093547a472..4c5927d9c6d21e4a9ca06ff4332f3dd5b079aed2 100644 (file)
@@ -23,7 +23,7 @@
 #define PA_STREAM_MANAGER_INTERFACE                             "org.pulseaudio.StreamManager"
 #define PA_STREAM_MANAGER_METHOD_NAME_GET_STREAM_INFO           "GetStreamInfo"
 #define PA_STREAM_MANAGER_METHOD_NAME_SET_STREAM_ROUTE_DEVICES  "SetStreamRouteDevices"
-#define PA_STREAM_MANAGER_METHOD_NAME_SET_STREAM_ROUTE_OPTIONS  "SetStreamRouteOptions"
+#define PA_STREAM_MANAGER_METHOD_NAME_SET_STREAM_ROUTE_OPTION  "SetStreamRouteOption"
 #define PA_STREAM_MANAGER_METHOD_NAME_GET_VOLUME_MAX_LEVEL      "GetVolumeMaxLevel"
 #define PA_STREAM_MANAGER_METHOD_NAME_GET_CURRENT_VOLUME_TYPE   "GetCurrentVolumeType"
 
@@ -657,17 +657,16 @@ int __set_manual_route_info (unsigned int index, manual_route_info_s *info)
        return ret;
 }
 
-int __set_route_options (unsigned int index, char **route_options)
+int __set_route_option (unsigned int index, const char *name, int value)
 {
        int ret = MM_ERROR_NONE;
        int i = 0;
-       GVariantBuilder *builder;
 
        GVariant *result = NULL;
        GDBusConnection *conn = NULL;
        GError *err = NULL;
 
-       assert(route_options);
+       assert(name);
 
        conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
        if (!conn && err) {
@@ -676,22 +675,15 @@ int __set_route_options (unsigned int index, char **route_options)
                return MM_ERROR_SOUND_INTERNAL;
        }
 
-       builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
-       for (i = 0; i < ROUTE_OPTIONS_MAX; i++) {
-               if (route_options[i]) {
-                       g_variant_builder_add(builder, "s", route_options[i]);
-                       LOGI("[OPTIONS] %s", route_options[i]);
-               } else {
-                       break;
-               }
-       }
+       LOGI("[OPTION] %s(%d)", name, value);
+
 
        result = g_dbus_connection_call_sync (conn,
                                                        PA_BUS_NAME,
                                                        PA_STREAM_MANAGER_OBJECT_PATH,
                                                        PA_STREAM_MANAGER_INTERFACE,
-                                                       PA_STREAM_MANAGER_METHOD_NAME_SET_STREAM_ROUTE_OPTIONS,
-                                                       g_variant_new ("(uas)", index, builder),
+                                                       PA_STREAM_MANAGER_METHOD_NAME_SET_STREAM_ROUTE_OPTION,
+                                                       g_variant_new ("(usi)", index, name, value),
                                                        G_VARIANT_TYPE("(s)"),
                                                        G_DBUS_CALL_FLAGS_NONE,
                                                        2000,
@@ -704,12 +696,13 @@ int __set_route_options (unsigned int index, char **route_options)
                const gchar *dbus_ret = NULL;
                g_variant_get(result, "(&s)", &dbus_ret);
                LOGI("g_dbus_connection_call_sync() success, method return value is (%s)", dbus_ret);
-               if (strncmp("STREAM_MANAGER_RETURN_OK", dbus_ret, strlen(dbus_ret))) {
+               if (!strncmp("STREAM_MANAGER_RETURN_ERROR_NO_STREAM", dbus_ret, strlen(dbus_ret))) {
+                       ret = MM_ERROR_SOUND_INVALID_STATE;
+               } else if (strncmp("STREAM_MANAGER_RETURN_OK", dbus_ret, strlen(dbus_ret))) {
                        ret = MM_ERROR_SOUND_INTERNAL;
                }
                g_variant_unref(result);
        }
-       g_variant_builder_unref(builder);
        g_object_unref(conn);
        return ret;
 }
@@ -1176,11 +1169,7 @@ int _destroy_pa_connection_and_unregister_focus(sound_stream_info_s *stream_h)
                        free(stream_h->stream_conf_info.avail_frameworks[i]);
                }
        }
-       for (i = 0; i < ROUTE_OPTIONS_MAX; i++) {
-               if (stream_h->route_options[i]) {
-                       free(stream_h->route_options[i]);
-               }
-       }
+
        for (i = 0; i < SOUND_STREAM_INFO_ARR_MAX; i++) {
                if (sound_stream_info_arr[i] && sound_stream_info_arr[i]->index == stream_h->index) {
                        sound_stream_info_arr[i] = NULL;
index a64b95a62b3b3bc629dac4d1dc77f6a39c8c7bdd..0beacb7d6c407122345ab63731a3c69179aafb8d 100644 (file)
@@ -63,9 +63,7 @@ enum
        CURRENT_STATUS_ADD_DEVICE_FOR_STREAM_ROUTING,
        CURRENT_STATUS_REMOVE_DEVICE_FOR_STREAM_ROUTING,
        CURRENT_STATUS_APPLY_STREAM_ROUTING,
-       CURRENT_STATUS_ADD_OPTION_FOR_STREAM_ROUTING,
-       CURRENT_STATUS_REMOVE_OPTION_FOR_STREAM_ROUTING,
-       CURRENT_STATUS_APPLY_STREAM_ROUTING_OPTIONS,
+       CURRENT_STATUS_SET_STREAM_ROUTING_OPTION,
        CURRENT_STATUS_ACQUIRE_FOCUS,
        CURRENT_STATUS_RELEASE_FOCUS,
        CURRENT_STATUS_GET_ACQUIRED_FOCUS,
@@ -252,17 +250,9 @@ void _interpret_main_menu(char *cmd)
                {
                        g_menu_state = CURRENT_STATUS_APPLY_STREAM_ROUTING;
                }
-               else if (strncmp(cmd, "aos", 3) == 0 )
+               else if (strncmp(cmd, "sso", 3) == 0 )
                {
-                       g_menu_state = CURRENT_STATUS_ADD_OPTION_FOR_STREAM_ROUTING;
-               }
-               else if (strncmp(cmd, "ros", 3) == 0 )
-               {
-                       g_menu_state = CURRENT_STATUS_REMOVE_OPTION_FOR_STREAM_ROUTING;
-               }
-               else if (strncmp(cmd, "aso", 3) == 0 )
-               {
-                       g_menu_state = CURRENT_STATUS_APPLY_STREAM_ROUTING_OPTIONS;
+                       g_menu_state = CURRENT_STATUS_SET_STREAM_ROUTING_OPTION;
                }
                else if (strncmp(cmd, "afc", 3) == 0 )
                {
@@ -370,9 +360,7 @@ void display_sub_basic()
        g_print("gfs. Get Focus State\n");
        g_print("sfw. Set Focus State Watch CB\t");
        g_print("ufw. Unset Focus State Watch CB\n");
-       g_print("aos. *Add option for stream routing\t");
-       g_print("ros. *Remove option for stream routing\t");
-       g_print("aso. *Apply options for stream routing\n");
+       g_print("sso. *Set option for stream routing\n");
        g_print("vcr. *Create VStream\t");
        g_print("vsr. *Start VStream\t");
        g_print("vst. *Stop VStream\t");
@@ -525,17 +513,9 @@ static void displaymenu()
        {
                g_print("*** press enter to apply devices for stream routing\n");
        }
-       else if (g_menu_state == CURRENT_STATUS_ADD_OPTION_FOR_STREAM_ROUTING)
-       {
-               g_print("*** input option to add\n");
-       }
-       else if (g_menu_state == CURRENT_STATUS_REMOVE_OPTION_FOR_STREAM_ROUTING)
-       {
-               g_print("*** input option to remove\n");
-       }
-       else if (g_menu_state == CURRENT_STATUS_APPLY_STREAM_ROUTING_OPTIONS)
+       else if (g_menu_state == CURRENT_STATUS_SET_STREAM_ROUTING_OPTION)
        {
-               g_print("*** press enter to apply options for stream routing \n");
+               g_print("*** input option(name/value) for routing (0:option_1/0, 1:option_1/1, 2:option_2/0, 3:option_2:1)\n");
        }
        else if (g_menu_state == CURRENT_STATUS_ACQUIRE_FOCUS)
        {
@@ -1350,32 +1330,38 @@ static void interpret (char *cmd)
                        reset_menu_state();
                }
                break;
-               case CURRENT_STATUS_ADD_OPTION_FOR_STREAM_ROUTING:
-               {
-                       int ret = SOUND_MANAGER_ERROR_NONE;
-                       ret = sound_manager_add_option_for_stream_routing (g_stream_info_h, cmd);
-                       if (ret) {
-                               g_print("failed to sound_manager_add_option_for_stream_routing(), ret(0x%x)\n", ret);
-                       }
-                       reset_menu_state();
-               }
-               break;
-               case CURRENT_STATUS_REMOVE_OPTION_FOR_STREAM_ROUTING:
+               case CURRENT_STATUS_SET_STREAM_ROUTING_OPTION:
                {
                        int ret = SOUND_MANAGER_ERROR_NONE;
-                       ret = sound_manager_remove_option_for_stream_routing (g_stream_info_h, cmd);
-                       if (ret) {
-                               g_print("failed to sound_manager_remove_option_for_stream_routing(), ret(0x%x)\n", ret);
+                       int selection = 0;
+                       char *name = NULL;
+                       int value = -1;
+                       selection = atoi(cmd);
+                       switch(selection) {
+                       case 0:
+                               name = "option_1";
+                               value = 0;
+                               break;
+                       case 1:
+                               name = "option_1";
+                               value = 1;
+                               break;
+                       case 2:
+                               name = "option_2";
+                               value = 0;
+                               break;
+                       case 3:
+                               name = "option_2";
+                               value = 1;
+                               break;
+                       default:
+                               g_print("invalid argument, try again..\n");
+                               reset_menu_state();
+                               break;
                        }
-                       reset_menu_state();
-               }
-               break;
-               case CURRENT_STATUS_APPLY_STREAM_ROUTING_OPTIONS:
-               {
-                       int ret = SOUND_MANAGER_ERROR_NONE;
-                       ret = sound_manager_apply_stream_routing_options (g_stream_info_h);
+                       ret = sound_manager_set_stream_routing_option (g_stream_info_h, name, value);
                        if (ret) {
-                               g_print("failed to sound_manager_apply_stream_routing_options(), ret(0x%x)\n", ret);
+                               g_print("failed to sound_manager_set_stream_routing_option(), ret(0x%x)\n", ret);
                        }
                        reset_menu_state();
                }