TrackMetrics: Fix volume computation
Average volume should be weighted based on active time
not total lifetime.
Improve the numerical accuracy of average volume using
West's algorithm.
Remove unneeded variables.
Test: youtube, play/pause, adb shell dumpsys media.metrics
Bug: 233409482
Change-Id: I9fadb7287bd0bccbf5c74aad5a07eab277303d02
diff --git a/services/audioflinger/Tracks.cpp b/services/audioflinger/Tracks.cpp
index a9720da..30301a8 100644
--- a/services/audioflinger/Tracks.cpp
+++ b/services/audioflinger/Tracks.cpp
@@ -1123,6 +1123,7 @@
.mPosition[ExtendedTimestamp::LOCATION_KERNEL];
mLogLatencyMs = 0.;
}
+ mLogForceVolumeUpdate = true; // at least one volume logged for metrics when starting.
if (status == NO_ERROR || status == ALREADY_EXISTS) {
// for streaming tracks, remove the buffer read stop limit.
@@ -1394,7 +1395,11 @@
if (mFinalVolume != volume) { // Compare to an epsilon if too many meaningless updates
mFinalVolume = volume;
setMetadataHasChanged();
- mTrackMetrics.logVolume(volume);
+ mLogForceVolumeUpdate = true;
+ }
+ if (mLogForceVolumeUpdate) {
+ mLogForceVolumeUpdate = false;
+ mTrackMetrics.logVolume(mFinalVolume);
}
}