| 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 | 1264 | void ff_vp56_init_dequant(VP56Context *s, int quantizer) | |
| 37 | { | ||
| 38 |
2/2✓ Branch 0 taken 410 times.
✓ Branch 1 taken 854 times.
|
1264 | if (s->quantizer != quantizer) |
| 39 | 410 | ff_vp3dsp_set_bounding_values(s->bounding_values_array, ff_vp56_filter_threshold[quantizer]); | |
| 40 | 1264 | s->quantizer = quantizer; | |
| 41 | 1264 | s->dequant_dc = ff_vp56_dc_dequant[quantizer] << 2; | |
| 42 | 1264 | s->dequant_ac = ff_vp56_ac_dequant[quantizer] << 2; | |
| 43 | 1264 | } | |
| 44 | |||
| 45 | 240114 | static int vp56_get_vectors_predictors(VP56Context *s, int row, int col, | |
| 46 | VP56Frame ref_frame) | ||
| 47 | { | ||
| 48 | 240114 | int nb_pred = 0; | |
| 49 | 240114 | VP56mv vect[2] = {{0,0}, {0,0}}; | |
| 50 | int pos, offset; | ||
| 51 | VP56mv mvp; | ||
| 52 | |||
| 53 |
2/2✓ Branch 0 taken 2296366 times.
✓ Branch 1 taken 162577 times.
|
2458943 | for (pos=0; pos<12; pos++) { |
| 54 | 2296366 | mvp.x = col + ff_vp56_candidate_predictor_pos[pos][0]; | |
| 55 | 2296366 | mvp.y = row + ff_vp56_candidate_predictor_pos[pos][1]; | |
| 56 |
4/4✓ Branch 0 taken 2196802 times.
✓ Branch 1 taken 99564 times.
✓ Branch 2 taken 2138631 times.
✓ Branch 3 taken 58171 times.
|
2296366 | if (mvp.x < 0 || mvp.x >= s->mb_width || |
| 57 |
3/4✓ Branch 0 taken 1919906 times.
✓ Branch 1 taken 218725 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1919906 times.
|
2138631 | mvp.y < 0 || mvp.y >= s->mb_height) |
| 58 | 376460 | continue; | |
| 59 | 1919906 | offset = mvp.x + s->mb_width*mvp.y; | |
| 60 | |||
| 61 |
2/2✓ Branch 0 taken 332000 times.
✓ Branch 1 taken 1587906 times.
|
1919906 | if (ff_vp56_reference_frame[s->macroblocks[offset].type] != ref_frame) |
| 62 | 332000 | continue; | |
| 63 |
2/2✓ Branch 0 taken 1295926 times.
✓ Branch 1 taken 291980 times.
|
1587906 | if ((s->macroblocks[offset].mv.x == vect[0].x && |
| 64 |
2/2✓ Branch 0 taken 76354 times.
✓ Branch 1 taken 1219572 times.
|
1295926 | s->macroblocks[offset].mv.y == vect[0].y) || |
| 65 |
2/2✓ Branch 0 taken 208346 times.
✓ Branch 1 taken 159988 times.
|
368334 | (s->macroblocks[offset].mv.x == 0 && |
| 66 |
2/2✓ Branch 0 taken 177388 times.
✓ Branch 1 taken 30958 times.
|
208346 | s->macroblocks[offset].mv.y == 0)) |
| 67 | 1396960 | continue; | |
| 68 | |||
| 69 | 190946 | vect[nb_pred++] = s->macroblocks[offset].mv; | |
| 70 |
2/2✓ Branch 0 taken 77537 times.
✓ Branch 1 taken 113409 times.
|
190946 | if (nb_pred > 1) { |
| 71 | 77537 | nb_pred = -1; | |
| 72 | 77537 | break; | |
| 73 | } | ||
| 74 | 113409 | s->vector_candidate_pos = pos; | |
| 75 | } | ||
| 76 | |||
| 77 | 240114 | s->vector_candidate[0] = vect[0]; | |
| 78 | 240114 | s->vector_candidate[1] = vect[1]; | |
| 79 | |||
| 80 | 240114 | return nb_pred+1; | |
| 81 | } | ||
| 82 | |||
| 83 | 1218 | static void vp56_parse_mb_type_models(VP56Context *s) | |
| 84 | { | ||
| 85 | 1218 | VPXRangeCoder *c = &s->c; | |
| 86 | 1218 | VP56Model *model = s->modelp; | |
| 87 | int i, ctx, type; | ||
| 88 | |||
| 89 |
2/2✓ Branch 0 taken 3654 times.
✓ Branch 1 taken 1218 times.
|
4872 | for (ctx=0; ctx<3; ctx++) { |
| 90 |
2/2✓ Branch 1 taken 730 times.
✓ Branch 2 taken 2924 times.
|
3654 | 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 3537 times.
|
3654 | 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 3654 times.
✓ Branch 1 taken 1218 times.
|
4872 | for (ctx=0; ctx<3; ctx++) { |
| 115 | int p[10]; | ||
| 116 | |||
| 117 |
2/2✓ Branch 0 taken 36540 times.
✓ Branch 1 taken 3654 times.
|
40194 | for (type=0; type<10; type++) |
| 118 | 36540 | p[type] = 100 * model->mb_types_stats[ctx][type][1]; | |
| 119 | |||
| 120 |
2/2✓ Branch 0 taken 36540 times.
✓ Branch 1 taken 3654 times.
|
40194 | for (type=0; type<10; type++) { |
| 121 | int p02, p34, p0234, p17, p56, p89, p5689, p156789; | ||
| 122 | |||
| 123 | /* conservative MB type probability */ | ||
| 124 | 36540 | 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 | 36540 | p[type] = 0; /* same MB type => weight is null */ | |
| 127 | |||
| 128 | /* binary tree parsing probabilities */ | ||
| 129 | 36540 | p02 = p[0] + p[2]; | |
| 130 | 36540 | p34 = p[3] + p[4]; | |
| 131 | 36540 | p0234 = p02 + p34; | |
| 132 | 36540 | p17 = p[1] + p[7]; | |
| 133 | 36540 | p56 = p[5] + p[6]; | |
| 134 | 36540 | p89 = p[8] + p[9]; | |
| 135 | 36540 | p5689 = p56 + p89; | |
| 136 | 36540 | p156789 = p17 + p5689; | |
| 137 | |||
| 138 | 36540 | model->mb_type[ctx][type][1] = 1 + 255 * p0234/(1+p0234+p156789); | |
| 139 | 36540 | model->mb_type[ctx][type][2] = 1 + 255 * p02 / (1+p0234); | |
| 140 | 36540 | model->mb_type[ctx][type][3] = 1 + 255 * p17 / (1+p156789); | |
| 141 | 36540 | model->mb_type[ctx][type][4] = 1 + 255 * p[0] / (1+p02); | |
| 142 | 36540 | model->mb_type[ctx][type][5] = 1 + 255 * p[3] / (1+p34); | |
| 143 | 36540 | model->mb_type[ctx][type][6] = 1 + 255 * p[1] / (1+p17); | |
| 144 | 36540 | model->mb_type[ctx][type][7] = 1 + 255 * p56 / (1+p5689); | |
| 145 | 36540 | model->mb_type[ctx][type][8] = 1 + 255 * p[5] / (1+p56); | |
| 146 | 36540 | model->mb_type[ctx][type][9] = 1 + 255 * p[8] / (1+p89); | |
| 147 | |||
| 148 | /* restore initial value */ | ||
| 149 | 36540 | p[type] = 100 * model->mb_types_stats[ctx][type][1]; | |
| 150 | } | ||
| 151 | } | ||
| 152 | 1218 | } | |
| 153 | |||
| 154 | 237456 | static VP56mb vp56_parse_mb_type(VP56Context *s, | |
| 155 | VP56mb prev_type, int ctx) | ||
| 156 | { | ||
| 157 | 237456 | uint8_t *mb_type_model = s->modelp->mb_type[ctx][prev_type]; | |
| 158 | 237456 | VPXRangeCoder *c = &s->c; | |
| 159 | |||
| 160 |
2/2✓ Branch 1 taken 179903 times.
✓ Branch 2 taken 57553 times.
|
237456 | if (vpx_rac_get_prob_branchy(c, mb_type_model[0])) |
| 161 | 179903 | return prev_type; | |
| 162 | else | ||
| 163 | 57553 | return vp56_rac_get_tree(c, ff_vp56_pmbt_tree, mb_type_model); | |
| 164 | } | ||
| 165 | |||
| 166 | 11044 | static void vp56_decode_4mv(VP56Context *s, int row, int col) | |
| 167 | { | ||
| 168 | 11044 | VP56mv mv = {0,0}; | |
| 169 | int type[4]; | ||
| 170 | int b; | ||
| 171 | |||
| 172 | /* parse each block type */ | ||
| 173 |
2/2✓ Branch 0 taken 44176 times.
✓ Branch 1 taken 11044 times.
|
55220 | for (b=0; b<4; b++) { |
| 174 | 44176 | type[b] = vp56_rac_gets(&s->c, 2); | |
| 175 |
2/2✓ Branch 0 taken 34983 times.
✓ Branch 1 taken 9193 times.
|
44176 | if (type[b]) |
| 176 | 34983 | type[b]++; /* only returns 0, 2, 3 or 4 (all INTER_PF) */ | |
| 177 | } | ||
| 178 | |||
| 179 | /* get vectors */ | ||
| 180 |
2/2✓ Branch 0 taken 44176 times.
✓ Branch 1 taken 11044 times.
|
55220 | for (b=0; b<4; b++) { |
| 181 |
4/5✓ Branch 0 taken 9193 times.
✓ Branch 1 taken 13235 times.
✓ Branch 2 taken 13066 times.
✓ Branch 3 taken 8682 times.
✗ Branch 4 not taken.
|
44176 | switch (type[b]) { |
| 182 | 9193 | case VP56_MB_INTER_NOVEC_PF: | |
| 183 | 9193 | s->mv[b] = (VP56mv) {0,0}; | |
| 184 | 9193 | break; | |
| 185 | 13235 | case VP56_MB_INTER_DELTA_PF: | |
| 186 | 13235 | s->parse_vector_adjustment(s, &s->mv[b]); | |
| 187 | 13235 | break; | |
| 188 | 13066 | case VP56_MB_INTER_V1_PF: | |
| 189 | 13066 | s->mv[b] = s->vector_candidate[0]; | |
| 190 | 13066 | break; | |
| 191 | 8682 | case VP56_MB_INTER_V2_PF: | |
| 192 | 8682 | s->mv[b] = s->vector_candidate[1]; | |
| 193 | 8682 | break; | |
| 194 | } | ||
| 195 | 44176 | mv.x += s->mv[b].x; | |
| 196 | 44176 | mv.y += s->mv[b].y; | |
| 197 | } | ||
| 198 | |||
| 199 | /* this is the one selected for the whole MB for prediction */ | ||
| 200 | 11044 | 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 5666 times.
|
11044 | s->mv[4].x = s->mv[5].x = RSHIFT(mv.x,2); |
| 204 |
2/2✓ Branch 0 taken 4966 times.
✓ Branch 1 taken 6078 times.
|
11044 | s->mv[4].y = s->mv[5].y = RSHIFT(mv.y,2); |
| 205 | 11044 | } | |
| 206 | |||
| 207 | 237456 | static VP56mb vp56_decode_mv(VP56Context *s, int row, int col) | |
| 208 | { | ||
| 209 | 237456 | VP56mv *mv, vect = {0,0}; | |
| 210 | int ctx, b; | ||
| 211 | |||
| 212 | 237456 | ctx = vp56_get_vectors_predictors(s, row, col, VP56_FRAME_PREVIOUS); | |
| 213 | 237456 | s->mb_type = vp56_parse_mb_type(s, s->mb_type, ctx); | |
| 214 | 237456 | s->macroblocks[row * s->mb_width + col].type = s->mb_type; | |
| 215 | |||
| 216 |
8/8✓ Branch 0 taken 37072 times.
✓ Branch 1 taken 11549 times.
✓ Branch 2 taken 1054 times.
✓ Branch 3 taken 160 times.
✓ Branch 4 taken 14864 times.
✓ Branch 5 taken 1444 times.
✓ Branch 6 taken 11044 times.
✓ Branch 7 taken 160269 times.
|
237456 | switch (s->mb_type) { |
| 217 | 37072 | case VP56_MB_INTER_V1_PF: | |
| 218 | 37072 | mv = &s->vector_candidate[0]; | |
| 219 | 37072 | 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 | 14864 | case VP56_MB_INTER_DELTA_PF: | |
| 236 | 14864 | s->parse_vector_adjustment(s, &vect); | |
| 237 | 14864 | mv = &vect; | |
| 238 | 14864 | 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 | 11044 | case VP56_MB_INTER_4V: | |
| 247 | 11044 | vp56_decode_4mv(s, row, col); | |
| 248 | 11044 | return s->mb_type; | |
| 249 | |||
| 250 | 160269 | default: | |
| 251 | 160269 | mv = &vect; | |
| 252 | 160269 | break; | |
| 253 | } | ||
| 254 | |||
| 255 | 226412 | s->macroblocks[row*s->mb_width + col].mv = *mv; | |
| 256 | |||
| 257 | /* same vector for all blocks */ | ||
| 258 |
2/2✓ Branch 0 taken 1358472 times.
✓ Branch 1 taken 226412 times.
|
1584884 | for (b=0; b<6; b++) |
| 259 | 1358472 | s->mv[b] = *mv; | |
| 260 | |||
| 261 | 226412 | 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 | 247641 | static void vp56_add_predictors_dc(VP56Context *s, VP56Frame ref_frame) | |
| 284 | { | ||
| 285 | 247641 | int idx = s->idct_scantable[0]; | |
| 286 | int b; | ||
| 287 | |||
| 288 |
2/2✓ Branch 0 taken 1485846 times.
✓ Branch 1 taken 247641 times.
|
1733487 | for (b=0; b<6; b++) { |
| 289 | 1485846 | VP56RefDc *ab = &s->above_blocks[s->above_block_idx[b]]; | |
| 290 | 1485846 | VP56RefDc *lb = &s->left_block[ff_vp56_b6to4[b]]; | |
| 291 | 1485846 | int count = 0; | |
| 292 | 1485846 | int dc = 0; | |
| 293 | int i; | ||
| 294 | |||
| 295 |
2/2✓ Branch 0 taken 1396446 times.
✓ Branch 1 taken 89400 times.
|
1485846 | if (ref_frame == lb->ref_frame) { |
| 296 | 1396446 | dc += lb->dc_coeff; | |
| 297 | 1396446 | count++; | |
| 298 | } | ||
| 299 |
2/2✓ Branch 0 taken 1366006 times.
✓ Branch 1 taken 119840 times.
|
1485846 | if (ref_frame == ab->ref_frame) { |
| 300 | 1366006 | dc += ab->dc_coeff; | |
| 301 | 1366006 | count++; | |
| 302 | } | ||
| 303 |
2/2✓ Branch 0 taken 901056 times.
✓ Branch 1 taken 584790 times.
|
1485846 | 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 19285 times.
✓ Branch 1 taken 1466561 times.
|
1485846 | if (count == 0) |
| 310 | 19285 | dc = s->prev_dc[ff_vp56_b2p[b]][ref_frame]; | |
| 311 |
2/2✓ Branch 0 taken 1368003 times.
✓ Branch 1 taken 98558 times.
|
1466561 | else if (count == 2) |
| 312 | 1368003 | dc /= 2; | |
| 313 | |||
| 314 | 1485846 | s->block_coeff[b][idx] += dc; | |
| 315 | 1485846 | s->prev_dc[ff_vp56_b2p[b]][ref_frame] = s->block_coeff[b][idx]; | |
| 316 | 1485846 | ab->dc_coeff = s->block_coeff[b][idx]; | |
| 317 | 1485846 | ab->ref_frame = ref_frame; | |
| 318 | 1485846 | lb->dc_coeff = s->block_coeff[b][idx]; | |
| 319 | 1485846 | lb->ref_frame = ref_frame; | |
| 320 | 1485846 | s->block_coeff[b][idx] *= s->dequant_dc; | |
| 321 | } | ||
| 322 | 247641 | } | |
| 323 | |||
| 324 | 423610 | 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 173992 times.
|
423610 | 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->vp5dsp.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->vp5dsp.edge_filter_ver(yuv + stride*(10-dy), stride, t); |
| 331 | } else { | ||
| 332 | 173992 | int * bounding_values = s->bounding_values_array + 127; | |
| 333 |
2/2✓ Branch 0 taken 66268 times.
✓ Branch 1 taken 107724 times.
|
173992 | 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 110710 times.
|
173992 | if (dy) |
| 336 | 63282 | ff_vp3dsp_v_loop_filter_12(yuv + stride*(10-dy), stride, bounding_values); | |
| 337 | } | ||
| 338 | 423610 | } | |
| 339 | |||
| 340 | 450808 | 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 | 450808 | uint8_t *dst = s->frames[VP56_FRAME_CURRENT]->data[plane] + s->block_offset[b]; | |
| 344 | uint8_t *src_block; | ||
| 345 | int src_offset; | ||
| 346 | 450808 | int overlap_offset = 0; | |
| 347 | 450808 | int mask = s->vp56_coord_div[b] - 1; | |
| 348 | 450808 | int deblock_filtering = s->deblock_filtering; | |
| 349 | int dx; | ||
| 350 | int dy; | ||
| 351 | |||
| 352 |
1/2✓ Branch 0 taken 450808 times.
✗ Branch 1 not taken.
|
450808 | if (s->avctx->skip_loop_filter >= AVDISCARD_ALL || |
| 353 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 450808 times.
|
450808 | (s->avctx->skip_loop_filter >= AVDISCARD_NONKEY |
| 354 | ✗ | && !(s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY))) | |
| 355 | ✗ | deblock_filtering = 0; | |
| 356 | |||
| 357 | 450808 | dx = s->mv[b].x / s->vp56_coord_div[b]; | |
| 358 | 450808 | dy = s->mv[b].y / s->vp56_coord_div[b]; | |
| 359 | |||
| 360 |
2/2✓ Branch 0 taken 142064 times.
✓ Branch 1 taken 308744 times.
|
450808 | if (b >= 4) { |
| 361 | 142064 | x /= 2; | |
| 362 | 142064 | y /= 2; | |
| 363 | } | ||
| 364 | 450808 | x += dx - 2; | |
| 365 | 450808 | y += dy - 2; | |
| 366 | |||
| 367 |
4/4✓ Branch 0 taken 6924 times.
✓ Branch 1 taken 443884 times.
✓ Branch 2 taken 282 times.
✓ Branch 3 taken 6642 times.
|
450808 | 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 440798 times.
✓ Branch 1 taken 9728 times.
✓ Branch 2 taken 425177 times.
✓ Branch 3 taken 15621 times.
✓ Branch 4 taken 415217 times.
✓ Branch 5 taken 9960 times.
|
450526 | } else if (x<0 || x+12>=s->plane_width[plane] || |
| 378 |
2/2✓ Branch 0 taken 19798 times.
✓ Branch 1 taken 395419 times.
|
415217 | y<0 || y+12>=s->plane_height[plane]) { |
| 379 | 55107 | s->vdsp.emulated_edge_mc(s->edge_emu_buffer, | |
| 380 | 55107 | 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 | 55107 | src_block = s->edge_emu_buffer; | |
| 386 | 55107 | src_offset = 2 + 2*stride; | |
| 387 |
2/2✓ Branch 0 taken 375490 times.
✓ Branch 1 taken 19929 times.
|
395419 | } else if (deblock_filtering) { |
| 388 | /* only need a 12x12 block, but there is no such dsp function, */ | ||
| 389 | /* so copy a 16x12 block */ | ||
| 390 | 375490 | s->hdsp.put_pixels_tab[0][0](s->edge_emu_buffer, | |
| 391 | 375490 | src + s->block_offset[b] + (dy-2)*stride + (dx-2), | |
| 392 | stride, 12); | ||
| 393 | 375490 | src_block = s->edge_emu_buffer; | |
| 394 | 375490 | 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 423610 times.
✓ Branch 1 taken 27198 times.
|
450808 | if (deblock_filtering) |
| 401 | 423610 | vp56_deblock_filter(s, src_block, stride, dx&7, dy&7); | |
| 402 | |||
| 403 |
2/2✓ Branch 0 taken 288380 times.
✓ Branch 1 taken 162428 times.
|
450808 | 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 281078 times.
✓ Branch 1 taken 169730 times.
|
450808 | if (s->mv[b].y & mask) |
| 406 |
2/2✓ Branch 0 taken 126505 times.
✓ Branch 1 taken 154573 times.
|
281078 | overlap_offset += (s->mv[b].y > 0) ? stride : -stride; |
| 407 | |||
| 408 |
2/2✓ Branch 0 taken 393915 times.
✓ Branch 1 taken 56893 times.
|
450808 | if (overlap_offset) { |
| 409 |
2/2✓ Branch 0 taken 177796 times.
✓ Branch 1 taken 216119 times.
|
393915 | if (s->filter) |
| 410 | 177796 | 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 | 56893 | s->hdsp.put_pixels_tab[1][0](dst, src_block+src_offset, stride, 8); | |
| 418 | } | ||
| 419 | 450808 | } | |
| 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 | 1245600 | 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 874239 times.
✓ Branch 1 taken 371361 times.
|
1245600 | if (selector > 10) |
| 432 | 874239 | s->vp3dsp.idct_add(dest, stride, block); | |
| 433 |
2/2✓ Branch 0 taken 370942 times.
✓ Branch 1 taken 419 times.
|
371361 | else if (selector > 1) |
| 434 | 370942 | ff_vp3dsp_idct10_add(dest, stride, block); | |
| 435 | else | ||
| 436 | 419 | s->vp3dsp.idct_dc_add(dest, stride, block); | |
| 437 | 1245600 | } | |
| 438 | |||
| 439 | 247641 | 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 | 247641 | VP56Frame ref_frame = ff_vp56_reference_frame[mb_type]; | |
| 444 | ptrdiff_t ref_stride[4]; | ||
| 445 | |||
| 446 | 247641 | vp56_add_predictors_dc(s, ref_frame); | |
| 447 | |||
| 448 | 247641 | frame_current = s->frames[VP56_FRAME_CURRENT]; | |
| 449 | 247641 | frame_ref = s->frames[ref_frame]; | |
| 450 |
3/4✓ Branch 0 taken 214100 times.
✓ Branch 1 taken 33541 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 214100 times.
|
247641 | if (mb_type != VP56_MB_INTRA && !frame_ref->data[0]) |
| 451 | ✗ | return; | |
| 452 | |||
| 453 | 247641 | memcpy(ref_stride, s->stride, sizeof(s->stride)); | |
| 454 |
4/4✓ Branch 0 taken 1812 times.
✓ Branch 1 taken 245829 times.
✓ Branch 2 taken 76 times.
✓ Branch 3 taken 1736 times.
|
247641 | 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 | 247641 | ab = 6*is_alpha; | |
| 461 | 247641 | b_max = 6 - 2*is_alpha; | |
| 462 | |||
| 463 |
3/4✓ Branch 0 taken 33541 times.
✓ Branch 1 taken 136914 times.
✓ Branch 2 taken 77186 times.
✗ Branch 3 not taken.
|
247641 | 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 | 136914 | case VP56_MB_INTER_NOVEC_PF: | |
| 473 | case VP56_MB_INTER_NOVEC_GF: | ||
| 474 |
2/2✓ Branch 0 taken 794792 times.
✓ Branch 1 taken 136914 times.
|
931706 | for (b=0; b<b_max; b++) { |
| 475 | 794792 | plane = ff_vp56_b2p[b+ab]; | |
| 476 | 794792 | off = s->block_offset[b]; | |
| 477 | 794792 | s->hdsp.put_pixels_tab[1][0](frame_current->data[plane] + off, | |
| 478 | 794792 | frame_ref->data[plane] + off, | |
| 479 | s->stride[plane], 8); | ||
| 480 | 794792 | vp56_idct_add(s, frame_current->data[plane] + off, | |
| 481 | 794792 | s->stride[plane], s->block_coeff[b], s->idct_selector[b]); | |
| 482 | } | ||
| 483 | 136914 | break; | |
| 484 | |||
| 485 | 77186 | 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 450808 times.
✓ Branch 1 taken 77186 times.
|
527994 | for (b=0; b<b_max; b++) { |
| 493 |
4/4✓ Branch 0 taken 373622 times.
✓ Branch 1 taken 77186 times.
✓ Branch 2 taken 77186 times.
✓ Branch 3 taken 296436 times.
|
450808 | int x_off = b==1 || b==3 ? 8 : 0; |
| 494 |
8/8✓ Branch 0 taken 373622 times.
✓ Branch 1 taken 77186 times.
✓ Branch 2 taken 77186 times.
✓ Branch 3 taken 296436 times.
✓ Branch 4 taken 2308 times.
✓ Branch 5 taken 152064 times.
✓ Branch 6 taken 94 times.
✓ Branch 7 taken 2214 times.
|
450808 | int y_off = b==2 || b==3 ? (s->interlaced && s->il_block ? 1 : 8) : 0; |
| 495 | 450808 | plane = ff_vp56_b2p[b+ab]; | |
| 496 | 450808 | vp56_mc(s, b, plane, frame_ref->data[plane], s->stride[plane], | |
| 497 | 450808 | 16*col+x_off, 16*row+y_off, ref_stride[plane]); | |
| 498 | 450808 | vp56_idct_add(s, frame_current->data[plane] + s->block_offset[b], | |
| 499 | 450808 | s->stride[plane], s->block_coeff[b], s->idct_selector[b]); | |
| 500 | } | ||
| 501 | 77186 | break; | |
| 502 | } | ||
| 503 | |||
| 504 |
2/2✓ Branch 0 taken 21204 times.
✓ Branch 1 taken 226437 times.
|
247641 | 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 245829 times.
✓ Branch 2 taken 76 times.
✓ Branch 3 taken 1736 times.
|
247641 | 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 | 247279 | 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 245467 times.
|
247279 | 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 237456 times.
|
247279 | if (s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY) |
| 535 | 9823 | mb_type = VP56_MB_INTRA; | |
| 536 | else | ||
| 537 | 237456 | mb_type = vp56_decode_mv(s, row, col); | |
| 538 | |||
| 539 | 247279 | ret = s->parse_coeff(s); | |
| 540 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 247278 times.
|
247279 | if (ret < 0) |
| 541 | 1 | return ret; | |
| 542 | |||
| 543 | 247278 | vp56_render_mb(s, row, col, is_alpha, mb_type); | |
| 544 | |||
| 545 | 247278 | 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 | 1171 | int ff_vp56_decode_frame(AVCodecContext *avctx, AVFrame *rframe, | |
| 608 | int *got_frame, AVPacket *avpkt) | ||
| 609 | { | ||
| 610 | 1171 | const uint8_t *buf = avpkt->data; | |
| 611 | 1171 | VP56Context *s = avctx->priv_data; | |
| 612 | 1171 | AVFrame *const p = s->frames[VP56_FRAME_CURRENT]; | |
| 613 | 1171 | int remaining_buf_size = avpkt->size; | |
| 614 | 1171 | 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 985 times.
|
1171 | 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 | 1171 | res = s->parse_header(s, buf, alpha_offset); | |
| 628 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1171 times.
|
1171 | if (res < 0) |
| 629 | ✗ | return res; | |
| 630 | |||
| 631 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 1157 times.
|
1171 | 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 | 1171 | ret = ff_get_buffer(avctx, p, AV_GET_BUFFER_FLAG_REF); | |
| 641 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1171 times.
|
1171 | 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 1078 times.
|
1171 | 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 1157 times.
|
1171 | 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 1078 times.
|
1171 | 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 | 1171 | s->discard_frame = 0; | |
| 686 |
2/2✓ Branch 0 taken 93 times.
✓ Branch 1 taken 1078 times.
|
1171 | 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 1171 times.
|
1171 | if (s->discard_frame) |
| 689 | ✗ | return AVERROR_INVALIDDATA; | |
| 690 | |||
| 691 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1171 times.
|
1171 | if ((res = av_frame_ref(rframe, p)) < 0) |
| 692 | ✗ | return res; | |
| 693 | 1171 | *got_frame = 1; | |
| 694 | |||
| 695 | 1171 | return avpkt->size; | |
| 696 | } | ||
| 697 | |||
| 698 | 1264 | static int ff_vp56_decode_mbs(AVCodecContext *avctx, void *data, | |
| 699 | int jobnr, int threadnr) | ||
| 700 | { | ||
| 701 | 1264 | VP56Context *s0 = avctx->priv_data; | |
| 702 | 1264 | int is_alpha = (jobnr == 1); | |
| 703 |
2/2✓ Branch 0 taken 93 times.
✓ Branch 1 taken 1171 times.
|
1264 | VP56Context *s = is_alpha ? s0->alpha_context : s0; |
| 704 | 1264 | AVFrame *const p = s->frames[VP56_FRAME_CURRENT]; | |
| 705 | 1264 | 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 | 1264 | int damaged = 0; | |
| 710 | |||
| 711 |
2/2✓ Branch 0 taken 46 times.
✓ Branch 1 taken 1218 times.
|
1264 | 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 | 1218 | p->pict_type = AV_PICTURE_TYPE_P; | |
| 718 | 1218 | vp56_parse_mb_type_models(s); | |
| 719 | 1218 | s->parse_vector_models(s); | |
| 720 | 1218 | s->mb_type = VP56_MB_INTER_NOVEC_PF; | |
| 721 | } | ||
| 722 | |||
| 723 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1264 times.
|
1264 | if (s->parse_coeff_models(s)) |
| 724 | ✗ | goto next; | |
| 725 | |||
| 726 |
2/2✓ Branch 0 taken 302 times.
✓ Branch 1 taken 962 times.
|
1264 | 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 | 1264 | memset(s->prev_dc, 0, sizeof(s->prev_dc)); | |
| 732 | 1264 | s->prev_dc[1][VP56_FRAME_CURRENT] = 128; | |
| 733 | 1264 | s->prev_dc[2][VP56_FRAME_CURRENT] = 128; | |
| 734 | |||
| 735 |
2/2✓ Branch 0 taken 77784 times.
✓ Branch 1 taken 1264 times.
|
79048 | for (block=0; block < 4*s->mb_width+6; block++) { |
| 736 | 77784 | s->above_blocks[block].ref_frame = VP56_FRAME_NONE; | |
| 737 | 77784 | s->above_blocks[block].dc_coeff = 0; | |
| 738 | 77784 | s->above_blocks[block].not_null_dc = 0; | |
| 739 | } | ||
| 740 | 1264 | s->above_blocks[2*s->mb_width + 2].ref_frame = VP56_FRAME_CURRENT; | |
| 741 | 1264 | s->above_blocks[3*s->mb_width + 4].ref_frame = VP56_FRAME_CURRENT; | |
| 742 | |||
| 743 | 1264 | stride_y = p->linesize[0]; | |
| 744 | 1264 | stride_uv = p->linesize[1]; | |
| 745 | |||
| 746 |
2/2✓ Branch 0 taken 810 times.
✓ Branch 1 taken 454 times.
|
1264 | if (s->flip < 0) |
| 747 | 810 | mb_offset = 7; | |
| 748 | |||
| 749 | /* main macroblocks loop */ | ||
| 750 |
2/2✓ Branch 0 taken 12322 times.
✓ Branch 1 taken 1264 times.
|
13586 | for (mb_row=0; mb_row<s->mb_height; mb_row++) { |
| 751 |
2/2✓ Branch 0 taken 8099 times.
✓ Branch 1 taken 4223 times.
|
12322 | if (s->flip < 0) |
| 752 | 8099 | 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 49288 times.
✓ Branch 1 taken 12322 times.
|
61610 | for (block=0; block<4; block++) { |
| 757 | 49288 | s->left_block[block].ref_frame = VP56_FRAME_NONE; | |
| 758 | 49288 | s->left_block[block].dc_coeff = 0; | |
| 759 | 49288 | s->left_block[block].not_null_dc = 0; | |
| 760 | } | ||
| 761 | 12322 | memset(s->coeff_ctx, 0, sizeof(s->coeff_ctx)); | |
| 762 | 12322 | memset(s->coeff_ctx_last, 24, sizeof(s->coeff_ctx_last)); | |
| 763 | |||
| 764 | 12322 | s->above_block_idx[0] = 1; | |
| 765 | 12322 | s->above_block_idx[1] = 2; | |
| 766 | 12322 | s->above_block_idx[2] = 1; | |
| 767 | 12322 | s->above_block_idx[3] = 2; | |
| 768 | 12322 | s->above_block_idx[4] = 2*s->mb_width + 2 + 1; | |
| 769 | 12322 | s->above_block_idx[5] = 3*s->mb_width + 4 + 1; | |
| 770 | |||
| 771 | 12322 | s->block_offset[s->frbi] = (mb_row_flip*16 + mb_offset) * stride_y; | |
| 772 | 12322 | s->block_offset[s->srbi] = s->block_offset[s->frbi] + 8*stride_y; | |
| 773 | 12322 | s->block_offset[1] = s->block_offset[0] + 8; | |
| 774 | 12322 | s->block_offset[3] = s->block_offset[2] + 8; | |
| 775 | 12322 | s->block_offset[4] = (mb_row_flip*8 + mb_offset) * stride_uv; | |
| 776 | 12322 | s->block_offset[5] = s->block_offset[4]; | |
| 777 | |||
| 778 |
2/2✓ Branch 0 taken 247641 times.
✓ Branch 1 taken 12322 times.
|
259963 | for (mb_col=0; mb_col<s->mb_width; mb_col++) { |
| 779 |
2/2✓ Branch 0 taken 247279 times.
✓ Branch 1 taken 362 times.
|
247641 | if (!damaged) { |
| 780 | 247279 | int ret = vp56_decode_mb(s, mb_row, mb_col, is_alpha); | |
| 781 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 247278 times.
|
247279 | 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 247278 times.
|
247641 | if (damaged) |
| 790 | 363 | vp56_conceal_mb(s, mb_row, mb_col, is_alpha); | |
| 791 | |||
| 792 |
2/2✓ Branch 0 taken 990564 times.
✓ Branch 1 taken 247641 times.
|
1238205 | for (y=0; y<4; y++) { |
| 793 | 990564 | s->above_block_idx[y] += 2; | |
| 794 | 990564 | s->block_offset[y] += 16; | |
| 795 | } | ||
| 796 | |||
| 797 |
2/2✓ Branch 0 taken 495282 times.
✓ Branch 1 taken 247641 times.
|
742923 | for (uv=4; uv<6; uv++) { |
| 798 | 495282 | s->above_block_idx[uv] += 1; | |
| 799 | 495282 | s->block_offset[uv] += 8; | |
| 800 | } | ||
| 801 | } | ||
| 802 | } | ||
| 803 | |||
| 804 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1263 times.
|
1264 | if (!damaged) |
| 805 | 1263 | s->have_undamaged_frame = 1; | |
| 806 | |||
| 807 | 1 | next: | |
| 808 |
4/4✓ Branch 0 taken 1218 times.
✓ Branch 1 taken 46 times.
✓ Branch 2 taken 33 times.
✓ Branch 3 taken 1185 times.
|
1264 | 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 | 1264 | av_frame_unref(s->frames[VP56_FRAME_PREVIOUS]); | |
| 814 | 1264 | FFSWAP(AVFrame *, s->frames[VP56_FRAME_CURRENT], | |
| 815 | s->frames[VP56_FRAME_PREVIOUS]); | ||
| 816 | 1264 | 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); | |
| 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 |