From: Sangchul Lee Date: Wed, 15 Jul 2015 01:02:02 +0000 (+0900) Subject: Modify internal API for setting routing option X-Git-Tag: submit/tizen/20150715.092047^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F72%2F43872%2F2;p=platform%2Fcore%2Fapi%2Fsound-manager.git Modify internal API for setting routing option [Version] Release 0.3.13 [profile] Common [Issue Type] Revise API Change-Id: I69ef98f5e3d42ff1ec185018fd118722704a858f --- diff --git a/include/sound_manager_internal.h b/include/sound_manager_internal.h index a1725aa..8582078 100644 --- a/include/sound_manager_internal.h +++ b/include/sound_manager_internal.h @@ -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 diff --git a/include/sound_manager_private.h b/include/sound_manager_private.h index b6148b2..756860e 100644 --- a/include/sound_manager_private.h +++ b/include/sound_manager_private.h @@ -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); diff --git a/packaging/capi-media-sound-manager.spec b/packaging/capi-media-sound-manager.spec index 31cb6e1..b1ebace 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.12 +Version: 0.3.13 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/sound_manager_internal.c b/src/sound_manager_internal.c index d058f9f..be80ac4 100644 --- a/src/sound_manager_internal.c +++ b/src/sound_manager_internal.c @@ -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); diff --git a/src/sound_manager_private.c b/src/sound_manager_private.c index f53c257..4c5927d 100644 --- a/src/sound_manager_private.c +++ b/src/sound_manager_private.c @@ -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; diff --git a/test/sound_manager_test.c b/test/sound_manager_test.c index a64b95a..0beacb7 100644 --- a/test/sound_manager_test.c +++ b/test/sound_manager_test.c @@ -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(); }