MythTV  master
H264Parser.cpp
Go to the documentation of this file.
1 // MythTV headers
2 #include "H264Parser.h"
3 #include <iostream>
4 
5 #include "mythlogging.h"
6 #include "recorders/dtvrecorder.h" // for FrameRate
7 
8 
9 extern "C" {
10 #include "libavcodec/avcodec.h"
11 #include "libavutil/internal.h"
12 #include "libavcodec/golomb.h"
13 }
14 
15 #include <cmath>
16 #include <strings.h>
17 
18 static const float eps = 1E-5;
19 
20 /*
21  Most of the comments below were cut&paste from ITU-T Rec. H.264
22  as found here: http://www.itu.int/rec/T-REC-H.264/e
23  */
24 
25 /*
26  Useful definitions:
27 
28  * access unit: A set of NAL units always containing exactly one
29  primary coded picture. In addition to the primary coded picture, an
30  access unit may also contain one or more redundant coded pictures
31  or other NAL units not containing slices or slice data partitions
32  of a coded picture. The decoding of an access unit always results
33  in a decoded picture.
34 
35  * instantaneous decoding refresh (IDR) access unit: An access unit in
36  which the primary coded picture is an IDR picture.
37 
38  * instantaneous decoding refresh (IDR) picture: A coded picture
39  containing only slices with I or SI slice types that causes the
40  decoding process to mark all reference pictures as "unused for
41  reference" immediately after decoding the IDR picture. After the
42  decoding of an IDR picture all following coded pictures in decoding
43  order can be decoded without inter prediction from any picture
44  decoded prior to the IDR picture. The first picture of each coded
45  video sequence is an IDR picture.
46 
47  * NAL unit: A syntax structure containing an indication of the type
48  of data to follow and bytes containing that data in the form of an
49  RBSP interspersed as necessary with emulation prevention bytes.
50 
51  * raw byte sequence payload (RBSP): A syntax structure containing an
52  integer number of bytes that is encapsulated in a NAL unit. An RBSP
53  is either empty or has the form of a string of data bits containing
54  syntax elements followed by an RBSP stop bit and followed by zero
55  or more subsequent bits equal to 0.
56 
57  * raw byte sequence payload (RBSP) stop bit: A bit equal to 1 present
58  within a raw byte sequence payload (RBSP) after a string of data
59  bits. The location of the end of the string of data bits within an
60  RBSP can be identified by searching from the end of the RBSP for
61  the RBSP stop bit, which is the last non-zero bit in the RBSP.
62 
63  * parity: The parity of a field can be top or bottom.
64 
65  * picture: A collective term for a field or a frame.
66 
67  * picture parameter set: A syntax structure containing syntax
68  elements that apply to zero or more entire coded pictures as
69  determined by the m_picParameterSetId syntax element found in each
70  slice header.
71 
72  * primary coded picture: The coded representation of a picture to be
73  used by the decoding process for a bitstream conforming to this
74  Recommendation | International Standard. The primary coded picture
75  contains all macroblocks of the picture. The only pictures that
76  have a normative effect on the decoding process are primary coded
77  pictures. See also redundant coded picture.
78 
79  * VCL: Video Coding Layer
80 
81  - The VCL is specified to efficiently represent the content of the
82  video data. The NAL is specified to format that data and provide
83  header information in a manner appropriate for conveyance on a
84  variety of communication channels or storage media. All data are
85  contained in NAL units, each of which contains an integer number of
86  bytes. A NAL unit specifies a generic format for use in both
87  packet-oriented and bitstream systems. The format of NAL units for
88  both packet-oriented transport and byte stream is identical except
89  that each NAL unit can be preceded by a start code prefix and extra
90  padding bytes in the byte stream format.
91 
92 */
93 
95 {
96  m_rbspBuffer = new uint8_t[m_rbspBufferSize];
97  if (m_rbspBuffer == nullptr)
98  m_rbspBufferSize = 0;
99 
100  Reset();
101 }
102 
104 {
105  m_stateChanged = false;
106  m_seenSps = false;
107  m_isKeyframe = false;
108  m_spsOffset = 0;
109 
110  m_syncAccumulator = 0xffffffff;
111  m_auPending = false;
112 
113  m_frameNum = -1;
114  m_prevFrameNum = -1;
117  m_picParameterSetId = -1;
118  m_prevFieldPicFlag = -1;
119  m_fieldPicFlag = -1;
121  m_bottomFieldFlag = -1;
122  m_prevNALRefIdc = 111; // != [0|1|2|3]
123  m_nalRefIdc = 111; // != [0|1|2|3]
125  m_picOrderCntType = 0;
127  m_picOrderCntType = 0;
129  m_picOrderCntLsb = 0;
132  m_prevDeltaPicOrderCnt[0] = 0;
133  m_deltaPicOrderCnt[0] = 0;
134  m_prevDeltaPicOrderCnt[1] = 0;
135  m_deltaPicOrderCnt[1] = 0;
138 
139  // The value of m_idrPicId shall be in the range of 0 to 65535, inclusive.
140  m_prevIdrPicId = 65536;
141  m_idrPicId = 65536;
142 
143  m_log2MaxFrameNum = 0;
146 
149  m_chromaFormatIdc = 1;
150  m_frameMbsOnlyFlag = -1;
153 
154  m_numRefFrames = 0;
155  m_redundantPicCnt = 0;
156 
157 // m_picWidthInMbs = 0;
158 // m_picHeightInMapUnits = 0;
159  m_picWidth = 0;
160  m_picHeight = 0;
165  m_aspectRatioIdc = 0;
166  m_sarWidth = 0;
167  m_sarHeight = 0;
168  m_unitsInTick = 0;
169  m_timeScale = 0;
170  m_fixedRate = false;
171 
172  m_pktOffset = 0;
173  m_auOffset = 0;
174  m_frameStartOffset = 0;
176  m_onFrame = false;
177  m_onKeyFrame = false;
178 
179  resetRBSP();
180 }
181 
182 
184 {
185  switch (type)
186  {
187  case UNKNOWN:
188  return "UNKNOWN";
189  case SLICE:
190  return "SLICE";
191  case SLICE_DPA:
192  return "SLICE_DPA";
193  case SLICE_DPB:
194  return "SLICE_DPB";
195  case SLICE_DPC:
196  return "SLICE_DPC";
197  case SLICE_IDR:
198  return "SLICE_IDR";
199  case SEI:
200  return "SEI";
201  case SPS:
202  return "SPS";
203  case PPS:
204  return "PPS";
205  case AU_DELIMITER:
206  return "AU_DELIMITER";
207  case END_SEQUENCE:
208  return "END_SEQUENCE";
209  case END_STREAM:
210  return "END_STREAM";
211  case FILLER_DATA:
212  return "FILLER_DATA";
213  case SPS_EXT:
214  return "SPS_EXT";
215  }
216  return "OTHER";
217 }
218 
220 {
221  /*
222  An access unit consists of one primary coded picture, zero or more
223  corresponding redundant coded pictures, and zero or more non-VCL NAL
224  units. The association of VCL NAL units to primary or redundant coded
225  pictures is described in subclause 7.4.1.2.5.
226 
227  The first access unit in the bitstream starts with the first NAL unit
228  of the bitstream.
229 
230  The first of any of the following NAL units after the last VCL NAL
231  unit of a primary coded picture specifies the start of a new access
232  unit.
233 
234  – access unit delimiter NAL unit (when present)
235  – sequence parameter set NAL unit (when present)
236  – picture parameter set NAL unit (when present)
237  – SEI NAL unit (when present)
238  – NAL units with m_nalUnitType in the range of 14 to 18, inclusive
239  – first VCL NAL unit of a primary coded picture (always present)
240  */
241 
242  /*
243  7.4.1.2.4 Detection of the first VCL NAL unit of a primary coded
244  picture This subclause specifies constraints on VCL NAL unit syntax
245  that are sufficient to enable the detection of the first VCL NAL unit
246  of each primary coded picture.
247 
248  Any coded slice NAL unit or coded slice data partition A NAL unit of
249  the primary coded picture of the current access unit shall be
250  different from any coded slice NAL unit or coded slice data partition
251  A NAL unit of the primary coded picture of the previous access unit in
252  one or more of the following ways.
253 
254  - frame_num differs in value. The value of frame_num used to
255  test this condition is the value of frame_num that appears in
256  the syntax of the slice header, regardless of whether that value
257  is inferred to have been equal to 0 for subsequent use in the
258  decoding process due to the presence of
259  memory_management_control_operation equal to 5.
260  Note: If the current picture is an IDR picture FrameNum and
261  PrevRefFrameNum are set equal to 0.
262  - m_picParameterSetId differs in value.
263  - m_fieldPicFlag differs in value.
264  - bottom_field_flag is present in both and differs in value.
265  - nal_ref_idc differs in value with one of the nal_ref_idc
266  values being equal to 0.
267  - m_picOrderCntType is equal to 0 for both and either
268  m_picOrderCntLsb differs in value, or m_deltaPicOrderCntBottom
269  differs in value.
270  - m_picOrderCntType is equal to 1 for both and either
271  m_deltaPicOrderCnt[0] differs in value, or
272  m_deltaPicOrderCnt[1] differs in value.
273  - m_nalUnitType differs in value with one of the m_nalUnitType values
274  being equal to 5.
275  - m_nalUnitType is equal to 5 for both and m_idrPicId differs in
276  value.
277 
278  NOTE – Some of the VCL NAL units in redundant coded pictures or some
279  non-VCL NAL units (e.g. an access unit delimiter NAL unit) may also
280  be used for the detection of the boundary between access units, and
281  may therefore aid in the detection of the start of a new primary
282  coded picture.
283 
284  */
285 
286  bool result = false;
287 
288  if (m_prevFrameNum != -1)
289  {
290  // Need previous slice information for comparison
291 
293  result = true; // NOLINT(bugprone-branch-clone)
294  else if (m_prevPicParameterSetId != -1 &&
296  result = true;
298  result = true;
299  else if ((m_bottomFieldFlag != -1 && m_prevBottomFieldFlag != -1) &&
301  result = true;
302  else if ((m_nalRefIdc == 0 || m_prevNALRefIdc == 0) &&
304  result = true;
305  else if ((m_picOrderCntType == 0 && m_prevPicOrderCntType == 0) &&
308  result = true;
309  else if ((m_picOrderCntType == 1 && m_prevPicOrderCntType == 1) &&
312  result = true;
313  else if ((m_nalUnitType == SLICE_IDR ||
316  result = true;
317  else if ((m_nalUnitType == SLICE_IDR &&
320  result = true;
321  }
322 
334 
335  return result;
336 }
337 
339 {
340  m_rbspIndex = 0;
341  m_consecutiveZeros = 0;
342  m_haveUnfinishedNAL = false;
343 }
344 
345 bool H264Parser::fillRBSP(const uint8_t *byteP, uint32_t byte_count,
346  bool found_start_code)
347 {
348  /*
349  bitstream buffer, must be AV_INPUT_BUFFER_PADDING_SIZE
350  bytes larger then the actual data
351  */
352  uint32_t required_size = m_rbspIndex + byte_count +
353  AV_INPUT_BUFFER_PADDING_SIZE;
354  if (m_rbspBufferSize < required_size)
355  {
356  // Round up to packet size
357  required_size = ((required_size / 188) + 1) * 188;
358 
359  /* Need a bigger buffer */
360  auto *new_buffer = new uint8_t[required_size];
361 
362  if (new_buffer == nullptr)
363  {
364  /* Allocation failed. Discard the new bytes */
365  LOG(VB_GENERAL, LOG_ERR,
366  "H264Parser::fillRBSP: FAILED to allocate RBSP buffer!");
367  return false;
368  }
369 
370  /* Copy across bytes from old buffer */
371  memcpy(new_buffer, m_rbspBuffer, m_rbspIndex);
372  delete [] m_rbspBuffer;
373  m_rbspBuffer = new_buffer;
374  m_rbspBufferSize = required_size;
375  }
376 
377  /* Fill rbsp while we have data */
378  while (byte_count)
379  {
380  /* Copy the byte into the rbsp, unless it
381  * is the 0x03 in a 0x000003 */
382  if (m_consecutiveZeros < 2 || *byteP != 0x03)
383  m_rbspBuffer[m_rbspIndex++] = *byteP;
384 
385  if (*byteP == 0)
387  else
388  m_consecutiveZeros = 0;
389 
390  ++byteP;
391  --byte_count;
392  }
393 
394  /* If we've found the next start code then that, plus the first byte of
395  * the next NAL, plus the preceding zero bytes will all be in the rbsp
396  * buffer. Move rbsp_index++ back to the end of the actual rbsp data. We
397  * need to know the correct size of the rbsp to decode some NALs.
398  */
399  if (found_start_code)
400  {
401  if (m_rbspIndex >= 4)
402  {
403  m_rbspIndex -= 4;
404  while (m_rbspIndex > 0 && m_rbspBuffer[m_rbspIndex-1] == 0)
405  --m_rbspIndex;
406  }
407  else
408  {
409  /* This should never happen. */
410  LOG(VB_GENERAL, LOG_ERR,
411  QString("H264Parser::fillRBSP: Found start code, rbsp_index "
412  "is %1 but it should be >4")
413  .arg(m_rbspIndex));
414  }
415  }
416 
417  /* Stick some 0xff on the end for get_bits to run into */
418  memset(&m_rbspBuffer[m_rbspIndex], 0xff, AV_INPUT_BUFFER_PADDING_SIZE);
419  return true;
420 }
421 
422 uint32_t H264Parser::addBytes(const uint8_t *bytes,
423  const uint32_t byte_count,
424  const uint64_t stream_offset)
425 {
426  const uint8_t *startP = bytes;
427 
428  m_stateChanged = false;
429  m_onFrame = false;
430  m_onKeyFrame = false;
431 
432  while (startP < bytes + byte_count && !m_onFrame)
433  {
434  const uint8_t *endP = avpriv_find_start_code(startP,
435  bytes + byte_count, &m_syncAccumulator);
436 
437  bool found_start_code = ((m_syncAccumulator & 0xffffff00) == 0x00000100);
438 
439  /* Between startP and endP we potentially have some more
440  * bytes of a NAL that we've been parsing (plus some bytes of
441  * start code)
442  */
444  {
445  if (!fillRBSP(startP, endP - startP, found_start_code))
446  {
447  resetRBSP();
448  return endP - bytes;
449  }
450  processRBSP(found_start_code); /* Call may set have_uinfinished_NAL
451  * to false */
452  }
453 
454  /* Dealt with everything up to endP */
455  startP = endP;
456 
457  if (found_start_code)
458  {
460  {
461  /* We've found a new start code, without completely
462  * parsing the previous NAL. Either there's a
463  * problem with the stream or with this parser.
464  */
465  LOG(VB_GENERAL, LOG_ERR,
466  "H264Parser::addBytes: Found new start "
467  "code, but previous NAL is incomplete!");
468  }
469 
470  /* Prepare for accepting the new NAL */
471  resetRBSP();
472 
473  /* If we find the start of an AU somewhere from here
474  * to the next start code, the offset to associate with
475  * it is the one passed in to this call, not any of the
476  * subsequent calls.
477  */
478  m_pktOffset = stream_offset; // + (startP - bytes);
479 
480 /*
481  m_nalUnitType specifies the type of RBSP data structure contained in
482  the NAL unit as specified in Table 7-1. VCL NAL units
483  are specified as those NAL units having m_nalUnitType
484  equal to 1 to 5, inclusive. All remaining NAL units
485  are called non-VCL NAL units:
486 
487  0 Unspecified
488  1 Coded slice of a non-IDR picture slice_layer_without_partitioning_rbsp( )
489  2 Coded slice data partition A slice_data_partition_a_layer_rbsp( )
490  3 Coded slice data partition B slice_data_partition_b_layer_rbsp( )
491  4 Coded slice data partition C slice_data_partition_c_layer_rbsp( )
492  5 Coded slice of an IDR picture slice_layer_without_partitioning_rbsp( )
493  6 Supplemental enhancement information (SEI) 5 sei_rbsp( )
494  7 Sequence parameter set (SPS) seq_parameter_set_rbsp( )
495  8 Picture parameter set pic_parameter_set_rbsp( )
496  9 Access unit delimiter access_unit_delimiter_rbsp( )
497  10 End of sequence end_of_seq_rbsp( )
498  11 End of stream end_of_stream_rbsp( )
499 */
501  m_nalRefIdc = (m_syncAccumulator >> 5) & 0x3;
502 
503  bool good_nal_unit = true;
504  if (m_nalRefIdc)
505  {
506  /* nal_ref_idc shall be equal to 0 for all NAL units having
507  * m_nalUnitType equal to 6, 9, 10, 11, or 12.
508  */
509  if (m_nalUnitType == SEI ||
512  good_nal_unit = false;
513  }
514  else
515  {
516  /* nal_ref_idc shall not be equal to 0 for NAL units with
517  * m_nalUnitType equal to 5
518  */
519  if (m_nalUnitType == SLICE_IDR)
520  good_nal_unit = false;
521  }
522 
523  if (good_nal_unit)
524  {
525  if (m_nalUnitType == SPS || m_nalUnitType == PPS ||
527  {
528  /* This is a NAL we need to parse. We may have the body
529  * of it in the part of the stream past to us this call,
530  * or we may get the rest in subsequent calls to addBytes.
531  * Either way, we set m_haveUnfinishedNAL, so that we
532  * start filling the rbsp buffer
533  */
534  m_haveUnfinishedNAL = true;
535  }
536  else if (m_nalUnitType == AU_DELIMITER ||
537  (m_nalUnitType > SPS_EXT &&
539  {
540  set_AU_pending();
541  }
542  }
543  else
544  LOG(VB_GENERAL, LOG_ERR,
545  "H264Parser::addbytes: malformed NAL units");
546  } //found start code
547  }
548 
549  return startP - bytes;
550 }
551 
552 
553 void H264Parser::processRBSP(bool rbsp_complete)
554 {
555  GetBitContext gb;
556 
557  init_get_bits(&gb, m_rbspBuffer, 8 * m_rbspIndex);
558 
559  if (m_nalUnitType == SEI)
560  {
561  /* SEI cannot be parsed without knowing its size. If
562  * we haven't got the whole rbsp, return and wait for
563  * the rest
564  */
565  if (!rbsp_complete)
566  return;
567 
568  set_AU_pending();
569 
570  decode_SEI(&gb);
571  }
572  else if (m_nalUnitType == SPS)
573  {
574  /* Best wait until we have the whole thing */
575  if (!rbsp_complete)
576  return;
577 
578  set_AU_pending();
579 
580  if (!m_seenSps)
582 
583  decode_SPS(&gb);
584  }
585  else if (m_nalUnitType == PPS)
586  {
587  /* Best wait until we have the whole thing */
588  if (!rbsp_complete)
589  return;
590 
591  set_AU_pending();
592 
593  decode_PPS(&gb);
594  }
595  else
596  {
597  /* Need only parse the header. So return only
598  * if we have insufficient bytes */
599  if (!rbsp_complete && m_rbspIndex < MAX_SLICE_HEADER_SIZE)
600  return;
601 
602  decode_Header(&gb);
603 
604  if (new_AU())
605  set_AU_pending();
606  }
607 
608  /* If we got this far, we managed to parse a sufficient
609  * prefix of the current NAL. We can go onto the next. */
610  m_haveUnfinishedNAL = false;
611 
613  {
614  /* Once we know the slice type of a new AU, we can
615  * determine if it is a keyframe or just a frame
616  */
617  m_auPending = false;
619 
620  m_onFrame = true;
622 
624  {
625  m_onKeyFrame = true;
627  }
628  }
629 }
630 
631 /*
632  7.4.3 Slice header semantics
633 */
634 bool H264Parser::decode_Header(GetBitContext *gb)
635 {
636  m_isKeyframe = false;
637 
638  if (m_log2MaxFrameNum == 0)
639  {
640  /* SPS has not been parsed yet */
641  return false;
642  }
643 
644  /*
645  m_firstMbInSlice specifies the address of the first macroblock
646  in the slice. When arbitrary slice order is not allowed as
647  specified in Annex A, the value of first_mb_in_slice is
648  constrained as follows.
649 
650  – If m_separateColourPlaneFlag is equal to 0, the value of
651  first_mb_in_slice shall not be less than the value of
652  first_mb_in_slice for any other slice of the current picture
653  that precedes the current slice in decoding order.
654 
655  – Otherwise (m_separateColourPlaneFlag is equal to 1), the value of
656  first_mb_in_slice shall not be less than the value of
657  first_mb_in_slice for any other slice of the current picture
658  that precedes the current slice in decoding order and has the
659  same value of colour_plane_id.
660  */
661  /* uint first_mb_in_slice = */ get_ue_golomb(gb);
662 
663  /*
664  slice_type specifies the coding type of the slice according to
665  Table 7-6. e.g. P, B, I, SP, SI
666 
667  When m_nalUnitType is equal to 5 (IDR picture), slice_type shall
668  be equal to 2, 4, 7, or 9 (I or SI)
669  */
670  m_sliceType = get_ue_golomb_31(gb);
671 
672  /* s->pict_type = golomb_to_pict_type[slice_type % 5];
673  */
674 
675  /*
676  m_picParameterSetId specifies the picture parameter set in
677  use. The value of m_picParameterSetId shall be in the range of
678  0 to 255, inclusive.
679  */
680  m_picParameterSetId = get_ue_golomb(gb);
681 
682  /*
683  m_separateColourPlaneFlag equal to 1 specifies that the three
684  colour components of the 4:4:4 chroma format are coded
685  separately. m_separateColourPlaneFlag equal to 0 specifies that
686  the colour components are not coded separately. When
687  m_separateColourPlaneFlag is not present, it shall be inferred
688  to be equal to 0. When m_separateColourPlaneFlag is equal to 1,
689  the primary coded picture consists of three separate components,
690  each of which consists of coded samples of one colour plane (Y,
691  Cb or Cr) that each use the monochrome coding syntax. In this
692  case, each colour plane is associated with a specific
693  colour_plane_id value.
694  */
696  get_bits(gb, 2); // colour_plane_id
697 
698  /*
699  frame_num is used as an identifier for pictures and shall be
700  represented by m_log2MaxFrameNum_minus4 + 4 bits in the
701  bitstream....
702 
703  If the current picture is an IDR picture, frame_num shall be equal to 0.
704 
705  When m_maxNumRefFrames is equal to 0, slice_type shall be equal
706  to 2, 4, 7, or 9.
707  */
708  m_frameNum = get_bits(gb, m_log2MaxFrameNum);
709 
710  /*
711  m_fieldPicFlag equal to 1 specifies that the slice is a slice of a
712  coded field. m_fieldPicFlag equal to 0 specifies that the slice is a
713  slice of a coded frame. When m_fieldPicFlag is not present it shall be
714  inferred to be equal to 0.
715 
716  bottom_field_flag equal to 1 specifies that the slice is part of a
717  coded bottom field. bottom_field_flag equal to 0 specifies that the
718  picture is a coded top field. When this syntax element is not present
719  for the current slice, it shall be inferred to be equal to 0.
720  */
721  if (!m_frameMbsOnlyFlag)
722  {
723  m_fieldPicFlag = get_bits1(gb);
724  m_bottomFieldFlag = m_fieldPicFlag ? get_bits1(gb) : 0;
725  }
726  else
727  {
728  m_fieldPicFlag = 0;
729  m_bottomFieldFlag = -1;
730  }
731 
732  /*
733  m_idrPicId identifies an IDR picture. The values of m_idrPicId
734  in all the slices of an IDR picture shall remain unchanged. When
735  two consecutive access units in decoding order are both IDR
736  access units, the value of m_idrPicId in the slices of the first
737  such IDR access unit shall differ from the m_idrPicId in the
738  second such IDR access unit. The value of m_idrPicId shall be in
739  the range of 0 to 65535, inclusive.
740  */
741  if (m_nalUnitType == SLICE_IDR)
742  {
743  m_idrPicId = get_ue_golomb(gb);
744  m_isKeyframe = true;
745  }
746  else
748 
749  /*
750  m_picOrderCntLsb specifies the picture order count modulo
751  MaxPicOrderCntLsb for the top field of a coded frame or for a coded
752  field. The size of the m_picOrderCntLsb syntax element is
753  m_log2MaxPicOrderCntLsbMinus4 + 4 bits. The value of the
754  pic_order_cnt_lsb shall be in the range of 0 to MaxPicOrderCntLsb – 1,
755  inclusive.
756 
757  m_deltaPicOrderCntBottom specifies the picture order count
758  difference between the bottom field and the top field of a coded
759  frame.
760  */
761  if (m_picOrderCntType == 0)
762  {
764 
765  if ((m_picOrderPresentFlag == 1) && !m_fieldPicFlag)
766  m_deltaPicOrderCntBottom = get_se_golomb(gb);
767  else
769  }
770  else
772 
773  /*
774  m_deltaPicOrderAlwaysZeroFlag equal to 1 specifies that
775  m_deltaPicOrderCnt[ 0 ] and m_deltaPicOrderCnt[ 1 ] are not
776  present in the slice headers of the sequence and shall be
777  inferred to be equal to 0. m_deltaPicOrderAlwaysZeroFlag
778  equal to 0 specifies that m_deltaPicOrderCnt[ 0 ] is present in
779  the slice headers of the sequence and m_deltaPicOrderCnt[ 1 ]
780  may be present in the slice headers of the sequence.
781  */
783  {
785  }
786  else if (m_picOrderCntType == 1)
787  {
788  /*
789  m_deltaPicOrderCnt[ 0 ] specifies the picture order count
790  difference from the expected picture order count for the top
791  field of a coded frame or for a coded field as specified in
792  subclause 8.2.1. The value of m_deltaPicOrderCnt[ 0 ] shall
793  be in the range of -2^31 to 2^31 - 1, inclusive. When this
794  syntax element is not present in the bitstream for the
795  current slice, it shall be inferred to be equal to 0.
796 
797  m_deltaPicOrderCnt[ 1 ] specifies the picture order count
798  difference from the expected picture order count for the
799  bottom field of a coded frame specified in subclause
800  8.2.1. The value of m_deltaPicOrderCnt[ 1 ] shall be in the
801  range of -2^31 to 2^31 - 1, inclusive. When this syntax
802  element is not present in the bitstream for the current
803  slice, it shall be inferred to be equal to 0.
804  */
805  m_deltaPicOrderCnt[0] = get_se_golomb(gb);
806 
807  if ((m_picOrderPresentFlag == 1) && !m_fieldPicFlag)
808  m_deltaPicOrderCnt[1] = get_se_golomb(gb);
809  else
810  m_deltaPicOrderCnt[1] = 0;
811  }
812 
813  /*
814  m_redundantPicCnt shall be equal to 0 for slices and slice data
815  partitions belonging to the primary coded picture. The
816  m_redundantPicCnt shall be greater than 0 for coded slices and
817  coded slice data partitions in redundant coded pictures. When
818  m_redundantPicCnt is not present, its value shall be inferred to
819  be equal to 0. The value of m_redundantPicCnt shall be in the
820  range of 0 to 127, inclusive.
821  */
822  m_redundantPicCnt = m_redundantPicCntPresentFlag ? get_ue_golomb(gb) : 0;
823 
824  return true;
825 }
826 
827 /*
828  * libavcodec used for example
829  */
830 void H264Parser::decode_SPS(GetBitContext * gb)
831 {
832  m_seenSps = true;
833 
834  int profile_idc = get_bits(gb, 8);
835  get_bits1(gb); // constraint_set0_flag
836  get_bits1(gb); // constraint_set1_flag
837  get_bits1(gb); // constraint_set2_flag
838  get_bits1(gb); // constraint_set3_flag
839  get_bits(gb, 4); // reserved
840  get_bits(gb, 8); // level_idc
841  get_ue_golomb(gb); // sps_id
842 
843  if (profile_idc == 100 || profile_idc == 110 || profile_idc == 122 ||
844  profile_idc == 244 || profile_idc == 44 || profile_idc == 83 ||
845  profile_idc == 86 || profile_idc == 118 || profile_idc == 128 )
846  { // high profile
847  if ((m_chromaFormatIdc = get_ue_golomb(gb)) == 3)
848  m_separateColourPlaneFlag = (get_bits1(gb) == 1);
849 
850  get_ue_golomb(gb); // bit_depth_luma_minus8
851  get_ue_golomb(gb); // bit_depth_chroma_minus8
852  get_bits1(gb); // qpprime_y_zero_transform_bypass_flag
853 
854  if (get_bits1(gb)) // seq_scaling_matrix_present_flag
855  {
856  for (int idx = 0; idx < ((m_chromaFormatIdc != 3) ? 8 : 12); ++idx)
857  {
858  if (get_bits1(gb)) // Scaling list present
859  {
860  int lastScale = 8;
861  int nextScale = 8;
862  int sl_n = ((idx < 6) ? 16 : 64);
863  for(int sl_i = 0; sl_i < sl_n; ++sl_i)
864  {
865  if (nextScale != 0)
866  {
867  int deltaScale = get_se_golomb(gb);
868  nextScale = (lastScale + deltaScale + 256) % 256;
869  }
870  lastScale = (nextScale == 0) ? lastScale : nextScale;
871  }
872  }
873  }
874  }
875  }
876 
877  /*
878  m_log2MaxFrameNum_minus4 specifies the value of the variable
879  MaxFrameNum that is used in frame_num related derivations as
880  follows:
881 
882  MaxFrameNum = 2( m_log2MaxFrameNum_minus4 + 4 )
883  */
884  m_log2MaxFrameNum = get_ue_golomb(gb) + 4;
885 
886  /*
887  m_picOrderCntType specifies the method to decode picture order
888  count (as specified in subclause 8.2.1). The value of
889  m_picOrderCntType shall be in the range of 0 to 2, inclusive.
890  */
891  m_picOrderCntType = get_ue_golomb(gb);
892  if (m_picOrderCntType == 0)
893  {
894  /*
895  m_log2MaxPicOrderCntLsbMinus4 specifies the value of the
896  variable MaxPicOrderCntLsb that is used in the decoding
897  process for picture order count as specified in subclause
898  8.2.1 as follows:
899 
900  MaxPicOrderCntLsb = 2( m_log2MaxPicOrderCntLsbMinus4 + 4 )
901 
902  The value of m_log2MaxPicOrderCntLsbMinus4 shall be in
903  the range of 0 to 12, inclusive.
904  */
905  m_log2MaxPicOrderCntLsb = get_ue_golomb(gb) + 4;
906  }
907  else if (m_picOrderCntType == 1)
908  {
909  /*
910  m_deltaPicOrderAlwaysZeroFlag equal to 1 specifies that
911  m_deltaPicOrderCnt[ 0 ] and m_deltaPicOrderCnt[ 1 ] are
912  not present in the slice headers of the sequence and shall
913  be inferred to be equal to
914  0. m_deltaPicOrderAlwaysZeroFlag
915  */
916  m_deltaPicOrderAlwaysZeroFlag = get_bits1(gb);
917 
918  /*
919  offset_for_non_ref_pic is used to calculate the picture
920  order count of a non-reference picture as specified in
921  8.2.1. The value of offset_for_non_ref_pic shall be in the
922  range of -231 to 231 - 1, inclusive.
923  */
924  int offset_for_non_ref_pic = get_se_golomb(gb);
925  (void) offset_for_non_ref_pic; // suppress unused var warning
926 
927  /*
928  offset_for_top_to_bottom_field is used to calculate the
929  picture order count of a bottom field as specified in
930  subclause 8.2.1. The value of offset_for_top_to_bottom_field
931  shall be in the range of -231 to 231 - 1, inclusive.
932  */
933  int offset_for_top_to_bottom_field = get_se_golomb(gb);
934  (void) offset_for_top_to_bottom_field; // suppress unused var warning
935 
936  /*
937  offset_for_ref_frame[ i ] is an element of a list of
938  m_numRefFrames_in_pic_order_cnt_cycle values used in the
939  decoding process for picture order count as specified in
940  subclause 8.2.1. The value of offset_for_ref_frame[ i ]
941  shall be in the range of -231 to 231 - 1, inclusive.
942  */
943  uint tmp = get_ue_golomb(gb);
944  for (uint idx = 0; idx < tmp; ++idx)
945  get_se_golomb(gb); // offset_for_ref_frame[i]
946  }
947 
948  /*
949  m_numRefFrames specifies the maximum number of short-term and
950  long-term reference frames, complementary reference field pairs,
951  and non-paired reference fields that may be used by the decoding
952  process for inter prediction of any picture in the
953  sequence. m_numRefFrames also determines the size of the sliding
954  window operation as specified in subclause 8.2.5.3. The value of
955  m_numRefFrames shall be in the range of 0 to MaxDpbSize (as
956  specified in subclause A.3.1 or A.3.2), inclusive.
957  */
958  m_numRefFrames = get_ue_golomb(gb);
959  /*
960  gaps_in_frame_num_value_allowed_flag specifies the allowed
961  values of frame_num as specified in subclause 7.4.3 and the
962  decoding process in case of an inferred gap between values of
963  frame_num as specified in subclause 8.2.5.2.
964  */
965  /* bool gaps_in_frame_num_allowed_flag = */ get_bits1(gb);
966 
967  /*
968  pic_width_in_mbs_minus1 plus 1 specifies the width of each
969  decoded picture in units of macroblocks. 16 macroblocks in a row
970  */
971  m_picWidth = (get_ue_golomb(gb) + 1) * 16;
972  /*
973  pic_height_in_map_units_minus1 plus 1 specifies the height in
974  slice group map units of a decoded frame or field. 16
975  macroblocks in each column.
976  */
977  m_picHeight = (get_ue_golomb(gb) + 1) * 16;
978 
979  /*
980  m_frameMbsOnlyFlag equal to 0 specifies that coded pictures of
981  the coded video sequence may either be coded fields or coded
982  frames. m_frameMbsOnlyFlag equal to 1 specifies that every
983  coded picture of the coded video sequence is a coded frame
984  containing only frame macroblocks.
985  */
986  m_frameMbsOnlyFlag = get_bits1(gb);
987  if (!m_frameMbsOnlyFlag)
988  {
989  m_picHeight *= 2;
990 
991  /*
992  mb_adaptive_frame_field_flag equal to 0 specifies no
993  switching between frame and field macroblocks within a
994  picture. mb_adaptive_frame_field_flag equal to 1 specifies
995  the possible use of switching between frame and field
996  macroblocks within frames. When mb_adaptive_frame_field_flag
997  is not present, it shall be inferred to be equal to 0.
998  */
999  get_bits1(gb); // mb_adaptive_frame_field_flag
1000  }
1001 
1002  get_bits1(gb); // direct_8x8_inference_flag
1003 
1004  /*
1005  frame_cropping_flag equal to 1 specifies that the frame cropping
1006  offset parameters follow next in the sequence parameter
1007  set. frame_cropping_flag equal to 0 specifies that the frame
1008  cropping offset parameters are not present.
1009  */
1010  if (get_bits1(gb)) // frame_cropping_flag
1011  {
1012  m_frameCropLeftOffset = get_ue_golomb(gb);
1013  m_frameCropRightOffset = get_ue_golomb(gb);
1014  m_frameCropTopOffset = get_ue_golomb(gb);
1015  m_frameCropBottomOffset = get_ue_golomb(gb);
1016  }
1017 
1018  /*
1019  vui_parameters_present_flag equal to 1 specifies that the
1020  vui_parameters( ) syntax structure as specified in Annex E is
1021  present. vui_parameters_present_flag equal to 0 specifies that
1022  the vui_parameters( ) syntax structure as specified in Annex E
1023  is not present.
1024  */
1025  if (get_bits1(gb)) // vui_parameters_present_flag
1026  vui_parameters(gb);
1027 }
1028 
1029 void H264Parser::parse_SPS(uint8_t *sps, uint32_t sps_size,
1030  bool& interlaced, int32_t& max_ref_frames)
1031 {
1032  GetBitContext gb;
1033  init_get_bits(&gb, sps, sps_size << 3);
1034  decode_SPS(&gb);
1035  interlaced = (m_frameMbsOnlyFlag == 0);
1036  max_ref_frames = m_numRefFrames;
1037 }
1038 
1039 void H264Parser::decode_PPS(GetBitContext * gb)
1040 {
1041  /*
1042  m_picParameterSetId identifies the picture parameter set that
1043  is referred to in the slice header. The value of
1044  m_picParameterSetId shall be in the range of 0 to 255,
1045  inclusive.
1046  */
1047  m_picParameterSetId = get_ue_golomb(gb);
1048 
1049  /*
1050  m_seqParameterSetId refers to the active sequence parameter
1051  set. The value of m_seqParameterSetId shall be in the range of
1052  0 to 31, inclusive.
1053  */
1054  m_seqParameterSetId = get_ue_golomb(gb);
1055  get_bits1(gb); // entropy_coding_mode_flag;
1056 
1057  /*
1058  m_picOrderPresentFlag equal to 1 specifies that the picture
1059  order count related syntax elements are present in the slice
1060  headers as specified in subclause 7.3.3. m_picOrderPresentFlag
1061  equal to 0 specifies that the picture order count related syntax
1062  elements are not present in the slice headers.
1063  */
1064  m_picOrderPresentFlag = get_bits1(gb);
1065 
1066 #if 0 // Rest not currently needed, and requires <math.h>
1067  uint num_slice_groups = get_ue_golomb(gb) + 1;
1068  if (num_slice_groups > 1) // num_slice_groups (minus 1)
1069  {
1070  uint idx;
1071 
1072  switch (get_ue_golomb(gb)) // slice_group_map_type
1073  {
1074  case 0:
1075  for (idx = 0; idx < num_slice_groups; ++idx)
1076  get_ue_golomb(gb); // run_length_minus1[idx]
1077  break;
1078  case 1:
1079  for (idx = 0; idx < num_slice_groups; ++idx)
1080  {
1081  get_ue_golomb(gb); // top_left[idx]
1082  get_ue_golomb(gb); // bottom_right[idx]
1083  }
1084  break;
1085  case 3:
1086  case 4:
1087  case 5:
1088  get_bits1(gb); // slice_group_change_direction_flag
1089  get_ue_golomb(gb); // slice_group_change_rate_minus1
1090  break;
1091  case 6:
1092  uint pic_size_in_map_units = get_ue_golomb(gb) + 1;
1093  uint num_bits = (int)ceil(log2(num_slice_groups));
1094  for (idx = 0; idx < pic_size_in_map_units; ++idx)
1095  {
1096  get_bits(gb, num_bits); //slice_group_id[idx]
1097  }
1098  }
1099  }
1100 
1101  get_ue_golomb(gb); // num_ref_idx_10_active_minus1
1102  get_ue_golomb(gb); // num_ref_idx_11_active_minus1
1103  get_bits1(gb); // weighted_pred_flag;
1104  get_bits(gb, 2); // weighted_bipred_idc
1105  get_se_golomb(gb); // pic_init_qp_minus26
1106  get_se_golomb(gb); // pic_init_qs_minus26
1107  get_se_golomb(gb); // chroma_qp_index_offset
1108  get_bits1(gb); // deblocking_filter_control_present_flag
1109  get_bits1(gb); // constrained_intra_pref_flag
1110  m_redundantPicCntPresentFlag = get_bits1(gb);
1111 #endif
1112 }
1113 
1114 void H264Parser::decode_SEI(GetBitContext *gb)
1115 {
1116  int recovery_frame_cnt = -1;
1117 #if 0
1118  bool exact_match_flag = false;
1119  bool broken_link_flag = false;
1120  int changing_group_slice_idc = -1;
1121 #endif
1122 
1123  int type = 0;
1124  int size = 0;
1125 
1126  /* A message requires at least 2 bytes, and then
1127  * there's the stop bit plus alignment, so there
1128  * can be no message in less than 24 bits */
1129  while (get_bits_left(gb) >= 24)
1130  {
1131  do {
1132  type += show_bits(gb, 8);
1133  } while (get_bits(gb, 8) == 0xFF);
1134 
1135  do {
1136  size += show_bits(gb, 8);
1137  } while (get_bits(gb, 8) == 0xFF);
1138 
1139  switch (type)
1140  {
1142  recovery_frame_cnt = get_ue_golomb(gb);
1143 #if 0
1144  exact_match_flag = (get_bits1(gb) != 0U);
1145  broken_link_flag = (get_bits1(gb) != 0U);
1146  changing_group_slice_idc = get_bits(gb, 2);
1147 #endif
1148  m_auContainsKeyframeMessage = (recovery_frame_cnt == 0);
1149  if ((size - 12) > 0)
1150  skip_bits(gb, (size - 12) * 8);
1151  return;
1152 
1153  default:
1154  skip_bits(gb, size * 8);
1155  break;
1156  }
1157  }
1158 }
1159 
1160 void H264Parser::vui_parameters(GetBitContext * gb)
1161 {
1162  /*
1163  aspect_ratio_info_present_flag equal to 1 specifies that
1164  m_aspectRatioIdc is present. aspect_ratio_info_present_flag
1165  equal to 0 specifies that m_aspectRatioIdc is not present.
1166  */
1167  if (get_bits1(gb)) //aspect_ratio_info_present_flag
1168  {
1169  /*
1170  m_aspectRatioIdc specifies the value of the sample aspect
1171  ratio of the luma samples. Table E-1 shows the meaning of
1172  the code. When m_aspectRatioIdc indicates Extended_SAR, the
1173  sample aspect ratio is represented by m_sarWidth and
1174  m_sarHeight. When the m_aspectRatioIdc syntax element is not
1175  present, m_aspectRatioIdc value shall be inferred to be
1176  equal to 0.
1177  */
1178  m_aspectRatioIdc = get_bits(gb, 8);
1179 
1180  switch (m_aspectRatioIdc)
1181  {
1182  case 0: // NOLINT(bugprone-branch-clone)
1183  // Unspecified
1184  break;
1185  case 1:
1186  // 1:1
1187  /*
1188  1280x720 16:9 frame without overscan
1189  1920x1080 16:9 frame without overscan (cropped from 1920x1088)
1190  640x480 4:3 frame without overscan
1191  */
1192  break;
1193  case 2:
1194  // 12:11
1195  /*
1196  720x576 4:3 frame with horizontal overscan
1197  352x288 4:3 frame without overscan
1198  */
1199  break;
1200  case 3:
1201  // 10:11
1202  /*
1203  720x480 4:3 frame with horizontal overscan
1204  352x240 4:3 frame without overscan
1205  */
1206  break;
1207  case 4:
1208  // 16:11
1209  /*
1210  720x576 16:9 frame with horizontal overscan
1211  540x576 4:3 frame with horizontal overscan
1212  */
1213  break;
1214  case 5:
1215  // 40:33
1216  /*
1217  720x480 16:9 frame with horizontal overscan
1218  540x480 4:3 frame with horizontal overscan
1219  */
1220  break;
1221  case 6:
1222  // 24:11
1223  /*
1224  352x576 4:3 frame without overscan
1225  540x576 16:9 frame with horizontal overscan
1226  */
1227  break;
1228  case 7:
1229  // 20:11
1230  /*
1231  352x480 4:3 frame without overscan
1232  480x480 16:9 frame with horizontal overscan
1233  */
1234  break;
1235  case 8:
1236  // 32:11
1237  /*
1238  352x576 16:9 frame without overscan
1239  */
1240  break;
1241  case 9:
1242  // 80:33
1243  /*
1244  352x480 16:9 frame without overscan
1245  */
1246  break;
1247  case 10:
1248  // 18:11
1249  /*
1250  480x576 4:3 frame with horizontal overscan
1251  */
1252  break;
1253  case 11:
1254  // 15:11
1255  /*
1256  480x480 4:3 frame with horizontal overscan
1257  */
1258  break;
1259  case 12:
1260  // 64:33
1261  /*
1262  540x576 16:9 frame with horizontal overscan
1263  */
1264  break;
1265  case 13:
1266  // 160:99
1267  /*
1268  540x576 16:9 frame with horizontal overscan
1269  */
1270  break;
1271  case EXTENDED_SAR:
1272  m_sarWidth = get_bits(gb, 16);
1273  m_sarHeight = get_bits(gb, 16);
1274  break;
1275  }
1276  }
1277  else
1278  m_sarWidth = m_sarHeight = 0;
1279 
1280  if (get_bits1(gb)) //overscan_info_present_flag
1281  get_bits1(gb); //overscan_appropriate_flag
1282 
1283  if (get_bits1(gb)) //video_signal_type_present_flag
1284  {
1285  get_bits(gb, 3); //video_format
1286  get_bits1(gb); //video_full_range_flag
1287  if (get_bits1(gb)) // colour_description_present_flag
1288  {
1289  get_bits(gb, 8); // colour_primaries
1290  get_bits(gb, 8); // transfer_characteristics
1291  get_bits(gb, 8); // matrix_coefficients
1292  }
1293  }
1294 
1295  if (get_bits1(gb)) //chroma_loc_info_present_flag
1296  {
1297  get_ue_golomb(gb); //chroma_sample_loc_type_top_field ue(v)
1298  get_ue_golomb(gb); //chroma_sample_loc_type_bottom_field ue(v)
1299  }
1300 
1301  if (get_bits1(gb)) //timing_info_present_flag
1302  {
1303  m_unitsInTick = get_bits_long(gb, 32); //num_units_in_tick
1304  m_timeScale = get_bits_long(gb, 32); //time_scale
1305  m_fixedRate = (get_bits1(gb) != 0U);
1306  }
1307 }
1308 
1309 double H264Parser::frameRate(void) const
1310 {
1311  uint64_t num = 500 * (uint64_t)m_timeScale; /* 1000 * 0.5 */
1312  double fps = ( m_unitsInTick != 0 ? num / (double)m_unitsInTick : 0 ) / 1000;
1313 
1314  return fps;
1315 }
1316 
1318 {
1319  if (m_unitsInTick == 0)
1320  result = FrameRate(0);
1321  else if (m_timeScale & 0x1)
1322  result = FrameRate(m_timeScale, m_unitsInTick * 2);
1323  else
1324  result = FrameRate(m_timeScale / 2, m_unitsInTick);
1325 }
1326 
1328 {
1329  return m_numRefFrames;
1330 }
1331 
1333 {
1334 
1335  double aspect = 0.0;
1336 
1337  if (m_picHeight)
1338  aspect = pictureWidthCropped() / (double)pictureHeightCropped();
1339 
1340  switch (m_aspectRatioIdc)
1341  {
1342  case 0: // Unspecified
1343  case 1: // 1:1
1344  break;
1345  case 2:
1346  // 12:11
1347  aspect *= 1.0909090909090908;
1348  break;
1349  case 3:
1350  // 10:11
1351  aspect *= 0.90909090909090906;
1352  break;
1353  case 4:
1354  // 16:11
1355  aspect *= 1.4545454545454546;
1356  break;
1357  case 5:
1358  // 40:33
1359  aspect *= 1.2121212121212122;
1360  break;
1361  case 6:
1362  // 24:11
1363  aspect *= 2.1818181818181817;
1364  break;
1365  case 7:
1366  // 20:11
1367  aspect *= 1.8181818181818181;
1368  break;
1369  case 8:
1370  // 32:11
1371  aspect *= 2.9090909090909092;
1372  break;
1373  case 9:
1374  // 80:33
1375  aspect *= 2.4242424242424243;
1376  break;
1377  case 10:
1378  // 18:11
1379  aspect *= 1.6363636363636365;
1380  break;
1381  case 11:
1382  // 15:11
1383  aspect *= 1.3636363636363635;
1384  break;
1385  case 12:
1386  // 64:33
1387  aspect *= 1.9393939393939394;
1388  break;
1389  case 13:
1390  // 160:99
1391  aspect *= 1.6161616161616161;
1392  break;
1393  case 14:
1394  // 4:3
1395  aspect *= 1.3333333333333333;
1396  break;
1397  case 15:
1398  // 3:2
1399  aspect *= 1.5;
1400  break;
1401  case 16:
1402  // 2:1
1403  aspect *= 2.0;
1404  break;
1405  case EXTENDED_SAR:
1406  if (m_sarHeight)
1407  aspect *= m_sarWidth / (double)m_sarHeight;
1408  else
1409  aspect = 0.0;
1410  break;
1411  }
1412 
1413  if (aspect == 0.0)
1414  return 0;
1415  if (fabs(aspect - 1.3333333333333333) < static_cast<double>(eps))
1416  return 2;
1417  if (fabs(aspect - 1.7777777777777777) < static_cast<double>(eps))
1418  return 3;
1419  if (fabs(aspect - 2.21) < static_cast<double>(eps))
1420  return 4;
1421 
1422  return aspect * 1000000;
1423 }
1424 
1425 // Following the lead of libavcodec, ignore the left cropping.
1427 {
1428  uint ChromaArrayType = m_separateColourPlaneFlag ? 0 : m_chromaFormatIdc;
1429  uint CropUnitX = 1;
1430  uint SubWidthC = m_chromaFormatIdc == 3 ? 1 : 2;
1431  if (ChromaArrayType != 0)
1432  CropUnitX = SubWidthC;
1433  uint crop = CropUnitX * m_frameCropRightOffset;
1434  return m_picWidth - crop;
1435 }
1436 
1437 // Following the lead of libavcodec, ignore the top cropping.
1439 {
1440  uint ChromaArrayType = m_separateColourPlaneFlag ? 0 : m_chromaFormatIdc;
1441  uint CropUnitY = 2 - m_frameMbsOnlyFlag;
1442  uint SubHeightC = m_chromaFormatIdc <= 1 ? 2 : 1;
1443  if (ChromaArrayType != 0)
1444  CropUnitY *= SubHeightC;
1445  uint crop = CropUnitY * m_frameCropBottomOffset;
1446  return m_picHeight - crop;
1447 }
bool new_AU(void)
Definition: H264Parser.cpp:219
void decode_SEI(GetBitContext *gb)
uint64_t m_spsOffset
Definition: H264Parser.h:297
int m_frameNum
Definition: H264Parser.h:242
int m_picOrderCntLsb
Definition: H264Parser.h:255
bool m_fixedRate
Definition: H264Parser.h:291
uint64_t m_frameStartOffset
Definition: H264Parser.h:295
uint8_t m_prevNalUnitType
Definition: H264Parser.h:260
int m_prevFrameNum
Definition: H264Parser.h:241
uint64_t m_auOffset
Definition: H264Parser.h:294
bool m_separateColourPlaneFlag
Definition: H264Parser.h:270
bool m_iIsKeyframe
Definition: H264Parser.h:232
int8_t m_picOrderPresentFlag
Definition: H264Parser.h:272
bool decode_Header(GetBitContext *gb)
Definition: H264Parser.cpp:634
bool m_isKeyframe
Definition: H264Parser.h:231
bool m_auPending
Definition: H264Parser.h:227
int8_t m_prevFieldPicFlag
Definition: H264Parser.h:246
int m_prevPicOrderCntLsb
Definition: H264Parser.h:254
bool m_onKeyFrame
Definition: H264Parser.h:299
uint m_numRefFrames
Definition: H264Parser.h:276
int m_prevDeltaPicOrderCntBottom
Definition: H264Parser.h:256
void parse_SPS(uint8_t *sps, uint32_t sps_size, bool &interlaced, int32_t &max_ref_frames)
int8_t m_prevBottomFieldFlag
Definition: H264Parser.h:248
uint aspectRatio(void) const
Computes aspect ratio from picture size and sample aspect ratio.
static guint32 * tmp
Definition: goom_core.cpp:30
uint8_t m_prevNALRefIdc
Definition: H264Parser.h:250
uint m_log2MaxFrameNum
Definition: H264Parser.h:265
uint m_frameCropBottomOffset
Definition: H264Parser.h:285
int m_prevPicParameterSetId
Definition: H264Parser.h:244
uint pictureWidthCropped(void) const
void Reset(void)
Definition: H264Parser.cpp:103
bool fillRBSP(const uint8_t *byteP, uint32_t byte_count, bool found_start_code)
Definition: H264Parser.cpp:345
bool m_stateChanged
Definition: H264Parser.h:228
uint8_t m_nalRefIdc
Definition: H264Parser.h:251
uint m_log2MaxPicOrderCntLsb
Definition: H264Parser.h:266
uint m_redundantPicCnt
Definition: H264Parser.h:277
uint m_sliceType
Definition: H264Parser.h:243
void vui_parameters(GetBitContext *gb)
uint m_frameCropLeftOffset
Definition: H264Parser.h:282
int m_prevDeltaPicOrderCnt[2]
Definition: H264Parser.h:258
bool m_onFrame
Definition: H264Parser.h:298
bool m_auContainsKeyframeMessage
Definition: H264Parser.h:230
int m_deltaPicOrderCnt[2]
Definition: H264Parser.h:259
uint m_picHeight
Definition: H264Parser.h:281
static const float eps
Definition: H264Parser.cpp:18
void getFrameRate(FrameRate &result) const
uint8_t m_deltaPicOrderAlwaysZeroFlag
Definition: H264Parser.h:269
bool m_seenSps
Definition: H264Parser.h:229
uint8_t * m_rbspBuffer
Definition: H264Parser.h:235
uint32_t m_consecutiveZeros
Definition: H264Parser.h:238
uint m_sarWidth
Definition: H264Parser.h:287
void set_AU_pending(void)
Definition: H264Parser.h:206
unsigned int uint
Definition: compat.h:140
int m_picParameterSetId
Definition: H264Parser.h:245
static bool NALisSlice(uint8_t nal_type)
Definition: H264Parser.h:181
uint m_frameCropTopOffset
Definition: H264Parser.h:284
uint64_t m_keyframeStartOffset
Definition: H264Parser.h:296
uint8_t m_aspectRatioIdc
Definition: H264Parser.h:286
void decode_PPS(GetBitContext *gb)
void processRBSP(bool rbsp_complete)
Definition: H264Parser.cpp:553
int m_deltaPicOrderCntBottom
Definition: H264Parser.h:257
uint32_t addBytes(const uint8_t *bytes, uint32_t byte_count, uint64_t stream_offset)
Definition: H264Parser.cpp:422
static QString NAL_type_str(uint8_t type)
Definition: H264Parser.cpp:183
uint8_t m_prevPicOrderCntType
Definition: H264Parser.h:252
uint getRefFrames(void) const
uint m_picWidth
Definition: H264Parser.h:280
uint32_t m_syncAccumulator
Definition: H264Parser.h:234
uint m_idrPicId
Definition: H264Parser.h:263
uint m_frameCropRightOffset
Definition: H264Parser.h:283
int8_t m_bottomFieldFlag
Definition: H264Parser.h:249
double frameRate(void) const
void resetRBSP(void)
Definition: H264Parser.cpp:338
uint32_t m_unitsInTick
Definition: H264Parser.h:289
bool m_haveUnfinishedNAL
Definition: H264Parser.h:239
static bool isKeySlice(uint slice_type)
Definition: H264Parser.h:173
uint m_prevIdrPicId
Definition: H264Parser.h:262
void decode_SPS(GetBitContext *gb)
Definition: H264Parser.cpp:830
int8_t m_fieldPicFlag
Definition: H264Parser.h:247
uint64_t m_pktOffset
Definition: H264Parser.h:293
uint8_t m_nalUnitType
Definition: H264Parser.h:261
uint8_t m_picOrderCntType
Definition: H264Parser.h:253
uint m_sarHeight
Definition: H264Parser.h:288
static int x3
Definition: mythsocket.cpp:62
int8_t m_frameMbsOnlyFlag
Definition: H264Parser.h:271
uint32_t m_timeScale
Definition: H264Parser.h:290
uint32_t m_rbspBufferSize
Definition: H264Parser.h:236
H264Parser(void)
Definition: H264Parser.cpp:94
int8_t m_redundantPicCntPresentFlag
Definition: H264Parser.h:273
uint32_t m_rbspIndex
Definition: H264Parser.h:237
int8_t m_chromaFormatIdc
Definition: H264Parser.h:274
uint pictureHeightCropped(void) const
static int x1
Definition: mythsocket.cpp:60
uint m_seqParameterSetId
Definition: H264Parser.h:267
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23