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

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

AudioFlinger: Extract PatchCommandThread class

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
Change-Id: I7ef21750a59aa74c4f9104fc73f536a2d3c92cda
parent 8e6b62a0
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -129,6 +129,9 @@
#include "IAfThread.h"
#include "IAfTrack.h"

// Classes that depend on IAf* interfaces but are not cross-dependent.
#include "PatchCommandThread.h"

namespace android {

class AudioMixer;
@@ -586,8 +589,6 @@ public:
    using TeePatches = std::vector<TeePatch>;
private:

#include "PatchCommandThread.h"

#include "DeviceEffectManager.h"

#include "MelReporter.h"
+12 −12
Original line number Diff line number Diff line
@@ -24,24 +24,24 @@ namespace android {

constexpr char kPatchCommandThreadName[] = "AudioFlinger_PatchCommandThread";

AudioFlinger::PatchCommandThread::~PatchCommandThread() {
PatchCommandThread::~PatchCommandThread() {
    exit();

    std::lock_guard _l(mLock);
    mCommands.clear();
}

void AudioFlinger::PatchCommandThread::onFirstRef() {
void PatchCommandThread::onFirstRef() {
    run(kPatchCommandThreadName, ANDROID_PRIORITY_AUDIO);
}

void AudioFlinger::PatchCommandThread::addListener(const sp<PatchCommandListener>& listener) {
void PatchCommandThread::addListener(const sp<PatchCommandListener>& listener) {
    ALOGV("%s add listener %p", __func__, static_cast<void*>(listener.get()));
    std::lock_guard _l(mListenerLock);
    mListeners.emplace_back(listener);
}

void AudioFlinger::PatchCommandThread::createAudioPatch(audio_patch_handle_t handle,
void PatchCommandThread::createAudioPatch(audio_patch_handle_t handle,
        const IAfPatchPanel::Patch& patch) {
    ALOGV("%s handle %d mHalHandle %d num sinks %d device sink %08x",
            __func__, handle, patch.mHalHandle,
@@ -51,12 +51,12 @@ void AudioFlinger::PatchCommandThread::createAudioPatch(audio_patch_handle_t han
    createAudioPatchCommand(handle, patch);
}

void AudioFlinger::PatchCommandThread::releaseAudioPatch(audio_patch_handle_t handle) {
void PatchCommandThread::releaseAudioPatch(audio_patch_handle_t handle) {
    ALOGV("%s", __func__);
    releaseAudioPatchCommand(handle);
}

void AudioFlinger::PatchCommandThread::updateAudioPatch(audio_patch_handle_t oldHandle,
void PatchCommandThread::updateAudioPatch(audio_patch_handle_t oldHandle,
        audio_patch_handle_t newHandle, const IAfPatchPanel::Patch& patch) {
    ALOGV("%s handle %d mHalHandle %d num sinks %d device sink %08x",
            __func__, oldHandle, patch.mHalHandle,
@@ -66,7 +66,7 @@ void AudioFlinger::PatchCommandThread::updateAudioPatch(audio_patch_handle_t old
    updateAudioPatchCommand(oldHandle, newHandle, patch);
}

bool AudioFlinger::PatchCommandThread::threadLoop()
bool PatchCommandThread::threadLoop()
NO_THREAD_SAFETY_ANALYSIS  // bug in clang compiler.
{
    std::unique_lock _l(mLock);
@@ -144,13 +144,13 @@ NO_THREAD_SAFETY_ANALYSIS // bug in clang compiler.
    return false;
}

void AudioFlinger::PatchCommandThread::sendCommand(const sp<Command>& command) {
void PatchCommandThread::sendCommand(const sp<Command>& command) {
    std::lock_guard _l(mLock);
    mCommands.emplace_back(command);
    mWaitWorkCV.notify_one();
}

void AudioFlinger::PatchCommandThread::createAudioPatchCommand(
void PatchCommandThread::createAudioPatchCommand(
        audio_patch_handle_t handle, const IAfPatchPanel::Patch& patch) {
    auto command = sp<Command>::make(CREATE_AUDIO_PATCH,
                                     new CreateAudioPatchData(handle, patch));
@@ -161,14 +161,14 @@ void AudioFlinger::PatchCommandThread::createAudioPatchCommand(
    sendCommand(command);
}

void AudioFlinger::PatchCommandThread::releaseAudioPatchCommand(audio_patch_handle_t handle) {
void PatchCommandThread::releaseAudioPatchCommand(audio_patch_handle_t handle) {
    sp<Command> command =
        sp<Command>::make(RELEASE_AUDIO_PATCH, new ReleaseAudioPatchData(handle));
    ALOGV("%s adding release patch", __func__);
    sendCommand(command);
}

void AudioFlinger::PatchCommandThread::updateAudioPatchCommand(
void PatchCommandThread::updateAudioPatchCommand(
        audio_patch_handle_t oldHandle, audio_patch_handle_t newHandle,
        const IAfPatchPanel::Patch& patch) {
    sp<Command> command = sp<Command>::make(UPDATE_AUDIO_PATCH,
@@ -178,7 +178,7 @@ void AudioFlinger::PatchCommandThread::updateAudioPatchCommand(
    sendCommand(command);
}

void AudioFlinger::PatchCommandThread::exit() {
void PatchCommandThread::exit() {
    ALOGV("%s", __func__);
    {
        std::lock_guard _l(mLock);
+5 −3
Original line number Diff line number Diff line
@@ -15,9 +15,9 @@
** limitations under the License.
*/

#ifndef INCLUDING_FROM_AUDIOFLINGER_H
    #error This header file should only be included from AudioFlinger.h
#endif
#pragma once

namespace android {

class Command;

@@ -121,3 +121,5 @@ private:
    std::mutex mListenerLock;
    std::vector<wp<PatchCommandListener>> mListeners GUARDED_BY(mListenerLock);
};

}  // namespace android