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