VolumeShaper: Update Direct/Offload to use media time
Test: atest --host monotonicframecounter_tests
Test: atest VolumeShaperTest
Bug: 253083520
Change-Id: I0d8d73e70ed52c760cd483ebdb62e0f10b7f642d
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index f917527..45142cd 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -6281,11 +6281,20 @@
{
float left, right;
-
// 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;
gain_minifloat_packed_t vlr = proxy->getVolumeLR();
@@ -6767,6 +6776,7 @@
mFlushPending = false;
mTimestampVerifier.discontinuity(discontinuityForStandbyOrFlush());
mTimestamp.clear();
+ mMonotonicFrameCounter.onFlush();
}
int64_t AudioFlinger::DirectOutputThread::computeWaitTimeNs_l() const {