blob: 5d2a725607e28d17c527f0038306075e8da61029 [file] [log] [blame]
Richard Xief2932a02023-10-20 17:37:57 +00001/*
2 * Copyright (C) 2023 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 ANDROID_C2_SOFT_DAV1D_DEC_H_
18#define ANDROID_C2_SOFT_DAV1D_DEC_H_
19
20#include <inttypes.h>
21
22#include <memory>
23
24#include <media/stagefright/foundation/ColorUtils.h>
25
26#include <C2Config.h>
27#include <SimpleC2Component.h>
28
29#include <dav1d/dav1d.h>
30#include <deque>
Suyog Pawar4602c372023-08-17 11:09:23 +053031#include <C2SoftDav1dDump.h>
Richard Xief2932a02023-10-20 17:37:57 +000032
33//#define FILE_DUMP_ENABLE 1
Richard Xief2932a02023-10-20 17:37:57 +000034
35namespace android {
36
37struct C2SoftDav1dDec : public SimpleC2Component {
38 class IntfImpl;
39
40 C2SoftDav1dDec(const char* name, c2_node_id_t id, const std::shared_ptr<IntfImpl>& intfImpl);
41 ~C2SoftDav1dDec();
42
43 // Begin SimpleC2Component overrides.
44 c2_status_t onInit() override;
45 c2_status_t onStop() override;
46 void onReset() override;
47 void onRelease() override;
48 c2_status_t onFlush_sm() override;
49 void process(const std::unique_ptr<C2Work>& work,
50 const std::shared_ptr<C2BlockPool>& pool) override;
51 c2_status_t drain(uint32_t drainMode, const std::shared_ptr<C2BlockPool>& pool) override;
52 // End SimpleC2Component overrides.
53
54 private:
55 std::shared_ptr<IntfImpl> mIntf;
56
57 int mInputBufferIndex = 0;
58 int mOutputBufferIndex = 0;
59
60 Dav1dContext* mDav1dCtx = nullptr;
Richard Xief2932a02023-10-20 17:37:57 +000061
62 // configurations used by component in process
63 // (TODO: keep this in intf but make them internal only)
64 std::shared_ptr<C2StreamPixelFormatInfo::output> mPixelFormatInfo;
65
66 uint32_t mHalPixelFormat;
67 uint32_t mWidth;
68 uint32_t mHeight;
69 bool mSignalledOutputEos;
70 bool mSignalledError;
71 // Used during 10-bit I444/I422 to 10-bit P010 & 8-bit I420 conversions.
72 std::unique_ptr<uint16_t[]> mTmpFrameBuffer;
73 size_t mTmpFrameBufferSize = 0;
74
75 C2StreamHdrStaticMetadataInfo::output mHdrStaticMetadataInfo;
76 std::unique_ptr<C2StreamHdr10PlusInfo::output> mHdr10PlusInfo = nullptr;
77
78 // Color aspects. These are ISO values and are meant to detect changes in aspects to avoid
79 // converting them to C2 values for each frame
80 struct VuiColorAspects {
81 uint8_t primaries;
82 uint8_t transfer;
83 uint8_t coeffs;
84 uint8_t fullRange;
85
86 // default color aspects
87 VuiColorAspects()
88 : primaries(C2Color::PRIMARIES_UNSPECIFIED),
89 transfer(C2Color::TRANSFER_UNSPECIFIED),
90 coeffs(C2Color::MATRIX_UNSPECIFIED),
91 fullRange(C2Color::RANGE_UNSPECIFIED) {}
92
93 bool operator==(const VuiColorAspects& o) {
94 return primaries == o.primaries && transfer == o.transfer && coeffs == o.coeffs &&
95 fullRange == o.fullRange;
96 }
97 } mBitstreamColorAspects;
98
99 nsecs_t mTimeStart = 0; // Time at the start of decode()
100 nsecs_t mTimeEnd = 0; // Time at the end of decode()
101
102 bool initDecoder();
Harish Mahendrakar98d9a242023-12-19 06:42:48 +0000103 void getHDRStaticParams(const Dav1dPicture* picture, const std::unique_ptr<C2Work>& work);
104 void getHDR10PlusInfoData(const Dav1dPicture* picture, const std::unique_ptr<C2Work>& work);
105 void getVuiParams(const Dav1dPicture* picture);
Richard Xief2932a02023-10-20 17:37:57 +0000106 void destroyDecoder();
107 void finishWork(uint64_t index, const std::unique_ptr<C2Work>& work,
Harish Mahendrakar98d9a242023-12-19 06:42:48 +0000108 const std::shared_ptr<C2GraphicBlock>& block,
109 const Dav1dPicture &img);
Richard Xief2932a02023-10-20 17:37:57 +0000110 // Sets |work->result| and mSignalledError. Returns false.
111 void setError(const std::unique_ptr<C2Work>& work, c2_status_t error);
112 bool allocTmpFrameBuffer(size_t size);
113 bool outputBuffer(const std::shared_ptr<C2BlockPool>& pool,
114 const std::unique_ptr<C2Work>& work);
115
116 c2_status_t drainInternal(uint32_t drainMode, const std::shared_ptr<C2BlockPool>& pool,
117 const std::unique_ptr<C2Work>& work);
118
119 void flushDav1d();
120
121#ifdef FILE_DUMP_ENABLE
Suyog Pawar4602c372023-08-17 11:09:23 +0530122 C2SoftDav1dDump mC2SoftDav1dDump;
Richard Xief2932a02023-10-20 17:37:57 +0000123#endif
124
125 C2_DO_NOT_COPY(C2SoftDav1dDec);
126};
127
128} // namespace android
129
130#endif // ANDROID_C2_SOFT_DAV1D_DEC_H_