• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef VIDEOENC_API11_SAMPLE_H
17 #define VIDEOENC_API11_SAMPLE_H
18 
19 #include <iostream>
20 #include <cstdio>
21 #include <unistd.h>
22 #include <atomic>
23 #include <fstream>
24 #include <thread>
25 #include <mutex>
26 #include <queue>
27 #include <string>
28 #include <unordered_map>
29 #include "securec.h"
30 #include "native_avcodec_videoencoder.h"
31 #include "nocopyable.h"
32 #include "native_avbuffer.h"
33 #include "native_avformat.h"
34 #include "native_averrors.h"
35 #include "window.h"
36 #include "media_description.h"
37 #include "av_common.h"
38 #include "external_window.h"
39 #include "native_buffer.h"
40 namespace OHOS {
41 namespace Media {
42 class VEncSyncSample : public NoCopyable {
43 public:
44     VEncSyncSample() = default;
45     ~VEncSyncSample();
46     uint32_t defaultWidth = 1280;
47     uint32_t defaultHeight = 720;
48     uint32_t defaultBitrate = 5000000;
49     uint32_t defaultQuality = 30;
50     double defaultFrameRate = 30.0;
51     bool isAVCEncoder = true;
52     const uint8_t *fuzzData;
53     int32_t maxFrameInput = 20;
54     size_t fuzzSize;
55     OH_HEVCProfile hevcProfile = HEVC_PROFILE_MAIN;
56     OH_AVCProfile avcProfile = AVC_PROFILE_BASELINE;
57     int32_t defaultQp = 20;
58     uint32_t DEFAULT_BITRATE_MODE = CBR;
59     OH_AVPixelFormat DEFAULT_PIX_FMT = AV_PIXEL_FORMAT_NV12;
60     uint32_t defaultKeyFrameInterval = 1000;
61     uint32_t defaultRangeFlag = 0;
62     uint32_t DEFAULT_COLOR_PRIMARIES = COLOR_PRIMARY_BT709;
63     uint32_t DEFAULT_TRANSFER_CHARACTERISTICS = TRANSFER_CHARACTERISTIC_BT709;
64     uint32_t DEFAULT_MATRIX_COEFFICIENTS = MATRIX_COEFFICIENT_BT709;
65     int32_t enbleBFrameMode = 0;
66     int32_t CreateVideoEncoder(const char *codecName);
67     int32_t ConfigureVideoEncoder();
68     int32_t ConfigureVideoEncoderFuzz(int32_t data);
69     int32_t CreateSurface();
70     int64_t GetSystemTimeUs();
71     int32_t Start();
72     int32_t Stop();
73     int32_t Release();
74     int32_t SetParameter(int32_t data);
75     void SyncInputFuncFuzz();
76     void InputFuncSurfaceFuzz();
77     void SyncOutputFuncFuzz();
78     uint32_t FlushSurf(OHNativeWindowBuffer *ohNativeWindowBuffer, OH_NativeBuffer *nativeBuffer);
79     uint32_t errCount = 0;
80     int32_t frameCount = 0;
81     int32_t codecType = 0;
82     bool sleepOnFPS = false;
83     bool surfInput = false;
84     bool enableColorSpaceParams = false;
85     bool enableQP = false;
86     bool enableLTR = false;
87     bool fuzzMode = false;
88     bool enableRepeat = false;
89     bool setMaxCount = false;
90     int32_t defaultFrameAfter = 1;
91     int32_t defaultMaxCount = 1;
92     int32_t enbleSyncMode = 0;
93     int64_t syncInputWaitTime = -1;
94     int64_t syncOutputWaitTime = -1;
95     std::atomic<bool> isRunning_ { false };
96     int32_t frameIndex_ = 0;
97 private:
98     OH_AVCodec *venc_;
99     OHNativeWindow *nativeWindow;
100 };
101 } // namespace Media
102 } // namespace OHOS
103 
104 #endif // VIDEOENC_API11_SAMPLE_H
105