• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef HARDWARE_GOOGLE_MEDIA_C2_V1_0_UTILS_CONFIGURABLE_H
18 #define HARDWARE_GOOGLE_MEDIA_C2_V1_0_UTILS_CONFIGURABLE_H
19 
20 #include <codec2/hidl/1.0/ConfigurableC2Intf.h>
21 
22 #include <C2Component.h>
23 #include <C2Param.h>
24 #include <C2.h>
25 
26 #include <hardware/google/media/c2/1.0/IConfigurable.h>
27 #include <hidl/Status.h>
28 
29 #include <memory>
30 
31 namespace hardware {
32 namespace google {
33 namespace media {
34 namespace c2 {
35 namespace V1_0 {
36 namespace utils {
37 
38 using ::android::hardware::hidl_array;
39 using ::android::hardware::hidl_memory;
40 using ::android::hardware::hidl_string;
41 using ::android::hardware::hidl_vec;
42 using ::android::hardware::Return;
43 using ::android::hardware::Void;
44 using ::android::sp;
45 
46 struct ComponentStore;
47 
48 /**
49  * Implementation of the IConfigurable interface that supports caching of
50  * supported parameters from a supplied ComponentStore.
51  *
52  * This is mainly the same for all of the configurable C2 interfaces though
53  * there are slight differences in the blocking behavior. This is handled in the
54  * ConfigurableC2Intf implementations.
55  */
56 struct CachedConfigurable : public IConfigurable {
57     CachedConfigurable(std::unique_ptr<ConfigurableC2Intf>&& intf);
58 
59     c2_status_t init(ComponentStore* store);
60 
61     // Methods from ::android::hardware::media::c2::V1_0::IConfigurable
62 
63     virtual Return<void> getName(getName_cb _hidl_cb) override;
64 
65     virtual Return<void> query(
66             const hidl_vec<uint32_t>& indices,
67             bool mayBlock,
68             query_cb _hidl_cb) override;
69 
70     virtual Return<void> config(
71             const hidl_vec<uint8_t>& inParams,
72             bool mayBlock,
73             config_cb _hidl_cb) override;
74 
75     virtual Return<void> querySupportedParams(
76             uint32_t start,
77             uint32_t count,
78             querySupportedParams_cb _hidl_cb) override;
79 
80     virtual Return<void> querySupportedValues(
81             const hidl_vec<FieldSupportedValuesQuery>& inFields,
82             bool mayBlock,
83             querySupportedValues_cb _hidl_cb) override;
84 
85 protected:
86     // Common Codec2.0 interface wrapper
87     std::unique_ptr<ConfigurableC2Intf> mIntf;
88 
89     // Cached supported params
90     std::vector<std::shared_ptr<C2ParamDescriptor>> mSupportedParams;
91 };
92 
93 /**
94  * Template that implements the `IConfigurable` interface for an inherited
95  * interface. Classes that implement a child interface `I` of `IConfigurable`
96  * can derive from `Configurable<I>`.
97  */
98 template <typename I>
99 struct Configurable : public I {
ConfigurableConfigurable100     Configurable(const sp<CachedConfigurable>& intf): mIntf(intf) {
101     }
102 
initConfigurable103     c2_status_t init(ComponentStore* store) {
104         return mIntf->init(store);
105     }
106 
107     // Methods from ::android::hardware::media::c2::V1_0::IConfigurable
108 
109     using getName_cb = typename I::getName_cb;
getNameConfigurable110     virtual Return<void> getName(getName_cb _hidl_cb) override {
111         return mIntf->getName(_hidl_cb);
112     }
113 
114     using query_cb = typename I::query_cb;
queryConfigurable115     virtual Return<void> query(
116             const hidl_vec<uint32_t>& indices,
117             bool mayBlock,
118             query_cb _hidl_cb) override {
119         return mIntf->query(indices, mayBlock, _hidl_cb);
120     }
121 
122     using config_cb = typename I::config_cb;
configConfigurable123     virtual Return<void> config(
124             const hidl_vec<uint8_t>& inParams,
125             bool mayBlock,
126             config_cb _hidl_cb) override {
127         return mIntf->config(inParams, mayBlock, _hidl_cb);
128     }
129 
130     using querySupportedParams_cb = typename I::querySupportedParams_cb;
querySupportedParamsConfigurable131     virtual Return<void> querySupportedParams(
132             uint32_t start,
133             uint32_t count,
134             querySupportedParams_cb _hidl_cb) override {
135         return mIntf->querySupportedParams(start, count, _hidl_cb);
136     }
137 
138     using querySupportedValues_cb = typename I::querySupportedValues_cb;
querySupportedValuesConfigurable139     virtual Return<void> querySupportedValues(
140             const hidl_vec<FieldSupportedValuesQuery>& inFields,
141             bool mayBlock,
142             querySupportedValues_cb _hidl_cb) override {
143         return mIntf->querySupportedValues(inFields, mayBlock, _hidl_cb);
144     }
145 
146 protected:
147     sp<CachedConfigurable> mIntf;
148 };
149 
150 }  // namespace utils
151 }  // namespace V1_0
152 }  // namespace c2
153 }  // namespace media
154 }  // namespace google
155 }  // namespace hardware
156 
157 #endif  // HARDWARE_GOOGLE_MEDIA_C2_V1_0_UTILS_CONFIGURABLE_H
158