Android Codec2 CCodec (七)IConfigurable

server/2024/9/29 5:25:42/

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

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.ppmy.cn/server/110484.html

相关文章

[Leetcode 47][Medium]-全排列 II-回溯(全排列问题)

目录 一、题目描述 二、整体思路 三、代码 一、题目描述 原题地址 二、整体思路 和上一道Leetcode46相比&#xff0c;有变化的地方是要排除重复组合的情况。那么在组合问题中去除重复组合的方法是先对数组进行排序,然后在回溯函数中判断当前元素与上一个元素是否相同,若相同…

科研绘图系列:R语言差异基因四分图(Quad plot)

介绍 四分图(Quad plot)是一种数据可视化技术,通常用于展示四个变量之间的关系。它由四个子图组成,每个子图都显示两个变量之间的关系。四分图的布局通常是2x2的网格,每个格子代表一个变量对的散点图。 在四分图中,通常: 第一个子图显示变量A和B的关系。第二个子图显示…

【CSS】border-image 样式不生效 - 和谷歌浏览器版本有关系 - 谷歌 80 版本边框图片样式失效问题

目录 问题解决 问题 使用边框图片时&#xff0c;部分谷歌浏览器版本中边框图片不生效 边框图片样式代码 border-image-source: url(img/dialog-bg.40ddf10d.png); border-image-slice: var(--topSlice) 50 var(--bottomSlice) 330; border-image-repeat: stretch; border-im…

Linux sentinel写法

在linux驱动里我们经常能看到类似下面的写法&#xff1a; static const struct of_device_id asensm6_of_match[] {{ .compatible DRIVER_COMPATIBLE },{ /* sentinel */ }, };static const struct of_device_id rockchip_pinctrl_dt_match[] {{ .compatible "rockch…

使用Vuetify构建优雅的Vue.js应用

一、引言 在Vue.js生态系统中&#xff0c;Vuetify 是一个非常流行的 Material Design 组件库&#xff0c;它提供了丰富的 UI 组件&#xff0c;可以帮助开发者快速构建美观且功能丰富的应用。本文将介绍如何在Vue项目中集成和使用Vuetify。 二、Vuetify的安装 1. 创建Vue项目…

Matlab simulink建模与仿真 第七章(表查询库)

参考视频&#xff1a;simulink1.1simulink简介_哔哩哔哩_bilibili 一、表查询库中的模块概览 二、表查询模块 使用Lookup Table表查询模块&#xff0c;需要在配置窗口中建立x-y&#xff08;自变量-因变量&#xff09;离散数据对&#xff0c;x与y的维数应相同&#xff0c;x集&a…

C++中函数重载的原理

C++的编译器在编译函数时,会对函数进行换名,将参数的类型信息整合到新的名字中,解决函数重载和名字冲突的矛盾。 在C++标准语法规定,在编译C++函数时候,会进行换名,将函数的参数表类型信息整合到新的名字中,因为满足多个重载函数的多个函数参数有所差异,这样在换名字之…

OpenHarmony Camera源码分析

一、简介 当前&#xff0c;开源在科技进步和产业发展中发挥着越来越重要的作用&#xff0c;OpenAtom OpenHarmony&#xff08;简称“OpenHarmony”&#xff09;赋予了开发者孕育创新的种子&#xff0c;也为数字化产业发展开辟了一片土壤。深开鸿是开源的坚定践行者&#xff0c…