blob: 386e0976121c433e36ee2fe324c094b8be5a530a [file] [log] [blame]
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -07001/*
2 * Copyright (C) 2019 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 "C2SoftGav1Dec"
19#include "C2SoftGav1Dec.h"
20
21#include <C2Debug.h>
22#include <C2PlatformSupport.h>
Neelkamal Semwal678a2b82021-09-01 17:07:30 +053023#include <Codec2Mapper.h>
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -070024#include <SimpleC2Interface.h>
25#include <log/log.h>
26#include <media/stagefright/foundation/AUtils.h>
27#include <media/stagefright/foundation/MediaDefs.h>
28
29namespace android {
Vignesh Venkatasubramanianbfd9a212021-02-04 12:39:06 -080030namespace {
31
32constexpr uint8_t NEUTRAL_UV_VALUE = 128;
33
34} // namespace
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -070035
Ray Essickc2cc4372019-08-21 14:02:28 -070036// codecname set and passed in as a compile flag from Android.bp
37constexpr char COMPONENT_NAME[] = CODECNAME;
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -070038
Ray Essick1af2cc52022-01-25 15:59:23 -080039constexpr size_t kMinInputBufferSize = 2 * 1024 * 1024;
40
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -070041class C2SoftGav1Dec::IntfImpl : public SimpleInterface<void>::BaseParams {
42 public:
43 explicit IntfImpl(const std::shared_ptr<C2ReflectorHelper> &helper)
44 : SimpleInterface<void>::BaseParams(
45 helper, COMPONENT_NAME, C2Component::KIND_DECODER,
46 C2Component::DOMAIN_VIDEO, MEDIA_MIMETYPE_VIDEO_AV1) {
47 noPrivateBuffers(); // TODO: account for our buffers here.
48 noInputReferences();
49 noOutputReferences();
50 noInputLatency();
51 noTimeStretch();
52
53 addParameter(DefineParam(mAttrib, C2_PARAMKEY_COMPONENT_ATTRIBUTES)
54 .withConstValue(new C2ComponentAttributesSetting(
55 C2Component::ATTRIB_IS_TEMPORAL))
56 .build());
57
58 addParameter(
59 DefineParam(mSize, C2_PARAMKEY_PICTURE_SIZE)
60 .withDefault(new C2StreamPictureSizeInfo::output(0u, 320, 240))
61 .withFields({
Vignesh Venkatasubramanian2509e1a2021-01-25 09:42:44 -080062 C2F(mSize, width).inRange(2, 4096, 2),
63 C2F(mSize, height).inRange(2, 4096, 2),
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -070064 })
65 .withSetter(SizeSetter)
66 .build());
67
68 addParameter(DefineParam(mProfileLevel, C2_PARAMKEY_PROFILE_LEVEL)
69 .withDefault(new C2StreamProfileLevelInfo::input(
70 0u, C2Config::PROFILE_AV1_0, C2Config::LEVEL_AV1_2_1))
71 .withFields({C2F(mProfileLevel, profile)
72 .oneOf({C2Config::PROFILE_AV1_0,
73 C2Config::PROFILE_AV1_1}),
74 C2F(mProfileLevel, level)
75 .oneOf({
Harish Mahendrakar07dc80d2021-06-04 15:42:31 -070076 C2Config::LEVEL_AV1_2, C2Config::LEVEL_AV1_2_1,
77 C2Config::LEVEL_AV1_2_2, C2Config::LEVEL_AV1_2_3,
78 C2Config::LEVEL_AV1_3, C2Config::LEVEL_AV1_3_1,
79 C2Config::LEVEL_AV1_3_2, C2Config::LEVEL_AV1_3_3,
80 C2Config::LEVEL_AV1_4, C2Config::LEVEL_AV1_4_1,
81 C2Config::LEVEL_AV1_4_2, C2Config::LEVEL_AV1_4_3,
82 C2Config::LEVEL_AV1_5, C2Config::LEVEL_AV1_5_1,
83 C2Config::LEVEL_AV1_5_2, C2Config::LEVEL_AV1_5_3,
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -070084 })})
85 .withSetter(ProfileLevelSetter, mSize)
86 .build());
87
88 mHdr10PlusInfoInput = C2StreamHdr10PlusInfo::input::AllocShared(0);
89 addParameter(
90 DefineParam(mHdr10PlusInfoInput, C2_PARAMKEY_INPUT_HDR10_PLUS_INFO)
91 .withDefault(mHdr10PlusInfoInput)
92 .withFields({
93 C2F(mHdr10PlusInfoInput, m.value).any(),
94 })
95 .withSetter(Hdr10PlusInfoInputSetter)
96 .build());
97
98 mHdr10PlusInfoOutput = C2StreamHdr10PlusInfo::output::AllocShared(0);
99 addParameter(
100 DefineParam(mHdr10PlusInfoOutput, C2_PARAMKEY_OUTPUT_HDR10_PLUS_INFO)
101 .withDefault(mHdr10PlusInfoOutput)
102 .withFields({
103 C2F(mHdr10PlusInfoOutput, m.value).any(),
104 })
105 .withSetter(Hdr10PlusInfoOutputSetter)
106 .build());
107
108 addParameter(
109 DefineParam(mMaxSize, C2_PARAMKEY_MAX_PICTURE_SIZE)
110 .withDefault(new C2StreamMaxPictureSizeTuning::output(0u, 320, 240))
111 .withFields({
112 C2F(mSize, width).inRange(2, 2048, 2),
113 C2F(mSize, height).inRange(2, 2048, 2),
114 })
115 .withSetter(MaxPictureSizeSetter, mSize)
116 .build());
117
118 addParameter(DefineParam(mMaxInputSize, C2_PARAMKEY_INPUT_MAX_BUFFER_SIZE)
Ray Essick1af2cc52022-01-25 15:59:23 -0800119 .withDefault(new C2StreamMaxBufferSizeInfo::input(0u, kMinInputBufferSize))
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -0700120 .withFields({
121 C2F(mMaxInputSize, value).any(),
122 })
123 .calculatedAs(MaxInputSizeSetter, mMaxSize)
124 .build());
125
126 C2ChromaOffsetStruct locations[1] = {C2ChromaOffsetStruct::ITU_YUV_420_0()};
127 std::shared_ptr<C2StreamColorInfo::output> defaultColorInfo =
128 C2StreamColorInfo::output::AllocShared(1u, 0u, 8u /* bitDepth */,
129 C2Color::YUV_420);
130 memcpy(defaultColorInfo->m.locations, locations, sizeof(locations));
131
132 defaultColorInfo = C2StreamColorInfo::output::AllocShared(
133 {C2ChromaOffsetStruct::ITU_YUV_420_0()}, 0u, 8u /* bitDepth */,
134 C2Color::YUV_420);
135 helper->addStructDescriptors<C2ChromaOffsetStruct>();
136
137 addParameter(DefineParam(mColorInfo, C2_PARAMKEY_CODED_COLOR_INFO)
138 .withConstValue(defaultColorInfo)
139 .build());
140
141 addParameter(
142 DefineParam(mDefaultColorAspects, C2_PARAMKEY_DEFAULT_COLOR_ASPECTS)
143 .withDefault(new C2StreamColorAspectsTuning::output(
144 0u, C2Color::RANGE_UNSPECIFIED, C2Color::PRIMARIES_UNSPECIFIED,
145 C2Color::TRANSFER_UNSPECIFIED, C2Color::MATRIX_UNSPECIFIED))
146 .withFields(
147 {C2F(mDefaultColorAspects, range)
148 .inRange(C2Color::RANGE_UNSPECIFIED, C2Color::RANGE_OTHER),
149 C2F(mDefaultColorAspects, primaries)
150 .inRange(C2Color::PRIMARIES_UNSPECIFIED,
151 C2Color::PRIMARIES_OTHER),
152 C2F(mDefaultColorAspects, transfer)
153 .inRange(C2Color::TRANSFER_UNSPECIFIED,
154 C2Color::TRANSFER_OTHER),
155 C2F(mDefaultColorAspects, matrix)
156 .inRange(C2Color::MATRIX_UNSPECIFIED,
157 C2Color::MATRIX_OTHER)})
158 .withSetter(DefaultColorAspectsSetter)
159 .build());
160
Neelkamal Semwal678a2b82021-09-01 17:07:30 +0530161 addParameter(
162 DefineParam(mCodedColorAspects, C2_PARAMKEY_VUI_COLOR_ASPECTS)
163 .withDefault(new C2StreamColorAspectsInfo::input(
164 0u, C2Color::RANGE_LIMITED, C2Color::PRIMARIES_UNSPECIFIED,
165 C2Color::TRANSFER_UNSPECIFIED, C2Color::MATRIX_UNSPECIFIED))
166 .withFields({
167 C2F(mCodedColorAspects, range).inRange(
168 C2Color::RANGE_UNSPECIFIED, C2Color::RANGE_OTHER),
169 C2F(mCodedColorAspects, primaries).inRange(
170 C2Color::PRIMARIES_UNSPECIFIED, C2Color::PRIMARIES_OTHER),
171 C2F(mCodedColorAspects, transfer).inRange(
172 C2Color::TRANSFER_UNSPECIFIED, C2Color::TRANSFER_OTHER),
173 C2F(mCodedColorAspects, matrix).inRange(
174 C2Color::MATRIX_UNSPECIFIED, C2Color::MATRIX_OTHER)
175 })
176 .withSetter(CodedColorAspectsSetter)
177 .build());
178
179 addParameter(
180 DefineParam(mColorAspects, C2_PARAMKEY_COLOR_ASPECTS)
181 .withDefault(new C2StreamColorAspectsInfo::output(
182 0u, C2Color::RANGE_UNSPECIFIED, C2Color::PRIMARIES_UNSPECIFIED,
183 C2Color::TRANSFER_UNSPECIFIED, C2Color::MATRIX_UNSPECIFIED))
184 .withFields({
185 C2F(mColorAspects, range).inRange(
186 C2Color::RANGE_UNSPECIFIED, C2Color::RANGE_OTHER),
187 C2F(mColorAspects, primaries).inRange(
188 C2Color::PRIMARIES_UNSPECIFIED, C2Color::PRIMARIES_OTHER),
189 C2F(mColorAspects, transfer).inRange(
190 C2Color::TRANSFER_UNSPECIFIED, C2Color::TRANSFER_OTHER),
191 C2F(mColorAspects, matrix).inRange(
192 C2Color::MATRIX_UNSPECIFIED, C2Color::MATRIX_OTHER)
193 })
194 .withSetter(ColorAspectsSetter, mDefaultColorAspects, mCodedColorAspects)
195 .build());
196
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -0700197 // TODO: support more formats?
198 addParameter(DefineParam(mPixelFormat, C2_PARAMKEY_PIXEL_FORMAT)
199 .withConstValue(new C2StreamPixelFormatInfo::output(
200 0u, HAL_PIXEL_FORMAT_YCBCR_420_888))
201 .build());
202 }
203
204 static C2R SizeSetter(bool mayBlock,
205 const C2P<C2StreamPictureSizeInfo::output> &oldMe,
206 C2P<C2StreamPictureSizeInfo::output> &me) {
207 (void)mayBlock;
208 C2R res = C2R::Ok();
209 if (!me.F(me.v.width).supportsAtAll(me.v.width)) {
210 res = res.plus(C2SettingResultBuilder::BadValue(me.F(me.v.width)));
211 me.set().width = oldMe.v.width;
212 }
213 if (!me.F(me.v.height).supportsAtAll(me.v.height)) {
214 res = res.plus(C2SettingResultBuilder::BadValue(me.F(me.v.height)));
215 me.set().height = oldMe.v.height;
216 }
217 return res;
218 }
219
220 static C2R MaxPictureSizeSetter(
221 bool mayBlock, C2P<C2StreamMaxPictureSizeTuning::output> &me,
222 const C2P<C2StreamPictureSizeInfo::output> &size) {
223 (void)mayBlock;
224 // TODO: get max width/height from the size's field helpers vs.
225 // hardcoding
226 me.set().width = c2_min(c2_max(me.v.width, size.v.width), 4096u);
227 me.set().height = c2_min(c2_max(me.v.height, size.v.height), 4096u);
228 return C2R::Ok();
229 }
230
231 static C2R MaxInputSizeSetter(
232 bool mayBlock, C2P<C2StreamMaxBufferSizeInfo::input> &me,
233 const C2P<C2StreamMaxPictureSizeTuning::output> &maxSize) {
234 (void)mayBlock;
Ray Essick1af2cc52022-01-25 15:59:23 -0800235 // assume compression ratio of 2, but enforce a floor
236 me.set().value = c2_max((((maxSize.v.width + 63) / 64)
237 * ((maxSize.v.height + 63) / 64) * 3072), kMinInputBufferSize);
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -0700238 return C2R::Ok();
239 }
240
241 static C2R DefaultColorAspectsSetter(
242 bool mayBlock, C2P<C2StreamColorAspectsTuning::output> &me) {
243 (void)mayBlock;
244 if (me.v.range > C2Color::RANGE_OTHER) {
245 me.set().range = C2Color::RANGE_OTHER;
246 }
247 if (me.v.primaries > C2Color::PRIMARIES_OTHER) {
248 me.set().primaries = C2Color::PRIMARIES_OTHER;
249 }
250 if (me.v.transfer > C2Color::TRANSFER_OTHER) {
251 me.set().transfer = C2Color::TRANSFER_OTHER;
252 }
253 if (me.v.matrix > C2Color::MATRIX_OTHER) {
254 me.set().matrix = C2Color::MATRIX_OTHER;
255 }
256 return C2R::Ok();
257 }
258
Neelkamal Semwal678a2b82021-09-01 17:07:30 +0530259 static C2R CodedColorAspectsSetter(bool mayBlock, C2P<C2StreamColorAspectsInfo::input> &me) {
260 (void)mayBlock;
261 if (me.v.range > C2Color::RANGE_OTHER) {
262 me.set().range = C2Color::RANGE_OTHER;
263 }
264 if (me.v.primaries > C2Color::PRIMARIES_OTHER) {
265 me.set().primaries = C2Color::PRIMARIES_OTHER;
266 }
267 if (me.v.transfer > C2Color::TRANSFER_OTHER) {
268 me.set().transfer = C2Color::TRANSFER_OTHER;
269 }
270 if (me.v.matrix > C2Color::MATRIX_OTHER) {
271 me.set().matrix = C2Color::MATRIX_OTHER;
272 }
273 return C2R::Ok();
274 }
275
276 static C2R ColorAspectsSetter(bool mayBlock, C2P<C2StreamColorAspectsInfo::output> &me,
277 const C2P<C2StreamColorAspectsTuning::output> &def,
278 const C2P<C2StreamColorAspectsInfo::input> &coded) {
279 (void)mayBlock;
280 // take default values for all unspecified fields, and coded values for specified ones
281 me.set().range = coded.v.range == RANGE_UNSPECIFIED ? def.v.range : coded.v.range;
282 me.set().primaries = coded.v.primaries == PRIMARIES_UNSPECIFIED
283 ? def.v.primaries : coded.v.primaries;
284 me.set().transfer = coded.v.transfer == TRANSFER_UNSPECIFIED
285 ? def.v.transfer : coded.v.transfer;
286 me.set().matrix = coded.v.matrix == MATRIX_UNSPECIFIED ? def.v.matrix : coded.v.matrix;
287 return C2R::Ok();
288 }
289
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -0700290 static C2R ProfileLevelSetter(
291 bool mayBlock, C2P<C2StreamProfileLevelInfo::input> &me,
292 const C2P<C2StreamPictureSizeInfo::output> &size) {
293 (void)mayBlock;
294 (void)size;
295 (void)me; // TODO: validate
296 return C2R::Ok();
297 }
298
299 std::shared_ptr<C2StreamColorAspectsTuning::output>
300 getDefaultColorAspects_l() {
301 return mDefaultColorAspects;
302 }
303
Neelkamal Semwal678a2b82021-09-01 17:07:30 +0530304 std::shared_ptr<C2StreamColorAspectsInfo::output> getColorAspects_l() {
305 return mColorAspects;
306 }
307
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -0700308 static C2R Hdr10PlusInfoInputSetter(bool mayBlock,
309 C2P<C2StreamHdr10PlusInfo::input> &me) {
310 (void)mayBlock;
311 (void)me; // TODO: validate
312 return C2R::Ok();
313 }
314
315 static C2R Hdr10PlusInfoOutputSetter(bool mayBlock,
316 C2P<C2StreamHdr10PlusInfo::output> &me) {
317 (void)mayBlock;
318 (void)me; // TODO: validate
319 return C2R::Ok();
320 }
321
322 private:
323 std::shared_ptr<C2StreamProfileLevelInfo::input> mProfileLevel;
324 std::shared_ptr<C2StreamPictureSizeInfo::output> mSize;
325 std::shared_ptr<C2StreamMaxPictureSizeTuning::output> mMaxSize;
326 std::shared_ptr<C2StreamMaxBufferSizeInfo::input> mMaxInputSize;
327 std::shared_ptr<C2StreamColorInfo::output> mColorInfo;
328 std::shared_ptr<C2StreamPixelFormatInfo::output> mPixelFormat;
329 std::shared_ptr<C2StreamColorAspectsTuning::output> mDefaultColorAspects;
Neelkamal Semwal678a2b82021-09-01 17:07:30 +0530330 std::shared_ptr<C2StreamColorAspectsInfo::input> mCodedColorAspects;
331 std::shared_ptr<C2StreamColorAspectsInfo::output> mColorAspects;
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -0700332 std::shared_ptr<C2StreamHdr10PlusInfo::input> mHdr10PlusInfoInput;
333 std::shared_ptr<C2StreamHdr10PlusInfo::output> mHdr10PlusInfoOutput;
334};
335
336C2SoftGav1Dec::C2SoftGav1Dec(const char *name, c2_node_id_t id,
337 const std::shared_ptr<IntfImpl> &intfImpl)
338 : SimpleC2Component(
339 std::make_shared<SimpleInterface<IntfImpl>>(name, id, intfImpl)),
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700340 mIntf(intfImpl),
341 mCodecCtx(nullptr) {
342 gettimeofday(&mTimeStart, nullptr);
343 gettimeofday(&mTimeEnd, nullptr);
344}
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -0700345
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700346C2SoftGav1Dec::~C2SoftGav1Dec() { onRelease(); }
347
348c2_status_t C2SoftGav1Dec::onInit() {
349 return initDecoder() ? C2_OK : C2_CORRUPTED;
350}
351
352c2_status_t C2SoftGav1Dec::onStop() {
353 mSignalledError = false;
354 mSignalledOutputEos = false;
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -0700355 return C2_OK;
356}
357
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700358void C2SoftGav1Dec::onReset() {
359 (void)onStop();
360 c2_status_t err = onFlush_sm();
361 if (err != C2_OK) {
362 ALOGW("Failed to flush the av1 decoder. Trying to hard reset.");
363 destroyDecoder();
364 if (!initDecoder()) {
365 ALOGE("Hard reset failed.");
366 }
367 }
368}
369
370void C2SoftGav1Dec::onRelease() { destroyDecoder(); }
371
372c2_status_t C2SoftGav1Dec::onFlush_sm() {
James Zernb7aee6e2020-06-26 13:49:53 -0700373 Libgav1StatusCode status = mCodecCtx->SignalEOS();
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700374 if (status != kLibgav1StatusOk) {
375 ALOGE("Failed to flush av1 decoder. status: %d.", status);
376 return C2_CORRUPTED;
377 }
378
379 // Dequeue frame (if any) that was enqueued previously.
380 const libgav1::DecoderBuffer *buffer;
381 status = mCodecCtx->DequeueFrame(&buffer);
James Zernb7aee6e2020-06-26 13:49:53 -0700382 if (status != kLibgav1StatusOk && status != kLibgav1StatusNothingToDequeue) {
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700383 ALOGE("Failed to dequeue frame after flushing the av1 decoder. status: %d",
384 status);
385 return C2_CORRUPTED;
386 }
387
388 mSignalledError = false;
389 mSignalledOutputEos = false;
390
391 return C2_OK;
392}
393
394static int GetCPUCoreCount() {
395 int cpuCoreCount = 1;
396#if defined(_SC_NPROCESSORS_ONLN)
397 cpuCoreCount = sysconf(_SC_NPROCESSORS_ONLN);
398#else
399 // _SC_NPROC_ONLN must be defined...
400 cpuCoreCount = sysconf(_SC_NPROC_ONLN);
401#endif
402 CHECK(cpuCoreCount >= 1);
403 ALOGV("Number of CPU cores: %d", cpuCoreCount);
404 return cpuCoreCount;
405}
406
407bool C2SoftGav1Dec::initDecoder() {
408 mSignalledError = false;
409 mSignalledOutputEos = false;
410 mCodecCtx.reset(new libgav1::Decoder());
411
412 if (mCodecCtx == nullptr) {
413 ALOGE("mCodecCtx is null");
414 return false;
415 }
416
417 libgav1::DecoderSettings settings = {};
418 settings.threads = GetCPUCoreCount();
419
Vignesh Venkatasubramanian61ba2cf2019-06-24 10:04:00 -0700420 ALOGV("Using libgav1 AV1 software decoder.");
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700421 Libgav1StatusCode status = mCodecCtx->Init(&settings);
422 if (status != kLibgav1StatusOk) {
423 ALOGE("av1 decoder failed to initialize. status: %d.", status);
424 return false;
425 }
426
427 return true;
428}
429
430void C2SoftGav1Dec::destroyDecoder() { mCodecCtx = nullptr; }
431
432void fillEmptyWork(const std::unique_ptr<C2Work> &work) {
433 uint32_t flags = 0;
434 if (work->input.flags & C2FrameData::FLAG_END_OF_STREAM) {
435 flags |= C2FrameData::FLAG_END_OF_STREAM;
436 ALOGV("signalling eos");
437 }
438 work->worklets.front()->output.flags = (C2FrameData::flags_t)flags;
439 work->worklets.front()->output.buffers.clear();
440 work->worklets.front()->output.ordinal = work->input.ordinal;
441 work->workletsProcessed = 1u;
442}
443
444void C2SoftGav1Dec::finishWork(uint64_t index,
445 const std::unique_ptr<C2Work> &work,
446 const std::shared_ptr<C2GraphicBlock> &block) {
447 std::shared_ptr<C2Buffer> buffer =
448 createGraphicBuffer(block, C2Rect(mWidth, mHeight));
Neelkamal Semwal678a2b82021-09-01 17:07:30 +0530449 {
450 IntfImpl::Lock lock = mIntf->lock();
451 buffer->setInfo(mIntf->getColorAspects_l());
452 }
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700453 auto fillWork = [buffer, index](const std::unique_ptr<C2Work> &work) {
454 uint32_t flags = 0;
455 if ((work->input.flags & C2FrameData::FLAG_END_OF_STREAM) &&
456 (c2_cntr64_t(index) == work->input.ordinal.frameIndex)) {
457 flags |= C2FrameData::FLAG_END_OF_STREAM;
458 ALOGV("signalling eos");
459 }
460 work->worklets.front()->output.flags = (C2FrameData::flags_t)flags;
461 work->worklets.front()->output.buffers.clear();
462 work->worklets.front()->output.buffers.push_back(buffer);
463 work->worklets.front()->output.ordinal = work->input.ordinal;
464 work->workletsProcessed = 1u;
465 };
466 if (work && c2_cntr64_t(index) == work->input.ordinal.frameIndex) {
467 fillWork(work);
468 } else {
469 finish(index, fillWork);
470 }
471}
472
473void C2SoftGav1Dec::process(const std::unique_ptr<C2Work> &work,
474 const std::shared_ptr<C2BlockPool> &pool) {
475 work->result = C2_OK;
476 work->workletsProcessed = 0u;
477 work->worklets.front()->output.configUpdate.clear();
478 work->worklets.front()->output.flags = work->input.flags;
479 if (mSignalledError || mSignalledOutputEos) {
480 work->result = C2_BAD_VALUE;
481 return;
482 }
483
484 size_t inOffset = 0u;
485 size_t inSize = 0u;
486 C2ReadView rView = mDummyReadView;
487 if (!work->input.buffers.empty()) {
488 rView = work->input.buffers[0]->data().linearBlocks().front().map().get();
489 inSize = rView.capacity();
490 if (inSize && rView.error()) {
491 ALOGE("read view map failed %d", rView.error());
492 work->result = C2_CORRUPTED;
493 return;
494 }
495 }
496
497 bool codecConfig =
498 ((work->input.flags & C2FrameData::FLAG_CODEC_CONFIG) != 0);
499 bool eos = ((work->input.flags & C2FrameData::FLAG_END_OF_STREAM) != 0);
500
501 ALOGV("in buffer attr. size %zu timestamp %d frameindex %d, flags %x", inSize,
502 (int)work->input.ordinal.timestamp.peeku(),
503 (int)work->input.ordinal.frameIndex.peeku(), work->input.flags);
504
505 if (codecConfig) {
506 fillEmptyWork(work);
507 return;
508 }
509
510 int64_t frameIndex = work->input.ordinal.frameIndex.peekll();
511 if (inSize) {
512 uint8_t *bitstream = const_cast<uint8_t *>(rView.data() + inOffset);
513 int32_t decodeTime = 0;
514 int32_t delay = 0;
515
516 GETTIME(&mTimeStart, nullptr);
517 TIME_DIFF(mTimeEnd, mTimeStart, delay);
518
519 const Libgav1StatusCode status =
James Zernb7aee6e2020-06-26 13:49:53 -0700520 mCodecCtx->EnqueueFrame(bitstream, inSize, frameIndex,
521 /*buffer_private_data=*/nullptr);
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700522
523 GETTIME(&mTimeEnd, nullptr);
524 TIME_DIFF(mTimeStart, mTimeEnd, decodeTime);
525 ALOGV("decodeTime=%4d delay=%4d\n", decodeTime, delay);
526
527 if (status != kLibgav1StatusOk) {
528 ALOGE("av1 decoder failed to decode frame. status: %d.", status);
529 work->result = C2_CORRUPTED;
530 work->workletsProcessed = 1u;
531 mSignalledError = true;
532 return;
533 }
534
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700535 }
536
537 (void)outputBuffer(pool, work);
538
539 if (eos) {
540 drainInternal(DRAIN_COMPONENT_WITH_EOS, pool, work);
541 mSignalledOutputEos = true;
542 } else if (!inSize) {
543 fillEmptyWork(work);
544 }
545}
546
ming.zhouac19c3d2019-10-11 11:14:07 +0800547static void copyOutputBufferToYV12Frame(uint8_t *dstY, uint8_t *dstU, uint8_t *dstV,
548 const uint8_t *srcY, const uint8_t *srcU, const uint8_t *srcV,
549 size_t srcYStride, size_t srcUStride, size_t srcVStride,
550 size_t dstYStride, size_t dstUVStride,
Vignesh Venkatasubramanianbfd9a212021-02-04 12:39:06 -0800551 uint32_t width, uint32_t height,
552 bool isMonochrome) {
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700553
554 for (size_t i = 0; i < height; ++i) {
ming.zhouac19c3d2019-10-11 11:14:07 +0800555 memcpy(dstY, srcY, width);
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700556 srcY += srcYStride;
ming.zhouac19c3d2019-10-11 11:14:07 +0800557 dstY += dstYStride;
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700558 }
559
Vignesh Venkatasubramanianbfd9a212021-02-04 12:39:06 -0800560 if (isMonochrome) {
561 // Fill with neutral U/V values.
562 for (size_t i = 0; i < height / 2; ++i) {
563 memset(dstV, NEUTRAL_UV_VALUE, width / 2);
564 memset(dstU, NEUTRAL_UV_VALUE, width / 2);
565 dstV += dstUVStride;
566 dstU += dstUVStride;
567 }
568 return;
569 }
570
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700571 for (size_t i = 0; i < height / 2; ++i) {
ming.zhouac19c3d2019-10-11 11:14:07 +0800572 memcpy(dstV, srcV, width / 2);
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700573 srcV += srcVStride;
ming.zhouac19c3d2019-10-11 11:14:07 +0800574 dstV += dstUVStride;
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700575 }
576
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700577 for (size_t i = 0; i < height / 2; ++i) {
ming.zhouac19c3d2019-10-11 11:14:07 +0800578 memcpy(dstU, srcU, width / 2);
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700579 srcU += srcUStride;
ming.zhouac19c3d2019-10-11 11:14:07 +0800580 dstU += dstUVStride;
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700581 }
582}
583
584static void convertYUV420Planar16ToY410(uint32_t *dst, const uint16_t *srcY,
585 const uint16_t *srcU,
586 const uint16_t *srcV, size_t srcYStride,
587 size_t srcUStride, size_t srcVStride,
588 size_t dstStride, size_t width,
589 size_t height) {
590 // Converting two lines at a time, slightly faster
591 for (size_t y = 0; y < height; y += 2) {
592 uint32_t *dstTop = (uint32_t *)dst;
593 uint32_t *dstBot = (uint32_t *)(dst + dstStride);
594 uint16_t *ySrcTop = (uint16_t *)srcY;
595 uint16_t *ySrcBot = (uint16_t *)(srcY + srcYStride);
596 uint16_t *uSrc = (uint16_t *)srcU;
597 uint16_t *vSrc = (uint16_t *)srcV;
598
599 uint32_t u01, v01, y01, y23, y45, y67, uv0, uv1;
600 size_t x = 0;
601 for (; x < width - 3; x += 4) {
602 u01 = *((uint32_t *)uSrc);
603 uSrc += 2;
604 v01 = *((uint32_t *)vSrc);
605 vSrc += 2;
606
607 y01 = *((uint32_t *)ySrcTop);
608 ySrcTop += 2;
609 y23 = *((uint32_t *)ySrcTop);
610 ySrcTop += 2;
611 y45 = *((uint32_t *)ySrcBot);
612 ySrcBot += 2;
613 y67 = *((uint32_t *)ySrcBot);
614 ySrcBot += 2;
615
616 uv0 = (u01 & 0x3FF) | ((v01 & 0x3FF) << 20);
617 uv1 = (u01 >> 16) | ((v01 >> 16) << 20);
618
619 *dstTop++ = 3 << 30 | ((y01 & 0x3FF) << 10) | uv0;
620 *dstTop++ = 3 << 30 | ((y01 >> 16) << 10) | uv0;
621 *dstTop++ = 3 << 30 | ((y23 & 0x3FF) << 10) | uv1;
622 *dstTop++ = 3 << 30 | ((y23 >> 16) << 10) | uv1;
623
624 *dstBot++ = 3 << 30 | ((y45 & 0x3FF) << 10) | uv0;
625 *dstBot++ = 3 << 30 | ((y45 >> 16) << 10) | uv0;
626 *dstBot++ = 3 << 30 | ((y67 & 0x3FF) << 10) | uv1;
627 *dstBot++ = 3 << 30 | ((y67 >> 16) << 10) | uv1;
628 }
629
630 // There should be at most 2 more pixels to process. Note that we don't
631 // need to consider odd case as the buffer is always aligned to even.
632 if (x < width) {
633 u01 = *uSrc;
634 v01 = *vSrc;
635 y01 = *((uint32_t *)ySrcTop);
636 y45 = *((uint32_t *)ySrcBot);
637 uv0 = (u01 & 0x3FF) | ((v01 & 0x3FF) << 20);
638 *dstTop++ = ((y01 & 0x3FF) << 10) | uv0;
639 *dstTop++ = ((y01 >> 16) << 10) | uv0;
640 *dstBot++ = ((y45 & 0x3FF) << 10) | uv0;
641 *dstBot++ = ((y45 >> 16) << 10) | uv0;
642 }
643
644 srcY += srcYStride * 2;
645 srcU += srcUStride;
646 srcV += srcVStride;
647 dst += dstStride * 2;
648 }
649}
650
651static void convertYUV420Planar16ToYUV420Planar(
ming.zhouac19c3d2019-10-11 11:14:07 +0800652 uint8_t *dstY, uint8_t *dstU, uint8_t *dstV,
653 const uint16_t *srcY, const uint16_t *srcU, const uint16_t *srcV,
654 size_t srcYStride, size_t srcUStride, size_t srcVStride,
655 size_t dstYStride, size_t dstUVStride,
Vignesh Venkatasubramanianbfd9a212021-02-04 12:39:06 -0800656 size_t width, size_t height, bool isMonochrome) {
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700657
658 for (size_t y = 0; y < height; ++y) {
659 for (size_t x = 0; x < width; ++x) {
660 dstY[x] = (uint8_t)(srcY[x] >> 2);
661 }
662
663 srcY += srcYStride;
ming.zhouac19c3d2019-10-11 11:14:07 +0800664 dstY += dstYStride;
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700665 }
666
Vignesh Venkatasubramanianbfd9a212021-02-04 12:39:06 -0800667 if (isMonochrome) {
668 // Fill with neutral U/V values.
669 for (size_t y = 0; y < (height + 1) / 2; ++y) {
670 memset(dstV, NEUTRAL_UV_VALUE, (width + 1) / 2);
671 memset(dstU, NEUTRAL_UV_VALUE, (width + 1) / 2);
672 dstV += dstUVStride;
673 dstU += dstUVStride;
674 }
675 return;
676 }
677
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700678 for (size_t y = 0; y < (height + 1) / 2; ++y) {
679 for (size_t x = 0; x < (width + 1) / 2; ++x) {
680 dstU[x] = (uint8_t)(srcU[x] >> 2);
681 dstV[x] = (uint8_t)(srcV[x] >> 2);
682 }
683
684 srcU += srcUStride;
685 srcV += srcVStride;
686 dstU += dstUVStride;
687 dstV += dstUVStride;
688 }
689}
690
Neelkamal Semwal678a2b82021-09-01 17:07:30 +0530691void C2SoftGav1Dec::getVuiParams(const libgav1::DecoderBuffer *buffer) {
692 VuiColorAspects vuiColorAspects;
693 vuiColorAspects.primaries = buffer->color_primary;
694 vuiColorAspects.transfer = buffer->transfer_characteristics;
695 vuiColorAspects.coeffs = buffer->matrix_coefficients;
696 vuiColorAspects.fullRange = buffer->color_range;
697
698 // convert vui aspects to C2 values if changed
699 if (!(vuiColorAspects == mBitstreamColorAspects)) {
700 mBitstreamColorAspects = vuiColorAspects;
701 ColorAspects sfAspects;
702 C2StreamColorAspectsInfo::input codedAspects = { 0u };
703 ColorUtils::convertIsoColorAspectsToCodecAspects(
704 vuiColorAspects.primaries, vuiColorAspects.transfer, vuiColorAspects.coeffs,
705 vuiColorAspects.fullRange, sfAspects);
706 if (!C2Mapper::map(sfAspects.mPrimaries, &codedAspects.primaries)) {
707 codedAspects.primaries = C2Color::PRIMARIES_UNSPECIFIED;
708 }
709 if (!C2Mapper::map(sfAspects.mRange, &codedAspects.range)) {
710 codedAspects.range = C2Color::RANGE_UNSPECIFIED;
711 }
712 if (!C2Mapper::map(sfAspects.mMatrixCoeffs, &codedAspects.matrix)) {
713 codedAspects.matrix = C2Color::MATRIX_UNSPECIFIED;
714 }
715 if (!C2Mapper::map(sfAspects.mTransfer, &codedAspects.transfer)) {
716 codedAspects.transfer = C2Color::TRANSFER_UNSPECIFIED;
717 }
718 std::vector<std::unique_ptr<C2SettingResult>> failures;
719 mIntf->config({&codedAspects}, C2_MAY_BLOCK, &failures);
720 }
721}
722
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700723bool C2SoftGav1Dec::outputBuffer(const std::shared_ptr<C2BlockPool> &pool,
724 const std::unique_ptr<C2Work> &work) {
725 if (!(work && pool)) return false;
726
727 const libgav1::DecoderBuffer *buffer;
728 const Libgav1StatusCode status = mCodecCtx->DequeueFrame(&buffer);
729
James Zernb7aee6e2020-06-26 13:49:53 -0700730 if (status != kLibgav1StatusOk && status != kLibgav1StatusNothingToDequeue) {
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700731 ALOGE("av1 decoder DequeueFrame failed. status: %d.", status);
732 return false;
733 }
734
James Zernb7aee6e2020-06-26 13:49:53 -0700735 // |buffer| can be NULL if status was equal to kLibgav1StatusOk or
736 // kLibgav1StatusNothingToDequeue. This is not an error. This could mean one
737 // of two things:
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700738 // - The EnqueueFrame() call was either a flush (called with nullptr).
739 // - The enqueued frame did not have any displayable frames.
740 if (!buffer) {
741 return false;
742 }
743
744 const int width = buffer->displayed_width[0];
745 const int height = buffer->displayed_height[0];
746 if (width != mWidth || height != mHeight) {
747 mWidth = width;
748 mHeight = height;
749
750 C2StreamPictureSizeInfo::output size(0u, mWidth, mHeight);
751 std::vector<std::unique_ptr<C2SettingResult>> failures;
752 c2_status_t err = mIntf->config({&size}, C2_MAY_BLOCK, &failures);
753 if (err == C2_OK) {
754 work->worklets.front()->output.configUpdate.push_back(
755 C2Param::Copy(size));
756 } else {
757 ALOGE("Config update size failed");
758 mSignalledError = true;
759 work->result = C2_CORRUPTED;
760 work->workletsProcessed = 1u;
761 return false;
762 }
763 }
764
Neelkamal Semwal678a2b82021-09-01 17:07:30 +0530765 getVuiParams(buffer);
James Zerna8236b42021-06-29 21:38:12 +0000766 if (!(buffer->image_format == libgav1::kImageFormatYuv420 ||
767 buffer->image_format == libgav1::kImageFormatMonochrome400)) {
768 ALOGE("image_format %d not supported", buffer->image_format);
769 mSignalledError = true;
770 work->workletsProcessed = 1u;
771 work->result = C2_CORRUPTED;
772 return false;
773 }
Vignesh Venkatasubramanianbfd9a212021-02-04 12:39:06 -0800774 const bool isMonochrome =
775 buffer->image_format == libgav1::kImageFormatMonochrome400;
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700776
777 std::shared_ptr<C2GraphicBlock> block;
778 uint32_t format = HAL_PIXEL_FORMAT_YV12;
779 if (buffer->bitdepth == 10) {
780 IntfImpl::Lock lock = mIntf->lock();
Neelkamal Semwal678a2b82021-09-01 17:07:30 +0530781 std::shared_ptr<C2StreamColorAspectsInfo::output> codedColorAspects =
782 mIntf->getColorAspects_l();
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700783
Neelkamal Semwal678a2b82021-09-01 17:07:30 +0530784 if (codedColorAspects->primaries == C2Color::PRIMARIES_BT2020 &&
785 codedColorAspects->matrix == C2Color::MATRIX_BT2020 &&
786 codedColorAspects->transfer == C2Color::TRANSFER_ST2084) {
Vignesh Venkatasubramanianbfd9a212021-02-04 12:39:06 -0800787 if (buffer->image_format != libgav1::kImageFormatYuv420) {
788 ALOGE("Only YUV420 output is supported when targeting RGBA_1010102");
789 mSignalledError = true;
790 work->result = C2_OMITTED;
791 work->workletsProcessed = 1u;
792 return false;
793 }
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700794 format = HAL_PIXEL_FORMAT_RGBA_1010102;
795 }
796 }
797 C2MemoryUsage usage = {C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE};
798
799 c2_status_t err = pool->fetchGraphicBlock(align(mWidth, 16), mHeight, format,
800 usage, &block);
801
802 if (err != C2_OK) {
803 ALOGE("fetchGraphicBlock for Output failed with status %d", err);
804 work->result = err;
805 return false;
806 }
807
808 C2GraphicView wView = block->map().get();
809
810 if (wView.error()) {
811 ALOGE("graphic view map failed %d", wView.error());
812 work->result = C2_CORRUPTED;
813 return false;
814 }
815
816 ALOGV("provided (%dx%d) required (%dx%d), out frameindex %d", block->width(),
817 block->height(), mWidth, mHeight, (int)buffer->user_private_data);
818
ming.zhouac19c3d2019-10-11 11:14:07 +0800819 uint8_t *dstY = const_cast<uint8_t *>(wView.data()[C2PlanarLayout::PLANE_Y]);
820 uint8_t *dstU = const_cast<uint8_t *>(wView.data()[C2PlanarLayout::PLANE_U]);
821 uint8_t *dstV = const_cast<uint8_t *>(wView.data()[C2PlanarLayout::PLANE_V]);
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700822 size_t srcYStride = buffer->stride[0];
823 size_t srcUStride = buffer->stride[1];
824 size_t srcVStride = buffer->stride[2];
825
ming.zhouac19c3d2019-10-11 11:14:07 +0800826 C2PlanarLayout layout = wView.layout();
827 size_t dstYStride = layout.planes[C2PlanarLayout::PLANE_Y].rowInc;
828 size_t dstUVStride = layout.planes[C2PlanarLayout::PLANE_U].rowInc;
829
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700830 if (buffer->bitdepth == 10) {
831 const uint16_t *srcY = (const uint16_t *)buffer->plane[0];
832 const uint16_t *srcU = (const uint16_t *)buffer->plane[1];
833 const uint16_t *srcV = (const uint16_t *)buffer->plane[2];
834
835 if (format == HAL_PIXEL_FORMAT_RGBA_1010102) {
836 convertYUV420Planar16ToY410(
ming.zhouac19c3d2019-10-11 11:14:07 +0800837 (uint32_t *)dstY, srcY, srcU, srcV, srcYStride / 2, srcUStride / 2,
James Zern8dfb3f22020-08-07 18:49:51 -0700838 srcVStride / 2, dstYStride / sizeof(uint32_t), mWidth, mHeight);
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700839 } else {
Vignesh Venkatasubramanianbfd9a212021-02-04 12:39:06 -0800840 convertYUV420Planar16ToYUV420Planar(
841 dstY, dstU, dstV, srcY, srcU, srcV, srcYStride / 2, srcUStride / 2,
842 srcVStride / 2, dstYStride, dstUVStride, mWidth, mHeight,
843 isMonochrome);
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700844 }
845 } else {
846 const uint8_t *srcY = (const uint8_t *)buffer->plane[0];
847 const uint8_t *srcU = (const uint8_t *)buffer->plane[1];
848 const uint8_t *srcV = (const uint8_t *)buffer->plane[2];
Vignesh Venkatasubramanianbfd9a212021-02-04 12:39:06 -0800849 copyOutputBufferToYV12Frame(
850 dstY, dstU, dstV, srcY, srcU, srcV, srcYStride, srcUStride, srcVStride,
851 dstYStride, dstUVStride, mWidth, mHeight, isMonochrome);
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700852 }
853 finishWork(buffer->user_private_data, work, std::move(block));
854 block = nullptr;
855 return true;
856}
857
858c2_status_t C2SoftGav1Dec::drainInternal(
859 uint32_t drainMode, const std::shared_ptr<C2BlockPool> &pool,
860 const std::unique_ptr<C2Work> &work) {
861 if (drainMode == NO_DRAIN) {
862 ALOGW("drain with NO_DRAIN: no-op");
863 return C2_OK;
864 }
865 if (drainMode == DRAIN_CHAIN) {
866 ALOGW("DRAIN_CHAIN not supported");
867 return C2_OMITTED;
868 }
869
James Zernb7aee6e2020-06-26 13:49:53 -0700870 const Libgav1StatusCode status = mCodecCtx->SignalEOS();
Vignesh Venkatasubramanian0f3e7422019-06-17 16:21:36 -0700871 if (status != kLibgav1StatusOk) {
872 ALOGE("Failed to flush av1 decoder. status: %d.", status);
873 return C2_CORRUPTED;
874 }
875
876 while (outputBuffer(pool, work)) {
877 }
878
879 if (drainMode == DRAIN_COMPONENT_WITH_EOS && work &&
880 work->workletsProcessed == 0u) {
881 fillEmptyWork(work);
882 }
883
884 return C2_OK;
885}
886
887c2_status_t C2SoftGav1Dec::drain(uint32_t drainMode,
888 const std::shared_ptr<C2BlockPool> &pool) {
889 return drainInternal(drainMode, pool, nullptr);
890}
891
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -0700892class C2SoftGav1Factory : public C2ComponentFactory {
893 public:
894 C2SoftGav1Factory()
895 : mHelper(std::static_pointer_cast<C2ReflectorHelper>(
896 GetCodec2PlatformComponentStore()->getParamReflector())) {}
897
898 virtual c2_status_t createComponent(
899 c2_node_id_t id, std::shared_ptr<C2Component> *const component,
900 std::function<void(C2Component *)> deleter) override {
901 *component = std::shared_ptr<C2Component>(
902 new C2SoftGav1Dec(COMPONENT_NAME, id,
903 std::make_shared<C2SoftGav1Dec::IntfImpl>(mHelper)),
904 deleter);
905 return C2_OK;
906 }
907
908 virtual c2_status_t createInterface(
909 c2_node_id_t id, std::shared_ptr<C2ComponentInterface> *const interface,
910 std::function<void(C2ComponentInterface *)> deleter) override {
911 *interface = std::shared_ptr<C2ComponentInterface>(
912 new SimpleInterface<C2SoftGav1Dec::IntfImpl>(
913 COMPONENT_NAME, id,
914 std::make_shared<C2SoftGav1Dec::IntfImpl>(mHelper)),
915 deleter);
916 return C2_OK;
917 }
918
919 virtual ~C2SoftGav1Factory() override = default;
920
921 private:
922 std::shared_ptr<C2ReflectorHelper> mHelper;
923};
924
925} // namespace android
926
Cindy Zhouf6c0c3c2020-12-02 10:53:40 -0800927__attribute__((cfi_canonical_jump_table))
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -0700928extern "C" ::C2ComponentFactory *CreateCodec2Factory() {
929 ALOGV("in %s", __func__);
930 return new ::android::C2SoftGav1Factory();
931}
932
Cindy Zhouf6c0c3c2020-12-02 10:53:40 -0800933__attribute__((cfi_canonical_jump_table))
Vignesh Venkatasubramanianb6d383d2019-06-10 15:11:58 -0700934extern "C" void DestroyCodec2Factory(::C2ComponentFactory *factory) {
935 ALOGV("in %s", __func__);
936 delete factory;
937}