1 /*
2  * Copyright (c) 2020-2021 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 TEST_PLAY_FILE_H265_H
16 #define TEST_PLAY_FILE_H265_H
17 
18 #include <cstdio>
19 #include <fstream>
20 #include <mutex>
21 #include <queue>
22 
23 #include "codec_type.h"
24 #include "hal_display.h"
25 
26 #define FILENAME (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
27 #define DEMO_LOG(format, ...) printf("%s[%s:%d]" format "\n", __func__, (FILENAME), __LINE__, ##__VA_ARGS__)
28 
29 constexpr uint32_t PARAM_MAX_NUM = 10;
30 constexpr int32_t DEMO_OK = 0;
31 constexpr int32_t DEMO_ERR = -1;
32 
33 class PlayManager {
34 public:
35     PlayManager();
36     ~PlayManager();
37     void Display(CODEC_HANDLETYPE decoderHdl);
GetCnt()38     bool GetCnt() const
39     {
40         return frameCnt_;
41     }
42 
43 private:
44     std::queue<OutputInfo *> playQ_ = {};
45     HalVideoOutputHdl voHdl_ = 0;
46     int64_t frameCnt_ = 0;
47 
48     int32_t InitVideoOutput();
49     int32_t DeinitVideoOutput();
50     int32_t Write2VideoDevice(OutputInfo &outputInfo);
51 };
52 
53 class DecodeManager {
54 public:
55     DecodeManager();
56     ~DecodeManager();
57     int32_t DecodePack(uint8_t *addr, uint32_t len, uint64_t timeStampUs);
GetHdl()58     CODEC_HANDLETYPE GetHdl() const
59     {
60         return decoderHdl_;
61     }
GetCnt()62     bool GetCnt() const
63     {
64         return frameCnt_;
65     }
66 
67 private:
68     CODEC_HANDLETYPE decoderHdl_;
69     int64_t frameCnt_ = 0;
70 
71     int32_t DecoderCreate();
72     void DecoderDestroy();
73 };
74 
75 #endif // TEST_PLAY_FILE_H265_H