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