[Draft] Add audio effect API ref/for/tizen
authorJaechul Lee <jcsing.lee@samsung.com>
Tue, 4 Jul 2023 07:50:18 +0000 (16:50 +0900)
committerJaechul Lee <jcsing.lee@samsung.com>
Thu, 6 Jul 2023 06:18:01 +0000 (15:18 +0900)
Change-Id: I28026a39615fed8790f1f2b3f3e062d417c56750
Signed-off-by: Jaechul Lee <jcsing.lee@samsung.com>
include/sound_manager.h
include/sound_manager_private.h
src/sound_manager.c

index 186c1f1cb89fdd62ce1af94eb97b0c6084afa64a..afe5777b42d5df5ac2c9c30b88d602cba6b97d0d 100644 (file)
@@ -255,6 +255,33 @@ typedef enum {
        SOUND_SAMPLE_RATE_192000,  /**< 192000 Hz sample rate */
 } sound_sample_rate_e;
 
+/**
+ * @brief Definition for the value indicating that the reference device for the stream information was not set.
+ * @since_tizen 8.0
+ * @see sound_manager_get_effect_reference_device()
+ */
+#define SOUND_MANAGER_STREAM_NO_REFERENCE_DEVICE    0
+
+/**
+* @brief Enumeration for sound effects that need a reference device.
+* @since_tizen 8.0
+*/
+typedef enum {
+       SOUND_EFFECT_REFERENCE_COPY,                    /** < including reference source */
+       SOUND_EFFECT_ACOUSTIC_ECHO_CANCEL_SPEEX,        /** < acoustic echo cancel with speex */
+       SOUND_EFFECT_ACOUSTIC_ECHO_CANCEL_WEBRTC,       /** < acoustic echo cancel with webrtc */
+} sound_effect_reference_method_e;
+
+/**
+* @brief Enumeration for sound effects.
+* @since_tizen 8.0
+*/
+typedef enum {
+       SOUND_EFFECT_NOISE_SUPPRESSION_VOICECALL        = 0x0100,  /** < noise suppression with rnnoise */
+       SOUND_EFFECT_NOISE_SUPPRESSION_VOICERECOGNITION = 0x0200,  /** < noise suppression with pse */
+       SOUND_EFFECT_NOISE_SUPPRESSION_VERSATILE        = 0x0400,  /** < noise suppression with versatile */
+} sound_effect_method_e;
+
 /**
  * @}
  */
@@ -1633,6 +1660,112 @@ 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
+ * @since_tizen 8.0
+ * @remark This function isn't allow more than 2 acoustic echo cancellation effects.\n
+ *     If @a method is set with more than 2 acoustic echo cancellation effects,\n
+ *     It will return #SOUND_MANAGER_ERROR_INVALID_PARAMETER.
+ * @param[in]  stream_info     The handle of stream information
+ * @param[in]  method  The method of audio effect, 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
+ * @see sound_manager_create_stream_information()
+ */
+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 audio effect
+ * @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_create_stream_information()
+ * @see sound_manager_set_audio_effect_method()
+ */
+int sound_manager_get_effect_method(sound_stream_info_h stream_info, int *method);
+
+/**
+ * @brief Sets a reference device for audio-effects that must need a reference
+ * @since_tizen 8.0
+ * @remark You can get a device handle by using sound_manager_get_device_list() and sound_manager_get_next_device()\n
+ *     If @a device is not supported by @a stream_info, #SOUND_MANAGER_ERROR_POLICY will be returned.\n
+ *     If a sort of a method of acoustic echo cancellation isn't set, It will return ##SOUND_MANAGER_ERROR_INTERNAL.
+ * @param[in]  stream_info     The handle of stream information
+ * @param[in]  device  The reference device of echo-cancellation
+ * @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
+ * @retval #SOUND_MANAGER_ERROR_INTERNAL Internal error inside the sound system
+ * @pre Call sound_manager_set_effect_method() before calling this function.
+ * @see sound_manager_create_stream_information()
+ * @see sound_manager_get_device_list()
+ * @see sound_manager_get_next_device()
+ * @see sound_manager_free_device_list()
+ */
+int sound_manager_set_effect_reference_device(sound_stream_info_h stream_info, sound_device_h device);
+
+/**
+ * @brief Gets a reference device
+ * @since_tizen 8.0
+ * @remarks    If there is no reference device that has been set, the output value will be set to
+ *     #SOUND_MANAGER_STREAM_NO_REFERENCE_DEVICE.\n
+ *     You can get a device handle of the id value by using sound_manager_get_device_list(),
+ *     sound_manager_get_next_device() and sound_manager_get_device_id().
+ * @param[in]  stream_info     The handle of stream information
+ * @param[out] device_id       The reference device id of echo-cancellation
+ * @return @c 0 on success,
+ *         otherwise a negative error value
+ * @retval #SOUND_MANAGER_ERROR_NONE Success
+ * @retval #SOUND_MANAGER_ERROR_INVALID_PARAMETER Invalid parameter
+ * @pre Call sound_manager_set_effect_method() before calling this function.
+ * @see sound_manager_create_stream_information()
+ * @see sound_manager_get_device_list()
+ * @see sound_manager_get_next_device()
+ * @see sound_manager_free_device_list()
+ */
+int sound_manager_get_effect_reference_device(sound_stream_info_h stream_info, int *device_id);
+
+/**
+ * @brief Sets sound effect methods that must need a reference device such as acoustic echo cancellation
+ * @since_tizen 8.0
+ * @remark This function isn't allow more than 2 acoustic echo cancellation effects.\n
+ *     If @a method is set with more than 2 acoustic echo cancellation effects,\n
+ *     It will return #SOUND_MANAGER_ERROR_INVALID_PARAMETER.
+ * @param[in]  stream_info     The handle of stream information
+ * @param[in]  method  The method of #sound_effect_reference_method_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
+ * @see sound_manager_create_stream_information()
+ */
+int sound_manager_set_effect_method_with_reference(sound_stream_info_h stream_info, sound_effect_reference_method_e method, sound_device_h device);
+
+int sound_manager_get_effect_method_with_reference(sound_stream_info_h stream_info, sound_effect_reference_method_e method, int *device_id);
+
+int sound_manager_set_effect_method(sound_stream_info_h stream_info, int method);
+
+int sound_manager_get_effect_method(sound_stream_info_h stream_info, int *method);
+
+
+/**
+ * @}
+ */
+
 /**
  * @}
  */
