*/
int sound_manager_set_stream_preferred_device_id(sound_stream_info_h stream_info, sound_device_io_direction_e io_direction, int device_id);
+/**
+ * @internal
+ * @brief Definition for the value indicating that the preemptive device for the specific stream type was not set.
+ * @since_tizen 5.5
+ * @see sound_manager_get_stream_preemptive_device()
+ */
+#define SOUND_MANAGER_STREAM_NO_PREEMPTIVE_DEVICE 0
+
+/**
+ * @internal
+ * @brief Sets the preemptive device for the stream routing.
+ * @since_tizen 5.5
+ *
+ * @remarks This function is to set a device id to streams made by the specific stream type.
+ * The available stream types for this function are #SOUND_STREAM_TYPE_MEDIA, #SOUND_STREAM_TYPE_SYSTEM,\n
+ * #SOUND_STREAM_TYPE_VOICE_INFORMATION and #SOUND_STREAM_TYPE_VOICE_RECOGNITION. Otherwise, #SOUND_MANAGER_ERROR_POLICY will be returned.
+ *
+ * @param[in] stream_type The type of stream
+ * @param[in] io_direction The IO direction of the device
+ * @param[in] device_id The preemptive device id (this can be #SOUND_MANAGER_STREAM_NO_PREEMPTIVE_DEVICE to unset)
+ * @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_POLICY Noncompliance with the sound system policy
+ * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
+ * @pre Get a device by calling sound_manager_get_device_list() and sound_manager_get_next_device().
+ * @pre Get a device id by calling sound_manager_get_device_id().
+ * @post You can get preemptive devices by calling sound_manager_get_stream_preemptive_device().
+ * @post Call sound_manager_free_device_list() to free the devices.
+ * @see sound_manager_get_stream_preemptive_device()
+ * @see sound_manager_get_device_list()
+ * @see sound_manager_get_next_device()
+ * @see sound_manager_get_device_id()
+ * @see sound_manager_free_device_list()
+ */
+int sound_manager_set_stream_preemptive_device(sound_stream_type_e stream_type, sound_device_io_direction_e direction, int device_id);
+
+/**
+ * @internal
+ * @brief Gets the preemptive device for the stream routing.
+ * @since_tizen 5.5
+ *
+ * @remarks This function is to return the preemptive device id per each direction if it has been set.
+ * If there is no preemptive device for a given direction, the corresponding output value will be set to
+ * #SOUND_MANAGER_STREAM_NO_PREEMPTIVE_DEVICE.
+ * You can get a device handle of the id value by using sound_manager_get_device_list(),
+ * sound_manager_get_next_device() and sound_manager_get_device_id().
+ *
+ * @param[in] stream_type The type of stream
+ * @param[out] in_device_id The preemptive input device id
+ * @param[out] out_device_id The preemptive output device id
+ * @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
+ * @see sound_manager_set_stream_preemptive_device()
+ * @see sound_manager_get_device_list()
+ * @see sound_manager_get_next_device()
+ * @see sound_manager_get_device_id()
+ * @see sound_manager_free_device_list()
+ */
+int sound_manager_get_stream_preemptive_device(sound_stream_type_e stream_type, int *in_device_id, int *out_device_id);
+
/**
* @internal
* @brief Gets the state of the device by id.
*/
int sound_manager_set_stream_preferred_device_id(sound_stream_info_h stream_info, sound_device_io_direction_e io_direction, int device_id);
+/**
+ * @internal
+ * @brief Definition for the value indicating that the preemptive device for the specific stream type was not set.
+ * @since_tizen 5.5
+ * @see sound_manager_get_stream_preemptive_device()
+ */
+#define SOUND_MANAGER_STREAM_NO_PREEMPTIVE_DEVICE 0
+
+/**
+ * @internal
+ * @brief Sets the preemptive device for the stream routing.
+ * @since_tizen 5.5
+ *
+ * @remarks This function is to set a device id to streams made by the specific stream type.
+ * The available stream types for this function are #SOUND_STREAM_TYPE_MEDIA, #SOUND_STREAM_TYPE_SYSTEM,\n
+ * #SOUND_STREAM_TYPE_VOICE_INFORMATION and #SOUND_STREAM_TYPE_VOICE_RECOGNITION. Otherwise, #SOUND_MANAGER_ERROR_POLICY will be returned.
+ *
+ * @param[in] stream_type The type of stream
+ * @param[in] io_direction The IO direction of the device
+ * @param[in] device_id The preemptive device id (this can be #SOUND_MANAGER_STREAM_NO_PREEMPTIVE_DEVICE to unset)
+ * @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_POLICY Noncompliance with the sound system policy
+ * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
+ * @pre Get a device by calling sound_manager_get_device_list() and sound_manager_get_next_device().
+ * @pre Get a device id by calling sound_manager_get_device_id().
+ * @post You can get preemptive devices by calling sound_manager_get_stream_preemptive_device().
+ * @post Call sound_manager_free_device_list() to free the devices.
+ * @see sound_manager_get_stream_preemptive_device()
+ * @see sound_manager_get_device_list()
+ * @see sound_manager_get_next_device()
+ * @see sound_manager_get_device_id()
+ * @see sound_manager_free_device_list()
+ */
+int sound_manager_set_stream_preemptive_device(sound_stream_type_e stream_type, sound_device_io_direction_e direction, int device_id);
+
+/**
+ * @internal
+ * @brief Gets the preemptive device for the stream routing.
+ * @since_tizen 5.5
+ *
+ * @remarks This function is to return the preemptive device id per each direction if it has been set.
+ * If there is no preemptive device for a given direction, the corresponding output value will be set to
+ * #SOUND_MANAGER_STREAM_NO_PREEMPTIVE_DEVICE.
+ * You can get a device handle of the id value by using sound_manager_get_device_list(),
+ * sound_manager_get_next_device() and sound_manager_get_device_id().
+ *
+ * @param[in] stream_type The type of stream
+ * @param[out] in_device_id The preemptive input device id
+ * @param[out] out_device_id The preemptive output device id
+ * @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
+ * @see sound_manager_set_stream_preemptive_device()
+ * @see sound_manager_get_device_list()
+ * @see sound_manager_get_next_device()
+ * @see sound_manager_get_device_id()
+ * @see sound_manager_free_device_list()
+ */
+int sound_manager_get_stream_preemptive_device(sound_stream_type_e stream_type, int *in_device_id, int *out_device_id);
+
/**
* @internal
* @brief Gets the state of the device by id.
int _get_preferred_device(sound_stream_info_s *stream_info, int *in_device_id, int *out_device_id);
+int _set_preemptive_device(sound_stream_type_e stream_type, sound_device_io_direction_e direction, int device_id);
+
+int _get_preemptive_device(sound_stream_type_e stream_type, int *in_device_id, int *out_device_id);
+
int _get_latest_stream_pid(int stream_type, unsigned int *pid);
#ifdef __cplusplus
Name: capi-media-sound-manager
Summary: Sound Manager library
-Version: 0.6.2
+Version: 0.6.3
Release: 0
Group: Multimedia/API
License: Apache-2.0
ret = _get_latest_stream_pid(stream_type, pid);
+ return _convert_sound_manager_error_code(__func__, ret);
+}
+
+int sound_manager_set_stream_preemptive_device(sound_stream_type_e stream_type, sound_device_io_direction_e io_direction, int device_id)
+{
+ int ret = MM_ERROR_NONE;
+
+ ret = _set_preemptive_device(stream_type, io_direction, device_id);
+
+ return _convert_sound_manager_error_code(__func__, ret);
+}
+
+int sound_manager_get_stream_preemptive_device(sound_stream_type_e stream_type, int *in_device_id, int *out_device_id)
+{
+ int ret = MM_ERROR_NONE;
+
+ SM_NULL_ARG_CHECK(in_device_id || out_device_id);
+
+ ret = _get_preemptive_device(stream_type, in_device_id, out_device_id);
+
return _convert_sound_manager_error_code(__func__, ret);
}
\ No newline at end of file
#define STREAM_NETWORK_SOURCE_MEDIA "network-source-media"
#define STREAM_EXT_MEDIA "ext-media"
+#define DBUS_METHOD_TIMEOUT 2000
+
#define PA_BUS_NAME "org.pulseaudio.Server"
#define PA_STREAM_MANAGER_OBJECT_PATH "/org/pulseaudio/StreamManager"
#define PA_STREAM_MANAGER_METHOD_NAME_SET_STREAM_ROUTE_OPTION "SetStreamRouteOption"
#define PA_STREAM_MANAGER_METHOD_NAME_SET_STREAM_PREFERRED_DEVICE "SetStreamPreferredDevice"
#define PA_STREAM_MANAGER_METHOD_NAME_GET_STREAM_PREFERRED_DEVICE "GetStreamPreferredDevice"
+#define PA_STREAM_MANAGER_METHOD_NAME_SET_STREAM_PREEMPTIVE_DEVICE "SetStreamPreemptiveDevice"
+#define PA_STREAM_MANAGER_METHOD_NAME_GET_STREAM_PREEMPTIVE_DEVICE "GetStreamPreemptiveDevice"
#define PA_STREAM_MANAGER_METHOD_NAME_GET_VOLUME_MAX_LEVEL "GetVolumeMaxLevel"
#define PA_STREAM_MANAGER_METHOD_NAME_GET_VOLUME_LEVEL "GetVolumeLevel"
#define PA_STREAM_MANAGER_METHOD_NAME_SET_VOLUME_LEVEL "SetVolumeLevel"
return ret;
}
+static int __invoke_ipc_set_preemptive_device(sound_stream_type_e stream_type, sound_device_io_direction_e io_direction, int device_id)
+{
+ int ret = MM_ERROR_NONE;
+ GVariant *result = NULL;
+ GDBusConnection *conn = NULL;
+ GError *err = NULL;
+ const gchar *dbus_ret = NULL;
+ const gchar *direction_str;
+ char *stream_type_str;
+ int i;
+
+ if ((ret = _convert_stream_type(stream_type, &stream_type_str)) != MM_ERROR_NONE)
+ return ret;
+
+ if ((ret = __get_dbus_connection(&conn)))
+ return ret;
+
+ for (i = SOUND_DEVICE_IO_DIRECTION_IN; i < SOUND_DEVICE_IO_DIRECTION_BOTH; i++) {
+ if (io_direction != SOUND_DEVICE_IO_DIRECTION_BOTH && io_direction != i)
+ continue;
+ direction_str = (i == SOUND_DEVICE_IO_DIRECTION_IN) ? "in" : "out";
+
+ 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_PREEMPTIVE_DEVICE,
+ g_variant_new("(ssu)", stream_type_str, direction_str, (unsigned int)device_id),
+ NULL,
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_METHOD_TIMEOUT,
+ NULL,
+ &err);
+ if (!result || err) {
+ LOGE("g_dbus_connection_call_sync() for SET_STREAM_PREEMPTIVE_DEVICE, direction(%s) error (%s)",
+ direction_str, err ? err->message : NULL);
+ ret = _convert_dbus_error(err ? err->message : NULL);
+ if (err)
+ g_error_free(err);
+ if (result)
+ g_variant_unref(result);
+ continue;
+ }
+
+ LOGI("Preemptive device(id:%d, direction:%s) is set", device_id, direction_str);
+
+ 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_INVALID_ARGUMENT", dbus_ret, strlen(dbus_ret)))
+ ret = MM_ERROR_INVALID_ARGUMENT;
+ else if (!strncmp("STREAM_MANAGER_RETURN_POLICY", dbus_ret, strlen(dbus_ret)))
+ ret = MM_ERROR_POLICY_INTERNAL;
+ else if (strncmp("STREAM_MANAGER_RETURN_OK", dbus_ret, strlen(dbus_ret)))
+ ret = MM_ERROR_SOUND_INTERNAL;
+
+ g_variant_unref(result);
+ if (ret)
+ goto LEAVE;
+ }
+
+LEAVE:
+ g_object_unref(conn);
+ return ret;
+}
+
+static int __invoke_ipc_get_preemptive_device(sound_stream_type_e stream_type, int *in_device_id, int *out_device_id)
+{
+ int ret = MM_ERROR_NONE;
+ GDBusConnection *conn = NULL;
+ GError *err = NULL;
+ GVariant *result = NULL;
+ const gchar *dbus_ret = NULL;
+ unsigned int _in_device_id;
+ unsigned int _out_device_id;
+ char *stream_type_str;
+
+ if ((ret = _convert_stream_type(stream_type, &stream_type_str)) != MM_ERROR_NONE)
+ return ret;
+
+ if ((ret = __get_dbus_connection(&conn)))
+ return ret;
+
+ 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_STREAM_PREEMPTIVE_DEVICE,
+ g_variant_new("(s)", stream_type_str),
+ G_VARIANT_TYPE("(uus)"),
+ G_DBUS_CALL_FLAGS_NONE,
+ DBUS_METHOD_TIMEOUT,
+ NULL,
+ &err);
+ if (!result || err) {
+ LOGE("g_dbus_connection_call_sync() for GET_STREAM_PREEMPTIVE_DEVICE error");
+ ret = _convert_dbus_error(err ? err->message : NULL);
+ if (err)
+ g_error_free(err);
+ goto LEAVE;
+ }
+ g_variant_get(result, "(uu&s)", &_in_device_id, &_out_device_id, &dbus_ret);
+
+ LOGI("dbus return value is (%s)", dbus_ret);
+
+ if (!strncmp("STREAM_MANAGER_RETURN_OK", dbus_ret, strlen(dbus_ret))) {
+ if (in_device_id) {
+ *in_device_id = _in_device_id;
+ LOGI("preemptive device id[in:%d]", *in_device_id);
+ }
+ if (out_device_id) {
+ *out_device_id = _out_device_id;
+ LOGI("preemptive device id[out:%d]", *out_device_id);
+ }
+ } else {
+ ret = MM_ERROR_SOUND_INTERNAL;
+ }
+
+LEAVE:
+ g_variant_unref(result);
+ g_object_unref(conn);
+
+ return ret;
+}
+
+int _set_preemptive_device(sound_stream_type_e stream_type, sound_device_io_direction_e direction, int device_id)
+{
+ return __invoke_ipc_set_preemptive_device(stream_type, direction, device_id);
+}
+
+int _get_preemptive_device(sound_stream_type_e stream_type, int *in_device_id, int *out_device_id)
+{
+ return __invoke_ipc_get_preemptive_device(stream_type, in_device_id, out_device_id);
+}
+
int _get_latest_stream_pid(int stream_type, unsigned int *pid)
{
int ret = MM_ERROR_NONE;
CURRENT_STATUS_SET_STREAM_PREFERRED_DEVICE,
CURRENT_STATUS_SET_STREAM_PREFERRED_DEVICE_ID,
CURRENT_STATUS_GET_STREAM_PREFERRED_DEVICE,
+ CURRENT_STATUS_SET_STREAM_PREEMPTIVE_DEVICE,
+ CURRENT_STATUS_GET_STREAM_PREEMPTIVE_DEVICE,
CURRENT_STATUS_SET_STREAM_ROUTING_OPTION,
CURRENT_STATUS_ACQUIRE_FOCUS,
CURRENT_STATUS_RELEASE_FOCUS,
g_menu_state = CURRENT_STATUS_SET_STREAM_PREFERRED_DEVICE_ID;
else if (strncmp(cmd, "gpd", MAX_CMD_LEN) == 0)
g_menu_state = CURRENT_STATUS_GET_STREAM_PREFERRED_DEVICE;
+ else if (strncmp(cmd, "spt", MAX_CMD_LEN) == 0)
+ g_menu_state = CURRENT_STATUS_SET_STREAM_PREEMPTIVE_DEVICE;
+ else if (strncmp(cmd, "gpt", MAX_CMD_LEN) == 0)
+ g_menu_state = CURRENT_STATUS_GET_STREAM_PREEMPTIVE_DEVICE;
else if (strncmp(cmd, "afc", MAX_CMD_LEN) == 0)
g_menu_state = CURRENT_STATUS_ACQUIRE_FOCUS;
else if (strncmp(cmd, "rfc", MAX_CMD_LEN) == 0)
g_print("spd. Set preferred device\t");
g_print("spi. *Set preferred device id\t");
g_print("gpd. Get preferred device\n");
+ g_print("spt. *Set preemptive device\t");
+ g_print("gpt. *Get preemptive device\n");
g_print("afc. Acquire Focus\t");
g_print("rfc. Release Focus\t");
g_print("gfs. Get Focus State\n");
flag = 1;
} else if (g_menu_state == CURRENT_STATUS_GET_STREAM_PREFERRED_DEVICE)
g_print("*** press enter to get preferred device\n");
+ else if (g_menu_state == CURRENT_STATUS_SET_STREAM_PREEMPTIVE_DEVICE) {
+ if (flag == 0)
+ g_print("*** input stream type(0:media 1:system, 2:voice-information, 3:voice-recognition)\n");
+ else if (flag == 1)
+ g_print("*** input preemptive device id(0:unset, 1 ~: device_id) and direction(0:out, 1:in, 2:both)\n");
+ flag++;
+ } else if (g_menu_state == CURRENT_STATUS_GET_STREAM_PREEMPTIVE_DEVICE)
+ g_print("*** input stream type to get preemptive device (0:media 1:system: 2:voice-information, 3:voice-recognition)\n");
else if (g_menu_state == CURRENT_STATUS_SET_STREAM_ROUTING_OPTION)
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)
reset_menu_state();
break;
}
+ case CURRENT_STATUS_SET_STREAM_PREEMPTIVE_DEVICE: {
+ int ret = SOUND_MANAGER_ERROR_NONE;
+ static int cnt = 0;
+ static int device_id = 0;
+ static sound_stream_type_e stream_type;
+ sound_device_io_direction_e direction;
+
+ if (cnt == 0) {
+ switch (atoi(cmd)) {
+ case 0:
+ stream_type = SOUND_STREAM_TYPE_MEDIA;
+ break;
+ case 1:
+ stream_type = SOUND_STREAM_TYPE_SYSTEM;
+ break;
+ case 2:
+ stream_type = SOUND_STREAM_TYPE_VOICE_INFORMATION;
+ break;
+ case 3:
+ stream_type = SOUND_STREAM_TYPE_VOICE_RECOGNITION;
+ break;
+ default:
+ g_print("invalid argument, try again..\n");
+ reset_menu_state();
+ cnt = 0;
+ goto end;
+ }
+ cnt++;
+ } else if (cnt == 1) {
+ device_id = atoi(cmd);
+ cnt++;
+ } else if (cnt == 2) {
+ switch (atoi(cmd)) {
+ case 0:
+ direction = SOUND_DEVICE_IO_DIRECTION_OUT;
+ break;
+ case 1:
+ direction = SOUND_DEVICE_IO_DIRECTION_IN;
+ break;
+ case 2:
+ direction = SOUND_DEVICE_IO_DIRECTION_BOTH;
+ break;
+ default:
+ g_print("invalid argument, try again..\n");
+ reset_menu_state();
+ cnt = 0;
+ goto end;
+ }
+ cnt = 0;
+
+ ret = sound_manager_set_stream_preemptive_device(stream_type, direction, device_id);
+ if (ret)
+ g_print("failed to sound_manager_set_stream_preemptive_device(), ret(0x%x)\n", ret);
+
+ reset_menu_state();
+ }
+ break;
+ }
+ case CURRENT_STATUS_GET_STREAM_PREEMPTIVE_DEVICE: {
+ int ret = SOUND_MANAGER_ERROR_NONE;
+ int in_device_id = 0;
+ int out_device_id = 0;
+ sound_stream_type_e stream_type;
+ sound_device_list_h device_list;
+ sound_device_h device;
+ sound_device_type_e device_type;
+ int id;
+
+ switch (atoi(cmd)) {
+ case 0:
+ stream_type = SOUND_STREAM_TYPE_MEDIA;
+ break;
+ case 1:
+ stream_type = SOUND_STREAM_TYPE_SYSTEM;
+ break;
+ case 2:
+ stream_type = SOUND_STREAM_TYPE_VOICE_INFORMATION;
+ break;
+ case 3:
+ stream_type = SOUND_STREAM_TYPE_VOICE_RECOGNITION;
+ break;
+ default:
+ g_print("invalid argument, try again..\n");
+ reset_menu_state();
+ goto end;
+ }
+
+ ret = sound_manager_get_stream_preemptive_device(stream_type, &in_device_id, &out_device_id);
+ if (ret) {
+ g_print("failed to sound_manager_get_stream_preemptive_device(), ret(0x%x)\n", ret);
+ reset_menu_state();
+ break;
+ }
+
+ if (in_device_id == SOUND_MANAGER_STREAM_NO_PREFERRED_DEVICE)
+ g_print("preemptive [ IN] device was not set\n");
+ if (out_device_id == SOUND_MANAGER_STREAM_NO_PREFERRED_DEVICE)
+ g_print("preemptive [OUT] device was not set\n");
+ if ((in_device_id == SOUND_MANAGER_STREAM_NO_PREFERRED_DEVICE) &&
+ (out_device_id == SOUND_MANAGER_STREAM_NO_PREFERRED_DEVICE)) {
+ reset_menu_state();
+ break;
+ }
+
+ ret = sound_manager_get_device_list(SOUND_DEVICE_ALL_MASK, &device_list);
+ if (ret) {
+ g_print("failed to get device list(), ret(0x%x)\n", ret);
+ } else {
+ while (!sound_manager_get_next_device(device_list, &device)) {
+ if (!sound_manager_get_device_id(device, &id)) {
+ if (in_device_id && id == in_device_id) {
+ if (sound_manager_get_device_type(device, &device_type) == SOUND_MANAGER_ERROR_NONE)
+ g_print("preemptive [ IN] device type[%s], id[%d]\n", g_device_type_str[device_type], in_device_id);
+ }
+ if (out_device_id && id == out_device_id) {
+ if (sound_manager_get_device_type(device, &device_type) == SOUND_MANAGER_ERROR_NONE)
+ g_print("preemptive [OUT] device type[%s], id[%d]\n", g_device_type_str[device_type], out_device_id);
+ }
+ }
+ }
+
+ ret = sound_manager_free_device_list(device_list);
+ if (ret)
+ g_print("failed to sound_manager_free_device_list, ret(0x%x)\n", ret);
+ }
+ reset_menu_state();
+ break;
+ }
case CURRENT_STATUS_ACQUIRE_FOCUS: {
int ret = SOUND_MANAGER_ERROR_NONE;
int focus_type = 0;