blob: 0e09fccfd2de8022ab9ab7816060b1359d0cef8b [file] [log] [blame]
Vignesh Venkatasubramanian46e06392019-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#ifndef ANDROID_C2_SOFT_GAV1_DEC_H_
18#define ANDROID_C2_SOFT_GAV1_DEC_H_
19
Ray Essick24754942022-04-16 09:50:35 -070020#include <inttypes.h>
21
James Zern0958b8b2023-02-17 21:48:08 -080022#include <memory>
23
Neelkamal Semwalc13a76a2021-09-01 17:07:30 +053024#include <media/stagefright/foundation/ColorUtils.h>
25
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070026#include <SimpleC2Component.h>
Neelkamal Semwalc13a76a2021-09-01 17:07:30 +053027#include <C2Config.h>
Harish Mahendrakarfb031332021-12-20 21:34:12 -080028#include <gav1/decoder.h>
29#include <gav1/decoder_settings.h>
Vignesh Venkatasubramanian87f6ede2019-06-17 16:21:36 -070030
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070031namespace android {
32
33struct C2SoftGav1Dec : public SimpleC2Component {
34 class IntfImpl;
35
36 C2SoftGav1Dec(const char* name, c2_node_id_t id,
37 const std::shared_ptr<IntfImpl>& intfImpl);
Vignesh Venkatasubramanian87f6ede2019-06-17 16:21:36 -070038 ~C2SoftGav1Dec();
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070039
40 // Begin SimpleC2Component overrides.
41 c2_status_t onInit() override;
42 c2_status_t onStop() override;
43 void onReset() override;
44 void onRelease() override;
45 c2_status_t onFlush_sm() override;
46 void process(const std::unique_ptr<C2Work>& work,
47 const std::shared_ptr<C2BlockPool>& pool) override;
48 c2_status_t drain(uint32_t drainMode,
49 const std::shared_ptr<C2BlockPool>& pool) override;
50 // End SimpleC2Component overrides.
51
52 private:
53 std::shared_ptr<IntfImpl> mIntf;
Vignesh Venkatasubramanian87f6ede2019-06-17 16:21:36 -070054 std::unique_ptr<libgav1::Decoder> mCodecCtx;
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070055
Harish Mahendrakar10c0c5d2022-05-30 20:35:16 -070056 // configurations used by component in process
57 // (TODO: keep this in intf but make them internal only)
58 std::shared_ptr<C2StreamPixelFormatInfo::output> mPixelFormatInfo;
59
Harish Mahendrakard4bbb762022-03-29 11:53:23 -070060 uint32_t mHalPixelFormat;
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070061 uint32_t mWidth;
62 uint32_t mHeight;
63 bool mSignalledOutputEos;
64 bool mSignalledError;
James Zern0958b8b2023-02-17 21:48:08 -080065 // Used during 10-bit I444/I422 to 10-bit P010 & 8-bit I420 conversions.
66 std::unique_ptr<uint16_t[]> mTmpFrameBuffer;
67 size_t mTmpFrameBufferSize = 0;
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070068
Manisha Jajoo210d52e2022-05-19 17:11:55 +053069 C2StreamHdrStaticMetadataInfo::output mHdrStaticMetadataInfo;
70 std::unique_ptr<C2StreamHdr10PlusInfo::output> mHdr10PlusInfo = nullptr;
71
Neelkamal Semwalc13a76a2021-09-01 17:07:30 +053072 // Color aspects. These are ISO values and are meant to detect changes in aspects to avoid
73 // converting them to C2 values for each frame
74 struct VuiColorAspects {
75 uint8_t primaries;
76 uint8_t transfer;
77 uint8_t coeffs;
78 uint8_t fullRange;
79
80 // default color aspects
81 VuiColorAspects()
82 : primaries(C2Color::PRIMARIES_UNSPECIFIED),
83 transfer(C2Color::TRANSFER_UNSPECIFIED),
84 coeffs(C2Color::MATRIX_UNSPECIFIED),
85 fullRange(C2Color::RANGE_UNSPECIFIED) { }
86
Satish Yalla892344a2024-06-11 01:36:45 +000087 bool operator==(const VuiColorAspects &o) {
Neelkamal Semwalc13a76a2021-09-01 17:07:30 +053088 return primaries == o.primaries && transfer == o.transfer && coeffs == o.coeffs
89 && fullRange == o.fullRange;
90 }
91 } mBitstreamColorAspects;
92
Ray Essick24754942022-04-16 09:50:35 -070093 nsecs_t mTimeStart = 0; // Time at the start of decode()
94 nsecs_t mTimeEnd = 0; // Time at the end of decode()
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -070095
96 bool initDecoder();
Manisha Jajoo210d52e2022-05-19 17:11:55 +053097 void getHDRStaticParams(const libgav1::DecoderBuffer *buffer,
98 const std::unique_ptr<C2Work> &work);
99 void getHDR10PlusInfoData(const libgav1::DecoderBuffer *buffer,
100 const std::unique_ptr<C2Work> &work);
Neelkamal Semwalc13a76a2021-09-01 17:07:30 +0530101 void getVuiParams(const libgav1::DecoderBuffer *buffer);
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -0700102 void destroyDecoder();
103 void finishWork(uint64_t index, const std::unique_ptr<C2Work>& work,
104 const std::shared_ptr<C2GraphicBlock>& block);
James Zern0958b8b2023-02-17 21:48:08 -0800105 // Sets |work->result| and mSignalledError. Returns false.
106 void setError(const std::unique_ptr<C2Work> &work, c2_status_t error);
107 bool allocTmpFrameBuffer(size_t size);
Vignesh Venkatasubramanian3a12ac22023-06-02 03:09:33 +0000108 bool fillMonochromeRow(int value);
Vignesh Venkatasubramanian46e06392019-06-10 15:11:58 -0700109 bool outputBuffer(const std::shared_ptr<C2BlockPool>& pool,
110 const std::unique_ptr<C2Work>& work);
111 c2_status_t drainInternal(uint32_t drainMode,
112 const std::shared_ptr<C2BlockPool>& pool,
113 const std::unique_ptr<C2Work>& work);
114
115 C2_DO_NOT_COPY(C2SoftGav1Dec);
116};
117
118} // namespace android
119
120#endif // ANDROID_C2_SOFT_GAV1_DEC_H_