MythTV master
HEVCParser.h
Go to the documentation of this file.
1// -*- Mode: c++ -*-
2/*******************************************************************
3 * HEVCParser
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 HEVCPARSER_H
24#define HEVCPARSER_H
25
26#include <array>
27#include <map>
28#include <vector>
29
30#include "mpeg/H2645Parser.h"
31
32class HEVCParser : public H2645Parser
33{
34 public:
35
36 enum NAL_unit_type : std::uint8_t {
37 TAIL_N = 0, // Coded slice segment of a non-TSA, non-STSA trailing picture
38 TAIL_R = 1, // slice_segment_layer_rbsp() VCL
39
40 TSA_N = 2, // Coded slice segment of a TSA picture
41 TSA_R = 3, // slice_segment_layer_rbsp() VCL
42
43 STSA_N = 4, // Coded slice segment of an STSA picture
44 STSA_R = 5, // slice_segment_layer_rbsp() VCL
45
46 RADL_N = 6, // Coded slice segment of a RADL picture
47 RADL_R = 7, // slice_segment_layer_rbsp() VCL
48
49 // random access skipped leading (RASL) pictures
50 RASL_N = 8, // Coded slice segment of a RASL picture
51 RASL_R = 9, // slice_segment_layer_rbsp() VCL
52
53 RSV_VCL_N10 = 10, //
54 RSV_VCL_N12 = 12, // Reserved non-IRAP SLNR VCL NAL unit types VCL
55 RSV_VCL_N14 = 14, //
56
57 RSV_VCL_R11 = 11, //
58 RSV_VCL_R13 = 13, // Reserved non-IRAP sub-layer reference VCL NAL unit
59 RSV_VCL_R15 = 15, // types VCL
60
61 // RADL = random access decodable leading picture
62
63 /*
64 A broken link access (BLA) picture having
65 nal_unit_type equal to BLA_W_LP may have associated
66 RASL or RADL pictures present in the bitstream. A
67 BLA picture having nal_unit_type equal to
68 BLA_W_RADL does not have associated RASL pictures
69 present in the bitstream, but may have associated
70 RADL pictures in the bitstream. A BLA picture
71 having nal_unit_type equal to BLA_N_LP does not
72 have associated leading pictures present in the
73 bitstream.
74 */
75 BLA_W_LP = 16, //
76 BLA_W_RADL = 17, // Coded slice segment of a BLA picture
77 BLA_N_LP = 18, // slice_segment_layer_rbsp() VCL
78
79 /*
80 An instantaneous decoding refresh (IDR) picture
81 having nal_unit_type equal to IDR_N_LP does not
82 have associated leading pictures present in the
83 bitstream. An IDR picture having nal_unit_type
84 equal to IDR_W_RADL does not have associated RASL
85 pictures present in the bitstream, but may have
86 associated RADL pictures in the bitstream.
87 */
88 IDR_W_RADL = 19, // Coded slice segment of an IDR picture
89 IDR_N_LP = 20, // slice_segment_layer_rbsp() VCL
90
91 /* A clean random access (CRA) picture may have
92 associated random access skipped leading (RASL) or
93 random access decodable leading (RADL) pictures
94 present in the bitstream.
95 */
96 CRA_NUT = 21, // Coded slice segment of a CRA picture
97 // slice_segment_layer_rbsp() VCL
98
100 RSV_IRAP_VCL23 = 23, // Reserved IRAP VCL NAL unit types VCL
101
102 RSV_VCL24 = 24, // Reserved non-IRAP VCL NAL unit types
110
111 VPS_NUT = 32, // Video parameter set video_parameter_set_rbsp() non-VCL
112 SPS_NUT = 33, // Sequence parameter set seq_parameter_set_rbsp() non-VCL
113 PPS_NUT = 34, // Picture parameter set pic_parameter_set_rbsp() non-VCL
114 AUD_NUT = 35, // Access unit delimiter access_unit_delimiter_rbsp() non-VCL
115 EOS_NUT = 36, // End of sequence end_of_seq_rbsp() non-VCL
116 EOB_NUT = 37, // End of bitstream end_of_bitstream_rbsp() non-VCL
117 FD_NUT = 38, // Filler data filler_data_rbsp() non-VCL
118
119 PREFIX_SEI_NUT = 39, // Supplemental enhancement information
120 SUFFIX_SEI_NUT = 40, // sei_rbsp() non-VCL
121
122 RSV_NVCL41 = 41, // Reserved non-VCL
129
130 UNSPEC48 = 48, // Unspecified non-VCL
145 UNSPEC63 = 63
146 };
147
148 struct SPS {
154
155 };
156
157 struct VPS {
158 uint8_t max_sub_layers; // range 0 to 3
159 };
160
161 struct PPS {
166 };
167
169 /* calculated values */
170 std::array<int32_t,16> DeltaPocS0;
171 std::array<int32_t,16> DeltaPocS1;
172 std::array<uint8_t,16> UsedByCurrPicS0;
173 std::array<uint8_t,16> UsedByCurrPicS1;
177
178 // Parsed values
183 };
184
185
186 /*
187 scaling_list_dc_coef_minus8_16x16: this plus 8 specifies the DC
188 Coefficient values for 16x16 scaling list
189 scaling_list_dc_coef_minus8_32x32: this plus 8 specifies the
190 DC Coefficient values for 32x32 scaling list
191 scaling_lists_4x4: 4x4 scaling list
192 scaling_lists_8x8: 8x8 scaling list
193 scaling_lists_16x16: 16x16 scaling list
194 scaling_lists_32x32: 32x32 scaling list
195 */
196 struct ScalingList {
197 std::vector<int16_t> scaling_list_dc_coef_minus8_16x16 {6,0};
198 std::vector<int16_t> scaling_list_dc_coef_minus8_32x32 {2,0};
199
200 std::array<std::array<uint8_t,16>,6> scaling_lists_4x4 {};
201 std::array<std::array<uint8_t,64>,6> scaling_lists_8x8 {};
202 std::array<std::array<uint8_t,64>,6> scaling_lists_16x16 {};
203 std::array<std::array<uint8_t,64>,2> scaling_lists_32x32 {};
204 };
205
206 enum QuantMatrixSize : std::uint8_t
207 {
212 };
213
214
215 HEVCParser(void) { ; }
217 ~HEVCParser(void) override { ; }
218
219 /* random access point (RAP) are NAL type of:
220 * * stantaneous decoding refresh (IDR)
221 * * broken link access (BLA)
222 * * clean random access (CRA)
223 */
224 static bool NALisRAP(uint type)
225 {
226 return (BLA_W_LP <= type && type <= CRA_NUT);
227 }
228
229 /*
230 3.73 intra random access point (IRAP) picture: A coded picture
231 for which each VCL NAL unit has nal_unit_type in the range of
232 BLA_W_LP to RSV_IRAP_VCL23, inclusive.
233 */
234 static bool NALisIRAP(uint type)
235 {
236 return (BLA_W_LP <= type && type <= RSV_IRAP_VCL23);
237 }
238
239 static bool NALisVCL(uint type)
240 {
241 return (TAIL_N <= type && type <= RSV_VCL31);
242 }
243
244 uint32_t addBytes(const uint8_t *bytes,
245 uint32_t byte_count,
246 uint64_t stream_offset) override;
247
248 void Reset(void) override;
249
250 QString NAL_type_str(int8_t type) override;
251
252 uint pictureWidthCropped(void) const override;
253 uint pictureHeightCropped(void) const override;
254
255 field_type getFieldType(void) const override { return FRAME; }
256 MythAVRational getFrameRate() const override;
257
258 protected:
259 bool newAU(void);
260 void processRBSP(bool rbsp_complete);
262 bool profilePresentFlag,
263 int maxNumSubLayersMinus1);
266 bool parseSPS(BitReader& br);
267 bool parseVPS(BitReader& br);
268 bool parsePPS(BitReader& br);
269
270 private:
272 uint32_t m_picOrderCntMsb {0};
273 uint32_t m_picOrderCntVal {0};
276 uint32_t m_resolutionCheck {0};
277
279
280 uint8_t m_nalTemperalId {0};
281 uint8_t m_nuhLayerId {0};
282
284 bool m_nextNALisAU {false};
285 bool m_noRaslOutputFlag {false};
286 bool m_seenEOS {true};
287
288 std::map<uint, SPS> m_sps;
289 std::map<uint, PPS> m_pps;
290 std::map<uint, VPS> m_vps;
291 std::map<uint, uint> m_poc;
292};
293
294#endif /* HEVCPARSER_H */
uint8_t m_nalTemperalId
Definition: HEVCParser.h:280
std::map< uint, uint > m_poc
Definition: HEVCParser.h:291
std::map< uint, SPS > m_sps
Definition: HEVCParser.h:288
uint32_t m_picOrderCntMsb
Definition: HEVCParser.h:272
uint m_nalUnitType
Definition: HEVCParser.h:278
uint pictureHeightCropped(void) const override
uint pictureWidthCropped(void) const override
uint32_t m_prevPicOrderCntMsb
Definition: HEVCParser.h:275
bool newAU(void)
Definition: HEVCParser.cpp:248
bool m_nextNALisAU
Definition: HEVCParser.h:284
std::map< uint, PPS > m_pps
Definition: HEVCParser.h:289
uint8_t m_nuhLayerId
Definition: HEVCParser.h:281
field_type getFieldType(void) const override
Definition: HEVCParser.h:255
bool parseSliceSegmentLayer(BitReader &br)
QString NAL_type_str(int8_t type) override
Definition: HEVCParser.cpp:50
std::map< uint, VPS > m_vps
Definition: HEVCParser.h:290
bool parseSliceSegmentHeader(BitReader &br)
MythAVRational getFrameRate() const override
static bool NALisRAP(uint type)
Definition: HEVCParser.h:224
bool m_noRaslOutputFlag
Definition: HEVCParser.h:285
static bool NALisVCL(uint type)
Definition: HEVCParser.h:239
uint32_t m_resolutionCheck
Definition: HEVCParser.h:276
uint32_t m_picOrderCntVal
Definition: HEVCParser.h:273
void processRBSP(bool rbsp_complete)
Definition: HEVCParser.cpp:457
uint32_t addBytes(const uint8_t *bytes, uint32_t byte_count, uint64_t stream_offset) override
Definition: HEVCParser.cpp:126
uint32_t m_prevPicOrderCntLsb
Definition: HEVCParser.h:274
@ RSV_IRAP_VCL22
Definition: HEVCParser.h:99
@ RSV_IRAP_VCL23
Definition: HEVCParser.h:100
@ PREFIX_SEI_NUT
Definition: HEVCParser.h:119
@ SUFFIX_SEI_NUT
Definition: HEVCParser.h:120
bool profileTierLevel(BitReader &br, bool profilePresentFlag, int maxNumSubLayersMinus1)
Definition: HEVCParser.cpp:576
@ QUANT_MATIX_16X16
Definition: HEVCParser.h:210
@ QUANT_MATIX_8X8
Definition: HEVCParser.h:209
@ QUANT_MATIX_4X4
Definition: HEVCParser.h:208
@ QUANT_MATIX_32X32
Definition: HEVCParser.h:211
bool m_firstSliceSegmentInPicFlag
Definition: HEVCParser.h:283
~HEVCParser(void) override
Definition: HEVCParser.h:217
static bool NALisIRAP(uint type)
Definition: HEVCParser.h:234
uint32_t m_maxPicOrderCntLsb
Definition: HEVCParser.h:271
bool parsePPS(BitReader &br)
void Reset(void) override
Definition: HEVCParser.cpp:45
bool parseSPS(BitReader &br)
HEVCParser(void)
Definition: HEVCParser.h:215
HEVCParser(const HEVCParser &rhs)
bool m_seenEOS
Definition: HEVCParser.h:286
bool parseVPS(BitReader &br)
C++ wrapper for FFmpeg libavutil AVRational.
unsigned int uint
Definition: freesurround.h:24
unsigned short uint16_t
Definition: iso6937tables.h:3
bool dependent_slice_segments_enabled_flag
Definition: HEVCParser.h:162
bool output_flag_present_flag
Definition: HEVCParser.h:163
uint8_t num_extra_slice_header_bits
Definition: HEVCParser.h:164
bool sub_layer_ordering_info_present_flag
Definition: HEVCParser.h:153
bool separate_colour_plane_flag
Definition: HEVCParser.h:152
uint8_t log2_min_luma_coding_block_size
Definition: HEVCParser.h:149
uint8_t log2_diff_max_min_luma_coding_block_size
Definition: HEVCParser.h:150
uint8_t log2_max_pic_order_cnt_lsb
Definition: HEVCParser.h:151
std::array< std::array< uint8_t, 64 >, 6 > scaling_lists_16x16
Definition: HEVCParser.h:202
std::vector< int16_t > scaling_list_dc_coef_minus8_16x16
Definition: HEVCParser.h:197
std::vector< int16_t > scaling_list_dc_coef_minus8_32x32
Definition: HEVCParser.h:198
std::array< std::array< uint8_t, 64 >, 6 > scaling_lists_8x8
Definition: HEVCParser.h:201
std::array< std::array< uint8_t, 16 >, 6 > scaling_lists_4x4
Definition: HEVCParser.h:200
std::array< std::array< uint8_t, 64 >, 2 > scaling_lists_32x32
Definition: HEVCParser.h:203
std::array< uint8_t, 16 > UsedByCurrPicS1
Definition: HEVCParser.h:173
std::array< uint8_t, 16 > UsedByCurrPicS0
Definition: HEVCParser.h:172
std::array< int32_t, 16 > DeltaPocS1
Definition: HEVCParser.h:171
std::array< int32_t, 16 > DeltaPocS0
Definition: HEVCParser.h:170
uint8_t max_sub_layers
Definition: HEVCParser.h:158