blob: fc4ad7d264fd551f0fa2eedae47949bcf1a8a5a7 [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
Fyodor Kyslovdd7d5992024-11-05 21:40:16 +000068 void ColorConvertP010ToYUV422P10le(const C2GraphicView* const input, oapv_imgb_t* imgb);
Fyodor Kyslovdd7d5992024-11-05 21:40:16 +000069
70 void createCsdData(const std::unique_ptr<C2Work>& work, oapv_bitb_t* bitb,
71 uint32_t encodedSize);
72
73 std::shared_ptr<IntfImpl> mIntf;
74 int32_t mBitDepth;
75 int32_t mColorFormat;
76
77 bool mStarted;
78 bool mSignalledEos;
79 bool mSignalledError;
80
81 std::shared_ptr<C2StreamBitrateInfo::output> mBitrate;
82 std::shared_ptr<C2StreamPictureSizeInfo::input> mSize;
83 std::shared_ptr<C2StreamFrameRateInfo::output> mFrameRate;
84 std::shared_ptr<C2StreamProfileLevelInfo::output> mProfileLevel;
85 std::shared_ptr<C2StreamColorAspectsInfo::input> mColorAspects;
86 std::shared_ptr<C2StreamColorAspectsInfo::output> mCodedColorAspects;
87 std::shared_ptr<C2StreamPictureQuantizationTuning::output> mPictureQuantization;
88 std::shared_ptr<C2StreamQualityTuning::output> mQuality;
89 std::shared_ptr<C2StreamBitrateModeTuning::output> mBitrateMode;
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;
Fyodor Kyslovdd7d5992024-11-05 21:40:16 +0000107 bool mReceivedFirstFrame = false;
108 C2_DO_NOT_COPY(C2SoftApvEnc);
109};
110} // namespace android
111
112#endif // ANDROID_C2_SOFT_APV_ENC_H_