| 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 | * VP6 compatible video decoder | ||
| 24 | * | ||
| 25 | * The VP6F decoder accepts an optional 1 byte extradata. It is composed of: | ||
| 26 | * - upper 4 bits: difference between encoded width and visible width | ||
| 27 | * - lower 4 bits: difference between encoded height and visible height | ||
| 28 | */ | ||
| 29 | |||
| 30 | #include <stdlib.h> | ||
| 31 | |||
| 32 | #include "avcodec.h" | ||
| 33 | #include "codec_internal.h" | ||
| 34 | #include "decode.h" | ||
| 35 | #include "get_bits.h" | ||
| 36 | #include "huffman.h" | ||
| 37 | |||
| 38 | #include "vp56.h" | ||
| 39 | #include "vp56data.h" | ||
| 40 | #include "vp6data.h" | ||
| 41 | #include "vpx_rac.h" | ||
| 42 | |||
| 43 | #define VP6_MAX_HUFF_SIZE 12 | ||
| 44 | #define AC_DC_HUFF_BITS 10 | ||
| 45 | #define RUN_HUFF_BITS 8 | ||
| 46 | |||
| 47 | static int vp6_parse_coeff(VP56Context *s); | ||
| 48 | static int vp6_parse_coeff_huffman(VP56Context *s); | ||
| 49 | |||
| 50 | 1017 | static int vp6_parse_header(VP56Context *s, const uint8_t *buf, int buf_size) | |
| 51 | { | ||
| 52 | 1017 | VPXRangeCoder *c = &s->c; | |
| 53 | 1017 | int parse_filter_info = 0; | |
| 54 | 1017 | int coeff_offset = 0; | |
| 55 | 1017 | int vrt_shift = 0; | |
| 56 | int sub_version; | ||
| 57 | int rows, cols; | ||
| 58 | 1017 | int res = 0; | |
| 59 | int ret; | ||
| 60 | 1017 | int separated_coeff = buf[0] & 1; | |
| 61 | |||
| 62 |
2/2✓ Branch 0 taken 41 times.
✓ Branch 1 taken 976 times.
|
1017 | if (!(buf[0] & 0x80)) |
| 63 | 41 | s->frames[VP56_FRAME_CURRENT]->flags |= AV_FRAME_FLAG_KEY; | |
| 64 | else | ||
| 65 | 976 | s->frames[VP56_FRAME_CURRENT]->flags &= ~AV_FRAME_FLAG_KEY; | |
| 66 | 1017 | ff_vp56_init_dequant(s, (buf[0] >> 1) & 0x3F); | |
| 67 | |||
| 68 |
2/2✓ Branch 0 taken 41 times.
✓ Branch 1 taken 976 times.
|
1017 | if (s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY) { |
| 69 | 41 | sub_version = buf[1] >> 3; | |
| 70 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
|
41 | if (sub_version > 8) |
| 71 | ✗ | return AVERROR_INVALIDDATA; | |
| 72 | 41 | s->filter_header = buf[1] & 0x06; | |
| 73 | 41 | s->interlaced = buf[1] & 1; | |
| 74 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 39 times.
|
41 | if (s->interlaced) |
| 75 | 2 | s->def_coeff_reorder = vp6_il_coeff_reorder; | |
| 76 | else | ||
| 77 | 39 | s->def_coeff_reorder = vp6_def_coeff_reorder; | |
| 78 |
3/4✓ Branch 0 taken 28 times.
✓ Branch 1 taken 13 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 28 times.
|
41 | if (separated_coeff || !s->filter_header) { |
| 79 | 13 | coeff_offset = AV_RB16(buf+2) - 2; | |
| 80 | 13 | buf += 2; | |
| 81 | 13 | buf_size -= 2; | |
| 82 | } | ||
| 83 | |||
| 84 | 41 | rows = buf[2]; /* number of stored macroblock rows */ | |
| 85 | 41 | cols = buf[3]; /* number of stored macroblock cols */ | |
| 86 | /* buf[4] is number of displayed macroblock rows */ | ||
| 87 | /* buf[5] is number of displayed macroblock cols */ | ||
| 88 |
2/4✓ Branch 0 taken 41 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 41 times.
|
41 | if (!rows || !cols) { |
| 89 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "Invalid size %dx%d\n", cols << 4, rows << 4); | |
| 90 | ✗ | return AVERROR_INVALIDDATA; | |
| 91 | } | ||
| 92 | |||
| 93 |
2/2✓ Branch 0 taken 28 times.
✓ Branch 1 taken 13 times.
|
41 | if (!s->macroblocks || /* first frame */ |
| 94 |
1/2✓ Branch 0 taken 28 times.
✗ Branch 1 not taken.
|
28 | 16*cols != s->avctx->coded_width || |
| 95 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 28 times.
|
28 | 16*rows != s->avctx->coded_height) { |
| 96 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 2 times.
|
13 | if (s->avctx->extradata_size == 0 && |
| 97 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 5 times.
|
11 | FFALIGN(s->avctx->width, 16) == 16 * cols && |
| 98 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | FFALIGN(s->avctx->height, 16) == 16 * rows) { |
| 99 | // We assume this is properly signalled container cropping, | ||
| 100 | // in an F4V file. Just set the coded_width/height, don't | ||
| 101 | // touch the cropped ones. | ||
| 102 | 6 | s->avctx->coded_width = 16 * cols; | |
| 103 | 6 | s->avctx->coded_height = 16 * rows; | |
| 104 | } else { | ||
| 105 | 7 | ret = ff_set_dimensions(s->avctx, 16 * cols, 16 * rows); | |
| 106 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | if (ret < 0) |
| 107 | ✗ | return ret; | |
| 108 | |||
| 109 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 5 times.
|
7 | if (s->avctx->extradata_size == 1) { |
| 110 | 2 | s->avctx->width -= s->avctx->extradata[0] >> 4; | |
| 111 | 2 | s->avctx->height -= s->avctx->extradata[0] & 0x0F; | |
| 112 | } | ||
| 113 | } | ||
| 114 | 13 | res = VP56_SIZE_CHANGE; | |
| 115 | } | ||
| 116 | |||
| 117 | 41 | ret = ff_vpx_init_range_decoder(c, buf+6, buf_size-6); | |
| 118 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 41 times.
|
41 | if (ret < 0) |
| 119 | ✗ | goto fail; | |
| 120 | 41 | vp56_rac_gets(c, 2); | |
| 121 | |||
| 122 | 41 | parse_filter_info = s->filter_header; | |
| 123 |
2/2✓ Branch 0 taken 16 times.
✓ Branch 1 taken 25 times.
|
41 | if (sub_version < 8) |
| 124 | 16 | vrt_shift = 5; | |
| 125 | 41 | s->sub_version = sub_version; | |
| 126 | 41 | s->golden_frame = 0; | |
| 127 | } else { | ||
| 128 |
3/6✓ Branch 0 taken 976 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 976 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 976 times.
|
976 | if (!s->sub_version || !s->avctx->coded_width || !s->avctx->coded_height) |
| 129 | ✗ | return AVERROR_INVALIDDATA; | |
| 130 | |||
| 131 |
3/4✓ Branch 0 taken 550 times.
✓ Branch 1 taken 426 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 550 times.
|
976 | if (separated_coeff || !s->filter_header) { |
| 132 | 426 | coeff_offset = AV_RB16(buf+1) - 2; | |
| 133 | 426 | buf += 2; | |
| 134 | 426 | buf_size -= 2; | |
| 135 | } | ||
| 136 | 976 | ret = ff_vpx_init_range_decoder(c, buf+1, buf_size-1); | |
| 137 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 976 times.
|
976 | if (ret < 0) |
| 138 | ✗ | return ret; | |
| 139 | |||
| 140 | 976 | s->golden_frame = vpx_rac_get(c); | |
| 141 |
2/2✓ Branch 0 taken 550 times.
✓ Branch 1 taken 426 times.
|
976 | if (s->filter_header) { |
| 142 | 550 | s->deblock_filtering = vpx_rac_get(c); | |
| 143 |
1/2✓ Branch 0 taken 550 times.
✗ Branch 1 not taken.
|
550 | if (s->deblock_filtering) |
| 144 | 550 | vpx_rac_get(c); | |
| 145 |
2/2✓ Branch 0 taken 429 times.
✓ Branch 1 taken 121 times.
|
550 | if (s->sub_version > 7) |
| 146 | 429 | parse_filter_info = vpx_rac_get(c); | |
| 147 | } | ||
| 148 | } | ||
| 149 | |||
| 150 |
2/2✓ Branch 0 taken 167 times.
✓ Branch 1 taken 850 times.
|
1017 | if (parse_filter_info) { |
| 151 |
1/2✓ Branch 1 taken 167 times.
✗ Branch 2 not taken.
|
167 | if (vpx_rac_get(c)) { |
| 152 | 167 | s->filter_mode = 2; | |
| 153 | 167 | s->sample_variance_threshold = vp56_rac_gets(c, 5) << vrt_shift; | |
| 154 | 167 | s->max_vector_length = 2 << vp56_rac_gets(c, 3); | |
| 155 | ✗ | } else if (vpx_rac_get(c)) { | |
| 156 | ✗ | s->filter_mode = 1; | |
| 157 | } else { | ||
| 158 | ✗ | s->filter_mode = 0; | |
| 159 | } | ||
| 160 |
2/2✓ Branch 0 taken 164 times.
✓ Branch 1 taken 3 times.
|
167 | if (s->sub_version > 7) |
| 161 | 164 | s->filter_selection = vp56_rac_gets(c, 4); | |
| 162 | else | ||
| 163 | 3 | s->filter_selection = 16; | |
| 164 | } | ||
| 165 | |||
| 166 | 1017 | s->use_huffman = vpx_rac_get(c); | |
| 167 | |||
| 168 | 1017 | s->parse_coeff = vp6_parse_coeff; | |
| 169 |
2/2✓ Branch 0 taken 439 times.
✓ Branch 1 taken 578 times.
|
1017 | if (coeff_offset) { |
| 170 | 439 | buf += coeff_offset; | |
| 171 | 439 | buf_size -= coeff_offset; | |
| 172 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 439 times.
|
439 | if (buf_size < 0) { |
| 173 | ✗ | ret = AVERROR_INVALIDDATA; | |
| 174 | ✗ | goto fail; | |
| 175 | } | ||
| 176 |
2/2✓ Branch 0 taken 117 times.
✓ Branch 1 taken 322 times.
|
439 | if (s->use_huffman) { |
| 177 | 117 | s->parse_coeff = vp6_parse_coeff_huffman; | |
| 178 | 117 | ret = init_get_bits8(&s->gb, buf, buf_size); | |
| 179 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 117 times.
|
117 | if (ret < 0) |
| 180 | ✗ | return ret; | |
| 181 | } else { | ||
| 182 | 322 | ret = ff_vpx_init_range_decoder(&s->cc, buf, buf_size); | |
| 183 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 322 times.
|
322 | if (ret < 0) |
| 184 | ✗ | goto fail; | |
| 185 | 322 | s->ccp = &s->cc; | |
| 186 | } | ||
| 187 | } else { | ||
| 188 | 578 | s->ccp = &s->c; | |
| 189 | } | ||
| 190 | |||
| 191 | 1017 | return res; | |
| 192 | ✗ | fail: | |
| 193 | ✗ | if (res == VP56_SIZE_CHANGE) | |
| 194 | ✗ | ff_set_dimensions(s->avctx, 0, 0); | |
| 195 | ✗ | return ret; | |
| 196 | } | ||
| 197 | |||
| 198 | 344 | static void vp6_coeff_order_table_init(VP56Context *s) | |
| 199 | { | ||
| 200 | 344 | int i, pos, idx = 1; | |
| 201 | |||
| 202 | 344 | s->modelp->coeff_index_to_pos[0] = 0; | |
| 203 |
2/2✓ Branch 0 taken 5504 times.
✓ Branch 1 taken 344 times.
|
5848 | for (i=0; i<16; i++) |
| 204 |
2/2✓ Branch 0 taken 346752 times.
✓ Branch 1 taken 5504 times.
|
352256 | for (pos=1; pos<64; pos++) |
| 205 |
2/2✓ Branch 0 taken 21672 times.
✓ Branch 1 taken 325080 times.
|
346752 | if (s->modelp->coeff_reorder[pos] == i) |
| 206 | 21672 | s->modelp->coeff_index_to_pos[idx++] = pos; | |
| 207 | |||
| 208 |
2/2✓ Branch 0 taken 22016 times.
✓ Branch 1 taken 344 times.
|
22360 | for (idx = 0; idx < 64; idx++) { |
| 209 | 22016 | int max = 0; | |
| 210 |
2/2✓ Branch 0 taken 715520 times.
✓ Branch 1 taken 22016 times.
|
737536 | for (i = 0; i <= idx; i++) { |
| 211 | 715520 | int v = s->modelp->coeff_index_to_pos[i]; | |
| 212 |
2/2✓ Branch 0 taken 257658 times.
✓ Branch 1 taken 457862 times.
|
715520 | if (v > max) |
| 213 | 257658 | max = v; | |
| 214 | } | ||
| 215 |
2/2✓ Branch 0 taken 2560 times.
✓ Branch 1 taken 19456 times.
|
22016 | if (s->sub_version > 6) |
| 216 | 2560 | max++; | |
| 217 | 22016 | s->modelp->coeff_index_to_idct_selector[idx] = max; | |
| 218 | } | ||
| 219 | 344 | } | |
| 220 | |||
| 221 | 41 | static void vp6_default_models_init(VP56Context *s) | |
| 222 | { | ||
| 223 | 41 | VP56Model *model = s->modelp; | |
| 224 | |||
| 225 | 41 | model->vector_dct[0] = 0xA2; | |
| 226 | 41 | model->vector_dct[1] = 0xA4; | |
| 227 | 41 | model->vector_sig[0] = 0x80; | |
| 228 | 41 | model->vector_sig[1] = 0x80; | |
| 229 | |||
| 230 | 41 | memcpy(model->mb_types_stats, ff_vp56_def_mb_types_stats, sizeof(model->mb_types_stats)); | |
| 231 | 41 | memcpy(model->vector_fdv, vp6_def_fdv_vector_model, sizeof(model->vector_fdv)); | |
| 232 | 41 | memcpy(model->vector_pdv, vp6_def_pdv_vector_model, sizeof(model->vector_pdv)); | |
| 233 | 41 | memcpy(model->coeff_runv, vp6_def_runv_coeff_model, sizeof(model->coeff_runv)); | |
| 234 | 41 | memcpy(model->coeff_reorder, s->def_coeff_reorder, sizeof(model->coeff_reorder)); | |
| 235 | |||
| 236 | 41 | vp6_coeff_order_table_init(s); | |
| 237 | 41 | } | |
| 238 | |||
| 239 | 976 | static void vp6_parse_vector_models(VP56Context *s) | |
| 240 | { | ||
| 241 | 976 | VPXRangeCoder *c = &s->c; | |
| 242 | 976 | VP56Model *model = s->modelp; | |
| 243 | int comp, node; | ||
| 244 | |||
| 245 |
2/2✓ Branch 0 taken 1952 times.
✓ Branch 1 taken 976 times.
|
2928 | for (comp=0; comp<2; comp++) { |
| 246 |
2/2✓ Branch 1 taken 109 times.
✓ Branch 2 taken 1843 times.
|
1952 | if (vpx_rac_get_prob_branchy(c, vp6_sig_dct_pct[comp][0])) |
| 247 | 109 | model->vector_dct[comp] = vp56_rac_gets_nn(c, 7); | |
| 248 |
2/2✓ Branch 1 taken 17 times.
✓ Branch 2 taken 1935 times.
|
1952 | if (vpx_rac_get_prob_branchy(c, vp6_sig_dct_pct[comp][1])) |
| 249 | 17 | model->vector_sig[comp] = vp56_rac_gets_nn(c, 7); | |
| 250 | } | ||
| 251 | |||
| 252 |
2/2✓ Branch 0 taken 1952 times.
✓ Branch 1 taken 976 times.
|
2928 | for (comp=0; comp<2; comp++) |
| 253 |
2/2✓ Branch 0 taken 13664 times.
✓ Branch 1 taken 1952 times.
|
15616 | for (node=0; node<7; node++) |
| 254 |
2/2✓ Branch 1 taken 24 times.
✓ Branch 2 taken 13640 times.
|
13664 | if (vpx_rac_get_prob_branchy(c, vp6_pdv_pct[comp][node])) |
| 255 | 24 | model->vector_pdv[comp][node] = vp56_rac_gets_nn(c, 7); | |
| 256 | |||
| 257 |
2/2✓ Branch 0 taken 1952 times.
✓ Branch 1 taken 976 times.
|
2928 | for (comp=0; comp<2; comp++) |
| 258 |
2/2✓ Branch 0 taken 15616 times.
✓ Branch 1 taken 1952 times.
|
17568 | for (node=0; node<8; node++) |
| 259 |
2/2✓ Branch 1 taken 10 times.
✓ Branch 2 taken 15606 times.
|
15616 | if (vpx_rac_get_prob_branchy(c, vp6_fdv_pct[comp][node])) |
| 260 | 10 | model->vector_fdv[comp][node] = vp56_rac_gets_nn(c, 7); | |
| 261 | 976 | } | |
| 262 | |||
| 263 | /* nodes must ascend by count, but with descending symbol order */ | ||
| 264 | 104420 | static int vp6_huff_cmp(const void *va, const void *vb) | |
| 265 | { | ||
| 266 | 104420 | const Node *a = va, *b = vb; | |
| 267 | 104420 | return (a->count - b->count)*16 + (b->sym - a->sym); | |
| 268 | } | ||
| 269 | |||
| 270 | 3276 | static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[], | |
| 271 | const uint8_t *map, unsigned size, | ||
| 272 | int nb_bits, VLC *vlc) | ||
| 273 | { | ||
| 274 | 3276 | Node nodes[2*VP6_MAX_HUFF_SIZE], *tmp = &nodes[size]; | |
| 275 | int a, b, i; | ||
| 276 | |||
| 277 | /* first compute probabilities from model */ | ||
| 278 | 3276 | tmp[0].count = 256; | |
| 279 |
2/2✓ Branch 0 taken 35334 times.
✓ Branch 1 taken 3276 times.
|
38610 | for (i=0; i<size-1; i++) { |
| 280 | 35334 | a = tmp[i].count * coeff_model[i] >> 8; | |
| 281 | 35334 | b = tmp[i].count * (255 - coeff_model[i]) >> 8; | |
| 282 | 35334 | nodes[map[2*i ]].count = a + !a; | |
| 283 | 35334 | nodes[map[2*i+1]].count = b + !b; | |
| 284 | } | ||
| 285 | |||
| 286 | 3276 | ff_vlc_free(vlc); | |
| 287 | /* then build the huffman tree according to probabilities */ | ||
| 288 | 3276 | return ff_huff_build_tree(s->avctx, vlc, size, nb_bits, | |
| 289 | nodes, vp6_huff_cmp, | ||
| 290 | FF_HUFFMAN_FLAG_HNODE_FIRST); | ||
| 291 | } | ||
| 292 | |||
| 293 | 1017 | static int vp6_parse_coeff_models(VP56Context *s) | |
| 294 | { | ||
| 295 | 1017 | VPXRangeCoder *c = &s->c; | |
| 296 | 1017 | VP56Model *model = s->modelp; | |
| 297 | int def_prob[11]; | ||
| 298 | int node, cg, ctx, pos; | ||
| 299 | int ct; /* code type */ | ||
| 300 | int pt; /* plane type (0 for Y, 1 for U or V) */ | ||
| 301 | int ret; | ||
| 302 | |||
| 303 | 1017 | memset(def_prob, 0x80, sizeof(def_prob)); | |
| 304 | |||
| 305 |
2/2✓ Branch 0 taken 2034 times.
✓ Branch 1 taken 1017 times.
|
3051 | for (pt=0; pt<2; pt++) |
| 306 |
2/2✓ Branch 0 taken 22374 times.
✓ Branch 1 taken 2034 times.
|
24408 | for (node=0; node<11; node++) |
| 307 |
2/2✓ Branch 1 taken 1216 times.
✓ Branch 2 taken 21158 times.
|
22374 | if (vpx_rac_get_prob_branchy(c, vp6_dccv_pct[pt][node])) { |
| 308 | 1216 | def_prob[node] = vp56_rac_gets_nn(c, 7); | |
| 309 | 1216 | model->coeff_dccv[pt][node] = def_prob[node]; | |
| 310 |
2/2✓ Branch 0 taken 601 times.
✓ Branch 1 taken 20557 times.
|
21158 | } else if (s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY) { |
| 311 | 601 | model->coeff_dccv[pt][node] = def_prob[node]; | |
| 312 | } | ||
| 313 | |||
| 314 |
2/2✓ Branch 1 taken 303 times.
✓ Branch 2 taken 714 times.
|
1017 | if (vpx_rac_get(c)) { |
| 315 |
2/2✓ Branch 0 taken 19089 times.
✓ Branch 1 taken 303 times.
|
19392 | for (pos=1; pos<64; pos++) |
| 316 |
2/2✓ Branch 1 taken 15976 times.
✓ Branch 2 taken 3113 times.
|
19089 | if (vpx_rac_get_prob_branchy(c, vp6_coeff_reorder_pct[pos])) |
| 317 | 15976 | model->coeff_reorder[pos] = vp56_rac_gets(c, 4); | |
| 318 | 303 | vp6_coeff_order_table_init(s); | |
| 319 | } | ||
| 320 | |||
| 321 |
2/2✓ Branch 0 taken 2034 times.
✓ Branch 1 taken 1017 times.
|
3051 | for (cg=0; cg<2; cg++) |
| 322 |
2/2✓ Branch 0 taken 28476 times.
✓ Branch 1 taken 2034 times.
|
30510 | for (node=0; node<14; node++) |
| 323 |
2/2✓ Branch 1 taken 887 times.
✓ Branch 2 taken 27589 times.
|
28476 | if (vpx_rac_get_prob_branchy(c, vp6_runv_pct[cg][node])) |
| 324 | 887 | model->coeff_runv[cg][node] = vp56_rac_gets_nn(c, 7); | |
| 325 | |||
| 326 |
2/2✓ Branch 0 taken 3051 times.
✓ Branch 1 taken 1017 times.
|
4068 | for (ct=0; ct<3; ct++) |
| 327 |
2/2✓ Branch 0 taken 6102 times.
✓ Branch 1 taken 3051 times.
|
9153 | for (pt=0; pt<2; pt++) |
| 328 |
2/2✓ Branch 0 taken 36612 times.
✓ Branch 1 taken 6102 times.
|
42714 | for (cg=0; cg<6; cg++) |
| 329 |
2/2✓ Branch 0 taken 402732 times.
✓ Branch 1 taken 36612 times.
|
439344 | for (node=0; node<11; node++) |
| 330 |
2/2✓ Branch 1 taken 5424 times.
✓ Branch 2 taken 397308 times.
|
402732 | if (vpx_rac_get_prob_branchy(c, vp6_ract_pct[ct][pt][cg][node])) { |
| 331 | 5424 | def_prob[node] = vp56_rac_gets_nn(c, 7); | |
| 332 | 5424 | model->coeff_ract[pt][ct][cg][node] = def_prob[node]; | |
| 333 |
2/2✓ Branch 0 taken 14606 times.
✓ Branch 1 taken 382702 times.
|
397308 | } else if (s->frames[VP56_FRAME_CURRENT]->flags & AV_FRAME_FLAG_KEY) { |
| 334 | 14606 | model->coeff_ract[pt][ct][cg][node] = def_prob[node]; | |
| 335 | } | ||
| 336 | |||
| 337 |
2/2✓ Branch 0 taken 117 times.
✓ Branch 1 taken 900 times.
|
1017 | if (s->use_huffman) { |
| 338 |
2/2✓ Branch 0 taken 234 times.
✓ Branch 1 taken 117 times.
|
351 | for (pt=0; pt<2; pt++) { |
| 339 | 234 | ret = vp6_build_huff_tree(s, model->coeff_dccv[pt], | |
| 340 | vp6_huff_coeff_map, 12, AC_DC_HUFF_BITS, | ||
| 341 | &s->dccv_vlc[pt]); | ||
| 342 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 234 times.
|
234 | if (ret < 0) |
| 343 | ✗ | return ret; | |
| 344 | 234 | ret = vp6_build_huff_tree(s, model->coeff_runv[pt], | |
| 345 | vp6_huff_run_map, 9, RUN_HUFF_BITS, | ||
| 346 | &s->runv_vlc[pt]); | ||
| 347 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 234 times.
|
234 | if (ret < 0) |
| 348 | ✗ | return ret; | |
| 349 |
2/2✓ Branch 0 taken 702 times.
✓ Branch 1 taken 234 times.
|
936 | for (ct=0; ct<3; ct++) |
| 350 |
2/2✓ Branch 0 taken 2808 times.
✓ Branch 1 taken 702 times.
|
3510 | for (int cg = 0; cg < 4; cg++) { |
| 351 | 2808 | ret = vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg], | |
| 352 | vp6_huff_coeff_map, 12, | ||
| 353 | AC_DC_HUFF_BITS, | ||
| 354 | &s->ract_vlc[pt][ct][cg]); | ||
| 355 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2808 times.
|
2808 | if (ret < 0) |
| 356 | ✗ | return ret; | |
| 357 | } | ||
| 358 | } | ||
| 359 | 117 | memset(s->nb_null, 0, sizeof(s->nb_null)); | |
| 360 | } else { | ||
| 361 | /* coeff_dcct is a linear combination of coeff_dccv */ | ||
| 362 |
2/2✓ Branch 0 taken 1800 times.
✓ Branch 1 taken 900 times.
|
2700 | for (pt=0; pt<2; pt++) |
| 363 |
2/2✓ Branch 0 taken 5400 times.
✓ Branch 1 taken 1800 times.
|
7200 | for (ctx=0; ctx<3; ctx++) |
| 364 |
2/2✓ Branch 0 taken 27000 times.
✓ Branch 1 taken 5400 times.
|
32400 | for (node=0; node<5; node++) |
| 365 | 27000 | model->coeff_dcct[pt][ctx][node] = av_clip(((model->coeff_dccv[pt][node] * vp6_dccv_lc[ctx][node][0] + 128) >> 8) + vp6_dccv_lc[ctx][node][1], 1, 255); | |
| 366 | } | ||
| 367 | 1017 | return 0; | |
| 368 | } | ||
| 369 | |||
| 370 | 19436 | static void vp6_parse_vector_adjustment(VP56Context *s, VP56mv *vect) | |
| 371 | { | ||
| 372 | 19436 | VPXRangeCoder *c = &s->c; | |
| 373 | 19436 | VP56Model *model = s->modelp; | |
| 374 | int comp; | ||
| 375 | |||
| 376 | 19436 | *vect = (VP56mv) {0,0}; | |
| 377 |
2/2✓ Branch 0 taken 16653 times.
✓ Branch 1 taken 2783 times.
|
19436 | if (s->vector_candidate_pos < 2) |
| 378 | 16653 | *vect = s->vector_candidate[0]; | |
| 379 | |||
| 380 |
2/2✓ Branch 0 taken 38872 times.
✓ Branch 1 taken 19436 times.
|
58308 | for (comp=0; comp<2; comp++) { |
| 381 | 38872 | int i, delta = 0; | |
| 382 | |||
| 383 |
2/2✓ Branch 1 taken 8755 times.
✓ Branch 2 taken 30117 times.
|
38872 | if (vpx_rac_get_prob_branchy(c, model->vector_dct[comp])) { |
| 384 | static const uint8_t prob_order[] = {0, 1, 2, 7, 6, 5, 4}; | ||
| 385 |
2/2✓ Branch 0 taken 61285 times.
✓ Branch 1 taken 8755 times.
|
70040 | for (i=0; i<sizeof(prob_order); i++) { |
| 386 | 61285 | int j = prob_order[i]; | |
| 387 | 61285 | delta |= vpx_rac_get_prob(c, model->vector_fdv[comp][j])<<j; | |
| 388 | } | ||
| 389 |
2/2✓ Branch 0 taken 4348 times.
✓ Branch 1 taken 4407 times.
|
8755 | if (delta & 0xF0) |
| 390 | 4348 | delta |= vpx_rac_get_prob(c, model->vector_fdv[comp][3])<<3; | |
| 391 | else | ||
| 392 | 4407 | delta |= 8; | |
| 393 | } else { | ||
| 394 | 30117 | delta = vp56_rac_get_tree(c, ff_vp56_pva_tree, | |
| 395 | 30117 | model->vector_pdv[comp]); | |
| 396 | } | ||
| 397 | |||
| 398 |
4/4✓ Branch 0 taken 29700 times.
✓ Branch 1 taken 9172 times.
✓ Branch 3 taken 14329 times.
✓ Branch 4 taken 15371 times.
|
38872 | if (delta && vpx_rac_get_prob_branchy(c, model->vector_sig[comp])) |
| 399 | 14329 | delta = -delta; | |
| 400 | |||
| 401 |
2/2✓ Branch 0 taken 19436 times.
✓ Branch 1 taken 19436 times.
|
38872 | if (!comp) |
| 402 | 19436 | vect->x += delta; | |
| 403 | else | ||
| 404 | 19436 | vect->y += delta; | |
| 405 | } | ||
| 406 | 19436 | } | |
| 407 | |||
| 408 | /** | ||
| 409 | * Read number of consecutive blocks with null DC or AC. | ||
| 410 | * This value is < 74. | ||
| 411 | */ | ||
| 412 | 28576 | static unsigned vp6_get_nb_null(VP56Context *s) | |
| 413 | { | ||
| 414 | 28576 | unsigned val = get_bits(&s->gb, 2); | |
| 415 |
2/2✓ Branch 0 taken 4892 times.
✓ Branch 1 taken 23684 times.
|
28576 | if (val == 2) |
| 416 | 4892 | val += get_bits(&s->gb, 2); | |
| 417 |
2/2✓ Branch 0 taken 806 times.
✓ Branch 1 taken 22878 times.
|
23684 | else if (val == 3) { |
| 418 | 806 | val = get_bits1(&s->gb) << 2; | |
| 419 | 806 | val = 6+val + get_bits(&s->gb, 2+val); | |
| 420 | } | ||
| 421 | 28576 | return val; | |
| 422 | } | ||
| 423 | |||
| 424 | 16848 | static int vp6_parse_coeff_huffman(VP56Context *s) | |
| 425 | { | ||
| 426 | 16848 | VP56Model *model = s->modelp; | |
| 427 | 16848 | uint8_t *permute = s->idct_scantable; | |
| 428 | VLC *vlc_coeff; | ||
| 429 | int sign, coeff_idx; | ||
| 430 | int b, cg, idx; | ||
| 431 | 16848 | int pt = 0; /* plane type (0 for Y, 1 for U or V) */ | |
| 432 | |||
| 433 |
2/2✓ Branch 0 taken 101088 times.
✓ Branch 1 taken 16848 times.
|
117936 | for (b=0; b<6; b++) { |
| 434 | 101088 | int ct = 0; /* code type */ | |
| 435 |
2/2✓ Branch 0 taken 33696 times.
✓ Branch 1 taken 67392 times.
|
101088 | if (b > 3) pt = 1; |
| 436 | 101088 | vlc_coeff = &s->dccv_vlc[pt]; | |
| 437 | |||
| 438 | 101088 | for (coeff_idx = 0;;) { | |
| 439 | 1161120 | int run = 1; | |
| 440 |
4/4✓ Branch 0 taken 202176 times.
✓ Branch 1 taken 958944 times.
✓ Branch 2 taken 28871 times.
✓ Branch 3 taken 173305 times.
|
1161120 | if (coeff_idx<2 && s->nb_null[coeff_idx][pt]) { |
| 441 | 28871 | s->nb_null[coeff_idx][pt]--; | |
| 442 |
2/2✓ Branch 0 taken 11362 times.
✓ Branch 1 taken 17509 times.
|
28871 | if (coeff_idx) |
| 443 | 11362 | break; | |
| 444 | } else { | ||
| 445 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1132249 times.
|
1132249 | if (get_bits_left(&s->gb) <= 0) |
| 446 | ✗ | return AVERROR_INVALIDDATA; | |
| 447 | 1132249 | int coeff = get_vlc2(&s->gb, vlc_coeff->table, AC_DC_HUFF_BITS, 2); | |
| 448 |
2/2✓ Branch 0 taken 345601 times.
✓ Branch 1 taken 786648 times.
|
1132249 | if (coeff == 0) { |
| 449 |
2/2✓ Branch 0 taken 326823 times.
✓ Branch 1 taken 18778 times.
|
345601 | if (coeff_idx) { |
| 450 | 326823 | int pt = (coeff_idx >= 6); | |
| 451 | 326823 | run += get_vlc2(&s->gb, s->runv_vlc[pt].table, RUN_HUFF_BITS, 1); | |
| 452 |
2/2✓ Branch 0 taken 60162 times.
✓ Branch 1 taken 266661 times.
|
326823 | if (run >= 9) |
| 453 | 60162 | run += get_bits(&s->gb, 6); | |
| 454 | } else | ||
| 455 | 18778 | s->nb_null[0][pt] = vp6_get_nb_null(s); | |
| 456 | 345601 | ct = 0; | |
| 457 |
2/2✓ Branch 0 taken 88872 times.
✓ Branch 1 taken 697776 times.
|
786648 | } else if (coeff == 11) { /* end of block */ |
| 458 |
2/2✓ Branch 0 taken 9798 times.
✓ Branch 1 taken 79074 times.
|
88872 | if (coeff_idx == 1) /* first AC coeff ? */ |
| 459 | 9798 | s->nb_null[1][pt] = vp6_get_nb_null(s); | |
| 460 | 88872 | break; | |
| 461 | } else { | ||
| 462 | 697776 | int coeff2 = ff_vp56_coeff_bias[coeff]; | |
| 463 |
2/2✓ Branch 0 taken 39048 times.
✓ Branch 1 taken 658728 times.
|
697776 | if (coeff > 4) |
| 464 |
2/2✓ Branch 0 taken 38623 times.
✓ Branch 1 taken 425 times.
|
39048 | coeff2 += get_bits(&s->gb, coeff <= 9 ? coeff - 4 : 11); |
| 465 |
2/2✓ Branch 0 taken 188610 times.
✓ Branch 1 taken 509166 times.
|
697776 | ct = 1 + (coeff2 > 1); |
| 466 | 697776 | sign = get_bits1(&s->gb); | |
| 467 | 697776 | coeff2 = (coeff2 ^ -sign) + sign; | |
| 468 |
2/2✓ Branch 0 taken 632975 times.
✓ Branch 1 taken 64801 times.
|
697776 | if (coeff_idx) |
| 469 | 632975 | coeff2 *= s->dequant_ac; | |
| 470 | 697776 | idx = model->coeff_index_to_pos[coeff_idx]; | |
| 471 | 697776 | s->block_coeff[b][permute[idx]] = coeff2; | |
| 472 | } | ||
| 473 | } | ||
| 474 | 1060886 | coeff_idx+=run; | |
| 475 |
2/2✓ Branch 0 taken 854 times.
✓ Branch 1 taken 1060032 times.
|
1060886 | if (coeff_idx >= 64) |
| 476 | 854 | break; | |
| 477 | 1060032 | cg = FFMIN(vp6_coeff_groups[coeff_idx], 3); | |
| 478 | 1060032 | vlc_coeff = &s->ract_vlc[pt][ct][cg]; | |
| 479 | } | ||
| 480 | 101088 | s->idct_selector[b] = model->coeff_index_to_idct_selector[FFMIN(coeff_idx, 63)]; | |
| 481 | } | ||
| 482 | 16848 | return 0; | |
| 483 | } | ||
| 484 | |||
| 485 | 80617 | static int vp6_parse_coeff(VP56Context *s) | |
| 486 | { | ||
| 487 | 80617 | VPXRangeCoder *c = s->ccp; | |
| 488 | 80617 | VP56Model *model = s->modelp; | |
| 489 | 80617 | uint8_t *permute = s->idct_scantable; | |
| 490 | uint8_t *model1, *model2, *model3; | ||
| 491 | int coeff, sign, coeff_idx; | ||
| 492 | int b, i, cg, idx, ctx; | ||
| 493 | 80617 | int pt = 0; /* plane type (0 for Y, 1 for U or V) */ | |
| 494 | |||
| 495 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 80617 times.
|
80617 | if (vpx_rac_is_end(c)) { |
| 496 | ✗ | av_log(s->avctx, AV_LOG_ERROR, "End of AC stream reached in vp6_parse_coeff\n"); | |
| 497 | ✗ | return AVERROR_INVALIDDATA; | |
| 498 | } | ||
| 499 | |||
| 500 |
2/2✓ Branch 0 taken 483702 times.
✓ Branch 1 taken 80617 times.
|
564319 | for (b=0; b<6; b++) { |
| 501 | 483702 | int ct = 1; /* code type */ | |
| 502 | 483702 | int run = 1; | |
| 503 | |||
| 504 |
2/2✓ Branch 0 taken 161234 times.
✓ Branch 1 taken 322468 times.
|
483702 | if (b > 3) pt = 1; |
| 505 | |||
| 506 | 483702 | ctx = s->left_block[ff_vp56_b6to4[b]].not_null_dc | |
| 507 | 483702 | + s->above_blocks[s->above_block_idx[b]].not_null_dc; | |
| 508 | 483702 | model1 = model->coeff_dccv[pt]; | |
| 509 | 483702 | model2 = model->coeff_dcct[pt][ctx]; | |
| 510 | |||
| 511 | 483702 | coeff_idx = 0; | |
| 512 | for (;;) { | ||
| 513 |
6/6✓ Branch 0 taken 1169986 times.
✓ Branch 1 taken 967404 times.
✓ Branch 2 taken 798282 times.
✓ Branch 3 taken 371704 times.
✓ Branch 5 taken 513923 times.
✓ Branch 6 taken 1251763 times.
|
2137390 | if ((coeff_idx>1 && ct==0) || vpx_rac_get_prob_branchy(c, model2[0])) { |
| 514 | /* parse a coeff */ | ||
| 515 |
2/2✓ Branch 1 taken 250900 times.
✓ Branch 2 taken 634727 times.
|
885627 | if (vpx_rac_get_prob_branchy(c, model2[2])) { |
| 516 |
2/2✓ Branch 1 taken 48250 times.
✓ Branch 2 taken 202650 times.
|
250900 | if (vpx_rac_get_prob_branchy(c, model2[3])) { |
| 517 | 48250 | idx = vp56_rac_get_tree(c, ff_vp56_pc_tree, model1); | |
| 518 | 48250 | coeff = ff_vp56_coeff_bias[idx+5]; | |
| 519 |
2/2✓ Branch 0 taken 96958 times.
✓ Branch 1 taken 48250 times.
|
145208 | for (i=ff_vp56_coeff_bit_length[idx]; i>=0; i--) |
| 520 | 96958 | coeff += vpx_rac_get_prob(c, ff_vp56_coeff_parse_table[idx][i]) << i; | |
| 521 | } else { | ||
| 522 |
2/2✓ Branch 1 taken 69895 times.
✓ Branch 2 taken 132755 times.
|
202650 | if (vpx_rac_get_prob_branchy(c, model2[4])) |
| 523 | 69895 | coeff = 3 + vpx_rac_get_prob(c, model1[5]); | |
| 524 | else | ||
| 525 | 132755 | coeff = 2; | |
| 526 | } | ||
| 527 | 250900 | ct = 2; | |
| 528 | } else { | ||
| 529 | 634727 | ct = 1; | |
| 530 | 634727 | coeff = 1; | |
| 531 | } | ||
| 532 | 885627 | sign = vpx_rac_get(c); | |
| 533 | 885627 | coeff = (coeff ^ -sign) + sign; | |
| 534 |
2/2✓ Branch 0 taken 800702 times.
✓ Branch 1 taken 84925 times.
|
885627 | if (coeff_idx) |
| 535 | 800702 | coeff *= s->dequant_ac; | |
| 536 | 885627 | idx = model->coeff_index_to_pos[coeff_idx]; | |
| 537 | 885627 | s->block_coeff[b][permute[idx]] = coeff; | |
| 538 | 885627 | run = 1; | |
| 539 | } else { | ||
| 540 | /* parse a run */ | ||
| 541 | 1251763 | ct = 0; | |
| 542 |
2/2✓ Branch 0 taken 852986 times.
✓ Branch 1 taken 398777 times.
|
1251763 | if (coeff_idx > 0) { |
| 543 |
2/2✓ Branch 1 taken 481282 times.
✓ Branch 2 taken 371704 times.
|
852986 | if (!vpx_rac_get_prob_branchy(c, model2[1])) |
| 544 | 481282 | break; | |
| 545 | |||
| 546 | 371704 | model3 = model->coeff_runv[coeff_idx >= 6]; | |
| 547 | 371704 | run = vp56_rac_get_tree(c, vp6_pcr_tree, model3); | |
| 548 |
2/2✓ Branch 0 taken 52839 times.
✓ Branch 1 taken 318865 times.
|
371704 | if (!run) |
| 549 |
2/2✓ Branch 0 taken 317034 times.
✓ Branch 1 taken 52839 times.
|
369873 | for (run=9, i=0; i<6; i++) |
| 550 | 317034 | run += vpx_rac_get_prob(c, model3[i+8]) << i; | |
| 551 | } | ||
| 552 | } | ||
| 553 | 1656108 | coeff_idx += run; | |
| 554 |
2/2✓ Branch 0 taken 2420 times.
✓ Branch 1 taken 1653688 times.
|
1656108 | if (coeff_idx >= 64) |
| 555 | 2420 | break; | |
| 556 | 1653688 | cg = vp6_coeff_groups[coeff_idx]; | |
| 557 | 1653688 | model1 = model2 = model->coeff_ract[pt][ct][cg]; | |
| 558 | } | ||
| 559 | |||
| 560 | 483702 | s->left_block[ff_vp56_b6to4[b]].not_null_dc = | |
| 561 | 483702 | s->above_blocks[s->above_block_idx[b]].not_null_dc = !!s->block_coeff[b][0]; | |
| 562 | 483702 | s->idct_selector[b] = model->coeff_index_to_idct_selector[FFMIN(coeff_idx, 63)]; | |
| 563 | } | ||
| 564 | 80617 | return 0; | |
| 565 | } | ||
| 566 | |||
| 567 | 85134 | static int vp6_block_variance(uint8_t *src, ptrdiff_t stride) | |
| 568 | { | ||
| 569 | 85134 | int sum = 0, square_sum = 0; | |
| 570 | int y, x; | ||
| 571 | |||
| 572 |
2/2✓ Branch 0 taken 340536 times.
✓ Branch 1 taken 85134 times.
|
425670 | for (y=0; y<8; y+=2) { |
| 573 |
2/2✓ Branch 0 taken 1362144 times.
✓ Branch 1 taken 340536 times.
|
1702680 | for (x=0; x<8; x+=2) { |
| 574 | 1362144 | sum += src[x]; | |
| 575 | 1362144 | square_sum += src[x]*src[x]; | |
| 576 | } | ||
| 577 | 340536 | src += 2*stride; | |
| 578 | } | ||
| 579 | 85134 | return (16*square_sum - sum*sum) >> 8; | |
| 580 | } | ||
| 581 | |||
| 582 | 32792 | static void vp6_filter_hv4(uint8_t *dst, uint8_t *src, ptrdiff_t stride, | |
| 583 | int delta, const int16_t *weights) | ||
| 584 | { | ||
| 585 | int x, y; | ||
| 586 | |||
| 587 |
2/2✓ Branch 0 taken 262336 times.
✓ Branch 1 taken 32792 times.
|
295128 | for (y=0; y<8; y++) { |
| 588 |
2/2✓ Branch 0 taken 2098688 times.
✓ Branch 1 taken 262336 times.
|
2361024 | for (x=0; x<8; x++) { |
| 589 | 2098688 | dst[x] = av_clip_uint8(( src[x-delta ] * weights[0] | |
| 590 | 2098688 | + src[x ] * weights[1] | |
| 591 | 2098688 | + src[x+delta ] * weights[2] | |
| 592 | 2098688 | + src[x+2*delta] * weights[3] + 64) >> 7); | |
| 593 | } | ||
| 594 | 262336 | src += stride; | |
| 595 | 262336 | dst += stride; | |
| 596 | } | ||
| 597 | 32792 | } | |
| 598 | |||
| 599 | 54829 | static void vp6_filter_diag2(VP56Context *s, uint8_t *dst, uint8_t *src, | |
| 600 | ptrdiff_t stride, int h_weight, int v_weight) | ||
| 601 | { | ||
| 602 | 54829 | uint8_t *tmp = s->edge_emu_buffer+16; | |
| 603 | 54829 | s->h264chroma.put_h264_chroma_pixels_tab[0](tmp, src, stride, 9, h_weight, 0); | |
| 604 | 54829 | s->h264chroma.put_h264_chroma_pixels_tab[0](dst, tmp, stride, 8, 0, v_weight); | |
| 605 | 54829 | } | |
| 606 | |||
| 607 | 177796 | static void vp6_filter(VP56Context *s, uint8_t *dst, uint8_t *src, | |
| 608 | int offset1, int offset2, ptrdiff_t stride, | ||
| 609 | VP56mv mv, int mask, int select, int luma) | ||
| 610 | { | ||
| 611 | 177796 | int filter4 = 0; | |
| 612 | 177796 | int x8 = mv.x & mask; | |
| 613 | 177796 | int y8 = mv.y & mask; | |
| 614 | |||
| 615 |
2/2✓ Branch 0 taken 120356 times.
✓ Branch 1 taken 57440 times.
|
177796 | if (luma) { |
| 616 | 120356 | x8 *= 2; | |
| 617 | 120356 | y8 *= 2; | |
| 618 | 120356 | filter4 = s->filter_mode; | |
| 619 |
2/2✓ Branch 0 taken 105559 times.
✓ Branch 1 taken 14797 times.
|
120356 | if (filter4 == 2) { |
| 620 |
1/2✓ Branch 0 taken 105559 times.
✗ Branch 1 not taken.
|
105559 | if (s->max_vector_length && |
| 621 |
2/2✓ Branch 0 taken 92794 times.
✓ Branch 1 taken 12765 times.
|
105559 | (FFABS(mv.x) > s->max_vector_length || |
| 622 |
2/2✓ Branch 0 taken 7660 times.
✓ Branch 1 taken 85134 times.
|
92794 | FFABS(mv.y) > s->max_vector_length)) { |
| 623 | 20425 | filter4 = 0; | |
| 624 |
1/2✓ Branch 0 taken 85134 times.
✗ Branch 1 not taken.
|
85134 | } else if (s->sample_variance_threshold |
| 625 | 85134 | && (vp6_block_variance(src+offset1, stride) | |
| 626 |
2/2✓ Branch 0 taken 24996 times.
✓ Branch 1 taken 60138 times.
|
85134 | < s->sample_variance_threshold)) { |
| 627 | 24996 | filter4 = 0; | |
| 628 | } | ||
| 629 | } | ||
| 630 | } | ||
| 631 | |||
| 632 |
8/8✓ Branch 0 taken 136409 times.
✓ Branch 1 taken 41387 times.
✓ Branch 2 taken 61409 times.
✓ Branch 3 taken 75000 times.
✓ Branch 4 taken 41387 times.
✓ Branch 5 taken 61409 times.
✓ Branch 6 taken 15077 times.
✓ Branch 7 taken 26310 times.
|
177796 | if ((y8 && (offset2-offset1)*s->flip<0) || (!y8 && offset1 > offset2)) { |
| 633 | 90077 | offset1 = offset2; | |
| 634 | } | ||
| 635 | |||
| 636 |
2/2✓ Branch 0 taken 60138 times.
✓ Branch 1 taken 117658 times.
|
177796 | if (filter4) { |
| 637 |
2/2✓ Branch 0 taken 12003 times.
✓ Branch 1 taken 48135 times.
|
60138 | if (!y8) { /* left or right combine */ |
| 638 | 12003 | vp6_filter_hv4(dst, src+offset1, stride, 1, | |
| 639 | 12003 | vp6_block_copy_filter[select][x8]); | |
| 640 |
2/2✓ Branch 0 taken 20789 times.
✓ Branch 1 taken 27346 times.
|
48135 | } else if (!x8) { /* above or below combine */ |
| 641 | 20789 | vp6_filter_hv4(dst, src+offset1, stride, stride, | |
| 642 | 20789 | vp6_block_copy_filter[select][y8]); | |
| 643 | } else { | ||
| 644 | 27346 | s->vp56dsp.vp6_filter_diag4(dst, src+offset1+((mv.x^mv.y)>>31), stride, | |
| 645 | 27346 | vp6_block_copy_filter[select][x8], | |
| 646 | 27346 | vp6_block_copy_filter[select][y8]); | |
| 647 | } | ||
| 648 | } else { | ||
| 649 |
4/4✓ Branch 0 taken 84213 times.
✓ Branch 1 taken 33445 times.
✓ Branch 2 taken 29384 times.
✓ Branch 3 taken 54829 times.
|
117658 | if (!x8 || !y8) { |
| 650 | 62829 | s->h264chroma.put_h264_chroma_pixels_tab[0](dst, src + offset1, stride, 8, x8, y8); | |
| 651 | } else { | ||
| 652 | 54829 | vp6_filter_diag2(s, dst, src+offset1 + ((mv.x^mv.y)>>31), stride, x8, y8); | |
| 653 | } | ||
| 654 | } | ||
| 655 | 177796 | } | |
| 656 | |||
| 657 | 21 | static av_cold int vp6_decode_init_context(AVCodecContext *avctx, | |
| 658 | VP56Context *s, int flip, int has_alpha) | ||
| 659 | { | ||
| 660 | 21 | int ret = ff_vp56_init_context(avctx, s, flip, has_alpha); | |
| 661 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (ret < 0) |
| 662 | ✗ | return ret; | |
| 663 | |||
| 664 | 21 | ff_vp6dsp_init(&s->vp56dsp); | |
| 665 | |||
| 666 | 21 | s->deblock_filtering = 0; | |
| 667 | 21 | s->vp56_coord_div = vp6_coord_div; | |
| 668 | 21 | s->parse_vector_adjustment = vp6_parse_vector_adjustment; | |
| 669 | 21 | s->filter = vp6_filter; | |
| 670 | 21 | s->default_models_init = vp6_default_models_init; | |
| 671 | 21 | s->parse_vector_models = vp6_parse_vector_models; | |
| 672 | 21 | s->parse_coeff_models = vp6_parse_coeff_models; | |
| 673 | 21 | s->parse_header = vp6_parse_header; | |
| 674 | |||
| 675 | 21 | return 0; | |
| 676 | } | ||
| 677 | |||
| 678 | 17 | static av_cold int vp6_decode_init(AVCodecContext *avctx) | |
| 679 | { | ||
| 680 | 17 | VP56Context *s = avctx->priv_data; | |
| 681 | int ret; | ||
| 682 | |||
| 683 | 17 | ret = vp6_decode_init_context(avctx, s, avctx->codec_id == AV_CODEC_ID_VP6, | |
| 684 | 17 | avctx->codec_id == AV_CODEC_ID_VP6A); | |
| 685 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | if (ret < 0) |
| 686 | ✗ | return ret; | |
| 687 | |||
| 688 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 13 times.
|
17 | if (s->has_alpha) { |
| 689 | /* Can only happen for ff_vp6a_decoder */ | ||
| 690 | 4 | s->alpha_context = &s[1]; | |
| 691 | 4 | ret = vp6_decode_init_context(avctx, s->alpha_context, | |
| 692 | 4 | s->flip == -1, s->has_alpha); | |
| 693 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
|
4 | if (ret < 0) |
| 694 | ✗ | return ret; | |
| 695 | } | ||
| 696 | |||
| 697 | 17 | return 0; | |
| 698 | } | ||
| 699 | |||
| 700 | static av_cold void vp6_decode_free_context(VP56Context *s); | ||
| 701 | |||
| 702 | 17 | static av_cold int vp6_decode_free(AVCodecContext *avctx) | |
| 703 | { | ||
| 704 | 17 | VP56Context *s = avctx->priv_data; | |
| 705 | |||
| 706 | 17 | vp6_decode_free_context(s); | |
| 707 | |||
| 708 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 13 times.
|
17 | if (s->alpha_context) { |
| 709 | 4 | vp6_decode_free_context(s->alpha_context); | |
| 710 | 4 | s->alpha_context = NULL; | |
| 711 | } | ||
| 712 | |||
| 713 | 17 | return 0; | |
| 714 | } | ||
| 715 | |||
| 716 | 21 | static av_cold void vp6_decode_free_context(VP56Context *s) | |
| 717 | { | ||
| 718 | 21 | ff_vp56_free_context(s); | |
| 719 | |||
| 720 |
2/2✓ Branch 0 taken 42 times.
✓ Branch 1 taken 21 times.
|
63 | for (int pt = 0; pt < 2; ++pt) { |
| 721 | 42 | ff_vlc_free(&s->dccv_vlc[pt]); | |
| 722 | 42 | ff_vlc_free(&s->runv_vlc[pt]); | |
| 723 |
2/2✓ Branch 0 taken 126 times.
✓ Branch 1 taken 42 times.
|
168 | for (int ct = 0; ct < 3; ++ct) |
| 724 |
2/2✓ Branch 0 taken 504 times.
✓ Branch 1 taken 126 times.
|
630 | for (int cg = 0; cg < 4; ++cg) |
| 725 | 504 | ff_vlc_free(&s->ract_vlc[pt][ct][cg]); | |
| 726 | } | ||
| 727 | 21 | } | |
| 728 | |||
| 729 | const FFCodec ff_vp6_decoder = { | ||
| 730 | .p.name = "vp6", | ||
| 731 | CODEC_LONG_NAME("On2 VP6"), | ||
| 732 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
| 733 | .p.id = AV_CODEC_ID_VP6, | ||
| 734 | .priv_data_size = sizeof(VP56Context), | ||
| 735 | .init = vp6_decode_init, | ||
| 736 | .close = vp6_decode_free, | ||
| 737 | FF_CODEC_DECODE_CB(ff_vp56_decode_frame), | ||
| 738 | .p.capabilities = AV_CODEC_CAP_DR1, | ||
| 739 | .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, | ||
| 740 | }; | ||
| 741 | |||
| 742 | /* flash version, not flipped upside-down */ | ||
| 743 | const FFCodec ff_vp6f_decoder = { | ||
| 744 | .p.name = "vp6f", | ||
| 745 | CODEC_LONG_NAME("On2 VP6 (Flash version)"), | ||
| 746 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
| 747 | .p.id = AV_CODEC_ID_VP6F, | ||
| 748 | .priv_data_size = sizeof(VP56Context), | ||
| 749 | .init = vp6_decode_init, | ||
| 750 | .close = vp6_decode_free, | ||
| 751 | FF_CODEC_DECODE_CB(ff_vp56_decode_frame), | ||
| 752 | .p.capabilities = AV_CODEC_CAP_DR1, | ||
| 753 | .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, | ||
| 754 | }; | ||
| 755 | |||
| 756 | /* flash version, not flipped upside-down, with alpha channel */ | ||
| 757 | const FFCodec ff_vp6a_decoder = { | ||
| 758 | .p.name = "vp6a", | ||
| 759 | CODEC_LONG_NAME("On2 VP6 (Flash version, with alpha channel)"), | ||
| 760 | .p.type = AVMEDIA_TYPE_VIDEO, | ||
| 761 | .p.id = AV_CODEC_ID_VP6A, | ||
| 762 | .priv_data_size = 2 /* Main context + alpha context */ * sizeof(VP56Context), | ||
| 763 | .init = vp6_decode_init, | ||
| 764 | .close = vp6_decode_free, | ||
| 765 | FF_CODEC_DECODE_CB(ff_vp56_decode_frame), | ||
| 766 | .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_SLICE_THREADS, | ||
| 767 | .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, | ||
| 768 | }; | ||
| 769 |