Coverage Report

Created: 2025-07-18 08:04

/src/vlc/modules/packetizer/h264_slice.c
Line
Count
Source (jump to first uncovered line)
1
/*****************************************************************************
2
 * h264_slice.c: h264 slice parser
3
 *****************************************************************************
4
 * Copyright (C) 2001-17 VLC authors and VideoLAN
5
 *
6
 * This program is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU Lesser General Public License as published by
8
 * the Free Software Foundation; either version 2.1 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this program; if not, write to the Free Software Foundation,
18
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19
 *****************************************************************************/
20
#ifdef HAVE_CONFIG_H
21
# include "config.h"
22
#endif
23
24
#include <vlc_common.h>
25
#include <vlc_bits.h>
26
27
#include "h264_nal.h"
28
#include "h264_slice.h"
29
#include "hxxx_nal.h"
30
#include "hxxx_ep3b.h"
31
32
struct h264_slice_s
33
{
34
    int i_nal_type;
35
    int i_nal_ref_idc;
36
37
    int type;
38
    int i_pic_parameter_set_id;
39
    unsigned i_frame_num;
40
41
    int i_field_pic_flag;
42
    int i_bottom_field_flag;
43
44
    int i_idr_pic_id;
45
46
    int i_pic_order_cnt_type;
47
    int i_pic_order_cnt_lsb;
48
    int i_delta_pic_order_cnt_bottom;
49
50
    int i_delta_pic_order_cnt0;
51
    int i_delta_pic_order_cnt1;
52
53
    bool no_output_of_prior_pics_flag;
54
    bool has_mmco5;
55
};
56
57
enum h264_slice_type_e h264_get_slice_type( const h264_slice_t *p_slice )
58
683k
{
59
683k
    return p_slice->type;
60
683k
}
61
62
bool h264_has_mmco5( const h264_slice_t *p_slice )
63
0
{
64
0
    return p_slice->has_mmco5;
65
0
}
66
67
bool h264_is_field_pic( const h264_slice_t *p_slice )
68
0
{
69
0
    return p_slice->i_field_pic_flag;
70
0
}
71
72
int h264_get_slice_pps_id( const h264_slice_t *p_slice )
73
246k
{
74
246k
    return p_slice->i_pic_parameter_set_id;
75
246k
}
76
77
unsigned h264_get_frame_num( const h264_slice_t *p_slice )
78
204k
{
79
204k
    return p_slice->i_frame_num;
80
204k
}
81
82
unsigned h264_get_nal_ref_idc( const h264_slice_t *p_slice )
83
0
{
84
0
    return p_slice->i_nal_ref_idc;
85
0
}
86
87
void h264_slice_release( h264_slice_t *p_slice )
88
521k
{
89
521k
    free( p_slice );
90
521k
}
91
92
void h264_slice_copy_idr_id( const h264_slice_t *src, h264_slice_t *dst )
93
246k
{
94
246k
    if( !src || src->i_nal_type != H264_NAL_SLICE_IDR ) /* value only set on IDR */
95
221k
        return;
96
24.5k
    dst->i_idr_pic_id = src->i_idr_pic_id;
97
24.5k
}
98
99
h264_slice_t * h264_decode_slice( const uint8_t *p_buffer, size_t i_buffer,
100
                                  void (* get_sps_pps)(uint8_t, void *,
101
                                             const h264_sequence_parameter_set_t **,
102
                                             const h264_picture_parameter_set_t ** ),
103
                                  void *priv )
