基于上一篇文章,已经把解析audio_policy_configuration.xml的代码trace 完毕,AudioPolicyManager 的成员变量已经保存了xml 解析得到的参数,接下来,继续Trace AudioPolicymanager如何使用这些configuration 参数。
一、回顾audio_policy_configuration.xml 解析
回顾上一篇APM 的结论:
audio_policy_configuration.xml文件解析的参数,会首先储存在class AudioPolicyManager : AudioPolicyConfig mConfig; 这个成员变量。
mConfig 的关键成员参数( mHwModules,mOutputDevices,mInputDevices,mDefaultOutputDevice )对应到AudioPolicyManager这个类的这些参数 (mHwModulesAll, mOutputDevicesAll, mInputDevicesAll, mDefaultOutputDevice),也就是通过AudioPolicyManager的这些成员已经可以访问到xml 解析得到的所有信息。
(mOutputDevices,mInputDevices)( mOutputDevicesAll, mInputDevicesAll ) 分别代表的信息是,所有HwModule 声明并且已经在<attachedDevices> 中声明,只有<attachedDevices> 声明的device 才是可以被使用的device。关于这点,可以从下面的code 找到答案。
\frameworks\av\services\audiopolicy\common\managerdefinitions\src\ Serializer.cpp
template<>
std::variant<status_t, ModuleTraits::Element> PolicySerializer::deserialize<ModuleTraits>(
const xmlNode *cur, ModuleTraits::PtrSerializingCtx ctx){for (const xmlNode *children = cur->xmlChildrenNode; children != NULL;
children = children->next) {
if (!xmlStrcmp(children->name, reinterpret_cast<const xmlChar*>(childAttachedDevicesTag))) {
ALOGV("%s: %s %s found", __func__, tag, childAttachedDevicesTag);
for (const xmlNode *child = children->xmlChildrenNode; child != NULL;
child = child->next) {
if (!xmlStrcmp(child->name,
reinterpret_cast<const xmlChar*>( childAttachedDeviceTag))) {
auto attachedDevice = make_xmlUnique(xmlNodeListGetString(
child->doc, child->xmlChildrenNode, 1));
if (attachedDevice != nullptr) {
ALOGV("%s: %s %s=%s", __func__, tag, childAttachedDeviceTag,
reinterpret_cast<const char*>(attachedDevice.get()));
sp<DeviceDescriptor> device = module-> getDeclaredDevices().
getDeviceFromTagName(std::string(reinterpret_cast<const char*>(
attachedDevice.get())));
if (device == nullptr && mIgnoreVendorExtensions) {
ALOGW("Skipped attached device \"%s\" because it likely uses a vendor"
"extension type",
reinterpret_cast<const char*>(attachedDevice.get()));
continue;
}
ctx-> addDevice(device);
}
}
}
}
}
class AudioPolicyConfig
......
private:
static const constexpr char* const kDefaultEngineLibraryNameSuffix = "default";std::string mSource;
std::string mEngineLibraryNameSuffix;
HwModuleCollection &mHwModules; /**< Collection of Module, with Profiles, i.e. Mix Ports. */(xml 解析到的所有Hw Modules 都放在这个变量)
DeviceVector &mOutputDevices;//(xml 所声明的所有的output devices,并且在<attachedDevices> list 里面)
DeviceVector &mInputDevices;//(xml 所声明的所有的input devices并且在<attachedDevices> list 里面)
sp<DeviceDescriptor> &mDefaultOutputDevice;//audio_policy_configuration.xml 声明的default device, 一般audio_policy_configuration.xml 会包含多个Hw modules,但是只会有一个Hw modules 声明<defaultOutputDevice>
// TODO: remove when legacy conf file is removed. true on devices that use DRC on the
// DEVICE_CATEGORY_SPEAKER path to boost soft sounds, used to adjust volume curves accordingly.
// Note: remove also speaker_drc_enabled from global configuration of XML config file.
bool mIsSpeakerDrcEnabled;
bool mIsCallScreenModeSupported;
SurroundFormats mSurroundFormats;
};
mixports / routes/ devices 等信息,会储存在class HwModule 这个class,
class HwModule : public RefBase
{......
private:
void refreshSupportedDevices();const String8 mName; // base name of the audio HW module (prim