1 /*
2  * Copyright (C) 2023 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 HDRCODEC_SAMPLE_H
17 #define HDRCODEC_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 "native_avcodec_videoencoder.h"
32 #include "nocopyable.h"
33 #include "native_avmemory.h"
34 #include "native_avformat.h"
35 #include "native_averrors.h"
36 #include "surface/window.h"
37 
38 namespace OHOS {
39 namespace Media {
40 class VSignal {
41 public:
42     std::mutex inMutex_;
43     std::mutex outMutex_;
44     std::condition_variable inCond_;
45     std::condition_variable outCond_;
46     std::queue<uint32_t> inIdxQueue_;
47     std::queue<uint32_t> outIdxQueue_;
48     std::queue<OH_AVCodecBufferAttr> attrQueue_;
49     std::queue<OH_AVMemory *> inBufferQueue_;
50     std::queue<OH_AVMemory *> outBufferQueue_;
51 };
52 
53 class HDRCodecNdkSample : public NoCopyable {
54 public:
55     HDRCodecNdkSample() = default;
56     ~HDRCodecNdkSample();
57     int32_t CreateCodec();
58     int32_t Configure();
59     int32_t Start();
60     int32_t Release();
61     void WaitForEos();
62     void ReleaseInFile();
63     void StopInloop();
64     void InputFunc();
65     void FlushBuffer();
66     void SwitchInputFile();
67     int32_t ReConfigure();
68     int32_t RepeatCall();
69     const char *INP_DIR = "/data/test/media/1920_1080_10_30Mb.h264";
70     bool needEncode = false;
71     bool needTransCode = false;
72     uint32_t DEFAULT_WIDTH = 3840;
73     uint32_t DEFAULT_HEIGHT = 2160;
74     double DEFAULT_FRAME_RATE = 30.0;
75 
76     uint32_t REPEAT_START_STOP_BEFORE_EOS = 0;  // 1200 测试用例
77     uint32_t REPEAT_START_FLUSH_BEFORE_EOS = 0; // 1300 测试用例
78     uint32_t REPEAT_START_FLUSH_STOP_BEFORE_EOS = 0;
79     uint32_t frameCount_ = 0;
80     uint32_t repeat_time = 0;
81     uint32_t frameCountDec = 0;
82     uint32_t frameCountEnc = 0;
83     int32_t DEFAULT_PROFILE = HEVC_PROFILE_MAIN_10;
84     bool needOutputFile;
85     VSignal *decSignal;
86     std::unique_ptr<std::thread> inputLoop_;
87     OH_AVCodec *vdec_;
88     OH_AVCodec *venc_;
89     uint32_t errorCount = 0;
90 private:
91     OHNativeWindow *window = nullptr;
92     OH_AVCodecAsyncCallback encCb_;
93     OH_AVCodecAsyncCallback decCb_;
94 };
95 } // namespace Media
96 } // namespace OHOS
97 
98 #endif
99