FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/h264_slice.c
Date: 2023-09-22 12:20:07
Exec Total Coverage
Lines: 1381 1682 82.1%
Functions: 32 33 97.0%
Branches: 919 1261 72.9%

Line Branch Exec Source
1 /*
2 * H.26L/H.264/AVC/JVT/14496-10/... decoder
3 * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * H.264 / AVC / MPEG-4 part10 codec.
25 * @author Michael Niedermayer <michaelni@gmx.at>
26 */
27
28 #include "config_components.h"
29
30 #include "libavutil/avassert.h"
31 #include "libavutil/pixdesc.h"
32 #include "libavutil/timecode.h"
33 #include "decode.h"
34 #include "cabac.h"
35 #include "cabac_functions.h"
36 #include "error_resilience.h"
37 #include "avcodec.h"
38 #include "h264.h"
39 #include "h264dec.h"
40 #include "h264data.h"
41 #include "h264chroma.h"
42 #include "h264_ps.h"
43 #include "golomb.h"
44 #include "mathops.h"
45 #include "mpegutils.h"
46 #include "rectangle.h"
47 #include "thread.h"
48 #include "threadframe.h"
49
50 static const uint8_t field_scan[16+1] = {
51 0 + 0 * 4, 0 + 1 * 4, 1 + 0 * 4, 0 + 2 * 4,
52 0 + 3 * 4, 1 + 1 * 4, 1 + 2 * 4, 1 + 3 * 4,
53 2 + 0 * 4, 2 + 1 * 4, 2 + 2 * 4, 2 + 3 * 4,
54 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4,
55 };
56
57 static const uint8_t field_scan8x8[64+1] = {
58 0 + 0 * 8, 0 + 1 * 8, 0 + 2 * 8, 1 + 0 * 8,
59 1 + 1 * 8, 0 + 3 * 8, 0 + 4 * 8, 1 + 2 * 8,
60 2 + 0 * 8, 1 + 3 * 8, 0 + 5 * 8, 0 + 6 * 8,
61 0 + 7 * 8, 1 + 4 * 8, 2 + 1 * 8, 3 + 0 * 8,
62 2 + 2 * 8, 1 + 5 * 8, 1 + 6 * 8, 1 + 7 * 8,
63 2 + 3 * 8, 3 + 1 * 8, 4 + 0 * 8, 3 + 2 * 8,
64 2 + 4 * 8, 2 + 5 * 8, 2 + 6 * 8, 2 + 7 * 8,
65 3 + 3 * 8, 4 + 1 * 8, 5 + 0 * 8, 4 + 2 * 8,
66 3 + 4 * 8, 3 + 5 * 8, 3 + 6 * 8, 3 + 7 * 8,
67 4 + 3 * 8, 5 + 1 * 8, 6 + 0 * 8, 5 + 2 * 8,
68 4 + 4 * 8, 4 + 5 * 8, 4 + 6 * 8, 4 + 7 * 8,
69 5 + 3 * 8, 6 + 1 * 8, 6 + 2 * 8, 5 + 4 * 8,
70 5 + 5 * 8, 5 + 6 * 8, 5 + 7 * 8, 6 + 3 * 8,
71 7 + 0 * 8, 7 + 1 * 8, 6 + 4 * 8, 6 + 5 * 8,
72 6 + 6 * 8, 6 + 7 * 8, 7 + 2 * 8, 7 + 3 * 8,
73 7 + 4 * 8, 7 + 5 * 8, 7 + 6 * 8, 7 + 7 * 8,
74 };
75
76 static const uint8_t field_scan8x8_cavlc[64+1] = {
77 0 + 0 * 8, 1 + 1 * 8, 2 + 0 * 8, 0 + 7 * 8,
78 2 + 2 * 8, 2 + 3 * 8, 2 + 4 * 8, 3 + 3 * 8,
79 3 + 4 * 8, 4 + 3 * 8, 4 + 4 * 8, 5 + 3 * 8,
80 5 + 5 * 8, 7 + 0 * 8, 6 + 6 * 8, 7 + 4 * 8,
81 0 + 1 * 8, 0 + 3 * 8, 1 + 3 * 8, 1 + 4 * 8,
82 1 + 5 * 8, 3 + 1 * 8, 2 + 5 * 8, 4 + 1 * 8,
83 3 + 5 * 8, 5 + 1 * 8, 4 + 5 * 8, 6 + 1 * 8,
84 5 + 6 * 8, 7 + 1 * 8, 6 + 7 * 8, 7 + 5 * 8,
85 0 + 2 * 8, 0 + 4 * 8, 0 + 5 * 8, 2 + 1 * 8,
86 1 + 6 * 8, 4 + 0 * 8, 2 + 6 * 8, 5 + 0 * 8,
87 3 + 6 * 8, 6 + 0 * 8, 4 + 6 * 8, 6 + 2 * 8,
88 5 + 7 * 8, 6 + 4 * 8, 7 + 2 * 8, 7 + 6 * 8,
89 1 + 0 * 8, 1 + 2 * 8, 0 + 6 * 8, 3 + 0 * 8,
90 1 + 7 * 8, 3 + 2 * 8, 2 + 7 * 8, 4 + 2 * 8,
91 3 + 7 * 8, 5 + 2 * 8, 4 + 7 * 8, 5 + 4 * 8,
92 6 + 3 * 8, 6 + 5 * 8, 7 + 3 * 8, 7 + 7 * 8,
93 };
94
95 // zigzag_scan8x8_cavlc[i] = zigzag_scan8x8[(i/4) + 16*(i%4)]
96 static const uint8_t zigzag_scan8x8_cavlc[64+1] = {
97 0 + 0 * 8, 1 + 1 * 8, 1 + 2 * 8, 2 + 2 * 8,
98 4 + 1 * 8, 0 + 5 * 8, 3 + 3 * 8, 7 + 0 * 8,
99 3 + 4 * 8, 1 + 7 * 8, 5 + 3 * 8, 6 + 3 * 8,
100 2 + 7 * 8, 6 + 4 * 8, 5 + 6 * 8, 7 + 5 * 8,
101 1 + 0 * 8, 2 + 0 * 8, 0 + 3 * 8, 3 + 1 * 8,
102 3 + 2 * 8, 0 + 6 * 8, 4 + 2 * 8, 6 + 1 * 8,
103 2 + 5 * 8, 2 + 6 * 8, 6 + 2 * 8, 5 + 4 * 8,
104 3 + 7 * 8, 7 + 3 * 8, 4 + 7 * 8, 7 + 6 * 8,
105 0 + 1 * 8, 3 + 0 * 8, 0 + 4 * 8, 4 + 0 * 8,
106 2 + 3 * 8, 1 + 5 * 8, 5 + 1 * 8, 5 + 2 * 8,
107 1 + 6 * 8, 3 + 5 * 8, 7 + 1 * 8, 4 + 5 * 8,
108 4 + 6 * 8, 7 + 4 * 8, 5 + 7 * 8, 6 + 7 * 8,
109 0 + 2 * 8, 2 + 1 * 8, 1 + 3 * 8, 5 + 0 * 8,
110 1 + 4 * 8, 2 + 4 * 8, 6 + 0 * 8, 4 + 3 * 8,
111 0 + 7 * 8, 4 + 4 * 8, 7 + 2 * 8, 3 + 6 * 8,
112 5 + 5 * 8, 6 + 5 * 8, 6 + 6 * 8, 7 + 7 * 8,
113 };
114
115 27593 static void release_unused_pictures(H264Context *h, int remove_current)
116 {
117 int i;
118
119 /* release non reference frames */
120
2/2
✓ Branch 0 taken 993348 times.
✓ Branch 1 taken 27593 times.
1020941 for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) {
121
6/6
✓ Branch 0 taken 141845 times.
✓ Branch 1 taken 851503 times.
✓ Branch 2 taken 23997 times.
✓ Branch 3 taken 117848 times.
✓ Branch 4 taken 2609 times.
✓ Branch 5 taken 21388 times.
993348 if (h->DPB[i].f->buf[0] && !h->DPB[i].reference &&
122
2/2
✓ Branch 0 taken 723 times.
✓ Branch 1 taken 1886 times.
2609 (remove_current || &h->DPB[i] != h->cur_pic_ptr)) {
123 22111 ff_h264_unref_picture(h, &h->DPB[i]);
124 }
125 }
126 27593 }
127
128 35993 static int alloc_scratch_buffers(H264SliceContext *sl, int linesize)
129 {
130 35993 const H264Context *h = sl->h264;
131 35993 int alloc_size = FFALIGN(FFABS(linesize) + 32, 32);
132
133 35993 av_fast_malloc(&sl->bipred_scratchpad, &sl->bipred_scratchpad_allocated, 16 * 6 * alloc_size);
134 // edge emu needs blocksize + filter length - 1
135 // (= 21x21 for H.264)
136 35993 av_fast_malloc(&sl->edge_emu_buffer, &sl->edge_emu_buffer_allocated, alloc_size * 2 * 21);
137
138 35993 av_fast_mallocz(&sl->top_borders[0], &sl->top_borders_allocated[0],
139 35993 h->mb_width * 16 * 3 * sizeof(uint8_t) * 2);
140 35993 av_fast_mallocz(&sl->top_borders[1], &sl->top_borders_allocated[1],
141 35993 h->mb_width * 16 * 3 * sizeof(uint8_t) * 2);
142
143
2/4
✓ Branch 0 taken 35993 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 35993 times.
✗ Branch 3 not taken.
35993 if (!sl->bipred_scratchpad || !sl->edge_emu_buffer ||
144
2/4
✓ Branch 0 taken 35993 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 35993 times.
35993 !sl->top_borders[0] || !sl->top_borders[1]) {
145 av_freep(&sl->bipred_scratchpad);
146 av_freep(&sl->edge_emu_buffer);
147 av_freep(&sl->top_borders[0]);
148 av_freep(&sl->top_borders[1]);
149
150 sl->bipred_scratchpad_allocated = 0;
151 sl->edge_emu_buffer_allocated = 0;
152 sl->top_borders_allocated[0] = 0;
153 sl->top_borders_allocated[1] = 0;
154 return AVERROR(ENOMEM);
155 }
156
157 35993 return 0;
158 }
159
160 586 static int init_table_pools(H264Context *h)
161 {
162 586 const int big_mb_num = h->mb_stride * (h->mb_height + 1) + 1;
163 586 const int mb_array_size = h->mb_stride * h->mb_height;
164 586 const int b4_stride = h->mb_width * 4 + 1;
165 586 const int b4_array_size = b4_stride * h->mb_height * 4;
166
167 586 h->qscale_table_pool = av_buffer_pool_init(big_mb_num + h->mb_stride,
168 av_buffer_allocz);
169 586 h->mb_type_pool = av_buffer_pool_init((big_mb_num + h->mb_stride) *
170 sizeof(uint32_t), av_buffer_allocz);
171 586 h->motion_val_pool = av_buffer_pool_init(2 * (b4_array_size + 4) *
172 sizeof(int16_t), av_buffer_allocz);
173 586 h->ref_index_pool = av_buffer_pool_init(4 * mb_array_size, av_buffer_allocz);
174
175
3/6
✓ Branch 0 taken 586 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 586 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 586 times.
✗ Branch 5 not taken.
586 if (!h->qscale_table_pool || !h->mb_type_pool || !h->motion_val_pool ||
176
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
586 !h->ref_index_pool) {
177 av_buffer_pool_uninit(&h->qscale_table_pool);
178 av_buffer_pool_uninit(&h->mb_type_pool);
179 av_buffer_pool_uninit(&h->motion_val_pool);
180 av_buffer_pool_uninit(&h->ref_index_pool);
181 return AVERROR(ENOMEM);
182 }
183
184 586 return 0;
185 }
186
187 24232 static int alloc_picture(H264Context *h, H264Picture *pic)
188 {
189 24232 int i, ret = 0;
190
191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24232 times.
24232 av_assert0(!pic->f->data[0]);
192
193 24232 pic->tf.f = pic->f;
194 24232 ret = ff_thread_get_ext_buffer(h->avctx, &pic->tf,
195 24232 pic->reference ? AV_GET_BUFFER_FLAG_REF : 0);
196
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24232 times.
24232 if (ret < 0)
197 goto fail;
198
199
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24232 times.
24232 if (pic->needs_fg) {
200 pic->f_grain->format = pic->f->format;
201 pic->f_grain->width = pic->f->width;
202 pic->f_grain->height = pic->f->height;
203 ret = ff_thread_get_buffer(h->avctx, pic->f_grain, 0);
204 if (ret < 0)
205 goto fail;
206 }
207
208 24232 ret = ff_hwaccel_frame_priv_alloc(h->avctx, &pic->hwaccel_picture_private,
209 &pic->hwaccel_priv_buf);
210
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24232 times.
24232 if (ret < 0)
211 goto fail;
212
213
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 24190 times.
24232 if (h->decode_error_flags_pool) {
214 42 pic->decode_error_flags = av_buffer_pool_get(h->decode_error_flags_pool);
215
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
42 if (!pic->decode_error_flags)
216 goto fail;
217 42 atomic_init((atomic_int*)pic->decode_error_flags->data, 0);
218 }
219
220 if (CONFIG_GRAY && !h->avctx->hwaccel && h->flags & AV_CODEC_FLAG_GRAY && pic->f->data[2]) {
221 int h_chroma_shift, v_chroma_shift;
222 av_pix_fmt_get_chroma_sub_sample(pic->f->format,
223 &h_chroma_shift, &v_chroma_shift);
224
225 for(i=0; i<AV_CEIL_RSHIFT(pic->f->height, v_chroma_shift); i++) {
226 memset(pic->f->data[1] + pic->f->linesize[1]*i,
227 0x80, AV_CEIL_RSHIFT(pic->f->width, h_chroma_shift));
228 memset(pic->f->data[2] + pic->f->linesize[2]*i,
229 0x80, AV_CEIL_RSHIFT(pic->f->width, h_chroma_shift));
230 }
231 }
232
233
2/2
✓ Branch 0 taken 586 times.
✓ Branch 1 taken 23646 times.
24232 if (!h->qscale_table_pool) {
234 586 ret = init_table_pools(h);
235
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
586 if (ret < 0)
236 goto fail;
237 }
238
239 24232 pic->qscale_table_buf = av_buffer_pool_get(h->qscale_table_pool);
240 24232 pic->mb_type_buf = av_buffer_pool_get(h->mb_type_pool);
241
2/4
✓ Branch 0 taken 24232 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 24232 times.
24232 if (!pic->qscale_table_buf || !pic->mb_type_buf)
242 goto fail;
243
244 24232 pic->mb_type = (uint32_t*)pic->mb_type_buf->data + 2 * h->mb_stride + 1;
245 24232 pic->qscale_table = pic->qscale_table_buf->data + 2 * h->mb_stride + 1;
246
247
2/2
✓ Branch 0 taken 48464 times.
✓ Branch 1 taken 24232 times.
72696 for (i = 0; i < 2; i++) {
248 48464 pic->motion_val_buf[i] = av_buffer_pool_get(h->motion_val_pool);
249 48464 pic->ref_index_buf[i] = av_buffer_pool_get(h->ref_index_pool);
250
2/4
✓ Branch 0 taken 48464 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48464 times.
48464 if (!pic->motion_val_buf[i] || !pic->ref_index_buf[i])
251 goto fail;
252
253 48464 pic->motion_val[i] = (int16_t (*)[2])pic->motion_val_buf[i]->data + 4;
254 48464 pic->ref_index[i] = pic->ref_index_buf[i]->data;
255 }
256
257 24232 pic->pps_buf = av_buffer_ref(h->ps.pps_ref);
258
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24232 times.
24232 if (!pic->pps_buf)
259 goto fail;
260 24232 pic->pps = (const PPS*)pic->pps_buf->data;
261
262 24232 pic->mb_width = h->mb_width;
263 24232 pic->mb_height = h->mb_height;
264 24232 pic->mb_stride = h->mb_stride;
265
266 24232 return 0;
267 fail:
268 ff_h264_unref_picture(h, pic);
269 return (ret < 0) ? ret : AVERROR(ENOMEM);
270 }
271
272 24232 static int find_unused_picture(H264Context *h)
273 {
274 int i;
275
276
1/2
✓ Branch 0 taken 84210 times.
✗ Branch 1 not taken.
84210 for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) {
277
2/2
✓ Branch 0 taken 24232 times.
✓ Branch 1 taken 59978 times.
84210 if (!h->DPB[i].f->buf[0])
278 24232 return i;
279 }
280 return AVERROR_INVALIDDATA;
281 }
282
283
284 #define IN_RANGE(a, b, size) (((void*)(a) >= (void*)(b)) && ((void*)(a) < (void*)((b) + (size))))
285
286 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
287 (((pic) && (pic) >= (old_ctx)->DPB && \
288 (pic) < (old_ctx)->DPB + H264_MAX_PICTURE_COUNT) ? \
289 &(new_ctx)->DPB[(pic) - (old_ctx)->DPB] : NULL)
290
291 186 static void copy_picture_range(H264Picture **to, H264Picture **from, int count,
292 H264Context *new_base,
293 H264Context *old_base)
294 {
295 int i;
296
297
2/2
✓ Branch 0 taken 5084 times.
✓ Branch 1 taken 186 times.
5270 for (i = 0; i < count; i++) {
298 av_assert1(!from[i] ||
299 IN_RANGE(from[i], old_base, 1) ||
300 IN_RANGE(from[i], old_base->DPB, H264_MAX_PICTURE_COUNT));
301
4/6
✓ Branch 0 taken 265 times.
✓ Branch 1 taken 4819 times.
✓ Branch 2 taken 265 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 265 times.
✗ Branch 5 not taken.
5084 to[i] = REBASE_PICTURE(from[i], new_base, old_base);
302 }
303 186 }
304
305 18 static void color_frame(AVFrame *frame, const int c[4])
306 {
307 18 const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
308
309
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
18 av_assert0(desc->flags & AV_PIX_FMT_FLAG_PLANAR);
310
311
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 18 times.
72 for (int p = 0; p < desc->nb_components; p++) {
312 54 uint8_t *dst = frame->data[p];
313
4/4
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
✓ Branch 2 taken 18 times.
✓ Branch 3 taken 18 times.
54 int is_chroma = p == 1 || p == 2;
314
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 int bytes = is_chroma ? AV_CEIL_RSHIFT(frame->width, desc->log2_chroma_w) : frame->width;
315
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 int height = is_chroma ? AV_CEIL_RSHIFT(frame->height, desc->log2_chroma_h) : frame->height;
316
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54 times.
54 if (desc->comp[0].depth >= 9) {
317 ((uint16_t*)dst)[0] = c[p];
318 av_memcpy_backptr(dst + 2, 2, bytes - 2);
319 dst += frame->linesize[p];
320 for (int y = 1; y < height; y++) {
321 memcpy(dst, frame->data[p], 2*bytes);
322 dst += frame->linesize[p];
323 }
324 } else {
325
2/2
✓ Branch 0 taken 27328 times.
✓ Branch 1 taken 54 times.
27382 for (int y = 0; y < height; y++) {
326 27328 memset(dst, c[p], bytes);
327 27328 dst += frame->linesize[p];
328 }
329 }
330 }
331 18 }
332
333 static int h264_slice_header_init(H264Context *h);
334
335 62 int ff_h264_update_thread_context(AVCodecContext *dst,
336 const AVCodecContext *src)
337 {
338 62 H264Context *h = dst->priv_data, *h1 = src->priv_data;
339 62 int inited = h->context_initialized, err = 0;
340 62 int need_reinit = 0;
341 int i, ret;
342
343
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
62 if (dst == src)
344 return 0;
345
346
3/4
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 46 times.
62 if (inited && !h1->ps.sps)
347 return AVERROR_INVALIDDATA;
348
349
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 16 times.
62 if (inited &&
350
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 (h->width != h1->width ||
351
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 h->height != h1->height ||
352
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 h->mb_width != h1->mb_width ||
353
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 h->mb_height != h1->mb_height ||
354
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 !h->ps.sps ||
355
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 h->ps.sps->bit_depth_luma != h1->ps.sps->bit_depth_luma ||
356
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 h->ps.sps->chroma_format_idc != h1->ps.sps->chroma_format_idc ||
357
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 h->ps.sps->vui.matrix_coeffs != h1->ps.sps->vui.matrix_coeffs)) {
358 need_reinit = 1;
359 }
360
361 /* copy block_offset since frame_start may not be called */
362 62 memcpy(h->block_offset, h1->block_offset, sizeof(h->block_offset));
363
364 // SPS/PPS
365
2/2
✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 62 times.
2046 for (i = 0; i < FF_ARRAY_ELEMS(h->ps.sps_list); i++) {
366 1984 ret = av_buffer_replace(&h->ps.sps_list[i], h1->ps.sps_list[i]);
367
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1984 times.
1984 if (ret < 0)
368 return ret;
369 }
370
2/2
✓ Branch 0 taken 15872 times.
✓ Branch 1 taken 62 times.
15934 for (i = 0; i < FF_ARRAY_ELEMS(h->ps.pps_list); i++) {
371 15872 ret = av_buffer_replace(&h->ps.pps_list[i], h1->ps.pps_list[i]);
372
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15872 times.
15872 if (ret < 0)
373 return ret;
374 }
375
376 62 ret = av_buffer_replace(&h->ps.pps_ref, h1->ps.pps_ref);
377
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
62 if (ret < 0)
378 return ret;
379 62 h->ps.pps = NULL;
380 62 h->ps.sps = NULL;
381
1/2
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
62 if (h1->ps.pps_ref) {
382 62 h->ps.pps = (const PPS*)h->ps.pps_ref->data;
383 62 h->ps.sps = h->ps.pps->sps;
384 }
385
386
3/4
✓ Branch 0 taken 62 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 46 times.
62 if (need_reinit || !inited) {
387 16 h->width = h1->width;
388 16 h->height = h1->height;
389 16 h->mb_height = h1->mb_height;
390 16 h->mb_width = h1->mb_width;
391 16 h->mb_num = h1->mb_num;
392 16 h->mb_stride = h1->mb_stride;
393 16 h->b_stride = h1->b_stride;
394 16 h->x264_build = h1->x264_build;
395
396
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
16 if (h->context_initialized || h1->context_initialized) {
397
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
16 if ((err = h264_slice_header_init(h)) < 0) {
398 av_log(h->avctx, AV_LOG_ERROR, "h264_slice_header_init() failed");
399 return err;
400 }
401 }
402
403 /* copy block_offset since frame_start may not be called */
404 16 memcpy(h->block_offset, h1->block_offset, sizeof(h->block_offset));
405 }
406
407 62 h->avctx->coded_height = h1->avctx->coded_height;
408 62 h->avctx->coded_width = h1->avctx->coded_width;
409 62 h->avctx->width = h1->avctx->width;
410 62 h->avctx->height = h1->avctx->height;
411 62 h->width_from_caller = h1->width_from_caller;
412 62 h->height_from_caller = h1->height_from_caller;
413 62 h->coded_picture_number = h1->coded_picture_number;
414 62 h->first_field = h1->first_field;
415 62 h->picture_structure = h1->picture_structure;
416 62 h->mb_aff_frame = h1->mb_aff_frame;
417 62 h->droppable = h1->droppable;
418
419
2/2
✓ Branch 0 taken 2232 times.
✓ Branch 1 taken 62 times.
2294 for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) {
420 2232 ret = ff_h264_replace_picture(h, &h->DPB[i], &h1->DPB[i]);
421
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2232 times.
2232 if (ret < 0)
422 return ret;
423 }
424
425
4/6
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 20 times.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
✗ Branch 5 not taken.
62 h->cur_pic_ptr = REBASE_PICTURE(h1->cur_pic_ptr, h, h1);
426 62 ret = ff_h264_replace_picture(h, &h->cur_pic, &h1->cur_pic);
427
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
62 if (ret < 0)
428 return ret;
429
430 62 h->enable_er = h1->enable_er;
431 62 h->workaround_bugs = h1->workaround_bugs;
432 62 h->droppable = h1->droppable;
433
434 // extradata/NAL handling
435 62 h->is_avc = h1->is_avc;
436 62 h->nal_length_size = h1->nal_length_size;
437
438 62 memcpy(&h->poc, &h1->poc, sizeof(h->poc));
439
440 62 memcpy(h->short_ref, h1->short_ref, sizeof(h->short_ref));
441 62 memcpy(h->long_ref, h1->long_ref, sizeof(h->long_ref));
442 62 memcpy(h->delayed_pic, h1->delayed_pic, sizeof(h->delayed_pic));
443 62 memcpy(h->last_pocs, h1->last_pocs, sizeof(h->last_pocs));
444
445 62 h->next_output_pic = h1->next_output_pic;
446 62 h->next_outputed_poc = h1->next_outputed_poc;
447 62 h->poc_offset = h1->poc_offset;
448
449 62 memcpy(h->mmco, h1->mmco, sizeof(h->mmco));
450 62 h->nb_mmco = h1->nb_mmco;
451 62 h->mmco_reset = h1->mmco_reset;
452 62 h->explicit_ref_marking = h1->explicit_ref_marking;
453 62 h->long_ref_count = h1->long_ref_count;
454 62 h->short_ref_count = h1->short_ref_count;
455
456 62 copy_picture_range(h->short_ref, h1->short_ref, 32, h, h1);
457 62 copy_picture_range(h->long_ref, h1->long_ref, 32, h, h1);
458 62 copy_picture_range(h->delayed_pic, h1->delayed_pic,
459 FF_ARRAY_ELEMS(h->delayed_pic), h, h1);
460
461 62 h->frame_recovered = h1->frame_recovered;
462
463 62 ret = ff_h264_sei_ctx_replace(&h->sei, &h1->sei);
464
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
62 if (ret < 0)
465 return ret;
466
467 62 h->sei.common.unregistered.x264_build = h1->sei.common.unregistered.x264_build;
468 62 h->sei.common.mastering_display = h1->sei.common.mastering_display;
469 62 h->sei.common.content_light = h1->sei.common.content_light;
470
471
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 42 times.
62 if (!h->cur_pic_ptr)
472 20 return 0;
473
474
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 15 times.
42 if (!h->droppable) {
475 27 err = ff_h264_execute_ref_pic_marking(h);
476 27 h->poc.prev_poc_msb = h->poc.poc_msb;
477 27 h->poc.prev_poc_lsb = h->poc.poc_lsb;
478 }
479 42 h->poc.prev_frame_num_offset = h->poc.frame_num_offset;
480 42 h->poc.prev_frame_num = h->poc.frame_num;
481
482 42 h->recovery_frame = h1->recovery_frame;
483
484 42 return err;
485 }
486
487 50 int ff_h264_update_thread_context_for_user(AVCodecContext *dst,
488 const AVCodecContext *src)
489 {
490 50 H264Context *h = dst->priv_data;
491 50 const H264Context *h1 = src->priv_data;
492
493 50 h->is_avc = h1->is_avc;
494 50 h->nal_length_size = h1->nal_length_size;
495
496 50 return 0;
497 }
498
499 24232 static int h264_frame_start(H264Context *h)
500 {
501 H264Picture *pic;
502 int i, ret;
503 24232 const int pixel_shift = h->pixel_shift;
504
505
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24232 times.
24232 if (!ff_thread_can_start_frame(h->avctx)) {
506 av_log(h->avctx, AV_LOG_ERROR, "Attempt to start a frame outside SETUP state\n");
507 return -1;
508 }
509
510 24232 release_unused_pictures(h, 1);
511 24232 h->cur_pic_ptr = NULL;
512
513 24232 i = find_unused_picture(h);
514
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 24232 times.
24232 if (i < 0) {
515 av_log(h->avctx, AV_LOG_ERROR, "no frame buffer available\n");
516 return i;
517 }
518 24232 pic = &h->DPB[i];
519
520
2/2
✓ Branch 0 taken 16837 times.
✓ Branch 1 taken 7395 times.
24232 pic->reference = h->droppable ? 0 : h->picture_structure;
521 #if FF_API_FRAME_PICTURE_NUMBER
522 FF_DISABLE_DEPRECATION_WARNINGS
523 24232 pic->f->coded_picture_number = h->coded_picture_number++;
524 FF_ENABLE_DEPRECATION_WARNINGS
525 #endif
526 24232 pic->field_picture = h->picture_structure != PICT_FRAME;
527 24232 pic->frame_num = h->poc.frame_num;
528 /*
529 * Zero key_frame here; IDR markings per slice in frame or fields are ORed
530 * in later.
531 * See decode_nal_units().
532 */
533 24232 pic->f->flags &= ~AV_FRAME_FLAG_KEY;
534 24232 pic->mmco_reset = 0;
535 24232 pic->recovered = 0;
536 24232 pic->invalid_gap = 0;
537 24232 pic->sei_recovery_frame_cnt = h->sei.recovery_point.recovery_frame_cnt;
538
539 24232 pic->f->pict_type = h->slice_ctx[0].slice_type;
540
541 24232 pic->f->crop_left = h->crop_left;
542 24232 pic->f->crop_right = h->crop_right;
543 24232 pic->f->crop_top = h->crop_top;
544 24232 pic->f->crop_bottom = h->crop_bottom;
545
546
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24232 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24232 pic->needs_fg = h->sei.common.film_grain_characteristics.present && !h->avctx->hwaccel &&
547 !(h->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN);
548
549
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24232 times.
24232 if ((ret = alloc_picture(h, pic)) < 0)
550 return ret;
551
552 24232 h->cur_pic_ptr = pic;
553 24232 ff_h264_unref_picture(h, &h->cur_pic);
554 if (CONFIG_ERROR_RESILIENCE) {
555 24232 ff_h264_set_erpic(&h->er.cur_pic, NULL);
556 }
557
558
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 24232 times.
24232 if ((ret = ff_h264_ref_picture(h, &h->cur_pic, h->cur_pic_ptr)) < 0)
559 return ret;
560
561
2/2
✓ Branch 0 taken 24532 times.
✓ Branch 1 taken 24232 times.
48764 for (i = 0; i < h->nb_slice_ctx; i++) {
562 24532 h->slice_ctx[i].linesize = h->cur_pic_ptr->f->linesize[0];
563 24532 h->slice_ctx[i].uvlinesize = h->cur_pic_ptr->f->linesize[1];
564 }
565
566
2/2
✓ Branch 0 taken 23932 times.
✓ Branch 1 taken 300 times.
24232 if (CONFIG_ERROR_RESILIENCE && h->enable_er) {
567 23932 ff_er_frame_start(&h->er);
568 23932 ff_h264_set_erpic(&h->er.last_pic, NULL);
569 23932 ff_h264_set_erpic(&h->er.next_pic, NULL);
570 }
571
572
2/2
✓ Branch 0 taken 387712 times.
✓ Branch 1 taken 24232 times.
411944 for (i = 0; i < 16; i++) {
573 387712 h->block_offset[i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3);
574 387712 h->block_offset[48 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 8 * pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3);
575 }
576
2/2
✓ Branch 0 taken 387712 times.
✓ Branch 1 taken 24232 times.
411944 for (i = 0; i < 16; i++) {
577 387712 h->block_offset[16 + i] =
578 387712 h->block_offset[32 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3);
579 387712 h->block_offset[48 + 16 + i] =
580 387712 h->block_offset[48 + 32 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 8 * pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3);
581 }
582
583 /* We mark the current picture as non-reference after allocating it, so
584 * that if we break out due to an error it can be released automatically
585 * in the next ff_mpv_frame_start().
586 */
587 24232 h->cur_pic_ptr->reference = 0;
588
589 24232 h->cur_pic_ptr->field_poc[0] = h->cur_pic_ptr->field_poc[1] = INT_MAX;
590
591 24232 h->next_output_pic = NULL;
592
593 24232 h->postpone_filter = 0;
594
595
4/4
✓ Branch 0 taken 2860 times.
✓ Branch 1 taken 21372 times.
✓ Branch 2 taken 2352 times.
✓ Branch 3 taken 508 times.
24232 h->mb_aff_frame = h->ps.sps->mb_aff && (h->picture_structure == PICT_FRAME);
596
597
2/2
✓ Branch 0 taken 2050 times.
✓ Branch 1 taken 22182 times.
24232 if (h->sei.common.unregistered.x264_build >= 0)
598 2050 h->x264_build = h->sei.common.unregistered.x264_build;
599
600 assert(h->cur_pic_ptr->long_ref == 0);
601
602 24232 return 0;
603 }
604
605 12148276 static av_always_inline void backup_mb_border(const H264Context *h, H264SliceContext *sl,
606 uint8_t *src_y,
607 uint8_t *src_cb, uint8_t *src_cr,
608 int linesize, int uvlinesize,
609 int simple)
610 {
611 uint8_t *top_border;
612 12148276 int top_idx = 1;
613 12148276 const int pixel_shift = h->pixel_shift;
614 12148276 int chroma444 = CHROMA444(h);
615 12148276 int chroma422 = CHROMA422(h);
616
617 12148276 src_y -= linesize;
618 12148276 src_cb -= uvlinesize;
619 12148276 src_cr -= uvlinesize;
620
621
3/4
✓ Branch 0 taken 12148276 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2019936 times.
✓ Branch 3 taken 10128340 times.
12148276 if (!simple && FRAME_MBAFF(h)) {
622
2/2
✓ Branch 0 taken 1009968 times.
✓ Branch 1 taken 1009968 times.
2019936 if (sl->mb_y & 1) {
623
2/2
✓ Branch 0 taken 747670 times.
✓ Branch 1 taken 262298 times.
1009968 if (!MB_MBAFF(sl)) {
624 747670 top_border = sl->top_borders[0][sl->mb_x];
625 747670 AV_COPY128(top_border, src_y + 15 * linesize);
626
2/2
✓ Branch 0 taken 213139 times.
✓ Branch 1 taken 534531 times.
747670 if (pixel_shift)
627 213139 AV_COPY128(top_border + 16, src_y + 15 * linesize + 16);
628 if (simple || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) {
629
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 747670 times.
747670 if (chroma444) {
630 if (pixel_shift) {
631 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
632 AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16);
633 AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize);
634 AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16);
635 } else {
636 AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize);
637 AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize);
638 }
639
2/2
✓ Branch 0 taken 106510 times.
✓ Branch 1 taken 641160 times.
747670 } else if (chroma422) {
640
1/2
✓ Branch 0 taken 106510 times.
✗ Branch 1 not taken.
106510 if (pixel_shift) {
641 106510 AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize);
642 106510 AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize);
643 } else {
644 AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize);
645 AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize);
646 }
647 } else {
648
2/2
✓ Branch 0 taken 106629 times.
✓ Branch 1 taken 534531 times.
641160 if (pixel_shift) {
649 106629 AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize);
650 106629 AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize);
651 } else {
652 534531 AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize);
653 534531 AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize);
654 }
655 }
656 }
657 }
658
2/2
✓ Branch 0 taken 262298 times.
✓ Branch 1 taken 747670 times.
1009968 } else if (MB_MBAFF(sl)) {
659 262298 top_idx = 0;
660 } else
661 747670 return;
662 }
663
664 11400606 top_border = sl->top_borders[top_idx][sl->mb_x];
665 /* There are two lines saved, the line above the top macroblock
666 * of a pair, and the line above the bottom macroblock. */
667 11400606 AV_COPY128(top_border, src_y + 16 * linesize);
668
2/2
✓ Branch 0 taken 1369541 times.
✓ Branch 1 taken 10031065 times.
11400606 if (pixel_shift)
669 1369541 AV_COPY128(top_border + 16, src_y + 16 * linesize + 16);
670
671 if (simple || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) {
672
2/2
✓ Branch 0 taken 80328 times.
✓ Branch 1 taken 11320278 times.
11400606 if (chroma444) {
673
2/2
✓ Branch 0 taken 19800 times.
✓ Branch 1 taken 60528 times.
80328 if (pixel_shift) {
674 19800 AV_COPY128(top_border + 32, src_cb + 16 * linesize);
675 19800 AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16);
676 19800 AV_COPY128(top_border + 64, src_cr + 16 * linesize);
677 19800 AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16);
678 } else {
679 60528 AV_COPY128(top_border + 16, src_cb + 16 * linesize);
680 60528 AV_COPY128(top_border + 32, src_cr + 16 * linesize);
681 }
682
2/2
✓ Branch 0 taken 588635 times.
✓ Branch 1 taken 10731643 times.
11320278 } else if (chroma422) {
683
2/2
✓ Branch 0 taken 584675 times.
✓ Branch 1 taken 3960 times.
588635 if (pixel_shift) {
684 584675 AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize);
685 584675 AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize);
686 } else {
687 3960 AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize);
688 3960 AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize);
689 }
690 } else {
691
2/2
✓ Branch 0 taken 765066 times.
✓ Branch 1 taken 9966577 times.
10731643 if (pixel_shift) {
692 765066 AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize);
693 765066 AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize);
694 } else {
695 9966577 AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize);
696 9966577 AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize);
697 }
698 }
699 }
700 }
701
702 /**
703 * Initialize implicit_weight table.
704 * @param field 0/1 initialize the weight for interlaced MBAFF
705 * -1 initializes the rest
706 */
707 3301 static void implicit_weight_table(const H264Context *h, H264SliceContext *sl, int field)
708 {
709 int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1;
710
711
2/2
✓ Branch 0 taken 6602 times.
✓ Branch 1 taken 3301 times.
9903 for (i = 0; i < 2; i++) {
712 6602 sl->pwt.luma_weight_flag[i] = 0;
713 6602 sl->pwt.chroma_weight_flag[i] = 0;
714 }
715
716
2/2
✓ Branch 0 taken 1591 times.
✓ Branch 1 taken 1710 times.
3301 if (field < 0) {
717
1/2
✓ Branch 0 taken 1591 times.
✗ Branch 1 not taken.
1591 if (h->picture_structure == PICT_FRAME) {
718 1591 cur_poc = h->cur_pic_ptr->poc;
719 } else {
720 cur_poc = h->cur_pic_ptr->field_poc[h->picture_structure - 1];
721 }
722
6/6
✓ Branch 0 taken 417 times.
✓ Branch 1 taken 1174 times.
✓ Branch 2 taken 107 times.
✓ Branch 3 taken 310 times.
✓ Branch 4 taken 97 times.
✓ Branch 5 taken 10 times.
1591 if (sl->ref_count[0] == 1 && sl->ref_count[1] == 1 && !FRAME_MBAFF(h) &&
723
2/2
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 63 times.
97 sl->ref_list[0][0].poc + (int64_t)sl->ref_list[1][0].poc == 2LL * cur_poc) {
724 34 sl->pwt.use_weight = 0;
725 34 sl->pwt.use_weight_chroma = 0;
726 34 return;
727 }
728 1557 ref_start = 0;
729 1557 ref_count0 = sl->ref_count[0];
730 1557 ref_count1 = sl->ref_count[1];
731 } else {
732 1710 cur_poc = h->cur_pic_ptr->field_poc[field];
733 1710 ref_start = 16;
734 1710 ref_count0 = 16 + 2 * sl->ref_count[0];
735 1710 ref_count1 = 16 + 2 * sl->ref_count[1];
736 }
737
738 3267 sl->pwt.use_weight = 2;
739 3267 sl->pwt.use_weight_chroma = 2;
740 3267 sl->pwt.luma_log2_weight_denom = 5;
741 3267 sl->pwt.chroma_log2_weight_denom = 5;
742
743
2/2
✓ Branch 0 taken 11618 times.
✓ Branch 1 taken 3267 times.
14885 for (ref0 = ref_start; ref0 < ref_count0; ref0++) {
744 11618 int64_t poc0 = sl->ref_list[0][ref0].poc;
745
2/2
✓ Branch 0 taken 21707 times.
✓ Branch 1 taken 11618 times.
33325 for (ref1 = ref_start; ref1 < ref_count1; ref1++) {
746 21707 int w = 32;
747
2/4
✓ Branch 0 taken 21707 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21707 times.
✗ Branch 3 not taken.
21707 if (!sl->ref_list[0][ref0].parent->long_ref && !sl->ref_list[1][ref1].parent->long_ref) {
748 21707 int poc1 = sl->ref_list[1][ref1].poc;
749 21707 int td = av_clip_int8(poc1 - poc0);
750
2/2
✓ Branch 0 taken 21641 times.
✓ Branch 1 taken 66 times.
21707 if (td) {
751 21641 int tb = av_clip_int8(cur_poc - poc0);
752 21641 int tx = (16384 + (FFABS(td) >> 1)) / td;
753 21641 int dist_scale_factor = (tb * tx + 32) >> 8;
754
3/4
✓ Branch 0 taken 21637 times.
✓ Branch 1 taken 4 times.
✓ Branch 2 taken 21637 times.
✗ Branch 3 not taken.
21641 if (dist_scale_factor >= -64 && dist_scale_factor <= 128)
755 21637 w = 64 - dist_scale_factor;
756 }
757 }
758
2/2
✓ Branch 0 taken 5827 times.
✓ Branch 1 taken 15880 times.
21707 if (field < 0) {
759 5827 sl->pwt.implicit_weight[ref0][ref1][0] =
760 5827 sl->pwt.implicit_weight[ref0][ref1][1] = w;
761 } else {
762 15880 sl->pwt.implicit_weight[ref0][ref1][field] = w;
763 }
764 }
765 }
766 }
767
768 /**
769 * initialize scan tables
770 */
771 586 static void init_scan_tables(H264Context *h)
772 {
773 int i;
774
2/2
✓ Branch 0 taken 9376 times.
✓ Branch 1 taken 586 times.
9962 for (i = 0; i < 16; i++) {
775 #define TRANSPOSE(x) ((x) >> 2) | (((x) << 2) & 0xF)
776 9376 h->zigzag_scan[i] = TRANSPOSE(ff_zigzag_scan[i]);
777 9376 h->field_scan[i] = TRANSPOSE(field_scan[i]);
778 #undef TRANSPOSE
779 }
780
2/2
✓ Branch 0 taken 37504 times.
✓ Branch 1 taken 586 times.
38090 for (i = 0; i < 64; i++) {
781 #define TRANSPOSE(x) ((x) >> 3) | (((x) & 7) << 3)
782 37504 h->zigzag_scan8x8[i] = TRANSPOSE(ff_zigzag_direct[i]);
783 37504 h->zigzag_scan8x8_cavlc[i] = TRANSPOSE(zigzag_scan8x8_cavlc[i]);
784 37504 h->field_scan8x8[i] = TRANSPOSE(field_scan8x8[i]);
785 37504 h->field_scan8x8_cavlc[i] = TRANSPOSE(field_scan8x8_cavlc[i]);
786 #undef TRANSPOSE
787 }
788
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 572 times.
586 if (h->ps.sps->transform_bypass) { // FIXME same ugly
789 14 memcpy(h->zigzag_scan_q0 , ff_zigzag_scan , sizeof(h->zigzag_scan_q0 ));
790 14 memcpy(h->zigzag_scan8x8_q0 , ff_zigzag_direct , sizeof(h->zigzag_scan8x8_q0 ));
791 14 memcpy(h->zigzag_scan8x8_cavlc_q0 , zigzag_scan8x8_cavlc , sizeof(h->zigzag_scan8x8_cavlc_q0));
792 14 memcpy(h->field_scan_q0 , field_scan , sizeof(h->field_scan_q0 ));
793 14 memcpy(h->field_scan8x8_q0 , field_scan8x8 , sizeof(h->field_scan8x8_q0 ));
794 14 memcpy(h->field_scan8x8_cavlc_q0 , field_scan8x8_cavlc , sizeof(h->field_scan8x8_cavlc_q0 ));
795 } else {
796 572 memcpy(h->zigzag_scan_q0 , h->zigzag_scan , sizeof(h->zigzag_scan_q0 ));
797 572 memcpy(h->zigzag_scan8x8_q0 , h->zigzag_scan8x8 , sizeof(h->zigzag_scan8x8_q0 ));
798 572 memcpy(h->zigzag_scan8x8_cavlc_q0 , h->zigzag_scan8x8_cavlc , sizeof(h->zigzag_scan8x8_cavlc_q0));
799 572 memcpy(h->field_scan_q0 , h->field_scan , sizeof(h->field_scan_q0 ));
800 572 memcpy(h->field_scan8x8_q0 , h->field_scan8x8 , sizeof(h->field_scan8x8_q0 ));
801 572 memcpy(h->field_scan8x8_cavlc_q0 , h->field_scan8x8_cavlc , sizeof(h->field_scan8x8_cavlc_q0 ));
802 }
803 586 }
804
805 27174 static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback)
806 {
807 #define HWACCEL_MAX (CONFIG_H264_DXVA2_HWACCEL + \
808 (CONFIG_H264_D3D11VA_HWACCEL * 2) + \
809 CONFIG_H264_NVDEC_HWACCEL + \
810 CONFIG_H264_VAAPI_HWACCEL + \
811 CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \
812 CONFIG_H264_VDPAU_HWACCEL + \
813 CONFIG_H264_VULKAN_HWACCEL)
814 27174 enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts;
815
816
3/6
✓ Branch 0 taken 155 times.
✓ Branch 1 taken 367 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 26652 times.
✗ Branch 5 not taken.
27174 switch (h->ps.sps->bit_depth_luma) {
817 155 case 9:
818
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 155 times.
155 if (CHROMA444(h)) {
819 if (h->avctx->colorspace == AVCOL_SPC_RGB) {
820 *fmt++ = AV_PIX_FMT_GBRP9;
821 } else
822 *fmt++ = AV_PIX_FMT_YUV444P9;
823
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 103 times.
155 } else if (CHROMA422(h))
824 52 *fmt++ = AV_PIX_FMT_YUV422P9;
825 else
826 103 *fmt++ = AV_PIX_FMT_YUV420P9;
827 155 break;
828 367 case 10:
829 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
830 if (h->avctx->colorspace != AVCOL_SPC_RGB)
831 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
832 #endif
833 #if CONFIG_H264_VULKAN_HWACCEL
834 *fmt++ = AV_PIX_FMT_VULKAN;
835 #endif
836
2/2
✓ Branch 0 taken 51 times.
✓ Branch 1 taken 316 times.
367 if (CHROMA444(h)) {
837
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
51 if (h->avctx->colorspace == AVCOL_SPC_RGB) {
838 *fmt++ = AV_PIX_FMT_GBRP10;
839 } else
840 51 *fmt++ = AV_PIX_FMT_YUV444P10;
841
2/2
✓ Branch 0 taken 164 times.
✓ Branch 1 taken 152 times.
316 } else if (CHROMA422(h))
842 164 *fmt++ = AV_PIX_FMT_YUV422P10;
843 else {
844 #if CONFIG_H264_VAAPI_HWACCEL
845 // Just add as candidate. Whether VAProfileH264High10 usable or
846 // not is decided by vaapi_decode_make_config() defined in FFmpeg
847 // and vaQueryCodingProfile() defined in libva.
848 152 *fmt++ = AV_PIX_FMT_VAAPI;
849 #endif
850 152 *fmt++ = AV_PIX_FMT_YUV420P10;
851 }
852 367 break;
853 case 12:
854 #if CONFIG_H264_VULKAN_HWACCEL
855 *fmt++ = AV_PIX_FMT_VULKAN;
856 #endif
857 if (CHROMA444(h)) {
858 if (h->avctx->colorspace == AVCOL_SPC_RGB) {
859 *fmt++ = AV_PIX_FMT_GBRP12;
860 } else
861 *fmt++ = AV_PIX_FMT_YUV444P12;
862 } else if (CHROMA422(h))
863 *fmt++ = AV_PIX_FMT_YUV422P12;
864 else
865 *fmt++ = AV_PIX_FMT_YUV420P12;
866 break;
867 case 14:
868 if (CHROMA444(h)) {
869 if (h->avctx->colorspace == AVCOL_SPC_RGB) {
870 *fmt++ = AV_PIX_FMT_GBRP14;
871 } else
872 *fmt++ = AV_PIX_FMT_YUV444P14;
873 } else if (CHROMA422(h))
874 *fmt++ = AV_PIX_FMT_YUV422P14;
875 else
876 *fmt++ = AV_PIX_FMT_YUV420P14;
877 break;
878 26652 case 8:
879 #if CONFIG_H264_VDPAU_HWACCEL
880 26652 *fmt++ = AV_PIX_FMT_VDPAU;
881 #endif
882 #if CONFIG_H264_VULKAN_HWACCEL
883 *fmt++ = AV_PIX_FMT_VULKAN;
884 #endif
885 #if CONFIG_H264_NVDEC_HWACCEL
886 *fmt++ = AV_PIX_FMT_CUDA;
887 #endif
888 #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL
889 if (h->avctx->colorspace != AVCOL_SPC_RGB)
890 *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX;
891 #endif
892
2/2
✓ Branch 0 taken 484 times.
✓ Branch 1 taken 26168 times.
26652 if (CHROMA444(h)) {
893
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 484 times.
484 if (h->avctx->colorspace == AVCOL_SPC_RGB)
894 *fmt++ = AV_PIX_FMT_GBRP;
895
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 482 times.
484 else if (h->avctx->color_range == AVCOL_RANGE_JPEG)
896 2 *fmt++ = AV_PIX_FMT_YUVJ444P;
897 else
898 482 *fmt++ = AV_PIX_FMT_YUV444P;
899
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 26146 times.
26168 } else if (CHROMA422(h)) {
900
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
22 if (h->avctx->color_range == AVCOL_RANGE_JPEG)
901 *fmt++ = AV_PIX_FMT_YUVJ422P;
902 else
903 22 *fmt++ = AV_PIX_FMT_YUV422P;
904 } else {
905 #if CONFIG_H264_DXVA2_HWACCEL
906 *fmt++ = AV_PIX_FMT_DXVA2_VLD;
907 #endif
908 #if CONFIG_H264_D3D11VA_HWACCEL
909 *fmt++ = AV_PIX_FMT_D3D11VA_VLD;
910 *fmt++ = AV_PIX_FMT_D3D11;
911 #endif
912 #if CONFIG_H264_VAAPI_HWACCEL
913 26146 *fmt++ = AV_PIX_FMT_VAAPI;
914 #endif
915
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 26143 times.
26146 if (h->avctx->color_range == AVCOL_RANGE_JPEG)
916 3 *fmt++ = AV_PIX_FMT_YUVJ420P;
917 else
918 26143 *fmt++ = AV_PIX_FMT_YUV420P;
919 }
920 26652 break;
921 default:
922 av_log(h->avctx, AV_LOG_ERROR,
923 "Unsupported bit depth %d\n", h->ps.sps->bit_depth_luma);
924 return AVERROR_INVALIDDATA;
925 }
926
927 27174 *fmt = AV_PIX_FMT_NONE;
928
929
2/2
✓ Branch 0 taken 80124 times.
✓ Branch 1 taken 573 times.
80697 for (int i = 0; pix_fmts[i] != AV_PIX_FMT_NONE; i++)
930
4/4
✓ Branch 0 taken 26852 times.
✓ Branch 1 taken 53272 times.
✓ Branch 2 taken 26601 times.
✓ Branch 3 taken 251 times.
80124 if (pix_fmts[i] == h->avctx->pix_fmt && !force_callback)
931 26601 return pix_fmts[i];
932 573 return ff_get_format(h->avctx, pix_fmts);
933 }
934
935 /* export coded and cropped frame dimensions to AVCodecContext */
936 26920 static void init_dimensions(H264Context *h)
937 {
938 26920 const SPS *sps = (const SPS*)h->ps.sps;
939 26920 int cr = sps->crop_right;
940 26920 int cl = sps->crop_left;
941 26920 int ct = sps->crop_top;
942 26920 int cb = sps->crop_bottom;
943 26920 int width = h->width - (cr + cl);
944 26920 int height = h->height - (ct + cb);
945
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26920 times.
26920 av_assert0(sps->crop_right + sps->crop_left < (unsigned)h->width);
946
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26920 times.
26920 av_assert0(sps->crop_top + sps->crop_bottom < (unsigned)h->height);
947
948 /* handle container cropping */
949
3/4
✓ Branch 0 taken 24684 times.
✓ Branch 1 taken 2236 times.
✓ Branch 2 taken 24684 times.
✗ Branch 3 not taken.
26920 if (h->width_from_caller > 0 && h->height_from_caller > 0 &&
950
3/4
✓ Branch 0 taken 24683 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 24683 times.
✗ Branch 3 not taken.
24684 !sps->crop_top && !sps->crop_left &&
951
2/2
✓ Branch 0 taken 24676 times.
✓ Branch 1 taken 7 times.
24683 FFALIGN(h->width_from_caller, 16) == FFALIGN(width, 16) &&
952
1/2
✓ Branch 0 taken 24676 times.
✗ Branch 1 not taken.
24676 FFALIGN(h->height_from_caller, 16) == FFALIGN(height, 16) &&
953
2/2
✓ Branch 0 taken 24675 times.
✓ Branch 1 taken 1 times.
24676 h->width_from_caller <= width &&
954
2/2
✓ Branch 0 taken 24673 times.
✓ Branch 1 taken 2 times.
24675 h->height_from_caller <= height) {
955 24673 width = h->width_from_caller;
956 24673 height = h->height_from_caller;
957 24673 cl = 0;
958 24673 ct = 0;
959 24673 cr = h->width - width;
960 24673 cb = h->height - height;
961 } else {
962 2247 h->width_from_caller = 0;
963 2247 h->height_from_caller = 0;
964 }
965
966 26920 h->avctx->coded_width = h->width;
967 26920 h->avctx->coded_height = h->height;
968 26920 h->avctx->width = width;
969 26920 h->avctx->height = height;
970 26920 h->crop_right = cr;
971 26920 h->crop_left = cl;
972 26920 h->crop_top = ct;
973 26920 h->crop_bottom = cb;
974 26920 }
975
976 586 static int h264_slice_header_init(H264Context *h)
977 {
978 586 const SPS *sps = h->ps.sps;
979 int i, ret;
980
981
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
586 if (!sps) {
982 ret = AVERROR_INVALIDDATA;
983 goto fail;
984 }
985
986 586 ff_set_sar(h->avctx, sps->vui.sar);
987 586 av_pix_fmt_get_chroma_sub_sample(h->avctx->pix_fmt,
988 &h->chroma_x_shift, &h->chroma_y_shift);
989
990
2/2
✓ Branch 0 taken 168 times.
✓ Branch 1 taken 418 times.
586 if (sps->timing_info_present_flag) {
991 168 int64_t den = sps->time_scale;
992
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 168 times.
168 if (h->x264_build < 44U)
993 den *= 2;
994 168 av_reduce(&h->avctx->framerate.den, &h->avctx->framerate.num,
995 168 sps->num_units_in_tick * 2, den, 1 << 30);
996 }
997
998 586 ff_h264_free_tables(h);
999
1000 586 h->first_field = 0;
1001 586 h->prev_interlaced_frame = 1;
1002
1003 586 init_scan_tables(h);
1004 586 ret = ff_h264_alloc_tables(h);
1005
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 586 times.
586 if (ret < 0) {
1006 av_log(h->avctx, AV_LOG_ERROR, "Could not allocate memory\n");
1007 goto fail;
1008 }
1009
1010
2/4
✓ Branch 0 taken 586 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 586 times.
✗ Branch 3 not taken.
586 if (sps->bit_depth_luma < 8 || sps->bit_depth_luma > 14 ||
1011
2/4
✓ Branch 0 taken 586 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 586 times.
586 sps->bit_depth_luma == 11 || sps->bit_depth_luma == 13
1012 ) {
1013 av_log(h->avctx, AV_LOG_ERROR, "Unsupported bit depth %d\n",
1014 sps->bit_depth_luma);
1015 ret = AVERROR_INVALIDDATA;
1016 goto fail;
1017 }
1018
1019 586 h->cur_bit_depth_luma =
1020 586 h->avctx->bits_per_raw_sample = sps->bit_depth_luma;
1021 586 h->cur_chroma_format_idc = sps->chroma_format_idc;
1022 586 h->pixel_shift = sps->bit_depth_luma > 8;
1023 586 h->chroma_format_idc = sps->chroma_format_idc;
1024 586 h->bit_depth_luma = sps->bit_depth_luma;
1025
1026 586 ff_h264dsp_init(&h->h264dsp, sps->bit_depth_luma,
1027 586 sps->chroma_format_idc);
1028 586 ff_h264chroma_init(&h->h264chroma, sps->bit_depth_chroma);
1029 586 ff_h264qpel_init(&h->h264qpel, sps->bit_depth_luma);
1030 586 ff_h264_pred_init(&h->hpc, AV_CODEC_ID_H264, sps->bit_depth_luma,
1031 586 sps->chroma_format_idc);
1032 586 ff_videodsp_init(&h->vdsp, sps->bit_depth_luma);
1033
1034
2/2
✓ Branch 0 taken 585 times.
✓ Branch 1 taken 1 times.
586 if (!HAVE_THREADS || !(h->avctx->active_thread_type & FF_THREAD_SLICE)) {
1035 585 ff_h264_slice_context_init(h, &h->slice_ctx[0]);
1036 } else {
1037
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 for (i = 0; i < h->nb_slice_ctx; i++) {
1038 2 H264SliceContext *sl = &h->slice_ctx[i];
1039
1040 2 sl->h264 = h;
1041 2 sl->intra4x4_pred_mode = h->intra4x4_pred_mode + i * 8 * 2 * h->mb_stride;
1042 2 sl->mvd_table[0] = h->mvd_table[0] + i * 8 * 2 * h->mb_stride;
1043 2 sl->mvd_table[1] = h->mvd_table[1] + i * 8 * 2 * h->mb_stride;
1044
1045 2 ff_h264_slice_context_init(h, sl);
1046 }
1047 }
1048
1049 586 h->context_initialized = 1;
1050
1051 586 return 0;
1052 fail:
1053 ff_h264_free_tables(h);
1054 h->context_initialized = 0;
1055 return ret;
1056 }
1057
1058 53208 static enum AVPixelFormat non_j_pixfmt(enum AVPixelFormat a)
1059 {
1060
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 53206 times.
53208 switch (a) {
1061 2 case AV_PIX_FMT_YUVJ420P: return AV_PIX_FMT_YUV420P;
1062 case AV_PIX_FMT_YUVJ422P: return AV_PIX_FMT_YUV422P;
1063 case AV_PIX_FMT_YUVJ444P: return AV_PIX_FMT_YUV444P;
1064 53206 default:
1065 53206 return a;
1066 }
1067 }
1068
1069 26920 static int h264_init_ps(H264Context *h, const H264SliceContext *sl, int first_slice)
1070 {
1071 const SPS *sps;
1072 26920 int needs_reinit = 0, must_reinit, ret;
1073
1074
2/2
✓ Branch 0 taken 26727 times.
✓ Branch 1 taken 193 times.
26920 if (first_slice) {
1075 26727 av_buffer_unref(&h->ps.pps_ref);
1076 26727 h->ps.pps = NULL;
1077 26727 h->ps.pps_ref = av_buffer_ref(h->ps.pps_list[sl->pps_id]);
1078
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26727 times.
26727 if (!h->ps.pps_ref)
1079 return AVERROR(ENOMEM);
1080 26727 h->ps.pps = (const PPS*)h->ps.pps_ref->data;
1081 }
1082
1083
2/2
✓ Branch 0 taken 572 times.
✓ Branch 1 taken 26348 times.
26920 if (h->ps.sps != h->ps.pps->sps) {
1084 572 h->ps.sps = (const SPS*)h->ps.pps->sps;
1085
1086
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 565 times.
572 if (h->mb_width != h->ps.sps->mb_width ||
1087
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 h->mb_height != h->ps.sps->mb_height ||
1088
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 h->cur_bit_depth_luma != h->ps.sps->bit_depth_luma ||
1089
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
6 h->cur_chroma_format_idc != h->ps.sps->chroma_format_idc
1090 )
1091 567 needs_reinit = 1;
1092
1093
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 562 times.
572 if (h->bit_depth_luma != h->ps.sps->bit_depth_luma ||
1094
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9 times.
10 h->chroma_format_idc != h->ps.sps->chroma_format_idc)
1095 563 needs_reinit = 1;
1096 }
1097 26920 sps = h->ps.sps;
1098
1099
2/2
✓ Branch 0 taken 26357 times.
✓ Branch 1 taken 563 times.
53277 must_reinit = (h->context_initialized &&
1100
2/2
✓ Branch 0 taken 26352 times.
✓ Branch 1 taken 5 times.
26357 ( 16*sps->mb_width != h->avctx->coded_width
1101
1/2
✓ Branch 0 taken 26352 times.
✗ Branch 1 not taken.
26352 || 16*sps->mb_height != h->avctx->coded_height
1102
2/2
✓ Branch 0 taken 26351 times.
✓ Branch 1 taken 1 times.
26352 || h->cur_bit_depth_luma != sps->bit_depth_luma
1103
2/2
✓ Branch 0 taken 26350 times.
✓ Branch 1 taken 1 times.
26351 || h->cur_chroma_format_idc != sps->chroma_format_idc
1104
1/2
✓ Branch 0 taken 26350 times.
✗ Branch 1 not taken.
26350 || h->mb_width != sps->mb_width
1105
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26350 times.
26350 || h->mb_height != sps->mb_height
1106 ));
1107
2/2
✓ Branch 0 taken 26604 times.
✓ Branch 1 taken 316 times.
26920 if (h->avctx->pix_fmt == AV_PIX_FMT_NONE
1108
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 26601 times.
26604 || (non_j_pixfmt(h->avctx->pix_fmt) != non_j_pixfmt(get_pixel_format(h, 0))))
1109 319 must_reinit = 1;
1110
1111
4/4
✓ Branch 0 taken 26727 times.
✓ Branch 1 taken 193 times.
✓ Branch 3 taken 65 times.
✓ Branch 4 taken 26662 times.
26920 if (first_slice && av_cmp_q(sps->vui.sar, h->avctx->sample_aspect_ratio))
1112 65 must_reinit = 1;
1113
1114
1/2
✓ Branch 0 taken 26920 times.
✗ Branch 1 not taken.
26920 if (!h->setup_finished) {
1115 26920 h->avctx->profile = ff_h264_get_profile(sps);
1116 26920 h->avctx->level = sps->level_idc;
1117 26920 h->avctx->refs = sps->ref_frame_count;
1118
1119 26920 h->mb_width = sps->mb_width;
1120 26920 h->mb_height = sps->mb_height;
1121 26920 h->mb_num = h->mb_width * h->mb_height;
1122 26920 h->mb_stride = h->mb_width + 1;
1123
1124 26920 h->b_stride = h->mb_width * 4;
1125
1126 26920 h->chroma_y_shift = sps->chroma_format_idc <= 1; // 400 uses yuv420p
1127
1128 26920 h->width = 16 * h->mb_width;
1129 26920 h->height = 16 * h->mb_height;
1130
1131 26920 init_dimensions(h);
1132
1133
2/2
✓ Branch 0 taken 1282 times.
✓ Branch 1 taken 25638 times.
26920 if (sps->vui.video_signal_type_present_flag) {
1134 2564 h->avctx->color_range = sps->vui.video_full_range_flag > 0 ? AVCOL_RANGE_JPEG
1135
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1280 times.
1282 : AVCOL_RANGE_MPEG;
1136
2/2
✓ Branch 0 taken 1184 times.
✓ Branch 1 taken 98 times.
1282 if (sps->vui.colour_description_present_flag) {
1137
2/2
✓ Branch 0 taken 19 times.
✓ Branch 1 taken 1165 times.
1184 if (h->avctx->colorspace != sps->vui.matrix_coeffs)
1138 19 needs_reinit = 1;
1139 1184 h->avctx->color_primaries = sps->vui.colour_primaries;
1140 1184 h->avctx->color_trc = sps->vui.transfer_characteristics;
1141 1184 h->avctx->colorspace = sps->vui.matrix_coeffs;
1142 }
1143 }
1144
1145
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 26920 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
26920 if (h->sei.common.alternative_transfer.present &&
1146 av_color_transfer_name(h->sei.common.alternative_transfer.preferred_transfer_characteristics) &&
1147 h->sei.common.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) {
1148 h->avctx->color_trc = h->sei.common.alternative_transfer.preferred_transfer_characteristics;
1149 }
1150 }
1151 26920 h->avctx->chroma_sample_location = sps->vui.chroma_location;
1152
1153
5/6
✓ Branch 0 taken 26357 times.
✓ Branch 1 taken 563 times.
✓ Branch 2 taken 26350 times.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 26350 times.
26920 if (!h->context_initialized || must_reinit || needs_reinit) {
1154 570 int flush_changes = h->context_initialized;
1155 570 h->context_initialized = 0;
1156
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 570 times.
570 if (sl != h->slice_ctx) {
1157 av_log(h->avctx, AV_LOG_ERROR,
1158 "changing width %d -> %d / height %d -> %d on "
1159 "slice %d\n",
1160 h->width, h->avctx->coded_width,
1161 h->height, h->avctx->coded_height,
1162 h->current_slice + 1);
1163 return AVERROR_INVALIDDATA;
1164 }
1165
1166 av_assert1(first_slice);
1167
1168
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 563 times.
570 if (flush_changes)
1169 7 ff_h264_flush_change(h);
1170
1171
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 570 times.
570 if ((ret = get_pixel_format(h, 1)) < 0)
1172 return ret;
1173 570 h->avctx->pix_fmt = ret;
1174
1175 570 av_log(h->avctx, AV_LOG_VERBOSE, "Reinit context to %dx%d, "
1176 570 "pix_fmt: %s\n", h->width, h->height, av_get_pix_fmt_name(h->avctx->pix_fmt));
1177
1178
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 570 times.
570 if ((ret = h264_slice_header_init(h)) < 0) {
1179 av_log(h->avctx, AV_LOG_ERROR,
1180 "h264_slice_header_init() failed\n");
1181 return ret;
1182 }
1183 }
1184
1185 26920 return 0;
1186 }
1187
1188 23554 static int h264_export_frame_props(H264Context *h)
1189 {
1190 23554 const SPS *sps = h->ps.sps;
1191 23554 H264Picture *cur = h->cur_pic_ptr;
1192 23554 AVFrame *out = cur->f;
1193 23554 int interlaced_frame = 0, top_field_first = 0;
1194 int ret;
1195
1196 23554 out->flags &= ~AV_FRAME_FLAG_INTERLACED;
1197 23554 out->repeat_pict = 0;
1198
1199 /* Signal interlacing information externally. */
1200 /* Prioritize picture timing SEI information over used
1201 * decoding process if it exists. */
1202
2/2
✓ Branch 0 taken 1424 times.
✓ Branch 1 taken 22130 times.
23554 if (h->sei.picture_timing.present) {
1203 1424 int ret = ff_h264_sei_process_picture_timing(&h->sei.picture_timing, sps,
1204 1424 h->avctx);
1205
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1424 times.
1424 if (ret < 0) {
1206 av_log(h->avctx, AV_LOG_ERROR, "Error processing a picture timing SEI\n");
1207 if (h->avctx->err_recognition & AV_EF_EXPLODE)
1208 return ret;
1209 h->sei.picture_timing.present = 0;
1210 }
1211 }
1212
1213
4/4
✓ Branch 0 taken 1502 times.
✓ Branch 1 taken 22052 times.
✓ Branch 2 taken 1416 times.
✓ Branch 3 taken 86 times.
24970 if (sps->pic_struct_present_flag && h->sei.picture_timing.present) {
1214 1416 H264SEIPictureTiming *pt = &h->sei.picture_timing;
1215
4/7
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 376 times.
✓ Branch 2 taken 741 times.
✓ Branch 3 taken 167 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
1416 switch (pt->pic_struct) {
1216 132 case H264_SEI_PIC_STRUCT_FRAME:
1217 132 break;
1218 376 case H264_SEI_PIC_STRUCT_TOP_FIELD:
1219 case H264_SEI_PIC_STRUCT_BOTTOM_FIELD:
1220 376 interlaced_frame = 1;
1221 376 break;
1222 741 case H264_SEI_PIC_STRUCT_TOP_BOTTOM:
1223 case H264_SEI_PIC_STRUCT_BOTTOM_TOP:
1224
3/4
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 737 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
741 if (FIELD_OR_MBAFF_PICTURE(h))
1225 737 interlaced_frame = 1;
1226 else
1227 // try to flag soft telecine progressive
1228 4 interlaced_frame = !!h->prev_interlaced_frame;
1229 741 break;
1230 167 case H264_SEI_PIC_STRUCT_TOP_BOTTOM_TOP:
1231 case H264_SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM:
1232 /* Signal the possibility of telecined film externally
1233 * (pic_struct 5,6). From these hints, let the applications
1234 * decide if they apply deinterlacing. */
1235 167 out->repeat_pict = 1;
1236 167 break;
1237 case H264_SEI_PIC_STRUCT_FRAME_DOUBLING:
1238 out->repeat_pict = 2;
1239 break;
1240 case H264_SEI_PIC_STRUCT_FRAME_TRIPLING:
1241 out->repeat_pict = 4;
1242 break;
1243 }
1244
1245
2/2
✓ Branch 0 taken 651 times.
✓ Branch 1 taken 765 times.
1416 if ((pt->ct_type & 3) &&
1246
2/2
✓ Branch 0 taken 487 times.
✓ Branch 1 taken 164 times.
651 pt->pic_struct <= H264_SEI_PIC_STRUCT_BOTTOM_TOP)
1247 487 interlaced_frame = ((pt->ct_type & (1 << 1)) != 0);
1248 } else {
1249 /* Derive interlacing flag from used decoding process. */
1250
4/4
✓ Branch 0 taken 20551 times.
✓ Branch 1 taken 1587 times.
✓ Branch 2 taken 2821 times.
✓ Branch 3 taken 17730 times.
22138 interlaced_frame = !!FIELD_OR_MBAFF_PICTURE(h);
1251 }
1252 23554 h->prev_interlaced_frame = interlaced_frame;
1253
1254
2/2
✓ Branch 0 taken 3334 times.
✓ Branch 1 taken 20220 times.
23554 if (cur->field_poc[0] != cur->field_poc[1]) {
1255 /* Derive top_field_first from field pocs. */
1256 3334 top_field_first = (cur->field_poc[0] < cur->field_poc[1]);
1257 } else {
1258
4/4
✓ Branch 0 taken 225 times.
✓ Branch 1 taken 19995 times.
✓ Branch 2 taken 139 times.
✓ Branch 3 taken 86 times.
20220 if (sps->pic_struct_present_flag && h->sei.picture_timing.present) {
1259 /* Use picture timing SEI information. Even if it is a
1260 * information of a past frame, better than nothing. */
1261
2/2
✓ Branch 0 taken 138 times.
✓ Branch 1 taken 1 times.
139 if (h->sei.picture_timing.pic_struct == H264_SEI_PIC_STRUCT_TOP_BOTTOM ||
1262
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 136 times.
138 h->sei.picture_timing.pic_struct == H264_SEI_PIC_STRUCT_TOP_BOTTOM_TOP)
1263 3 top_field_first = 1;
1264
2/2
✓ Branch 0 taken 2554 times.
✓ Branch 1 taken 17527 times.
20081 } else if (interlaced_frame) {
1265 /* Default to top field first when pic_struct_present_flag
1266 * is not set but interlaced frame detected */
1267 2554 top_field_first = 1;
1268 } // else
1269 /* Most likely progressive */
1270 }
1271
1272 23554 out->flags |= (AV_FRAME_FLAG_INTERLACED * interlaced_frame) |
1273 23554 (AV_FRAME_FLAG_TOP_FIELD_FIRST * top_field_first);
1274
1275 23554 ret = ff_h2645_sei_to_frame(out, &h->sei.common, AV_CODEC_ID_H264, h->avctx,
1276 23554 &sps->vui, sps->bit_depth_luma, sps->bit_depth_chroma,
1277 23554 cur->poc + (unsigned)(h->poc_offset << 5));
1278
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23554 times.
23554 if (ret < 0)
1279 return ret;
1280
1281
2/2
✓ Branch 0 taken 651 times.
✓ Branch 1 taken 22903 times.
23554 if (h->sei.picture_timing.timecode_cnt > 0) {
1282 uint32_t *tc_sd;
1283 char tcbuf[AV_TIMECODE_STR_SIZE];
1284
1285 651 AVFrameSideData *tcside = av_frame_new_side_data(out,
1286 AV_FRAME_DATA_S12M_TIMECODE,
1287 sizeof(uint32_t)*4);
1288
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 651 times.
651 if (!tcside)
1289 return AVERROR(ENOMEM);
1290
1291 651 tc_sd = (uint32_t*)tcside->data;
1292 651 tc_sd[0] = h->sei.picture_timing.timecode_cnt;
1293
1294
2/2
✓ Branch 0 taken 952 times.
✓ Branch 1 taken 651 times.
1603 for (int i = 0; i < tc_sd[0]; i++) {
1295 952 int drop = h->sei.picture_timing.timecode[i].dropframe;
1296 952 int hh = h->sei.picture_timing.timecode[i].hours;
1297 952 int mm = h->sei.picture_timing.timecode[i].minutes;
1298 952 int ss = h->sei.picture_timing.timecode[i].seconds;
1299 952 int ff = h->sei.picture_timing.timecode[i].frame;
1300
1301 952 tc_sd[i + 1] = av_timecode_get_smpte(h->avctx->framerate, drop, hh, mm, ss, ff);
1302 952 av_timecode_make_smpte_tc_string2(tcbuf, h->avctx->framerate, tc_sd[i + 1], 0, 0);
1303 952 av_dict_set(&out->metadata, "timecode", tcbuf, 0);
1304 }
1305 651 h->sei.picture_timing.timecode_cnt = 0;
1306 }
1307
1308 23554 return 0;
1309 }
1310
1311 23554 static int h264_select_output_frame(H264Context *h)
1312 {
1313 23554 const SPS *sps = h->ps.sps;
1314 23554 H264Picture *out = h->cur_pic_ptr;
1315 23554 H264Picture *cur = h->cur_pic_ptr;
1316 int i, pics, out_of_order, out_idx;
1317
1318 23554 cur->mmco_reset = h->mmco_reset;
1319 23554 h->mmco_reset = 0;
1320
1321
2/2
✓ Branch 0 taken 20018 times.
✓ Branch 1 taken 3536 times.
23554 if (sps->bitstream_restriction_flag ||
1322
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20018 times.
20018 h->avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT) {
1323 3536 h->avctx->has_b_frames = FFMAX(h->avctx->has_b_frames, sps->num_reorder_frames);
1324 }
1325
1326 385951 for (i = 0; 1; i++) {
1327
4/4
✓ Branch 0 taken 370873 times.
✓ Branch 1 taken 15078 times.
✓ Branch 2 taken 8476 times.
✓ Branch 3 taken 362397 times.
385951 if(i == H264_MAX_DPB_FRAMES || cur->poc < h->last_pocs[i]){
1328
1/2
✓ Branch 0 taken 23554 times.
✗ Branch 1 not taken.
23554 if(i)
1329 23554 h->last_pocs[i-1] = cur->poc;
1330 23554 break;
1331
2/2
✓ Branch 0 taken 338843 times.
✓ Branch 1 taken 23554 times.
362397 } else if(i) {
1332 338843 h->last_pocs[i-1]= h->last_pocs[i];
1333 }
1334 }
1335 23554 out_of_order = H264_MAX_DPB_FRAMES - i;
1336
2/2
✓ Branch 0 taken 15969 times.
✓ Branch 1 taken 7585 times.
23554 if( cur->f->pict_type == AV_PICTURE_TYPE_B
1337
4/4
✓ Branch 0 taken 14866 times.
✓ Branch 1 taken 1103 times.
✓ Branch 2 taken 4641 times.
✓ Branch 3 taken 10225 times.
15969 || (h->last_pocs[H264_MAX_DPB_FRAMES-2] > INT_MIN && h->last_pocs[H264_MAX_DPB_FRAMES-1] - (int64_t)h->last_pocs[H264_MAX_DPB_FRAMES-2] > 2))
1338 12226 out_of_order = FFMAX(out_of_order, 1);
1339
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23554 times.
23554 if (out_of_order == H264_MAX_DPB_FRAMES) {
1340 av_log(h->avctx, AV_LOG_VERBOSE, "Invalid POC %d<%d\n", cur->poc, h->last_pocs[0]);
1341 for (i = 1; i < H264_MAX_DPB_FRAMES; i++)
1342 h->last_pocs[i] = INT_MIN;
1343 h->last_pocs[0] = cur->poc;
1344 cur->mmco_reset = 1;
1345
3/4
✓ Branch 0 taken 140 times.
✓ Branch 1 taken 23414 times.
✓ Branch 2 taken 140 times.
✗ Branch 3 not taken.
23554 } else if(h->avctx->has_b_frames < out_of_order && !sps->bitstream_restriction_flag){
1346
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 107 times.
140 int loglevel = h->avctx->frame_num > 1 ? AV_LOG_WARNING : AV_LOG_VERBOSE;
1347 140 av_log(h->avctx, loglevel, "Increasing reorder buffer to %d\n", out_of_order);
1348 140 h->avctx->has_b_frames = out_of_order;
1349 }
1350
1351 23554 pics = 0;
1352
2/2
✓ Branch 0 taken 29181 times.
✓ Branch 1 taken 23554 times.
52735 while (h->delayed_pic[pics])
1353 29181 pics++;
1354
1355
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23554 times.
23554 av_assert0(pics <= H264_MAX_DPB_FRAMES);
1356
1357 23554 h->delayed_pic[pics++] = cur;
1358
2/2
✓ Branch 0 taken 22079 times.
✓ Branch 1 taken 1475 times.
23554 if (cur->reference == 0)
1359 22079 cur->reference = DELAYED_PIC_REF;
1360
1361 23554 out = h->delayed_pic[0];
1362 23554 out_idx = 0;
1363 23554 for (i = 1; h->delayed_pic[i] &&
1364
4/4
✓ Branch 0 taken 26731 times.
✓ Branch 1 taken 23098 times.
✓ Branch 2 taken 26362 times.
✓ Branch 3 taken 369 times.
49829 !(h->delayed_pic[i]->f->flags & AV_FRAME_FLAG_KEY) &&
1365
2/2
✓ Branch 0 taken 26275 times.
✓ Branch 1 taken 87 times.
26362 !h->delayed_pic[i]->mmco_reset;
1366 26275 i++)
1367
2/2
✓ Branch 0 taken 9774 times.
✓ Branch 1 taken 16501 times.
26275 if (h->delayed_pic[i]->poc < out->poc) {
1368 9774 out = h->delayed_pic[i];
1369 9774 out_idx = i;
1370 }
1371
2/2
✓ Branch 0 taken 10257 times.
✓ Branch 1 taken 13297 times.
23554 if (h->avctx->has_b_frames == 0 &&
1372
4/4
✓ Branch 0 taken 9465 times.
✓ Branch 1 taken 792 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 9453 times.
10257 ((h->delayed_pic[0]->f->flags & AV_FRAME_FLAG_KEY) || h->delayed_pic[0]->mmco_reset))
1373 804 h->next_outputed_poc = INT_MIN;
1374 23554 out_of_order = out->poc < h->next_outputed_poc;
1375
1376
4/4
✓ Branch 0 taken 23441 times.
✓ Branch 1 taken 113 times.
✓ Branch 2 taken 22931 times.
✓ Branch 3 taken 510 times.
23554 if (out_of_order || pics > h->avctx->has_b_frames) {
1377 23044 out->reference &= ~DELAYED_PIC_REF;
1378
2/2
✓ Branch 0 taken 37365 times.
✓ Branch 1 taken 23044 times.
60409 for (i = out_idx; h->delayed_pic[i]; i++)
1379 37365 h->delayed_pic[i] = h->delayed_pic[i + 1];
1380 }
1381
4/4
✓ Branch 0 taken 23441 times.
✓ Branch 1 taken 113 times.
✓ Branch 2 taken 22931 times.
✓ Branch 3 taken 510 times.
23554 if (!out_of_order && pics > h->avctx->has_b_frames) {
1382 22931 h->next_output_pic = out;
1383
8/8
✓ Branch 0 taken 14677 times.
✓ Branch 1 taken 8254 times.
✓ Branch 2 taken 4421 times.
✓ Branch 3 taken 10256 times.
✓ Branch 4 taken 4347 times.
✓ Branch 5 taken 74 times.
✓ Branch 6 taken 21 times.
✓ Branch 7 taken 4326 times.
22931 if (out_idx == 0 && h->delayed_pic[0] && ((h->delayed_pic[0]->f->flags & AV_FRAME_FLAG_KEY) || h->delayed_pic[0]->mmco_reset)) {
1384 95 h->next_outputed_poc = INT_MIN;
1385 } else
1386 22836 h->next_outputed_poc = out->poc;
1387
1388
2/2
✓ Branch 0 taken 22840 times.
✓ Branch 1 taken 91 times.
22931 if (out->recovered) {
1389 // We have reached an recovery point and all frames after it in
1390 // display order are "recovered".
1391 22840 h->frame_recovered |= FRAME_RECOVERED_SEI;
1392 }
1393 22931 out->recovered |= !!(h->frame_recovered & FRAME_RECOVERED_SEI);
1394
1395
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 22853 times.
22931 if (!out->recovered) {
1396
1/2
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
78 if (!(h->avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) &&
1397
1/2
✓ Branch 0 taken 78 times.
✗ Branch 1 not taken.
78 !(h->avctx->flags2 & AV_CODEC_FLAG2_SHOW_ALL)) {
1398 78 h->next_output_pic = NULL;
1399 } else {
1400 out->f->flags |= AV_FRAME_FLAG_CORRUPT;
1401 }
1402 }
1403 } else {
1404
2/2
✓ Branch 0 taken 113 times.
✓ Branch 1 taken 510 times.
623 av_log(h->avctx, AV_LOG_DEBUG, "no picture %s\n", out_of_order ? "ooo" : "");
1405 }
1406
1407 23554 return 0;
1408 }
1409
1410 /* This function is called right after decoding the slice header for a first
1411 * slice in a field (or a frame). It decides whether we are decoding a new frame
1412 * or a second field in a pair and does the necessary setup.
1413 */
1414 26920 static int h264_field_start(H264Context *h, const H264SliceContext *sl,
1415 const H2645NAL *nal, int first_slice)
1416 {
1417 int i;
1418 const SPS *sps;
1419
1420 int last_pic_structure, last_pic_droppable, ret;
1421
1422 26920 ret = h264_init_ps(h, sl, first_slice);
1423
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26920 times.
26920 if (ret < 0)
1424 return ret;
1425
1426 26920 sps = h->ps.sps;
1427
1428
3/4
✓ Branch 0 taken 26920 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3868 times.
✓ Branch 3 taken 23052 times.
26920 if (sps && sps->bitstream_restriction_flag &&
1429
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 3841 times.
3868 h->avctx->has_b_frames < sps->num_reorder_frames) {
1430 27 h->avctx->has_b_frames = sps->num_reorder_frames;
1431 }
1432
1433 26920 last_pic_droppable = h->droppable;
1434 26920 last_pic_structure = h->picture_structure;
1435 26920 h->droppable = (nal->ref_idc == 0);
1436 26920 h->picture_structure = sl->picture_structure;
1437
1438 26920 h->poc.frame_num = sl->frame_num;
1439 26920 h->poc.poc_lsb = sl->poc_lsb;
1440 26920 h->poc.delta_poc_bottom = sl->delta_poc_bottom;
1441 26920 h->poc.delta_poc[0] = sl->delta_poc[0];
1442 26920 h->poc.delta_poc[1] = sl->delta_poc[1];
1443
1444
2/2
✓ Branch 0 taken 1059 times.
✓ Branch 1 taken 25861 times.
26920 if (nal->type == H264_NAL_IDR_SLICE)
1445 1059 h->poc_offset = sl->idr_pic_id;
1446
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 25861 times.
25861 else if (h->picture_intra_only)
1447 h->poc_offset = 0;
1448
1449 /* Shorten frame num gaps so we don't have to allocate reference
1450 * frames just to throw them away */
1451
2/2
✓ Branch 0 taken 15330 times.
✓ Branch 1 taken 11590 times.
26920 if (h->poc.frame_num != h->poc.prev_frame_num) {
1452 15330 int unwrap_prev_frame_num = h->poc.prev_frame_num;
1453 15330 int max_frame_num = 1 << sps->log2_max_frame_num;
1454
1455
2/2
✓ Branch 0 taken 169 times.
✓ Branch 1 taken 15161 times.
15330 if (unwrap_prev_frame_num > h->poc.frame_num)
1456 169 unwrap_prev_frame_num -= max_frame_num;
1457
1458
2/2
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 15262 times.
15330 if ((h->poc.frame_num - unwrap_prev_frame_num) > sps->ref_frame_count) {
1459 68 unwrap_prev_frame_num = (h->poc.frame_num - sps->ref_frame_count) - 1;
1460
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 66 times.
68 if (unwrap_prev_frame_num < 0)
1461 2 unwrap_prev_frame_num += max_frame_num;
1462
1463 68 h->poc.prev_frame_num = unwrap_prev_frame_num;
1464 }
1465 }
1466
1467 /* See if we have a decoded first field looking for a pair...
1468 * Here, we're using that to see if we should mark previously
1469 * decode frames as "finished".
1470 * We have to do that before the "dummy" in-between frame allocation,
1471 * since that can modify h->cur_pic_ptr. */
1472
2/2
✓ Branch 0 taken 3361 times.
✓ Branch 1 taken 23559 times.
26920 if (h->first_field) {
1473 3361 int last_field = last_pic_structure == PICT_BOTTOM_FIELD;
1474
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3361 times.
3361 av_assert0(h->cur_pic_ptr);
1475
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3361 times.
3361 av_assert0(h->cur_pic_ptr->f->buf[0]);
1476 assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF);
1477
1478 /* Mark old field/frame as completed */
1479
1/2
✓ Branch 0 taken 3361 times.
✗ Branch 1 not taken.
3361 if (h->cur_pic_ptr->tf.owner[last_field] == h->avctx) {
1480 3361 ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, last_field);
1481 }
1482
1483 /* figure out if we have a complementary field pair */
1484
2/4
✓ Branch 0 taken 3361 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3361 times.
3361 if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) {
1485 /* Previous field is unmatched. Don't display it, but let it
1486 * remain for reference if marked as such. */
1487 if (last_pic_structure != PICT_FRAME) {
1488 ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,
1489 last_pic_structure == PICT_TOP_FIELD);
1490 }
1491 } else {
1492
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3361 times.
3361 if (h->cur_pic_ptr->frame_num != h->poc.frame_num) {
1493 /* This and previous field were reference, but had
1494 * different frame_nums. Consider this field first in
1495 * pair. Throw away previous field except for reference
1496 * purposes. */
1497 if (last_pic_structure != PICT_FRAME) {
1498 ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,
1499 last_pic_structure == PICT_TOP_FIELD);
1500 }
1501 } else {
1502 /* Second field in complementary pair */
1503
3/4
✓ Branch 0 taken 3353 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
3361 if (!((last_pic_structure == PICT_TOP_FIELD &&
1504
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3353 times.
3353 h->picture_structure == PICT_BOTTOM_FIELD) ||
1505 8 (last_pic_structure == PICT_BOTTOM_FIELD &&
1506
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 h->picture_structure == PICT_TOP_FIELD))) {
1507 av_log(h->avctx, AV_LOG_ERROR,
1508 "Invalid field mode combination %d/%d\n",
1509 last_pic_structure, h->picture_structure);
1510 h->picture_structure = last_pic_structure;
1511 h->droppable = last_pic_droppable;
1512 return AVERROR_INVALIDDATA;
1513
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3361 times.
3361 } else if (last_pic_droppable != h->droppable) {
1514 avpriv_request_sample(h->avctx,
1515 "Found reference and non-reference fields in the same frame, which");
1516 h->picture_structure = last_pic_structure;
1517 h->droppable = last_pic_droppable;
1518 return AVERROR_PATCHWELCOME;
1519 }
1520 }
1521 }
1522 }
1523
1524
3/4
✓ Branch 0 taken 16003 times.
✓ Branch 1 taken 11590 times.
✓ Branch 2 taken 16003 times.
✗ Branch 3 not taken.
54513 while (h->poc.frame_num != h->poc.prev_frame_num && !h->first_field &&
1525
2/2
✓ Branch 0 taken 673 times.
✓ Branch 1 taken 15330 times.
16003 h->poc.frame_num != (h->poc.prev_frame_num + 1) % (1 << sps->log2_max_frame_num)) {
1526
2/2
✓ Branch 0 taken 647 times.
✓ Branch 1 taken 26 times.
673 const H264Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL;
1527 673 av_log(h->avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n",
1528 h->poc.frame_num, h->poc.prev_frame_num);
1529
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 577 times.
673 if (!sps->gaps_in_frame_num_allowed_flag)
1530
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 96 times.
1632 for(i=0; i<FF_ARRAY_ELEMS(h->last_pocs); i++)
1531 1536 h->last_pocs[i] = INT_MIN;
1532 673 ret = h264_frame_start(h);
1533
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 673 times.
673 if (ret < 0) {
1534 h->first_field = 0;
1535 return ret;
1536 }
1537
1538 673 h->poc.prev_frame_num++;
1539 673 h->poc.prev_frame_num %= 1 << sps->log2_max_frame_num;
1540 673 h->cur_pic_ptr->frame_num = h->poc.prev_frame_num;
1541 673 h->cur_pic_ptr->invalid_gap = !sps->gaps_in_frame_num_allowed_flag;
1542 673 ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 0);
1543 673 ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 1);
1544
1545 673 h->explicit_ref_marking = 0;
1546 673 ret = ff_h264_execute_ref_pic_marking(h);
1547
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 673 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
673 if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
1548 return ret;
1549 /* Error concealment: If a ref is missing, copy the previous ref
1550 * in its place.
1551 * FIXME: Avoiding a memcpy would be nice, but ref handling makes
1552 * many assumptions about there being no actual duplicates.
1553 * FIXME: This does not copy padding for out-of-frame motion
1554 * vectors. Given we are concealing a lost frame, this probably
1555 * is not noticeable by comparison, but it should be fixed. */
1556
1/2
✓ Branch 0 taken 673 times.
✗ Branch 1 not taken.
673 if (h->short_ref_count) {
1557 673 int c[4] = {
1558 673 1<<(h->ps.sps->bit_depth_luma-1),
1559 673 1<<(h->ps.sps->bit_depth_chroma-1),
1560 673 1<<(h->ps.sps->bit_depth_chroma-1),
1561 -1
1562 };
1563
1564
2/2
✓ Branch 0 taken 647 times.
✓ Branch 1 taken 26 times.
673 if (prev &&
1565
1/2
✓ Branch 0 taken 647 times.
✗ Branch 1 not taken.
647 h->short_ref[0]->f->width == prev->f->width &&
1566
1/2
✓ Branch 0 taken 647 times.
✗ Branch 1 not taken.
647 h->short_ref[0]->f->height == prev->f->height &&
1567
1/2
✓ Branch 0 taken 647 times.
✗ Branch 1 not taken.
647 h->short_ref[0]->f->format == prev->f->format) {
1568 647 ff_thread_await_progress(&prev->tf, INT_MAX, 0);
1569
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 619 times.
647 if (prev->field_picture)
1570 28 ff_thread_await_progress(&prev->tf, INT_MAX, 1);
1571 647 ff_thread_release_ext_buffer(h->avctx, &h->short_ref[0]->tf);
1572 647 h->short_ref[0]->tf.f = h->short_ref[0]->f;
1573 647 ret = ff_thread_ref_frame(&h->short_ref[0]->tf, &prev->tf);
1574
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 647 times.
647 if (ret < 0)
1575 return ret;
1576 647 h->short_ref[0]->poc = prev->poc + 2U;
1577 647 ff_thread_report_progress(&h->short_ref[0]->tf, INT_MAX, 0);
1578
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 619 times.
647 if (h->short_ref[0]->field_picture)
1579 28 ff_thread_report_progress(&h->short_ref[0]->tf, INT_MAX, 1);
1580
3/4
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
26 } else if (!h->frame_recovered && !h->avctx->hwaccel)
1581 18 color_frame(h->short_ref[0]->f, c);
1582 673 h->short_ref[0]->frame_num = h->poc.prev_frame_num;
1583 }
1584 }
1585
1586 /* See if we have a decoded first field looking for a pair...
1587 * We're using that to see whether to continue decoding in that
1588 * frame, or to allocate a new one. */
1589
2/2
✓ Branch 0 taken 3361 times.
✓ Branch 1 taken 23559 times.
26920 if (h->first_field) {
1590
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3361 times.
3361 av_assert0(h->cur_pic_ptr);
1591
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3361 times.
3361 av_assert0(h->cur_pic_ptr->f->buf[0]);
1592 assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF);
1593
1594 /* figure out if we have a complementary field pair */
1595
2/4
✓ Branch 0 taken 3361 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3361 times.
3361 if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) {
1596 /* Previous field is unmatched. Don't display it, but let it
1597 * remain for reference if marked as such. */
1598 h->missing_fields ++;
1599 h->cur_pic_ptr = NULL;
1600 h->first_field = FIELD_PICTURE(h);
1601 } else {
1602 3361 h->missing_fields = 0;
1603
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3361 times.
3361 if (h->cur_pic_ptr->frame_num != h->poc.frame_num) {
1604 ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX,
1605 h->picture_structure==PICT_BOTTOM_FIELD);
1606 /* This and the previous field had different frame_nums.
1607 * Consider this field first in pair. Throw away previous
1608 * one except for reference purposes. */
1609 h->first_field = 1;
1610 h->cur_pic_ptr = NULL;
1611
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3361 times.
3361 } else if (h->cur_pic_ptr->reference & DELAYED_PIC_REF) {
1612 /* This frame was already output, we cannot draw into it
1613 * anymore.
1614 */
1615 h->first_field = 1;
1616 h->cur_pic_ptr = NULL;
1617 } else {
1618 /* Second field in complementary pair */
1619 3361 h->first_field = 0;
1620 }
1621 }
1622 } else {
1623 /* Frame or first field in a potentially complementary pair */
1624 23559 h->first_field = FIELD_PICTURE(h);
1625 }
1626
1627
4/4
✓ Branch 0 taken 6727 times.
✓ Branch 1 taken 20193 times.
✓ Branch 2 taken 3366 times.
✓ Branch 3 taken 3361 times.
26920 if (!FIELD_PICTURE(h) || h->first_field) {
1628
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 23559 times.
23559 if (h264_frame_start(h) < 0) {
1629 h->first_field = 0;
1630 return AVERROR_INVALIDDATA;
1631 }
1632 } else {
1633 3361 int field = h->picture_structure == PICT_BOTTOM_FIELD;
1634 3361 release_unused_pictures(h, 0);
1635 3361 h->cur_pic_ptr->tf.owner[field] = h->avctx;
1636 }
1637 /* Some macroblocks can be accessed before they're available in case
1638 * of lost slices, MBAFF or threading. */
1639
2/2
✓ Branch 0 taken 6727 times.
✓ Branch 1 taken 20193 times.
26920 if (FIELD_PICTURE(h)) {
1640
2/2
✓ Branch 0 taken 168207 times.
✓ Branch 1 taken 6727 times.
174934 for(i = (h->picture_structure == PICT_BOTTOM_FIELD); i<h->mb_height; i++)
1641 168207 memset(h->slice_table + i*h->mb_stride, -1, (h->mb_stride - (i+1==h->mb_height)) * sizeof(*h->slice_table));
1642 } else {
1643 20193 memset(h->slice_table, -1,
1644 20193 (h->mb_height * h->mb_stride - 1) * sizeof(*h->slice_table));
1645 }
1646
1647 26920 ret = ff_h264_init_poc(h->cur_pic_ptr->field_poc, &h->cur_pic_ptr->poc,
1648 26920 h->ps.sps, &h->poc, h->picture_structure, nal->ref_idc);
1649
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26920 times.
26920 if (ret < 0)
1650 return ret;
1651
1652 26920 memcpy(h->mmco, sl->mmco, sl->nb_mmco * sizeof(*h->mmco));
1653 26920 h->nb_mmco = sl->nb_mmco;
1654 26920 h->explicit_ref_marking = sl->explicit_ref_marking;
1655
1656 26920 h->picture_idr = nal->type == H264_NAL_IDR_SLICE;
1657
1658
2/2
✓ Branch 0 taken 66 times.
✓ Branch 1 taken 26854 times.
26920 if (h->sei.recovery_point.recovery_frame_cnt >= 0) {
1659 66 const int sei_recovery_frame_cnt = h->sei.recovery_point.recovery_frame_cnt;
1660
1661
4/4
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 41 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 14 times.
66 if (h->poc.frame_num != sei_recovery_frame_cnt || sl->slice_type_nos != AV_PICTURE_TYPE_I)
1662 52 h->valid_recovery_point = 1;
1663
1664
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 65 times.
66 if ( h->recovery_frame < 0
1665
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 || av_mod_uintp2(h->recovery_frame - h->poc.frame_num, h->ps.sps->log2_max_frame_num) > sei_recovery_frame_cnt) {
1666 65 h->recovery_frame = av_mod_uintp2(h->poc.frame_num + sei_recovery_frame_cnt, h->ps.sps->log2_max_frame_num);
1667
1668
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 59 times.
65 if (!h->valid_recovery_point)
1669 6 h->recovery_frame = h->poc.frame_num;
1670 }
1671 }
1672
1673
2/2
✓ Branch 0 taken 1059 times.
✓ Branch 1 taken 25861 times.
26920 h->cur_pic_ptr->f->flags |= AV_FRAME_FLAG_KEY * !!(nal->type == H264_NAL_IDR_SLICE);
1674
1675
2/2
✓ Branch 0 taken 25861 times.
✓ Branch 1 taken 1059 times.
26920 if (nal->type == H264_NAL_IDR_SLICE ||
1676
4/4
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 25806 times.
✓ Branch 2 taken 53 times.
✓ Branch 3 taken 2 times.
25861 (h->recovery_frame == h->poc.frame_num && nal->ref_idc)) {
1677 1112 h->recovery_frame = -1;
1678 1112 h->cur_pic_ptr->recovered = 1;
1679 }
1680 // If we have an IDR, all frames after it in decoded order are
1681 // "recovered".
1682
2/2
✓ Branch 0 taken 1059 times.
✓ Branch 1 taken 25861 times.
26920 if (nal->type == H264_NAL_IDR_SLICE)
1683 1059 h->frame_recovered |= FRAME_RECOVERED_IDR;
1684 #if 1
1685 26920 h->cur_pic_ptr->recovered |= h->frame_recovered;
1686 #else
1687 h->cur_pic_ptr->recovered |= !!(h->frame_recovered & FRAME_RECOVERED_IDR);
1688 #endif
1689
1690 /* Set the frame properties/side data. Only done for the second field in
1691 * field coded frames, since some SEI information is present for each field
1692 * and is merged by the SEI parsing code. */
1693
5/6
✓ Branch 0 taken 6727 times.
✓ Branch 1 taken 20193 times.
✓ Branch 2 taken 3366 times.
✓ Branch 3 taken 3361 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3366 times.
26920 if (!FIELD_PICTURE(h) || !h->first_field || h->missing_fields > 1) {
1694 23554 ret = h264_export_frame_props(h);
1695
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23554 times.
23554 if (ret < 0)
1696 return ret;
1697
1698 23554 ret = h264_select_output_frame(h);
1699
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 23554 times.
23554 if (ret < 0)
1700 return ret;
1701 }
1702
1703 26920 return 0;
1704 }
1705
1706 36240 static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl,
1707 const H2645NAL *nal)
1708 {
1709 const SPS *sps;
1710 const PPS *pps;
1711 int ret;
1712 unsigned int slice_type, tmp, i;
1713 int field_pic_flag, bottom_field_flag;
1714
4/4
✓ Branch 0 taken 35790 times.
✓ Branch 1 taken 450 times.
✓ Branch 2 taken 26970 times.
✓ Branch 3 taken 8820 times.
36240 int first_slice = sl == h->slice_ctx && !h->current_slice;
1715 int picture_structure;
1716
1717
2/2
✓ Branch 0 taken 26970 times.
✓ Branch 1 taken 9270 times.
36240 if (first_slice)
1718
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 26970 times.
26970 av_assert0(!h->setup_finished);
1719
1720 36240 sl->first_mb_addr = get_ue_golomb_long(&sl->gb);
1721
1722 36240 slice_type = get_ue_golomb_31(&sl->gb);
1723
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36240 times.
36240 if (slice_type > 9) {
1724 av_log(h->avctx, AV_LOG_ERROR,
1725 "slice type %d too large at %d\n",
1726 slice_type, sl->first_mb_addr);
1727 return AVERROR_INVALIDDATA;
1728 }
1729
2/2
✓ Branch 0 taken 22516 times.
✓ Branch 1 taken 13724 times.
36240 if (slice_type > 4) {
1730 22516 slice_type -= 5;
1731 22516 sl->slice_type_fixed = 1;
1732 } else
1733 13724 sl->slice_type_fixed = 0;
1734
1735 36240 slice_type = ff_h264_golomb_to_pict_type[slice_type];
1736 36240 sl->slice_type = slice_type;
1737 36240 sl->slice_type_nos = slice_type & 3;
1738
1739
2/2
✓ Branch 0 taken 2245 times.
✓ Branch 1 taken 33995 times.
36240 if (nal->type == H264_NAL_IDR_SLICE &&
1740
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2245 times.
2245 sl->slice_type_nos != AV_PICTURE_TYPE_I) {
1741 av_log(h->avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\n");
1742 return AVERROR_INVALIDDATA;
1743 }
1744
1745 36240 sl->pps_id = get_ue_golomb(&sl->gb);
1746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36240 times.
36240 if (sl->pps_id >= MAX_PPS_COUNT) {
1747 av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", sl->pps_id);
1748 return AVERROR_INVALIDDATA;
1749 }
1750
2/2
✓ Branch 0 taken 167 times.
✓ Branch 1 taken 36073 times.
36240 if (!h->ps.pps_list[sl->pps_id]) {
1751 167 av_log(h->avctx, AV_LOG_ERROR,
1752 "non-existing PPS %u referenced\n",
1753 sl->pps_id);
1754 167 return AVERROR_INVALIDDATA;
1755 }
1756 36073 pps = (const PPS*)h->ps.pps_list[sl->pps_id]->data;
1757 36073 sps = pps->sps;
1758
1759 36073 sl->frame_num = get_bits(&sl->gb, sps->log2_max_frame_num);
1760
2/2
✓ Branch 0 taken 9266 times.
✓ Branch 1 taken 26807 times.
36073 if (!first_slice) {
1761
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9266 times.
9266 if (h->poc.frame_num != sl->frame_num) {
1762 av_log(h->avctx, AV_LOG_ERROR, "Frame num change from %d to %d\n",
1763 h->poc.frame_num, sl->frame_num);
1764 return AVERROR_INVALIDDATA;
1765 }
1766 }
1767
1768 36073 sl->mb_mbaff = 0;
1769
1770
2/2
✓ Branch 0 taken 21582 times.
✓ Branch 1 taken 14491 times.
36073 if (sps->frame_mbs_only_flag) {
1771 21582 picture_structure = PICT_FRAME;
1772 } else {
1773
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 14491 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14491 if (!sps->direct_8x8_inference_flag && slice_type == AV_PICTURE_TYPE_B) {
1774 av_log(h->avctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\n");
1775 return -1;
1776 }
1777 14491 field_pic_flag = get_bits1(&sl->gb);
1778
2/2
✓ Branch 0 taken 9024 times.
✓ Branch 1 taken 5467 times.
14491 if (field_pic_flag) {
1779 9024 bottom_field_flag = get_bits1(&sl->gb);
1780 9024 picture_structure = PICT_TOP_FIELD + bottom_field_flag;
1781 } else {
1782 5467 picture_structure = PICT_FRAME;
1783 }
1784 }
1785 36073 sl->picture_structure = picture_structure;
1786 36073 sl->mb_field_decoding_flag = picture_structure != PICT_FRAME;
1787
1788
2/2
✓ Branch 0 taken 27049 times.
✓ Branch 1 taken 9024 times.
36073 if (picture_structure == PICT_FRAME) {
1789 27049 sl->curr_pic_num = sl->frame_num;
1790 27049 sl->max_pic_num = 1 << sps->log2_max_frame_num;
1791 } else {
1792 9024 sl->curr_pic_num = 2 * sl->frame_num + 1;
1793 9024 sl->max_pic_num = 1 << (sps->log2_max_frame_num + 1);
1794 }
1795
1796
2/2
✓ Branch 0 taken 2240 times.
✓ Branch 1 taken 33833 times.
36073 if (nal->type == H264_NAL_IDR_SLICE) {
1797 2240 unsigned idr_pic_id = get_ue_golomb_long(&sl->gb);
1798
1/2
✓ Branch 0 taken 2240 times.
✗ Branch 1 not taken.
2240 if (idr_pic_id < 65536) {
1799 2240 sl->idr_pic_id = idr_pic_id;
1800 } else
1801 av_log(h->avctx, AV_LOG_WARNING, "idr_pic_id is invalid\n");
1802 }
1803
1804 36073 sl->poc_lsb = 0;
1805 36073 sl->delta_poc_bottom = 0;
1806
2/2
✓ Branch 0 taken 28293 times.
✓ Branch 1 taken 7780 times.
36073 if (sps->poc_type == 0) {
1807 28293 sl->poc_lsb = get_bits(&sl->gb, sps->log2_max_poc_lsb);
1808
1809
4/4
✓ Branch 0 taken 8522 times.
✓ Branch 1 taken 19771 times.
✓ Branch 2 taken 6630 times.
✓ Branch 3 taken 1892 times.
28293 if (pps->pic_order_present == 1 && picture_structure == PICT_FRAME)
1810 6630 sl->delta_poc_bottom = get_se_golomb(&sl->gb);
1811 }
1812
1813 36073 sl->delta_poc[0] = sl->delta_poc[1] = 0;
1814
4/4
✓ Branch 0 taken 3055 times.
✓ Branch 1 taken 33018 times.
✓ Branch 2 taken 2848 times.
✓ Branch 3 taken 207 times.
36073 if (sps->poc_type == 1 && !sps->delta_pic_order_always_zero_flag) {
1815 2848 sl->delta_poc[0] = get_se_golomb(&sl->gb);
1816
1817
4/4
✓ Branch 0 taken 770 times.
✓ Branch 1 taken 2078 times.
✓ Branch 2 taken 453 times.
✓ Branch 3 taken 317 times.
2848 if (pps->pic_order_present == 1 && picture_structure == PICT_FRAME)
1818 453 sl->delta_poc[1] = get_se_golomb(&sl->gb);
1819 }
1820
1821 36073 sl->redundant_pic_count = 0;
1822
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36073 times.
36073 if (pps->redundant_pic_cnt_present)
1823 sl->redundant_pic_count = get_ue_golomb(&sl->gb);
1824
1825
2/2
✓ Branch 0 taken 12610 times.
✓ Branch 1 taken 23463 times.
36073 if (sl->slice_type_nos == AV_PICTURE_TYPE_B)
1826 12610 sl->direct_spatial_mv_pred = get_bits1(&sl->gb);
1827
1828 36073 ret = ff_h264_parse_ref_count(&sl->list_count, sl->ref_count,
1829 &sl->gb, pps, sl->slice_type_nos,
1830 36073 picture_structure, h->avctx);
1831
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 36073 times.
36073 if (ret < 0)
1832 return ret;
1833
1834
2/2
✓ Branch 0 taken 31625 times.
✓ Branch 1 taken 4448 times.
36073 if (sl->slice_type_nos != AV_PICTURE_TYPE_I) {
1835 31625 ret = ff_h264_decode_ref_pic_list_reordering(sl, h->avctx);
1836
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31625 times.
31625 if (ret < 0) {
1837 sl->ref_count[1] = sl->ref_count[0] = 0;
1838 return ret;
1839 }
1840 }
1841
1842 36073 sl->pwt.use_weight = 0;
1843
2/2
✓ Branch 0 taken 72146 times.
✓ Branch 1 taken 36073 times.
108219 for (i = 0; i < 2; i++) {
1844 72146 sl->pwt.luma_weight_flag[i] = 0;
1845 72146 sl->pwt.chroma_weight_flag[i] = 0;
1846 }
1847
4/4
✓ Branch 0 taken 2946 times.
✓ Branch 1 taken 33127 times.
✓ Branch 2 taken 1076 times.
✓ Branch 3 taken 1870 times.
36073 if ((pps->weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) ||
1848
2/2
✓ Branch 0 taken 386 times.
✓ Branch 1 taken 33817 times.
34203 (pps->weighted_bipred_idc == 1 &&
1849
1/2
✓ Branch 0 taken 386 times.
✗ Branch 1 not taken.
386 sl->slice_type_nos == AV_PICTURE_TYPE_B)) {
1850 2256 ret = ff_h264_pred_weight_table(&sl->gb, sps, sl->ref_count,
1851 sl->slice_type_nos, &sl->pwt,
1852 2256 picture_structure, h->avctx);
1853
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2256 times.
2256 if (ret < 0)
1854 return ret;
1855 }
1856
1857 36073 sl->explicit_ref_marking = 0;
1858
2/2
✓ Branch 0 taken 24123 times.
✓ Branch 1 taken 11950 times.
36073 if (nal->ref_idc) {
1859 24123 ret = ff_h264_decode_ref_pic_marking(sl, &sl->gb, nal, h->avctx);
1860
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 24123 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
24123 if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE))
1861 return AVERROR_INVALIDDATA;
1862 }
1863
1864
4/4
✓ Branch 0 taken 31625 times.
✓ Branch 1 taken 4448 times.
✓ Branch 2 taken 16813 times.
✓ Branch 3 taken 14812 times.
36073 if (sl->slice_type_nos != AV_PICTURE_TYPE_I && pps->cabac) {
1865 16813 tmp = get_ue_golomb_31(&sl->gb);
1866
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16813 times.
16813 if (tmp > 2) {
1867 av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", tmp);
1868 return AVERROR_INVALIDDATA;
1869 }
1870 16813