当前位置: 首页 > news >正文

Android Codec2 CCodec (七)IConfigurable

上一篇文章我们了解了接口参数的定义,这一节我们简单梳理一下参数获取、配置以及参数反射过程。

1、IConfigurable

通过之前的介绍我们了解到,Codec2模块的功能实现与配置实现是相互分离的,Codec2框架设计了一组API用于获取与模块关联的配置对象。

Codec2给ComponentStore设计了名为getConfigurable的API,用于获取Store中的参数对象:

struct ComponentStore : public IComponentStore {virtual Return<sp<IConfigurable>> getConfigurable() override;
}

给Component设计的API是getInterface:

struct Component : public IComponent {virtual Return<sp<IComponentInterface>> getInterface() override;
}

两个API看似不一样,实则是一样的。IComponentInterface内部有一个接口getConfigurable:

struct ComponentInterface : public IComponentInterface {virtual Return<sp<IConfigurable>> getConfigurable() override;
}

所以,调用组件的getInterface方法拿到IComponentInterface对象后,还要再调用一次getConfigurable才能拿到与组件相关联的参数配置。

IConfigurable有四个与参数配置相关的接口:

virtual Return<void> query(const hidl_vec<uint32_t>& indices,bool mayBlock,query_cb _hidl_cb) override;virtual Return<void> config(const hidl_vec<uint8_t>& inParams,bool mayBlock,config_cb _hidl_cb) override;virtual Return<void> querySupportedParams(uint32_t start,uint32_t count,querySupportedParams_cb _hidl_cb) override;virtual Return<void> querySupportedValues(const hidl_vec<FieldSupportedValuesQuery>& inFields,bool mayBlock,querySupportedValues_cb _hidl_cb) override;
  • query:请求指定index参数的值;
  • config:修改指定index参数的值,
  • querySupportedParams:请求支持的参数,start为开始索引,count为选择范围;
  • querySupportedValues:请求字段支持的值。

后续用的最多的是query和config方法,接下来我们将以C2Store为例,对他俩的调用流程进行梳理。为了能将调用流程看得更清楚,这里要再贴一遍C2Store的UML类图:
在这里插入图片描述

2、query

Return<void> CachedConfigurable::query(const hidl_vec<uint32_t>& indices,bool mayBlock,query_cb _hidl_cb) {typedef C2Param::Index Index;std::vector<Index> c2heapParamIndices((Index*)indices.data(),(Index*)indices.data() + indices.size());std::vector<std::unique_ptr<C2Param>> c2heapParams;c2_status_t c2res = mIntf->query(c2heapParamIndices,mayBlock ? C2_MAY_BLOCK : C2_DONT_BLOCK,&c2heapParams);hidl_vec<uint8_t> params;if (!createParamsBlob(&params, c2heapParams)) {LOG(WARNING) << "query -- invalid output params.";}_hidl_cb(static_cast<Status>(c2res), params);return Void();
}

query方法传入参数是一个hidl_vec,可以一次请求一个参数的值,也可以一次请求多个参数的值。hidl_vec元素类型为uint32_t。

  • Index里存储的是一个uint32_t,所以拿到参数可以直接将hidl_vec转换为标准库的vector;
  • 调用ConfigurableIntf的query方法,由StoreIntf最终调用到C2PlatformComponentStore的query_sm方法;
  • 拿到返回值后,需要将C2Param重新转换为hidl_vec,最后通过hidl callback将结果返回。
struct StoreIntf : public ConfigurableC2Intf {virtual c2_status_t query(const std::vector<C2Param::Index> &indices,c2_blocking_t mayBlock,std::vector<std::unique_ptr<C2Param>> *const params) const override {if (mayBlock == C2_DONT_BLOCK && indices.size() != 0) {return C2_BLOCKING;}return mStore->query_sm({}, indices, params);}
}c2_status_t C2PlatformComponentStore::query_sm(const std::vector<C2Param*> &stackParams,const std::vector<C2Param::Index> &heapParamIndices,std::vector<std::unique_ptr<C2Param>> *const heapParams) const {return mInterface.query(stackParams, heapParamIndices, C2_MAY_BLOCK, heapParams);
}

通过上一节的学习我们可以知道,mInterface是继承于C2InterfaceHelper的,因此最终调用的是C2InterfaceHelper的query方法。

c2_status_t C2InterfaceHelper::query(const std::vector<C2Param*> &stackParams,const std::vector<C2Param::Index> &heapParamIndices,c2_blocking_t mayBlock __unused /* TODO */,std::vector<std::unique_ptr<C2Param>>* const heapParams) const {std::lock_guard<std::mutex> lock(mMutex);bool paramWasInvalid = false;bool paramNotFound = false;bool paramDidNotFit = false;bool paramNoMemory = false;// ...// 遍历要获取参数的索引for (const C2Param::Index ix : heapParamIndices) {// 调用Factory的getParamValue方法std::shared_ptr<C2Param> value = _mFactory->getParamValue(ix);if (value) {// 如果value不为null,则拷贝一份C2Paramstd::unique_ptr<C2Param> p = C2Param::Copy(*value);if (p != nullptr) {heapParams->push_back(std::move(p));} else {heapParams->push_back(nullptr);paramNoMemory = true;}} else {heapParams->push_back(nullptr);paramNotFound = true;}}return paramNoMemory ? C2_NO_MEMORY :paramNotFound ? C2_BAD_INDEX :// the following errors are not marked in the return valueparamDidNotFit ? C2_OK :paramWasInvalid ? C2_OK : C2_OK;
}

3、config

4、getStructDescriptors

关注公众号《青山渺渺》阅读完整内容

请添加图片描述


http://www.mrgr.cn/news/17496.html

相关文章:

  • 后台框架-统一异常管理
  • Python爬虫案例五:将获取到的文本生成词云图
  • 走进酒厂,探寻白酒酿造的奥秘
  • MySQL事务处理详解:实现数据一致性与隔离性的艺术
  • 【AI大模型】基于docker部署向量数据库Milvus和可视化工具Attu详解步骤
  • 茴香豆Web实践
  • 基于STM32心电模块学习笔记
  • 【网络安全】逻辑漏洞:绕过应用程序重要功能
  • 低代码开发:挑战与机遇并存,为何赞誉多而普及难!
  • 写论文去哪个网站?推荐这7家开题报告一键自动生成网站!
  • OpenAI Whisper API (InvalidRequestError)
  • 自然语言处理-词向量转换
  • java fastxml json 科学计数法转换处理
  • Java 入门指南:Java 并发编程 —— Condition 灵活管理线程间的同步
  • 18037 20秒后的时间
  • 前端项目常用方法
  • Spring源码(2)BeanFactory工厂后置处理器、Bean的后置处理器、ApplicationContext容器、Bean的生命周期
  • C++STL简介
  • 华为盘古大模型
  • 实施面试题目