Brush up audio parameters usage
It is preferred to use the constants from AudioParameter
(which can now serve as an abstraction layer similar to libaudiohal).
Grepped for usages of defines and just string values
and replaced with references to AudioParameter.
Since the parameter definitions are being moved to system/audio.h,
update includes in AudioParemeter and stagefright Utils.
Change-Id: I2addb983707d866b16f39d45d0e14b802595e292
Test: make
diff --git a/services/audiopolicy/common/managerdefinitions/include/TypeConverter.h b/services/audiopolicy/common/managerdefinitions/include/TypeConverter.h
index 069c9e7..8e3dbad 100644
--- a/services/audiopolicy/common/managerdefinitions/include/TypeConverter.h
+++ b/services/audiopolicy/common/managerdefinitions/include/TypeConverter.h
@@ -18,6 +18,7 @@
#include "policy.h"
#include <Volume.h>
+#include <media/AudioParameter.h>
#include <system/audio.h>
#include <convert/convert.h>
#include <utils/Log.h>
@@ -89,7 +90,7 @@
template <class Traits>
static void collectionFromString(const std::string &str, typename Traits::Collection &collection,
- const char *del = "|")
+ const char *del = AudioParameter::valueListSeparator)
{
char *literal = strdup(str.c_str());
for (const char *cstr = strtok(literal, del); cstr != NULL; cstr = strtok(NULL, del)) {
@@ -111,11 +112,13 @@
static void collectionFromString(const std::string &str,
typename Traits::Collection &collection,
- const char *del = "|");
+ const char *del = AudioParameter::valueListSeparator);
- static uint32_t maskFromString(const std::string &str, const char *del = "|");
+ static uint32_t maskFromString(
+ const std::string &str, const char *del = AudioParameter::valueListSeparator);
- static void maskToString(uint32_t mask, std::string &str, const char *del = "|");
+ static void maskToString(
+ uint32_t mask, std::string &str, const char *del = AudioParameter::valueListSeparator);
protected:
struct Table {
@@ -139,8 +142,8 @@
typedef TypeConverter<AudioModeTraits> AudioModeConverter;
inline
-static SampleRateTraits::Collection samplingRatesFromString(const std::string &samplingRates,
- const char *del = "|")
+static SampleRateTraits::Collection samplingRatesFromString(
+ const std::string &samplingRates, const char *del = AudioParameter::valueListSeparator)
{
SampleRateTraits::Collection samplingRateCollection;
collectionFromString<SampleRateTraits>(samplingRates, samplingRateCollection, del);
@@ -148,7 +151,8 @@
}
inline
-static FormatTraits::Collection formatsFromString(const std::string &formats, const char *del = "|")
+static FormatTraits::Collection formatsFromString(
+ const std::string &formats, const char *del = AudioParameter::valueListSeparator)
{
FormatTraits::Collection formatCollection;
FormatConverter::collectionFromString(formats, formatCollection, del);
@@ -178,8 +182,8 @@
}
inline
-static ChannelTraits::Collection channelMasksFromString(const std::string &channels,
- const char *del = "|")
+static ChannelTraits::Collection channelMasksFromString(
+ const std::string &channels, const char *del = AudioParameter::valueListSeparator)
{
ChannelTraits::Collection channelMaskCollection;
OutputChannelConverter::collectionFromString(channels, channelMaskCollection, del);
@@ -189,8 +193,8 @@
}
inline
-static InputChannelTraits::Collection inputChannelMasksFromString(const std::string &inChannels,
- const char *del = "|")
+static InputChannelTraits::Collection inputChannelMasksFromString(
+ const std::string &inChannels, const char *del = AudioParameter::valueListSeparator)
{
InputChannelTraits::Collection inputChannelMaskCollection;
InputChannelConverter::collectionFromString(inChannels, inputChannelMaskCollection, del);
@@ -199,8 +203,8 @@
}
inline
-static OutputChannelTraits::Collection outputChannelMasksFromString(const std::string &outChannels,
- const char *del = "|")
+static OutputChannelTraits::Collection outputChannelMasksFromString(
+ const std::string &outChannels, const char *del = AudioParameter::valueListSeparator)
{
OutputChannelTraits::Collection outputChannelMaskCollection;
OutputChannelConverter::collectionFromString(outChannels, outputChannelMaskCollection, del);
diff --git a/services/audiopolicy/common/managerdefinitions/src/ConfigParsingUtils.cpp b/services/audiopolicy/common/managerdefinitions/src/ConfigParsingUtils.cpp
index e32d0d3..643ac1e 100644
--- a/services/audiopolicy/common/managerdefinitions/src/ConfigParsingUtils.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/ConfigParsingUtils.cpp
@@ -23,6 +23,7 @@
#include "IOProfile.h"
#include "TypeConverter.h"
#include <system/audio.h>
+#include <media/AudioParameter.h>
#include <utils/Log.h>
#include <cutils/misc.h>
@@ -289,7 +290,7 @@
const DeviceVector &declaredDevices)
{
char *tagLiteral = strndup(tag, strlen(tag));
- char *devTag = strtok(tagLiteral, "|");
+ char *devTag = strtok(tagLiteral, AudioParameter::valueListSeparator);
while (devTag != NULL) {
if (strlen(devTag) != 0) {
audio_devices_t type;
@@ -311,7 +312,7 @@
}
}
}
- devTag = strtok(NULL, "|");
+ devTag = strtok(NULL, AudioParameter::valueListSeparator);
}
free(tagLiteral);
}
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index c1ed252..125d422 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -69,7 +69,7 @@
{
AudioParameter param(device_address);
const String8 key(state == AUDIO_POLICY_DEVICE_STATE_AVAILABLE ?
- AUDIO_PARAMETER_DEVICE_CONNECT : AUDIO_PARAMETER_DEVICE_DISCONNECT);
+ AudioParameter::keyStreamConnect : AudioParameter::keyStreamDisconnect);
param.addInt(key, device);
mpClientInterface->setParameters(AUDIO_IO_HANDLE_NONE, param.toString());
}
@@ -3594,7 +3594,7 @@
mTestFormat = format;
} else if (mTestOutputs[mCurOutput] != 0) {
AudioParameter outputParam = AudioParameter();
- outputParam.addInt(String8("format"), format);
+ outputParam.addInt(String8(AudioParameter::keyStreamSupportedFormats), format);
mpClientInterface->setParameters(mTestOutputs[mCurOutput], outputParam.toString());
}
}
@@ -3613,7 +3613,7 @@
mTestChannels = channels;
} else if (mTestOutputs[mCurOutput] != 0) {
AudioParameter outputParam = AudioParameter();
- outputParam.addInt(String8("channels"), channels);
+ outputParam.addInt(String8(AudioParameter::keyStreamSupportedChannels), channels);
mpClientInterface->setParameters(mTestOutputs[mCurOutput], outputParam.toString());
}
}
@@ -3626,7 +3626,7 @@
mTestSamplingRate = samplingRate;
} else if (mTestOutputs[mCurOutput] != 0) {
AudioParameter outputParam = AudioParameter();
- outputParam.addInt(String8("sampling_rate"), samplingRate);
+ outputParam.addInt(String8(AudioParameter::keyStreamSupportedSamplingRates), samplingRate);
mpClientInterface->setParameters(mTestOutputs[mCurOutput], outputParam.toString());
}
}
@@ -5544,12 +5544,12 @@
// Format MUST be checked first to update the list of AudioProfile
if (profiles.hasDynamicFormat()) {
- reply = mpClientInterface->getParameters(ioHandle,
- String8(AUDIO_PARAMETER_STREAM_SUP_FORMATS));
+ reply = mpClientInterface->getParameters(
+ ioHandle, String8(AudioParameter::keyStreamSupportedFormats));
ALOGV("%s: supported formats %s", __FUNCTION__, reply.string());
AudioParameter repliedParameters(reply);
if (repliedParameters.get(
- String8(AUDIO_PARAMETER_STREAM_SUP_FORMATS), reply) != NO_ERROR) {
+ String8(AudioParameter::keyStreamSupportedFormats), reply) != NO_ERROR) {
ALOGE("%s: failed to retrieve format, bailing out", __FUNCTION__);
return;
}
@@ -5566,27 +5566,28 @@
ChannelsVector channelMasks;
SampleRateVector samplingRates;
AudioParameter requestedParameters;
- requestedParameters.addInt(String8(AUDIO_PARAMETER_STREAM_FORMAT), format);
+ requestedParameters.addInt(String8(AudioParameter::keyFormat), format);
if (profiles.hasDynamicRateFor(format)) {
- reply = mpClientInterface->getParameters(ioHandle,
- requestedParameters.toString() + ";" +
- AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES);
+ reply = mpClientInterface->getParameters(
+ ioHandle,
+ requestedParameters.toString() + ";" +
+ AudioParameter::keyStreamSupportedSamplingRates);
ALOGV("%s: supported sampling rates %s", __FUNCTION__, reply.string());
AudioParameter repliedParameters(reply);
if (repliedParameters.get(
- String8(AUDIO_PARAMETER_STREAM_SUP_SAMPLING_RATES), reply) == NO_ERROR) {
+ String8(AudioParameter::keyStreamSupportedSamplingRates), reply) == NO_ERROR) {
samplingRates = samplingRatesFromString(reply.string());
}
}
if (profiles.hasDynamicChannelsFor(format)) {
reply = mpClientInterface->getParameters(ioHandle,
requestedParameters.toString() + ";" +
- AUDIO_PARAMETER_STREAM_SUP_CHANNELS);
+ AudioParameter::keyStreamSupportedChannels);
ALOGV("%s: supported channel masks %s", __FUNCTION__, reply.string());
AudioParameter repliedParameters(reply);
if (repliedParameters.get(
- String8(AUDIO_PARAMETER_STREAM_SUP_CHANNELS), reply) == NO_ERROR) {
+ String8(AudioParameter::keyStreamSupportedChannels), reply) == NO_ERROR) {
channelMasks = channelMasksFromString(reply.string());
if (device == AUDIO_DEVICE_OUT_HDMI) {
filterSurroundChannelMasks(&channelMasks);
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.h b/services/audiopolicy/managerdefault/AudioPolicyManager.h
index 44e9baf..46f0625 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.h
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.h
@@ -662,7 +662,7 @@
const char *device_name);
void updateMono(audio_io_handle_t output) {
AudioParameter param;
- param.addInt(String8(AUDIO_PARAMETER_MONO_OUTPUT), (int)mMasterMono);
+ param.addInt(String8(AudioParameter::keyMonoOutput), (int)mMasterMono);
mpClientInterface->setParameters(output, param.toString());
}
};