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