xref: /aosp_15_r20/frameworks/av/media/codec2/hal/aidl/include/codec2/aidl/ParamTypes.h (revision ec779b8e0859a360c3d303172224686826e6e0e1)
1 /*
2  * Copyright 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 CODEC2_AIDL_UTILS_PARAM_TYPES_H
18 #define CODEC2_AIDL_UTILS_PARAM_TYPES_H
19 
20 #include <aidl/android/hardware/media/c2/FieldSupportedValuesQuery.h>
21 #include <aidl/android/hardware/media/c2/FieldSupportedValuesQueryResult.h>
22 #include <aidl/android/hardware/media/c2/IComponentStore.h>
23 #include <aidl/android/hardware/media/c2/ParamDescriptor.h>
24 #include <aidl/android/hardware/media/c2/SettingResult.h>
25 #include <aidl/android/hardware/media/c2/Status.h>
26 #include <aidl/android/hardware/media/c2/StructDescriptor.h>
27 
28 #include <C2Component.h>
29 #include <C2Param.h>
30 #include <C2ParamDef.h>
31 #include <util/C2Debug-base.h>
32 
33 namespace aidl {
34 namespace android {
35 namespace hardware {
36 namespace media {
37 namespace c2 {
38 namespace utils {
39 
40 // Returns true iff AIDL c2 HAL is selected for the system
41 bool IsSelected();
42 
43 // Make asString() and operator<< work with Status as well as c2_status_t.
44 C2_DECLARE_AS_STRING_AND_DEFINE_STREAM_OUT(Status);
45 
46 /**
47  * All To/FromAidl() functions will return a boolean value indicating whether the
48  * conversion succeeds or not.
49  */
50 
51 // C2SettingResult -> SettingResult
52 bool ToAidl(
53         SettingResult* d,
54         const C2SettingResult& s);
55 
56 // SettingResult -> std::unique_ptr<C2SettingResult>
57 bool FromAidl(
58         std::unique_ptr<C2SettingResult>* d,
59         const SettingResult& s);
60 
61 // C2ParamDescriptor -> ParamDescriptor
62 bool ToAidl(
63         ParamDescriptor* d,
64         const C2ParamDescriptor& s);
65 
66 // ParamDescriptor -> std::shared_ptr<C2ParamDescriptor>
67 bool FromAidl(
68         std::shared_ptr<C2ParamDescriptor>* d,
69         const ParamDescriptor& s);
70 
71 // C2FieldSupportedValuesQuery -> FieldSupportedValuesQuery
72 bool ToAidl(
73         FieldSupportedValuesQuery* d,
74         const C2FieldSupportedValuesQuery& s);
75 
76 // FieldSupportedValuesQuery -> C2FieldSupportedValuesQuery
77 bool FromAidl(
78         C2FieldSupportedValuesQuery* d,
79         const FieldSupportedValuesQuery& s);
80 
81 // C2FieldSupportedValuesQuery -> FieldSupportedValuesQueryResult
82 bool ToAidl(
83         FieldSupportedValuesQueryResult* d,
84         const C2FieldSupportedValuesQuery& s);
85 
86 // FieldSupportedValuesQuery, FieldSupportedValuesQueryResult -> C2FieldSupportedValuesQuery
87 bool FromAidl(
88         C2FieldSupportedValuesQuery* d,
89         const FieldSupportedValuesQuery& sq,
90         const FieldSupportedValuesQueryResult& sr);
91 
92 // C2Component::Traits -> ComponentTraits
93 bool ToAidl(
94         IComponentStore::ComponentTraits* d,
95         const C2Component::Traits& s);
96 
97 // ComponentTraits -> C2Component::Traits
98 bool FromAidl(
99         C2Component::Traits* d,
100         const IComponentStore::ComponentTraits& s);
101 
102 // C2StructDescriptor -> StructDescriptor
103 bool ToAidl(
104         StructDescriptor* d,
105         const C2StructDescriptor& s);
106 
107 // StructDescriptor -> C2StructDescriptor
108 bool FromAidl(
109         std::unique_ptr<C2StructDescriptor>* d,
110         const StructDescriptor& s);
111 
112 /**
113  * Parses a params blob and returns C2Param pointers to its params. The pointers
114  * point to locations inside the underlying buffer of \p blob. If \p blob is
115  * destroyed, the pointers become invalid.
116  *
117  * \param[out] params target vector of C2Param pointers
118  * \param[in] blob parameter blob to parse
119  * \retval true if the full blob was parsed
120  * \retval false otherwise
121  */
122 bool ParseParamsBlob(
123         std::vector<C2Param*> *params,
124         const Params &blob);
125 
126 /**
127  * Concatenates a list of C2Params into a params blob.
128  *
129  * \param[out] blob target blob
130  * \param[in] params parameters to concatenate
131  * \retval true if the blob was successfully created
132  * \retval false if the blob was not successful (this only happens if the
133  *         parameters were not const)
134  */
135 bool CreateParamsBlob(
136         Params *blob,
137         const std::vector<C2Param*> &params);
138 bool CreateParamsBlob(
139         Params *blob,
140         const std::vector<std::unique_ptr<C2Param>> &params);
141 bool CreateParamsBlob(
142         Params *blob,
143         const std::vector<std::shared_ptr<const C2Info>> &params);
144 bool CreateParamsBlob(
145         Params *blob,
146         const std::vector<std::unique_ptr<C2Tuning>> &params);
147 
148 /**
149  * Parses a params blob and create a vector of C2Params whose members are copies
150  * of the params in the blob.
151  *
152  * \param[out] params the resulting vector
153  * \param[in] blob parameter blob to parse
154  * \retval true if the full blob was parsed and params was constructed
155  * \retval false otherwise
156  */
157 bool CopyParamsFromBlob(
158         std::vector<std::unique_ptr<C2Param>>* params,
159         const Params &blob);
160 bool CopyParamsFromBlob(
161         std::vector<std::unique_ptr<C2Tuning>>* params,
162         const Params &blob);
163 
164 /**
165  * Parses a params blob and applies updates to params.
166  *
167  * \param[in,out] params params to be updated
168  * \param[in] blob parameter blob containing updates
169  * \retval true if the full blob was parsed and params was updated
170  * \retval false otherwise
171  */
172 bool UpdateParamsFromBlob(
173         const std::vector<C2Param*>& params,
174         const Params& blob);
175 
176 }  // namespace utils
177 }  // namespace c2
178 }  // namespace media
179 }  // namespace hardware
180 }  // namespace android
181 }  // namespace aidl
182 
183 #endif  // CODEC2_AIDL_UTILS_PARAM_TYPES_H
184