Revision f3d09d44
libavcodec/vp8.c  

528  528 
((s>mb_height  1  mb_y) << 6) + MARGIN); 
529  529 
} 
530  530  
531 
static av_always_inline 

532 
void find_near_mvs(VP8Context *s, VP8Macroblock *mb, 

533 
VP56mv near[2], VP56mv *best, uint8_t cnt[4]) 

534 
{ 

535 
VP8Macroblock *mb_edge[3] = { mb + 2 /* top */, 

536 
mb  1 /* left */, 

537 
mb + 1 /* topleft */ }; 

538 
enum { EDGE_TOP, EDGE_LEFT, EDGE_TOPLEFT }; 

539 
VP56mv near_mv[4] = {{ 0 }}; 

540 
enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV }; 

541 
int idx = CNT_ZERO; 

542 
int best_idx = CNT_ZERO; 

543 
int cur_sign_bias = s>sign_bias[mb>ref_frame]; 

544 
int *sign_bias = s>sign_bias; 

545  
546 
/* Process MB on top, left and topleft */ 

547 
#define MV_EDGE_CHECK(n)\ 

548 
{\ 

549 
VP8Macroblock *edge = mb_edge[n];\ 

550 
int edge_ref = edge>ref_frame;\ 

551 
if (edge_ref != VP56_FRAME_CURRENT) {\ 

552 
uint32_t mv = AV_RN32A(&edge>mv);\ 

553 
if (mv) {\ 

554 
if (cur_sign_bias != sign_bias[edge_ref]) {\ 

555 
/* SWAR negate of the values in mv. */\ 

556 
mv = ~mv;\ 

557 
mv = ((mv&0x7fff7fff) + 0x00010001) ^ (mv&0x80008000);\ 

558 
}\ 

559 
if (!n  mv != AV_RN32A(&near_mv[idx]))\ 

560 
AV_WN32A(&near_mv[++idx], mv);\ 

561 
cnt[idx] += 1 + (n != 2);\ 

562 
} else\ 

563 
cnt[CNT_ZERO] += 1 + (n != 2);\ 

564 
}\ 

565 
} 

566 
MV_EDGE_CHECK(0) 

567 
MV_EDGE_CHECK(1) 

568 
MV_EDGE_CHECK(2) 

569  
570 
/* If we have three distinct MVs, merge first and last if they're the same */ 

571 
if (cnt[CNT_SPLITMV] && AV_RN32A(&near_mv[1+EDGE_TOP]) == AV_RN32A(&near_mv[1+EDGE_TOPLEFT])) 

572 
cnt[CNT_NEAREST] += 1; 

573  
574 
cnt[CNT_SPLITMV] = ((mb_edge[EDGE_LEFT]>mode == VP8_MVMODE_SPLIT) + 

575 
(mb_edge[EDGE_TOP]>mode == VP8_MVMODE_SPLIT)) * 2 + 

576 
(mb_edge[EDGE_TOPLEFT]>mode == VP8_MVMODE_SPLIT); 

577  
578 
/* Swap near and nearest if necessary */ 

579 
if (cnt[CNT_NEAR] > cnt[CNT_NEAREST]) { 

580 
FFSWAP(uint8_t, cnt[CNT_NEAREST], cnt[CNT_NEAR]); 

581 
FFSWAP( VP56mv, near_mv[CNT_NEAREST], near_mv[CNT_NEAR]); 

582 
} 

583  
584 
/* Choose the best mv out of 0,0 and the nearest mv */ 

585 
if (cnt[CNT_NEAREST] >= cnt[CNT_ZERO]) 

586 
best_idx = CNT_NEAREST; 

587  
588 
mb>mv = near_mv[best_idx]; 

589 
near[0] = near_mv[CNT_NEAREST]; 

590 
near[1] = near_mv[CNT_NEAR]; 

591 
} 

592  
593  531 
/** 
594  532 
* Motion vector coding, 17.1. 
595  533 
*/ 
...  ...  
700  638 
} 
701  639  
702  640 
static av_always_inline 
641 
void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y) 

642 
{ 

643 
VP8Macroblock *mb_edge[3] = { mb + 2 /* top */, 

644 
mb  1 /* left */, 

645 
mb + 1 /* topleft */ }; 

646 
enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV }; 

647 
enum { EDGE_TOP, EDGE_LEFT, EDGE_TOPLEFT }; 

648 
int idx = CNT_ZERO; 

649 
int cur_sign_bias = s>sign_bias[mb>ref_frame]; 

650 
int *sign_bias = s>sign_bias; 

651 
VP56mv near_mv[4]; 

652 
uint8_t cnt[4] = { 0 }; 

653 
VP56RangeCoder *c = &s>c; 

654  
655 
AV_ZERO32(&near_mv[0]); 

656 
AV_ZERO32(&near_mv[1]); 

657 
AV_ZERO32(&near_mv[2]); 

658  
659 
/* Process MB on top, left and topleft */ 

660 
#define MV_EDGE_CHECK(n)\ 

661 
{\ 

662 
VP8Macroblock *edge = mb_edge[n];\ 

663 
int edge_ref = edge>ref_frame;\ 

664 
if (edge_ref != VP56_FRAME_CURRENT) {\ 

665 
uint32_t mv = AV_RN32A(&edge>mv);\ 

666 
if (mv) {\ 

667 
if (cur_sign_bias != sign_bias[edge_ref]) {\ 

668 
/* SWAR negate of the values in mv. */\ 

669 
mv = ~mv;\ 

670 
mv = ((mv&0x7fff7fff) + 0x00010001) ^ (mv&0x80008000);\ 

671 
}\ 

672 
if (!n  mv != AV_RN32A(&near_mv[idx]))\ 

673 
AV_WN32A(&near_mv[++idx], mv);\ 

674 
cnt[idx] += 1 + (n != 2);\ 

675 
} else\ 

676 
cnt[CNT_ZERO] += 1 + (n != 2);\ 

677 
}\ 

678 
} 

