GCC Code Coverage Report
Directory: ../../../ffmpeg/ Exec Total Coverage
File: src/libavcodec/cbs_h264_syntax_template.c Lines: 482 641 75.2 %
Date: 2021-04-19 06:27:07 Branches: 489 1028 47.6 %

Line Branch Exec Source
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
19
7210
static int FUNC(rbsp_trailing_bits)(CodedBitstreamContext *ctx, RWContext *rw)
20
{
21
    int err;
22
23
7210
    fixed(1, rbsp_stop_one_bit, 1);
24
38492
    while (byte_alignment(rw) != 0)
25
31284
        fixed(1, rbsp_alignment_zero_bit, 0);
26
27
7208
    return 0;
28
}
29
30
27032
static int FUNC(nal_unit_header)(CodedBitstreamContext *ctx, RWContext *rw,
31
                                 H264RawNALUnitHeader *current,
32
                                 uint32_t valid_type_mask)
33
{
34
    int err;
35
36
27032
    fixed(1, forbidden_zero_bit, 0);
37
27032
    ub(2, nal_ref_idc);
38
27032
    ub(5, nal_unit_type);
39
40
27032
    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
27032
    if (current->nal_unit_type == 14 ||
47
27032
        current->nal_unit_type == 20 ||
48
27032
        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
27032
    return 0;
69
}
70
71
static int FUNC(scaling_list)(CodedBitstreamContext *ctx, RWContext *rw,
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
88
24
static int FUNC(hrd_parameters)(CodedBitstreamContext *ctx, RWContext *rw,
89
                                H264RawHRD *current)
90
{
91
    int err, i;
92
93
24
    ue(cpb_cnt_minus1, 0, 31);
94
24
    ub(4, bit_rate_scale);
95
24
    ub(4, cpb_size_scale);
96
97
48
    for (i = 0; i <= current->cpb_cnt_minus1; i++) {
98
24
        ues(bit_rate_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
99
24
        ues(cpb_size_value_minus1[i], 0, UINT32_MAX - 1, 1, i);
100
24
        flags(cbr_flag[i], 1, i);
101
    }
102
103
24
    ub(5, initial_cpb_removal_delay_length_minus1);
104
24
    ub(5, cpb_removal_delay_length_minus1);
105
24
    ub(5, dpb_output_delay_length_minus1);
106
24
    ub(5, time_offset_length);
107
108
24
    return 0;
109
}
110
111
24
static int FUNC(vui_parameters)(CodedBitstreamContext *ctx, RWContext *rw,
112
                                H264RawVUI *current, H264RawSPS *sps)
113
{
114
    int err;
115
116
24
    flag(aspect_ratio_info_present_flag);
117
24
    if (current->aspect_ratio_info_present_flag) {
118
8
        ub(8, aspect_ratio_idc);
119
8
        if (current->aspect_ratio_idc == 255) {
120
            ub(16, sar_width);
121
            ub(16, sar_height);
122
        }
123
    } else {
124
16
        infer(aspect_ratio_idc, 0);
125
    }
126
127
24
    flag(overscan_info_present_flag);
128
24
    if (current->overscan_info_present_flag)
129
8
        flag(overscan_appropriate_flag);
130
131
24
    flag(video_signal_type_present_flag);
132
24
    if (current->video_signal_type_present_flag) {
133
8
        ub(3, video_format);
134
8
        flag(video_full_range_flag);
135
8
        flag(colour_description_present_flag);
136
8
        if (current->colour_description_present_flag) {
137
8
            ub(8, colour_primaries);
138
8
            ub(8, transfer_characteristics);
139
8
            ub(8, matrix_coefficients);
140
        } else {
141
            infer(colour_primaries,         2);
142
            infer(transfer_characteristics, 2);
143
            infer(matrix_coefficients,      2);
144
        }
145
    } else {
146
16
        infer(video_format,             5);
147
16
        infer(video_full_range_flag,    0);
148
16
        infer(colour_primaries,         2);
149
16
        infer(transfer_characteristics, 2);
150
16
        infer(matrix_coefficients,      2);
151
    }
152
153
24
    flag(chroma_loc_info_present_flag);
154
24
    if (current->chroma_loc_info_present_flag) {
155
8
        ue(chroma_sample_loc_type_top_field,    0, 5);
156
8
        ue(chroma_sample_loc_type_bottom_field, 0, 5);
157
    } else {
158
16
        infer(chroma_sample_loc_type_top_field,    0);
159
16
        infer(chroma_sample_loc_type_bottom_field, 0);
160
    }
161
162
24
    flag(timing_info_present_flag);
163
24
    if (current->timing_info_present_flag) {
164
24
        u(32, num_units_in_tick, 1, UINT32_MAX);
165
24
        u(32, time_scale,        1, UINT32_MAX);
166
24
        flag(fixed_frame_rate_flag);
167
    } else {
168
        infer(fixed_frame_rate_flag, 0);
169
    }
170
171
24
    flag(nal_hrd_parameters_present_flag);
172
24
    if (current->nal_hrd_parameters_present_flag)
173
16
        CHECK(FUNC(hrd_parameters)(ctx, rw, &current->nal_hrd_parameters));
174
175
24
    flag(vcl_hrd_parameters_present_flag);
176
24
    if (current->vcl_hrd_parameters_present_flag)
177
8
        CHECK(FUNC(hrd_parameters)(ctx, rw, &current->vcl_hrd_parameters));
178
179
24
    if (current->nal_hrd_parameters_present_flag ||
180
8
        current->vcl_hrd_parameters_present_flag)
181
16
        flag(low_delay_hrd_flag);
182
    else
183
8
        infer(low_delay_hrd_flag, 1 - current->fixed_frame_rate_flag);
184
185
24
    flag(pic_struct_present_flag);
186
187
24
    flag(bitstream_restriction_flag);
188
24
    if (current->bitstream_restriction_flag) {
189
16
        flag(motion_vectors_over_pic_boundaries_flag);
190
16
        ue(max_bytes_per_pic_denom, 0, 16);
191
16
        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
16
        ue(log2_max_mv_length_horizontal, 0, 16);
195
16
        ue(log2_max_mv_length_vertical,   0, 16);
196
16
        ue(max_num_reorder_frames,  0, H264_MAX_DPB_FRAMES);
197
16
        ue(max_dec_frame_buffering, 0, H264_MAX_DPB_FRAMES);
198
    } else {
199
8
        infer(motion_vectors_over_pic_boundaries_flag, 1);
200
8
        infer(max_bytes_per_pic_denom, 2);
201
8
        infer(max_bits_per_mb_denom,   1);
202
8
        infer(log2_max_mv_length_horizontal, 15);
203
8
        infer(log2_max_mv_length_vertical,   15);
204
205

8
        if ((sps->profile_idc ==  44 || sps->profile_idc ==  86 ||
206

8
             sps->profile_idc == 100 || sps->profile_idc == 110 ||
207
             sps->profile_idc == 122 || sps->profile_idc == 244) &&
208
8
            sps->constraint_set3_flag) {
209
            infer(max_num_reorder_frames,  0);
210
            infer(max_dec_frame_buffering, 0);
211
        } else {
212
8
            infer(max_num_reorder_frames,  H264_MAX_DPB_FRAMES);
213
8
            infer(max_dec_frame_buffering, H264_MAX_DPB_FRAMES);
214
        }
215
    }
216
217
24
    return 0;
218
}
219
220
144
static int FUNC(vui_parameters_default)(CodedBitstreamContext *ctx,
221
                                        RWContext *rw, H264RawVUI *current,
222
                                        H264RawSPS *sps)
223
{
224
144
    infer(aspect_ratio_idc, 0);
225
226
144
    infer(video_format,             5);
227
144
    infer(video_full_range_flag,    0);
228
144
    infer(colour_primaries,         2);
229
144
    infer(transfer_characteristics, 2);
230
144
    infer(matrix_coefficients,      2);
231
232
144
    infer(chroma_sample_loc_type_top_field,    0);
233
144
    infer(chroma_sample_loc_type_bottom_field, 0);
234
235
144
    infer(fixed_frame_rate_flag, 0);
236
144
    infer(low_delay_hrd_flag,    1);
237
238
144
    infer(pic_struct_present_flag, 0);
239
240
144
    infer(motion_vectors_over_pic_boundaries_flag, 1);
241
144
    infer(max_bytes_per_pic_denom, 2);
242
144
    infer(max_bits_per_mb_denom,   1);
243
144
    infer(log2_max_mv_length_horizontal, 15);
244
144
    infer(log2_max_mv_length_vertical,   15);
245
246

144
    if ((sps->profile_idc ==  44 || sps->profile_idc ==  86 ||
247

144
         sps->profile_idc == 100 || sps->profile_idc == 110 ||
248

144
         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
144
        infer(max_num_reorder_frames,  H264_MAX_DPB_FRAMES);
254
144
        infer(max_dec_frame_buffering, H264_MAX_DPB_FRAMES);
255
    }
256
257
144
    return 0;
258
}
259
260
168
static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw,
261
                     H264RawSPS *current)
262
{
263
    int err, i;
264
265
168
    HEADER("Sequence Parameter Set");
266
267
168
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
268
                                1 << H264_NAL_SPS));
269
270
168
    ub(8, profile_idc);
271
272
168
    flag(constraint_set0_flag);
273
168
    flag(constraint_set1_flag);
274
168
    flag(constraint_set2_flag);
275
168
    flag(constraint_set3_flag);
276
168
    flag(constraint_set4_flag);
277
168
    flag(constraint_set5_flag);
278
279
168
    u(2, reserved_zero_2bits,  0, 0);
280
281
168
    ub(8, level_idc);
282
283
168
    ue(seq_parameter_set_id, 0, 31);
284
285

168
    if (current->profile_idc == 100 || current->profile_idc == 110 ||
286

160
        current->profile_idc == 122 || current->profile_idc == 244 ||
287

160
        current->profile_idc ==  44 || current->profile_idc ==  83 ||
288

160
        current->profile_idc ==  86 || current->profile_idc == 118 ||
289

160
        current->profile_idc == 128 || current->profile_idc == 138) {
290
8
        ue(chroma_format_idc, 0, 3);
291
292
8
        if (current->chroma_format_idc == 3)
293
            flag(separate_colour_plane_flag);
294
        else
295
8
            infer(separate_colour_plane_flag, 0);
296
297
8
        ue(bit_depth_luma_minus8,   0, 6);
298
8
        ue(bit_depth_chroma_minus8, 0, 6);
299
300
8
        flag(qpprime_y_zero_transform_bypass_flag);
301
302
8
        flag(seq_scaling_matrix_present_flag);
303
8
        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
160
        infer(chroma_format_idc, current->profile_idc == 183 ? 0 : 1);
320
321
160
        infer(separate_colour_plane_flag, 0);
322
160
        infer(bit_depth_luma_minus8,      0);
323
160
        infer(bit_depth_chroma_minus8,    0);
324
    }
325
326
168
    ue(log2_max_frame_num_minus4, 0, 12);
327
168
    ue(pic_order_cnt_type, 0, 2);
328
329
168
    if (current->pic_order_cnt_type == 0) {
330
100
        ue(log2_max_pic_order_cnt_lsb_minus4, 0, 12);
331
68
    } else if (current->pic_order_cnt_type == 1) {
332
32
        flag(delta_pic_order_always_zero_flag);
333
32
        se(offset_for_non_ref_pic,         INT32_MIN + 1, INT32_MAX);
334
32
        se(offset_for_top_to_bottom_field, INT32_MIN + 1, INT32_MAX);
335
32
        ue(num_ref_frames_in_pic_order_cnt_cycle, 0, 255);
336
337
64
        for (i = 0; i < current->num_ref_frames_in_pic_order_cnt_cycle; i++)
338
32
            ses(offset_for_ref_frame[i], INT32_MIN + 1, INT32_MAX, 1, i);
339
    }
340
341
168
    ue(max_num_ref_frames, 0, H264_MAX_DPB_FRAMES);
342
168
    flag(gaps_in_frame_num_allowed_flag);
343
344
168
    ue(pic_width_in_mbs_minus1,        0, H264_MAX_MB_WIDTH);
345
168
    ue(pic_height_in_map_units_minus1, 0, H264_MAX_MB_HEIGHT);
346
347
168
    flag(frame_mbs_only_flag);
348
168
    if (!current->frame_mbs_only_flag)
349
52
        flag(mb_adaptive_frame_field_flag);
350
351
168
    flag(direct_8x8_inference_flag);
352
353
168
    flag(frame_cropping_flag);
354
168
    if (current->frame_cropping_flag) {
355
16
        ue(frame_crop_left_offset,   0, H264_MAX_WIDTH);
356
16
        ue(frame_crop_right_offset,  0, H264_MAX_WIDTH);
357
16
        ue(frame_crop_top_offset,    0, H264_MAX_HEIGHT);
358
16
        ue(frame_crop_bottom_offset, 0, H264_MAX_HEIGHT);
359
    }
360
361
168
    flag(vui_parameters_present_flag);
362
168
    if (current->vui_parameters_present_flag)
363
24
        CHECK(FUNC(vui_parameters)(ctx, rw, &current->vui, current));
364
    else
365
144
        CHECK(FUNC(vui_parameters_default)(ctx, rw, &current->vui, current));
366
367
168
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
368
369
168
    return 0;
370
}
371
372
static int FUNC(sps_extension)(CodedBitstreamContext *ctx, RWContext *rw,
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
        ub(bits, alpha_opaque_value);
394
        ub(bits, alpha_transparent_value);
395
    }
396
397
    flag(additional_extension_flag);
398
399
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
400
401
    return 0;
402
}
403
404
4736
static int FUNC(pps)(CodedBitstreamContext *ctx, RWContext *rw,
405
                     H264RawPPS *current)
