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

Commit 7035e863 authored by Andy Hung's avatar Andy Hung Committed by Android (Google) Code Review
Browse files

Merge "AudioFlinger: Add more Thread interfaces" into main

parents be6ed903 87c693cd
Loading
Loading
Loading
Loading
+146 −143

File changed.

Preview size limit exceeded, changes collapsed.

+25 −33
Original line number Diff line number Diff line
@@ -499,11 +499,7 @@ private:

    SimpleLog mThreadLog{16}; // 16 Thread history limit

public:
    // TODO(b/288339104)
    class ThreadBase;
private:
    void dumpToThreadLog_l(const sp<ThreadBase> &thread);
    void dumpToThreadLog_l(const sp<IAfThreadBase>& thread);

    // --- Notification Client ---
    class NotificationClient : public IBinder::DeathRecipient {
@@ -609,7 +605,7 @@ private:
            const uint32_t sessionType = threads.valueAt(i)->hasAudioSession(sessionId);
            if (sessionType != 0) {
                io = threads.keyAt(i);
                if ((sessionType & AudioFlinger::ThreadBase::EFFECT_SESSION) != 0) {
                if ((sessionType & IAfThreadBase::EFFECT_SESSION) != 0) {
                    break; // effect chain here.
                }
            }
@@ -640,17 +636,16 @@ private:
        const sp<MmapThread> mThread;
    };

              ThreadBase *checkThread_l(audio_io_handle_t ioHandle) const;
              sp<AudioFlinger::ThreadBase> checkOutputThread_l(audio_io_handle_t ioHandle) const
                      REQUIRES(mLock);
              PlaybackThread *checkPlaybackThread_l(audio_io_handle_t output) const;
              MixerThread *checkMixerThread_l(audio_io_handle_t output) const;
              RecordThread *checkRecordThread_l(audio_io_handle_t input) const;
    IAfThreadBase* checkThread_l(audio_io_handle_t ioHandle) const;
    sp<IAfThreadBase> checkOutputThread_l(audio_io_handle_t ioHandle) const REQUIRES(mLock);
    IAfPlaybackThread* checkPlaybackThread_l(audio_io_handle_t output) const;
    IAfPlaybackThread* checkMixerThread_l(audio_io_handle_t output) const;
    IAfRecordThread* checkRecordThread_l(audio_io_handle_t input) const;
              MmapThread *checkMmapThread_l(audio_io_handle_t io) const;
              sp<VolumeInterface> getVolumeInterface_l(audio_io_handle_t output) const;
              std::vector<sp<VolumeInterface>> getAllVolumeInterfaces_l() const;

              sp<ThreadBase> openInput_l(audio_module_handle_t module,
    sp<IAfThreadBase> openInput_l(audio_module_handle_t module,
                                           audio_io_handle_t *input,
                                           audio_config_t *config,
                                           audio_devices_t device,
@@ -659,7 +654,7 @@ private:
                                           audio_input_flags_t flags,
                                           audio_devices_t outputDevice,
                                           const String8& outputDeviceAddress);
              sp<ThreadBase> openOutput_l(audio_module_handle_t module,
    sp<IAfThreadBase> openOutput_l(audio_module_handle_t module,
                                          audio_io_handle_t *output,
                                          audio_config_t *halConfig,
                                          audio_config_base_t *mixerConfig,
@@ -667,8 +662,8 @@ private:
                                          const String8& address,
                                          audio_output_flags_t flags);

              void closeOutputFinish(const sp<PlaybackThread>& thread);
              void closeInputFinish(const sp<RecordThread>& thread);
    void closeOutputFinish(const sp<IAfPlaybackThread>& thread);
    void closeInputFinish(const sp<IAfRecordThread>& thread);

              // no range check, AudioFlinger::mLock held
              bool streamMute_l(audio_stream_type_t stream) const
@@ -693,33 +688,30 @@ private:
              audio_unique_id_t nextUniqueId(audio_unique_id_use_t use);

              status_t moveEffectChain_l(audio_session_t sessionId,
                                     PlaybackThread *srcThread,
                                     PlaybackThread *dstThread);
            IAfPlaybackThread* srcThread, IAfPlaybackThread* dstThread);
              status_t moveEffectChain_l(audio_session_t sessionId,
                                         RecordThread *srcThread,
                                         RecordThread *dstThread);
            IAfRecordThread* srcThread, IAfRecordThread* dstThread);

public:
    // TODO(b/288339104) cluster together
              status_t moveAuxEffectToIo(int EffectId,
                                         const sp<PlaybackThread>& dstThread,
                                         sp<PlaybackThread> *srcThread);
            const sp<IAfPlaybackThread>& dstThread, sp<IAfPlaybackThread>* srcThread);