679  
680 
MV_EDGE_CHECK(0) 

681 
MV_EDGE_CHECK(1) 

682 
MV_EDGE_CHECK(2) 

683  
684 
mb>partitioning = VP8_SPLITMVMODE_NONE; 

685 
if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_ZERO]][0])) { 

686 
mb>mode = VP8_MVMODE_MV; 

687  
688 
/* If we have three distinct MVs, merge first and last if they're the same */ 

689 
if (cnt[CNT_SPLITMV] && AV_RN32A(&near_mv[1+EDGE_TOP]) == AV_RN32A(&near_mv[1+EDGE_TOPLEFT])) 

690 
cnt[CNT_NEAREST] += 1; 

691  
692 
/* Swap near and nearest if necessary */ 

693 
if (cnt[CNT_NEAR] > cnt[CNT_NEAREST]) { 

694 
FFSWAP(uint8_t, cnt[CNT_NEAREST], cnt[CNT_NEAR]); 

695 
FFSWAP( VP56mv, near_mv[CNT_NEAREST], near_mv[CNT_NEAR]); 

696 
} 

697  
698 
if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_NEAREST]][1])) { 

699 
if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_NEAR]][2])) { 

700  
701 
/* Choose the best mv out of 0,0 and the nearest mv */ 

702 
clamp_mv(s, &mb>mv, &near_mv[CNT_ZERO + (cnt[CNT_NEAREST] >= cnt[CNT_ZERO])], mb_x, mb_y); 

703 
cnt[CNT_SPLITMV] = ((mb_edge[EDGE_LEFT]>mode == VP8_MVMODE_SPLIT) + 

704 
(mb_edge[EDGE_TOP]>mode == VP8_MVMODE_SPLIT)) * 2 + 

705 
(mb_edge[EDGE_TOPLEFT]>mode == VP8_MVMODE_SPLIT); 

706  
707 
if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_SPLITMV]][3])) { 

708 
mb>mode = VP8_MVMODE_SPLIT; 

709 
mb>mv = mb>bmv[decode_splitmvs(s, c, mb)  1]; 

710 
} else { 

711 
mb>mv.y += read_mv_component(c, s>prob>mvc[0]); 

712 
mb>mv.x += read_mv_component(c, s>prob>mvc[1]); 

713 
mb>bmv[0] = mb>mv; 

714 
} 

715 
} else { 

716 
clamp_mv(s, &mb>mv, &near_mv[CNT_NEAR], mb_x, mb_y); 

717 
mb>bmv[0] = mb>mv; 

718 
} 

719 
} else { 

720 
clamp_mv(s, &mb>mv, &near_mv[CNT_NEAREST], mb_x, mb_y); 

721 
mb>bmv[0] = mb>mv; 

722 
} 

723 
} else { 

724 
mb>mode = VP8_MVMODE_ZERO; 

725 
AV_ZERO32(&mb>mv); 

726 
mb>bmv[0] = mb>mv; 

727 
} 

728 
} 

729  
730 
static av_always_inline 

703  731 
void decode_intra4x4_modes(VP8Context *s, VP56RangeCoder *c, 
704  732 
int mb_x, int keyframe) 
705  733 
{ 
...  ...  
749  777 
s>chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree, vp8_pred8x8c_prob_intra); 
750  778 
mb>ref_frame = VP56_FRAME_CURRENT; 
751  779 
} else if (vp56_rac_get_prob_branchy(c, s>prob>intra)) { 
752 
VP56mv near[2], best; 

753 
uint8_t cnt[4] = { 0 }; 

754  
755  780 
// inter MB, 16.2 
756  781 
if (vp56_rac_get_prob_branchy(c, s>prob>last)) 
757  782 
mb>ref_frame = vp56_rac_get_prob(c, s>prob>golden) ? 
...  ...  
761  786 
s>ref_count[mb>ref_frame1]++; 
762  787  
763  788 
// motion vectors, 16.3 
764 
find_near_mvs(s, mb, near, &best, cnt); 

765 
if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[0]][0])) { 

766 
mb>mode = VP8_MVMODE_MV; 

767 
if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[1]][1])) { 

768 
if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[2]][2])) { 

769 
if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[3]][3])) { 

770 
mb>mode = VP8_MVMODE_SPLIT; 

771 
clamp_mv(s, &mb>mv, &mb>mv, mb_x, mb_y); 

772 
mb>mv = mb>bmv[decode_splitmvs(s, c, mb)  1]; 

773 
} else { 

774 
clamp_mv(s, &mb>mv, &mb>mv, mb_x, mb_y); 

775 
mb>mv.y += read_mv_component(c, s>prob>mvc[0]); 

776 
mb>mv.x += read_mv_component(c, s>prob>mvc[1]); 

777 
} 

778 
} else 

779 
clamp_mv(s, &mb>mv, &near[1], mb_x, mb_y); 

780 
} else 

781 
clamp_mv(s, &mb>mv, &near[0], mb_x, mb_y); 

782 
} else { 

783 
mb>mode = VP8_MVMODE_ZERO; 

784 
AV_ZERO32(&mb>mv); 

785 
} 

786 
if (mb>mode != VP8_MVMODE_SPLIT) { 

787 
mb>partitioning = VP8_SPLITMVMODE_NONE; 

788 
mb>bmv[0] = mb>mv; 

789 
} 

789 
decode_mvs(s, mb, mb_x, mb_y); 

790  790 
} else { 
791  791 
// intra MB, 16.1 
792  792 
mb>mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_inter, s>prob>pred16x16); 
Also available in: Unified diff