406
{
407
4736
    CodedBitstreamH264Context *h264 = ctx->priv_data;
408
    const H264RawSPS *sps;
409
    int err, i;
410
411
4736
    HEADER("Picture Parameter Set");
412
413
4736
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
414
                                1 << H264_NAL_PPS));
415
416
4736
    ue(pic_parameter_set_id, 0, 255);
417
4736
    ue(seq_parameter_set_id, 0, 31);
418
419
4736
    sps = h264->sps[current->seq_parameter_set_id];
420
4736
    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
4736
    flag(entropy_coding_mode_flag);
427
4736
    flag(bottom_field_pic_order_in_frame_present_flag);
428
429
4736
    ue(num_slice_groups_minus1, 0, 7);
430
4736
    if (current->num_slice_groups_minus1 > 0) {
431
        unsigned int pic_size;
432
        int iGroup;
433
434
56
        pic_size = (sps->pic_width_in_mbs_minus1 + 1) *
435
56
                   (sps->pic_height_in_map_units_minus1 + 1);
436
437
56
        ue(slice_group_map_type, 0, 6);
438
439
56
        if (current->slice_group_map_type == 0) {
440
72
            for (iGroup = 0; iGroup <= current->num_slice_groups_minus1; iGroup++)
441
64
                ues(run_length_minus1[iGroup], 0, pic_size - 1, 1, iGroup);
442
443
48
        } else if (current->slice_group_map_type == 2) {
444
24
            for (iGroup = 0; iGroup < current->num_slice_groups_minus1; iGroup++) {
445
16
                ues(top_left[iGroup],       0, pic_size - 1, 1, iGroup);
446
16
                ues(bottom_right[iGroup],
447
                    current->top_left[iGroup], pic_size - 1, 1, iGroup);
448
            }
449
40
        } else if (current->slice_group_map_type == 3 ||
450
32
                   current->slice_group_map_type == 4 ||
451
24
                   current->slice_group_map_type == 5) {
452
24
            flag(slice_group_change_direction_flag);
453
24
            ue(slice_group_change_rate_minus1, 0, pic_size - 1);
454
16
        } else if (current->slice_group_map_type == 6) {
455
8
            ue(pic_size_in_map_units_minus1, pic_size - 1, pic_size - 1);
456
457
8
            allocate(current->slice_group_id,
458
                     current->pic_size_in_map_units_minus1 + 1);
459
800
            for (i = 0; i <= current->pic_size_in_map_units_minus1; i++)
460
792
                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
4736
    ue(num_ref_idx_l0_default_active_minus1, 0, 31);
466
4736
    ue(num_ref_idx_l1_default_active_minus1, 0, 31);
467
468
4736
    flag(weighted_pred_flag);
469
4736
    u(2, weighted_bipred_idc, 0, 2);
470
471
4736
    se(pic_init_qp_minus26, -26 - 6 * sps->bit_depth_luma_minus8, +25);
472
4736
    se(pic_init_qs_minus26, -26, +25);
473
4736
    se(chroma_qp_index_offset, -12, +12);
474
475
4736
    flag(deblocking_filter_control_present_flag);
476
4736
    flag(constrained_intra_pred_flag);
477
4736
    flag(redundant_pic_cnt_present_flag);
478
479
4736
    if (more_rbsp_data(current->more_rbsp_data))
480
    {
481
8
        flag(transform_8x8_mode_flag);
482
483
8
        flag(pic_scaling_matrix_present_flag);
484
8
        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
8
        se(second_chroma_qp_index_offset, -12, +12);
502
    } else {
503
4728
        infer(transform_8x8_mode_flag, 0);
504
4728
        infer(pic_scaling_matrix_present_flag, 0);
505
4728
        infer(second_chroma_qp_index_offset, current->chroma_qp_index_offset);
506
    }
507
508
4736
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
509
510
4736
    return 0;
511
}
512
513
18
static int FUNC(sei_buffering_period)(CodedBitstreamContext *ctx, RWContext *rw,
514
                                      H264RawSEIBufferingPeriod *current,
515
                                      SEIMessageState *sei)
516
{
517
18
    CodedBitstreamH264Context *h264 = ctx->priv_data;
518
    const H264RawSPS *sps;
519
    int err, i, length;
520
521
18
    HEADER("Buffering Period");
522
523
18
    ue(seq_parameter_set_id, 0, 31);
524
525
18
    sps = h264->sps[current->seq_parameter_set_id];
526
18
    if (!sps) {
527
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
528
               current->seq_parameter_set_id);
529
        return AVERROR_INVALIDDATA;
530
    }
531
18
    h264->active_sps = sps;
532
533
18
    if (sps->vui.nal_hrd_parameters_present_flag) {
534
24
        for (i = 0; i <= sps->vui.nal_hrd_parameters.cpb_cnt_minus1; i++) {
535
12
            length = sps->vui.nal_hrd_parameters.initial_cpb_removal_delay_length_minus1 + 1;
536
12
            xu(length, initial_cpb_removal_delay[SchedSelIdx],
537
               current->nal.initial_cpb_removal_delay[i],
538
               1, MAX_UINT_BITS(length), 1, i);
539
12
            xu(length, initial_cpb_removal_delay_offset[SchedSelIdx],
540
               current->nal.initial_cpb_removal_delay_offset[i],
541
               0, MAX_UINT_BITS(length), 1, i);
542
        }
543
    }
544
545
18
    if (sps->vui.vcl_hrd_parameters_present_flag) {
546
12
        for (i = 0; i <= sps->vui.vcl_hrd_parameters.cpb_cnt_minus1; i++) {
547
6
            length = sps->vui.vcl_hrd_parameters.initial_cpb_removal_delay_length_minus1 + 1;
548
6
            xu(length, initial_cpb_removal_delay[SchedSelIdx],
549
               current->vcl.initial_cpb_removal_delay[i],
550
               1, MAX_UINT_BITS(length), 1, i);
551
6
            xu(length, initial_cpb_removal_delay_offset[SchedSelIdx],
552
               current->vcl.initial_cpb_removal_delay_offset[i],
553
               0, MAX_UINT_BITS(length), 1, i);
554
        }
555
    }
556
557
18
    return 0;
558
}
559
560
static int FUNC(sei_pic_timestamp)(CodedBitstreamContext *ctx, RWContext *rw,
561
                                   H264RawSEIPicTimestamp *current,
562
                                   const H264RawSPS *sps)
