blob: 2da9d5b35a0d1e43a8bb9adb3eca57252d2da211 [file] [log] [blame]
Pawin Vongmasa36653902018-11-15 00:10:25 -08001/*
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//#define LOG_NDEBUG 0
18#define LOG_TAG "C2SoftVpxDec"
19#include <log/log.h>
20
Wonsik Kimf61206f2019-05-18 16:52:46 -070021#include <algorithm>
22
Pawin Vongmasa36653902018-11-15 00:10:25 -080023#include <media/stagefright/foundation/AUtils.h>
24#include <media/stagefright/foundation/MediaDefs.h>
25
26#include <C2Debug.h>
27#include <C2PlatformSupport.h>
Harish Mahendrakarf0fa7a22021-12-10 20:36:32 -080028#include <Codec2BufferUtils.h>
Pawin Vongmasa36653902018-11-15 00:10:25 -080029#include <SimpleC2Interface.h>
30
31#include "C2SoftVpxDec.h"
32
33namespace android {
Harish Mahendrakare55c4712019-07-26 12:32:13 -070034constexpr size_t kMinInputBufferSize = 2 * 1024 * 1024;
Pawin Vongmasa36653902018-11-15 00:10:25 -080035#ifdef VP9
36constexpr char COMPONENT_NAME[] = "c2.android.vp9.decoder";
37#else
38constexpr char COMPONENT_NAME[] = "c2.android.vp8.decoder";
39#endif
40
41class C2SoftVpxDec::IntfImpl : public SimpleInterface<void>::BaseParams {
42public:
43 explicit IntfImpl(const std::shared_ptr<C2ReflectorHelper> &helper)
44 : SimpleInterface<void>::BaseParams(
45 helper,
46 COMPONENT_NAME,
47 C2Component::KIND_DECODER,
48 C2Component::DOMAIN_VIDEO,
49#ifdef VP9
50 MEDIA_MIMETYPE_VIDEO_VP9
51#else
52 MEDIA_MIMETYPE_VIDEO_VP8
53#endif
54 ) {
55 noPrivateBuffers(); // TODO: account for our buffers here
56 noInputReferences();
57 noOutputReferences();
58 noInputLatency();
59 noTimeStretch();
60
61 // TODO: output latency and reordering
62
63 addParameter(
64 DefineParam(mAttrib, C2_PARAMKEY_COMPONENT_ATTRIBUTES)
65 .withConstValue(new C2ComponentAttributesSetting(C2Component::ATTRIB_IS_TEMPORAL))
66 .build());
67
68 addParameter(
69 DefineParam(mSize, C2_PARAMKEY_PICTURE_SIZE)
70 .withDefault(new C2StreamPictureSizeInfo::output(0u, 320, 240))
71 .withFields({
72 C2F(mSize, width).inRange(2, 2048, 2),
73 C2F(mSize, height).inRange(2, 2048, 2),
74 })
75 .withSetter(SizeSetter)
76 .build());
77
78#ifdef VP9
79 // TODO: Add C2Config::PROFILE_VP9_2HDR ??
80 addParameter(
81 DefineParam(mProfileLevel, C2_PARAMKEY_PROFILE_LEVEL)
82 .withDefault(new C2StreamProfileLevelInfo::input(0u,
83 C2Config::PROFILE_VP9_0, C2Config::LEVEL_VP9_5))
84 .withFields({
85 C2F(mProfileLevel, profile).oneOf({
86 C2Config::PROFILE_VP9_0,
87 C2Config::PROFILE_VP9_2}),
88 C2F(mProfileLevel, level).oneOf({
89 C2Config::LEVEL_VP9_1,
90 C2Config::LEVEL_VP9_1_1,
91 C2Config::LEVEL_VP9_2,
92 C2Config::LEVEL_VP9_2_1,
93 C2Config::LEVEL_VP9_3,
94 C2Config::LEVEL_VP9_3_1,
95 C2Config::LEVEL_VP9_4,
96 C2Config::LEVEL_VP9_4_1,
97 C2Config::LEVEL_VP9_5,
98 })
99 })
100 .withSetter(ProfileLevelSetter, mSize)
101 .build());
102
Pawin Vongmasa8be93112018-12-11 14:01:42 -0800103 mHdr10PlusInfoInput = C2StreamHdr10PlusInfo::input::AllocShared(0);
104 addParameter(
105 DefineParam(mHdr10PlusInfoInput, C2_PARAMKEY_INPUT_HDR10_PLUS_INFO)
106 .withDefault(mHdr10PlusInfoInput)
107 .withFields({
108 C2F(mHdr10PlusInfoInput, m.value).any(),
109 })
110 .withSetter(Hdr10PlusInfoInputSetter)
111 .build());
112
113 mHdr10PlusInfoOutput = C2StreamHdr10PlusInfo::output::AllocShared(0);
114 addParameter(
115 DefineParam(mHdr10PlusInfoOutput, C2_PARAMKEY_OUTPUT_HDR10_PLUS_INFO)
116 .withDefault(mHdr10PlusInfoOutput)
117 .withFields({
118 C2F(mHdr10PlusInfoOutput, m.value).any(),
119 })
120 .withSetter(Hdr10PlusInfoOutputSetter)
121 .build());
122
Pawin Vongmasa36653902018-11-15 00:10:25 -0800123#if 0
124 // sample BT.2020 static info
125 mHdrStaticInfo = std::make_shared<C2StreamHdrStaticInfo::output>();
126 mHdrStaticInfo->mastering = {
127 .red = { .x = 0.708, .y = 0.292 },
128 .green = { .x = 0.170, .y = 0.797 },
129 .blue = { .x = 0.131, .y = 0.046 },
130 .white = { .x = 0.3127, .y = 0.3290 },
131 .maxLuminance = 1000,
132 .minLuminance = 0.1,
133 };
134 mHdrStaticInfo->maxCll = 1000;
135 mHdrStaticInfo->maxFall = 120;
136
137 mHdrStaticInfo->maxLuminance = 0; // disable static info
138
139 helper->addStructDescriptors<C2MasteringDisplayColorVolumeStruct, C2ColorXyStruct>();
140 addParameter(
141 DefineParam(mHdrStaticInfo, C2_PARAMKEY_HDR_STATIC_INFO)
142 .withDefault(mHdrStaticInfo)
143 .withFields({
144 C2F(mHdrStaticInfo, mastering.red.x).inRange(0, 1),
145 // TODO
146 })
147 .withSetter(HdrStaticInfoSetter)
148 .build());
149#endif
150#else
151 addParameter(
152 DefineParam(mProfileLevel, C2_PARAMKEY_PROFILE_LEVEL)
Harish Mahendrakar22cb9d02021-08-26 16:35:48 -0700153 .withDefault(new C2StreamProfileLevelInfo::input(0u,
154 C2Config::PROFILE_VP8_0, C2Config::LEVEL_UNUSED))
155 .withFields({
156 C2F(mProfileLevel, profile).equalTo(
157 PROFILE_VP8_0
158 ),
159 C2F(mProfileLevel, level).equalTo(
160 LEVEL_UNUSED),
161 })
162 .withSetter(ProfileLevelSetter, mSize)
Pawin Vongmasa36653902018-11-15 00:10:25 -0800163 .build());
164#endif
165
166 addParameter(
167 DefineParam(mMaxSize, C2_PARAMKEY_MAX_PICTURE_SIZE)
168 .withDefault(new C2StreamMaxPictureSizeTuning::output(0u, 320, 240))
169 .withFields({
170 C2F(mSize, width).inRange(2, 2048, 2),
171 C2F(mSize, height).inRange(2, 2048, 2),
172 })
173 .withSetter(MaxPictureSizeSetter, mSize)
174 .build());
175
176 addParameter(
177 DefineParam(mMaxInputSize, C2_PARAMKEY_INPUT_MAX_BUFFER_SIZE)
Harish Mahendrakare55c4712019-07-26 12:32:13 -0700178 .withDefault(new C2StreamMaxBufferSizeInfo::input(0u, kMinInputBufferSize))
Pawin Vongmasa36653902018-11-15 00:10:25 -0800179 .withFields({
180 C2F(mMaxInputSize, value).any(),
181 })
182 .calculatedAs(MaxInputSizeSetter, mMaxSize)
183 .build());
184
185 C2ChromaOffsetStruct locations[1] = { C2ChromaOffsetStruct::ITU_YUV_420_0() };
186 std::shared_ptr<C2StreamColorInfo::output> defaultColorInfo =
187 C2StreamColorInfo::output::AllocShared(
188 1u, 0u, 8u /* bitDepth */, C2Color::YUV_420);
189 memcpy(defaultColorInfo->m.locations, locations, sizeof(locations));
190
191 defaultColorInfo =
192 C2StreamColorInfo::output::AllocShared(
193 { C2ChromaOffsetStruct::ITU_YUV_420_0() },
194 0u, 8u /* bitDepth */, C2Color::YUV_420);
195 helper->addStructDescriptors<C2ChromaOffsetStruct>();
196
197 addParameter(
198 DefineParam(mColorInfo, C2_PARAMKEY_CODED_COLOR_INFO)
199 .withConstValue(defaultColorInfo)
200 .build());
201
Harish Mahendrakared4e0cd2018-10-11 18:11:49 -0700202 addParameter(
203 DefineParam(mDefaultColorAspects, C2_PARAMKEY_DEFAULT_COLOR_ASPECTS)
204 .withDefault(new C2StreamColorAspectsTuning::output(
205 0u, C2Color::RANGE_UNSPECIFIED, C2Color::PRIMARIES_UNSPECIFIED,
206 C2Color::TRANSFER_UNSPECIFIED, C2Color::MATRIX_UNSPECIFIED))
207 .withFields({
208 C2F(mDefaultColorAspects, range).inRange(
209 C2Color::RANGE_UNSPECIFIED, C2Color::RANGE_OTHER),
210 C2F(mDefaultColorAspects, primaries).inRange(
211 C2Color::PRIMARIES_UNSPECIFIED, C2Color::PRIMARIES_OTHER),
212 C2F(mDefaultColorAspects, transfer).inRange(
213 C2Color::TRANSFER_UNSPECIFIED, C2Color::TRANSFER_OTHER),
214 C2F(mDefaultColorAspects, matrix).inRange(
215 C2Color::MATRIX_UNSPECIFIED, C2Color::MATRIX_OTHER)
216 })
217 .withSetter(DefaultColorAspectsSetter)
218 .build());
219
Pawin Vongmasa36653902018-11-15 00:10:25 -0800220 // TODO: support more formats?
221 addParameter(
222 DefineParam(mPixelFormat, C2_PARAMKEY_PIXEL_FORMAT)
223 .withConstValue(new C2StreamPixelFormatInfo::output(
224 0u, HAL_PIXEL_FORMAT_YCBCR_420_888))
225 .build());
226 }
227
228 static C2R SizeSetter(bool mayBlock, const C2P<C2StreamPictureSizeInfo::output> &oldMe,
Lajos Molnar3bb81cd2019-02-20 15:10:30 -0800229 C2P<C2StreamPictureSizeInfo::output> &me) {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800230 (void)mayBlock;
231 C2R res = C2R::Ok();
232 if (!me.F(me.v.width).supportsAtAll(me.v.width)) {
233 res = res.plus(C2SettingResultBuilder::BadValue(me.F(me.v.width)));
234 me.set().width = oldMe.v.width;
235 }
236 if (!me.F(me.v.height).supportsAtAll(me.v.height)) {
237 res = res.plus(C2SettingResultBuilder::BadValue(me.F(me.v.height)));
238 me.set().height = oldMe.v.height;
239 }
240 return res;
241 }
242
243 static C2R MaxPictureSizeSetter(bool mayBlock, C2P<C2StreamMaxPictureSizeTuning::output> &me,
244 const C2P<C2StreamPictureSizeInfo::output> &size) {
245 (void)mayBlock;
246 // TODO: get max width/height from the size's field helpers vs. hardcoding
247 me.set().width = c2_min(c2_max(me.v.width, size.v.width), 2048u);
248 me.set().height = c2_min(c2_max(me.v.height, size.v.height), 2048u);
249 return C2R::Ok();
250 }
251
252 static C2R MaxInputSizeSetter(bool mayBlock, C2P<C2StreamMaxBufferSizeInfo::input> &me,
253 const C2P<C2StreamMaxPictureSizeTuning::output> &maxSize) {
254 (void)mayBlock;
255 // assume compression ratio of 2
Harish Mahendrakare55c4712019-07-26 12:32:13 -0700256 me.set().value = c2_max((((maxSize.v.width + 63) / 64)
257 * ((maxSize.v.height + 63) / 64) * 3072), kMinInputBufferSize);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800258 return C2R::Ok();
259 }
260
Harish Mahendrakared4e0cd2018-10-11 18:11:49 -0700261 static C2R DefaultColorAspectsSetter(bool mayBlock, C2P<C2StreamColorAspectsTuning::output> &me) {
262 (void)mayBlock;
263 if (me.v.range > C2Color::RANGE_OTHER) {
264 me.set().range = C2Color::RANGE_OTHER;
265 }
266 if (me.v.primaries > C2Color::PRIMARIES_OTHER) {
267 me.set().primaries = C2Color::PRIMARIES_OTHER;
268 }
269 if (me.v.transfer > C2Color::TRANSFER_OTHER) {
270 me.set().transfer = C2Color::TRANSFER_OTHER;
271 }
272 if (me.v.matrix > C2Color::MATRIX_OTHER) {
273 me.set().matrix = C2Color::MATRIX_OTHER;
274 }
275 return C2R::Ok();
276 }
Pawin Vongmasa36653902018-11-15 00:10:25 -0800277
278 static C2R ProfileLevelSetter(bool mayBlock, C2P<C2StreamProfileLevelInfo::input> &me,
279 const C2P<C2StreamPictureSizeInfo::output> &size) {
280 (void)mayBlock;
281 (void)size;
282 (void)me; // TODO: validate
283 return C2R::Ok();
284 }
Harish Mahendrakared4e0cd2018-10-11 18:11:49 -0700285 std::shared_ptr<C2StreamColorAspectsTuning::output> getDefaultColorAspects_l() {
286 return mDefaultColorAspects;
287 }
Pawin Vongmasa36653902018-11-15 00:10:25 -0800288
Pawin Vongmasa8be93112018-12-11 14:01:42 -0800289 static C2R Hdr10PlusInfoInputSetter(bool mayBlock, C2P<C2StreamHdr10PlusInfo::input> &me) {
290 (void)mayBlock;
291 (void)me; // TODO: validate
292 return C2R::Ok();
293 }
294
295 static C2R Hdr10PlusInfoOutputSetter(bool mayBlock, C2P<C2StreamHdr10PlusInfo::output> &me) {
296 (void)mayBlock;
297 (void)me; // TODO: validate
298 return C2R::Ok();
299 }
300
Pawin Vongmasa36653902018-11-15 00:10:25 -0800301private:
302 std::shared_ptr<C2StreamProfileLevelInfo::input> mProfileLevel;
303 std::shared_ptr<C2StreamPictureSizeInfo::output> mSize;
304 std::shared_ptr<C2StreamMaxPictureSizeTuning::output> mMaxSize;
305 std::shared_ptr<C2StreamMaxBufferSizeInfo::input> mMaxInputSize;
306 std::shared_ptr<C2StreamColorInfo::output> mColorInfo;
307 std::shared_ptr<C2StreamPixelFormatInfo::output> mPixelFormat;
Harish Mahendrakared4e0cd2018-10-11 18:11:49 -0700308 std::shared_ptr<C2StreamColorAspectsTuning::output> mDefaultColorAspects;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800309#ifdef VP9
310#if 0
311 std::shared_ptr<C2StreamHdrStaticInfo::output> mHdrStaticInfo;
312#endif
Pawin Vongmasa8be93112018-12-11 14:01:42 -0800313 std::shared_ptr<C2StreamHdr10PlusInfo::input> mHdr10PlusInfoInput;
314 std::shared_ptr<C2StreamHdr10PlusInfo::output> mHdr10PlusInfoOutput;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800315#endif
316};
317
Wonsik Kimf61206f2019-05-18 16:52:46 -0700318C2SoftVpxDec::ConverterThread::ConverterThread(
319 const std::shared_ptr<Mutexed<ConversionQueue>> &queue)
320 : Thread(false), mQueue(queue) {}
321
322bool C2SoftVpxDec::ConverterThread::threadLoop() {
323 Mutexed<ConversionQueue>::Locked queue(*mQueue);
324 if (queue->entries.empty()) {
325 queue.waitForCondition(queue->cond);
326 if (queue->entries.empty()) {
327 return true;
328 }
329 }
330 std::function<void()> convert = queue->entries.front();
331 queue->entries.pop_front();
332 if (!queue->entries.empty()) {
333 queue->cond.signal();
334 }
335 queue.unlock();
336
337 convert();
338
339 queue.lock();
340 if (--queue->numPending == 0u) {
341 queue->cond.broadcast();
342 }
343 return true;
344}
345
Pawin Vongmasa36653902018-11-15 00:10:25 -0800346C2SoftVpxDec::C2SoftVpxDec(
347 const char *name,
348 c2_node_id_t id,
349 const std::shared_ptr<IntfImpl> &intfImpl)
350 : SimpleC2Component(std::make_shared<SimpleInterface<IntfImpl>>(name, id, intfImpl)),
351 mIntf(intfImpl),
Wonsik Kimf61206f2019-05-18 16:52:46 -0700352 mCodecCtx(nullptr),
353 mCoreCount(1),
354 mQueue(new Mutexed<ConversionQueue>) {
Harish Mahendrakarf0fa7a22021-12-10 20:36:32 -0800355 mIsFormatR10G10B10A2Supported = IsFormatR10G10B10A2SupportedForLegacyRendering();
Pawin Vongmasa36653902018-11-15 00:10:25 -0800356}
357
358C2SoftVpxDec::~C2SoftVpxDec() {
359 onRelease();
360}
361
362c2_status_t C2SoftVpxDec::onInit() {
363 status_t err = initDecoder();
364 return err == OK ? C2_OK : C2_CORRUPTED;
365}
366
367c2_status_t C2SoftVpxDec::onStop() {
368 mSignalledError = false;
369 mSignalledOutputEos = false;
370
371 return C2_OK;
372}
373
374void C2SoftVpxDec::onReset() {
375 (void)onStop();
376 c2_status_t err = onFlush_sm();
377 if (err != C2_OK)
378 {
379 ALOGW("Failed to flush decoder. Try to hard reset decoder");
380 destroyDecoder();
381 (void)initDecoder();
382 }
383}
384
385void C2SoftVpxDec::onRelease() {
386 destroyDecoder();
387}
388
389c2_status_t C2SoftVpxDec::onFlush_sm() {
390 if (mFrameParallelMode) {
391 // Flush decoder by passing nullptr data ptr and 0 size.
392 // Ideally, this should never fail.
393 if (vpx_codec_decode(mCodecCtx, nullptr, 0, nullptr, 0)) {
394 ALOGE("Failed to flush on2 decoder.");
395 return C2_CORRUPTED;
396 }
397 }
398
399 // Drop all the decoded frames in decoder.
400 vpx_codec_iter_t iter = nullptr;
401 while (vpx_codec_get_frame(mCodecCtx, &iter)) {
402 }
403
404 mSignalledError = false;
405 mSignalledOutputEos = false;
406 return C2_OK;
407}
408
409static int GetCPUCoreCount() {
410 int cpuCoreCount = 1;
411#if defined(_SC_NPROCESSORS_ONLN)
412 cpuCoreCount = sysconf(_SC_NPROCESSORS_ONLN);
413#else
414 // _SC_NPROC_ONLN must be defined...
415 cpuCoreCount = sysconf(_SC_NPROC_ONLN);
416#endif
417 CHECK(cpuCoreCount >= 1);
418 ALOGV("Number of CPU cores: %d", cpuCoreCount);
419 return cpuCoreCount;
420}
421
422status_t C2SoftVpxDec::initDecoder() {
423#ifdef VP9
424 mMode = MODE_VP9;
425#else
426 mMode = MODE_VP8;
427#endif
428
429 mWidth = 320;
430 mHeight = 240;
431 mFrameParallelMode = false;
432 mSignalledOutputEos = false;
433 mSignalledError = false;
434
435 if (!mCodecCtx) {
436 mCodecCtx = new vpx_codec_ctx_t;
437 }
438 if (!mCodecCtx) {
439 ALOGE("mCodecCtx is null");
440 return NO_MEMORY;
441 }
442
443 vpx_codec_dec_cfg_t cfg;
444 memset(&cfg, 0, sizeof(vpx_codec_dec_cfg_t));
Wonsik Kimf61206f2019-05-18 16:52:46 -0700445 cfg.threads = mCoreCount = GetCPUCoreCount();
Pawin Vongmasa36653902018-11-15 00:10:25 -0800446
447 vpx_codec_flags_t flags;
448 memset(&flags, 0, sizeof(vpx_codec_flags_t));
449 if (mFrameParallelMode) flags |= VPX_CODEC_USE_FRAME_THREADING;
450
451 vpx_codec_err_t vpx_err;
452 if ((vpx_err = vpx_codec_dec_init(
453 mCodecCtx, mMode == MODE_VP8 ? &vpx_codec_vp8_dx_algo : &vpx_codec_vp9_dx_algo,
454 &cfg, flags))) {
455 ALOGE("on2 decoder failed to initialize. (%d)", vpx_err);
456 return UNKNOWN_ERROR;
457 }
458
Wonsik Kimf61206f2019-05-18 16:52:46 -0700459 if (mMode == MODE_VP9) {
460 using namespace std::string_literals;
461 for (int i = 0; i < mCoreCount; ++i) {
462 sp<ConverterThread> thread(new ConverterThread(mQueue));
463 mConverterThreads.push_back(thread);
464 if (thread->run(("vp9conv #"s + std::to_string(i)).c_str(),
465 ANDROID_PRIORITY_AUDIO) != OK) {
466 return UNKNOWN_ERROR;
467 }
468 }
469 }
470
Pawin Vongmasa36653902018-11-15 00:10:25 -0800471 return OK;
472}
473
474status_t C2SoftVpxDec::destroyDecoder() {
475 if (mCodecCtx) {
476 vpx_codec_destroy(mCodecCtx);
477 delete mCodecCtx;
478 mCodecCtx = nullptr;
479 }
Wonsik Kimf61206f2019-05-18 16:52:46 -0700480 bool running = true;
481 for (const sp<ConverterThread> &thread : mConverterThreads) {
482 thread->requestExit();
483 }
484 while (running) {
485 mQueue->lock()->cond.broadcast();
486 running = false;
487 for (const sp<ConverterThread> &thread : mConverterThreads) {
488 if (thread->isRunning()) {
489 running = true;
490 break;
491 }
492 }
493 }
494 mConverterThreads.clear();
Pawin Vongmasa36653902018-11-15 00:10:25 -0800495
496 return OK;
497}
498
499void fillEmptyWork(const std::unique_ptr<C2Work> &work) {
500 uint32_t flags = 0;
501 if (work->input.flags & C2FrameData::FLAG_END_OF_STREAM) {
502 flags |= C2FrameData::FLAG_END_OF_STREAM;
503 ALOGV("signalling eos");
504 }
505 work->worklets.front()->output.flags = (C2FrameData::flags_t)flags;
506 work->worklets.front()->output.buffers.clear();
507 work->worklets.front()->output.ordinal = work->input.ordinal;
508 work->workletsProcessed = 1u;
509}
510
511void C2SoftVpxDec::finishWork(uint64_t index, const std::unique_ptr<C2Work> &work,
512 const std::shared_ptr<C2GraphicBlock> &block) {
513 std::shared_ptr<C2Buffer> buffer = createGraphicBuffer(block,
514 C2Rect(mWidth, mHeight));
Pawin Vongmasa8be93112018-12-11 14:01:42 -0800515 auto fillWork = [buffer, index, intf = this->mIntf](
516 const std::unique_ptr<C2Work> &work) {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800517 uint32_t flags = 0;
518 if ((work->input.flags & C2FrameData::FLAG_END_OF_STREAM) &&
519 (c2_cntr64_t(index) == work->input.ordinal.frameIndex)) {
520 flags |= C2FrameData::FLAG_END_OF_STREAM;
521 ALOGV("signalling eos");
522 }
523 work->worklets.front()->output.flags = (C2FrameData::flags_t)flags;
524 work->worklets.front()->output.buffers.clear();
525 work->worklets.front()->output.buffers.push_back(buffer);
526 work->worklets.front()->output.ordinal = work->input.ordinal;
527 work->workletsProcessed = 1u;
Pawin Vongmasa8be93112018-12-11 14:01:42 -0800528
529 for (const std::unique_ptr<C2Param> &param: work->input.configUpdate) {
530 if (param) {
531 C2StreamHdr10PlusInfo::input *hdr10PlusInfo =
532 C2StreamHdr10PlusInfo::input::From(param.get());
533
534 if (hdr10PlusInfo != nullptr) {
535 std::vector<std::unique_ptr<C2SettingResult>> failures;
536 std::unique_ptr<C2Param> outParam = C2Param::CopyAsStream(
537 *param.get(), true /*output*/, param->stream());
538 c2_status_t err = intf->config(
539 { outParam.get() }, C2_MAY_BLOCK, &failures);
540 if (err == C2_OK) {
541 work->worklets.front()->output.configUpdate.push_back(
542 C2Param::Copy(*outParam.get()));
543 } else {
544 ALOGE("finishWork: Config update size failed");
545 }
546 break;
547 }
548 }
549 }
Pawin Vongmasa36653902018-11-15 00:10:25 -0800550 };
551 if (work && c2_cntr64_t(index) == work->input.ordinal.frameIndex) {
552 fillWork(work);
553 } else {
554 finish(index, fillWork);
555 }
556}
557
558void C2SoftVpxDec::process(
559 const std::unique_ptr<C2Work> &work,
560 const std::shared_ptr<C2BlockPool> &pool) {
561 // Initialize output work
562 work->result = C2_OK;
563 work->workletsProcessed = 0u;
564 work->worklets.front()->output.configUpdate.clear();
565 work->worklets.front()->output.flags = work->input.flags;
566
567 if (mSignalledError || mSignalledOutputEos) {
568 work->result = C2_BAD_VALUE;
569 return;
570 }
571
572 size_t inOffset = 0u;
573 size_t inSize = 0u;
574 C2ReadView rView = mDummyReadView;
575 if (!work->input.buffers.empty()) {
576 rView = work->input.buffers[0]->data().linearBlocks().front().map().get();
577 inSize = rView.capacity();
578 if (inSize && rView.error()) {
579 ALOGE("read view map failed %d", rView.error());
580 work->result = C2_CORRUPTED;
581 return;
582 }
583 }
584
585 bool codecConfig = ((work->input.flags & C2FrameData::FLAG_CODEC_CONFIG) !=0);
586 bool eos = ((work->input.flags & C2FrameData::FLAG_END_OF_STREAM) != 0);
587
588 ALOGV("in buffer attr. size %zu timestamp %d frameindex %d, flags %x",
589 inSize, (int)work->input.ordinal.timestamp.peeku(),
590 (int)work->input.ordinal.frameIndex.peeku(), work->input.flags);
591
592 // Software VP9 Decoder does not need the Codec Specific Data (CSD)
593 // (specified in http://www.webmproject.org/vp9/profiles/). Ignore it if
594 // it was passed.
595 if (codecConfig) {
596 // Ignore CSD buffer for VP9.
597 if (mMode == MODE_VP9) {
598 fillEmptyWork(work);
599 return;
600 } else {
601 // Tolerate the CSD buffer for VP8. This is a workaround
602 // for b/28689536. continue
603 ALOGW("WARNING: Got CSD buffer for VP8. Continue");
604 }
605 }
606
Pawin Vongmasa36653902018-11-15 00:10:25 -0800607 if (inSize) {
608 uint8_t *bitstream = const_cast<uint8_t *>(rView.data() + inOffset);
609 vpx_codec_err_t err = vpx_codec_decode(
Wonsik Kim377eeab2019-11-03 19:05:59 -0800610 mCodecCtx, bitstream, inSize, &work->input.ordinal.frameIndex, 0);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800611 if (err != VPX_CODEC_OK) {
612 ALOGE("on2 decoder failed to decode frame. err: %d", err);
613 mSignalledError = true;
614 work->workletsProcessed = 1u;
615 work->result = C2_CORRUPTED;
616 return;
617 }
618 }
619
Wonsik Kim377eeab2019-11-03 19:05:59 -0800620 status_t err = outputBuffer(pool, work);
621 if (err == NOT_ENOUGH_DATA) {
622 if (inSize > 0) {
623 ALOGV("Maybe non-display frame at %lld.",
624 work->input.ordinal.frameIndex.peekll());
625 // send the work back with empty buffer.
626 inSize = 0;
627 }
628 } else if (err != OK) {
629 ALOGD("Error while getting the output frame out");
630 // work->result would be already filled; do fillEmptyWork() below to
631 // send the work back.
632 inSize = 0;
633 }
Pawin Vongmasa36653902018-11-15 00:10:25 -0800634
635 if (eos) {
636 drainInternal(DRAIN_COMPONENT_WITH_EOS, pool, work);
637 mSignalledOutputEos = true;
638 } else if (!inSize) {
639 fillEmptyWork(work);
640 }
641}
642
Harish Mahendrakardfa3f5a2019-05-02 12:10:24 -0700643static void copyOutputBufferToYuvPlanarFrame(
ming.zhouac19c3d2019-10-11 11:14:07 +0800644 uint8_t *dstY, uint8_t *dstU, uint8_t *dstV,
645 const uint8_t *srcY, const uint8_t *srcU, const uint8_t *srcV,
Pawin Vongmasa36653902018-11-15 00:10:25 -0800646 size_t srcYStride, size_t srcUStride, size_t srcVStride,
Harish Mahendrakardfa3f5a2019-05-02 12:10:24 -0700647 size_t dstYStride, size_t dstUVStride,
Harish Mahendrakared4e0cd2018-10-11 18:11:49 -0700648 uint32_t width, uint32_t height) {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800649
650 for (size_t i = 0; i < height; ++i) {
ming.zhouac19c3d2019-10-11 11:14:07 +0800651 memcpy(dstY, srcY, width);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800652 srcY += srcYStride;
ming.zhouac19c3d2019-10-11 11:14:07 +0800653 dstY += dstYStride;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800654 }
655
Pawin Vongmasa36653902018-11-15 00:10:25 -0800656 for (size_t i = 0; i < height / 2; ++i) {
ming.zhouac19c3d2019-10-11 11:14:07 +0800657 memcpy(dstV, srcV, width / 2);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800658 srcV += srcVStride;
ming.zhouac19c3d2019-10-11 11:14:07 +0800659 dstV += dstUVStride;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800660 }
661
Pawin Vongmasa36653902018-11-15 00:10:25 -0800662 for (size_t i = 0; i < height / 2; ++i) {
ming.zhouac19c3d2019-10-11 11:14:07 +0800663 memcpy(dstU, srcU, width / 2);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800664 srcU += srcUStride;
ming.zhouac19c3d2019-10-11 11:14:07 +0800665 dstU += dstUVStride;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800666 }
ming.zhouac19c3d2019-10-11 11:14:07 +0800667
Pawin Vongmasa36653902018-11-15 00:10:25 -0800668}
669
Harish Mahendrakared4e0cd2018-10-11 18:11:49 -0700670static void convertYUV420Planar16ToY410(uint32_t *dst,
671 const uint16_t *srcY, const uint16_t *srcU, const uint16_t *srcV,
672 size_t srcYStride, size_t srcUStride, size_t srcVStride,
673 size_t dstStride, size_t width, size_t height) {
674
675 // Converting two lines at a time, slightly faster
676 for (size_t y = 0; y < height; y += 2) {
677 uint32_t *dstTop = (uint32_t *) dst;
678 uint32_t *dstBot = (uint32_t *) (dst + dstStride);
679 uint16_t *ySrcTop = (uint16_t*) srcY;
680 uint16_t *ySrcBot = (uint16_t*) (srcY + srcYStride);
681 uint16_t *uSrc = (uint16_t*) srcU;
682 uint16_t *vSrc = (uint16_t*) srcV;
683
684 uint32_t u01, v01, y01, y23, y45, y67, uv0, uv1;
685 size_t x = 0;
686 for (; x < width - 3; x += 4) {
687
688 u01 = *((uint32_t*)uSrc); uSrc += 2;
689 v01 = *((uint32_t*)vSrc); vSrc += 2;
690
691 y01 = *((uint32_t*)ySrcTop); ySrcTop += 2;
692 y23 = *((uint32_t*)ySrcTop); ySrcTop += 2;
693 y45 = *((uint32_t*)ySrcBot); ySrcBot += 2;
694 y67 = *((uint32_t*)ySrcBot); ySrcBot += 2;
695
696 uv0 = (u01 & 0x3FF) | ((v01 & 0x3FF) << 20);
697 uv1 = (u01 >> 16) | ((v01 >> 16) << 20);
698
699 *dstTop++ = 3 << 30 | ((y01 & 0x3FF) << 10) | uv0;
700 *dstTop++ = 3 << 30 | ((y01 >> 16) << 10) | uv0;
701 *dstTop++ = 3 << 30 | ((y23 & 0x3FF) << 10) | uv1;
702 *dstTop++ = 3 << 30 | ((y23 >> 16) << 10) | uv1;
703
704 *dstBot++ = 3 << 30 | ((y45 & 0x3FF) << 10) | uv0;
705 *dstBot++ = 3 << 30 | ((y45 >> 16) << 10) | uv0;
706 *dstBot++ = 3 << 30 | ((y67 & 0x3FF) << 10) | uv1;
707 *dstBot++ = 3 << 30 | ((y67 >> 16) << 10) | uv1;
708 }
709
710 // There should be at most 2 more pixels to process. Note that we don't
711 // need to consider odd case as the buffer is always aligned to even.
712 if (x < width) {
713 u01 = *uSrc;
714 v01 = *vSrc;
715 y01 = *((uint32_t*)ySrcTop);
716 y45 = *((uint32_t*)ySrcBot);
717 uv0 = (u01 & 0x3FF) | ((v01 & 0x3FF) << 20);
718 *dstTop++ = ((y01 & 0x3FF) << 10) | uv0;
719 *dstTop++ = ((y01 >> 16) << 10) | uv0;
720 *dstBot++ = ((y45 & 0x3FF) << 10) | uv0;
721 *dstBot++ = ((y45 >> 16) << 10) | uv0;
722 }
723
724 srcY += srcYStride * 2;
725 srcU += srcUStride;
726 srcV += srcVStride;
727 dst += dstStride * 2;
728 }
729
730 return;
731}
732
ming.zhouac19c3d2019-10-11 11:14:07 +0800733static void convertYUV420Planar16ToYUV420Planar(
734 uint8_t *dstY, uint8_t *dstU, uint8_t *dstV,
Harish Mahendrakared4e0cd2018-10-11 18:11:49 -0700735 const uint16_t *srcY, const uint16_t *srcU, const uint16_t *srcV,
736 size_t srcYStride, size_t srcUStride, size_t srcVStride,
ming.zhouac19c3d2019-10-11 11:14:07 +0800737 size_t dstYStride, size_t dstUVStride,
738 size_t width, size_t height) {
Harish Mahendrakared4e0cd2018-10-11 18:11:49 -0700739
740 for (size_t y = 0; y < height; ++y) {
741 for (size_t x = 0; x < width; ++x) {
742 dstY[x] = (uint8_t)(srcY[x] >> 2);
743 }
744
745 srcY += srcYStride;
Harish Mahendrakardfa3f5a2019-05-02 12:10:24 -0700746 dstY += dstYStride;
Harish Mahendrakared4e0cd2018-10-11 18:11:49 -0700747 }
748
749 for (size_t y = 0; y < (height + 1) / 2; ++y) {
750 for (size_t x = 0; x < (width + 1) / 2; ++x) {
751 dstU[x] = (uint8_t)(srcU[x] >> 2);
752 dstV[x] = (uint8_t)(srcV[x] >> 2);
753 }
754
755 srcU += srcUStride;
756 srcV += srcVStride;
757 dstU += dstUVStride;
758 dstV += dstUVStride;
759 }
760 return;
761}
Wonsik Kim377eeab2019-11-03 19:05:59 -0800762status_t C2SoftVpxDec::outputBuffer(
Pawin Vongmasa36653902018-11-15 00:10:25 -0800763 const std::shared_ptr<C2BlockPool> &pool,
764 const std::unique_ptr<C2Work> &work)
765{
Wonsik Kim377eeab2019-11-03 19:05:59 -0800766 if (!(work && pool)) return BAD_VALUE;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800767
768 vpx_codec_iter_t iter = nullptr;
769 vpx_image_t *img = vpx_codec_get_frame(mCodecCtx, &iter);
770
Wonsik Kim377eeab2019-11-03 19:05:59 -0800771 if (!img) return NOT_ENOUGH_DATA;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800772
773 if (img->d_w != mWidth || img->d_h != mHeight) {
774 mWidth = img->d_w;
775 mHeight = img->d_h;
776
Lajos Molnar3bb81cd2019-02-20 15:10:30 -0800777 C2StreamPictureSizeInfo::output size(0u, mWidth, mHeight);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800778 std::vector<std::unique_ptr<C2SettingResult>> failures;
779 c2_status_t err = mIntf->config({&size}, C2_MAY_BLOCK, &failures);
780 if (err == C2_OK) {
781 work->worklets.front()->output.configUpdate.push_back(
782 C2Param::Copy(size));
783 } else {
784 ALOGE("Config update size failed");
785 mSignalledError = true;
786 work->workletsProcessed = 1u;
787 work->result = C2_CORRUPTED;
Wonsik Kim377eeab2019-11-03 19:05:59 -0800788 return UNKNOWN_ERROR;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800789 }
790
791 }
Harish Mahendrakar3fdfaa32019-08-02 15:44:30 -0700792 if(img->fmt != VPX_IMG_FMT_I420 && img->fmt != VPX_IMG_FMT_I42016) {
793 ALOGE("img->fmt %d not supported", img->fmt);
794 mSignalledError = true;
795 work->workletsProcessed = 1u;
796 work->result = C2_CORRUPTED;
797 return false;
798 }
Pawin Vongmasa36653902018-11-15 00:10:25 -0800799
800 std::shared_ptr<C2GraphicBlock> block;
801 uint32_t format = HAL_PIXEL_FORMAT_YV12;
Harish Mahendrakared4e0cd2018-10-11 18:11:49 -0700802 if (img->fmt == VPX_IMG_FMT_I42016) {
803 IntfImpl::Lock lock = mIntf->lock();
804 std::shared_ptr<C2StreamColorAspectsTuning::output> defaultColorAspects = mIntf->getDefaultColorAspects_l();
805
806 if (defaultColorAspects->primaries == C2Color::PRIMARIES_BT2020 &&
807 defaultColorAspects->matrix == C2Color::MATRIX_BT2020 &&
808 defaultColorAspects->transfer == C2Color::TRANSFER_ST2084) {
Harish Mahendrakarf0fa7a22021-12-10 20:36:32 -0800809 // TODO (b/201787956) For devices that do not support HAL_PIXEL_FORMAT_RGBA_1010102,
810 // HAL_PIXEL_FORMAT_YV12 is used as a temporary work around.
811 if (!mIsFormatR10G10B10A2Supported) {
812 ALOGE("HAL_PIXEL_FORMAT_RGBA_1010102 isn't supported");
813 format = HAL_PIXEL_FORMAT_YV12;
814 } else {
815 format = HAL_PIXEL_FORMAT_RGBA_1010102;
816 }
Harish Mahendrakared4e0cd2018-10-11 18:11:49 -0700817 }
818 }
Pawin Vongmasa36653902018-11-15 00:10:25 -0800819 C2MemoryUsage usage = { C2MemoryUsage::CPU_READ, C2MemoryUsage::CPU_WRITE };
Harish Mahendrakared4e0cd2018-10-11 18:11:49 -0700820 c2_status_t err = pool->fetchGraphicBlock(align(mWidth, 16), mHeight, format, usage, &block);
Pawin Vongmasa36653902018-11-15 00:10:25 -0800821 if (err != C2_OK) {
822 ALOGE("fetchGraphicBlock for Output failed with status %d", err);
823 work->result = err;
Wonsik Kim377eeab2019-11-03 19:05:59 -0800824 return UNKNOWN_ERROR;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800825 }
826
827 C2GraphicView wView = block->map().get();
828 if (wView.error()) {
829 ALOGE("graphic view map failed %d", wView.error());
830 work->result = C2_CORRUPTED;
Wonsik Kim377eeab2019-11-03 19:05:59 -0800831 return UNKNOWN_ERROR;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800832 }
833
Wonsik Kim377eeab2019-11-03 19:05:59 -0800834 ALOGV("provided (%dx%d) required (%dx%d), out frameindex %lld",
835 block->width(), block->height(), mWidth, mHeight,
836 ((c2_cntr64_t *)img->user_priv)->peekll());
Pawin Vongmasa36653902018-11-15 00:10:25 -0800837
ming.zhouac19c3d2019-10-11 11:14:07 +0800838 uint8_t *dstY = const_cast<uint8_t *>(wView.data()[C2PlanarLayout::PLANE_Y]);
839 uint8_t *dstU = const_cast<uint8_t *>(wView.data()[C2PlanarLayout::PLANE_U]);
840 uint8_t *dstV = const_cast<uint8_t *>(wView.data()[C2PlanarLayout::PLANE_V]);
841
Pawin Vongmasa36653902018-11-15 00:10:25 -0800842 size_t srcYStride = img->stride[VPX_PLANE_Y];
843 size_t srcUStride = img->stride[VPX_PLANE_U];
844 size_t srcVStride = img->stride[VPX_PLANE_V];
Harish Mahendrakardfa3f5a2019-05-02 12:10:24 -0700845 C2PlanarLayout layout = wView.layout();
846 size_t dstYStride = layout.planes[C2PlanarLayout::PLANE_Y].rowInc;
847 size_t dstUVStride = layout.planes[C2PlanarLayout::PLANE_U].rowInc;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800848
Harish Mahendrakared4e0cd2018-10-11 18:11:49 -0700849 if (img->fmt == VPX_IMG_FMT_I42016) {
850 const uint16_t *srcY = (const uint16_t *)img->planes[VPX_PLANE_Y];
851 const uint16_t *srcU = (const uint16_t *)img->planes[VPX_PLANE_U];
852 const uint16_t *srcV = (const uint16_t *)img->planes[VPX_PLANE_V];
853
854 if (format == HAL_PIXEL_FORMAT_RGBA_1010102) {
Wonsik Kimf61206f2019-05-18 16:52:46 -0700855 Mutexed<ConversionQueue>::Locked queue(*mQueue);
856 size_t i = 0;
857 constexpr size_t kHeight = 64;
858 for (; i < mHeight; i += kHeight) {
859 queue->entries.push_back(
ming.zhouac19c3d2019-10-11 11:14:07 +0800860 [dstY, srcY, srcU, srcV,
Wonsik Kimf61206f2019-05-18 16:52:46 -0700861 srcYStride, srcUStride, srcVStride, dstYStride,
862 width = mWidth, height = std::min(mHeight - i, kHeight)] {
863 convertYUV420Planar16ToY410(
ming.zhouac19c3d2019-10-11 11:14:07 +0800864 (uint32_t *)dstY, srcY, srcU, srcV, srcYStride / 2,
Wonsik Kimf61206f2019-05-18 16:52:46 -0700865 srcUStride / 2, srcVStride / 2, dstYStride / sizeof(uint32_t),
866 width, height);
867 });
868 srcY += srcYStride / 2 * kHeight;
869 srcU += srcUStride / 2 * (kHeight / 2);
870 srcV += srcVStride / 2 * (kHeight / 2);
ming.zhouac19c3d2019-10-11 11:14:07 +0800871 dstY += dstYStride * kHeight;
Wonsik Kimf61206f2019-05-18 16:52:46 -0700872 }
873 CHECK_EQ(0u, queue->numPending);
874 queue->numPending = queue->entries.size();
875 while (queue->numPending > 0) {
876 queue->cond.signal();
877 queue.waitForCondition(queue->cond);
878 }
Harish Mahendrakared4e0cd2018-10-11 18:11:49 -0700879 } else {
ming.zhouac19c3d2019-10-11 11:14:07 +0800880 convertYUV420Planar16ToYUV420Planar(dstY, dstU, dstV,
881 srcY, srcU, srcV,
882 srcYStride / 2, srcUStride / 2, srcVStride / 2,
Wonsik Kimf61206f2019-05-18 16:52:46 -0700883 dstYStride, dstUVStride,
884 mWidth, mHeight);
Harish Mahendrakared4e0cd2018-10-11 18:11:49 -0700885 }
886 } else {
887 const uint8_t *srcY = (const uint8_t *)img->planes[VPX_PLANE_Y];
888 const uint8_t *srcU = (const uint8_t *)img->planes[VPX_PLANE_U];
889 const uint8_t *srcV = (const uint8_t *)img->planes[VPX_PLANE_V];
ming.zhouac19c3d2019-10-11 11:14:07 +0800890
Harish Mahendrakardfa3f5a2019-05-02 12:10:24 -0700891 copyOutputBufferToYuvPlanarFrame(
ming.zhouac19c3d2019-10-11 11:14:07 +0800892 dstY, dstU, dstV,
893 srcY, srcU, srcV,
Harish Mahendrakardfa3f5a2019-05-02 12:10:24 -0700894 srcYStride, srcUStride, srcVStride,
895 dstYStride, dstUVStride,
896 mWidth, mHeight);
Harish Mahendrakared4e0cd2018-10-11 18:11:49 -0700897 }
Wonsik Kim377eeab2019-11-03 19:05:59 -0800898 finishWork(((c2_cntr64_t *)img->user_priv)->peekull(), work, std::move(block));
899 return OK;
Pawin Vongmasa36653902018-11-15 00:10:25 -0800900}
901
902c2_status_t C2SoftVpxDec::drainInternal(
903 uint32_t drainMode,
904 const std::shared_ptr<C2BlockPool> &pool,
905 const std::unique_ptr<C2Work> &work) {
906 if (drainMode == NO_DRAIN) {
907 ALOGW("drain with NO_DRAIN: no-op");
908 return C2_OK;
909 }
910 if (drainMode == DRAIN_CHAIN) {
911 ALOGW("DRAIN_CHAIN not supported");
912 return C2_OMITTED;
913 }
914
Wonsik Kim377eeab2019-11-03 19:05:59 -0800915 while (outputBuffer(pool, work) == OK) {
Pawin Vongmasa36653902018-11-15 00:10:25 -0800916 }
917
918 if (drainMode == DRAIN_COMPONENT_WITH_EOS &&
919 work && work->workletsProcessed == 0u) {
920 fillEmptyWork(work);
921 }
922
923 return C2_OK;
924}
925c2_status_t C2SoftVpxDec::drain(
926 uint32_t drainMode,
927 const std::shared_ptr<C2BlockPool> &pool) {
928 return drainInternal(drainMode, pool, nullptr);
929}
930
931class C2SoftVpxFactory : public C2ComponentFactory {
932public:
933 C2SoftVpxFactory() : mHelper(std::static_pointer_cast<C2ReflectorHelper>(
934 GetCodec2PlatformComponentStore()->getParamReflector())) {
935 }
936
937 virtual c2_status_t createComponent(
938 c2_node_id_t id,
939 std::shared_ptr<C2Component>* const component,
940 std::function<void(C2Component*)> deleter) override {
941 *component = std::shared_ptr<C2Component>(
942 new C2SoftVpxDec(COMPONENT_NAME, id,
943 std::make_shared<C2SoftVpxDec::IntfImpl>(mHelper)),
944 deleter);
945 return C2_OK;
946 }
947
948 virtual c2_status_t createInterface(
949 c2_node_id_t id,
950 std::shared_ptr<C2ComponentInterface>* const interface,
951 std::function<void(C2ComponentInterface*)> deleter) override {
952 *interface = std::shared_ptr<C2ComponentInterface>(
953 new SimpleInterface<C2SoftVpxDec::IntfImpl>(
954 COMPONENT_NAME, id,
955 std::make_shared<C2SoftVpxDec::IntfImpl>(mHelper)),
956 deleter);
957 return C2_OK;
958 }
959
960 virtual ~C2SoftVpxFactory() override = default;
961
962private:
963 std::shared_ptr<C2ReflectorHelper> mHelper;
964};
965
966} // namespace android
967
Cindy Zhouf6c0c3c2020-12-02 10:53:40 -0800968__attribute__((cfi_canonical_jump_table))
Pawin Vongmasa36653902018-11-15 00:10:25 -0800969extern "C" ::C2ComponentFactory* CreateCodec2Factory() {
970 ALOGV("in %s", __func__);
971 return new ::android::C2SoftVpxFactory();
972}
973
Cindy Zhouf6c0c3c2020-12-02 10:53:40 -0800974__attribute__((cfi_canonical_jump_table))
Pawin Vongmasa36653902018-11-15 00:10:25 -0800975extern "C" void DestroyCodec2Factory(::C2ComponentFactory* factory) {
976 ALOGV("in %s", __func__);
977 delete factory;
978}