Add new public APIs to set effect method 52/295252/21 accepted/tizen/unified/20230719.170106
authorJaechul Lee <jcsing.lee@samsung.com>
Tue, 4 Jul 2023 07:50:18 +0000 (16:50 +0900)
committerJaechul Lee <jcsing.lee@samsung.com>
Tue, 18 Jul 2023 06:43:59 +0000 (15:43 +0900)
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 <jcsing.lee@samsung.com>
include/sound_manager.h
include/sound_manager_internal.h
include/sound_manager_private.h
packaging/capi-media-sound-manager.spec
src/sound_manager.c
src/sound_manager_private.c

index 186c1f1cb89fdd62ce1af94eb97b0c6084afa64a..25b40636cc756d846c294fe5aee2f18829622019 100644 (file)
@@ -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);
+
+/**
+ * @}
+ */
+
 /**
  * @}
  */
index 5444555167f26f19283ecf6aef17d1dbb1d2067f..d20e124e0f28281b33f68aa9aa031b7d75d6bed0 100644 (file)
@@ -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.
index 53c897f674ca0ec71526d14b202599bc5fab8b06..88bb0e12a005741122eeddc48b3bfde7f7e78055 100644 (file)
@@ -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
index 9b12a0d9bde8e6ed07538f58eee92094b17aa6fb..21d930dc034bb17ac6d53676c994ae41667bd1fd 100644 (file)
@@ -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
index 10b5144a1d4cbddac3af6ebb7562e15e6405d938..0c5fa1e4f4187ee99d0c696709e2f9f4d183f4fc 100644 (file)
@@ -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);
+}
+
index d2e58cd5600393b186b529b4ab3e2aabdcade1c9..ea252c66a5eae52453321a390417b44dc183f58f 100644 (file)
@@ -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