104
306k
{
105
306k
    h264_slice_t *p_slice = calloc( 1, sizeof(*p_slice) );
106
306k
    if( !p_slice )
107
0
        return NULL;
108
109
306k
    int i_slice_type;
110
306k
    bs_t s;
111
306k
    struct hxxx_bsfw_ep3b_ctx_s bsctx;
112
306k
    hxxx_bsfw_ep3b_ctx_init( &bsctx );
113
306k
    bs_init_custom( &s, p_buffer, i_buffer, &hxxx_bsfw_ep3b_callbacks, &bsctx );
114
115
    /* nal unit header */
116
306k
    bs_skip( &s, 1 );
117
306k
    const uint8_t i_nal_ref_idc = bs_read( &s, 2 );
118
306k
    const uint8_t i_nal_type = bs_read( &s, 5 );
119
120
    /* first_mb_in_slice */
121
    /* int i_first_mb = */ bs_read_ue( &s );
122
123
    /* slice_type */
124
306k
    i_slice_type = bs_read_ue( &s );
125
306k
    if( i_slice_type > 9 )
126
7.11k
        goto error;
127
299k
    p_slice->type = i_slice_type % 5;
128
129
    /* */
130
299k
    p_slice->i_nal_type = i_nal_type;
131
299k
    p_slice->i_nal_ref_idc = i_nal_ref_idc;
132
133
299k
    p_slice->i_pic_parameter_set_id = bs_read_ue( &s );
134
299k
    if( p_slice->i_pic_parameter_set_id > H264_PPS_ID_MAX )
135
982
        goto error;
136
137
298k
    const h264_sequence_parameter_set_t *p_sps;
138
298k
    const h264_picture_parameter_set_t *p_pps;
139
140
    /* Bind matched/referred PPS and SPS */
141
298k
    get_sps_pps( p_slice->i_pic_parameter_set_id, priv, &p_sps, &p_pps );
142
298k
    if( !p_sps || !p_pps )
143
22.4k
        goto error;
144
145
276k
    p_slice->i_frame_num = bs_read( &s, p_sps->i_log2_max_frame_num + 4 );
146
147
276k
    if( !p_sps->frame_mbs_only_flag )
148
91.9k
    {
149
        /* field_pic_flag */
150
91.9k
        p_slice->i_field_pic_flag = bs_read( &s, 1 );
151
91.9k
        if( p_slice->i_field_pic_flag )
152
37.2k
            p_slice->i_bottom_field_flag = bs_read( &s, 1 );
153
91.9k
    }
154
155
276k
    if( p_slice->i_nal_type == H264_NAL_SLICE_IDR )
156
51.2k
    {
157
51.2k
        p_slice->i_idr_pic_id = bs_read_ue( &s );
158
51.2k
        if( p_slice->i_idr_pic_id > 65535 )
159
528
            goto error;
160
51.2k
    }
161
162
275k
    p_slice->i_pic_order_cnt_type = p_sps->i_pic_order_cnt_type;
163
275k
    if( p_sps->i_pic_order_cnt_type == 0 )
164
85.6k
    {
165
85.6k
        p_slice->i_pic_order_cnt_lsb = bs_read( &s, p_sps->i_log2_max_pic_order_cnt_lsb + 4 );
166
85.6k
        if( p_pps->i_pic_order_present_flag && !p_slice->i_field_pic_flag )
167
20.4k
            p_slice->i_delta_pic_order_cnt_bottom = bs_read_se( &s );
168
85.6k
    }
169
190k
    else if( (p_sps->i_pic_order_cnt_type == 1) &&
170
190k
             (!p_sps->i_delta_pic_order_always_zero_flag) )
171
37.9k
    {
172
37.9k
        p_slice->i_delta_pic_order_cnt0 = bs_read_se( &s );
173
37.9k
        if( p_pps->i_pic_order_present_flag && !p_slice->i_field_pic_flag )
174
20.2k
            p_slice->i_delta_pic_order_cnt1 = bs_read_se( &s );
175
37.9k
    }
176
177
275k
    if( p_pps->i_redundant_pic_present_flag )
178
43.0k
        bs_read_ue( &s ); /* redudant_pic_count */
179
180
275k
    uint32_t num_ref_idx_l01_active_minus1[2] = { p_pps->num_ref_idx_l01_default_active_minus1[0],
181
275k
                                                  p_pps->num_ref_idx_l01_default_active_minus1[1] };
182
183
275k
    if( i_slice_type == 1 || i_slice_type == 6 ) /* B slices */
184
36.6k
        bs_skip( &s, 1 ); /* direct_spatial_mv_pred_flag */
185
275k
    if( i_slice_type == 0 || i_slice_type == 5 ||
186
275k
        i_slice_type == 3 || i_slice_type == 8 ||
187
275k
        i_slice_type == 1 || i_slice_type == 6 ) /* P SP B slices */
188
235k
    {
189
235k
        if( bs_read1( &s ) ) /* num_ref_idx_active_override_flag */
190
56.2k
        {
191
56.2k
            num_ref_idx_l01_active_minus1[0] = bs_read_ue( &s );
192
56.2k
            if( i_slice_type == 1 || i_slice_type == 6 ) /* B slices */
193
14.7k
                num_ref_idx_l01_active_minus1[1] = bs_read_ue( &s );
194
56.2k
        }
195
235k
    }
196
197
    /* BELOW, Further processing up to assert MMCO 5 presence for POC */
198
275k
    if( p_slice->i_nal_type == 5 || p_slice->i_nal_ref_idc == 0 )
199
206k
    {
200
        /* Early END, don't waste parsing below */
201
206k
        p_slice->has_mmco5 = false;
202
206k
        return p_slice;
203
206k
    }
204
205
    /* ref_pic_list_[mvc_]modification() */
206
69.2k
    const bool b_mvc = (p_slice->i_nal_type == 20 || p_slice->i_nal_type == 21 );
207
69.2k
    unsigned i = 0;
208
69.2k
    if( i_slice_type % 5 != 2 && i_slice_type % 5 != 4 )
209
60.0k
        i++;
210
69.2k
    if( i_slice_type % 5 == 1 )
211
4.34k
        i++;
212
213
133k
    for( ; i>0; i-- )
214
64.3k
    {
215
64.3k
        if( bs_read1( &s ) ) /* ref_pic_list_modification_flag_l{0,1} */
216
18.8k
        {
217
18.8k
            uint32_t mod;
218
18.8k
            do
219
609k
            {
220
609k
                mod = bs_read_ue( &s );
221
609k
                if( mod < 3 || ( b_mvc && (mod == 4 || mod == 5) ) )
222
490k
                    bs_read_ue( &s ); /* abs_diff_pic_num_minus1, long_term_pic_num, abs_diff_view_idx_min1 */
223
609k
            }
224
609k
            while( mod != 3 && !bs_eof( &s ) );
225
18.8k
        }
226
64.3k
    }
227
228
69.2k
    if( bs_error( &s ) )
229
17.0k
        goto error;
230
231
    /* pred_weight_table() */
232
52.1k
    if( ( p_pps->weighted_pred_flag && ( i_slice_type == 0 || i_slice_type == 5 || /* P, SP */
233
31.7k
                                         i_slice_type == 3 || i_slice_type == 8 ) ) ||
234
52.1k
        ( p_pps->weighted_bipred_idc == 1 && ( i_slice_type == 1 || i_slice_type == 6 ) /* B */ ) )
235
24.6k
    {
236
24.6k
        bs_read_ue( &s ); /* luma_log2_weight_denom */
237
24.6k
        if( !p_sps->b_separate_colour_planes_flag ) /* ChromaArrayType != 0 */
238
23.6k
            bs_read_ue( &s ); /* chroma_log2_weight_denom */
239
240
24.6k
        const unsigned i_num_layers = ( i_slice_type % 5 == 1 ) ? 2 : 1;
241
50.2k
        for( unsigned j=0; j < i_num_layers; j++ )
242
25.6k
        {
243
104M
            for( unsigned k=0; k<=num_ref_idx_l01_active_minus1[j]; k++ )
244
104M
            {
245
104M
                if( bs_read1( &s ) ) /* luma_weight_l{0,1}_flag */
246
45.4k
                {
247
45.4k
                    bs_read_se( &s );
248
45.4k
                    bs_read_se( &s );
249
45.4k
                }
250
104M
                if( !p_sps->b_separate_colour_planes_flag ) /* ChromaArrayType != 0 */
251
95.8M
                {
252
95.8M
                    if( bs_read1( &s ) ) /* chroma_weight_l{0,1}_flag */
253
39.2k
                    {
254
39.2k
                        bs_read_se( &s );
255
39.2k
                        bs_read_se( &s );
256
39.2k
                        bs_read_se( &s );
257
39.2k
                        bs_read_se( &s );
258
39.2k
                    }
259
95.8M
                }
260
104M
            }
261
25.6k
        }
262
24.6k
    }
263
264
    /* dec_ref_pic_marking() */
265
52.1k
    if( p_slice->i_nal_type == 5 ) /* IdrFlag */
266
0
    {
267
0
        p_slice->no_output_of_prior_pics_flag = bs_read1( &s );
268
0
        bs_skip( &s, 1 ); /* long_term_reference_flag */
269
0
    }
270
52.1k
    else
271
52.1k
    {
272
52.1k
        if( bs_read1( &s ) ) /* adaptive_ref_pic_marking_mode_flag */
273
21.8k
        {
274
21.8k
            uint32_t mmco;
275
21.8k
            do
276
37.1k
            {
277
37.1k
                mmco = bs_read_ue( &s );
278
37.1k
                if( mmco > 6 )
279
2.33k
                    goto error;
280
34.8k
                if( mmco == 1 || mmco == 3 )
281
9.71k
                    bs_read_ue( &s ); /* diff_pics_minus1 */
282
34.8k
                if( mmco == 2 )
283
3.07k
                    bs_read_ue( &s ); /* long_term_pic_num */
284
34.8k
                if( mmco == 3 || mmco == 6 )
285
2.92k
                    bs_read_ue( &s ); /* long_term_frame_idx */
286
34.8k
                if( mmco == 4 )
287
946
                    bs_read_ue( &s ); /* max_long_term_frame_idx_plus1 */
288
34.8k
                if( mmco == 5 )
289
1.32k
                {
290
1.32k
                    p_slice->has_mmco5 = true;
291
1.32k
                    break; /* Early END */
292
1.32k
                }
293
34.8k
            }
294
33.5k
            while( mmco > 0 );
295
21.8k
        }
296
52.1k
    }
297
298
    /* If you need to store anything else than MMCO presence above, care of "Early END" cases */
299
300
49.8k
    if(bs_error( &s ))
301
10.2k
        goto error;
302
39.5k
    return p_slice;
303
304
60.6k
error:
305
60.6k
    h264_slice_release( p_slice );
306
60.6k
    return NULL;
307
49.8k
}
308
309
310
void h264_compute_poc( const h264_sequence_parameter_set_t *p_sps,
311
                       const h264_slice_t *p_slice, h264_poc_context_t *p_ctx,
312
                       int *p_PictureOrderCount, int *p_tFOC, int *p_bFOC )
