Android Audio Development - AAudio Process (16)

        AAudioService provides many methods for us to use it, and the next step is to analyze several important methods to understand their working principles. 

1. Process analysis

        The process of opening a stream is mainly divided into two situations:

Shared mode : Multiple audio streams can access the audio device at the same time, and the audio delay in this mode is slightly higher.
Exclusive mode : Only this audio stream can access the audio device, and other audio streams deny access. In this mode, the audio performance is high and the delay is low.

        Note: If the audio device is no longer used in exclusive mode, the audio stream needs to be released immediately, so as not to affect other audio streams accessing the audio device.

1. Open the audio stream

AAudioService.cpp

Source location: /frameworks/av/services/oboeservice/AAudioService.cpp

aaudio_handle_t AAudioService::openStream(const aaudio::AAudioStreamRequest &request, aaudio::AAudioStreamConfiguration &configurationOutput) {
    // 当EXCLUSIVE端点被盗时,锁用于命令打开端点。我们希望顺序是:
    // 1) 线程A打开独占的MMAP端点
    // 2) 线程B想要打开一个独占的MMAP端点,所以它在此锁下从A窃取一个
    // 3) 线程B打开共享的MMAP端点
    // 4) 线程A可以获得锁并打开共享流.
    // 没有锁。线程A可能在B打开共享流之前潜入并重新分配独占流
    std::unique_lock<std::recursive_mutex> lock(mOpen

Guess you like

Origin blog.csdn.net/c19344881x/article/details/131165386