1 /*
2  * Copyright (C) 2024 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 REFERENCE_PARSER_H
17 #define REFERENCE_PARSER_H
18 
19 #include <cstdint>
20 #include <vector>
21 #include <map>
22 #include <set>
23 #include <iterator>
24 #include <memory>
25 #include <utility>
26 #include <algorithm>
27 #include <iostream>
28 #include "securec.h"
29 #include "common/status.h"
30 #include "common/log.h"
31 #include "common/media_core.h"
32 
33 namespace OHOS {
34 namespace Media {
35 namespace Plugins {
36 constexpr uint8_t DEFAULT_NAL_LEN_SIZE = 4;
37 
38 enum struct CodecType : int32_t {
39     H264 = 0,
40     H265,
41 };
42 
43 enum SliceType {
44     B_SLICE = 0,
45     P_SLICE,
46     I_SLICE,
47     UNKNOWN_SLICE_TYPE,
48 };
49 
50 struct PicRefInfo {
51     uint32_t streamId = 0;
52     uint32_t poc = 0;
53     int32_t layerId = -1;
54     bool isDiscardable = false;
55     SliceType sliceType = SliceType::UNKNOWN_SLICE_TYPE;
56     std::vector<uint32_t> refList;
57 };
58 
59 class __attribute__((visibility("default"))) RefParser {
60 public:
61     virtual ~RefParser() = default;
62     virtual Status RefParserInit() = 0;
63     virtual Status ParserNalUnits(uint8_t *nalData, int32_t nalDataSize, uint32_t frameId, int64_t dts) = 0;
64     virtual Status ParserExtraData(uint8_t *extraData, int32_t extraDataSize) = 0;
65     virtual Status ParserSdtpData(uint8_t *sdtpData, int32_t sdtpDataSize) = 0;
66     virtual Status GetFrameLayerInfo(uint32_t frameId, FrameLayerInfo &frameLayerInfo) = 0;
67     virtual Status GetFrameLayerInfo(int64_t dts, FrameLayerInfo &frameLayerInfo) = 0;
68     virtual Status GetGopLayerInfo(uint32_t gopId, GopLayerInfo &gopLayerInfo) = 0;
69 };
70 
71 extern "C" __attribute__((visibility("default"))) RefParser *CreateRefParser(
72     CodecType codeType, std::vector<uint32_t> &IFramePos);
73 
74 extern "C" __attribute__((visibility("default"))) void DestroyRefParser(RefParser *refParser);
75 } // Plugins
76 } // Media
77 } // OHOS
78 #endif // REFERENCE_PARSER_H