Add echo-cancel properties to AudioInfo 31/272831/2
authorJaechul Lee <jcsing.lee@samsung.com>
Thu, 24 Mar 2022 07:33:56 +0000 (16:33 +0900)
committerJaechul Lee <jcsing.lee@samsung.com>
Thu, 31 Mar 2022 06:00:25 +0000 (15:00 +0900)
Properties that is related to echo-cancellation are added to AudioInfo
class. The properties are used when input stream is handled by 'prepare
function'.

[Version] 0.5.45
[Issue Type] New feature

Change-Id: I0dd1241364e5ed1189aa656dd99efee531ff8d8f
Signed-off-by: Jaechul Lee <jcsing.lee@samsung.com>
include/CAudioInfo.h
packaging/capi-media-audio-io.spec
src/cpp/CAudioIO.cpp
src/cpp/CAudioInfo.cpp
src/cpp/CPulseAudioClient.cpp

index 60c2de9..c0215ab 100644 (file)
@@ -139,6 +139,8 @@ namespace tizen_media_audio {
         int getAudioIndex() noexcept;
         void setAudioIndex(int audioIndex) noexcept;
         int getSampleSize() noexcept;
+        void bindEchoCancelReferenceDeviceId(int id) noexcept;
+        int getEchoCancelReferenceDeviceId() noexcept;
 
         /* Setter & Getter Utilities */
         const char* getConvertedStreamType();
@@ -194,6 +196,7 @@ namespace tizen_media_audio {
         ESampleType  __mSampleType;
         EAudioType   __mAudioType;
         int          __mAudioIndex;
+        int          __mReferenceDeviceId;
     };
 
 
index 6b06cdf..557021a 100644 (file)
@@ -1,6 +1,6 @@
 Name:           capi-media-audio-io
 Summary:        An Audio Input & Audio Output library in Tizen Native API
-Version:        0.5.44
+Version:        0.5.45
 Release:        0
 Group:          Multimedia/API
 License:        Apache-2.0
index 7565f6b..093e7c2 100644 (file)
@@ -223,4 +223,20 @@ void CAudioIO::setStreamInfo(sound_stream_info_h stream_info) {
     if ((errorCode = sound_manager_get_index_from_stream_information(stream_info, &index)) != SOUND_MANAGER_ERROR_NONE)
         THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "Parameter stream_info->index is invalid [ret:%d]", errorCode); //LCOV_EXCL_LINE
     getAudioInfo().setAudioIndex(index);
+
+    if (mDirection == CAudioInfo::EAudioDirection::AUDIO_DIRECTION_IN) {
+        sound_device_h device = NULL;
+
+        if ((errorCode = sound_manager_get_echo_cancel_reference_device(stream_info, &device) != SOUND_MANAGER_ERROR_NONE))
+            THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_ARGUMENT, "Can't get reference device [ret:%d]", errorCode); //LCOV_EXCL_LINE
+
+        if (device) {
+            int id;
+
+            if ((errorCode = sound_manager_get_device_id(device, &id) != SOUND_MANAGER_ERROR_NONE))
+                THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_INVALID_OPERATION, "Can't get device id [ret:%d]", errorCode); //LCOV_EXCL_LINE
+
+            getAudioInfo().bindEchoCancelReferenceDeviceId(id);
+        }
+    }
 }
index f35f3f4..d35b37f 100644 (file)
@@ -40,7 +40,8 @@ CAudioInfo::CAudioInfo(unsigned int sampleRate, EChannel channel, ESampleType sa
     __mChannel(channel),
     __mSampleType(sampleType),
     __mAudioType(audioType),
-    __mAudioIndex(audioIndex) {
+    __mAudioIndex(audioIndex),
+    __mReferenceDeviceId(0) {
     // Check to invalid AudioInfo
     if (sampleRate < CAudioInfo::MIN_SYSTEM_SAMPLERATE ||
         sampleRate > CAudioInfo::MAX_SYSTEM_SAMPLERATE)
@@ -121,6 +122,14 @@ int CAudioInfo::getSampleSize() noexcept {
     return bytes_in_sample * static_cast<int>(__mChannel);
 }
 
+void CAudioInfo::bindEchoCancelReferenceDeviceId(int id) noexcept {
+    __mReferenceDeviceId = id;
+}
+
+int CAudioInfo::getEchoCancelReferenceDeviceId() noexcept {
+    return __mReferenceDeviceId;
+}
+
 const char* CAudioInfo::getConvertedStreamType() {
     if (__mAudioType < CAudioInfo::EAudioType::AUDIO_IN_TYPE_MEDIA ||
         __mAudioType >= CAudioInfo::EAudioType::AUDIO_TYPE_MAX)
@@ -150,4 +159,4 @@ CAudioInfo::EAudioType CAudioInfo::convertOutputStreamTypeToAudioType(const char
     }
     THROW_ERROR_MSG_FORMAT(CAudioError::EError::ERROR_NOT_SUPPORTED_TYPE,
                            "The streamType of output is not supported [streamType:%s]", streamType);
-}
\ No newline at end of file
+}
index 105a293..f57c592 100644 (file)
@@ -51,6 +51,7 @@ CPulseAudioClient::CPulseThreadLocker::~CPulseThreadLocker() {
  * class CPulseAudioClient
  */
 const char* CPulseAudioClient::CLIENT_NAME = "AUDIO_IO_PA_CLIENT";
+const char* ec_method = "default";
 static constexpr auto drain_wait_interval = 10000;
 static constexpr auto drain_wait_max_count = 30;
 
@@ -401,6 +402,12 @@ void CPulseAudioClient::initialize() {
         if (index >= 0)
             pa_proplist_setf(__mpPropList, PA_PROP_MEDIA_PARENT_ID, "%u", (unsigned int) index);
 
+        int reference_id = __mSpec.getAudioInfo().getEchoCancelReferenceDeviceId();
+        if (reference_id > 0) {
+            pa_proplist_setf(__mpPropList, PA_PROP_MEDIA_ECHO_CANCEL_METHOD, "%s", ec_method);
+            pa_proplist_setf(__mpPropList, PA_PROP_MEDIA_ECHO_CANCEL_REFERENCE_DEVICE, "%d", reference_id);
+        }
+
         // Adds latency on proplist for delivery to PULSEAUDIO
         AUDIO_IO_LOGD("LATENCY : %s[%d]", __mSpec.getStreamLatencyToString(), static_cast<int>(__mSpec.getStreamLatency()));
         pa_proplist_setf(__mpPropList, PA_PROP_MEDIA_TIZEN_AUDIO_LATENCY, "%s", __mSpec.getStreamLatencyToString());