comparison h264.h @ 10864:e3f5eb016712 libavcodec

Split motion vector prediction off h264.c/h.
author michael
date Tue, 12 Jan 2010 21:36:26 +0000
parents 974ac220c93a
children d26e9b4d2ca1
comparison
equal deleted inserted replaced
10863:974ac220c93a 10864:e3f5eb016712
692 */ 692 */
693 static inline int get_chroma_qp(H264Context *h, int t, int qscale){ 693 static inline int get_chroma_qp(H264Context *h, int t, int qscale){
694 return h->pps.chroma_qp_table[t][qscale]; 694 return h->pps.chroma_qp_table[t][qscale];
695 } 695 }
696 696
697 static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width){
698 const int topright_ref= h->ref_cache[list][ i - 8 + part_width ];
699 MpegEncContext *s = &h->s;
700
701 /* there is no consistent mapping of mvs to neighboring locations that will
702 * make mbaff happy, so we can't move all this logic to fill_caches */
703 if(FRAME_MBAFF){
704 const uint32_t *mb_types = s->current_picture_ptr->mb_type;
705 const int16_t *mv;
706 *(uint32_t*)h->mv_cache[list][scan8[0]-2] = 0;
707 *C = h->mv_cache[list][scan8[0]-2];
708
709 if(!MB_FIELD
710 && (s->mb_y&1) && i < scan8[0]+8 && topright_ref != PART_NOT_AVAILABLE){
711 int topright_xy = s->mb_x + (s->mb_y-1)*s->mb_stride + (i == scan8[0]+3);
712 if(IS_INTERLACED(mb_types[topright_xy])){
713 #define SET_DIAG_MV(MV_OP, REF_OP, X4, Y4)\
714 const int x4 = X4, y4 = Y4;\
715 const int mb_type = mb_types[(x4>>2)+(y4>>2)*s->mb_stride];\
716 if(!USES_LIST(mb_type,list))\
717 return LIST_NOT_USED;\
718 mv = s->current_picture_ptr->motion_val[list][x4 + y4*h->b_stride];\
719 h->mv_cache[list][scan8[0]-2][0] = mv[0];\
720 h->mv_cache[list][scan8[0]-2][1] = mv[1] MV_OP;\
721 return s->current_picture_ptr->ref_index[list][(x4>>1) + (y4>>1)*h->b8_stride] REF_OP;
722
723 SET_DIAG_MV(*2, >>1, s->mb_x*4+(i&7)-4+part_width, s->mb_y*4-1);
724 }
725 }
726 if(topright_ref == PART_NOT_AVAILABLE
727 && ((s->mb_y&1) || i >= scan8[0]+8) && (i&7)==4
728 && h->ref_cache[list][scan8[0]-1] != PART_NOT_AVAILABLE){
729 if(!MB_FIELD
730 && IS_INTERLACED(mb_types[h->left_mb_xy[0]])){
731 SET_DIAG_MV(*2, >>1, s->mb_x*4-1, (s->mb_y|1)*4+(s->mb_y&1)*2+(i>>4)-1);
732 }
733 if(MB_FIELD
734 && !IS_INTERLACED(mb_types[h->left_mb_xy[0]])
735 && i >= scan8[0]+8){
736 // left shift will turn LIST_NOT_USED into PART_NOT_AVAILABLE, but that's OK.
737 SET_DIAG_MV(/2, <<1, s->mb_x*4-1, (s->mb_y&~1)*4 - 1 + ((i-scan8[0])>>3)*2);
738 }
739 }
740 #undef SET_DIAG_MV
741 }
742
743 if(topright_ref != PART_NOT_AVAILABLE){
744 *C= h->mv_cache[list][ i - 8 + part_width ];
745 return topright_ref;
746 }else{
747 tprintf(s->avctx, "topright MV not available\n");
748
749 *C= h->mv_cache[list][ i - 8 - 1 ];
750 return h->ref_cache[list][ i - 8 - 1 ];
751 }
752 }
753
754 /**
755 * gets the predicted MV.
756 * @param n the block index
757 * @param part_width the width of the partition (4, 8,16) -> (1, 2, 4)
758 * @param mx the x component of the predicted motion vector
759 * @param my the y component of the predicted motion vector
760 */
761 static inline void pred_motion(H264Context * const h, int n, int part_width, int list, int ref, int * const mx, int * const my){
762 const int index8= scan8[n];
763 const int top_ref= h->ref_cache[list][ index8 - 8 ];
764 const int left_ref= h->ref_cache[list][ index8 - 1 ];
765 const int16_t * const A= h->mv_cache[list][ index8 - 1 ];
766 const int16_t * const B= h->mv_cache[list][ index8 - 8 ];
767 const int16_t * C;
768 int diagonal_ref, match_count;
769
770 assert(part_width==1 || part_width==2 || part_width==4);
771
772 /* mv_cache
773 B . . A T T T T
774 U . . L . . , .
775 U . . L . . . .
776 U . . L . . , .
777 . . . L . . . .
778 */
779
780 diagonal_ref= fetch_diagonal_mv(h, &C, index8, list, part_width);
781 match_count= (diagonal_ref==ref) + (top_ref==ref) + (left_ref==ref);
782 tprintf(h->s.avctx, "pred_motion match_count=%d\n", match_count);
783 if(match_count > 1){ //most common
784 *mx= mid_pred(A[0], B[0], C[0]);
785 *my= mid_pred(A[1], B[1], C[1]);
786 }else if(match_count==1){
787 if(left_ref==ref){
788 *mx= A[0];
789 *my= A[1];
790 }else if(top_ref==ref){
791 *mx= B[0];
792 *my= B[1];
793 }else{
794 *mx= C[0];
795 *my= C[1];
796 }
797 }else{
798 if(top_ref == PART_NOT_AVAILABLE && diagonal_ref == PART_NOT_AVAILABLE && left_ref != PART_NOT_AVAILABLE){
799 *mx= A[0];
800 *my= A[1];
801 }else{
802 *mx= mid_pred(A[0], B[0], C[0]);
803 *my= mid_pred(A[1], B[1], C[1]);
804 }
805 }
806
807 tprintf(h->s.avctx, "pred_motion (%2d %2d %2d) (%2d %2d %2d) (%2d %2d %2d) -> (%2d %2d %2d) at %2d %2d %d list %d\n", top_ref, B[0], B[1], diagonal_ref, C[0], C[1], left_ref, A[0], A[1], ref, *mx, *my, h->s.mb_x, h->s.mb_y, n, list);
808 }
809
810
811 #endif /* AVCODEC_H264_H */ 697 #endif /* AVCODEC_H264_H */