1 /*
2 * Copyright (C) 2017 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 //#define LOG_NDEBUG 0
18 #define LOG_TAG "SimpleC2Interface"
19 #include <utils/Log.h>
20
21 // use MediaDefs here vs. MediaCodecConstants as this is not MediaCodec
22 // specific/dependent
23 #include <media/stagefright/foundation/MediaDefs.h>
24
25 #include <C2PlatformSupport.h>
26 #include <SimpleC2Interface.h>
27
28 namespace android {
29
30 /* SimpleInterface */
31
BaseParams(const std::shared_ptr<C2ReflectorHelper> & reflector,C2String name,C2Component::kind_t kind,C2Component::domain_t domain,C2String mediaType,std::vector<C2String> aliases)32 SimpleInterface<void>::BaseParams::BaseParams(
33 const std::shared_ptr<C2ReflectorHelper> &reflector, C2String name,
34 C2Component::kind_t kind, C2Component::domain_t domain, C2String mediaType,
35 std::vector<C2String> aliases)
36 : C2InterfaceHelper(reflector) {
37 setDerivedInstance(this);
38
39 /*
40 addParameter(
41 DefineParam(mApiFeatures, C2_PARAMKEY_API_FEATURES)
42 .withConstValue(new C2ApiFeaturesSetting(C2Config::api_feature_t(
43 API_REFLECTION | API_VALUES | API_CURRENT_VALUES |
44 API_DEPENDENCY | API_SAME_INPUT_BUFFER)))
45 .build());
46 */
47
48 addParameter(DefineParam(mName, C2_PARAMKEY_COMPONENT_NAME)
49 .withConstValue(AllocSharedString<C2ComponentNameSetting>(
50 name.c_str()))
51 .build());
52
53 if (aliases.size()) {
54 C2String joined;
55 for (const C2String &alias : aliases) {
56 if (joined.length()) {
57 joined += ",";
58 }
59 joined += alias;
60 }
61 addParameter(
62 DefineParam(mAliases, C2_PARAMKEY_COMPONENT_ALIASES)
63 .withConstValue(AllocSharedString<C2ComponentAliasesSetting>(
64 joined.c_str()))
65 .build());
66 }
67
68 addParameter(DefineParam(mKind, C2_PARAMKEY_COMPONENT_KIND)
69 .withConstValue(new C2ComponentKindSetting(kind))
70 .build());
71
72 addParameter(DefineParam(mDomain, C2_PARAMKEY_COMPONENT_DOMAIN)
73 .withConstValue(new C2ComponentDomainSetting(domain))
74 .build());
75
76 // simple interfaces have single streams
77 addParameter(DefineParam(mInputStreamCount, C2_PARAMKEY_INPUT_STREAM_COUNT)
78 .withConstValue(new C2PortStreamCountTuning::input(1))
79 .build());
80
81 addParameter(
82 DefineParam(mOutputStreamCount, C2_PARAMKEY_OUTPUT_STREAM_COUNT)
83 .withConstValue(new C2PortStreamCountTuning::output(1))
84 .build());
85
86 // set up buffer formats and allocators
87
88 // default to linear buffers and no media type
89 C2BufferData::type_t rawBufferType = C2BufferData::LINEAR;
90 C2String rawMediaType;
91 C2Allocator::id_t rawAllocator = C2AllocatorStore::DEFAULT_LINEAR;
92 C2BlockPool::local_id_t rawPoolId = C2BlockPool::BASIC_LINEAR;
93 C2BufferData::type_t codedBufferType = C2BufferData::LINEAR;
94 int poolMask = GetCodec2PoolMask();
95 C2Allocator::id_t preferredLinearId =
96 GetPreferredLinearAllocatorId(poolMask);
97 C2Allocator::id_t codedAllocator = preferredLinearId;
98 C2BlockPool::local_id_t codedPoolId = C2BlockPool::BASIC_LINEAR;
99
100 switch (domain) {
101 case C2Component::DOMAIN_IMAGE:
102 [[fallthrough]];
103 case C2Component::DOMAIN_VIDEO:
104 // TODO: should we define raw image? The only difference is timestamp
105 // handling
106 rawBufferType = C2BufferData::GRAPHIC;
107 rawMediaType = MEDIA_MIMETYPE_VIDEO_RAW;
108 rawAllocator = C2PlatformAllocatorStore::GRALLOC;
109 rawPoolId = C2BlockPool::BASIC_GRAPHIC;
110 break;
111 case C2Component::DOMAIN_AUDIO:
112 rawBufferType = C2BufferData::LINEAR;
113 rawMediaType = MEDIA_MIMETYPE_AUDIO_RAW;
114 rawAllocator = preferredLinearId;
115 rawPoolId = C2BlockPool::BASIC_LINEAR;
116 break;
117 default:
118 break;
119 }
120 bool isEncoder = kind == C2Component::KIND_ENCODER;
121
122 // handle raw decoders
123 if (mediaType == rawMediaType) {
124 codedBufferType = rawBufferType;
125 codedAllocator = rawAllocator;
126 codedPoolId = rawPoolId;
127 }
128
129 addParameter(DefineParam(mInputFormat, C2_PARAMKEY_INPUT_STREAM_BUFFER_TYPE)
130 .withConstValue(new C2StreamBufferTypeSetting::input(
131 0u, isEncoder ? rawBufferType : codedBufferType))
132 .build());
133
134 addParameter(
135 DefineParam(mInputMediaType, C2_PARAMKEY_INPUT_MEDIA_TYPE)
136 .withConstValue(AllocSharedString<C2PortMediaTypeSetting::input>(
137 isEncoder ? rawMediaType : mediaType))
138 .build());
139
140 addParameter(
141 DefineParam(mOutputFormat, C2_PARAMKEY_OUTPUT_STREAM_BUFFER_TYPE)
142 .withConstValue(new C2StreamBufferTypeSetting::output(
143 0u, isEncoder ? codedBufferType : rawBufferType))
144 .build());
145
146 addParameter(
147 DefineParam(mOutputMediaType, C2_PARAMKEY_OUTPUT_MEDIA_TYPE)
148 .withConstValue(AllocSharedString<C2PortMediaTypeSetting::output>(
149 isEncoder ? mediaType : rawMediaType))
150 .build());
151
152 C2Allocator::id_t inputAllocators[1] = {isEncoder ? rawAllocator
153 : codedAllocator};
154 C2Allocator::id_t outputAllocators[1] = {isEncoder ? codedAllocator
155 : rawAllocator};
156 C2BlockPool::local_id_t outputPoolIds[1] = {isEncoder ? codedPoolId
157 : rawPoolId};
158
159 addParameter(
160 DefineParam(mInputAllocators, C2_PARAMKEY_INPUT_ALLOCATORS)
161 .withDefault(
162 C2PortAllocatorsTuning::input::AllocShared(inputAllocators))
163 .withFields({C2F(mInputAllocators, m.values[0]).any(),
164 C2F(mInputAllocators, m.values).inRange(0, 1)})
165 .withSetter(
166 Setter<
167 C2PortAllocatorsTuning::input>::NonStrictValuesWithNoDeps)
168 .build());
169
170 addParameter(
171 DefineParam(mOutputAllocators, C2_PARAMKEY_OUTPUT_ALLOCATORS)
172 .withDefault(
173 C2PortAllocatorsTuning::output::AllocShared(outputAllocators))
174 .withFields({C2F(mOutputAllocators, m.values[0]).any(),
175 C2F(mOutputAllocators, m.values).inRange(0, 1)})
176 .withSetter(
177 Setter<
178 C2PortAllocatorsTuning::output>::NonStrictValuesWithNoDeps)
179 .build());
180
181 addParameter(
182 DefineParam(mOutputPoolIds, C2_PARAMKEY_OUTPUT_BLOCK_POOLS)
183 .withDefault(
184 C2PortBlockPoolsTuning::output::AllocShared(outputPoolIds))
185 .withFields({C2F(mOutputPoolIds, m.values[0]).any(),
186 C2F(mOutputPoolIds, m.values).inRange(0, 1)})
187 .withSetter(
188 Setter<
189 C2PortBlockPoolsTuning::output>::NonStrictValuesWithNoDeps)
190 .build());
191
192 // add stateless params
193 addParameter(
194 DefineParam(mSubscribedParamIndices,
195 C2_PARAMKEY_SUBSCRIBED_PARAM_INDICES)
196 .withDefault(C2SubscribedParamIndicesTuning::AllocShared(0u))
197 .withFields({C2F(mSubscribedParamIndices, m.values[0]).any(),
198 C2F(mSubscribedParamIndices, m.values).any()})
199 .withSetter(
200 Setter<
201 C2SubscribedParamIndicesTuning>::NonStrictValuesWithNoDeps)
202 .build());
203
204 /* TODO
205
206 addParameter(
207 DefineParam(mCurrentWorkOrdinal, C2_PARAMKEY_CURRENT_WORK)
208 .withDefault(new C2CurrentWorkTuning())
209 .withFields({ C2F(mCurrentWorkOrdinal, m.timeStamp).any(),
210 C2F(mCurrentWorkOrdinal, m.frameIndex).any(),
211 C2F(mCurrentWorkOrdinal, m.customOrdinal).any() })
212 .withSetter(Setter<C2CurrentWorkTuning>::NonStrictValuesWithNoDeps)
213 .build());
214
215 addParameter(
216 DefineParam(mLastInputQueuedWorkOrdinal,
217 C2_PARAMKEY_LAST_INPUT_QUEUED) .withDefault(new
218 C2LastWorkQueuedTuning::input()) .withFields({
219 C2F(mLastInputQueuedWorkOrdinal, m.timeStamp).any(),
220 C2F(mLastInputQueuedWorkOrdinal, m.frameIndex).any(),
221 C2F(mLastInputQueuedWorkOrdinal,
222 m.customOrdinal).any() })
223 .withSetter(Setter<C2LastWorkQueuedTuning::input>::NonStrictValuesWithNoDeps)
224 .build());
225
226 addParameter(
227 DefineParam(mLastOutputQueuedWorkOrdinal,
228 C2_PARAMKEY_LAST_OUTPUT_QUEUED) .withDefault(new
229 C2LastWorkQueuedTuning::output()) .withFields({
230 C2F(mLastOutputQueuedWorkOrdinal, m.timeStamp).any(),
231 C2F(mLastOutputQueuedWorkOrdinal, m.frameIndex).any(),
232 C2F(mLastOutputQueuedWorkOrdinal,
233 m.customOrdinal).any() })
234 .withSetter(Setter<C2LastWorkQueuedTuning::output>::NonStrictValuesWithNoDeps)
235 .build());
236
237 std::shared_ptr<C2OutOfMemoryTuning> mOutOfMemory;
238
239 std::shared_ptr<C2PortConfigCounterTuning::input> mInputConfigCounter;
240 std::shared_ptr<C2PortConfigCounterTuning::output> mOutputConfigCounter;
241 std::shared_ptr<C2ConfigCounterTuning> mDirectConfigCounter;
242
243 */
244 }
245
noInputLatency()246 void SimpleInterface<void>::BaseParams::noInputLatency() {
247 addParameter(
248 DefineParam(mRequestedInputDelay, C2_PARAMKEY_INPUT_DELAY_REQUEST)
249 .withConstValue(new C2PortRequestedDelayTuning::input(0u))
250 .build());
251
252 addParameter(DefineParam(mActualInputDelay, C2_PARAMKEY_INPUT_DELAY)
253 .withConstValue(new C2PortActualDelayTuning::input(0u))
254 .build());
255 }
256
noOutputLatency()257 void SimpleInterface<void>::BaseParams::noOutputLatency() {
258 addParameter(
259 DefineParam(mRequestedOutputDelay, C2_PARAMKEY_OUTPUT_DELAY_REQUEST)
260 .withConstValue(new C2PortRequestedDelayTuning::output(0u))
261 .build());
262
263 addParameter(DefineParam(mActualOutputDelay, C2_PARAMKEY_OUTPUT_DELAY)
264 .withConstValue(new C2PortActualDelayTuning::output(0u))
265 .build());
266 }
267
noPipelineLatency()268 void SimpleInterface<void>::BaseParams::noPipelineLatency() {
269 addParameter(
270 DefineParam(mRequestedPipelineDelay, C2_PARAMKEY_PIPELINE_DELAY_REQUEST)
271 .withConstValue(new C2RequestedPipelineDelayTuning(0u))
272 .build());
273
274 addParameter(DefineParam(mActualPipelineDelay, C2_PARAMKEY_PIPELINE_DELAY)
275 .withConstValue(new C2ActualPipelineDelayTuning(0u))
276 .build());
277 }
278
noPrivateBuffers()279 void SimpleInterface<void>::BaseParams::noPrivateBuffers() {
280 addParameter(DefineParam(mPrivateAllocators, C2_PARAMKEY_PRIVATE_ALLOCATORS)
281 .withConstValue(C2PrivateAllocatorsTuning::AllocShared(0u))
282 .build());
283
284 addParameter(
285 DefineParam(mMaxPrivateBufferCount,
286 C2_PARAMKEY_MAX_PRIVATE_BUFFER_COUNT)
287 .withConstValue(C2MaxPrivateBufferCountTuning::AllocShared(0u))
288 .build());
289
290 addParameter(DefineParam(mPrivatePoolIds, C2_PARAMKEY_PRIVATE_BLOCK_POOLS)
291 .withConstValue(C2PrivateBlockPoolsTuning::AllocShared(0u))
292 .build());
293 }
294
noInputReferences()295 void SimpleInterface<void>::BaseParams::noInputReferences() {
296 addParameter(
297 DefineParam(mMaxInputReferenceAge, C2_PARAMKEY_INPUT_MAX_REFERENCE_AGE)
298 .withConstValue(new C2StreamMaxReferenceAgeTuning::input(0u))
299 .build());
300
301 addParameter(
302 DefineParam(mMaxInputReferenceCount,
303 C2_PARAMKEY_INPUT_MAX_REFERENCE_COUNT)
304 .withConstValue(new C2StreamMaxReferenceCountTuning::input(0u))
305 .build());
306 }
307
noOutputReferences()308 void SimpleInterface<void>::BaseParams::noOutputReferences() {
309 addParameter(
310 DefineParam(mMaxOutputReferenceAge,
311 C2_PARAMKEY_OUTPUT_MAX_REFERENCE_AGE)
312 .withConstValue(new C2StreamMaxReferenceAgeTuning::output(0u))
313 .build());
314
315 addParameter(
316 DefineParam(mMaxOutputReferenceCount,
317 C2_PARAMKEY_OUTPUT_MAX_REFERENCE_COUNT)
318 .withConstValue(new C2StreamMaxReferenceCountTuning::output(0u))
319 .build());
320 }
321
noTimeStretch()322 void SimpleInterface<void>::BaseParams::noTimeStretch() {
323 addParameter(DefineParam(mTimeStretch, C2_PARAMKEY_TIME_STRETCH)
324 .withConstValue(new C2ComponentTimeStretchTuning(1.f))
325 .build());
326 }
327
328 /*
329 Clients need to handle the following base params due to custom dependency.
330
331 std::shared_ptr<C2ApiLevelSetting> mApiLevel;
332 std::shared_ptr<C2ComponentAttributesSetting> mAttrib;
333
334 std::shared_ptr<C2PortSuggestedBufferCountTuning::input>
335 mSuggestedInputBufferCount;
336 std::shared_ptr<C2PortSuggestedBufferCountTuning::output>
337 mSuggestedOutputBufferCount;
338
339 std::shared_ptr<C2TrippedTuning> mTripped;
340
341 */
342
343 } // namespace android
344