/* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ANDROID_C2_SOFT_AV1_ENC_H_ #define ANDROID_C2_SOFT_AV1_ENC_H_ #include #include #include #include #include #include #include "aom/aom_encoder.h" #include "aom/aomcx.h" #include "common/av1_config.h" namespace android { struct C2SoftAomEnc : public SimpleC2Component { class IntfImpl; C2SoftAomEnc(const char* name, c2_node_id_t id, const std::shared_ptr& intfImpl); // From SimpleC2Component c2_status_t onInit() override final; c2_status_t onStop() override final; void onReset() override final; void onRelease() override final; c2_status_t onFlush_sm() override final; void process(const std::unique_ptr& work, const std::shared_ptr& pool) override final; c2_status_t drain(uint32_t drainMode, const std::shared_ptr& pool) override final; protected: virtual ~C2SoftAomEnc(); private: std::shared_ptr mIntf; // Initializes aom encoder with available settings. status_t initEncoder(); // aom specific opaque data structure that // stores encoder state aom_codec_ctx_t* mCodecContext; // aom specific data structure that // stores encoder configuration aom_codec_enc_cfg_t* mCodecConfiguration; // aom specific read-only data structure // that specifies algorithm interface aom_codec_iface_t* mCodecInterface; // align stride to the power of 2 int32_t mStrideAlign; aom_rc_mode mBitrateControlMode; // Minimum (best quality) quantizer uint32_t mMinQuantizer; // Maximum (worst quality) quantizer uint32_t mMaxQuantizer; // Last input buffer timestamp uint64_t mLastTimestamp; // Number of input frames int64_t mNumInputFrames; // Conversion buffer is needed to input to // yuv420 planar format. MemoryBlock mConversionBuffer; // Signalled End Of Stream bool mSignalledOutputEos; // Signalled Error bool mSignalledError; bool mHeadersReceived; bool mIs10Bit; uint32_t mAV1EncLevel; std::shared_ptr mSize; std::shared_ptr mIntraRefresh; std::shared_ptr mFrameRate; std::shared_ptr mBitrate; std::shared_ptr mQuality; std::shared_ptr mComplexity; std::shared_ptr mBitrateMode; std::shared_ptr mRequestSync; std::shared_ptr mColorAspects; std::shared_ptr mQpBounds; aom_codec_err_t setupCodecParameters(); }; class C2SoftAomEnc::IntfImpl : public SimpleInterface::BaseParams { public: explicit IntfImpl(const std::shared_ptr& helper); static C2R BitrateSetter(bool mayBlock, C2P& me); static C2R SizeSetter(bool mayBlock, const C2P& oldMe, C2P& me); static C2R ProfileLevelSetter(bool mayBlock, C2P& me, const C2P& size, const C2P& frameRate, const C2P& bitrate); static C2R PictureQuantizationSetter(bool mayBlock, C2P &me); // unsafe getters std::shared_ptr getSize_l() const { return mSize; } std::shared_ptr getIntraRefresh_l() const { return mIntraRefresh; } std::shared_ptr getFrameRate_l() const { return mFrameRate; } std::shared_ptr getBitrate_l() const { return mBitrate; } std::shared_ptr getQuality_l() const { return mQuality; } std::shared_ptr getComplexity_l() const { return mComplexity; } std::shared_ptr getBitrateMode_l() const { return mBitrateMode; } std::shared_ptr getRequestSync_l() const { return mRequestSync; } std::shared_ptr getCodedColorAspects_l() const { return mCodedColorAspects; } std::shared_ptr getPixelFormat_l() const { return mPixelFormat; } std::shared_ptr getPictureQuantization_l() const { return mPictureQuantization; } uint32_t getSyncFramePeriod() const; static C2R ColorAspectsSetter(bool mayBlock, C2P& me); static C2R CodedColorAspectsSetter(bool mayBlock, C2P& me, const C2P& coded); uint32_t getLevel_l() const; private: std::shared_ptr mUsage; std::shared_ptr mSize; std::shared_ptr mFrameRate; std::shared_ptr mIntraRefresh; std::shared_ptr mRequestSync; std::shared_ptr mSyncFramePeriod; std::shared_ptr mBitrate; std::shared_ptr mQuality; std::shared_ptr mComplexity; std::shared_ptr mBitrateMode; std::shared_ptr mProfileLevel; std::shared_ptr mColorAspects; std::shared_ptr mCodedColorAspects; std::shared_ptr mPixelFormat; std::shared_ptr mPictureQuantization; }; } // namespace android #endif // ANDROID_C2_SOFT_AV1_ENC_H_