563
{
564
    uint8_t time_offset_length;
565
    int err;
566
567
    u(2, ct_type, 0, 2);
568
    flag(nuit_field_based_flag);
569
    u(5, counting_type, 0, 6);
570
    flag(full_timestamp_flag);
571
    flag(discontinuity_flag);
572
    flag(cnt_dropped_flag);
573
    ub(8, n_frames);
574
    if (current->full_timestamp_flag) {
575
            u(6, seconds_value, 0, 59);
576
            u(6, minutes_value, 0, 59);
577
            u(5, hours_value,   0, 23);
578
    } else {
579
        flag(seconds_flag);
580
        if (current->seconds_flag) {
581
            u(6, seconds_value, 0, 59);
582
            flag(minutes_flag);
583
            if (current->minutes_flag) {
584
                u(6, minutes_value, 0, 59);
585
                flag(hours_flag);
586
                if (current->hours_flag)
587
                    u(5, hours_value, 0, 23);
588
            }
589
        }
590
    }
591
592
    if (sps->vui.nal_hrd_parameters_present_flag)
593
        time_offset_length = sps->vui.nal_hrd_parameters.time_offset_length;
594
    else if (sps->vui.vcl_hrd_parameters_present_flag)
595
        time_offset_length = sps->vui.vcl_hrd_parameters.time_offset_length;
596
    else
597
        time_offset_length = 24;
598
599
    if (time_offset_length > 0)
600
        ib(time_offset_length, time_offset);
601
    else
602
        infer(time_offset, 0);
603
604
    return 0;
605
}
606
607
1934
static int FUNC(sei_pic_timing)(CodedBitstreamContext *ctx, RWContext *rw,
608
                                H264RawSEIPicTiming *current,
609
                                SEIMessageState *sei)
