• 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 VIDEODEC_SAMPLE_H
17 #define VIDEODEC_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_avmemory.h"
33 #include "nocopyable.h"
34 #include "securec.h"
35 #include "window.h"
36 #include "iconsumer_surface.h"
37 
38 namespace OHOS {
39 namespace Media {
40 
41 class TestConsumerListener : public IBufferConsumerListener {
42 public:
43     TestConsumerListener(sptr<Surface> cs, std::string_view name);
44     ~TestConsumerListener();
45     void OnBufferAvailable() override;
46 
47 private:
48     int64_t timestamp_ = 0;
49     OHOS::Rect damage_ = {};
50     sptr<Surface> cs_ = nullptr;
51     std::unique_ptr<std::ofstream> outDir_;
52 };
53 
54 class VDecSignal {
55 public:
56     std::mutex inMutex_;
57     std::mutex outMutex_;
58     std::condition_variable inCond_;
59     std::condition_variable outCond_;
60     std::queue<uint32_t> inQueue_;
61     std::queue<uint32_t> outQueue_;
62     std::queue<OH_AVCodecBufferAttr> attrQueue_;
63     std::queue<OH_AVMemory *> inBufferQueue_;
64     std::queue<OH_AVMemory *> outBufferQueue_;
65 };
66 
67 class VDecFuzzSample : public NoCopyable {
68 public:
69     VDecFuzzSample() = default;
70     ~VDecFuzzSample();
71     int32_t SetParameter();
72     int32_t ProceFunc();
73     void PrepareResource();
74     void RunVideoDec();
75     void FormatChangeInputFunc();
76     void OutputFunc();
77     int32_t SwitchSurface();
78     int32_t CheckCodecStatus();
79     bool isSurfaceMode = true;
80 
81 protected:
82     std::atomic<bool> isRunning_ = false;
83     std::unique_ptr<std::ifstream> testFile_;
84     std::unique_ptr<std::ofstream> outFile_;
85     std::unique_ptr<std::thread> inputLoop_;
86     std::unique_ptr<std::thread> outputLoop_;
87 
88     struct OH_AVCodecAsyncCallback cb_;
89     std::shared_ptr<VDecSignal> signal_ = nullptr;
90     OH_AVCodec *videoDec_ = nullptr;
91     OH_AVFormat *format_ = nullptr;
92     bool isFirstFrame_ = true;
93     uint32_t frameCount_ = 0;
94     sptr<Surface> surface_ = nullptr;
95 };
96 } // namespace Media
97 } // namespace OHOS
98 #endif // VIDEODEC_SAMPLE_H