FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vp56.c
Date: 2025-07-01 21:35:40
Exec Total Coverage
Lines: 497 532 93.4%
Functions: 20 20 100.0%
Branches: 272 307 88.6%

Line Branch Exec Source
1 /*
2 * Copyright (C) 2006 Aurelien Jacobs <aurel@gnuage.org>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /**
22 * @file
23 * VP5 and VP6 compatible video decoder (common features)
24 */
25
26 #include "libavutil/mem.h"
27 #include "avcodec.h"
28 #include "bytestream.h"
29 #include "decode.h"
30 #include "h264chroma.h"
31 #include "vp56.h"
32 #include "vp56data.h"
33 #include "vpx_rac.h"
34
35
36 1266 void ff_vp56_init_dequant(VP56Context *s, int quantizer)
37 {
38
2/2
✓ Branch 0 taken 410 times.
✓ Branch 1 taken 856 times.
1266 if (s->quantizer != quantizer)
39 410 ff_vp3dsp_set_bounding_values(s->bounding_values_array, ff_vp56_filter_threshold[quantizer]);
40 1266 s->quantizer = quantizer;
41 1266 s->dequant_dc = ff_vp56_dc_dequant[quantizer] << 2;
42 1266 s->dequant_ac = ff_vp56_ac_dequant[quantizer] << 2;
43 1266 }
44
45 240212 static int vp56_get_vectors_predictors(VP56Context *s, int row, int col,
46 VP56Frame ref_frame)
47 {
48 240212 int nb_pred = 0;
49 240212 VP56mv vect[2] = {{0,0}, {0,0}};
50 int pos, offset;
51 VP56mv mvp;
52
53
2/2
✓ Branch 0 taken 2297542 times.
✓ Branch 1 taken 162675 times.
2460217 for (pos=0; pos<12; pos++) {
54 2297542 mvp.x = col + ff_vp56_candidate_predictor_pos[pos][0];
55 2297542 mvp.y = row + ff_vp56_candidate_predictor_pos[pos][1];
56
4/4
✓ Branch 0 taken 2197852 times.
✓ Branch 1 taken 99690 times.
✓ Branch 2 taken 2139597 times.
✓ Branch 3 taken 58255 times.
2297542 if (mvp.x < 0 || mvp.x >= s->mb_width ||
57
3/4
✓ Branch 0 taken 1920698 times.
✓ Branch 1 taken 218899 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1920698 times.
2139597 mvp.y < 0 || mvp.y >= s->mb_height)
58 376844 continue;
59 1920698 offset = mvp.x + s->mb_width*mvp.y;
60
61
2/2
✓ Branch 0 taken 332002 times.
✓ Branch 1 taken 1588696 times.
1920698 if (ff_vp56_reference_frame[s->macroblocks[offset].type] != ref_frame)
62 332002 continue;
63
2/2
✓ Branch 0 taken 1296716 times.
✓ Branch 1 taken 291980 times.
1588696 if ((s->macroblocks[offset].mv.x == vect[0].x &&
64
2/2
✓ Branch 0 taken 76550 times.
✓ Branch 1 taken 1220166 times.
1296716 s->macroblocks[offset].mv.y == vect[0].y) ||
65
2/2
✓ Branch 0 taken 208542 times.
✓ Branch 1 taken 159988 times.
368530 (s->macroblocks[offset].mv.x == 0 &&
66
2/2
✓ Branch 0 taken 177502 times.
✓ Branch 1 taken 31040 times.
208542 s->macroblocks[offset].mv.y == 0))
67 1397668 continue;
68
69 191028 vect[nb_pred++] = s->macroblocks[offset].mv;
70
2/2
✓ Branch 0 taken 77537 times.
✓ Branch 1 taken 113491 times.
191028 if (nb_pred > 1) {
71 77537 nb_pred = -1;
72 77537 break;
73 }
74 113491 s->vector_candidate_pos = pos;
75 }
76
77 240212 s->vector_candidate[0] = vect[0];
78 240212 s->vector_candidate[1] = vect[1];
79
80 240212 return nb_pred+1;
81 }
82
83 1220 static void vp56_parse_mb_type_models(VP56Context *s)
84 {
85 1220 VPXRangeCoder *c = &s->c;
86 1220 VP56Model *model = s->modelp;
87 int i, ctx, type;
88
89
2/2
✓ Branch 0 taken 3660 times.
✓ Branch 1 taken 1220 times.
4880 for (ctx=0; ctx<3; ctx++) {
90
2/2
✓ Branch 1 taken 730 times.
✓ Branch 2 taken 2930 times.
3660 if (vpx_rac_get_prob_branchy(c, 174)) {
91 730 int idx = vp56_rac_gets(c, 4);
92 730 memcpy(model->mb_types_stats[ctx],
93 730 ff_vp56_pre_def_mb_type_stats[idx][ctx],
94 sizeof(model->mb_types_stats[ctx]));
95 }
96
2/2
✓ Branch 1 taken 117 times.
✓ Branch 2 taken 3543 times.
3660 if (vpx_rac_get_prob_branchy(c, 254)) {
97
2/2
✓ Branch 0 taken 1170 times.
✓ Branch 1 taken 117 times.
1287 for (type=0; type<10; type++) {
98
2/2
✓ Branch 0 taken 2340 times.
✓ Branch 1 taken 1170 times.
3510 for(i=0; i<2; i++) {
99
2/2
✓ Branch 1 taken 915 times.
✓ Branch 2 taken 1425 times.
2340 if (vpx_rac_get_prob_branchy(c, 205)) {
100 915 int delta, sign = vpx_rac_get(c);
101
102 915 delta = vp56_rac_get_tree(c, ff_vp56_pmbtm_tree,
103 ff_vp56_mb_type_model_model);
104
2/2
✓ Branch 0 taken 139 times.
✓ Branch 1 taken 776 times.
915 if (!delta)
105 139 delta = 4 * vp56_rac_gets(c, 7);
106 915 model->mb_types_stats[ctx][type][i] += (delta ^ -sign) + sign;
107 }
108 }
109 }
110 }
111 }
112
113 /* compute MB type probability tables based on previous MB type */
114
2/2
✓ Branch 0 taken 3660 times.
✓ Branch 1 taken 1220 times.
4880 for (ctx=0; ctx<3; ctx++) {
115 int p[10];
116
117
2/2
✓ Branch 0 taken 36600 times.
✓ Branch 1 taken 3660 times.
40260 for (type=0; type<10; type++)
118 36600 p[type] = 100 * model->mb_types_stats[ctx][type][1];
119
120
2/2
✓ Branch 0 taken 36600 times.
✓ Branch 1 taken 3660 times.
40260 for (type=0; type<10; type++) {
121 int p02, p34, p0234, p17, p56, p89, p5689, p156789;
122
123 /* conservative MB type probability */
124 36600 model->mb_type[ctx][type][0] = 255 - (255 * model->mb_types_stats[ctx][type][0]) / (1 + model->mb_types_stats[ctx][type][0] + model->mb_types_stats[ctx][type][1]);
125
126 36600 p[type] = 0; /* same MB type => weight is null */
127
128 /* binary tree parsing probabilities */
129 36600 p02 = p[0] + p[2];
130 36600 p34 = p[3] + p[4];
131 36600 p0234 = p02 + p34;
132 36600 p17 = p[1] + p[7];
133 36600 p56 = p[5] + p[6];
134 36600 p89 = p[8] + p[9];
135 36600 p5689 = p56 + p89;
136 36600 p156789 = p17 + p5689;
137
138 36600 model->mb_type[ctx][type][1] = 1 + 255 * p0234/(1+p0234+p156789);
139 36600 model->mb_type[ctx][type][2] = 1 + 255 * p02 / (1+p0234);
140 36600 model->mb_type[ctx][type][3] = 1 + 255 * p17 / (1+p156789);
141 36600 model->mb_type[ctx][type][4] = 1 + 255 * p[0] / (1+p02);
142 36600 model->mb_type[ctx][type][5] = 1 + 255 * p[3] / (1+p34);
143 36600 model->mb_type[ctx][type][6] = 1 + 255 * p[1] / (1+p17);
144 36600 model->mb_type[ctx][type][7] = 1 + 255 * p56 / (1+p5689);
145 36600 model->mb_type[ctx][type][8] = 1 + 255 * p[5] / (1+p56);
146 36600 model->mb_type[ctx][type][9] = 1 + 255 * p[8] / (1+p89);
147
148 /* restore initial value */
149 36600 p[type] = 100 * model->mb_types_stats[ctx][type][1];
150 }
151 }
152 1220 }
153
154 237554 static VP56mb vp56_parse_mb_type(VP56Context *s,
155 VP56mb prev_type, int ctx)
156 {
157 237554 uint8_t *mb_type_model = s->modelp->mb_type[ctx][prev_type];
158 237554 VPXRangeCoder *c = &s->c;
159
160
2/2
✓ Branch 1 taken 179975 times.
✓ Branch 2 taken 57579 times.
237554 if (vpx_rac_get_prob_branchy(c, mb_type_model[0]))
161 179975 return prev_type;
162 else
163 57579 return vp56_rac_get_tree(c, ff_vp56_pmbt_tree, mb_type_model);
164 }
165
166 11055 static void vp56_decode_4mv(VP56Context *s, int row, int col)
167 {
168 11055 VP56mv mv = {0,0};
169 int type[4];
170 int b;
171
172 /* parse each block type */
173
2/2
✓ Branch 0 taken 44220 times.
✓ Branch 1 taken 11055 times.
55275 for (b=0; b<4; b++) {
174 44220 type[b] = vp56_rac_gets(&s->c, 2);
175
2/2
✓ Branch 0 taken 35003 times.
✓ Branch 1 taken 9217 times.
44220 if (type[b])
176 35003 type[b]++; /* only returns 0, 2, 3 or 4 (all INTER_PF) */
177 }
178
179 /* get vectors */
180
2/2
✓ Branch 0 taken 44220 times.
✓ Branch 1 taken 11055 times.
55275 for (b=0; b<4; b++) {
181
4/5
✓ Branch 0 taken 9217 times.
✓ Branch 1 taken 13235 times.
✓ Branch 2 taken 13086 times.
✓ Branch 3 taken 8682 times.
✗ Branch 4 not taken.
44220 switch (type[b]) {
182 9217 case VP56_MB_INTER_NOVEC_PF:
183 9217 s->mv[b] = (VP56mv) {0,0};
184 9217 break;
185 13235 case VP56_MB_INTER_DELTA_PF:
186 13235 s->parse_vector_adjustment(s, &s->mv[b]);
187 13235 break;
188 13086 case VP56_MB_INTER_V1_PF:
189 13086 s->mv[b] = s->vector_candidate[0];
190 13086 break;
191 8682 case VP56_MB_INTER_V2_PF:
192 8682 s->mv[b] = s->vector_candidate[1];
193 8682 break;
194 }
195 44220 mv.x += s->mv[b].x;
196 44220 mv.y += s->mv[b].y;
197 }
198
199 /* this is the one selected for the whole MB for prediction */
200 11055 s->macroblocks[row * s->mb_width + col].mv = s->mv[3];
201
202 /* chroma vectors are average luma vectors */
203
2/2
✓ Branch 0 taken 5378 times.
✓ Branch 1 taken 5677 times.
11055 s->mv[4].x = s->mv[5].x = RSHIFT(mv.x,2);
204
2/2
✓ Branch 0 taken 4966 times.
✓ Branch 1 taken 6089 times.
11055 s->mv[4].y = s->mv[5].y = RSHIFT(mv.y,2);
205 11055 }
206
207 237554 static VP56mb vp56_decode_mv(VP56Context *s, int row, int col)
208 {
209 237554 VP56mv *mv, vect = {0,0};
210 int ctx, b;
211
212 237554 ctx = vp56_get_vectors_predictors(s, row, col, VP56_FRAME_PREVIOUS);
213 237554 s->mb_type = vp56_parse_mb_type(s, s->mb_type, ctx);
214 237554 s->macroblocks[row * s->mb_width + col].type = s->mb_type;
215
216
8/8
✓ Branch 0 taken 37131 times.
✓ Branch 1 taken 11549 times.
✓ Branch 2 taken 1054 times.
✓ Branch 3 taken 160 times.
✓ Branch 4 taken 14866 times.
✓ Branch 5 taken 1444 times.
✓ Branch 6 taken 11055 times.
✓ Branch 7 taken 160295 times.
237554 switch (s->mb_type) {
217 37131 case VP56_MB_INTER_V1_PF:
218 37131 mv = &s->vector_candidate[0];
219 37131 break;
220
221 11549 case VP56_MB_INTER_V2_PF:
222 11549 mv = &s->vector_candidate[1];
223 11549 break;
224
225 1054 case VP56_MB_INTER_V1_GF:
226 1054 vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
227 1054 mv = &s->vector_candidate[0];
228 1054 break;
229
230 160 case VP56_MB_INTER_V2_GF:
231 160 vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
232 160 mv = &s->vector_candidate[1];
233 160 break;
234
235 14866 case VP56_MB_INTER_DELTA_PF:
236 14866 s->parse_vector_adjustment(s, &vect);
237 14866 mv = &vect;
238 14866 break;
239
240 1444 case VP56_MB_INTER_DELTA_GF:
241 1444 vp56_get_vectors_predictors(s, row, col, VP56_FRAME_GOLDEN);
242 1444 s->parse_vector_adjustment(s, &vect);
243 1444 mv = &vect;
244 1444 break;
245
246 11055 case VP56_MB_INTER_4V:
247 11055 vp56_decode_4mv(s, row, col);
248 11055 return s->mb_type;
249
250 160295 default:
251 160295 mv = &vect;
252 160295 break;
253 }
254
255 226499 s->macroblocks[row*s->mb_width + col].mv = *mv;
256
257 /* same vector for all blocks */
258
2/2
✓ Branch 0 taken 1358994 times.
✓ Branch 1 taken 226499 times.
1585493 for (b=0; b<6; b++)
259 1358994 s->mv[b] = *mv;
260
261 226499 return s->mb_type;
262 }
263
264 363 static VP56mb vp56_conceal_mv(VP56Context *s, int row, int col)
265 {
266 363 VP56mv *mv, vect = {0,0};
267 int b;
268
269 363 s->mb_type = VP56_MB_INTER_NOVEC_PF;
270 363 s->macroblocks[row * s->mb_width + col].type = s->mb_type;
271
272 363 mv = &vect;
273
274 363 s->macroblocks[row*s->mb_width + col].mv = *mv;
275
276 /* same vector for all blocks */
277
2/2
✓ Branch 0 taken 2178 times.
✓ Branch 1 taken 363 times.
2541 for (b=0; b<6; b++)
278 2178 s->mv[b] = *mv;
279
280 363 return s->mb_type;
281 }
282
283 247739 static void vp56_add_predictors_dc(VP56Context *s, VP56Frame ref_frame)
284 {
285 247739 int idx = s->idct_scantable[0];
286 int b;
287
288
2/2
✓ Branch 0 taken 1486434 times.
✓ Branch 1 taken 247739 times.
1734173 for (b=0; b<6; b++) {
289 1486434 VP56RefDc *ab = &s->above_blocks[s->above_block_idx[b]];
290 1486434 VP56RefDc *lb = &s->left_block[ff_vp56_b6to4[b]];
291 1486434 int count = 0;
292 1486434 int dc = 0;
293 int i;
294
295
2/2
✓ Branch 0 taken 1396970 times.
✓ Branch 1 taken 89464 times.
1486434 if (ref_frame == lb->ref_frame) {
296 1396970 dc += lb->dc_coeff;
297 1396970 count++;
298 }
299
2/2
✓ Branch 0 taken 1366522 times.
✓ Branch 1 taken 119912 times.
1486434 if (ref_frame == ab->ref_frame) {
300 1366522 dc += ab->dc_coeff;
301 1366522 count++;
302 }
303
2/2
✓ Branch 0 taken 901056 times.
✓ Branch 1 taken 585378 times.
1486434 if (s->avctx->codec->id == AV_CODEC_ID_VP5)
304
2/2
✓ Branch 0 taken 1802112 times.
✓ Branch 1 taken 901056 times.
2703168 for (i=0; i<2; i++)
305
4/4
✓ Branch 0 taken 107317 times.
✓ Branch 1 taken 1694795 times.
✓ Branch 2 taken 72112 times.
✓ Branch 3 taken 35205 times.
1802112 if (count < 2 && ref_frame == ab[-1+2*i].ref_frame) {
306 72112 dc += ab[-1+2*i].dc_coeff;
307 72112 count++;
308 }
309
2/2
✓ Branch 0 taken 19297 times.
✓ Branch 1 taken 1467137 times.
1486434 if (count == 0)
310 19297 dc = s->prev_dc[ff_vp56_b2p[b]][ref_frame];
311
2/2
✓ Branch 0 taken 1368467 times.
✓ Branch 1 taken 98670 times.
1467137 else if (count == 2)
312 1368467 dc /= 2;
313
314 1486434 s->block_coeff[b][idx] += dc;
315 1486434 s->prev_dc[ff_vp56_b2p[b]][ref_frame] = s->block_coeff[b][idx];
316 1486434 ab->dc_coeff = s->block_coeff[b][idx];
317 1486434 ab->ref_frame = ref_frame;
318 1486434 lb->dc_coeff = s->block_coeff[b][idx];
319 1486434 lb->ref_frame = ref_frame;
320 1486434 s->block_coeff[b][idx] *= s->dequant_dc;
321 }
322 247739 }
323
324 424042 static void vp56_deblock_filter(VP56Context *s, uint8_t *yuv,
325 ptrdiff_t stride, int dx, int dy)
326 {
327
2/2
✓ Branch 0 taken 249618 times.
✓ Branch 1 taken 174424 times.
424042 if (s->avctx->codec->id == AV_CODEC_ID_VP5) {
328 249618 int t = ff_vp56_filter_threshold[s->quantizer];
329
2/2
✓ Branch 0 taken 84139 times.
✓ Branch 1 taken 165479 times.
249618 if (dx) s->vp56dsp.edge_filter_hor(yuv + 10-dx , stride, t);
330
2/2
✓ Branch 0 taken 25724 times.
✓ Branch 1 taken 223894 times.
249618 if (dy) s->vp56dsp.edge_filter_ver(yuv + stride*(10-dy), stride, t);
331 } else {
332 174424 int * bounding_values = s->bounding_values_array + 127;
333
2/2
✓ Branch 0 taken 66268 times.
✓ Branch 1 taken 108156 times.
174424 if (dx)
334 66268 ff_vp3dsp_h_loop_filter_12(yuv + 10-dx, stride, bounding_values);
335
2/2
✓ Branch 0 taken 63282 times.
✓ Branch 1 taken 111142 times.
174424 if (dy)
336 63282 ff_vp3dsp_v_loop_filter_12(yuv + stride*(10-dy), stride, bounding_values);
337 }
338 424042 }
339
340 451240 static void vp56_mc(VP56Context *s, int b, int plane, uint8_t *src,
341 ptrdiff_t stride, int x, int y, ptrdiff_t ref_stride)
342 {
343 451240 uint8_t *dst = s->frames[VP56_FRAME_CURRENT]->data[plane] + s->block_offset[b];
344 uint8_t *src_block;
345 int src_offset;
346 451240 int overlap_offset = 0;
347 451240 int mask = s->vp56_coord_div[b] - 1;
348 451240 int deblock_filtering = s->deblock_filtering;
349 int dx;
350 int dy;
351
352
1/2
✓ Branch 0 taken 451240 times.
✗ Branch 1 not taken.
451240 if (s->avctx->skip_loop_filter >= AVDISCARD_ALL ||
353
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 451240 times.
451240 (s->avctx->skip_loop_filter >= AVDISCARD_NONKEY
354 && !(s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY)))
355 deblock_filtering = 0;
356
357 451240 dx = s->mv[b].x / s->vp56_coord_div[b];
358 451240 dy = s->mv[b].y / s->vp56_coord_div[b];
359
360
2/2
✓ Branch 0 taken 142208 times.
✓ Branch 1 taken 309032 times.
451240 if (b >= 4) {
361 142208 x /= 2;
362 142208 y /= 2;
363 }
364 451240 x += dx - 2;
365 451240 y += dy - 2;
366
367
4/4
✓ Branch 0 taken 6924 times.
✓ Branch 1 taken 444316 times.
✓ Branch 2 taken 282 times.
✓ Branch 3 taken 6642 times.
451240 if (s->interlaced && s->il_block) {
368 /* extract 12*(4+16+4) block from frame (containing both fields), then treat src_block as specific field */
369 282 s->vdsp.emulated_edge_mc(s->edge_emu_buffer,
370 282 src + s->block_offset[b] + (dy-4)*ref_stride + (dx-2),
371 ref_stride, ref_stride,
372 12, 24, x, y - 2,
373 s->plane_width[plane],
374 s->plane_height[plane]);
375 282 src_block = s->edge_emu_buffer;
376 282 src_offset = 2 + 4*ref_stride;
377
6/6
✓ Branch 0 taken 441194 times.
✓ Branch 1 taken 9764 times.
✓ Branch 2 taken 425537 times.
✓ Branch 3 taken 15657 times.
✓ Branch 4 taken 415556 times.
✓ Branch 5 taken 9981 times.
450958 } else if (x<0 || x+12>=s->plane_width[plane] ||
378
2/2
✓ Branch 0 taken 19815 times.
✓ Branch 1 taken 395741 times.
415556 y<0 || y+12>=s->plane_height[plane]) {
379 55217 s->vdsp.emulated_edge_mc(s->edge_emu_buffer,
380 55217 src + s->block_offset[b] + (dy-2)*stride + (dx-2),
381 stride, stride,
382 12, 12, x, y,
383 s->plane_width[plane],
384 s->plane_height[plane]);
385 55217 src_block = s->edge_emu_buffer;
386 55217 src_offset = 2 + 2*stride;
387
2/2
✓ Branch 0 taken 375812 times.
✓ Branch 1 taken 19929 times.
395741 } else if (deblock_filtering) {
388 /* only need a 12x12 block, but there is no such dsp function, */
389 /* so copy a 16x12 block */
390 375812 s->hdsp.put_pixels_tab[0][0](s->edge_emu_buffer,
391 375812 src + s->block_offset[b] + (dy-2)*stride + (dx-2),
392 stride, 12);
393 375812 src_block = s->edge_emu_buffer;
394 375812 src_offset = 2 + 2*stride;
395 } else {
396 19929 src_block = src;
397 19929 src_offset = s->block_offset[b] + dy*stride + dx;
398 }
399
400
2/2
✓ Branch 0 taken 424042 times.
✓ Branch 1 taken 27198 times.
451240 if (deblock_filtering)
401 424042 vp56_deblock_filter(s, src_block, stride, dx&7, dy&7);
402
403
2/2
✓ Branch 0 taken 288380 times.
✓ Branch 1 taken 162860 times.
451240 if (s->mv[b].x & mask)
404
2/2
✓ Branch 0 taken 163485 times.
✓ Branch 1 taken 124895 times.
288380 overlap_offset += (s->mv[b].x > 0) ? 1 : -1;
405
2/2
✓ Branch 0 taken 281478 times.
✓ Branch 1 taken 169762 times.
451240 if (s->mv[b].y & mask)
406
2/2
✓ Branch 0 taken 126905 times.
✓ Branch 1 taken 154573 times.
281478 overlap_offset += (s->mv[b].y > 0) ? stride : -stride;
407
408
2/2
✓ Branch 0 taken 394315 times.
✓ Branch 1 taken 56925 times.
451240 if (overlap_offset) {
409
2/2
✓ Branch 0 taken 178196 times.
✓ Branch 1 taken 216119 times.
394315 if (s->filter)
410 178196 s->filter(s, dst, src_block, src_offset, src_offset+overlap_offset,
411 stride, s->mv[b], mask, s->filter_selection, b<4);
412 else
413 216119 s->vp3dsp.put_no_rnd_pixels_l2(dst, src_block+src_offset,
414 216119 src_block+src_offset+overlap_offset,
415 stride, 8);
416 } else {
417 56925 s->hdsp.put_pixels_tab[1][0](dst, src_block+src_offset, stride, 8);
418 }
419 451240 }
420
421 197838 static void vp56_idct_put(VP56Context *s, uint8_t * dest, ptrdiff_t stride, int16_t *block, int selector)
422 {
423
3/4
✓ Branch 0 taken 34993 times.
✓ Branch 1 taken 162845 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 34993 times.
197838 if (selector > 10 || selector == 1)
424 162845 s->vp3dsp.idct_put(dest, stride, block);
425 else
426 34993 ff_vp3dsp_idct10_put(dest, stride, block);
427 197838 }
428
429 1246188 static void vp56_idct_add(VP56Context *s, uint8_t * dest, ptrdiff_t stride, int16_t *block, int selector)
430 {
431
2/2
✓ Branch 0 taken 874514 times.
✓ Branch 1 taken 371674 times.
1246188 if (selector > 10)
432 874514 s->vp3dsp.idct_add(dest, stride, block);
433
2/2
✓ Branch 0 taken 371255 times.
✓ Branch 1 taken 419 times.
371674 else if (selector > 1)
434 371255 ff_vp3dsp_idct10_add(dest, stride, block);
435 else
436 419 s->vp3dsp.idct_dc_add(dest, stride, block);
437 1246188 }
438
439 247739 static av_always_inline void vp56_render_mb(VP56Context *s, int row, int col, int is_alpha, VP56mb mb_type)
440 {
441 int b, ab, b_max, plane, off;
442 AVFrame *frame_current, *frame_ref;
443 247739 VP56Frame ref_frame = ff_vp56_reference_frame[mb_type];
444 ptrdiff_t ref_stride[4];
445
446 247739 vp56_add_predictors_dc(s, ref_frame);
447
448 247739 frame_current = s->frames[VP56_FRAME_CURRENT];
449 247739 frame_ref = s->frames[ref_frame];
450
3/4
✓ Branch 0 taken 214198 times.
✓ Branch 1 taken 33541 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 214198 times.
247739 if (mb_type != VP56_MB_INTRA && !frame_ref->data[0])
451 return;
452
453 247739 memcpy(ref_stride, s->stride, sizeof(s->stride));
454
4/4
✓ Branch 0 taken 1812 times.
✓ Branch 1 taken 245927 times.
✓ Branch 2 taken 76 times.
✓ Branch 3 taken 1736 times.
247739 if (s->interlaced && s->il_block) {
455 76 s->block_offset[2] -= s->stride[0] * 7;
456 76 s->block_offset[3] -= s->stride[0] * 7;
457 76 s->stride[0] *= 2;
458 }
459
460 247739 ab = 6*is_alpha;
461 247739 b_max = 6 - 2*is_alpha;
462
463
3/4
✓ Branch 0 taken 33541 times.
✓ Branch 1 taken 136940 times.
✓ Branch 2 taken 77258 times.
✗ Branch 3 not taken.
247739 switch (mb_type) {
464 33541 case VP56_MB_INTRA:
465
2/2
✓ Branch 0 taken 197838 times.
✓ Branch 1 taken 33541 times.
231379 for (b=0; b<b_max; b++) {
466 197838 plane = ff_vp56_b2p[b+ab];
467 197838 vp56_idct_put(s, frame_current->data[plane] + s->block_offset[b],
468 197838 s->stride[plane], s->block_coeff[b], s->idct_selector[b]);
469 }
470 33541 break;
471
472 136940 case VP56_MB_INTER_NOVEC_PF:
473 case VP56_MB_INTER_NOVEC_GF:
474
2/2
✓ Branch 0 taken 794948 times.
✓ Branch 1 taken 136940 times.
931888 for (b=0; b<b_max; b++) {
475 794948 plane = ff_vp56_b2p[b+ab];
476 794948 off = s->block_offset[b];
477 794948 s->hdsp.put_pixels_tab[1][0](frame_current->data[plane] + off,
478 794948 frame_ref->data[plane] + off,
479 s->stride[plane], 8);
480 794948 vp56_idct_add(s, frame_current->data[plane] + off,
481 794948 s->stride[plane], s->block_coeff[b], s->idct_selector[b]);
482 }
483 136940 break;
484
485 77258 case VP56_MB_INTER_DELTA_PF:
486 case VP56_MB_INTER_V1_PF:
487 case VP56_MB_INTER_V2_PF:
488 case VP56_MB_INTER_DELTA_GF:
489 case VP56_MB_INTER_4V:
490 case VP56_MB_INTER_V1_GF:
491 case VP56_MB_INTER_V2_GF:
492
2/2
✓ Branch 0 taken 451240 times.
✓ Branch 1 taken 77258 times.
528498 for (b=0; b<b_max; b++) {
493
4/4
✓ Branch 0 taken 373982 times.
✓ Branch 1 taken 77258 times.
✓ Branch 2 taken 77258 times.
✓ Branch 3 taken 296724 times.
451240 int x_off = b==1 || b==3 ? 8 : 0;
494
8/8
✓ Branch 0 taken 373982 times.
✓ Branch 1 taken 77258 times.
✓ Branch 2 taken 77258 times.
✓ Branch 3 taken 296724 times.
✓ Branch 4 taken 2308 times.
✓ Branch 5 taken 152208 times.
✓ Branch 6 taken 94 times.
✓ Branch 7 taken 2214 times.
451240 int y_off = b==2 || b==3 ? (s->interlaced && s->il_block ? 1 : 8) : 0;
495 451240 plane = ff_vp56_b2p[b+ab];
496 451240 vp56_mc(s, b, plane, frame_ref->data[plane], s->stride[plane],
497 451240 16*col+x_off, 16*row+y_off, ref_stride[plane]);
498 451240 vp56_idct_add(s, frame_current->data[plane] + s->block_offset[b],
499 451240 s->stride[plane], s->block_coeff[b], s->idct_selector[b]);
500 }
501 77258 break;
502 }
503
504
2/2
✓ Branch 0 taken 21204 times.
✓ Branch 1 taken 226535 times.
247739 if (is_alpha) {
505 21204 s->block_coeff[4][0] = 0;
506 21204 s->block_coeff[5][0] = 0;
507 }
508
509
4/4
✓ Branch 0 taken 1812 times.
✓ Branch 1 taken 245927 times.
✓ Branch 2 taken 76 times.
✓ Branch 3 taken 1736 times.
247739 if (s->interlaced && s->il_block) {
510 76 s->stride[0] /= 2;
511 76 s->block_offset[2] += s->stride[0] * 7;
512 76 s->block_offset[3] += s->stride[0] * 7;
513 }
514 }
515
516 247377 static int vp56_decode_mb(VP56Context *s, int row, int col, int is_alpha)
517 {
518 VP56mb mb_type;
519 int ret;
520
521
2/2
✓ Branch 0 taken 1812 times.
✓ Branch 1 taken 245565 times.
247377 if (s->interlaced) {
522 1812 int prob = s->il_prob;
523
524
2/2
✓ Branch 0 taken 906 times.
✓ Branch 1 taken 906 times.
1812 if (col > 0) {
525
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 880 times.
906 if (s->il_block)
526 26 prob -= prob >> 1;
527 else
528 880 prob += (256 - prob) >> 1; /* can be simplified/combined */
529 }
530
531 1812 s->il_block = vpx_rac_get_prob(&s->c, prob);
532 }
533
534
2/2
✓ Branch 0 taken 9823 times.
✓ Branch 1 taken 237554 times.
247377 if (s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY)
535 9823 mb_type = VP56_MB_INTRA;
536 else
537 237554 mb_type = vp56_decode_mv(s, row, col);
538
539 247377 ret = s->parse_coeff(s);
540
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 247376 times.
247377 if (ret < 0)
541 1 return ret;
542
543 247376 vp56_render_mb(s, row, col, is_alpha, mb_type);
544
545 247376 return 0;
546 }
547
548 363 static int vp56_conceal_mb(VP56Context *s, int row, int col, int is_alpha)
549 {
550 VP56mb mb_type;
551
552
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 363 times.
363 if (s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY)
553 mb_type = VP56_MB_INTRA;
554 else
555 363 mb_type = vp56_conceal_mv(s, row, col);
556
557 363 vp56_render_mb(s, row, col, is_alpha, mb_type);
558
559 363 return 0;
560 }
561
562 16 static int vp56_size_changed(VP56Context *s)
563 {
564 16 AVCodecContext *avctx = s->avctx;
565 16 int stride = s->frames[VP56_FRAME_CURRENT]->linesize[0];
566 int i;
567
568 16 s->plane_width[0] = s->plane_width[3] = avctx->coded_width;
569 16 s->plane_width[1] = s->plane_width[2] = avctx->coded_width/2;
570 16 s->plane_height[0] = s->plane_height[3] = avctx->coded_height;
571 16 s->plane_height[1] = s->plane_height[2] = avctx->coded_height/2;
572
573 16 s->have_undamaged_frame = 0;
574
575
2/2
✓ Branch 0 taken 64 times.
✓ Branch 1 taken 16 times.
80 for (i=0; i<4; i++)
576 64 s->stride[i] = s->flip * s->frames[VP56_FRAME_CURRENT]->linesize[i];
577
578 16 s->mb_width = (avctx->coded_width +15) / 16;
579 16 s->mb_height = (avctx->coded_height+15) / 16;
580
581
2/4
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 16 times.
16 if (s->mb_width > 1000 || s->mb_height > 1000) {
582 ff_set_dimensions(avctx, 0, 0);
583 av_log(avctx, AV_LOG_ERROR, "picture too big\n");
584 return AVERROR_INVALIDDATA;
585 }
586
587 16 av_reallocp_array(&s->above_blocks, 4*s->mb_width+6,
588 sizeof(*s->above_blocks));
589 16 av_reallocp_array(&s->macroblocks, s->mb_width*s->mb_height,
590 sizeof(*s->macroblocks));
591 16 av_free(s->edge_emu_buffer_alloc);
592 16 s->edge_emu_buffer_alloc = av_malloc(16*stride*2);
593 16 s->edge_emu_buffer = s->edge_emu_buffer_alloc;
594
3/6
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 16 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 16 times.
16 if (!s->above_blocks || !s->macroblocks || !s->edge_emu_buffer_alloc)
595 return AVERROR(ENOMEM);
596
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 6 times.
16 if (s->flip < 0)
597 10 s->edge_emu_buffer += 15 * stride * 2;
598
599
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 14 times.
16 if (s->alpha_context)
600 2 return vp56_size_changed(s->alpha_context);
601
602 14 return 0;
603 }
604
605 static int ff_vp56_decode_mbs(AVCodecContext *avctx, void *, int, int);
606
607 1173 int ff_vp56_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
608 int *got_frame, AVPacket *avpkt)
609 {
610 1173 const uint8_t *buf = avpkt->data;
611 1173 VP56Context *s = avctx->priv_data;
612 1173 AVFrame *const p = s->frames[VP56_FRAME_CURRENT];
613 1173 int remaining_buf_size = avpkt->size;
614 1173 int alpha_offset = remaining_buf_size;
615 int i, res;
616 int ret;
617
618
2/2
✓ Branch 0 taken 186 times.
✓ Branch 1 taken 987 times.
1173 if (s->has_alpha) {
619
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 186 times.
186 if (remaining_buf_size < 3)
620 return AVERROR_INVALIDDATA;
621 186 alpha_offset = bytestream_get_be24(&buf);
622 186 remaining_buf_size -= 3;
623
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 186 times.
186 if (remaining_buf_size < alpha_offset)
624 return AVERROR_INVALIDDATA;
625 }
626
627 1173 res = s->parse_header(s, buf, alpha_offset);
628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1173 times.
1173 if (res < 0)
629 return res;
630
631
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 1159 times.
1173 if (res == VP56_SIZE_CHANGE) {
632
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 14 times.
70 for (i = 0; i < 4; i++) {
633 56 av_frame_unref(s->frames[i]);
634
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 48 times.
56 if (s->alpha_context)
635 8 av_frame_unref(s->alpha_context->frames[i]);
636 }
637 14 s->frames[VP56_FRAME_CURRENT]->flags |= AV_FRAME_FLAG_KEY; //FIXME
638 }
639
640 1173 ret = ff_get_buffer(avctx, p, AV_GET_BUFFER_FLAG_REF);
641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1173 times.
1173 if (ret < 0) {
642 if (res == VP56_SIZE_CHANGE)
643 ff_set_dimensions(avctx, 0, 0);
644 return ret;
645 }
646
647
2/2
✓ Branch 0 taken 93 times.
✓ Branch 1 taken 1080 times.
1173 if (avctx->pix_fmt == AV_PIX_FMT_YUVA420P) {
648
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 93 times.
93 if ((ret = av_frame_replace(s->alpha_context->frames[VP56_FRAME_CURRENT], p)) < 0) {
649 av_frame_unref(p);
650 if (res == VP56_SIZE_CHANGE)
651 ff_set_dimensions(avctx, 0, 0);
652 return ret;
653 }
654 }
655
656
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 1159 times.
1173 if (res == VP56_SIZE_CHANGE) {
657
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 14 times.
14 if (vp56_size_changed(s)) {
658 av_frame_unref(p);
659 return AVERROR_INVALIDDATA;
660 }
661 }
662
663
2/2
✓ Branch 0 taken 93 times.
✓ Branch 1 taken 1080 times.
1173 if (avctx->pix_fmt == AV_PIX_FMT_YUVA420P) {
664 93 int bak_w = avctx->width;
665 93 int bak_h = avctx->height;
666 93 int bak_cw = avctx->coded_width;
667 93 int bak_ch = avctx->coded_height;
668 93 buf += alpha_offset;
669 93 remaining_buf_size -= alpha_offset;
670
671 93 res = s->alpha_context->parse_header(s->alpha_context, buf, remaining_buf_size);
672
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 93 times.
93 if (res != 0) {
673 if(res==VP56_SIZE_CHANGE) {
674 av_log(avctx, AV_LOG_ERROR, "Alpha reconfiguration\n");
675 avctx->width = bak_w;
676 avctx->height = bak_h;
677 avctx->coded_width = bak_cw;
678 avctx->coded_height = bak_ch;
679 }
680 av_frame_unref(p);
681 return AVERROR_INVALIDDATA;
682 }
683 }
684
685 1173 s->discard_frame = 0;
686
2/2
✓ Branch 0 taken 93 times.
✓ Branch 1 taken 1080 times.
1173 avctx->execute2(avctx, ff_vp56_decode_mbs, 0, 0, (avctx->pix_fmt == AV_PIX_FMT_YUVA420P) + 1);
687
688
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1173 times.
1173 if (s->discard_frame)
689 return AVERROR_INVALIDDATA;
690
691
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1173 times.
1173 if ((res = av_frame_ref(rframe, p)) < 0)
692 return res;
693 1173 *got_frame = 1;
694
695 1173 return avpkt->size;
696 }
697
698 1266 static int ff_vp56_decode_mbs(AVCodecContext *avctx, void *data,
699 int jobnr, int threadnr)
700 {
701 1266 VP56Context *s0 = avctx->priv_data;
702 1266 int is_alpha = (jobnr == 1);
703
2/2
✓ Branch 0 taken 93 times.
✓ Branch 1 taken 1173 times.
1266 VP56Context *s = is_alpha ? s0->alpha_context : s0;
704 1266 AVFrame *const p = s->frames[VP56_FRAME_CURRENT];
705 1266 int mb_row, mb_col, mb_row_flip, mb_offset = 0;
706 int block, y, uv;
707 ptrdiff_t stride_y, stride_uv;
708 int res;
709 1266 int damaged = 0;
710
711
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 1220 times.
1266 if (p->flags & AV_FRAME_FLAG_KEY) {
712 46 p->pict_type = AV_PICTURE_TYPE_I;
713 46 s->default_models_init(s);
714
2/2
✓ Branch 0 taken 9823 times.
✓ Branch 1 taken 46 times.
9869 for (block=0; block<s->mb_height*s->mb_width; block++)
715 9823 s->macroblocks[block].type = VP56_MB_INTRA;
716 } else {
717 1220 p->pict_type = AV_PICTURE_TYPE_P;
718 1220 vp56_parse_mb_type_models(s);
719 1220 s->parse_vector_models(s);
720 1220 s->mb_type = VP56_MB_INTER_NOVEC_PF;
721 }
722
723
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1266 times.
1266 if (s->parse_coeff_models(s))
724 goto next;
725
726
2/2
✓ Branch 0 taken 302 times.
✓ Branch 1 taken 964 times.
1266 if (s->interlaced) {
727 302 s->frames[VP56_FRAME_CURRENT]->flags |= AV_FRAME_FLAG_INTERLACED;
728 302 s->il_prob = vp56_rac_gets(&s->c, 8);
729 }
730
731 1266 memset(s->prev_dc, 0, sizeof(s->prev_dc));
732 1266 s->prev_dc[1][VP56_FRAME_CURRENT] = 128;
733 1266 s->prev_dc[2][VP56_FRAME_CURRENT] = 128;
734
735
2/2
✓ Branch 0 taken 77852 times.
✓ Branch 1 taken 1266 times.
79118 for (block=0; block < 4*s->mb_width+6; block++) {
736 77852 s->above_blocks[block].ref_frame = VP56_FRAME_NONE;
737 77852 s->above_blocks[block].dc_coeff = 0;
738 77852 s->above_blocks[block].not_null_dc = 0;
739 }
740 1266 s->above_blocks[2*s->mb_width + 2].ref_frame = VP56_FRAME_CURRENT;
741 1266 s->above_blocks[3*s->mb_width + 4].ref_frame = VP56_FRAME_CURRENT;
742
743 1266 stride_y = p->linesize[0];
744 1266 stride_uv = p->linesize[1];
745
746
2/2
✓ Branch 0 taken 812 times.
✓ Branch 1 taken 454 times.
1266 if (s->flip < 0)
747 812 mb_offset = 7;
748
749 /* main macroblocks loop */
750
2/2
✓ Branch 0 taken 12336 times.
✓ Branch 1 taken 1266 times.
13602 for (mb_row=0; mb_row<s->mb_height; mb_row++) {
751
2/2
✓ Branch 0 taken 8113 times.
✓ Branch 1 taken 4223 times.
12336 if (s->flip < 0)
752 8113 mb_row_flip = s->mb_height - mb_row - 1;
753 else
754 4223 mb_row_flip = mb_row;
755
756
2/2
✓ Branch 0 taken 49344 times.
✓ Branch 1 taken 12336 times.
61680 for (block=0; block<4; block++) {
757 49344 s->left_block[block].ref_frame = VP56_FRAME_NONE;
758 49344 s->left_block[block].dc_coeff = 0;
759 49344 s->left_block[block].not_null_dc = 0;
760 }
761 12336 memset(s->coeff_ctx, 0, sizeof(s->coeff_ctx));
762 12336 memset(s->coeff_ctx_last, 24, sizeof(s->coeff_ctx_last));
763
764 12336 s->above_block_idx[0] = 1;
765 12336 s->above_block_idx[1] = 2;
766 12336 s->above_block_idx[2] = 1;
767 12336 s->above_block_idx[3] = 2;
768 12336 s->above_block_idx[4] = 2*s->mb_width + 2 + 1;
769 12336 s->above_block_idx[5] = 3*s->mb_width + 4 + 1;
770
771 12336 s->block_offset[s->frbi] = (mb_row_flip*16 + mb_offset) * stride_y;
772 12336 s->block_offset[s->srbi] = s->block_offset[s->frbi] + 8*stride_y;
773 12336 s->block_offset[1] = s->block_offset[0] + 8;
774 12336 s->block_offset[3] = s->block_offset[2] + 8;
775 12336 s->block_offset[4] = (mb_row_flip*8 + mb_offset) * stride_uv;
776 12336 s->block_offset[5] = s->block_offset[4];
777
778
2/2
✓ Branch 0 taken 247739 times.
✓ Branch 1 taken 12336 times.
260075 for (mb_col=0; mb_col<s->mb_width; mb_col++) {
779
2/2
✓ Branch 0 taken 247377 times.
✓ Branch 1 taken 362 times.
247739 if (!damaged) {
780 247377 int ret = vp56_decode_mb(s, mb_row, mb_col, is_alpha);
781
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 247376 times.
247377 if (ret < 0) {
782 1 damaged = 1;
783
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 if (!s->have_undamaged_frame || !avctx->error_concealment) {
784 s->discard_frame = 1;
785 return AVERROR_INVALIDDATA;
786 }
787 }
788 }
789
2/2
✓ Branch 0 taken 363 times.
✓ Branch 1 taken 247376 times.
247739 if (damaged)
790 363 vp56_conceal_mb(s, mb_row, mb_col, is_alpha);
791
792
2/2
✓ Branch 0 taken 990956 times.
✓ Branch 1 taken 247739 times.
1238695 for (y=0; y<4; y++) {
793 990956 s->above_block_idx[y] += 2;
794 990956 s->block_offset[y] += 16;
795 }
796
797
2/2
✓ Branch 0 taken 495478 times.
✓ Branch 1 taken 247739 times.
743217 for (uv=4; uv<6; uv++) {
798 495478 s->above_block_idx[uv] += 1;
799 495478 s->block_offset[uv] += 8;
800 }
801 }
802 }
803
804
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1265 times.
1266 if (!damaged)
805 1265 s->have_undamaged_frame = 1;
806
807 1 next:
808
4/4
✓ Branch 0 taken 1220 times.
✓ Branch 1 taken 46 times.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 1187 times.
1266 if ((p->flags & AV_FRAME_FLAG_KEY) || s->golden_frame) {
809
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 79 times.
79 if ((res = av_frame_replace(s->frames[VP56_FRAME_GOLDEN], p)) < 0)
810 return res;
811 }
812
813 1266 av_frame_unref(s->frames[VP56_FRAME_PREVIOUS]);
814 1266 FFSWAP(AVFrame *, s->frames[VP56_FRAME_CURRENT],
815 s->frames[VP56_FRAME_PREVIOUS]);
816 1266 return 0;
817 }
818
819 25 av_cold int ff_vp56_init_context(AVCodecContext *avctx, VP56Context *s,
820 int flip, int has_alpha)
821 {
822 int i;
823
824 25 s->avctx = avctx;
825
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 17 times.
25 avctx->pix_fmt = has_alpha ? AV_PIX_FMT_YUVA420P : AV_PIX_FMT_YUV420P;
826
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 21 times.
25 if (avctx->skip_alpha) avctx->pix_fmt = AV_PIX_FMT_YUV420P;
827
828 25 ff_h264chroma_init(&s->h264chroma, 8);
829 25 ff_hpeldsp_init(&s->hdsp, avctx->flags);
830 25 ff_videodsp_init(&s->vdsp, 8);
831 25 ff_vp3dsp_init(&s->vp3dsp, avctx->flags);
832
2/2
✓ Branch 0 taken 1600 times.
✓ Branch 1 taken 25 times.
1625 for (i = 0; i < 64; i++) {
833 #define TRANSPOSE(x) (((x) >> 3) | (((x) & 7) << 3))
834 1600 s->idct_scantable[i] = TRANSPOSE(ff_zigzag_direct[i]);
835 #undef TRANSPOSE
836 }
837
838
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 25 times.
125 for (i = 0; i < FF_ARRAY_ELEMS(s->frames); i++) {
839 100 s->frames[i] = av_frame_alloc();
840
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 if (!s->frames[i])
841 return AVERROR(ENOMEM);
842 }
843 25 s->edge_emu_buffer_alloc = NULL;
844
845 25 s->above_blocks = NULL;
846 25 s->macroblocks = NULL;
847 25 s->quantizer = -1;
848 25 s->deblock_filtering = 1;
849 25 s->golden_frame = 0;
850
851 25 s->filter = NULL;
852
853 25 s->has_alpha = has_alpha;
854
855 25 s->modelp = &s->model;
856
857
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 10 times.
25 if (flip) {
858 15 s->flip = -1;
859 15 s->frbi = 2;
860 15 s->srbi = 0;
861 } else {
862 10 s->flip = 1;
863 10 s->frbi = 0;
864 10 s->srbi = 2;
865 }
866
867 25 return 0;
868 }
869
870 25 av_cold int ff_vp56_free_context(VP56Context *s)
871 {
872 int i;
873
874 25 av_freep(&s->above_blocks);
875 25 av_freep(&s->macroblocks);
876 25 av_freep(&s->edge_emu_buffer_alloc);
877
878
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 25 times.
125 for (i = 0; i < FF_ARRAY_ELEMS(s->frames); i++)
879 100 av_frame_free(&s->frames[i]);
880
881 25 return 0;
882 }
883