610
{
611
1934
    CodedBitstreamH264Context *h264 = ctx->priv_data;
612
    const H264RawSPS *sps;
613
    int err;
614
615
1934
    HEADER("Picture Timing");
616
617
1934
    sps = h264->active_sps;
618
1934
    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
1934
    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
640
1934
    if (sps->vui.nal_hrd_parameters_present_flag ||
641
236
        sps->vui.vcl_hrd_parameters_present_flag) {
642
        const H264RawHRD *hrd;
643
644
1698
        if (sps->vui.nal_hrd_parameters_present_flag)
645
1698
            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
1698
        ub(hrd->cpb_removal_delay_length_minus1 + 1, cpb_removal_delay);
655
1698
        ub(hrd->dpb_output_delay_length_minus1 + 1, dpb_output_delay);
656
    }
657
658
1934
    if (sps->vui.pic_struct_present_flag) {
659
        static const uint8_t num_clock_ts[9] = {
660
            1, 1, 1, 2, 2, 3, 3, 2, 3
661
        };
662
        int i;
663
664
1904
        u(4, pic_struct, 0, 8);
665
1904
        if (current->pic_struct > 8)
666
            return AVERROR_INVALIDDATA;
667
668
6304
        for (i = 0; i < num_clock_ts[current->pic_struct]; i++) {
669
4400
            flags(clock_timestamp_flag[i], 1, i);
670
4400
            if (current->clock_timestamp_flag[i])
671
                CHECK(FUNC(sei_pic_timestamp)(ctx, rw,
672
                                              &current->timestamp[i], sps));
673
        }
674
    }
675
676
1934
    return 0;
677
}
678
679
30
static int FUNC(sei_pan_scan_rect)(CodedBitstreamContext *ctx, RWContext *rw,
680
                                   H264RawSEIPanScanRect *current,
681
                                   SEIMessageState *sei)
