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