• 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 #ifndef VIDEO_SAMPLE_H
16 #define VIDEO_SAMPLE_H
17 #include <iostream>
18 #include <string>
19 #include <thread>
20 #include <queue>
21 #include <fstream>
22 #include <memory>
23 #include "video_processing.h"
24 #include "surface/window.h"
25 #include "native_buffer.h"
26 #include "iconsumer_surface.h"
27 #include "sync_fence.h"
28 #include "openssl/crypto.h"
29 #include "openssl/sha.h"
30 
31 typedef struct VideoProcessParam {
32     OH_NativeBuffer_Format inFmt;
33     OH_NativeBuffer_ColorSpace inColorSpace;
34     OH_NativeBuffer_Format outFmt;
35     OH_NativeBuffer_ColorSpace outColorSpace;
36 }VideoProcessParam;
37 
38 constexpr uint32_t DEFAULT_WIDTH = 3840;
39 constexpr uint32_t DEFAULT_HEIGHT = 2160;
40 namespace OHOS {
41 class VideoSample {
42 public:
43     VideoSample() = default;
44     ~VideoSample();
45     std::string inputFilePath = "";
46     std::string inputMetaPath = "";
47     std::string outputFilePath = "";
48     std::string outputMetaPath = "";
49     std::string hashValJsonPath = "/data/test/media/hash_val.json";
50     std::string DEFAULT = "default";
51     std::string defaultPixelFormat = "";
52     std::string outputPixelFormat = "";
53     std::string convertType = "";
54     bool isHDRVivid = false;
55     bool isHDRVividOut = false;
56     bool md5Equal = true;
57     bool inputFuncFinished = false;
58     bool isEOF = false;
59     uint32_t inCount = 0;
60     uint32_t outCount = 0;
61     int32_t InputFunc();
62     void OutputThread();
63     int32_t InitVideoSample(const int32_t type, int32_t width, int32_t height, VideoProcessParam param);
64     int32_t StartProcess();
65     void ProcessOutputData(SurfaceBuffer *buffer);
66     int32_t WaitAndStopSample();
67     bool MdCompare(uint8_t source[]);
68     std::vector<uint8_t> LoadHashFile();
69     int32_t errCount = 0;
70     std::queue<sptr<SurfaceBuffer>> outputBufferAvilQue_;
71     sptr<Surface> cs = nullptr;
72     bool isRunning = false;
73     std::mutex mutex2_;
74     std::mutex mutex_;
75     bool isStopped = false;
76 private:
77     void SetInputWindowParam();
78     void GetMetadata(OH_NativeBuffer *buffer);
79     void ShowHashValue(uint8_t source[]);
80     std::unique_ptr<std::ofstream> outFile;
81     int32_t width_ = 0;
82     int32_t height_ = 0;
83     VideoProcessParam param_;
84     int32_t ReadOneFrameYUV420SP(uint8_t *addr, OH_NativeBuffer_Config config);
85     int32_t ReadOneFrameP010(uint8_t *addr, OH_NativeBuffer_Config config);
86     int32_t ReadOneFrameRGBA10(uint8_t *addr, OH_NativeBuffer_Config config);
87     OH_VideoProcessing* videoProcessor = nullptr;
88     bool isMetadataGen = false;
89     OHNativeWindow *inWindow = nullptr;
90     OHNativeWindow *outWindow = nullptr;
91     std::unique_ptr<std::ifstream> inFile;
92     std::unique_ptr<std::ifstream> metaDataFile;
93     std::unique_ptr<std::thread> inputLoop_;
94     std::unique_ptr<std::thread> outputLoop_;
95     VideoProcessing_Callback* callback = nullptr;
96     struct Region region;
97     struct Region::Rect *rect;
98     uint8_t *metaData = nullptr;
99     int32_t metadataSize = 0;
100     SHA512_CTX ctx;
101     uint8_t md[SHA512_DIGEST_LENGTH];
102 };
103 }
104 #endif