• 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_API11_SAMPLE_H
17 #define VIDEODEC_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_videodecoder.h"
31 #include "nocopyable.h"
32 #include "native_avmemory.h"
33 #include "native_avformat.h"
34 #include "native_averrors.h"
35 #include "window.h"
36 #include "iconsumer_surface.h"
37 
38 namespace OHOS {
39 namespace Media {
40 
41 class VDecSyncSample : public NoCopyable {
42 public:
43     VDecSyncSample() = default;
44     ~VDecSyncSample();
45     const char *outDir = "/data/test/media/VDecTest.yuv";
46     const char *outDir2 = "/data/test/media/VDecTest2.yuv";
47     bool sfOutput = false;
48     bool transferFlag = false;
49     bool nV21Flag = false;
50     uint32_t defaultWidth = 1920;
51     uint32_t defaultHeight = 1080;
52     uint32_t originalWidth = 0;
53     uint32_t originalHeight = 0;
54     int enbleBlankFrame = 0;
55     uint32_t defualtPixelFormat = AV_PIXEL_FORMAT_NV12;
56     int maxSurfNum = 2;
57     int32_t codecType = 0;
58     double defaultFrameRate = 30.0;
59     // 解码输出数据预期
60     bool enableVRR = false;
61     bool enableLowLatency = false;
62     int32_t enbleSyncMode = 0;
63     int64_t syncInputWaitTime = -1;
64     int64_t syncOutputWaitTime = -1;
65     int32_t Start();
66     int32_t Stop();
67     int32_t Flush();
68     int32_t Reset();
69     int32_t ConfigureVideoDecoder();
70     int64_t GetSystemTimeUs();
71     int32_t CreateVideoDecoder(std::string codeName);
72     int32_t Release();
73     int32_t SyncInputFuncFuzz(const uint8_t *data, size_t size);
74     int32_t SyncOutputFuncFuzz();
75     void CreateSurface();
76     void ReleaseInFile();
77     bool isRenderAttime = false;
78     uint32_t errCount = 0;
79     int64_t renderTimestampNs = 0;
80     int32_t maxInputSize = 0;
81     bool autoSwitchSurface = false;
82     std::atomic<bool> isFlushing_ { false };
83     std::atomic<bool> isRunning_ { false };
84     bool useHDRSource = false;
85     int32_t DEFAULT_PROFILE = HEVC_PROFILE_MAIN_10;
86     int32_t DecodeSetSurface();
87     void SetParameter(int32_t data);
88 private:
89     std::unique_ptr<std::ifstream> inFile_;
90     OH_AVCodec *vdec_;
91     OHNativeWindow *nativeWindow[2] = {};
92     sptr<Surface> cs[2] = {};
93     sptr<Surface> ps[2] = {};
94 };
95 } // namespace Media
96 } // namespace OHOS
97 #endif // VIDEODEC_SAMPLE_H
98