682
{
683
    int err, i;
684
685
30
    HEADER("Pan-Scan Rectangle");
686
687
30
    ue(pan_scan_rect_id, 0, UINT32_MAX - 1);
688
30
    flag(pan_scan_rect_cancel_flag);
689
690
30
    if (!current->pan_scan_rect_cancel_flag) {
691
30
        ue(pan_scan_cnt_minus1, 0, 2);
692
693
60
        for (i = 0; i <= current->pan_scan_cnt_minus1; i++) {
694
30
            ses(pan_scan_rect_left_offset[i],   INT32_MIN + 1, INT32_MAX, 1, i);
695
30
            ses(pan_scan_rect_right_offset[i],  INT32_MIN + 1, INT32_MAX, 1, i);
696
30
            ses(pan_scan_rect_top_offset[i],    INT32_MIN + 1, INT32_MAX, 1, i);
697
30
            ses(pan_scan_rect_bottom_offset[i], INT32_MIN + 1, INT32_MAX, 1, i);
698
        }
699
700
30
        ue(pan_scan_rect_repetition_period, 0, 16384);
701
    }
702
703
30
    return 0;
704
}
705
706
12
static int FUNC(sei_recovery_point)(CodedBitstreamContext *ctx, RWContext *rw,
707
                                    H264RawSEIRecoveryPoint *current,
708
                                    SEIMessageState *sei)
709
{
710
    int err;
711
712
12
    HEADER("Recovery Point");
713
714
12
    ue(recovery_frame_cnt, 0, 65535);
715
12
    flag(exact_match_flag);
716
12
    flag(broken_link_flag);
717
12
    u(2, changing_slice_group_idc, 0, 2);
718
719
12
    return 0;
720
}
721
722
6
static int FUNC(sei_display_orientation)(CodedBitstreamContext *ctx, RWContext *rw,
723
                                         H264RawSEIDisplayOrientation *current,
724
                                         SEIMessageState *sei)
725
{
726
    int err;
727
728
6
    HEADER("Display Orientation");
729
730
6
    flag(display_orientation_cancel_flag);
731
6
    if (!current->display_orientation_cancel_flag) {
732
6
        flag(hor_flip);
733
6
        flag(ver_flip);
734
6
        ub(16, anticlockwise_rotation);
735
6
        ue(display_orientation_repetition_period, 0, 16384);
736
6
        flag(display_orientation_extension_flag);
737
    }
738
739
6
    return 0;
740
}
741
742
1378
static int FUNC(sei)(CodedBitstreamContext *ctx, RWContext *rw,
743
                     H264RawSEI *current)
744
{
745
    int err;
746
747
1378
    HEADER("Supplemental Enhancement Information");
748
749
1378
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
750
                                1 << H264_NAL_SEI));
751
752
1378
    CHECK(FUNC_SEI(message_list)(ctx, rw, &current->message_list, 1));
753
754
1378
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
755
756
1378
    return 0;
757
}
758
759
860
static int FUNC(aud)(CodedBitstreamContext *ctx, RWContext *rw,
760
                     H264RawAUD *current)
761
{
762
    int err;
763
764
860
    HEADER("Access Unit Delimiter");
765
766
860
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
767
                                1 << H264_NAL_AUD));
768
769
860
    ub(3, primary_pic_type);
770
771
860
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
772
773
860
    return 0;
774
}
775
776
19810
static int FUNC(ref_pic_list_modification)(CodedBitstreamContext *ctx, RWContext *rw,
777
                                           H264RawSliceHeader *current)
778
{
779
19810
    CodedBitstreamH264Context *h264 = ctx->priv_data;
780
19810
    const H264RawSPS *sps = h264->active_sps;
781
    int err, i, mopn;
782
783
19810
    if (current->slice_type % 5 != 2 &&
784
18678
        current->slice_type % 5 != 4) {
785
18678
        flag(ref_pic_list_modification_flag_l0);
786
18678
        if (current->ref_pic_list_modification_flag_l0) {
787
6172
            for (i = 0; i < H264_MAX_RPLM_COUNT; i++) {
788
6172
                xue(modification_of_pic_nums_idc,
789
                    current->rplm_l0[i].modification_of_pic_nums_idc, 0, 3, 0);
790
791
6172
                mopn = current->rplm_l0[i].modification_of_pic_nums_idc;
792
6172
                if (mopn == 3)
793
1980
                    break;
794
795

4192
                if (mopn == 0 || mopn == 1)
796
4164
                    xue(abs_diff_pic_num_minus1,
797
                        current->rplm_l0[i].abs_diff_pic_num_minus1,
798
                        0, (1 + current->field_pic_flag) *
799
                        (1 << (sps->log2_max_frame_num_minus4 + 4)), 0);
800
28
                else if (mopn == 2)
801
28
                    xue(long_term_pic_num,
802
                        current->rplm_l0[i].long_term_pic_num,
803
                        0, sps->max_num_ref_frames - 1, 0);
804
            }
805
        }
806
    }
807
808
19810
    if (current->slice_type % 5 == 1) {
809
4390
        flag(ref_pic_list_modification_flag_l1);
810
4390
        if (current->ref_pic_list_modification_flag_l1) {
811
            for (i = 0; i < H264_MAX_RPLM_COUNT; i++) {
812
                xue(modification_of_pic_nums_idc,
813
                    current->rplm_l1[i].modification_of_pic_nums_idc, 0, 3, 0);
814
815
                mopn = current->rplm_l1[i].modification_of_pic_nums_idc;
816
                if (mopn == 3)
817
                    break;
818
819
                if (mopn == 0 || mopn == 1)
820
                    xue(abs_diff_pic_num_minus1,
821
                        current->rplm_l1[i].abs_diff_pic_num_minus1,
822
                        0, (1 + current->field_pic_flag) *
823
                        (1 << (sps->log2_max_frame_num_minus4 + 4)), 0);
824
                else if (mopn == 2)
825
                    xue(long_term_pic_num,
826
                        current->rplm_l1[i].long_term_pic_num,
827
                        0, sps->max_num_ref_frames - 1, 0);
828
            }
829
        }
830
    }
831
832
19810
    return 0;
833
}
834
835
336
static int FUNC(pred_weight_table)(CodedBitstreamContext *ctx, RWContext *rw,
836
                                   H264RawSliceHeader *current)
