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 <array>
27 #include <H2645Parser.h>
28 
29 class AVCParser : public H2645Parser
30 {
31  public:
32 
33  // ITU-T Rec. H.264 table 7-1
34  enum NAL_unit_type {
35  UNKOWN = -1,
36  SLICE = 1, // 1 - 5 are VCL NAL units
37  SLICE_DPA = 2,
38  SLICE_DPB = 3,
39  SLICE_DPC = 4,
40  SLICE_IDR = 5,
41  SEI = 6,
42  SPS = 7,
43  PPS = 8,
44  AU_DELIMITER = 9,
45  END_SEQUENCE = 10,
46  END_STREAM = 11,
47  FILLER_DATA = 12,
48  SPS_EXT = 13,
49  NALU_prefix = 14,
50  SPS_subset = 15,
51  AUXILIARY_SLICE = 19,
52  SLICE_EXTENSION = 20
53  };
54 
55  enum SEI_type {
60  };
61 
62  field_type getFieldType(void) const override;
63 
64  /*
65  slice_type values in the range 5..9 specify, in addition to the
66  coding type of the current slice, that all other slices of the
67  current coded picture shall have a value of slice_type equal to
68  the current value of slice_type or equal to the current value of
69  slice_type – 5.
70  */
71  AVCParser(void) { ; }
72  AVCParser(const AVCParser& rhs);
73  ~AVCParser(void) override { ; }
74 
75  uint32_t addBytes(const uint8_t *bytes,
76  uint32_t byte_count,
77  uint64_t stream_offset) override;
78  void Reset(void) override;
79 
80  QString NAL_type_str(int8_t type) override;
81 
82  // == NAL_type AU_delimiter: primary_pic_type = 5
83  static bool isKeySlice(uint slice_type)
84  {
85  return (slice_type == SLICE_I ||
86  slice_type == SLICE_SI ||
87  slice_type == SLICE_I_a ||
88  slice_type == SLICE_SI_a);
89  }
90 
91  static bool NALisSlice(int8_t nal_type)
92  {
93  return (nal_type == SLICE ||
94  nal_type == SLICE_DPA ||
95  nal_type == SLICE_IDR);
96  }
97 
98  void use_I_forKeyframes(bool val) { m_iIsKeyframe = val; }
99  bool using_I_forKeyframes(void) const { return m_iIsKeyframe; }
100 
101  void parse_SPS(uint8_t *sps, uint32_t sps_size,
102  bool& interlaced, int32_t& max_ref_frames);
103 
104  void reset_SPS(void) { m_seenSPS = false; }
105  bool seen_SPS(void) const { return m_seenSPS; }
106 
107  bool found_AU(void) const { return m_auPending; }
108 
109  uint8_t lastNALtype(void) const { return m_nalUnitType; }
110 
111  uint getRefFrames(void) const { return m_numRefFrames; }
112 
113  uint pictureWidthCropped(void) const override;
114  uint pictureHeightCropped(void) const override;
115 
116  double frameRate(void) const;
117  void getFrameRate(FrameRate &result) const override;
118 
119  inline void set_AU_pending(void)
120  {
121  if (!m_auPending)
122  {
123  m_auPending = true;
126  }
127  }
128 
129  protected:
130  bool new_AU(void);
131  void processRBSP(bool rbsp_complete);
132 
133  private:
134  bool decode_Header(GetBitContext *gb);
135  void decode_SPS(GetBitContext *gb);
136  void decode_PPS(GetBitContext * gb);
137  void decode_SEI(GetBitContext * gb);
138 
139 
140  int m_deltaPicOrderCntBottom {0};
141  std::array<int,2> m_deltaPicOrderCnt {0};
142  int m_frameNum {-1};
143  int m_picOrderCntLsb {0};
144  int m_picParameterSetId {-1};
146  std::array<int,2> m_prevDeltaPicOrderCnt {0};
147  int m_prevFrameNum {-1};
148  int m_prevPicOrderCntLsb {0};
149  int m_prevPicParameterSetId {-1};
150 
151  uint m_idrPicId {65536};
154  uint m_numRefFrames {0};
155  uint m_prevIdrPicId {65536};
159 
160  int8_t m_bottomFieldFlag {-1};
161  int8_t m_fieldPicFlag {-1};
162  int8_t m_frameMbsOnlyFlag {-1};
166  int8_t m_prevFieldPicFlag {-1};
169 
171  uint8_t m_nalRefIdc {111}; // != [0|1|2|3]
172  uint8_t m_picOrderCntType {0};
173  uint8_t m_prevNALRefIdc {111}; // != [0|1|2|3]
175 
177  bool m_iIsKeyframe {true};
178 };
179 
180 #endif /* AVCPARSER_H */
AVCParser::getFrameRate
void getFrameRate(FrameRate &result) const override
Definition: AVCParser.cpp:1077
AVCParser::NAL_unit_type
NAL_unit_type
Definition: AVCParser.h:53
AVCParser
Definition: AVCParser.h:29
AVCParser::SEI_FILLER_PAYLOAD
@ SEI_FILLER_PAYLOAD
Definition: AVCParser.h:76
H2645Parser::m_seenSPS
bool m_seenSPS
Definition: H2645Parser.h:188
AVCParser::PPS
@ PPS
Definition: AVCParser.h:81
AVCParser::m_sliceType
uint m_sliceType
Definition: AVCParser.h:177
AVCParser::END_SEQUENCE
@ END_SEQUENCE
Definition: AVCParser.h:83
AVCParser::decode_SPS
void decode_SPS(GetBitContext *gb)
Definition: AVCParser.cpp:696
AVCParser::m_prevPicOrderCntType
uint8_t m_prevPicOrderCntType
Definition: AVCParser.h:193
AVCParser::NALU_prefix
@ NALU_prefix
Definition: AVCParser.h:87
AVCParser::using_I_forKeyframes
bool using_I_forKeyframes(void) const
Definition: AVCParser.h:118
AVCParser::m_prevIdrPicId
uint m_prevIdrPicId
Definition: AVCParser.h:174
AVCParser::m_prevNALRefIdc
uint8_t m_prevNALRefIdc
Definition: AVCParser.h:192
AVCParser::m_deltaPicOrderCnt
std::array< int, 2 > m_deltaPicOrderCnt
Definition: AVCParser.h:160
AVCParser::parse_SPS
void parse_SPS(uint8_t *sps, uint32_t sps_size, bool &interlaced, int32_t &max_ref_frames)
Definition: AVCParser.cpp:895
AVCParser::NAL_type_str
QString NAL_type_str(int8_t type) override
Definition: AVCParser.cpp:134
AVCParser::AU_DELIMITER
@ AU_DELIMITER
Definition: AVCParser.h:82
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:117
AVCParser::m_deltaPicOrderAlwaysZeroFlag
uint8_t m_deltaPicOrderAlwaysZeroFlag
Definition: AVCParser.h:189
AVCParser::m_prevPicOrderCntLsb
int m_prevPicOrderCntLsb
Definition: AVCParser.h:167
AVCParser::SEI_TYPE_PIC_TIMING
@ SEI_TYPE_PIC_TIMING
Definition: AVCParser.h:75
AVCParser::m_frameNum
int m_frameNum
Definition: AVCParser.h:161
AVCParser::m_iIsKeyframe
bool m_iIsKeyframe
Definition: AVCParser.h:196
AVCParser::SLICE_DPB
@ SLICE_DPB
Definition: AVCParser.h:76
AVCParser::SEI_TYPE_USER_DATA_UNREGISTERED
@ SEI_TYPE_USER_DATA_UNREGISTERED
Definition: AVCParser.h:77
AVCParser::m_nalRefIdc
uint8_t m_nalRefIdc
Definition: AVCParser.h:190
H2645Parser.h
AVCParser::m_redundantPicCnt
uint m_redundantPicCnt
Definition: AVCParser.h:175
AVCParser::SPS_subset
@ SPS_subset
Definition: AVCParser.h:88
AVCParser::m_prevPicParameterSetId
int m_prevPicParameterSetId
Definition: AVCParser.h:168
AVCParser::m_prevBottomFieldFlag
int8_t m_prevBottomFieldFlag
Definition: AVCParser.h:184
AVCParser::SLICE_DPA
@ SLICE_DPA
Definition: AVCParser.h:75
AVCParser::SEI
@ SEI
Definition: AVCParser.h:79
AVCParser::SLICE_DPC
@ SLICE_DPC
Definition: AVCParser.h:77
AVCParser::m_prevDeltaPicOrderCnt
std::array< int, 2 > m_prevDeltaPicOrderCnt
Definition: AVCParser.h:165
AVCParser::SLICE_EXTENSION
@ SLICE_EXTENSION
Definition: AVCParser.h:90
AVCParser::decode_SEI
void decode_SEI(GetBitContext *gb)
Definition: AVCParser.cpp:980
AVCParser::m_prevDeltaPicOrderCntBottom
int m_prevDeltaPicOrderCntBottom
Definition: AVCParser.h:164
AVCParser::lastNALtype
uint8_t lastNALtype(void) const
Definition: AVCParser.h:128
H2645Parser::SLICE_I_a
@ SLICE_I_a
Definition: H2645Parser.h:133
AVCParser::m_log2MaxFrameNum
uint m_log2MaxFrameNum
Definition: AVCParser.h:171
H2645Parser::SLICE_SI_a
@ SLICE_SI_a
Definition: H2645Parser.h:135
AVCParser::m_picOrderCntLsb
int m_picOrderCntLsb
Definition: AVCParser.h:162
AVCParser::pictureHeightCropped
uint pictureHeightCropped(void) const override
Definition: AVCParser.cpp:1039
AVCParser::processRBSP
void processRBSP(bool rbsp_complete)
Definition: AVCParser.cpp:419
AVCParser::m_fieldPicFlag
int8_t m_fieldPicFlag
Definition: AVCParser.h:180
AVCParser::new_AU
bool new_AU(void)
Definition: AVCParser.cpp:170
AVCParser::SLICE_IDR
@ SLICE_IDR
Definition: AVCParser.h:78
AVCParser::m_picOrderPresentFlag
int8_t m_picOrderPresentFlag
Definition: AVCParser.h:183
AVCParser::UNKOWN
@ UNKOWN
Definition: AVCParser.h:73
AVCParser::getFieldType
field_type getFieldType(void) const override
Definition: AVCParser.cpp:1050
AVCParser::m_auContainsKeyframeMessage
bool m_auContainsKeyframeMessage
Definition: AVCParser.h:195
FrameRate
Definition: recorderbase.h:36
AVCParser::m_deltaPicOrderCntBottom
int m_deltaPicOrderCntBottom
Definition: AVCParser.h:159
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:74
uint
unsigned int uint
Definition: compat.h:144
AVCParser::found_AU
bool found_AU(void) const
Definition: AVCParser.h:126
AVCParser::~AVCParser
~AVCParser(void) override
Definition: AVCParser.h:92
AVCParser::m_redundantPicCntPresentFlag
int8_t m_redundantPicCntPresentFlag
Definition: AVCParser.h:187
AVCParser::m_seqParameterSetId
uint m_seqParameterSetId
Definition: AVCParser.h:176
AVCParser::m_nalUnitType
int8_t m_nalUnitType
Definition: AVCParser.h:182
AVCParser::frameRate
double frameRate(void) const
Definition: AVCParser.cpp:1069
AVCParser::seen_SPS
bool seen_SPS(void) const
Definition: AVCParser.h:124
AVCParser::set_AU_pending
void set_AU_pending(void)
Definition: AVCParser.h:138
musicbrainzngs.compat.bytes
bytes
Definition: compat.py:49
AVCParser::m_bottomFieldFlag
int8_t m_bottomFieldFlag
Definition: AVCParser.h:179
AVCParser::decode_Header
bool decode_Header(GetBitContext *gb)
Definition: AVCParser.cpp:500
AVCParser::SEI_type
SEI_type
Definition: AVCParser.h:74
AVCParser::SEI_TYPE_RECOVERY_POINT
@ SEI_TYPE_RECOVERY_POINT
Definition: AVCParser.h:78
AVCParser::reset_SPS
void reset_SPS(void)
Definition: AVCParser.h:123
AVCParser::FILLER_DATA
@ FILLER_DATA
Definition: AVCParser.h:85
AVCParser::m_prevNalUnitType
int8_t m_prevNalUnitType
Definition: AVCParser.h:186
AVCParser::AUXILIARY_SLICE
@ AUXILIARY_SLICE
Definition: AVCParser.h:89
H2645Parser::SLICE_UNDEF
@ SLICE_UNDEF
Definition: H2645Parser.h:136
AVCParser::m_picParameterSetId
int m_picParameterSetId
Definition: AVCParser.h:163
AVCParser::getRefFrames
uint getRefFrames(void) const
Definition: AVCParser.h:130
AVCParser::decode_PPS
void decode_PPS(GetBitContext *gb)
Definition: AVCParser.cpp:905
H2645Parser
Definition: H2645Parser.h:74
AVCParser::NALisSlice
static bool NALisSlice(int8_t nal_type)
Definition: AVCParser.h:110
AVCParser::pictureWidthCropped
uint pictureWidthCropped(void) const override
Definition: AVCParser.cpp:1027
H2645Parser::UNKNOWN
@ UNKNOWN
Definition: H2645Parser.h:122
AVCParser::SPS
@ SPS
Definition: AVCParser.h:80
AVCParser::AVCParser
AVCParser(void)
Definition: AVCParser.h:90
AVCParser::SPS_EXT
@ SPS_EXT
Definition: AVCParser.h:86
AVCParser::m_prevFrameNum
int m_prevFrameNum
Definition: AVCParser.h:166
AVCParser::m_picOrderCntType
uint8_t m_picOrderCntType
Definition: AVCParser.h:191
AVCParser::m_idrPicId
uint m_idrPicId
Definition: AVCParser.h:170
AVCParser::m_prevFieldPicFlag
int8_t m_prevFieldPicFlag
Definition: AVCParser.h:185
AVCParser::m_log2MaxPicOrderCntLsb
uint m_log2MaxPicOrderCntLsb
Definition: AVCParser.h:172
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:289
AVCParser::m_numRefFrames
uint m_numRefFrames
Definition: AVCParser.h:173
AVCParser::m_frameMbsOnlyFlag
int8_t m_frameMbsOnlyFlag
Definition: AVCParser.h:181
AVCParser::END_STREAM
@ END_STREAM
Definition: AVCParser.h:84
AVCParser::isKeySlice
static bool isKeySlice(uint slice_type)
Definition: AVCParser.h:102