• 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_inner.h"
40 namespace OHOS {
41 namespace Media {
42 class VEncSignal {
43 public:
44     std::mutex inMutex_;
45     std::condition_variable inCond_;
46     std::queue<uint32_t> inIdxQueue_;
47     std::queue<OH_AVBuffer *> inBufferQueue_;
48     int count = 0;
49 };
50 
51 class VEncAPI11FuzzSample : public NoCopyable {
52 public:
53     VEncAPI11FuzzSample() = default;
54     ~VEncAPI11FuzzSample();
55     uint32_t defaultWidth = 1280;
56     uint32_t defaultHeight = 720;
57     uint32_t defaultBitRate = 5000000;
58     uint32_t defaultQuality = 30;
59     double defaultFrameRate = 30.0;
60     uint32_t maxFrameInput = 20;
61     int32_t defaultQP = 20;
62     uint32_t defaultBitRateMode = CBR;
63     OH_AVPixelFormat defaultPixFmt = AV_PIXEL_FORMAT_NV12;
64     uint32_t defaultKeyFrameInterval = 1000;
65     const uint8_t *fuzzData;
66     size_t fuzzSize;
67     int32_t CreateVideoEncoder(const char *codecName);
68     int32_t ConfigureVideoEncoder();
69     int32_t SetVideoEncoderCallback();
70     int32_t StartVideoEncoder();
71     void GetStride();
72     void WaitForEOS();
73     int64_t GetSystemTimeUs();
74     int32_t Start();
75     int32_t Flush();
76     int32_t Reset();
77     int32_t Stop();
78     int32_t Release();
79     void SetEOS(uint32_t index, OH_AVBuffer *buffer);
80     void InputFunc();
81     void ReleaseInFile();
82     void ReleaseSignal();
83     void StopInloop();
84     VEncSignal *signal_;
85     uint32_t frameCount = 0;
86     bool sleepOnFPS = false;
87     bool surfInput = false;
88     std::atomic<bool> isRunning_{false};
89 
90 private:
91     std::unique_ptr<std::thread> inputLoop_;
92     OH_AVCodec *venc_;
93     OH_AVCodecCallback cb_;
94     int stride_;
95 };
96 } // namespace Media
97 } // namespace OHOS
98 
99 #endif // VIDEOENC_API11_SAMPLE_H
100