From: Seungbae Shin Date: Thu, 6 Oct 2022 11:46:37 +0000 (+0900) Subject: Add internal APIs to query additional device information X-Git-Tag: accepted/tizen/unified/20221102.020518^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=01e6a12f3fe01afd873b72a716ceca4287307ac6;p=platform%2Fcore%2Fapi%2Fsound-manager.git Add internal APIs to query additional device information - 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 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 248a0f7..8307a5f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12) -SET(Services +SET(Services "application" "base" "content" diff --git a/include/sound_manager_internal.h b/include/sound_manager_internal.h index cee7e34..39b2c57 100644 --- a/include/sound_manager_internal.h +++ b/include/sound_manager_internal.h @@ -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); + /** * @} */ diff --git a/include/sound_manager_internal_tv.h b/include/sound_manager_internal_tv.h index d858ce6..3b117b6 100644 --- a/include/sound_manager_internal_tv.h +++ b/include/sound_manager_internal_tv.h @@ -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); /** * @} diff --git a/include/sound_manager_private.h b/include/sound_manager_private.h index 1be415f..d8a4c9e 100644 --- a/include/sound_manager_private.h +++ b/include/sound_manager_private.h @@ -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); diff --git a/packaging/capi-media-sound-manager.spec b/packaging/capi-media-sound-manager.spec index a4b567e..43f922f 100644 --- a/packaging/capi-media-sound-manager.spec +++ b/packaging/capi-media-sound-manager.spec @@ -1,6 +1,6 @@ Name: capi-media-sound-manager Summary: Sound Manager library -Version: 0.7.0 +Version: 0.7.1 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/sound_manager_internal.c b/src/sound_manager_internal.c index eeb244d..1c78a10 100644 --- a/src/sound_manager_internal.c +++ b/src/sound_manager_internal.c @@ -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; diff --git a/src/sound_manager_private.c b/src/sound_manager_private.c index 4adc4dd..ef52fe8 100644 --- a/src/sound_manager_private.c +++ b/src/sound_manager_private.c @@ -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; diff --git a/test/sound_manager_test.c b/test/sound_manager_test.c index 3f1e53d..ca21a20 100644 --- a/test/sound_manager_test.c +++ b/test/sound_manager_test.c @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -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(" => [ ");