Is it possible to open 2 microphones in Android at same time with Oboe library?

爷,独闯天下 提交于 2021-02-05 06:10:24

问题


I'm trying to open 2 microphone streams with google's Oboe library like this, for each microphone:

oboe::AudioStreamBuilder builder;
    builder.setChannelCount(channelCount)
            ->setDirection(isInput ? oboe::Direction::Input : oboe::Direction::Output)
            ->setSharingMode((oboe::SharingMode) sharingMode)
            ->setPerformanceMode((oboe::PerformanceMode) performanceMode)
            ->setInputPreset((oboe::InputPreset)inputPreset)
            ->setDeviceId(deviceId)
            ->setSessionId((oboe::SessionId) sessionId)
            ->setSampleRate(sampleRate)
            ->setFormat((oboe::AudioFormat) format)
            ->setChannelConversionAllowed(channelConversionAllowed)
            ->setFormatConversionAllowed(formatConversionAllowed)
            ->setSampleRateConversionQuality((oboe::SampleRateConversionQuality) rateConversionQuality)
            ;

oboe::AudioStream *oboeStream = nullptr;
oboe::Result result = builder.openStream(&oboeStream);

As you can see, the deviceId is passed to the builder. This is the microphone ID that I get with some java methods. I pass 7 and 9 as ids, for built-in microphone and telephone microphone. The problem is when I try to start the 2 streams:

oboeStream.requestStart()

I get this error for the second stream:

E/AudioRecord: start() status -38

but if I try to open the first one only, and then the second one only, in 2 different builds, everything works. So is it true that I cannot open 2 microphone streams with Oboe? It looks like a powerful library, it shouldbe possible.


回答1:


Android doesn't allow you to capture audio from more than one thread most of the time. It doesn't matter how many input sources your phone has or which library do you use. You can't open two audio streams at the same time. Even two separate ordinary applications don't have access to the input sources simultaneously and if you want to start recording while a stream source captured by another process an error would be returned. From Android 10 some changes occurred. According to the doc:

Android 10 (API level 29) and higher imposes a priority scheme that can switch the input audio stream between apps while they are running. In most cases, if a new app acquires the audio input, the previously capturing app continues to run, but receives silence. In some cases the system can continue to deliver audio to both apps.

Two streams mean two thread which is like two different apps. In some scenarios, two processes can capture audio at the same time like so:

Assistant + ordinary app

Accessibility service + ordinary app

Voice call + ordinary app

For more details please read this page at the Android doc.




回答2:


in fact even if you have two microphones, from what is stated in the docs it is not possible to have more than one stream at the same time, ONLY IF we are talking about internal microphones since they are represented by the same channel, if instead we are talking about external devices then there are two input-output channels and you can have two different streams.



来源:https://stackoverflow.com/questions/63368914/is-it-possible-to-open-2-microphones-in-android-at-same-time-with-oboe-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!