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 | 28973 | 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 1043028 times.
✓ Branch 1 taken 28973 times.
|
1072001 | for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) { |
123 |
6/6✓ Branch 0 taken 145912 times.
✓ Branch 1 taken 897116 times.
✓ Branch 2 taken 25348 times.
✓ Branch 3 taken 120564 times.
✓ Branch 4 taken 2610 times.
✓ Branch 5 taken 22738 times.
|
1043028 | 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 | 23461 | ff_h264_unref_picture(&h->DPB[i]); | |
126 | } | ||
127 | } | ||
128 | 28973 | } | |
129 | |||
130 | 37361 | static int alloc_scratch_buffers(H264SliceContext *sl, int linesize) | |
131 | { | ||
132 | 37361 | const H264Context *h = sl->h264; | |
133 | 37361 | int alloc_size = FFALIGN(FFABS(linesize) + 32, 32); | |
134 | |||
135 | 37361 | 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 | 37361 | av_fast_malloc(&sl->edge_emu_buffer, &sl->edge_emu_buffer_allocated, alloc_size * 2 * 21); | |
139 | |||
140 | 37361 | av_fast_mallocz(&sl->top_borders[0], &sl->top_borders_allocated[0], | |
141 | 37361 | h->mb_width * 16 * 3 * sizeof(uint8_t) * 2); | |
142 | 37361 | av_fast_mallocz(&sl->top_borders[1], &sl->top_borders_allocated[1], | |
143 | 37361 | h->mb_width * 16 * 3 * sizeof(uint8_t) * 2); | |
144 | |||
145 |
2/4✓ Branch 0 taken 37361 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37361 times.
✗ Branch 3 not taken.
|
37361 | if (!sl->bipred_scratchpad || !sl->edge_emu_buffer || |
146 |
2/4✓ Branch 0 taken 37361 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 37361 times.
|
37361 | !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 | 37361 | 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 | 25611 | static int alloc_picture(H264Context *h, H264Picture *pic) | |
189 | { | ||
190 | 25611 | int i, ret = 0; | |
191 | |||
192 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25611 times.
|
25611 | av_assert0(!pic->f->data[0]); |
193 | |||
194 | 25611 | pic->tf.f = pic->f; | |
195 | 25611 | ret = ff_thread_get_ext_buffer(h->avctx, &pic->tf, | |
196 | 25611 | pic->reference ? AV_GET_BUFFER_FLAG_REF : 0); | |
197 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25611 times.
|
25611 | if (ret < 0) |
198 | ✗ | goto fail; | |
199 | |||
200 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25611 times.
|
25611 | 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 | 25611 | ret = ff_hwaccel_frame_priv_alloc(h->avctx, &pic->hwaccel_picture_private); | |
210 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25611 times.
|
25611 | if (ret < 0) |
211 | ✗ | goto fail; | |
212 | |||
213 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 25569 times.
|
25611 | 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 25010 times.
|
25611 | 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 | 25611 | pic->qscale_table_base = ff_refstruct_pool_get(h->qscale_table_pool); | |
240 | 25611 | pic->mb_type_base = ff_refstruct_pool_get(h->mb_type_pool); | |
241 |
2/4✓ Branch 0 taken 25611 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 25611 times.
|
25611 | if (!pic->qscale_table_base || !pic->mb_type_base) |
242 | ✗ | goto fail; | |
243 | |||
244 | 25611 | pic->mb_type = pic->mb_type_base + 2 * h->mb_stride + 1; | |
245 | 25611 | pic->qscale_table = pic->qscale_table_base + 2 * h->mb_stride + 1; | |
246 | |||
247 |
2/2✓ Branch 0 taken 51222 times.
✓ Branch 1 taken 25611 times.
|
76833 | for (i = 0; i < 2; i++) { |
248 | 51222 | pic->motion_val_base[i] = ff_refstruct_pool_get(h->motion_val_pool); | |
249 | 51222 | pic->ref_index[i] = ff_refstruct_pool_get(h->ref_index_pool); | |
250 |
2/4✓ Branch 0 taken 51222 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 51222 times.
|
51222 | if (!pic->motion_val_base[i] || !pic->ref_index[i]) |
251 | ✗ | goto fail; | |
252 | |||
253 | 51222 | pic->motion_val[i] = pic->motion_val_base[i] + 4; | |
254 | } | ||
255 | |||
256 | 25611 | pic->pps = ff_refstruct_ref_c(h->ps.pps); | |
257 | |||
258 | 25611 | pic->mb_width = h->mb_width; | |
259 | 25611 | pic->mb_height = h->mb_height; | |
260 | 25611 | pic->mb_stride = h->mb_stride; | |
261 | |||
262 | 25611 | return 0; | |
263 | ✗ | fail: | |
264 | ✗ | ff_h264_unref_picture(pic); | |
265 | ✗ | return (ret < 0) ? ret : AVERROR(ENOMEM); | |
266 | } | ||
267 | |||
268 | 25611 | static int find_unused_picture(const H264Context *h) | |
269 | { | ||
270 | int i; | ||
271 | |||
272 |
1/2✓ Branch 0 taken 86986 times.
✗ Branch 1 not taken.
|
86986 | for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) { |
273 |
2/2✓ Branch 0 taken 25611 times.
✓ Branch 1 taken 61375 times.
|
86986 | if (!h->DPB[i].f->buf[0]) |
274 | 25611 | 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 | 174 | 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 4756 times.
✓ Branch 1 taken 174 times.
|
4930 | 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 251 times.
✓ Branch 1 taken 4505 times.
✓ Branch 2 taken 251 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 251 times.
✗ Branch 5 not taken.
|
4756 | to[i] = REBASE_PICTURE(from[i], new_base, old_base); |
297 | } | ||
298 | 174 | } | |
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 | 58 | int ff_h264_update_thread_context(AVCodecContext *dst, | |
331 | const AVCodecContext *src) | ||
332 | { | ||
333 | 58 | H264Context *h = dst->priv_data, *h1 = src->priv_data; | |
334 | 58 | int inited = h->context_initialized, err = 0; | |
335 | 58 | int need_reinit = 0; | |
336 | int i, ret; | ||
337 | |||
338 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (dst == src) |
339 | ✗ | return 0; | |
340 | |||
341 |
3/4✓ Branch 0 taken 42 times.
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 42 times.
|
58 | if (inited && !h1->ps.sps) |
342 | ✗ | return AVERROR_INVALIDDATA; | |
343 | |||
344 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 16 times.
|
58 | if (inited && |
345 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | (h->width != h1->width || |
346 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | h->height != h1->height || |
347 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | h->mb_width != h1->mb_width || |
348 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | h->mb_height != h1->mb_height || |
349 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | !h->ps.sps || |
350 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | h->ps.sps->bit_depth_luma != h1->ps.sps->bit_depth_luma || |
351 |
1/2✓ Branch 0 taken 42 times.
✗ Branch 1 not taken.
|
42 | h->ps.sps->chroma_format_idc != h1->ps.sps->chroma_format_idc || |
352 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
|
42 | 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 | 58 | memcpy(h->block_offset, h1->block_offset, sizeof(h->block_offset)); | |
358 | |||
359 | // SPS/PPS | ||
360 |
2/2✓ Branch 0 taken 1856 times.
✓ Branch 1 taken 58 times.
|
1914 | for (int i = 0; i < FF_ARRAY_ELEMS(h->ps.sps_list); i++) |
361 | 1856 | ff_refstruct_replace(&h->ps.sps_list[i], h1->ps.sps_list[i]); | |
362 |
2/2✓ Branch 0 taken 14848 times.
✓ Branch 1 taken 58 times.
|
14906 | for (int i = 0; i < FF_ARRAY_ELEMS(h->ps.pps_list); i++) |
363 | 14848 | ff_refstruct_replace(&h->ps.pps_list[i], h1->ps.pps_list[i]); | |
364 | |||
365 | 58 | ff_refstruct_replace(&h->ps.pps, h1->ps.pps); | |
366 | 58 | h->ps.sps = h1->ps.sps; | |
367 | |||
368 |
3/4✓ Branch 0 taken 58 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✓ Branch 3 taken 42 times.
|
58 | 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 | 58 | h->width_from_caller = h1->width_from_caller; | |
390 | 58 | h->height_from_caller = h1->height_from_caller; | |
391 | 58 | h->first_field = h1->first_field; | |
392 | 58 | h->picture_structure = h1->picture_structure; | |
393 | 58 | h->mb_aff_frame = h1->mb_aff_frame; | |
394 | 58 | h->droppable = h1->droppable; | |
395 | |||
396 |
2/2✓ Branch 0 taken 2088 times.
✓ Branch 1 taken 58 times.
|
2146 | for (i = 0; i < H264_MAX_PICTURE_COUNT; i++) { |
397 | 2088 | ret = ff_h264_replace_picture(&h->DPB[i], &h1->DPB[i]); | |
398 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2088 times.
|
2088 | if (ret < 0) |
399 | ✗ | return ret; | |
400 | } | ||
401 | |||
402 |
4/6✓ Branch 0 taken 42 times.
✓ Branch 1 taken 16 times.
✓ Branch 2 taken 42 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 42 times.
✗ Branch 5 not taken.
|
58 | h->cur_pic_ptr = REBASE_PICTURE(h1->cur_pic_ptr, h, h1); |
403 | 58 | ret = ff_h264_replace_picture(&h->cur_pic, &h1->cur_pic); | |
404 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (ret < 0) |
405 | ✗ | return ret; | |
406 | |||
407 | 58 | h->enable_er = h1->enable_er; | |
408 | 58 | h->workaround_bugs = h1->workaround_bugs; | |
409 | 58 | h->droppable = h1->droppable; | |
410 | |||
411 | // extradata/NAL handling | ||
412 | 58 | h->is_avc = h1->is_avc; | |
413 | 58 | h->nal_length_size = h1->nal_length_size; | |
414 | |||
415 | 58 | memcpy(&h->poc, &h1->poc, sizeof(h->poc)); | |
416 | |||
417 | 58 | memcpy(h->short_ref, h1->short_ref, sizeof(h->short_ref)); | |
418 | 58 | memcpy(h->long_ref, h1->long_ref, sizeof(h->long_ref)); | |
419 | 58 | memcpy(h->delayed_pic, h1->delayed_pic, sizeof(h->delayed_pic)); | |
420 | 58 | memcpy(h->last_pocs, h1->last_pocs, sizeof(h->last_pocs)); | |
421 | |||
422 | 58 | h->next_output_pic = h1->next_output_pic; | |
423 | 58 | h->next_outputed_poc = h1->next_outputed_poc; | |
424 | 58 | h->poc_offset = h1->poc_offset; | |
425 | |||
426 | 58 | memcpy(h->mmco, h1->mmco, sizeof(h->mmco)); | |
427 | 58 | h->nb_mmco = h1->nb_mmco; | |
428 | 58 | h->mmco_reset = h1->mmco_reset; | |
429 | 58 | h->explicit_ref_marking = h1->explicit_ref_marking; | |
430 | 58 | h->long_ref_count = h1->long_ref_count; | |
431 | 58 | h->short_ref_count = h1->short_ref_count; | |
432 | |||
433 | 58 | copy_picture_range(h->short_ref, h1->short_ref, 32, h, h1); | |
434 | 58 | copy_picture_range(h->long_ref, h1->long_ref, 32, h, h1); | |
435 | 58 | copy_picture_range(h->delayed_pic, h1->delayed_pic, | |
436 | FF_ARRAY_ELEMS(h->delayed_pic), h, h1); | ||
437 | |||
438 | 58 | h->frame_recovered = h1->frame_recovered; | |
439 | |||
440 | 58 | ret = ff_h264_sei_ctx_replace(&h->sei, &h1->sei); | |
441 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 58 times.
|
58 | if (ret < 0) |
442 | ✗ | return ret; | |
443 | |||
444 | 58 | h->sei.common.unregistered.x264_build = h1->sei.common.unregistered.x264_build; | |
445 | 58 | h->sei.common.mastering_display = h1->sei.common.mastering_display; | |
446 | 58 | h->sei.common.content_light = h1->sei.common.content_light; | |
447 | |||
448 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 42 times.
|
58 | if (!h->cur_pic_ptr) |
449 | 16 | 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 | 46 | int ff_h264_update_thread_context_for_user(AVCodecContext *dst, | |
466 | const AVCodecContext *src) | ||
467 | { | ||
468 | 46 | H264Context *h = dst->priv_data; | |
469 | 46 | const H264Context *h1 = src->priv_data; | |
470 | |||
471 | 46 | h->is_avc = h1->is_avc; | |
472 | 46 | h->nal_length_size = h1->nal_length_size; | |
473 | |||
474 | 46 | return 0; | |
475 | } | ||
476 | |||
477 | 25611 | static int h264_frame_start(H264Context *h) | |
478 | { | ||
479 | H264Picture *pic; | ||
480 | int i, ret; | ||
481 | 25611 | const int pixel_shift = h->pixel_shift; | |
482 | |||
483 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25611 times.
|
25611 | 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 | 25611 | release_unused_pictures(h, 1); | |
489 | 25611 | h->cur_pic_ptr = NULL; | |
490 | |||
491 | 25611 | i = find_unused_picture(h); | |
492 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 25611 times.
|
25611 | if (i < 0) { |
493 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "no frame buffer available\n"); | |
494 | ✗ | return i; | |
495 | } | ||
496 | 25611 | pic = &h->DPB[i]; | |
497 | |||
498 |
2/2✓ Branch 0 taken 17667 times.
✓ Branch 1 taken 7944 times.
|
25611 | pic->reference = h->droppable ? 0 : h->picture_structure; |
499 | 25611 | pic->field_picture = h->picture_structure != PICT_FRAME; | |
500 | 25611 | 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 | 25611 | pic->f->flags &= ~AV_FRAME_FLAG_KEY; | |
507 | 25611 | pic->mmco_reset = 0; | |
508 | 25611 | pic->recovered = 0; | |
509 | 25611 | pic->invalid_gap = 0; | |
510 | 25611 | pic->sei_recovery_frame_cnt = h->sei.recovery_point.recovery_frame_cnt; | |
511 | |||
512 | 25611 | pic->f->pict_type = h->slice_ctx[0].slice_type; | |
513 | |||
514 | 25611 | pic->f->crop_left = h->crop_left; | |
515 | 25611 | pic->f->crop_right = h->crop_right; | |
516 | 25611 | pic->f->crop_top = h->crop_top; | |
517 | 25611 | pic->f->crop_bottom = h->crop_bottom; | |
518 | |||
519 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 25611 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
25611 | 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 25611 times.
|
25611 | if ((ret = alloc_picture(h, pic)) < 0) |
523 | ✗ | return ret; | |
524 | |||
525 | 25611 | h->cur_pic_ptr = pic; | |
526 | 25611 | ff_h264_unref_picture(&h->cur_pic); | |
527 | if (CONFIG_ERROR_RESILIENCE) { | ||
528 | 25611 | ff_h264_set_erpic(&h->er.cur_pic, NULL); | |
529 | } | ||
530 | |||
531 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 25611 times.
|
25611 | if ((ret = ff_h264_ref_picture(&h->cur_pic, h->cur_pic_ptr)) < 0) |
532 | ✗ | return ret; | |
533 | |||
534 |
2/2✓ Branch 0 taken 25911 times.
✓ Branch 1 taken 25611 times.
|
51522 | for (i = 0; i < h->nb_slice_ctx; i++) { |
535 | 25911 | h->slice_ctx[i].linesize = h->cur_pic_ptr->f->linesize[0]; | |
536 | 25911 | h->slice_ctx[i].uvlinesize = h->cur_pic_ptr->f->linesize[1]; | |
537 | } | ||
538 | |||
539 |
2/2✓ Branch 0 taken 25311 times.
✓ Branch 1 taken 300 times.
|
25611 | if (CONFIG_ERROR_RESILIENCE && h->enable_er) { |
540 | 25311 | ff_er_frame_start(&h->er); | |
541 | 25311 | ff_h264_set_erpic(&h->er.last_pic, NULL); | |
542 | 25311 | ff_h264_set_erpic(&h->er.next_pic, NULL); | |
543 | } | ||
544 | |||
545 |
2/2✓ Branch 0 taken 409776 times.
✓ Branch 1 taken 25611 times.
|
435387 | for (i = 0; i < 16; i++) { |
546 | 409776 | h->block_offset[i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * pic->f->linesize[0] * ((scan8[i] - scan8[0]) >> 3); | |
547 | 409776 | 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 409776 times.
✓ Branch 1 taken 25611 times.
|
435387 | for (i = 0; i < 16; i++) { |
550 | 409776 | h->block_offset[16 + i] = | |
551 | 409776 | h->block_offset[32 + i] = (4 * ((scan8[i] - scan8[0]) & 7) << pixel_shift) + 4 * pic->f->linesize[1] * ((scan8[i] - scan8[0]) >> 3); | |
552 | 409776 | h->block_offset[48 + 16 + i] = | |
553 | 409776 | 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 | 25611 | h->cur_pic_ptr->reference = 0; | |
561 | |||
562 | 25611 | h->cur_pic_ptr->field_poc[0] = h->cur_pic_ptr->field_poc[1] = INT_MAX; | |
563 | |||
564 | 25611 | h->next_output_pic = NULL; | |
565 | |||
566 | 25611 | h->postpone_filter = 0; | |
567 | |||
568 |
4/4✓ Branch 0 taken 2862 times.
✓ Branch 1 taken 22749 times.
✓ Branch 2 taken 2354 times.
✓ Branch 3 taken 508 times.
|
25611 | 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 23548 times.
|
25611 | 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 | 25611 | return 0; | |
576 | } | ||
577 | |||
578 | 12577276 | 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 | 12577276 | int top_idx = 1; | |
586 | 12577276 | const int pixel_shift = h->pixel_shift; | |
587 | 12577276 | int chroma444 = CHROMA444(h); | |
588 | 12577276 | int chroma422 = CHROMA422(h); | |
589 | |||
590 | 12577276 | src_y -= linesize; | |
591 | 12577276 | src_cb -= uvlinesize; | |
592 | 12577276 | src_cr -= uvlinesize; | |
593 | |||
594 |
3/4✓ Branch 0 taken 12577276 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2021856 times.
✓ Branch 3 taken 10555420 times.
|
12577276 | 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 | 11829606 | 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 | 11829606 | AV_COPY128(top_border, src_y + 16 * linesize); | |
641 |
2/2✓ Branch 0 taken 1381381 times.
✓ Branch 1 taken 10448225 times.
|
11829606 | 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 11749278 times.
|
11829606 | 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 11160643 times.
|
11749278 | } 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 10383737 times.
|
11160643 | 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 | 10383737 | AV_COPY64(top_border + 16, src_cb + 8 * uvlinesize); | |
669 | 10383737 | 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 | 3840 | 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 7680 times.
✓ Branch 1 taken 3840 times.
|
11520 | for (i = 0; i < 2; i++) { |
685 | 7680 | sl->pwt.luma_weight_flag[i] = 0; | |
686 | 7680 | sl->pwt.chroma_weight_flag[i] = 0; | |
687 | } | ||
688 | |||
689 |
2/2✓ Branch 0 taken 2128 times.
✓ Branch 1 taken 1712 times.
|
3840 | if (field < 0) { |
690 |
1/2✓ Branch 0 taken 2128 times.
✗ Branch 1 not taken.
|
2128 | if (h->picture_structure == PICT_FRAME) { |
691 | 2128 | 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 952 times.
✓ Branch 1 taken 1176 times.
✓ Branch 2 taken 642 times.
✓ Branch 3 taken 310 times.
✓ Branch 4 taken 632 times.
✓ Branch 5 taken 10 times.
|
2128 | 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 216 times.
|
632 | 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 | 1712 | ref_start = 0; | |
702 | 1712 | ref_count0 = sl->ref_count[0]; | |
703 | 1712 | 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 | 3424 | sl->pwt.use_weight = 2; | |
712 | 3424 | sl->pwt.use_weight_chroma = 2; | |
713 | 3424 | sl->pwt.luma_log2_weight_denom = 5; | |
714 | 3424 | sl->pwt.chroma_log2_weight_denom = 5; | |
715 | |||
716 |
2/2✓ Branch 0 taken 11794 times.
✓ Branch 1 taken 3424 times.
|
15218 | for (ref0 = ref_start; ref0 < ref_count0; ref0++) { |
717 | 11794 | int64_t poc0 = sl->ref_list[0][ref0].poc; | |
718 |
2/2✓ Branch 0 taken 21895 times.
✓ Branch 1 taken 11794 times.
|
33689 | for (ref1 = ref_start; ref1 < ref_count1; ref1++) { |
719 | 21895 | int w = 32; | |
720 |
2/4✓ Branch 0 taken 21895 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 21895 times.
✗ Branch 3 not taken.
|
21895 | if (!sl->ref_list[0][ref0].parent->long_ref && !sl->ref_list[1][ref1].parent->long_ref) { |
721 | 21895 | int poc1 = sl->ref_list[1][ref1].poc; | |
722 | 21895 | int td = av_clip_int8(poc1 - poc0); | |
723 |
2/2✓ Branch 0 taken 21828 times.
✓ Branch 1 taken 67 times.
|
21895 | if (td) { |
724 | 21828 | int tb = av_clip_int8(cur_poc - poc0); | |
725 | 21828 | int tx = (16384 + (FFABS(td) >> 1)) / td; | |
726 | 21828 | int dist_scale_factor = (tb * tx + 32) >> 8; | |
727 |
3/4✓ Branch 0 taken 21818 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 21818 times.
✗ Branch 3 not taken.
|
21828 | if (dist_scale_factor >= -64 && dist_scale_factor <= 128) |
728 | 21818 | w = 64 - dist_scale_factor; | |
729 | } | ||
730 | } | ||
731 |
2/2✓ Branch 0 taken 5991 times.
✓ Branch 1 taken 15904 times.
|
21895 | if (field < 0) { |
732 | 5991 | sl->pwt.implicit_weight[ref0][ref1][0] = | |
733 | 5991 | 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 | 28547 | 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 | 28547 | 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 28020 times.
✗ Branch 5 not taken.
|
28547 | 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 | 28020 | case 8: | |
853 | #if CONFIG_H264_VDPAU_HWACCEL | ||
854 | 28020 | *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 27536 times.
|
28020 | 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 27514 times.
|
27536 | } 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 | 27514 | *fmt++ = AV_PIX_FMT_VAAPI; | |
891 | #endif | ||
892 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 27511 times.
|
27514 | if (h->avctx->color_range == AVCOL_RANGE_JPEG) |
893 | 3 | *fmt++ = AV_PIX_FMT_YUVJ420P; | |
894 | else | ||
895 | 27511 | *fmt++ = AV_PIX_FMT_YUV420P; | |
896 | } | ||
897 | 28020 | 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 | 28547 | *fmt = AV_PIX_FMT_NONE; | |
905 | |||
906 |
2/2✓ Branch 0 taken 84238 times.
✓ Branch 1 taken 588 times.
|
84826 | for (int i = 0; pix_fmts[i] != AV_PIX_FMT_NONE; i++) |
907 |
4/4✓ Branch 0 taken 28215 times.
✓ Branch 1 taken 56023 times.
✓ Branch 2 taken 27959 times.
✓ Branch 3 taken 256 times.
|
84238 | if (pix_fmts[i] == h->avctx->pix_fmt && !force_callback) |
908 | 27959 | 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 | 28288 | static void init_dimensions(H264Context *h) | |
914 | { | ||
915 | 28288 | const SPS *sps = h->ps.sps; | |
916 | 28288 | int cr = sps->crop_right; | |
917 | 28288 | int cl = sps->crop_left; | |
918 | 28288 | int ct = sps->crop_top; | |
919 | 28288 | int cb = sps->crop_bottom; | |
920 | 28288 | int width = h->width - (cr + cl); | |
921 | 28288 | int height = h->height - (ct + cb); | |
922 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28288 times.
|
28288 | av_assert0(sps->crop_right + sps->crop_left < (unsigned)h->width); |
923 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28288 times.
|
28288 | av_assert0(sps->crop_top + sps->crop_bottom < (unsigned)h->height); |
924 | |||
925 | /* handle container cropping */ | ||
926 |
3/4✓ Branch 0 taken 26047 times.
✓ Branch 1 taken 2241 times.
✓ Branch 2 taken 26047 times.
✗ Branch 3 not taken.
|
28288 | if (h->width_from_caller > 0 && h->height_from_caller > 0 && |
927 |
3/4✓ Branch 0 taken 26046 times.
✓ Branch 1 taken 1 times.
✓ Branch 2 taken 26046 times.
✗ Branch 3 not taken.
|
26047 | !sps->crop_top && !sps->crop_left && |
928 |
2/2✓ Branch 0 taken 26037 times.
✓ Branch 1 taken 9 times.
|
26046 | FFALIGN(h->width_from_caller, 16) == FFALIGN(width, 16) && |
929 |
1/2✓ Branch 0 taken 26037 times.
✗ Branch 1 not taken.
|
26037 | FFALIGN(h->height_from_caller, 16) == FFALIGN(height, 16) && |
930 |
2/2✓ Branch 0 taken 26036 times.
✓ Branch 1 taken 1 times.
|
26037 | h->width_from_caller <= width && |
931 |
2/2✓ Branch 0 taken 26034 times.
✓ Branch 1 taken 2 times.
|
26036 | h->height_from_caller <= height) { |
932 | 26034 | width = h->width_from_caller; | |
933 | 26034 | height = h->height_from_caller; | |
934 | 26034 | cl = 0; | |
935 | 26034 | ct = 0; | |
936 | 26034 | cr = h->width - width; | |
937 | 26034 | cb = h->height - height; | |
938 | } else { | ||
939 | 2254 | h->width_from_caller = 0; | |
940 | 2254 | h->height_from_caller = 0; | |
941 | } | ||
942 | |||
943 | 28288 | h->avctx->coded_width = h->width; | |
944 | 28288 | h->avctx->coded_height = h->height; | |
945 | 28288 | h->avctx->width = width; | |
946 | 28288 | h->avctx->height = height; | |
947 | 28288 | h->crop_right = cr; | |
948 | 28288 | h->crop_left = cl; | |
949 | 28288 | h->crop_top = ct; | |
950 | 28288 | h->crop_bottom = cb; | |
951 | 28288 | } | |
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 | 55924 | 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 55922 times.
|
55924 | 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 | 55922 | default: | |
1042 | 55922 | return a; | |
1043 | } | ||
1044 | } | ||
1045 | |||
1046 | 28288 | static int h264_init_ps(H264Context *h, const H264SliceContext *sl, int first_slice) | |
1047 | { | ||
1048 | const SPS *sps; | ||
1049 | 28288 | int needs_reinit = 0, must_reinit, ret; | |
1050 | |||
1051 |
2/2✓ Branch 0 taken 28094 times.
✓ Branch 1 taken 194 times.
|
28288 | if (first_slice) |
1052 | 28094 | 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 27701 times.
|
28288 | 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 | 28288 | sps = h->ps.sps; | |
1069 | |||
1070 |
2/2✓ Branch 0 taken 27711 times.
✓ Branch 1 taken 577 times.
|
55999 | must_reinit = (h->context_initialized && |
1071 |
2/2✓ Branch 0 taken 27705 times.
✓ Branch 1 taken 6 times.
|
27711 | ( 16*sps->mb_width != h->avctx->coded_width |
1072 |
1/2✓ Branch 0 taken 27705 times.
✗ Branch 1 not taken.
|
27705 | || 16*sps->mb_height != h->avctx->coded_height |
1073 |
2/2✓ Branch 0 taken 27704 times.
✓ Branch 1 taken 1 times.
|
27705 | || h->cur_bit_depth_luma != sps->bit_depth_luma |
1074 |
2/2✓ Branch 0 taken 27703 times.
✓ Branch 1 taken 1 times.
|
27704 | || h->cur_chroma_format_idc != sps->chroma_format_idc |
1075 |
1/2✓ Branch 0 taken 27703 times.
✗ Branch 1 not taken.
|
27703 | || h->mb_width != sps->mb_width |
1076 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 27703 times.
|
27703 | || h->mb_height != sps->mb_height |
1077 | )); | ||
1078 |
2/2✓ Branch 0 taken 27962 times.
✓ Branch 1 taken 326 times.
|
28288 | if (h->avctx->pix_fmt == AV_PIX_FMT_NONE |
1079 |
2/2✓ Branch 3 taken 3 times.
✓ Branch 4 taken 27959 times.
|
27962 | || (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 28094 times.
✓ Branch 1 taken 194 times.
✓ Branch 3 taken 71 times.
✓ Branch 4 taken 28023 times.
|
28288 | 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 28288 times.
✗ Branch 1 not taken.
|
28288 | if (!h->setup_finished) { |
1086 | 28288 | h->avctx->profile = ff_h264_get_profile(sps); | |
1087 | 28288 | h->avctx->level = sps->level_idc; | |
1088 | 28288 | h->avctx->refs = sps->ref_frame_count; | |
1089 | |||
1090 | 28288 | h->mb_width = sps->mb_width; | |
1091 | 28288 | h->mb_height = sps->mb_height; | |
1092 | 28288 | h->mb_num = h->mb_width * h->mb_height; | |
1093 | 28288 | h->mb_stride = h->mb_width + 1; | |
1094 | |||
1095 | 28288 | h->b_stride = h->mb_width * 4; | |
1096 | |||
1097 | 28288 | h->chroma_y_shift = sps->chroma_format_idc <= 1; // 400 uses yuv420p | |
1098 | |||
1099 | 28288 | h->width = 16 * h->mb_width; | |
1100 | 28288 | h->height = 16 * h->mb_height; | |
1101 | |||
1102 | 28288 | init_dimensions(h); | |
1103 | |||
1104 |
2/2✓ Branch 0 taken 1287 times.
✓ Branch 1 taken 27001 times.
|
28288 | 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 28288 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
28288 | 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 | 28288 | h->avctx->chroma_sample_location = sps->vui.chroma_location; | |
1123 | |||
1124 |
5/6✓ Branch 0 taken 27711 times.
✓ Branch 1 taken 577 times.
✓ Branch 2 taken 27703 times.
✓ Branch 3 taken 8 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 27703 times.
|
28288 | 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 | 28288 | return 0; | |
1157 | } | ||
1158 | |||
1159 | 24921 | static int h264_export_frame_props(H264Context *h) | |
1160 | { | ||
1161 | 24921 | const SPS *sps = h->ps.sps; | |
1162 | 24921 | H264Picture *cur = h->cur_pic_ptr; | |
1163 | 24921 | AVFrame *out = cur->f; | |
1164 | 24921 | int interlaced_frame = 0, top_field_first = 0; | |
1165 | int ret; | ||
1166 | |||
1167 | 24921 | out->flags &= ~AV_FRAME_FLAG_INTERLACED; | |
1168 | 24921 | 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 23494 times.
|
24921 | 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 23416 times.
✓ Branch 2 taken 1419 times.
✓ Branch 3 taken 86 times.
|
26340 | 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 21915 times.
✓ Branch 1 taken 1587 times.
✓ Branch 2 taken 2821 times.
✓ Branch 3 taken 19094 times.
|
23502 | interlaced_frame = !!FIELD_OR_MBAFF_PICTURE(h); |
1222 | } | ||
1223 | 24921 | h->prev_interlaced_frame = interlaced_frame; | |
1224 | |||
1225 |
2/2✓ Branch 0 taken 3337 times.
✓ Branch 1 taken 21584 times.
|
24921 | 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 21359 times.
✓ Branch 2 taken 139 times.
✓ Branch 3 taken 86 times.
|
21584 | 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 18891 times.
|
21445 | } 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 | 24921 | out->flags |= (AV_FRAME_FLAG_INTERLACED * interlaced_frame) | | |
1244 | 24921 | (AV_FRAME_FLAG_TOP_FIELD_FIRST * top_field_first); | |
1245 | |||
1246 | 24921 | ret = ff_h2645_sei_to_frame(out, &h->sei.common, AV_CODEC_ID_H264, h->avctx, | |
1247 | 24921 | &sps->vui, sps->bit_depth_luma, sps->bit_depth_chroma, | |
1248 | 24921 | cur->poc + (unsigned)(h->poc_offset << 5)); | |
1249 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24921 times.
|
24921 | if (ret < 0) |
1250 | ✗ | return ret; | |
1251 | |||
1252 |
2/2✓ Branch 0 taken 652 times.
✓ Branch 1 taken 24269 times.
|
24921 | 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 | 24921 | return 0; | |
1281 | } | ||
1282 | |||
1283 | 24921 | static int h264_select_output_frame(H264Context *h) | |
1284 | { | ||
1285 | 24921 | const SPS *sps = h->ps.sps; | |
1286 | 24921 | H264Picture *out = h->cur_pic_ptr; | |
1287 | 24921 | H264Picture *cur = h->cur_pic_ptr; | |
1288 | int i, pics, out_of_order, out_idx; | ||
1289 | |||
1290 | 24921 | cur->mmco_reset = h->mmco_reset; | |
1291 | 24921 | h->mmco_reset = 0; | |
1292 | |||
1293 |
2/2✓ Branch 0 taken 20019 times.
✓ Branch 1 taken 4902 times.
|
24921 | 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 | 4902 | h->avctx->has_b_frames = FFMAX(h->avctx->has_b_frames, sps->num_reorder_frames); | |
1296 | } | ||
1297 | |||
1298 | 408659 | for (i = 0; 1; i++) { | |
1299 |
4/4✓ Branch 0 taken 392745 times.
✓ Branch 1 taken 15914 times.
✓ Branch 2 taken 9007 times.
✓ Branch 3 taken 383738 times.
|
408659 | if(i == H264_MAX_DPB_FRAMES || cur->poc < h->last_pocs[i]){ |
1300 |
1/2✓ Branch 0 taken 24921 times.
✗ Branch 1 not taken.
|
24921 | if(i) |
1301 | 24921 | h->last_pocs[i-1] = cur->poc; | |
1302 | 24921 | break; | |
1303 |
2/2✓ Branch 0 taken 358817 times.
✓ Branch 1 taken 24921 times.
|
383738 | } else if(i) { |
1304 | 358817 | h->last_pocs[i-1]= h->last_pocs[i]; | |
1305 | } | ||
1306 | } | ||
1307 | 24921 | out_of_order = H264_MAX_DPB_FRAMES - i; | |
1308 |
2/2✓ Branch 0 taken 16798 times.
✓ Branch 1 taken 8123 times.
|
24921 | if( cur->f->pict_type == AV_PICTURE_TYPE_B |
1309 |
4/4✓ Branch 0 taken 15677 times.
✓ Branch 1 taken 1121 times.
✓ Branch 2 taken 5062 times.
✓ Branch 3 taken 10615 times.
|
16798 | || (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 | 13185 | out_of_order = FFMAX(out_of_order, 1); | |
1311 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24921 times.
|
24921 | 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 24781 times.
✓ Branch 2 taken 140 times.
✗ Branch 3 not taken.
|
24921 | } 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 | 24921 | pics = 0; | |
1324 |
2/2✓ Branch 0 taken 30538 times.
✓ Branch 1 taken 24921 times.
|
55459 | while (h->delayed_pic[pics]) |
1325 | 30538 | pics++; | |
1326 | |||
1327 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24921 times.
|
24921 | av_assert0(pics <= H264_MAX_DPB_FRAMES); |
1328 | |||
1329 | 24921 | h->delayed_pic[pics++] = cur; | |
1330 |
2/2✓ Branch 0 taken 23446 times.
✓ Branch 1 taken 1475 times.
|
24921 | if (cur->reference == 0) |
1331 | 23446 | cur->reference = DELAYED_PIC_REF; | |
1332 | |||
1333 | 24921 | out = h->delayed_pic[0]; | |
1334 | 24921 | out_idx = 0; | |
1335 | 24921 | for (i = 1; h->delayed_pic[i] && | |
1336 |
4/4✓ Branch 0 taken 28087 times.
✓ Branch 1 taken 24454 times.
✓ Branch 2 taken 27707 times.
✓ Branch 3 taken 380 times.
|
52541 | !(h->delayed_pic[i]->f->flags & AV_FRAME_FLAG_KEY) && |
1337 |
2/2✓ Branch 0 taken 27620 times.
✓ Branch 1 taken 87 times.
|
27707 | !h->delayed_pic[i]->mmco_reset; |
1338 | 27620 | i++) | |
1339 |
2/2✓ Branch 0 taken 10306 times.
✓ Branch 1 taken 17314 times.
|
27620 | if (h->delayed_pic[i]->poc < out->poc) { |
1340 | 10306 | out = h->delayed_pic[i]; | |
1341 | 10306 | out_idx = i; | |
1342 | } | ||
1343 |
2/2✓ Branch 0 taken 10258 times.
✓ Branch 1 taken 14663 times.
|
24921 | 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 | 24921 | out_of_order = out->poc < h->next_outputed_poc; | |
1347 | |||
1348 |
4/4✓ Branch 0 taken 24808 times.
✓ Branch 1 taken 113 times.
✓ Branch 2 taken 24283 times.
✓ Branch 3 taken 525 times.
|
24921 | if (out_of_order || pics > h->avctx->has_b_frames) { |
1349 | 24396 | out->reference &= ~DELAYED_PIC_REF; | |
1350 |
2/2✓ Branch 0 taken 39541 times.
✓ Branch 1 taken 24396 times.
|
63937 | for (i = out_idx; h->delayed_pic[i]; i++) |
1351 | 39541 | h->delayed_pic[i] = h->delayed_pic[i + 1]; | |
1352 | } | ||
1353 |
4/4✓ Branch 0 taken 24808 times.
✓ Branch 1 taken 113 times.
✓ Branch 2 taken 24283 times.
✓ Branch 3 taken 525 times.
|
24921 | if (!out_of_order && pics > h->avctx->has_b_frames) { |
1354 | 24283 | h->next_output_pic = out; | |
1355 |
8/8✓ Branch 0 taken 15497 times.
✓ Branch 1 taken 8786 times.
✓ Branch 2 taken 5240 times.
✓ Branch 3 taken 10257 times.
✓ Branch 4 taken 5156 times.
✓ Branch 5 taken 84 times.
✓ Branch 6 taken 21 times.
✓ Branch 7 taken 5135 times.
|
24283 | 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 | 24178 | 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 | 24283 | h->frame_recovered |= out->recovered; | |
1363 | |||
1364 | 24283 | out->recovered |= h->frame_recovered & FRAME_RECOVERED_SEI; | |
1365 | |||
1366 |
2/2✓ Branch 0 taken 249 times.
✓ Branch 1 taken 24034 times.
|
24283 | 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 | 24921 | 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 | 28288 | 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 | 28288 | ret = h264_init_ps(h, sl, first_slice); | |
1394 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28288 times.
|
28288 | if (ret < 0) |
1395 | ✗ | return ret; | |
1396 | |||
1397 | 28288 | sps = h->ps.sps; | |
1398 | |||
1399 |
2/2✓ Branch 0 taken 5235 times.
✓ Branch 1 taken 23053 times.
|
28288 | if (sps->bitstream_restriction_flag && |
1400 |
2/2✓ Branch 0 taken 29 times.
✓ Branch 1 taken 5206 times.
|
5235 | h->avctx->has_b_frames < sps->num_reorder_frames) { |
1401 | 29 | h->avctx->has_b_frames = sps->num_reorder_frames; | |
1402 | } | ||
1403 | |||
1404 | 28288 | last_pic_droppable = h->droppable; | |
1405 | 28288 | last_pic_structure = h->picture_structure; | |
1406 | 28288 | h->droppable = (nal->ref_idc == 0); | |
1407 | 28288 | h->picture_structure = sl->picture_structure; | |
1408 | |||
1409 | 28288 | h->poc.frame_num = sl->frame_num; | |
1410 | 28288 | h->poc.poc_lsb = sl->poc_lsb; | |
1411 | 28288 | h->poc.delta_poc_bottom = sl->delta_poc_bottom; | |
1412 | 28288 | h->poc.delta_poc[0] = sl->delta_poc[0]; | |
1413 | 28288 | h->poc.delta_poc[1] = sl->delta_poc[1]; | |
1414 | |||
1415 |
2/2✓ Branch 0 taken 1077 times.
✓ Branch 1 taken 27211 times.
|
28288 | 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 27211 times.
|
27211 | 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 12142 times.
|
28288 | 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 24926 times.
|
28288 | 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 12142 times.
✓ Branch 2 taken 16831 times.
✗ Branch 3 not taken.
|
57261 | 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 24926 times.
|
28288 | 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 | 24926 | h->first_field = FIELD_PICTURE(h); | |
1600 | } | ||
1601 | |||
1602 |
4/4✓ Branch 0 taken 6729 times.
✓ Branch 1 taken 21559 times.
✓ Branch 2 taken 3367 times.
✓ Branch 3 taken 3362 times.
|
28288 | if (!FIELD_PICTURE(h) || h->first_field) { |
1603 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 24926 times.
|
24926 | 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 21559 times.
|
28288 | 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 | 21559 | memset(h->slice_table, -1, | |
1619 | 21559 | (h->mb_height * h->mb_stride - 1) * sizeof(*h->slice_table)); | |
1620 | } | ||
1621 | |||
1622 | 28288 | ret = ff_h264_init_poc(h->cur_pic_ptr->field_poc, &h->cur_pic_ptr->poc, | |
1623 | 28288 | h->ps.sps, &h->poc, h->picture_structure, nal->ref_idc); | |
1624 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28288 times.
|
28288 | if (ret < 0) |
1625 | ✗ | return ret; | |
1626 | |||
1627 | 28288 | memcpy(h->mmco, sl->mmco, sl->nb_mmco * sizeof(*h->mmco)); | |
1628 | 28288 | h->nb_mmco = sl->nb_mmco; | |
1629 | 28288 | h->explicit_ref_marking = sl->explicit_ref_marking; | |
1630 | |||
1631 | 28288 | h->picture_idr = nal->type == H264_NAL_IDR_SLICE; | |
1632 | |||
1633 |
2/2✓ Branch 0 taken 90 times.
✓ Branch 1 taken 28198 times.
|
28288 | 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 27211 times.
|
28288 | 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 27211 times.
|
28288 | 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 28189 times.
✓ Branch 2 taken 85 times.
✓ Branch 3 taken 14 times.
|
28288 | 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 | 28288 | 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 21559 times.
✓ Branch 2 taken 3367 times.
✓ Branch 3 taken 3362 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 3367 times.
|
28288 | if (!FIELD_PICTURE(h) || !h->first_field || h->missing_fields > 1) { |
1672 | 24921 | ret = h264_export_frame_props(h); | |
1673 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24921 times.
|
24921 | if (ret < 0) |
1674 | ✗ | return ret; | |
1675 | |||
1676 | 24921 | ret = h264_select_output_frame(h); | |
1677 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24921 times.
|
24921 | if (ret < 0) |
1678 | ✗ | return ret; | |
1679 | } | ||
1680 | |||
1681 | 28288 | return 0; | |
1682 | } | ||
1683 | |||
1684 | 37608 | 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 37158 times.
✓ Branch 1 taken 450 times.
✓ Branch 2 taken 28337 times.
✓ Branch 3 taken 8821 times.
|
37608 | int first_slice = sl == h->slice_ctx && !h->current_slice; |
1693 | int picture_structure; | ||
1694 | |||
1695 |
2/2✓ Branch 0 taken 28337 times.
✓ Branch 1 taken 9271 times.
|
37608 | if (first_slice) |
1696 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28337 times.
|
28337 | av_assert0(!h->setup_finished); |
1697 | |||
1698 | 37608 | sl->first_mb_addr = get_ue_golomb_long(&sl->gb); | |
1699 | |||
1700 | 37608 | slice_type = get_ue_golomb_31(&sl->gb); | |
1701 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37608 times.
|
37608 | 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 23884 times.
✓ Branch 1 taken 13724 times.
|
37608 | if (slice_type > 4) { |
1708 | 23884 | slice_type -= 5; | |
1709 | 23884 | sl->slice_type_fixed = 1; | |
1710 | } else | ||
1711 | 13724 | sl->slice_type_fixed = 0; | |
1712 | |||
1713 | 37608 | slice_type = ff_h264_golomb_to_pict_type[slice_type]; | |
1714 | 37608 | sl->slice_type = slice_type; | |
1715 | 37608 | sl->slice_type_nos = slice_type & 3; | |
1716 | |||
1717 |
2/2✓ Branch 0 taken 2263 times.
✓ Branch 1 taken 35345 times.
|
37608 | 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 | 37608 | sl->pps_id = get_ue_golomb(&sl->gb); | |
1724 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37608 times.
|
37608 | 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 37441 times.
|
37608 | 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 | 37441 | pps = h->ps.pps_list[sl->pps_id]; | |
1735 | 37441 | sps = pps->sps; | |
1736 | |||
1737 | 37441 | sl->frame_num = get_bits(&sl->gb, sps->log2_max_frame_num); | |
1738 |
2/2✓ Branch 0 taken 9267 times.
✓ Branch 1 taken 28174 times.
|
37441 | 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 | 37441 | sl->mb_mbaff = 0; | |
1747 | |||
1748 |
2/2✓ Branch 0 taken 22946 times.
✓ Branch 1 taken 14495 times.
|
37441 | if (sps->frame_mbs_only_flag) { |
1749 | 22946 | 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 | 37441 | sl->picture_structure = picture_structure; | |
1764 | 37441 | sl->mb_field_decoding_flag = picture_structure != PICT_FRAME; | |
1765 | |||
1766 |
2/2✓ Branch 0 taken 28415 times.
✓ Branch 1 taken 9026 times.
|
37441 | if (picture_structure == PICT_FRAME) { |
1767 | 28415 | sl->curr_pic_num = sl->frame_num; | |
1768 | 28415 | 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 35183 times.
|
37441 | 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 | 37441 | sl->poc_lsb = 0; | |
1783 | 37441 | sl->delta_poc_bottom = 0; | |
1784 |
2/2✓ Branch 0 taken 29661 times.
✓ Branch 1 taken 7780 times.
|
37441 | if (sps->poc_type == 0) { |
1785 | 29661 | sl->poc_lsb = get_bits(&sl->gb, sps->log2_max_poc_lsb); | |
1786 | |||
1787 |
4/4✓ Branch 0 taken 8524 times.
✓ Branch 1 taken 21137 times.
✓ Branch 2 taken 6632 times.
✓ Branch 3 taken 1892 times.
|
29661 | if (pps->pic_order_present == 1 && picture_structure == PICT_FRAME) |
1788 | 6632 | sl->delta_poc_bottom = get_se_golomb(&sl->gb); | |
1789 | } | ||
1790 | |||
1791 | 37441 | sl->delta_poc[0] = sl->delta_poc[1] = 0; | |
1792 |
4/4✓ Branch 0 taken 3055 times.
✓ Branch 1 taken 34386 times.
✓ Branch 2 taken 2848 times.
✓ Branch 3 taken 207 times.
|
37441 | 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 | 37441 | sl->redundant_pic_count = 0; | |
1800 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37441 times.
|
37441 | if (pps->redundant_pic_cnt_present) |
1801 | ✗ | sl->redundant_pic_count = get_ue_golomb(&sl->gb); | |
1802 | |||
1803 |
2/2✓ Branch 0 taken 13149 times.
✓ Branch 1 taken 24292 times.
|
37441 | if (sl->slice_type_nos == AV_PICTURE_TYPE_B) |
1804 | 13149 | sl->direct_spatial_mv_pred = get_bits1(&sl->gb); | |
1805 | |||
1806 | 37441 | ret = ff_h264_parse_ref_count(&sl->list_count, sl->ref_count, | |
1807 | &sl->gb, pps, sl->slice_type_nos, | ||
1808 | 37441 | picture_structure, h->avctx); | |
1809 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37441 times.
|
37441 | if (ret < 0) |
1810 | ✗ | return ret; | |
1811 | |||
1812 |
2/2✓ Branch 0 taken 32975 times.
✓ Branch 1 taken 4466 times.
|
37441 | if (sl->slice_type_nos != AV_PICTURE_TYPE_I) { |
1813 | 32975 | ret = ff_h264_decode_ref_pic_list_reordering(sl, h->avctx); | |
1814 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 32975 times.
|
32975 | if (ret < 0) { |
1815 | ✗ | sl->ref_count[1] = sl->ref_count[0] = 0; | |
1816 | ✗ | return ret; | |
1817 | } | ||
1818 | } | ||
1819 | |||
1820 | 37441 | sl->pwt.use_weight = 0; | |
1821 |
2/2✓ Branch 0 taken 74882 times.
✓ Branch 1 taken 37441 times.
|
112323 | for (i = 0; i < 2; i++) { |
1822 | 74882 | sl->pwt.luma_weight_flag[i] = 0; | |
1823 | 74882 | sl->pwt.chroma_weight_flag[i] = 0; | |
1824 | } | ||
1825 |
4/4✓ Branch 0 taken 4309 times.
✓ Branch 1 taken 33132 times.
✓ Branch 2 taken 1630 times.
✓ Branch 3 taken 2679 times.
|
37441 | if ((pps->weighted_pred && sl->slice_type_nos == AV_PICTURE_TYPE_P) || |
1826 |
2/2✓ Branch 0 taken 386 times.
✓ Branch 1 taken 34376 times.
|
34762 | (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 | 3065 | ret = ff_h264_pred_weight_table(&sl->gb, sps, sl->ref_count, | |
1829 | sl->slice_type_nos, &sl->pwt, | ||
1830 | 3065 | picture_structure, h->avctx); | |
1831 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3065 times.
|
3065 | if (ret < 0) |
1832 | ✗ | return ret; | |
1833 | } | ||
1834 | |||
1835 | 37441 | sl->explicit_ref_marking = 0; | |
1836 |
2/2✓ Branch 0 taken 24953 times.
✓ Branch 1 taken 12488 times.
|
37441 | if (nal->ref_idc) { |
1837 | 24953 | ret = ff_h264_decode_ref_pic_marking(sl, &sl->gb, nal, h->avctx); | |
1838 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 24953 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
24953 | if (ret < 0 && (h->avctx->err_recognition & AV_EF_EXPLODE)) |
1839 | ✗ | return AVERROR_INVALIDDATA; | |
1840 | } | ||
1841 | |||
1842 |
4/4✓ Branch 0 taken 32975 times.
✓ Branch 1 taken 4466 times.
✓ Branch 2 taken 18163 times.
✓ Branch 3 taken 14812 times.
|
37441 | if (sl->slice_type_nos != AV_PICTURE_TYPE_I && pps->cabac) { |
1843 | 18163 | tmp = get_ue_golomb_31(&sl->gb); | |
1844 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18163 times.
|
18163 | if (tmp > 2) { |
1845 | ✗ | av_log(h->avctx, AV_LOG_ERROR, "cabac_init_idc %u overflow\n", tmp); | |
1846 | ✗ | return AVERROR_INVALIDDATA; | |
1847 | } | ||
1848 | 18163 | sl->cabac_init_idc = tmp; | |
1849 | } | ||
1850 | |||
1851 | 37441 | sl->last_qscale_diff = 0; | |
1852 | 37441 | tmp = pps->init_qp + (unsigned)get_se_golomb(&sl->gb); | |
1853 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37441 times.
|
37441 | 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 | 37441 | sl->qscale = tmp; | |
1858 | 37441 | sl->chroma_qp[0] = get_chroma_qp(pps, 0, sl->qscale); | |
1859 | 37441 | 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 37441 times.
|
37441 | if (sl->slice_type == AV_PICTURE_TYPE_SP) |
1862 | ✗ | get_bits1(&sl->gb); /* sp_for_switch_flag */ | |
1863 |
1/2✓ Branch 0 taken 37441 times.
✗ Branch 1 not taken.
|
37441 | if (sl->slice_type == AV_PICTURE_TYPE_SP || |
1864 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 37441 times.
|
37441 | sl->slice_type == AV_PICTURE_TYPE_SI) |
1865 | ✗ | get_se_golomb(&sl->gb); /* slice_qs_delta */ | |
1866 | |||
1867 | 37441 | sl->deblocking_filter = 1; | |
1868 | 37441 | sl->slice_alpha_c0_offset = 0; | |
1869 | 37441 | sl->slice_beta_offset = 0; | |
1870 |
2/2✓ Branch 0 taken 22658 times.
✓ Branch 1 taken 14783 times.
|
37441 | if (pps->deblocking_filter_parameters_present) { |
1871 | 22658 | tmp = get_ue_golomb_31(&sl->gb); | |
1872 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 22658 times.
|
22658 | 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 |