MythTV  master
H2645Parser.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 /*******************************************************************
3  * H2645Parser
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 H2645PARSER_H
24 #define H2645PARSER_H
25 
26 #include <cstdint>
27 
28 #include <QString>
29 
30 #include "libmythbase/compat.h" // for uint on Darwin, MinGW
31 #include "libmythbase/mythconfig.h"
33 
34 #include "libmythtv/scantype.h"
35 
36 class BitReader;
37 class FrameRate;
38 
39 class H2645Parser {
40  public:
41  static constexpr uint16_t kMaxSliceHeaderSize { 256 };
42 
43  enum field_type : std::uint8_t {
44  FRAME = 'F',
45  FIELD_TOP = 'T',
47  };
48 
49  H2645Parser(void);
50  H2645Parser(const H2645Parser& rhs);
51  virtual ~H2645Parser(void) {delete [] m_rbspBuffer;}
52 
53  virtual uint32_t addBytes(const uint8_t *bytes,
54  uint32_t byte_count,
55  uint64_t stream_offset) = 0;
56  virtual void Reset(void);
57 
58  virtual QString NAL_type_str(int8_t type) = 0;
59 
60  bool stateChanged(void) const { return m_stateChanged; }
61 
62  bool onFrameStart(void) const { return m_onFrame; }
63  bool onKeyFrameStart(void) const { return m_onKeyFrame; }
64 
65  uint pictureWidth(void) const { return m_picWidth; }
66  uint pictureHeight(void) const { return m_picHeight; }
67  virtual uint pictureWidthCropped(void) const = 0;
68  virtual uint pictureHeightCropped(void) const = 0;
69 
72  uint aspectRatio(void) const;
73  virtual void getFrameRate(FrameRate &result) const = 0;
74  virtual field_type getFieldType(void) const = 0;
75 
76  uint64_t frameAUstreamOffset(void) const {return m_frameStartOffset;}
77  uint64_t keyframeAUstreamOffset(void) const {return m_keyframeStartOffset;}
78  uint64_t SPSstreamOffset(void) const {return m_spsOffset;}
79 
80  uint32_t GetTimeScale(void) const { return m_timeScale; }
81  uint32_t GetUnitsInTick(void) const { return m_unitsInTick; }
82  SCAN_t GetScanType(void) const { return m_scanType; }
83 
84  enum NAL_unit_type : std::int8_t {
85  UNKNOWN = -1
86  };
87 
88  enum SLICE_type : std::uint8_t {
89  SLICE_P = 0,
90  SLICE_B = 1,
91  SLICE_I = 2,
92  SLICE_SP = 3,
93  SLICE_SI = 4,
94  SLICE_P_a = 5,
95  SLICE_B_a = 6,
96  SLICE_I_a = 7,
100  };
101 
102  protected:
103  static constexpr uint8_t kExtendedSar { 255 };
104 
105  void resetRBSP(void);
106  bool fillRBSP(const uint8_t *byteP, uint32_t byte_count,
107  bool found_start_code);
108 
109  void vui_parameters(BitReader& br, bool hevc);
110 
111  uint64_t m_framecnt {0};
112  uint64_t m_keyframecnt {0};
113  uint64_t m_totalframecnt {0};
114  uint64_t m_totalkeyframecnt {0};
115  uint64_t m_auOffset {0};
116  uint64_t m_frameStartOffset {0};
117  uint64_t m_keyframeStartOffset {0};
118  uint64_t m_pktOffset {0};
119  uint64_t m_spsOffset {0};
120 
121  uint32_t m_consecutiveZeros {0};
122  uint32_t m_rbspBufferSize {188 * 2};
123  uint32_t m_rbspIndex {0};
124  uint32_t m_syncAccumulator {0xffffffff};
125  uint32_t m_timeScale {0};
126  uint32_t m_unitsInTick {0};
127 
129 
138 
139  uint8_t *m_rbspBuffer {nullptr};
140  uint8_t m_aspectRatioIdc {0};
141 
142  int8_t m_chromaFormatIdc {1};
143 
144  bool m_auPending {false};
145  bool m_fixedRate {false};
146  bool m_haveUnfinishedNAL {false};
147  bool m_isKeyframe {false};
148  bool m_onAU {false};
149  bool m_onFrame {false};
150  bool m_onKeyFrame {false};
151  bool m_seenSPS {false};
153  bool m_stateChanged {false};
154 };
155 
156 #endif /* H2645PARSER_H */
H2645Parser::m_onAU
bool m_onAU
Definition: H2645Parser.h:148
H2645Parser::m_seenSPS
bool m_seenSPS
Definition: H2645Parser.h:151
H2645Parser::SLICE_B_a
@ SLICE_B_a
Definition: H2645Parser.h:95
H2645Parser::m_frameCropRightOffset
uint m_frameCropRightOffset
Definition: H2645Parser.h:132
H2645Parser::m_frameStartOffset
uint64_t m_frameStartOffset
Definition: H2645Parser.h:116
H2645Parser::fillRBSP
bool fillRBSP(const uint8_t *byteP, uint32_t byte_count, bool found_start_code)
Definition: H2645Parser.cpp:134
H2645Parser::m_separateColourPlaneFlag
bool m_separateColourPlaneFlag
Definition: H2645Parser.h:152
SCAN_t
SCAN_t
Definition: scantype.h:6
H2645Parser::m_sarWidth
uint m_sarWidth
Definition: H2645Parser.h:137
H2645Parser::~H2645Parser
virtual ~H2645Parser(void)
Definition: H2645Parser.h:51
H2645Parser::m_keyframeStartOffset
uint64_t m_keyframeStartOffset
Definition: H2645Parser.h:117
H2645Parser::pictureWidthCropped
virtual uint pictureWidthCropped(void) const =0
H2645Parser::kMaxSliceHeaderSize
static constexpr uint16_t kMaxSliceHeaderSize
Definition: H2645Parser.h:41
H2645Parser::getFrameRate
virtual void getFrameRate(FrameRate &result) const =0
H2645Parser::pictureHeightCropped
virtual uint pictureHeightCropped(void) const =0
H2645Parser::m_unitsInTick
uint32_t m_unitsInTick
Definition: H2645Parser.h:126
H2645Parser::m_framecnt
uint64_t m_framecnt
Definition: H2645Parser.h:111
H2645Parser::m_picWidth
uint m_picWidth
Definition: H2645Parser.h:135
SCAN_t::UNKNOWN_SCAN
@ UNKNOWN_SCAN
H2645Parser::SPSstreamOffset
uint64_t SPSstreamOffset(void) const
Definition: H2645Parser.h:78
H2645Parser::m_pktOffset
uint64_t m_pktOffset
Definition: H2645Parser.h:118
H2645Parser::m_scanType
SCAN_t m_scanType
Definition: H2645Parser.h:128
H2645Parser::m_frameCropLeftOffset
uint m_frameCropLeftOffset
Definition: H2645Parser.h:131
H2645Parser::Reset
virtual void Reset(void)
Definition: H2645Parser.cpp:93
H2645Parser::SLICE_B
@ SLICE_B
Definition: H2645Parser.h:90
H2645Parser::pictureWidth
uint pictureWidth(void) const
Definition: H2645Parser.h:65
H2645Parser::m_rbspBufferSize
uint32_t m_rbspBufferSize
Definition: H2645Parser.h:122
H2645Parser::GetUnitsInTick
uint32_t GetUnitsInTick(void) const
Definition: H2645Parser.h:81
H2645Parser::UNKNOWN
@ UNKNOWN
Definition: H2645Parser.h:85
H2645Parser::m_aspectRatioIdc
uint8_t m_aspectRatioIdc
Definition: H2645Parser.h:140
H2645Parser::SLICE_SP
@ SLICE_SP
Definition: H2645Parser.h:92
H2645Parser::vui_parameters
void vui_parameters(BitReader &br, bool hevc)
Definition: H2645Parser.cpp:215
H2645Parser::SLICE_I_a
@ SLICE_I_a
Definition: H2645Parser.h:96
BitReader
Definition: bitreader.h:38
mythlogging.h
H2645Parser::m_keyframecnt
uint64_t m_keyframecnt
Definition: H2645Parser.h:112
H2645Parser::keyframeAUstreamOffset
uint64_t keyframeAUstreamOffset(void) const
Definition: H2645Parser.h:77
H2645Parser::GetScanType
SCAN_t GetScanType(void) const
Definition: H2645Parser.h:82
H2645Parser::m_rbspIndex
uint32_t m_rbspIndex
Definition: H2645Parser.h:123
H2645Parser::m_consecutiveZeros
uint32_t m_consecutiveZeros
Definition: H2645Parser.h:121
H2645Parser::m_fixedRate
bool m_fixedRate
Definition: H2645Parser.h:145
H2645Parser::m_frameCropBottomOffset
uint m_frameCropBottomOffset
Definition: H2645Parser.h:130
compat.h
H2645Parser::SLICE_SP_a
@ SLICE_SP_a
Definition: H2645Parser.h:97
H2645Parser::onFrameStart
bool onFrameStart(void) const
Definition: H2645Parser.h:62
FrameRate
Definition: recorderbase.h:38
H2645Parser::m_rbspBuffer
uint8_t * m_rbspBuffer
Definition: H2645Parser.h:139
H2645Parser::m_auOffset
uint64_t m_auOffset
Definition: H2645Parser.h:115
H2645Parser::m_auPending
bool m_auPending
Definition: H2645Parser.h:144
H2645Parser::m_onKeyFrame
bool m_onKeyFrame
Definition: H2645Parser.h:150
uint
unsigned int uint
Definition: compat.h:81
H2645Parser::m_spsOffset
uint64_t m_spsOffset
Definition: H2645Parser.h:119
H2645Parser::addBytes
virtual uint32_t addBytes(const uint8_t *bytes, uint32_t byte_count, uint64_t stream_offset)=0
H2645Parser::m_stateChanged
bool m_stateChanged
Definition: H2645Parser.h:153
H2645Parser::m_timeScale
uint32_t m_timeScale
Definition: H2645Parser.h:125
H2645Parser::m_onFrame
bool m_onFrame
Definition: H2645Parser.h:149
H2645Parser::m_isKeyframe
bool m_isKeyframe
Definition: H2645Parser.h:147
H2645Parser::m_haveUnfinishedNAL
bool m_haveUnfinishedNAL
Definition: H2645Parser.h:146
H2645Parser::m_frameCropTopOffset
uint m_frameCropTopOffset
Definition: H2645Parser.h:133
H2645Parser::m_syncAccumulator
uint32_t m_syncAccumulator
Definition: H2645Parser.h:124
musicbrainzngs.compat.bytes
bytes
Definition: compat.py:49
scantype.h
H2645Parser::SLICE_I
@ SLICE_I
Definition: H2645Parser.h:91
H2645Parser::m_totalframecnt
uint64_t m_totalframecnt
Definition: H2645Parser.h:113
H2645Parser::NAL_unit_type
NAL_unit_type
Definition: H2645Parser.h:84
H2645Parser::getFieldType
virtual field_type getFieldType(void) const =0
H2645Parser::frameAUstreamOffset
uint64_t frameAUstreamOffset(void) const
Definition: H2645Parser.h:76
H2645Parser::FIELD_TOP
@ FIELD_TOP
Definition: H2645Parser.h:45
H2645Parser::FIELD_BOTTOM
@ FIELD_BOTTOM
Definition: H2645Parser.h:46
H2645Parser::onKeyFrameStart
bool onKeyFrameStart(void) const
Definition: H2645Parser.h:63
H2645Parser::m_chromaFormatIdc
int8_t m_chromaFormatIdc
Definition: H2645Parser.h:142
H2645Parser::aspectRatio
uint aspectRatio(void) const
Computes aspect ratio from picture size and sample aspect ratio.
Definition: H2645Parser.cpp:388
H2645Parser::SLICE_UNDEF
@ SLICE_UNDEF
Definition: H2645Parser.h:99
H2645Parser::field_type
field_type
Definition: H2645Parser.h:43
H2645Parser::m_picHeight
uint m_picHeight
Definition: H2645Parser.h:134
uint16_t
unsigned short uint16_t
Definition: iso6937tables.h:3
H2645Parser
Definition: H2645Parser.h:39
H2645Parser::GetTimeScale
uint32_t GetTimeScale(void) const
Definition: H2645Parser.h:80
H2645Parser::NAL_type_str
virtual QString NAL_type_str(int8_t type)=0
H2645Parser::SLICE_type
SLICE_type
Definition: H2645Parser.h:88
H2645Parser::pictureHeight
uint pictureHeight(void) const
Definition: H2645Parser.h:66
H2645Parser::SLICE_P_a
@ SLICE_P_a
Definition: H2645Parser.h:94
H2645Parser::m_sarHeight
uint m_sarHeight
Definition: H2645Parser.h:136
H2645Parser::resetRBSP
void resetRBSP(void)
Definition: H2645Parser.cpp:127
H2645Parser::SLICE_SI_a
@ SLICE_SI_a
Definition: H2645Parser.h:98
H2645Parser::m_totalkeyframecnt
uint64_t m_totalkeyframecnt
Definition: H2645Parser.h:114
H2645Parser::SLICE_SI
@ SLICE_SI
Definition: H2645Parser.h:93
H2645Parser::H2645Parser
H2645Parser(void)
Definition: H2645Parser.cpp:86
H2645Parser::kExtendedSar
static constexpr uint8_t kExtendedSar
Definition: H2645Parser.h:103
H2645Parser::FRAME
@ FRAME
Definition: H2645Parser.h:44
H2645Parser::SLICE_P
@ SLICE_P
Definition: H2645Parser.h:89
H2645Parser::stateChanged
bool stateChanged(void) const
Definition: H2645Parser.h:60