Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee58e4ae authored by Andy Hung's avatar Andy Hung
Browse files

AudioFlinger: Extract inner Thread classes

Test: atest audiorecord_tests audiotrack_tests audiorouting_tests trackplayerbase_tests audiosystem_tests
Test: atest AAudioTests AudioTrackOffloadTest
Test: atest AudioTrackTest AudioRecordTest
Test: YouTube Camera
Bug: 288339104
Bug: 289233517
Change-Id: I642498760a50a5b55751f090627f75ad5adb5468
parent d3ddf3f1
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -3039,8 +3039,8 @@ sp<IAfThreadBase> AudioFlinger::openOutput_l(audio_module_handle_t module,

    if (status == NO_ERROR) {
        if (flags & AUDIO_OUTPUT_FLAG_MMAP_NOIRQ) {
            const sp<IAfMmapPlaybackThread> thread =
                    new MmapPlaybackThread(this, *output, outHwDev, outputStream, mSystemReady);
            const sp<IAfMmapPlaybackThread> thread = IAfMmapPlaybackThread::create(
                    this, *output, outHwDev, outputStream, mSystemReady);
            mMmapThreads.add(*output, thread);
            ALOGV("openOutput_l() created mmap playback thread: ID %d thread %p",
                  *output, thread.get());
@@ -3048,28 +3048,30 @@ sp<IAfThreadBase> AudioFlinger::openOutput_l(audio_module_handle_t module,
        } else {
            sp<IAfPlaybackThread> thread;
            if (flags & AUDIO_OUTPUT_FLAG_BIT_PERFECT) {
                thread = sp<BitPerfectThread>::make(this, outputStream, *output, mSystemReady);
                thread = IAfPlaybackThread::createBitPerfectThread(
                        this, outputStream, *output, mSystemReady);
                ALOGV("%s() created bit-perfect output: ID %d thread %p",
                      __func__, *output, thread.get());
            } else if (flags & AUDIO_OUTPUT_FLAG_SPATIALIZER) {
                thread = new SpatializerThread(this, outputStream, *output,
                thread = IAfPlaybackThread::createSpatializerThread(this, outputStream, *output,
                                                    mSystemReady, mixerConfig);
                ALOGV("openOutput_l() created spatializer output: ID %d thread %p",
                      *output, thread.get());
            } else if (flags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) {
                thread = new OffloadThread(this, outputStream, *output,
                thread = IAfPlaybackThread::createOffloadThread(this, outputStream, *output,
                        mSystemReady, halConfig->offload_info);
                ALOGV("openOutput_l() created offload output: ID %d thread %p",
                      *output, thread.get());
            } else if ((flags & AUDIO_OUTPUT_FLAG_DIRECT)
                    || !isValidPcmSinkFormat(halConfig->format)
                    || !isValidPcmSinkChannelMask(halConfig->channel_mask)) {
                thread = new DirectOutputThread(this, outputStream, *output,
                thread = IAfPlaybackThread::createDirectOutputThread(this, outputStream, *output,
                        mSystemReady, halConfig->offload_info);
                ALOGV("openOutput_l() created direct output: ID %d thread %p",
                      *output, thread.get());
            } else {
                thread = new MixerThread(this, outputStream, *output, mSystemReady);
                thread = IAfPlaybackThread::createMixerThread(
                        this, outputStream, *output, mSystemReady);
                ALOGV("openOutput_l() created mixer output: ID %d thread %p",
                      *output, thread.get());
            }
@@ -3172,7 +3174,8 @@ audio_io_handle_t AudioFlinger::openDuplicateOutput(audio_io_handle_t output1,
    }

    audio_io_handle_t id = nextUniqueId(AUDIO_UNIQUE_ID_USE_OUTPUT);
    IAfDuplicatingThread* const thread = new DuplicatingThread(this, thread1, id, mSystemReady);
    const sp<IAfDuplicatingThread> thread = IAfDuplicatingThread::create(
            this, thread1, id, mSystemReady);
    thread->addOutputTrack(thread2);
    mPlaybackThreads.add(id, thread);
    // notify client processes of the new output creation
@@ -3411,7 +3414,7 @@ sp<IAfThreadBase> AudioFlinger::openInput_l(audio_module_handle_t module,
        AudioStreamIn *inputStream = new AudioStreamIn(inHwDev, inStream, flags);
        if ((flags & AUDIO_INPUT_FLAG_MMAP_NOIRQ) != 0) {
            const sp<IAfMmapCaptureThread> thread =
                    new MmapCaptureThread(this, *input, inHwDev, inputStream, mSystemReady);
                    IAfMmapCaptureThread::create(this, *input, inHwDev, inputStream, mSystemReady);
            mMmapThreads.add(*input, thread);
            ALOGV("openInput_l() created mmap capture thread: ID %d thread %p", *input,
                    thread.get());
+14 −14
Original line number Diff line number Diff line
@@ -150,10 +150,24 @@ static const nsecs_t kDefaultStandbyTimeInNsecs = seconds(3);

using android::content::AttributionSourceState;

struct stream_type_t {
    float volume = 1.f;
    bool mute = false;
};

class AudioFlinger : public AudioFlingerServerAdapter::Delegate
{
    friend class sp<AudioFlinger>;
    friend class Client; // removeClient_l();
    // TODO(b/291012167) replace the Thread friends with an interface.
    friend class DirectOutputThread;
    friend class MixerThread;
    friend class MmapPlaybackThread;
    friend class MmapThread;
    friend class PlaybackThread;
    friend class RecordThread;
    friend class ThreadBase;

public:
    static void instantiate() ANDROID_API;

@@ -571,20 +585,6 @@ public:
    using TeePatches = std::vector<TeePatch>;
private:

    struct  stream_type_t {
        stream_type_t()
            :   volume(1.0f),
                mute(false)
        {
        }
        float       volume;
        bool        mute;
    };

    // --- PlaybackThread ---

#include "Threads.h"

#include "PatchPanel.h"

#include "PatchCommandThread.h"
+32 −0
Original line number Diff line number Diff line
@@ -255,6 +255,26 @@ public:

class IAfPlaybackThread : public virtual IAfThreadBase, public virtual VolumeInterface {
public:
    static sp<IAfPlaybackThread> createBitPerfectThread(
            const sp<AudioFlinger>& audioflinger, AudioStreamOut* output, audio_io_handle_t id,
            bool systemReady);

    static sp<IAfPlaybackThread> createDirectOutputThread(
            const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, audio_io_handle_t id,
            bool systemReady, const audio_offload_info_t& offloadInfo);

    static sp<IAfPlaybackThread> createMixerThread(
            const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, audio_io_handle_t id,
            bool systemReady, type_t type = MIXER, audio_config_base_t* mixerConfig = nullptr);

    static sp<IAfPlaybackThread> createOffloadThread(
            const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, audio_io_handle_t id,
            bool systemReady, const audio_offload_info_t& offloadInfo);

    static sp<IAfPlaybackThread> createSpatializerThread(
            const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, audio_io_handle_t id,
            bool systemReady, audio_config_base_t* mixerConfig);

    static constexpr int8_t kMaxTrackStopRetriesOffload = 2;

    enum mixer_state {
@@ -367,6 +387,10 @@ public:

class IAfDuplicatingThread : public virtual IAfPlaybackThread {
public:
    static sp<IAfDuplicatingThread> create(
            const sp<AudioFlinger>& audioFlinger, IAfPlaybackThread* mainThread,
            audio_io_handle_t id, bool systemReady);

    virtual void addOutputTrack(IAfPlaybackThread* thread) = 0;
    virtual uint32_t waitTimeMs() const = 0;
    virtual void removeOutputTrack(IAfPlaybackThread* thread) = 0;
@@ -474,11 +498,19 @@ public:

class IAfMmapPlaybackThread : public virtual IAfMmapThread, public virtual VolumeInterface {
public:
    static sp<IAfMmapPlaybackThread> create(
            const sp<AudioFlinger>& audioFlinger, audio_io_handle_t id, AudioHwDevice* hwDev,
            AudioStreamOut* output, bool systemReady);

    virtual AudioStreamOut* clearOutput() = 0;
};

class IAfMmapCaptureThread : public virtual IAfMmapThread {
public:
    static sp<IAfMmapCaptureThread> create(
            const sp<AudioFlinger>& audioFlinger, audio_io_handle_t id, AudioHwDevice* hwDev,
            AudioStreamIn* input, bool systemReady);

    virtual AudioStreamIn* clearInput() = 0;
};

+3 −3
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ public:
     */
    void processMuteEvent_l(const sp<IAudioManager>& audioManager,
                            mute_state_t muteState)
                            REQUIRES(AudioFlinger::MmapPlaybackThread::mLock) final;
                            /* REQUIRES(MmapPlaybackThread::mLock) */ final;
private:
    friend class MmapThread;

@@ -82,9 +82,9 @@ private:
    // TODO: replace PersistableBundle with own struct
    // access these two variables only when holding player thread lock.
    std::unique_ptr<os::PersistableBundle> mMuteEventExtras
            GUARDED_BY(AudioFlinger::MmapPlaybackThread::mLock);
            /* GUARDED_BY(MmapPlaybackThread::mLock) */;
    mute_state_t mMuteState
            GUARDED_BY(AudioFlinger::MmapPlaybackThread::mLock);
            /* GUARDED_BY(MmapPlaybackThread::mLock) */;
};  // end of Track

} // namespace android
 No newline at end of file
+412 −361

File changed.

Preview size limit exceeded, changes collapsed.

Loading