usecase validator: narrow down the remapping to game use case
Do not remap media usage to game usage just because a client
is attached to a stream with a fast mixer: the client itself
might be on the normal mixer.
Also do not remap if the content type is speech, sonification
or ultra sound.
Bug: 278412306
Test: atest UsecaseValidatorTest
Change-Id: I3eec04c35f6c57f0b64b959b85d9f7fc7a128d0b
diff --git a/media/libaudiousecasevalidation/UsecaseValidator.cpp b/media/libaudiousecasevalidation/UsecaseValidator.cpp
index 0e5a824..d62df3a 100644
--- a/media/libaudiousecasevalidation/UsecaseValidator.cpp
+++ b/media/libaudiousecasevalidation/UsecaseValidator.cpp
@@ -99,10 +99,8 @@
audio_attributes_t attrRet = attributes;
- // Check if attribute usage media or unknown has been set.
- bool isUsageValid = this->isUsageValid(attributes);
-
- if (isUsageValid && m_lookup.isGameStream(streamId)) {
+ if (isUsageValid(attributes.usage) && isContentTypeValid(attributes.content_type)
+ && areFlagsValid(attributes.flags) && m_lookup.isGameStream(streamId)) {
ALOGI("%s update usage: %d to AUDIO_USAGE_GAME for output: %d pid: %d package: %s",
__func__, attributes.usage, streamId, attributionSource.pid,
attributionSource.packageName.value_or("").c_str());
@@ -117,9 +115,9 @@
/**
* Check if attribute usage valid.
*/
- bool isUsageValid(const audio_attributes_t& attr) {
- ALOGV("isUsageValid attr.usage: %d", attr.usage);
- switch (attr.usage) {
+ bool isUsageValid(audio_usage_t usage) {
+ ALOGV("isUsageValid usage: %d", usage);
+ switch (usage) {
case AUDIO_USAGE_MEDIA:
case AUDIO_USAGE_UNKNOWN:
return true;
@@ -129,6 +127,27 @@
return false;
}
+ bool isContentTypeValid(audio_content_type_t contentType) {
+ ALOGV("isContentTypeValid contentType: %d", contentType);
+ switch (contentType) {
+ case AUDIO_CONTENT_TYPE_MUSIC:
+ case AUDIO_CONTENT_TYPE_MOVIE:
+ case AUDIO_CONTENT_TYPE_UNKNOWN:
+ return true;
+ default:
+ break;
+ }
+ return false;
+ }
+
+ bool areFlagsValid(audio_flags_mask_t flags) {
+ ALOGV("areFlagsValid flags: %#x", flags);
+ if ((flags & AUDIO_FLAG_LOW_LATENCY) != 0) {
+ return true;
+ }
+ return false;
+ }
+
protected:
UsecaseLookup m_lookup;
};