You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1279 lines
42KB

  1. /*
  2. * This file is part of Libav.
  3. *
  4. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. static int FUNC(rbsp_trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw)
  19. {
  20. int err;
  21. av_unused int one = 1, zero = 0;
  22. xu(1, rbsp_stop_one_bit, one, 1, 1);
  23. while (byte_alignment(rw) != 0)
  24. xu(1, rbsp_alignment_zero_bit, zero, 0, 0);
  25. return 0;
  26. }
  27. static int FUNC(nal_unit_header)(CodedBitstreamContext *ctx, RWContext *rw,
  28. H264RawNALUnitHeader *current,
  29. uint32_t valid_type_mask)
  30. {
  31. int err;
  32. u(1, forbidden_zero_bit, 0, 0);
  33. u(2, nal_ref_idc, 0, 3);
  34. u(5, nal_unit_type, 0, 31);
  35. if (!(1 << current->nal_unit_type & valid_type_mask)) {
  36. av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid NAL unit type %d.\n",
  37. current->nal_unit_type);
  38. return AVERROR_INVALIDDATA;
  39. }
  40. if (current->nal_unit_type == 14 ||
  41. current->nal_unit_type == 20 ||
  42. current->nal_unit_type == 21) {
  43. if (current->nal_unit_type != 21)
  44. flag(svc_extension_flag);
  45. else
  46. flag(avc_3d_extension_flag);
  47. if (current->svc_extension_flag) {
  48. av_log(ctx->log_ctx, AV_LOG_ERROR, "SVC not supported.\n");
  49. return AVERROR_PATCHWELCOME;
  50. } else if (current->avc_3d_extension_flag) {
  51. av_log(ctx->log_ctx, AV_LOG_ERROR, "3DAVC not supported.\n");
  52. return AVERROR_PATCHWELCOME;
  53. } else {
  54. av_log(ctx->log_ctx, AV_LOG_ERROR, "MVC not supported.\n");
  55. return AVERROR_PATCHWELCOME;
  56. }
  57. }
  58. return 0;
  59. }
  60. static int FUNC(scaling_list)(CodedBitstreamContext *ctx, RWContext *rw,
  61. H264RawScalingList *current,
  62. int size_of_scaling_list)
  63. {
  64. int err, i, scale;
  65. scale = 8;
  66. for (i = 0; i < size_of_scaling_list; i++) {
  67. xse(delta_scale, current->delta_scale[i], -128, +127);
  68. scale = (scale + current->delta_scale[i] + 256) % 256;
  69. if (scale == 0)
  70. break;
  71. }
  72. return 0;
  73. }
  74. static int FUNC(hrd_parameters)(CodedBitstreamContext *ctx, RWContext *rw,
  75. H264RawHRD *current)
  76. {
  77. int err, i;
  78. ue(cpb_cnt_minus1, 0, 31);
  79. u(4, bit_rate_scale, 0, 15);
  80. u(4, cpb_size_scale, 0, 15);
  81. for (i = 0; i <= current->cpb_cnt_minus1; i++) {
  82. ue(bit_rate_value_minus1[i], 0, UINT32_MAX - 1);
  83. ue(cpb_size_value_minus1[i], 0, UINT32_MAX - 1);
  84. flag(cbr_flag[i]);
  85. }
  86. u(5, initial_cpb_removal_delay_length_minus1, 0, 31);
  87. u(5, cpb_removal_delay_length_minus1, 0, 31);
  88. u(5, dpb_output_delay_length_minus1, 0, 31);
  89. u(5, time_offset_length, 0, 31);
  90. return 0;
  91. }
  92. static int FUNC(vui_parameters)(CodedBitstreamContext *ctx, RWContext *rw,
  93. H264RawVUI *current, H264RawSPS *sps)
  94. {
  95. int err;
  96. flag(aspect_ratio_info_present_flag);
  97. if (current->aspect_ratio_info_present_flag) {
  98. u(8, aspect_ratio_idc, 0, 255);
  99. if (current->aspect_ratio_idc == 255) {
  100. u(16, sar_width, 0, 65535);
  101. u(16, sar_height, 0, 65535);
  102. }
  103. } else {
  104. infer(aspect_ratio_idc, 0);
  105. }
  106. flag(overscan_info_present_flag);
  107. if (current->overscan_info_present_flag)
  108. flag(overscan_appropriate_flag);
  109. flag(video_signal_type_present_flag);
  110. if (current->video_signal_type_present_flag) {
  111. u(3, video_format, 0, 7);
  112. flag(video_full_range_flag);
  113. flag(colour_description_present_flag);
  114. if (current->colour_description_present_flag) {
  115. u(8, colour_primaries, 0, 255);
  116. u(8, transfer_characteristics, 0, 255);
  117. u(8, matrix_coefficients, 0, 255);
  118. }
  119. } else {
  120. infer(video_format, 5);
  121. infer(video_full_range_flag, 0);
  122. infer(colour_primaries, 2);
  123. infer(transfer_characteristics, 2);
  124. infer(matrix_coefficients, 2);
  125. }
  126. flag(chroma_loc_info_present_flag);
  127. if (current->chroma_loc_info_present_flag) {
  128. ue(chroma_sample_loc_type_top_field, 0, 5);
  129. ue(chroma_sample_loc_type_bottom_field, 0, 5);
  130. } else {
  131. infer(chroma_sample_loc_type_top_field, 0);
  132. infer(chroma_sample_loc_type_bottom_field, 0);
  133. }
  134. flag(timing_info_present_flag);
  135. if (current->timing_info_present_flag) {
  136. u(32, num_units_in_tick, 1, UINT32_MAX);
  137. u(32, time_scale, 1, UINT32_MAX);
  138. flag(fixed_frame_rate_flag);
  139. } else {
  140. infer(fixed_frame_rate_flag, 0);
  141. }
  142. flag(nal_hrd_parameters_present_flag);
  143. if (current->nal_hrd_parameters_present_flag)
  144. CHECK(FUNC(hrd_parameters)(ctx, rw, &current->nal_hrd_parameters));
  145. flag(vcl_hrd_parameters_present_flag);
  146. if (current->vcl_hrd_parameters_present_flag)
  147. CHECK(FUNC(hrd_parameters)(ctx, rw, &current->vcl_hrd_parameters));
  148. if (current->nal_hrd_parameters_present_flag ||
  149. current->vcl_hrd_parameters_present_flag)
  150. flag(low_delay_hrd_flag);
  151. else
  152. infer(low_delay_hrd_flag, 1 - current->fixed_frame_rate_flag);
  153. flag(pic_struct_present_flag);
  154. flag(bitstream_restriction_flag);
  155. if (current->bitstream_restriction_flag) {
  156. flag(motion_vectors_over_pic_boundaries_flag);
  157. ue(max_bytes_per_pic_denom, 0, 16);
  158. ue(max_bits_per_mb_denom, 0, 16);
  159. ue(log2_max_mv_length_horizontal, 0, 16);
  160. ue(log2_max_mv_length_vertical, 0, 16);
  161. ue(max_num_reorder_frames, 0, H264_MAX_DPB_FRAMES);
  162. ue(max_dec_frame_buffering, 0, H264_MAX_DPB_FRAMES);
  163. } else {
  164. infer(motion_vectors_over_pic_boundaries_flag, 1);
  165. infer(max_bytes_per_pic_denom, 2);
  166. infer(max_bits_per_mb_denom, 1);
  167. infer(log2_max_mv_length_horizontal, 16);
  168. infer(log2_max_mv_length_vertical, 16);
  169. if ((sps->profile_idc == 44 || sps->profile_idc == 86 ||
  170. sps->profile_idc == 110 || sps->profile_idc == 110 ||
  171. sps->profile_idc == 122 || sps->profile_idc == 244) &&
  172. sps->constraint_set3_flag) {
  173. infer(max_num_reorder_frames, 0);
  174. infer(max_dec_frame_buffering, 0);
  175. } else {
  176. infer(max_num_reorder_frames, H264_MAX_DPB_FRAMES);
  177. infer(max_dec_frame_buffering, H264_MAX_DPB_FRAMES);
  178. }
  179. }
  180. return 0;
  181. }
  182. static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw,
  183. H264RawSPS *current)
  184. {
  185. int err, i;
  186. HEADER("Sequence Parameter Set");
  187. CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
  188. 1 << H264_NAL_SPS));
  189. u(8, profile_idc, 0, 255);
  190. flag(constraint_set0_flag);
  191. flag(constraint_set1_flag);
  192. flag(constraint_set2_flag);
  193. flag(constraint_set3_flag);
  194. flag(constraint_set4_flag);
  195. flag(constraint_set5_flag);
  196. u(2, reserved_zero_2bits, 0, 0);
  197. u(8, level_idc, 0, 255);
  198. ue(seq_parameter_set_id, 0, 31);
  199. if (current->profile_idc == 100 || current->profile_idc == 110 ||
  200. current->profile_idc == 122 || current->profile_idc == 244 ||
  201. current->profile_idc == 44 || current->profile_idc == 83 ||
  202. current->profile_idc == 86 || current->profile_idc == 118 ||
  203. current->profile_idc == 128 || current->profile_idc == 138) {
  204. ue(chroma_format_idc, 0, 3);
  205. if (current->chroma_format_idc == 3)
  206. flag(separate_colour_plane_flag);
  207. else
  208. infer(separate_colour_plane_flag, 0);
  209. ue(bit_depth_luma_minus8, 0, 6);
  210. ue(bit_depth_chroma_minus8, 0, 6);
  211. flag(qpprime_y_zero_transform_bypass_flag);
  212. flag(seq_scaling_matrix_present_flag);
  213. if (current->seq_scaling_matrix_present_flag) {
  214. for (i = 0; i < ((current->chroma_format_idc != 3) ? 8 : 12); i++) {
  215. flag(seq_scaling_list_present_flag[i]);
  216. if (current->seq_scaling_list_present_flag[i]) {
  217. if (i < 6)
  218. CHECK(FUNC(scaling_list)(ctx, rw,
  219. &current->scaling_list_4x4[i],
  220. 16));
  221. else
  222. CHECK(FUNC(scaling_list)(ctx, rw,
  223. &current->scaling_list_8x8[i - 6],
  224. 64));
  225. }
  226. }
  227. }
  228. } else {
  229. infer(chroma_format_idc, current->profile_idc == 183 ? 0 : 1);
  230. infer(separate_colour_plane_flag, 0);
  231. infer(bit_depth_luma_minus8, 0);
  232. infer(bit_depth_chroma_minus8, 0);
  233. }
  234. ue(log2_max_frame_num_minus4, 0, 12);
  235. ue(pic_order_cnt_type, 0, 2);
  236. if (current->pic_order_cnt_type == 0) {
  237. ue(log2_max_pic_order_cnt_lsb_minus4, 0, 12);
  238. } else if (current->pic_order_cnt_type == 1) {
  239. flag(delta_pic_order_always_zero_flag);
  240. se(offset_for_non_ref_pic, INT32_MIN + 1, INT32_MAX);
  241. se(offset_for_top_to_bottom_field, INT32_MIN + 1, INT32_MAX);
  242. ue(num_ref_frames_in_pic_order_cnt_cycle, 0, 255);
  243. for (i = 0; i < current->num_ref_frames_in_pic_order_cnt_cycle; i++)
  244. se(offset_for_ref_frame[i], INT32_MIN + 1, INT32_MAX);
  245. }
  246. ue(max_num_ref_frames, 0, H264_MAX_DPB_FRAMES);
  247. flag(gaps_in_frame_num_allowed_flag);
  248. ue(pic_width_in_mbs_minus1, 0, H264_MAX_MB_WIDTH);
  249. ue(pic_height_in_map_units_minus1, 0, H264_MAX_MB_HEIGHT);
  250. flag(frame_mbs_only_flag);
  251. if (!current->frame_mbs_only_flag)
  252. flag(mb_adaptive_frame_field_flag);
  253. flag(direct_8x8_inference_flag);
  254. flag(frame_cropping_flag);
  255. if (current->frame_cropping_flag) {
  256. ue(frame_crop_left_offset, 0, H264_MAX_WIDTH);
  257. ue(frame_crop_right_offset, 0, H264_MAX_WIDTH);
  258. ue(frame_crop_top_offset, 0, H264_MAX_HEIGHT);
  259. ue(frame_crop_bottom_offset, 0, H264_MAX_HEIGHT);
  260. }
  261. flag(vui_parameters_present_flag);
  262. if (current->vui_parameters_present_flag)
  263. CHECK(FUNC(vui_parameters)(ctx, rw, &current->vui, current));
  264. CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
  265. return 0;
  266. }
  267. static int FUNC(sps_extension)(CodedBitstreamContext *ctx, RWContext *rw,
  268. H264RawSPSExtension *current)
  269. {
  270. int err;
  271. HEADER("Sequence Parameter Set Extension");
  272. CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
  273. 1 << H264_NAL_SPS_EXT));
  274. ue(seq_parameter_set_id, 0, 31);
  275. ue(aux_format_idc, 0, 3);
  276. if (current->aux_format_idc != 0) {
  277. int bits;
  278. ue(bit_depth_aux_minus8, 0, 4);
  279. flag(alpha_incr_flag);
  280. bits = current->bit_depth_aux_minus8 + 9;
  281. u(bits, alpha_opaque_value, 0, (1 << bits) - 1);
  282. u(bits, alpha_transparent_value, 0, (1 << bits) - 1);
  283. }
  284. flag(additional_extension_flag);
  285. CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
  286. return 0;
  287. }
  288. static int FUNC(pps)(CodedBitstreamContext *ctx, RWContext *rw,
  289. H264RawPPS *current)
  290. {
  291. CodedBitstreamH264Context *h264 = ctx->priv_data;
  292. const H264RawSPS *sps;
  293. int err, i;
  294. HEADER("Picture Parameter Set");
  295. CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
  296. 1 << H264_NAL_PPS));
  297. ue(pic_parameter_set_id, 0, 255);
  298. ue(seq_parameter_set_id, 0, 31);
  299. sps = h264->sps[current->seq_parameter_set_id];
  300. if (!sps) {
  301. av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
  302. current->seq_parameter_set_id);
  303. return AVERROR_INVALIDDATA;
  304. }
  305. flag(entropy_coding_mode_flag);
  306. flag(bottom_field_pic_order_in_frame_present_flag);
  307. ue(num_slice_groups_minus1, 0, 7);
  308. if (current->num_slice_groups_minus1 > 0) {
  309. unsigned int pic_size;
  310. int iGroup;
  311. pic_size = (sps->pic_width_in_mbs_minus1 + 1) *
  312. (sps->pic_height_in_map_units_minus1 + 1);
  313. ue(slice_group_map_type, 0, 6);
  314. if (current->slice_group_map_type == 0) {
  315. for (iGroup = 0; iGroup <= current->num_slice_groups_minus1; iGroup++)
  316. ue(run_length_minus1[iGroup], 0, pic_size - 1);
  317. } else if (current->slice_group_map_type == 2) {
  318. for (iGroup = 0; iGroup < current->num_slice_groups_minus1; iGroup++) {
  319. ue(top_left[iGroup], 0, pic_size - 1);
  320. ue(bottom_right[iGroup], current->top_left[iGroup], pic_size - 1);
  321. }
  322. } else if (current->slice_group_map_type == 3 ||
  323. current->slice_group_map_type == 4 ||
  324. current->slice_group_map_type == 5) {
  325. flag(slice_group_change_direction_flag);
  326. ue(slice_group_change_rate_minus1, 0, pic_size - 1);
  327. } else if (current->slice_group_map_type == 6) {
  328. ue(pic_size_in_map_units_minus1, pic_size - 1, pic_size - 1);
  329. allocate(current->slice_group_id,
  330. current->pic_size_in_map_units_minus1 + 1);
  331. for (i = 0; i <= current->pic_size_in_map_units_minus1; i++)
  332. u(av_log2(2 * current->num_slice_groups_minus1 + 1),
  333. slice_group_id[i], 0, current->num_slice_groups_minus1);
  334. }
  335. }
  336. ue(num_ref_idx_l0_default_active_minus1, 0, 31);
  337. ue(num_ref_idx_l1_default_active_minus1, 0, 31);
  338. flag(weighted_pred_flag);
  339. u(2, weighted_bipred_idc, 0, 2);
  340. se(pic_init_qp_minus26, -26 - 6 * sps->bit_depth_luma_minus8, +25);
  341. se(pic_init_qs_minus26, -26, +25);
  342. se(chroma_qp_index_offset, -12, +12);
  343. flag(deblocking_filter_control_present_flag);
  344. flag(constrained_intra_pred_flag);
  345. flag(redundant_pic_cnt_present_flag);
  346. if (more_rbsp_data(current->more_rbsp_data))
  347. {
  348. flag(transform_8x8_mode_flag);
  349. flag(pic_scaling_matrix_present_flag);
  350. if (current->pic_scaling_matrix_present_flag) {
  351. for (i = 0; i < 6 + (((sps->chroma_format_idc != 3) ? 2 : 6) *
  352. current->transform_8x8_mode_flag); i++) {
  353. flag(pic_scaling_list_present_flag[i]);
  354. if (current->pic_scaling_list_present_flag[i]) {
  355. if (i < 6)
  356. CHECK(FUNC(scaling_list)(ctx, rw,
  357. &current->scaling_list_4x4[i],
  358. 16));
  359. else
  360. CHECK(FUNC(scaling_list)(ctx, rw,
  361. &current->scaling_list_8x8[i - 6],
  362. 64));
  363. }
  364. }
  365. }
  366. se(second_chroma_qp_index_offset, -12, +12);
  367. } else {
  368. infer(transform_8x8_mode_flag, 0);
  369. infer(pic_scaling_matrix_present_flag, 0);
  370. infer(second_chroma_qp_index_offset, current->chroma_qp_index_offset);
  371. }
  372. CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
  373. return 0;
  374. }
  375. static int FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, RWContext *rw,
  376. H264RawSEIBufferingPeriod *current)
  377. {
  378. CodedBitstreamH264Context *h264 = ctx->priv_data;
  379. const H264RawSPS *sps;
  380. int err, i, length;
  381. ue(seq_parameter_set_id, 0, 31);
  382. sps = h264->sps[current->seq_parameter_set_id];
  383. if (!sps) {
  384. av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
  385. current->seq_parameter_set_id);
  386. return AVERROR_INVALIDDATA;
  387. }
  388. h264->active_sps = sps;
  389. if (sps->vui.nal_hrd_parameters_present_flag) {
  390. for (i = 0; i <= sps->vui.nal_hrd_parameters.cpb_cnt_minus1; i++) {
  391. length = sps->vui.nal_hrd_parameters.initial_cpb_removal_delay_length_minus1 + 1;
  392. xu(length, initial_cpb_removal_delay[SchedSelIdx],
  393. current->nal.initial_cpb_removal_delay[i],
  394. 0, (1 << (uint64_t)length) - 1);
  395. xu(length, initial_cpb_removal_delay_offset[SchedSelIdx],
  396. current->nal.initial_cpb_removal_delay_offset[i],
  397. 0, (1 << (uint64_t)length) - 1);
  398. }
  399. }
  400. if (sps->vui.vcl_hrd_parameters_present_flag) {
  401. for (i = 0; i <= sps->vui.vcl_hrd_parameters.cpb_cnt_minus1; i++) {
  402. length = sps->vui.vcl_hrd_parameters.initial_cpb_removal_delay_length_minus1 + 1;
  403. xu(length, initial_cpb_removal_delay[SchedSelIdx],
  404. current->vcl.initial_cpb_removal_delay[i],
  405. 0, (1 << (uint64_t)length) - 1);
  406. xu(length, initial_cpb_removal_delay_offset[SchedSelIdx],
  407. current->vcl.initial_cpb_removal_delay_offset[i],
  408. 0, (1 << (uint64_t)length) - 1);
  409. }
  410. }
  411. return 0;
  412. }
  413. static int FUNC(sei_pic_timestamp)(CodedBitstreamContext *ctx, RWContext *rw,
  414. H264RawSEIPicTimestamp *current)
  415. {
  416. CodedBitstreamH264Context *h264 = ctx->priv_data;
  417. const H264RawSPS *sps;
  418. uint8_t time_offset_length;
  419. int err;
  420. u(2, ct_type, 0, 2);
  421. flag(nuit_field_based_flag);
  422. u(5, counting_type, 0, 6);
  423. flag(full_timestamp_flag);
  424. flag(discontinuity_flag);
  425. flag(cnt_dropped_flag);
  426. u(8, n_frames, 0, 255);
  427. if (current->full_timestamp_flag) {
  428. u(6, seconds_value, 0, 59);
  429. u(6, minutes_value, 0, 59);
  430. u(5, hours_value, 0, 23);
  431. } else {
  432. flag(seconds_flag);
  433. if (current->seconds_flag) {
  434. u(6, seconds_value, 0, 59);
  435. flag(minutes_flag);
  436. if (current->minutes_flag) {
  437. u(6, minutes_value, 0, 59);
  438. flag(hours_flag);
  439. if (current->hours_flag)
  440. u(5, hours_value, 0, 23);
  441. }
  442. }
  443. }
  444. sps = h264->active_sps;
  445. if (sps->vui.nal_hrd_parameters_present_flag)
  446. time_offset_length = sps->vui.nal_hrd_parameters.time_offset_length;
  447. else if (sps->vui.vcl_hrd_parameters_present_flag)
  448. time_offset_length = sps->vui.vcl_hrd_parameters.time_offset_length;
  449. else
  450. time_offset_length = 24;
  451. if (time_offset_length > 0)
  452. u(time_offset_length, time_offset,
  453. 0, (1 << (uint64_t)time_offset_length) - 1);
  454. else
  455. infer(time_offset, 0);
  456. return 0;
  457. }
  458. static int FUNC(sei_pic_timing)(CodedBitstreamContext *ctx, RWContext *rw,
  459. H264RawSEIPicTiming *current)
  460. {
  461. CodedBitstreamH264Context *h264 = ctx->priv_data;
  462. const H264RawSPS *sps;
  463. int err;
  464. sps = h264->active_sps;
  465. if (!sps) {
  466. // If there is exactly one possible SPS but it is not yet active
  467. // then just assume that it should be the active one.
  468. int i, k = -1;
  469. for (i = 0; i < H264_MAX_SPS_COUNT; i++) {
  470. if (h264->sps[i]) {
  471. if (k >= 0) {
  472. k = -1;
  473. break;
  474. }
  475. k = i;
  476. }
  477. }
  478. if (k >= 0)
  479. sps = h264->sps[k];
  480. }
  481. if (!sps) {
  482. av_log(ctx->log_ctx, AV_LOG_ERROR,
  483. "No active SPS for pic_timing.\n");
  484. return AVERROR_INVALIDDATA;
  485. }
  486. if (sps->vui.nal_hrd_parameters_present_flag ||
  487. sps->vui.vcl_hrd_parameters_present_flag) {
  488. const H264RawHRD *hrd;
  489. if (sps->vui.nal_hrd_parameters_present_flag)
  490. hrd = &sps->vui.nal_hrd_parameters;
  491. else if (sps->vui.vcl_hrd_parameters_present_flag)
  492. hrd = &sps->vui.vcl_hrd_parameters;
  493. else {
  494. av_log(ctx->log_ctx, AV_LOG_ERROR,
  495. "No HRD parameters for pic_timing.\n");
  496. return AVERROR_INVALIDDATA;
  497. }
  498. u(hrd->cpb_removal_delay_length_minus1 + 1, cpb_removal_delay,
  499. 0, (1 << (uint64_t)hrd->cpb_removal_delay_length_minus1) + 1);
  500. u(hrd->dpb_output_delay_length_minus1 + 1, dpb_output_delay,
  501. 0, (1 << (uint64_t)hrd->dpb_output_delay_length_minus1) + 1);
  502. }
  503. if (sps->vui.pic_struct_present_flag) {
  504. static const int num_clock_ts[9] = {
  505. 1, 1, 1, 2, 2, 3, 3, 2, 3
  506. };
  507. int i;
  508. u(4, pic_struct, 0, 8);
  509. if (current->pic_struct > 8)
  510. return AVERROR_INVALIDDATA;
  511. for (i = 0; i < num_clock_ts[current->pic_struct]; i++) {
  512. flag(clock_timestamp_flag[i]);
  513. if (current->clock_timestamp_flag[i])
  514. CHECK(FUNC(sei_pic_timestamp)(ctx, rw, &current->timestamp[i]));
  515. }
  516. }
  517. return 0;
  518. }
  519. static int FUNC(sei_user_data_registered)(CodedBitstreamContext *ctx, RWContext *rw,
  520. H264RawSEIUserDataRegistered *current,
  521. uint32_t *payload_size)
  522. {
  523. int err, i, j;
  524. u(8, itu_t_t35_country_code, 0x00, 0xff);
  525. if (current->itu_t_t35_country_code != 0xff)
  526. i = 1;
  527. else {
  528. u(8, itu_t_t35_country_code_extension_byte, 0x00, 0xff);
  529. i = 2;
  530. }
  531. #ifdef READ
  532. if (*payload_size < i) {
  533. av_log(ctx->log_ctx, AV_LOG_ERROR,
  534. "Invalid SEI user data registered payload.\n");
  535. return AVERROR_INVALIDDATA;
  536. }
  537. current->data_length = *payload_size - i;
  538. #else
  539. *payload_size = i + current->data_length;
  540. #endif
  541. allocate(current->data, current->data_length);
  542. for (j = 0; j < current->data_length; j++)
  543. xu(8, itu_t_t35_payload_byte, current->data[j], 0x00, 0xff);
  544. return 0;
  545. }
  546. static int FUNC(sei_user_data_unregistered)(CodedBitstreamContext *ctx, RWContext *rw,
  547. H264RawSEIUserDataUnregistered *current,
  548. uint32_t *payload_size)
  549. {
  550. int err, i;
  551. #ifdef READ
  552. if (*payload_size < 16) {
  553. av_log(ctx->log_ctx, AV_LOG_ERROR,
  554. "Invalid SEI user data unregistered payload.\n");
  555. return AVERROR_INVALIDDATA;
  556. }
  557. current->data_length = *payload_size - 16;
  558. #else
  559. *payload_size = 16 + current->data_length;
  560. #endif
  561. for (i = 0; i < 16; i++) {
  562. xu(8, uuid_iso_iec_11578,
  563. current->uuid_iso_iec_11578[i], 0x00, 0xff);
  564. }
  565. allocate(current->data, current->data_length);
  566. for (i = 0; i < current->data_length; i++)
  567. xu(8, user_data_payload_byte, current->data[i], 0x00, 0xff);
  568. return 0;
  569. }
  570. static int FUNC(sei_recovery_point)(CodedBitstreamContext *ctx, RWContext *rw,
  571. H264RawSEIRecoveryPoint *current)
  572. {
  573. int err;
  574. ue(recovery_frame_cnt, 0, 65535);
  575. flag(exact_match_flag);
  576. flag(broken_link_flag);
  577. u(2, changing_slice_group_idc, 0, 2);
  578. return 0;
  579. }
  580. static int FUNC(sei_display_orientation)(CodedBitstreamContext *ctx, RWContext *rw,
  581. H264RawSEIDisplayOrientation *current)
  582. {
  583. int err;
  584. flag(display_orientation_cancel_flag);
  585. if (!current->display_orientation_cancel_flag) {
  586. flag(hor_flip);
  587. flag(ver_flip);
  588. u(16, anticlockwise_rotation, 0, 65535);
  589. ue(display_orientation_repetition_period, 0, 16384);
  590. flag(display_orientation_extension_flag);
  591. }
  592. return 0;
  593. }
  594. static int FUNC(sei_payload)(CodedBitstreamContext *ctx, RWContext *rw,
  595. H264RawSEIPayload *current)
  596. {
  597. int err, i;
  598. int start_position, end_position;
  599. #ifdef READ
  600. start_position = bitstream_tell(rw);
  601. #else
  602. start_position = put_bits_count(rw);
  603. #endif
  604. switch (current->payload_type) {
  605. case H264_SEI_TYPE_BUFFERING_PERIOD:
  606. CHECK(FUNC(sei_buffering_period)
  607. (ctx, rw, &current->payload.buffering_period));
  608. break;
  609. case H264_SEI_TYPE_PIC_TIMING:
  610. CHECK(FUNC(sei_pic_timing)
  611. (ctx, rw, &current->payload.pic_timing));
  612. break;
  613. case H264_SEI_TYPE_FILLER_PAYLOAD:
  614. {
  615. av_unused int ff_byte = 0xff;
  616. for (i = 0; i < current->payload_size; i++)
  617. xu(8, ff_byte, ff_byte, 0xff, 0xff);
  618. }
  619. break;
  620. case H264_SEI_TYPE_USER_DATA_REGISTERED:
  621. CHECK(FUNC(sei_user_data_registered)
  622. (ctx, rw, &current->payload.user_data_registered, &current->payload_size));
  623. break;
  624. case H264_SEI_TYPE_USER_DATA_UNREGISTERED:
  625. CHECK(FUNC(sei_user_data_unregistered)
  626. (ctx, rw, &current->payload.user_data_unregistered, &current->payload_size));
  627. break;
  628. case H264_SEI_TYPE_RECOVERY_POINT:
  629. CHECK(FUNC(sei_recovery_point)
  630. (ctx, rw, &current->payload.recovery_point));
  631. break;
  632. case H264_SEI_TYPE_DISPLAY_ORIENTATION:
  633. CHECK(FUNC(sei_display_orientation)
  634. (ctx, rw, &current->payload.display_orientation));
  635. break;
  636. default:
  637. {
  638. allocate(current->payload.other.data, current->payload_size);
  639. for (i = 0; i < current->payload_size; i++)
  640. xu(8, payload_byte, current->payload.other.data[i], 0, 255);
  641. }
  642. }
  643. if (byte_alignment(rw)) {
  644. av_unused int one = 1, zero = 0;
  645. xu(1, bit_equal_to_one, one, 1, 1);
  646. while (byte_alignment(rw))
  647. xu(1, bit_equal_to_zero, zero, 0, 0);
  648. }
  649. #ifdef READ
  650. end_position = bitstream_tell(rw);
  651. if (end_position < start_position + 8 * current->payload_size) {
  652. av_log(ctx->log_ctx, AV_LOG_ERROR, "Incorrect SEI payload length: "
  653. "header %d bits, actually %d bits.\n",
  654. 8 * current->payload_size,
  655. end_position - start_position);
  656. return AVERROR_INVALIDDATA;
  657. }
  658. #else
  659. end_position = put_bits_count(rw);
  660. current->payload_size = (end_position - start_position) / 8;
  661. #endif
  662. return 0;
  663. }
  664. static int FUNC(sei)(CodedBitstreamContext *ctx, RWContext *rw,
  665. H264RawSEI *current)
  666. {
  667. int err, k;
  668. HEADER("Supplemental Enhancement Information");
  669. CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
  670. 1 << H264_NAL_SEI));
  671. #ifdef READ
  672. for (k = 0; k < H264_MAX_SEI_PAYLOADS; k++) {
  673. uint32_t payload_type = 0;
  674. uint32_t payload_size = 0;
  675. uint32_t tmp;
  676. while (bitstream_peek(rw, 8) == 0xff) {
  677. xu(8, ff_byte, tmp, 0xff, 0xff);
  678. payload_type += 255;
  679. }
  680. xu(8, last_payload_type_byte, tmp, 0, 254);
  681. payload_type += tmp;
  682. while (bitstream_peek(rw, 8) == 0xff) {
  683. xu(8, ff_byte, tmp, 0xff, 0xff);
  684. payload_size += 255;
  685. }
  686. xu(8, last_payload_size_byte, tmp, 0, 254);
  687. payload_size += tmp;
  688. current->payload[k].payload_type = payload_type;
  689. current->payload[k].payload_size = payload_size;
  690. CHECK(FUNC(sei_payload)(ctx, rw, &current->payload[k]));
  691. if (!cbs_h2645_read_more_rbsp_data(rw))
  692. break;
  693. }
  694. if (k >= H264_MAX_SEI_PAYLOADS) {
  695. av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many payloads in "
  696. "SEI message: found %d.\n", k);
  697. return AVERROR_INVALIDDATA;
  698. }
  699. current->payload_count = k + 1;
  700. #else
  701. for (k = 0; k < current->payload_count; k++) {
  702. PutBitContext start_state;
  703. uint32_t tmp;
  704. int need_size, i;
  705. // Somewhat clumsy: we write the payload twice when
  706. // we don't know the size in advance. This will mess
  707. // with trace output, but is otherwise harmless.
  708. start_state = *rw;
  709. need_size = !current->payload[k].payload_size;
  710. for (i = 0; i < 1 + need_size; i++) {
  711. *rw = start_state;
  712. tmp = current->payload[k].payload_type;
  713. while (tmp >= 255) {
  714. xu(8, ff_byte, 0xff, 0xff, 0xff);
  715. tmp -= 255;
  716. }
  717. xu(8, last_payload_type_byte, tmp, 0, 254);
  718. tmp = current->payload[k].payload_size;
  719. while (tmp >= 255) {
  720. xu(8, ff_byte, 0xff, 0xff, 0xff);
  721. tmp -= 255;
  722. }
  723. xu(8, last_payload_size_byte, tmp, 0, 254);
  724. CHECK(FUNC(sei_payload)(ctx, rw, &current->payload[k]));
  725. }
  726. }
  727. #endif
  728. CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
  729. return 0;
  730. }
  731. static int FUNC(aud)(CodedBitstreamContext *ctx, RWContext *rw,
  732. H264RawAUD *current)
  733. {
  734. int err;
  735. HEADER("Access Unit Delimiter");
  736. CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
  737. 1 << H264_NAL_AUD));
  738. u(3, primary_pic_type, 0, 7);
  739. CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
  740. return 0;
  741. }
  742. static int FUNC(ref_pic_list_modification)(CodedBitstreamContext *ctx, RWContext *rw,
  743. H264RawSliceHeader *current)
  744. {
  745. CodedBitstreamH264Context *h264 = ctx->priv_data;
  746. const H264RawSPS *sps = h264->active_sps;
  747. int err, i, mopn;
  748. if (current->slice_type % 5 != 2 &&
  749. current->slice_type % 5 != 4) {
  750. flag(ref_pic_list_modification_flag_l0);
  751. if (current->ref_pic_list_modification_flag_l0) {
  752. for (i = 0; i < H264_MAX_RPLM_COUNT; i++) {
  753. xue(modification_of_pic_nums_idc,
  754. current->rplm_l0[i].modification_of_pic_nums_idc, 0, 3);
  755. mopn = current->rplm_l0[i].modification_of_pic_nums_idc;
  756. if (mopn == 3)
  757. break;
  758. if (mopn == 0 || mopn == 1)
  759. xue(abs_diff_pic_num_minus1,
  760. current->rplm_l0[i].abs_diff_pic_num_minus1,
  761. 0, (1 + current->field_pic_flag) *
  762. (1 << (sps->log2_max_frame_num_minus4 + 4)));
  763. else if (mopn == 2)
  764. xue(long_term_pic_num,
  765. current->rplm_l0[i].long_term_pic_num,
  766. 0, sps->max_num_ref_frames - 1);
  767. }
  768. }
  769. }
  770. if (current->slice_type % 5 == 1) {
  771. flag(ref_pic_list_modification_flag_l1);
  772. if (current->ref_pic_list_modification_flag_l1) {
  773. for (i = 0; i < H264_MAX_RPLM_COUNT; i++) {
  774. xue(modification_of_pic_nums_idc,
  775. current->rplm_l1[i].modification_of_pic_nums_idc, 0, 3);
  776. mopn = current->rplm_l1[i].modification_of_pic_nums_idc;
  777. if (mopn == 3)
  778. break;
  779. if (mopn == 0 || mopn == 1)
  780. xue(abs_diff_pic_num_minus1,
  781. current->rplm_l1[i].abs_diff_pic_num_minus1,
  782. 0, (1 + current->field_pic_flag) *
  783. (1 << (sps->log2_max_frame_num_minus4 + 4)));
  784. else if (mopn == 2)
  785. xue(long_term_pic_num,
  786. current->rplm_l1[i].long_term_pic_num,
  787. 0, sps->max_num_ref_frames - 1);
  788. }
  789. }
  790. }
  791. return 0;
  792. }
  793. static int FUNC(pred_weight_table)(CodedBitstreamContext *ctx, RWContext *rw,
  794. H264RawSliceHeader *current)
  795. {
  796. CodedBitstreamH264Context *h264 = ctx->priv_data;
  797. const H264RawSPS *sps = h264->active_sps;
  798. int chroma;
  799. int err, i, j;
  800. ue(luma_log2_weight_denom, 0, 7);
  801. chroma = !sps->separate_colour_plane_flag && sps->chroma_format_idc != 0;
  802. if (chroma)
  803. ue(chroma_log2_weight_denom, 0, 7);
  804. for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
  805. flag(luma_weight_l0_flag[i]);
  806. if (current->luma_weight_l0_flag[i]) {
  807. se(luma_weight_l0[i], -128, +127);
  808. se(luma_offset_l0[i], -128, +127);
  809. }
  810. if (chroma) {
  811. flag(chroma_weight_l0_flag[i]);
  812. if (current->chroma_weight_l0_flag[i]) {
  813. for (j = 0; j < 2; j++) {
  814. se(chroma_weight_l0[i][j], -128, +127);
  815. se(chroma_offset_l0[i][j], -128, +127);
  816. }
  817. }
  818. }
  819. }
  820. if (current->slice_type % 5 == 1) {
  821. for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
  822. flag(luma_weight_l1_flag[i]);
  823. if (current->luma_weight_l1_flag[i]) {
  824. se(luma_weight_l1[i], -128, +127);
  825. se(luma_offset_l1[i], -128, +127);
  826. }
  827. if (chroma) {
  828. flag(chroma_weight_l1_flag[i]);
  829. if (current->chroma_weight_l1_flag[i]) {
  830. for (j = 0; j < 2; j++) {
  831. se(chroma_weight_l1[i][j], -128, +127);
  832. se(chroma_offset_l1[i][j], -128, +127);
  833. }
  834. }
  835. }
  836. }
  837. }
  838. return 0;
  839. }
  840. static int FUNC(dec_ref_pic_marking)(CodedBitstreamContext *ctx, RWContext *rw,
  841. H264RawSliceHeader *current, int idr_pic_flag)
  842. {
  843. CodedBitstreamH264Context *h264 = ctx->priv_data;
  844. const H264RawSPS *sps = h264->active_sps;
  845. int err, i;
  846. uint32_t mmco;
  847. if (idr_pic_flag) {
  848. flag(no_output_of_prior_pics_flag);
  849. flag(long_term_reference_flag);
  850. } else {
  851. flag(adaptive_ref_pic_marking_mode_flag);
  852. if (current->adaptive_ref_pic_marking_mode_flag) {
  853. for (i = 0; i < H264_MAX_MMCO_COUNT; i++) {
  854. xue(memory_management_control_operation,
  855. current->mmco[i].memory_management_control_operation,
  856. 0, 6);
  857. mmco = current->mmco[i].memory_management_control_operation;
  858. if (mmco == 0)
  859. break;
  860. if (mmco == 1 || mmco == 3)
  861. xue(difference_of_pic_nums_minus1,
  862. current->mmco[i].difference_of_pic_nums_minus1,
  863. 0, INT32_MAX);
  864. if (mmco == 2)
  865. xue(long_term_pic_num,
  866. current->mmco[i].long_term_pic_num,
  867. 0, sps->max_num_ref_frames - 1);
  868. if (mmco == 3 || mmco == 6)
  869. xue(long_term_frame_idx,
  870. current->mmco[i].long_term_frame_idx,
  871. 0, sps->max_num_ref_frames - 1);
  872. if (mmco == 4)
  873. xue(max_long_term_frame_idx_plus1,
  874. current->mmco[i].max_long_term_frame_idx_plus1,
  875. 0, sps->max_num_ref_frames);
  876. }
  877. if (i == H264_MAX_MMCO_COUNT) {
  878. av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many "
  879. "memory management control operations.\n");
  880. return AVERROR_INVALIDDATA;
  881. }
  882. }
  883. }
  884. return 0;
  885. }
  886. static int FUNC(slice_header)(CodedBitstreamContext *ctx, RWContext *rw,
  887. H264RawSliceHeader *current)
  888. {
  889. CodedBitstreamH264Context *h264 = ctx->priv_data;
  890. const H264RawSPS *sps;
  891. const H264RawPPS *pps;
  892. int err;
  893. int idr_pic_flag;
  894. int slice_type_i, slice_type_p, slice_type_b;
  895. int slice_type_si, slice_type_sp;
  896. HEADER("Slice Header");
  897. CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
  898. 1 << H264_NAL_SLICE |
  899. 1 << H264_NAL_IDR_SLICE |
  900. 1 << H264_NAL_AUXILIARY_SLICE));
  901. if (current->nal_unit_header.nal_unit_type == H264_NAL_AUXILIARY_SLICE) {
  902. if (!h264->last_slice_nal_unit_type) {
  903. av_log(ctx->log_ctx, AV_LOG_ERROR, "Auxiliary slice "
  904. "is not decodable without the main picture "
  905. "in the same access unit.\n");
  906. return AVERROR_INVALIDDATA;
  907. }
  908. } else {
  909. h264->last_slice_nal_unit_type =
  910. current->nal_unit_header.nal_unit_type;
  911. }
  912. idr_pic_flag = h264->last_slice_nal_unit_type == H264_NAL_IDR_SLICE;
  913. ue(first_mb_in_slice, 0, H264_MAX_MB_PIC_SIZE - 1);
  914. ue(slice_type, 0, 9);
  915. slice_type_i = current->slice_type % 5 == 2;
  916. slice_type_p = current->slice_type % 5 == 0;
  917. slice_type_b = current->slice_type % 5 == 1;
  918. slice_type_si = current->slice_type % 5 == 4;
  919. slice_type_sp = current->slice_type % 5 == 3;
  920. if (idr_pic_flag && !(slice_type_i || slice_type_si)) {
  921. av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid slice type %d "
  922. "for IDR picture.\n", current->slice_type);
  923. return AVERROR_INVALIDDATA;
  924. }
  925. ue(pic_parameter_set_id, 0, 255);
  926. pps = h264->pps[current->pic_parameter_set_id];
  927. if (!pps) {
  928. av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
  929. current->pic_parameter_set_id);
  930. return AVERROR_INVALIDDATA;
  931. }
  932. h264->active_pps = pps;
  933. sps = h264->sps[pps->seq_parameter_set_id];
  934. if (!sps) {
  935. av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
  936. pps->seq_parameter_set_id);
  937. return AVERROR_INVALIDDATA;
  938. }
  939. h264->active_sps = sps;
  940. if (sps->separate_colour_plane_flag)
  941. u(2, colour_plane_id, 0, 2);
  942. u(sps->log2_max_frame_num_minus4 + 4, frame_num,
  943. 0, (1 << (sps->log2_max_frame_num_minus4 + 4)) - 1);
  944. if (!sps->frame_mbs_only_flag) {
  945. flag(field_pic_flag);
  946. if (current->field_pic_flag)
  947. flag(bottom_field_flag);
  948. else
  949. infer(bottom_field_flag, 0);
  950. } else {
  951. infer(field_pic_flag, 0);
  952. infer(bottom_field_flag, 0);
  953. }
  954. if (idr_pic_flag)
  955. ue(idr_pic_id, 0, 65535);
  956. if (sps->pic_order_cnt_type == 0) {
  957. u(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, pic_order_cnt_lsb,
  958. 0, (1 << (sps->log2_max_pic_order_cnt_lsb_minus4 + 4)) - 1);
  959. if (pps->bottom_field_pic_order_in_frame_present_flag &&
  960. !current->field_pic_flag)
  961. se(delta_pic_order_cnt_bottom, INT32_MIN + 1, INT32_MAX);
  962. } else if (sps->pic_order_cnt_type == 1) {
  963. if (!sps->delta_pic_order_always_zero_flag) {
  964. se(delta_pic_order_cnt[0], INT32_MIN + 1, INT32_MAX);
  965. if (pps->bottom_field_pic_order_in_frame_present_flag &&
  966. !current->field_pic_flag)
  967. se(delta_pic_order_cnt[1], INT32_MIN + 1, INT32_MAX);
  968. else
  969. infer(delta_pic_order_cnt[1], 0);
  970. } else {
  971. infer(delta_pic_order_cnt[0], 0);
  972. infer(delta_pic_order_cnt[1], 0);
  973. }
  974. }
  975. if (pps->redundant_pic_cnt_present_flag)
  976. ue(redundant_pic_cnt, 0, 127);
  977. if (slice_type_b)
  978. flag(direct_spatial_mv_pred_flag);
  979. if (slice_type_p || slice_type_sp || slice_type_b) {
  980. flag(num_ref_idx_active_override_flag);
  981. if (current->num_ref_idx_active_override_flag) {
  982. ue(num_ref_idx_l0_active_minus1, 0, 31);
  983. if (slice_type_b)
  984. ue(num_ref_idx_l1_active_minus1, 0, 31);
  985. } else {
  986. infer(num_ref_idx_l0_active_minus1,
  987. pps->num_ref_idx_l0_default_active_minus1);
  988. infer(num_ref_idx_l1_active_minus1,
  989. pps->num_ref_idx_l1_default_active_minus1);
  990. }
  991. }
  992. if (current->nal_unit_header.nal_unit_type == 20 ||
  993. current->nal_unit_header.nal_unit_type == 21) {
  994. av_log(ctx->log_ctx, AV_LOG_ERROR, "MVC / 3DAVC not supported.\n");
  995. return AVERROR_PATCHWELCOME;
  996. } else {
  997. CHECK(FUNC(ref_pic_list_modification)(ctx, rw, current));
  998. }
  999. if ((pps->weighted_pred_flag && (slice_type_p || slice_type_sp)) ||
  1000. (pps->weighted_bipred_idc == 1 && slice_type_b)) {
  1001. CHECK(FUNC(pred_weight_table)(ctx, rw, current));
  1002. }
  1003. if (current->nal_unit_header.nal_ref_idc != 0) {
  1004. CHECK(FUNC(dec_ref_pic_marking)(ctx, rw, current, idr_pic_flag));
  1005. }
  1006. if (pps->entropy_coding_mode_flag &&
  1007. !slice_type_i && !slice_type_si) {
  1008. ue(cabac_init_idc, 0, 2);
  1009. }
  1010. se(slice_qp_delta, - 51 - 6 * sps->bit_depth_luma_minus8,
  1011. + 51 + 6 * sps->bit_depth_luma_minus8);
  1012. if (slice_type_sp || slice_type_si) {
  1013. if (slice_type_sp)
  1014. flag(sp_for_switch_flag);
  1015. se(slice_qs_delta, -51, +51);
  1016. }
  1017. if (pps->deblocking_filter_control_present_flag) {
  1018. ue(disable_deblocking_filter_idc, 0, 2);
  1019. if (current->disable_deblocking_filter_idc != 1) {
  1020. se(slice_alpha_c0_offset_div2, -6, +6);
  1021. se(slice_beta_offset_div2, -6, +6);
  1022. } else {
  1023. infer(slice_alpha_c0_offset_div2, 0);
  1024. infer(slice_beta_offset_div2, 0);
  1025. }
  1026. } else {
  1027. infer(disable_deblocking_filter_idc, 0);
  1028. infer(slice_alpha_c0_offset_div2, 0);
  1029. infer(slice_beta_offset_div2, 0);
  1030. }
  1031. if (pps->num_slice_groups_minus1 > 0 &&
  1032. pps->slice_group_map_type >= 3 &&
  1033. pps->slice_group_map_type <= 5) {
  1034. unsigned int pic_size, max, bits;
  1035. pic_size = (sps->pic_width_in_mbs_minus1 + 1) *
  1036. (sps->pic_height_in_map_units_minus1 + 1);
  1037. max = (pic_size + pps->slice_group_change_rate_minus1) /
  1038. (pps->slice_group_change_rate_minus1 + 1);
  1039. bits = av_log2(2 * max - 1);
  1040. u(bits, slice_group_change_cycle, 0, max);
  1041. }
  1042. if (pps->entropy_coding_mode_flag) {
  1043. av_unused int one = 1;
  1044. while (byte_alignment(rw))
  1045. xu(1, cabac_alignment_one_bit, one, 1, 1);
  1046. }
  1047. return 0;
  1048. }
  1049. static int FUNC(filler)(CodedBitstreamContext *ctx, RWContext *rw,
  1050. H264RawFiller *current)
  1051. {
  1052. av_unused int ff_byte = 0xff;
  1053. int err;
  1054. HEADER("Filler Data");
  1055. CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
  1056. 1 << H264_NAL_FILLER_DATA));
  1057. #ifdef READ
  1058. while (bitstream_peek(rw, 8) == 0xff) {
  1059. xu(8, ff_byte, ff_byte, 0xff, 0xff);
  1060. ++current->filler_size;
  1061. }
  1062. #else
  1063. {
  1064. uint32_t i;
  1065. for (i = 0; i < current->filler_size; i++)
  1066. xu(8, ff_byte, ff_byte, 0xff, 0xff);
  1067. }
  1068. #endif
  1069. CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
  1070. return 0;
  1071. }