blob: 441c663357077d88cb062a568d06b29f8124278c [file] [log] [blame]
Fyodor Kyslovdd7d5992024-11-05 21:40:16 +00001/*
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
27namespace android {
28
29#define CODEC_MAX_CORES 4
30
31#define APV_QP_MIN 1
32#define APV_QP_MAX 51
33
Fyodor Kyslov3fea66b2024-11-08 18:32:26 +000034struct C2SoftApvEnc final : public SimpleC2Component {
Fyodor Kyslovdd7d5992024-11-05 21:40:16 +000035 class IntfImpl;
36
37 C2SoftApvEnc(const char* name, c2_node_id_t id, const std::shared_ptr<IntfImpl>& intfImpl);
Fyodor Kyslov3fea66b2024-11-08 18:32:26 +000038 virtual ~C2SoftApvEnc();
Fyodor Kyslovdd7d5992024-11-05 21:40:16 +000039
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 C2Config::level_t decisionApvLevel(int32_t width, int32_t height, int32_t fps, int32_t bitrate,
64 int32_t band);
65
66 void showEncoderParams(oapve_cdesc_t* cdsc);
67
68 void ColorConvertNv12ToP210(const C2GraphicView* const input, oapv_imgb_t* imgb);
69 void ColorConvertP010ToYUV422P10le(const C2GraphicView* const input, oapv_imgb_t* imgb);
70 void ColorConvertP010ToP210(const C2GraphicView* const input, oapv_imgb_t* imgb);
71
72 void createCsdData(const std::unique_ptr<C2Work>& work, oapv_bitb_t* bitb,
73 uint32_t encodedSize);
74
75 std::shared_ptr<IntfImpl> mIntf;
76 int32_t mBitDepth;
77 int32_t mColorFormat;
78
79 bool mStarted;
80 bool mSignalledEos;
81 bool mSignalledError;
82
83 std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;
84 std::shared_ptr<C2StreamPictureSizeInfo::input> mSize;
85 std::shared_ptr<C2StreamFrameRateInfo::output> mFrameRate;
86 std::shared_ptr<C2StreamProfileLevelInfo::output> mProfileLevel;
87 std::shared_ptr<C2StreamColorAspectsInfo::input> mColorAspects;
88 std::shared_ptr<C2StreamColorAspectsInfo::output> mCodedColorAspects;
89 std::shared_ptr<C2StreamPictureQuantizationTuning::output> mPictureQuantization;
90 std::shared_ptr<C2StreamQualityTuning::output> mQuality;
91 std::shared_ptr<C2StreamBitrateModeTuning::output> mBitrateMode;
92 std::shared_ptr<C2LinearBlock> mOutBlock;
93 std::shared_ptr<C2StreamComplexityTuning::output> mComplexity;
94 std::shared_ptr<C2StreamPixelFormatInfo::input> mPixelFormat;
95
96 std::map<const void*, std::shared_ptr<C2Buffer>> mBuffers;
97 MemoryBlockPool mConversionBuffers;
98 std::map<const void*, MemoryBlock> mConversionBuffersInUse;
99
100 bool mInitEncoder;
101 int32_t mMaxFrames;
102 int32_t mReceivedFrames;
103 std::unique_ptr<oapve_cdesc_t> mCodecDesc;
104 oapv_frms_t mInputFrames;
105 oapv_frms_t mReconFrames;
106 oapve_t mEncoderId;
107 oapvm_t mMetaId;
108 uint8_t* mBitstreamBuf = nullptr;
109 std::vector<uint16_t> mSdrToHdrMapping;
110 bool mReceivedFirstFrame = false;
111 C2_DO_NOT_COPY(C2SoftApvEnc);
112};
113} // namespace android
114
115#endif // ANDROID_C2_SOFT_APV_ENC_H_