MythTV  master
AVCParser.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 /*******************************************************************
3  * AVCParser
4  *
5  * Distributed as part of MythTV (www.mythtv.org)
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  ********************************************************************/
22 
23 #ifndef AVCPARSER_H
24 #define AVCPARSER_H
25 
26 #include <H2645Parser.h>
27 
28 class AVCParser : public H2645Parser
29 {
30  public:
31 
32  // ITU-T Rec. H.264 table 7-1
33  enum NAL_unit_type {
34  UNKOWN = -1,
35  SLICE = 1, // 1 - 5 are VCL NAL units
36  SLICE_DPA = 2,
37  SLICE_DPB = 3,
38  SLICE_DPC = 4,
39  SLICE_IDR = 5,
40  SEI = 6,
41  SPS = 7,
42  PPS = 8,
43  AU_DELIMITER = 9,
44  END_SEQUENCE = 10,
45  END_STREAM = 11,
46  FILLER_DATA = 12,
47  SPS_EXT = 13,
48  NALU_prefix = 14,
49  SPS_subset = 15,
50  AUXILIARY_SLICE = 19,
51  SLICE_EXTENSION = 20
52  };
53 
54  enum SEI_type {
59  };
60 
61  field_type getFieldType(void) const override;
62 
63  /*
64  slice_type values in the range 5..9 specify, in addition to the
65  coding type of the current slice, that all other slices of the
66  current coded picture shall have a value of slice_type equal to
67  the current value of slice_type or equal to the current value of
68  slice_type – 5.
69  */
70  AVCParser(void) { ; }
71  AVCParser(const AVCParser& rhs);
72  ~AVCParser(void) override { ; }
73 
74  uint32_t addBytes(const uint8_t *bytes,
75  uint32_t byte_count,
76  uint64_t stream_offset) override;
77  void Reset(void) override;
78 
79  QString NAL_type_str(int8_t type) override;
80 
81  // == NAL_type AU_delimiter: primary_pic_type = 5
82  static bool isKeySlice(uint slice_type)
83  {
84  return (slice_type == SLICE_I ||
85  slice_type == SLICE_SI ||
86  slice_type == SLICE_I_a ||
87  slice_type == SLICE_SI_a);
88  }
89 
90  static bool NALisSlice(int8_t nal_type)
91  {
92  return (nal_type == SLICE ||
93  nal_type == SLICE_DPA ||
94  nal_type == SLICE_IDR);
95  }
96 
97  void use_I_forKeyframes(bool val) { m_iIsKeyframe = val; }
98  bool using_I_forKeyframes(void) const { return m_iIsKeyframe; }
99 
100  void parse_SPS(uint8_t *sps, uint32_t sps_size,
101  bool& interlaced, int32_t& max_ref_frames);
102 
103  void reset_SPS(void) { m_seenSPS = false; }
104  bool seen_SPS(void) const { return m_seenSPS; }
105 
106  bool found_AU(void) const { return m_auPending; }
107 
108  uint8_t lastNALtype(void) const { return m_nalUnitType; }
109 
110  uint getRefFrames(void) const { return m_numRefFrames; }
111 
112  uint pictureWidthCropped(void) const override;
113  uint pictureHeightCropped(void) const override;
114 
115  double frameRate(void) const;
116  void getFrameRate(FrameRate &result) const override;
117 
118  inline void set_AU_pending(void)
119  {
120  if (!m_auPending)
121  {
122  m_auPending = true;
125  }
126  }
127 
128  protected:
129  bool new_AU(void);
130  void processRBSP(bool rbsp_complete);
131 
132  private:
133  bool decode_Header(GetBitContext *gb);
134  void decode_SPS(GetBitContext *gb);
135  void decode_PPS(GetBitContext * gb);
136  void decode_SEI(GetBitContext * gb);
137 
138 
139  int m_deltaPicOrderCntBottom {0};
140  int m_deltaPicOrderCnt[2] {0};
141  int m_frameNum {-1};
142  int m_picOrderCntLsb {0};
143  int m_picParameterSetId {-1};
145  int m_prevDeltaPicOrderCnt[2] {0};
146  int m_prevFrameNum {-1};
147  int m_prevPicOrderCntLsb {0};
148  int m_prevPicParameterSetId {-1};
149 
150  uint m_idrPicId {65536};
153  uint m_numRefFrames {0};
154  uint m_prevIdrPicId {65536};
158 
159  int8_t m_bottomFieldFlag {-1};
160  int8_t m_fieldPicFlag {-1};
161  int8_t m_frameMbsOnlyFlag {-1};
165  int8_t m_prevFieldPicFlag {-1};
168 
170  uint8_t m_nalRefIdc {111}; // != [0|1|2|3]
171  uint8_t m_picOrderCntType {0};
172  uint8_t m_prevNALRefIdc {111}; // != [0|1|2|3]
174 
176  bool m_iIsKeyframe {true};
177 };
178 
179 #endif /* AVCPARSER_H */
AVCParser::getFrameRate
void getFrameRate(FrameRate &result) const override
Definition: AVCParser.cpp:1081
AVCParser::NAL_unit_type
NAL_unit_type
Definition: AVCParser.h:52
AVCParser
Definition: AVCParser.h:29
AVCParser::SEI_FILLER_PAYLOAD
@ SEI_FILLER_PAYLOAD
Definition: AVCParser.h:75
H2645Parser::m_seenSPS
bool m_seenSPS
Definition: H2645Parser.h:188
AVCParser::m_prevDeltaPicOrderCnt
int m_prevDeltaPicOrderCnt[2]
Definition: AVCParser.h:164
AVCParser::PPS
@ PPS
Definition: AVCParser.h:80
AVCParser::m_sliceType
uint m_sliceType
Definition: AVCParser.h:176
AVCParser::END_SEQUENCE
@ END_SEQUENCE
Definition: AVCParser.h:82
AVCParser::decode_SPS
void decode_SPS(GetBitContext *gb)
Definition: AVCParser.cpp:700
AVCParser::m_prevPicOrderCntType
uint8_t m_prevPicOrderCntType
Definition: AVCParser.h:192
AVCParser::NALU_prefix
@ NALU_prefix
Definition: AVCParser.h:86
AVCParser::using_I_forKeyframes
bool using_I_forKeyframes(void) const
Definition: AVCParser.h:117
AVCParser::m_prevIdrPicId
uint m_prevIdrPicId
Definition: AVCParser.h:173
AVCParser::m_prevNALRefIdc
uint8_t m_prevNALRefIdc
Definition: AVCParser.h:191
AVCParser::parse_SPS
void parse_SPS(uint8_t *sps, uint32_t sps_size, bool &interlaced, int32_t &max_ref_frames)
Definition: AVCParser.cpp:899
AVCParser::NAL_type_str
QString NAL_type_str(int8_t type) override
Definition: AVCParser.cpp:136
AVCParser::AU_DELIMITER
@ AU_DELIMITER
Definition: AVCParser.h:81
H2645Parser::field_type
field_type
Definition: H2645Parser.h:80
H2645Parser::m_pktOffset
uint64_t m_pktOffset
Definition: H2645Parser.h:155
AVCParser::use_I_forKeyframes
void use_I_forKeyframes(bool val)
Definition: AVCParser.h:116
AVCParser::m_deltaPicOrderAlwaysZeroFlag
uint8_t m_deltaPicOrderAlwaysZeroFlag
Definition: AVCParser.h:188
AVCParser::m_prevPicOrderCntLsb
int m_prevPicOrderCntLsb
Definition: AVCParser.h:166
AVCParser::SEI_TYPE_PIC_TIMING
@ SEI_TYPE_PIC_TIMING
Definition: AVCParser.h:74
AVCParser::m_frameNum
int m_frameNum
Definition: AVCParser.h:160
AVCParser::m_iIsKeyframe
bool m_iIsKeyframe
Definition: AVCParser.h:195
AVCParser::SLICE_DPB
@ SLICE_DPB
Definition: AVCParser.h:75
AVCParser::SEI_TYPE_USER_DATA_UNREGISTERED
@ SEI_TYPE_USER_DATA_UNREGISTERED
Definition: AVCParser.h:76
AVCParser::m_nalRefIdc
uint8_t m_nalRefIdc
Definition: AVCParser.h:189
H2645Parser.h
AVCParser::m_redundantPicCnt
uint m_redundantPicCnt
Definition: AVCParser.h:174
AVCParser::SPS_subset
@ SPS_subset
Definition: AVCParser.h:87
AVCParser::m_prevPicParameterSetId
int m_prevPicParameterSetId
Definition: AVCParser.h:167
AVCParser::m_prevBottomFieldFlag
int8_t m_prevBottomFieldFlag
Definition: AVCParser.h:183
AVCParser::SLICE_DPA
@ SLICE_DPA
Definition: AVCParser.h:74
AVCParser::SEI
@ SEI
Definition: AVCParser.h:78
AVCParser::SLICE_DPC
@ SLICE_DPC
Definition: AVCParser.h:76
AVCParser::SLICE_EXTENSION
@ SLICE_EXTENSION
Definition: AVCParser.h:89
AVCParser::decode_SEI
void decode_SEI(GetBitContext *gb)
Definition: AVCParser.cpp:984
AVCParser::m_prevDeltaPicOrderCntBottom
int m_prevDeltaPicOrderCntBottom
Definition: AVCParser.h:163
AVCParser::lastNALtype
uint8_t lastNALtype(void) const
Definition: AVCParser.h:127
H2645Parser::SLICE_I_a
@ SLICE_I_a
Definition: H2645Parser.h:133
AVCParser::m_log2MaxFrameNum
uint m_log2MaxFrameNum
Definition: AVCParser.h:170
H2645Parser::SLICE_SI_a
@ SLICE_SI_a
Definition: H2645Parser.h:135
AVCParser::m_picOrderCntLsb
int m_picOrderCntLsb
Definition: AVCParser.h:161
AVCParser::pictureHeightCropped
uint pictureHeightCropped(void) const override
Definition: AVCParser.cpp:1043
AVCParser::processRBSP
void processRBSP(bool rbsp_complete)
Definition: AVCParser.cpp:421
AVCParser::m_fieldPicFlag
int8_t m_fieldPicFlag
Definition: AVCParser.h:179
AVCParser::new_AU
bool new_AU(void)
Definition: AVCParser.cpp:172
AVCParser::SLICE_IDR
@ SLICE_IDR
Definition: AVCParser.h:77
AVCParser::m_picOrderPresentFlag
int8_t m_picOrderPresentFlag
Definition: AVCParser.h:182
AVCParser::UNKOWN
@ UNKOWN
Definition: AVCParser.h:72
AVCParser::getFieldType
field_type getFieldType(void) const override
Definition: AVCParser.cpp:1054
AVCParser::m_auContainsKeyframeMessage
bool m_auContainsKeyframeMessage
Definition: AVCParser.h:194
FrameRate
Definition: recorderbase.h:37
AVCParser::m_deltaPicOrderCntBottom
int m_deltaPicOrderCntBottom
Definition: AVCParser.h:158
H2645Parser::SLICE_SI
@ SLICE_SI
Definition: H2645Parser.h:130
H2645Parser::m_auOffset
uint64_t m_auOffset
Definition: H2645Parser.h:152
H2645Parser::m_auPending
bool m_auPending
Definition: H2645Parser.h:181
H2645Parser::SLICE_I
@ SLICE_I
Definition: H2645Parser.h:128
AVCParser::SLICE
@ SLICE
Definition: AVCParser.h:73
uint
unsigned int uint
Definition: compat.h:140
AVCParser::found_AU
bool found_AU(void) const
Definition: AVCParser.h:125
AVCParser::~AVCParser
~AVCParser(void) override
Definition: AVCParser.h:91
AVCParser::m_redundantPicCntPresentFlag
int8_t m_redundantPicCntPresentFlag
Definition: AVCParser.h:186
AVCParser::m_seqParameterSetId
uint m_seqParameterSetId
Definition: AVCParser.h:175
AVCParser::m_nalUnitType
int8_t m_nalUnitType
Definition: AVCParser.h:181
AVCParser::frameRate
double frameRate(void) const
Definition: AVCParser.cpp:1073
AVCParser::seen_SPS
bool seen_SPS(void) const
Definition: AVCParser.h:123
AVCParser::set_AU_pending
void set_AU_pending(void)
Definition: AVCParser.h:137
musicbrainzngs.compat.bytes
bytes
Definition: compat.py:49
AVCParser::m_bottomFieldFlag
int8_t m_bottomFieldFlag
Definition: AVCParser.h:178
AVCParser::decode_Header
bool decode_Header(GetBitContext *gb)
Definition: AVCParser.cpp:502
AVCParser::SEI_type
SEI_type
Definition: AVCParser.h:73
AVCParser::SEI_TYPE_RECOVERY_POINT
@ SEI_TYPE_RECOVERY_POINT
Definition: AVCParser.h:77
AVCParser::reset_SPS
void reset_SPS(void)
Definition: AVCParser.h:122
AVCParser::FILLER_DATA
@ FILLER_DATA
Definition: AVCParser.h:84
AVCParser::m_prevNalUnitType
int8_t m_prevNalUnitType
Definition: AVCParser.h:185
AVCParser::AUXILIARY_SLICE
@ AUXILIARY_SLICE
Definition: AVCParser.h:88
H2645Parser::SLICE_UNDEF
@ SLICE_UNDEF
Definition: H2645Parser.h:136
AVCParser::m_picParameterSetId
int m_picParameterSetId
Definition: AVCParser.h:162
AVCParser::getRefFrames
uint getRefFrames(void) const
Definition: AVCParser.h:129
AVCParser::decode_PPS
void decode_PPS(GetBitContext *gb)
Definition: AVCParser.cpp:909
H2645Parser
Definition: H2645Parser.h:74
AVCParser::NALisSlice
static bool NALisSlice(int8_t nal_type)
Definition: AVCParser.h:109
AVCParser::pictureWidthCropped
uint pictureWidthCropped(void) const override
Definition: AVCParser.cpp:1031
AVCParser::m_deltaPicOrderCnt
int m_deltaPicOrderCnt[2]
Definition: AVCParser.h:159
H2645Parser::UNKNOWN
@ UNKNOWN
Definition: H2645Parser.h:122
AVCParser::SPS
@ SPS
Definition: AVCParser.h:79
AVCParser::AVCParser
AVCParser(void)
Definition: AVCParser.h:89
AVCParser::SPS_EXT
@ SPS_EXT
Definition: AVCParser.h:85
AVCParser::m_prevFrameNum
int m_prevFrameNum
Definition: AVCParser.h:165
AVCParser::m_picOrderCntType
uint8_t m_picOrderCntType
Definition: AVCParser.h:190
AVCParser::m_idrPicId
uint m_idrPicId
Definition: AVCParser.h:169
AVCParser::m_prevFieldPicFlag
int8_t m_prevFieldPicFlag
Definition: AVCParser.h:184
AVCParser::m_log2MaxPicOrderCntLsb
uint m_log2MaxPicOrderCntLsb
Definition: AVCParser.h:171
AVCParser::Reset
void Reset(void) override
Definition: AVCParser.cpp:92
AVCParser::addBytes
uint32_t addBytes(const uint8_t *bytes, uint32_t byte_count, uint64_t stream_offset) override
Definition: AVCParser.cpp:291
AVCParser::m_numRefFrames
uint m_numRefFrames
Definition: AVCParser.h:172
AVCParser::m_frameMbsOnlyFlag
int8_t m_frameMbsOnlyFlag
Definition: AVCParser.h:180
AVCParser::END_STREAM
@ END_STREAM
Definition: AVCParser.h:83
AVCParser::isKeySlice
static bool isKeySlice(uint slice_type)
Definition: AVCParser.h:101