From: Seungbae Shin Date: Wed, 30 Mar 2022 11:48:44 +0000 (+0900) Subject: Add host volume set/get internal api X-Git-Tag: submit/tizen/20220415.044607~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2edba6e506b839618a116028be33eb1ec0404624;p=platform%2Fcore%2Fapi%2Fsound-manager.git Add host volume set/get internal api these APIs can be used for container environment [Version] 0.6.44 [Issue Type] Internal API Change-Id: Idfd85201fa44ed0bc41a3320ad6bfade47ebfa2d --- diff --git a/include/sound_manager_internal.h b/include/sound_manager_internal.h index 2e45dfb..a9be2b1 100644 --- a/include/sound_manager_internal.h +++ b/include/sound_manager_internal.h @@ -1275,6 +1275,36 @@ int sound_manager_set_rpi_playback_route(sound_rpi_playback_route_type type); */ int sound_manager_get_rpi_playback_route(sound_rpi_playback_route_type *type); + +/** + * @brief Sets the host volume level specified for a particular sound type. + * @since_tizen 7.0 + * @privlevel public + * @privilege %http://tizen.org/privilege/volume.set + * @param[in] type The sound type + * @param[in] volume The volume level to be set + * @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_PERMISSION_DENIED Permission denied + * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system + */ +int sound_manager_set_host_volume(sound_type_e type, int volume); + +/** + * @brief Gets the host volume level specified for a particular sound type. + * @since_tizen 7.0 + * @param[in] type The sound type + * @param[out] volume The current volume level + * @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 + */ +int sound_manager_get_host_volume(sound_type_e type, int *volume); + /** * @} */ diff --git a/include/sound_manager_private.h b/include/sound_manager_private.h index fc9611d..6de1ff6 100644 --- a/include/sound_manager_private.h +++ b/include/sound_manager_private.h @@ -399,6 +399,10 @@ int _set_rpi_playback_route(sound_rpi_playback_route_type type); int _get_rpi_playback_route(sound_rpi_playback_route_type *type); +int _set_host_volume_level(const char *direction, const char *volume_type, unsigned int level); + +int _get_host_volume_level(const char *direction, const char *volume_type, unsigned int *level); + #ifdef __cplusplus } #endif diff --git a/packaging/capi-media-sound-manager.spec b/packaging/capi-media-sound-manager.spec index bc42b57..3567f8b 100644 --- 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.6.43 +Version: 0.6.44 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/sound_manager_internal.c b/src/sound_manager_internal.c index 42402c5..2ec8673 100644 --- a/src/sound_manager_internal.c +++ b/src/sound_manager_internal.c @@ -917,3 +917,44 @@ int sound_manager_get_rpi_playback_route(sound_rpi_playback_route_type *type) { return _get_rpi_playback_route(type); } + +int sound_manager_set_host_volume(sound_type_e type, int volume) +{ + int ret = SOUND_MANAGER_ERROR_NONE; + const char *volume_type = NULL; + + SM_ARG_CHECK(type < SOUND_TYPE_NUM); + + LOGI("type[%d] volume[%d]", type, volume); + + ret = _convert_sound_type(type, &volume_type); + if (ret != SOUND_MANAGER_ERROR_NONE) + return ret; + + ret = _set_host_volume_level(DIRECTION_OUT_STR, volume_type, (unsigned int)volume); + + return _convert_sound_manager_error_code(__func__, ret); +} + +int sound_manager_get_host_volume(sound_type_e type, int *volume) +{ + int ret = SOUND_MANAGER_ERROR_NONE; + const char *volume_type = NULL; + unsigned int volume_level = 0; + + SM_ARG_CHECK(volume); + + LOGI("type[%d]", type); + + ret = _convert_sound_type(type, &volume_type); + if (ret != SOUND_MANAGER_ERROR_NONE) + return ret; + + ret = _get_host_volume_level(DIRECTION_OUT_STR, volume_type, &volume_level); + if (ret == SOUND_MANAGER_ERROR_NONE) { + *volume = (int)volume_level; + LOGI("host volume[%d]", *volume); + } + + return _convert_sound_manager_error_code(__func__, ret); +} diff --git a/src/sound_manager_private.c b/src/sound_manager_private.c index ba1479e..ef739cd 100644 --- a/src/sound_manager_private.c +++ b/src/sound_manager_private.c @@ -3797,4 +3797,108 @@ LEAVE: return ret; } -//LCOV_EXCL_STOP + +#define CONTAINER_FILE "/run/systemd/container" +#define DBUS_HOST_SYSTEM_BUS_ADDRESS "unix:path=/run/host/dbus/system_bus_socket" + +static GDBusConnection * __get_host_dbus_connection() +{ + GDBusConnection *conn = NULL; + + g_autoptr(GError) err = NULL; + + if (access(CONTAINER_FILE, F_OK) != 0) { + LOGE("Not in container...."); + return NULL; + } + + conn = g_dbus_connection_new_for_address_sync(DBUS_HOST_SYSTEM_BUS_ADDRESS, + G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION, + NULL, NULL, &err); + if (!conn) + LOGE("g_dbus_connection_new_for_address_sync() error (%s)", err ? err->message : "(null)"); + + return conn; +} + +int _set_host_volume_level(const char *direction, const char *volume_type, unsigned int level) +{ + int ret = SOUND_MANAGER_ERROR_NONE; + const gchar *dbus_ret = NULL; + + g_autoptr(GVariant) result = NULL; + g_autoptr(GDBusConnection) conn = NULL; + g_autoptr(GError) err = NULL; + + SM_ARG_CHECK(direction); + SM_ARG_CHECK(volume_type); + + if (!(conn = __get_host_dbus_connection())) + return SOUND_MANAGER_ERROR_INVALID_OPERATION; + + 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_VOLUME_LEVEL, + g_variant_new("(ssu)", direction, volume_type, level), + G_VARIANT_TYPE("(s)"), + G_DBUS_CALL_FLAGS_NONE, + DBUS_METHOD_TIMEOUT, + NULL, + &err); + if (!result) + return _convert_sound_manager_error_code(__func__, _convert_dbus_error(err ? err->message : NULL)); + + g_variant_get(result, "(&s)", &dbus_ret); + + if (strncmp("STREAM_MANAGER_RETURN_OK", dbus_ret, strlen(dbus_ret))) + ret = SOUND_MANAGER_ERROR_INTERNAL; + + LOGI("dbus_ret[%s] ret[0x%x]", dbus_ret, ret); + + return ret; +} + +int _get_host_volume_level(const char *direction, const char *volume_type, unsigned int *level) +{ + int ret = SOUND_MANAGER_ERROR_NONE; + const gchar *dbus_ret = NULL; + + g_autoptr(GVariant) result = NULL; + g_autoptr(GDBusConnection) conn = NULL; + g_autoptr(GError) err = NULL; + + SM_ARG_CHECK(direction); + SM_ARG_CHECK(volume_type); + SM_ARG_CHECK(level); + + if (!(conn = __get_host_dbus_connection())) + return SOUND_MANAGER_ERROR_INVALID_OPERATION; + + 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_VOLUME_LEVEL, + g_variant_new("(ss)", direction, volume_type), + G_VARIANT_TYPE("(us)"), + G_DBUS_CALL_FLAGS_NONE, + DBUS_METHOD_TIMEOUT, + NULL, + &err); + if (!result) + return _convert_sound_manager_error_code(__func__, _convert_dbus_error(err ? err->message : NULL)); + + g_variant_get(result, "(u&s)", level, &dbus_ret); + + if (strncmp("STREAM_MANAGER_RETURN_OK", dbus_ret, strlen(dbus_ret))) + ret = SOUND_MANAGER_ERROR_INTERNAL; + else + LOGI("level[%u]", *level); + + LOGI("dbus_ret[%s] ret[0x%x]", dbus_ret, ret); + + return ret; +} +//LCOV_EXCL_STOP \ No newline at end of file diff --git a/test/sound_manager_test.c b/test/sound_manager_test.c index 6c9e74b..14eb9a5 100644 --- a/test/sound_manager_test.c +++ b/test/sound_manager_test.c @@ -120,6 +120,8 @@ enum { CURRENT_STATUS_SET_REMOTE_PERMISSION, CURRENT_STATUS_SET_RPI_PLAYBACK_ROUTE, CURRENT_STATUS_GET_RPI_PLAYBACK_ROUTE, + CURRENT_STATUS_SET_HOST_VOLUME, + CURRENT_STATUS_GET_HOST_VOLUME, }; @@ -395,6 +397,10 @@ void _interpret_main_menu(char *cmd) g_menu_state = CURRENT_STATUS_SET_RPI_PLAYBACK_ROUTE; else if (strncmp(cmd, "grpr", MAX_CMD_LEN) == 0) g_menu_state = CURRENT_STATUS_GET_RPI_PLAYBACK_ROUTE; + else if (strncmp(cmd, "shv", MAX_CMD_LEN) == 0) + g_menu_state = CURRENT_STATUS_SET_HOST_VOLUME; + else if (strncmp(cmd, "ghv", MAX_CMD_LEN) == 0) + g_menu_state = CURRENT_STATUS_GET_HOST_VOLUME; else if (strncmp(cmd, "q", MAX_CMD_LEN) == 0) { g_print("closing the test suite\n"); quit_program(); @@ -506,6 +512,8 @@ void display_sub_basic() g_print("alw. *Allow remote device\n"); g_print("srpr. *Set RPI playback route\t"); g_print("grpr. *Get RPI playback route\n"); + g_print("shv. *Set HOST Volume\t"); + g_print("ghv. *Get HOST Volume\n"); g_print(" * is for internal usage.\n"); g_print("=========================================================================================\n"); } @@ -708,6 +716,12 @@ static void displaymenu() g_print("*** input rpi playback route to set (0:auto, 1:headphone, 2:HDMI1, 3:HDMI2(rpi4 only)\n"); else if (g_menu_state == CURRENT_STATUS_GET_RPI_PLAYBACK_ROUTE) g_print("*** press enter to get rpi playback route\n"); + else if (g_menu_state == CURRENT_STATUS_SET_HOST_VOLUME) { + if (flag == 0) + g_print("*** input sound type and desired volume level for HOST(0:SYSTEM 1:NOTIFICATION 2:ALARM 3:RINGTONE 4:MEDIA 5:CALL 6:VOIP 7:VOICE, (0~max volume))\n"); + flag = 1; + } else if (g_menu_state == CURRENT_STATUS_GET_HOST_VOLUME) + g_print("*** input sound type for HOST(0:SYSTEM 1:NOTIFICATION 2:ALARM 3:RINGTONE 4:MEDIA 5:CALL 6:VOIP 7:VOICE)\n"); else { g_print("*** unknown status.\n"); quit_program(); @@ -2846,6 +2860,43 @@ static void interpret(char *cmd) reset_menu_state(); break; } + case CURRENT_STATUS_SET_HOST_VOLUME: { + static int cnt = 0; + static sound_type_e type; + int volume; + switch (cnt) { + case 0: + if (convert_sound_type(&type, cmd) == 1) + cnt++; + else + reset_menu_state(); + break; + case 1: + volume = atoi(cmd); + if (sound_manager_set_host_volume(type, volume) != SOUND_MANAGER_ERROR_NONE) + g_print("fail to set host volume(%d) check sound type(%d)'s available volume level\n", volume, type); + else + g_print("set host volume success : sound type(%d), volume(%d)\n", type, volume); + cnt = 0; + reset_menu_state(); + break; + default: + break; + } + break; + } + case CURRENT_STATUS_GET_HOST_VOLUME: { + sound_type_e type; + int volume; + if (convert_sound_type(&type, cmd) == 1) { + if (sound_manager_get_host_volume(type, &volume) != SOUND_MANAGER_ERROR_NONE) + g_print("fail to get host volume\n"); + else + g_print("current host volume of this type(%d) is : %d\n", type, volume); + } + reset_menu_state(); + break; + } } end: g_timeout_add(100, timeout_menu_display, 0);