From: Sangchul Lee Date: Fri, 15 May 2015 08:46:39 +0000 (+0900) Subject: Revise codes regarding current volume type X-Git-Tag: submit/tizen/20150715.092047~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F18%2F41118%2F2;p=platform%2Fcore%2Fapi%2Fsound-manager.git Revise codes regarding current volume type Change-Id: I8f37413c00e56ea9219e7d6a8e2b0cf0f0024419 --- diff --git a/include/sound_manager_private.h b/include/sound_manager_private.h index 5dc2506..04c9384 100644 --- a/include/sound_manager_private.h +++ b/include/sound_manager_private.h @@ -231,8 +231,6 @@ int __convert_stream_type_to_change_reason (const char *stream_type, sound_strea int __convert_device_type (sound_device_type_e device_type_enum, char **device_type); -int __convert_device_type_to_enum (char *device_type, sound_device_type_e *device_type_enum); - int __convert_device_io_direction (mm_sound_device_io_direction_e io_direction, sound_device_io_direction_e *sound_io_direction); const char* __convert_api_name (native_api_e api_name); @@ -245,8 +243,12 @@ int __set_route_options (unsigned int index, char **route_options); 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 __get_volume_max_level (const char *direction, const char *volume_type, unsigned int *max_level); +int __get_current_volume_type (const char *direction, char **volume_type); + void _pa_context_state_cb (pa_context *c, void *userdata); void _pa_stream_state_cb (pa_stream *s, void * userdata); diff --git a/packaging/capi-media-sound-manager.spec b/packaging/capi-media-sound-manager.spec index 745d836..323340a 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.8 +Version: 0.3.9 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/sound_manager.c b/src/sound_manager.c index f4676fe..9fc38f8 100644 --- a/src/sound_manager.c +++ b/src/sound_manager.c @@ -107,11 +107,25 @@ int sound_manager_set_current_sound_type (sound_type_e type) int sound_manager_get_current_sound_type (sound_type_e *type) { int ret = MM_ERROR_NONE; + volume_type_t mm_sound_vol_type = VOLUME_TYPE_UNKNOWN; + char *volume_type = NULL; if (type == NULL) return __convert_sound_manager_error_code(__func__, MM_ERROR_INVALID_ARGUMENT); - ret = mm_sound_volume_get_current_playing_type((volume_type_t *)type); + ret = mm_sound_volume_primary_type_get(&mm_sound_vol_type); + if (ret == MM_ERROR_NONE) { + 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); + } + } else { + *type = mm_sound_vol_type; + } + } LOGI("returns : type=%d, ret=%p", *type, ret); return __convert_sound_manager_error_code(__func__, ret); @@ -121,7 +135,7 @@ int sound_manager_unset_current_sound_type (void) { int ret = MM_ERROR_NONE; - ret = mm_sound_volume_primary_type_clear(); + ret = mm_sound_volume_primary_type_set(VOLUME_TYPE_UNKNOWN); return __convert_sound_manager_error_code(__func__, ret); } diff --git a/src/sound_manager_private.c b/src/sound_manager_private.c index acd6d46..4dc88a2 100644 --- a/src/sound_manager_private.c +++ b/src/sound_manager_private.c @@ -25,6 +25,7 @@ #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_GET_VOLUME_MAX_LEVEL "GetVolumeMaxLevel" +#define PA_STREAM_MANAGER_METHOD_NAME_GET_CURRENT_VOLUME_TYPE "GetCurrentVolumeType" extern _session_interrupt_info_s g_session_interrupt_cb_table; extern _session_mode_e g_cached_session_mode; @@ -262,6 +263,37 @@ 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 ret = MM_ERROR_NONE; + + SM_NULL_ARG_CHECK(sound_type); + SM_NULL_ARG_CHECK(sound_type_enum); + + if (!strncmp(sound_type, "system", strlen(sound_type))) { + *sound_type_enum = SOUND_TYPE_SYSTEM; + } else if (!strncmp(sound_type, "notification", strlen(sound_type))) { + *sound_type_enum = SOUND_TYPE_NOTIFICATION; + } else if (!strncmp(sound_type, "alarm", strlen(sound_type))) { + *sound_type_enum = SOUND_TYPE_ALARM; + } else if (!strncmp(sound_type, "ringtone", strlen(sound_type))) { + *sound_type_enum = SOUND_TYPE_RINGTONE; + } else if (!strncmp(sound_type, "media", strlen(sound_type))) { + *sound_type_enum = SOUND_TYPE_MEDIA; + } else if (!strncmp(sound_type, "call", strlen(sound_type))) { + *sound_type_enum = SOUND_TYPE_CALL; + } else if (!strncmp(sound_type, "voip", strlen(sound_type))) { + *sound_type_enum = SOUND_TYPE_VOIP; + } else if (!strncmp(sound_type, "voice", strlen(sound_type))) { + *sound_type_enum = SOUND_TYPE_VOICE; + } else { + ret = MM_ERROR_INVALID_ARGUMENT; + LOGE("not supported sound_type(%s), err(0x%08x)", sound_type, ret); + } + + return ret; +} + int __convert_device_type (sound_device_type_e device_type_enum, char **device_type) { int ret = MM_ERROR_NONE; @@ -303,38 +335,6 @@ int __convert_device_type (sound_device_type_e device_type_enum, char **device_t return ret; } -/* it will be deprecated after ready for changing device type that is from server to string */ -int __convert_device_type_to_enum (char *device_type, sound_device_type_e *device_type_enum) -{ - int ret = MM_ERROR_NONE; - - SM_NULL_ARG_CHECK(device_type); - SM_NULL_ARG_CHECK(device_type_enum); - - if (!strncmp(device_type, "builtin-speaker", SOUND_DEVICE_TYPE_LEN)) { - *device_type_enum = SOUND_DEVICE_BUILTIN_SPEAKER; - } else if (!strncmp(device_type, "builtin-receiver", SOUND_DEVICE_TYPE_LEN)) { - *device_type_enum = SOUND_DEVICE_BUILTIN_RECEIVER; - } else if (!strncmp(device_type, "builtin-mic", SOUND_DEVICE_TYPE_LEN)) { - *device_type_enum = SOUND_DEVICE_BUILTIN_MIC; - } else if (!strncmp(device_type, "audio-jack", SOUND_DEVICE_TYPE_LEN)) { - *device_type_enum = SOUND_DEVICE_AUDIO_JACK; - } else if (!strncmp(device_type, "bt", SOUND_DEVICE_TYPE_LEN)) { - *device_type_enum = SOUND_DEVICE_BLUETOOTH; - } else if (!strncmp(device_type, "hdmi", SOUND_DEVICE_TYPE_LEN)) { - *device_type_enum = SOUND_DEVICE_HDMI; - } else if (!strncmp(device_type, "forwarding", SOUND_DEVICE_TYPE_LEN)) { - *device_type_enum = SOUND_DEVICE_FORWARDING; - } else if (!strncmp(device_type, "usb-audio", SOUND_DEVICE_TYPE_LEN)) { - *device_type_enum = SOUND_DEVICE_USB_AUDIO; - } else { - ret = MM_ERROR_INVALID_ARGUMENT; - LOGE("not supported device_type(%s), err(0x%08x)", device_type, ret); - } - - return ret; -} - int __convert_device_io_direction (mm_sound_device_io_direction_e io_direction, sound_device_io_direction_e *sound_io_direction) { int ret = MM_ERROR_NONE; @@ -644,7 +644,7 @@ int __set_manual_route_info (unsigned int index, manual_route_info_s *info) ret = MM_ERROR_SOUND_INTERNAL; } else { const gchar *dbus_ret = NULL; - g_variant_get(result, "(s)", &dbus_ret); + 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))) { ret = MM_ERROR_SOUND_INVALID_STATE; @@ -702,7 +702,7 @@ int __set_route_options (unsigned int index, char **route_options) ret = MM_ERROR_SOUND_INTERNAL; } else { const gchar *dbus_ret = NULL; - g_variant_get(result, "(s)", &dbus_ret); + 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))) { ret = MM_ERROR_SOUND_INTERNAL; @@ -749,7 +749,7 @@ int __get_volume_max_level (const char *direction, const char *volume_type, unsi ret = MM_ERROR_SOUND_INTERNAL; } else { const gchar *dbus_ret = NULL; - g_variant_get(result, "(us)", max_level, &dbus_ret); + g_variant_get(result, "(u&s)", max_level, &dbus_ret); LOGI("g_dbus_connection_call_sync() success, method return value is (%u, %s)", *max_level, dbus_ret); if (strncmp("STREAM_MANAGER_RETURN_OK", dbus_ret, strlen(dbus_ret))) { ret = MM_ERROR_SOUND_INTERNAL; @@ -760,6 +760,57 @@ int __get_volume_max_level (const char *direction, const char *volume_type, unsi return ret; } +int __get_current_volume_type (const char *direction, char **volume_type) +{ + int ret = MM_ERROR_NONE; + + GVariant *result = NULL; + GDBusConnection *conn = NULL; + GError *err = NULL; + + assert(direction); + assert(volume_type); + + conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); + if (!conn && err) { + LOGE("g_bus_get_sync() error (%s)", err->message); + g_error_free (err); + return MM_ERROR_SOUND_INTERNAL; + } + + result = g_dbus_connection_call_sync (conn, + PA_BUS_NAME, + PA_STREAM_MANAGER_OBJECT_PATH, + PA_STREAM_MANAGER_INTERFACE, + PA_STREAM_MANAGER_METHOD_NAME_GET_CURRENT_VOLUME_TYPE, + g_variant_new ("(s)", direction), + G_VARIANT_TYPE("(ss)"), + G_DBUS_CALL_FLAGS_NONE, + 2000, + NULL, + &err); + if (!result && err) { + LOGE("g_dbus_connection_call_sync() error (%s)", err->message); + ret = MM_ERROR_SOUND_INTERNAL; + } else { + const gchar *dbus_volume_type = NULL; + const gchar *dbus_ret = NULL; + g_variant_get(result, "(&s&s)", &dbus_volume_type, &dbus_ret); + LOGI("g_dbus_connection_call_sync() success, method return value is (%s, %s)", dbus_volume_type, dbus_ret); + if (!strncmp("STREAM_MANAGER_RETURN_OK", dbus_ret, strlen(dbus_ret))) { + ret = MM_ERROR_NONE; + *volume_type = strdup(dbus_volume_type); + } else if (!strncmp("STREAM_MANAGER_RETURN_ERROR_NO_STREAM", dbus_ret, strlen(dbus_ret))) { + ret = MM_ERROR_SOUND_VOLUME_NO_INSTANCE; + } else { + ret = MM_ERROR_SOUND_INTERNAL; + } + g_variant_unref(result); + } + g_object_unref(conn); + return ret; +} + void _session_interrupt_cb (session_msg_t msg, session_event_t event, void *user_data){ if( g_session_interrupt_cb_table.user_cb ){ sound_session_interrupted_code_e e = SOUND_SESSION_INTERRUPTED_COMPLETED;