private:

              // return thread associated with primary hardware device, or NULL
              PlaybackThread *primaryPlaybackThread_l() const;
              IAfPlaybackThread* primaryPlaybackThread_l() const;
              DeviceTypeSet primaryOutputDevice_l() const;

              // return the playback thread with smallest HAL buffer size, and prefer fast
              PlaybackThread *fastPlaybackThread_l() const;
              IAfPlaybackThread* fastPlaybackThread_l() const;

              sp<ThreadBase> getEffectThread_l(audio_session_t sessionId, int effectId);
              sp<IAfThreadBase> getEffectThread_l(audio_session_t sessionId, int effectId);

              ThreadBase *hapticPlaybackThread_l() const;
              IAfThreadBase* hapticPlaybackThread_l() const;

              void updateSecondaryOutputsForTrack_l(
                      IAfTrack* track,
                      PlaybackThread* thread,
                      IAfPlaybackThread* thread,
                      const std::vector<audio_io_handle_t>& secondaryOutputs) const;


@@ -760,7 +752,7 @@ private:
                void updateOutDevicesForRecordThreads_l(const DeviceDescriptorBaseVector& devices);
                void forwardParametersToDownstreamPatches_l(
                        audio_io_handle_t upStream, const String8& keyValuePairs,
                        const std::function<bool(const sp<PlaybackThread>&)>& useThread = nullptr);
            const std::function<bool(const sp<IAfPlaybackThread>&)>& useThread = nullptr);

    struct TeePatch {
        sp<IAfPatchRecord> patchRecord;
@@ -833,7 +825,7 @@ private:
    mutable     hardware_call_state                 mHardwareStatus;    // for dump only


                DefaultKeyedVector< audio_io_handle_t, sp<PlaybackThread> >  mPlaybackThreads;
    DefaultKeyedVector<audio_io_handle_t, sp<IAfPlaybackThread>> mPlaybackThreads;
                stream_type_t                       mStreamTypes[AUDIO_STREAM_CNT];

                // member variables below are protected by mLock
@@ -842,7 +834,7 @@ private:
                float                               mMasterBalance = 0.f;
                // end of variables protected by mLock

                DefaultKeyedVector< audio_io_handle_t, sp<RecordThread> >    mRecordThreads;
    DefaultKeyedVector<audio_io_handle_t, sp<IAfRecordThread>> mRecordThreads;

                // protected by mClientLock
                DefaultKeyedVector< pid_t, sp<NotificationClient> >    mNotificationClients;
@@ -880,10 +872,10 @@ private:

    // for use from destructor
    status_t    closeOutput_nonvirtual(audio_io_handle_t output);
    void        closeThreadInternal_l(const sp<PlaybackThread>& thread);
    void closeThreadInternal_l(const sp<IAfPlaybackThread>& thread);
    status_t    closeInput_nonvirtual(audio_io_handle_t input);
    void        closeThreadInternal_l(const sp<RecordThread>& thread);
    void        setAudioHwSyncForSession_l(PlaybackThread *thread, audio_session_t sessionId);
    void closeThreadInternal_l(const sp<IAfRecordThread>& thread);
    void setAudioHwSyncForSession_l(IAfPlaybackThread* thread, audio_session_t sessionId);

    status_t    checkStreamType(audio_stream_type_t stream) const;

+49 −49
Original line number Diff line number Diff line
@@ -2118,21 +2118,21 @@ NO_THREAD_SAFETY_ANALYSIS // conditional try lock

/* static */
sp<IAfEffectChain> IAfEffectChain::create(
        const wp<Thread /*ThreadBase*/>& wThread,  // TODO(b/288339104) update type
        const wp<IAfThreadBase>& wThread,
        audio_session_t sessionId)
{
    // TODO(b/288339104) no weak pointer cast.
    return sp<EffectChain>::make(sp<AudioFlinger::ThreadBase>::cast(wThread.promote()), sessionId);
    return sp<EffectChain>::make(wThread, sessionId);
}

EffectChain::EffectChain(const wp<AudioFlinger::ThreadBase>& thread,
EffectChain::EffectChain(const wp<IAfThreadBase>& thread,
                                       audio_session_t sessionId)
    : mSessionId(sessionId), mActiveTrackCnt(0), mTrackCnt(0), mTailBufferCount(0),
      mVolumeCtrlIdx(-1), mLeftVolume(UINT_MAX), mRightVolume(UINT_MAX),
      mNewLeftVolume(UINT_MAX), mNewRightVolume(UINT_MAX),
      mEffectCallback(new EffectCallback(wp<EffectChain>(this), thread))
{
    sp<AudioFlinger::ThreadBase> p = thread.promote();
    const sp<IAfThreadBase> p = thread.promote();
    if (p == nullptr) {
        return;
    }
@@ -2145,7 +2145,7 @@ EffectChain::~EffectChain()
{
}

// getEffectFromDesc_l() must be called with AudioFlinger::ThreadBase::mLock held
// getEffectFromDesc_l() must be called with IAfThreadBase::mutex() held
sp<IAfEffectModule> EffectChain::getEffectFromDesc_l(
        effect_descriptor_t *descriptor) const
{
@@ -2159,7 +2159,7 @@ sp<IAfEffectModule> EffectChain::getEffectFromDesc_l(
    return 0;
}

// getEffectFromId_l() must be called with AudioFlinger::ThreadBase::mLock held
// getEffectFromId_l() must be called with IAfThreadBase::mutex() held
sp<IAfEffectModule> EffectChain::getEffectFromId_l(int id) const
{
    size_t size = mEffects.size();
@@ -2173,7 +2173,7 @@ sp<IAfEffectModule> EffectChain::getEffectFromId_l(int id) const
    return 0;
}

// getEffectFromType_l() must be called with AudioFlinger::ThreadBase::mLock held
// getEffectFromType_l() must be called with IAfThreadBase::mutex() held
sp<IAfEffectModule> EffectChain::getEffectFromType_l(
        const effect_uuid_t *type) const
{
@@ -2268,7 +2268,7 @@ void EffectChain::process_l()
    }
}

// createEffect_l() must be called with AudioFlinger::ThreadBase::mLock held
// createEffect_l() must be called with IAfThreadBase::mutex() held
status_t EffectChain::createEffect_l(sp<IAfEffectModule>& effect,
                                                   effect_descriptor_t *desc,
                                                   int id,
@@ -2287,13 +2287,13 @@ status_t EffectChain::createEffect_l(sp<IAfEffectModule>& effect,
    return lStatus;
}

// addEffect_l() must be called with AudioFlinger::ThreadBase::mLock held
// addEffect_l() must be called with IAfThreadBase::mutex() held
status_t EffectChain::addEffect_l(const sp<IAfEffectModule>& effect)
{
    Mutex::Autolock _l(mLock);
    return addEffect_ll(effect);
}
// addEffect_l() must be called with AudioFlinger::ThreadBase::mLock and EffectChain::mLock held
// addEffect_l() must be called with IAfThreadBase::mLock and EffectChain::mutex() held
status_t EffectChain::addEffect_ll(const sp<IAfEffectModule>& effect)
{
    effect->setCallback(mEffectCallback);
@@ -2447,7 +2447,7 @@ ssize_t EffectChain::getInsertIndex(const effect_descriptor_t& desc) {
    return idx_insert;
}

// removeEffect_l() must be called with AudioFlinger::ThreadBase::mLock held
// removeEffect_l() must be called with IAfThreadBase::mutex() held
size_t EffectChain::removeEffect_l(const sp<IAfEffectModule>& effect,
                                                 bool release)
{
@@ -2495,7 +2495,7 @@ size_t EffectChain::removeEffect_l(const sp<IAfEffectModule>& effect,
    return mEffects.size();
}

// setDevices_l() must be called with AudioFlinger::ThreadBase::mLock held
// setDevices_l() must be called with IAfThreadBase::mutex() held
void EffectChain::setDevices_l(const AudioDeviceTypeAddrVector &devices)
{
    size_t size = mEffects.size();
@@ -2504,7 +2504,7 @@ void EffectChain::setDevices_l(const AudioDeviceTypeAddrVector &devices)
    }
}

// setInputDevice_l() must be called with AudioFlinger::ThreadBase::mLock held
// setInputDevice_l() must be called with IAfThreadBase::mutex() held
void EffectChain::setInputDevice_l(const AudioDeviceTypeAddr &device)
{
    size_t size = mEffects.size();
@@ -2513,7 +2513,7 @@ void EffectChain::setInputDevice_l(const AudioDeviceTypeAddr &device)
    }
}

// setMode_l() must be called with AudioFlinger::ThreadBase::mLock held
// setMode_l() must be called with IAfThreadBase::mutex() held
void EffectChain::setMode_l(audio_mode_t mode)
{
    size_t size = mEffects.size();
@@ -2522,7 +2522,7 @@ void EffectChain::setMode_l(audio_mode_t mode)
    }
}

// setAudioSource_l() must be called with AudioFlinger::ThreadBase::mLock held
// setAudioSource_l() must be called with IAfThreadBase::mutex() held
void EffectChain::setAudioSource_l(audio_source_t source)
{
    size_t size = mEffects.size();
@@ -2538,7 +2538,7 @@ bool EffectChain::hasVolumeControlEnabled_l() const {
    return false;
}

// setVolume_l() must be called with AudioFlinger::ThreadBase::mLock or EffectChain::mLock held
// setVolume_l() must be called with IAfThreadBase::mLock or EffectChain::mLock held
bool EffectChain::setVolume_l(uint32_t *left, uint32_t *right, bool force)
{
    uint32_t newLeft = *left;
@@ -2605,7 +2605,7 @@ bool EffectChain::setVolume_l(uint32_t *left, uint32_t *right, bool force)
    return hasControl;
}

// resetVolume_l() must be called with AudioFlinger::ThreadBase::mLock or EffectChain::mLock held
// resetVolume_l() must be called with IAfThreadBase::mutex() or EffectChain::mLock held
void EffectChain::resetVolume_l()
{
    if ((mLeftVolume != UINT_MAX) && (mRightVolume != UINT_MAX)) {
@@ -2616,7 +2616,7 @@ void EffectChain::resetVolume_l()
}

// containsHapticGeneratingEffect_l must be called with
// AudioFlinger::ThreadBase::mLock or EffectChain::mLock held
// IAfThreadBase::mutex() or EffectChain::mLock held
bool EffectChain::containsHapticGeneratingEffect_l()
{
    for (size_t i = 0; i < mEffects.size(); ++i) {
@@ -2685,7 +2685,7 @@ NO_THREAD_SAFETY_ANALYSIS // conditional try lock
    }
}

// must be called with AudioFlinger::ThreadBase::mLock held
// must be called with IAfThreadBase::mutex() held
void EffectChain::setEffectSuspended_l(
        const effect_uuid_t *type, bool suspend)
{
@@ -2741,7 +2741,7 @@ void EffectChain::setEffectSuspended_l(
    }
}

// must be called with AudioFlinger::ThreadBase::mLock held
// must be called with IAfThreadBase::mutex() held
void EffectChain::setEffectSuspendedAll_l(bool suspend)
{
    sp<SuspendedEffectDesc> desc;
@@ -2897,7 +2897,7 @@ bool EffectChain::isNonOffloadableEnabled_l() const
    return false;
}

void EffectChain::setThread(const sp<AudioFlinger::ThreadBase>& thread)
void EffectChain::setThread(const sp<IAfThreadBase>& thread)
{
    Mutex::Autolock _l(mLock);
    mEffectCallback->setThread(thread);
@@ -2964,7 +2964,7 @@ bool EffectChain::isBitPerfectCompatible() const {
}

// isCompatibleWithThread_l() must be called with thread->mLock held
bool EffectChain::isCompatibleWithThread_l(const sp<AudioFlinger::ThreadBase>& thread) const
bool EffectChain::isCompatibleWithThread_l(const sp<IAfThreadBase>& thread) const
{
    Mutex::Autolock _l(mLock);
    for (size_t i = 0; i < mEffects.size(); i++) {
@@ -3002,7 +3002,7 @@ status_t EffectChain::EffectCallback::allocateHalBuffer(
status_t EffectChain::EffectCallback::addEffectToHal(
        const sp<EffectHalInterface>& effect) {
    status_t result = NO_INIT;
    sp<AudioFlinger::ThreadBase> t = thread().promote();
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
        return result;
    }
@@ -3018,7 +3018,7 @@ status_t EffectChain::EffectCallback::addEffectToHal(
status_t EffectChain::EffectCallback::removeEffectFromHal(
        const sp<EffectHalInterface>& effect) {
    status_t result = NO_INIT;
    sp<AudioFlinger::ThreadBase> t = thread().promote();
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
        return result;
    }
@@ -3032,7 +3032,7 @@ status_t EffectChain::EffectCallback::removeEffectFromHal(
}

audio_io_handle_t EffectChain::EffectCallback::io() const {
    sp<AudioFlinger::ThreadBase> t = thread().promote();
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
        return AUDIO_IO_HANDLE_NONE;
    }
@@ -3040,7 +3040,7 @@ audio_io_handle_t EffectChain::EffectCallback::io() const {
}

bool EffectChain::EffectCallback::isOutput() const {
    sp<AudioFlinger::ThreadBase> t = thread().promote();
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
        return true;
    }
@@ -3048,19 +3048,19 @@ bool EffectChain::EffectCallback::isOutput() const {
}

bool EffectChain::EffectCallback::isOffload() const {
    return mThreadType == AudioFlinger::ThreadBase::OFFLOAD;
    return mThreadType == IAfThreadBase::OFFLOAD;
}

bool EffectChain::EffectCallback::isOffloadOrDirect() const {
    return mThreadType == AudioFlinger::ThreadBase::OFFLOAD
            || mThreadType == AudioFlinger::ThreadBase::DIRECT;
    return mThreadType == IAfThreadBase::OFFLOAD
            || mThreadType == IAfThreadBase::DIRECT;
}

bool EffectChain::EffectCallback::isOffloadOrMmap() const {
    switch (mThreadType) {
    case AudioFlinger::ThreadBase::OFFLOAD:
    case AudioFlinger::ThreadBase::MMAP_PLAYBACK:
    case AudioFlinger::ThreadBase::MMAP_CAPTURE:
    case IAfThreadBase::OFFLOAD:
    case IAfThreadBase::MMAP_PLAYBACK:
    case IAfThreadBase::MMAP_CAPTURE:
        return true;
    default:
        return false;
@@ -3068,11 +3068,11 @@ bool EffectChain::EffectCallback::isOffloadOrMmap() const {
}

bool EffectChain::EffectCallback::isSpatializer() const {
    return mThreadType == AudioFlinger::ThreadBase::SPATIALIZER;
    return mThreadType == IAfThreadBase::SPATIALIZER;
}

uint32_t EffectChain::EffectCallback::sampleRate() const {
    sp<AudioFlinger::ThreadBase> t = thread().promote();
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
        return 0;
    }
@@ -3080,7 +3080,7 @@ uint32_t EffectChain::EffectCallback::sampleRate() const {
}

audio_channel_mask_t EffectChain::EffectCallback::inChannelMask(int id) const {
    sp<AudioFlinger::ThreadBase> t = thread().promote();
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
        return AUDIO_CHANNEL_NONE;
    }
@@ -3089,7 +3089,7 @@ audio_channel_mask_t EffectChain::EffectCallback::inChannelMask(int id) const {
        return AUDIO_CHANNEL_NONE;
    }

    if (mThreadType == AudioFlinger::ThreadBase::SPATIALIZER) {
    if (mThreadType == IAfThreadBase::SPATIALIZER) {
        if (c->sessionId() == AUDIO_SESSION_OUTPUT_STAGE) {
            if (c->isFirstEffect(id)) {
                return t->mixerChannelMask();
@@ -3098,7 +3098,7 @@ audio_channel_mask_t EffectChain::EffectCallback::inChannelMask(int id) const {
            }
        } else if (!audio_is_global_session(c->sessionId())) {
            if ((t->hasAudioSession_l(c->sessionId())
                    & AudioFlinger::ThreadBase::SPATIALIZED_SESSION) != 0) {
                    & IAfThreadBase::SPATIALIZED_SESSION) != 0) {
                return t->mixerChannelMask();
            } else {
                return t->channelMask();
@@ -3116,7 +3116,7 @@ uint32_t EffectChain::EffectCallback::inChannelCount(int id) const {
}

audio_channel_mask_t EffectChain::EffectCallback::outChannelMask() const {
    sp<AudioFlinger::ThreadBase> t = thread().promote();
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
        return AUDIO_CHANNEL_NONE;
    }
@@ -3125,10 +3125,10 @@ audio_channel_mask_t EffectChain::EffectCallback::outChannelMask() const {
        return AUDIO_CHANNEL_NONE;
    }

    if (mThreadType == AudioFlinger::ThreadBase::SPATIALIZER) {
    if (mThreadType == IAfThreadBase::SPATIALIZER) {
        if (!audio_is_global_session(c->sessionId())) {
            if ((t->hasAudioSession_l(c->sessionId())
                    & AudioFlinger::ThreadBase::SPATIALIZED_SESSION) != 0) {
                    & IAfThreadBase::SPATIALIZED_SESSION) != 0) {
                return t->mixerChannelMask();
            } else {
                return t->channelMask();
@@ -3146,7 +3146,7 @@ uint32_t EffectChain::EffectCallback::outChannelCount() const {
}

audio_channel_mask_t EffectChain::EffectCallback::hapticChannelMask() const {
    sp<AudioFlinger::ThreadBase> t = thread().promote();
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
        return AUDIO_CHANNEL_NONE;
    }
@@ -3154,7 +3154,7 @@ audio_channel_mask_t EffectChain::EffectCallback::hapticChannelMask() const {
}

size_t EffectChain::EffectCallback::frameCount() const {
    sp<AudioFlinger::ThreadBase> t = thread().promote();
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
        return 0;
    }
@@ -3164,7 +3164,7 @@ size_t EffectChain::EffectCallback::frameCount() const {
uint32_t EffectChain::EffectCallback::latency() const
NO_THREAD_SAFETY_ANALYSIS  // latency_l() access
{
    sp<AudioFlinger::ThreadBase> t = thread().promote();
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
        return 0;
    }
@@ -3175,7 +3175,7 @@ NO_THREAD_SAFETY_ANALYSIS // latency_l() access
void EffectChain::EffectCallback::setVolumeForOutput(float left, float right) const
NO_THREAD_SAFETY_ANALYSIS  // setVolumeForOutput_l() access
{
    sp<AudioFlinger::ThreadBase> t = thread().promote();
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
        return;
    }
@@ -3184,7 +3184,7 @@ NO_THREAD_SAFETY_ANALYSIS // setVolumeForOutput_l() access

void EffectChain::EffectCallback::checkSuspendOnEffectEnabled(
        const sp<IAfEffectBase>& effect, bool enabled, bool threadLocked) {
    sp<AudioFlinger::ThreadBase> t = thread().promote();
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
        return;
    }
@@ -3199,7 +3199,7 @@ void EffectChain::EffectCallback::checkSuspendOnEffectEnabled(
}

void EffectChain::EffectCallback::onEffectEnable(const sp<IAfEffectBase>& effect) {
    sp<AudioFlinger::ThreadBase> t = thread().promote();
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
        return;
    }
@@ -3210,7 +3210,7 @@ void EffectChain::EffectCallback::onEffectEnable(const sp<IAfEffectBase>& effect
void EffectChain::EffectCallback::onEffectDisable(const sp<IAfEffectBase>& effect) {
    checkSuspendOnEffectEnabled(effect, false, false /*threadLocked*/);

    sp<AudioFlinger::ThreadBase> t = thread().promote();
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
        return;
    }
@@ -3219,7 +3219,7 @@ void EffectChain::EffectCallback::onEffectDisable(const sp<IAfEffectBase>& effec

bool EffectChain::EffectCallback::disconnectEffectHandle(IAfEffectHandle *handle,
                                                      bool unpinIfLast) {
    sp<AudioFlinger::ThreadBase> t = thread().promote();
    const sp<IAfThreadBase> t = thread().promote();
    if (t == nullptr) {
        return false;
    }
@@ -3401,7 +3401,7 @@ status_t DeviceEffectProxy::checkPort(const AudioFlinger::PatchPanel::Patch& pat
            mDevicePort.id = AUDIO_PORT_HANDLE_NONE;
        }
    } else if (patch.isSoftware() || patch.thread().promote() != nullptr) {
        sp <AudioFlinger::ThreadBase> thread;
        sp<IAfThreadBase> thread;
        if (audio_port_config_has_input_direction(port)) {
            if (patch.isSoftware()) {
                thread = patch.mRecord.thread();
+11 −22
Original line number Diff line number Diff line
@@ -382,7 +382,7 @@ private:
// it also provide it's own input buffer used by the track as accumulation buffer.
class EffectChain : public IAfEffectChain {
public:
    EffectChain(const wp<AudioFlinger::ThreadBase>& wThread, audio_session_t sessionId);
    EffectChain(const wp<IAfThreadBase>& wThread, audio_session_t sessionId);
    ~EffectChain() override;

    void process_l() final;
@@ -479,12 +479,7 @@ public:
    bool isBitPerfectCompatible() const final;

    // isCompatibleWithThread_l() must be called with thread->mLock held
    // TODO(b/288339104) type
    bool isCompatibleWithThread_l(const sp<Thread>& thread) const final {
        return isCompatibleWithThread_l(sp<AudioFlinger::ThreadBase>::cast(thread));
    }

    bool isCompatibleWithThread_l(const sp<AudioFlinger::ThreadBase>& thread) const;
    bool isCompatibleWithThread_l(const sp<IAfThreadBase>& thread) const final;

    bool containsHapticGeneratingEffect_l() final;

@@ -492,8 +487,7 @@ public:

    sp<EffectCallbackInterface> effectCallback() const final { return mEffectCallback; }

    // TODO(b/288339104) type
    wp<Thread> thread() const final { return mEffectCallback->thread(); }
    wp<IAfThreadBase> thread() const final { return mEffectCallback->thread(); }

    bool isFirstEffect(int id) const final {
        return !mEffects.isEmpty() && id == mEffects[0]->id();
@@ -507,12 +501,7 @@ public:
        return mEffects[index];
    }

    // TODO(b/288339104) type
    void setThread(const sp<Thread>& thread) final {
        setThread(sp<AudioFlinger::ThreadBase>::cast(thread));
    }

    void setThread(const sp<AudioFlinger::ThreadBase>& thread);
    void setThread(const sp<IAfThreadBase>& thread) final;

private:

@@ -527,15 +516,15 @@ private:
        // Note: ctors taking a weak pointer to their owner must not promote it
        // during construction (but may keep a reference for later promotion).
        EffectCallback(const wp<EffectChain>& owner,
                       const wp<AudioFlinger::ThreadBase>& thread)
                const wp<IAfThreadBase>& thread)
            : mChain(owner)
            , mThread(thread)
            , mAudioFlinger(*AudioFlinger::gAudioFlinger) {
            sp<AudioFlinger::ThreadBase> base = thread.promote();
            const sp<IAfThreadBase> base = thread.promote();
            if (base != nullptr) {
                mThreadType = base->type();
            } else {
                mThreadType = AudioFlinger::ThreadBase::MIXER;  // assure a consistent value.
                mThreadType = IAfThreadBase::MIXER;  // assure a consistent value.
            }
        }

@@ -580,18 +569,18 @@ private:
            return mAudioFlinger.isAudioPolicyReady();
        }

        wp<AudioFlinger::ThreadBase> thread() const { return mThread.load(); }
        wp<IAfThreadBase> thread() const { return mThread.load(); }

        void setThread(const sp<AudioFlinger::ThreadBase>& thread) {
        void setThread(const sp<IAfThreadBase>& thread) {
            mThread = thread;
            mThreadType = thread->type();
        }

    private:
        const wp<IAfEffectChain> mChain;
        mediautils::atomic_wp<AudioFlinger::ThreadBase> mThread;
        mediautils::atomic_wp<IAfThreadBase> mThread;
        AudioFlinger &mAudioFlinger;  // implementation detail: outer instance always exists.
        AudioFlinger::ThreadBase::type_t mThreadType;
        IAfThreadBase::type_t mThreadType;
    };

    DISALLOW_COPY_AND_ASSIGN(EffectChain);
+5 −5
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ class IAfEffectBase;
class IAfEffectChain;
class IAfEffectHandle;
class IAfEffectModule;
class IAfThreadBase;

// Interface implemented by the EffectModule parent or owner (e.g an EffectChain) to abstract
// interactions between the EffectModule and the reset of the audio framework.
@@ -190,7 +191,7 @@ class IAfEffectChain : public RefBase {
    // Most of these methods are accessed from AudioFlinger::Thread
public:
    static sp<IAfEffectChain> create(
            const wp<Thread /*ThreadBase*/>& wThread,  // TODO(b/288339104) type
            const wp<IAfThreadBase>& wThread,
            audio_session_t sessionId);

    // special key used for an entry in mSuspendedEffects keyed vector
@@ -279,8 +280,7 @@ public:
    virtual bool isBitPerfectCompatible() const = 0;

    // isCompatibleWithThread_l() must be called with thread->mLock held
    //  TODO(b/288339104) type
    virtual bool isCompatibleWithThread_l(const sp<Thread>& thread) const = 0;
    virtual bool isCompatibleWithThread_l(const sp<IAfThreadBase>& thread) const = 0;

    virtual bool containsHapticGeneratingEffect_l() = 0;

@@ -288,8 +288,8 @@ public:

    virtual sp<EffectCallbackInterface> effectCallback() const = 0;

    virtual wp<Thread> thread() const = 0;  // TODO(b/288339104) type
    virtual void setThread(const sp<Thread>& thread) = 0;  // TODO(b/288339104) type
    virtual wp<IAfThreadBase> thread() const = 0;
    virtual void setThread(const sp<IAfThreadBase>& thread) = 0;

    virtual bool isFirstEffect(int id) const = 0;

Loading