Fix odd values in aaudio metrics.
1. Do not log the AudioStream information if it is from the service. The
service side may automatically create an AudioStreamInternal instance
when a shared endpoint is used. This is not the interesting part for the
metrics.
2. If the aaudio stream uses legacy path, only channel mask will be
logged. Calculate channel count from channel mask for logging aaudio
metrics.
Test: atest AAudioTests MediaMetricsAtomTests
Test: dumpsys media.metrics
Bug: 194937266
Bug: 192313064
Change-Id: I183224a4acc59c40d511ee2eb37da05210851348
(cherry picked from commit fbf2030e6935180d03885901992bb679cca8f922)
diff --git a/services/mediametrics/AudioAnalytics.cpp b/services/mediametrics/AudioAnalytics.cpp
index 11ec993..45c9f56 100644
--- a/services/mediametrics/AudioAnalytics.cpp
+++ b/services/mediametrics/AudioAnalytics.cpp
@@ -24,6 +24,7 @@
#include <audio_utils/clock.h> // clock conversions
#include <cutils/properties.h>
#include <statslog.h> // statsd
+#include <system/audio.h>
#include "AudioTypes.h" // string to int conversions
#include "MediaMetricsService.h" // package info
@@ -957,6 +958,25 @@
int32_t channelCount = -1;
mAudioAnalytics.mAnalyticsState->timeMachine().get(
key, AMEDIAMETRICS_PROP_CHANNELCOUNT, &channelCount);
+ if (channelCount == -1) {
+ // Try to get channel count from channel mask. From the legacy path,
+ // only channel mask are logged.
+ int32_t channelMask = 0;
+ mAudioAnalytics.mAnalyticsState->timeMachine().get(
+ key, AMEDIAMETRICS_PROP_CHANNELMASK, &channelMask);
+ if (channelMask != 0) {
+ switch (direction) {
+ case 1: // Output, keep sync with AudioTypes#getAAudioDirection()
+ channelCount = audio_channel_count_from_out_mask(channelMask);
+ break;
+ case 2: // Input, keep sync with AudioTypes#getAAudioDirection()
+ channelCount = audio_channel_count_from_in_mask(channelMask);
+ break;
+ default:
+ ALOGW("Invalid direction %d", direction);
+ }
+ }
+ }
int64_t totalFramesTransferred = -1;
mAudioAnalytics.mAnalyticsState->timeMachine().get(