• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 #ifndef ANDROID_C2_SOFT_GAV1_DEC_H_
18 #define ANDROID_C2_SOFT_GAV1_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 #include <util/C2InterfaceHelper.h>
29 
30 #include <gav1/decoder.h>
31 #include <gav1/decoder_settings.h>
32 
33 namespace android {
34 
35 struct C2SoftGav1Dec : public SimpleC2Component {
36   class IntfImpl;
37 
38   C2SoftGav1Dec(const char* name, c2_node_id_t id,
39                 const std::shared_ptr<IntfImpl>& intfImpl);
40   C2SoftGav1Dec(const char* name, c2_node_id_t id,
41                 const std::shared_ptr<C2ReflectorHelper>& helper);
42   ~C2SoftGav1Dec();
43 
44   // Begin SimpleC2Component overrides.
45   c2_status_t onInit() override;
46   c2_status_t onStop() override;
47   void onReset() override;
48   void onRelease() override;
49   c2_status_t onFlush_sm() override;
50   void process(const std::unique_ptr<C2Work>& work,
51                const std::shared_ptr<C2BlockPool>& pool) override;
52   c2_status_t drain(uint32_t drainMode,
53                     const std::shared_ptr<C2BlockPool>& pool) override;
54   // End SimpleC2Component overrides.
55 
56  private:
57   std::shared_ptr<IntfImpl> mIntf;
58   std::unique_ptr<libgav1::Decoder> mCodecCtx;
59 
60   // configurations used by component in process
61   // (TODO: keep this in intf but make them internal only)
62   std::shared_ptr<C2StreamPixelFormatInfo::output> mPixelFormatInfo;
63 
64   uint32_t mHalPixelFormat;
65   uint32_t mWidth;
66   uint32_t mHeight;
67   bool mSignalledOutputEos;
68   bool mSignalledError;
69   // Used during 10-bit I444/I422 to 10-bit P010 & 8-bit I420 conversions.
70   std::unique_ptr<uint16_t[]> mTmpFrameBuffer;
71   size_t mTmpFrameBufferSize = 0;
72 
73   C2StreamHdrStaticMetadataInfo::output mHdrStaticMetadataInfo;
74   std::unique_ptr<C2StreamHdr10PlusInfo::output> mHdr10PlusInfo = nullptr;
75 
76   // Color aspects. These are ISO values and are meant to detect changes in aspects to avoid
77   // converting them to C2 values for each frame
78   struct VuiColorAspects {
79       uint8_t primaries;
80       uint8_t transfer;
81       uint8_t coeffs;
82       uint8_t fullRange;
83 
84       // default color aspects
VuiColorAspectsC2SoftGav1Dec::VuiColorAspects85       VuiColorAspects()
86           : primaries(C2Color::PRIMARIES_UNSPECIFIED),
87             transfer(C2Color::TRANSFER_UNSPECIFIED),
88             coeffs(C2Color::MATRIX_UNSPECIFIED),
89             fullRange(C2Color::RANGE_UNSPECIFIED) { }
90 
91       bool operator==(const VuiColorAspects &o) const {
92           return primaries == o.primaries && transfer == o.transfer && coeffs == o.coeffs
93                   && fullRange == o.fullRange;
94       }
95   } mBitstreamColorAspects;
96 
97   nsecs_t mTimeStart = 0;  // Time at the start of decode()
98   nsecs_t mTimeEnd = 0;    // Time at the end of decode()
99 
100   bool initDecoder();
101   void getHDRStaticParams(const libgav1::DecoderBuffer *buffer,
102                   const std::unique_ptr<C2Work> &work);
103   void getHDR10PlusInfoData(const libgav1::DecoderBuffer *buffer,
104                   const std::unique_ptr<C2Work> &work);
105   void getVuiParams(const libgav1::DecoderBuffer *buffer);
106   void destroyDecoder();
107   void finishWork(uint64_t index, const std::unique_ptr<C2Work>& work,
108                   const std::shared_ptr<C2GraphicBlock>& block);
109   // Sets |work->result| and mSignalledError. Returns false.
110   void setError(const std::unique_ptr<C2Work> &work, c2_status_t error);
111   bool allocTmpFrameBuffer(size_t size);
112   bool fillMonochromeRow(int value);
113   bool outputBuffer(const std::shared_ptr<C2BlockPool>& pool,
114                     const std::unique_ptr<C2Work>& work);
115   c2_status_t drainInternal(uint32_t drainMode,
116                             const std::shared_ptr<C2BlockPool>& pool,
117                             const std::unique_ptr<C2Work>& work);
118 
119   C2_DO_NOT_COPY(C2SoftGav1Dec);
120 };
121 
122 }  // namespace android
123 
124 #endif  // ANDROID_C2_SOFT_GAV1_DEC_H_
125