837
{
838
336
    CodedBitstreamH264Context *h264 = ctx->priv_data;
839
336
    const H264RawSPS *sps = h264->active_sps;
840
    int chroma;
841
    int err, i, j;
842
843
336
    ue(luma_log2_weight_denom, 0, 7);
844
845

336
    chroma = !sps->separate_colour_plane_flag && sps->chroma_format_idc != 0;
846
336
    if (chroma)
847
336
        ue(chroma_log2_weight_denom, 0, 7);
848
849
1976
    for (i = 0; i <= current->num_ref_idx_l0_active_minus1; i++) {
850
1640
        flags(luma_weight_l0_flag[i], 1, i);
851
1640
        if (current->luma_weight_l0_flag[i]) {
852
872
            ses(luma_weight_l0[i], -128, +127, 1, i);
853
872
            ses(luma_offset_l0[i], -128, +127, 1, i);
854
        }
855
1640
        if (chroma) {
856
1640
            flags(chroma_weight_l0_flag[i], 1, i);
857
1640
            if (current->chroma_weight_l0_flag[i]) {
858
2496
                for (j = 0; j < 2; j++) {
859
1664
                    ses(chroma_weight_l0[i][j], -128, +127, 2, i, j);
860
1664
                    ses(chroma_offset_l0[i][j], -128, +127, 2, i, j);
861
                }
862
            }
863
        }
864
    }
865
866
336
    if (current->slice_type % 5 == 1) {
867
        for (i = 0; i <= current->num_ref_idx_l1_active_minus1; i++) {
868
            flags(luma_weight_l1_flag[i], 1, i);
869
            if (current->luma_weight_l1_flag[i]) {
870
                ses(luma_weight_l1[i], -128, +127, 1, i);
871
                ses(luma_offset_l1[i], -128, +127, 1, i);
872
            }
873
            if (chroma) {
874
                flags(chroma_weight_l1_flag[i], 1, i);
875
                if (current->chroma_weight_l1_flag[i]) {
876
                    for (j = 0; j < 2; j++) {
877
                        ses(chroma_weight_l1[i][j], -128, +127, 2, i, j);
878
                        ses(chroma_offset_l1[i][j], -128, +127, 2, i, j);
879
                    }
880
                }
881
            }
882
        }
883
    }
884
885
336
    return 0;
886
}
887
888
15452
static int FUNC(dec_ref_pic_marking)(CodedBitstreamContext *ctx, RWContext *rw,
889
                                     H264RawSliceHeader *current, int idr_pic_flag)
890
{
891
15452
    CodedBitstreamH264Context *h264 = ctx->priv_data;
892
15452
    const H264RawSPS *sps = h264->active_sps;
893
    int err, i;
894
    uint32_t mmco;
895
896
15452
    if (idr_pic_flag) {
897
232
        flag(no_output_of_prior_pics_flag);
898
232
        flag(long_term_reference_flag);
899
    } else {
900
15220
        flag(adaptive_ref_pic_marking_mode_flag);
901
15220
        if (current->adaptive_ref_pic_marking_mode_flag) {
902
1772
            for (i = 0; i < H264_MAX_MMCO_COUNT; i++) {
903
1772
                xue(memory_management_control_operation,
904
                    current->mmco[i].memory_management_control_operation,
905
                    0, 6, 0);
906
907
1772
                mmco = current->mmco[i].memory_management_control_operation;
908
1772
                if (mmco == 0)
909
864
                    break;
910
911

908
                if (mmco == 1 || mmco == 3)
912
744
                    xue(difference_of_pic_nums_minus1,
913
                        current->mmco[i].difference_of_pic_nums_minus1,
914
                        0, INT32_MAX, 0);
915
908
                if (mmco == 2)
916
                    xue(long_term_pic_num,
917
                        current->mmco[i].long_term_pic_num,
918
                        0, sps->max_num_ref_frames - 1, 0);
919

908
                if (mmco == 3 || mmco == 6)
920
112
                    xue(long_term_frame_idx,
921
                        current->mmco[i].long_term_frame_idx,
922
                        0, sps->max_num_ref_frames - 1, 0);
923
908
                if (mmco == 4)
924
8
                    xue(max_long_term_frame_idx_plus1,
925
                        current->mmco[i].max_long_term_frame_idx_plus1,
926
                        0, sps->max_num_ref_frames, 0);
927
            }
928
864
            if (i == H264_MAX_MMCO_COUNT) {
929
                av_log(ctx->log_ctx, AV_LOG_ERROR, "Too many "
930
                       "memory management control operations.\n");
931
                return AVERROR_INVALIDDATA;
932
            }
933
        }
934
    }
935
936
15452
    return 0;
937
}
938
939
19810
static int FUNC(slice_header)(CodedBitstreamContext *ctx, RWContext *rw,
940
                              H264RawSliceHeader *current)