313
204k
{
314
204k
    *p_tFOC = *p_bFOC = 0;
315
316
204k
    if( p_sps->i_pic_order_cnt_type == 0 )
317
52.6k
    {
318
52.6k
        unsigned maxPocLSB = 1U << (p_sps->i_log2_max_pic_order_cnt_lsb  + 4);
319
320
        /* POC reference */
321
52.6k
        if( p_slice->i_nal_type == H264_NAL_SLICE_IDR )
322
9.33k
        {
323
9.33k
            p_ctx->prevPicOrderCnt.lsb = 0;
324
9.33k
            p_ctx->prevPicOrderCnt.msb = 0;
325
9.33k
        }
326
43.3k
        else if( p_ctx->prevRefPictureHasMMCO5 )
327
689
        {
328
689
            p_ctx->prevPicOrderCnt.msb = 0;
329
689
            if( !p_ctx->prevRefPictureIsBottomField )
330
443
                p_ctx->prevPicOrderCnt.lsb = p_ctx->prevRefPictureTFOC;
331
246
            else
332
246
                p_ctx->prevPicOrderCnt.lsb = 0;
333
689
        }
334
335
        /* 8.2.1.1 */
336
52.6k
        int pocMSB = p_ctx->prevPicOrderCnt.msb;
337
52.6k
        int64_t orderDiff = p_slice->i_pic_order_cnt_lsb - p_ctx->prevPicOrderCnt.lsb;
338
52.6k
        if( orderDiff < 0 && -orderDiff >= maxPocLSB / 2 )
339
2.79k
            pocMSB += maxPocLSB;
340
49.8k
        else if( orderDiff > maxPocLSB / 2 )
341
8.94k
            pocMSB -= maxPocLSB;
342
343
52.6k
        *p_tFOC = *p_bFOC = pocMSB + p_slice->i_pic_order_cnt_lsb;
344
52.6k
        if( p_slice->i_field_pic_flag )
345
19.3k
            *p_bFOC += p_slice->i_delta_pic_order_cnt_bottom;
346
347
        /* Save from ref picture */
348
52.6k
        if( p_slice->i_nal_ref_idc /* Is reference */ )
349
25.7k
        {
350
25.7k
            p_ctx->prevRefPictureIsBottomField = (p_slice->i_field_pic_flag &&
351
25.7k
                                                  p_slice->i_bottom_field_flag);
352
25.7k
            p_ctx->prevRefPictureHasMMCO5 = p_slice->has_mmco5;
353
25.7k
            p_ctx->prevRefPictureTFOC = *p_tFOC;
354
25.7k
            p_ctx->prevPicOrderCnt.lsb = p_slice->i_pic_order_cnt_lsb;
355
25.7k
            p_ctx->prevPicOrderCnt.msb = pocMSB;
356
25.7k
        }
357
52.6k
    }
358
151k
    else
359
151k
    {
360
151k
        unsigned maxFrameNum = 1 << (p_sps->i_log2_max_frame_num + 4);
361
151k
        unsigned frameNumOffset;
362
151k
        unsigned expectedPicOrderCnt = 0;
363
364
151k
        if( p_slice->i_nal_type == H264_NAL_SLICE_IDR )
365
28.7k
            frameNumOffset = 0;
366
122k
        else if( p_ctx->prevFrameNum > p_slice->i_frame_num )
367
56.2k
            frameNumOffset = p_ctx->prevFrameNumOffset + maxFrameNum;
368
66.6k
        else
369
66.6k
            frameNumOffset = p_ctx->prevFrameNumOffset;
370
371
151k
        if( p_sps->i_pic_order_cnt_type == 1 )
372
134k
        {
373
134k
            unsigned absFrameNum;
374
375
134k
            if( p_sps->i_num_ref_frames_in_pic_order_cnt_cycle > 0 )
376
123k
                absFrameNum = frameNumOffset + p_slice->i_frame_num;
377
11.7k
            else
378
11.7k
                absFrameNum = 0;
379
380
134k
            if( p_slice->i_nal_ref_idc == 0 && absFrameNum > 0 )
381
105k
                absFrameNum--;
382
383
134k
            if( absFrameNum > 0 )
384
122k
            {
385
122k
                int32_t expectedDeltaPerPicOrderCntCycle = 0;
386
415k
                for( int i=0; i<p_sps->i_num_ref_frames_in_pic_order_cnt_cycle; i++ )
387
292k
                    expectedDeltaPerPicOrderCntCycle += p_sps->offset_for_ref_frame[i];
388
389
122k
                unsigned picOrderCntCycleCnt = 0;
390
122k
                unsigned frameNumInPicOrderCntCycle = 0;
391
122k
                if( p_sps->i_num_ref_frames_in_pic_order_cnt_cycle )
392
122k
                {
393
122k
                    picOrderCntCycleCnt = ( absFrameNum - 1 ) / p_sps->i_num_ref_frames_in_pic_order_cnt_cycle;
394
122k
                    frameNumInPicOrderCntCycle = ( absFrameNum - 1 ) % p_sps->i_num_ref_frames_in_pic_order_cnt_cycle;
395
122k
                }
396
397
122k
                expectedPicOrderCnt = picOrderCntCycleCnt * expectedDeltaPerPicOrderCntCycle;
398
281k
                for( unsigned i=0; i <= frameNumInPicOrderCntCycle; i++ )
399
158k
                    expectedPicOrderCnt = expectedPicOrderCnt + p_sps->offset_for_ref_frame[i];
400
122k
            }
401
402
134k
            if( p_slice->i_nal_ref_idc == 0 )
403
110k
                expectedPicOrderCnt = expectedPicOrderCnt + p_sps->offset_for_non_ref_pic;
404
405
134k
            *p_tFOC = expectedPicOrderCnt + p_slice->i_delta_pic_order_cnt0;
406
134k
            if( !p_slice->i_field_pic_flag )
407
130k
                *p_bFOC = *p_tFOC + p_sps->offset_for_top_to_bottom_field + p_slice->i_delta_pic_order_cnt1;
408
4.79k
            else if( p_slice->i_bottom_field_flag )
409
2.04k
                *p_bFOC = expectedPicOrderCnt + p_sps->offset_for_top_to_bottom_field + p_slice->i_delta_pic_order_cnt0;
410
134k
        }
411
16.6k
        else if( p_sps->i_pic_order_cnt_type == 2 )
412
9.44k
        {
413
9.44k
            unsigned tempPicOrderCnt;
414
415
9.44k
            if( p_slice->i_nal_type == H264_NAL_SLICE_IDR )
416
5.00k
                tempPicOrderCnt = 0;
417
4.44k
            else if( p_slice->i_nal_ref_idc == 0 )
418
1.83k
                tempPicOrderCnt = 2 * ( frameNumOffset + p_slice->i_frame_num ) - 1;
419
2.60k
            else
420
2.60k
                tempPicOrderCnt = 2 * ( frameNumOffset + p_slice->i_frame_num );
421
422
9.44k
            *p_bFOC = *p_tFOC = tempPicOrderCnt;
423
9.44k
        }
424
425
151k
        p_ctx->prevFrameNum = p_slice->i_frame_num;
426
151k
        if( p_slice->has_mmco5 )
427
376
            p_ctx->prevFrameNumOffset = 0;
428
151k
        else
429
151k
            p_ctx->prevFrameNumOffset = frameNumOffset;
430
151k
    }
431
432
    /* 8.2.1 (8-1) */
433
204k
    if( !p_slice->i_field_pic_flag ) /* progressive or contains both fields */
434
178k
        *p_PictureOrderCount = __MIN( *p_bFOC, *p_tFOC );
435
25.9k
    else /* split top or bottom field */
436
25.9k
    if ( p_slice->i_bottom_field_flag )
437
4.73k
        *p_PictureOrderCount = *p_bFOC;
438
21.2k
    else
439
21.2k
        *p_PictureOrderCount = *p_tFOC;
440
204k
}
441
442
static uint8_t h264_infer_pic_struct( const h264_sequence_parameter_set_t *p_sps,
443
                                      const h264_slice_t *p_slice,
444
                                      uint8_t i_pic_struct, int tFOC, int bFOC )
