Vignesh Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 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 | |
Ray Essick | 2475494 | 2022-04-16 09:50:35 -0700 | [diff] [blame] | 20 | #include <inttypes.h> |
| 21 | |
James Zern | 0958b8b | 2023-02-17 21:48:08 -0800 | [diff] [blame] | 22 | #include <memory> |
| 23 | |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 24 | #include <media/stagefright/foundation/ColorUtils.h> |
| 25 | |
Vignesh Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 26 | #include <SimpleC2Component.h> |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 27 | #include <C2Config.h> |
Harish Mahendrakar | fb03133 | 2021-12-20 21:34:12 -0800 | [diff] [blame] | 28 | #include <gav1/decoder.h> |
| 29 | #include <gav1/decoder_settings.h> |
Vignesh Venkatasubramanian | 87f6ede | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 30 | |
Vignesh Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 31 | namespace android { |
| 32 | |
| 33 | struct 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 Venkatasubramanian | 87f6ede | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 38 | ~C2SoftGav1Dec(); |
Vignesh Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 39 | |
| 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 Venkatasubramanian | 87f6ede | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 54 | std::unique_ptr<libgav1::Decoder> mCodecCtx; |
Vignesh Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 55 | |
Harish Mahendrakar | 10c0c5d | 2022-05-30 20:35:16 -0700 | [diff] [blame] | 56 | // 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 Mahendrakar | d4bbb76 | 2022-03-29 11:53:23 -0700 | [diff] [blame] | 60 | uint32_t mHalPixelFormat; |
Vignesh Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 61 | uint32_t mWidth; |
| 62 | uint32_t mHeight; |
| 63 | bool mSignalledOutputEos; |
| 64 | bool mSignalledError; |
James Zern | 0958b8b | 2023-02-17 21:48:08 -0800 | [diff] [blame] | 65 | // 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 Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 68 | |
Manisha Jajoo | 210d52e | 2022-05-19 17:11:55 +0530 | [diff] [blame] | 69 | C2StreamHdrStaticMetadataInfo::output mHdrStaticMetadataInfo; |
| 70 | std::unique_ptr<C2StreamHdr10PlusInfo::output> mHdr10PlusInfo = nullptr; |
| 71 | |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 72 | // 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 Yalla | 892344a | 2024-06-11 01:36:45 +0000 | [diff] [blame] | 87 | bool operator==(const VuiColorAspects &o) { |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 88 | return primaries == o.primaries && transfer == o.transfer && coeffs == o.coeffs |
| 89 | && fullRange == o.fullRange; |
| 90 | } |
| 91 | } mBitstreamColorAspects; |
| 92 | |
Ray Essick | 2475494 | 2022-04-16 09:50:35 -0700 | [diff] [blame] | 93 | nsecs_t mTimeStart = 0; // Time at the start of decode() |
| 94 | nsecs_t mTimeEnd = 0; // Time at the end of decode() |
Vignesh Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 95 | |
| 96 | bool initDecoder(); |
Manisha Jajoo | 210d52e | 2022-05-19 17:11:55 +0530 | [diff] [blame] | 97 | 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 Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 101 | void getVuiParams(const libgav1::DecoderBuffer *buffer); |
Vignesh Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 102 | void destroyDecoder(); |
| 103 | void finishWork(uint64_t index, const std::unique_ptr<C2Work>& work, |
| 104 | const std::shared_ptr<C2GraphicBlock>& block); |
James Zern | 0958b8b | 2023-02-17 21:48:08 -0800 | [diff] [blame] | 105 | // 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 Venkatasubramanian | 3a12ac2 | 2023-06-02 03:09:33 +0000 | [diff] [blame] | 108 | bool fillMonochromeRow(int value); |
Vignesh Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 109 | 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_ |