summaryrefslogtreecommitdiffstats
path: root/services/audiopolicy/common
diff options
context:
space:
mode:
authorAndy Hung <hunga@google.com>2015-04-22 10:17:59 -0700
committerAndy Hung <hunga@google.com>2015-04-23 13:52:46 -0700
commit138f77425a0956d867f078881f91628518ae8258 (patch)
treea8e3afaf98d7d32d04d5aab3a72354e04334614b /services/audiopolicy/common
parent1ac91ed2c67245ea5052182212463d3f0afe8b5a (diff)
downloadframeworks_av-138f77425a0956d867f078881f91628518ae8258.zip
frameworks_av-138f77425a0956d867f078881f91628518ae8258.tar.gz
frameworks_av-138f77425a0956d867f078881f91628518ae8258.tar.bz2
Fix format sorting order in AudioPort
Otherwise AUDIO_FORMAT_DEFAULT (used for dynamic formats) is no longer the first entry. Change-Id: I23869a9ca2ed138759d722e7c9838497f640921a
Diffstat (limited to 'services/audiopolicy/common')
-rw-r--r--services/audiopolicy/common/managerdefinitions/include/AudioPort.h6
-rw-r--r--services/audiopolicy/common/managerdefinitions/src/AudioPort.cpp28
2 files changed, 22 insertions, 12 deletions
diff --git a/services/audiopolicy/common/managerdefinitions/include/AudioPort.h b/services/audiopolicy/common/managerdefinitions/include/AudioPort.h
index 1c2c27e..82e2c43 100644
--- a/services/audiopolicy/common/managerdefinitions/include/AudioPort.h
+++ b/services/audiopolicy/common/managerdefinitions/include/AudioPort.h
@@ -75,10 +75,8 @@ public:
audio_format_t pickFormat() const;
static const audio_format_t sPcmFormatCompareTable[];
- static int compareFormatsGoodToBad(
- const audio_format_t *format1, const audio_format_t *format2) {
- // compareFormats sorts from bad to good, we reverse it here
- return compareFormats(*format2, *format1);
+ static int compareFormats(const audio_format_t *format1, const audio_format_t *format2) {
+ return compareFormats(*format1, *format2);
}
static int compareFormats(audio_format_t format1, audio_format_t format2);
diff --git a/services/audiopolicy/common/managerdefinitions/src/AudioPort.cpp b/services/audiopolicy/common/managerdefinitions/src/AudioPort.cpp
index 647550c..64f883a 100644
--- a/services/audiopolicy/common/managerdefinitions/src/AudioPort.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/AudioPort.cpp
@@ -146,7 +146,7 @@ void AudioPort::importAudioPort(const sp<AudioPort> port) {
break;
}
}
- if (!hasFormat) { // never import a channel mask twice
+ if (!hasFormat) { // never import a format twice
mFormats.add(format);
}
}
@@ -216,7 +216,12 @@ void AudioPort::loadFormats(char *name)
}
str = strtok(NULL, "|");
}
- mFormats.sort(compareFormatsGoodToBad);
+ // we sort from worst to best, so that AUDIO_FORMAT_DEFAULT is always the first entry.
+ // TODO: compareFormats could be a lambda to convert between pointer-to-format to format:
+ // [](const audio_format_t *format1, const audio_format_t *format2) {
+ // return compareFormats(*format1, *format2);
+ // }
+ mFormats.sort(compareFormats);
}
void AudioPort::loadInChannels(char *name)
@@ -558,11 +563,13 @@ status_t AudioPort::checkCompatibleFormat(audio_format_t format, audio_format_t
mType == AUDIO_PORT_TYPE_MIX && mRole == AUDIO_PORT_ROLE_SINK
&& audio_is_linear_pcm(format);
- for (size_t i = 0; i < mFormats.size(); ++i) {
+ // iterate from best format to worst format (reverse order)
+ for (ssize_t i = mFormats.size() - 1; i >= 0 ; --i) {
if (mFormats[i] == format ||
- (checkInexact && audio_is_linear_pcm(mFormats[i]))) {
- // for inexact checks we take the first linear pcm format since
- // mFormats is sorted from best PCM format to worst PCM format.
+ (checkInexact
+ && mFormats[i] != AUDIO_FORMAT_DEFAULT
+ && audio_is_linear_pcm(mFormats[i]))) {
+ // for inexact checks we take the first linear pcm format due to sorting.
if (updatedFormat != NULL) {
*updatedFormat = mFormats[i];
}
@@ -789,10 +796,15 @@ void AudioPort::dump(int fd, int spaces) const
const char *formatStr = ConfigParsingUtils::enumToString(sFormatNameToEnumTable,
ARRAY_SIZE(sFormatNameToEnumTable),
mFormats[i]);
- if (i == 0 && strcmp(formatStr, "") == 0) {
+ const bool isEmptyStr = formatStr[0] == 0;
+ if (i == 0 && isEmptyStr) {
snprintf(buffer, SIZE, "Dynamic");
} else {
- snprintf(buffer, SIZE, "%s", formatStr);
+ if (isEmptyStr) {
+ snprintf(buffer, SIZE, "%#x", mFormats[i]);
+ } else {
+ snprintf(buffer, SIZE, "%s", formatStr);
+ }
}
result.append(buffer);
result.append(i == (mFormats.size() - 1) ? "" : ", ");