Add new APIs for USB audio output device 87/185587/10 accepted/tizen/unified/20180813.061405 submit/tizen/20180810.055142
authorSangchul Lee <sc11.lee@samsung.com>
Mon, 30 Jul 2018 04:21:17 +0000 (13:21 +0900)
committerSangchul Lee <sc11.lee@samsung.com>
Thu, 9 Aug 2018 02:09:56 +0000 (11:09 +0900)
For getting/setting a particular sample format and rate,
a user can use these new APIs below.
  sound_manager_get_supported_sample_formats()
  sound_manager_set_sample_format()
  sound_manager_get_sample_format()
  sound_manager_get_supported_sample_rates()
  sound_manager_set_sample_rate()
  sound_manager_get_sample_rate()

If a user wants to use stream's original sample information
to the USB device without S/W resampling in audio daemon,
these new APIs can be useful.
  sound_manager_set_avoid_resampling()
  sound_manager_get_avoid_resampling()

A user can set the USB device only for media sound. If set
it true, only media type streams can be routed to the device.
  sound_manager_set_media_stream_only()
  sound_manager_get_media_stream_only()

[Version] 0.5.10
[Issue Type] New API

Change-Id: I8a6b49539776b56a87cd5b10914d3ded2d01db06
Signed-off-by: Sangchul Lee <sc11.lee@samsung.com>
include/sound_manager.h
include/sound_manager_private.h
packaging/capi-media-sound-manager.spec
src/sound_manager.c
src/sound_manager_private.c
test/sound_manager_test.c

index 5abc929..1d796ad 100644 (file)
@@ -228,6 +228,32 @@ typedef enum {
 } sound_device_mask_e;
 
 /**
+* @brief Enumeration for sound sample format.
+* @since_tizen 5.0
+*/
+typedef enum {
+       SOUND_SAMPLE_FORMAT_U8,         /**< Unsigned 8 bit samples */
+       SOUND_SAMPLE_FORMAT_S16_LE,     /**< Signed 16 bit samples */
+       SOUND_SAMPLE_FORMAT_S24_LE,     /**< Signed 24 bit samples */
+       SOUND_SAMPLE_FORMAT_S24_32_LE,  /**< Signed 24 bit(packed in 32 bit) samples */
+} sound_sample_format_e;
+
+/**
+* @brief Enumeration for sound sample rate.
+* @since_tizen 5.0
+*/
+typedef enum {
+       SOUND_SAMPLE_RATE_8000,    /**< 8000 Hz sample rate */
+       SOUND_SAMPLE_RATE_16000,   /**< 16000 Hz sample rate */
+       SOUND_SAMPLE_RATE_22050,   /**< 22050 Hz sample rate */
+       SOUND_SAMPLE_RATE_44100,   /**< 44100 Hz sample rate */
+       SOUND_SAMPLE_RATE_48000,   /**< 48000 Hz sample rate */
+       SOUND_SAMPLE_RATE_88200,   /**< 88200 Hz sample rate */
+       SOUND_SAMPLE_RATE_96000,   /**< 96000 Hz sample rate */
+       SOUND_SAMPLE_RATE_192000,  /**< 192000 Hz sample rate */
+} sound_sample_rate_e;
+
+/**
  * @}
  */
 
