FFmpeg  4.1.11
cbs_h264_syntax_template.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
20 {
21  int err;
22 
23  fixed(1, rbsp_stop_one_bit, 1);
24  while (byte_alignment(rw) != 0)
25  fixed(1, rbsp_alignment_zero_bit, 0);
26 
27  return 0;
28 }
29 
31  H264RawNALUnitHeader *current,
32  uint32_t valid_type_mask)
33 {
34  int err;
35 
36  u(1, forbidden_zero_bit, 0, 0);
37  u(2, nal_ref_idc, 0, 3);
38  u(5, nal_unit_type, 0, 31);
39 
40  if (!(1 << current->nal_unit_type & valid_type_mask)) {
41  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid NAL unit type %d.\n",
42  current->nal_unit_type);
43  return AVERROR_INVALIDDATA;
44  }
45 
46  if (current->nal_unit_type == 14 ||
47  current->nal_unit_type == 20 ||
48  current->nal_unit_type == 21) {
49  if (current->nal_unit_type != 21)
50  flag(svc_extension_flag);
51  else
52  flag(avc_3d_extension_flag);
53 
54  if (current->svc_extension_flag) {
55  av_log(ctx->log_ctx, AV_LOG_ERROR, "SVC not supported.\n");
56  return AVERROR_PATCHWELCOME;
57 
58  } else if (current->avc_3d_extension_flag) {
59  av_log(ctx->log_ctx, AV_LOG_ERROR, "3DAVC not supported.\n");
60  return AVERROR_PATCHWELCOME;
61 
62  } else {
63  av_log(ctx->log_ctx, AV_LOG_ERROR, "MVC not supported.\n");
64  return AVERROR_PATCHWELCOME;
65  }
66  }
67 
68  return 0;
69 }
70 
72  H264RawScalingList *current,
73  int size_of_scaling_list)
74 {
75  int err, i, scale;
76 
77  scale = 8;
78  for (i = 0; i < size_of_scaling_list; i++) {
79  ses(delta_scale[i], -128, +127, 1, i);
80  scale = (scale + current->delta_scale[i] + 256) % 256;
81  if (scale == 0)
82  break;
83  }
84 
85  return 0;
86 }
87 
89  H264RawHRD *current)
90 {
91  int err, i;
92 
93  ue(cpb_cnt_minus1, 0, 31);
94  u(4, bit_rate_scale, 0, 15);
95  u(4, cpb_size_scale, 0, 15);
96 
97  for (i = 0; i <= current->cpb_cnt_minus1; i++) {
98  ues(bit_rate_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
99  ues(cpb_size_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
100  flags(cbr_flag[i], 1, i);
101  }
102 
103  u(5, initial_cpb_removal_delay_length_minus1, 0, 31);
104  u(5, cpb_removal_delay_length_minus1, 0, 31);
105  u(5, dpb_output_delay_length_minus1, 0, 31);
106  u(5, time_offset_length, 0, 31);
107 
108  return 0;
109 }
110 
112  H264RawVUI *current, H264RawSPS *sps)
113 {
114  int err;
115 
116  flag(aspect_ratio_info_present_flag);
117  if (current->aspect_ratio_info_present_flag) {
118  u(8, aspect_ratio_idc, 0, 255);
119  if (current->aspect_ratio_idc == 255) {
120  u(16, sar_width, 0, 65535);
121  u(16, sar_height, 0, 65535);
122  }
123  } else {
124  infer(aspect_ratio_idc, 0);
125  }
126 
127  flag(overscan_info_present_flag);
128  if (current->overscan_info_present_flag)
129  flag(overscan_appropriate_flag);
130 
131  flag(video_signal_type_present_flag);
132  if (current->video_signal_type_present_flag) {
133  u(3, video_format, 0, 7);
134  flag(video_full_range_flag);
135  flag(colour_description_present_flag);
136  if (current->colour_description_present_flag) {
137  u(8, colour_primaries, 0, 255);
138  u(8, transfer_characteristics, 0, 255);
139  u(8, matrix_coefficients, 0, 255);
140  } else {
141  infer(colour_primaries, 2);
143  infer(matrix_coefficients, 2);
144  }
145  } else {
146  infer(video_format, 5);
147  infer(video_full_range_flag, 0);
148  infer(colour_primaries, 2);
150  infer(matrix_coefficients, 2);
151  }
152 
153  flag(chroma_loc_info_present_flag);
154  if (current->chroma_loc_info_present_flag) {
155  ue(chroma_sample_loc_type_top_field, 0, 5);
156  ue(chroma_sample_loc_type_bottom_field, 0, 5);
157  } else {
158  infer(chroma_sample_loc_type_top_field, 0);
159  infer(chroma_sample_loc_type_bottom_field, 0);
160  }
161 
162  flag(timing_info_present_flag);
163  if (current->timing_info_present_flag) {
164  u(32, num_units_in_tick, 1, UINT32_MAX);
165  u(32, time_scale, 1, UINT32_MAX);
166  flag(fixed_frame_rate_flag);
167  } else {
168  infer(fixed_frame_rate_flag, 0);
169  }
170 
171  flag(nal_hrd_parameters_present_flag);
172  if (current->nal_hrd_parameters_present_flag)
173  CHECK(FUNC(hrd_parameters)(ctx, rw, &current->nal_hrd_parameters));
174 
175  flag(vcl_hrd_parameters_present_flag);
176  if (current->vcl_hrd_parameters_present_flag)
177  CHECK(FUNC(hrd_parameters)(ctx, rw, &current->vcl_hrd_parameters));
178 
179  if (current->nal_hrd_parameters_present_flag ||
180  current->vcl_hrd_parameters_present_flag)
181  flag(low_delay_hrd_flag);
182  else
183  infer(low_delay_hrd_flag, 1 - current->fixed_frame_rate_flag);
184 
185  flag(pic_struct_present_flag);
186 
187  flag(bitstream_restriction_flag);
188  if (current->bitstream_restriction_flag) {
189  flag(motion_vectors_over_pic_boundaries_flag);
190  ue(max_bytes_per_pic_denom, 0, 16);
191  ue(max_bits_per_mb_denom, 0, 16);
192  // The current version of the standard constrains this to be in
193  // [0,15], but older versions allow 16.
194  ue(log2_max_mv_length_horizontal, 0, 16);
195  ue(log2_max_mv_length_vertical, 0, 16);
196  ue(max_num_reorder_frames, 0, H264_MAX_DPB_FRAMES);
197  ue(max_dec_frame_buffering, 0, H264_MAX_DPB_FRAMES);
198  } else {
199  infer(motion_vectors_over_pic_boundaries_flag, 1);
200  infer(max_bytes_per_pic_denom, 2);
201  infer(max_bits_per_mb_denom, 1);
202  infer(log2_max_mv_length_horizontal, 15);
203  infer(log2_max_mv_length_vertical, 15);
204 
205  if ((sps->profile_idc == 44 || sps->profile_idc == 86 ||
206  sps->profile_idc == 100 || sps->profile_idc == 110 ||
207  sps->profile_idc == 122 || sps->profile_idc == 244) &&
208  sps->constraint_set3_flag) {
209  infer(max_num_reorder_frames, 0);
210  infer(max_dec_frame_buffering, 0);
211  } else {
212  infer(max_num_reorder_frames, H264_MAX_DPB_FRAMES);
213  infer(max_dec_frame_buffering, H264_MAX_DPB_FRAMES);
214  }
215  }
216 
217  return 0;
218 }
219 
221  RWContext *rw, H264RawVUI *current,
222  H264RawSPS *sps)
223 {
224  infer(aspect_ratio_idc, 0);
225 
226  infer(video_format, 5);
227  infer(video_full_range_flag, 0);
228  infer(colour_primaries, 2);
230  infer(matrix_coefficients, 2);
231 
232  infer(chroma_sample_loc_type_top_field, 0);
233  infer(chroma_sample_loc_type_bottom_field, 0);
234 
235  infer(fixed_frame_rate_flag, 0);
236  infer(low_delay_hrd_flag, 1);
237 
238  infer(pic_struct_present_flag, 0);
239 
240  infer(motion_vectors_over_pic_boundaries_flag, 1);
241  infer(max_bytes_per_pic_denom, 2);
242  infer(max_bits_per_mb_denom, 1);
243  infer(log2_max_mv_length_horizontal, 15);
244  infer(log2_max_mv_length_vertical, 15);
245 
246  if ((sps->profile_idc == 44 || sps->profile_idc == 86 ||
247  sps->profile_idc == 100 || sps->profile_idc == 110 ||
248  sps->profile_idc == 122 || sps->profile_idc == 244) &&
249  sps->constraint_set3_flag) {
250  infer(max_num_reorder_frames, 0);
251  infer(max_dec_frame_buffering, 0);
252  } else {
253  infer(max_num_reorder_frames, H264_MAX_DPB_FRAMES);
254  infer(max_dec_frame_buffering, H264_MAX_DPB_FRAMES);
255  }
256 
257  return 0;
258 }
259 
261  H264RawSPS *current)
262 {
263  int err, i;
264 
265  HEADER("Sequence Parameter Set");
266 
267  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
268  1 << H264_NAL_SPS));
269 
270  u(8, profile_idc, 0, 255);
271 
272  flag(constraint_set0_flag);
273  flag(constraint_set1_flag);
274  flag(constraint_set2_flag);
275  flag(constraint_set3_flag);
276  flag(constraint_set4_flag);
277  flag(constraint_set5_flag);
278 
279  u(2, reserved_zero_2bits, 0, 0);
280 
281  u(8, level_idc, 0, 255);
282 
283  ue(seq_parameter_set_id, 0, 31);
284 
285  if (current->profile_idc == 100 || current->profile_idc == 110 ||
286  current->profile_idc == 122 || current->profile_idc == 244 ||
287  current->profile_idc == 44 || current->profile_idc == 83 ||
288  current->profile_idc == 86 || current->profile_idc == 118 ||
289  current->profile_idc == 128 || current->profile_idc == 138) {
290  ue(chroma_format_idc, 0, 3);
291 
292  if (current->chroma_format_idc == 3)
293  flag(separate_colour_plane_flag);
294  else
295  infer(separate_colour_plane_flag, 0);
296 
297  ue(bit_depth_luma_minus8, 0, 6);
298  ue(bit_depth_chroma_minus8, 0, 6);
299 
300  flag(qpprime_y_zero_transform_bypass_flag);
301 
302  flag(seq_scaling_matrix_present_flag);
303  if (current->seq_scaling_matrix_present_flag) {
304  for (i = 0; i < ((current->chroma_format_idc != 3) ? 8 : 12); i++) {
305  flags(seq_scaling_list_present_flag[i], 1, i);
306  if (current->seq_scaling_list_present_flag[i]) {
307  if (i < 6)
308  CHECK(FUNC(scaling_list)(ctx, rw,
309  &current->scaling_list_4x4[i],
310  16));
311  else
312  CHECK(FUNC(scaling_list)(ctx, rw,
313  &current->scaling_list_8x8[i - 6],
314  64));
315  }
316  }
317  }
318  } else {
319  infer(chroma_format_idc, current->profile_idc == 183 ? 0 : 1);
320 
321  infer(separate_colour_plane_flag, 0);
322  infer(bit_depth_luma_minus8, 0);
323  infer(bit_depth_chroma_minus8, 0);
324  }
325 
326  ue(log2_max_frame_num_minus4, 0, 12);
327  ue(pic_order_cnt_type, 0, 2);
328 
329  if (current->pic_order_cnt_type == 0) {
330  ue(log2_max_pic_order_cnt_lsb_minus4, 0, 12);
331  } else if (current->pic_order_cnt_type == 1) {
332  flag(delta_pic_order_always_zero_flag);
333  se(offset_for_non_ref_pic, INT32_MIN + 1, INT32_MAX);
334  se(offset_for_top_to_bottom_field, INT32_MIN + 1, INT32_MAX);
335  ue(num_ref_frames_in_pic_order_cnt_cycle, 0, 255);
336 
337  for (i = 0; i < current->num_ref_frames_in_pic_order_cnt_cycle; i++)
338  ses(offset_for_ref_frame[i], INT32_MIN + 1, INT32_MAX, 1, i);
339  }
340 
341  ue(max_num_ref_frames, 0, H264_MAX_DPB_FRAMES);
342  flag(gaps_in_frame_num_allowed_flag);
343 
344  ue(pic_width_in_mbs_minus1, 0, H264_MAX_MB_WIDTH);
345  ue(pic_height_in_map_units_minus1, 0, H264_MAX_MB_HEIGHT);
346 
347  flag(frame_mbs_only_flag);
348  if (!current->frame_mbs_only_flag)
349  flag(mb_adaptive_frame_field_flag);
350 
351  flag(direct_8x8_inference_flag);
352 
353  flag(frame_cropping_flag);
354  if (current->frame_cropping_flag) {
355  ue(frame_crop_left_offset, 0, H264_MAX_WIDTH);
356  ue(frame_crop_right_offset, 0, H264_MAX_WIDTH);
357  ue(frame_crop_top_offset, 0, H264_MAX_HEIGHT);
358  ue(frame_crop_bottom_offset, 0, H264_MAX_HEIGHT);
359  }
360 
361  flag(vui_parameters_present_flag);
362  if (current->vui_parameters_present_flag)
363  CHECK(FUNC(vui_parameters)(ctx, rw, &current->vui, current));
364  else
365  CHECK(FUNC(vui_parameters_default)(ctx, rw, &current->vui, current));
366 
368 
369  return 0;
370 }
371 
373  H264RawSPSExtension *current)
374 {
375  int err;
376 
377  HEADER("Sequence Parameter Set Extension");
378 
379  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
380  1 << H264_NAL_SPS_EXT));
381 
382  ue(seq_parameter_set_id, 0, 31);
383 
384  ue(aux_format_idc, 0, 3);
385 
386  if (current->aux_format_idc != 0) {
387  int bits;
388 
389  ue(bit_depth_aux_minus8, 0, 4);
390  flag(alpha_incr_flag);
391 
392  bits = current->bit_depth_aux_minus8 + 9;
393  u(bits, alpha_opaque_value, 0, MAX_UINT_BITS(bits));
394  u(bits, alpha_transparent_value, 0, MAX_UINT_BITS(bits));
395  }
396 
397  flag(additional_extension_flag);
398 
400 
401  return 0;
402 }
403 
405  H264RawPPS *current)
406 {
408  const H264RawSPS *sps;
409  int err, i;
410 
411  HEADER("Picture Parameter Set");
412 
413  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
414  1 << H264_NAL_PPS));
415 
416  ue(pic_parameter_set_id, 0, 255);
417  ue(seq_parameter_set_id, 0, 31);
418 
419  sps = h264->sps[current->seq_parameter_set_id];
420  if (!sps) {
421  av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
422  current->seq_parameter_set_id);
423  return AVERROR_INVALIDDATA;
424  }
425 
426  flag(entropy_coding_mode_flag);
427  flag(bottom_field_pic_order_in_frame_present_flag);
428 
429  ue(num_slice_groups_minus1, 0, 7);
430  if (current->num_slice_groups_minus1 > 0) {
431  unsigned int pic_size;
432  int iGroup;
433 
434  pic_size = (sps->pic_width_in_mbs_minus1 + 1) *
436 
437  ue(slice_group_map_type, 0, 6);
438 
439  if (current->slice_group_map_type == 0) {
440  for (iGroup = 0; iGroup <= current->num_slice_groups_minus1; iGroup++)
441  ues(run_length_minus1[iGroup], 0, pic_size - 1, 1, iGroup);
442 
443  } else if (current->slice_group_map_type == 2) {
444  for (iGroup = 0; iGroup < current->num_slice_groups_minus1; iGroup++) {
445  ues(top_left[iGroup], 0, pic_size - 1, 1, iGroup);
446  ues(bottom_right[iGroup],
447  current->top_left[iGroup], pic_size - 1, 1, iGroup);
448  }
449  } else if (current->slice_group_map_type == 3 ||
450  current->slice_group_map_type == 4 ||
451  current->slice_group_map_type == 5) {
452  flag(slice_group_change_direction_flag);
453  ue(slice_group_change_rate_minus1, 0, pic_size - 1);
454  } else if (current->slice_group_map_type == 6) {
455  ue(pic_size_in_map_units_minus1, pic_size - 1, pic_size - 1);
456 
457  allocate(current->slice_group_id,
458  current->pic_size_in_map_units_minus1 + 1);
459  for (i = 0; i <= current->pic_size_in_map_units_minus1; i++)
460  us(av_log2(2 * current->num_slice_groups_minus1 + 1),
461  slice_group_id[i], 0, current->num_slice_groups_minus1, 1, i);
462  }
463  }
464 
465  ue(num_ref_idx_l0_default_active_minus1, 0, 31);
466  ue(num_ref_idx_l1_default_active_minus1, 0, 31);
467 
468  flag(weighted_pred_flag);
469  u(2, weighted_bipred_idc, 0, 2);
470 
471  se(pic_init_qp_minus26, -26 - 6 * sps->bit_depth_luma_minus8, +25);
472  se(pic_init_qs_minus26, -26, +25);
473  se(chroma_qp_index_offset, -12, +12);
474 
475  flag(deblocking_filter_control_present_flag);
476  flag(constrained_intra_pred_flag);
477  flag(redundant_pic_cnt_present_flag);
478 
479  if (more_rbsp_data(current->more_rbsp_data))
480  {
481  flag(transform_8x8_mode_flag);
482 
483  flag(pic_scaling_matrix_present_flag);
484  if (current->pic_scaling_matrix_present_flag) {
485  for (i = 0; i < 6 + (((sps->chroma_format_idc != 3) ? 2 : 6) *
486  current->transform_8x8_mode_flag); i++) {
487  flags(pic_scaling_list_present_flag[i], 1, i);
488  if (current->pic_scaling_list_present_flag[i]) {
489  if (i < 6)
490  CHECK(FUNC(scaling_list)(ctx, rw,
491  &current->scaling_list_4x4[i],
492  16));
493  else
494  CHECK(FUNC(scaling_list)(ctx, rw,
495  &current->scaling_list_8x8[i - 6],
496  64));
497  }
498  }
499  }
500 
501  se(second_chroma_qp_index_offset, -12, +12);
502  } else {
503  infer(transform_8x8_mode_flag, 0);
504  infer(pic_scaling_matrix_present_flag, 0);
505  infer(second_chroma_qp_index_offset, current->chroma_qp_index_offset);
506  }
507 
509 
510  return 0;
511 }
512 
514  H264RawSEIBufferingPeriod *current)
515 {
517  const H264RawSPS *sps;
518  int err, i, length;
519 
520  HEADER("Buffering Period");
521 
522  ue(seq_parameter_set_id, 0, 31);
523 
524  sps = h264->sps[current->seq_parameter_set_id];
525  if (!sps) {
526  av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
527  current->seq_parameter_set_id);
528  return AVERROR_INVALIDDATA;
529  }
530  h264->active_sps = sps;
531 
533  for (i = 0; i <= sps->vui.nal_hrd_parameters.cpb_cnt_minus1; i++) {
535  xu(length, initial_cpb_removal_delay[SchedSelIdx],
536  current->nal.initial_cpb_removal_delay[i],
537  1, MAX_UINT_BITS(length), 1, i);
538  xu(length, initial_cpb_removal_delay_offset[SchedSelIdx],
539  current->nal.initial_cpb_removal_delay_offset[i],
540  0, MAX_UINT_BITS(length), 1, i);
541  }
542  }
543 
545  for (i = 0; i <= sps->vui.vcl_hrd_parameters.cpb_cnt_minus1; i++) {
547  xu(length, initial_cpb_removal_delay[SchedSelIdx],
548  current->vcl.initial_cpb_removal_delay[i],
549  1, MAX_UINT_BITS(length), 1, i);
550  xu(length, initial_cpb_removal_delay_offset[SchedSelIdx],
551  current->vcl.initial_cpb_removal_delay_offset[i],
552  0, MAX_UINT_BITS(length), 1, i);
553  }
554  }
555 
556  return 0;
557 }
558 
560  H264RawSEIPicTimestamp *current,
561  const H264RawSPS *sps)
562 {
563  uint8_t time_offset_length;
564  int err;
565 
566  u(2, ct_type, 0, 2);
567  flag(nuit_field_based_flag);
568  u(5, counting_type, 0, 6);
569  flag(full_timestamp_flag);
570  flag(discontinuity_flag);
571  flag(cnt_dropped_flag);
572  u(8, n_frames, 0, 255);
573  if (current->full_timestamp_flag) {
574  u(6, seconds_value, 0, 59);
575  u(6, minutes_value, 0, 59);
576  u(5, hours_value, 0, 23);
577  } else {
578  flag(seconds_flag);
579  if (current->seconds_flag) {
580  u(6, seconds_value, 0, 59);
581  flag(minutes_flag);
582  if (current->minutes_flag) {
583  u(6, minutes_value, 0, 59);
584  flag(hours_flag);
585  if (current->hours_flag)
586  u(5, hours_value, 0, 23);
587  }
588  }
589  }
590 
591  if (sps->vui.nal_hrd_parameters_present_flag)
592  time_offset_length = sps->vui.nal_hrd_parameters.time_offset_length;
593  else if (sps->vui.vcl_hrd_parameters_present_flag)
594  time_offset_length = sps->vui.vcl_hrd_parameters.time_offset_length;
595  else
596  time_offset_length = 24;
597 
598  if (time_offset_length > 0)
599  i(time_offset_length, time_offset,
600  MIN_INT_BITS(time_offset_length),
601  MAX_INT_BITS(time_offset_length));
602  else
603  infer(time_offset, 0);
604 
605  return 0;
606 }
607 
609  H264RawSEIPicTiming *current)
610 {
612  const H264RawSPS *sps;
613  int err;
614 
615  HEADER("Picture Timing");
616 
617  sps = h264->active_sps;
618  if (!sps) {
619  // If there is exactly one possible SPS but it is not yet active
620  // then just assume that it should be the active one.
621  int i, k = -1;
622  for (i = 0; i < H264_MAX_SPS_COUNT; i++) {
623  if (h264->sps[i]) {
624  if (k >= 0) {
625  k = -1;
626  break;
627  }
628  k = i;
629  }
630  }
631  if (k >= 0)
632  sps = h264->sps[k];
633  }
634  if (!sps) {
635  av_log(ctx->log_ctx, AV_LOG_ERROR,
636  "No active SPS for pic_timing.\n");
637  return AVERROR_INVALIDDATA;
638  }
639 
642  const H264RawHRD *hrd;
643 
645  hrd = &sps->vui.nal_hrd_parameters;
646  else if (sps->vui.vcl_hrd_parameters_present_flag)
647  hrd = &sps->vui.vcl_hrd_parameters;
648  else {
649  av_log(ctx->log_ctx, AV_LOG_ERROR,
650  "No HRD parameters for pic_timing.\n");
651  return AVERROR_INVALIDDATA;
652  }
653 
654  u(hrd->cpb_removal_delay_length_minus1 + 1, cpb_removal_delay,
656  u(hrd->dpb_output_delay_length_minus1 + 1, dpb_output_delay,
658  }
659 
660  if (sps->vui.pic_struct_present_flag) {
661  static const int num_clock_ts[9] = {
662  1, 1, 1, 2, 2, 3, 3, 2, 3
663  };
664  int i;
665 
666  u(4, pic_struct, 0, 8);
667  if (current->pic_struct > 8)
668  return AVERROR_INVALIDDATA;
669 
670  for (i = 0; i < num_clock_ts[current->pic_struct]; i++) {
671  flags(clock_timestamp_flag[i], 1, i);
672  if (current->clock_timestamp_flag[i])
674  &current->timestamp[i], sps));
675  }
676  }
677 
678  return 0;
679 }
680 
682  H264RawSEIPanScanRect *current)
683 {
684  int err, i;
685 
686  HEADER("Pan-Scan Rectangle");
687 
688  ue(pan_scan_rect_id, 0, UINT32_MAX - 1);
689  flag(pan_scan_rect_cancel_flag);
690 
691  if (!current->pan_scan_rect_cancel_flag) {
692  ue(pan_scan_cnt_minus1, 0, 2);
693 
694  for (i = 0; i <= current->pan_scan_cnt_minus1; i++) {
695  ses(pan_scan_rect_left_offset[i], INT32_MIN + 1, INT32_MAX, 1, i);
696  ses(pan_scan_rect_right_offset[i], INT32_MIN + 1, INT32_MAX, 1, i);
697  ses(pan_scan_rect_top_offset[i], INT32_MIN + 1, INT32_MAX, 1, i);
698  ses(pan_scan_rect_bottom_offset[i], INT32_MIN + 1, INT32_MAX, 1, i);
699  }
700 
701  ue(pan_scan_rect_repetition_period, 0, 16384);
702  }
703 
704  return 0;
705 }
706 
709  uint32_t *payload_size)
710 {
711  int err, i, j;
712 
713  HEADER("User Data Registered ITU-T T.35");
714 
715  u(8, itu_t_t35_country_code, 0x00, 0xff);
716  if (current->itu_t_t35_country_code != 0xff)
717  i = 1;
718  else {
719  u(8, itu_t_t35_country_code_extension_byte, 0x00, 0xff);
720  i = 2;
721  }
722 
723 #ifdef READ
724  if (*payload_size < i) {
725  av_log(ctx->log_ctx, AV_LOG_ERROR,
726  "Invalid SEI user data registered payload.\n");
727  return AVERROR_INVALIDDATA;
728  }
729  current->data_length = *payload_size - i;
730 #else
731  *payload_size = i + current->data_length;
732 #endif
733 
734  allocate(current->data, current->data_length);
735  for (j = 0; j < current->data_length; j++)
736  xu(8, itu_t_t35_payload_byte[i], current->data[j], 0x00, 0xff, 1, i + j);
737 
738  return 0;
739 }
740 
743  uint32_t *payload_size)
744 {
745  int err, i;
746 
747  HEADER("User Data Unregistered");
748 
749 #ifdef READ
750  if (*payload_size < 16) {
751  av_log(ctx->log_ctx, AV_LOG_ERROR,
752  "Invalid SEI user data unregistered payload.\n");
753  return AVERROR_INVALIDDATA;
754  }
755  current->data_length = *payload_size - 16;
756 #else
757  *payload_size = 16 + current->data_length;
758 #endif
759 
760  for (i = 0; i < 16; i++)
761  us(8, uuid_iso_iec_11578[i], 0x00, 0xff, 1, i);
762 
763  allocate(current->data, current->data_length);
764 
765  for (i = 0; i < current->data_length; i++)
766  xu(8, user_data_payload_byte[i], current->data[i], 0x00, 0xff, 1, i);
767 
768  return 0;
769 }
770 
772  H264RawSEIRecoveryPoint *current)
773 {
774  int err;
775 
776  HEADER("Recovery Point");
777 
778  ue(recovery_frame_cnt, 0, 65535);
779  flag(exact_match_flag);
780  flag(broken_link_flag);
781  u(2, changing_slice_group_idc, 0, 2);
782 
783  return 0;
784 }
785 
788 {
789  int err;
790 
791  HEADER("Display Orientation");
792 
793  flag(display_orientation_cancel_flag);
794  if (!current->display_orientation_cancel_flag) {
795  flag(hor_flip);
796  flag(ver_flip);
797  u(16, anticlockwise_rotation, 0, 65535);
798  ue(display_orientation_repetition_period, 0, 16384);
799  flag(display_orientation_extension_flag);
800  }
801 
802  return 0;
803 }
804 
807 {
808  int err, c;
809 
810  HEADER("Mastering Display Colour Volume");
811 
812  for (c = 0; c < 3; c++) {
813  us(16, display_primaries_x[c], 0, 50000, 1, c);
814  us(16, display_primaries_y[c], 0, 50000, 1, c);
815  }
816 
817  u(16, white_point_x, 0, 50000);
818  u(16, white_point_y, 0, 50000);
819 
820  u(32, max_display_mastering_luminance, 1, MAX_UINT_BITS(32));
821  u(32, min_display_mastering_luminance, 0, current->max_display_mastering_luminance - 1);
822 
823  return 0;
824 }
825 
827  H264RawSEIPayload *current)
828 {
829  int err, i;
830  int start_position, end_position;
831 
832 #ifdef READ
833  start_position = get_bits_count(rw);
834 #else
835  start_position = put_bits_count(rw);
836 #endif
837 
838  switch (current->payload_type) {
841  (ctx, rw, &current->payload.buffering_period));
842  break;
845  (ctx, rw, &current->payload.pic_timing));
846  break;
849  (ctx, rw, &current->payload.pan_scan_rect));
850  break;
852  {
853  for (i = 0; i < current->payload_size; i++)
854  fixed(8, ff_byte, 0xff);
855  }
856  break;
859  (ctx, rw, &current->payload.user_data_registered, &current->payload_size));
860  break;
863  (ctx, rw, &current->payload.user_data_unregistered, &current->payload_size));
864  break;
867  (ctx, rw, &current->payload.recovery_point));
868  break;
871  (ctx, rw, &current->payload.display_orientation));
872  break;
875  (ctx, rw, &current->payload.mastering_display_colour_volume));
876  break;
877  default:
878  {
879 #ifdef READ
880  current->payload.other.data_length = current->payload_size;
881 #endif
882  allocate(current->payload.other.data, current->payload.other.data_length);
883  for (i = 0; i < current->payload.other.data_length; i++)
884  xu(8, payload_byte[i], current->payload.other.data[i], 0, 255, 1, i);
885  }
886  }
887 
888  if (byte_alignment(rw)) {
889  fixed(1, bit_equal_to_one, 1);
890  while (byte_alignment(rw))
891  fixed(1, bit_equal_to_zero, 0);
892  }
893 
894 #ifdef READ
895  end_position = get_bits_count(rw);
896  if (end_position < start_position + 8 * current->payload_size) {
897  av_log(ctx->log_ctx, AV_LOG_ERROR, "Incorrect SEI payload length: "
898  "header %"PRIu32" bits, actually %d bits.\n",
899  8 * current->payload_size,
900  end_position - start_position);
901  return AVERROR_INVALIDDATA;
902  }
903 #else
904  end_position = put_bits_count(rw);
905  current->payload_size = (end_position - start_position) / 8;
906 #endif
907 
908  return 0;
909 }
910 
912  H264RawSEI *current)
913 {
914  int err, k;
915 
916  HEADER("Supplemental Enhancement Information");
917 
918  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
919  1 << H264_NAL_SEI));
920 
921 #ifdef READ
922  for (k = 0; k < H264_MAX_SEI_PAYLOADS; k++) {
923  uint32_t payload_type = 0;
924  uint32_t payload_size = 0;
925  uint32_t tmp;
926 
927  while (show_bits(rw, 8) == 0xff) {
928  fixed(8, ff_byte, 0xff);
929  payload_type += 255;
930  }
931  xu(8, last_payload_type_byte, tmp, 0, 254, 0);
932  payload_type += tmp;
933 
934  while (show_bits(rw, 8) == 0xff) {
935  fixed(8, ff_byte, 0xff);
936  payload_size += 255;
937  }
938  xu(8, last_payload_size_byte, tmp, 0, 254, 0);
939  payload_size += tmp;
940 
941  current->payload[k].payload_type = payload_type;
942  current->payload[k].payload_size = payload_size;
943 
944  CHECK(FUNC(sei_payload)(ctx, rw, &current->payload[k]));
945 
947  break;
948  }
949  if (k >= H264_MAX_SEI_PAYLOADS) {
950  av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many payloads in "
951  "SEI message: found %d.\n", k);
952  return AVERROR_INVALIDDATA;
953  }
954  current->payload_count = k + 1;
955 #else
956  for (k = 0; k < current->payload_count; k++) {
957  PutBitContext start_state;
958  uint32_t tmp;
959  int need_size, i;
960 
961  // Somewhat clumsy: we write the payload twice when
962  // we don't know the size in advance. This will mess
963  // with trace output, but is otherwise harmless.
964  start_state = *rw;
965  need_size = !current->payload[k].payload_size;
966  for (i = 0; i < 1 + need_size; i++) {
967  *rw = start_state;
968 
969  tmp = current->payload[k].payload_type;
970  while (tmp >= 255) {
971  fixed(8, ff_byte, 0xff);
972  tmp -= 255;
973  }
974  xu(8, last_payload_type_byte, tmp, 0, 254, 0);
975 
976  tmp = current->payload[k].payload_size;
977  while (tmp >= 255) {
978  fixed(8, ff_byte, 0xff);
979  tmp -= 255;
980  }
981  xu(8, last_payload_size_byte, tmp, 0, 254, 0);
982 
983  CHECK(FUNC(sei_payload)(ctx, rw, &current->payload[k]));
984  }
985  }
986 #endif
987 
989 
990  return 0;
991 }
992 
994  H264RawAUD *current)
995 {
996  int err;
997 
998  HEADER("Access Unit Delimiter");
999 
1000  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
1001  1 << H264_NAL_AUD));
1002 
1003  u(3, primary_pic_type, 0, 7);
1004 
1006 
1007  return 0;
1008 }
1009 
1011  H264RawSliceHeader *current)
1012 {
1014  const H264RawSPS *sps = h264->active_sps;
1015  int err, i, mopn;
1016 
1017  if (current->slice_type % 5 != 2 &&
1018  current->slice_type % 5 != 4) {
1019  flag(ref_pic_list_modification_flag_l0);
1020  if (current->ref_pic_list_modification_flag_l0) {
1021  for (i = 0; i < H264_MAX_RPLM_COUNT; i++) {
1022  xue(modification_of_pic_nums_idc,
1023  current->rplm_l0[i].modification_of_pic_nums_idc, 0, 3, 0);
1024 
1025  mopn = current->rplm_l0[i].modification_of_pic_nums_idc;
1026  if (mopn == 3)
1027  break;
1028 
1029  if (mopn == 0 || mopn == 1)
1030  xue(abs_diff_pic_num_minus1,
1031  current->rplm_l0[i].abs_diff_pic_num_minus1,
1032  0, (1 + current->field_pic_flag) *
1033  (1 << (sps->log2_max_frame_num_minus4 + 4)), 0);
1034  else if (mopn == 2)
1035  xue(long_term_pic_num,
1036  current->rplm_l0[i].long_term_pic_num,
1037  0, sps->max_num_ref_frames - 1, 0);
1038  }
1039  }
1040  }
1041 
1042  if (current->slice_type % 5 == 1) {
1043  flag(ref_pic_list_modification_flag_l1);
1044  if (current->ref_pic_list_modification_flag_l1) {
1045  for (i = 0; i < H264_MAX_RPLM_COUNT; i++) {
1046  xue(modification_of_pic_nums_idc,
1047  current->rplm_l1[i].modification_of_pic_nums_idc, 0, 3, 0);
1048 
1049  mopn = current->rplm_l1[i].modification_of_pic_nums_idc;
1050  if (mopn == 3)
1051  break;
1052 
1053  if (mopn == 0 || mopn == 1)
1054  xue(abs_diff_pic_num_minus1,
1055  current->rplm_l1[i].abs_diff_pic_num_minus1,
1056  0, (1 + current->field_pic_flag) *
1057  (1 << (sps->log2_max_frame_num_minus4 + 4)), 0);
1058  else if (mopn == 2)
1059  xue(long_term_pic_num,
1060  current->rplm_l1[i].long_term_pic_num,
1061  0, sps->max_num_ref_frames - 1, 0);
1062  }
1063  }
1064  }
1065 
1066  return 0;
1067 }
1068 
1070  H264RawSliceHeader *current)
1071 {
1073  const H264RawSPS *sps = h264->active_sps;
1074  int chroma;
1075  int err, i, j;
1076 
1077  ue(luma_log2_weight_denom, 0, 7);
1078 
1079  chroma = !sps->separate_colour_plane_flag && sps->chroma_format_idc != 0;
1080  if (chroma)
1081  ue(chroma_log2_weight_denom, 0, 7);
1082 
1083  for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
1084  flags(luma_weight_l0_flag[i], 1, i);
1085  if (current->luma_weight_l0_flag[i]) {
1086  ses(luma_weight_l0[i], -128, +127, 1, i);
1087  ses(luma_offset_l0[i], -128, +127, 1, i);
1088  }
1089  if (chroma) {
1090  flags(chroma_weight_l0_flag[i], 1, i);
1091  if (current->chroma_weight_l0_flag[i]) {
1092  for (j = 0; j < 2; j++) {
1093  ses(chroma_weight_l0[i][j], -128, +127, 2, i, j);
1094  ses(chroma_offset_l0[i][j], -128, +127, 2, i, j);
1095  }
1096  }
1097  }
1098  }
1099 
1100  if (current->slice_type % 5 == 1) {
1101  for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
1102  flags(luma_weight_l1_flag[i], 1, i);
1103  if (current->luma_weight_l1_flag[i]) {
1104  ses(luma_weight_l1[i], -128, +127, 1, i);
1105  ses(luma_offset_l1[i], -128, +127, 1, i);
1106  }
1107  if (chroma) {
1108  flags(chroma_weight_l1_flag[i], 1, i);
1109  if (current->chroma_weight_l1_flag[i]) {
1110  for (j = 0; j < 2; j++) {
1111  ses(chroma_weight_l1[i][j], -128, +127, 2, i, j);
1112  ses(chroma_offset_l1[i][j], -128, +127, 2, i, j);
1113  }
1114  }
1115  }
1116  }
1117  }
1118 
1119  return 0;
1120 }
1121 
1123  H264RawSliceHeader *current, int idr_pic_flag)
1124 {
1126  const H264RawSPS *sps = h264->active_sps;
1127  int err, i;
1128  uint32_t mmco;
1129 
1130  if (idr_pic_flag) {
1131  flag(no_output_of_prior_pics_flag);
1132  flag(long_term_reference_flag);
1133  } else {
1134  flag(adaptive_ref_pic_marking_mode_flag);
1135  if (current->adaptive_ref_pic_marking_mode_flag) {
1136  for (i = 0; i < H264_MAX_MMCO_COUNT; i++) {
1137  xue(memory_management_control_operation,
1138  current->mmco[i].memory_management_control_operation,
1139  0, 6, 0);
1140 
1141  mmco = current->mmco[i].memory_management_control_operation;
1142  if (mmco == 0)
1143  break;
1144 
1145  if (mmco == 1 || mmco == 3)
1146  xue(difference_of_pic_nums_minus1,
1147  current->mmco[i].difference_of_pic_nums_minus1,
1148  0, INT32_MAX, 0);
1149  if (mmco == 2)
1150  xue(long_term_pic_num,
1151  current->mmco[i].long_term_pic_num,
1152  0, sps->max_num_ref_frames - 1, 0);
1153  if (mmco == 3 || mmco == 6)
1154  xue(long_term_frame_idx,
1155  current->mmco[i].long_term_frame_idx,
1156  0, sps->max_num_ref_frames - 1, 0);
1157  if (mmco == 4)
1158  xue(max_long_term_frame_idx_plus1,
1159  current->mmco[i].max_long_term_frame_idx_plus1,
1160  0, sps->max_num_ref_frames, 0);
1161  }
1162  if (i == H264_MAX_MMCO_COUNT) {
1163  av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many "
1164  "memory management control operations.\n");
1165  return AVERROR_INVALIDDATA;
1166  }
1167  }
1168  }
1169 
1170  return 0;
1171 }
1172 
1174  H264RawSliceHeader *current)
1175 {
1177  const H264RawSPS *sps;
1178  const H264RawPPS *pps;
1179  int err;
1180  int idr_pic_flag;
1181  int slice_type_i, slice_type_p, slice_type_b;
1182  int slice_type_si, slice_type_sp;
1183 
1184  HEADER("Slice Header");
1185 
1186  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
1187  1 << H264_NAL_SLICE |
1188  1 << H264_NAL_IDR_SLICE |
1189  1 << H264_NAL_AUXILIARY_SLICE));
1190 
1191  if (current->nal_unit_header.nal_unit_type == H264_NAL_AUXILIARY_SLICE) {
1192  if (!h264->last_slice_nal_unit_type) {
1193  av_log(ctx->log_ctx, AV_LOG_ERROR, "Auxiliary slice "
1194  "is not decodable without the main picture "
1195  "in the same access unit.\n");
1196  return AVERROR_INVALIDDATA;
1197  }
1198  idr_pic_flag = h264->last_slice_nal_unit_type == H264_NAL_IDR_SLICE;
1199  } else {
1200  idr_pic_flag = current->nal_unit_header.nal_unit_type == H264_NAL_IDR_SLICE;
1201  }
1202 
1203  ue(first_mb_in_slice, 0, H264_MAX_MB_PIC_SIZE - 1);
1204  ue(slice_type, 0, 9);
1205 
1206  slice_type_i = current->slice_type % 5 == 2;
1207  slice_type_p = current->slice_type % 5 == 0;
1208  slice_type_b = current->slice_type % 5 == 1;
1209  slice_type_si = current->slice_type % 5 == 4;
1210  slice_type_sp = current->slice_type % 5 == 3;
1211 
1212  if (idr_pic_flag && !(slice_type_i || slice_type_si)) {
1213  av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid slice type %d "
1214  "for IDR picture.\n", current->slice_type);
1215  return AVERROR_INVALIDDATA;
1216  }
1217 
1218  ue(pic_parameter_set_id, 0, 255);
1219 
1220  pps = h264->pps[current->pic_parameter_set_id];
1221  if (!pps) {
1222  av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
1223  current->pic_parameter_set_id);
1224  return AVERROR_INVALIDDATA;
1225  }
1226  h264->active_pps = pps;
1227 
1228  sps = h264->sps[pps->seq_parameter_set_id];
1229  if (!sps) {
1230  av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
1231  pps->seq_parameter_set_id);
1232  return AVERROR_INVALIDDATA;
1233  }
1234  h264->active_sps = sps;
1235 
1236  if (sps->separate_colour_plane_flag)
1237  u(2, colour_plane_id, 0, 2);
1238 
1239  u(sps->log2_max_frame_num_minus4 + 4, frame_num,
1241 
1242  if (!sps->frame_mbs_only_flag) {
1243  flag(field_pic_flag);
1244  if (current->field_pic_flag)
1245  flag(bottom_field_flag);
1246  else
1247  infer(bottom_field_flag, 0);
1248  } else {
1249  infer(field_pic_flag, 0);
1250  infer(bottom_field_flag, 0);
1251  }
1252 
1253  if (idr_pic_flag)
1254  ue(idr_pic_id, 0, 65535);
1255 
1256  if (sps->pic_order_cnt_type == 0) {
1257  u(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, pic_order_cnt_lsb,
1260  !current->field_pic_flag)
1261  se(delta_pic_order_cnt_bottom, INT32_MIN + 1, INT32_MAX);
1262 
1263  } else if (sps->pic_order_cnt_type == 1) {
1265  se(delta_pic_order_cnt[0], INT32_MIN + 1, INT32_MAX);
1267  !current->field_pic_flag)
1268  se(delta_pic_order_cnt[1], INT32_MIN + 1, INT32_MAX);
1269  else
1270  infer(delta_pic_order_cnt[1], 0);
1271  } else {
1272  infer(delta_pic_order_cnt[0], 0);
1273  infer(delta_pic_order_cnt[1], 0);
1274  }
1275  }
1276 
1278  ue(redundant_pic_cnt, 0, 127);
1279  else
1280  infer(redundant_pic_cnt, 0);
1281 
1282  if (current->nal_unit_header.nal_unit_type != H264_NAL_AUXILIARY_SLICE
1283  && !current->redundant_pic_cnt)
1284  h264->last_slice_nal_unit_type =
1285  current->nal_unit_header.nal_unit_type;
1286 
1287  if (slice_type_b)
1288  flag(direct_spatial_mv_pred_flag);
1289 
1290  if (slice_type_p || slice_type_sp || slice_type_b) {
1291  flag(num_ref_idx_active_override_flag);
1292  if (current->num_ref_idx_active_override_flag) {
1293  ue(num_ref_idx_l0_active_minus1, 0, 31);
1294  if (slice_type_b)
1295  ue(num_ref_idx_l1_active_minus1, 0, 31);
1296  } else {
1297  infer(num_ref_idx_l0_active_minus1,
1299  infer(num_ref_idx_l1_active_minus1,
1301  }
1302  }
1303 
1304  if (current->nal_unit_header.nal_unit_type == 20 ||
1305  current->nal_unit_header.nal_unit_type == 21) {
1306  av_log(ctx->log_ctx, AV_LOG_ERROR, "MVC / 3DAVC not supported.\n");
1307  return AVERROR_PATCHWELCOME;
1308  } else {
1309  CHECK(FUNC(ref_pic_list_modification)(ctx, rw, current));
1310  }
1311 
1312  if ((pps->weighted_pred_flag && (slice_type_p || slice_type_sp)) ||
1313  (pps->weighted_bipred_idc == 1 && slice_type_b)) {
1314  CHECK(FUNC(pred_weight_table)(ctx, rw, current));
1315  }
1316 
1317  if (current->nal_unit_header.nal_ref_idc != 0) {
1318  CHECK(FUNC(dec_ref_pic_marking)(ctx, rw, current, idr_pic_flag));
1319  }
1320 
1321  if (pps->entropy_coding_mode_flag &&
1322  !slice_type_i && !slice_type_si) {
1323  ue(cabac_init_idc, 0, 2);
1324  }
1325 
1326  se(slice_qp_delta, - 51 - 6 * sps->bit_depth_luma_minus8,
1327  + 51 + 6 * sps->bit_depth_luma_minus8);
1328  if (slice_type_sp || slice_type_si) {
1329  if (slice_type_sp)
1330  flag(sp_for_switch_flag);
1331  se(slice_qs_delta, -51, +51);
1332  }
1333 
1335  ue(disable_deblocking_filter_idc, 0, 2);
1336  if (current->disable_deblocking_filter_idc != 1) {
1337  se(slice_alpha_c0_offset_div2, -6, +6);
1338  se(slice_beta_offset_div2, -6, +6);
1339  } else {
1340  infer(slice_alpha_c0_offset_div2, 0);
1341  infer(slice_beta_offset_div2, 0);
1342  }
1343  } else {
1344  infer(disable_deblocking_filter_idc, 0);
1345  infer(slice_alpha_c0_offset_div2, 0);
1346  infer(slice_beta_offset_div2, 0);
1347  }
1348 
1349  if (pps->num_slice_groups_minus1 > 0 &&
1350  pps->slice_group_map_type >= 3 &&
1351  pps->slice_group_map_type <= 5) {
1352  unsigned int pic_size, max, bits;
1353 
1354  pic_size = (sps->pic_width_in_mbs_minus1 + 1) *
1355  (sps->pic_height_in_map_units_minus1 + 1);
1356  max = (pic_size + pps->slice_group_change_rate_minus1) /
1357  (pps->slice_group_change_rate_minus1 + 1);
1358  bits = av_ceil_log2(max + 1);
1359 
1360  u(bits, slice_group_change_cycle, 0, max);
1361  }
1362 
1363  if (pps->entropy_coding_mode_flag) {
1364  while (byte_alignment(rw))
1365  fixed(1, cabac_alignment_one_bit, 1);
1366  }
1367 
1368  return 0;
1369 }
1370 
1372  H264RawFiller *current)
1373 {
1374  int err;
1375 
1376  HEADER("Filler Data");
1377 
1378  CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
1379  1 << H264_NAL_FILLER_DATA));
1380 
1381 #ifdef READ
1382  while (show_bits(rw, 8) == 0xff) {
1383  fixed(8, ff_byte, 0xff);
1384  ++current->filler_size;
1385  }
1386 #else
1387  {
1388  uint32_t i;
1389  for (i = 0; i < current->filler_size; i++)
1390  fixed(8, ff_byte, 0xff);
1391  }
1392 #endif
1393 
1395 
1396  return 0;
1397 }
1398 
1400  H264RawNALUnitHeader *current)
1401 {
1402  HEADER("End of Sequence");
1403 
1404  return FUNC(nal_unit_header)(ctx, rw, current,
1405  1 << H264_NAL_END_SEQUENCE);
1406 }
1407 
1409  H264RawNALUnitHeader *current)
1410 {
1411  HEADER("End of Stream");
1412 
1413  return FUNC(nal_unit_header)(ctx, rw, current,
1414  1 << H264_NAL_END_STREAM);
1415 }
#define allocate(name, size)
Definition: cbs_h2645.c:405
static int FUNC() sei_mastering_display_colour_volume(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIMasteringDisplayColourVolume *current)
uint8_t deblocking_filter_control_present_flag
Definition: cbs_h264.h:212
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static int FUNC() dec_ref_pic_marking(CodedBitstreamContext *ctx, RWContext *rw, H264RawSliceHeader *current, int idr_pic_flag)
#define se(name, range_min, range_max)
Definition: cbs_h2645.c:260
static int FUNC() sei_pic_timestamp(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIPicTimestamp *current, const H264RawSPS *sps)
uint8_t dpb_output_delay_length_minus1
Definition: cbs_h264.h:64
#define fixed(width, name, value)
Definition: cbs_av1.c:615
uint8_t initial_cpb_removal_delay_length_minus1
Definition: cbs_h264.h:62
H264RawPPS * pps[H264_MAX_PPS_COUNT]
Definition: cbs_h264.h:449
#define RWContext
Definition: cbs_av1.c:710
uint8_t log2_max_frame_num_minus4
Definition: cbs_h264.h:138
#define us(width, name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:263
static int FUNC() sps_extension(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPSExtension *current)
#define xue(name, var, range_min, range_max, subs,...)
Definition: cbs_h2645.c:373
H264RawVUI vui
Definition: cbs_h264.h:164
static int FUNC() sei_display_orientation(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIDisplayOrientation *current)
static int FUNC() scaling_list(CodedBitstreamContext *ctx, RWContext *rw, H264RawScalingList *current, int size_of_scaling_list)
int profile_idc
Definition: h264_levels.c:52
pan-scan rectangle
Definition: h264_sei.h:30
uint8_t weighted_pred_flag
Definition: cbs_h264.h:205
H264RawHRD nal_hrd_parameters
Definition: cbs_h264.h:95
static int FUNC() sei_payload(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIPayload *current)
uint8_t
uint16_t pic_width_in_mbs_minus1
Definition: cbs_h264.h:150
#define byte_alignment(rw)
Definition: cbs_av1.c:764
#define HEADER(name)
Definition: cbs_av1.c:582
#define MAX_UINT_BITS(length)
Definition: cbs_internal.h:96
static int FUNC() vui_parameters_default(CodedBitstreamContext *ctx, RWContext *rw, H264RawVUI *current, H264RawSPS *sps)
unregistered user data
Definition: h264_sei.h:33
#define MAX_INT_BITS(length)
Definition: cbs_internal.h:100
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:253
display orientation
Definition: h264_sei.h:36
int level_idc
Definition: h264_levels.c:25
static int FUNC() pred_weight_table(CodedBitstreamContext *ctx, RWContext *rw, H264RawSliceHeader *current)
#define ses(name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:271
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
H264RawSPS * sps[H264_MAX_SPS_COUNT]
Definition: cbs_h264.h:448
static int FUNC() slice_header(CodedBitstreamContext *ctx, RWContext *rw, H264RawSliceHeader *current)
#define av_log(a,...)
uint8_t nal_hrd_parameters_present_flag
Definition: cbs_h264.h:94
uint8_t bit_depth_luma_minus8
Definition: cbs_h264.h:129
uint8_t slice_group_map_type
Definition: cbs_h264.h:191
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:258
buffering period (H.264, D.1.1)
Definition: h264_sei.h:28
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
#define FUNC(a)
static av_always_inline void chroma(WaveformContext *s, AVFrame *in, AVFrame *out, int component, int intensity, int offset_y, int offset_x, int column, int mirror, int jobnr, int nb_jobs)
Definition: vf_waveform.c:1511
uint8_t max_num_ref_frames
Definition: cbs_h264.h:147
uint8_t weighted_bipred_idc
Definition: cbs_h264.h:206
static int FUNC() sei_pan_scan_rect(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIPanScanRect *current)
#define ue(name, range_min, range_max)
Definition: cbs_h2645.c:256
static int FUNC() rbsp_trailing_bits(CodedBitstreamContext *ctx, RWContext *rw)
uint8_t num_ref_idx_l1_default_active_minus1
Definition: cbs_h264.h:203
uint8_t frame_mbs_only_flag
Definition: cbs_h264.h:153
static int put_bits_count(PutBitContext *s)
Definition: put_bits.h:85
uint8_t seq_parameter_set_id
Definition: cbs_h264.h:185
static int FUNC() sei_recovery_point(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIRecoveryPoint *current)
static const struct TransferCharacteristics transfer_characteristics[AVCOL_TRC_NB]
picture timing
Definition: h264_sei.h:29
static int FUNC() ref_pic_list_modification(CodedBitstreamContext *ctx, RWContext *rw, H264RawSliceHeader *current)
uint8_t separate_colour_plane_flag
Definition: cbs_h264.h:128
uint8_t last_slice_nal_unit_type
Definition: cbs_h264.h:460
AVFormatContext * ctx
Definition: movenc.c:48
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:443
#define more_rbsp_data(var)
Definition: cbs_h2645.c:401
uint8_t chroma_format_idc
Definition: cbs_h264.h:127
static int FUNC() hrd_parameters(CodedBitstreamContext *ctx, RWContext *rw, H264RawHRD *current)
#define av_log2
Definition: intmath.h:83
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
static int FUNC() vui_parameters(CodedBitstreamContext *ctx, RWContext *rw, H264RawVUI *current, H264RawSPS *sps)
uint8_t cpb_cnt_minus1
Definition: cbs_h264.h:54
static int FUNC() nal_unit_header(CodedBitstreamContext *ctx, RWContext *rw, H264RawNALUnitHeader *current, uint32_t valid_type_mask)
uint8_t num_slice_groups_minus1
Definition: cbs_h264.h:190
uint8_t bottom_field_pic_order_in_frame_present_flag
Definition: cbs_h264.h:188
uint8_t entropy_coding_mode_flag
Definition: cbs_h264.h:187
#define xu(width, name, var, range_min, range_max, subs,...)
Definition: cbs_h2645.c:367
static int FUNC() aud(CodedBitstreamContext *ctx, RWContext *rw, H264RawAUD *current)
uint8_t pic_order_cnt_type
Definition: cbs_h264.h:139
static int FUNC() pps(CodedBitstreamContext *ctx, RWContext *rw, H264RawPPS *current)
Context structure for coded bitstream operations.
Definition: cbs.h:159
uint8_t num_ref_idx_l0_default_active_minus1
Definition: cbs_h264.h:202
static int FUNC() end_of_sequence(CodedBitstreamContext *ctx, RWContext *rw, H264RawNALUnitHeader *current)
CHECK(-1) CHECK(-2) }} }} CHECK(1) CHECK(2) }} }} } if(diff0+diff1 > 0) temp -
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
recovery point (frame # to decoder sync)
Definition: h264_sei.h:34
static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc)
Definition: cbs_h2645.c:318
registered user data as specified by Rec. ITU-T T.35
Definition: h264_sei.h:32
#define flags(name, subs,...)
Definition: cbs_av1.c:610
static int FUNC() filler(CodedBitstreamContext *ctx, RWContext *rw, H264RawFiller *current)
static int FUNC() sei_user_data_registered(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIUserDataRegistered *current, uint32_t *payload_size)
static int FUNC() end_of_stream(CodedBitstreamContext *ctx, RWContext *rw, H264RawNALUnitHeader *current)
uint8_t redundant_pic_cnt_present_flag
Definition: cbs_h264.h:217
uint8_t pic_struct_present_flag
Definition: cbs_h264.h:100
#define flag(name)
Definition: cbs_av1.c:602
static double c[64]
uint8_t cpb_removal_delay_length_minus1
Definition: cbs_h264.h:63
static int FUNC() sei_user_data_unregistered(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIUserDataUnregistered *current, uint32_t *payload_size)
static int FUNC() sei(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEI *current)
static int FUNC() sei_buffering_period(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIBufferingPeriod *current)
static int FUNC() sei_pic_timing(CodedBitstreamContext *ctx, RWContext *rw, H264RawSEIPicTiming *current)
uint8_t log2_max_pic_order_cnt_lsb_minus4
Definition: cbs_h264.h:140
#define MIN_INT_BITS(length)
Definition: cbs_internal.h:104
void * priv_data
Format private data.
Definition: avformat.h:1379
uint8_t delta_pic_order_always_zero_flag
Definition: cbs_h264.h:141
mastering display properties
Definition: h264_sei.h:38
const H264RawPPS * active_pps
Definition: cbs_h264.h:455
const char int length
Definition: avisynth_c.h:768
uint16_t pic_height_in_map_units_minus1
Definition: cbs_h264.h:151
#define infer(name, value)
Definition: cbs_av1.c:755
#define ues(name, range_min, range_max, subs,...)
Definition: cbs_h2645.c:267
uint8_t vcl_hrd_parameters_present_flag
Definition: cbs_h264.h:96
H264RawHRD vcl_hrd_parameters
Definition: cbs_h264.h:97
const H264RawSPS * active_sps
Definition: cbs_h264.h:454
uint16_t slice_group_change_rate_minus1
Definition: cbs_h264.h:196
static uint8_t tmp[11]
Definition: aes_ctr.c:26