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