941
{
942
19810
    CodedBitstreamH264Context *h264 = ctx->priv_data;
943
    const H264RawSPS *sps;
944
    const H264RawPPS *pps;
945
    int err;
946
    int idr_pic_flag;
947
    int slice_type_i, slice_type_p, slice_type_b;
948
    int slice_type_si, slice_type_sp;
949
950
19810
    HEADER("Slice Header");
951
952
19810
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
953
                                1 << H264_NAL_SLICE     |
954
                                1 << H264_NAL_IDR_SLICE |
955
                                1 << H264_NAL_AUXILIARY_SLICE));
956
957
19810
    if (current->nal_unit_header.nal_unit_type == H264_NAL_AUXILIARY_SLICE) {
958
        if (!h264->last_slice_nal_unit_type) {
959
            av_log(ctx->log_ctx, AV_LOG_ERROR, "Auxiliary slice "
960
                   "is not decodable without the main picture "
961
                   "in the same access unit.\n");
962
            return AVERROR_INVALIDDATA;
963
        }
964
        idr_pic_flag = h264->last_slice_nal_unit_type == H264_NAL_IDR_SLICE;
965
    } else {
966
19810
        idr_pic_flag = current->nal_unit_header.nal_unit_type == H264_NAL_IDR_SLICE;
967
    }
968
969
19810
    ue(first_mb_in_slice, 0, H264_MAX_MB_PIC_SIZE - 1);
970
19810
    ue(slice_type, 0, 9);
971
972
19810
    slice_type_i  = current->slice_type % 5 == 2;
973
19810
    slice_type_p  = current->slice_type % 5 == 0;
974
19810
    slice_type_b  = current->slice_type % 5 == 1;
975
19810
    slice_type_si = current->slice_type % 5 == 4;
976
19810
    slice_type_sp = current->slice_type % 5 == 3;
977
978

19810
    if (idr_pic_flag && !(slice_type_i || slice_type_si)) {
979
        av_log(ctx->log_ctx, AV_LOG_ERROR, "Invalid slice type %d "
980
               "for IDR picture.\n", current->slice_type);
981
        return AVERROR_INVALIDDATA;
982
    }
983
984
19810
    ue(pic_parameter_set_id, 0, 255);
985
986
19810
    pps = h264->pps[current->pic_parameter_set_id];
987
19810
    if (!pps) {
988
        av_log(ctx->log_ctx, AV_LOG_ERROR, "PPS id %d not available.\n",
989
               current->pic_parameter_set_id);
990
        return AVERROR_INVALIDDATA;
991
    }
992
19810
    h264->active_pps = pps;
993
994
19810
    sps = h264->sps[pps->seq_parameter_set_id];
995
19810
    if (!sps) {
996
        av_log(ctx->log_ctx, AV_LOG_ERROR, "SPS id %d not available.\n",
997
               pps->seq_parameter_set_id);
998
        return AVERROR_INVALIDDATA;
999
    }
1000
19810
    h264->active_sps = sps;
1001
1002
19810
    if (sps->separate_colour_plane_flag)
1003
        u(2, colour_plane_id, 0, 2);
1004
1005
19810
    ub(sps->log2_max_frame_num_minus4 + 4, frame_num);
1006
1007
19810
    if (!sps->frame_mbs_only_flag) {
1008
1562
        flag(field_pic_flag);
1009
1562
        if (current->field_pic_flag)
1010
1174
            flag(bottom_field_flag);
1011
        else
1012
388
            infer(bottom_field_flag, 0);
1013
    } else {
1014
18248
        infer(field_pic_flag,    0);
1015
18248
        infer(bottom_field_flag, 0);
1016
    }
1017
1018
19810
    if (idr_pic_flag)
1019
232
        ue(idr_pic_id, 0, 65535);
1020
1021
19810
    if (sps->pic_order_cnt_type == 0) {
1022
10122
        ub(sps->log2_max_pic_order_cnt_lsb_minus4 + 4, pic_order_cnt_lsb);
1023
10122
        if (pps->bottom_field_pic_order_in_frame_present_flag &&
1024
360
            !current->field_pic_flag)
1025
360
            se(delta_pic_order_cnt_bottom, INT32_MIN + 1, INT32_MAX);
1026
1027
9688
    } else if (sps->pic_order_cnt_type == 1) {
1028
9124
        if (!sps->delta_pic_order_always_zero_flag) {
1029
1692
            se(delta_pic_order_cnt[0], INT32_MIN + 1, INT32_MAX);
1030
1692
            if (pps->bottom_field_pic_order_in_frame_present_flag &&
1031
                !current->field_pic_flag)
1032
                se(delta_pic_order_cnt[1], INT32_MIN + 1, INT32_MAX);
1033
            else
1034
1692
                infer(delta_pic_order_cnt[1], 0);
1035
        } else {
1036
7432
            infer(delta_pic_order_cnt[0], 0);
1037
7432
            infer(delta_pic_order_cnt[1], 0);
1038
        }
1039
    }
1040
1041
19810
    if (pps->redundant_pic_cnt_present_flag)
1042
        ue(redundant_pic_cnt, 0, 127);
1043
    else
1044
19810
        infer(redundant_pic_cnt, 0);
1045
1046
19810
    if (current->nal_unit_header.nal_unit_type != H264_NAL_AUXILIARY_SLICE
1047
19810
        && !current->redundant_pic_cnt)
1048
19810
        h264->last_slice_nal_unit_type =
1049
19810
            current->nal_unit_header.nal_unit_type;
1050
1051
19810
    if (slice_type_b)
1052
4390
        flag(direct_spatial_mv_pred_flag);
1053
1054

