APM: update logic of populating profiles for dynamic mix port.
For AIDL HAL, use getAudioPort API to query the profiles for the dynamic
mix ports.
For HIDL HAL, if the HAL supports getAudioPort API, add the profiles of
the device port that contain attributes also reported by getParameters
API. The attributes reported by getParameters API but not in device port
will also be added to mix port.
The reason of using getAudioPort API instead of getParameters is that
getAudioPort API can return well structed audio profiles, which show the
correct relationship between audio format and sample rates, channel
masks.
Test: repo steps from the bug
Test: atest audiofoundation_containers_test
Test: atest audiopolicy_tests
Bug: 284033428
Change-Id: I6d3faf49470514c05fe57be755bb868d74d74dbb
diff --git a/services/audiopolicy/tests/AudioPolicyManagerTestClient.h b/services/audiopolicy/tests/AudioPolicyManagerTestClient.h
index 3629c16..7ef0266 100644
--- a/services/audiopolicy/tests/AudioPolicyManagerTestClient.h
+++ b/services/audiopolicy/tests/AudioPolicyManagerTestClient.h
@@ -201,6 +201,26 @@
return mAudioParameters.toString();
}
+ status_t getAudioMixPort(const struct audio_port_v7 *devicePort __unused,
+ struct audio_port_v7 *mixPort) override {
+ mixPort->num_audio_profiles = 0;
+ for (auto format : mSupportedFormats) {
+ const int i = mixPort->num_audio_profiles;
+ mixPort->audio_profiles[i].format = format;
+ mixPort->audio_profiles[i].num_sample_rates = 1;
+ mixPort->audio_profiles[i].sample_rates[0] = 48000;
+ mixPort->audio_profiles[i].num_channel_masks = 0;
+ for (const auto& cm : mSupportedChannelMasks) {
+ if (audio_channel_mask_is_valid(cm)) {
+ mixPort->audio_profiles[i].channel_masks[
+ mixPort->audio_profiles[i].num_channel_masks++] = cm;
+ }
+ }
+ mixPort->num_audio_profiles++;
+ }
+ return NO_ERROR;
+ }
+
void addSupportedFormat(audio_format_t format) {
mSupportedFormats.insert(format);
}
diff --git a/services/audiopolicy/tests/AudioPolicyTestClient.h b/services/audiopolicy/tests/AudioPolicyTestClient.h
index 2ae0e97..e55e935 100644
--- a/services/audiopolicy/tests/AudioPolicyTestClient.h
+++ b/services/audiopolicy/tests/AudioPolicyTestClient.h
@@ -106,6 +106,10 @@
status_t invalidateTracks(const std::vector<audio_port_handle_t>& /*portIds*/) override {
return NO_INIT;
}
+ status_t getAudioMixPort(const struct audio_port_v7 *devicePort __unused,
+ struct audio_port_v7 *mixPort __unused) override {
+ return INVALID_OPERATION;
+ }
};
} // namespace android
diff --git a/services/audiopolicy/tests/audiopolicymanager_tests.cpp b/services/audiopolicy/tests/audiopolicymanager_tests.cpp
index 5e58dbb..378255d 100644
--- a/services/audiopolicy/tests/audiopolicymanager_tests.cpp
+++ b/services/audiopolicy/tests/audiopolicymanager_tests.cpp
@@ -1423,6 +1423,7 @@
ASSERT_NO_FATAL_FAILURE(AudioPolicyManagerTest::SetUp());
mClient->addSupportedFormat(AUDIO_FORMAT_AC3);
mClient->addSupportedFormat(AUDIO_FORMAT_E_AC3);
+ mClient->addSupportedChannelMask(AUDIO_CHANNEL_OUT_STEREO);
mManager->setDeviceConnectionState(
AUDIO_DEVICE_OUT_HDMI, AUDIO_POLICY_DEVICE_STATE_AVAILABLE,
"" /*address*/, "" /*name*/, AUDIO_FORMAT_DEFAULT);
@@ -1548,13 +1549,13 @@
mManager->setForceUse(
AUDIO_POLICY_FORCE_FOR_ENCODED_SURROUND, AUDIO_POLICY_FORCE_ENCODED_SURROUND_MANUAL);
- ASSERT_EQ(NO_ERROR, mManager->setSurroundFormatEnabled(GetParam(), false /*enabled*/));
- auto formats = getFormatsFromPorts();
- ASSERT_EQ(0, formats.count(GetParam()));
-
ASSERT_EQ(NO_ERROR, mManager->setSurroundFormatEnabled(GetParam(), true /*enabled*/));
- formats = getFormatsFromPorts();
+ auto formats = getFormatsFromPorts();
ASSERT_EQ(1, formats.count(GetParam()));
+
+ ASSERT_EQ(NO_ERROR, mManager->setSurroundFormatEnabled(GetParam(), false /*enabled*/));
+ formats = getFormatsFromPorts();
+ ASSERT_EQ(0, formats.count(GetParam()));
}
TEST_P(AudioPolicyManagerTestForHdmi,