1 /* 2 * Copyright 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_ENC_H_ 18 #define ANDROID_C2_SOFT_APV_ENC_H_ 19 20 #include <SimpleC2Component.h> 21 #include <utils/Vector.h> 22 #include <map> 23 #include "oapv.h" 24 25 #include <C2SoftApvCommon.h> 26 27 namespace android { 28 29 #define CODEC_MAX_CORES 4 30 31 #define APV_QP_MIN 1 32 #define APV_QP_MAX 51 33 34 struct C2SoftApvEnc final : public SimpleC2Component { 35 class IntfImpl; 36 37 C2SoftApvEnc(const char* name, c2_node_id_t id, const std::shared_ptr<IntfImpl>& intfImpl); 38 virtual ~C2SoftApvEnc(); 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 c2_status_t reset(); 52 c2_status_t initEncoder(); 53 c2_status_t releaseEncoder(); 54 c2_status_t setEncodeArgs(oapv_frms_t* imgb_inp, const C2GraphicView* const input, 55 uint64_t workIndex); 56 void finishWork(uint64_t workIndex, const std::unique_ptr<C2Work>& work, 57 const std::shared_ptr<C2BlockPool>& pool, oapv_bitb_t* bitb, 58 oapve_stat_t* stat); 59 c2_status_t drainInternal(uint32_t drainMode, const std::shared_ptr<C2BlockPool>& pool, 60 const std::unique_ptr<C2Work>& work); 61 void setParams(oapve_param_t& param); 62 int32_t getQpFromQuality(int quality); 63 64 void showEncoderParams(oapve_cdesc_t* cdsc); 65 66 void ColorConvertP010ToYUV422P10le(const C2GraphicView* const input, oapv_imgb_t* imgb); 67 68 void createCsdData(const std::unique_ptr<C2Work>& work, oapv_bitb_t* bitb, 69 uint32_t encodedSize); 70 71 std::shared_ptr<IntfImpl> mIntf; 72 int32_t mBitDepth; 73 int32_t mColorFormat; 74 75 bool mStarted; 76 bool mSignalledEos; 77 bool mSignalledError; 78 79 std::shared_ptr<C2StreamBitrateInfo::output> mBitrate; 80 std::shared_ptr<C2StreamPictureSizeInfo::input> mSize; 81 std::shared_ptr<C2StreamFrameRateInfo::output> mFrameRate; 82 std::shared_ptr<C2StreamProfileLevelInfo::output> mProfileLevel; 83 std::shared_ptr<C2StreamColorAspectsInfo::input> mColorAspects; 84 std::shared_ptr<C2StreamColorAspectsInfo::output> mCodedColorAspects; 85 std::shared_ptr<C2StreamPictureQuantizationTuning::output> mPictureQuantization; 86 std::shared_ptr<C2StreamQualityTuning::output> mQuality; 87 std::shared_ptr<C2StreamBitrateModeTuning::output> mBitrateMode; 88 std::shared_ptr<C2LinearBlock> mOutBlock; 89 std::shared_ptr<C2StreamComplexityTuning::output> mComplexity; 90 std::shared_ptr<C2StreamPixelFormatInfo::input> mPixelFormat; 91 92 std::map<const void*, std::shared_ptr<C2Buffer>> mBuffers; 93 MemoryBlockPool mConversionBuffers; 94 std::map<const void*, MemoryBlock> mConversionBuffersInUse; 95 96 bool mInitEncoder; 97 int32_t mMaxFrames; 98 int32_t mReceivedFrames; 99 std::unique_ptr<oapve_cdesc_t> mCodecDesc; 100 oapv_frms_t mInputFrames; 101 oapv_frms_t mReconFrames; 102 oapve_t mEncoderId; 103 oapvm_t mMetaId; 104 uint8_t* mBitstreamBuf = nullptr; 105 bool mReceivedFirstFrame = false; 106 C2_DO_NOT_COPY(C2SoftApvEnc); 107 }; 108 } // namespace android 109 110 #endif // ANDROID_C2_SOFT_APV_ENC_H_ 111