@@ -319,7 +345,7 @@ typedef void (*sound_stream_focus_state_watch_cb) (int id, sound_stream_focus_ma
  * @remarks @a device is freed by the platform after this callback exits.
  *
  * @param[in]   device The sound_device
- * @param[in]   is_connected   The state of device connection : (@c true = connected, @c false = disconnected)
+ * @param[in]   is_connected   The state of device connection: (@c true = connected, @c false = disconnected)
  * @param[in]   user_data      The user data passed from the callback registration function
  * @pre You should add this callback using sound_manager_add_device_connection_changed_cb().
  * @see sound_manager_add_device_connection_changed_cb()
@@ -334,7 +360,7 @@ typedef void (*sound_device_connection_changed_cb) (sound_device_h device, bool
  * @remarks @a device is freed by the platform after this callback exits.
  *
  * @param[in]   device The sound_device
- * @param[in]   is_running     The state of the device : (@c true = running, @c false = not runnning)
+ * @param[in]   is_running     The state of the device: (@c true = running, @c false = not runnning)
  * @param[in]   user_data      The user data passed from the callback registration function
  * @pre You should add this callback using sound_manager_add_device_running_changed_cb().
  * @see sound_manager_add_device_running_changed_cb()
@@ -770,7 +796,7 @@ int sound_manager_get_focus_state(sound_stream_info_h stream_info, sound_stream_
  *     If you don't want to reacquire the focus you've lost automatically, disable the focus reacquisition setting by using this function and vice versa.
  *
  * @param[in]  stream_info     The handle of stream information
- * @param[in]  enable  The auto focus reacquisition property to set : (@c true = enable, @c false = disable)
+ * @param[in]  enable  The auto focus reacquisition property value to set: (@c true = enable, @c false = disable)
  * @return @c 0 on success,
  *         otherwise a negative error value
  * @retval #SOUND_MANAGER_ERROR_NONE Success
@@ -787,7 +813,7 @@ int sound_manager_set_focus_reacquisition(sound_stream_info_h stream_info, bool
  * @remarks    The default value is true.
  *
  * @param[in]  stream_info     The handle of stream information
- * @param[out] enabled The value of focus auto reacquisition property : (@c true = enabled, @c false = disabled)
+ * @param[out] enabled The value of focus auto reacquisition property: (@c true = enabled, @c false = disabled)
  * @return @c 0 on success,
  *         otherwise a negative error value
  * @retval #SOUND_MANAGER_ERROR_NONE Success
@@ -830,7 +856,7 @@ int sound_manager_deliver_focus(sound_stream_info_h source, sound_stream_info_h
  *
  * @param[in]  stream_info     The handle of stream information
  * @param[in]  device  The device item
- * @param[out] is_on   Whether the stream info is using the device or not : (@c true = use, @c false = not use)
+ * @param[out] is_on   Whether the stream info is using the device or not: (@c true = use, @c false = not use)
  * @return @c 0 on success,
  *         otherwise a negative error value
  * @retval #SOUND_MANAGER_ERROR_NONE Success
@@ -1134,7 +1160,7 @@ int sound_manager_get_device_name(sound_device_h device, char **name);
  * @brief Checks if the device is running.
  * @since_tizen 5.0
  * @param[in]  device  The device item
- * @param[out] is_running      Whether the device is running or not : (@c true = running, @c false = not running)
+ * @param[out] is_running      Whether the device is running or not: (@c true = running, @c false = not running)
  * @return @c 0 on success,
  *         otherwise a negative error value
  * @retval #SOUND_MANAGER_ERROR_NONE Success
@@ -1172,6 +1198,224 @@ int sound_manager_is_device_running(sound_device_h device, bool *is_running);
 int sound_manager_get_device_state(sound_device_h device, sound_device_state_e *state) TIZEN_DEPRECATED_API;
 
 /**
+ * @brief Gets the device's supported sample formats.
+ * @since_tizen 5.0
+ *
+ * @remarks    @a device should be #SOUND_DEVICE_USB_AUDIO type and an output device,\n
+ *     otherwise #SOUND_MANAGER_ERROR_INVALID_OPERATION will be returned.\n
+ *     Use sound_manager_get_device_io_direction() to check if it is an output device or not.\n
+ *     The @a formats should be released using free().
+ *
+ * @param[in]  device  The device item
+ * @param[out] formats The supported sample format list
+ * @param[out] num_of_elems    The number of elements in the sample format list
+ * @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_INVALID_OPERATION Invalid operation
+ * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
+ * @see sound_manager_set_sample_format()
+ * @see sound_manager_get_sample_format()
+ */
+int sound_manager_get_supported_sample_formats(sound_device_h device, sound_sample_format_e **formats, unsigned int *num_of_elems);
+
+/**
+ * @brief Sets the device's sample format.
+ * @since_tizen 5.0
+ *
+ * @remarks    @a device should be #SOUND_DEVICE_USB_AUDIO type and an output device.\n
+ *     @a format should be one of the values received from sound_manager_get_supported_sample_formats(),\n
+ *     otherwise #SOUND_MANAGER_ERROR_INVALID_OPERATION will be returned.\n
+ *     Use sound_manager_get_device_io_direction() to check if it is an output device or not.
+ *
+ * @param[in]  device  The device item
+ * @param[in]  format  The sample format
+ * @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_INVALID_OPERATION Invalid operation
+ * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
+ * @see sound_manager_get_supported_sample_formats()
+ * @see sound_manager_get_sample_format()
+ */
+int sound_manager_set_sample_format(sound_device_h device, sound_sample_format_e format);
+
+/**
+ * @brief Gets the device's sample format.
+ * @since_tizen 5.0
+ *
+ * @remarks    @a device should be #SOUND_DEVICE_USB_AUDIO type and an output device,\n
+ *     otherwise #SOUND_MANAGER_ERROR_INVALID_OPERATION will be returned.\n
+ *     Use sound_manager_get_device_io_direction() to check if it is an output device or not.
+ *
+ * @param[in]  device  The device item
+ * @param[out] format  The sample format
+ * @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_INVALID_OPERATION Invalid operation
+ * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
+ * @see sound_manager_get_supported_sample_formats()
+ * @see sound_manager_set_sample_format()
+ */
+int sound_manager_get_sample_format(sound_device_h device, sound_sample_format_e *format);
+
+/**
+ * @brief Gets the device's supported sample rates.
+ * @since_tizen 5.0
+ *
+ * @remarks    @a device should be #SOUND_DEVICE_USB_AUDIO type and an output device,\n
+ *     otherwise #SOUND_MANAGER_ERROR_INVALID_OPERATION will be returned.\n
+ *     Use sound_manager_get_device_io_direction() to check if it is an output device or not.\n
+ *     The @a rates should be released using free().
+ *
+ * @param[in]  device  The device item
+ * @param[out] rates   The supported sample rate list
+ * @param[out] num_of_elems    The number of elements in the sample rate list
+ * @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_INVALID_OPERATION Invalid operation
+ * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
+ * @see sound_manager_set_sample_rate()
+ * @see sound_manager_get_sample_rate()
+ */
+int sound_manager_get_supported_sample_rates(sound_device_h device, sound_sample_rate_e **rates, unsigned int *num_of_elems);
+
+/**
+ * @brief Sets the device's sample rate.
+ * @since_tizen 5.0
+ *
+ * @remarks    @a device should be #SOUND_DEVICE_USB_AUDIO type and an output device.\n
+ *     @a rate should be one of the values received from sound_manager_get_supported_sample_rates(),\n
+ *     otherwise #SOUND_MANAGER_ERROR_INVALID_OPERATION will be returned.\n
+ *     Use sound_manager_get_device_io_direction() to check if it is an output device or not.
+ *
+ * @param[in]  device  The device item
+ * @param[in]  rate    The sample rate
+ * @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_INVALID_OPERATION Invalid operation
+ * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
+ * @see sound_manager_get_supported_sample_rates()
+ * @see sound_manager_get_sample_rate()
+ */
+int sound_manager_set_sample_rate(sound_device_h device, sound_sample_rate_e rate);
+
+/**
+ * @brief Gets the device's sample rate.
+ * @since_tizen 5.0
+ *
+ * @remarks    @a device should be #SOUND_DEVICE_USB_AUDIO type and an output device,\n
+ *     otherwise #SOUND_MANAGER_ERROR_INVALID_OPERATION will be returned.\n
+ *     Use sound_manager_get_device_io_direction() to check if it is an output device or not.
+ *
+ * @param[in]  device  The device item
+ * @param[out] rate    The sample rate
+ * @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_INVALID_OPERATION Invalid operation
+ * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
+ * @see sound_manager_get_supported_sample_rates()
+ * @see sound_manager_set_sample_rate()
+ */
+int sound_manager_get_sample_rate(sound_device_h device, sound_sample_rate_e *rate);
+
+/**
+ * @brief Sets the device's 'avoid resampling' property.
+ * @since_tizen 5.0
+ *
+ * @remarks    @a device should be #SOUND_DEVICE_USB_AUDIO type and an output device,\n
+ *     otherwise #SOUND_MANAGER_ERROR_INVALID_OPERATION will be returned.\n
+ *     Use sound_manager_get_device_io_direction() to check if it is an output device or not.\n
+ *     The 'avoid resampling' property is not enabled as default. With this enabled, @a device will\n
+ *     use the first stream's original sample format and rate without resampling if supported.
+ *
+ * @param[in]  device  The device item
+ * @param[in]  enable  The 'avoid resampling' property value to set: (@c true = enable, @c false = disable)
+ * @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_INVALID_OPERATION Invalid operation
+ * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
+ * @see sound_manager_get_avoid_resampling()
+ */
+int sound_manager_set_avoid_resampling(sound_device_h device, bool enable);
+
+/**
+ * @brief Gets the device's 'avoid resampling' property.
+ * @since_tizen 5.0
+ *
+ * @remarks    @a device should be #SOUND_DEVICE_USB_AUDIO type and an output device,\n
+ *     otherwise #SOUND_MANAGER_ERROR_INVALID_OPERATION will be returned.\n
+ *     Use sound_manager_get_device_io_direction() to check if it is an output device or not.\n
+ *     The default value of 'avoid resampling' is false.
+ *
+ * @param[in]  device  The device item
+ * @param[in]  enabled The value of 'avoid resampling' property: (@c true = enabled, @c false = disabled)
+ * @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_INVALID_OPERATION Invalid operation
+ * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
+ * @see sound_manager_set_avoid_resampling()
+ */
+int sound_manager_get_avoid_resampling(sound_device_h device, bool *enabled);
+
+/**
+ * @brief Sets the restriction of stream type only for media.
+ * @since_tizen 5.0
+ *
+ * @remarks    @a device should be #SOUND_DEVICE_USB_AUDIO type and an output device,\n
+ *     otherwise #SOUND_MANAGER_ERROR_INVALID_OPERATION will be returned.\n
+ *     Use sound_manager_get_device_io_direction() to check if it is an output device or not.\n
+ *     This property is not enabled as default. With this enabled, no other stream types\n
+ *     except #SOUND_STREAM_TYPE_MEDIA is not allowed to @a device.
+ *
+ * @param[in]  device  The device item
+ * @param[in]  enable  The 'media stream only' property value to set: (@c true = enable, @c false = disable)
+ * @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_INVALID_OPERATION Invalid operation
+ * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
+ * @see sound_manager_get_media_stream_only()
+ */
+int sound_manager_set_media_stream_only(sound_device_h device, bool enable);
+
+/**
+ * @brief Gets the restriction of stream type only for media.
+ * @since_tizen 5.0
+ *
+ * @remarks    @a device should be #SOUND_DEVICE_USB_AUDIO type and an output device,\n
+ *     otherwise #SOUND_MANAGER_ERROR_INVALID_OPERATION will be returned.\n
+ *     Use sound_manager_get_device_io_direction() to check if it is an output device or not.\n
+ *     The property is not enabled as default.
+ *
+ * @param[in]  device  The device item
+ * @param[out] enabled The value of 'media stream only' property: (@c true = enabled, @c false = disabled)
+ * @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_INVALID_OPERATION Invalid operation
+ * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
+ * @see sound_manager_set_media_stream_only()
+ */
+int sound_manager_get_media_stream_only(sound_device_h device, bool *enabled);
+
+/**
  * @brief Adds a callback function to be invoked when the connection state of a sound device was changed.
  * @since_tizen 3.0
  *
index a5aee7c..b65f835 100644 (file)
@@ -158,6 +158,7 @@ if (pthread_mutex_unlock(x_mutex)) { \
 #define SOUND_STREAM_TYPE_LEN 64
 #define SOUND_STREAM_DIRECTION_MAX 2
 #define SOUND_DEVICE_TYPE_LEN 64
+#define SOUND_SAMPLE_FORMAT_LEN 12
 
 #define DIRECTION_OUT_STR         "out"
 #define SOUND_TYPE_MASTER_STR     "master"
@@ -239,6 +240,8 @@ void _focus_state_change_callback(int index, mm_sound_focus_type_e focus_type, m
 
 void _focus_watch_callback(int id, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason, const char *extra_info, void *user_data);
 
+int _convert_error_from_dbus_error(const char *error_msg);
+
 int _convert_sound_manager_error_code(const char *func, int code);
 
 int _convert_stream_type(sound_stream_type_e enum_type, char **stream_type);
@@ -259,6 +262,8 @@ int _convert_device_io_direction(mm_sound_device_io_direction_e io_direction, so
 
 const char* _convert_api_name(native_api_e api_name);
 
+int _return_val_if_not_usb_device(sound_device_h device, int ret_val);
+
 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);
@@ -281,6 +286,26 @@ int _get_current_media_routing_path(const char *direction, sound_device_type_e *
 
 void _update_focus_status(unsigned int index, unsigned int acquired_focus_status);
 
+int _get_supported_sample_formats(int device_id, sound_sample_format_e **formats, unsigned int *num);
+
+int _set_sample_format(int device_id, sound_sample_format_e format);
+
+int _get_sample_format(int device_id, sound_sample_format_e *format);
+
+int _get_supported_sample_rates(int device_id, sound_sample_rate_e **rates, unsigned int *num);
+
+int _set_sample_rate(int device_id, sound_sample_rate_e rate);
+
+int _get_sample_rate(int device_id, sound_sample_rate_e *rate);
+
+int _set_avoid_resampling(int device_id, bool enable);
+
+int _get_avoid_resampling(int device_id, bool *enabled);
+
+int _set_media_stream_only(int device_id, bool enable);
+
+int _get_media_stream_only(int device_id, bool *enabled);
+
 void _pa_context_state_cb(pa_context *c, void *userdata);
 
 void _pa_stream_state_cb(pa_stream *s, void * userdata);
index 6fbd2f7..4951c71 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-sound-manager
 Summary:    Sound Manager library
-Version:    0.5.9
+Version:    0.5.10
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 6c74e77..626017f 100644 (file)
@@ -833,6 +833,174 @@ int sound_manager_get_device_state(sound_device_h device, sound_device_state_e *
        return _convert_sound_manager_error_code(__func__, ret);
 }
 
+int sound_manager_get_supported_sample_formats(sound_device_h device, sound_sample_format_e **formats, unsigned int *num_of_elems)
+{
+       int ret = MM_ERROR_NONE;
+       int device_id;
+
+       SM_INSTANCE_CHECK(device);
+       SM_NULL_ARG_CHECK(formats);
+       SM_NULL_ARG_CHECK(num_of_elems);
+
+       if ((ret = _return_val_if_not_usb_device(device, SOUND_MANAGER_ERROR_INVALID_OPERATION)))
+               return ret;
+
+       if (!(ret = mm_sound_get_device_id(device, &device_id)))
+               ret = _get_supported_sample_formats(device_id, formats, num_of_elems);
+
+       return _convert_sound_manager_error_code(__func__, ret);
+}
+
+int sound_manager_set_sample_format(sound_device_h device, sound_sample_format_e format)
+{
+       int ret = MM_ERROR_NONE;
+       int device_id;
+
+       SM_INSTANCE_CHECK(device);
+
+       if ((ret = _return_val_if_not_usb_device(device, SOUND_MANAGER_ERROR_INVALID_OPERATION)))
+               return ret;
+
+       if (!(ret = mm_sound_get_device_id(device, &device_id)))
+               ret = _set_sample_format(device_id, format);
+
+       return _convert_sound_manager_error_code(__func__, ret);
+}
+
+int sound_manager_get_sample_format(sound_device_h device, sound_sample_format_e *format)
+{
+       int ret = MM_ERROR_NONE;
+       int device_id;
+
+       SM_INSTANCE_CHECK(device);
+       SM_NULL_ARG_CHECK(format);
+
+       if ((ret = _return_val_if_not_usb_device(device, SOUND_MANAGER_ERROR_INVALID_OPERATION)))
+               return ret;
+
+       if (!(ret = mm_sound_get_device_id(device, &device_id)))
+               ret = _get_sample_format(device_id, format);
+
+       return _convert_sound_manager_error_code(__func__, ret);
+}
+
+int sound_manager_get_supported_sample_rates(sound_device_h device, sound_sample_rate_e **rates, unsigned int *num_of_elems)
+{
+       int ret = MM_ERROR_NONE;
+       int device_id;
+
+       SM_INSTANCE_CHECK(device);
+       SM_NULL_ARG_CHECK(rates);
+       SM_NULL_ARG_CHECK(num_of_elems);
+
+       if ((ret = _return_val_if_not_usb_device(device, SOUND_MANAGER_ERROR_INVALID_OPERATION)))
+               return ret;
+
+       if (!(ret = mm_sound_get_device_id(device, &device_id)))
+               ret = _get_supported_sample_rates(device_id, rates, num_of_elems);
+
+       return _convert_sound_manager_error_code(__func__, ret);
+}
+
+int sound_manager_set_sample_rate(sound_device_h device, sound_sample_rate_e rate)
+{
+       int ret = MM_ERROR_NONE;
+       int device_id;
+
+       SM_INSTANCE_CHECK(device);
+
+       if ((ret = _return_val_if_not_usb_device(device, SOUND_MANAGER_ERROR_INVALID_OPERATION)))
+               return ret;
+
+       if (!(ret = mm_sound_get_device_id(device, &device_id)))
+               ret = _set_sample_rate(device_id, rate);
+
+       return _convert_sound_manager_error_code(__func__, ret);
+}
+
+int sound_manager_get_sample_rate(sound_device_h device, sound_sample_rate_e *rate)
+{
+       int ret = MM_ERROR_NONE;
+       int device_id;
+
+       SM_INSTANCE_CHECK(device);
+       SM_NULL_ARG_CHECK(rate);
+
+       if ((ret = _return_val_if_not_usb_device(device, SOUND_MANAGER_ERROR_INVALID_OPERATION)))
+               return ret;
+
+       if (!(ret = mm_sound_get_device_id(device, &device_id)))
+               ret = _get_sample_rate(device_id, rate);
+
+       return _convert_sound_manager_error_code(__func__, ret);
+}
+
+int sound_manager_set_avoid_resampling(sound_device_h device, bool enable)
+{
+       int ret = MM_ERROR_NONE;
+       int device_id;
+
+       SM_INSTANCE_CHECK(device);
+
+       if ((ret = _return_val_if_not_usb_device(device, SOUND_MANAGER_ERROR_INVALID_OPERATION)))
+               return ret;
+
+       if (!(ret = mm_sound_get_device_id(device, &device_id)))
+               ret = _set_avoid_resampling(device_id, enable);
+
+       return _convert_sound_manager_error_code(__func__, ret);
+}
+
+int sound_manager_get_avoid_resampling(sound_device_h device, bool *enabled)
+{
+       int ret = MM_ERROR_NONE;
+       int device_id;
+
+       SM_INSTANCE_CHECK(device);
+       SM_NULL_ARG_CHECK(enabled);
+
+       if ((ret = _return_val_if_not_usb_device(device, SOUND_MANAGER_ERROR_INVALID_OPERATION)))
+               return ret;
+
+       if (!(ret = mm_sound_get_device_id(device, &device_id)))
+               ret = _get_avoid_resampling(device_id, enabled);
+
+       return _convert_sound_manager_error_code(__func__, ret);
+}
+
+int sound_manager_set_media_stream_only(sound_device_h device, bool enable)
+{
+       int ret = MM_ERROR_NONE;
+       int device_id;
+
+       SM_INSTANCE_CHECK(device);
+
+       if ((ret = _return_val_if_not_usb_device(device, SOUND_MANAGER_ERROR_INVALID_OPERATION)))
+               return ret;
+
+       if (!(ret = mm_sound_get_device_id(device, &device_id)))
+               ret = _set_media_stream_only(device_id, enable);
+
+       return _convert_sound_manager_error_code(__func__, ret);
+}
+
+int sound_manager_get_media_stream_only(sound_device_h device, bool *enabled)
+{
+       int ret = MM_ERROR_NONE;
+       int device_id;
+
+       SM_INSTANCE_CHECK(device);
+       SM_NULL_ARG_CHECK(enabled);
+
+       if ((ret = _return_val_if_not_usb_device(device, SOUND_MANAGER_ERROR_INVALID_OPERATION)))
+               return ret;
+
+       if (!(ret = mm_sound_get_device_id(device, &device_id)))
+               ret = _get_media_stream_only(device_id, enabled);
+
+       return _convert_sound_manager_error_code(__func__, ret);
+}
+
 int sound_manager_add_device_connection_changed_cb(int device_mask, sound_device_connection_changed_cb callback, void *user_data, int *id)
 {
        int ret = MM_ERROR_NONE;
index 73d43c8..a073399 100644 (file)
@@ -20,6 +20,7 @@
 #include <vconf.h>
 
 #define PA_BUS_NAME                                             "org.pulseaudio.Server"
+
 #define PA_STREAM_MANAGER_OBJECT_PATH                           "/org/pulseaudio/StreamManager"
 #define PA_STREAM_MANAGER_INTERFACE                             "org.pulseaudio.StreamManager"
 #define PA_STREAM_MANAGER_METHOD_NAME_GET_STREAM_INFO           "GetStreamInfo"
 #define PA_STREAM_MANAGER_METHOD_NAME_GET_CURRENT_MEDIA_ROUTING_PATH "GetCurrentMediaRoutingPath"
 #define PA_STREAM_MANAGER_METHOD_NAME_UPDATE_FOCUS_STATUS       "UpdateFocusStatus"
 #define PA_STREAM_MANAGER_METHOD_NAME_CHECK_STREAM_EXIST_BY_PID "CheckStreamExistByPid"
+
+#define PA_DEVICE_MANAGER_OBJECT_PATH                           "/org/pulseaudio/DeviceManager"
+#define PA_DEVICE_MANAGER_INTERFACE                             "org.pulseaudio.DeviceManager"
+#define PA_DEVICE_MANAGER_METHOD_NAME_GET_SUPPORTED_SAMPLE_FORMATS "GetSupportedSampleFormats"
+#define PA_DEVICE_MANAGER_METHOD_NAME_SET_SAMPLE_FORMAT         "SetSampleFormat"
+#define PA_DEVICE_MANAGER_METHOD_NAME_GET_SAMPLE_FORMAT         "GetSampleFormat"
+#define PA_DEVICE_MANAGER_METHOD_NAME_GET_SUPPORTED_SAMPLE_RATES   "GetSupportedSampleRates"
+#define PA_DEVICE_MANAGER_METHOD_NAME_SET_SAMPLE_RATE           "SetSampleRate"
+#define PA_DEVICE_MANAGER_METHOD_NAME_GET_SAMPLE_RATE           "GetSampleRate"
+#define PA_DEVICE_MANAGER_METHOD_NAME_SET_AVOID_RESAMPLING      "SetAvoidResampling"
+#define PA_DEVICE_MANAGER_METHOD_NAME_GET_AVOID_RESAMPLING      "GetAvoidResampling"
+#define PA_DEVICE_MANAGER_METHOD_NAME_SET_SPECIFIC_STREAM       "SetSpecificStreamOnly"
+#define PA_DEVICE_MANAGER_METHOD_NAME_GET_SPECIFIED_STREAM      "GetSpecifiedStream"
+
 #define VCONF_PATH_PREFIX_VOLUME                                "file/private/sound/volume/"
 #define VCONF_PATH_MAX                                          64
 
+#define DBUS_ERR_MSG_MAX                                        24
+
+int _convert_dbus_error(const char *error_msg)
+{
+       int ret = MM_ERROR_NONE;
+       const char ch = '.';
+       char *ret_str;
+
+       if (!error_msg)
+               return MM_ERROR_SOUND_INTERNAL;
+
+       /* parsing dbus error message, for example,
+        *   GDBus.Error:org.freedesktop.DBus.Error.InvalidArgs:
+        *   org.tizen.multimedia.audio.InvalidArgument */
+       if (!(ret_str = strrchr(error_msg, ch)))
+               return MM_ERROR_SOUND_INTERNAL;
+
+       ret_str = ret_str + 1;
+       if (ret_str[0] == '\0')
+               return MM_ERROR_SOUND_INTERNAL;
+
+       if (!strncmp(ret_str, "InvalidArgument", DBUS_ERR_MSG_MAX))
+               ret = MM_ERROR_INVALID_ARGUMENT;
+       else if (!strncmp(ret_str, "InvalidOperation", DBUS_ERR_MSG_MAX))
+               ret = MM_ERROR_SOUND_INVALID_OPERATION;
+       else if (!strncmp(ret_str, "PolicyInternal", DBUS_ERR_MSG_MAX))
+               ret = MM_ERROR_POLICY_INTERNAL;
+       else
+               ret = MM_ERROR_SOUND_INTERNAL;
+
+       LOGE("%s => 0x%x", ret_str, ret);
+
+       return ret;
+}
+
 int _convert_sound_manager_error_code(const char *func, int code)
 {
        int ret = SOUND_MANAGER_ERROR_NONE;
@@ -528,6 +578,141 @@ const char* _convert_api_name(native_api_e api_name)
        return name;
 }
 
+int _convert_sample_format_enum_to_str(sound_sample_format_e format, char **format_str)
+{
+       SM_NULL_ARG_CHECK_FOR_PRIV(format_str);
+
+       switch (format) {
+       case SOUND_SAMPLE_FORMAT_U8:
+               *format_str = "u8";
+               break;
+       case SOUND_SAMPLE_FORMAT_S16_LE:
+               *format_str = "s16le";
+               break;
+       case SOUND_SAMPLE_FORMAT_S24_LE:
+               *format_str = "s24le";
+               break;
+       case SOUND_SAMPLE_FORMAT_S24_32_LE:
+               *format_str = "s24-32le";
+               break;
+       default:
+               LOGE("could not find format[%d] in this switch case statement", format);
+               return MM_ERROR_SOUND_INTERNAL;
+       }
+
+       return MM_ERROR_NONE;
+}
+
+int _convert_sample_format_str_to_enum(const char *format_str, sound_sample_format_e *format)
+{
+       SM_NULL_ARG_CHECK_FOR_PRIV(format_str);
+       SM_NULL_ARG_CHECK_FOR_PRIV(format);
+
+       if (!strncmp(format_str, "u8", SOUND_SAMPLE_FORMAT_LEN) || !strncmp(format_str, "8", SOUND_SAMPLE_FORMAT_LEN)) {
+               *format = SOUND_SAMPLE_FORMAT_U8;
+       } else if (!strncmp(format_str, "s16le", SOUND_SAMPLE_FORMAT_LEN)) {
+               *format = SOUND_SAMPLE_FORMAT_S16_LE;
+       } else if (!strncmp(format_str, "s24le", SOUND_SAMPLE_FORMAT_LEN)) {
+               *format = SOUND_SAMPLE_FORMAT_S24_LE;
+       } else if (!strncmp(format_str, "s24-32le", SOUND_SAMPLE_FORMAT_LEN)) {
+               *format = SOUND_SAMPLE_FORMAT_S24_32_LE;
+       } else {
+               LOGE("not supported sample format(%s)", format_str);
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       return MM_ERROR_NONE;
+}
+
+int _convert_sample_rate_enum_to_uint(sound_sample_rate_e rate, unsigned int *sample_rate)
+{
+       SM_NULL_ARG_CHECK_FOR_PRIV(sample_rate);
+
+       switch (rate) {
+       case SOUND_SAMPLE_RATE_8000:
+               *sample_rate = 8000;
+               break;
+       case SOUND_SAMPLE_RATE_16000:
+               *sample_rate = 16000;
+               break;
+       case SOUND_SAMPLE_RATE_22050:
+               *sample_rate = 22050;
+               break;
+       case SOUND_SAMPLE_RATE_44100:
+               *sample_rate = 44100;
+               break;
+       case SOUND_SAMPLE_RATE_48000:
+               *sample_rate = 48000;
+               break;
+       case SOUND_SAMPLE_RATE_88200:
+               *sample_rate = 88200;
+               break;
+       case SOUND_SAMPLE_RATE_96000:
+               *sample_rate = 96000;
+               break;
+       case SOUND_SAMPLE_RATE_192000:
+               *sample_rate = 192000;
+               break;
+       default:
+               LOGE("not supported sample rate(%u)", rate);
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       return MM_ERROR_NONE;
+}
+
+int _convert_sample_rate_to_enum(unsigned int rate, sound_sample_rate_e *rate_e)
+{
+       SM_NULL_ARG_CHECK_FOR_PRIV(rate_e);
+
+       switch (rate) {
+       case 8000:
+               *rate_e = SOUND_SAMPLE_RATE_8000;
+               break;
+       case 16000:
+               *rate_e = SOUND_SAMPLE_RATE_16000;
+               break;
+       case 22050:
+               *rate_e = SOUND_SAMPLE_RATE_22050;
+               break;
+       case 44100:
+               *rate_e = SOUND_SAMPLE_RATE_44100;
+               break;
+       case 48000:
+               *rate_e = SOUND_SAMPLE_RATE_48000;
+               break;
+       case 88200:
+               *rate_e = SOUND_SAMPLE_RATE_88200;
+               break;
+       case 96000:
+               *rate_e = SOUND_SAMPLE_RATE_96000;
+               break;
+       case 192000:
+               *rate_e = SOUND_SAMPLE_RATE_192000;
+               break;
+       default:
+               LOGE("not supported sample rate(%u)", rate);
+               return MM_ERROR_INVALID_ARGUMENT;
+       }
+
+       return MM_ERROR_NONE;
+}
+
+int _return_val_if_not_usb_device(sound_device_h device, int ret_val)
+{
+       mm_sound_device_type_e type;
+
+       if (mm_sound_get_device_type(device, &type))
+               return ret_val;
+
+       if (type != MM_SOUND_DEVICE_TYPE_USB_AUDIO)     {
+               LOGE("device type is not USB AUDIO");
+               return ret_val;
+       }
+
+       return MM_ERROR_NONE;
+}
+
 //LCOV_EXCL_START
 void _focus_state_change_callback(int index, mm_sound_focus_type_e focus_type, mm_sound_focus_state_e state, const char *reason, int option, const char *extra_info, void *user_data)
 {
@@ -1207,6 +1392,472 @@ LEAVE:
        return;
 }
 
+#define SM_SAMPLE_FORMAT_NUM    4 /* check declaration of sound_sample_format_e */
+int _get_supported_sample_formats(int device_id, sound_sample_format_e **formats, unsigned int *num)
+{
+       int ret = MM_ERROR_NONE;
+       GVariant *result = NULL;
+       GDBusConnection *conn = NULL;
+       GError *err = NULL;
+       GVariantIter *iter = NULL;
+       gchar *format_str;
+       unsigned int iter_num;
+       unsigned int elem_num = 0;
+       sound_sample_format_e format;
+       sound_sample_format_e sm_formats[SM_SAMPLE_FORMAT_NUM] = {0, };
+
+       SM_NULL_ARG_CHECK_FOR_PRIV(formats);
+       SM_NULL_ARG_CHECK_FOR_PRIV(num);
+
+       if ((ret = __get_dbus_connection(&conn)))
+               return ret;
+
+       result = g_dbus_connection_call_sync(conn,
+                                                       PA_BUS_NAME,
+                                                       PA_DEVICE_MANAGER_OBJECT_PATH,
+                                                       PA_DEVICE_MANAGER_INTERFACE,
+                                                       PA_DEVICE_MANAGER_METHOD_NAME_GET_SUPPORTED_SAMPLE_FORMATS,
+                                                       g_variant_new("(i)", device_id),
+                                                       G_VARIANT_TYPE("(as)"),
+                                                       G_DBUS_CALL_FLAGS_NONE,
+                                                       2000,
+                                                       NULL,
+                                                       &err);
+       if (!result || err) {
+               LOGE("g_dbus_connection_call_sync() for GET_SUPPORTED_SAMPLE_FORMATS error (%s)", err ? err->message : NULL);
+               ret = _convert_dbus_error(err ? err->message : NULL);
+               g_error_free(err);
+               goto LEAVE;
+       }
+
+       g_variant_get(result, "(as)", &iter);
+       if ((iter_num = (unsigned int) g_variant_iter_n_children(iter)) == 0) {
+               LOGE("could not get supported sample formats");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto LEAVE;
+       }
+
+       while (g_variant_iter_loop(iter, "&s", &format_str)) {
+               if (_convert_sample_format_str_to_enum((const char *)format_str, &format))
+                       continue;
+               LOGI("%s(enum:%u) is supported", format_str, format);
+               elem_num++;
+               sm_formats[elem_num - 1] = format;
+       }
+
+       if (elem_num == 0) {
+               LOGE("could not find supported sample formats");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto LEAVE;
+       }
+
+       if (!(*formats = (sound_sample_format_e *) calloc(elem_num, sizeof(sound_sample_format_e)))) {
+               LOGE("failed to calloc(), elem_num(%d)", elem_num);
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto LEAVE;
+       } else {
+               memcpy(*formats, sm_formats, elem_num * sizeof(sound_sample_format_e));
+       }
+
+       *num = elem_num;
+
+LEAVE:
+       g_variant_iter_free(iter);
+       g_variant_unref(result);
+       g_object_unref(conn);
+
+       return ret;
+}
+
+int _set_sample_format(int device_id, sound_sample_format_e format)
+{
+       int ret = MM_ERROR_NONE;
+       GDBusConnection *conn = NULL;
+       GError *err = NULL;
+       char *format_str = NULL;
+
+       if ((ret = __get_dbus_connection(&conn)))
+               return ret;
+
+       if ((ret = _convert_sample_format_enum_to_str(format, &format_str)))
+               return ret;
+
+       g_dbus_connection_call_sync(conn,
+                                               PA_BUS_NAME,
+                                               PA_DEVICE_MANAGER_OBJECT_PATH,
+                                               PA_DEVICE_MANAGER_INTERFACE,
+                                               PA_DEVICE_MANAGER_METHOD_NAME_SET_SAMPLE_FORMAT,
+                                               g_variant_new("(is)", device_id, format_str),
+                                               NULL,
+                                               G_DBUS_CALL_FLAGS_NONE,
+                                               2000,
+                                               NULL,
+                                               &err);
+       if (err) {
+               LOGE("g_dbus_connection_call_sync() for SET_SAMPLE_FORMAT error (%s)", err->message);
+               ret = _convert_dbus_error(err->message);
+               g_error_free(err);
+       }
+
+       g_object_unref(conn);
+
+       return ret;
+}
+
+int _get_sample_format(int device_id, sound_sample_format_e *format)
+{
+       int ret = MM_ERROR_NONE;
+       GVariant *result = NULL;
+       GDBusConnection *conn = NULL;
+       GError *err = NULL;
+       gchar *format_str;
+       sound_sample_format_e format_e;
+
+       SM_NULL_ARG_CHECK_FOR_PRIV(format);
+
+       if ((ret = __get_dbus_connection(&conn)))
+               return ret;
+
+       result = g_dbus_connection_call_sync(conn,
+                                                       PA_BUS_NAME,
+                                                       PA_DEVICE_MANAGER_OBJECT_PATH,
+                                                       PA_DEVICE_MANAGER_INTERFACE,
+                                                       PA_DEVICE_MANAGER_METHOD_NAME_GET_SAMPLE_FORMAT,
+                                                       g_variant_new("(i)", device_id),
+                                                       G_VARIANT_TYPE("(s)"),
+                                                       G_DBUS_CALL_FLAGS_NONE,
+                                                       2000,
+                                                       NULL,
+                                                       &err);
+       if (!result || err) {
+               LOGE("g_dbus_connection_call_sync() for GET_SAMPLE_FORMAT error (%s)", err ? err->message : NULL);
+               ret = _convert_dbus_error(err ? err->message : NULL);
+               g_error_free(err);
+               goto LEAVE;
+       }
+       g_variant_get(result, "(&s)", &format_str);
+       if (_convert_sample_format_str_to_enum((const char *)format_str, &format_e))
+               ret = MM_ERROR_SOUND_INTERNAL;
+       else
+               *format = format_e;
+
+       g_variant_unref(result);
+
+LEAVE:
+       g_object_unref(conn);
+
+       return ret;
+}
+
+#define SM_SAMPLE_RATE_NUM    8 /* check declaration of sound_sample_rate_e */
+int _get_supported_sample_rates(int device_id, sound_sample_rate_e **rates, unsigned int *num)
+{
+       int ret = MM_ERROR_NONE;
+       GVariant *result = NULL;
+       GDBusConnection *conn = NULL;
+       GError *err = NULL;
+       GVariantIter *iter = NULL;
+       unsigned int rate;
+       unsigned int iter_num;
+       unsigned int elem_num = 0;
+       sound_sample_rate_e rate_e;
+       sound_sample_rate_e sm_rates[SM_SAMPLE_RATE_NUM] = {0, };
+
+       SM_NULL_ARG_CHECK_FOR_PRIV(rates);
+       SM_NULL_ARG_CHECK_FOR_PRIV(num);
+
+       if ((ret = __get_dbus_connection(&conn)))
+               return ret;
+
+       result = g_dbus_connection_call_sync(conn,
+                                                       PA_BUS_NAME,
+                                                       PA_DEVICE_MANAGER_OBJECT_PATH,
+                                                       PA_DEVICE_MANAGER_INTERFACE,
+                                                       PA_DEVICE_MANAGER_METHOD_NAME_GET_SUPPORTED_SAMPLE_RATES,
+                                                       g_variant_new("(i)", device_id),
+                                                       G_VARIANT_TYPE("(au)"),
+                                                       G_DBUS_CALL_FLAGS_NONE,
+                                                       2000,
+                                                       NULL,
+                                                       &err);
+       if (!result || err) {
+               LOGE("g_dbus_connection_call_sync() for GET_SUPPORTED_SAMPLE_RATES error (%s)", err ? err->message : NULL);
+               ret = _convert_dbus_error(err ? err->message : NULL);
+               g_error_free(err);
+               goto LEAVE;
+       }
+
+       g_variant_get(result, "(au)", &iter);
+       if ((iter_num = (unsigned int) g_variant_iter_n_children(iter)) == 0) {
+               LOGE("could not get supported sample rates");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto LEAVE;
+       }
+
+       while (g_variant_iter_loop(iter, "u", &rate)) {
+               if (_convert_sample_rate_to_enum(rate, &rate_e))
+                       continue;
+               LOGI("%u(enum:%u) is supported", rate, rate_e);
+               elem_num++;
+               sm_rates[elem_num - 1] = rate_e;
+       }
+
+       if (elem_num == 0) {
+               LOGE("could not find supported sample rates");
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto LEAVE;
+       }
+
+       if (!(*rates = (sound_sample_rate_e *) calloc(elem_num, sizeof(sound_sample_rate_e)))) {
+               LOGE("failed to calloc(), elem_num(%d)", elem_num);
+               ret = MM_ERROR_SOUND_INTERNAL;
+               goto LEAVE;
+       } else {
+               memcpy(*rates, sm_rates, elem_num * sizeof(sound_sample_rate_e));
+       }
+
+       *num = elem_num;
+
+LEAVE:
+       g_variant_iter_free(iter);
+       g_variant_unref(result);
+       g_object_unref(conn);
+
+       return ret;
+}
+
+int _set_sample_rate(int device_id, sound_sample_rate_e rate)
+{
+       int ret = MM_ERROR_NONE;
+       GDBusConnection *conn = NULL;
+       GError *err = NULL;
+       unsigned int _rate;
+
+       if ((ret = __get_dbus_connection(&conn)))
+               return ret;
+
+       if ((ret = _convert_sample_rate_enum_to_uint(rate, &_rate)))
+               return ret;
+
+       g_dbus_connection_call_sync(conn,
+                                               PA_BUS_NAME,
+                                               PA_DEVICE_MANAGER_OBJECT_PATH,
+                                               PA_DEVICE_MANAGER_INTERFACE,
+                                               PA_DEVICE_MANAGER_METHOD_NAME_SET_SAMPLE_RATE,
+                                               g_variant_new("(iu)", device_id, _rate),
+                                               NULL,
+                                               G_DBUS_CALL_FLAGS_NONE,
+                                               2000,
+                                               NULL,
+                                               &err);
+       if (err) {
+               LOGE("g_dbus_connection_call_sync() for SET_SAMPLE_RATE error (%s)", err->message);
+               ret = _convert_dbus_error(err->message);
+               g_error_free(err);
+       }
+
+       g_object_unref(conn);
+
+       return ret;
+}
+
+int _get_sample_rate(int device_id, sound_sample_rate_e *rate)
+{
+       int ret = MM_ERROR_NONE;
+       GVariant *result = NULL;
+       GDBusConnection *conn = NULL;
+       GError *err = NULL;
+       unsigned int _rate;
+       sound_sample_rate_e rate_e;
+
+       SM_NULL_ARG_CHECK_FOR_PRIV(rate);
+
+       if ((ret = __get_dbus_connection(&conn)))
+               return ret;
+
+       result = g_dbus_connection_call_sync(conn,
+                                                       PA_BUS_NAME,
+                                                       PA_DEVICE_MANAGER_OBJECT_PATH,
+                                                       PA_DEVICE_MANAGER_INTERFACE,
+                                                       PA_DEVICE_MANAGER_METHOD_NAME_GET_SAMPLE_RATE,
+                                                       g_variant_new("(i)", device_id),
+                                                       G_VARIANT_TYPE("(u)"),
+                                                       G_DBUS_CALL_FLAGS_NONE,
+                                                       2000,
+                                                       NULL,
+                                                       &err);
+       if (!result || err) {
+               LOGE("g_dbus_connection_call_sync() for GET_SAMPLE_RATE error (%s)", err ? err->message : NULL);
+               ret = _convert_dbus_error(err ? err->message : NULL);
+               g_error_free(err);
+               goto LEAVE;
+       }
+       g_variant_get(result, "(u)", &_rate);
+       if (_convert_sample_rate_to_enum(_rate, &rate_e))
+               ret = MM_ERROR_SOUND_INTERNAL;
+       else
+               *rate = rate_e;
+
+       g_variant_unref(result);
+
+LEAVE:
+       g_object_unref(conn);
+
+       return ret;
+}
+
+int _set_avoid_resampling(int device_id, bool enable)
+{
+       int ret = MM_ERROR_NONE;
+       GDBusConnection *conn = NULL;
+       GError *err = NULL;
+
+       if ((ret = __get_dbus_connection(&conn)))
+               return ret;
+
+       g_dbus_connection_call_sync(conn,
+                                               PA_BUS_NAME,
+                                               PA_DEVICE_MANAGER_OBJECT_PATH,
+                                               PA_DEVICE_MANAGER_INTERFACE,
+                                               PA_DEVICE_MANAGER_METHOD_NAME_SET_AVOID_RESAMPLING,
+                                               g_variant_new("(ib)", device_id, enable),
+                                               NULL,
+                                               G_DBUS_CALL_FLAGS_NONE,
+                                               2000,
+                                               NULL,
+                                               &err);
+       if (err) {
+               LOGE("g_dbus_connection_call_sync() for SET_AVOID_RESAMPLING error (%s)", err->message);
+               ret = _convert_dbus_error(err->message);
+               g_error_free(err);
+       }
+
+       g_object_unref(conn);
+
+       return ret;
+}
+
+int _get_avoid_resampling(int device_id, bool *enabled)
+{
+       int ret = MM_ERROR_NONE;
+       GVariant *result = NULL;
+       GDBusConnection *conn = NULL;
+       GError *err = NULL;
+
+       SM_NULL_ARG_CHECK_FOR_PRIV(enabled);
+
+       if ((ret = __get_dbus_connection(&conn)))
+               return ret;
+
+       result = g_dbus_connection_call_sync(conn,
+                                                       PA_BUS_NAME,
+                                                       PA_DEVICE_MANAGER_OBJECT_PATH,
+                                                       PA_DEVICE_MANAGER_INTERFACE,
+                                                       PA_DEVICE_MANAGER_METHOD_NAME_GET_AVOID_RESAMPLING,
+                                                       g_variant_new("(i)", device_id),
+                                                       G_VARIANT_TYPE("(b)"),
+                                                       G_DBUS_CALL_FLAGS_NONE,
+                                                       2000,
+                                                       NULL,
+                                                       &err);
+       if (!result || err) {
+               LOGE("g_dbus_connection_call_sync() for GET_AVOID_RESAMPLING error (%s)", err ? err->message : NULL);
+               ret = _convert_dbus_error(err ? err->message : NULL);
+               g_error_free(err);
+               goto LEAVE;
+       }
+
+       g_variant_get(result, "(b)", enabled);
+       g_variant_unref(result);
+
+LEAVE:
+       g_object_unref(conn);
+
+       return ret;
+}
+
+int _set_media_stream_only(int device_id, bool enable)
+{
+       int ret = MM_ERROR_NONE;
+       GDBusConnection *conn = NULL;
+       GError *err = NULL;
+       const char *stream_type;
+
+       if ((ret = __get_dbus_connection(&conn)))
+               return ret;
+
+       if (enable)
+               stream_type = "media";
+       else
+               stream_type = "none";
+
+       g_dbus_connection_call_sync(conn,
+                                               PA_BUS_NAME,
+                                               PA_DEVICE_MANAGER_OBJECT_PATH,
+                                               PA_DEVICE_MANAGER_INTERFACE,
+                                               PA_DEVICE_MANAGER_METHOD_NAME_SET_SPECIFIC_STREAM,
+                                               g_variant_new("(is)", device_id, stream_type),
+                                               NULL,
+                                               G_DBUS_CALL_FLAGS_NONE,
+                                               2000,
+                                               NULL,
+                                               &err);
+       if (err) {
+               LOGE("g_dbus_connection_call_sync() for SET_SPECIFIC_STREAM error (%s)", err->message);
+               ret = _convert_dbus_error(err->message);
+               g_error_free(err);
+       }
+
+       g_object_unref(conn);
+
+       return ret;
+}
+
+int _get_media_stream_only(int device_id, bool *enabled)
+{
+       int ret = MM_ERROR_NONE;
+       GVariant *result = NULL;
+       GDBusConnection *conn = NULL;
+       GError *err = NULL;
+       char *stream_type;
+
+       SM_NULL_ARG_CHECK_FOR_PRIV(enabled);
+
+       if ((ret = __get_dbus_connection(&conn)))
+               return ret;
+
+       result = g_dbus_connection_call_sync(conn,
+                                                       PA_BUS_NAME,
+                                                       PA_DEVICE_MANAGER_OBJECT_PATH,
+                                                       PA_DEVICE_MANAGER_INTERFACE,
+                                                       PA_DEVICE_MANAGER_METHOD_NAME_GET_SPECIFIED_STREAM,
+                                                       g_variant_new("(i)", device_id),
+                                                       G_VARIANT_TYPE("(s)"),
+                                                       G_DBUS_CALL_FLAGS_NONE,
+                                                       2000,
+                                                       NULL,
+                                                       &err);
+       if (!result || err) {
+               LOGE("g_dbus_connection_call_sync() for GET_SPECIFIED_STREAM error (%s)", err ? err->message : NULL);
+               ret = _convert_dbus_error(err ? err->message : NULL);
+               g_error_free(err);
+               goto LEAVE;
+       }
+
+       g_variant_get(result, "(&s)", &stream_type);
+       if (!strncmp(stream_type, "media", SOUND_STREAM_TYPE_LEN))
+               *enabled = true;
+       else
+               *enabled = false;
+
+       g_variant_unref(result);
+
+LEAVE:
+       g_object_unref(conn);
+
+       return ret;
+}
+
 int _make_pa_connection_and_register_focus(sound_stream_info_s *stream_h, sound_stream_focus_state_changed_cb callback, void *user_data)
 {
        int ret = MM_ERROR_NONE;
index 5ab49c4..e76047c 100644 (file)
@@ -44,6 +44,16 @@ enum {
        CURRENT_STATUS_GET_DEVICE_NEXT,
        CURRENT_STATUS_GET_DEVICE_PREV,
        CURRENT_STATUS_GET_DEVICE_STATE_BY_ID,
+       CURRENT_STATUS_GET_SUPPORTED_SAMPLE_FORMATS,
+       CURRENT_STATUS_SET_SAMPLE_FORMAT,
+       CURRENT_STATUS_GET_SAMPLE_FORMAT,
+       CURRENT_STATUS_GET_SUPPORTED_SAMPLE_RATES,
+       CURRENT_STATUS_SET_SAMPLE_RATE,
+       CURRENT_STATUS_GET_SAMPLE_RATE,
+       CURRENT_STATUS_SET_AVOID_RESAMPLING,
+       CURRENT_STATUS_GET_AVOID_RESAMPLING,
+       CURRENT_STATUS_SET_MEDIA_STREAM_ONLY,
+       CURRENT_STATUS_GET_MEDIA_STREAM_ONLY,
        CURRENT_STATUS_ADD_DEVICE_CONNECTION_CHANGED_CB,
        CURRENT_STATUS_REMOVE_DEVICE_CONNECTION_CHANGED_CB,
        CURRENT_STATUS_ADD_DEVICE_RUNNING_CHANGED_CB,
@@ -90,6 +100,7 @@ static int g_menu_state = CURRENT_STATUS_MAINMENU;
 
 GMainLoop* g_loop;
 sound_device_list_h g_device_list = NULL;
+sound_device_h g_device = NULL;
 sound_device_mask_e g_device_mask = SOUND_DEVICE_ALL_MASK;
 sound_stream_info_h g_stream_info_h = NULL;
 virtual_sound_stream_h g_vstream_h = NULL;
@@ -195,6 +206,26 @@ void _interpret_main_menu(char *cmd)
                g_menu_state = CURRENT_STATUS_GET_DEVICE_PREV;
        else if (strncmp(cmd, "gd", 3) == 0)
                g_menu_state = CURRENT_STATUS_GET_DEVICE_STATE_BY_ID;
+       else if (strncmp(cmd, "gssf", 4) == 0)
+               g_menu_state = CURRENT_STATUS_GET_SUPPORTED_SAMPLE_FORMATS;
+       else if (strncmp(cmd, "ssf", 3) == 0)
+               g_menu_state = CURRENT_STATUS_SET_SAMPLE_FORMAT;
+       else if (strncmp(cmd, "gsf", 3) == 0)
+               g_menu_state = CURRENT_STATUS_GET_SAMPLE_FORMAT;
+       else if (strncmp(cmd, "gssr", 4) == 0)
+               g_menu_state = CURRENT_STATUS_GET_SUPPORTED_SAMPLE_RATES;
+       else if (strncmp(cmd, "ssr", 3) == 0)
+               g_menu_state = CURRENT_STATUS_SET_SAMPLE_RATE;
+       else if (strncmp(cmd, "gsr", 3) == 0)
+               g_menu_state = CURRENT_STATUS_GET_SAMPLE_RATE;
+       else if (strncmp(cmd, "sar", 3) == 0)
+               g_menu_state = CURRENT_STATUS_SET_AVOID_RESAMPLING;
+       else if (strncmp(cmd, "gar", 3) == 0)
+               g_menu_state = CURRENT_STATUS_GET_AVOID_RESAMPLING;
+       else if (strncmp(cmd, "sms", 3) == 0)
+               g_menu_state = CURRENT_STATUS_SET_MEDIA_STREAM_ONLY;
+       else if (strncmp(cmd, "gms", 3) == 0)
+               g_menu_state = CURRENT_STATUS_GET_MEDIA_STREAM_ONLY;
        else if (strncmp(cmd, "adcc", 4) == 0)
                g_menu_state = CURRENT_STATUS_ADD_DEVICE_CONNECTION_CHANGED_CB;
        else if (strncmp(cmd, "rdcc", 4) == 0)
@@ -308,6 +339,16 @@ void display_sub_basic()
        g_print("gn. Get Next Device\t\t");
        g_print("gp. Get Prev Device\n");
        g_print("gd. *Get Device State by Id\n");
+       g_print("gssf. Get Supported Sample Formats\t");
+       g_print("gssr. Get Supported Sample Rates\n");
+       g_print("ssf. Set Sample Format\t");
+       g_print("ssr. Set Sample Rate\n");
+       g_print("gsf. Get Sample Format\t");
+       g_print("gsr. Get Sample Rate\n");
+       g_print("sar. Set Avoid Resampling\t");
+       g_print("sms. Set Media Stream Only\n");
+       g_print("gar. Get Avoid Resampling\t");
+       g_print("gms. Get Media Stream Only\n");
        g_print("adcc. Add Device Connenection Changed CB\t\t");
        g_print("rdcc. Remove Device Connenection Changed CB\n");
        g_print("adrc. Add Device Running Changed CB\t\t");
@@ -359,7 +400,7 @@ static void displaymenu()
                g_print("*** input sound type(0:SYSTEM 1:NOTIFICATION 2:ALARM 3:RINGTONE 4:MEDIA 5:CALL 6:VOIP 7:VOICE)\n");
        else if (g_menu_state == CURRENT_STATUS_SET_VOLUME) {
                if (flag == 0)
-                       g_print("*** input sound type and desired volume level(0:SYSTEM 1:NOTIFICATION 2:ALARM 3:RINGTONE 4:MEDIA 5:CALL 6:VOIP 7:VOICE, (0~max volum).\n");
+                       g_print("*** input sound type and desired volume level(0:SYSTEM 1:NOTIFICATION 2:ALARM 3:RINGTONE 4:MEDIA 5:CALL 6:VOIP 7:VOICE, (0~max volum))\n");
                flag = 1;
        } else if (g_menu_state == CURRENT_STATUS_GET_VOLUME)
                g_print("*** input sound type(0:SYSTEM 1:NOTIFICATION 2:ALARM 3:RINGTONE 4:MEDIA 5:CALL 6:VOIP 7:VOICE)\n");
@@ -370,7 +411,7 @@ static void displaymenu()
        else if (g_menu_state == CURRENT_STATUS_REMOVE_VOLUME_CHANGED_CB)
                g_print("*** press enter to remove volume changed cb\n");
        else if (g_menu_state == CURRENT_STATUS_SET_DEVICE_MASK)
-               g_print("*** input device mask (0:ALL, 1:INTERNAL, 2:EXTERNAL, 3:INPUT, 4:OUTPUT, 5:BOTH, 6:ACTIVATED, 7:DEACTIVATED, b:back to the menu\n");
+               g_print("*** input device mask (0:ALL, 1:INTERNAL, 2:EXTERNAL, 3:INPUT, 4:OUTPUT, 5:BOTH, 6:ACTIVATED, 7:DEACTIVATED, b:back to the menu)\n");
        else if (g_menu_state == CURRENT_STATUS_GET_DEVICE_MASK)
                g_print("*** press enter to get device mask\n");
        else if (g_menu_state == CURRENT_STATUS_GET_DEVICE_LIST)
@@ -385,6 +426,26 @@ static void displaymenu()
                g_print("*** press enter to get previous device from the list\n");
        else if (g_menu_state == CURRENT_STATUS_GET_DEVICE_STATE_BY_ID)
                g_print("*** press enter device id to get state\n");
+       else if (g_menu_state == CURRENT_STATUS_GET_SUPPORTED_SAMPLE_FORMATS)
+               g_print("*** press enter to get supported sample formats\n");
+       else if (g_menu_state == CURRENT_STATUS_SET_SAMPLE_FORMAT)
+               g_print("*** input sample format (0:u8, 1:s16le, 2:s24le, 3:s24_32le)\n");
+       else if (g_menu_state == CURRENT_STATUS_GET_SAMPLE_FORMAT)
+               g_print("*** press enter to get sample format\n");
+       else if (g_menu_state == CURRENT_STATUS_GET_SUPPORTED_SAMPLE_RATES)
+               g_print("*** press enter to get supported sample rates\n");
+       else if (g_menu_state == CURRENT_STATUS_SET_SAMPLE_RATE)
+               g_print("*** input sample rate (0:8kHz, 1:16KHz, 2:22.05kHz, 3:44.1kHz, 4:48kHz, 5:88.2kHz, 6:96kHz, 7:192kHz)\n");
+       else if (g_menu_state == CURRENT_STATUS_GET_SAMPLE_RATE)
+               g_print("*** press enter to get sample ratet\n");
+       else if (g_menu_state == CURRENT_STATUS_SET_AVOID_RESAMPLING)
+               g_print("*** input avoid resampling (0:disable, 1:enable)\n");
+       else if (g_menu_state == CURRENT_STATUS_GET_AVOID_RESAMPLING)
+               g_print("*** press enter to get avoid resampling\n");
+       else if (g_menu_state == CURRENT_STATUS_SET_MEDIA_STREAM_ONLY)
+               g_print("*** input media stream only (0:disable, 1:enable)\n");
+       else if (g_menu_state == CURRENT_STATUS_GET_MEDIA_STREAM_ONLY)
+               g_print("*** press enter to get media stream only\n");
        else if (g_menu_state == CURRENT_STATUS_ADD_DEVICE_CONNECTION_CHANGED_CB)
                g_print("*** press enter to add device connected cb\n");
        else if (g_menu_state == CURRENT_STATUS_REMOVE_DEVICE_CONNECTION_CHANGED_CB)
@@ -430,7 +491,7 @@ static void displaymenu()
        else if (g_menu_state == CURRENT_STATUS_REMOVE_FOCUS_WATCH_CB)
                g_print("*** input focus watch callback id to remove\n");
        else if (g_menu_state == CURRENT_STATUS_SET_FOCUS_REACQUISITION)
-               g_print("*** input focus reacquisition property (1:enable, 2:disable)\n");
+               g_print("*** input focus reacquisition property (0:disable, 1:enable)\n");
        else if (g_menu_state == CURRENT_STATUS_GET_FOCUS_REACQUISITION)
                g_print("*** press enter to get focus reacquisition property\n");
        else if (g_menu_state == CURRENT_STATUS_GET_REASON_FOR_P_FOCUS)
@@ -772,12 +833,29 @@ static void interpret(char *cmd)
                const char *direc;
                const char *state;
                bool is_running;
+               unsigned int num;
+               sound_sample_format_e *formats;
+               sound_sample_rate_e *rates;
+
                if (!(ret = sound_manager_get_device_list(g_device_mask, &device_list))) {
                        g_print("success to get current device list\n");
                        while (!sound_manager_get_next_device(device_list, &device)) {
                                _get_device_props_simple(device, &id, &type, &name, &direc, &state, &vendor_id, &product_id, &is_running);
                                g_print("[ Device #%d %s %s ]\n", id, type, name);
                                g_print("    Direc[ %-4s ] State[ %-12s ] Running[ %d ] VendorID[ %04x ] ProductID[ %04x ]\n", direc, state, is_running, vendor_id, product_id);
+
+                               if (!(ret = sound_manager_get_supported_sample_formats(device, &formats, &num))) {
+                                       while (num--)
+                                               g_print("format(%u) ", formats[num]);
+                                       g_print("are supported.\n");
+                                       free(formats);
+                               }
+                               if (!(ret = sound_manager_get_supported_sample_rates(device, &rates, &num))) {
+                                       while (num--)
+                                               g_print("rate(%u) ", rates[num]);
+                                       g_print("are supported.\n");
+                                       free(rates);
+                               }
                        }
                } else {
                        g_print("fail to get current device list, ret[0x%x]\n", ret);
@@ -798,24 +876,23 @@ static void interpret(char *cmd)
                break;
        }
        case CURRENT_STATUS_GET_DEVICE_NEXT: {
-               sound_device_h device;
                sound_device_type_e type;
                sound_device_io_direction_e io_direction;
                sound_device_state_e state;
                int id;
                char *name;
                int ret = SOUND_MANAGER_ERROR_NONE;
-               if (!(ret = sound_manager_get_next_device(g_device_list, &device))) {
+               if (!(ret = sound_manager_get_next_device(g_device_list, &g_device))) {
                        g_print("success to get next device\n");
-                       if ((ret = sound_manager_get_device_type(device, &type)))
+                       if ((ret = sound_manager_get_device_type(g_device, &type)))
                                g_print("failed to get device type, ret[0x%x]\n", ret);
-                       if ((ret = sound_manager_get_device_io_direction(device, &io_direction)))
+                       if ((ret = sound_manager_get_device_io_direction(g_device, &io_direction)))
                                g_print("failed to get device io direction, ret[0x%x]\n", ret);
-                       if ((ret = sound_manager_get_device_id(device, &id)))
+                       if ((ret = sound_manager_get_device_id(g_device, &id)))
                                g_print("failed to get device id, ret[0x%x]\n", ret);
-                       if ((ret = sound_manager_get_device_name(device, &name)))
+                       if ((ret = sound_manager_get_device_name(g_device, &name)))
                                g_print("failed to get device name, ret[0x%x]\n", ret);
-                       if ((ret = sound_manager_get_device_state(device, &state)))
+                       if ((ret = sound_manager_get_device_state(g_device, &state)))
                                g_print("failed to get device state, ret[0x%x]\n", ret);
                        if (!ret)
                                g_print("-- NEXT device type[%d], io_direction[%d], id[%d], name[%s], state[%d]\n", type, io_direction, id, name, state);
@@ -826,24 +903,23 @@ static void interpret(char *cmd)
                break;
        }
        case CURRENT_STATUS_GET_DEVICE_PREV: {
-               sound_device_h device;
                sound_device_type_e type;
                sound_device_io_direction_e io_direction;
                sound_device_state_e state;
                int id;
                char *name;
                int ret = SOUND_MANAGER_ERROR_NONE;
-               if (!(ret = sound_manager_get_prev_device(g_device_list, &device))) {
+               if (!(ret = sound_manager_get_prev_device(g_device_list, &g_device))) {
                        g_print("success to get previous device\n");
-                       if ((ret = sound_manager_get_device_type(device, &type)))
+                       if ((ret = sound_manager_get_device_type(g_device, &type)))
                                g_print("failed to get device type, ret[0x%x]\n", ret);
-                       if ((ret = sound_manager_get_device_io_direction(device, &io_direction)))
+                       if ((ret = sound_manager_get_device_io_direction(g_device, &io_direction)))
                                g_print("failed to get device io direction, ret[0x%x]\n", ret);
-                       if ((ret = sound_manager_get_device_id(device, &id)))
+                       if ((ret = sound_manager_get_device_id(g_device, &id)))
                                g_print("failed to get device id, ret[0x%x]\n", ret);
-                       if ((ret = sound_manager_get_device_name(device, &name)))
+                       if ((ret = sound_manager_get_device_name(g_device, &name)))
                                g_print("failed to get device name, ret[0x%x]\n", ret);
-                       if ((ret = sound_manager_get_device_state(device, &state)))
+                       if ((ret = sound_manager_get_device_state(g_device, &state)))
                                g_print("failed to get device state, ret[0x%x]\n", ret);
                        if (!ret)
                                g_print("-- PREV device type[%d], io_direction[%d], id[%d], name[%s], state[%d]\n", type, io_direction, id, name, state);
@@ -868,6 +944,142 @@ static void interpret(char *cmd)
                reset_menu_state();
                break;
        }
+       case CURRENT_STATUS_GET_SUPPORTED_SAMPLE_FORMATS: {
+               int ret = SOUND_MANAGER_ERROR_NONE;
+               unsigned int num = 0;
+               sound_sample_format_e *formats;
+
+               if ((ret = sound_manager_get_supported_sample_formats(g_device, &formats, &num))) {
+                       g_print("failed to get supported sample formats, ret[0x%x]\n", ret);
+               } else {
+                       while (num--)
+                               g_print("sample format(%u) is supported\n", formats[num]);
+                       free(formats);
+               }
+
+               reset_menu_state();
+               break;
+       }
+       case CURRENT_STATUS_SET_SAMPLE_FORMAT: {
+               int ret = SOUND_MANAGER_ERROR_NONE;
+               sound_sample_format_e format;
+
+               format = atoi(cmd);
+
+               if ((ret = sound_manager_set_sample_format(g_device, format)))
+                       g_print("failed to set sample format, ret[0x%x]\n", ret);
+               else
+                       g_print("set sample format(%u)\n", format);
+
+               reset_menu_state();
+               break;
+       }
+       case CURRENT_STATUS_GET_SAMPLE_FORMAT: {
+               int ret = SOUND_MANAGER_ERROR_NONE;
+               sound_sample_format_e format;
+
+               if ((ret = sound_manager_get_sample_format(g_device, &format)))
+                       g_print("failed to get sample format, ret[0x%x]\n", ret);
+               else
+                       g_print("get sample format(%u)\n", format);
+
+               reset_menu_state();
+               break;
+       }
+       case CURRENT_STATUS_GET_SUPPORTED_SAMPLE_RATES: {
+               int ret = SOUND_MANAGER_ERROR_NONE;
+               unsigned int num = 0;
+               sound_sample_rate_e *rates;
+
+               if ((ret = sound_manager_get_supported_sample_rates(g_device, &rates, &num))) {
+                       g_print("failed to get supported sample rates, ret[0x%x]\n", ret);
+               } else {
+                       while (num--)
+                               g_print("sample rate(%u) is supported\n", rates[num]);
+                       free(rates);
+               }
+
+               reset_menu_state();
+               break;
+       }
+       case CURRENT_STATUS_SET_SAMPLE_RATE: {
+               int ret = SOUND_MANAGER_ERROR_NONE;
+               sound_sample_rate_e rate;
+
+               rate = atoi(cmd);
+
+               if ((ret = sound_manager_set_sample_rate(g_device, rate)))
+                       g_print("failed to set sample rate, ret[0x%x]\n", ret);
+               else
+                       g_print("set sample rate(%u)\n", rate);
+
+               reset_menu_state();
+               break;
+       }
+       case CURRENT_STATUS_GET_SAMPLE_RATE: {
+               int ret = SOUND_MANAGER_ERROR_NONE;
+               sound_sample_rate_e rate;
+
+               if ((ret = sound_manager_get_sample_rate(g_device, &rate)))
+                       g_print("failed to get sample format, ret[0x%x]\n", ret);
+               else
+                       g_print("get sample rate(%u)\n", rate);
+
+               reset_menu_state();
+               break;
+       }
+       case CURRENT_STATUS_SET_AVOID_RESAMPLING: {
+               int ret = SOUND_MANAGER_ERROR_NONE;
+               bool enable;
+
+               enable = atoi(cmd);
+
+               if ((ret = sound_manager_set_avoid_resampling(g_device, enable)))
+                       g_print("failed to set avoid resampling, ret[0x%x]\n", ret);
+               else
+                       g_print("set avoid resampling(%d)\n", enable);
+
+               reset_menu_state();
+               break;
+       }
+       case CURRENT_STATUS_GET_AVOID_RESAMPLING: {
+               int ret = SOUND_MANAGER_ERROR_NONE;
+               bool enabled;
+
+               if ((ret = sound_manager_get_avoid_resampling(g_device, &enabled)))
+                       g_print("failed to get avoid resampling, ret[0x%x]\n", ret);
+               else
+                       g_print("get avoid resampling(%d)\n", enabled);
+
+               reset_menu_state();
+               break;
+       }
+       case CURRENT_STATUS_SET_MEDIA_STREAM_ONLY: {
+               int ret = SOUND_MANAGER_ERROR_NONE;
+               bool enable;
+
+               enable = atoi(cmd);
+
+               if ((ret = sound_manager_set_media_stream_only(g_device, enable)))
+                       g_print("failed to set media stream only, ret[0x%x]\n", ret);
+               else
+                       g_print("set media stream only(%d)\n", enable);
+
+               reset_menu_state();
+               break;
+       }
+       case CURRENT_STATUS_GET_MEDIA_STREAM_ONLY: {
+               int ret = SOUND_MANAGER_ERROR_NONE;
+               bool enabled;
+
+               if ((ret = sound_manager_get_media_stream_only(g_device, &enabled)))
+                       g_print("failed to get media stream only, ret[0x%x]\n", ret);
+               else
+                       g_print("get media stream only(%d)\n", enabled);
+
+               reset_menu_state();
+               break;
+       }
        case CURRENT_STATUS_ADD_DEVICE_CONNECTION_CHANGED_CB: {
                if (sound_manager_add_device_connection_changed_cb(g_device_mask, _device_connected_cb, NULL, &g_device_conn_cb_id))
                        g_print("fail to add device connection changed cb\n");
@@ -1567,17 +1779,8 @@ static void interpret(char *cmd)
                int ret = SOUND_MANAGER_ERROR_NONE;
                bool enable;
 
-               switch (atoi(cmd)) {
-               case 1: /* enable */
-                       enable = true;
-                       break;
-               case 2: /* disable */
-                       enable = false;
-                       break;
-               default:
-                       enable = true;
-                       break;
-               }
+               enable = atoi(cmd);
+
                ret = sound_manager_set_focus_reacquisition(g_stream_info_h, enable);
                if (ret)
                        g_print("fail to sound_manager_set_focus_reacquisition, ret(0x%x)\n", ret);