00001
00025 #include "libavcore/imgutils.h"
00026 #include "avcodec.h"
00027 #include "vp56.h"
00028 #include "vp8data.h"
00029 #include "vp8dsp.h"
00030 #include "h264pred.h"
00031 #include "rectangle.h"
00032
00033 typedef struct {
00034 uint8_t filter_level;
00035 uint8_t inner_limit;
00036 uint8_t inner_filter;
00037 } VP8FilterStrength;
00038
00039 typedef struct {
00040 uint8_t skip;
00041
00042
00043 uint8_t mode;
00044 uint8_t ref_frame;
00045 uint8_t partitioning;
00046 VP56mv mv;
00047 VP56mv bmv[16];
00048 } VP8Macroblock;
00049
00050 typedef struct {
00051 AVCodecContext *avctx;
00052 DSPContext dsp;
00053 VP8DSPContext vp8dsp;
00054 H264PredContext hpc;
00055 vp8_mc_func put_pixels_tab[3][3][3];
00056 AVFrame frames[4];
00057 AVFrame *framep[4];
00058 uint8_t *edge_emu_buffer;
00059 VP56RangeCoder c;
00060 int profile;
00061
00062 int mb_width;
00063 int mb_height;
00064 int linesize;
00065 int uvlinesize;
00066
00067 int keyframe;
00068 int invisible;
00069 int update_last;
00070 int update_golden;
00071 int update_altref;
00072 int deblock_filter;
00073
00078 int update_probabilities;
00079
00084 int num_coeff_partitions;
00085 VP56RangeCoder coeff_partition[8];
00086
00087 VP8Macroblock *macroblocks;
00088 VP8Macroblock *macroblocks_base;
00089 VP8FilterStrength *filter_strength;
00090
00091 uint8_t *intra4x4_pred_mode_top;
00092 uint8_t intra4x4_pred_mode_left[4];
00093 uint8_t *segmentation_map;
00094
00099 uint8_t (*top_border)[16+8+8];
00100
00107 uint8_t (*top_nnz)[9];
00108 DECLARE_ALIGNED(8, uint8_t, left_nnz)[9];
00109
00117 DECLARE_ALIGNED(16, uint8_t, non_zero_count_cache)[6][4];
00118 DECLARE_ALIGNED(16, DCTELEM, block)[6][4][16];
00119 DECLARE_ALIGNED(16, DCTELEM, block_dc)[16];
00120 uint8_t intra4x4_pred_mode_mb[16];
00121
00122 int chroma_pred_mode;
00123 int segment;
00124
00125 int mbskip_enabled;
00126 int sign_bias[4];
00127 int ref_count[3];
00128
00134 struct {
00135 int enabled;
00136 int absolute_vals;
00137 int update_map;
00138 int8_t base_quant[4];
00139 int8_t filter_level[4];
00140 } segmentation;
00141
00147 struct {
00148
00149 int16_t luma_qmul[2];
00150 int16_t luma_dc_qmul[2];
00151 int16_t chroma_qmul[2];
00152 } qmat[4];
00153
00154 struct {
00155 int simple;
00156 int level;
00157 int sharpness;
00158 } filter;
00159
00160 struct {
00161 int enabled;
00162
00171 int8_t mode[4];
00172
00180 int8_t ref[4];
00181 } lf_delta;
00182
00189 struct {
00190 uint8_t segmentid[3];
00191 uint8_t mbskip;
00192 uint8_t intra;
00193 uint8_t last;
00194 uint8_t golden;
00195 uint8_t pred16x16[4];
00196 uint8_t pred8x8c[3];
00197
00198 uint8_t token[4][17][3][NUM_DCT_TOKENS-1];
00199 uint8_t mvc[2][19];
00200 } prob[2];
00201 } VP8Context;
00202
00203 static void vp8_decode_flush(AVCodecContext *avctx)
00204 {
00205 VP8Context *s = avctx->priv_data;
00206 int i;
00207
00208 for (i = 0; i < 4; i++)
00209 if (s->frames[i].data[0])
00210 avctx->release_buffer(avctx, &s->frames[i]);
00211 memset(s->framep, 0, sizeof(s->framep));
00212
00213 av_freep(&s->macroblocks_base);
00214 av_freep(&s->filter_strength);
00215 av_freep(&s->intra4x4_pred_mode_top);
00216 av_freep(&s->top_nnz);
00217 av_freep(&s->edge_emu_buffer);
00218 av_freep(&s->top_border);
00219 av_freep(&s->segmentation_map);
00220
00221 s->macroblocks = NULL;
00222 }
00223
00224 static int update_dimensions(VP8Context *s, int width, int height)
00225 {
00226 if (av_image_check_size(width, height, 0, s->avctx))
00227 return AVERROR_INVALIDDATA;
00228
00229 vp8_decode_flush(s->avctx);
00230
00231 avcodec_set_dimensions(s->avctx, width, height);
00232
00233 s->mb_width = (s->avctx->coded_width +15) / 16;
00234 s->mb_height = (s->avctx->coded_height+15) / 16;
00235
00236 s->macroblocks_base = av_mallocz((s->mb_width+s->mb_height*2+1)*sizeof(*s->macroblocks));
00237 s->filter_strength = av_mallocz(s->mb_width*sizeof(*s->filter_strength));
00238 s->intra4x4_pred_mode_top = av_mallocz(s->mb_width*4);
00239 s->top_nnz = av_mallocz(s->mb_width*sizeof(*s->top_nnz));
00240 s->top_border = av_mallocz((s->mb_width+1)*sizeof(*s->top_border));
00241 s->segmentation_map = av_mallocz(s->mb_width*s->mb_height);
00242
00243 if (!s->macroblocks_base || !s->filter_strength || !s->intra4x4_pred_mode_top ||
00244 !s->top_nnz || !s->top_border || !s->segmentation_map)
00245 return AVERROR(ENOMEM);
00246
00247 s->macroblocks = s->macroblocks_base + 1;
00248
00249 return 0;
00250 }
00251
00252 static void parse_segment_info(VP8Context *s)
00253 {
00254 VP56RangeCoder *c = &s->c;
00255 int i;
00256
00257 s->segmentation.update_map = vp8_rac_get(c);
00258
00259 if (vp8_rac_get(c)) {
00260 s->segmentation.absolute_vals = vp8_rac_get(c);
00261
00262 for (i = 0; i < 4; i++)
00263 s->segmentation.base_quant[i] = vp8_rac_get_sint(c, 7);
00264
00265 for (i = 0; i < 4; i++)
00266 s->segmentation.filter_level[i] = vp8_rac_get_sint(c, 6);
00267 }
00268 if (s->segmentation.update_map)
00269 for (i = 0; i < 3; i++)
00270 s->prob->segmentid[i] = vp8_rac_get(c) ? vp8_rac_get_uint(c, 8) : 255;
00271 }
00272
00273 static void update_lf_deltas(VP8Context *s)
00274 {
00275 VP56RangeCoder *c = &s->c;
00276 int i;
00277
00278 for (i = 0; i < 4; i++)
00279 s->lf_delta.ref[i] = vp8_rac_get_sint(c, 6);
00280
00281 for (i = 0; i < 4; i++)
00282 s->lf_delta.mode[i] = vp8_rac_get_sint(c, 6);
00283 }
00284
00285 static int setup_partitions(VP8Context *s, const uint8_t *buf, int buf_size)
00286 {
00287 const uint8_t *sizes = buf;
00288 int i;
00289
00290 s->num_coeff_partitions = 1 << vp8_rac_get_uint(&s->c, 2);
00291
00292 buf += 3*(s->num_coeff_partitions-1);
00293 buf_size -= 3*(s->num_coeff_partitions-1);
00294 if (buf_size < 0)
00295 return -1;
00296
00297 for (i = 0; i < s->num_coeff_partitions-1; i++) {
00298 int size = AV_RL24(sizes + 3*i);
00299 if (buf_size - size < 0)
00300 return -1;
00301
00302 ff_vp56_init_range_decoder(&s->coeff_partition[i], buf, size);
00303 buf += size;
00304 buf_size -= size;
00305 }
00306 ff_vp56_init_range_decoder(&s->coeff_partition[i], buf, buf_size);
00307
00308 return 0;
00309 }
00310
00311 static void get_quants(VP8Context *s)
00312 {
00313 VP56RangeCoder *c = &s->c;
00314 int i, base_qi;
00315
00316 int yac_qi = vp8_rac_get_uint(c, 7);
00317 int ydc_delta = vp8_rac_get_sint(c, 4);
00318 int y2dc_delta = vp8_rac_get_sint(c, 4);
00319 int y2ac_delta = vp8_rac_get_sint(c, 4);
00320 int uvdc_delta = vp8_rac_get_sint(c, 4);
00321 int uvac_delta = vp8_rac_get_sint(c, 4);
00322
00323 for (i = 0; i < 4; i++) {
00324 if (s->segmentation.enabled) {
00325 base_qi = s->segmentation.base_quant[i];
00326 if (!s->segmentation.absolute_vals)
00327 base_qi += yac_qi;
00328 } else
00329 base_qi = yac_qi;
00330
00331 s->qmat[i].luma_qmul[0] = vp8_dc_qlookup[av_clip(base_qi + ydc_delta , 0, 127)];
00332 s->qmat[i].luma_qmul[1] = vp8_ac_qlookup[av_clip(base_qi , 0, 127)];
00333 s->qmat[i].luma_dc_qmul[0] = 2 * vp8_dc_qlookup[av_clip(base_qi + y2dc_delta, 0, 127)];
00334 s->qmat[i].luma_dc_qmul[1] = 155 * vp8_ac_qlookup[av_clip(base_qi + y2ac_delta, 0, 127)] / 100;
00335 s->qmat[i].chroma_qmul[0] = vp8_dc_qlookup[av_clip(base_qi + uvdc_delta, 0, 127)];
00336 s->qmat[i].chroma_qmul[1] = vp8_ac_qlookup[av_clip(base_qi + uvac_delta, 0, 127)];
00337
00338 s->qmat[i].luma_dc_qmul[1] = FFMAX(s->qmat[i].luma_dc_qmul[1], 8);
00339 s->qmat[i].chroma_qmul[0] = FFMIN(s->qmat[i].chroma_qmul[0], 132);
00340 }
00341 }
00342
00356 static VP56Frame ref_to_update(VP8Context *s, int update, VP56Frame ref)
00357 {
00358 VP56RangeCoder *c = &s->c;
00359
00360 if (update)
00361 return VP56_FRAME_CURRENT;
00362
00363 switch (vp8_rac_get_uint(c, 2)) {
00364 case 1:
00365 return VP56_FRAME_PREVIOUS;
00366 case 2:
00367 return (ref == VP56_FRAME_GOLDEN) ? VP56_FRAME_GOLDEN2 : VP56_FRAME_GOLDEN;
00368 }
00369 return VP56_FRAME_NONE;
00370 }
00371
00372 static void update_refs(VP8Context *s)
00373 {
00374 VP56RangeCoder *c = &s->c;
00375
00376 int update_golden = vp8_rac_get(c);
00377 int update_altref = vp8_rac_get(c);
00378
00379 s->update_golden = ref_to_update(s, update_golden, VP56_FRAME_GOLDEN);
00380 s->update_altref = ref_to_update(s, update_altref, VP56_FRAME_GOLDEN2);
00381 }
00382
00383 static int decode_frame_header(VP8Context *s, const uint8_t *buf, int buf_size)
00384 {
00385 VP56RangeCoder *c = &s->c;
00386 int header_size, hscale, vscale, i, j, k, l, m, ret;
00387 int width = s->avctx->width;
00388 int height = s->avctx->height;
00389
00390 s->keyframe = !(buf[0] & 1);
00391 s->profile = (buf[0]>>1) & 7;
00392 s->invisible = !(buf[0] & 0x10);
00393 header_size = AV_RL24(buf) >> 5;
00394 buf += 3;
00395 buf_size -= 3;
00396
00397 if (s->profile > 3)
00398 av_log(s->avctx, AV_LOG_WARNING, "Unknown profile %d\n", s->profile);
00399
00400 if (!s->profile)
00401 memcpy(s->put_pixels_tab, s->vp8dsp.put_vp8_epel_pixels_tab, sizeof(s->put_pixels_tab));
00402 else
00403 memcpy(s->put_pixels_tab, s->vp8dsp.put_vp8_bilinear_pixels_tab, sizeof(s->put_pixels_tab));
00404
00405 if (header_size > buf_size - 7*s->keyframe) {
00406 av_log(s->avctx, AV_LOG_ERROR, "Header size larger than data provided\n");
00407 return AVERROR_INVALIDDATA;
00408 }
00409
00410 if (s->keyframe) {
00411 if (AV_RL24(buf) != 0x2a019d) {
00412 av_log(s->avctx, AV_LOG_ERROR, "Invalid start code 0x%x\n", AV_RL24(buf));
00413 return AVERROR_INVALIDDATA;
00414 }
00415 width = AV_RL16(buf+3) & 0x3fff;
00416 height = AV_RL16(buf+5) & 0x3fff;
00417 hscale = buf[4] >> 6;
00418 vscale = buf[6] >> 6;
00419 buf += 7;
00420 buf_size -= 7;
00421
00422 if (hscale || vscale)
00423 av_log_missing_feature(s->avctx, "Upscaling", 1);
00424
00425 s->update_golden = s->update_altref = VP56_FRAME_CURRENT;
00426 for (i = 0; i < 4; i++)
00427 for (j = 0; j < 16; j++)
00428 memcpy(s->prob->token[i][j], vp8_token_default_probs[i][vp8_coeff_band[j]],
00429 sizeof(s->prob->token[i][j]));
00430 memcpy(s->prob->pred16x16, vp8_pred16x16_prob_inter, sizeof(s->prob->pred16x16));
00431 memcpy(s->prob->pred8x8c , vp8_pred8x8c_prob_inter , sizeof(s->prob->pred8x8c));
00432 memcpy(s->prob->mvc , vp8_mv_default_prob , sizeof(s->prob->mvc));
00433 memset(&s->segmentation, 0, sizeof(s->segmentation));
00434 }
00435
00436 if (!s->macroblocks_base ||
00437 width != s->avctx->width || height != s->avctx->height) {
00438 if ((ret = update_dimensions(s, width, height) < 0))
00439 return ret;
00440 }
00441
00442 ff_vp56_init_range_decoder(c, buf, header_size);
00443 buf += header_size;
00444 buf_size -= header_size;
00445
00446 if (s->keyframe) {
00447 if (vp8_rac_get(c))
00448 av_log(s->avctx, AV_LOG_WARNING, "Unspecified colorspace\n");
00449 vp8_rac_get(c);
00450 }
00451
00452 if ((s->segmentation.enabled = vp8_rac_get(c)))
00453 parse_segment_info(s);
00454 else
00455 s->segmentation.update_map = 0;
00456
00457 s->filter.simple = vp8_rac_get(c);
00458 s->filter.level = vp8_rac_get_uint(c, 6);
00459 s->filter.sharpness = vp8_rac_get_uint(c, 3);
00460
00461 if ((s->lf_delta.enabled = vp8_rac_get(c)))
00462 if (vp8_rac_get(c))
00463 update_lf_deltas(s);
00464
00465 if (setup_partitions(s, buf, buf_size)) {
00466 av_log(s->avctx, AV_LOG_ERROR, "Invalid partitions\n");
00467 return AVERROR_INVALIDDATA;
00468 }
00469
00470 get_quants(s);
00471
00472 if (!s->keyframe) {
00473 update_refs(s);
00474 s->sign_bias[VP56_FRAME_GOLDEN] = vp8_rac_get(c);
00475 s->sign_bias[VP56_FRAME_GOLDEN2 ] = vp8_rac_get(c);
00476 }
00477
00478
00479
00480 if (!(s->update_probabilities = vp8_rac_get(c)))
00481 s->prob[1] = s->prob[0];
00482
00483 s->update_last = s->keyframe || vp8_rac_get(c);
00484
00485 for (i = 0; i < 4; i++)
00486 for (j = 0; j < 8; j++)
00487 for (k = 0; k < 3; k++)
00488 for (l = 0; l < NUM_DCT_TOKENS-1; l++)
00489 if (vp56_rac_get_prob_branchy(c, vp8_token_update_probs[i][j][k][l])) {
00490 int prob = vp8_rac_get_uint(c, 8);
00491 for (m = 0; vp8_coeff_band_indexes[j][m] >= 0; m++)
00492 s->prob->token[i][vp8_coeff_band_indexes[j][m]][k][l] = prob;
00493 }
00494
00495 if ((s->mbskip_enabled = vp8_rac_get(c)))
00496 s->prob->mbskip = vp8_rac_get_uint(c, 8);
00497
00498 if (!s->keyframe) {
00499 s->prob->intra = vp8_rac_get_uint(c, 8);
00500 s->prob->last = vp8_rac_get_uint(c, 8);
00501 s->prob->golden = vp8_rac_get_uint(c, 8);
00502
00503 if (vp8_rac_get(c))
00504 for (i = 0; i < 4; i++)
00505 s->prob->pred16x16[i] = vp8_rac_get_uint(c, 8);
00506 if (vp8_rac_get(c))
00507 for (i = 0; i < 3; i++)
00508 s->prob->pred8x8c[i] = vp8_rac_get_uint(c, 8);
00509
00510
00511 for (i = 0; i < 2; i++)
00512 for (j = 0; j < 19; j++)
00513 if (vp56_rac_get_prob_branchy(c, vp8_mv_update_prob[i][j]))
00514 s->prob->mvc[i][j] = vp8_rac_get_nn(c);
00515 }
00516
00517 return 0;
00518 }
00519
00520 static av_always_inline
00521 void clamp_mv(VP8Context *s, VP56mv *dst, const VP56mv *src, int mb_x, int mb_y)
00522 {
00523 #define MARGIN (16 << 2)
00524 dst->x = av_clip(src->x, -((mb_x << 6) + MARGIN),
00525 ((s->mb_width - 1 - mb_x) << 6) + MARGIN);
00526 dst->y = av_clip(src->y, -((mb_y << 6) + MARGIN),
00527 ((s->mb_height - 1 - mb_y) << 6) + MARGIN);
00528 }
00529
00530 static av_always_inline
00531 void find_near_mvs(VP8Context *s, VP8Macroblock *mb,
00532 VP56mv near[2], VP56mv *best, uint8_t cnt[4])
00533 {
00534 VP8Macroblock *mb_edge[3] = { mb + 2 ,
00535 mb - 1 ,
00536 mb + 1 };
00537 enum { EDGE_TOP, EDGE_LEFT, EDGE_TOPLEFT };
00538 VP56mv near_mv[4] = {{ 0 }};
00539 enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV };
00540 int idx = CNT_ZERO;
00541 int best_idx = CNT_ZERO;
00542 int cur_sign_bias = s->sign_bias[mb->ref_frame];
00543 int *sign_bias = s->sign_bias;
00544
00545
00546 #define MV_EDGE_CHECK(n)\
00547 {\
00548 VP8Macroblock *edge = mb_edge[n];\
00549 int edge_ref = edge->ref_frame;\
00550 if (edge_ref != VP56_FRAME_CURRENT) {\
00551 uint32_t mv = AV_RN32A(&edge->mv);\
00552 if (mv) {\
00553 if (cur_sign_bias != sign_bias[edge_ref]) {\
00554 \
00555 mv = ~mv;\
00556 mv = ((mv&0x7fff7fff) + 0x00010001) ^ (mv&0x80008000);\
00557 }\
00558 if (!n || mv != AV_RN32A(&near_mv[idx]))\
00559 AV_WN32A(&near_mv[++idx], mv);\
00560 cnt[idx] += 1 + (n != 2);\
00561 } else\
00562 cnt[CNT_ZERO] += 1 + (n != 2);\
00563 }\
00564 }
00565 MV_EDGE_CHECK(0)
00566 MV_EDGE_CHECK(1)
00567 MV_EDGE_CHECK(2)
00568
00569
00570 if (cnt[CNT_SPLITMV] && AV_RN32A(&near_mv[1+EDGE_TOP]) == AV_RN32A(&near_mv[1+EDGE_TOPLEFT]))
00571 cnt[CNT_NEAREST] += 1;
00572
00573 cnt[CNT_SPLITMV] = ((mb_edge[EDGE_LEFT]->mode == VP8_MVMODE_SPLIT) +
00574 (mb_edge[EDGE_TOP]->mode == VP8_MVMODE_SPLIT)) * 2 +
00575 (mb_edge[EDGE_TOPLEFT]->mode == VP8_MVMODE_SPLIT);
00576
00577
00578 if (cnt[CNT_NEAR] > cnt[CNT_NEAREST]) {
00579 FFSWAP(uint8_t, cnt[CNT_NEAREST], cnt[CNT_NEAR]);
00580 FFSWAP( VP56mv, near_mv[CNT_NEAREST], near_mv[CNT_NEAR]);
00581 }
00582
00583
00584 if (cnt[CNT_NEAREST] >= cnt[CNT_ZERO])
00585 best_idx = CNT_NEAREST;
00586
00587 mb->mv = near_mv[best_idx];
00588 near[0] = near_mv[CNT_NEAREST];
00589 near[1] = near_mv[CNT_NEAR];
00590 }
00591
00595 static int read_mv_component(VP56RangeCoder *c, const uint8_t *p)
00596 {
00597 int bit, x = 0;
00598
00599 if (vp56_rac_get_prob_branchy(c, p[0])) {
00600 int i;
00601
00602 for (i = 0; i < 3; i++)
00603 x += vp56_rac_get_prob(c, p[9 + i]) << i;
00604 for (i = 9; i > 3; i--)
00605 x += vp56_rac_get_prob(c, p[9 + i]) << i;
00606 if (!(x & 0xFFF0) || vp56_rac_get_prob(c, p[12]))
00607 x += 8;
00608 } else {
00609
00610 const uint8_t *ps = p+2;
00611 bit = vp56_rac_get_prob(c, *ps);
00612 ps += 1 + 3*bit;
00613 x += 4*bit;
00614 bit = vp56_rac_get_prob(c, *ps);
00615 ps += 1 + bit;
00616 x += 2*bit;
00617 x += vp56_rac_get_prob(c, *ps);
00618 }
00619
00620 return (x && vp56_rac_get_prob(c, p[1])) ? -x : x;
00621 }
00622
00623 static av_always_inline
00624 const uint8_t *get_submv_prob(uint32_t left, uint32_t top)
00625 {
00626 if (left == top)
00627 return vp8_submv_prob[4-!!left];
00628 if (!top)
00629 return vp8_submv_prob[2];
00630 return vp8_submv_prob[1-!!left];
00631 }
00632
00637 static av_always_inline
00638 int decode_splitmvs(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb)
00639 {
00640 int part_idx;
00641 int n, num;
00642 VP8Macroblock *top_mb = &mb[2];
00643 VP8Macroblock *left_mb = &mb[-1];
00644 const uint8_t *mbsplits_left = vp8_mbsplits[left_mb->partitioning],
00645 *mbsplits_top = vp8_mbsplits[top_mb->partitioning],
00646 *mbsplits_cur, *firstidx;
00647 VP56mv *top_mv = top_mb->bmv;
00648 VP56mv *left_mv = left_mb->bmv;
00649 VP56mv *cur_mv = mb->bmv;
00650
00651 if (vp56_rac_get_prob_branchy(c, vp8_mbsplit_prob[0])) {
00652 if (vp56_rac_get_prob_branchy(c, vp8_mbsplit_prob[1])) {
00653 part_idx = VP8_SPLITMVMODE_16x8 + vp56_rac_get_prob(c, vp8_mbsplit_prob[2]);
00654 } else {
00655 part_idx = VP8_SPLITMVMODE_8x8;
00656 }
00657 } else {
00658 part_idx = VP8_SPLITMVMODE_4x4;
00659 }
00660
00661 num = vp8_mbsplit_count[part_idx];
00662 mbsplits_cur = vp8_mbsplits[part_idx],
00663 firstidx = vp8_mbfirstidx[part_idx];
00664 mb->partitioning = part_idx;
00665
00666 for (n = 0; n < num; n++) {
00667 int k = firstidx[n];
00668 uint32_t left, above;
00669 const uint8_t *submv_prob;
00670
00671 if (!(k & 3))
00672 left = AV_RN32A(&left_mv[mbsplits_left[k + 3]]);
00673 else
00674 left = AV_RN32A(&cur_mv[mbsplits_cur[k - 1]]);
00675 if (k <= 3)
00676 above = AV_RN32A(&top_mv[mbsplits_top[k + 12]]);
00677 else
00678 above = AV_RN32A(&cur_mv[mbsplits_cur[k - 4]]);
00679
00680 submv_prob = get_submv_prob(left, above);
00681
00682 if (vp56_rac_get_prob_branchy(c, submv_prob[0])) {
00683 if (vp56_rac_get_prob_branchy(c, submv_prob[1])) {
00684 if (vp56_rac_get_prob_branchy(c, submv_prob[2])) {
00685 mb->bmv[n].y = mb->mv.y + read_mv_component(c, s->prob->mvc[0]);
00686 mb->bmv[n].x = mb->mv.x + read_mv_component(c, s->prob->mvc[1]);
00687 } else {
00688 AV_ZERO32(&mb->bmv[n]);
00689 }
00690 } else {
00691 AV_WN32A(&mb->bmv[n], above);
00692 }
00693 } else {
00694 AV_WN32A(&mb->bmv[n], left);
00695 }
00696 }
00697
00698 return num;
00699 }
00700
00701 static av_always_inline
00702 void decode_intra4x4_modes(VP8Context *s, VP56RangeCoder *c,
00703 int mb_x, int keyframe)
00704 {
00705 uint8_t *intra4x4 = s->intra4x4_pred_mode_mb;
00706 if (keyframe) {
00707 int x, y;
00708 uint8_t* const top = s->intra4x4_pred_mode_top + 4 * mb_x;
00709 uint8_t* const left = s->intra4x4_pred_mode_left;
00710 for (y = 0; y < 4; y++) {
00711 for (x = 0; x < 4; x++) {
00712 const uint8_t *ctx;
00713 ctx = vp8_pred4x4_prob_intra[top[x]][left[y]];
00714 *intra4x4 = vp8_rac_get_tree(c, vp8_pred4x4_tree, ctx);
00715 left[y] = top[x] = *intra4x4;
00716 intra4x4++;
00717 }
00718 }
00719 } else {
00720 int i;
00721 for (i = 0; i < 16; i++)
00722 intra4x4[i] = vp8_rac_get_tree(c, vp8_pred4x4_tree, vp8_pred4x4_prob_inter);
00723 }
00724 }
00725
00726 static av_always_inline
00727 void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, uint8_t *segment)
00728 {
00729 VP56RangeCoder *c = &s->c;
00730
00731 if (s->segmentation.update_map)
00732 *segment = vp8_rac_get_tree(c, vp8_segmentid_tree, s->prob->segmentid);
00733 s->segment = *segment;
00734
00735 mb->skip = s->mbskip_enabled ? vp56_rac_get_prob(c, s->prob->mbskip) : 0;
00736
00737 if (s->keyframe) {
00738 mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_intra, vp8_pred16x16_prob_intra);
00739
00740 if (mb->mode == MODE_I4x4) {
00741 decode_intra4x4_modes(s, c, mb_x, 1);
00742 } else {
00743 const uint32_t modes = vp8_pred4x4_mode[mb->mode] * 0x01010101u;
00744 AV_WN32A(s->intra4x4_pred_mode_top + 4 * mb_x, modes);
00745 AV_WN32A(s->intra4x4_pred_mode_left, modes);
00746 }
00747
00748 s->chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree, vp8_pred8x8c_prob_intra);
00749 mb->ref_frame = VP56_FRAME_CURRENT;
00750 } else if (vp56_rac_get_prob_branchy(c, s->prob->intra)) {
00751 VP56mv near[2], best;
00752 uint8_t cnt[4] = { 0 };
00753
00754
00755 if (vp56_rac_get_prob_branchy(c, s->prob->last))
00756 mb->ref_frame = vp56_rac_get_prob(c, s->prob->golden) ?
00757 VP56_FRAME_GOLDEN2 : VP56_FRAME_GOLDEN;
00758 else
00759 mb->ref_frame = VP56_FRAME_PREVIOUS;
00760 s->ref_count[mb->ref_frame-1]++;
00761
00762
00763 find_near_mvs(s, mb, near, &best, cnt);
00764 if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[0]][0])) {
00765 if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[1]][1])) {
00766 if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[2]][2])) {
00767 if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[3]][3])) {
00768 mb->mode = VP8_MVMODE_SPLIT;
00769 clamp_mv(s, &mb->mv, &mb->mv, mb_x, mb_y);
00770 mb->mv = mb->bmv[decode_splitmvs(s, c, mb) - 1];
00771 } else {
00772 mb->mode = VP8_MVMODE_NEW;
00773 clamp_mv(s, &mb->mv, &mb->mv, mb_x, mb_y);
00774 mb->mv.y += read_mv_component(c, s->prob->mvc[0]);
00775 mb->mv.x += read_mv_component(c, s->prob->mvc[1]);
00776 }
00777 } else {
00778 mb->mode = VP8_MVMODE_NEAR;
00779 clamp_mv(s, &mb->mv, &near[1], mb_x, mb_y);
00780 }
00781 } else {
00782 mb->mode = VP8_MVMODE_NEAREST;
00783 clamp_mv(s, &mb->mv, &near[0], mb_x, mb_y);
00784 }
00785 } else {
00786 mb->mode = VP8_MVMODE_ZERO;
00787 AV_ZERO32(&mb->mv);
00788 }
00789 if (mb->mode != VP8_MVMODE_SPLIT) {
00790 mb->partitioning = VP8_SPLITMVMODE_NONE;
00791 mb->bmv[0] = mb->mv;
00792 }
00793 } else {
00794
00795 mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_inter, s->prob->pred16x16);
00796
00797 if (mb->mode == MODE_I4x4)
00798 decode_intra4x4_modes(s, c, mb_x, 0);
00799
00800 s->chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree, s->prob->pred8x8c);
00801 mb->ref_frame = VP56_FRAME_CURRENT;
00802 mb->partitioning = VP8_SPLITMVMODE_NONE;
00803 AV_ZERO32(&mb->bmv[0]);
00804 }
00805 }
00806
00818 static int decode_block_coeffs_internal(VP56RangeCoder *c, DCTELEM block[16],
00819 uint8_t probs[8][3][NUM_DCT_TOKENS-1],
00820 int i, uint8_t *token_prob, int16_t qmul[2])
00821 {
00822 goto skip_eob;
00823 do {
00824 int coeff;
00825 if (!vp56_rac_get_prob_branchy(c, token_prob[0]))
00826 return i;
00827
00828 skip_eob:
00829 if (!vp56_rac_get_prob_branchy(c, token_prob[1])) {
00830 if (++i == 16)
00831 return i;
00832 token_prob = probs[i][0];
00833 goto skip_eob;
00834 }
00835
00836 if (!vp56_rac_get_prob_branchy(c, token_prob[2])) {
00837 coeff = 1;
00838 token_prob = probs[i+1][1];
00839 } else {
00840 if (!vp56_rac_get_prob_branchy(c, token_prob[3])) {
00841 coeff = vp56_rac_get_prob_branchy(c, token_prob[4]);
00842 if (coeff)
00843 coeff += vp56_rac_get_prob(c, token_prob[5]);
00844 coeff += 2;
00845 } else {
00846
00847 if (!vp56_rac_get_prob_branchy(c, token_prob[6])) {
00848 if (!vp56_rac_get_prob_branchy(c, token_prob[7])) {
00849 coeff = 5 + vp56_rac_get_prob(c, vp8_dct_cat1_prob[0]);
00850 } else {
00851 coeff = 7;
00852 coeff += vp56_rac_get_prob(c, vp8_dct_cat2_prob[0]) << 1;
00853 coeff += vp56_rac_get_prob(c, vp8_dct_cat2_prob[1]);
00854 }
00855 } else {
00856 int a = vp56_rac_get_prob(c, token_prob[8]);
00857 int b = vp56_rac_get_prob(c, token_prob[9+a]);
00858 int cat = (a<<1) + b;
00859 coeff = 3 + (8<<cat);
00860 coeff += vp8_rac_get_coeff(c, vp8_dct_cat_prob[cat]);
00861 }
00862 }
00863 token_prob = probs[i+1][2];
00864 }
00865 block[zigzag_scan[i]] = (vp8_rac_get(c) ? -coeff : coeff) * qmul[!!i];
00866 } while (++i < 16);
00867
00868 return i;
00869 }
00870
00871 static av_always_inline
00872 int decode_block_coeffs(VP56RangeCoder *c, DCTELEM block[16],
00873 uint8_t probs[8][3][NUM_DCT_TOKENS-1],
00874 int i, int zero_nhood, int16_t qmul[2])
00875 {
00876 uint8_t *token_prob = probs[i][zero_nhood];
00877 if (!vp56_rac_get_prob_branchy(c, token_prob[0]))
00878 return 0;
00879 return decode_block_coeffs_internal(c, block, probs, i, token_prob, qmul);
00880 }
00881
00882 static av_always_inline
00883 void decode_mb_coeffs(VP8Context *s, VP56RangeCoder *c, VP8Macroblock *mb,
00884 uint8_t t_nnz[9], uint8_t l_nnz[9])
00885 {
00886 int i, x, y, luma_start = 0, luma_ctx = 3;
00887 int nnz_pred, nnz, nnz_total = 0;
00888 int segment = s->segment;
00889 int block_dc = 0;
00890
00891 if (mb->mode != MODE_I4x4 && mb->mode != VP8_MVMODE_SPLIT) {
00892 nnz_pred = t_nnz[8] + l_nnz[8];
00893
00894
00895 nnz = decode_block_coeffs(c, s->block_dc, s->prob->token[1], 0, nnz_pred,
00896 s->qmat[segment].luma_dc_qmul);
00897 l_nnz[8] = t_nnz[8] = !!nnz;
00898 if (nnz) {
00899 nnz_total += nnz;
00900 block_dc = 1;
00901 if (nnz == 1)
00902 s->vp8dsp.vp8_luma_dc_wht_dc(s->block, s->block_dc);
00903 else
00904 s->vp8dsp.vp8_luma_dc_wht(s->block, s->block_dc);
00905 }
00906 luma_start = 1;
00907 luma_ctx = 0;
00908 }
00909
00910
00911 for (y = 0; y < 4; y++)
00912 for (x = 0; x < 4; x++) {
00913 nnz_pred = l_nnz[y] + t_nnz[x];
00914 nnz = decode_block_coeffs(c, s->block[y][x], s->prob->token[luma_ctx], luma_start,
00915 nnz_pred, s->qmat[segment].luma_qmul);
00916
00917 s->non_zero_count_cache[y][x] = nnz + block_dc;
00918 t_nnz[x] = l_nnz[y] = !!nnz;
00919 nnz_total += nnz;
00920 }
00921
00922
00923
00924
00925 for (i = 4; i < 6; i++)
00926 for (y = 0; y < 2; y++)
00927 for (x = 0; x < 2; x++) {
00928 nnz_pred = l_nnz[i+2*y] + t_nnz[i+2*x];
00929 nnz = decode_block_coeffs(c, s->block[i][(y<<1)+x], s->prob->token[2], 0,
00930 nnz_pred, s->qmat[segment].chroma_qmul);
00931 s->non_zero_count_cache[i][(y<<1)+x] = nnz;
00932 t_nnz[i+2*x] = l_nnz[i+2*y] = !!nnz;
00933 nnz_total += nnz;
00934 }
00935
00936
00937
00938
00939 if (!nnz_total)
00940 mb->skip = 1;
00941 }
00942
00943 static av_always_inline
00944 void backup_mb_border(uint8_t *top_border, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr,
00945 int linesize, int uvlinesize, int simple)
00946 {
00947 AV_COPY128(top_border, src_y + 15*linesize);
00948 if (!simple) {
00949 AV_COPY64(top_border+16, src_cb + 7*uvlinesize);
00950 AV_COPY64(top_border+24, src_cr + 7*uvlinesize);
00951 }
00952 }
00953
00954 static av_always_inline
00955 void xchg_mb_border(uint8_t *top_border, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr,
00956 int linesize, int uvlinesize, int mb_x, int mb_y, int mb_width,
00957 int simple, int xchg)
00958 {
00959 uint8_t *top_border_m1 = top_border-32;
00960 src_y -= linesize;
00961 src_cb -= uvlinesize;
00962 src_cr -= uvlinesize;
00963
00964 #define XCHG(a,b,xchg) do { \
00965 if (xchg) AV_SWAP64(b,a); \
00966 else AV_COPY64(b,a); \
00967 } while (0)
00968
00969 XCHG(top_border_m1+8, src_y-8, xchg);
00970 XCHG(top_border, src_y, xchg);
00971 XCHG(top_border+8, src_y+8, 1);
00972 if (mb_x < mb_width-1)
00973 XCHG(top_border+32, src_y+16, 1);
00974
00975
00976
00977 if (!simple || !mb_y) {
00978 XCHG(top_border_m1+16, src_cb-8, xchg);
00979 XCHG(top_border_m1+24, src_cr-8, xchg);
00980 XCHG(top_border+16, src_cb, 1);
00981 XCHG(top_border+24, src_cr, 1);
00982 }
00983 }
00984
00985 static av_always_inline
00986 int check_dc_pred8x8_mode(int mode, int mb_x, int mb_y)
00987 {
00988 if (!mb_x) {
00989 return mb_y ? TOP_DC_PRED8x8 : DC_128_PRED8x8;
00990 } else {
00991 return mb_y ? mode : LEFT_DC_PRED8x8;
00992 }
00993 }
00994
00995 static av_always_inline
00996 int check_tm_pred8x8_mode(int mode, int mb_x, int mb_y)
00997 {
00998 if (!mb_x) {
00999 return mb_y ? VERT_PRED8x8 : DC_129_PRED8x8;
01000 } else {
01001 return mb_y ? mode : HOR_PRED8x8;
01002 }
01003 }
01004
01005 static av_always_inline
01006 int check_intra_pred8x8_mode(int mode, int mb_x, int mb_y)
01007 {
01008 if (mode == DC_PRED8x8) {
01009 return check_dc_pred8x8_mode(mode, mb_x, mb_y);
01010 } else {
01011 return mode;
01012 }
01013 }
01014
01015 static av_always_inline
01016 int check_intra_pred8x8_mode_emuedge(int mode, int mb_x, int mb_y)
01017 {
01018 switch (mode) {
01019 case DC_PRED8x8:
01020 return check_dc_pred8x8_mode(mode, mb_x, mb_y);
01021 case VERT_PRED8x8:
01022 return !mb_y ? DC_127_PRED8x8 : mode;
01023 case HOR_PRED8x8:
01024 return !mb_x ? DC_129_PRED8x8 : mode;
01025 case PLANE_PRED8x8 :
01026 return check_tm_pred8x8_mode(mode, mb_x, mb_y);
01027 }
01028 return mode;
01029 }
01030
01031 static av_always_inline
01032 int check_tm_pred4x4_mode(int mode, int mb_x, int mb_y)
01033 {
01034 if (!mb_x) {
01035 return mb_y ? VERT_VP8_PRED : DC_129_PRED;
01036 } else {
01037 return mb_y ? mode : HOR_VP8_PRED;
01038 }
01039 }
01040
01041 static av_always_inline
01042 int check_intra_pred4x4_mode_emuedge(int mode, int mb_x, int mb_y, int *copy_buf)
01043 {
01044 switch (mode) {
01045 case VERT_PRED:
01046 if (!mb_x && mb_y) {
01047 *copy_buf = 1;
01048 return mode;
01049 }
01050
01051 case DIAG_DOWN_LEFT_PRED:
01052 case VERT_LEFT_PRED:
01053 return !mb_y ? DC_127_PRED : mode;
01054 case HOR_PRED:
01055 if (!mb_y) {
01056 *copy_buf = 1;
01057 return mode;
01058 }
01059
01060 case HOR_UP_PRED:
01061 return !mb_x ? DC_129_PRED : mode;
01062 case TM_VP8_PRED:
01063 return check_tm_pred4x4_mode(mode, mb_x, mb_y);
01064 case DC_PRED:
01065 case DIAG_DOWN_RIGHT_PRED:
01066 case VERT_RIGHT_PRED:
01067 case HOR_DOWN_PRED:
01068 if (!mb_y || !mb_x)
01069 *copy_buf = 1;
01070 return mode;
01071 }
01072 return mode;
01073 }
01074
01075 static av_always_inline
01076 void intra_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb,
01077 int mb_x, int mb_y)
01078 {
01079 AVCodecContext *avctx = s->avctx;
01080 int x, y, mode, nnz, tr;
01081
01082
01083
01084 if (!(avctx->flags & CODEC_FLAG_EMU_EDGE && !mb_y) && (s->deblock_filter || !mb_y))
01085 xchg_mb_border(s->top_border[mb_x+1], dst[0], dst[1], dst[2],
01086 s->linesize, s->uvlinesize, mb_x, mb_y, s->mb_width,
01087 s->filter.simple, 1);
01088
01089 if (mb->mode < MODE_I4x4) {
01090 if (avctx->flags & CODEC_FLAG_EMU_EDGE) {
01091 mode = check_intra_pred8x8_mode_emuedge(mb->mode, mb_x, mb_y);
01092 } else {
01093 mode = check_intra_pred8x8_mode(mb->mode, mb_x, mb_y);
01094 }
01095 s->hpc.pred16x16[mode](dst[0], s->linesize);
01096 } else {
01097 uint8_t *ptr = dst[0];
01098 uint8_t *intra4x4 = s->intra4x4_pred_mode_mb;
01099 uint8_t tr_top[4] = { 127, 127, 127, 127 };
01100
01101
01102
01103 uint8_t *tr_right = ptr - s->linesize + 16;
01104
01105
01106
01107 if (!(!mb_y && avctx->flags & CODEC_FLAG_EMU_EDGE) &&
01108 mb_x == s->mb_width-1) {
01109 tr = tr_right[-1]*0x01010101;
01110 tr_right = (uint8_t *)&tr;
01111 }
01112
01113 if (mb->skip)
01114 AV_ZERO128(s->non_zero_count_cache);
01115
01116 for (y = 0; y < 4; y++) {
01117 uint8_t *topright = ptr + 4 - s->linesize;
01118 for (x = 0; x < 4; x++) {
01119 int copy = 0, linesize = s->linesize;
01120 uint8_t *dst = ptr+4*x;
01121 DECLARE_ALIGNED(4, uint8_t, copy_dst)[5*8];
01122
01123 if ((y == 0 || x == 3) && mb_y == 0 && avctx->flags & CODEC_FLAG_EMU_EDGE) {
01124 topright = tr_top;
01125 } else if (x == 3)
01126 topright = tr_right;
01127
01128 if (avctx->flags & CODEC_FLAG_EMU_EDGE) {
01129 mode = check_intra_pred4x4_mode_emuedge(intra4x4[x], mb_x + x, mb_y + y, ©);
01130 if (copy) {
01131 dst = copy_dst + 12;
01132 linesize = 8;
01133 if (!(mb_y + y)) {
01134 copy_dst[3] = 127U;
01135 * (uint32_t *) (copy_dst + 4) = 127U * 0x01010101U;
01136 } else {
01137 * (uint32_t *) (copy_dst + 4) = * (uint32_t *) (ptr+4*x-s->linesize);
01138 if (!(mb_x + x)) {
01139 copy_dst[3] = 129U;
01140 } else {
01141 copy_dst[3] = ptr[4*x-s->linesize-1];
01142 }
01143 }
01144 if (!(mb_x + x)) {
01145 copy_dst[11] =
01146 copy_dst[19] =
01147 copy_dst[27] =
01148 copy_dst[35] = 129U;
01149 } else {
01150 copy_dst[11] = ptr[4*x -1];
01151 copy_dst[19] = ptr[4*x+s->linesize -1];
01152 copy_dst[27] = ptr[4*x+s->linesize*2-1];
01153 copy_dst[35] = ptr[4*x+s->linesize*3-1];
01154 }
01155 }
01156 } else {
01157 mode = intra4x4[x];
01158 }
01159 s->hpc.pred4x4[mode](dst, topright, linesize);
01160 if (copy) {
01161 * (uint32_t *) (ptr+4*x) = * (uint32_t *) (copy_dst + 12);
01162 * (uint32_t *) (ptr+4*x+s->linesize) = * (uint32_t *) (copy_dst + 20);
01163 * (uint32_t *) (ptr+4*x+s->linesize*2) = * (uint32_t *) (copy_dst + 28);
01164 * (uint32_t *) (ptr+4*x+s->linesize*3) = * (uint32_t *) (copy_dst + 36);
01165 }
01166
01167 nnz = s->non_zero_count_cache[y][x];
01168 if (nnz) {
01169 if (nnz == 1)
01170 s->vp8dsp.vp8_idct_dc_add(ptr+4*x, s->block[y][x], s->linesize);
01171 else
01172 s->vp8dsp.vp8_idct_add(ptr+4*x, s->block[y][x], s->linesize);
01173 }
01174 topright += 4;
01175 }
01176
01177 ptr += 4*s->linesize;
01178 intra4x4 += 4;
01179 }
01180 }
01181
01182 if (avctx->flags & CODEC_FLAG_EMU_EDGE) {
01183 mode = check_intra_pred8x8_mode_emuedge(s->chroma_pred_mode, mb_x, mb_y);
01184 } else {
01185 mode = check_intra_pred8x8_mode(s->chroma_pred_mode, mb_x, mb_y);
01186 }
01187 s->hpc.pred8x8[mode](dst[1], s->uvlinesize);
01188 s->hpc.pred8x8[mode](dst[2], s->uvlinesize);
01189
01190 if (!(avctx->flags & CODEC_FLAG_EMU_EDGE && !mb_y) && (s->deblock_filter || !mb_y))
01191 xchg_mb_border(s->top_border[mb_x+1], dst[0], dst[1], dst[2],
01192 s->linesize, s->uvlinesize, mb_x, mb_y, s->mb_width,
01193 s->filter.simple, 0);
01194 }
01195
01213 static av_always_inline
01214 void vp8_mc(VP8Context *s, int luma,
01215 uint8_t *dst, uint8_t *src, const VP56mv *mv,
01216 int x_off, int y_off, int block_w, int block_h,
01217 int width, int height, int linesize,
01218 vp8_mc_func mc_func[3][3])
01219 {
01220 if (AV_RN32A(mv)) {
01221 static const uint8_t idx[8] = { 0, 1, 2, 1, 2, 1, 2, 1 };
01222 int mx = (mv->x << luma)&7, mx_idx = idx[mx];
01223 int my = (mv->y << luma)&7, my_idx = idx[my];
01224
01225 x_off += mv->x >> (3 - luma);
01226 y_off += mv->y >> (3 - luma);
01227
01228
01229 src += y_off * linesize + x_off;
01230 if (x_off < 2 || x_off >= width - block_w - 3 ||
01231 y_off < 2 || y_off >= height - block_h - 3) {
01232 ff_emulated_edge_mc(s->edge_emu_buffer, src - 2 * linesize - 2, linesize,
01233 block_w + 5, block_h + 5,
01234 x_off - 2, y_off - 2, width, height);
01235 src = s->edge_emu_buffer + 2 + linesize * 2;
01236 }
01237 mc_func[my_idx][mx_idx](dst, linesize, src, linesize, block_h, mx, my);
01238 } else
01239 mc_func[0][0](dst, linesize, src + y_off * linesize + x_off, linesize, block_h, 0, 0);
01240 }
01241
01242 static av_always_inline
01243 void vp8_mc_part(VP8Context *s, uint8_t *dst[3],
01244 AVFrame *ref_frame, int x_off, int y_off,
01245 int bx_off, int by_off,
01246 int block_w, int block_h,
01247 int width, int height, VP56mv *mv)
01248 {
01249 VP56mv uvmv = *mv;
01250
01251
01252 vp8_mc(s, 1, dst[0] + by_off * s->linesize + bx_off,
01253 ref_frame->data[0], mv, x_off + bx_off, y_off + by_off,
01254 block_w, block_h, width, height, s->linesize,
01255 s->put_pixels_tab[block_w == 8]);
01256
01257
01258 if (s->profile == 3) {
01259 uvmv.x &= ~7;
01260 uvmv.y &= ~7;
01261 }
01262 x_off >>= 1; y_off >>= 1;
01263 bx_off >>= 1; by_off >>= 1;
01264 width >>= 1; height >>= 1;
01265 block_w >>= 1; block_h >>= 1;
01266 vp8_mc(s, 0, dst[1] + by_off * s->uvlinesize + bx_off,
01267 ref_frame->data[1], &uvmv, x_off + bx_off, y_off + by_off,
01268 block_w, block_h, width, height, s->uvlinesize,
01269 s->put_pixels_tab[1 + (block_w == 4)]);
01270 vp8_mc(s, 0, dst[2] + by_off * s->uvlinesize + bx_off,
01271 ref_frame->data[2], &uvmv, x_off + bx_off, y_off + by_off,
01272 block_w, block_h, width, height, s->uvlinesize,
01273 s->put_pixels_tab[1 + (block_w == 4)]);
01274 }
01275
01276
01277
01278 static av_always_inline void prefetch_motion(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, int mb_xy, int ref)
01279 {
01280
01281 if (s->ref_count[ref-1] > (mb_xy >> 5)) {
01282 int x_off = mb_x << 4, y_off = mb_y << 4;
01283 int mx = (mb->mv.x>>2) + x_off + 8;
01284 int my = (mb->mv.y>>2) + y_off;
01285 uint8_t **src= s->framep[ref]->data;
01286 int off= mx + (my + (mb_x&3)*4)*s->linesize + 64;
01287 s->dsp.prefetch(src[0]+off, s->linesize, 4);
01288 off= (mx>>1) + ((my>>1) + (mb_x&7))*s->uvlinesize + 64;
01289 s->dsp.prefetch(src[1]+off, src[2]-src[1], 2);
01290 }
01291 }
01292
01296 static av_always_inline
01297 void inter_predict(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb,
01298 int mb_x, int mb_y)
01299 {
01300 int x_off = mb_x << 4, y_off = mb_y << 4;
01301 int width = 16*s->mb_width, height = 16*s->mb_height;
01302 AVFrame *ref = s->framep[mb->ref_frame];
01303 VP56mv *bmv = mb->bmv;
01304
01305 if (mb->mode < VP8_MVMODE_SPLIT) {
01306 vp8_mc_part(s, dst, ref, x_off, y_off,
01307 0, 0, 16, 16, width, height, &mb->mv);
01308 } else switch (mb->partitioning) {
01309 case VP8_SPLITMVMODE_4x4: {
01310 int x, y;
01311 VP56mv uvmv;
01312
01313
01314 for (y = 0; y < 4; y++) {
01315 for (x = 0; x < 4; x++) {
01316 vp8_mc(s, 1, dst[0] + 4*y*s->linesize + x*4,
01317 ref->data[0], &bmv[4*y + x],
01318 4*x + x_off, 4*y + y_off, 4, 4,
01319 width, height, s->linesize,
01320 s->put_pixels_tab[2]);
01321 }
01322 }
01323
01324
01325 x_off >>= 1; y_off >>= 1; width >>= 1; height >>= 1;
01326 for (y = 0; y < 2; y++) {
01327 for (x = 0; x < 2; x++) {
01328 uvmv.x = mb->bmv[ 2*y * 4 + 2*x ].x +
01329 mb->bmv[ 2*y * 4 + 2*x+1].x +
01330 mb->bmv[(2*y+1) * 4 + 2*x ].x +
01331 mb->bmv[(2*y+1) * 4 + 2*x+1].x;
01332 uvmv.y = mb->bmv[ 2*y * 4 + 2*x ].y +
01333 mb->bmv[ 2*y * 4 + 2*x+1].y +
01334 mb->bmv[(2*y+1) * 4 + 2*x ].y +
01335 mb->bmv[(2*y+1) * 4 + 2*x+1].y;
01336 uvmv.x = (uvmv.x + 2 + (uvmv.x >> (INT_BIT-1))) >> 2;
01337 uvmv.y = (uvmv.y + 2 + (uvmv.y >> (INT_BIT-1))) >> 2;
01338 if (s->profile == 3) {
01339 uvmv.x &= ~7;
01340 uvmv.y &= ~7;
01341 }
01342 vp8_mc(s, 0, dst[1] + 4*y*s->uvlinesize + x*4,
01343 ref->data[1], &uvmv,
01344 4*x + x_off, 4*y + y_off, 4, 4,
01345 width, height, s->uvlinesize,
01346 s->put_pixels_tab[2]);
01347 vp8_mc(s, 0, dst[2] + 4*y*s->uvlinesize + x*4,
01348 ref->data[2], &uvmv,
01349 4*x + x_off, 4*y + y_off, 4, 4,
01350 width, height, s->uvlinesize,
01351 s->put_pixels_tab[2]);
01352 }
01353 }
01354 break;
01355 }
01356 case VP8_SPLITMVMODE_16x8:
01357 vp8_mc_part(s, dst, ref, x_off, y_off,
01358 0, 0, 16, 8, width, height, &bmv[0]);
01359 vp8_mc_part(s, dst, ref, x_off, y_off,
01360 0, 8, 16, 8, width, height, &bmv[1]);
01361 break;
01362 case VP8_SPLITMVMODE_8x16:
01363 vp8_mc_part(s, dst, ref, x_off, y_off,
01364 0, 0, 8, 16, width, height, &bmv[0]);
01365 vp8_mc_part(s, dst, ref, x_off, y_off,
01366 8, 0, 8, 16, width, height, &bmv[1]);
01367 break;
01368 case VP8_SPLITMVMODE_8x8:
01369 vp8_mc_part(s, dst, ref, x_off, y_off,
01370 0, 0, 8, 8, width, height, &bmv[0]);
01371 vp8_mc_part(s, dst, ref, x_off, y_off,
01372 8, 0, 8, 8, width, height, &bmv[1]);
01373 vp8_mc_part(s, dst, ref, x_off, y_off,
01374 0, 8, 8, 8, width, height, &bmv[2]);
01375 vp8_mc_part(s, dst, ref, x_off, y_off,
01376 8, 8, 8, 8, width, height, &bmv[3]);
01377 break;
01378 }
01379 }
01380
01381 static av_always_inline void idct_mb(VP8Context *s, uint8_t *dst[3], VP8Macroblock *mb)
01382 {
01383 int x, y, ch;
01384
01385 if (mb->mode != MODE_I4x4) {
01386 uint8_t *y_dst = dst[0];
01387 for (y = 0; y < 4; y++) {
01388 uint32_t nnz4 = AV_RN32A(s->non_zero_count_cache[y]);
01389 if (nnz4) {
01390 if (nnz4&~0x01010101) {
01391 for (x = 0; x < 4; x++) {
01392 int nnz = s->non_zero_count_cache[y][x];
01393 if (nnz) {
01394 if (nnz == 1)
01395 s->vp8dsp.vp8_idct_dc_add(y_dst+4*x, s->block[y][x], s->linesize);
01396 else
01397 s->vp8dsp.vp8_idct_add(y_dst+4*x, s->block[y][x], s->linesize);
01398 }
01399 }
01400 } else {
01401 s->vp8dsp.vp8_idct_dc_add4y(y_dst, s->block[y], s->linesize);
01402 }
01403 }
01404 y_dst += 4*s->linesize;
01405 }
01406 }
01407
01408 for (ch = 0; ch < 2; ch++) {
01409 uint32_t nnz4 = AV_RN32A(s->non_zero_count_cache[4+ch]);
01410 if (nnz4) {
01411 uint8_t *ch_dst = dst[1+ch];
01412 if (nnz4&~0x01010101) {
01413 for (y = 0; y < 2; y++) {
01414 for (x = 0; x < 2; x++) {
01415 int nnz = s->non_zero_count_cache[4+ch][(y<<1)+x];
01416 if (nnz) {
01417 if (nnz == 1)
01418 s->vp8dsp.vp8_idct_dc_add(ch_dst+4*x, s->block[4+ch][(y<<1)+x], s->uvlinesize);
01419 else
01420 s->vp8dsp.vp8_idct_add(ch_dst+4*x, s->block[4+ch][(y<<1)+x], s->uvlinesize);
01421 }
01422 }
01423 ch_dst += 4*s->uvlinesize;
01424 }
01425 } else {
01426 s->vp8dsp.vp8_idct_dc_add4uv(ch_dst, s->block[4+ch], s->uvlinesize);
01427 }
01428 }
01429 }
01430 }
01431
01432 static av_always_inline void filter_level_for_mb(VP8Context *s, VP8Macroblock *mb, VP8FilterStrength *f )
01433 {
01434 int interior_limit, filter_level;
01435
01436 if (s->segmentation.enabled) {
01437 filter_level = s->segmentation.filter_level[s->segment];
01438 if (!s->segmentation.absolute_vals)
01439 filter_level += s->filter.level;
01440 } else
01441 filter_level = s->filter.level;
01442
01443 if (s->lf_delta.enabled) {
01444 filter_level += s->lf_delta.ref[mb->ref_frame];
01445
01446 if (mb->ref_frame == VP56_FRAME_CURRENT) {
01447 if (mb->mode == MODE_I4x4)
01448 filter_level += s->lf_delta.mode[0];
01449 } else {
01450 if (mb->mode == VP8_MVMODE_ZERO)
01451 filter_level += s->lf_delta.mode[1];
01452 else if (mb->mode == VP8_MVMODE_SPLIT)
01453 filter_level += s->lf_delta.mode[3];
01454 else
01455 filter_level += s->lf_delta.mode[2];
01456 }
01457 }
01458 filter_level = av_clip(filter_level, 0, 63);
01459
01460 interior_limit = filter_level;
01461 if (s->filter.sharpness) {
01462 interior_limit >>= s->filter.sharpness > 4 ? 2 : 1;
01463 interior_limit = FFMIN(interior_limit, 9 - s->filter.sharpness);
01464 }
01465 interior_limit = FFMAX(interior_limit, 1);
01466
01467 f->filter_level = filter_level;
01468 f->inner_limit = interior_limit;
01469 f->inner_filter = !mb->skip || mb->mode == MODE_I4x4 || mb->mode == VP8_MVMODE_SPLIT;
01470 }
01471
01472 static av_always_inline void filter_mb(VP8Context *s, uint8_t *dst[3], VP8FilterStrength *f, int mb_x, int mb_y)
01473 {
01474 int mbedge_lim, bedge_lim, hev_thresh;
01475 int filter_level = f->filter_level;
01476 int inner_limit = f->inner_limit;
01477 int inner_filter = f->inner_filter;
01478 int linesize = s->linesize;
01479 int uvlinesize = s->uvlinesize;
01480
01481 if (!filter_level)
01482 return;
01483
01484 mbedge_lim = 2*(filter_level+2) + inner_limit;
01485 bedge_lim = 2* filter_level + inner_limit;
01486 hev_thresh = filter_level >= 15;
01487
01488 if (s->keyframe) {
01489 if (filter_level >= 40)
01490 hev_thresh = 2;
01491 } else {
01492 if (filter_level >= 40)
01493 hev_thresh = 3;
01494 else if (filter_level >= 20)
01495 hev_thresh = 2;
01496 }
01497
01498 if (mb_x) {
01499 s->vp8dsp.vp8_h_loop_filter16y(dst[0], linesize,
01500 mbedge_lim, inner_limit, hev_thresh);
01501 s->vp8dsp.vp8_h_loop_filter8uv(dst[1], dst[2], uvlinesize,
01502 mbedge_lim, inner_limit, hev_thresh);
01503 }
01504
01505 if (inner_filter) {
01506 s->vp8dsp.vp8_h_loop_filter16y_inner(dst[0]+ 4, linesize, bedge_lim,
01507 inner_limit, hev_thresh);
01508 s->vp8dsp.vp8_h_loop_filter16y_inner(dst[0]+ 8, linesize, bedge_lim,
01509 inner_limit, hev_thresh);
01510 s->vp8dsp.vp8_h_loop_filter16y_inner(dst[0]+12, linesize, bedge_lim,
01511 inner_limit, hev_thresh);
01512 s->vp8dsp.vp8_h_loop_filter8uv_inner(dst[1] + 4, dst[2] + 4,
01513 uvlinesize, bedge_lim,
01514 inner_limit, hev_thresh);
01515 }
01516
01517 if (mb_y) {
01518 s->vp8dsp.vp8_v_loop_filter16y(dst[0], linesize,
01519 mbedge_lim, inner_limit, hev_thresh);
01520 s->vp8dsp.vp8_v_loop_filter8uv(dst[1], dst[2], uvlinesize,
01521 mbedge_lim, inner_limit, hev_thresh);
01522 }
01523
01524 if (inner_filter) {
01525 s->vp8dsp.vp8_v_loop_filter16y_inner(dst[0]+ 4*linesize,
01526 linesize, bedge_lim,
01527 inner_limit, hev_thresh);
01528 s->vp8dsp.vp8_v_loop_filter16y_inner(dst[0]+ 8*linesize,
01529 linesize, bedge_lim,
01530 inner_limit, hev_thresh);
01531 s->vp8dsp.vp8_v_loop_filter16y_inner(dst[0]+12*linesize,
01532 linesize, bedge_lim,
01533 inner_limit, hev_thresh);
01534 s->vp8dsp.vp8_v_loop_filter8uv_inner(dst[1] + 4 * uvlinesize,
01535 dst[2] + 4 * uvlinesize,
01536 uvlinesize, bedge_lim,
01537 inner_limit, hev_thresh);
01538 }
01539 }
01540
01541 static av_always_inline void filter_mb_simple(VP8Context *s, uint8_t *dst, VP8FilterStrength *f, int mb_x, int mb_y)
01542 {
01543 int mbedge_lim, bedge_lim;
01544 int filter_level = f->filter_level;
01545 int inner_limit = f->inner_limit;
01546 int inner_filter = f->inner_filter;
01547 int linesize = s->linesize;
01548
01549 if (!filter_level)
01550 return;
01551
01552 mbedge_lim = 2*(filter_level+2) + inner_limit;
01553 bedge_lim = 2* filter_level + inner_limit;
01554
01555 if (mb_x)
01556 s->vp8dsp.vp8_h_loop_filter_simple(dst, linesize, mbedge_lim);
01557 if (inner_filter) {
01558 s->vp8dsp.vp8_h_loop_filter_simple(dst+ 4, linesize, bedge_lim);
01559 s->vp8dsp.vp8_h_loop_filter_simple(dst+ 8, linesize, bedge_lim);
01560 s->vp8dsp.vp8_h_loop_filter_simple(dst+12, linesize, bedge_lim);
01561 }
01562
01563 if (mb_y)
01564 s->vp8dsp.vp8_v_loop_filter_simple(dst, linesize, mbedge_lim);
01565 if (inner_filter) {
01566 s->vp8dsp.vp8_v_loop_filter_simple(dst+ 4*linesize, linesize, bedge_lim);
01567 s->vp8dsp.vp8_v_loop_filter_simple(dst+ 8*linesize, linesize, bedge_lim);
01568 s->vp8dsp.vp8_v_loop_filter_simple(dst+12*linesize, linesize, bedge_lim);
01569 }
01570 }
01571
01572 static void filter_mb_row(VP8Context *s, int mb_y)
01573 {
01574 VP8FilterStrength *f = s->filter_strength;
01575 uint8_t *dst[3] = {
01576 s->framep[VP56_FRAME_CURRENT]->data[0] + 16*mb_y*s->linesize,
01577 s->framep[VP56_FRAME_CURRENT]->data[1] + 8*mb_y*s->uvlinesize,
01578 s->framep[VP56_FRAME_CURRENT]->data[2] + 8*mb_y*s->uvlinesize
01579 };
01580 int mb_x;
01581
01582 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
01583 backup_mb_border(s->top_border[mb_x+1], dst[0], dst[1], dst[2], s->linesize, s->uvlinesize, 0);
01584 filter_mb(s, dst, f++, mb_x, mb_y);
01585 dst[0] += 16;
01586 dst[1] += 8;
01587 dst[2] += 8;
01588 }
01589 }
01590
01591 static void filter_mb_row_simple(VP8Context *s, int mb_y)
01592 {
01593 VP8FilterStrength *f = s->filter_strength;
01594 uint8_t *dst = s->framep[VP56_FRAME_CURRENT]->data[0] + 16*mb_y*s->linesize;
01595 int mb_x;
01596
01597 for (mb_x = 0; mb_x < s->mb_width; mb_x++) {
01598 backup_mb_border(s->top_border[mb_x+1], dst, NULL, NULL, s->linesize, 0, 1);
01599 filter_mb_simple(s, dst, f++, mb_x, mb_y);
01600 dst += 16;
01601 }
01602 }
01603
01604 static int vp8_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
01605 AVPacket *avpkt)
01606 {
01607 VP8Context *s = avctx->priv_data;
01608 int ret, mb_x, mb_y, i, y, referenced;
01609 enum AVDiscard skip_thresh;
01610 AVFrame *av_uninit(curframe);
01611
01612 if ((ret = decode_frame_header(s, avpkt->data, avpkt->size)) < 0)
01613 return ret;
01614
01615 referenced = s->update_last || s->update_golden == VP56_FRAME_CURRENT
01616 || s->update_altref == VP56_FRAME_CURRENT;
01617
01618 skip_thresh = !referenced ? AVDISCARD_NONREF :
01619 !s->keyframe ? AVDISCARD_NONKEY : AVDISCARD_ALL;
01620
01621 if (avctx->skip_frame >= skip_thresh) {
01622 s->invisible = 1;
01623 goto skip_decode;
01624 }
01625 s->deblock_filter = s->filter.level && avctx->skip_loop_filter < skip_thresh;
01626
01627 for (i = 0; i < 4; i++)
01628 if (&s->frames[i] != s->framep[VP56_FRAME_PREVIOUS] &&
01629 &s->frames[i] != s->framep[VP56_FRAME_GOLDEN] &&
01630 &s->frames[i] != s->framep[VP56_FRAME_GOLDEN2]) {
01631 curframe = s->framep[VP56_FRAME_CURRENT] = &s->frames[i];
01632 break;
01633 }
01634 if (curframe->data[0])
01635 avctx->release_buffer(avctx, curframe);
01636
01637 curframe->key_frame = s->keyframe;
01638 curframe->pict_type = s->keyframe ? FF_I_TYPE : FF_P_TYPE;
01639 curframe->reference = referenced ? 3 : 0;
01640 if ((ret = avctx->get_buffer(avctx, curframe))) {
01641 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed!\n");
01642 return ret;
01643 }
01644
01645
01646
01647
01648 if (!s->keyframe && (!s->framep[VP56_FRAME_PREVIOUS] ||
01649 !s->framep[VP56_FRAME_GOLDEN] ||
01650 !s->framep[VP56_FRAME_GOLDEN2])) {
01651 av_log(avctx, AV_LOG_WARNING, "Discarding interframe without a prior keyframe!\n");
01652 return AVERROR_INVALIDDATA;
01653 }
01654
01655 s->linesize = curframe->linesize[0];
01656 s->uvlinesize = curframe->linesize[1];
01657
01658 if (!s->edge_emu_buffer)
01659 s->edge_emu_buffer = av_malloc(21*s->linesize);
01660
01661 memset(s->top_nnz, 0, s->mb_width*sizeof(*s->top_nnz));
01662
01663
01664 memset(s->macroblocks + s->mb_height*2 - 1, 0, (s->mb_width+1)*sizeof(*s->macroblocks));
01665
01666
01667 if (!(avctx->flags & CODEC_FLAG_EMU_EDGE)) {
01668 s->top_border[0][15] = s->top_border[0][23] = 127;
01669 memset(s->top_border[1]-1, 127, s->mb_width*sizeof(*s->top_border)+1);
01670 }
01671 memset(s->ref_count, 0, sizeof(s->ref_count));
01672 if (s->keyframe)
01673 memset(s->intra4x4_pred_mode_top, DC_PRED, s->mb_width*4);
01674
01675 for (mb_y = 0; mb_y < s->mb_height; mb_y++) {
01676 VP56RangeCoder *c = &s->coeff_partition[mb_y & (s->num_coeff_partitions-1)];
01677 VP8Macroblock *mb = s->macroblocks + (s->mb_height - mb_y - 1)*2;
01678 int mb_xy = mb_y*s->mb_width;
01679 uint8_t *dst[3] = {
01680 curframe->data[0] + 16*mb_y*s->linesize,
01681 curframe->data[1] + 8*mb_y*s->uvlinesize,
01682 curframe->data[2] + 8*mb_y*s->uvlinesize
01683 };
01684
01685 memset(mb - 1, 0, sizeof(*mb));
01686 memset(s->left_nnz, 0, sizeof(s->left_nnz));
01687 AV_WN32A(s->intra4x4_pred_mode_left, DC_PRED*0x01010101);
01688
01689
01690 if (!(avctx->flags & CODEC_FLAG_EMU_EDGE)) {
01691 for (i = 0; i < 3; i++)
01692 for (y = 0; y < 16>>!!i; y++)
01693 dst[i][y*curframe->linesize[i]-1] = 129;
01694 if (mb_y == 1)
01695 s->top_border[0][15] = s->top_border[0][23] = s->top_border[0][31] = 129;
01696 }
01697
01698 for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb_xy++, mb++) {
01699
01700 s->dsp.prefetch(dst[0] + (mb_x&3)*4*s->linesize + 64, s->linesize, 4);
01701 s->dsp.prefetch(dst[1] + (mb_x&7)*s->uvlinesize + 64, dst[2] - dst[1], 2);
01702
01703 decode_mb_mode(s, mb, mb_x, mb_y, s->segmentation_map + mb_xy);
01704
01705 prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_PREVIOUS);
01706
01707 if (!mb->skip)
01708 decode_mb_coeffs(s, c, mb, s->top_nnz[mb_x], s->left_nnz);
01709
01710 if (mb->mode <= MODE_I4x4)
01711 intra_predict(s, dst, mb, mb_x, mb_y);
01712 else
01713 inter_predict(s, dst, mb, mb_x, mb_y);
01714
01715 prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_GOLDEN);
01716
01717 if (!mb->skip) {
01718 idct_mb(s, dst, mb);
01719 } else {
01720 AV_ZERO64(s->left_nnz);
01721 AV_WN64(s->top_nnz[mb_x], 0);
01722
01723
01724 if (mb->mode != MODE_I4x4 && mb->mode != VP8_MVMODE_SPLIT) {
01725 s->left_nnz[8] = 0;
01726 s->top_nnz[mb_x][8] = 0;
01727 }
01728 }
01729
01730 if (s->deblock_filter)
01731 filter_level_for_mb(s, mb, &s->filter_strength[mb_x]);
01732
01733 prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_GOLDEN2);
01734
01735 dst[0] += 16;
01736 dst[1] += 8;
01737 dst[2] += 8;
01738 }
01739 if (s->deblock_filter) {
01740 if (s->filter.simple)
01741 filter_mb_row_simple(s, mb_y);
01742 else
01743 filter_mb_row(s, mb_y);
01744 }
01745 }
01746
01747 skip_decode:
01748
01749
01750 if (!s->update_probabilities)
01751 s->prob[0] = s->prob[1];
01752
01753
01754 if (s->update_altref == VP56_FRAME_GOLDEN &&
01755 s->update_golden == VP56_FRAME_GOLDEN2)
01756 FFSWAP(AVFrame *, s->framep[VP56_FRAME_GOLDEN], s->framep[VP56_FRAME_GOLDEN2]);
01757 else {
01758 if (s->update_altref != VP56_FRAME_NONE)
01759 s->framep[VP56_FRAME_GOLDEN2] = s->framep[s->update_altref];
01760
01761 if (s->update_golden != VP56_FRAME_NONE)
01762 s->framep[VP56_FRAME_GOLDEN] = s->framep[s->update_golden];
01763 }
01764
01765 if (s->update_last)
01766 s->framep[VP56_FRAME_PREVIOUS] = s->framep[VP56_FRAME_CURRENT];
01767
01768
01769 for (i = 0; i < 4; i++)
01770 if (s->frames[i].data[0] &&
01771 &s->frames[i] != s->framep[VP56_FRAME_CURRENT] &&
01772 &s->frames[i] != s->framep[VP56_FRAME_PREVIOUS] &&
01773 &s->frames[i] != s->framep[VP56_FRAME_GOLDEN] &&
01774 &s->frames[i] != s->framep[VP56_FRAME_GOLDEN2])
01775 avctx->release_buffer(avctx, &s->frames[i]);
01776
01777 if (!s->invisible) {
01778 *(AVFrame*)data = *s->framep[VP56_FRAME_CURRENT];
01779 *data_size = sizeof(AVFrame);
01780 }
01781
01782 return avpkt->size;
01783 }
01784
01785 static av_cold int vp8_decode_init(AVCodecContext *avctx)
01786 {
01787 VP8Context *s = avctx->priv_data;
01788
01789 s->avctx = avctx;
01790 avctx->pix_fmt = PIX_FMT_YUV420P;
01791
01792 dsputil_init(&s->dsp, avctx);
01793 ff_h264_pred_init(&s->hpc, CODEC_ID_VP8);
01794 ff_vp8dsp_init(&s->vp8dsp);
01795
01796 return 0;
01797 }
01798
01799 static av_cold int vp8_decode_free(AVCodecContext *avctx)
01800 {
01801 vp8_decode_flush(avctx);
01802 return 0;
01803 }
01804
01805 AVCodec vp8_decoder = {
01806 "vp8",
01807 AVMEDIA_TYPE_VIDEO,
01808 CODEC_ID_VP8,
01809 sizeof(VP8Context),
01810 vp8_decode_init,
01811 NULL,
01812 vp8_decode_free,
01813 vp8_decode_frame,
01814 CODEC_CAP_DR1,
01815 .flush = vp8_decode_flush,
01816 .long_name = NULL_IF_CONFIG_SMALL("On2 VP8"),
01817 };