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