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 // OMG this is a hack. Buried several layers down in FFmpeg includes
27 // is an include of unistd.h that using GCC will foricibly redefine
28 // NULL back to the wrong value. (Maybe just on ARM?) Include
29 // unistd.h up front so that the subsequent inclusions will be
30 // skipped, and then define NULL to the right value.
31 #include <unistd.h>
32 #undef NULL
33 #define NULL nullptr
34 
35 #include <QString>
36 #include <cstdint>
37 #include "mythconfig.h"
38 #include "compat.h" // for uint on Darwin, MinGW
39 #include "recorders/recorderbase.h" // for ScanType
40 
41 #if 1
42 #include "mythlogging.h"
43 #endif
44 
45 #ifndef INT_BIT
46 #define INT_BIT (CHAR_BIT * sizeof(int))
47 #endif
48 
49 // copied from libavutil/internal.h
50 extern "C" {
51 // Grr. NULL keeps getting redefined back to 0
52 #undef NULL
53 #define NULL nullptr
54 #include "libavutil/common.h" // for AV_GCC_VERSION_AT_LEAST()
55 }
56 #ifndef av_alias
57 #if HAVE_ATTRIBUTE_MAY_ALIAS && (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(3,3)
58 # define av_alias __attribute__((may_alias))
59 #else
60 # define av_alias
61 #endif
62 #endif
63 
64 extern "C" {
65 // Grr. NULL keeps getting redefined back to 0
66 #undef NULL
67 #define NULL nullptr
68 #include "libavcodec/get_bits.h"
69 }
70 
71 class FrameRate;
72 enum class SCAN_t : uint8_t;
73 
74 class H2645Parser {
75  public:
76  enum {
77  MAX_SLICE_HEADER_SIZE = 256
78  };
79 
80  enum field_type {
81  FRAME = 'F',
82  FIELD_TOP = 'T',
83  FIELD_BOTTOM = 'B'
84  };
85 
86  H2645Parser(void);
87  H2645Parser(const H2645Parser& rhs);
88  virtual ~H2645Parser(void) {delete [] m_rbspBuffer;}
89 
90  virtual uint32_t addBytes(const uint8_t *bytes,
91  uint32_t byte_count,
92  uint64_t stream_offset) = 0;
93  virtual void Reset(void);
94 
95  virtual QString NAL_type_str(int8_t type) = 0;
96 
97  bool stateChanged(void) const { return m_stateChanged; }
98 
99  bool onFrameStart(void) const { return m_onFrame; }
100  bool onKeyFrameStart(void) const { return m_onKeyFrame; }
101 
102  uint pictureWidth(void) const { return m_picWidth; }
103  uint pictureHeight(void) const { return m_picHeight; }
104  virtual uint pictureWidthCropped(void) const = 0;
105  virtual uint pictureHeightCropped(void) const = 0;
106 
109  uint aspectRatio(void) const;
110  virtual void getFrameRate(FrameRate &result) const = 0;
111  virtual field_type getFieldType(void) const = 0;
112 
113  uint64_t frameAUstreamOffset(void) const {return m_frameStartOffset;}
114  uint64_t keyframeAUstreamOffset(void) const {return m_keyframeStartOffset;}
115  uint64_t SPSstreamOffset(void) const {return m_spsOffset;}
116 
117  uint32_t GetTimeScale(void) const { return m_timeScale; }
118  uint32_t GetUnitsInTick(void) const { return m_unitsInTick; }
119  SCAN_t GetScanType(void) const { return m_scanType; }
120 
122  UNKNOWN = -1
123  };
124 
125  enum SLICE_type {
126  SLICE_P = 0,
127  SLICE_B = 1,
128  SLICE_I = 2,
129  SLICE_SP = 3,
130  SLICE_SI = 4,
131  SLICE_P_a = 5,
132  SLICE_B_a = 6,
133  SLICE_I_a = 7,
134  SLICE_SP_a = 8,
135  SLICE_SI_a = 9,
136  SLICE_UNDEF = 10
137  };
138 
139  protected:
140  enum constants {EXTENDED_SAR = 255};
141 
142  void resetRBSP(void);
143  bool fillRBSP(const uint8_t *byteP, uint32_t byte_count,
144  bool found_start_code);
145 
146  void vui_parameters(GetBitContext * gb, bool hevc);
147 
148  uint64_t m_framecnt {0};
149  uint64_t m_keyframecnt {0};
150  uint64_t m_totalframecnt {0};
151  uint64_t m_totalkeyframecnt {0};
152  uint64_t m_auOffset {0};
153  uint64_t m_frameStartOffset {0};
154  uint64_t m_keyframeStartOffset {0};
155  uint64_t m_pktOffset {0};
156  uint64_t m_spsOffset {0};
157 
158  uint32_t m_consecutiveZeros {0};
159  uint32_t m_rbspBufferSize {188 * 2};
160  uint32_t m_rbspIndex {0};
161  uint32_t m_syncAccumulator {0xffffffff};
162  uint32_t m_timeScale {0};
163  uint32_t m_unitsInTick {0};
164 
166 
167  uint m_frameCropBottomOffset {0};
168  uint m_frameCropLeftOffset {0};
169  uint m_frameCropRightOffset {0};
170  uint m_frameCropTopOffset {0};
171  uint m_picHeight {0};
172  uint m_picWidth {0};
173  uint m_sarHeight {0};
174  uint m_sarWidth {0};
175 
176  uint8_t *m_rbspBuffer {nullptr};
177  uint8_t m_aspectRatioIdc {0};
178 
179  int8_t m_chromaFormatIdc {1};
180 
181  bool m_auPending {false};
182  bool m_fixedRate {false};
183  bool m_haveUnfinishedNAL {false};
184  bool m_isKeyframe {false};
185  bool m_onAU {false};
186  bool m_onFrame {false};
187  bool m_onKeyFrame {false};
188  bool m_seenSPS {false};
189  bool m_separateColourPlaneFlag {false};
190  bool m_stateChanged {false};
191 };
192 
193 #endif /* H2645PARSER_H */
H2645Parser::m_frameStartOffset
uint64_t m_frameStartOffset
Definition: H2645Parser.h:153
H2645Parser::fillRBSP
bool fillRBSP(const uint8_t *byteP, uint32_t byte_count, bool found_start_code)
Definition: H2645Parser.cpp:141
H2645Parser::~H2645Parser
virtual ~H2645Parser(void)
Definition: H2645Parser.h:88
H2645Parser::vui_parameters
void vui_parameters(GetBitContext *gb, bool hevc)
Definition: H2645Parser.cpp:229
H2645Parser::m_keyframeStartOffset
uint64_t m_keyframeStartOffset
Definition: H2645Parser.h:154
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:163
H2645Parser::field_type
field_type
Definition: H2645Parser.h:80
H2645Parser::m_picWidth
uint m_picWidth
Definition: H2645Parser.h:172
H2645Parser::SPSstreamOffset
uint64_t SPSstreamOffset(void) const
Definition: H2645Parser.h:115
H2645Parser::m_scanType
SCAN_t m_scanType
Definition: H2645Parser.h:165
H2645Parser::Reset
virtual void Reset(void)
Definition: H2645Parser.cpp:100
H2645Parser::pictureWidth
uint pictureWidth(void) const
Definition: H2645Parser.h:102
H2645Parser::GetUnitsInTick
uint32_t GetUnitsInTick(void) const
Definition: H2645Parser.h:118
H2645Parser::NAL_unit_type
NAL_unit_type
Definition: H2645Parser.h:121
mythlogging.h
H2645Parser::keyframeAUstreamOffset
uint64_t keyframeAUstreamOffset(void) const
Definition: H2645Parser.h:114
H2645Parser::GetScanType
SCAN_t GetScanType(void) const
Definition: H2645Parser.h:119
compat.h
H2645Parser::constants
constants
Definition: H2645Parser.h:140
H2645Parser::onFrameStart
bool onFrameStart(void) const
Definition: H2645Parser.h:99
H2645Parser::H2645Parser
H2645Parser(const H2645Parser &rhs)
FrameRate
Definition: recorderbase.h:37
H2645Parser::m_rbspBuffer
uint8_t * m_rbspBuffer
Definition: H2645Parser.h:176
H2645Parser::m_onKeyFrame
bool m_onKeyFrame
Definition: H2645Parser.h:187
uint
unsigned int uint
Definition: compat.h:140
H2645Parser::m_spsOffset
uint64_t m_spsOffset
Definition: H2645Parser.h:156
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:190
H2645Parser::m_timeScale
uint32_t m_timeScale
Definition: H2645Parser.h:162
H2645Parser::m_onFrame
bool m_onFrame
Definition: H2645Parser.h:186
H2645Parser::SLICE_type
SLICE_type
Definition: H2645Parser.h:125
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:113
H2645Parser::onKeyFrameStart
bool onKeyFrameStart(void) const
Definition: H2645Parser.h:100
H2645Parser::aspectRatio
uint aspectRatio(void) const
Computes aspect ratio from picture size and sample aspect ratio.
Definition: H2645Parser.cpp:400
SCAN_t
SCAN_t
Definition: recorderbase.h:54
H2645Parser::m_picHeight
uint m_picHeight
Definition: H2645Parser.h:171
H2645Parser
Definition: H2645Parser.h:74
H2645Parser::GetTimeScale
uint32_t GetTimeScale(void) const
Definition: H2645Parser.h:117
H2645Parser::NAL_type_str
virtual QString NAL_type_str(int8_t type)=0
H2645Parser::pictureHeight
uint pictureHeight(void) const
Definition: H2645Parser.h:103
H2645Parser::resetRBSP
void resetRBSP(void)
Definition: H2645Parser.cpp:134
SCAN_t::PROGRESSIVE
@ PROGRESSIVE
H2645Parser::H2645Parser
H2645Parser(void)
Definition: H2645Parser.cpp:93
H2645Parser::stateChanged
bool stateChanged(void) const
Definition: H2645Parser.h:97