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 | |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 22 | #include <media/stagefright/foundation/ColorUtils.h> |
| 23 | |
Vignesh Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 24 | #include <SimpleC2Component.h> |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 25 | #include <C2Config.h> |
Harish Mahendrakar | fb03133 | 2021-12-20 21:34:12 -0800 | [diff] [blame] | 26 | #include <gav1/decoder.h> |
| 27 | #include <gav1/decoder_settings.h> |
Vignesh Venkatasubramanian | 87f6ede | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 28 | |
Vignesh Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 29 | namespace android { |
| 30 | |
| 31 | struct C2SoftGav1Dec : public SimpleC2Component { |
| 32 | class IntfImpl; |
| 33 | |
| 34 | C2SoftGav1Dec(const char* name, c2_node_id_t id, |
| 35 | const std::shared_ptr<IntfImpl>& intfImpl); |
Vignesh Venkatasubramanian | 87f6ede | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 36 | ~C2SoftGav1Dec(); |
Vignesh Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 37 | |
| 38 | // Begin SimpleC2Component overrides. |
| 39 | c2_status_t onInit() override; |
| 40 | c2_status_t onStop() override; |
| 41 | void onReset() override; |
| 42 | void onRelease() override; |
| 43 | c2_status_t onFlush_sm() override; |
| 44 | void process(const std::unique_ptr<C2Work>& work, |
| 45 | const std::shared_ptr<C2BlockPool>& pool) override; |
| 46 | c2_status_t drain(uint32_t drainMode, |
| 47 | const std::shared_ptr<C2BlockPool>& pool) override; |
| 48 | // End SimpleC2Component overrides. |
| 49 | |
| 50 | private: |
| 51 | std::shared_ptr<IntfImpl> mIntf; |
Vignesh Venkatasubramanian | 87f6ede | 2019-06-17 16:21:36 -0700 | [diff] [blame] | 52 | std::unique_ptr<libgav1::Decoder> mCodecCtx; |
Vignesh Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 53 | |
Harish Mahendrakar | 10c0c5d | 2022-05-30 20:35:16 -0700 | [diff] [blame] | 54 | // configurations used by component in process |
| 55 | // (TODO: keep this in intf but make them internal only) |
| 56 | std::shared_ptr<C2StreamPixelFormatInfo::output> mPixelFormatInfo; |
| 57 | |
Harish Mahendrakar | d4bbb76 | 2022-03-29 11:53:23 -0700 | [diff] [blame] | 58 | uint32_t mHalPixelFormat; |
Vignesh Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 59 | uint32_t mWidth; |
| 60 | uint32_t mHeight; |
| 61 | bool mSignalledOutputEos; |
| 62 | bool mSignalledError; |
| 63 | |
Manisha Jajoo | 210d52e | 2022-05-19 17:11:55 +0530 | [diff] [blame] | 64 | C2StreamHdrStaticMetadataInfo::output mHdrStaticMetadataInfo; |
| 65 | std::unique_ptr<C2StreamHdr10PlusInfo::output> mHdr10PlusInfo = nullptr; |
| 66 | |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 67 | // Color aspects. These are ISO values and are meant to detect changes in aspects to avoid |
| 68 | // converting them to C2 values for each frame |
| 69 | struct VuiColorAspects { |
| 70 | uint8_t primaries; |
| 71 | uint8_t transfer; |
| 72 | uint8_t coeffs; |
| 73 | uint8_t fullRange; |
| 74 | |
| 75 | // default color aspects |
| 76 | VuiColorAspects() |
| 77 | : primaries(C2Color::PRIMARIES_UNSPECIFIED), |
| 78 | transfer(C2Color::TRANSFER_UNSPECIFIED), |
| 79 | coeffs(C2Color::MATRIX_UNSPECIFIED), |
| 80 | fullRange(C2Color::RANGE_UNSPECIFIED) { } |
| 81 | |
| 82 | bool operator==(const VuiColorAspects &o) { |
| 83 | return primaries == o.primaries && transfer == o.transfer && coeffs == o.coeffs |
| 84 | && fullRange == o.fullRange; |
| 85 | } |
| 86 | } mBitstreamColorAspects; |
| 87 | |
Ray Essick | 2475494 | 2022-04-16 09:50:35 -0700 | [diff] [blame] | 88 | nsecs_t mTimeStart = 0; // Time at the start of decode() |
| 89 | nsecs_t mTimeEnd = 0; // Time at the end of decode() |
Vignesh Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 90 | |
| 91 | bool initDecoder(); |
Manisha Jajoo | 210d52e | 2022-05-19 17:11:55 +0530 | [diff] [blame] | 92 | void getHDRStaticParams(const libgav1::DecoderBuffer *buffer, |
| 93 | const std::unique_ptr<C2Work> &work); |
| 94 | void getHDR10PlusInfoData(const libgav1::DecoderBuffer *buffer, |
| 95 | const std::unique_ptr<C2Work> &work); |
Neelkamal Semwal | c13a76a | 2021-09-01 17:07:30 +0530 | [diff] [blame] | 96 | void getVuiParams(const libgav1::DecoderBuffer *buffer); |
Vignesh Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 97 | void destroyDecoder(); |
| 98 | void finishWork(uint64_t index, const std::unique_ptr<C2Work>& work, |
| 99 | const std::shared_ptr<C2GraphicBlock>& block); |
Vignesh Venkatasubramanian | 46e0639 | 2019-06-10 15:11:58 -0700 | [diff] [blame] | 100 | bool outputBuffer(const std::shared_ptr<C2BlockPool>& pool, |
| 101 | const std::unique_ptr<C2Work>& work); |
| 102 | c2_status_t drainInternal(uint32_t drainMode, |
| 103 | const std::shared_ptr<C2BlockPool>& pool, |
| 104 | const std::unique_ptr<C2Work>& work); |
| 105 | |
| 106 | C2_DO_NOT_COPY(C2SoftGav1Dec); |
| 107 | }; |
| 108 | |
| 109 | } // namespace android |
| 110 | |
| 111 | #endif // ANDROID_C2_SOFT_GAV1_DEC_H_ |