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

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

VolumeShaper: Update Direct/Offload to use media time

Test: atest --host monotonicframecounter_tests
Test: atest VolumeShaperTest
Bug: 253083520
Merged-In: I0d8d73e70ed52c760cd483ebdb62e0f10b7f642d
Change-Id: I0d8d73e70ed52c760cd483ebdb62e0f10b7f642d
parent 4a3734db
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -180,6 +180,7 @@ cc_library_shared {
        "av-types-aidl-cpp",
        "effect-aidl-cpp",
        "libaudioclient_aidl_conversion",
        "libaudioflinger_timing",
        "libaudiofoundation",
        "libaudiohal",
        "libaudioprocessing",
+2 −0
Original line number Diff line number Diff line
@@ -84,6 +84,8 @@
#include <audio_utils/SimpleLog.h>
#include <audio_utils/TimestampVerifier.h>

#include <timing/MonotonicFrameCounter.h>

#include "FastCapture.h"
#include "FastMixer.h"
#include <media/nbaio/NBAIO.h>
+13 −2
Original line number Diff line number Diff line
@@ -6190,8 +6190,18 @@ void AudioFlinger::DirectOutputThread::processVolume_l(Track *track, bool lastTr

    // Ensure volumeshaper state always advances even when muted.
    const sp<AudioTrackServerProxy> proxy = track->mAudioTrackServerProxy;
    const auto [shaperVolume, shaperActive] = track->getVolumeHandler()->getVolume(
            proxy->framesReleased());

    const size_t framesReleased = proxy->framesReleased();
    const int64_t frames = mTimestamp.mPosition[ExtendedTimestamp::LOCATION_KERNEL];
    const int64_t time = mTimestamp.mTimeNs[ExtendedTimestamp::LOCATION_KERNEL];

    ALOGV("%s: Direct/Offload bufferConsumed:%zu  timestamp frames:%lld  time:%lld",
            __func__, framesReleased, (long long)frames, (long long)time);

    const int64_t volumeShaperFrames =
            mMonotonicFrameCounter.updateAndGetMonotonicFrameCount(frames, time);
    const auto [shaperVolume, shaperActive] =
            track->getVolumeHandler()->getVolume(volumeShaperFrames);
    mVolumeShaperActive = shaperActive;

    if (mMasterMute || mStreamTypes[track->streamType()].mute || track->isPlaybackRestricted()) {
@@ -6667,6 +6677,7 @@ void AudioFlinger::DirectOutputThread::flushHw_l()
    mFlushPending = false;
    mTimestampVerifier.discontinuity(discontinuityForStandbyOrFlush());
    mTimestamp.clear();
    mMonotonicFrameCounter.onFlush();
}

int64_t AudioFlinger::DirectOutputThread::computeWaitTimeNs_l() const {
+2 −0
Original line number Diff line number Diff line
@@ -1581,6 +1581,8 @@ protected:
    virtual     void        onAddNewTrack_l();

    const       audio_offload_info_t mOffloadInfo;

    audioflinger::MonotonicFrameCounter mMonotonicFrameCounter;  // for VolumeShaper
    bool mVolumeShaperActive = false;

    DirectOutputThread(const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output,
+1 −19
Original line number Diff line number Diff line
@@ -1366,25 +1366,7 @@ VolumeShaper::Status AudioFlinger::PlaybackThread::Track::applyVolumeShaper(
        const sp<VolumeShaper::Configuration>& configuration,
        const sp<VolumeShaper::Operation>& operation)
{
    sp<VolumeShaper::Configuration> newConfiguration;

    if (isOffloadedOrDirect()) {
        const VolumeShaper::Configuration::OptionFlag optionFlag
            = configuration->getOptionFlags();
        if ((optionFlag & VolumeShaper::Configuration::OPTION_FLAG_CLOCK_TIME) == 0) {
            ALOGW("%s(%d): %s tracks do not support frame counted VolumeShaper,"
                    " using clock time instead",
                    __func__, mId,
                    isOffloaded() ? "Offload" : "Direct");
            newConfiguration = new VolumeShaper::Configuration(*configuration);
            newConfiguration->setOptionFlags(
                VolumeShaper::Configuration::OptionFlag(optionFlag
                        | VolumeShaper::Configuration::OPTION_FLAG_CLOCK_TIME));
        }
    }

    VolumeShaper::Status status = mVolumeHandler->applyVolumeShaper(
            (newConfiguration.get() != nullptr ? newConfiguration : configuration), operation);
    VolumeShaper::Status status = mVolumeHandler->applyVolumeShaper(configuration, operation);

    if (isOffloadedOrDirect()) {
        // Signal thread to fetch new volume.
Loading