AudioPolicyManager(一)

基于上一篇文章,已经把解析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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值