• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 VIDEODEC_API11_SAMPLE_H
17 #define VIDEODEC_API11_SAMPLE_H
18 
19 #include <atomic>
20 #include <cstdio>
21 #include <fstream>
22 #include <iostream>
23 #include <mutex>
24 #include <queue>
25 #include <string>
26 #include <thread>
27 #include <unistd.h>
28 #include <unordered_map>
29 #include "native_avcodec_videodecoder.h"
30 #include "native_averrors.h"
31 #include "native_avformat.h"
32 #include "native_avbuffer.h"
33 #include "nocopyable.h"
34 #include "securec.h"
35 #include "window.h"
36 #include "iconsumer_surface.h"
37 namespace OHOS {
38 namespace Media {
39 class VDecSignal {
40 public:
41     std::mutex inMutex_;
42     std::mutex outMutex_;
43     std::condition_variable inCond_;
44     std::condition_variable outCond_;
45     std::queue<uint32_t> inIdxQueue_;
46     std::queue<uint32_t> outIdxQueue_;
47     std::queue<OH_AVBuffer *> inBufferQueue_;
48 };
49 
50 class VDecApi11FuzzSample : public NoCopyable {
51 public:
52     VDecApi11FuzzSample() = default;
53     ~VDecApi11FuzzSample();
54     int32_t RunVideoDec(std::string codeName = "");
55     const char *inpDir = "/data/test/media/1280_720_30_10Mb.h264";
56     const char *outDir = "/data/test/media/VDecTest.yuv";
57     uint32_t defaultWidth = 1920;
58     uint32_t defaultHeight = 1080;
59     uint32_t defaultFrameRate = 30;
60     uint32_t defaultRotation = 0;
61     uint32_t defaultPixelFormat = AV_PIXEL_FORMAT_NV12;
62     uint32_t frameCount_ = 0;
63     int enbleBlankFrame = 0;
64     int32_t Start();
65     int32_t Stop();
66     int32_t Flush();
67     int32_t Reset();
68     void SetEOS(OH_AVBuffer *buffer, uint32_t index);
69     void WaitForEOS();
70     int32_t ConfigureVideoDecoder();
71     int32_t StartVideoDecoder();
72     int64_t GetSystemTimeUs();
73     int32_t CreateVideoDecoder();
74     int32_t SetVideoDecoderCallback();
75     int32_t Release();
76     void InputFuncTest();
77     void OutputFuncTest();
78     void ReleaseInFile();
79     void StopInloop();
80     int32_t PushData(uint32_t index, OH_AVBuffer *buffer);
81     uint32_t SendData(uint32_t bufferSize, uint32_t index, OH_AVBuffer *buffer);
82     void SetParameter(int32_t data);
83     OH_AVErrCode InputFuncFUZZ(const uint8_t *data, size_t size);
84     void ReleaseSignal();
85     VDecSignal *signal_;
86     uint32_t errCount = 0;
87     bool isSurfMode = false;
88     bool setParameters = false;
89     bool isRenderAttime = false;
90     int64_t renderTimestampNs = 0;
91     OH_AVCodec *vdec_;
92     OHNativeWindow *nativeWindow = nullptr;
93     sptr<Surface> cs = nullptr;
94     sptr<Surface> ps = nullptr;
95     std::atomic<bool> isRunning_ { false };
96 private:
97     std::unique_ptr<std::ifstream> inFile_;
98     std::unique_ptr<std::thread> inputLoop_;
99     std::unordered_map<uint32_t, OH_AVBuffer *> inBufferMap_;
100     std::unordered_map<uint32_t, OH_AVBuffer *> outBufferMap_;
101     OH_AVCodecCallback cb_;
102     int64_t timeStamp_ { 0 };
103     int64_t lastRenderedTimeUs_ { 0 };
104     bool isFirstFrame_ = true;
105 };
106 } // namespace Media
107 } // namespace OHOS
108 
109 void VdecError(OH_AVCodec *codec, int32_t errorCode, void *userData);
110 void VdecFormatChanged(OH_AVCodec *codec, OH_AVFormat *format, void *userData);
111 void VdecInputDataReady(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData);
112 void VdecOutputDataReady(OH_AVCodec *codec, uint32_t index, OH_AVBuffer *buffer, void *userData);
113 #endif // VIDEODEC_SAMPLE_H
114