From: Jaechul Lee Date: Tue, 4 Jul 2023 07:50:18 +0000 (+0900) Subject: Add new public APIs to set effect method X-Git-Tag: accepted/tizen/unified/20230719.170106^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=30c178eb66e6ce35da2739fcf5afc618fbc673f2;p=platform%2Fcore%2Fapi%2Fsound-manager.git Add new public APIs to set effect method Preprocesing functionality was added. There were two pair of functions for supporting audio effects such as noise-suppression and acoustic echo cancellation. - sound_manager_set_effect_method_with_reference - sound_manager_get_effect_method_with_reference - sound_manager_set_effect_method - sound_manager_get_effect_method [Version] 0.7.9 [Issue Type] Public API Change-Id: I28026a39615fed8790f1f2b3f3e062d417c56750 Signed-off-by: Jaechul Lee --- diff --git a/include/sound_manager.h b/include/sound_manager.h index 186c1f1..25b4063 100644 --- a/include/sound_manager.h +++ b/include/sound_manager.h @@ -255,6 +255,34 @@ typedef enum { SOUND_SAMPLE_RATE_192000, /**< 192000 Hz sample rate */ } sound_sample_rate_e; +/** + * @} + */ + +/** + * @addtogroup CAPI_MEDIA_SOUND_MANAGER_STREAM_POLICY_MODULE + * @{ + */ + +/** +* @brief Enumeration for sound effects that need a reference device. +* @since_tizen 8.0 +*/ +typedef enum { + SOUND_EFFECT_REFERENCE_COPY = 0x0001, /**< Including reference source */ + SOUND_EFFECT_ACOUSTIC_ECHO_CANCEL_SPEEX = 0x0002, /**< Acoustic echo cancel with speex */ + SOUND_EFFECT_ACOUSTIC_ECHO_CANCEL_WEBRTC = 0x0004, /**< Acoustic echo cancel with webrtc */ +} sound_effect_method_with_reference_e; + +/** +* @brief Enumeration for sound effects. +* @since_tizen 8.0 +*/ +typedef enum { + SOUND_EFFECT_NOISE_SUPPRESSION_VOIP = 0x0001, /**< Noise suppression for voice call */ + SOUND_EFFECT_AUTOMATIC_GAIN_CONTROL_CAPTURE = 0x0002, /**< Auto Gain Control for normal capturing */ +} sound_effect_method_e; + /** * @} */ @@ -1633,6 +1661,79 @@ int sound_manager_add_device_running_changed_cb(int device_mask, sound_device_ru */ int sound_manager_remove_device_running_changed_cb(int id); +/** + * @addtogroup CAPI_MEDIA_SOUND_MANAGER_STREAM_POLICY_MODULE + * @{ + */ + +/** + * @brief Sets sound effect methods that must need a reference device such as acoustic echo cancellation. + * @since_tizen 8.0 + * @param[in] stream_info The handle of stream information + * @param[in] method The method of #sound_effect_method_with_reference_e + * @param[in] device The reference 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 + * @retval #SOUND_MANAGER_ERROR_POLICY Noncompliance with the sound system policy + * @pre Get a device by calling sound_manager_get_device_list() and sound_manager_get_next_device(). + * @see sound_manager_create_stream_information() + * @see sound_manager_set_effect_method() + * @see sound_manager_get_effect_method_with_reference() + */ +int sound_manager_set_effect_method_with_reference(sound_stream_info_h stream_info, sound_effect_method_with_reference_e method, sound_device_h device); + +/** + * @brief Gets sound effect methods that must need a reference device such as acoustic echo cancellation. + * @since_tizen 8.0 + * @param[in] stream_info The handle of stream information + * @param[out] method The method of #sound_effect_method_with_reference_e + * @param[out] device_id The reference device id + * @return @c 0 on success, + * otherwise a negative error value + * @retval #SOUND_MANAGER_ERROR_NONE Success + * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SOUND_MANAGER_ERROR_INVALID_OPERATION Invalid operation + * @see sound_manager_create_stream_information() + * @see sound_manager_set_effect_method_with_reference() + */ +int sound_manager_get_effect_method_with_reference(sound_stream_info_h stream_info, sound_effect_method_with_reference_e *method, int *device_id); + +/** + * @brief Sets sound effect methods. + * @since_tizen 8.0 + * @param[in] stream_info The handle of stream information + * @param[in] method The methods of #sound_effect_method_e, values of #sound_effect_method_e combined with bitwise 'or' + * @return @c 0 on success, + * otherwise a negative error value + * @retval #SOUND_MANAGER_ERROR_NONE Success + * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #SOUND_MANAGER_ERROR_POLICY Noncompliance with the sound system policy + * @see sound_manager_create_stream_information() + * @see sound_manager_set_effect_method_with_reference() + */ +int sound_manager_set_effect_method(sound_stream_info_h stream_info, int method); + +/** + * @brief Gets sound effect methods. + * @since_tizen 8.0 + * @param[in] stream_info The handle of stream information + * @param[out] method The methods of #sound_effect_method_e, values of #sound_effect_method_e combined with bitwise 'or' + * @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 + * @see sound_manager_create_stream_information() + * @see sound_manager_set_effect_method() + */ +int sound_manager_get_effect_method(sound_stream_info_h stream_info, int *method); + +/** + * @} + */ + /** * @} */ diff --git a/include/sound_manager_internal.h b/include/sound_manager_internal.h index 5444555..d20e124 100644 --- a/include/sound_manager_internal.h +++ b/include/sound_manager_internal.h @@ -163,6 +163,15 @@ typedef enum { SOUND_NOISE_SUPPRESSION_VOICE_RECOGNITION, } sound_noise_suppression_type_e; +/** +* @brief Enumeration for sound effects. +* @since_tizen 8.0 +*/ +typedef enum { + SOUND_EFFECT_NOISE_SUPPRESSION_DOORBELL = 0x0100, /**< Noise suppression for doorbell */ + SOUND_EFFECT_NOISE_SUPPRESSION_VOICE_RECOGNITION = 0x0200, /**< Noise suppression for voice recognition */ +} sound_effect_method_internal_e; + /** * @internal * @brief Gets the maximum master volume level. diff --git a/include/sound_manager_private.h b/include/sound_manager_private.h index 53c897f..88bb0e1 100644 --- a/include/sound_manager_private.h +++ b/include/sound_manager_private.h @@ -196,6 +196,12 @@ typedef struct _preferred_device_info_s { int out; } preferred_device_info_s; +typedef struct _sound_effect { + sound_effect_method_with_reference_e reference_method; + int method; + int reference_device_id; +} sound_effect_s; + typedef struct _virtual_stream_info_s virtual_sound_stream_info_s; typedef struct _sound_stream_info_s { @@ -215,6 +221,7 @@ typedef struct _sound_stream_info_s { sound_acoustic_echo_cancel_type_e echo_cancel_type; bool noise_suppression_enable; sound_noise_suppression_type_e noise_suppression_type; + sound_effect_s sound_effect; pthread_mutex_t focus_state_mutex; pthread_mutex_t focus_cb_mutex; pthread_mutex_t vstream_mutex; @@ -418,6 +425,14 @@ int _set_host_volume_level(const char *direction, const char *volume_type, unsig int _get_host_volume_level(const char *direction, const char *volume_type, unsigned int *level); +int _set_effect_method_with_reference(sound_stream_info_h stream_info, sound_effect_method_with_reference_e method, sound_device_h device); + +int _get_effect_method_with_reference(sound_stream_info_h stream_info, sound_effect_method_with_reference_e *method, int *device_id); + +int _set_effect_method(sound_stream_info_h stream_info, int method); + +int _get_effect_method(sound_stream_info_h stream_info, int *method); + #ifdef __cplusplus } #endif diff --git a/packaging/capi-media-sound-manager.spec b/packaging/capi-media-sound-manager.spec index 9b12a0d..21d930d 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.8 +Version: 0.7.9 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/sound_manager.c b/src/sound_manager.c index 10b5144..0c5fa1e 100644 --- a/src/sound_manager.c +++ b/src/sound_manager.c @@ -1443,3 +1443,24 @@ int sound_manager_deactivate_ducking(sound_stream_ducking_h stream_ducking) return ret; } + +int sound_manager_set_effect_method_with_reference(sound_stream_info_h stream_info, sound_effect_method_with_reference_e method, sound_device_h device) +{ + return _set_effect_method_with_reference(stream_info, method, device); +} + +int sound_manager_get_effect_method_with_reference(sound_stream_info_h stream_info, sound_effect_method_with_reference_e *method, int *device_id) +{ + return _get_effect_method_with_reference(stream_info, method, device_id); +} + +int sound_manager_set_effect_method(sound_stream_info_h stream_info, int method) +{ + return _set_effect_method(stream_info, method); +} + +int sound_manager_get_effect_method(sound_stream_info_h stream_info, int *method) +{ + return _get_effect_method(stream_info, method); +} + diff --git a/src/sound_manager_private.c b/src/sound_manager_private.c index d2e58cd..ea252c6 100644 --- a/src/sound_manager_private.c +++ b/src/sound_manager_private.c @@ -107,6 +107,9 @@ if (!strncmp(x_sound_type, "system", strlen(x_sound_type)) || \ if (!strncmp(x_sound_type, "bixby", strlen(x_sound_type))) \ return x_error; \ +#define SOUND_MANAGER_STREAM_NO_METHOD 0 +#define SOUND_MANAGER_STREAM_NO_REFERENCE_DEVICE 0 + //LCOV_EXCL_START int _convert_dbus_error(const char *error_msg) { @@ -3929,4 +3932,107 @@ int _get_host_volume_level(const char *direction, const char *volume_type, unsig return ret; } + +int _set_effect_method_with_reference(sound_stream_info_h stream_info, sound_effect_method_with_reference_e method, sound_device_h device) +{ + sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info; + + int ret; + int device_id; + char *device_name; + + SM_ARG_CHECK(stream_h); + SM_ARG_CHECK(device); + + if (!stream_h->stream_conf_info.avail_in_devices[0]) { + LOGE("stream_h[%p, %s] does not support any input devices", stream_h, stream_h->stream_type); + return SOUND_MANAGER_ERROR_POLICY; + } + + if ((ret = mm_sound_get_device_id(device, &device_id)) != MM_ERROR_NONE) + return _convert_sound_manager_error_code(__func__, ret); + + if ((ret = mm_sound_get_device_name(device, &device_name)) != MM_ERROR_NONE) + return _convert_sound_manager_error_code(__func__, ret); + + if (method == SOUND_MANAGER_STREAM_NO_METHOD || + device_id == SOUND_MANAGER_STREAM_NO_REFERENCE_DEVICE) + return SOUND_MANAGER_ERROR_INVALID_PARAMETER; + + stream_h->sound_effect.reference_method = method; + stream_h->sound_effect.reference_device_id = device_id; + + LOGI("set a effect. stream_h[%p, %s], method[%d], reference device[id:%d, name:%s]", + stream_h, stream_h->stream_type, method, device_id, device_name); + + return SOUND_MANAGER_ERROR_NONE; +} + +int _get_effect_method_with_reference(sound_stream_info_h stream_info, sound_effect_method_with_reference_e *method, int *device_id) +{ + sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info; + + SM_ARG_CHECK(stream_h); + SM_ARG_CHECK(method); + SM_ARG_CHECK(device_id); + + if (stream_h->sound_effect.reference_method == SOUND_MANAGER_STREAM_NO_METHOD) { + LOGI("reference method isn't set yet"); + return SOUND_MANAGER_ERROR_INVALID_OPERATION; + } + + if (stream_h->sound_effect.reference_device_id == SOUND_MANAGER_STREAM_NO_REFERENCE_DEVICE) { + LOGI("reference method device isn't set yet"); + return SOUND_MANAGER_ERROR_INVALID_OPERATION; + } + + *method = stream_h->sound_effect.reference_method; + *device_id = stream_h->sound_effect.reference_device_id; + + LOGI("get a effect. stream_h[%p, %s] get sound effect. method(%d), reference device[id:%d]", + stream_h, stream_h->stream_type, *method, *device_id); + + return SOUND_MANAGER_ERROR_NONE; +} + +int _set_effect_method(sound_stream_info_h stream_info, int method) +{ + sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info; + + SM_ARG_CHECK(stream_h); + + if (!stream_h->stream_conf_info.avail_in_devices[0]) { + LOGE("stream_h[%p, %s] does not support any input devices", stream_h, stream_h->stream_type); + return SOUND_MANAGER_ERROR_POLICY; + } + + if (method == SOUND_MANAGER_STREAM_NO_METHOD) + return SOUND_MANAGER_ERROR_INVALID_PARAMETER; + + stream_h->sound_effect.method = method; + + LOGI("set effects. stream_h[%p, %s] method[0x%x]", stream_h, stream_h->stream_type, method); + + return SOUND_MANAGER_ERROR_NONE; +} + +int _get_effect_method(sound_stream_info_h stream_info, int *method) +{ + sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info; + + SM_ARG_CHECK(stream_h); + SM_ARG_CHECK(method); + + if (stream_h->sound_effect.method == SOUND_MANAGER_STREAM_NO_METHOD) { + LOGI("method aren't set yet"); + return SOUND_MANAGER_ERROR_INVALID_OPERATION; + } + + *method = stream_h->sound_effect.method; + + LOGI("get effects. stream_h[%p, %s] method[0x%x]", stream_h, stream_h->stream_type, *method); + + return SOUND_MANAGER_ERROR_NONE; +} + //LCOV_EXCL_STOP