Add internal APIs to query additional device information 17/282617/7 accepted/tizen/unified/20221102.020518
authorSeungbae Shin <seungbae.shin@samsung.com>
Thu, 6 Oct 2022 11:46:37 +0000 (20:46 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Mon, 17 Oct 2022 07:38:49 +0000 (16:38 +0900)
- sound_manager_get_device_sample_format()
- sound_manager_get_device_sample_rate()
- sound_manager_get_device_channels()

In addition, CMake warning related to minimum required version is also fixed.

[Version] 0.7.1
[Issue Type] Internal API

Change-Id: I489225ec19e56a2882a4eb514e1b67583f84f04e

CMakeLists.txt
include/sound_manager_internal.h
include/sound_manager_internal_tv.h
include/sound_manager_private.h
packaging/capi-media-sound-manager.spec
src/sound_manager_internal.c
src/sound_manager_private.c
test/sound_manager_test.c

index 248a0f73f1de772a0fbcb7363eb6a22fb5f324fa..8307a5f9994d435ba6e8d02aa75e9e9e321c349b 100644 (file)
@@ -1,6 +1,6 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
 
-SET(Services 
+SET(Services
         "application"
         "base"
         "content"
index cee7e34f742738531337dedbbd45914549aa141d..39b2c57268d5ae5029864ac1edbed8296db2bead 100644 (file)
@@ -1302,6 +1302,78 @@ int sound_manager_set_host_volume(sound_type_e type, int volume);
  */
 int sound_manager_get_host_volume(sound_type_e type, int *volume);
 
+/**
+ * @internal
+ * @brief Gets the sample format of the device.
+ * @since_tizen 7.0
+ *
+ * @param[in]  device  The device item
+ * @param[out] format  The sample format of the device
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #SOUND_MANAGER_ERROR_NONE Success
+ * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see sound_manager_get_device_list()
+ * @see sound_manager_get_next_device()
+ * @see sound_manager_get_prev_device()
+ * @see sound_manager_get_device_type()
+ * @see sound_manager_get_device_io_direction()
+ * @see sound_manager_get_device_name()
+ * @see sound_manager_get_device_id()
+ * @see sound_manager_get_device_sample_rate()
+ * @see sound_manager_get_device_channels()
+ * @see sound_manager_free_device_list()
+ */
+int sound_manager_get_device_sample_format(sound_device_h device, sound_sample_format_e *format);
+
+/**
+ * @internal
+ * @brief Gets the sample rate of the device.
+ * @since_tizen 7.0
+ *
+ * @param[in]  device  The device item
+ * @param[out] samplerate      The sample rate of the device
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #SOUND_MANAGER_ERROR_NONE Success
+ * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see sound_manager_get_device_list()
+ * @see sound_manager_get_next_device()
+ * @see sound_manager_get_prev_device()
+ * @see sound_manager_get_device_type()
+ * @see sound_manager_get_device_io_direction()
+ * @see sound_manager_get_device_name()
+ * @see sound_manager_get_device_id()
+ * @see sound_manager_get_device_sample_format()
+ * @see sound_manager_get_device_channels()
+ * @see sound_manager_free_device_list()
+ */
+int sound_manager_get_device_sample_rate(sound_device_h device, sound_sample_rate_e *samplerate);
+
+/**
+ * @internal
+ * @brief Gets the number of channels of the device.
+ * @since_tizen 7.0
+ *
+ * @param[in]  device  The device item
+ * @param[out] channels        The number of the channels of the device
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #SOUND_MANAGER_ERROR_NONE Success
+ * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see sound_manager_get_device_list()
+ * @see sound_manager_get_next_device()
+ * @see sound_manager_get_prev_device()
+ * @see sound_manager_get_device_type()
+ * @see sound_manager_get_device_io_direction()
+ * @see sound_manager_get_device_name()
+ * @see sound_manager_get_device_id()
+ * @see sound_manager_get_device_sample_format()
+ * @see sound_manager_get_device_sample_rate()
+ * @see sound_manager_free_device_list()
+ */
+int sound_manager_get_device_channels(sound_device_h device, int *channels);
+
 /**
  * @}
  */
index d858ce69a2598b4cc5bd151aff61d73749bc6b98..3b117b65a763143e0d7a09600f63b0bb7ee05f40 100644 (file)
@@ -1136,6 +1136,24 @@ int sound_manager_set_remote_permission(int id, bool allowed);
  */
 int sound_manager_start_discover_remote_device(void);
 
+/**
+ * @internal
+ * @brief Stops discovering of published remote devices on the local network.
+ * @since_tizen 6.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #SOUND_MANAGER_ERROR_NONE Success
+ * @retval #SOUND_MANAGER_ERROR_NOT_SUPPORTED Not supported
+ * @retval #SOUND_MANAGER_ERROR_PERMISSION_DENIED Permission denied
+ * @retval #SOUND_MANAGER_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
+ * @pre You should start discovering by sound_manager_start_discover_remote_device().
+ * @see sound_manager_start_discover_remote_device()
+ */
+int sound_manager_stop_discover_remote_device(void);
+
 /**
  * @internal
  * @brief Sets acoustic echo cancellation reference device
@@ -1178,24 +1196,85 @@ int sound_manager_set_echo_cancel_reference_device(sound_stream_info_h stream_in
  */
 int sound_manager_get_echo_cancel_reference_device(sound_stream_info_h stream_info, int *device_id);
 
-
 /**
  * @internal
- * @brief Stops discovering of published remote devices on the local network.
- * @since_tizen 6.0
- * @privlevel public
- * @privilege %http://tizen.org/privilege/internet
+ * @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_NOT_SUPPORTED Not supported
- * @retval #SOUND_MANAGER_ERROR_PERMISSION_DENIED Permission denied
- * @retval #SOUND_MANAGER_ERROR_INVALID_OPERATION Invalid operation
+ * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
  * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
- * @pre You should start discovering by sound_manager_start_discover_remote_device().
- * @see sound_manager_start_discover_remote_device()
  */
-int sound_manager_stop_discover_remote_device(void);
+int sound_manager_get_host_volume(sound_type_e type, int *volume);
+
+/**
+ * @internal
+ * @brief Gets the sample format of the device.
+ * @since_tizen 7.0
+ *
+ * @param[in]  device  The device item
+ * @param[out] format  The sample format of the device
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #SOUND_MANAGER_ERROR_NONE Success
+ * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see sound_manager_get_device_list()
+ * @see sound_manager_get_next_device()
+ * @see sound_manager_get_prev_device()
+ * @see sound_manager_get_device_type()
+ * @see sound_manager_get_device_io_direction()
+ * @see sound_manager_get_device_name()
+ * @see sound_manager_get_device_id()
+ * @see sound_manager_free_device_list()
+ */
+int sound_manager_get_device_sample_format(sound_device_h device, sound_sample_format_e *format);
+
+/**
+ * @internal
+ * @brief Gets the sample rate of the device.
+ * @since_tizen 7.0
+ *
+ * @param[in]  device  The device item
+ * @param[out] samplerate      The sample rate of the device
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #SOUND_MANAGER_ERROR_NONE Success
+ * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see sound_manager_get_device_list()
+ * @see sound_manager_get_next_device()
+ * @see sound_manager_get_prev_device()
+ * @see sound_manager_get_device_type()
+ * @see sound_manager_get_device_io_direction()
+ * @see sound_manager_get_device_name()
+ * @see sound_manager_get_device_id()
+ * @see sound_manager_free_device_list()
+ */
+int sound_manager_get_device_sample_rate(sound_device_h device, sound_sample_rate_e *samplerate);
+
+/**
+ * @internal
+ * @brief Gets the number of channels of the device.
+ * @since_tizen 7.0
+ *
+ * @param[in]  device  The device item
+ * @param[out] channels        The number of the channels of the device
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #SOUND_MANAGER_ERROR_NONE Success
+ * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @see sound_manager_get_device_list()
+ * @see sound_manager_get_next_device()
+ * @see sound_manager_get_prev_device()
+ * @see sound_manager_get_device_type()
+ * @see sound_manager_get_device_io_direction()
+ * @see sound_manager_get_device_name()
+ * @see sound_manager_get_device_id()
+ * @see sound_manager_free_device_list()
+ */
+int sound_manager_get_device_channels(sound_device_h device, int *channels);
 
 /**
  * @}
index 1be415fa66df74d5b6965d33e3f560b95f95fb5d..d8a4c9e7a2862907ed50edca4d1af4959aebe396 100644 (file)
@@ -277,6 +277,14 @@ int _convert_device_type_str_to_enum(const char *device_type_str, sound_device_t
 
 int _convert_device_io_direction(mm_sound_device_io_direction_e io_direction, sound_device_io_direction_e *device_io_direction);
 
+int _convert_sample_rate_to_enum(unsigned int rate, sound_sample_rate_e *rate_e);
+
+int _convert_sample_rate_enum_to_uint(sound_sample_rate_e rate, unsigned int *sample_rate);
+
+int _convert_sample_format_str_to_enum(const char *format_str, sound_sample_format_e *format);
+
+int _convert_sample_format_enum_to_str(sound_sample_format_e format, const char **format_str);
+
 const char* _convert_api_name(native_api_e api_name);
 
 int _return_val_if_not_usb_device(sound_device_h device, int ret_val);
index a4b567e0e4b69eaecb7473d1e8ade4786d53b136..43f922fc9759e868b9346a09dfa2e53089ac2ac2 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-sound-manager
 Summary:    Sound Manager library
-Version:    0.7.0
+Version:    0.7.1
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index eeb244dff20b5c1192432fbd0452d9cbb875d2d5..1c78a10cd98d2bd33661385cbaf7018265c8920c 100644 (file)
@@ -794,6 +794,62 @@ int sound_manager_get_device_product_id(sound_device_h device, int *product_id)
        return _convert_sound_manager_error_code(__func__, ret);
 }
 
+int sound_manager_get_device_sample_format(sound_device_h device, sound_sample_format_e *format)
+{
+       int ret = MM_ERROR_NONE;
+       int _format = 0;
+
+       SM_ARG_CHECK(device);
+       SM_ARG_CHECK(format);
+
+       LOGI("device[%p]", device);
+
+       if ((ret = mm_sound_get_device_sample_format(device, &_format)) != MM_ERROR_NONE)
+               return _convert_sound_manager_error_code(__func__, ret);
+
+       ret = _convert_sample_format_str_to_enum(pa_sample_format_to_string(_format), format);
+
+       LOGI("sample_format [%d]", *format);
+
+       return _convert_sound_manager_error_code(__func__, ret);
+}
+
+int sound_manager_get_device_sample_rate(sound_device_h device, sound_sample_rate_e *samplerate)
+{
+       int ret = MM_ERROR_NONE;
+       int _samplerate = 0;
+
+       SM_ARG_CHECK(device);
+       SM_ARG_CHECK(samplerate);
+
+       LOGI("device[%p]", device);
+
+       if ((ret = mm_sound_get_device_sample_rate(device, &_samplerate)) != MM_ERROR_NONE)
+               return _convert_sound_manager_error_code(__func__, ret);
+
+       ret = _convert_sample_rate_to_enum(_samplerate, samplerate);
+
+       LOGI("sample_rate [%d]", *samplerate);
+
+       return _convert_sound_manager_error_code(__func__, ret);
+}
+
+int sound_manager_get_device_channels(sound_device_h device, int *channels)
+{
+       int ret = MM_ERROR_NONE;
+
+       SM_ARG_CHECK(device);
+       SM_ARG_CHECK(channels);
+
+       LOGI("device[%p]", device);
+
+       ret = mm_sound_get_device_channels(device, channels);
+
+       LOGI("channels [%d]", *channels);
+
+       return _convert_sound_manager_error_code(__func__, ret);
+}
+
 int sound_manager_is_stream_on_device_by_id(sound_stream_info_h stream_info, int device_id, bool *is_on)
 {
        int ret = MM_ERROR_NONE;
index 4adc4dd580a85aedeed5b633d95960319163a007..ef52fe808518c8ba0be9eb9355bc7a5e3b8f1954 100644 (file)
@@ -667,7 +667,7 @@ const char* _convert_api_name(native_api_e api_name)
        }
 }
 
-int _convert_sample_format_enum_to_str(sound_sample_format_e format, char **format_str)
+int _convert_sample_format_enum_to_str(sound_sample_format_e format, const char **format_str)
 {
        SM_ARG_CHECK(format_str);
 
@@ -1695,7 +1695,7 @@ int _set_sample_format(int device_id, sound_sample_format_e format)
        GDBusConnection *conn = NULL;
        GVariant *result = NULL;
        GError *err = NULL;
-       char *format_str = NULL;
+       const char *format_str = NULL;
 
        if ((ret = __get_dbus_connection(&conn)) != SOUND_MANAGER_ERROR_NONE)
                return ret;
index 3f1e53d18634c6a50393900f632fa6837abab20a..ca21a2036b77b3058971c541acaa218985a0baf9 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdlib.h>
 
 #include <sound_manager.h>
+#include <sound_manager_private.h>
 #include <sound_manager_internal.h>
 #include <mm_sound.h>
 #include <pthread.h>
@@ -139,6 +140,7 @@ int g_internal_volume_cb_id;
 int g_device_conn_cb_id;
 int g_device_running_cb_id;
 
+static const char g_running_str[] = { 'x', 'o' };
 static const char *g_device_direction_str[] = {"IN", "OUT", "BOTH"};
 static const char *g_device_type_str[] = {"builtin-speaker", "builtin-receiver", "builtin-mic",
                                                        "audio-jack", "bt-media", "hdmi",
@@ -799,7 +801,8 @@ void _volume_changed_cb_internal(sound_type_internal_e type, unsigned int volume
 
 /* If failed to get some property, just give some default value */
 void _get_device_props_simple(sound_device_h device, int *id, const char **type, char **name,
-               const char **direction, int *vendor_id, int *product_id, bool *is_running)
+               const char **direction, int *vendor_id, int *product_id, bool *is_running,
+               sound_sample_format_e *format, sound_sample_rate_e *samplerate, int *channels)
 {
        int ret;
        sound_device_type_e _type;
@@ -843,6 +846,15 @@ void _get_device_props_simple(sound_device_h device, int *id, const char **type,
        } else {
                *is_running = running;
        }
+
+       if ((ret = sound_manager_get_device_sample_format(device, format)))
+               g_print("failed to get sample format, ret[0x%x]\n", ret);
+
+       if ((ret = sound_manager_get_device_sample_rate(device, samplerate)))
+               g_print("failed to get samplerate, ret[0x%x]\n", ret);
+
+       if ((ret = sound_manager_get_device_channels(device, channels)))
+               g_print("failed to get channels, ret[0x%x]\n", ret);
 }
 
 void _device_connected_cb(sound_device_h device, bool is_connected, void *user_data)
@@ -853,12 +865,15 @@ void _device_connected_cb(sound_device_h device, bool is_connected, void *user_d
        char *name;
        const char *type, *direction;
        bool is_running = false;
+       sound_sample_format_e format;
+       sound_sample_rate_e samplerate = -1;
+       int channels = 0;
 
-       _get_device_props_simple(device, &id, &type, &name, &direction, &vendor_id, &product_id, &is_running);
+       _get_device_props_simple(device, &id, &type, &name, &direction, &vendor_id, &product_id, &is_running, &format, &samplerate, &channels);
 
        g_print("\n[ Device #%d %-20s ] %15s : ", id, type, is_connected ? "Connected" : "Disconnected");
-       g_print("Direction[%-4s] Running[%d] Vendor/Product ID[%04x/%04x] Name[%s]\n",
-            direction, is_running, vendor_id, product_id, name);
+       g_print("Direction[%-4s] Running[%d] Format[%d], Samplerate[%d] Channels[%d] Vendor/Product ID[%04x/%04x] Name[%s]\n",
+                       direction, is_running, format, samplerate, channels, vendor_id, product_id, name);
 }
 
 void _device_running_changed_cb(sound_device_h device, bool is_running, void *user_data)
@@ -869,12 +884,15 @@ void _device_running_changed_cb(sound_device_h device, bool is_running, void *us
        char *name;
        const char *type, *direction;
        bool _is_running = false;
+       sound_sample_format_e format;
+       sound_sample_rate_e samplerate = -1;
+       int channels = 0;
 
-       _get_device_props_simple(device, &id, &type, &name, &direction, &vendor_id, &product_id, &_is_running);
+       _get_device_props_simple(device, &id, &type, &name, &direction, &vendor_id, &product_id, &_is_running, &format, &samplerate, &channels);
 
        g_print("\n[ Device #%d %-20s ] running changed to [%d] : ", id, type, is_running);
-       g_print("Direction [%-4s] Running[%d] Vendor/Product ID[%04x/%04x] Name[%s]\n",
-            direction, is_running, vendor_id, product_id, name);
+       g_print("Direction[%-4s] Running[%d] Format[%d], Samplerate[%d] Channels[%d] Vendor/Product ID[%04x/%04x] Name[%s]\n",
+                       direction, is_running, format, samplerate, channels, vendor_id, product_id, name);
 }
 
 void reset_menu_state(void)
@@ -1144,13 +1162,25 @@ static void interpret(char *cmd)
                sound_sample_format_e *formats;
                sound_sample_rate_e *rates;
 
+               sound_sample_format_e format;
+               const char *format_str = NULL;
+               sound_sample_rate_e samplerate = -1;
+               unsigned int samplerate_num = 0;
+               int channels = 0;
+
                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, &direction, &vendor_id, &product_id, &is_running);
+                               _get_device_props_simple(device, &id, &type, &name, &direction, &vendor_id, &product_id, &is_running, &format, &samplerate, &channels);
+
+                               if ((ret = _convert_sample_format_enum_to_str(format, &format_str)))
+                                       g_print("failed to convert format to string, ret[0x%x]\n", ret);
+                               if ((ret = _convert_sample_rate_enum_to_uint(samplerate, &samplerate_num)))
+                                       g_print("failed to convert samplerate to uint, ret[0x%x]\n", ret);
+
                                g_print("[ Device #%d %-20s ] : ", id, type);
-                               g_print("Direction[%-4s] Running[%d] Vendor/Product ID[%04x/%04x] Name[%s] \n",
-                                               direction, is_running, vendor_id, product_id, name);
+                               g_print("Direction[%-4s] Running[%c] Format[%d][%s] SampleRate[%d][%u] Channels[%d] ID(Vendor/Product)[%04x/%04x] Name[%s] \n",
+                                               direction, g_running_str[is_running], format, format_str, samplerate, samplerate_num, channels, vendor_id, product_id, name);
 
                                if (!(ret = sound_manager_get_supported_sample_formats(device, &formats, &num))) {
                                        g_print(" => [ ");