*/
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);
+
/**
* @}
*/
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
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
{
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);
+}
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
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,
};
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();
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");
}
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();
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);