445
204k
{
446
    /* See D-1 and note 6 */
447
204k
    if( !p_sps->vui.b_pic_struct_present_flag || i_pic_struct >= 9 )
448
200k
    {
449
200k
        if( p_slice->i_field_pic_flag )
450
24.6k
            i_pic_struct = 1 + p_slice->i_bottom_field_flag;
451
175k
        else if( tFOC == bFOC )
452
165k
            i_pic_struct = 0;
453
9.83k
        else if( tFOC < bFOC )
454
3.58k
            i_pic_struct = 3;
455
6.25k
        else
456
6.25k
            i_pic_struct = 4;
457
200k
    }
458
459
204k
    return i_pic_struct;
460
204k
}
461
462
uint8_t h264_get_num_ts( const h264_sequence_parameter_set_t *p_sps,
463
                         const h264_slice_t *p_slice, uint8_t i_pic_struct,
464
                         int tFOC, int bFOC )
465
204k
{
466
204k
    i_pic_struct = h264_infer_pic_struct( p_sps, p_slice, i_pic_struct, tFOC, bFOC );
467
    /* !WARN modified with nuit field based multiplier for values 0, 7 and 8 */
468
204k
    const uint8_t rgi_numclock[9] = { 2, 1, 1, 2, 2, 3, 3, 4, 6 };
469
204k
    return rgi_numclock[ i_pic_struct ];
470
204k
}
471
472
bool h264_slice_top_field( const h264_slice_t *p_slice )
473
758
{
474
758
    return !p_slice->i_bottom_field_flag;
475
758
}
476
477
bool h264_IsFirstVCLNALUnit( const h264_slice_t *p_prev, const h264_slice_t *p_cur )
478
246k
{
479
    /* Detection of the first VCL NAL unit of a primary coded picture
480
     * (cf. 7.4.1.2.4) */
481
246k
    if( !p_prev )
482
56.2k
        return true;
483
190k
    if( p_cur->i_frame_num != p_prev->i_frame_num ||
484
190k
        p_cur->i_pic_parameter_set_id != p_prev->i_pic_parameter_set_id ||
485
190k
        p_cur->i_field_pic_flag != p_prev->i_field_pic_flag ||
486
190k
        !p_cur->i_nal_ref_idc != !p_prev->i_nal_ref_idc )
487
149k
        return true;
488
40.0k
    if( p_cur->i_field_pic_flag && /* present in both and differs in value */
489
40.0k
        p_cur->i_bottom_field_flag != p_prev->i_bottom_field_flag )
490
546
        return true;
491
39.5k
    if( p_cur->i_pic_order_cnt_type == p_prev->i_pic_order_cnt_type )
492
39.5k
    {
493
39.5k
        if( p_cur->i_pic_order_cnt_type == 0 &&
494
39.5k
            ( p_cur->i_pic_order_cnt_lsb != p_prev->i_pic_order_cnt_lsb ||
495
20.9k
             p_cur->i_delta_pic_order_cnt_bottom != p_prev->i_delta_pic_order_cnt_bottom ) )
496
4.74k
            return true;
497
34.7k
        else if( p_cur->i_pic_order_cnt_type == 1 &&
498
34.7k
                 ( p_cur->i_delta_pic_order_cnt0 != p_prev->i_delta_pic_order_cnt0 ||
499
7.52k
                  p_cur->i_delta_pic_order_cnt1 != p_prev->i_delta_pic_order_cnt1 ) )
500
1.66k
            return true;
501
39.5k
    }
502
33.1k
    if( ( p_cur->i_nal_type == H264_NAL_SLICE_IDR || p_prev->i_nal_type == H264_NAL_SLICE_IDR ) &&
503
33.1k
        ( p_cur->i_nal_type != p_prev->i_nal_type || p_cur->i_idr_pic_id != p_prev->i_idr_pic_id ) )
504
1.71k
        return true;
505
31.4k
    return false;
506
33.1k
}
507
508
bool h264_CanSwapPTSWithDTS( const h264_slice_t *p_slice, const h264_sequence_parameter_set_t *p_sps )
509
66.4k
{
510
66.4k
    if( p_slice->i_nal_ref_idc == 0 && p_slice->type == H264_SLICE_TYPE_B )
511
1.03k
        return true;
512
65.4k
    else if( p_sps->vui_parameters_present_flag )
513
25.2k
        return p_sps->vui.i_max_num_reorder_frames == 0;
514
40.2k
    else
515
40.2k
        return p_sps->i_profile == PROFILE_H264_CAVLC_INTRA;
516
66.4k
}