forked from zillevdr/vdr-plugin-softhddevice-drm
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathh264parser.h
More file actions
131 lines (116 loc) · 3.55 KB
/
h264parser.h
File metadata and controls
131 lines (116 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// SPDX-License-Identifier: AGPL-3.0-or-later
/**
* @file h264parser.h
* H.264 Parser Header File
*
* @copyright 2025 - 2026 by Andreas Baierl. All Rights Reserved.
*
* @license{AGPL-3.0-or-later}
*/
#ifndef __H264PARSER_H
#define __H264PARSER_H
#include <set>
#include <string>
#include <vector>
extern "C" {
#include <libavcodec/avcodec.h>
}
/**
* H.264 Nal unit types
*
* @ingroup misc
*/
typedef enum {
NALU_TYPE_NON_IDR = (1 << 0),
NALU_TYPE_PART_A = (1 << 1),
NALU_TYPE_PART_B = (1 << 2),
NALU_TYPE_PART_C = (1 << 3),
NALU_TYPE_IDR = (1 << 4),
NALU_TYPE_SEI = (1 << 5),
NALU_TYPE_SPS = (1 << 6),
NALU_TYPE_PPS = (1 << 7),
NALU_TYPE_AUD = (1 << 8)
} NalUnitTypes;
/**
* H.264 Parser
*
* @ingroup misc
*/
class cH264Parser {
private:
struct RefPicMod {
int list;
int idc;
int abs_diff_pic_num_minus1;
int long_term_pic_num;
};
public:
cH264Parser(AVPacket *, int, int, int);
void BuildInvalidReferenceString(int);
void BuildValidReferenceString(void);
void AddFrameNumber(int);
void AddInvalidReference(int, int);
void AddValidReference(int);
void PrintNalUnits(void);
void PrintStreamData(void);
std::string GetNalUnitString(void) { return m_naluString; };
int GetWidth(void) { return m_width; };
int GetHeight(void) { return m_height; };
bool IsMbaff(void) { return m_mbaff; };
bool HasSPS(void) { return m_hasSPS; };
bool HasPPS(void) { return m_hasPPS; };
bool IsPSlice() const { return m_sliceType == 0; }
bool IsBSlice() const { return m_sliceType == 1; }
bool IsISlice() const { return m_sliceType == 2; }
bool IsIDR() const { return m_isIDR; }
bool IsReference() const { return m_isReference; }
int GetFrameNum() const { return m_frameNum; }
const std::vector<RefPicMod>& GetRefMods() const { return m_refMods; }
int GetLog2MaxFrameNumMinus4() const { return m_log2MaxFrameNumMinus4; }
int GetPpsNumRefIdxL0DefaultActiveMinus1(void) { return m_ppsNumRefIdxL0DefaultActiveMinus1; };
int GetPpsNumRefIdxL1DefaultActiveMinus1(void) { return m_ppsNumRefIdxL1DefaultActiveMinus1; };
int GetNumRefIdxL0Active(void) { return m_numRefIdxL0Active; };
int GetNumRefIdxL1Active(void) { return m_numRefIdxL1Active; };
bool HasInvalidReferences(void) { return m_hasInvalidReferences; };
bool HasInvalidBackwardReferences(void) { return m_hasInvalidBackwardReferences; };
bool HasParseError(void) const { return m_parseError; };
private:
AVPacket *m_pAvpkt;
const unsigned char *m_pStart;
std::vector<uint8_t> m_rbsp;
unsigned short m_nLength;
int m_nCurrentBit;
int m_nalutype = 0;
int m_width = 0;
int m_height = 0;
bool m_hasSPS = false;
bool m_hasPPS = false;
bool m_isIDR = false;
bool m_isReference = false;
bool m_mbaff = false;
bool m_parseError = false;
std::string m_naluString;
int m_sliceType = -1; // normalized: 0=P, 2=I
int m_frameNum = -1;
int m_nalRefIdc = 0;
std::set<int> m_invalidReferences;
std::set<int> m_validReferences;
std::vector<RefPicMod> m_refMods;
bool m_hasInvalidReferences = false;
bool m_hasInvalidBackwardReferences = false;
bool m_hasValidReferences = false;
int m_log2MaxFrameNumMinus4 = -4; // saved from SPS
int m_ppsNumRefIdxL0DefaultActiveMinus1 = -1; // saved from PPS
int m_ppsNumRefIdxL1DefaultActiveMinus1 = -1; // saved from PPS
int m_numRefIdxL0Active;
int m_numRefIdxL1Active;
unsigned int ReadBit(void);
unsigned int ReadBits(int);
unsigned int ReadExponentialGolombCode(void);
unsigned int ReadSE(void);
int GetSPSOffset(void);
int GetPPSOffset(void);
int GetSliceOffset(void);
void ConvertEBSPtoRBSP(const uint8_t *, int);
};
#endif