From fff41b5f4e085f84da1b777c111fb7d5350a9e19 Mon Sep 17 00:00:00 2001
From: kkostiuk <kateryna.kostiuk@savoirfairelinux.com>
Date: Thu, 20 May 2021 09:59:22 -0400
Subject: [PATCH] audio: filter input devices for macOS

When creating Voice Processing Audio Unit a
VPAUAggregateAudioDevice created. Also, input stream added
to speaker device for echo cancellation. This patch filter out
those devices from audio input devices.

Change-Id: I2d314947b33643d8199fb8f7a594100228e8968c
---
 src/media/audio/coreaudio/osx/corelayer.mm | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/media/audio/coreaudio/osx/corelayer.mm b/src/media/audio/coreaudio/osx/corelayer.mm
index 50cb3d64b4..fc91bd1e7c 100644
--- a/src/media/audio/coreaudio/osx/corelayer.mm
+++ b/src/media/audio/coreaudio/osx/corelayer.mm
@@ -498,6 +498,20 @@ CoreLayer::getDeviceList(bool getCapture) const
     for (int i = 0; i < nDevices; ++i) {
         auto dev = AudioDevice {devids[i], getCapture};
         if (dev.channels_ > 0) { // Channels < 0 if inactive.
+            //There is additional stream under the built-in device - the raw streams enabled by AUVP.
+            if (dev.name_.find("VPAUAggregateAudioDevice") != std::string::npos) {
+                //ignore VPAUAggregateAudioDevice
+                continue;
+            }
+            //for input device check if it not speaker
+            //since the speaker device has input stream for echo cancellation.
+            if (getCapture) {
+                auto devOutput = AudioDevice {devids[i], !getCapture};
+                // it is output device
+                if (devOutput.channels_ > 0) {
+                    continue;
+                }
+            }
             ret.push_back(std::move(dev));
         }
     }
-- 
GitLab