index 53c897f674ca0ec71526d14b202599bc5fab8b06..d21a2ac9a390259e6815d829e492aacfd81c52b3 100644 (file)
@@ -196,6 +196,11 @@ typedef struct _preferred_device_info_s {
        int out;
 } preferred_device_info_s;
 
+typedef struct _audio_effect {
+       audio_effect_method_e method;
+       int reference_device;
+} audio_effect_s;
+
 typedef struct _virtual_stream_info_s virtual_sound_stream_info_s;
 
 typedef struct _sound_stream_info_s {
@@ -215,6 +220,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;
+       audio_effect_s audio_effect;
        pthread_mutex_t focus_state_mutex;
        pthread_mutex_t focus_cb_mutex;
        pthread_mutex_t vstream_mutex;
index 10b5144a1d4cbddac3af6ebb7562e15e6405d938..251417192ee97c645e40d060890deb653316e763 100644 (file)
@@ -1443,3 +1443,81 @@ int sound_manager_deactivate_ducking(sound_stream_ducking_h stream_ducking)
 
        return ret;
 }
+
+int sound_manager_set_audio_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;
+       }
+
+       stream_h->audio_effect.method = method;
+
+       LOGI("stream_h[%p, %s] method[0x%x]", stream_h, stream_h->stream_type, method);
+
+       return SOUND_MANAGER_ERROR_NONE;
+}
+
+int sound_manager_get_audio_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);
+
+       *method = stream_h->audio_effect.method;
+
+       LOGI("stream_h[%p, %s] method[0x%x]",
+               stream_h, stream_h->stream_type, *method);
+
+       return SOUND_MANAGER_ERROR_NONE;
+}
+
+int sound_manager_set_audio_effect_reference_device(sound_stream_info_h stream_info, sound_device_h device)
+{
+       int ret;
+       int device_id;
+       char *device_name;
+       sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
+
+       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;
+       }
+
+       /* FIXME: check if the PA sink supports to pump the reference data to AEC module */
+       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);
+
+       stream_h->audio_effect.reference_device = device_id;
+
+       LOGI("stream_h[%p, %s] audio effect reference device[id:%d, name:%s]",
+               stream_h, stream_h->stream_type, device_id, device_name);
+
+       return SOUND_MANAGER_ERROR_NONE;
+}
+
+int sound_manager_get_audio_effect_reference_device(sound_stream_info_h stream_info, int *device_id)
+{
+       sound_stream_info_s *stream_h = (sound_stream_info_s*)stream_info;
+
+       SM_ARG_CHECK(stream_h);
+       SM_ARG_CHECK(device_id);
+
+       *device_id = stream_h->audio_effect.reference_device;
+
+       LOGI("stream_h[%p, %s] reference device_id[%d]",
+               stream_h, stream_h->stream_type, *device_id);
+
+       return SOUND_MANAGER_ERROR_NONE;
+}