1 /* 2 * Copyright (C) 2024 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_APV_DEC_H_ 18 #define ANDROID_C2_SOFT_APV_DEC_H_ 19 20 #include <media/stagefright/foundation/ColorUtils.h> 21 22 #include <SimpleC2Component.h> 23 #include <util/C2InterfaceHelper.h> 24 #include <inttypes.h> 25 #include <atomic> 26 27 #include "oapv.h" 28 #include <C2SoftApvCommon.h> 29 30 namespace android { 31 32 struct C2SoftApvDec final : public SimpleC2Component { 33 class IntfImpl; 34 35 C2SoftApvDec(const char* name, c2_node_id_t id, const std::shared_ptr<IntfImpl>& intfImpl); 36 C2SoftApvDec(const char* name, c2_node_id_t id, 37 const std::shared_ptr<C2ReflectorHelper>& helper); 38 virtual ~C2SoftApvDec(); 39 40 // From SimpleC2Component 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, const std::shared_ptr<C2BlockPool>& pool) override; 49 50 private: 51 status_t createDecoder(); 52 status_t initDecoder(); 53 bool isConfigured() const; 54 void drainDecoder(); 55 status_t setFlushMode(); 56 status_t resetDecoder(); 57 void resetPlugin(); 58 status_t deleteDecoder(); 59 void finishWork(uint64_t index, const std::unique_ptr<C2Work>& work, 60 const std::shared_ptr<C2GraphicBlock>& block); 61 void drainRingBuffer(const std::unique_ptr<C2Work>& work, 62 const std::shared_ptr<C2BlockPool>& pool, bool eos); 63 c2_status_t drainInternal(uint32_t drainMode, const std::shared_ptr<C2BlockPool>& pool, 64 const std::unique_ptr<C2Work>& work); 65 66 status_t outputBuffer(const std::shared_ptr<C2BlockPool>& pool, 67 const std::unique_ptr<C2Work>& work); 68 69 std::shared_ptr<IntfImpl> mIntf; 70 uint8_t *mOutBufferFlush; 71 uint32_t mOutputDelay; 72 std::atomic_uint64_t mOutIndex; 73 std::shared_ptr<C2GraphicBlock> mOutBlock; 74 75 std::shared_ptr<C2StreamPixelFormatInfo::output> mPixelFormatInfo; 76 77 std::shared_ptr<C2StreamPictureSizeInfo::input> mSize; 78 uint32_t mHalPixelFormat; 79 uint32_t mWidth; 80 uint32_t mHeight; 81 bool mSignalledOutputEos; 82 bool mSignalledError; 83 84 C2StreamHdrStaticMetadataInfo::output mHdrStaticMetadataInfo; 85 std::unique_ptr<C2StreamHdr10PlusInfo::output> mHdr10PlusInfo = nullptr; 86 87 // Color aspects. These are ISO values and are meant to detect changes in aspects to avoid 88 // converting them to C2 values for each frame 89 struct VuiColorAspects { 90 uint8_t primaries; 91 uint8_t transfer; 92 uint8_t coeffs; 93 uint8_t fullRange; 94 95 // default color aspects VuiColorAspectsfinal::VuiColorAspects96 VuiColorAspects() 97 : primaries(C2Color::PRIMARIES_UNSPECIFIED), 98 transfer(C2Color::TRANSFER_UNSPECIFIED), 99 coeffs(C2Color::MATRIX_UNSPECIFIED), 100 fullRange(C2Color::RANGE_UNSPECIFIED) { } 101 102 bool operator==(const VuiColorAspects &o) const { 103 return primaries == o.primaries && transfer == o.transfer && coeffs == o.coeffs 104 && fullRange == o.fullRange; 105 } 106 } mBitstreamColorAspects; 107 struct VuiColorAspects vuiColorAspects; 108 109 // HDR info that can be carried in APV bitstream 110 // Section 10.3.1 of APV syntax https://www.ietf.org/archive/id/draft-lim-apv-02.html 111 struct ApvHdrInfo { 112 bool has_hdr_mdcv; 113 bool has_itut_t35; 114 bool has_hdr_cll; 115 ApvHdrInfofinal::ApvHdrInfo116 ApvHdrInfo() 117 : has_hdr_mdcv(false), 118 has_itut_t35(false), 119 has_hdr_cll(false) { } 120 121 // Master Display Color Volume 122 struct HdrMdcv { 123 uint16_t primary_chromaticity_x[3]; 124 uint16_t primary_chromaticity_y[3]; 125 uint16_t white_point_chromaticity_x; 126 uint16_t white_point_chromaticity_y; 127 uint32_t max_mastering_luminance; 128 uint32_t min_mastering_luminance; 129 } hdr_mdcv; 130 131 // Content Light Level info 132 struct HdrCll { 133 uint16_t max_cll; 134 uint16_t max_fall; 135 } hdr_cll; 136 137 // ITU-T35 info 138 struct ItutT35 { 139 char country_code; 140 char country_code_extension_byte; 141 char *payload_bytes; 142 int payload_size; 143 } itut_t35; 144 }; 145 146 oapvd_t mDecHandle; 147 oapvm_t mMetadataHandle; 148 oapv_frms_t mOutFrames; 149 150 int mOutCsp; 151 152 void getVuiParams(const std::unique_ptr<C2Work> &work); 153 void getHdrInfo(struct ApvHdrInfo *buffer, int id); 154 void getHDRStaticParams(const struct ApvHdrInfo *buffer, const std::unique_ptr<C2Work>& work); 155 void getHDR10PlusInfoData(const struct ApvHdrInfo *buffer, const std::unique_ptr<C2Work>& work); 156 157 C2_DO_NOT_COPY(C2SoftApvDec); 158 }; 159 160 } // namespace android 161 162 #endif 163