FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/vp56.c
Date: 2024-11-20 23:03:26
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 1265 void ff_vp56_init_dequant(VP56Context *s, int quantizer)
37 {
38
2/2
✓ Branch 0 taken 410 times.
✓ Branch 1 taken 855 times.
1265 if (s->quantizer != quantizer)
39 410 ff_vp3dsp_set_bounding_values(s->bounding_values_array, ff_vp56_filter_threshold[quantizer]);
40 1265 s->quantizer = quantizer;
41 1265 s->dequant_dc = ff_vp56_dc_dequant[quantizer] << 2;
42 1265 s->dequant_ac = ff_vp56_ac_dequant[quantizer] << 2;
43 1265 }
44
45 240163 static int vp56_get_vectors_predictors(VP56Context *s, int row, int col,
46 VP56Frame ref_frame)
47 {
48 240163 int nb_pred = 0;
49 240163 VP56mv vect[2] = {{0,0}, {0,0}};
50 int pos, offset;
51 VP56mv mvp;
52
53
2/2
✓ Branch 0 taken 2296954 times.
✓ Branch 1 taken 162626 times.
2459580 for (pos=0; pos<12; pos++) {
54 2296954 mvp.x = col + ff_vp56_candidate_predictor_pos[pos][0];
55 2296954 mvp.y = row + ff_vp56_candidate_predictor_pos[pos][1];
56
4/4
✓ Branch 0 taken 2197327 times.
✓ Branch 1 taken 99627 times.
✓ Branch 2 taken 2139114 times.
✓ Branch 3 taken 58213 times.
2296954 if (mvp.x < 0 || mvp.x >= s->mb_width ||
57
3/4
✓ Branch 0 taken 1920302 times.
✓ Branch 1 taken 218812 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1920302 times.
2139114 mvp.y < 0 || mvp.y >= s->mb_height)
58 376652 continue;
59 1920302 offset = mvp.x + s->mb_width*mvp.y;
60
61
2/2
✓ Branch 0 taken 332001 times.
✓ Branch 1 taken 1588301 times.
1920302 if (ff_vp56_reference_frame[s->macroblocks[offset].type] != ref_frame)
62 332001 continue;
63
2/2
✓ Branch 0 taken 1296321 times.
✓ Branch 1 taken 291980 times.
1588301 if ((s->macroblocks[offset].mv.x == vect[0].x &&
64
2/2
✓ Branch 0 taken 76490 times.
✓ Branch 1 taken 1219831 times.
1296321 s->macroblocks[offset].mv.y == vect[0].y) ||
65
2/2
✓ Branch 0 taken 208482 times.
✓ Branch 1 taken 159988 times.
368470 (s->macroblocks[offset].mv.x == 0 &&
66
2/2
✓ Branch 0 taken 177489 times.
✓ Branch 1 taken 30993 times.
208482 s->macroblocks[offset].mv.y == 0))
67 1397320 continue;
68
69 190981 vect[nb_pred++] = s->macroblocks[offset].mv;
70
2/2
✓ Branch 0 taken 77537 times.
✓ Branch 1 taken 113444 times.
190981 if (nb_pred > 1) {
71 77537 nb_pred = -1;
72 77537 break;
73 }
74 113444 s->vector_candidate_pos = pos;
75 }
76
77 240163 s->vector_candidate[0] = vect[0];
78 240163 s->vector_candidate[1] = vect[1];
79
80 240163 return nb_pred+1;
81 }
82
83 1219 static void vp56_parse_mb_type_models(VP56Context *s)
84 {
85 1219 VPXRangeCoder *c = &s->c;
86 1219 VP56Model *model = s->modelp;
87 int i, ctx, type;
88
89
2/2
✓ Branch 0 taken 3657 times.
✓ Branch 1 taken 1219 times.
4876 for (ctx=0; ctx<3; ctx++) {
90
2/2
✓ Branch 1 taken 730 times.
✓ Branch 2 taken 2927 times.
3657 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 3540 times.
3657 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 3657 times.
✓ Branch 1 taken 1219 times.
4876 for (ctx=0; ctx<3; ctx++) {
115 int p[10];
116
117
2/2
✓ Branch 0 taken 36570 times.
✓ Branch 1 taken 3657 times.
40227 for (type=0; type<10; type++)
118 36570 p[type] = 100 * model->mb_types_stats[ctx][type][1];
119
120
2/2
✓ Branch 0 taken 36570 times.
✓ Branch 1 taken 3657 times.
40227 for (type=0; type<10; type++) {
121 int p02, p34, p0234, p17, p56, p89, p5689, p156789;
122
123 /* conservative MB type probability */
124 36570 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 36570 p[type] = 0; /* same MB type => weight is null */
127
128 /* binary tree parsing probabilities */
129 36570 p02 = p[0] + p[2];
130 36570 p34 = p[3] + p[4];
131 36570 p0234 = p02 + p34;
132 36570 p17 = p[1] + p[7];
133 36570 p56 = p[5] + p[6];
134 36570 p89 = p[8] + p[9];
135 36570 p5689 = p56 + p89;
136 36570 p156789 = p17 + p5689;
137
138 36570 model->mb_type[ctx][type][1] = 1 + 255 * p0234/(1+p0234+p156789);
139 36570 model->mb_type[ctx][type][2] = 1 + 255 * p02 / (1+p0234);
140 36570 model->mb_type[ctx][type][3] = 1 + 255 * p17 / (1+p156789);
141 36570 model->mb_type[ctx][type][4] = 1 + 255 * p[0] / (1+p02);
142 36570 model->mb_type[ctx][type][5] = 1 + 255 * p[3] / (1+p34);
143 36570 model->mb_type[ctx][type][6] = 1 + 255 * p[1] / (1+p17);
144 36570 model->mb_type[ctx][type][7] = 1 + 255 * p56 / (1+p5689);
145 36570 model->mb_type[ctx][type][8] = 1 + 255 * p[5] / (1+p56);
146 36570 model->mb_type[ctx][type][9] = 1 + 255 * p[8] / (1+p89);
147
148 /* restore initial value */
149 36570 p[type] = 100 * model->mb_types_stats[ctx][type][1];
150 }
151 }
152 1219 }
153
154 237505 static VP56mb vp56_parse_mb_type(VP56Context *s,
155 VP56mb prev_type, int ctx)
156 {
157 237505 uint8_t *mb_type_model = s->modelp->mb_type[ctx][prev_type];
158 237505 VPXRangeCoder *c = &s->c;
159
160
2/2
✓ Branch 1 taken 179935 times.
✓ Branch 2 taken 57570 times.
237505 if (vpx_rac_get_prob_branchy(c, mb_type_model[0]))
161 179935 return prev_type;
162 else
163 57570 return vp56_rac_get_tree(c, ff_vp56_pmbt_tree, mb_type_model);
164 }
165
166 11054 static void vp56_decode_4mv(VP56Context *s, int row, int col)
167 {
168 11054 VP56mv mv = {0,0};
169 int type[4];
170 int b;
171
172 /* parse each block type */
173
2/2
✓ Branch 0 taken 44216 times.
✓ Branch 1 taken 11054 times.
55270 for (b=0; b<4; b++) {
174 44216 type[b] = vp56_rac_gets(&s->c, 2);
175
2/2
✓ Branch 0 taken 35000 times.
✓ Branch 1 taken 9216 times.
44216 if (type[b])
176 35000 type[b]++; /* only returns 0, 2, 3 or 4 (all INTER_PF) */
177 }
178
179 /* get vectors */
180
2/2
✓ Branch 0 taken 44216 times.
✓ Branch 1 taken 11054 times.
55270 for (b=0; b<4; b++) {
181
4/5
✓ Branch 0 taken 9216 times.
✓ Branch 1 taken 13235 times.
✓ Branch 2 taken 13083 times.
✓ Branch 3 taken 8682 times.
✗ Branch 4 not taken.
44216 switch (type[b]) {
182 9216 case VP56_MB_INTER_NOVEC_PF:
183 9216 s->mv[b] = (VP56mv) {0,0};
184 9216 break;
185 13235 case VP56_MB_INTER_DELTA_PF:
186 13235 s->parse_vector_adjustment(s, &s->mv[b]);
187 13235 break;
188 13083 case VP56_MB_INTER_V1_PF:
189 13083 s->mv[b] = s->vector_candidate[0];
190 13083 break;
191 8682 case VP56_MB_INTER_V2_PF:
192 8682 s->mv[b] = s->vector_candidate[1];
193 8682 break;
194 }
195 44216 mv.x += s->mv[b].x;
196 44216 mv.y += s->mv[b].y;
197 }
198
199 /* this is the one selected for the whole MB for prediction */
200 11054 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 5676 times.
11054 s->mv[4].x = s->mv[5].x = RSHIFT(mv.x,2);
204
2/2
✓ Branch 0 taken 4966 times.
✓ Branch 1 taken 6088 times.
11054 s->mv[4].y = s->mv[5].y = RSHIFT(mv.y,2);
205 11054 }
206
207 237505 static VP56mb vp56_decode_mv(VP56Context *s, int row, int col)
208 {
209 237505 VP56mv *mv, vect = {0,0};
210 int ctx, b;
211
212 237505 ctx = vp56_get_vectors_predictors(s, row, col, VP56_FRAME_PREVIOUS);
213 237505 s->mb_type = vp56_parse_mb_type(s, s->mb_type, ctx);
214 237505 s->macroblocks[row * s->mb_width + col].type = s->mb_type;
215
216
8/8
✓ Branch 0 taken 37090 times.
✓ Branch 1 taken 11549 times.
✓ Branch 2 taken 1054 times.
✓ Branch 3 taken 160 times.
✓ Branch 4 taken 14865 times.
✓ Branch 5 taken 1444 times.
✓ Branch 6 taken 11054 times.
✓ Branch 7 taken 160289 times.
237505 switch (s->mb_type) {
217 37090 case VP56_MB_INTER_V1_PF:
218 37090 mv = &s->vector_candidate[0];
219 37090 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 14865 case VP56_MB_INTER_DELTA_PF:
236 14865 s->parse_vector_adjustment(s, &vect);
237 14865 mv = &vect;
238 14865 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 11054 case VP56_MB_INTER_4V:
247 11054 vp56_decode_4mv(s, row, col);
248 11054 return s->mb_type;
249
250 160289 default:
251 160289 mv = &vect;
252 160289 break;
253 }
254
255 226451 s->macroblocks[row*s->mb_width + col].mv = *mv;
256
257 /* same vector for all blocks */
258
2/2
✓ Branch 0 taken 1358706 times.
✓ Branch 1 taken 226451 times.
1585157 for (b=0; b<6; b++)
259 1358706 s->mv[b] = *mv;
260
261 226451 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 247690 static void vp56_add_predictors_dc(VP56Context *s, VP56Frame ref_frame)
284 {
285 247690 int idx = s->idct_scantable[0];
286 int b;
287
288
2/2
✓ Branch 0 taken 1486140 times.
✓ Branch 1 taken 247690 times.
1733830 for (b=0; b<6; b++) {
289 1486140 VP56RefDc *ab = &s->above_blocks[s->above_block_idx[b]];
290 1486140 VP56RefDc *lb = &s->left_block[ff_vp56_b6to4[b]];
291 1486140 int count = 0;
292 1486140 int dc = 0;
293 int i;
294
295
2/2
✓ Branch 0 taken 1396708 times.
✓ Branch 1 taken 89432 times.
1486140 if (ref_frame == lb->ref_frame) {
296 1396708 dc += lb->dc_coeff;
297 1396708 count++;
298 }
299
2/2
✓ Branch 0 taken 1366264 times.
✓ Branch 1 taken 119876 times.
1486140 if (ref_frame == ab->ref_frame) {
300 1366264 dc += ab->dc_coeff;
301 1366264 count++;
302 }
303
2/2
✓ Branch 0 taken 901056 times.
✓ Branch 1 taken 585084 times.
1486140 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 19291 times.
✓ Branch 1 taken 1466849 times.
1486140 if (count == 0)
310 19291 dc = s->prev_dc[ff_vp56_b2p[b]][ref_frame];
311
2/2
✓ Branch 0 taken 1368235 times.
✓ Branch 1 taken 98614 times.
1466849 else if (count == 2)
312 1368235 dc /= 2;
313
314 1486140 s->block_coeff[b][idx] += dc;
315 1486140 s->prev_dc[ff_vp56_b2p[b]][ref_frame] = s->block_coeff[b][idx];
316 1486140 ab->dc_coeff = s->block_coeff[b][idx];
317 1486140 ab->ref_frame = ref_frame;
318 1486140 lb->dc_coeff = s->block_coeff[b][idx];
319 1486140 lb->ref_frame = ref_frame;
320 1486140 s->block_coeff[b][idx] *= s->dequant_dc;
321 }
322 247690 }
323
324 423784 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 174166 times.
423784 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 174166 int * bounding_values = s->bounding_values_array + 127;
333
2/2
✓ Branch 0 taken 66268 times.
✓ Branch 1 taken 107898 times.
174166 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 110884 times.
174166 if (dy)
336 63282 ff_vp3dsp_v_loop_filter_12(yuv + stride*(10-dy), stride, bounding_values);
337 }
338 423784 }
339
340 450982 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 450982 uint8_t *dst = s->frames[VP56_FRAME_CURRENT]->data[plane] + s->block_offset[b];
344 uint8_t *src_block;
345 int src_offset;
346 450982 int overlap_offset = 0;
347 450982 int mask = s->vp56_coord_div[b] - 1;
348 450982 int deblock_filtering = s->deblock_filtering;
349 int dx;
350 int dy;
351
352
1/2
✓ Branch 0 taken 450982 times.
✗ Branch 1 not taken.
450982 if (s->avctx->skip_loop_filter >= AVDISCARD_ALL ||
353
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 450982 times.
450982 (s->avctx->skip_loop_filter >= AVDISCARD_NONKEY
354 && !(s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY)))
355 deblock_filtering = 0;
356
357 450982 dx = s->mv[b].x / s->vp56_coord_div[b];
358 450982 dy = s->mv[b].y / s->vp56_coord_div[b];
359
360
2/2
✓ Branch 0 taken 142122 times.
✓ Branch 1 taken 308860 times.
450982 if (b >= 4) {
361 142122 x /= 2;
362 142122 y /= 2;
363 }
364 450982 x += dx - 2;
365 450982 y += dy - 2;
366
367
4/4
✓ Branch 0 taken 6924 times.
✓ Branch 1 taken 444058 times.
✓ Branch 2 taken 282 times.
✓ Branch 3 taken 6642 times.
450982 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 440960 times.
✓ Branch 1 taken 9740 times.
✓ Branch 2 taken 425323 times.
✓ Branch 3 taken 15637 times.
✓ Branch 4 taken 415363 times.
✓ Branch 5 taken 9960 times.
450700 } else if (x<0 || x+12>=s->plane_width[plane] ||
378
2/2
✓ Branch 0 taken 19802 times.
✓ Branch 1 taken 395561 times.
415363 y<0 || y+12>=s->plane_height[plane]) {
379 55139 s->vdsp.emulated_edge_mc(s->edge_emu_buffer,
380 55139 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 55139 src_block = s->edge_emu_buffer;
386 55139 src_offset = 2 + 2*stride;
387
2/2
✓ Branch 0 taken 375632 times.
✓ Branch 1 taken 19929 times.
395561 } else if (deblock_filtering) {
388 /* only need a 12x12 block, but there is no such dsp function, */
389 /* so copy a 16x12 block */
390 375632 s->hdsp.put_pixels_tab[0][0](s->edge_emu_buffer,
391 375632 src + s->block_offset[b] + (dy-2)*stride + (dx-2),
392 stride, 12);
393 375632 src_block = s->edge_emu_buffer;
394 375632 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 423784 times.
✓ Branch 1 taken 27198 times.
450982 if (deblock_filtering)
401 423784 vp56_deblock_filter(s, src_block, stride, dx&7, dy&7);
402
403
2/2
✓ Branch 0 taken 288380 times.
✓ Branch 1 taken 162602 times.
450982 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 281221 times.
✓ Branch 1 taken 169761 times.
450982 if (s->mv[b].y & mask)
406
2/2
✓ Branch 0 taken 126648 times.
✓ Branch 1 taken 154573 times.
281221 overlap_offset += (s->mv[b].y > 0) ? stride : -stride;
407
408
2/2
✓ Branch 0 taken 394058 times.
✓ Branch 1 taken 56924 times.
450982 if (overlap_offset) {
409
2/2
✓ Branch 0 taken 177939 times.
✓ Branch 1 taken 216119 times.
394058 if (s->filter)
410 177939 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 56924 s->hdsp.put_pixels_tab[1][0](dst, src_block+src_offset, stride, 8);
418 }
419 450982 }
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 1245894 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 874367 times.
✓ Branch 1 taken 371527 times.
1245894 if (selector > 10)
432 874367 s->vp3dsp.idct_add(dest, stride, block);
433
2/2
✓ Branch 0 taken 371108 times.
✓ Branch 1 taken 419 times.
371527 else if (selector > 1)
434 371108 ff_vp3dsp_idct10_add(dest, stride, block);
435 else
436 419 s->vp3dsp.idct_dc_add(dest, stride, block);
437 1245894 }
438
439 247690 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 247690 VP56Frame ref_frame = ff_vp56_reference_frame[mb_type];
444 ptrdiff_t ref_stride[4];
445
446 247690 vp56_add_predictors_dc(s, ref_frame);
447
448 247690 frame_current = s->frames[VP56_FRAME_CURRENT];
449 247690 frame_ref = s->frames[ref_frame];
450
3/4
✓ Branch 0 taken 214149 times.
✓ Branch 1 taken 33541 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 214149 times.
247690 if (mb_type != VP56_MB_INTRA && !frame_ref->data[0])
451 return;
452
453 247690 memcpy(ref_stride, s->stride, sizeof(s->stride));
454
4/4
✓ Branch 0 taken 1812 times.
✓ Branch 1 taken 245878 times.
✓ Branch 2 taken 76 times.
✓ Branch 3 taken 1736 times.
247690 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 247690 ab = 6*is_alpha;
461 247690 b_max = 6 - 2*is_alpha;
462
463
3/4
✓ Branch 0 taken 33541 times.
✓ Branch 1 taken 136934 times.
✓ Branch 2 taken 77215 times.
✗ Branch 3 not taken.
247690 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 136934 case VP56_MB_INTER_NOVEC_PF:
473 case VP56_MB_INTER_NOVEC_GF:
474
2/2
✓ Branch 0 taken 794912 times.
✓ Branch 1 taken 136934 times.
931846 for (b=0; b<b_max; b++) {
475 794912 plane = ff_vp56_b2p[b+ab];
476 794912 off = s->block_offset[b];
477 794912 s->hdsp.put_pixels_tab[1][0](frame_current->data[plane] + off,
478 794912 frame_ref->data[plane] + off,
479 s->stride[plane], 8);
480 794912 vp56_idct_add(s, frame_current->data[plane] + off,
481 794912 s->stride[plane], s->block_coeff[b], s->idct_selector[b]);
482 }
483 136934 break;
484
485 77215 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 450982 times.
✓ Branch 1 taken 77215 times.
528197 for (b=0; b<b_max; b++) {
493
4/4
✓ Branch 0 taken 373767 times.
✓ Branch 1 taken 77215 times.
✓ Branch 2 taken 77215 times.
✓ Branch 3 taken 296552 times.
450982 int x_off = b==1 || b==3 ? 8 : 0;
494
8/8
✓ Branch 0 taken 373767 times.
✓ Branch 1 taken 77215 times.
✓ Branch 2 taken 77215 times.
✓ Branch 3 taken 296552 times.
✓ Branch 4 taken 2308 times.
✓ Branch 5 taken 152122 times.
✓ Branch 6 taken 94 times.
✓ Branch 7 taken 2214 times.
450982 int y_off = b==2 || b==3 ? (s->interlaced && s->il_block ? 1 : 8) : 0;
495 450982 plane = ff_vp56_b2p[b+ab];
496 450982 vp56_mc(s, b, plane, frame_ref->data[plane], s->stride[plane],
497 450982 16*col+x_off, 16*row+y_off, ref_stride[plane]);
498 450982 vp56_idct_add(s, frame_current->data[plane] + s->block_offset[b],
499 450982 s->stride[plane], s->block_coeff[b], s->idct_selector[b]);
500 }
501 77215 break;
502 }
503
504
2/2
✓ Branch 0 taken 21204 times.
✓ Branch 1 taken 226486 times.
247690 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 245878 times.
✓ Branch 2 taken 76 times.
✓ Branch 3 taken 1736 times.
247690 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 247328 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 245516 times.
247328 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 237505 times.
247328 if (s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY)
535 9823 mb_type = VP56_MB_INTRA;
536 else
537 237505 mb_type = vp56_decode_mv(s, row, col);
538
539 247328 ret = s->parse_coeff(s);
540
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 247327 times.
247328 if (ret < 0)
541 1 return ret;
542
543 247327 vp56_render_mb(s, row, col, is_alpha, mb_type);
544
545 247327 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 1172 int ff_vp56_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
608 int *got_frame, AVPacket *avpkt)
609 {
610 1172 const uint8_t *buf = avpkt->data;
611 1172 VP56Context *s = avctx->priv_data;
612 1172 AVFrame *const p = s->frames[VP56_FRAME_CURRENT];
613 1172 int remaining_buf_size = avpkt->size;
614 1172 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 986 times.
1172 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 1172 res = s->parse_header(s, buf, alpha_offset);
628
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
1172 if (res < 0)
629 return res;
630
631
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 1158 times.
1172 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 1172 ret = ff_get_buffer(avctx, p, AV_GET_BUFFER_FLAG_REF);
641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1172 times.
1172 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 1079 times.
1172 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 1158 times.
1172 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 1079 times.
1172 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 1172 s->discard_frame = 0;
686
2/2
✓ Branch 0 taken 93 times.
✓ Branch 1 taken 1079 times.
1172 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 1172 times.
1172 if (s->discard_frame)
689 return AVERROR_INVALIDDATA;
690
691
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1172 times.
1172 if ((res = av_frame_ref(rframe, p)) < 0)
692 return res;
693 1172 *got_frame = 1;
694
695 1172 return avpkt->size;
696 }
697
698 1265 static int ff_vp56_decode_mbs(AVCodecContext *avctx, void *data,
699 int jobnr, int threadnr)
700 {
701 1265 VP56Context *s0 = avctx->priv_data;
702 1265 int is_alpha = (jobnr == 1);
703
2/2
✓ Branch 0 taken 93 times.
✓ Branch 1 taken 1172 times.
1265 VP56Context *s = is_alpha ? s0->alpha_context : s0;
704 1265 AVFrame *const p = s->frames[VP56_FRAME_CURRENT];
705 1265 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 1265 int damaged = 0;
710
711
2/2
✓ Branch 0 taken 46 times.
✓ Branch 1 taken 1219 times.
1265 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 1219 p->pict_type = AV_PICTURE_TYPE_P;
718 1219 vp56_parse_mb_type_models(s);
719 1219 s->parse_vector_models(s);
720 1219 s->mb_type = VP56_MB_INTER_NOVEC_PF;
721 }
722
723
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 1265 times.
1265 if (s->parse_coeff_models(s))
724 goto next;
725
726
2/2
✓ Branch 0 taken 302 times.
✓ Branch 1 taken 963 times.
1265 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 1265 memset(s->prev_dc, 0, sizeof(s->prev_dc));
732 1265 s->prev_dc[1][VP56_FRAME_CURRENT] = 128;
733 1265 s->prev_dc[2][VP56_FRAME_CURRENT] = 128;
734
735
2/2
✓ Branch 0 taken 77818 times.
✓ Branch 1 taken 1265 times.
79083 for (block=0; block < 4*s->mb_width+6; block++) {
736 77818 s->above_blocks[block].ref_frame = VP56_FRAME_NONE;
737 77818 s->above_blocks[block].dc_coeff = 0;
738 77818 s->above_blocks[block].not_null_dc = 0;
739 }
740 1265 s->above_blocks[2*s->mb_width + 2].ref_frame = VP56_FRAME_CURRENT;
741 1265 s->above_blocks[3*s->mb_width + 4].ref_frame = VP56_FRAME_CURRENT;
742
743 1265 stride_y = p->linesize[0];
744 1265 stride_uv = p->linesize[1];
745
746
2/2
✓ Branch 0 taken 811 times.
✓ Branch 1 taken 454 times.
1265 if (s->flip < 0)
747 811 mb_offset = 7;
748
749 /* main macroblocks loop */
750
2/2
✓ Branch 0 taken 12329 times.
✓ Branch 1 taken 1265 times.
13594 for (mb_row=0; mb_row<s->mb_height; mb_row++) {
751
2/2
✓ Branch 0 taken 8106 times.
✓ Branch 1 taken 4223 times.
12329 if (s->flip < 0)
752 8106 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 49316 times.
✓ Branch 1 taken 12329 times.
61645 for (block=0; block<4; block++) {
757 49316 s->left_block[block].ref_frame = VP56_FRAME_NONE;
758 49316 s->left_block[block].dc_coeff = 0;
759 49316 s->left_block[block].not_null_dc = 0;
760 }
761 12329 memset(s->coeff_ctx, 0, sizeof(s->coeff_ctx));
762 12329 memset(s->coeff_ctx_last, 24, sizeof(s->coeff_ctx_last));
763
764 12329 s->above_block_idx[0] = 1;
765 12329 s->above_block_idx[1] = 2;
766 12329 s->above_block_idx[2] = 1;
767 12329 s->above_block_idx[3] = 2;
768 12329 s->above_block_idx[4] = 2*s->mb_width + 2 + 1;
769 12329 s->above_block_idx[5] = 3*s->mb_width + 4 + 1;
770
771 12329 s->block_offset[s->frbi] = (mb_row_flip*16 + mb_offset) * stride_y;
772 12329 s->block_offset[s->srbi] = s->block_offset[s->frbi] + 8*stride_y;
773 12329 s->block_offset[1] = s->block_offset[0] + 8;
774 12329 s->block_offset[3] = s->block_offset[2] + 8;
775 12329 s->block_offset[4] = (mb_row_flip*8 + mb_offset) * stride_uv;
776 12329 s->block_offset[5] = s->block_offset[4];
777
778
2/2
✓ Branch 0 taken 247690 times.
✓ Branch 1 taken 12329 times.
260019 for (mb_col=0; mb_col<s->mb_width; mb_col++) {
779
2/2
✓ Branch 0 taken 247328 times.
✓ Branch 1 taken 362 times.
247690 if (!damaged) {
780 247328 int ret = vp56_decode_mb(s, mb_row, mb_col, is_alpha);
781
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 247327 times.
247328 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 247327 times.
247690 if (damaged)
790 363 vp56_conceal_mb(s, mb_row, mb_col, is_alpha);
791
792
2/2
✓ Branch 0 taken 990760 times.
✓ Branch 1 taken 247690 times.
1238450 for (y=0; y<4; y++) {
793 990760 s->above_block_idx[y] += 2;
794 990760 s->block_offset[y] += 16;
795 }
796
797
2/2
✓ Branch 0 taken 495380 times.
✓ Branch 1 taken 247690 times.
743070 for (uv=4; uv<6; uv++) {
798 495380 s->above_block_idx[uv] += 1;
799 495380 s->block_offset[uv] += 8;
800 }
801 }
802 }
803
804
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1264 times.
1265 if (!damaged)
805 1264 s->have_undamaged_frame = 1;
806
807 1 next:
808
4/4
✓ Branch 0 taken 1219 times.
✓ Branch 1 taken 46 times.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 1186 times.
1265 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 1265 av_frame_unref(s->frames[VP56_FRAME_PREVIOUS]);
814 1265 FFSWAP(AVFrame *, s->frames[VP56_FRAME_CURRENT],
815 s->frames[VP56_FRAME_PREVIOUS]);
816 1265 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