19810
    if (slice_type_p || slice_type_sp || slice_type_b) {
1055
18678
        flag(num_ref_idx_active_override_flag);
1056
18678
        if (current->num_ref_idx_active_override_flag) {
1057
8752
            ue(num_ref_idx_l0_active_minus1, 0, 31);
1058
8752
            if (slice_type_b)
1059
4032
                ue(num_ref_idx_l1_active_minus1, 0, 31);
1060
        } else {
1061
9926
            infer(num_ref_idx_l0_active_minus1,
1062
                  pps->num_ref_idx_l0_default_active_minus1);
1063
9926
            infer(num_ref_idx_l1_active_minus1,
1064
                  pps->num_ref_idx_l1_default_active_minus1);
1065
        }
1066
    }
1067
1068
19810
    if (current->nal_unit_header.nal_unit_type == 20 ||
1069
19810
        current->nal_unit_header.nal_unit_type == 21) {
1070
        av_log(ctx->log_ctx, AV_LOG_ERROR, "MVC / 3DAVC not supported.\n");
1071
        return AVERROR_PATCHWELCOME;
1072
    } else {
1073
19810
        CHECK(FUNC(ref_pic_list_modification)(ctx, rw, current));
1074
    }
1075
1076

19810
    if ((pps->weighted_pred_flag && (slice_type_p || slice_type_sp)) ||
1077

19474
        (pps->weighted_bipred_idc == 1 && slice_type_b)) {
1078
336
        CHECK(FUNC(pred_weight_table)(ctx, rw, current));
1079
    }
1080
1081
19810
    if (current->nal_unit_header.nal_ref_idc != 0) {
1082
15452
        CHECK(FUNC(dec_ref_pic_marking)(ctx, rw, current, idr_pic_flag));
1083
    }
1084
1085

19810
    if (pps->entropy_coding_mode_flag &&
1086
4634
        !slice_type_i && !slice_type_si) {
1087
4634
        ue(cabac_init_idc, 0, 2);
1088
    }
1089
1090
19810
    se(slice_qp_delta, - 51 - 6 * sps->bit_depth_luma_minus8,
1091
                       + 51 + 6 * sps->bit_depth_luma_minus8);
1092

19810
    if (slice_type_sp || slice_type_si) {
1093
156
        if (slice_type_sp)
1094
156
            flag(sp_for_switch_flag);
1095
156
        se(slice_qs_delta, -51, +51);
1096
    }
1097
1098
19810
    if (pps->deblocking_filter_control_present_flag) {
1099
11636
        ue(disable_deblocking_filter_idc, 0, 2);
1100
11636
        if (current->disable_deblocking_filter_idc != 1) {
1101
8232
            se(slice_alpha_c0_offset_div2, -6, +6);
1102
8232
            se(slice_beta_offset_div2,     -6, +6);
1103
        } else {
1104
3404
            infer(slice_alpha_c0_offset_div2, 0);
1105
3404
            infer(slice_beta_offset_div2,     0);
1106
        }
1107
    } else {
1108
8174
        infer(disable_deblocking_filter_idc, 0);
1109
8174
        infer(slice_alpha_c0_offset_div2,    0);
1110
8174
        infer(slice_beta_offset_div2,        0);
1111
    }
1112
1113
19810
    if (pps->num_slice_groups_minus1 > 0 &&
1114
6476
        pps->slice_group_map_type >= 3 &&
1115
2656
        pps->slice_group_map_type <= 5) {
1116
        unsigned int pic_size, max, bits;
1117
1118
1256
        pic_size = (sps->pic_width_in_mbs_minus1 + 1) *
1119
1256
                   (sps->pic_height_in_map_units_minus1 + 1);
1120
1256
        max = (pic_size + pps->slice_group_change_rate_minus1) /
1121
1256
              (pps->slice_group_change_rate_minus1 + 1);
1122
1256
        bits = av_ceil_log2(max + 1);
1123
1124
1256
        u(bits, slice_group_change_cycle, 0, max);
1125
    }
1126
1127
19810
    if (pps->entropy_coding_mode_flag) {
1128
20772
        while (byte_alignment(rw))
1129
15814
            fixed(1, cabac_alignment_one_bit, 1);
1130
    }
1131
1132
19810
    return 0;
1133
}
1134
1135
68
static int FUNC(filler)(CodedBitstreamContext *ctx, RWContext *rw,
1136
                        H264RawFiller *current)
1137
{
1138
    int err;
1139
1140
68
    HEADER("Filler Data");
1141
1142
68
    CHECK(FUNC(nal_unit_header)(ctx, rw, &current->nal_unit_header,
1143
                                1 << H264_NAL_FILLER_DATA));
1144
1145
#ifdef READ
1146
1855340
    while (show_bits(rw, 8) == 0xff) {
1147
1855272
        fixed(8, ff_byte, 0xff);
1148
1855272
        ++current->filler_size;
1149
    }
1150
#else
1151
    {
1152
        uint32_t i;
1153
        for (i = 0; i < current->filler_size; i++)
1154
            fixed(8, ff_byte, 0xff);
1155
    }
1156
#endif
1157
1158
68
    CHECK(FUNC(rbsp_trailing_bits)(ctx, rw));
1159
1160
66
    return 0;
1161
}
1162
1163
4
static int FUNC(end_of_sequence)(CodedBitstreamContext *ctx, RWContext *rw,
1164
                                 H264RawNALUnitHeader *current)
1165
{
1166
4
    HEADER("End of Sequence");
1167
1168
4
    return FUNC(nal_unit_header)(ctx, rw, current,
1169
                                 1 << H264_NAL_END_SEQUENCE);
1170
}
1171
1172
4
static int FUNC(end_of_stream)(CodedBitstreamContext *ctx, RWContext *rw,
1173
                               H264RawNALUnitHeader *current)
1174
{
1175
4
    HEADER("End of Stream");
1176
1177
4
    return FUNC(nal_unit_header)(ctx, rw, current,
1178
                                 1 << H264_NAL_END_STREAM);
1179
}