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