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/mem.h" | ||
32 | #include "libavutil/pixdesc.h" | ||
33 | #include "libavutil/timecode.h" | ||
34 | #include "decode.h" | ||
35 | #include "cabac.h" | ||
36 | #include "cabac_functions.h" | ||
37 | #include "error_resilience.h" | ||
38 | #include "avcodec.h" | ||
39 | #include "h264.h" | ||
40 | #include "h264dec.h" | ||
41 | #include "h264data.h" | ||
42 | #include "h264chroma.h" | ||
43 | #include "h264_ps.h" | ||
44 | #include "golomb.h" | ||
45 | #include "mathops.h" | ||
46 | #include "mpegutils.h" | ||
47 | #include "rectangle.h" | ||
48 | #include "refstruct.h" | ||
49 | #include "thread.h" | ||
50 | #include "threadframe.h" | ||
51 | |||
52 | static const uint8_t field_scan[16+1] = { | ||
53 | 0 + 0 * 4, 0 + 1 * 4, 1 + 0 * 4, 0 + 2 * 4, | ||
54 | 0 + 3 * 4, 1 + 1 * 4, 1 + 2 * 4, 1 + 3 * 4, | ||
55 | 2 + 0 * 4, 2 + 1 * 4, 2 + 2 * 4, 2 + 3 * 4, | ||
56 | 3 + 0 * 4, 3 + 1 * 4, 3 + 2 * 4, 3 + 3 * 4, | ||
57 | }; | ||
58 | |||
59 | static const uint8_t field_scan8x8[64+1] = { | ||
60 | 0 + 0 * 8, 0 + 1 * 8, 0 + 2 * 8, 1 + 0 * 8, | ||
61 | 1 + 1 * 8, 0 + 3 * 8, 0 + 4 * 8, 1 + 2 * 8, | ||
62 | 2 + 0 * 8, 1 + 3 * 8, 0 + 5 * 8, 0 + 6 * 8, | ||
63 | 0 + 7 * 8, 1 + 4 * 8, 2 + 1 * 8, 3 + 0 * 8, | ||
64 | 2 + 2 * 8, 1 + 5 * 8, 1 + 6 * 8, 1 + 7 * 8, | ||
65 | 2 + 3 * 8, 3 + 1 * 8, 4 + 0 * 8, 3 + 2 * 8, | ||
66 | 2 + 4 * 8, 2 + 5 * 8, 2 + 6 * 8, 2 + 7 * 8, | ||
67 | 3 + 3 * 8, 4 + 1 * 8, 5 + 0 * 8, 4 + 2 * 8, | ||
68 | 3 + 4 * 8, 3 + 5 * 8, 3 + 6 * 8, 3 + 7 * 8, | ||
69 | 4 + 3 * 8, 5 + 1 * 8, 6 + 0 * 8, 5 + 2 * 8, | ||
70 | 4 + 4 * 8, 4 + 5 * 8, 4 + 6 * 8, 4 + 7 * 8, | ||
71 | 5 + 3 * 8, 6 + 1 * 8, 6 + 2 * 8, 5 + 4 * 8, | ||
72 | 5 + 5 * 8, 5 + 6 * 8, 5 + 7 * 8, 6 + 3 * 8, | ||
73 | 7 + 0 * 8, 7 + 1 * 8, 6 + 4 * 8, 6 + 5 * 8, | ||
74 | 6 + 6 * 8, 6 + 7 * 8, 7 + 2 * 8, 7 + 3 * 8, | ||
75 | 7 + 4 * 8, 7 + 5 * 8, 7 + 6 * 8, 7 + 7 * 8, | ||
76 | }; | ||
77 | |||
78 | static const uint8_t field_scan8x8_cavlc[64+1] = { | ||
79 | 0 + 0 * 8, 1 + 1 * 8, 2 + 0 * 8, 0 + 7 * 8, | ||
80 | 2 + 2 * 8, 2 + 3 * 8, 2 + 4 * 8, 3 + 3 * 8, | ||
81 | 3 + 4 * 8, 4 + 3 * 8, 4 + 4 * 8, 5 + 3 * 8, | ||
82 | 5 + 5 * 8, 7 + 0 * 8, 6 + 6 * 8, 7 + 4 * 8, | ||
83 | 0 + 1 * 8, 0 + 3 * 8, 1 + 3 * 8, 1 + 4 * 8, | ||
84 | 1 + 5 * 8, 3 + 1 * 8, 2 + 5 * 8, 4 + 1 * 8, | ||
85 | 3 + 5 * 8, 5 + 1 * 8, 4 + 5 * 8, 6 + 1 * 8, | ||
86 | 5 + 6 * 8, 7 + 1 * 8, 6 + 7 * 8, 7 + 5 * 8, | ||
87 | 0 + 2 * 8, 0 + 4 * 8, 0 + 5 * 8, 2 + 1 * 8, | ||
88 | 1 + 6 * 8, 4 + 0 * 8, 2 + 6 * 8, 5 + 0 * 8, | ||
89 | 3 + 6 * 8, 6 + 0 * 8, 4 + 6 * 8, 6 + 2 * 8, | ||
90 | 5 + 7 * 8, 6 + 4 * 8, 7 + 2 * 8, 7 + 6 * 8, | ||
91 | 1 + 0 * 8, 1 + 2 * 8, 0 + 6 * 8, 3 + 0 * 8, | ||
92 | 1 + 7 * 8, 3 + 2 * 8, 2 + 7 * 8, 4 + 2 * 8, | ||
93 | 3 + 7 * 8, 5 + 2 * 8, 4 + 7 * 8, 5 + 4 * 8, | ||
94 | 6 + 3 * 8, 6 + 5 * 8, 7 + 3 * 8, 7 + 7 * 8, | ||
95 | }; | ||
96 | |||
97 | // zigzag_scan8x8_cavlc[i] = zigzag_scan8x8[(i/4) + 16*(i%4)] | ||
98 | static const uint8_t zigzag_scan8x8_cavlc[64+1] = { | ||
99 | 0 + 0 * 8, 1 + 1 * 8, 1 + 2 * 8, 2 + 2 * 8, | ||
100 | 4 + 1 * 8, 0 + 5 * 8, 3 + 3 * 8, 7 + 0 * 8, | ||
101 | 3 + 4 * 8, 1 + 7 * 8, 5 + 3 * 8, 6 + 3 * 8, | ||
102 | 2 + 7 * 8, 6 + 4 * 8, 5 + 6 * 8, 7 + 5 * 8, | ||
103 | 1 + 0 * 8, 2 + 0 * 8, 0 + 3 * 8, 3 + 1 * 8, | ||
104 | 3 + 2 * 8, 0 + 6 * 8, 4 + 2 * 8, 6 + 1 * 8, | ||
105 | 2 + 5 * 8, 2 + 6 * 8, 6 + 2 * 8, 5 + 4 * 8, | ||
106 | 3 + 7 * 8, 7 + 3 * 8, 4 + 7 * 8, 7 + 6 * 8, | ||
107 | 0 + 1 * 8, 3 + 0 * 8, 0 + 4 * 8, 4 + 0 * 8, | ||
108 | 2 + 3 * 8, 1 + 5 * 8, 5 + 1 * 8, 5 + 2 * 8, | ||
109 | 1 + 6 * 8, 3 + 5 * 8, 7 + 1 * 8, 4 + 5 * 8, | ||
110 | 4 + 6 * 8, 7 + 4 * 8, 5 + 7 * 8, 6 + 7 * 8, | ||
111 | 0 + 2 * 8, 2 + 1 * 8, 1 + 3 * 8, 5 + 0 * 8, | ||
112 | 1 + 4 * 8, 2 + 4 * 8, 6 + 0 * 8, 4 + 3 * 8, | ||
113 | 0 + 7 * 8, 4 + 4 * 8, 7 + 2 * 8, 3 + 6 * 8, | ||
114 | 5 + 5 * 8, 6 + 5 * 8, 6 + 6 * 8, 7 + 7 * 8, | ||
115 | }; | ||
116 | |||
117 | 28975 | static void release_unused_pictures(H264Context *h, int remove_current) | |
118 | { | ||
119 | int i; | ||
120 | |||
121 | /* release non reference frames */ | ||
122 |
2/2✓ Branch 0 taken 1043100 times.
✓ Branch 1 taken 28975 times.
|
1072075 | for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) { |
123 |
6/6✓ Branch 0 taken 145918 times.
✓ Branch 1 taken 897182 times.
✓ Branch 2 taken 25350 times.
✓ Branch 3 taken 120568 times.
✓ Branch 4 taken 2610 times.
✓ Branch 5 taken 22740 times.
|
1043100 | if (h->DPB[i].f->buf[0] && !h->DPB[i].reference && |
124 |
2/2✓ Branch 0 taken 723 times.
✓ Branch 1 taken 1887 times.
|
2610 | (remove_current || &h->DPB[i] != h->cur_pic_ptr)) { |
125 | 23463 | ff_h264_unref_picture(&h->DPB[i]); | |
126 | } | ||
127 | } | ||
128 | 28975 | } | |
129 | |||
130 | 37363 | static int alloc_scratch_buffers(H264SliceContext *sl, int linesize) | |
131 | { | ||
132 | 37363 | const H264Context *h = sl->h264; | |
133 | 37363 | int alloc_size = FFALIGN(FFABS(linesize) + 32, 32); | |
134 | |||
135 | 37363 | av_fast_malloc(&sl->bipred_scratchpad, &sl->bipred_scratchpad_allocated, 16 * 6 * alloc_size); | |
136 | // edge emu needs blocksize + filter length - 1 | ||
137 | // (= 21x21 for H.264) | ||
138 | 37363 | av_fast_malloc(&sl->edge_emu_buffer, &sl->edge_emu_buffer_allocated, alloc_size * 2 * 21); | |
139 | |||
140 | 37363 | av_fast_mallocz(&sl->top_borders[0], &sl->top_borders_allocated[0], | |
141 | 37363 | h->mb_width * 16 * 3 * sizeof(uint8_t) * 2); | |
142 | 37363 | av_fast_mallocz(&sl->top_borders[1], &sl->top_borders_allocated[1], | |
143 | 37363 | h->mb_width * 16 * 3 * sizeof(uint8_t) * 2); | |
144 | |||
145 |
2/4✓ Branch 0 taken 37363 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37363 times.
✗ Branch 3 not taken.
|
37363 | if (!sl->bipred_scratchpad || !sl->edge_emu_buffer || |
146 |
2/4✓ Branch 0 taken 37363 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37363 times.
|
37363 | !sl->top_borders[0] || !sl->top_borders[1]) { |
147 | ✗ | av_freep(&sl->bipred_scratchpad); | |
148 | ✗ | av_freep(&sl->edge_emu_buffer); | |
149 | ✗ | av_freep(&sl->top_borders[0]); | |
150 | ✗ | av_freep(&sl->top_borders[1]); | |
151 | |||
152 | ✗ | sl->bipred_scratchpad_allocated = 0; | |
153 | ✗ | sl->edge_emu_buffer_allocated = 0; | |
154 | ✗ | sl->top_borders_allocated[0] = 0; | |
155 | ✗ | sl->top_borders_allocated[1] = 0; | |
156 | ✗ | return AVERROR(ENOMEM); | |
157 | } | ||
158 | |||
159 | 37363 | return 0; | |
160 | } | ||
161 | |||
162 | 601 | static int init_table_pools(H264Context *h) | |
163 | { | ||
164 | 601 | const int big_mb_num = h->mb_stride * (h->mb_height + 1) + 1; | |
165 | 601 | const int mb_array_size = h->mb_stride * h->mb_height; | |
166 | 601 | const int b4_stride = h->mb_width * 4 + 1; | |
167 | 601 | const int b4_array_size = b4_stride * h->mb_height * 4; | |
168 | |||
169 | 601 | h->qscale_table_pool = ff_refstruct_pool_alloc(big_mb_num + h->mb_stride, 0); | |
170 | 601 | h->mb_type_pool = ff_refstruct_pool_alloc((big_mb_num + h->mb_stride) * | |
171 | sizeof(uint32_t), 0); | ||
172 | 601 | h->motion_val_pool = ff_refstruct_pool_alloc(2 * (b4_array_size + 4) * | |
173 | sizeof(int16_t), 0); | ||
174 | 601 | h->ref_index_pool = ff_refstruct_pool_alloc(4 * mb_array_size, 0); | |
175 | |||
176 |
3/6✓ Branch 0 taken 601 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 601 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 601 times.
✗ Branch 5 not taken.
|
601 | if (!h->qscale_table_pool || !h->mb_type_pool || !h->motion_val_pool || |
177 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 601 times.
|
601 | !h->ref_index_pool) { |
178 | ✗ | ff_refstruct_pool_uninit(&h->qscale_table_pool); | |
179 | ✗ | ff_refstruct_pool_uninit(&h->mb_type_pool); | |
180 | ✗ | ff_refstruct_pool_uninit(&h->motion_val_pool); | |
181 | ✗ | ff_refstruct_pool_uninit(&h->ref_index_pool); | |
182 | ✗ | return AVERROR(ENOMEM); | |
183 | } | ||
184 | |||
185 | 601 | return 0; | |
186 | } | ||
187 | |||
188 | 25613 | static int alloc_picture(H264Context *h, H264Picture *pic) | |
189 | { | ||
190 | 25613 | int i, ret = 0; | |
191 | |||
192 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25613 times.
|
25613 | av_assert0(!pic->f->data[0]); |
193 | |||
194 | 25613 | pic->tf.f = pic->f; | |
195 | 25613 | ret = ff_thread_get_ext_buffer(h->avctx, &pic->tf, | |
196 | 25613 | pic->reference ? AV_GET_BUFFER_FLAG_REF : 0); | |
197 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25613 times.
|
25613 | if (ret < 0) |
198 | ✗ | goto fail; | |
199 | |||
200 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25613 times.
|
25613 | if (pic->needs_fg) { |
201 | ✗ | pic->f_grain->format = pic->f->format; | |
202 | ✗ | pic->f_grain->width = pic->f->width; | |
203 | ✗ | pic->f_grain->height = pic->f->height; | |
204 | ✗ | ret = ff_thread_get_buffer(h->avctx, pic->f_grain, 0); | |
205 | ✗ | if (ret < 0) | |
206 | ✗ | goto fail; | |
207 | } | ||
208 | |||
209 | 25613 | ret = ff_hwaccel_frame_priv_alloc(h->avctx, &pic->hwaccel_picture_private); | |
210 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25613 times.
|
25613 | if (ret < 0) |
211 | ✗ | goto fail; | |
212 | |||
213 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 25571 times.
|
25613 | if (h->decode_error_flags_pool) { |
214 | 42 | pic->decode_error_flags = ff_refstruct_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(pic->decode_error_flags, 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 601 times.
✓ Branch 1 taken 25012 times.
|
25613 | if (!h->qscale_table_pool) { |
234 | 601 | ret = init_table_pools(h); | |
235 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 601 times.
|
601 | if (ret < 0) |
236 | ✗ | goto fail; | |
237 | } | ||
238 | |||
239 | 25613 | pic->qscale_table_base = ff_refstruct_pool_get(h->qscale_table_pool); | |
240 | 25613 | pic->mb_type_base = ff_refstruct_pool_get(h->mb_type_pool); | |
241 |
2/4✓ Branch 0 taken 25613 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 25613 times.
|
25613 | if (!pic->qscale_table_base || !pic->mb_type_base) |
242 | ✗ | goto fail; | |
243 | |||
244 | 25613 | pic->mb_type = pic->mb_type_base + 2 * h->mb_stride + 1; | |
245 | 25613 | pic->qscale_table = pic->qscale_table_base + 2 * h->mb_stride + 1; | |
246 | |||
247 |
2/2✓ Branch 0 taken 51226 times.
✓ Branch 1 taken 25613 times.
|
76839 | for (i = 0; i < 2; i++) { |
248 | 51226 | pic->motion_val_base[i] = ff_refstruct_pool_get(h->motion_val_pool); | |
249 | 51226 | pic->ref_index[i] = ff_refstruct_pool_get(h->ref_index_pool); | |
250 |
2/4✓ Branch 0 taken 51226 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 51226 times.
|
51226 | if (!pic->motion_val_base[i] || !pic->ref_index[i]) |
251 | ✗ | goto fail; | |
252 | |||
253 | 51226 | pic->motion_val[i] = pic->motion_val_base[i] + 4; | |
254 | } | ||
255 | |||
256 | 25613 | pic->pps = ff_refstruct_ref_c(h->ps.pps); | |
257 | |||
258 | 25613 | pic->mb_width = h->mb_width; | |
259 | 25613 | pic->mb_height = h->mb_height; | |
260 | 25613 | pic->mb_stride = h->mb_stride; | |
261 | |||
262 | 25613 | return 0; | |
263 | ✗ | fail: | |
264 | ✗ | ff_h264_unref_picture(pic); | |
265 | ✗ | return (ret < 0) ? ret : AVERROR(ENOMEM); | |
266 | } | ||
267 | |||
268 | 25613 | static int find_unused_picture(const H264Context *h) | |
269 | { | ||
270 | int i; | ||
271 | |||
272 |
1/2✓ Branch 0 taken 86988 times.
✗ Branch 1 not taken.
|
86988 | for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) { |
273 |
2/2✓ Branch 0 taken 25613 times.
✓ Branch 1 taken 61375 times.
|
86988 | if (!h->DPB[i].f->buf[0]) |
274 | 25613 | return i; | |
275 | } | ||
276 | ✗ | return AVERROR_INVALIDDATA; | |
277 | } | ||
278 | |||
279 | |||
280 | #define IN_RANGE(a, b, size) (((void*)(a) >= (void*)(b)) && ((void*)(a) < (void*)((b) + (size)))) | ||
281 | |||
282 | #define REBASE_PICTURE(pic, new_ctx, old_ctx) \ | ||
283 | (((pic) && (pic) >= (old_ctx)->DPB && \ | ||
284 | (pic) < (old_ctx)->DPB + H264_MAX_PICTURE_COUNT) ? \ | ||
285 | &(new_ctx)->DPB[(pic) - (old_ctx)->DPB] : NULL) | ||
286 | |||
287 | 186 | static void copy_picture_range(H264Picture **to, H264Picture *const *from, int count, | |
288 | H264Context *new_base, const H264Context *old_base) | ||
289 | { | ||
290 | int i; | ||
291 | |||
292 |
2/2✓ Branch 0 taken 5084 times.
✓ Branch 1 taken 186 times.
|
5270 | for (i = 0; i < count; i++) { |
293 | av_assert1(!from[i] || | ||
294 | IN_RANGE(from[i], old_base, 1) || | ||
295 | IN_RANGE(from[i], old_base->DPB, H264_MAX_PICTURE_COUNT)); | ||
296 |
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); |
297 | } | ||
298 | 186 | } | |
299 | |||
300 | 24 | static void color_frame(AVFrame *frame, const int c[4]) | |
301 | { | ||
302 | 24 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); | |
303 | |||
304 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24 times.
|
24 | av_assert0(desc->flags & AV_PIX_FMT_FLAG_PLANAR); |
305 | |||
306 |
2/2✓ Branch 0 taken 72 times.
✓ Branch 1 taken 24 times.
|
96 | for (int p = 0; p < desc->nb_components; p++) { |
307 | 72 | uint8_t *dst = frame->data[p]; | |
308 |
4/4✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
✓ Branch 2 taken 24 times.
✓ Branch 3 taken 24 times.
|
72 | int is_chroma = p == 1 || p == 2; |
309 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
|
72 | int bytes = is_chroma ? AV_CEIL_RSHIFT(frame->width, desc->log2_chroma_w) : frame->width; |
310 |
2/2✓ Branch 0 taken 48 times.
✓ Branch 1 taken 24 times.
|
72 | int height = is_chroma ? AV_CEIL_RSHIFT(frame->height, desc->log2_chroma_h) : frame->height; |
311 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
|
72 | if (desc->comp[0].depth >= 9) { |
312 | ✗ | ((uint16_t*)dst)[0] = c[p]; | |
313 | ✗ | av_memcpy_backptr(dst + 2, 2, bytes - 2); | |
314 | ✗ | dst += frame->linesize[p]; | |
315 | ✗ | for (int y = 1; y < height; y++) { | |
316 | ✗ | memcpy(dst, frame->data[p], 2*bytes); | |
317 | ✗ | dst += frame->linesize[p]; | |
318 | } | ||
319 | } else { | ||
320 |
2/2✓ Branch 0 taken 30208 times.
✓ Branch 1 taken 72 times.
|
30280 | for (int y = 0; y < height; y++) { |
321 | 30208 | memset(dst, c[p], bytes); | |
322 | 30208 | dst += frame->linesize[p]; | |
323 | } | ||
324 | } | ||
325 | } | ||
326 | 24 | } | |
327 | |||
328 | static int h264_slice_header_init(H264Context *h); | ||
329 | |||
330 | 62 | int ff_h264_update_thread_context(AVCodecContext *dst, | |
331 | const AVCodecContext *src) | ||
332 | { | ||
333 | 62 | H264Context *h = dst->priv_data, *h1 = src->priv_data; | |
334 | 62 | int inited = h->context_initialized, err = 0; | |
335 | 62 | int need_reinit = 0; | |
336 | int i, ret; | ||
337 | |||
338 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
|
62 | if (dst == src) |
339 | ✗ | return 0; | |
340 | |||
341 |
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) |
342 | ✗ | return AVERROR_INVALIDDATA; | |
343 | |||
344 |
2/2✓ Branch 0 taken 46 times.
✓ Branch 1 taken 16 times.
|
62 | if (inited && |
345 |
1/2✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
|
46 | (h->width != h1->width || |
346 |
1/2✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
|
46 | h->height != h1->height || |
347 |
1/2✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
|
46 | h->mb_width != h1->mb_width || |
348 |
1/2✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
|
46 | h->mb_height != h1->mb_height || |
349 |
1/2✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
|
46 | !h->ps.sps || |
350 |
1/2✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
|
46 | h->ps.sps->bit_depth_luma != h1->ps.sps->bit_depth_luma || |
351 |
1/2✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
|
46 | h->ps.sps->chroma_format_idc != h1->ps.sps->chroma_format_idc || |
352 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
|
46 | h->ps.sps->vui.matrix_coeffs != h1->ps.sps->vui.matrix_coeffs)) { |
353 | ✗ | need_reinit = 1; | |
354 | } | ||
355 | |||
356 | /* copy block_offset since frame_start may not be called */ | ||
357 | 62 | memcpy(h->block_offset, h1->block_offset, sizeof(h->block_offset)); | |
358 | |||
359 | // SPS/PPS | ||
360 |
2/2✓ Branch 0 taken 1984 times.
✓ Branch 1 taken 62 times.
|
2046 | for (int i = 0; i < FF_ARRAY_ELEMS(h->ps.sps_list); i++) |
361 | 1984 | ff_refstruct_replace(&h->ps.sps_list[i], h1->ps.sps_list[i]); | |
362 |
2/2✓ Branch 0 taken 15872 times.
✓ Branch 1 taken 62 times.
|
15934 | for (int i = 0; i < FF_ARRAY_ELEMS(h->ps.pps_list); i++) |
363 | 15872 | ff_refstruct_replace(&h->ps.pps_list[i], h1->ps.pps_list[i]); | |
364 | |||
365 | 62 | ff_refstruct_replace(&h->ps.pps, h1->ps.pps); | |
366 | 62 | h->ps.sps = h1->ps.sps; | |
367 | |||
368 |
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) { |
369 | 16 | h->width = h1->width; | |
370 | 16 | h->height = h1->height; | |
371 | 16 | h->mb_height = h1->mb_height; | |
372 | 16 | h->mb_width = h1->mb_width; | |
373 | 16 | h->mb_num = h1->mb_num; | |
374 | 16 | h->mb_stride = h1->mb_stride; | |
375 | 16 | h->b_stride = h1->b_stride; | |
376 | 16 | h->x264_build = h1->x264_build; | |
377 | |||
378 |
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) { |
379 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
|
16 | if ((err = h264_slice_header_init(h)) < 0) { |
380 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "h264_slice_header_init() failed"); | |
381 | ✗ | return err; | |
382 | } | ||
383 | } | ||
384 | |||
385 | /* copy block_offset since frame_start may not be called */ | ||
386 | 16 | memcpy(h->block_offset, h1->block_offset, sizeof(h->block_offset)); | |
387 | } | ||
388 | |||
389 | 62 | h->width_from_caller = h1->width_from_caller; | |
390 | 62 | h->height_from_caller = h1->height_from_caller; | |
391 | 62 | h->first_field = h1->first_field; | |
392 | 62 | h->picture_structure = h1->picture_structure; | |
393 | 62 | h->mb_aff_frame = h1->mb_aff_frame; | |
394 | 62 | h->droppable = h1->droppable; | |
395 | |||
396 |
2/2✓ Branch 0 taken 2232 times.
✓ Branch 1 taken 62 times.
|
2294 | for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) { |
397 | 2232 | ret = ff_h264_replace_picture(&h->DPB[i], &h1->DPB[i]); | |
398 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2232 times.
|
2232 | if (ret < 0) |
399 | ✗ | return ret; | |
400 | } | ||
401 | |||
402 |
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); |
403 | 62 | ret = ff_h264_replace_picture(&h->cur_pic, &h1->cur_pic); | |
404 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
|
62 | if (ret < 0) |
405 | ✗ | return ret; | |
406 | |||
407 | 62 | h->enable_er = h1->enable_er; | |
408 | 62 | h->workaround_bugs = h1->workaround_bugs; | |
409 | 62 | h->droppable = h1->droppable; | |
410 | |||
411 | // extradata/NAL handling | ||
412 | 62 | h->is_avc = h1->is_avc; | |
413 | 62 | h->nal_length_size = h1->nal_length_size; | |
414 | |||
415 | 62 | memcpy(&h->poc, &h1->poc, sizeof(h->poc)); | |
416 | |||
417 | 62 | memcpy(h->short_ref, h1->short_ref, sizeof(h->short_ref)); | |
418 | 62 | memcpy(h->long_ref, h1->long_ref, sizeof(h->long_ref)); | |
419 | 62 | memcpy(h->delayed_pic, h1->delayed_pic, sizeof(h->delayed_pic)); | |
420 | 62 | memcpy(h->last_pocs, h1->last_pocs, sizeof(h->last_pocs)); | |
421 | |||
422 | 62 | h->next_output_pic = h1->next_output_pic; | |
423 | 62 | h->next_outputed_poc = h1->next_outputed_poc; | |
424 | 62 | h->poc_offset = h1->poc_offset; | |
425 | |||
426 | 62 | memcpy(h->mmco, h1->mmco, sizeof(h->mmco)); | |
427 | 62 | h->nb_mmco = h1->nb_mmco; | |
428 | 62 | h->mmco_reset = h1->mmco_reset; | |
429 | 62 | h->explicit_ref_marking = h1->explicit_ref_marking; | |
430 | 62 | h->long_ref_count = h1->long_ref_count; | |
431 | 62 | h->short_ref_count = h1->short_ref_count; | |
432 | |||
433 | 62 | copy_picture_range(h->short_ref, h1->short_ref, 32, h, h1); | |
434 | 62 | copy_picture_range(h->long_ref, h1->long_ref, 32, h, h1); | |
435 | 62 | copy_picture_range(h->delayed_pic, h1->delayed_pic, | |
436 | FF_ARRAY_ELEMS(h->delayed_pic), h, h1); | ||
437 | |||
438 | 62 | h->frame_recovered = h1->frame_recovered; | |
439 | |||
440 | 62 | ret = ff_h264_sei_ctx_replace(&h->sei, &h1->sei); | |
441 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 62 times.
|
62 | if (ret < 0) |
442 | ✗ | return ret; | |
443 | |||
444 | 62 | h->sei.common.unregistered.x264_build = h1->sei.common.unregistered.x264_build; | |
445 | 62 | h->sei.common.mastering_display = h1->sei.common.mastering_display; | |
446 | 62 | h->sei.common.content_light = h1->sei.common.content_light; | |
447 | |||
448 |
2/2✓ Branch 0 taken 20 times.
✓ Branch 1 taken 42 times.
|
62 | if (!h->cur_pic_ptr) |
449 | 20 | return 0; | |
450 | |||
451 |
2/2✓ Branch 0 taken 27 times.
✓ Branch 1 taken 15 times.
|
42 | if (!h->droppable) { |
452 | 27 | err = ff_h264_execute_ref_pic_marking(h); | |
453 | 27 | h->poc.prev_poc_msb = h->poc.poc_msb; | |
454 | 27 | h->poc.prev_poc_lsb = h->poc.poc_lsb; | |
455 | } | ||
456 | 42 | h->poc.prev_frame_num_offset = h->poc.frame_num_offset; | |
457 | 42 | h->poc.prev_frame_num = h->poc.frame_num; | |
458 | |||
459 | 42 | h->recovery_frame = h1->recovery_frame; | |
460 | 42 | h->non_gray = h1->non_gray; | |
461 | |||
462 | 42 | return err; | |
463 | } | ||
464 | |||
465 | 50 | int ff_h264_update_thread_context_for_user(AVCodecContext *dst, | |
466 | const AVCodecContext *src) | ||
467 | { | ||
468 | 50 | H264Context *h = dst->priv_data; | |
469 | 50 | const H264Context *h1 = src->priv_data; | |
470 | |||
471 | 50 | h->is_avc = h1->is_avc; | |
472 | 50 | h->nal_length_size = h1->nal_length_size; | |
473 | |||
474 | 50 | return 0; | |
475 | } | ||
476 | |||
477 | 25613 | static int h264_frame_start(H264Context *h) | |
478 | { | ||
479 | H264Picture *pic; | ||
480 | int i, ret; | ||
481 | 25613 | const int pixel_shift = h->pixel_shift; | |
482 | |||
483 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25613 times.
|
25613 | if (!ff_thread_can_start_frame(h->avctx)) { |
484 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Attempt to start a frame outside SETUP state\n"); | |
485 | ✗ | return AVERROR_BUG; | |
486 | } | ||
487 | |||
488 | 25613 | release_unused_pictures(h, 1); | |
489 | 25613 | h->cur_pic_ptr = NULL; | |
490 | |||
491 | 25613 | i = find_unused_picture(h); | |
492 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25613 times.
|
25613 | if (i < 0) { |
493 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "no frame buffer available\n"); | |
494 | ✗ | return i; | |
495 | } | ||
496 | 25613 | pic = &h->DPB[i]; | |
497 | |||
498 |
2/2✓ Branch 0 taken 17668 times.
✓ Branch 1 taken 7945 times.
|
25613 | pic->reference = h->droppable ? 0 : h->picture_structure; |
499 | 25613 | pic->field_picture = h->picture_structure != PICT_FRAME; | |
500 | 25613 | pic->frame_num = h->poc.frame_num; | |
501 | /* | ||
502 | * Zero key_frame here; IDR markings per slice in frame or fields are ORed | ||
503 | * in later. | ||
504 | * See decode_nal_units(). | ||
505 | */ | ||
506 | 25613 | pic->f->flags &= ~AV_FRAME_FLAG_KEY; | |
507 | 25613 | pic->mmco_reset = 0; | |
508 | 25613 | pic->recovered = 0; | |
509 | 25613 | pic->invalid_gap = 0; | |
510 | 25613 | pic->sei_recovery_frame_cnt = h->sei.recovery_point.recovery_frame_cnt; | |
511 | |||
512 | 25613 | pic->f->pict_type = h->slice_ctx[0].slice_type; | |
513 | |||
514 | 25613 | pic->f->crop_left = h->crop_left; | |
515 | 25613 | pic->f->crop_right = h->crop_right; | |
516 | 25613 | pic->f->crop_top = h->crop_top; | |
517 | 25613 | pic->f->crop_bottom = h->crop_bottom; | |
518 | |||
519 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 25613 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
25613 | pic->needs_fg = h->sei.common.film_grain_characteristics.present && !h->avctx->hwaccel && |
520 | ✗ | !(h->avctx->export_side_data & AV_CODEC_EXPORT_DATA_FILM_GRAIN); | |
521 | |||
522 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25613 times.
|
25613 | if ((ret = alloc_picture(h, pic)) < 0) |
523 | ✗ | return ret; | |
524 | |||
525 | 25613 | h->cur_pic_ptr = pic; | |
526 | 25613 | ff_h264_unref_picture(&h->cur_pic); | |
527 | if (CONFIG_ERROR_RESILIENCE) { | ||
528 | 25613 | ff_h264_set_erpic(&h->er.cur_pic, NULL); | |
529 | } | ||
530 | |||
531 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25613 times.
|
25613 | if ((ret = ff_h264_ref_picture(&h->cur_pic, h->cur_pic_ptr)) < 0) |
532 | ✗ | return ret; | |
533 | |||
534 |
2/2✓ Branch 0 taken 25913 times.
✓ Branch 1 taken 25613 times.
|
51526 | for (i = 0; i < h->nb_slice_ctx; i++) { |
535 | 25913 | h->slice_ctx[i].linesize = h->cur_pic_ptr->f->linesize[0]; | |
536 | 25913 | h->slice_ctx[i].uvlinesize = h->cur_pic_ptr->f->linesize[1]; | |
537 | } | ||
538 | |||
539 |
2/2✓ Branch 0 taken 25313 times.
✓ Branch 1 taken 300 times.
|
25613 | if (CONFIG_ERROR_RESILIENCE && h->enable_er) { |
540 | 25313 | ff_er_frame_start(&h->er); | |
541 | 25313 | ff_h264_set_erpic(&h->er.last_pic, NULL); | |
542 | 25313 | ff_h264_set_erpic(&h->er.next_pic, NULL); | |
543 | } | ||
544 | |||
545 |
2/2✓ Branch 0 taken 409808 times.
✓ Branch 1 taken 25613 times.
|
435421 | for (i = 0; i < 16; i++) { |
546 | 409808 | h->block_offset[i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3); | |
547 | 409808 | h->block_offset[48 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 8 * pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3); | |
548 | } | ||
549 |
2/2✓ Branch 0 taken 409808 times.
✓ Branch 1 taken 25613 times.
|
435421 | for (i = 0; i < 16; i++) { |
550 | 409808 | h->block_offset[16 + i] = | |
551 | 409808 | h->block_offset[32 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3); | |
552 | 409808 | h->block_offset[48 + 16 + i] = | |
553 | 409808 | h->block_offset[48 + 32 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 8 * pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3); | |
554 | } | ||
555 | |||
556 | /* We mark the current picture as non-reference after allocating it, so | ||
557 | * that if we break out due to an error it can be released automatically | ||
558 | * in the next ff_mpv_frame_start(). | ||
559 | */ | ||
560 | 25613 | h->cur_pic_ptr->reference = 0; | |
561 | |||
562 | 25613 | h->cur_pic_ptr->field_poc[0] = h->cur_pic_ptr->field_poc[1] = INT_MAX; | |
563 | |||
564 | 25613 | h->next_output_pic = NULL; | |
565 | |||
566 | 25613 | h->postpone_filter = 0; | |
567 | |||
568 |
4/4✓ Branch 0 taken 2862 times.
✓ Branch 1 taken 22751 times.
✓ Branch 2 taken 2354 times.
✓ Branch 3 taken 508 times.
|
25613 | h->mb_aff_frame = h->ps.sps->mb_aff && (h->picture_structure == PICT_FRAME); |
569 | |||
570 |
2/2✓ Branch 0 taken 2063 times.
✓ Branch 1 taken 23550 times.
|
25613 | if (h->sei.common.unregistered.x264_build >= 0) |
571 | 2063 | h->x264_build = h->sei.common.unregistered.x264_build; | |
572 | |||
573 | assert(h->cur_pic_ptr->long_ref == 0); | ||
574 | |||
575 | 25613 | return 0; | |
576 | } | ||
577 | |||
578 | 12577876 | static av_always_inline void backup_mb_border(const H264Context *h, H264SliceContext *sl, | |
579 | const uint8_t *src_y, | ||
580 | const uint8_t *src_cb, const uint8_t *src_cr, | ||
581 | int linesize, int uvlinesize, | ||
582 | int simple) | ||
583 | { | ||
584 | uint8_t *top_border; | ||
585 | 12577876 | int top_idx = 1; | |
586 | 12577876 | const int pixel_shift = h->pixel_shift; | |
587 | 12577876 | int chroma444 = CHROMA444(h); | |
588 | 12577876 | int chroma422 = CHROMA422(h); | |
589 | |||
590 | 12577876 | src_y -= linesize; | |
591 | 12577876 | src_cb -= uvlinesize; | |
592 | 12577876 | src_cr -= uvlinesize; | |
593 | |||
594 |
3/4✓ Branch 0 taken 12577876 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2021856 times.
✓ Branch 3 taken 10556020 times.
|
12577876 | if (!simple && FRAME_MBAFF(h)) { |
595 |
2/2✓ Branch 0 taken 1010928 times.
✓ Branch 1 taken 1010928 times.
|
2021856 | if (sl->mb_y & 1) { |
596 |
2/2✓ Branch 0 taken 747670 times.
✓ Branch 1 taken 263258 times.
|
1010928 | if (!MB_MBAFF(sl)) { |
597 | 747670 | top_border = sl->top_borders[0][sl->mb_x]; | |
598 | 747670 | AV_COPY128(top_border, src_y + 15 * linesize); | |
599 |
2/2✓ Branch 0 taken 213139 times.
✓ Branch 1 taken 534531 times.
|
747670 | if (pixel_shift) |
600 | 213139 | AV_COPY128(top_border + 16, src_y + 15 * linesize + 16); | |
601 | if (simple || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) { | ||
602 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 747670 times.
|
747670 | if (chroma444) { |
603 | ✗ | if (pixel_shift) { | |
604 | ✗ | AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize); | |
605 | ✗ | AV_COPY128(top_border + 48, src_cb + 15 * uvlinesize + 16); | |
606 | ✗ | AV_COPY128(top_border + 64, src_cr + 15 * uvlinesize); | |
607 | ✗ | AV_COPY128(top_border + 80, src_cr + 15 * uvlinesize + 16); | |
608 | } else { | ||
609 | ✗ | AV_COPY128(top_border + 16, src_cb + 15 * uvlinesize); | |
610 | ✗ | AV_COPY128(top_border + 32, src_cr + 15 * uvlinesize); | |
611 | } | ||
612 |
2/2✓ Branch 0 taken 106510 times.
✓ Branch 1 taken 641160 times.
|
747670 | } else if (chroma422) { |
613 |
1/2✓ Branch 0 taken 106510 times.
✗ Branch 1 not taken.
|
106510 | if (pixel_shift) { |
614 | 106510 | AV_COPY128(top_border + 32, src_cb + 15 * uvlinesize); | |
615 | 106510 | AV_COPY128(top_border + 48, src_cr + 15 * uvlinesize); | |
616 | } else { | ||
617 | ✗ | AV_COPY64(top_border + 16, src_cb + 15 * uvlinesize); | |
618 | ✗ | AV_COPY64(top_border + 24, src_cr + 15 * uvlinesize); | |
619 | } | ||
620 | } else { | ||
621 |
2/2✓ Branch 0 taken 106629 times.
✓ Branch 1 taken 534531 times.
|
641160 | if (pixel_shift) { |
622 | 106629 | AV_COPY128(top_border + 32, src_cb + 7 * uvlinesize); | |
623 | 106629 | AV_COPY128(top_border + 48, src_cr + 7 * uvlinesize); | |
624 | } else { | ||
625 | 534531 | AV_COPY64(top_border + 16, src_cb + 7 * uvlinesize); | |
626 | 534531 | AV_COPY64(top_border + 24, src_cr + 7 * uvlinesize); | |
627 | } | ||
628 | } | ||
629 | } | ||
630 | } | ||
631 |
2/2✓ Branch 0 taken 263258 times.
✓ Branch 1 taken 747670 times.
|
1010928 | } else if (MB_MBAFF(sl)) { |
632 | 263258 | top_idx = 0; | |
633 | } else | ||
634 | 747670 | return; | |
635 | } | ||
636 | |||
637 | 11830206 | top_border = sl->top_borders[top_idx][sl->mb_x]; | |
638 | /* There are two lines saved, the line above the top macroblock | ||
639 | * of a pair, and the line above the bottom macroblock. */ | ||
640 | 11830206 | AV_COPY128(top_border, src_y + 16 * linesize); | |
641 |
2/2✓ Branch 0 taken 1381381 times.
✓ Branch 1 taken 10448825 times.
|
11830206 | if (pixel_shift) |
642 | 1381381 | AV_COPY128(top_border + 16, src_y + 16 * linesize + 16); | |
643 | |||
644 | if (simple || !CONFIG_GRAY || !(h->flags & AV_CODEC_FLAG_GRAY)) { | ||
645 |
2/2✓ Branch 0 taken 80328 times.
✓ Branch 1 taken 11749878 times.
|
11830206 | if (chroma444) { |
646 |
2/2✓ Branch 0 taken 19800 times.
✓ Branch 1 taken 60528 times.
|
80328 | if (pixel_shift) { |
647 | 19800 | AV_COPY128(top_border + 32, src_cb + 16 * linesize); | |
648 | 19800 | AV_COPY128(top_border + 48, src_cb + 16 * linesize + 16); | |
649 | 19800 | AV_COPY128(top_border + 64, src_cr + 16 * linesize); | |
650 | 19800 | AV_COPY128(top_border + 80, src_cr + 16 * linesize + 16); | |
651 | } else { | ||
652 | 60528 | AV_COPY128(top_border + 16, src_cb + 16 * linesize); | |
653 | 60528 | AV_COPY128(top_border + 32, src_cr + 16 * linesize); | |
654 | } | ||
655 |
2/2✓ Branch 0 taken 588635 times.
✓ Branch 1 taken 11161243 times.
|
11749878 | } else if (chroma422) { |
656 |
2/2✓ Branch 0 taken 584675 times.
✓ Branch 1 taken 3960 times.
|
588635 | if (pixel_shift) { |
657 | 584675 | AV_COPY128(top_border + 32, src_cb + 16 * uvlinesize); | |
658 | 584675 | AV_COPY128(top_border + 48, src_cr + 16 * uvlinesize); | |
659 | } else { | ||
660 | 3960 | AV_COPY64(top_border + 16, src_cb + 16 * uvlinesize); | |
661 | 3960 | AV_COPY64(top_border + 24, src_cr + 16 * uvlinesize); | |
662 | } | ||
663 | } else { | ||
664 |
2/2✓ Branch 0 taken 776906 times.
✓ Branch 1 taken 10384337 times.
|
11161243 | if (pixel_shift) { |
665 | 776906 | AV_COPY128(top_border + 32, src_cb + 8 * uvlinesize); | |
666 | 776906 | AV_COPY128(top_border + 48, src_cr + 8 * uvlinesize); | |
667 | } else { | ||
668 | 10384337 | AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize); | |
669 | 10384337 | AV_COPY64(top_border + 24, src_cr + 8 * uvlinesize); | |
670 | } | ||
671 | } | ||
672 | } | ||
673 | } | ||
674 | |||
675 | /** | ||
676 | * Initialize implicit_weight table. | ||
677 | * @param field 0/1 initialize the weight for interlaced MBAFF | ||
678 | * -1 initializes the rest | ||
679 | */ | ||
680 | 3841 | static void implicit_weight_table(const H264Context *h, H264SliceContext *sl, int field) | |
681 | { | ||
682 | int ref0, ref1, i, cur_poc, ref_start, ref_count0, ref_count1; | ||
683 | |||
684 |
2/2✓ Branch 0 taken 7682 times.
✓ Branch 1 taken 3841 times.
|
11523 | for (i = 0; i < 2; i++) { |
685 | 7682 | sl->pwt.luma_weight_flag[i] = 0; | |
686 | 7682 | sl->pwt.chroma_weight_flag[i] = 0; | |
687 | } | ||
688 | |||
689 |
2/2✓ Branch 0 taken 2129 times.
✓ Branch 1 taken 1712 times.
|
3841 | if (field < 0) { |
690 |
1/2✓ Branch 0 taken 2129 times.
✗ Branch 1 not taken.
|
2129 | if (h->picture_structure == PICT_FRAME) { |
691 | 2129 | cur_poc = h->cur_pic_ptr->poc; | |
692 | } else { | ||
693 | ✗ | cur_poc = h->cur_pic_ptr->field_poc[h->picture_structure - 1]; | |
694 | } | ||
695 |
6/6✓ Branch 0 taken 953 times.
✓ Branch 1 taken 1176 times.
✓ Branch 2 taken 643 times.
✓ Branch 3 taken 310 times.
✓ Branch 4 taken 633 times.
✓ Branch 5 taken 10 times.
|
2129 | if (sl->ref_count[0] == 1 && sl->ref_count[1] == 1 && !FRAME_MBAFF(h) && |
696 |
2/2✓ Branch 0 taken 416 times.
✓ Branch 1 taken 217 times.
|
633 | sl->ref_list[0][0].poc + (int64_t)sl->ref_list[1][0].poc == 2LL * cur_poc) { |
697 | 416 | sl->pwt.use_weight = 0; | |
698 | 416 | sl->pwt.use_weight_chroma = 0; | |
699 | 416 | return; | |
700 | } | ||
701 | 1713 | ref_start = 0; | |
702 | 1713 | ref_count0 = sl->ref_count[0]; | |
703 | 1713 | ref_count1 = sl->ref_count[1]; | |
704 | } else { | ||
705 | 1712 | cur_poc = h->cur_pic_ptr->field_poc[field]; | |
706 | 1712 | ref_start = 16; | |
707 | 1712 | ref_count0 = 16 + 2 * sl->ref_count[0]; | |
708 | 1712 | ref_count1 = 16 + 2 * sl->ref_count[1]; | |
709 | } | ||
710 | |||
711 | 3425 | sl->pwt.use_weight = 2; | |
712 | 3425 | sl->pwt.use_weight_chroma = 2; | |
713 | 3425 | sl->pwt.luma_log2_weight_denom = 5; | |
714 | 3425 | sl->pwt.chroma_log2_weight_denom = 5; | |
715 | |||
716 |
2/2✓ Branch 0 taken 11795 times.
✓ Branch 1 taken 3425 times.
|
15220 | for (ref0 = ref_start; ref0 < ref_count0; ref0++) { |
717 | 11795 | int64_t poc0 = sl->ref_list[0][ref0].poc; | |
718 |
2/2✓ Branch 0 taken 21896 times.
✓ Branch 1 taken 11795 times.
|
33691 | for (ref1 = ref_start; ref1 < ref_count1; ref1++) { |
719 | 21896 | int w = 32; | |
720 |
2/4✓ Branch 0 taken 21896 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21896 times.
✗ Branch 3 not taken.
|
21896 | if (!sl->ref_list[0][ref0].parent->long_ref && !sl->ref_list[1][ref1].parent->long_ref) { |
721 | 21896 | int poc1 = sl->ref_list[1][ref1].poc; | |
722 | 21896 | int td = av_clip_int8(poc1 - poc0); | |
723 |
2/2✓ Branch 0 taken 21829 times.
✓ Branch 1 taken 67 times.
|
21896 | if (td) { |
724 | 21829 | int tb = av_clip_int8(cur_poc - poc0); | |
725 | 21829 | int tx = (16384 + (FFABS(td) >> 1)) / td; | |
726 | 21829 | int dist_scale_factor = (tb * tx + 32) >> 8; | |
727 |
3/4✓ Branch 0 taken 21819 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 21819 times.
✗ Branch 3 not taken.
|
21829 | if (dist_scale_factor >= -64 && dist_scale_factor <= 128) |
728 | 21819 | w = 64 - dist_scale_factor; | |
729 | } | ||
730 | } | ||
731 |
2/2✓ Branch 0 taken 5992 times.
✓ Branch 1 taken 15904 times.
|
21896 | if (field < 0) { |
732 | 5992 | sl->pwt.implicit_weight[ref0][ref1][0] = | |
733 | 5992 | sl->pwt.implicit_weight[ref0][ref1][1] = w; | |
734 | } else { | ||
735 | 15904 | sl->pwt.implicit_weight[ref0][ref1][field] = w; | |
736 | } | ||
737 | } | ||
738 | } | ||
739 | } | ||
740 | |||
741 | /** | ||
742 | * initialize scan tables | ||
743 | */ | ||
744 | 601 | static void init_scan_tables(H264Context *h) | |
745 | { | ||
746 | int i; | ||
747 |
2/2✓ Branch 0 taken 9616 times.
✓ Branch 1 taken 601 times.
|
10217 | for (i = 0; i < 16; i++) { |
748 | #define TRANSPOSE(x) ((x) >> 2) | (((x) << 2) & 0xF) | ||
749 | 9616 | h->zigzag_scan[i] = TRANSPOSE(ff_zigzag_scan[i]); | |
750 | 9616 | h->field_scan[i] = TRANSPOSE(field_scan[i]); | |
751 | #undef TRANSPOSE | ||
752 | } | ||
753 |
2/2✓ Branch 0 taken 38464 times.
✓ Branch 1 taken 601 times.
|
39065 | for (i = 0; i < 64; i++) { |
754 | #define TRANSPOSE(x) ((x) >> 3) | (((x) & 7) << 3) | ||
755 | 38464 | h->zigzag_scan8x8[i] = TRANSPOSE(ff_zigzag_direct[i]); | |
756 | 38464 | h->zigzag_scan8x8_cavlc[i] = TRANSPOSE(zigzag_scan8x8_cavlc[i]); | |
757 | 38464 | h->field_scan8x8[i] = TRANSPOSE(field_scan8x8[i]); | |
758 | 38464 | h->field_scan8x8_cavlc[i] = TRANSPOSE(field_scan8x8_cavlc[i]); | |
759 | #undef TRANSPOSE | ||
760 | } | ||
761 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 587 times.
|
601 | if (h->ps.sps->transform_bypass) { // FIXME same ugly |
762 | 14 | memcpy(h->zigzag_scan_q0 , ff_zigzag_scan , sizeof(h->zigzag_scan_q0 )); | |
763 | 14 | memcpy(h->zigzag_scan8x8_q0 , ff_zigzag_direct , sizeof(h->zigzag_scan8x8_q0 )); | |
764 | 14 | memcpy(h->zigzag_scan8x8_cavlc_q0 , zigzag_scan8x8_cavlc , sizeof(h->zigzag_scan8x8_cavlc_q0)); | |
765 | 14 | memcpy(h->field_scan_q0 , field_scan , sizeof(h->field_scan_q0 )); | |
766 | 14 | memcpy(h->field_scan8x8_q0 , field_scan8x8 , sizeof(h->field_scan8x8_q0 )); | |
767 | 14 | memcpy(h->field_scan8x8_cavlc_q0 , field_scan8x8_cavlc , sizeof(h->field_scan8x8_cavlc_q0 )); | |
768 | } else { | ||
769 | 587 | memcpy(h->zigzag_scan_q0 , h->zigzag_scan , sizeof(h->zigzag_scan_q0 )); | |
770 | 587 | memcpy(h->zigzag_scan8x8_q0 , h->zigzag_scan8x8 , sizeof(h->zigzag_scan8x8_q0 )); | |
771 | 587 | memcpy(h->zigzag_scan8x8_cavlc_q0 , h->zigzag_scan8x8_cavlc , sizeof(h->zigzag_scan8x8_cavlc_q0)); | |
772 | 587 | memcpy(h->field_scan_q0 , h->field_scan , sizeof(h->field_scan_q0 )); | |
773 | 587 | memcpy(h->field_scan8x8_q0 , h->field_scan8x8 , sizeof(h->field_scan8x8_q0 )); | |
774 | 587 | memcpy(h->field_scan8x8_cavlc_q0 , h->field_scan8x8_cavlc , sizeof(h->field_scan8x8_cavlc_q0 )); | |
775 | } | ||
776 | 601 | } | |
777 | |||
778 | 28549 | static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback) | |
779 | { | ||
780 | #define HWACCEL_MAX (CONFIG_H264_DXVA2_HWACCEL + \ | ||
781 | (CONFIG_H264_D3D11VA_HWACCEL * 2) + \ | ||
782 | CONFIG_H264_D3D12VA_HWACCEL + \ | ||
783 | CONFIG_H264_NVDEC_HWACCEL + \ | ||
784 | CONFIG_H264_VAAPI_HWACCEL + \ | ||
785 | CONFIG_H264_VIDEOTOOLBOX_HWACCEL + \ | ||
786 | CONFIG_H264_VDPAU_HWACCEL + \ | ||
787 | CONFIG_H264_VULKAN_HWACCEL) | ||
788 | 28549 | enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmt = pix_fmts; | |
789 | |||
790 |
3/6✓ Branch 0 taken 155 times.
✓ Branch 1 taken 372 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 28022 times.
✗ Branch 5 not taken.
|
28549 | switch (h->ps.sps->bit_depth_luma) { |
791 | 155 | case 9: | |
792 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 155 times.
|
155 | if (CHROMA444(h)) { |
793 | ✗ | if (h->avctx->colorspace == AVCOL_SPC_RGB) { | |
794 | ✗ | *fmt++ = AV_PIX_FMT_GBRP9; | |
795 | } else | ||
796 | ✗ | *fmt++ = AV_PIX_FMT_YUV444P9; | |
797 |
2/2✓ Branch 0 taken 52 times.
✓ Branch 1 taken 103 times.
|
155 | } else if (CHROMA422(h)) |
798 | 52 | *fmt++ = AV_PIX_FMT_YUV422P9; | |
799 | else | ||
800 | 103 | *fmt++ = AV_PIX_FMT_YUV420P9; | |
801 | 155 | break; | |
802 | 372 | case 10: | |
803 | #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL | ||
804 | if (h->avctx->colorspace != AVCOL_SPC_RGB) | ||
805 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
806 | #endif | ||
807 | #if CONFIG_H264_VULKAN_HWACCEL | ||
808 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
809 | #endif | ||
810 |
2/2✓ Branch 0 taken 51 times.
✓ Branch 1 taken 321 times.
|
372 | if (CHROMA444(h)) { |
811 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 51 times.
|
51 | if (h->avctx->colorspace == AVCOL_SPC_RGB) { |
812 | ✗ | *fmt++ = AV_PIX_FMT_GBRP10; | |
813 | } else | ||
814 | 51 | *fmt++ = AV_PIX_FMT_YUV444P10; | |
815 |
2/2✓ Branch 0 taken 164 times.
✓ Branch 1 taken 157 times.
|
321 | } else if (CHROMA422(h)) |
816 | 164 | *fmt++ = AV_PIX_FMT_YUV422P10; | |
817 | else { | ||
818 | #if CONFIG_H264_VAAPI_HWACCEL | ||
819 | // Just add as candidate. Whether VAProfileH264High10 usable or | ||
820 | // not is decided by vaapi_decode_make_config() defined in FFmpeg | ||
821 | // and vaQueryCodingProfile() defined in libva. | ||
822 | 157 | *fmt++ = AV_PIX_FMT_VAAPI; | |
823 | #endif | ||
824 | 157 | *fmt++ = AV_PIX_FMT_YUV420P10; | |
825 | } | ||
826 | 372 | break; | |
827 | ✗ | case 12: | |
828 | #if CONFIG_H264_VULKAN_HWACCEL | ||
829 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
830 | #endif | ||
831 | ✗ | if (CHROMA444(h)) { | |
832 | ✗ | if (h->avctx->colorspace == AVCOL_SPC_RGB) { | |
833 | ✗ | *fmt++ = AV_PIX_FMT_GBRP12; | |
834 | } else | ||
835 | ✗ | *fmt++ = AV_PIX_FMT_YUV444P12; | |
836 | ✗ | } else if (CHROMA422(h)) | |
837 | ✗ | *fmt++ = AV_PIX_FMT_YUV422P12; | |
838 | else | ||
839 | ✗ | *fmt++ = AV_PIX_FMT_YUV420P12; | |
840 | ✗ | break; | |
841 | ✗ | case 14: | |
842 | ✗ | if (CHROMA444(h)) { | |
843 | ✗ | if (h->avctx->colorspace == AVCOL_SPC_RGB) { | |
844 | ✗ | *fmt++ = AV_PIX_FMT_GBRP14; | |
845 | } else | ||
846 | ✗ | *fmt++ = AV_PIX_FMT_YUV444P14; | |
847 | ✗ | } else if (CHROMA422(h)) | |
848 | ✗ | *fmt++ = AV_PIX_FMT_YUV422P14; | |
849 | else | ||
850 | ✗ | *fmt++ = AV_PIX_FMT_YUV420P14; | |
851 | ✗ | break; | |
852 | 28022 | case 8: | |
853 | #if CONFIG_H264_VDPAU_HWACCEL | ||
854 | 28022 | *fmt++ = AV_PIX_FMT_VDPAU; | |
855 | #endif | ||
856 | #if CONFIG_H264_VULKAN_HWACCEL | ||
857 | *fmt++ = AV_PIX_FMT_VULKAN; | ||
858 | #endif | ||
859 | #if CONFIG_H264_NVDEC_HWACCEL | ||
860 | *fmt++ = AV_PIX_FMT_CUDA; | ||
861 | #endif | ||
862 | #if CONFIG_H264_VIDEOTOOLBOX_HWACCEL | ||
863 | if (h->avctx->colorspace != AVCOL_SPC_RGB) | ||
864 | *fmt++ = AV_PIX_FMT_VIDEOTOOLBOX; | ||
865 | #endif | ||
866 |
2/2✓ Branch 0 taken 484 times.
✓ Branch 1 taken 27538 times.
|
28022 | if (CHROMA444(h)) { |
867 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 484 times.
|
484 | if (h->avctx->colorspace == AVCOL_SPC_RGB) |
868 | ✗ | *fmt++ = AV_PIX_FMT_GBRP; | |
869 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 482 times.
|
484 | else if (h->avctx->color_range == AVCOL_RANGE_JPEG) |
870 | 2 | *fmt++ = AV_PIX_FMT_YUVJ444P; | |
871 | else | ||
872 | 482 | *fmt++ = AV_PIX_FMT_YUV444P; | |
873 |
2/2✓ Branch 0 taken 22 times.
✓ Branch 1 taken 27516 times.
|
27538 | } else if (CHROMA422(h)) { |
874 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
|
22 | if (h->avctx->color_range == AVCOL_RANGE_JPEG) |
875 | ✗ | *fmt++ = AV_PIX_FMT_YUVJ422P; | |
876 | else | ||
877 | 22 | *fmt++ = AV_PIX_FMT_YUV422P; | |
878 | } else { | ||
879 | #if CONFIG_H264_DXVA2_HWACCEL | ||
880 | *fmt++ = AV_PIX_FMT_DXVA2_VLD; | ||
881 | #endif | ||
882 | #if CONFIG_H264_D3D11VA_HWACCEL | ||
883 | *fmt++ = AV_PIX_FMT_D3D11VA_VLD; | ||
884 | *fmt++ = AV_PIX_FMT_D3D11; | ||
885 | #endif | ||
886 | #if CONFIG_H264_D3D12VA_HWACCEL | ||
887 | *fmt++ = AV_PIX_FMT_D3D12; | ||
888 | #endif | ||
889 | #if CONFIG_H264_VAAPI_HWACCEL | ||
890 | 27516 | *fmt++ = AV_PIX_FMT_VAAPI; | |
891 | #endif | ||
892 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 27513 times.
|
27516 | if (h->avctx->color_range == AVCOL_RANGE_JPEG) |
893 | 3 | *fmt++ = AV_PIX_FMT_YUVJ420P; | |
894 | else | ||
895 | 27513 | *fmt++ = AV_PIX_FMT_YUV420P; | |
896 | } | ||
897 | 28022 | break; | |
898 | ✗ | default: | |
899 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
900 | ✗ | "Unsupported bit depth %d\n", h->ps.sps->bit_depth_luma); | |
901 | ✗ | return AVERROR_INVALIDDATA; | |
902 | } | ||
903 | |||
904 | 28549 | *fmt = AV_PIX_FMT_NONE; | |
905 | |||
906 |
2/2✓ Branch 0 taken 84244 times.
✓ Branch 1 taken 588 times.
|
84832 | for (int i = 0; pix_fmts[i] != AV_PIX_FMT_NONE; i++) |
907 |
4/4✓ Branch 0 taken 28217 times.
✓ Branch 1 taken 56027 times.
✓ Branch 2 taken 27961 times.
✓ Branch 3 taken 256 times.
|
84244 | if (pix_fmts[i] == h->avctx->pix_fmt && !force_callback) |
908 | 27961 | return pix_fmts[i]; | |
909 | 588 | return ff_get_format(h->avctx, pix_fmts); | |
910 | } | ||
911 | |||
912 | /* export coded and cropped frame dimensions to AVCodecContext */ | ||
913 | 28290 | static void init_dimensions(H264Context *h) | |
914 | { | ||
915 | 28290 | const SPS *sps = h->ps.sps; | |
916 | 28290 | int cr = sps->crop_right; | |
917 | 28290 | int cl = sps->crop_left; | |
918 | 28290 | int ct = sps->crop_top; | |
919 | 28290 | int cb = sps->crop_bottom; | |
920 | 28290 | int width = h->width - (cr + cl); | |
921 | 28290 | int height = h->height - (ct + cb); | |
922 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28290 times.
|
28290 | av_assert0(sps->crop_right + sps->crop_left < (unsigned)h->width); |
923 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28290 times.
|
28290 | av_assert0(sps->crop_top + sps->crop_bottom < (unsigned)h->height); |
924 | |||
925 | /* handle container cropping */ | ||
926 |
3/4✓ Branch 0 taken 26049 times.
✓ Branch 1 taken 2241 times.
✓ Branch 2 taken 26049 times.
✗ Branch 3 not taken.
|
28290 | if (h->width_from_caller > 0 && h->height_from_caller > 0 && |
927 |
3/4✓ Branch 0 taken 26048 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 26048 times.
✗ Branch 3 not taken.
|
26049 | !sps->crop_top && !sps->crop_left && |
928 |
2/2✓ Branch 0 taken 26039 times.
✓ Branch 1 taken 9 times.
|
26048 | FFALIGN(h->width_from_caller, 16) == FFALIGN(width, 16) && |
929 |
1/2✓ Branch 0 taken 26039 times.
✗ Branch 1 not taken.
|
26039 | FFALIGN(h->height_from_caller, 16) == FFALIGN(height, 16) && |
930 |
2/2✓ Branch 0 taken 26038 times.
✓ Branch 1 taken 1 times.
|
26039 | h->width_from_caller <= width && |
931 |
2/2✓ Branch 0 taken 26036 times.
✓ Branch 1 taken 2 times.
|
26038 | h->height_from_caller <= height) { |
932 | 26036 | width = h->width_from_caller; | |
933 | 26036 | height = h->height_from_caller; | |
934 | 26036 | cl = 0; | |
935 | 26036 | ct = 0; | |
936 | 26036 | cr = h->width - width; | |
937 | 26036 | cb = h->height - height; | |
938 | } else { | ||
939 | 2254 | h->width_from_caller = 0; | |
940 | 2254 | h->height_from_caller = 0; | |
941 | } | ||
942 | |||
943 | 28290 | h->avctx->coded_width = h->width; | |
944 | 28290 | h->avctx->coded_height = h->height; | |
945 | 28290 | h->avctx->width = width; | |
946 | 28290 | h->avctx->height = height; | |
947 | 28290 | h->crop_right = cr; | |
948 | 28290 | h->crop_left = cl; | |
949 | 28290 | h->crop_top = ct; | |
950 | 28290 | h->crop_bottom = cb; | |
951 | 28290 | } | |
952 | |||
953 | 601 | static int h264_slice_header_init(H264Context *h) | |
954 | { | ||
955 | 601 | const SPS *sps = h->ps.sps; | |
956 | int i, ret; | ||
957 | |||
958 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 601 times.
|
601 | if (!sps) { |
959 | ✗ | ret = AVERROR_INVALIDDATA; | |
960 | ✗ | goto fail; | |
961 | } | ||
962 | |||
963 | 601 | ff_set_sar(h->avctx, sps->vui.sar); | |
964 | 601 | av_pix_fmt_get_chroma_sub_sample(h->avctx->pix_fmt, | |
965 | &h->chroma_x_shift, &h->chroma_y_shift); | ||
966 | |||
967 |
2/2✓ Branch 0 taken 183 times.
✓ Branch 1 taken 418 times.
|
601 | if (sps->timing_info_present_flag) { |
968 | 183 | int64_t den = sps->time_scale; | |
969 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 183 times.
|
183 | if (h->x264_build < 44U) |
970 | ✗ | den *= 2; | |
971 | 183 | av_reduce(&h->avctx->framerate.den, &h->avctx->framerate.num, | |
972 | 183 | sps->num_units_in_tick * 2, den, 1 << 30); | |
973 | } | ||
974 | |||
975 | 601 | ff_h264_free_tables(h); | |
976 | |||
977 | 601 | h->first_field = 0; | |
978 | 601 | h->prev_interlaced_frame = 1; | |
979 | |||
980 | 601 | init_scan_tables(h); | |
981 | 601 | ret = ff_h264_alloc_tables(h); | |
982 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 601 times.
|
601 | if (ret < 0) { |
983 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Could not allocate memory\n"); | |
984 | ✗ | goto fail; | |
985 | } | ||
986 | |||
987 |
2/4✓ Branch 0 taken 601 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 601 times.
✗ Branch 3 not taken.
|
601 | if (sps->bit_depth_luma < 8 || sps->bit_depth_luma > 14 || |
988 |
2/4✓ Branch 0 taken 601 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 601 times.
|
601 | sps->bit_depth_luma == 11 || sps->bit_depth_luma == 13 |
989 | ) { | ||
990 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Unsupported bit depth %d\n", | |
991 | ✗ | sps->bit_depth_luma); | |
992 | ✗ | ret = AVERROR_INVALIDDATA; | |
993 | ✗ | goto fail; | |
994 | } | ||
995 | |||
996 | 601 | h->cur_bit_depth_luma = | |
997 | 601 | h->avctx->bits_per_raw_sample = sps->bit_depth_luma; | |
998 | 601 | h->cur_chroma_format_idc = sps->chroma_format_idc; | |
999 | 601 | h->pixel_shift = sps->bit_depth_luma > 8; | |
1000 | 601 | h->chroma_format_idc = sps->chroma_format_idc; | |
1001 | 601 | h->bit_depth_luma = sps->bit_depth_luma; | |
1002 | |||
1003 | 601 | ff_h264dsp_init(&h->h264dsp, sps->bit_depth_luma, | |
1004 | 601 | sps->chroma_format_idc); | |
1005 | 601 | ff_h264chroma_init(&h->h264chroma, sps->bit_depth_chroma); | |
1006 | 601 | ff_h264qpel_init(&h->h264qpel, sps->bit_depth_luma); | |
1007 | 601 | ff_h264_pred_init(&h->hpc, AV_CODEC_ID_H264, sps->bit_depth_luma, | |
1008 | 601 | sps->chroma_format_idc); | |
1009 | 601 | ff_videodsp_init(&h->vdsp, sps->bit_depth_luma); | |
1010 | |||
1011 |
2/2✓ Branch 0 taken 600 times.
✓ Branch 1 taken 1 times.
|
601 | if (!HAVE_THREADS || !(h->avctx->active_thread_type & FF_THREAD_SLICE)) { |
1012 | 600 | ff_h264_slice_context_init(h, &h->slice_ctx[0]); | |
1013 | } else { | ||
1014 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | for (i = 0; i < h->nb_slice_ctx; i++) { |
1015 | 2 | H264SliceContext *sl = &h->slice_ctx[i]; | |
1016 | |||
1017 | 2 | sl->h264 = h; | |
1018 | 2 | sl->intra4x4_pred_mode = h->intra4x4_pred_mode + i * 8 * 2 * h->mb_stride; | |
1019 | 2 | sl->mvd_table[0] = h->mvd_table[0] + i * 8 * 2 * h->mb_stride; | |
1020 | 2 | sl->mvd_table[1] = h->mvd_table[1] + i * 8 * 2 * h->mb_stride; | |
1021 | |||
1022 | 2 | ff_h264_slice_context_init(h, sl); | |
1023 | } | ||
1024 | } | ||
1025 | |||
1026 | 601 | h->context_initialized = 1; | |
1027 | |||
1028 | 601 | return 0; | |
1029 | ✗ | fail: | |
1030 | ✗ | ff_h264_free_tables(h); | |
1031 | ✗ | h->context_initialized = 0; | |
1032 | ✗ | return ret; | |
1033 | } | ||
1034 | |||
1035 | 55928 | static enum AVPixelFormat non_j_pixfmt(enum AVPixelFormat a) | |
1036 | { | ||
1037 |
2/4✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 55926 times.
|
55928 | switch (a) { |
1038 | 2 | case AV_PIX_FMT_YUVJ420P: return AV_PIX_FMT_YUV420P; | |
1039 | ✗ | case AV_PIX_FMT_YUVJ422P: return AV_PIX_FMT_YUV422P; | |
1040 | ✗ | case AV_PIX_FMT_YUVJ444P: return AV_PIX_FMT_YUV444P; | |
1041 | 55926 | default: | |
1042 | 55926 | return a; | |
1043 | } | ||
1044 | } | ||
1045 | |||
1046 | 28290 | static int h264_init_ps(H264Context *h, const H264SliceContext *sl, int first_slice) | |
1047 | { | ||
1048 | const SPS *sps; | ||
1049 | 28290 | int needs_reinit = 0, must_reinit, ret; | |
1050 | |||
1051 |
2/2✓ Branch 0 taken 28096 times.
✓ Branch 1 taken 194 times.
|
28290 | if (first_slice) |
1052 | 28096 | ff_refstruct_replace(&h->ps.pps, h->ps.pps_list[sl->pps_id]); | |
1053 | |||
1054 |
2/2✓ Branch 0 taken 587 times.
✓ Branch 1 taken 27703 times.
|
28290 | if (h->ps.sps != h->ps.pps->sps) { |
1055 | 587 | h->ps.sps = h->ps.pps->sps; | |
1056 | |||
1057 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 580 times.
|
587 | if (h->mb_width != h->ps.sps->mb_width || |
1058 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | h->mb_height != h->ps.sps->mb_height || |
1059 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
|
7 | h->cur_bit_depth_luma != h->ps.sps->bit_depth_luma || |
1060 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
|
6 | h->cur_chroma_format_idc != h->ps.sps->chroma_format_idc |
1061 | ) | ||
1062 | 582 | needs_reinit = 1; | |
1063 | |||
1064 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 576 times.
|
587 | if (h->bit_depth_luma != h->ps.sps->bit_depth_luma || |
1065 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 10 times.
|
11 | h->chroma_format_idc != h->ps.sps->chroma_format_idc) |
1066 | 577 | needs_reinit = 1; | |
1067 | } | ||
1068 | 28290 | sps = h->ps.sps; | |
1069 | |||
1070 |
2/2✓ Branch 0 taken 27713 times.
✓ Branch 1 taken 577 times.
|
56003 | must_reinit = (h->context_initialized && |
1071 |
2/2✓ Branch 0 taken 27707 times.
✓ Branch 1 taken 6 times.
|
27713 | ( 16*sps->mb_width != h->avctx->coded_width |
1072 |
1/2✓ Branch 0 taken 27707 times.
✗ Branch 1 not taken.
|
27707 | || 16*sps->mb_height != h->avctx->coded_height |
1073 |
2/2✓ Branch 0 taken 27706 times.
✓ Branch 1 taken 1 times.
|
27707 | || h->cur_bit_depth_luma != sps->bit_depth_luma |
1074 |
2/2✓ Branch 0 taken 27705 times.
✓ Branch 1 taken 1 times.
|
27706 | || h->cur_chroma_format_idc != sps->chroma_format_idc |
1075 |
1/2✓ Branch 0 taken 27705 times.
✗ Branch 1 not taken.
|
27705 | || h->mb_width != sps->mb_width |
1076 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27705 times.
|
27705 | || h->mb_height != sps->mb_height |
1077 | )); | ||
1078 |
2/2✓ Branch 0 taken 27964 times.
✓ Branch 1 taken 326 times.
|
28290 | if (h->avctx->pix_fmt == AV_PIX_FMT_NONE |
1079 |
2/2✓ Branch 3 taken 3 times.
✓ Branch 4 taken 27961 times.
|
27964 | || (non_j_pixfmt(h->avctx->pix_fmt) != non_j_pixfmt(get_pixel_format(h, 0)))) |
1080 | 329 | must_reinit = 1; | |
1081 | |||
1082 |
4/4✓ Branch 0 taken 28096 times.
✓ Branch 1 taken 194 times.
✓ Branch 3 taken 71 times.
✓ Branch 4 taken 28025 times.
|
28290 | if (first_slice && av_cmp_q(sps->vui.sar, h->avctx->sample_aspect_ratio)) |
1083 | 71 | must_reinit = 1; | |
1084 | |||
1085 |
1/2✓ Branch 0 taken 28290 times.
✗ Branch 1 not taken.
|
28290 | if (!h->setup_finished) { |
1086 | 28290 | h->avctx->profile = ff_h264_get_profile(sps); | |
1087 | 28290 | h->avctx->level = sps->level_idc; | |
1088 | 28290 | h->avctx->refs = sps->ref_frame_count; | |
1089 | |||
1090 | 28290 | h->mb_width = sps->mb_width; | |
1091 | 28290 | h->mb_height = sps->mb_height; | |
1092 | 28290 | h->mb_num = h->mb_width * h->mb_height; | |
1093 | 28290 | h->mb_stride = h->mb_width + 1; | |
1094 | |||
1095 | 28290 | h->b_stride = h->mb_width * 4; | |
1096 | |||
1097 | 28290 | h->chroma_y_shift = sps->chroma_format_idc <= 1; // 400 uses yuv420p | |
1098 | |||
1099 | 28290 | h->width = 16 * h->mb_width; | |
1100 | 28290 | h->height = 16 * h->mb_height; | |
1101 | |||
1102 | 28290 | init_dimensions(h); | |
1103 | |||
1104 |
2/2✓ Branch 0 taken 1287 times.
✓ Branch 1 taken 27003 times.
|
28290 | if (sps->vui.video_signal_type_present_flag) { |
1105 | 2574 | h->avctx->color_range = sps->vui.video_full_range_flag > 0 ? AVCOL_RANGE_JPEG | |
1106 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1285 times.
|
1287 | : AVCOL_RANGE_MPEG; |
1107 |
2/2✓ Branch 0 taken 1189 times.
✓ Branch 1 taken 98 times.
|
1287 | if (sps->vui.colour_description_present_flag) { |
1108 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 1170 times.
|
1189 | if (h->avctx->colorspace != sps->vui.matrix_coeffs) |
1109 | 19 | needs_reinit = 1; | |
1110 | 1189 | h->avctx->color_primaries = sps->vui.colour_primaries; | |
1111 | 1189 | h->avctx->color_trc = sps->vui.transfer_characteristics; | |
1112 | 1189 | h->avctx->colorspace = sps->vui.matrix_coeffs; | |
1113 | } | ||
1114 | } | ||
1115 | |||
1116 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 28290 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
28290 | if (h->sei.common.alternative_transfer.present && |
1117 | ✗ | av_color_transfer_name(h->sei.common.alternative_transfer.preferred_transfer_characteristics) && | |
1118 | ✗ | h->sei.common.alternative_transfer.preferred_transfer_characteristics != AVCOL_TRC_UNSPECIFIED) { | |
1119 | ✗ | h->avctx->color_trc = h->sei.common.alternative_transfer.preferred_transfer_characteristics; | |
1120 | } | ||
1121 | } | ||
1122 | 28290 | h->avctx->chroma_sample_location = sps->vui.chroma_location; | |
1123 | |||
1124 |
5/6✓ Branch 0 taken 27713 times.
✓ Branch 1 taken 577 times.
✓ Branch 2 taken 27705 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 27705 times.
|
28290 | if (!h->context_initialized || must_reinit || needs_reinit) { |
1125 | 585 | int flush_changes = h->context_initialized; | |
1126 | 585 | h->context_initialized = 0; | |
1127 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 585 times.
|
585 | if (sl != h->slice_ctx) { |
1128 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
1129 | "changing width %d -> %d / height %d -> %d on " | ||
1130 | "slice %d\n", | ||
1131 | ✗ | h->width, h->avctx->coded_width, | |
1132 | ✗ | h->height, h->avctx->coded_height, | |
1133 | ✗ | h->current_slice + 1); | |
1134 | ✗ | return AVERROR_INVALIDDATA; | |
1135 | } | ||
1136 | |||
1137 | av_assert1(first_slice); | ||
1138 | |||
1139 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 577 times.
|
585 | if (flush_changes) |
1140 | 8 | ff_h264_flush_change(h); | |
1141 | |||
1142 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 585 times.
|
585 | if ((ret = get_pixel_format(h, 1)) < 0) |
1143 | ✗ | return ret; | |
1144 | 585 | h->avctx->pix_fmt = ret; | |
1145 | |||
1146 | 585 | av_log(h->avctx, AV_LOG_VERBOSE, "Reinit context to %dx%d, " | |
1147 | 585 | "pix_fmt: %s\n", h->width, h->height, av_get_pix_fmt_name(h->avctx->pix_fmt)); | |
1148 | |||
1149 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 585 times.
|
585 | if ((ret = h264_slice_header_init(h)) < 0) { |
1150 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
1151 | "h264_slice_header_init() failed\n"); | ||
1152 | ✗ | return ret; | |
1153 | } | ||
1154 | } | ||
1155 | |||
1156 | 28290 | return 0; | |
1157 | } | ||
1158 | |||
1159 | 24923 | static int h264_export_frame_props(H264Context *h) | |
1160 | { | ||
1161 | 24923 | const SPS *sps = h->ps.sps; | |
1162 | 24923 | H264Picture *cur = h->cur_pic_ptr; | |
1163 | 24923 | AVFrame *out = cur->f; | |
1164 | 24923 | int interlaced_frame = 0, top_field_first = 0; | |
1165 | int ret; | ||
1166 | |||
1167 | 24923 | out->flags &= ~AV_FRAME_FLAG_INTERLACED; | |
1168 | 24923 | out->repeat_pict = 0; | |
1169 | |||
1170 | /* Signal interlacing information externally. */ | ||
1171 | /* Prioritize picture timing SEI information over used | ||
1172 | * decoding process if it exists. */ | ||
1173 |
2/2✓ Branch 0 taken 1427 times.
✓ Branch 1 taken 23496 times.
|
24923 | if (h->sei.picture_timing.present) { |
1174 | 1427 | int ret = ff_h264_sei_process_picture_timing(&h->sei.picture_timing, sps, | |
1175 | 1427 | h->avctx); | |
1176 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1427 times.
|
1427 | if (ret < 0) { |
1177 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Error processing a picture timing SEI\n"); | |
1178 | ✗ | if (h->avctx->err_recognition & AV_EF_EXPLODE) | |
1179 | ✗ | return ret; | |
1180 | ✗ | h->sei.picture_timing.present = 0; | |
1181 | } | ||
1182 | } | ||
1183 | |||
1184 |
4/4✓ Branch 0 taken 1505 times.
✓ Branch 1 taken 23418 times.
✓ Branch 2 taken 1419 times.
✓ Branch 3 taken 86 times.
|
26342 | if (sps->pic_struct_present_flag && h->sei.picture_timing.present) { |
1185 | 1419 | const H264SEIPictureTiming *pt = &h->sei.picture_timing; | |
1186 |
4/7✓ Branch 0 taken 132 times.
✓ Branch 1 taken 377 times.
✓ Branch 2 taken 743 times.
✓ Branch 3 taken 167 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
|
1419 | switch (pt->pic_struct) { |
1187 | 132 | case H264_SEI_PIC_STRUCT_FRAME: | |
1188 | 132 | break; | |
1189 | 377 | case H264_SEI_PIC_STRUCT_TOP_FIELD: | |
1190 | case H264_SEI_PIC_STRUCT_BOTTOM_FIELD: | ||
1191 | 377 | interlaced_frame = 1; | |
1192 | 377 | break; | |
1193 | 743 | case H264_SEI_PIC_STRUCT_TOP_BOTTOM: | |
1194 | case H264_SEI_PIC_STRUCT_BOTTOM_TOP: | ||
1195 |
3/4✓ Branch 0 taken 4 times.
✓ Branch 1 taken 739 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
743 | if (FIELD_OR_MBAFF_PICTURE(h)) |
1196 | 739 | interlaced_frame = 1; | |
1197 | else | ||
1198 | // try to flag soft telecine progressive | ||
1199 | 4 | interlaced_frame = !!h->prev_interlaced_frame; | |
1200 | 743 | break; | |
1201 | 167 | case H264_SEI_PIC_STRUCT_TOP_BOTTOM_TOP: | |
1202 | case H264_SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM: | ||
1203 | /* Signal the possibility of telecined film externally | ||
1204 | * (pic_struct 5,6). From these hints, let the applications | ||
1205 | * decide if they apply deinterlacing. */ | ||
1206 | 167 | out->repeat_pict = 1; | |
1207 | 167 | break; | |
1208 | ✗ | case H264_SEI_PIC_STRUCT_FRAME_DOUBLING: | |
1209 | ✗ | out->repeat_pict = 2; | |
1210 | ✗ | break; | |
1211 | ✗ | case H264_SEI_PIC_STRUCT_FRAME_TRIPLING: | |
1212 | ✗ | out->repeat_pict = 4; | |
1213 | ✗ | break; | |
1214 | } | ||
1215 | |||
1216 |
2/2✓ Branch 0 taken 652 times.
✓ Branch 1 taken 767 times.
|
1419 | if ((pt->ct_type & 3) && |
1217 |
2/2✓ Branch 0 taken 488 times.
✓ Branch 1 taken 164 times.
|
652 | pt->pic_struct <= H264_SEI_PIC_STRUCT_BOTTOM_TOP) |
1218 | 488 | interlaced_frame = ((pt->ct_type & (1 << 1)) != 0); | |
1219 | } else { | ||
1220 | /* Derive interlacing flag from used decoding process. */ | ||
1221 |
4/4✓ Branch 0 taken 21917 times.
✓ Branch 1 taken 1587 times.
✓ Branch 2 taken 2821 times.
✓ Branch 3 taken 19096 times.
|
23504 | interlaced_frame = !!FIELD_OR_MBAFF_PICTURE(h); |
1222 | } | ||
1223 | 24923 | h->prev_interlaced_frame = interlaced_frame; | |
1224 | |||
1225 |
2/2✓ Branch 0 taken 3337 times.
✓ Branch 1 taken 21586 times.
|
24923 | if (cur->field_poc[0] != cur->field_poc[1]) { |
1226 | /* Derive top_field_first from field pocs. */ | ||
1227 | 3337 | top_field_first = (cur->field_poc[0] < cur->field_poc[1]); | |
1228 | } else { | ||
1229 |
4/4✓ Branch 0 taken 225 times.
✓ Branch 1 taken 21361 times.
✓ Branch 2 taken 139 times.
✓ Branch 3 taken 86 times.
|
21586 | if (sps->pic_struct_present_flag && h->sei.picture_timing.present) { |
1230 | /* Use picture timing SEI information. Even if it is a | ||
1231 | * information of a past frame, better than nothing. */ | ||
1232 |
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 || |
1233 |
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) |
1234 | 3 | top_field_first = 1; | |
1235 |
2/2✓ Branch 0 taken 2554 times.
✓ Branch 1 taken 18893 times.
|
21447 | } else if (interlaced_frame) { |
1236 | /* Default to top field first when pic_struct_present_flag | ||
1237 | * is not set but interlaced frame detected */ | ||
1238 | 2554 | top_field_first = 1; | |
1239 | } // else | ||
1240 | /* Most likely progressive */ | ||
1241 | } | ||
1242 | |||
1243 | 24923 | out->flags |= (AV_FRAME_FLAG_INTERLACED * interlaced_frame) | | |
1244 | 24923 | (AV_FRAME_FLAG_TOP_FIELD_FIRST * top_field_first); | |
1245 | |||
1246 | 24923 | ret = ff_h2645_sei_to_frame(out, &h->sei.common, AV_CODEC_ID_H264, h->avctx, | |
1247 | 24923 | &sps->vui, sps->bit_depth_luma, sps->bit_depth_chroma, | |
1248 | 24923 | cur->poc + (unsigned)(h->poc_offset << 5)); | |
1249 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24923 times.
|
24923 | if (ret < 0) |
1250 | ✗ | return ret; | |
1251 | |||
1252 |
2/2✓ Branch 0 taken 652 times.
✓ Branch 1 taken 24271 times.
|
24923 | if (h->sei.picture_timing.timecode_cnt > 0) { |
1253 | uint32_t *tc_sd; | ||
1254 | char tcbuf[AV_TIMECODE_STR_SIZE]; | ||
1255 | AVFrameSideData *tcside; | ||
1256 | 652 | ret = ff_frame_new_side_data(h->avctx, out, AV_FRAME_DATA_S12M_TIMECODE, | |
1257 | sizeof(uint32_t)*4, &tcside); | ||
1258 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 652 times.
|
652 | if (ret < 0) |
1259 | ✗ | return ret; | |
1260 | |||
1261 |
1/2✓ Branch 0 taken 652 times.
✗ Branch 1 not taken.
|
652 | if (tcside) { |
1262 | 652 | tc_sd = (uint32_t*)tcside->data; | |
1263 | 652 | tc_sd[0] = h->sei.picture_timing.timecode_cnt; | |
1264 | |||
1265 |
2/2✓ Branch 0 taken 953 times.
✓ Branch 1 taken 652 times.
|
1605 | for (int i = 0; i < tc_sd[0]; i++) { |
1266 | 953 | int drop = h->sei.picture_timing.timecode[i].dropframe; | |
1267 | 953 | int hh = h->sei.picture_timing.timecode[i].hours; | |
1268 | 953 | int mm = h->sei.picture_timing.timecode[i].minutes; | |
1269 | 953 | int ss = h->sei.picture_timing.timecode[i].seconds; | |
1270 | 953 | int ff = h->sei.picture_timing.timecode[i].frame; | |
1271 | |||
1272 | 953 | tc_sd[i + 1] = av_timecode_get_smpte(h->avctx->framerate, drop, hh, mm, ss, ff); | |
1273 | 953 | av_timecode_make_smpte_tc_string2(tcbuf, h->avctx->framerate, tc_sd[i + 1], 0, 0); | |
1274 | 953 | av_dict_set(&out->metadata, "timecode", tcbuf, 0); | |
1275 | } | ||
1276 | } | ||
1277 | 652 | h->sei.picture_timing.timecode_cnt = 0; | |
1278 | } | ||
1279 | |||
1280 | 24923 | return 0; | |
1281 | } | ||
1282 | |||
1283 | 24923 | static int h264_select_output_frame(H264Context *h) | |
1284 | { | ||
1285 | 24923 | const SPS *sps = h->ps.sps; | |
1286 | 24923 | H264Picture *out = h->cur_pic_ptr; | |
1287 | 24923 | H264Picture *cur = h->cur_pic_ptr; | |
1288 | int i, pics, out_of_order, out_idx; | ||
1289 | |||
1290 | 24923 | cur->mmco_reset = h->mmco_reset; | |
1291 | 24923 | h->mmco_reset = 0; | |
1292 | |||
1293 |
2/2✓ Branch 0 taken 20019 times.
✓ Branch 1 taken 4904 times.
|
24923 | if (sps->bitstream_restriction_flag || |
1294 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20019 times.
|
20019 | h->avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT) { |
1295 | 4904 | h->avctx->has_b_frames = FFMAX(h->avctx->has_b_frames, sps->num_reorder_frames); | |
1296 | } | ||
1297 | |||
1298 | 408692 | for (i = 0; 1; i++) { | |
1299 |
4/4✓ Branch 0 taken 392777 times.
✓ Branch 1 taken 15915 times.
✓ Branch 2 taken 9008 times.
✓ Branch 3 taken 383769 times.
|
408692 | if(i == H264_MAX_DPB_FRAMES || cur->poc < h->last_pocs[i]){ |
1300 |
1/2✓ Branch 0 taken 24923 times.
✗ Branch 1 not taken.
|
24923 | if(i) |
1301 | 24923 | h->last_pocs[i-1] = cur->poc; | |
1302 | 24923 | break; | |
1303 |
2/2✓ Branch 0 taken 358846 times.
✓ Branch 1 taken 24923 times.
|
383769 | } else if(i) { |
1304 | 358846 | h->last_pocs[i-1]= h->last_pocs[i]; | |
1305 | } | ||
1306 | } | ||
1307 | 24923 | out_of_order = H264_MAX_DPB_FRAMES - i; | |
1308 |
2/2✓ Branch 0 taken 16799 times.
✓ Branch 1 taken 8124 times.
|
24923 | if( cur->f->pict_type == AV_PICTURE_TYPE_B |
1309 |
4/4✓ Branch 0 taken 15678 times.
✓ Branch 1 taken 1121 times.
✓ Branch 2 taken 5063 times.
✓ Branch 3 taken 10615 times.
|
16799 | || (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)) |
1310 | 13187 | out_of_order = FFMAX(out_of_order, 1); | |
1311 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24923 times.
|
24923 | if (out_of_order == H264_MAX_DPB_FRAMES) { |
1312 | ✗ | av_log(h->avctx, AV_LOG_VERBOSE, "Invalid POC %d<%d\n", cur->poc, h->last_pocs[0]); | |
1313 | ✗ | for (i = 1; i < H264_MAX_DPB_FRAMES; i++) | |
1314 | ✗ | h->last_pocs[i] = INT_MIN; | |
1315 | ✗ | h->last_pocs[0] = cur->poc; | |
1316 | ✗ | cur->mmco_reset = 1; | |
1317 |
3/4✓ Branch 0 taken 140 times.
✓ Branch 1 taken 24783 times.
✓ Branch 2 taken 140 times.
✗ Branch 3 not taken.
|
24923 | } else if(h->avctx->has_b_frames < out_of_order && !sps->bitstream_restriction_flag){ |
1318 |
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; |
1319 | 140 | av_log(h->avctx, loglevel, "Increasing reorder buffer to %d\n", out_of_order); | |
1320 | 140 | h->avctx->has_b_frames = out_of_order; | |
1321 | } | ||
1322 | |||
1323 | 24923 | pics = 0; | |
1324 |
2/2✓ Branch 0 taken 30540 times.
✓ Branch 1 taken 24923 times.
|
55463 | while (h->delayed_pic[pics]) |
1325 | 30540 | pics++; | |
1326 | |||
1327 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24923 times.
|
24923 | av_assert0(pics <= H264_MAX_DPB_FRAMES); |
1328 | |||
1329 | 24923 | h->delayed_pic[pics++] = cur; | |
1330 |
2/2✓ Branch 0 taken 23448 times.
✓ Branch 1 taken 1475 times.
|
24923 | if (cur->reference == 0) |
1331 | 23448 | cur->reference = DELAYED_PIC_REF; | |
1332 | |||
1333 | 24923 | out = h->delayed_pic[0]; | |
1334 | 24923 | out_idx = 0; | |
1335 | 24923 | for (i = 1; h->delayed_pic[i] && | |
1336 |
4/4✓ Branch 0 taken 28089 times.
✓ Branch 1 taken 24456 times.
✓ Branch 2 taken 27709 times.
✓ Branch 3 taken 380 times.
|
52545 | !(h->delayed_pic[i]->f->flags & AV_FRAME_FLAG_KEY) && |
1337 |
2/2✓ Branch 0 taken 27622 times.
✓ Branch 1 taken 87 times.
|
27709 | !h->delayed_pic[i]->mmco_reset; |
1338 | 27622 | i++) | |
1339 |
2/2✓ Branch 0 taken 10307 times.
✓ Branch 1 taken 17315 times.
|
27622 | if (h->delayed_pic[i]->poc < out->poc) { |
1340 | 10307 | out = h->delayed_pic[i]; | |
1341 | 10307 | out_idx = i; | |
1342 | } | ||
1343 |
2/2✓ Branch 0 taken 10258 times.
✓ Branch 1 taken 14665 times.
|
24923 | if (h->avctx->has_b_frames == 0 && |
1344 |
4/4✓ Branch 0 taken 9466 times.
✓ Branch 1 taken 792 times.
✓ Branch 2 taken 12 times.
✓ Branch 3 taken 9454 times.
|
10258 | ((h->delayed_pic[0]->f->flags & AV_FRAME_FLAG_KEY) || h->delayed_pic[0]->mmco_reset)) |
1345 | 804 | h->next_outputed_poc = INT_MIN; | |
1346 | 24923 | out_of_order = out->poc < h->next_outputed_poc; | |
1347 | |||
1348 |
4/4✓ Branch 0 taken 24810 times.
✓ Branch 1 taken 113 times.
✓ Branch 2 taken 24285 times.
✓ Branch 3 taken 525 times.
|
24923 | if (out_of_order || pics > h->avctx->has_b_frames) { |
1349 | 24398 | out->reference &= ~DELAYED_PIC_REF; | |
1350 |
2/2✓ Branch 0 taken 39544 times.
✓ Branch 1 taken 24398 times.
|
63942 | for (i = out_idx; h->delayed_pic[i]; i++) |
1351 | 39544 | h->delayed_pic[i] = h->delayed_pic[i + 1]; | |
1352 | } | ||
1353 |
4/4✓ Branch 0 taken 24810 times.
✓ Branch 1 taken 113 times.
✓ Branch 2 taken 24285 times.
✓ Branch 3 taken 525 times.
|
24923 | if (!out_of_order && pics > h->avctx->has_b_frames) { |
1354 | 24285 | h->next_output_pic = out; | |
1355 |
8/8✓ Branch 0 taken 15498 times.
✓ Branch 1 taken 8787 times.
✓ Branch 2 taken 5241 times.
✓ Branch 3 taken 10257 times.
✓ Branch 4 taken 5157 times.
✓ Branch 5 taken 84 times.
✓ Branch 6 taken 21 times.
✓ Branch 7 taken 5136 times.
|
24285 | if (out_idx == 0 && h->delayed_pic[0] && ((h->delayed_pic[0]->f->flags & AV_FRAME_FLAG_KEY) || h->delayed_pic[0]->mmco_reset)) { |
1356 | 105 | h->next_outputed_poc = INT_MIN; | |
1357 | } else | ||
1358 | 24180 | h->next_outputed_poc = out->poc; | |
1359 | |||
1360 | // We have reached an recovery point and all frames after it in | ||
1361 | // display order are "recovered". | ||
1362 | 24285 | h->frame_recovered |= out->recovered; | |
1363 | |||
1364 | 24285 | out->recovered |= h->frame_recovered & FRAME_RECOVERED_SEI; | |
1365 | |||
1366 |
2/2✓ Branch 0 taken 249 times.
✓ Branch 1 taken 24036 times.
|
24285 | if (!out->recovered) { |
1367 |
1/2✓ Branch 0 taken 249 times.
✗ Branch 1 not taken.
|
249 | if (!(h->avctx->flags & AV_CODEC_FLAG_OUTPUT_CORRUPT) && |
1368 |
1/2✓ Branch 0 taken 249 times.
✗ Branch 1 not taken.
|
249 | !(h->avctx->flags2 & AV_CODEC_FLAG2_SHOW_ALL)) { |
1369 | 249 | h->next_output_pic = NULL; | |
1370 | } else { | ||
1371 | ✗ | out->f->flags |= AV_FRAME_FLAG_CORRUPT; | |
1372 | } | ||
1373 | } | ||
1374 | } else { | ||
1375 |
2/2✓ Branch 0 taken 113 times.
✓ Branch 1 taken 525 times.
|
638 | av_log(h->avctx, AV_LOG_DEBUG, "no picture %s\n", out_of_order ? "ooo" : ""); |
1376 | } | ||
1377 | |||
1378 | 24923 | return 0; | |
1379 | } | ||
1380 | |||
1381 | /* This function is called right after decoding the slice header for a first | ||
1382 | * slice in a field (or a frame). It decides whether we are decoding a new frame | ||
1383 | * or a second field in a pair and does the necessary setup. | ||
1384 | */ | ||
1385 | 28290 | static int h264_field_start(H264Context *h, const H264SliceContext *sl, | |
1386 | const H2645NAL *nal, int first_slice) | ||
1387 | { | ||
1388 | int i; | ||
1389 | const SPS *sps; | ||
1390 | |||
1391 | int last_pic_structure, last_pic_droppable, ret; | ||
1392 | |||
1393 | 28290 | ret = h264_init_ps(h, sl, first_slice); | |
1394 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28290 times.
|
28290 | if (ret < 0) |
1395 | ✗ | return ret; | |
1396 | |||
1397 | 28290 | sps = h->ps.sps; | |
1398 | |||
1399 |
2/2✓ Branch 0 taken 5237 times.
✓ Branch 1 taken 23053 times.
|
28290 | if (sps->bitstream_restriction_flag && |
1400 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 5208 times.
|
5237 | h->avctx->has_b_frames < sps->num_reorder_frames) { |
1401 | 29 | h->avctx->has_b_frames = sps->num_reorder_frames; | |
1402 | } | ||
1403 | |||
1404 | 28290 | last_pic_droppable = h->droppable; | |
1405 | 28290 | last_pic_structure = h->picture_structure; | |
1406 | 28290 | h->droppable = (nal->ref_idc == 0); | |
1407 | 28290 | h->picture_structure = sl->picture_structure; | |
1408 | |||
1409 | 28290 | h->poc.frame_num = sl->frame_num; | |
1410 | 28290 | h->poc.poc_lsb = sl->poc_lsb; | |
1411 | 28290 | h->poc.delta_poc_bottom = sl->delta_poc_bottom; | |
1412 | 28290 | h->poc.delta_poc[0] = sl->delta_poc[0]; | |
1413 | 28290 | h->poc.delta_poc[1] = sl->delta_poc[1]; | |
1414 | |||
1415 |
2/2✓ Branch 0 taken 1077 times.
✓ Branch 1 taken 27213 times.
|
28290 | if (nal->type == H264_NAL_IDR_SLICE) |
1416 | 1077 | h->poc_offset = sl->idr_pic_id; | |
1417 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27213 times.
|
27213 | else if (h->picture_intra_only) |
1418 | ✗ | h->poc_offset = 0; | |
1419 | |||
1420 | /* Shorten frame num gaps so we don't have to allocate reference | ||
1421 | * frames just to throw them away */ | ||
1422 |
2/2✓ Branch 0 taken 16146 times.
✓ Branch 1 taken 12144 times.
|
28290 | if (h->poc.frame_num != h->poc.prev_frame_num) { |
1423 | 16146 | int unwrap_prev_frame_num = h->poc.prev_frame_num; | |
1424 | 16146 | int max_frame_num = 1 << sps->log2_max_frame_num; | |
1425 | |||
1426 |
2/2✓ Branch 0 taken 193 times.
✓ Branch 1 taken 15953 times.
|
16146 | if (unwrap_prev_frame_num > h->poc.frame_num) |
1427 | 193 | unwrap_prev_frame_num -= max_frame_num; | |
1428 | |||
1429 |
2/2✓ Branch 0 taken 74 times.
✓ Branch 1 taken 16072 times.
|
16146 | if ((h->poc.frame_num - unwrap_prev_frame_num) > sps->ref_frame_count) { |
1430 | 74 | unwrap_prev_frame_num = (h->poc.frame_num - sps->ref_frame_count) - 1; | |
1431 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 72 times.
|
74 | if (unwrap_prev_frame_num < 0) |
1432 | 2 | unwrap_prev_frame_num += max_frame_num; | |
1433 | |||
1434 | 74 | h->poc.prev_frame_num = unwrap_prev_frame_num; | |
1435 | } | ||
1436 | } | ||
1437 | |||
1438 | /* See if we have a decoded first field looking for a pair... | ||
1439 | * Here, we're using that to see if we should mark previously | ||
1440 | * decode frames as "finished". | ||
1441 | * We have to do that before the "dummy" in-between frame allocation, | ||
1442 | * since that can modify h->cur_pic_ptr. */ | ||
1443 |
2/2✓ Branch 0 taken 3362 times.
✓ Branch 1 taken 24928 times.
|
28290 | if (h->first_field) { |
1444 | 3362 | int last_field = last_pic_structure == PICT_BOTTOM_FIELD; | |
1445 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3362 times.
|
3362 | av_assert0(h->cur_pic_ptr); |
1446 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3362 times.
|
3362 | av_assert0(h->cur_pic_ptr->f->buf[0]); |
1447 | assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF); | ||
1448 | |||
1449 | /* Mark old field/frame as completed */ | ||
1450 |
1/2✓ Branch 0 taken 3362 times.
✗ Branch 1 not taken.
|
3362 | if (h->cur_pic_ptr->tf.owner[last_field] == h->avctx) { |
1451 | 3362 | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, last_field); | |
1452 | } | ||
1453 | |||
1454 | /* figure out if we have a complementary field pair */ | ||
1455 |
2/4✓ Branch 0 taken 3362 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3362 times.
|
3362 | if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) { |
1456 | /* Previous field is unmatched. Don't display it, but let it | ||
1457 | * remain for reference if marked as such. */ | ||
1458 | ✗ | if (last_pic_structure != PICT_FRAME) { | |
1459 | ✗ | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, | |
1460 | last_pic_structure == PICT_TOP_FIELD); | ||
1461 | } | ||
1462 | } else { | ||
1463 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3362 times.
|
3362 | if (h->cur_pic_ptr->frame_num != h->poc.frame_num) { |
1464 | /* This and previous field were reference, but had | ||
1465 | * different frame_nums. Consider this field first in | ||
1466 | * pair. Throw away previous field except for reference | ||
1467 | * purposes. */ | ||
1468 | ✗ | if (last_pic_structure != PICT_FRAME) { | |
1469 | ✗ | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, | |
1470 | last_pic_structure == PICT_TOP_FIELD); | ||
1471 | } | ||
1472 | } else { | ||
1473 | /* Second field in complementary pair */ | ||
1474 |
3/4✓ Branch 0 taken 3354 times.
✓ Branch 1 taken 8 times.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
|
3362 | if (!((last_pic_structure == PICT_TOP_FIELD && |
1475 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3354 times.
|
3354 | h->picture_structure == PICT_BOTTOM_FIELD) || |
1476 | 8 | (last_pic_structure == PICT_BOTTOM_FIELD && | |
1477 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
|
8 | h->picture_structure == PICT_TOP_FIELD))) { |
1478 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
1479 | "Invalid field mode combination %d/%d\n", | ||
1480 | last_pic_structure, h->picture_structure); | ||
1481 | ✗ | h->picture_structure = last_pic_structure; | |
1482 | ✗ | h->droppable = last_pic_droppable; | |
1483 | ✗ | return AVERROR_INVALIDDATA; | |
1484 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3362 times.
|
3362 | } else if (last_pic_droppable != h->droppable) { |
1485 | ✗ | avpriv_request_sample(h->avctx, | |
1486 | "Found reference and non-reference fields in the same frame, which"); | ||
1487 | ✗ | h->picture_structure = last_pic_structure; | |
1488 | ✗ | h->droppable = last_pic_droppable; | |
1489 | ✗ | return AVERROR_PATCHWELCOME; | |
1490 | } | ||
1491 | } | ||
1492 | } | ||
1493 | } | ||
1494 | |||
1495 |
3/4✓ Branch 0 taken 16831 times.
✓ Branch 1 taken 12144 times.
✓ Branch 2 taken 16831 times.
✗ Branch 3 not taken.
|
57265 | while (h->poc.frame_num != h->poc.prev_frame_num && !h->first_field && |
1496 |
2/2✓ Branch 0 taken 685 times.
✓ Branch 1 taken 16146 times.
|
16831 | h->poc.frame_num != (h->poc.prev_frame_num + 1) % (1 << sps->log2_max_frame_num)) { |
1497 |
2/2✓ Branch 0 taken 653 times.
✓ Branch 1 taken 32 times.
|
685 | const H264Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL; |
1498 | 685 | av_log(h->avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n", | |
1499 | h->poc.frame_num, h->poc.prev_frame_num); | ||
1500 |
2/2✓ Branch 0 taken 108 times.
✓ Branch 1 taken 577 times.
|
685 | if (!sps->gaps_in_frame_num_allowed_flag) |
1501 |
2/2✓ Branch 0 taken 1728 times.
✓ Branch 1 taken 108 times.
|
1836 | for(i=0; i<FF_ARRAY_ELEMS(h->last_pocs); i++) |
1502 | 1728 | h->last_pocs[i] = INT_MIN; | |
1503 | 685 | ret = h264_frame_start(h); | |
1504 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 685 times.
|
685 | if (ret < 0) { |
1505 | ✗ | h->first_field = 0; | |
1506 | ✗ | return ret; | |
1507 | } | ||
1508 | |||
1509 | 685 | h->poc.prev_frame_num++; | |
1510 | 685 | h->poc.prev_frame_num %= 1 << sps->log2_max_frame_num; | |
1511 | 685 | h->cur_pic_ptr->frame_num = h->poc.prev_frame_num; | |
1512 | 685 | h->cur_pic_ptr->invalid_gap = !sps->gaps_in_frame_num_allowed_flag; | |
1513 | 685 | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 0); | |
1514 | 685 | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 1); | |
1515 | |||
1516 | 685 | h->explicit_ref_marking = 0; | |
1517 | 685 | ret = ff_h264_execute_ref_pic_marking(h); | |
1518 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 685 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
685 | if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) |
1519 | ✗ | return ret; | |
1520 | /* Error concealment: If a ref is missing, copy the previous ref | ||
1521 | * in its place. | ||
1522 | * FIXME: Avoiding a memcpy would be nice, but ref handling makes | ||
1523 | * many assumptions about there being no actual duplicates. | ||
1524 | * FIXME: This does not copy padding for out-of-frame motion | ||
1525 | * vectors. Given we are concealing a lost frame, this probably | ||
1526 | * is not noticeable by comparison, but it should be fixed. */ | ||
1527 |
1/2✓ Branch 0 taken 685 times.
✗ Branch 1 not taken.
|
685 | if (h->short_ref_count) { |
1528 | 685 | int c[4] = { | |
1529 | 685 | 1<<(h->ps.sps->bit_depth_luma-1), | |
1530 | 685 | 1<<(h->ps.sps->bit_depth_chroma-1), | |
1531 | 685 | 1<<(h->ps.sps->bit_depth_chroma-1), | |
1532 | -1 | ||
1533 | }; | ||
1534 | |||
1535 |
2/2✓ Branch 0 taken 653 times.
✓ Branch 1 taken 32 times.
|
685 | if (prev && |
1536 |
1/2✓ Branch 0 taken 653 times.
✗ Branch 1 not taken.
|
653 | h->short_ref[0]->f->width == prev->f->width && |
1537 |
1/2✓ Branch 0 taken 653 times.
✗ Branch 1 not taken.
|
653 | h->short_ref[0]->f->height == prev->f->height && |
1538 |
1/2✓ Branch 0 taken 653 times.
✗ Branch 1 not taken.
|
653 | h->short_ref[0]->f->format == prev->f->format) { |
1539 | 653 | ff_thread_await_progress(&prev->tf, INT_MAX, 0); | |
1540 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 625 times.
|
653 | if (prev->field_picture) |
1541 | 28 | ff_thread_await_progress(&prev->tf, INT_MAX, 1); | |
1542 | 653 | ff_thread_release_ext_buffer(&h->short_ref[0]->tf); | |
1543 | 653 | h->short_ref[0]->tf.f = h->short_ref[0]->f; | |
1544 | 653 | ret = ff_thread_ref_frame(&h->short_ref[0]->tf, &prev->tf); | |
1545 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 653 times.
|
653 | if (ret < 0) |
1546 | ✗ | return ret; | |
1547 | 653 | h->short_ref[0]->poc = prev->poc + 2U; | |
1548 | 653 | h->short_ref[0]->gray = prev->gray; | |
1549 | 653 | ff_thread_report_progress(&h->short_ref[0]->tf, INT_MAX, 0); | |
1550 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 625 times.
|
653 | if (h->short_ref[0]->field_picture) |
1551 | 28 | ff_thread_report_progress(&h->short_ref[0]->tf, INT_MAX, 1); | |
1552 |
2/2✓ Branch 0 taken 24 times.
✓ Branch 1 taken 8 times.
|
32 | } else if (!h->frame_recovered) { |
1553 |
1/2✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
|
24 | if (!h->avctx->hwaccel) |
1554 | 24 | color_frame(h->short_ref[0]->f, c); | |
1555 | 24 | h->short_ref[0]->gray = 1; | |
1556 | } | ||
1557 | 685 | h->short_ref[0]->frame_num = h->poc.prev_frame_num; | |
1558 | } | ||
1559 | } | ||
1560 | |||
1561 | /* See if we have a decoded first field looking for a pair... | ||
1562 | * We're using that to see whether to continue decoding in that | ||
1563 | * frame, or to allocate a new one. */ | ||
1564 |
2/2✓ Branch 0 taken 3362 times.
✓ Branch 1 taken 24928 times.
|
28290 | if (h->first_field) { |
1565 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3362 times.
|
3362 | av_assert0(h->cur_pic_ptr); |
1566 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3362 times.
|
3362 | av_assert0(h->cur_pic_ptr->f->buf[0]); |
1567 | assert(h->cur_pic_ptr->reference != DELAYED_PIC_REF); | ||
1568 | |||
1569 | /* figure out if we have a complementary field pair */ | ||
1570 |
2/4✓ Branch 0 taken 3362 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3362 times.
|
3362 | if (!FIELD_PICTURE(h) || h->picture_structure == last_pic_structure) { |
1571 | /* Previous field is unmatched. Don't display it, but let it | ||
1572 | * remain for reference if marked as such. */ | ||
1573 | ✗ | h->missing_fields ++; | |
1574 | ✗ | h->cur_pic_ptr = NULL; | |
1575 | ✗ | h->first_field = FIELD_PICTURE(h); | |
1576 | } else { | ||
1577 | 3362 | h->missing_fields = 0; | |
1578 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3362 times.
|
3362 | if (h->cur_pic_ptr->frame_num != h->poc.frame_num) { |
1579 | ✗ | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, | |
1580 | ✗ | h->picture_structure==PICT_BOTTOM_FIELD); | |
1581 | /* This and the previous field had different frame_nums. | ||
1582 | * Consider this field first in pair. Throw away previous | ||
1583 | * one except for reference purposes. */ | ||
1584 | ✗ | h->first_field = 1; | |
1585 | ✗ | h->cur_pic_ptr = NULL; | |
1586 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3362 times.
|
3362 | } else if (h->cur_pic_ptr->reference & DELAYED_PIC_REF) { |
1587 | /* This frame was already output, we cannot draw into it | ||
1588 | * anymore. | ||
1589 | */ | ||
1590 | ✗ | h->first_field = 1; | |
1591 | ✗ | h->cur_pic_ptr = NULL; | |
1592 | } else { | ||
1593 | /* Second field in complementary pair */ | ||
1594 | 3362 | h->first_field = 0; | |
1595 | } | ||
1596 | } | ||
1597 | } else { | ||
1598 | /* Frame or first field in a potentially complementary pair */ | ||
1599 | 24928 | h->first_field = FIELD_PICTURE(h); | |
1600 | } | ||
1601 | |||
1602 |
4/4✓ Branch 0 taken 6729 times.
✓ Branch 1 taken 21561 times.
✓ Branch 2 taken 3367 times.
✓ Branch 3 taken 3362 times.
|
28290 | if (!FIELD_PICTURE(h) || h->first_field) { |
1603 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 24928 times.
|
24928 | if (h264_frame_start(h) < 0) { |
1604 | ✗ | h->first_field = 0; | |
1605 | ✗ | return AVERROR_INVALIDDATA; | |
1606 | } | ||
1607 | } else { | ||
1608 | 3362 | int field = h->picture_structure == PICT_BOTTOM_FIELD; | |
1609 | 3362 | release_unused_pictures(h, 0); | |
1610 | 3362 | h->cur_pic_ptr->tf.owner[field] = h->avctx; | |
1611 | } | ||
1612 | /* Some macroblocks can be accessed before they're available in case | ||
1613 | * of lost slices, MBAFF or threading. */ | ||
1614 |
2/2✓ Branch 0 taken 6729 times.
✓ Branch 1 taken 21561 times.
|
28290 | if (FIELD_PICTURE(h)) { |
1615 |
2/2✓ Branch 0 taken 168342 times.
✓ Branch 1 taken 6729 times.
|
175071 | for(i = (h->picture_structure == PICT_BOTTOM_FIELD); i<h->mb_height; i++) |
1616 | 168342 | memset(h->slice_table + i*h->mb_stride, -1, (h->mb_stride - (i+1==h->mb_height)) * sizeof(*h->slice_table)); | |
1617 | } else { | ||
1618 | 21561 | memset(h->slice_table, -1, | |
1619 | 21561 | (h->mb_height * h->mb_stride - 1) * sizeof(*h->slice_table)); | |
1620 | } | ||
1621 | |||
1622 | 28290 | ret = ff_h264_init_poc(h->cur_pic_ptr->field_poc, &h->cur_pic_ptr->poc, | |
1623 | 28290 | h->ps.sps, &h->poc, h->picture_structure, nal->ref_idc); | |
1624 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28290 times.
|
28290 | if (ret < 0) |
1625 | ✗ | return ret; | |
1626 | |||
1627 | 28290 | memcpy(h->mmco, sl->mmco, sl->nb_mmco * sizeof(*h->mmco)); | |
1628 | 28290 | h->nb_mmco = sl->nb_mmco; | |
1629 | 28290 | h->explicit_ref_marking = sl->explicit_ref_marking; | |
1630 | |||
1631 | 28290 | h->picture_idr = nal->type == H264_NAL_IDR_SLICE; | |
1632 | |||
1633 |
2/2✓ Branch 0 taken 90 times.
✓ Branch 1 taken 28200 times.
|
28290 | if (h->sei.recovery_point.recovery_frame_cnt >= 0) { |
1634 | 90 | const int sei_recovery_frame_cnt = h->sei.recovery_point.recovery_frame_cnt; | |
1635 | |||
1636 |
4/4✓ Branch 0 taken 25 times.
✓ Branch 1 taken 65 times.
✓ Branch 2 taken 11 times.
✓ Branch 3 taken 14 times.
|
90 | if (h->poc.frame_num != sei_recovery_frame_cnt || sl->slice_type_nos != AV_PICTURE_TYPE_I) |
1637 | 76 | h->valid_recovery_point = 1; | |
1638 | |||
1639 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 86 times.
|
90 | if ( h->recovery_frame < 0 |
1640 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | || av_zero_extend(h->recovery_frame - h->poc.frame_num, h->ps.sps->log2_max_frame_num) > sei_recovery_frame_cnt) { |
1641 | 86 | h->recovery_frame = av_zero_extend(h->poc.frame_num + sei_recovery_frame_cnt, h->ps.sps->log2_max_frame_num); | |
1642 | |||
1643 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 80 times.
|
86 | if (!h->valid_recovery_point) |
1644 | 6 | h->recovery_frame = h->poc.frame_num; | |
1645 | } | ||
1646 | } | ||
1647 | |||
1648 |
2/2✓ Branch 0 taken 1077 times.
✓ Branch 1 taken 27213 times.
|
28290 | h->cur_pic_ptr->f->flags |= AV_FRAME_FLAG_KEY * !!(nal->type == H264_NAL_IDR_SLICE); |
1649 | |||
1650 |
2/2✓ Branch 0 taken 1077 times.
✓ Branch 1 taken 27213 times.
|
28290 | if (nal->type == H264_NAL_IDR_SLICE) { |
1651 | 1077 | h->cur_pic_ptr->recovered |= FRAME_RECOVERED_IDR; | |
1652 | // If we have an IDR, all frames after it in decoded order are | ||
1653 | // "recovered". | ||
1654 | 1077 | h->frame_recovered |= FRAME_RECOVERED_IDR; | |
1655 | } | ||
1656 | |||
1657 |
4/4✓ Branch 0 taken 99 times.
✓ Branch 1 taken 28191 times.
✓ Branch 2 taken 85 times.
✓ Branch 3 taken 14 times.
|
28290 | if (h->recovery_frame == h->poc.frame_num && nal->ref_idc) { |
1658 | 85 | h->recovery_frame = -1; | |
1659 | 85 | h->cur_pic_ptr->recovered |= FRAME_RECOVERED_SEI; | |
1660 | } | ||
1661 | |||
1662 | #if 1 | ||
1663 | 28290 | h->cur_pic_ptr->recovered |= h->frame_recovered; | |
1664 | #else | ||
1665 | h->cur_pic_ptr->recovered |= !!(h->frame_recovered & FRAME_RECOVERED_IDR); | ||
1666 | #endif | ||
1667 | |||
1668 | /* Set the frame properties/side data. Only done for the second field in | ||
1669 | * field coded frames, since some SEI information is present for each field | ||
1670 | * and is merged by the SEI parsing code. */ | ||
1671 |
5/6✓ Branch 0 taken 6729 times.
✓ Branch 1 taken 21561 times.
✓ Branch 2 taken 3367 times.
✓ Branch 3 taken 3362 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3367 times.
|
28290 | if (!FIELD_PICTURE(h) || !h->first_field || h->missing_fields > 1) { |
1672 | 24923 | ret = h264_export_frame_props(h); | |
1673 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24923 times.
|
24923 | if (ret < 0) |
1674 | ✗ | return ret; | |
1675 | |||
1676 | 24923 | ret = h264_select_output_frame(h); | |
1677 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24923 times.
|
24923 | if (ret < 0) |
1678 | ✗ | return ret; | |
1679 | } | ||
1680 | |||
1681 | 28290 | return 0; | |
1682 | } | ||
1683 | |||
1684 | 37610 | static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl, | |
1685 | const H2645NAL *nal) | ||
1686 | { | ||
1687 | const SPS *sps; | ||
1688 | const PPS *pps; | ||
1689 | int ret; | ||
1690 | unsigned int slice_type, tmp, i; | ||
1691 | int field_pic_flag, bottom_field_flag; | ||
1692 |
4/4✓ Branch 0 taken 37160 times.
✓ Branch 1 taken 450 times.
✓ Branch 2 taken 28339 times.
✓ Branch 3 taken 8821 times.
|
37610 | int first_slice = sl == h->slice_ctx && !h->current_slice; |
1693 | int picture_structure; | ||
1694 | |||
1695 |
2/2✓ Branch 0 taken 28339 times.
✓ Branch 1 taken 9271 times.
|
37610 | if (first_slice) |
1696 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28339 times.
|
28339 | av_assert0(!h->setup_finished); |
1697 | |||
1698 | 37610 | sl->first_mb_addr = get_ue_golomb_long(&sl->gb); | |
1699 | |||
1700 | 37610 | slice_type = get_ue_golomb_31(&sl->gb); | |
1701 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37610 times.
|
37610 | if (slice_type > 9) { |
1702 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
1703 | "slice type %d too large at %d\n", | ||
1704 | slice_type, sl->first_mb_addr); | ||
1705 | ✗ | return AVERROR_INVALIDDATA; | |
1706 | } | ||
1707 |
2/2✓ Branch 0 taken 23886 times.
✓ Branch 1 taken 13724 times.
|
37610 | if (slice_type > 4) { |
1708 | 23886 | slice_type -= 5; | |
1709 | 23886 | sl->slice_type_fixed = 1; | |
1710 | } else | ||
1711 | 13724 | sl->slice_type_fixed = 0; | |
1712 | |||
1713 | 37610 | slice_type = ff_h264_golomb_to_pict_type[slice_type]; | |
1714 | 37610 | sl->slice_type = slice_type; | |
1715 | 37610 | sl->slice_type_nos = slice_type & 3; | |
1716 | |||
1717 |
2/2✓ Branch 0 taken 2263 times.
✓ Branch 1 taken 35347 times.
|
37610 | if (nal->type == H264_NAL_IDR_SLICE && |
1718 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2263 times.
|
2263 | sl->slice_type_nos != AV_PICTURE_TYPE_I) { |
1719 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "A non-intra slice in an IDR NAL unit.\n"); | |
1720 | ✗ | return AVERROR_INVALIDDATA; | |
1721 | } | ||
1722 | |||
1723 | 37610 | sl->pps_id = get_ue_golomb(&sl->gb); | |
1724 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37610 times.
|
37610 | if (sl->pps_id >= MAX_PPS_COUNT) { |
1725 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "pps_id %u out of range\n", sl->pps_id); | |
1726 | ✗ | return AVERROR_INVALIDDATA; | |
1727 | } | ||
1728 |
2/2✓ Branch 0 taken 167 times.
✓ Branch 1 taken 37443 times.
|
37610 | if (!h->ps.pps_list[sl->pps_id]) { |
1729 | 167 | av_log(h->avctx, AV_LOG_ERROR, | |
1730 | "non-existing PPS %u referenced\n", | ||
1731 | sl->pps_id); | ||
1732 | 167 | return AVERROR_INVALIDDATA; | |
1733 | } | ||
1734 | 37443 | pps = h->ps.pps_list[sl->pps_id]; | |
1735 | 37443 | sps = pps->sps; | |
1736 | |||
1737 | 37443 | sl->frame_num = get_bits(&sl->gb, sps->log2_max_frame_num); | |
1738 |
2/2✓ Branch 0 taken 9267 times.
✓ Branch 1 taken 28176 times.
|
37443 | if (!first_slice) { |
1739 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9267 times.
|
9267 | if (h->poc.frame_num != sl->frame_num) { |
1740 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Frame num change from %d to %d\n", | |
1741 | ✗ | h->poc.frame_num, sl->frame_num); | |
1742 | ✗ | return AVERROR_INVALIDDATA; | |
1743 | } | ||
1744 | } | ||
1745 | |||
1746 | 37443 | sl->mb_mbaff = 0; | |
1747 | |||
1748 |
2/2✓ Branch 0 taken 22948 times.
✓ Branch 1 taken 14495 times.
|
37443 | if (sps->frame_mbs_only_flag) { |
1749 | 22948 | picture_structure = PICT_FRAME; | |
1750 | } else { | ||
1751 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 14495 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
14495 | if (!sps->direct_8x8_inference_flag && slice_type == AV_PICTURE_TYPE_B) { |
1752 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\n"); | |
1753 | ✗ | return -1; | |
1754 | } | ||
1755 | 14495 | field_pic_flag = get_bits1(&sl->gb); | |
1756 |
2/2✓ Branch 0 taken 9026 times.
✓ Branch 1 taken 5469 times.
|
14495 | if (field_pic_flag) { |
1757 | 9026 | bottom_field_flag = get_bits1(&sl->gb); | |
1758 | 9026 | picture_structure = PICT_TOP_FIELD + bottom_field_flag; | |
1759 | } else { | ||
1760 | 5469 | picture_structure = PICT_FRAME; | |
1761 | } | ||
1762 | } | ||
1763 | 37443 | sl->picture_structure = picture_structure; | |
1764 | 37443 | sl->mb_field_decoding_flag = picture_structure != PICT_FRAME; | |
1765 | |||
1766 |
2/2✓ Branch 0 taken 28417 times.
✓ Branch 1 taken 9026 times.
|
37443 | if (picture_structure == PICT_FRAME) { |
1767 | 28417 | sl->curr_pic_num = sl->frame_num; | |
1768 | 28417 | sl->max_pic_num = 1 << sps->log2_max_frame_num; | |
1769 | } else { | ||
1770 | 9026 | sl->curr_pic_num = 2 * sl->frame_num + 1; | |
1771 | 9026 | sl->max_pic_num = 1 << (sps->log2_max_frame_num + 1); | |
1772 | } | ||
1773 | |||
1774 |
2/2✓ Branch 0 taken 2258 times.
✓ Branch 1 taken 35185 times.
|
37443 | if (nal->type == H264_NAL_IDR_SLICE) { |
1775 | 2258 | unsigned idr_pic_id = get_ue_golomb_long(&sl->gb); | |
1776 |
1/2✓ Branch 0 taken 2258 times.
✗ Branch 1 not taken.
|
2258 | if (idr_pic_id < 65536) { |
1777 | 2258 | sl->idr_pic_id = idr_pic_id; | |
1778 | } else | ||
1779 | ✗ | av_log(h->avctx, AV_LOG_WARNING, "idr_pic_id is invalid\n"); | |
1780 | } | ||
1781 | |||
1782 | 37443 | sl->poc_lsb = 0; | |
1783 | 37443 | sl->delta_poc_bottom = 0; | |
1784 |
2/2✓ Branch 0 taken 29663 times.
✓ Branch 1 taken 7780 times.
|
37443 | if (sps->poc_type == 0) { |
1785 | 29663 | sl->poc_lsb = get_bits(&sl->gb, sps->log2_max_poc_lsb); | |
1786 | |||
1787 |
4/4✓ Branch 0 taken 8524 times.
✓ Branch 1 taken 21139 times.
✓ Branch 2 taken 6632 times.
✓ Branch 3 taken 1892 times.
|
29663 | if (pps->pic_order_present == 1 && picture_structure == PICT_FRAME) |
1788 | 6632 | sl->delta_poc_bottom = get_se_golomb(&sl->gb); | |
1789 | } | ||
1790 | |||
1791 | 37443 | sl->delta_poc[0] = sl->delta_poc[1] = 0; | |
1792 |
4/4✓ Branch 0 taken 3055 times.
✓ Branch 1 taken 34388 times.
✓ Branch 2 taken 2848 times.
✓ Branch 3 taken 207 times.
|
37443 | if (sps->poc_type == 1 && !sps->delta_pic_order_always_zero_flag) { |
1793 | 2848 | sl->delta_poc[0] = get_se_golomb(&sl->gb); | |
1794 | |||
1795 |
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) |
1796 | 453 | sl->delta_poc[1] = get_se_golomb(&sl->gb); | |
1797 | } | ||
1798 | |||
1799 | 37443 | sl->redundant_pic_count = 0; | |
1800 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37443 times.
|
37443 | if (pps->redundant_pic_cnt_present) |
1801 | ✗ | sl->redundant_pic_count = get_ue_golomb(&sl->gb); | |
1802 | |||
1803 |
2/2✓ Branch 0 taken 13150 times.
✓ Branch 1 taken 24293 times.
|
37443 | if (sl->slice_type_nos == AV_PICTURE_TYPE_B) |
1804 | 13150 | sl->direct_spatial_mv_pred = get_bits1(&sl->gb); | |
1805 | |||
1806 | 37443 | ret = ff_h264_parse_ref_count(&sl->list_count, sl->ref_count, | |
1807 | &sl->gb, pps, sl->slice_type_nos, | ||
1808 | 37443 | picture_structure, h->avctx); | |
1809 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37443 times.
|
37443 | if (ret < 0) |
1810 | ✗ | return ret; | |
1811 | |||
1812 |
2/2✓ Branch 0 taken 32977 times.
✓ Branch 1 taken 4466 times.
|
37443 | if (sl->slice_type_nos != AV_PICTURE_TYPE_I) { |
1813 | 32977 | ret = ff_h264_decode_ref_pic_list_reordering(sl, h->avctx); | |
1814 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32977 times.
|
32977 | if (ret < 0) { |
1815 | ✗ | sl->ref_count[1] = sl->ref_count[0] = 0; | |
1816 | ✗ | return ret; | |
1817 | } | ||
1818 | } | ||
1819 | |||
1820 | 37443 | sl->pwt.use_weight = 0; | |
1821 |
2/2✓ Branch 0 taken 74886 times.
✓ Branch 1 taken 37443 times.
|
112329 | for (i = 0; i < 2; i++) { |
1822 | 74886 | sl->pwt.luma_weight_flag[i] = 0; | |
1823 | 74886 | sl->pwt.chroma_weight_flag[i] = 0; | |
1824 | } | ||
1825 |
4/4✓ Branch 0 taken 4311 times.
✓ Branch 1 taken 33132 times.
✓ Branch 2 taken 1631 times.
✓ Branch 3 taken 2680 times.
|
37443 | if ((pps->weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) || |
1826 |
2/2✓ Branch 0 taken 386 times.
✓ Branch 1 taken 34377 times.
|
34763 | (pps->weighted_bipred_idc == 1 && |
1827 |
1/2✓ Branch 0 taken 386 times.
✗ Branch 1 not taken.
|
386 | sl->slice_type_nos == AV_PICTURE_TYPE_B)) { |
1828 | 3066 | ret = ff_h264_pred_weight_table(&sl->gb, sps, sl->ref_count, | |
1829 | sl->slice_type_nos, &sl->pwt, | ||
1830 | 3066 | picture_structure, h->avctx); | |
1831 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3066 times.
|
3066 | if (ret < 0) |
1832 | ✗ | return ret; | |
1833 | } | ||
1834 | |||
1835 | 37443 | sl->explicit_ref_marking = 0; | |
1836 |
2/2✓ Branch 0 taken 24954 times.
✓ Branch 1 taken 12489 times.
|
37443 | if (nal->ref_idc) { |
1837 | 24954 | ret = ff_h264_decode_ref_pic_marking(sl, &sl->gb, nal, h->avctx); | |
1838 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 24954 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
24954 | if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) |
1839 | ✗ | return AVERROR_INVALIDDATA; | |
1840 | } | ||
1841 | |||
1842 |
4/4✓ Branch 0 taken 32977 times.
✓ Branch 1 taken 4466 times.
✓ Branch 2 taken 18165 times.
✓ Branch 3 taken 14812 times.
|
37443 | if (sl->slice_type_nos != AV_PICTURE_TYPE_I && pps->cabac) { |
1843 | 18165 | tmp = get_ue_golomb_31(&sl->gb); | |
1844 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18165 times.
|
18165 | if (tmp > 2) { |
1845 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", tmp); | |
1846 | ✗ | return AVERROR_INVALIDDATA; | |
1847 | } | ||
1848 | 18165 | sl->cabac_init_idc = tmp; | |
1849 | } | ||
1850 | |||
1851 | 37443 | sl->last_qscale_diff = 0; | |
1852 | 37443 | tmp = pps->init_qp + (unsigned)get_se_golomb(&sl->gb); | |
1853 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37443 times.
|
37443 | if (tmp > 51 + 6 * (sps->bit_depth_luma - 8)) { |
1854 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp); | |
1855 | ✗ | return AVERROR_INVALIDDATA; | |
1856 | } | ||
1857 | 37443 | sl->qscale = tmp; | |
1858 | 37443 | sl->chroma_qp[0] = get_chroma_qp(pps, 0, sl->qscale); | |
1859 | 37443 | sl->chroma_qp[1] = get_chroma_qp(pps, 1, sl->qscale); | |
1860 | // FIXME qscale / qp ... stuff | ||
1861 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37443 times.
|
37443 | if (sl->slice_type == AV_PICTURE_TYPE_SP) |
1862 | ✗ | get_bits1(&sl->gb); /* sp_for_switch_flag */ | |
1863 |
1/2✓ Branch 0 taken 37443 times.
✗ Branch 1 not taken.
|
37443 | if (sl->slice_type == AV_PICTURE_TYPE_SP || |
1864 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37443 times.
|
37443 | sl->slice_type == AV_PICTURE_TYPE_SI) |
1865 | ✗ | get_se_golomb(&sl->gb); /* slice_qs_delta */ | |
1866 | |||
1867 | 37443 | sl->deblocking_filter = 1; | |
1868 | 37443 | sl->slice_alpha_c0_offset = 0; | |
1869 | 37443 | sl->slice_beta_offset = 0; | |
1870 |
2/2✓ Branch 0 taken 22660 times.
✓ Branch 1 taken 14783 times.
|
37443 | if (pps->deblocking_filter_parameters_present) { |
1871 | 22660 | tmp = get_ue_golomb_31(&sl->gb); | |
1872 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 22660 times.
|
22660 | if (tmp > 2) { |
1873 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
1874 | "deblocking_filter_idc %u out of range\n", tmp); | ||
1875 | ✗ | return AVERROR_INVALIDDATA; | |
1876 | } | ||
1877 | 22660 | sl->deblocking_filter = tmp; | |
1878 |
2/2✓ Branch 0 taken 20159 times.
✓ Branch 1 taken 2501 times.
|
22660 | if (sl->deblocking_filter < 2) |
1879 | 20159 | sl->deblocking_filter ^= 1; // 1<->0 | |
1880 | |||
1881 |
2/2✓ Branch 0 taken 14949 times.
✓ Branch 1 taken 7711 times.
|
22660 | if (sl->deblocking_filter) { |
1882 | 14949 | int slice_alpha_c0_offset_div2 = get_se_golomb(&sl->gb); | |
1883 | 14949 | int slice_beta_offset_div2 = get_se_golomb(&sl->gb); | |
1884 |
2/4✓ Branch 0 taken 14949 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 14949 times.
✗ Branch 3 not taken.
|
14949 | if (slice_alpha_c0_offset_div2 > 6 || |
1885 |
1/2✓ Branch 0 taken 14949 times.
✗ Branch 1 not taken.
|
14949 | slice_alpha_c0_offset_div2 < -6 || |
1886 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14949 times.
|
14949 | slice_beta_offset_div2 > 6 || |
1887 | slice_beta_offset_div2 < -6) { | ||
1888 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
1889 | "deblocking filter parameters %d %d out of range\n", | ||
1890 | slice_alpha_c0_offset_div2, slice_beta_offset_div2); | ||
1891 | ✗ | return AVERROR_INVALIDDATA; | |
1892 | } | ||
1893 | 14949 | sl->slice_alpha_c0_offset = slice_alpha_c0_offset_div2 * 2; | |
1894 | 14949 | sl->slice_beta_offset = slice_beta_offset_div2 * 2; | |
1895 | } | ||
1896 | } | ||
1897 | |||
1898 | 37443 | return 0; | |
1899 | } | ||
1900 | |||
1901 | /* do all the per-slice initialization needed before we can start decoding the | ||
1902 | * actual MBs */ | ||
1903 | 37363 | static int h264_slice_init(H264Context *h, H264SliceContext *sl, | |
1904 | const H2645NAL *nal) | ||
1905 | { | ||
1906 | 37363 | int i, j, ret = 0; | |
1907 | |||
1908 |
3/4✓ Branch 0 taken 2258 times.
✓ Branch 1 taken 35105 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2258 times.
|
37363 | if (h->picture_idr && nal->type != H264_NAL_IDR_SLICE) { |
1909 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Invalid mix of IDR and non-IDR slices\n"); | |
1910 | ✗ | return AVERROR_INVALIDDATA; | |
1911 | } | ||
1912 | |||
1913 | av_assert1(h->mb_num == h->mb_width * h->mb_height); | ||
1914 |
5/6✓ Branch 0 taken 32391 times.
✓ Branch 1 taken 4972 times.
✓ Branch 2 taken 8946 times.
✓ Branch 3 taken 23445 times.
✓ Branch 4 taken 37363 times.
✗ Branch 5 not taken.
|
37363 | if (sl->first_mb_addr << FIELD_OR_MBAFF_PICTURE(h) >= h->mb_num || |
1915 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37363 times.
|
37363 | sl->first_mb_addr >= h->mb_num) { |
1916 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "first_mb_in_slice overflow\n"); | |
1917 | ✗ | return AVERROR_INVALIDDATA; | |
1918 | } | ||
1919 | 37363 | sl->resync_mb_x = sl->mb_x = sl->first_mb_addr % h->mb_width; | |
1920 | 74726 | sl->resync_mb_y = sl->mb_y = (sl->first_mb_addr / h->mb_width) << | |
1921 |
4/4✓ Branch 0 taken 32391 times.
✓ Branch 1 taken 4972 times.
✓ Branch 2 taken 8946 times.
✓ Branch 3 taken 23445 times.
|
37363 | FIELD_OR_MBAFF_PICTURE(h); |
1922 |
2/2✓ Branch 0 taken 4470 times.
✓ Branch 1 taken 32893 times.
|
37363 | if (h->picture_structure == PICT_BOTTOM_FIELD) |
1923 | 4470 | sl->resync_mb_y = sl->mb_y = sl->mb_y + 1; | |
1924 | av_assert1(sl->mb_y < h->mb_height); | ||
1925 | |||
1926 | 37363 | ret = ff_h264_build_ref_list(h, sl); | |
1927 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37363 times.
|
37363 | if (ret < 0) |
1928 | ✗ | return ret; | |
1929 | |||
1930 |
2/2✓ Branch 0 taken 3814 times.
✓ Branch 1 taken 33549 times.
|
37363 | if (h->ps.pps->weighted_bipred_idc == 2 && |
1931 |
2/2✓ Branch 0 taken 2129 times.
✓ Branch 1 taken 1685 times.
|
3814 | sl->slice_type_nos == AV_PICTURE_TYPE_B) { |
1932 | 2129 | implicit_weight_table(h, sl, -1); | |
1933 |
2/2✓ Branch 0 taken 856 times.
✓ Branch 1 taken 1273 times.
|
2129 | if (FRAME_MBAFF(h)) { |
1934 | 856 | implicit_weight_table(h, sl, 0); | |
1935 | 856 | implicit_weight_table(h, sl, 1); | |
1936 | } | ||
1937 | } | ||
1938 | |||
1939 |
4/4✓ Branch 0 taken 13106 times.
✓ Branch 1 taken 24257 times.
✓ Branch 2 taken 7704 times.
✓ Branch 3 taken 5402 times.
|
37363 | if (sl->slice_type_nos == AV_PICTURE_TYPE_B && !sl->direct_spatial_mv_pred) |
1940 | 7704 | ff_h264_direct_dist_scale_factor(h, sl); | |
1941 |
1/2✓ Branch 0 taken 37363 times.
✗ Branch 1 not taken.
|
37363 | if (!h->setup_finished) |
1942 | 37363 | ff_h264_direct_ref_list_init(h, sl); | |
1943 | |||
1944 |
1/2✓ Branch 0 taken 37363 times.
✗ Branch 1 not taken.
|
37363 | if (h->avctx->skip_loop_filter >= AVDISCARD_ALL || |
1945 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37363 times.
|
37363 | (h->avctx->skip_loop_filter >= AVDISCARD_NONKEY && |
1946 | ✗ | h->nal_unit_type != H264_NAL_IDR_SLICE) || | |
1947 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37363 times.
|
37363 | (h->avctx->skip_loop_filter >= AVDISCARD_NONINTRA && |
1948 | ✗ | sl->slice_type_nos != AV_PICTURE_TYPE_I) || | |
1949 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37363 times.
|
37363 | (h->avctx->skip_loop_filter >= AVDISCARD_BIDIR && |
1950 | ✗ | sl->slice_type_nos == AV_PICTURE_TYPE_B) || | |
1951 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37363 times.
|
37363 | (h->avctx->skip_loop_filter >= AVDISCARD_NONREF && |
1952 | ✗ | nal->ref_idc == 0)) | |
1953 | ✗ | sl->deblocking_filter = 0; | |
1954 | |||
1955 |
3/4✓ Branch 0 taken 27151 times.
✓ Branch 1 taken 10212 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 27151 times.
|
37363 | if (sl->deblocking_filter == 1 && h->nb_slice_ctx > 1) { |
1956 | ✗ | if (h->avctx->flags2 & AV_CODEC_FLAG2_FAST) { | |
1957 | /* Cheat slightly for speed: | ||
1958 | * Do not bother to deblock across slices. */ | ||
1959 | ✗ | sl->deblocking_filter = 2; | |
1960 | } else { | ||
1961 | ✗ | h->postpone_filter = 1; | |
1962 | } | ||
1963 | } | ||
1964 | 37363 | sl->qp_thresh = 15 - | |
1965 | 37363 | FFMIN(sl->slice_alpha_c0_offset, sl->slice_beta_offset) - | |
1966 | 37363 | FFMAX3(0, | |
1967 | h->ps.pps->chroma_qp_index_offset[0], | ||
1968 | 37363 | h->ps.pps->chroma_qp_index_offset[1]) + | |
1969 | 37363 | 6 * (h->ps.sps->bit_depth_luma - 8); | |
1970 | |||
1971 | 37363 | sl->slice_num = ++h->current_slice; | |
1972 | |||
1973 |
1/2✓ Branch 0 taken 37363 times.
✗ Branch 1 not taken.
|
37363 | if (sl->slice_num) |
1974 | 37363 | h->slice_row[(sl->slice_num-1)&(MAX_SLICES-1)]= sl->resync_mb_y; | |
1975 |
2/2✓ Branch 0 taken 34491 times.
✓ Branch 1 taken 2872 times.
|
37363 | if ( h->slice_row[sl->slice_num&(MAX_SLICES-1)] + 3 >= sl->resync_mb_y |
1976 |
2/2✓ Branch 0 taken 25752 times.
✓ Branch 1 taken 8739 times.
|
34491 | && h->slice_row[sl->slice_num&(MAX_SLICES-1)] <= sl->resync_mb_y |
1977 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25752 times.
|
25752 | && sl->slice_num >= MAX_SLICES) { |
1978 | //in case of ASO this check needs to be updated depending on how we decide to assign slice numbers in this case | ||
1979 | ✗ | av_log(h->avctx, AV_LOG_WARNING, "Possibly too many slices (%d >= %d), increase MAX_SLICES and recompile if there are artifacts\n", sl->slice_num, MAX_SLICES); | |
1980 | } | ||
1981 | |||
1982 |
2/2✓ Branch 0 taken 74726 times.
✓ Branch 1 taken 37363 times.
|
112089 | for (j = 0; j < 2; j++) { |
1983 | int id_list[16]; | ||
1984 | 74726 | int *ref2frm = h->ref2frm[sl->slice_num & (MAX_SLICES - 1)][j]; | |
1985 |
2/2✓ Branch 0 taken 1195616 times.
✓ Branch 1 taken 74726 times.
|
1270342 | for (i = 0; i < 16; i++) { |
1986 | 1195616 | id_list[i] = 60; | |
1987 |
4/4✓ Branch 0 taken 736048 times.
✓ Branch 1 taken 459568 times.
✓ Branch 2 taken 140488 times.
✓ Branch 3 taken 595560 times.
|
1195616 | if (j < sl->list_count && i < sl->ref_count[j] && |
1988 |
1/2✓ Branch 0 taken 140488 times.
✗ Branch 1 not taken.
|
140488 | sl->ref_list[j][i].parent->f->buf[0]) { |
1989 | int k; | ||
1990 | 140488 | const AVBuffer *buf = sl->ref_list[j][i].parent->f->buf[0]->buffer; | |
1991 |
2/2✓ Branch 0 taken 469023 times.
✓ Branch 1 taken 1933 times.
|
470956 | for (k = 0; k < h->short_ref_count; k++) |
1992 |
2/2✓ Branch 0 taken 138555 times.
✓ Branch 1 taken 330468 times.
|
469023 | if (h->short_ref[k]->f->buf[0]->buffer == buf) { |
1993 | 138555 | id_list[i] = k; | |
1994 | 138555 | break; | |
1995 | } | ||
1996 |
2/2✓ Branch 0 taken 11870 times.
✓ Branch 1 taken 138696 times.
|
150566 | for (k = 0; k < h->long_ref_count; k++) |
1997 |
4/4✓ Branch 0 taken 11269 times.
✓ Branch 1 taken 601 times.
✓ Branch 2 taken 1792 times.
✓ Branch 3 taken 9477 times.
|
11870 | if (h->long_ref[k] && h->long_ref[k]->f->buf[0]->buffer == buf) { |
1998 | 1792 | id_list[i] = h->short_ref_count + k; | |
1999 | 1792 | break; | |
2000 | } | ||
2001 | } | ||
2002 | } | ||
2003 | |||
2004 | 74726 | ref2frm[0] = | |
2005 | 74726 | ref2frm[1] = -1; | |
2006 |
2/2✓ Branch 0 taken 1195616 times.
✓ Branch 1 taken 74726 times.
|
1270342 | for (i = 0; i < 16; i++) |
2007 | 1195616 | ref2frm[i + 2] = 4 * id_list[i] + (sl->ref_list[j][i].reference & 3); | |
2008 | 74726 | ref2frm[18 + 0] = | |
2009 | 74726 | ref2frm[18 + 1] = -1; | |
2010 |
2/2✓ Branch 0 taken 2391232 times.
✓ Branch 1 taken 74726 times.
|
2465958 | for (i = 16; i < 48; i++) |
2011 | 2391232 | ref2frm[i + 4] = 4 * id_list[(i - 16) >> 1] + | |
2012 | 2391232 | (sl->ref_list[j][i].reference & 3); | |
2013 | } | ||
2014 | |||
2015 |
2/2✓ Branch 0 taken 4466 times.
✓ Branch 1 taken 32897 times.
|
37363 | if (sl->slice_type_nos == AV_PICTURE_TYPE_I) { |
2016 | 4466 | h->cur_pic_ptr->gray = 0; | |
2017 | 4466 | h->non_gray = 1; | |
2018 | } else { | ||
2019 | 32897 | int gray = 0; | |
2020 |
2/2✓ Branch 0 taken 46003 times.
✓ Branch 1 taken 32897 times.
|
78900 | for (j = 0; j < sl->list_count; j++) { |
2021 |
2/2✓ Branch 0 taken 140488 times.
✓ Branch 1 taken 46003 times.
|
186491 | for (i = 0; i < sl->ref_count[j]; i++) { |
2022 | 140488 | gray |= sl->ref_list[j][i].parent->gray; | |
2023 | } | ||
2024 | } | ||
2025 | 32897 | h->cur_pic_ptr->gray = gray; | |
2026 | } | ||
2027 | |||
2028 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37363 times.
|
37363 | if (h->avctx->debug & FF_DEBUG_PICT_INFO) { |
2029 | ✗ | av_log(h->avctx, AV_LOG_DEBUG, | |
2030 | "slice:%d %c mb:%d %c%s%s frame:%d poc:%d/%d ref:%d/%d qp:%d loop:%d:%d:%d weight:%d%s %s\n", | ||
2031 | sl->slice_num, | ||
2032 | ✗ | (h->picture_structure == PICT_FRAME ? 'F' : h->picture_structure == PICT_TOP_FIELD ? 'T' : 'B'), | |
2033 | ✗ | sl->mb_y * h->mb_width + sl->mb_x, | |
2034 | ✗ | av_get_picture_type_char(sl->slice_type), | |
2035 | ✗ | sl->slice_type_fixed ? " fix" : "", | |
2036 | ✗ | nal->type == H264_NAL_IDR_SLICE ? " IDR" : "", | |
2037 | h->poc.frame_num, | ||
2038 | ✗ | h->cur_pic_ptr->field_poc[0], | |
2039 | ✗ | h->cur_pic_ptr->field_poc[1], | |
2040 | sl->ref_count[0], sl->ref_count[1], | ||
2041 | sl->qscale, | ||
2042 | sl->deblocking_filter, | ||
2043 | sl->slice_alpha_c0_offset, sl->slice_beta_offset, | ||
2044 | sl->pwt.use_weight, | ||
2045 | ✗ | sl->pwt.use_weight == 1 && sl->pwt.use_weight_chroma ? "c" : "", | |
2046 | ✗ | sl->slice_type == AV_PICTURE_TYPE_B ? (sl->direct_spatial_mv_pred ? "SPAT" : "TEMP") : ""); | |
2047 | } | ||
2048 | |||
2049 | 37363 | return 0; | |
2050 | } | ||
2051 | |||
2052 | 37610 | int ff_h264_queue_decode_slice(H264Context *h, const H2645NAL *nal) | |
2053 | { | ||
2054 | 37610 | H264SliceContext *sl = h->slice_ctx + h->nb_slice_ctx_queued; | |
2055 |
4/4✓ Branch 0 taken 37160 times.
✓ Branch 1 taken 450 times.
✓ Branch 2 taken 28339 times.
✓ Branch 3 taken 8821 times.
|
37610 | int first_slice = sl == h->slice_ctx && !h->current_slice; |
2056 | int ret; | ||
2057 | |||
2058 | 37610 | sl->gb = nal->gb; | |
2059 | |||
2060 | 37610 | ret = h264_slice_header_parse(h, sl, nal); | |
2061 |
2/2✓ Branch 0 taken 167 times.
✓ Branch 1 taken 37443 times.
|
37610 | if (ret < 0) |
2062 | 167 | return ret; | |
2063 | |||
2064 | // discard redundant pictures | ||
2065 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37443 times.
|
37443 | if (sl->redundant_pic_count > 0) { |
2066 | ✗ | sl->ref_count[0] = sl->ref_count[1] = 0; | |
2067 | ✗ | return 0; | |
2068 | } | ||
2069 | |||
2070 |
3/4✓ Branch 0 taken 9073 times.
✓ Branch 1 taken 28370 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9073 times.
|
37443 | if (sl->first_mb_addr == 0 || !h->current_slice) { |
2071 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28370 times.
|
28370 | if (h->setup_finished) { |
2072 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Too many fields\n"); | |
2073 | ✗ | return AVERROR_INVALIDDATA; | |
2074 | } | ||
2075 | } | ||
2076 | |||
2077 |
2/2✓ Branch 0 taken 28370 times.
✓ Branch 1 taken 9073 times.
|
37443 | if (sl->first_mb_addr == 0) { // FIXME better field boundary detection |
2078 |
2/2✓ Branch 0 taken 194 times.
✓ Branch 1 taken 28176 times.
|
28370 | if (h->current_slice) { |
2079 | // this slice starts a new field | ||
2080 | // first decode any pending queued slices | ||
2081 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 194 times.
|
194 | if (h->nb_slice_ctx_queued) { |
2082 | H264SliceContext tmp_ctx; | ||
2083 | |||
2084 | ✗ | ret = ff_h264_execute_decode_slices(h); | |
2085 | ✗ | if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) | |
2086 | ✗ | return ret; | |
2087 | |||
2088 | ✗ | memcpy(&tmp_ctx, h->slice_ctx, sizeof(tmp_ctx)); | |
2089 | ✗ | memcpy(h->slice_ctx, sl, sizeof(tmp_ctx)); | |
2090 | ✗ | memcpy(sl, &tmp_ctx, sizeof(tmp_ctx)); | |
2091 | ✗ | sl = h->slice_ctx; | |
2092 | } | ||
2093 | |||
2094 |
3/6✓ Branch 0 taken 194 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 194 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 194 times.
✗ Branch 5 not taken.
|
194 | if (h->cur_pic_ptr && FIELD_PICTURE(h) && h->first_field) { |
2095 | 194 | ret = ff_h264_field_end(h, h->slice_ctx, 1); | |
2096 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 194 times.
|
194 | if (ret < 0) |
2097 | ✗ | return ret; | |
2098 | ✗ | } else if (h->cur_pic_ptr && !FIELD_PICTURE(h) && !h->first_field && h->nal_unit_type == H264_NAL_IDR_SLICE) { | |
2099 | ✗ | av_log(h, AV_LOG_WARNING, "Broken frame packetizing\n"); | |
2100 | ✗ | ret = ff_h264_field_end(h, h->slice_ctx, 1); | |
2101 | ✗ | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 0); | |
2102 | ✗ | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, 1); | |
2103 | ✗ | h->cur_pic_ptr = NULL; | |
2104 | ✗ | if (ret < 0) | |
2105 | ✗ | return ret; | |
2106 | } else | ||
2107 | ✗ | return AVERROR_INVALIDDATA; | |
2108 | } | ||
2109 | |||
2110 |
2/2✓ Branch 0 taken 25008 times.
✓ Branch 1 taken 3362 times.
|
28370 | if (!h->first_field) { |
2111 |
3/4✓ Branch 0 taken 299 times.
✓ Branch 1 taken 24709 times.
✓ Branch 2 taken 299 times.
✗ Branch 3 not taken.
|
25008 | if (h->cur_pic_ptr && !h->droppable) { |
2112 | 299 | ff_thread_report_progress(&h->cur_pic_ptr->tf, INT_MAX, | |
2113 | 299 | h->picture_structure == PICT_BOTTOM_FIELD); | |
2114 | } | ||
2115 | 25008 | h->cur_pic_ptr = NULL; | |
2116 | } | ||
2117 | } | ||
2118 | |||
2119 |
2/2✓ Branch 0 taken 28370 times.
✓ Branch 1 taken 9073 times.
|
37443 | if (!h->current_slice) |
2120 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28370 times.
|
28370 | av_assert0(sl == h->slice_ctx); |
2121 | |||
2122 |
4/4✓ Branch 0 taken 28370 times.
✓ Branch 1 taken 9073 times.
✓ Branch 2 taken 25008 times.
✓ Branch 3 taken 3362 times.
|
37443 | if (h->current_slice == 0 && !h->first_field) { |
2123 | 25008 | if ( | |
2124 |
3/4✓ Branch 0 taken 84 times.
✓ Branch 1 taken 24924 times.
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
|
25008 | (h->avctx->skip_frame >= AVDISCARD_NONREF && !h->nal_ref_idc) || |
2125 |
4/4✓ Branch 0 taken 84 times.
✓ Branch 1 taken 24924 times.
✓ Branch 2 taken 40 times.
✓ Branch 3 taken 44 times.
|
25008 | (h->avctx->skip_frame >= AVDISCARD_BIDIR && sl->slice_type_nos == AV_PICTURE_TYPE_B) || |
2126 |
4/4✓ Branch 0 taken 40 times.
✓ Branch 1 taken 24924 times.
✓ Branch 2 taken 4 times.
✓ Branch 3 taken 36 times.
|
24964 | (h->avctx->skip_frame >= AVDISCARD_NONINTRA && sl->slice_type_nos != AV_PICTURE_TYPE_I) || |
2127 |
4/6✓ Branch 0 taken 2 times.
✓ Branch 1 taken 24926 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
24928 | (h->avctx->skip_frame >= AVDISCARD_NONKEY && h->nal_unit_type != H264_NAL_IDR_SLICE && h->sei.recovery_point.recovery_frame_cnt < 0) || |
2128 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24928 times.
|
24928 | h->avctx->skip_frame >= AVDISCARD_ALL) { |
2129 | 80 | return 0; | |
2130 | } | ||
2131 | } | ||
2132 | |||
2133 |
2/2✓ Branch 0 taken 9267 times.
✓ Branch 1 taken 28096 times.
|
37363 | if (!first_slice) { |
2134 | 9267 | const PPS *pps = h->ps.pps_list[sl->pps_id]; | |
2135 | |||
2136 |
1/2✓ Branch 0 taken 9267 times.
✗ Branch 1 not taken.
|
9267 | if (h->ps.pps->sps_id != pps->sps_id || |
2137 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9267 times.
|
9267 | h->ps.pps->transform_8x8_mode != pps->transform_8x8_mode /*|| |
2138 | (h->setup_finished && h->ps.pps != pps)*/) { | ||
2139 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "PPS changed between slices\n"); | |
2140 | ✗ | return AVERROR_INVALIDDATA; | |
2141 | } | ||
2142 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9267 times.
|
9267 | if (h->ps.sps != pps->sps) { |
2143 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
2144 | "SPS changed in the middle of the frame\n"); | ||
2145 | ✗ | return AVERROR_INVALIDDATA; | |
2146 | } | ||
2147 | } | ||
2148 | |||
2149 |
2/2✓ Branch 0 taken 28290 times.
✓ Branch 1 taken 9073 times.
|
37363 | if (h->current_slice == 0) { |
2150 | 28290 | ret = h264_field_start(h, sl, nal, first_slice); | |
2151 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28290 times.
|
28290 | if (ret < 0) |
2152 | ✗ | return ret; | |
2153 | } else { | ||
2154 |
1/2✓ Branch 0 taken 9073 times.
✗ Branch 1 not taken.
|
9073 | if (h->picture_structure != sl->picture_structure || |
2155 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9073 times.
|
9073 | h->droppable != (nal->ref_idc == 0)) { |
2156 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
2157 | "Changing field mode (%d -> %d) between slices is not allowed\n", | ||
2158 | h->picture_structure, sl->picture_structure); | ||
2159 | ✗ | return AVERROR_INVALIDDATA; | |
2160 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9073 times.
|
9073 | } else if (!h->cur_pic_ptr) { |
2161 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
2162 | "unset cur_pic_ptr on slice %d\n", | ||
2163 | ✗ | h->current_slice + 1); | |
2164 | ✗ | return AVERROR_INVALIDDATA; | |
2165 | } | ||
2166 | } | ||
2167 | |||
2168 | 37363 | ret = h264_slice_init(h, sl, nal); | |
2169 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37363 times.
|
37363 | if (ret < 0) |
2170 | ✗ | return ret; | |
2171 | |||
2172 | 37363 | h->nb_slice_ctx_queued++; | |
2173 | |||
2174 | 37363 | return 0; | |
2175 | } | ||
2176 | |||
2177 | ✗ | int ff_h264_get_slice_type(const H264SliceContext *sl) | |
2178 | { | ||
2179 | ✗ | switch (sl->slice_type) { | |
2180 | ✗ | case AV_PICTURE_TYPE_P: | |
2181 | ✗ | return 0; | |
2182 | ✗ | case AV_PICTURE_TYPE_B: | |
2183 | ✗ | return 1; | |
2184 | ✗ | case AV_PICTURE_TYPE_I: | |
2185 | ✗ | return 2; | |
2186 | ✗ | case AV_PICTURE_TYPE_SP: | |
2187 | ✗ | return 3; | |
2188 | ✗ | case AV_PICTURE_TYPE_SI: | |
2189 | ✗ | return 4; | |
2190 | ✗ | default: | |
2191 | ✗ | return AVERROR_INVALIDDATA; | |
2192 | } | ||
2193 | } | ||
2194 | |||
2195 | 12359450 | static av_always_inline void fill_filter_caches_inter(const H264Context *h, | |
2196 | H264SliceContext *sl, | ||
2197 | int mb_type, int top_xy, | ||
2198 | const int left_xy[LEFT_MBS], | ||
2199 | int top_type, | ||
2200 | const int left_type[LEFT_MBS], | ||
2201 | int mb_xy, int list) | ||
2202 | { | ||
2203 | 12359450 | int b_stride = h->b_stride; | |
2204 | 12359450 | int16_t(*mv_dst)[2] = &sl->mv_cache[list][scan8[0]]; | |
2205 | 12359450 | int8_t *ref_cache = &sl->ref_cache[list][scan8[0]]; | |
2206 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 12359450 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
12359450 | if (IS_INTER(mb_type) || IS_DIRECT(mb_type)) { |
2207 |
2/2✓ Branch 0 taken 9937984 times.
✓ Branch 1 taken 2421466 times.
|
12359450 | if (USES_LIST(top_type, list)) { |
2208 | 9937984 | const int b_xy = h->mb2b_xy[top_xy] + 3 * b_stride; | |
2209 | 9937984 | const int b8_xy = 4 * top_xy + 2; | |
2210 |
2/2✓ Branch 0 taken 343018 times.
✓ Branch 1 taken 9594966 times.
|
9937984 | const int *ref2frm = &h->ref2frm[h->slice_table[top_xy] & (MAX_SLICES - 1)][list][(MB_MBAFF(sl) ? 20 : 2)]; |
2211 | 9937984 | AV_COPY128(mv_dst - 1 * 8, h->cur_pic.motion_val[list][b_xy + 0]); | |
2212 | 9937984 | ref_cache[0 - 1 * 8] = | |
2213 | 9937984 | ref_cache[1 - 1 * 8] = ref2frm[h->cur_pic.ref_index[list][b8_xy + 0]]; | |
2214 | 9937984 | ref_cache[2 - 1 * 8] = | |
2215 | 9937984 | ref_cache[3 - 1 * 8] = ref2frm[h->cur_pic.ref_index[list][b8_xy + 1]]; | |
2216 | } else { | ||
2217 | 2421466 | AV_ZERO128(mv_dst - 1 * 8); | |
2218 | 2421466 | AV_WN32A(&ref_cache[0 - 1 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u); | |
2219 | } | ||
2220 | |||
2221 |
2/2✓ Branch 0 taken 11927265 times.
✓ Branch 1 taken 432185 times.
|
12359450 | if (!IS_INTERLACED(mb_type ^ left_type[LTOP])) { |
2222 |
2/2✓ Branch 0 taken 9963175 times.
✓ Branch 1 taken 1964090 times.
|
11927265 | if (USES_LIST(left_type[LTOP], list)) { |
2223 | 9963175 | const int b_xy = h->mb2b_xy[left_xy[LTOP]] + 3; | |
2224 | 9963175 | const int b8_xy = 4 * left_xy[LTOP] + 1; | |
2225 |
2/2✓ Branch 0 taken 240255 times.
✓ Branch 1 taken 9722920 times.
|
9963175 | const int *ref2frm = &h->ref2frm[h->slice_table[left_xy[LTOP]] & (MAX_SLICES - 1)][list][(MB_MBAFF(sl) ? 20 : 2)]; |
2226 | 9963175 | AV_COPY32(mv_dst - 1 + 0, h->cur_pic.motion_val[list][b_xy + b_stride * 0]); | |
2227 | 9963175 | AV_COPY32(mv_dst - 1 + 8, h->cur_pic.motion_val[list][b_xy + b_stride * 1]); | |
2228 | 9963175 | AV_COPY32(mv_dst - 1 + 16, h->cur_pic.motion_val[list][b_xy + b_stride * 2]); | |
2229 | 9963175 | AV_COPY32(mv_dst - 1 + 24, h->cur_pic.motion_val[list][b_xy + b_stride * 3]); | |
2230 | 9963175 | ref_cache[-1 + 0] = | |
2231 | 9963175 | ref_cache[-1 + 8] = ref2frm[h->cur_pic.ref_index[list][b8_xy + 2 * 0]]; | |
2232 | 9963175 | ref_cache[-1 + 16] = | |
2233 | 9963175 | ref_cache[-1 + 24] = ref2frm[h->cur_pic.ref_index[list][b8_xy + 2 * 1]]; | |
2234 | } else { | ||
2235 | 1964090 | AV_ZERO32(mv_dst - 1 + 0); | |
2236 | 1964090 | AV_ZERO32(mv_dst - 1 + 8); | |
2237 | 1964090 | AV_ZERO32(mv_dst - 1 + 16); | |
2238 | 1964090 | AV_ZERO32(mv_dst - 1 + 24); | |
2239 | 1964090 | ref_cache[-1 + 0] = | |
2240 | 1964090 | ref_cache[-1 + 8] = | |
2241 | 1964090 | ref_cache[-1 + 16] = | |
2242 | 1964090 | ref_cache[-1 + 24] = LIST_NOT_USED; | |
2243 | } | ||
2244 | } | ||
2245 | } | ||
2246 | |||
2247 |
2/2✓ Branch 0 taken 1379657 times.
✓ Branch 1 taken 10979793 times.
|
12359450 | if (!USES_LIST(mb_type, list)) { |
2248 | 1379657 | fill_rectangle(mv_dst, 4, 4, 8, pack16to32(0, 0), 4); | |
2249 | 1379657 | AV_WN32A(&ref_cache[0 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u); | |
2250 | 1379657 | AV_WN32A(&ref_cache[1 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u); | |
2251 | 1379657 | AV_WN32A(&ref_cache[2 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u); | |
2252 | 1379657 | AV_WN32A(&ref_cache[3 * 8], ((LIST_NOT_USED) & 0xFF) * 0x01010101u); | |
2253 | 1379657 | return; | |
2254 | } | ||
2255 | |||
2256 | { | ||
2257 | 10979793 | const int8_t *ref = &h->cur_pic.ref_index[list][4 * mb_xy]; | |
2258 |
2/2✓ Branch 0 taken 413842 times.
✓ Branch 1 taken 10565951 times.
|
10979793 | const int *ref2frm = &h->ref2frm[sl->slice_num & (MAX_SLICES - 1)][list][(MB_MBAFF(sl) ? 20 : 2)]; |
2259 | 10979793 | uint32_t ref01 = (pack16to32(ref2frm[ref[0]], ref2frm[ref[1]]) & 0x00FF00FF) * 0x0101; | |
2260 | 10979793 | uint32_t ref23 = (pack16to32(ref2frm[ref[2]], ref2frm[ref[3]]) & 0x00FF00FF) * 0x0101; | |
2261 | 10979793 | AV_WN32A(&ref_cache[0 * 8], ref01); | |
2262 | 10979793 | AV_WN32A(&ref_cache[1 * 8], ref01); | |
2263 | 10979793 | AV_WN32A(&ref_cache[2 * 8], ref23); | |
2264 | 10979793 | AV_WN32A(&ref_cache[3 * 8], ref23); | |
2265 | } | ||
2266 | |||
2267 | { | ||
2268 | 10979793 | int16_t(*mv_src)[2] = &h->cur_pic.motion_val[list][4 * sl->mb_x + 4 * sl->mb_y * b_stride]; | |
2269 | 10979793 | AV_COPY128(mv_dst + 8 * 0, mv_src + 0 * b_stride); | |
2270 | 10979793 | AV_COPY128(mv_dst + 8 * 1, mv_src + 1 * b_stride); | |
2271 | 10979793 | AV_COPY128(mv_dst + 8 * 2, mv_src + 2 * b_stride); | |
2272 | 10979793 | AV_COPY128(mv_dst + 8 * 3, mv_src + 3 * b_stride); | |
2273 | } | ||
2274 | } | ||
2275 | |||
2276 | /** | ||
2277 | * @return non zero if the loop filter can be skipped | ||
2278 | */ | ||
2279 | 12577876 | static int fill_filter_caches(const H264Context *h, H264SliceContext *sl, int mb_type) | |
2280 | { | ||
2281 | 12577876 | const int mb_xy = sl->mb_xy; | |
2282 | int top_xy, left_xy[LEFT_MBS]; | ||
2283 | int top_type, left_type[LEFT_MBS]; | ||
2284 | const uint8_t *nnz; | ||
2285 | uint8_t *nnz_cache; | ||
2286 | |||
2287 | 12577876 | top_xy = mb_xy - (h->mb_stride << MB_FIELD(sl)); | |
2288 | |||
2289 | 12577876 | left_xy[LBOT] = left_xy[LTOP] = mb_xy - 1; | |
2290 |
2/2✓ Branch 0 taken 2021856 times.
✓ Branch 1 taken 10556020 times.
|
12577876 | if (FRAME_MBAFF(h)) { |
2291 | 2021856 | const int left_mb_field_flag = IS_INTERLACED(h->cur_pic.mb_type[mb_xy - 1]); | |
2292 | 2021856 | const int curr_mb_field_flag = IS_INTERLACED(mb_type); | |
2293 |
2/2✓ Branch 0 taken 1010928 times.
✓ Branch 1 taken 1010928 times.
|
2021856 | if (sl->mb_y & 1) { |
2294 |
2/2✓ Branch 0 taken 204650 times.
✓ Branch 1 taken 806278 times.
|
1010928 | if (left_mb_field_flag != curr_mb_field_flag) |
2295 | 204650 | left_xy[LTOP] -= h->mb_stride; | |
2296 | } else { | ||
2297 |
2/2✓ Branch 0 taken 263258 times.
✓ Branch 1 taken 747670 times.
|
1010928 | if (curr_mb_field_flag) |
2298 | 263258 | top_xy += h->mb_stride & | |
2299 | 263258 | (((h->cur_pic.mb_type[top_xy] >> 7) & 1) - 1); | |
2300 |
2/2✓ Branch 0 taken 204650 times.
✓ Branch 1 taken 806278 times.
|
1010928 | if (left_mb_field_flag != curr_mb_field_flag) |
2301 | 204650 | left_xy[LBOT] += h->mb_stride; | |
2302 | } | ||
2303 | } | ||
2304 | |||
2305 | 12577876 | sl->top_mb_xy = top_xy; | |
2306 | 12577876 | sl->left_mb_xy[LTOP] = left_xy[LTOP]; | |
2307 | 12577876 | sl->left_mb_xy[LBOT] = left_xy[LBOT]; | |
2308 | { | ||
2309 | /* For sufficiently low qp, filtering wouldn't do anything. | ||
2310 | * This is a conservative estimate: could also check beta_offset | ||
2311 | * and more accurate chroma_qp. */ | ||
2312 | 12577876 | int qp_thresh = sl->qp_thresh; // FIXME strictly we should store qp_thresh for each mb of a slice | |
2313 | 12577876 | int qp = h->cur_pic.qscale_table[mb_xy]; | |
2314 |
2/2✓ Branch 0 taken 1768982 times.
✓ Branch 1 taken 10808894 times.
|
12577876 | if (qp <= qp_thresh && |
2315 |
2/2✓ Branch 0 taken 1767272 times.
✓ Branch 1 taken 1710 times.
|
1768982 | (left_xy[LTOP] < 0 || |
2316 |
4/4✓ Branch 0 taken 1707216 times.
✓ Branch 1 taken 60056 times.
✓ Branch 2 taken 1624300 times.
✓ Branch 3 taken 84626 times.
|
1768982 | ((qp + h->cur_pic.qscale_table[left_xy[LTOP]] + 1) >> 1) <= qp_thresh) && |
2317 | 1624300 | (top_xy < 0 || | |
2318 |
2/2✓ Branch 0 taken 1429319 times.
✓ Branch 1 taken 194981 times.
|
1624300 | ((qp + h->cur_pic.qscale_table[top_xy] + 1) >> 1) <= qp_thresh)) { |
2319 |
2/2✓ Branch 0 taken 1198134 times.
✓ Branch 1 taken 315811 times.
|
1513945 | if (!FRAME_MBAFF(h)) |
2320 | 1198134 | return 1; | |
2321 |
2/2✓ Branch 0 taken 315680 times.
✓ Branch 1 taken 131 times.
|
315811 | if ((left_xy[LTOP] < 0 || |
2322 |
2/2✓ Branch 0 taken 315151 times.
✓ Branch 1 taken 529 times.
|
315680 | ((qp + h->cur_pic.qscale_table[left_xy[LBOT]] + 1) >> 1) <= qp_thresh) && |
2323 |
2/2✓ Branch 0 taken 294673 times.
✓ Branch 1 taken 20609 times.
|
315282 | (top_xy < h->mb_stride || |
2324 |
2/2✓ Branch 0 taken 271562 times.
✓ Branch 1 taken 23111 times.
|
294673 | ((qp + h->cur_pic.qscale_table[top_xy - h->mb_stride] + 1) >> 1) <= qp_thresh)) |
2325 | 292171 | return 1; | |
2326 | } | ||
2327 | } | ||
2328 | |||
2329 | 11087571 | top_type = h->cur_pic.mb_type[top_xy]; | |
2330 | 11087571 | left_type[LTOP] = h->cur_pic.mb_type[left_xy[LTOP]]; | |
2331 | 11087571 | left_type[LBOT] = h->cur_pic.mb_type[left_xy[LBOT]]; | |
2332 |
2/2✓ Branch 0 taken 470376 times.
✓ Branch 1 taken 10617195 times.
|
11087571 | if (sl->deblocking_filter == 2) { |
2333 |
2/2✓ Branch 0 taken 56878 times.
✓ Branch 1 taken 413498 times.
|
470376 | if (h->slice_table[top_xy] != sl->slice_num) |
2334 | 56878 | top_type = 0; | |
2335 |
2/2✓ Branch 0 taken 13874 times.
✓ Branch 1 taken 456502 times.
|
470376 | if (h->slice_table[left_xy[LBOT]] != sl->slice_num) |
2336 | 13874 | left_type[LTOP] = left_type[LBOT] = 0; | |
2337 | } else { | ||
2338 |
2/2✓ Branch 0 taken 473679 times.
✓ Branch 1 taken 10143516 times.
|
10617195 | if (h->slice_table[top_xy] == 0xFFFF) |
2339 | 473679 | top_type = 0; | |
2340 |
2/2✓ Branch 0 taken 304128 times.
✓ Branch 1 taken 10313067 times.
|
10617195 | if (h->slice_table[left_xy[LBOT]] == 0xFFFF) |
2341 | 304128 | left_type[LTOP] = left_type[LBOT] = 0; | |
2342 | } | ||
2343 | 11087571 | sl->top_type = top_type; | |
2344 | 11087571 | sl->left_type[LTOP] = left_type[LTOP]; | |
2345 | 11087571 | sl->left_type[LBOT] = left_type[LBOT]; | |
2346 | |||
2347 |
2/2✓ Branch 0 taken 2983528 times.
✓ Branch 1 taken 8104043 times.
|
11087571 | if (IS_INTRA(mb_type)) |
2348 | 2983528 | return 0; | |
2349 | |||
2350 | 8104043 | fill_filter_caches_inter(h, sl, mb_type, top_xy, left_xy, | |
2351 | top_type, left_type, mb_xy, 0); | ||
2352 |
2/2✓ Branch 0 taken 4255407 times.
✓ Branch 1 taken 3848636 times.
|
8104043 | if (sl->list_count == 2) |
2353 | 4255407 | fill_filter_caches_inter(h, sl, mb_type, top_xy, left_xy, | |
2354 | top_type, left_type, mb_xy, 1); | ||
2355 | |||
2356 | 8104043 | nnz = h->non_zero_count[mb_xy]; | |
2357 | 8104043 | nnz_cache = sl->non_zero_count_cache; | |
2358 | 8104043 | AV_COPY32(&nnz_cache[4 + 8 * 1], &nnz[0]); | |
2359 | 8104043 | AV_COPY32(&nnz_cache[4 + 8 * 2], &nnz[4]); | |
2360 | 8104043 | AV_COPY32(&nnz_cache[4 + 8 * 3], &nnz[8]); | |
2361 | 8104043 | AV_COPY32(&nnz_cache[4 + 8 * 4], &nnz[12]); | |
2362 | 8104043 | sl->cbp = h->cbp_table[mb_xy]; | |
2363 | |||
2364 |
2/2✓ Branch 0 taken 7677262 times.
✓ Branch 1 taken 426781 times.
|
8104043 | if (top_type) { |
2365 | 7677262 | nnz = h->non_zero_count[top_xy]; | |
2366 | 7677262 | AV_COPY32(&nnz_cache[4 + 8 * 0], &nnz[3 * 4]); | |
2367 | } | ||
2368 | |||
2369 |
2/2✓ Branch 0 taken 7840492 times.
✓ Branch 1 taken 263551 times.
|
8104043 | if (left_type[LTOP]) { |
2370 | 7840492 | nnz = h->non_zero_count[left_xy[LTOP]]; | |
2371 | 7840492 | nnz_cache[3 + 8 * 1] = nnz[3 + 0 * 4]; | |
2372 | 7840492 | nnz_cache[3 + 8 * 2] = nnz[3 + 1 * 4]; | |
2373 | 7840492 | nnz_cache[3 + 8 * 3] = nnz[3 + 2 * 4]; | |
2374 | 7840492 | nnz_cache[3 + 8 * 4] = nnz[3 + 3 * 4]; | |
2375 | } | ||
2376 | |||
2377 | /* CAVLC 8x8dct requires NNZ values for residual decoding that differ | ||
2378 | * from what the loop filter needs */ | ||
2379 |
4/4✓ Branch 0 taken 2070968 times.
✓ Branch 1 taken 6033075 times.
✓ Branch 2 taken 246166 times.
✓ Branch 3 taken 1824802 times.
|
8104043 | if (!CABAC(h) && h->ps.pps->transform_8x8_mode) { |
2380 |
2/2✓ Branch 0 taken 107789 times.
✓ Branch 1 taken 138377 times.
|
246166 | if (IS_8x8DCT(top_type)) { |
2381 | 107789 | nnz_cache[4 + 8 * 0] = | |
2382 | 107789 | nnz_cache[5 + 8 * 0] = (h->cbp_table[top_xy] & 0x4000) >> 12; | |
2383 | 107789 | nnz_cache[6 + 8 * 0] = | |
2384 | 107789 | nnz_cache[7 + 8 * 0] = (h->cbp_table[top_xy] & 0x8000) >> 12; | |
2385 | } | ||
2386 |
2/2✓ Branch 0 taken 110456 times.
✓ Branch 1 taken 135710 times.
|
246166 | if (IS_8x8DCT(left_type[LTOP])) { |
2387 | 110456 | nnz_cache[3 + 8 * 1] = | |
2388 | 110456 | nnz_cache[3 + 8 * 2] = (h->cbp_table[left_xy[LTOP]] & 0x2000) >> 12; // FIXME check MBAFF | |
2389 | } | ||
2390 |
2/2✓ Branch 0 taken 110556 times.
✓ Branch 1 taken 135610 times.
|
246166 | if (IS_8x8DCT(left_type[LBOT])) { |
2391 | 110556 | nnz_cache[3 + 8 * 3] = | |
2392 | 110556 | nnz_cache[3 + 8 * 4] = (h->cbp_table[left_xy[LBOT]] & 0x8000) >> 12; // FIXME check MBAFF | |
2393 | } | ||
2394 | |||
2395 |
2/2✓ Branch 0 taken 104872 times.
✓ Branch 1 taken 141294 times.
|
246166 | if (IS_8x8DCT(mb_type)) { |
2396 | 104872 | nnz_cache[scan8[0]] = | |
2397 | 104872 | nnz_cache[scan8[1]] = | |
2398 | 104872 | nnz_cache[scan8[2]] = | |
2399 | 104872 | nnz_cache[scan8[3]] = (sl->cbp & 0x1000) >> 12; | |
2400 | |||
2401 | 104872 | nnz_cache[scan8[0 + 4]] = | |
2402 | 104872 | nnz_cache[scan8[1 + 4]] = | |
2403 | 104872 | nnz_cache[scan8[2 + 4]] = | |
2404 | 104872 | nnz_cache[scan8[3 + 4]] = (sl->cbp & 0x2000) >> 12; | |
2405 | |||
2406 | 104872 | nnz_cache[scan8[0 + 8]] = | |
2407 | 104872 | nnz_cache[scan8[1 + 8]] = | |
2408 | 104872 | nnz_cache[scan8[2 + 8]] = | |
2409 | 104872 | nnz_cache[scan8[3 + 8]] = (sl->cbp & 0x4000) >> 12; | |
2410 | |||
2411 | 104872 | nnz_cache[scan8[0 + 12]] = | |
2412 | 104872 | nnz_cache[scan8[1 + 12]] = | |
2413 | 104872 | nnz_cache[scan8[2 + 12]] = | |
2414 | 104872 | nnz_cache[scan8[3 + 12]] = (sl->cbp & 0x8000) >> 12; | |
2415 | } | ||
2416 | } | ||
2417 | |||
2418 | 8104043 | return 0; | |
2419 | } | ||
2420 | |||
2421 | 403071 | static void loop_filter(const H264Context *h, H264SliceContext *sl, int start_x, int end_x) | |
2422 | { | ||
2423 | uint8_t *dest_y, *dest_cb, *dest_cr; | ||
2424 | int linesize, uvlinesize, mb_x, mb_y; | ||
2425 | 403071 | const int end_mb_y = sl->mb_y + FRAME_MBAFF(h); | |
2426 | 403071 | const int old_slice_type = sl->slice_type; | |
2427 | 403071 | const int pixel_shift = h->pixel_shift; | |
2428 | 403071 | const int block_h = 16 >> h->chroma_y_shift; | |
2429 | |||
2430 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 403071 times.
|
403071 | if (h->postpone_filter) |
2431 | ✗ | return; | |
2432 | |||
2433 |
2/2✓ Branch 0 taken 326103 times.
✓ Branch 1 taken 76968 times.
|
403071 | if (sl->deblocking_filter) { |
2434 |
2/2✓ Branch 0 taken 11566948 times.
✓ Branch 1 taken 326103 times.
|
11893051 | for (mb_x = start_x; mb_x < end_x; mb_x++) |
2435 |
2/2✓ Branch 0 taken 12577876 times.
✓ Branch 1 taken 11566948 times.
|
24144824 | for (mb_y = end_mb_y - FRAME_MBAFF(h); mb_y <= end_mb_y; mb_y++) { |
2436 | int mb_xy, mb_type; | ||
2437 | 12577876 | mb_xy = sl->mb_xy = mb_x + mb_y * h->mb_stride; | |
2438 | 12577876 | mb_type = h->cur_pic.mb_type[mb_xy]; | |
2439 | |||
2440 |
2/2✓ Branch 0 taken 2021856 times.
✓ Branch 1 taken 10556020 times.
|
12577876 | if (FRAME_MBAFF(h)) |
2441 | 2021856 | sl->mb_mbaff = | |
2442 | 2021856 | sl->mb_field_decoding_flag = !!IS_INTERLACED(mb_type); | |
2443 | |||
2444 | 12577876 | sl->mb_x = mb_x; | |
2445 | 12577876 | sl->mb_y = mb_y; | |
2446 | 12577876 | dest_y = h->cur_pic.f->data[0] + | |
2447 | 12577876 | ((mb_x << pixel_shift) + mb_y * sl->linesize) * 16; | |
2448 | 25155752 | dest_cb = h->cur_pic.f->data[1] + | |
2449 |
2/2✓ Branch 0 taken 80328 times.
✓ Branch 1 taken 12497548 times.
|
12577876 | (mb_x << pixel_shift) * (8 << CHROMA444(h)) + |
2450 | 12577876 | mb_y * sl->uvlinesize * block_h; | |
2451 | 25155752 | dest_cr = h->cur_pic.f->data[2] + | |
2452 |
2/2✓ Branch 0 taken 80328 times.
✓ Branch 1 taken 12497548 times.
|
12577876 | (mb_x << pixel_shift) * (8 << CHROMA444(h)) + |
2453 | 12577876 | mb_y * sl->uvlinesize * block_h; | |
2454 | // FIXME simplify above | ||
2455 | |||
2456 |
2/2✓ Branch 0 taken 4648114 times.
✓ Branch 1 taken 7929762 times.
|
12577876 | if (MB_FIELD(sl)) { |
2457 | 4648114 | linesize = sl->mb_linesize = sl->linesize * 2; | |
2458 | 4648114 | uvlinesize = sl->mb_uvlinesize = sl->uvlinesize * 2; | |
2459 |
2/2✓ Branch 0 taken 2321318 times.
✓ Branch 1 taken 2326796 times.
|
4648114 | if (mb_y & 1) { // FIXME move out of this function? |
2460 | 2321318 | dest_y -= sl->linesize * 15; | |
2461 | 2321318 | dest_cb -= sl->uvlinesize * (block_h - 1); | |
2462 | 2321318 | dest_cr -= sl->uvlinesize * (block_h - 1); | |
2463 | } | ||
2464 | } else { | ||
2465 | 7929762 | linesize = sl->mb_linesize = sl->linesize; | |
2466 | 7929762 | uvlinesize = sl->mb_uvlinesize = sl->uvlinesize; | |
2467 | } | ||
2468 | 12577876 | backup_mb_border(h, sl, dest_y, dest_cb, dest_cr, linesize, | |
2469 | uvlinesize, 0); | ||
2470 |
2/2✓ Branch 1 taken 1490305 times.
✓ Branch 2 taken 11087571 times.
|
12577876 | if (fill_filter_caches(h, sl, mb_type)) |
2471 | 1490305 | continue; | |
2472 | 11087571 | sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, h->cur_pic.qscale_table[mb_xy]); | |
2473 | 11087571 | sl->chroma_qp[1] = get_chroma_qp(h->ps.pps, 1, h->cur_pic.qscale_table[mb_xy]); | |
2474 | |||
2475 |
2/2✓ Branch 0 taken 1729685 times.
✓ Branch 1 taken 9357886 times.
|
11087571 | if (FRAME_MBAFF(h)) { |
2476 | 1729685 | ff_h264_filter_mb(h, sl, mb_x, mb_y, dest_y, dest_cb, dest_cr, | |
2477 | linesize, uvlinesize); | ||
2478 | } else { | ||
2479 | 9357886 | ff_h264_filter_mb_fast(h, sl, mb_x, mb_y, dest_y, dest_cb, | |
2480 | dest_cr, linesize, uvlinesize); | ||
2481 | } | ||
2482 | } | ||
2483 | } | ||
2484 | 403071 | sl->slice_type = old_slice_type; | |
2485 | 403071 | sl->mb_x = end_x; | |
2486 | 403071 | sl->mb_y = end_mb_y - FRAME_MBAFF(h); | |
2487 | 403071 | sl->chroma_qp[0] = get_chroma_qp(h->ps.pps, 0, sl->qscale); | |
2488 | 403071 | sl->chroma_qp[1] = get_chroma_qp(h->ps.pps, 1, sl->qscale); | |
2489 | } | ||
2490 | |||
2491 | 24039 | static void predict_field_decoding_flag(const H264Context *h, H264SliceContext *sl) | |
2492 | { | ||
2493 | 24039 | const int mb_xy = sl->mb_x + sl->mb_y * h->mb_stride; | |
2494 | 48078 | int mb_type = (h->slice_table[mb_xy - 1] == sl->slice_num) ? | |
2495 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24039 times.
|
48078 | h->cur_pic.mb_type[mb_xy - 1] : |
2496 |
2/2✓ Branch 0 taken 23903 times.
✓ Branch 1 taken 136 times.
|
24039 | (h->slice_table[mb_xy - h->mb_stride] == sl->slice_num) ? |
2497 | 23903 | h->cur_pic.mb_type[mb_xy - h->mb_stride] : 0; | |
2498 | 24039 | sl->mb_mbaff = sl->mb_field_decoding_flag = IS_INTERLACED(mb_type) ? 1 : 0; | |
2499 | 24039 | } | |
2500 | |||
2501 | /** | ||
2502 | * Draw edges and report progress for the last MB row. | ||
2503 | */ | ||
2504 | 398511 | static void decode_finish_row(const H264Context *h, H264SliceContext *sl) | |
2505 | { | ||
2506 | 398511 | int top = 16 * (sl->mb_y >> FIELD_PICTURE(h)); | |
2507 | 398511 | int pic_height = 16 * h->mb_height >> FIELD_PICTURE(h); | |
2508 | 398511 | int height = 16 << FRAME_MBAFF(h); | |
2509 | 398511 | int deblock_border = (16 + 4) << FRAME_MBAFF(h); | |
2510 | |||
2511 |
2/2✓ Branch 0 taken 323011 times.
✓ Branch 1 taken 75500 times.
|
398511 | if (sl->deblocking_filter) { |
2512 |
2/2✓ Branch 0 taken 22437 times.
✓ Branch 1 taken 300574 times.
|
323011 | if ((top + height) >= pic_height) |
2513 | 22437 | height += deblock_border; | |
2514 | 323011 | top -= deblock_border; | |
2515 | } | ||
2516 | |||
2517 |
3/4✓ Branch 0 taken 398511 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 22438 times.
✓ Branch 3 taken 376073 times.
|
398511 | if (top >= pic_height || (top + height) < 0) |
2518 | 22438 | return; | |
2519 | |||
2520 | 376073 | height = FFMIN(height, pic_height - top); | |
2521 |
2/2✓ Branch 0 taken 22438 times.
✓ Branch 1 taken 353635 times.
|
376073 | if (top < 0) { |
2522 | 22438 | height = top + height; | |
2523 | 22438 | top = 0; | |
2524 | } | ||
2525 | |||
2526 | 376073 | ff_h264_draw_horiz_band(h, sl, top, height); | |
2527 | |||
2528 |
3/4✓ Branch 0 taken 242560 times.
✓ Branch 1 taken 133513 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 242560 times.
|
376073 | if (h->droppable || h->er.error_occurred) |
2529 | 133513 | return; | |
2530 | |||
2531 | 242560 | ff_thread_report_progress(&h->cur_pic_ptr->tf, top + height - 1, | |
2532 | 242560 | h->picture_structure == PICT_BOTTOM_FIELD); | |
2533 | } | ||
2534 | |||
2535 | 37363 | static void er_add_slice(H264SliceContext *sl, | |
2536 | int startx, int starty, | ||
2537 | int endx, int endy, int status) | ||
2538 | { | ||
2539 |
2/2✓ Branch 0 taken 1200 times.
✓ Branch 1 taken 36163 times.
|
37363 | if (!sl->h264->enable_er) |
2540 | 1200 | return; | |
2541 | |||
2542 | if (CONFIG_ERROR_RESILIENCE) { | ||
2543 | 36163 | ff_er_add_slice(sl->er, startx, starty, endx, endy, status); | |
2544 | } | ||
2545 | } | ||
2546 | |||
2547 | 37363 | static int decode_slice(struct AVCodecContext *avctx, void *arg) | |
2548 | { | ||
2549 | 37363 | H264SliceContext *sl = arg; | |
2550 | 37363 | const H264Context *h = sl->h264; | |
2551 | 37363 | int lf_x_start = sl->mb_x; | |
2552 | 37363 | int orig_deblock = sl->deblocking_filter; | |
2553 | int ret; | ||
2554 | |||
2555 | 37363 | sl->linesize = h->cur_pic_ptr->f->linesize[0]; | |
2556 | 37363 | sl->uvlinesize = h->cur_pic_ptr->f->linesize[1]; | |
2557 | |||
2558 | 37363 | ret = alloc_scratch_buffers(sl, sl->linesize); | |
2559 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37363 times.
|
37363 | if (ret < 0) |
2560 | ✗ | return ret; | |
2561 | |||
2562 | 37363 | sl->mb_skip_run = -1; | |
2563 | |||
2564 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37363 times.
|
37363 | av_assert0(h->block_offset[15] == (4 * ((scan8[15] - scan8[0]) & 7) << h->pixel_shift) + 4 * sl->linesize * ((scan8[15] - scan8[0]) >> 3)); |
2565 | |||
2566 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37363 times.
|
37363 | if (h->postpone_filter) |
2567 | ✗ | sl->deblocking_filter = 0; | |
2568 | |||
2569 |
4/4✓ Branch 0 taken 32391 times.
✓ Branch 1 taken 4972 times.
✓ Branch 2 taken 8946 times.
✓ Branch 3 taken 23445 times.
|
37363 | sl->is_complex = FRAME_MBAFF(h) || h->picture_structure != PICT_FRAME || |
2570 | (CONFIG_GRAY && (h->flags & AV_CODEC_FLAG_GRAY)); | ||
2571 | |||
2572 |
5/6✓ Branch 0 taken 36163 times.
✓ Branch 1 taken 1200 times.
✓ Branch 2 taken 27217 times.
✓ Branch 3 taken 8946 times.
✓ Branch 4 taken 27217 times.
✗ Branch 5 not taken.
|
37363 | if (!(h->avctx->active_thread_type & FF_THREAD_SLICE) && h->picture_structure == PICT_FRAME && sl->er->error_status_table) { |
2573 | 27217 | const int start_i = av_clip(sl->resync_mb_x + sl->resync_mb_y * h->mb_width, 0, h->mb_num - 1); | |
2574 |
2/2✓ Branch 0 taken 5956 times.
✓ Branch 1 taken 21261 times.
|
27217 | if (start_i) { |
2575 | 5956 | int prev_status = sl->er->error_status_table[sl->er->mb_index2xy[start_i - 1]]; | |
2576 | 5956 | prev_status &= ~ VP_START; | |
2577 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5956 times.
|
5956 | if (prev_status != (ER_MV_END | ER_DC_END | ER_AC_END)) |
2578 | ✗ | sl->er->error_occurred = 1; | |
2579 | } | ||
2580 | } | ||
2581 | |||
2582 |
2/2✓ Branch 0 taken 20622 times.
✓ Branch 1 taken 16741 times.
|
37363 | if (h->ps.pps->cabac) { |
2583 | /* realign */ | ||
2584 | 20622 | align_get_bits(&sl->gb); | |
2585 | |||
2586 | /* init cabac */ | ||
2587 | 41244 | ret = ff_init_cabac_decoder(&sl->cabac, | |
2588 | 20622 | sl->gb.buffer + get_bits_count(&sl->gb) / 8, | |
2589 | 20622 | (get_bits_left(&sl->gb) + 7) / 8); | |
2590 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 20622 times.
|
20622 | if (ret < 0) |
2591 | ✗ | return ret; | |
2592 | |||
2593 | 20622 | ff_h264_init_cabac_states(h, sl); | |
2594 | |||
2595 | 9357963 | for (;;) { | |
2596 | int ret, eos; | ||
2597 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9378585 times.
|
9378585 | if (sl->mb_x + sl->mb_y * h->mb_width >= sl->next_slice_idx) { |
2598 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Slice overlaps with next at %d\n", | |
2599 | sl->next_slice_idx); | ||
2600 | ✗ | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x, | |
2601 | sl->mb_y, ER_MB_ERROR); | ||
2602 | ✗ | return AVERROR_INVALIDDATA; | |
2603 | } | ||
2604 | |||
2605 | 9378585 | ret = ff_h264_decode_mb_cabac(h, sl); | |
2606 | |||
2607 |
2/2✓ Branch 0 taken 9378584 times.
✓ Branch 1 taken 1 times.
|
9378585 | if (ret >= 0) |
2608 | 9378584 | ff_h264_hl_decode_mb(h, sl); | |
2609 | |||
2610 | // FIXME optimal? or let mb_decode decode 16x32 ? | ||
2611 |
4/4✓ Branch 0 taken 9378584 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 902580 times.
✓ Branch 3 taken 8476004 times.
|
9378585 | if (ret >= 0 && FRAME_MBAFF(h)) { |
2612 | 902580 | sl->mb_y++; | |
2613 | |||
2614 | 902580 | ret = ff_h264_decode_mb_cabac(h, sl); | |
2615 | |||
2616 |
1/2✓ Branch 0 taken 902580 times.
✗ Branch 1 not taken.
|
902580 | if (ret >= 0) |
2617 | 902580 | ff_h264_hl_decode_mb(h, sl); | |
2618 | 902580 | sl->mb_y--; | |
2619 | } | ||
2620 | 9378585 | eos = get_cabac_terminate(&sl->cabac); | |
2621 | |||
2622 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 9378585 times.
|
9378585 | if ((h->workaround_bugs & FF_BUG_TRUNCATED) && |
2623 | ✗ | sl->cabac.bytestream > sl->cabac.bytestream_end + 2) { | |
2624 | ✗ | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x - 1, | |
2625 | sl->mb_y, ER_MB_END); | ||
2626 | ✗ | if (sl->mb_x >= lf_x_start) | |
2627 | ✗ | loop_filter(h, sl, lf_x_start, sl->mb_x + 1); | |
2628 | ✗ | goto finish; | |
2629 | } | ||
2630 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9378584 times.
|
9378585 | if (sl->cabac.bytestream > sl->cabac.bytestream_end + 2 ) |
2631 | 1 | av_log(h->avctx, AV_LOG_DEBUG, "bytestream overread %"PTRDIFF_SPECIFIER"\n", sl->cabac.bytestream_end - sl->cabac.bytestream); | |
2632 |
4/4✓ Branch 0 taken 9378584 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 9378583 times.
|
9378585 | if (ret < 0 || sl->cabac.bytestream > sl->cabac.bytestream_end + 4) { |
2633 | 2 | av_log(h->avctx, AV_LOG_ERROR, | |
2634 | "error while decoding MB %d %d, bytestream %"PTRDIFF_SPECIFIER"\n", | ||
2635 | sl->mb_x, sl->mb_y, | ||
2636 | 2 | sl->cabac.bytestream_end - sl->cabac.bytestream); | |
2637 | 2 | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x, | |
2638 | sl->mb_y, ER_MB_ERROR); | ||
2639 | 2 | return AVERROR_INVALIDDATA; | |
2640 | } | ||
2641 | |||
2642 |
2/2✓ Branch 0 taken 237547 times.
✓ Branch 1 taken 9141036 times.
|
9378583 | if (++sl->mb_x >= h->mb_width) { |
2643 | 237547 | loop_filter(h, sl, lf_x_start, sl->mb_x); | |
2644 | 237547 | sl->mb_x = lf_x_start = 0; | |
2645 | 237547 | decode_finish_row(h, sl); | |
2646 | 237547 | ++sl->mb_y; | |
2647 |
4/4✓ Branch 0 taken 216659 times.
✓ Branch 1 taken 20888 times.
✓ Branch 2 taken 59174 times.
✓ Branch 3 taken 157485 times.
|
237547 | if (FIELD_OR_MBAFF_PICTURE(h)) { |
2648 | 80062 | ++sl->mb_y; | |
2649 |
4/4✓ Branch 0 taken 20888 times.
✓ Branch 1 taken 59174 times.
✓ Branch 2 taken 19061 times.
✓ Branch 3 taken 1827 times.
|
80062 | if (FRAME_MBAFF(h) && sl->mb_y < h->mb_height) |
2650 | 19061 | predict_field_decoding_flag(h, sl); | |
2651 | } | ||
2652 | } | ||
2653 | |||
2654 |
3/4✓ Branch 0 taken 9357963 times.
✓ Branch 1 taken 20620 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9357963 times.
|
9378583 | if (eos || sl->mb_y >= h->mb_height) { |
2655 | ff_tlog(h->avctx, "slice end %d %d\n", | ||
2656 | get_bits_count(&sl->gb), sl->gb.size_in_bits); | ||
2657 | 20620 | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x - 1, | |
2658 | sl->mb_y, ER_MB_END); | ||
2659 |
2/2✓ Branch 0 taken 1382 times.
✓ Branch 1 taken 19238 times.
|
20620 | if (sl->mb_x > lf_x_start) |
2660 | 1382 | loop_filter(h, sl, lf_x_start, sl->mb_x); | |
2661 | 20620 | goto finish; | |
2662 | } | ||
2663 | } | ||
2664 | } else { | ||
2665 | 4575657 | for (;;) { | |
2666 | int ret; | ||
2667 | |||
2668 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4592398 times.
|
4592398 | if (sl->mb_x + sl->mb_y * h->mb_width >= sl->next_slice_idx) { |
2669 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "Slice overlaps with next at %d\n", | |
2670 | sl->next_slice_idx); | ||
2671 | ✗ | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x, | |
2672 | sl->mb_y, ER_MB_ERROR); | ||
2673 | ✗ | return AVERROR_INVALIDDATA; | |
2674 | } | ||
2675 | |||
2676 | 4592398 | ret = ff_h264_decode_mb_cavlc(h, sl); | |
2677 | |||
2678 |
1/2✓ Branch 0 taken 4592398 times.
✗ Branch 1 not taken.
|
4592398 | if (ret >= 0) |
2679 | 4592398 | ff_h264_hl_decode_mb(h, sl); | |
2680 | |||
2681 | // FIXME optimal? or let mb_decode decode 16x32 ? | ||
2682 |
3/4✓ Branch 0 taken 4592398 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 254472 times.
✓ Branch 3 taken 4337926 times.
|
4592398 | if (ret >= 0 && FRAME_MBAFF(h)) { |
2683 | 254472 | sl->mb_y++; | |
2684 | 254472 | ret = ff_h264_decode_mb_cavlc(h, sl); | |
2685 | |||
2686 |
1/2✓ Branch 0 taken 254472 times.
✗ Branch 1 not taken.
|
254472 | if (ret >= 0) |
2687 | 254472 | ff_h264_hl_decode_mb(h, sl); | |
2688 | 254472 | sl->mb_y--; | |
2689 | } | ||
2690 | |||
2691 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4592398 times.
|
4592398 | if (ret < 0) { |
2692 | ✗ | av_log(h->avctx, AV_LOG_ERROR, | |
2693 | "error while decoding MB %d %d\n", sl->mb_x, sl->mb_y); | ||
2694 | ✗ | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x, | |
2695 | sl->mb_y, ER_MB_ERROR); | ||
2696 | ✗ | return ret; | |
2697 | } | ||
2698 | |||
2699 |
2/2✓ Branch 0 taken 160964 times.
✓ Branch 1 taken 4431434 times.
|
4592398 | if (++sl->mb_x >= h->mb_width) { |
2700 | 160964 | loop_filter(h, sl, lf_x_start, sl->mb_x); | |
2701 | 160964 | sl->mb_x = lf_x_start = 0; | |
2702 | 160964 | decode_finish_row(h, sl); | |
2703 | 160964 | ++sl->mb_y; | |
2704 |
4/4✓ Branch 0 taken 155487 times.
✓ Branch 1 taken 5477 times.
✓ Branch 2 taken 26666 times.
✓ Branch 3 taken 128821 times.
|
160964 | if (FIELD_OR_MBAFF_PICTURE(h)) { |
2705 | 32143 | ++sl->mb_y; | |
2706 |
4/4✓ Branch 0 taken 5477 times.
✓ Branch 1 taken 26666 times.
✓ Branch 2 taken 4978 times.
✓ Branch 3 taken 499 times.
|
32143 | if (FRAME_MBAFF(h) && sl->mb_y < h->mb_height) |
2707 | 4978 | predict_field_decoding_flag(h, sl); | |
2708 | } | ||
2709 |
2/2✓ Branch 0 taken 12651 times.
✓ Branch 1 taken 148313 times.
|
160964 | if (sl->mb_y >= h->mb_height) { |
2710 | ff_tlog(h->avctx, "slice end %d %d\n", | ||
2711 | get_bits_count(&sl->gb), sl->gb.size_in_bits); | ||
2712 | |||
2713 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 12651 times.
|
12651 | if ( get_bits_left(&sl->gb) == 0 |
2714 | ✗ | || get_bits_left(&sl->gb) > 0 && !(h->avctx->err_recognition & AV_EF_AGGRESSIVE)) { | |
2715 | 12651 | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, | |
2716 | 12651 | sl->mb_x - 1, sl->mb_y, ER_MB_END); | |
2717 | |||
2718 | 12651 | goto finish; | |
2719 | } else { | ||
2720 | ✗ | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, | |
2721 | sl->mb_x, sl->mb_y, ER_MB_END); | ||
2722 | |||
2723 | ✗ | return AVERROR_INVALIDDATA; | |
2724 | } | ||
2725 | } | ||
2726 | } | ||
2727 | |||
2728 |
4/4✓ Branch 1 taken 238513 times.
✓ Branch 2 taken 4341234 times.
✓ Branch 3 taken 4090 times.
✓ Branch 4 taken 234423 times.
|
4579747 | if (get_bits_left(&sl->gb) <= 0 && sl->mb_skip_run <= 0) { |
2729 | ff_tlog(h->avctx, "slice end %d %d\n", | ||
2730 | get_bits_count(&sl->gb), sl->gb.size_in_bits); | ||
2731 | |||
2732 |
1/2✓ Branch 1 taken 4090 times.
✗ Branch 2 not taken.
|
4090 | if (get_bits_left(&sl->gb) == 0) { |
2733 | 4090 | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, | |
2734 | 4090 | sl->mb_x - 1, sl->mb_y, ER_MB_END); | |
2735 |
2/2✓ Branch 0 taken 3178 times.
✓ Branch 1 taken 912 times.
|
4090 | if (sl->mb_x > lf_x_start) |
2736 | 3178 | loop_filter(h, sl, lf_x_start, sl->mb_x); | |
2737 | |||
2738 | 4090 | goto finish; | |
2739 | } else { | ||
2740 | ✗ | er_add_slice(sl, sl->resync_mb_x, sl->resync_mb_y, sl->mb_x, | |
2741 | sl->mb_y, ER_MB_ERROR); | ||
2742 | |||
2743 | ✗ | return AVERROR_INVALIDDATA; | |
2744 | } | ||
2745 | } | ||
2746 | } | ||
2747 | } | ||
2748 | |||
2749 | 37361 | finish: | |
2750 | 37361 | sl->deblocking_filter = orig_deblock; | |
2751 | 37361 | return 0; | |
2752 | } | ||
2753 | |||
2754 | /** | ||
2755 | * Call decode_slice() for each context. | ||
2756 | * | ||
2757 | * @param h h264 master context | ||
2758 | */ | ||
2759 | 65755 | int ff_h264_execute_decode_slices(H264Context *h) | |
2760 | { | ||
2761 | 65755 | AVCodecContext *const avctx = h->avctx; | |
2762 | H264SliceContext *sl; | ||
2763 | 65755 | int context_count = h->nb_slice_ctx_queued; | |
2764 | 65755 | int ret = 0; | |
2765 | int i, j; | ||
2766 | |||
2767 | 65755 | h->slice_ctx[0].next_slice_idx = INT_MAX; | |
2768 | |||
2769 |
3/4✓ Branch 0 taken 65755 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28842 times.
✓ Branch 3 taken 36913 times.
|
65755 | if (h->avctx->hwaccel || context_count < 1) |
2770 | 28842 | return 0; | |
2771 | |||
2772 |
2/4✓ Branch 0 taken 36913 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 36913 times.
|
36913 | av_assert0(context_count && h->slice_ctx[context_count - 1].mb_y < h->mb_height); |
2773 | |||
2774 |
2/2✓ Branch 0 taken 36463 times.
✓ Branch 1 taken 450 times.
|
36913 | if (context_count == 1) { |
2775 | |||
2776 | 36463 | h->slice_ctx[0].next_slice_idx = h->mb_width * h->mb_height; | |
2777 | 36463 | h->postpone_filter = 0; | |
2778 | |||
2779 | 36463 | ret = decode_slice(avctx, &h->slice_ctx[0]); | |
2780 | 36463 | h->mb_y = h->slice_ctx[0].mb_y; | |
2781 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 36461 times.
|
36463 | if (ret < 0) |
2782 | 2 | goto finish; | |
2783 | } else { | ||
2784 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 450 times.
|
450 | av_assert0(context_count > 0); |
2785 |
2/2✓ Branch 0 taken 900 times.
✓ Branch 1 taken 450 times.
|
1350 | for (i = 0; i < context_count; i++) { |
2786 | 900 | int next_slice_idx = h->mb_width * h->mb_height; | |
2787 | int slice_idx; | ||
2788 | |||
2789 | 900 | sl = &h->slice_ctx[i]; | |
2790 | |||
2791 | /* make sure none of those slices overlap */ | ||
2792 | 900 | slice_idx = sl->mb_y * h->mb_width + sl->mb_x; | |
2793 |
2/2✓ Branch 0 taken 1800 times.
✓ Branch 1 taken 900 times.
|
2700 | for (j = 0; j < context_count; j++) { |
2794 | 1800 | H264SliceContext *sl2 = &h->slice_ctx[j]; | |
2795 | 1800 | int slice_idx2 = sl2->mb_y * h->mb_width + sl2->mb_x; | |
2796 | |||
2797 |
4/4✓ Branch 0 taken 900 times.
✓ Branch 1 taken 900 times.
✓ Branch 2 taken 450 times.
✓ Branch 3 taken 450 times.
|
1800 | if (i == j || slice_idx2 < slice_idx) |
2798 | 1350 | continue; | |
2799 | 450 | next_slice_idx = FFMIN(next_slice_idx, slice_idx2); | |
2800 | } | ||
2801 | 900 | sl->next_slice_idx = next_slice_idx; | |
2802 | } | ||
2803 | |||
2804 | 450 | avctx->execute(avctx, decode_slice, h->slice_ctx, | |
2805 | NULL, context_count, sizeof(h->slice_ctx[0])); | ||
2806 | |||
2807 | /* pull back stuff from slices to master context */ | ||
2808 | 450 | sl = &h->slice_ctx[context_count - 1]; | |
2809 | 450 | h->mb_y = sl->mb_y; | |
2810 | |||
2811 |
1/2✓ Branch 0 taken 450 times.
✗ Branch 1 not taken.
|
450 | if (h->postpone_filter) { |
2812 | ✗ | h->postpone_filter = 0; | |
2813 | |||
2814 | ✗ | for (i = 0; i < context_count; i++) { | |
2815 | int y_end, x_end; | ||
2816 | |||
2817 | ✗ | sl = &h->slice_ctx[i]; | |
2818 | ✗ | y_end = FFMIN(sl->mb_y + 1, h->mb_height); | |
2819 | ✗ | x_end = (sl->mb_y >= h->mb_height) ? h->mb_width : sl->mb_x; | |
2820 | |||
2821 | ✗ | for (j = sl->resync_mb_y; j < y_end; j += 1 + FIELD_OR_MBAFF_PICTURE(h)) { | |
2822 | ✗ | sl->mb_y = j; | |
2823 | ✗ | loop_filter(h, sl, j > sl->resync_mb_y ? 0 : sl->resync_mb_x, | |
2824 | ✗ | j == y_end - 1 ? x_end : h->mb_width); | |
2825 | } | ||
2826 | } | ||
2827 | } | ||
2828 | } | ||
2829 | |||
2830 | 450 | finish: | |
2831 | 36913 | h->nb_slice_ctx_queued = 0; | |
2832 | 36913 | return ret; | |
2833 | } | ||
2834 |