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

Commit d9357a6d authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Cache native audio manager interface" into main

parents 19bcdd47 8623bbd9
Loading
Loading
Loading
Loading
+17 −9
Original line number Diff line number Diff line
@@ -3079,19 +3079,27 @@ status_t AudioFlinger::systemReady()
    return NO_ERROR;
}

sp<IAudioManager> AudioFlinger::getOrCreateAudioManager()
{
    if (mAudioManager.load() == nullptr) {
sp<IAudioManager> AudioFlinger::getOrCreateAudioManager() {
    sp<IAudioManager> iface = mAudioManager.load();
    if (iface == nullptr) {
        // use checkService() to avoid blocking
        sp<IBinder> binder =
            defaultServiceManager()->checkService(String16(kAudioServiceName));
        sp<IBinder> binder = defaultServiceManager()->checkService(String16(kAudioServiceName));
        if (binder != nullptr) {
            mAudioManager = interface_cast<IAudioManager>(binder);
            iface = interface_cast<IAudioManager>(binder);
            if (const auto native_iface = iface->getNativeInterface(); native_iface) {
                mAudioManagerNative = std::move(native_iface);
                mAudioManager.store(iface);
            } else {
            ALOGE("%s(): binding to audio service failed.", __func__);
                iface = nullptr;
            }
        }
    }
    return mAudioManager.load();
    ALOGE_IF(iface == nullptr, "%s(): binding to audio service failed.", __func__);
    return iface;
}

sp<media::IAudioManagerNative> AudioFlinger::getAudioManagerNative() const {
    return mAudioManagerNative.load();
}

status_t AudioFlinger::getMicrophones(std::vector<media::MicrophoneInfoFw>* microphones) const
+3 −1
Original line number Diff line number Diff line
@@ -382,6 +382,7 @@ private:
        return mEffectsFactoryHal;
    }
    sp<IAudioManager> getOrCreateAudioManager() final;
    sp<media::IAudioManagerNative> getAudioManagerNative() const final;

    // Called when the last effect handle on an effect instance is removed. If this
    // effect belongs to an effect chain in mOrphanEffectChains, the chain is updated
@@ -807,8 +808,9 @@ private:
    int32_t mAAudioBurstsPerBuffer GUARDED_BY(mutex()) = 0;
    int32_t mAAudioHwBurstMinMicros GUARDED_BY(mutex()) = 0;

    /** Interface for interacting with the AudioService. */
    /** Interfaces for interacting with the AudioService. */
    mediautils::atomic_sp<IAudioManager> mAudioManager;
    mediautils::atomic_sp<media::IAudioManagerNative> mAudioManagerNative;

    // Bluetooth Variable latency control logic is enabled or disabled
    std::atomic<bool> mBluetoothLatencyModesEnabled = true;
+4 −1
Original line number Diff line number Diff line
@@ -96,7 +96,10 @@ public:
    virtual const sp<IAfPatchPanel>& getPatchPanel() const = 0;
    virtual const sp<MelReporter>& getMelReporter() const = 0;
    virtual const sp<EffectsFactoryHalInterface>& getEffectsFactoryHal() const = 0;
    virtual sp<IAudioManager> getOrCreateAudioManager() = 0;  // Tracks
    // AudioService interfaces
    virtual sp<IAudioManager> getOrCreateAudioManager() = 0;
    // Populated after getOrCreateAudioManager
    virtual sp<media::IAudioManagerNative> getAudioManagerNative() const = 0;

    virtual bool updateOrphanEffectChains(const sp<IAfEffectModule>& effect)
            EXCLUDES_AudioFlinger_Mutex = 0;
+13 −9
Original line number Diff line number Diff line
@@ -5865,8 +5865,10 @@ PlaybackThread::mixer_state MixerThread::prepareTracks_l(
                        volume = masterVolume * track->getPortVolume();
                    }
                }
                track->maybeLogPlaybackHardening(
                        *mAfThreadCallback->getOrCreateAudioManager()->getNativeInterface());
                if (const auto iface = mAfThreadCallback->getAudioManagerNative(); iface) {
                    track->maybeLogPlaybackHardening(*iface);
                }

                handleVoipVolume_l(&volume);

                // cache the combined master volume and stream type volume for fast mixer; this
@@ -6064,8 +6066,9 @@ PlaybackThread::mixer_state MixerThread::prepareTracks_l(
                }
            }
            handleVoipVolume_l(&v);
            track->maybeLogPlaybackHardening(
                    *mAfThreadCallback->getOrCreateAudioManager()->getNativeInterface());
            if (const auto iface = mAfThreadCallback->getAudioManagerNative(); iface) {
                track->maybeLogPlaybackHardening(*iface);
            }

            if (track->isPausing()) {
                vl = vr = 0;
@@ -6895,8 +6898,9 @@ void DirectOutputThread::processVolume_l(IAfTrack* track, bool lastTrack)
                               track->getPortMute(),
                               track->isPlaybackRestrictedControl()});
    }
    track->maybeLogPlaybackHardening(
            *mAfThreadCallback->getOrCreateAudioManager()->getNativeInterface());
    if (const auto iface = mAfThreadCallback->getAudioManagerNative(); iface) {
        track->maybeLogPlaybackHardening(*iface);
    }


    if (lastTrack) {
@@ -11470,9 +11474,9 @@ NO_THREAD_SAFETY_ANALYSIS // access of track->processMuteEvent_l
                                   track->getPortMute(),
                                   shouldMutePlaybackHardening});
            }
            track->maybeLogPlaybackHardening(
                    *mAfThreadCallback->getOrCreateAudioManager()->getNativeInterface());

            if (const auto iface = mAfThreadCallback->getAudioManagerNative(); iface) {
                track->maybeLogPlaybackHardening(*iface);
            }
        }
    }
}