上一篇的后面有提到 IComponentStore =::android::hardware::media::c2::V1_0::IComponentStore; 是 Codec2 HIDL service 的部分,这边就先看下:
1. hidl 的接口定义
有一个 /hardware/google/interfaces/media/c2/1.0/ 这边有没有用到不清楚??
正常用的是 /hardware/interfaces/media/c2/ 这边分 1.0 /1.1/1.2 三个路径(1.2 都是在前面的基础上进行扩展 比如多加API);
/hardware/interfaces/media/c2/1.0/
Android.bp
IComponent.hal
IComponentInterface.hal
IComponentListener.hal
IComponentStore.hal
IConfigurable.hal
IInputSurface.hal
IInputSurfaceConnection.hal
types.hal
==================
//主要先看 IComponentStore.hal 这个
/hardware/interfaces/media/c2/1.0/IComponentStore.hal
17 package hardware.google.media.c2@1.0;
26 interface IComponentStore extends IConfigurable {
28 /**
29 * Creates a component by name.
47 */
48 createComponent(
49 string name,
50 IComponentListener listener,
51 IClientManager pool
52 ) generates (
53 Status status,
54 IComponent comp
55 );
57 /**
58 * Creates a component interface by name.
73 */
74 createInterface(
75 string name
76 ) generates (
77 Status status,
78 IComponentInterface compIntf
79 );
81 /**
82 * Component traits.
83 */
84 struct ComponentTraits {
85 /**
86 * Name of the component.
87 */
88 string name;
89
90 enum Domain : uint32_t {
91 AUDIO,
92 VIDEO,
93 OTHER = 0xffffffff,
94 };
95 /**
96 * Component domain. The framework may not recognize `OTHER`.
97 */
98 Domain domain;
105
106 enum Kind : uint32_t {
107 DECODER,
108 ENCODER,
109 OTHER = 0xffffffff,
110 };
111 /**
112 * Component kind. The framework may not recognize `OTHER`.
113 */
114 Kind kind;
115 /**
116 * If #kind is `OTHER`, #kindOther can be used to provide additional
117 * information. Otherwise, #kindOther is ignored. The framework may not
118 * inspect this value.
119 */
120 uint32_t kindOther;
121
122 /**
123 * Rank used by MediaCodecList to determine component ordering. Lower
124 * value means higher priority.
125 */
126 uint32_t rank; //组件排名
128 /**
129 * Media type.
130 */
131 string mediaType;
132
133 /**
134 * Aliases for component name for backward compatibility.
135 *
136 * \note Multiple components can have the same alias (but not the same
137 * component name) as long as their media types differ.
138 */
139 vec<string> aliases;
140 };
141
142 /**
143 * Returns the list of components supported by this component store.
149 */
150 listComponents() generates (vec<ComponentTraits> traits);
151
152 /**
153 * Creates a persistent input surface that can be used as an input surface
154 * for any IComponent instance
159 */
160 createInputSurface() generates (IInputSurface surface);
161
169 /**
170 * Returns a list of `StructDescriptor` objects for a set of requested
171 * C2Param structure indices that this store is aware of.
172 *
173 * This operation must be performed at best effort, e.g. the component
174 * store must simply ignore all struct indices that it is not aware of.
184 */
185 getStructDescriptors(
186 vec<ParamIndex> indices
187 ) generates (
188 Status status,
189 vec<StructDescriptor> structs
190 );
191
192 /**
193 * Copies the contents of @p src into @p dst without changing the format of
194 * @p dst.
204 */
205 copyBuffer(Buffer src, Buffer dst) generates (Status status);
206
207 /**
208 * Returns the `IClientManager` object for the component's BufferPool.
213 */
214 getPoolClientManager() generates (IClientManager pool);
215
216 /**
217 * Returns the @ref IConfigurable instance associated to this component
218 * store.
221 */
222 getConfigurable() generates (IConfigurable configurable);
212 };
这里面的 API 还是经常遇到的,可以了解下
2. hidl sevice 的实现
实现是在 /frameworks/av/media/codec2/hal/hidl/ 路径下,其中分为 1.0/1.1/1.2
上一篇的分析中看起来新版本是用的 1.2 ,那就直接看最新的1.2
/frameworks/av/media/codec2/hal/hidl/1.2/utils/
include/codec2/hidl/1.2/
Android.bp
Component.cpp
ComponentInterface.cpp
ComponentStore.cpp
Configurable.cpp
InputBufferManager.cpp
InputSurface.cpp
InputSurfaceConnection.cpp
types.cpp
========================
//先来看 IComponentStore 的实现
/frameworks/av/media/codec2/hal/hidl/1.2/utils/include/codec2/hidl/1.2/ComponentStore.h
40 namespace android {
41 class FilterWrapper; //这是一个 plugin,有时间再去看
42
43 namespace hardware {
44 namespace media {
45 namespace c2 {
46 namespace V1_2 {
47 namespace utils {
58 struct ComponentStore : public IComponentStore {
73
74 /**
75 * Returns the store's ParameterCache. This is used for validation by
76 * Configurable::init().
77 */
78 std::shared_ptr<ParameterCache> getParameterCache() const;
81
82 // Methods from ::android::hardware::media::c2::V1_0::IComponentStore.
83 virtual Return<void> createComponent(
84 const hidl_string& name,
85 const sp<IComponentListener>& listener,
86 const sp<IClientManager>& pool,
87 createComponent_cb _hidl_cb) override;
88 virtual Return<void> createInterface(
89 const hidl_string& name,
90 createInterface_cb _hidl_cb) override;
......
109
110 // Methods from ::android::hardware::media::c2::V1_2::IComponentStore.
111 virtual Return<void> createComponent_1_2(
112 const hidl_string& name,
113 const sp<IComponentListener>& listener,
114 const sp<IClientManager>& pool,
115 createComponent_1_2_cb _hidl_cb) override;
}
=================
/frameworks/av/media/codec2/hal/hidl/1.2/utils/ComponentStore.cpp
18 #define LOG_TAG "Codec2-ComponentStore@1.2"
182
183 std::shared_ptr<ParameterCache> ComponentStore::getParameterCache() const {
184 return mParameterCache;
196
197 // Methods from ::android::hardware::media::c2::V1_0::IComponentStore
198 Return<void> ComponentStore::createComponent(
199 const hidl_string& name,
200 const sp<IComponentListener>& listener,
201 const sp<IClientManager>& pool,
202 createComponent_cb _hidl_cb) {
203
204 sp<Component> component;
205 std::shared_ptr<C2Component> c2component;
206 Status status = static_cast<Status>(
207 mStore->createComponent(name, &c2component));
208
209 if (status == Status::OK) {
210 #ifndef __ANDROID_APEX__
211 c2component = GetFilterWrapper()->maybeWrapComponent(c2component);
212 #endif
213 onInterfaceLoaded(c2component->intf());
214 component = new Component(c2component, listener, this, pool);
215 if (!component) {
216 status = Status::CORRUPTED;
217 } else {
218 reportComponentBirth(component.get());
219 if (component->status() != C2_OK) {
220 status = static_cast<Status>(component->status());
221 } else {
222 component->initListener(component);
223 if (component->status() != C2_OK) {
224 status = static_cast<Status>(component->status());
225 }
226 }
227 }
228 }
229 _hidl_cb(status, component);
230 return Void();
231 }
这边Hidl service 的代码 就先不详细看了,先主要了解一下,等后面实际调用到再去看了
3.hidl service
路径在 /frameworks/av/media/codec2/hal/services/:
Android.bp 中看到 bin 档:name: "android.hardware.media.c2@1.2-default-service",
所以这个就是上一篇想get 的 default sevice
//路径结构
/frameworks/av/media/codec2/hal/services/
Android.bp
android.hardware.media.c2@1.2-default-service.rc
manifest_media_c2_V1_0_default.xml
manifest_media_c2_V1_1_default.xml
manifest_media_c2_V1_2_default.xml
seccomp_policy
vendor.cpp
=====================
// manifest 的信息
/frameworks/av/media/codec2/hal/services/manifest_media_c2_V1_2_default.xml
1 <manifest version="1.0" type="device">
2 <hal>
3 <name>android.hardware.media.c2</name>
4 <transport>hwbinder</transport>
5 <version>1.2</version>
6 <interface>
7 <name>IComponentStore</name>
8 <instance>default</instance>
9 </interface>
10 </hal>
11 </manifest>
=====================
//rc 启动文档
/frameworks/av/media/codec2/hal/services/android.hardware.media.c2@1.2-default-service.rc
1 service android-hardware-media-c2-hal-1-2 /vendor/bin/hw/android.hardware.media.c2@1.2-default-service
2 class hal
3 user mediacodec
4 group camera mediadrm drmrpc
5 ioprio rt 4
6 task_profiles ProcessCapacityHigh
=========================
/frameworks/av/media/codec2/hal/services/vendor.cpp
18 #define LOG_TAG "android.hardware.media.c2@1.2-service"
165 int main(int /* argc */, char** /* argv */) {
166 using namespace ::android;
167 LOG(DEBUG) << "android.hardware.media.c2@1.2-service starting...";
168
169 // Set up minijail to limit system calls.
170 signal(SIGPIPE, SIG_IGN);
171 SetUpMinijail(kBaseSeccompPolicyPath, kExtSeccompPolicyPath);
172
173 // Enable vndbinder to allow vendor-to-vendor binder calls.
174 ProcessState::initWithDriver("/dev/vndbinder");
175
176 ProcessState::self()->startThreadPool();
177 // Extra threads may be needed to handle a stacked IPC sequence that
178 // contains alternating binder and hwbinder calls. (See b/35283480.)
179 hardware::configureRpcThreadpool(8, true /* callerWillJoin */);
180 //前面是 hidl sevice 的流程就不管了
181 // Create IComponentStore service.
182 {
183 using namespace ::android::hardware::media::c2::V1_2;
184 sp<IComponentStore> store;
185
189 LOG(DEBUG) << "Instantiating Codec2's IComponentStore service...";
190 store = new utils::ComponentStore(
191 std::make_shared<StoreImpl>());
192
193 if (store == nullptr) {
194 LOG(ERROR) << "Cannot create Codec2's IComponentStore service.";
195 } else {
196 constexpr char const* serviceName = "default";
197 if (store->registerAsService(serviceName) != OK) { //注册为 default service
198 LOG(ERROR) << "Cannot register Codec2's IComponentStore service"
199 " with instance name << \""
200 << serviceName << "\".";
201 } else {
202 LOG(DEBUG) << "Codec2's IComponentStore service registered. "
203 "Instance name: \"" << serviceName << "\".";
204 }
205 }
206 }
207
208 hardware::joinRpcThreadpool();
209 return 0;
210 }
service 里面主要就是 看 new utils::ComponentStore(std::make_shared<StoreImpl>()); 这一步
/frameworks/av/media/codec2/hal/services/vendor.cpp
42 class StoreImpl : public C2ComponentStore {
44 StoreImpl()
45 : mReflectorHelper(std::make_shared<C2ReflectorHelper>()),
46 mInterface(mReflectorHelper) {
47 }
54
55 virtual c2_status_t createComponent(
56 C2String /*name*/,
57 std::shared_ptr<C2Component>* const /*component*/) override {
58 return C2_NOT_FOUND;
59 }
60
61 virtual c2_status_t createInterface(
62 C2String /* name */,
63 std::shared_ptr<C2ComponentInterface>* const /* interface */) override {
64 return C2_NOT_FOUND;
65 }
看起来只是 创建了一个 StoreImp 对象(C2ReflectorHelper)并没有做什么事,里面的函数都是未实现的。
总结:到这边 code2 hidl service 就启动完成了,这个service 是专门为 vendor 的硬解,上层 framwokes 想要调用到 vendor 的compent 就要通过 hidl 来做到。