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

Commit 03595b6d authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 6852881 from 3195a132 to rvc-qpr1-release

Change-Id: Ia44770316fc7fff58b4edf24d551aa0b84335521
parents 8a588187 3195a132
Loading
Loading
Loading
Loading
+29 −16
Original line number Diff line number Diff line
@@ -47,8 +47,9 @@ dynamic_policy_callback AudioSystem::gDynPolicyCallback = NULL;
record_config_callback AudioSystem::gRecordConfigCallback = NULL;

// Required to be held while calling into gSoundTriggerCaptureStateListener.
class CaptureStateListenerImpl;
Mutex gSoundTriggerCaptureStateListenerLock;
sp<AudioSystem::CaptureStateListener> gSoundTriggerCaptureStateListener = nullptr;
sp<CaptureStateListenerImpl> gSoundTriggerCaptureStateListener = nullptr;

// establish binder interface to AudioFlinger service
const sp<IAudioFlinger> AudioSystem::get_audio_flinger()
@@ -1634,42 +1635,54 @@ status_t AudioSystem::getPreferredDeviceForStrategy(product_strategy_t strategy,
class CaptureStateListenerImpl : public media::BnCaptureStateListener,
                                 public IBinder::DeathRecipient {
public:
    CaptureStateListenerImpl(
            const sp<IAudioPolicyService>& aps,
            const sp<AudioSystem::CaptureStateListener>& listener)
            : mAps(aps), mListener(listener) {}

    void init() {
        bool active;
        status_t status = mAps->registerSoundTriggerCaptureStateListener(this, &active);
        if (status != NO_ERROR) {
            mListener->onServiceDied();
            return;
        }
        mListener->onStateChanged(active);
        IInterface::asBinder(mAps)->linkToDeath(this);
    }

    binder::Status setCaptureState(bool active) override {
        Mutex::Autolock _l(gSoundTriggerCaptureStateListenerLock);
        gSoundTriggerCaptureStateListener->onStateChanged(active);
        mListener->onStateChanged(active);
        return binder::Status::ok();
    }

    void binderDied(const wp<IBinder>&) override {
        Mutex::Autolock _l(gSoundTriggerCaptureStateListenerLock);
        gSoundTriggerCaptureStateListener->onServiceDied();
        mListener->onServiceDied();
        gSoundTriggerCaptureStateListener = nullptr;
    }

private:
    // Need this in order to keep the death receipent alive.
    sp<IAudioPolicyService> mAps;
    sp<AudioSystem::CaptureStateListener> mListener;
};

status_t AudioSystem::registerSoundTriggerCaptureStateListener(
    const sp<CaptureStateListener>& listener) {
    LOG_ALWAYS_FATAL_IF(listener == nullptr);

    const sp<IAudioPolicyService>& aps =
            AudioSystem::get_audio_policy_service();
    if (aps == 0) {
        return PERMISSION_DENIED;
    }

    sp<CaptureStateListenerImpl> wrapper = new CaptureStateListenerImpl();

    Mutex::Autolock _l(gSoundTriggerCaptureStateListenerLock);
    gSoundTriggerCaptureStateListener = new CaptureStateListenerImpl(aps, listener);
    gSoundTriggerCaptureStateListener->init();

    bool active;
    status_t status =
        aps->registerSoundTriggerCaptureStateListener(wrapper, &active);
    if (status != NO_ERROR) {
        listener->onServiceDied();
        return NO_ERROR;
    }
    gSoundTriggerCaptureStateListener = listener;
    listener->onStateChanged(active);
    sp<IBinder> binder = IInterface::asBinder(aps);
    binder->linkToDeath(wrapper);
    return NO_ERROR;
}

+7 −3
Original line number Diff line number Diff line
@@ -2362,7 +2362,7 @@ sp<AudioFlinger::PlaybackThread::Track> AudioFlinger::PlaybackThread::createTrac
        {
            Mutex::Autolock _atCbL(mAudioTrackCbLock);
            if (callback.get() != nullptr) {
                mAudioTrackCallbacks.emplace(callback);
                mAudioTrackCallbacks.emplace(track, callback);
            }
        }

@@ -2590,6 +2590,10 @@ void AudioFlinger::PlaybackThread::removeTrack_l(const sp<Track>& track)
    mLocalLog.log("removeTrack_l (%p) %s", track.get(), result.string());

    mTracks.remove(track);
    {
        Mutex::Autolock _atCbL(mAudioTrackCbLock);
        mAudioTrackCallbacks.erase(track);
    }
    if (track->isFastTrack()) {
        int index = track->mFastIndex;
        ALOG_ASSERT(0 < index && index < (int)FastMixerState::sMaxFastTracks);
@@ -2685,8 +2689,8 @@ void AudioFlinger::PlaybackThread::onCodecFormatChanged(
                    audio_utils::metadata::byteStringFromData(metadata);
            std::vector metadataVec(metaDataStr.begin(), metaDataStr.end());
            Mutex::Autolock _l(mAudioTrackCbLock);
            for (const auto& callback : mAudioTrackCallbacks) {
                callback->onCodecFormatChanged(metadataVec);
            for (const auto& callbackPair : mAudioTrackCallbacks) {
                callbackPair.second->onCodecFormatChanged(metadataVec);
            }
    }).detach();
}
+1 −1
Original line number Diff line number Diff line
@@ -1187,7 +1187,7 @@ private:

    Mutex                                    mAudioTrackCbLock;
    // Record of IAudioTrackCallback
    std::set<sp<media::IAudioTrackCallback>> mAudioTrackCallbacks;
    std::map<sp<Track>, sp<media::IAudioTrackCallback>> mAudioTrackCallbacks;

private:
    // The HAL output sink is treated as non-blocking, but current implementation is blocking