| OLD | NEW |
| 1 /** | 1 /** |
| 2 * VP8 compatible video decoder | 2 * VP8 compatible video decoder |
| 3 * | 3 * |
| 4 * Copyright (C) 2010 David Conrad | 4 * Copyright (C) 2010 David Conrad |
| 5 * Copyright (C) 2010 Ronald S. Bultje | 5 * Copyright (C) 2010 Ronald S. Bultje |
| 6 * Copyright (C) 2010 Jason Garrett-Glaser | 6 * Copyright (C) 2010 Jason Garrett-Glaser |
| 7 * | 7 * |
| 8 * This file is part of FFmpeg. | 8 * This file is part of FFmpeg. |
| 9 * | 9 * |
| 10 * FFmpeg is free software; you can redistribute it and/or | 10 * FFmpeg is free software; you can redistribute it and/or |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 /** | 80 /** |
| 81 * All coefficients are contained in separate arith coding contexts. | 81 * All coefficients are contained in separate arith coding contexts. |
| 82 * There can be 1, 2, 4, or 8 of these after the header context. | 82 * There can be 1, 2, 4, or 8 of these after the header context. |
| 83 */ | 83 */ |
| 84 int num_coeff_partitions; | 84 int num_coeff_partitions; |
| 85 VP56RangeCoder coeff_partition[8]; | 85 VP56RangeCoder coeff_partition[8]; |
| 86 | 86 |
| 87 VP8Macroblock *macroblocks; | 87 VP8Macroblock *macroblocks; |
| 88 VP8Macroblock *macroblocks_base; | 88 VP8Macroblock *macroblocks_base; |
| 89 VP8FilterStrength *filter_strength; | 89 VP8FilterStrength *filter_strength; |
| 90 int mb_stride; | |
| 91 | 90 |
| 92 uint8_t *intra4x4_pred_mode_top; | 91 uint8_t *intra4x4_pred_mode_top; |
| 93 uint8_t intra4x4_pred_mode_left[4]; | 92 uint8_t intra4x4_pred_mode_left[4]; |
| 94 uint8_t *segmentation_map; | 93 uint8_t *segmentation_map; |
| 95 int b4_stride; | |
| 96 | 94 |
| 97 /** | 95 /** |
| 98 * Cache of the top row needed for intra prediction | 96 * Cache of the top row needed for intra prediction |
| 99 * 16 for luma, 8 for each chroma plane | 97 * 16 for luma, 8 for each chroma plane |
| 100 */ | 98 */ |
| 101 uint8_t (*top_border)[16+8+8]; | 99 uint8_t (*top_border)[16+8+8]; |
| 102 | 100 |
| 103 /** | 101 /** |
| 104 * For coeff decode, we need to know whether the above block had non-zero | 102 * For coeff decode, we need to know whether the above block had non-zero |
| 105 * coefficients. This means for each macroblock, we need data for 4 luma | 103 * coefficients. This means for each macroblock, we need data for 4 luma |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 av_freep(&s->top_nnz); | 216 av_freep(&s->top_nnz); |
| 219 av_freep(&s->edge_emu_buffer); | 217 av_freep(&s->edge_emu_buffer); |
| 220 av_freep(&s->top_border); | 218 av_freep(&s->top_border); |
| 221 av_freep(&s->segmentation_map); | 219 av_freep(&s->segmentation_map); |
| 222 | 220 |
| 223 s->macroblocks = NULL; | 221 s->macroblocks = NULL; |
| 224 } | 222 } |
| 225 | 223 |
| 226 static int update_dimensions(VP8Context *s, int width, int height) | 224 static int update_dimensions(VP8Context *s, int width, int height) |
| 227 { | 225 { |
| 228 if (av_check_image_size(width, height, 0, s->avctx)) | 226 if (av_image_check_size(width, height, 0, s->avctx)) |
| 229 return AVERROR_INVALIDDATA; | 227 return AVERROR_INVALIDDATA; |
| 230 | 228 |
| 231 vp8_decode_flush(s->avctx); | 229 vp8_decode_flush(s->avctx); |
| 232 | 230 |
| 233 avcodec_set_dimensions(s->avctx, width, height); | 231 avcodec_set_dimensions(s->avctx, width, height); |
| 234 | 232 |
| 235 s->mb_width = (s->avctx->coded_width +15) / 16; | 233 s->mb_width = (s->avctx->coded_width +15) / 16; |
| 236 s->mb_height = (s->avctx->coded_height+15) / 16; | 234 s->mb_height = (s->avctx->coded_height+15) / 16; |
| 237 | 235 |
| 238 // we allocate a border around the top/left of intra4x4 modes | 236 s->macroblocks_base = av_mallocz((s->mb_width+s->mb_height*2+1)*sizeo
f(*s->macroblocks)); |
| 239 // this is 4 blocks for intra4x4 to keep 4-byte alignment for fill_rectangle | 237 s->filter_strength = av_mallocz(s->mb_width*sizeof(*s->filter_streng
th)); |
| 240 s->mb_stride = s->mb_width+1; | 238 s->intra4x4_pred_mode_top = av_mallocz(s->mb_width*4); |
| 241 s->b4_stride = 4*s->mb_stride; | |
| 242 | |
| 243 s->macroblocks_base = av_mallocz((s->mb_stride+s->mb_height*2+2)*size
of(*s->macroblocks)); | |
| 244 s->filter_strength = av_mallocz(s->mb_stride*sizeof(*s->filter_stren
gth)); | |
| 245 s->intra4x4_pred_mode_top = av_mallocz(s->b4_stride*4); | |
| 246 s->top_nnz = av_mallocz(s->mb_width*sizeof(*s->top_nnz)); | 239 s->top_nnz = av_mallocz(s->mb_width*sizeof(*s->top_nnz)); |
| 247 s->top_border = av_mallocz((s->mb_width+1)*sizeof(*s->top_borde
r)); | 240 s->top_border = av_mallocz((s->mb_width+1)*sizeof(*s->top_borde
r)); |
| 248 s->segmentation_map = av_mallocz(s->mb_stride*s->mb_height); | 241 s->segmentation_map = av_mallocz(s->mb_width*s->mb_height); |
| 249 | 242 |
| 250 if (!s->macroblocks_base || !s->filter_strength || !s->intra4x4_pred_mode_to
p || | 243 if (!s->macroblocks_base || !s->filter_strength || !s->intra4x4_pred_mode_to
p || |
| 251 !s->top_nnz || !s->top_border || !s->segmentation_map) | 244 !s->top_nnz || !s->top_border || !s->segmentation_map) |
| 252 return AVERROR(ENOMEM); | 245 return AVERROR(ENOMEM); |
| 253 | 246 |
| 254 s->macroblocks = s->macroblocks_base + 1; | 247 s->macroblocks = s->macroblocks_base + 1; |
| 255 | 248 |
| 256 return 0; | 249 return 0; |
| 257 } | 250 } |
| 258 | 251 |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 void clamp_mv(VP8Context *s, VP56mv *dst, const VP56mv *src, int mb_x, int mb_y) | 521 void clamp_mv(VP8Context *s, VP56mv *dst, const VP56mv *src, int mb_x, int mb_y) |
| 529 { | 522 { |
| 530 #define MARGIN (16 << 2) | 523 #define MARGIN (16 << 2) |
| 531 dst->x = av_clip(src->x, -((mb_x << 6) + MARGIN), | 524 dst->x = av_clip(src->x, -((mb_x << 6) + MARGIN), |
| 532 ((s->mb_width - 1 - mb_x) << 6) + MARGIN); | 525 ((s->mb_width - 1 - mb_x) << 6) + MARGIN); |
| 533 dst->y = av_clip(src->y, -((mb_y << 6) + MARGIN), | 526 dst->y = av_clip(src->y, -((mb_y << 6) + MARGIN), |
| 534 ((s->mb_height - 1 - mb_y) << 6) + MARGIN); | 527 ((s->mb_height - 1 - mb_y) << 6) + MARGIN); |
| 535 } | 528 } |
| 536 | 529 |
| 537 static av_always_inline | 530 static av_always_inline |
| 538 void find_near_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, | 531 void find_near_mvs(VP8Context *s, VP8Macroblock *mb, |
| 539 VP56mv near[2], VP56mv *best, uint8_t cnt[4]) | 532 VP56mv near[2], VP56mv *best, uint8_t cnt[4]) |
| 540 { | 533 { |
| 541 VP8Macroblock *mb_edge[3] = { mb + 2 /* top */, | 534 VP8Macroblock *mb_edge[3] = { mb + 2 /* top */, |
| 542 mb - 1 /* left */, | 535 mb - 1 /* left */, |
| 543 mb + 1 /* top-left */ }; | 536 mb + 1 /* top-left */ }; |
| 544 enum { VP8_EDGE_TOP, VP8_EDGE_LEFT, VP8_EDGE_TOPLEFT }; | 537 enum { VP8_EDGE_TOP, VP8_EDGE_LEFT, VP8_EDGE_TOPLEFT }; |
| 545 VP56mv near_mv[4] = {{ 0 }}; | 538 VP56mv near_mv[4] = {{ 0 }}; |
| 546 enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV }; | 539 enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV }; |
| 547 int idx = CNT_ZERO; | 540 int idx = CNT_ZERO; |
| 548 int best_idx = CNT_ZERO; | 541 int best_idx = CNT_ZERO; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 760 | 753 |
| 761 // inter MB, 16.2 | 754 // inter MB, 16.2 |
| 762 if (vp56_rac_get_prob_branchy(c, s->prob->last)) | 755 if (vp56_rac_get_prob_branchy(c, s->prob->last)) |
| 763 mb->ref_frame = vp56_rac_get_prob(c, s->prob->golden) ? | 756 mb->ref_frame = vp56_rac_get_prob(c, s->prob->golden) ? |
| 764 VP56_FRAME_GOLDEN2 /* altref */ : VP56_FRAME_GOLDEN; | 757 VP56_FRAME_GOLDEN2 /* altref */ : VP56_FRAME_GOLDEN; |
| 765 else | 758 else |
| 766 mb->ref_frame = VP56_FRAME_PREVIOUS; | 759 mb->ref_frame = VP56_FRAME_PREVIOUS; |
| 767 s->ref_count[mb->ref_frame-1]++; | 760 s->ref_count[mb->ref_frame-1]++; |
| 768 | 761 |
| 769 // motion vectors, 16.3 | 762 // motion vectors, 16.3 |
| 770 find_near_mvs(s, mb, mb_x, mb_y, near, &best, cnt); | 763 find_near_mvs(s, mb, near, &best, cnt); |
| 771 if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[0]][0])) { | 764 if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[0]][0])) { |
| 772 if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[1]][1])) { | 765 if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[1]][1])) { |
| 773 if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[2]][2]))
{ | 766 if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[2]][2]))
{ |
| 774 if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[3]][3
])) { | 767 if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[3]][3
])) { |
| 775 mb->mode = VP8_MVMODE_SPLIT; | 768 mb->mode = VP8_MVMODE_SPLIT; |
| 776 clamp_mv(s, &mb->mv, &mb->mv, mb_x, mb_y); | 769 clamp_mv(s, &mb->mv, &mb->mv, mb_x, mb_y); |
| 777 mb->mv = mb->bmv[decode_splitmvs(s, c, mb) - 1]; | 770 mb->mv = mb->bmv[decode_splitmvs(s, c, mb) - 1]; |
| 778 } else { | 771 } else { |
| 779 mb->mode = VP8_MVMODE_NEW; | 772 mb->mode = VP8_MVMODE_NEW; |
| 780 clamp_mv(s, &mb->mv, &mb->mv, mb_x, mb_y); | 773 clamp_mv(s, &mb->mv, &mb->mv, mb_x, mb_y); |
| 781 mb->mv.y += + read_mv_component(c, s->prob->mvc[0]); | 774 mb->mv.y += read_mv_component(c, s->prob->mvc[0]); |
| 782 mb->mv.x += + read_mv_component(c, s->prob->mvc[1]); | 775 mb->mv.x += read_mv_component(c, s->prob->mvc[1]); |
| 783 } | 776 } |
| 784 } else { | 777 } else { |
| 785 mb->mode = VP8_MVMODE_NEAR; | 778 mb->mode = VP8_MVMODE_NEAR; |
| 786 clamp_mv(s, &mb->mv, &near[1], mb_x, mb_y); | 779 clamp_mv(s, &mb->mv, &near[1], mb_x, mb_y); |
| 787 } | 780 } |
| 788 } else { | 781 } else { |
| 789 mb->mode = VP8_MVMODE_NEAREST; | 782 mb->mode = VP8_MVMODE_NEAREST; |
| 790 clamp_mv(s, &mb->mv, &near[0], mb_x, mb_y); | 783 clamp_mv(s, &mb->mv, &near[0], mb_x, mb_y); |
| 791 } | 784 } |
| 792 } else { | 785 } else { |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1529 } | 1522 } |
| 1530 | 1523 |
| 1531 s->linesize = curframe->linesize[0]; | 1524 s->linesize = curframe->linesize[0]; |
| 1532 s->uvlinesize = curframe->linesize[1]; | 1525 s->uvlinesize = curframe->linesize[1]; |
| 1533 | 1526 |
| 1534 if (!s->edge_emu_buffer) | 1527 if (!s->edge_emu_buffer) |
| 1535 s->edge_emu_buffer = av_malloc(21*s->linesize); | 1528 s->edge_emu_buffer = av_malloc(21*s->linesize); |
| 1536 | 1529 |
| 1537 memset(s->top_nnz, 0, s->mb_width*sizeof(*s->top_nnz)); | 1530 memset(s->top_nnz, 0, s->mb_width*sizeof(*s->top_nnz)); |
| 1538 | 1531 |
| 1539 /* Zero macroblock structures for top/left prediction from outside the frame
. */ | 1532 /* Zero macroblock structures for top/top-left prediction from outside the f
rame. */ |
| 1540 memset(s->macroblocks, 0, (s->mb_width + s->mb_height*2)*sizeof(*s->macroblo
cks)); | 1533 memset(s->macroblocks + s->mb_height*2 - 1, 0, (s->mb_width+1)*sizeof(*s->ma
croblocks)); |
| 1541 | 1534 |
| 1542 // top edge of 127 for intra prediction | 1535 // top edge of 127 for intra prediction |
| 1543 memset(s->top_border, 127, (s->mb_width+1)*sizeof(*s->top_border)); | 1536 memset(s->top_border, 127, (s->mb_width+1)*sizeof(*s->top_border)); |
| 1544 memset(s->ref_count, 0, sizeof(s->ref_count)); | 1537 memset(s->ref_count, 0, sizeof(s->ref_count)); |
| 1545 if (s->keyframe) | 1538 if (s->keyframe) |
| 1546 memset(s->intra4x4_pred_mode_top, DC_PRED, s->b4_stride*4); | 1539 memset(s->intra4x4_pred_mode_top, DC_PRED, s->mb_width*4); |
| 1547 | 1540 |
| 1548 for (mb_y = 0; mb_y < s->mb_height; mb_y++) { | 1541 for (mb_y = 0; mb_y < s->mb_height; mb_y++) { |
| 1549 VP56RangeCoder *c = &s->coeff_partition[mb_y & (s->num_coeff_partitions-
1)]; | 1542 VP56RangeCoder *c = &s->coeff_partition[mb_y & (s->num_coeff_partitions-
1)]; |
| 1550 VP8Macroblock *mb = s->macroblocks + (s->mb_height - mb_y - 1)*2; | 1543 VP8Macroblock *mb = s->macroblocks + (s->mb_height - mb_y - 1)*2; |
| 1551 uint8_t *segment_map = s->segmentation_map + mb_y*s->mb_stride; | 1544 int mb_xy = mb_y*s->mb_width; |
| 1552 int mb_xy = mb_y * s->mb_stride; | |
| 1553 uint8_t *dst[3] = { | 1545 uint8_t *dst[3] = { |
| 1554 curframe->data[0] + 16*mb_y*s->linesize, | 1546 curframe->data[0] + 16*mb_y*s->linesize, |
| 1555 curframe->data[1] + 8*mb_y*s->uvlinesize, | 1547 curframe->data[1] + 8*mb_y*s->uvlinesize, |
| 1556 curframe->data[2] + 8*mb_y*s->uvlinesize | 1548 curframe->data[2] + 8*mb_y*s->uvlinesize |
| 1557 }; | 1549 }; |
| 1558 | 1550 |
| 1551 memset(mb - 1, 0, sizeof(*mb)); // zero left macroblock |
| 1559 memset(s->left_nnz, 0, sizeof(s->left_nnz)); | 1552 memset(s->left_nnz, 0, sizeof(s->left_nnz)); |
| 1560 AV_WN32A(s->intra4x4_pred_mode_left, DC_PRED*0x01010101); | 1553 AV_WN32A(s->intra4x4_pred_mode_left, DC_PRED*0x01010101); |
| 1561 | 1554 |
| 1562 // left edge of 129 for intra prediction | 1555 // left edge of 129 for intra prediction |
| 1563 if (!(avctx->flags & CODEC_FLAG_EMU_EDGE)) | 1556 if (!(avctx->flags & CODEC_FLAG_EMU_EDGE)) |
| 1564 for (i = 0; i < 3; i++) | 1557 for (i = 0; i < 3; i++) |
| 1565 for (y = 0; y < 16>>!!i; y++) | 1558 for (y = 0; y < 16>>!!i; y++) |
| 1566 dst[i][y*curframe->linesize[i]-1] = 129; | 1559 dst[i][y*curframe->linesize[i]-1] = 129; |
| 1567 if (mb_y) | 1560 if (mb_y) |
| 1568 memset(s->top_border, 129, sizeof(*s->top_border)); | 1561 memset(s->top_border, 129, sizeof(*s->top_border)); |
| 1569 | 1562 |
| 1570 for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb_xy++, mb++) { | 1563 for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb_xy++, mb++) { |
| 1571 uint8_t *segment_mb = segment_map+mb_x; | |
| 1572 | |
| 1573 /* Prefetch the current frame, 4 MBs ahead */ | 1564 /* Prefetch the current frame, 4 MBs ahead */ |
| 1574 s->dsp.prefetch(dst[0] + (mb_x&3)*4*s->linesize + 64, s->linesize, 4
); | 1565 s->dsp.prefetch(dst[0] + (mb_x&3)*4*s->linesize + 64, s->linesize, 4
); |
| 1575 s->dsp.prefetch(dst[1] + (mb_x&7)*s->uvlinesize + 64, dst[2] - dst[1
], 2); | 1566 s->dsp.prefetch(dst[1] + (mb_x&7)*s->uvlinesize + 64, dst[2] - dst[1
], 2); |
| 1576 | 1567 |
| 1577 decode_mb_mode(s, mb, mb_x, mb_y, segment_mb); | 1568 decode_mb_mode(s, mb, mb_x, mb_y, s->segmentation_map + mb_xy); |
| 1578 | 1569 |
| 1579 prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_PREVIOUS); | 1570 prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_PREVIOUS); |
| 1580 | 1571 |
| 1581 if (!mb->skip) | 1572 if (!mb->skip) |
| 1582 decode_mb_coeffs(s, c, mb, s->top_nnz[mb_x], s->left_nnz); | 1573 decode_mb_coeffs(s, c, mb, s->top_nnz[mb_x], s->left_nnz); |
| 1583 | 1574 |
| 1584 if (mb->mode <= MODE_I4x4) | 1575 if (mb->mode <= MODE_I4x4) |
| 1585 intra_predict(s, dst, mb, mb_x, mb_y); | 1576 intra_predict(s, dst, mb, mb_x, mb_y); |
| 1586 else | 1577 else |
| 1587 inter_predict(s, dst, mb, mb_x, mb_y); | 1578 inter_predict(s, dst, mb, mb_x, mb_y); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1688 CODEC_ID_VP8, | 1679 CODEC_ID_VP8, |
| 1689 sizeof(VP8Context), | 1680 sizeof(VP8Context), |
| 1690 vp8_decode_init, | 1681 vp8_decode_init, |
| 1691 NULL, | 1682 NULL, |
| 1692 vp8_decode_free, | 1683 vp8_decode_free, |
| 1693 vp8_decode_frame, | 1684 vp8_decode_frame, |
| 1694 CODEC_CAP_DR1, | 1685 CODEC_CAP_DR1, |
| 1695 .flush = vp8_decode_flush, | 1686 .flush = vp8_decode_flush, |
| 1696 .long_name = NULL_IF_CONFIG_SMALL("On2 VP8"), | 1687 .long_name = NULL_IF_CONFIG_SMALL("On2 VP8"), |
| 1697 }; | 1688 }; |
| OLD | NEW |