Mercurial > libavcodec.hg
comparison motion_est.c @ 2072:c200977cdf78 libavcodec
clip input motion vectors
be somewhat more tollerant on invalid input
return INT_MAX instead of -1 for unuseable mv/mb types as that ensures nicely that they arent used
initalize limits earlier for b frames
a few more asserts to check for out of picture vectors
author | michael |
---|---|
date | Thu, 10 Jun 2004 22:56:43 +0000 |
parents | 4bfb146e701b |
children | aae3b4e66560 |
comparison
equal
deleted
inserted
replaced
2071:41d30bae5019 | 2072:c200977cdf78 |
---|---|
978 default: | 978 default: |
979 return dmin_sum+ 11*c->mb_penalty_factor; | 979 return dmin_sum+ 11*c->mb_penalty_factor; |
980 } | 980 } |
981 } | 981 } |
982 | 982 |
983 static void clip_input_mv(MpegEncContext * s, int16_t *mv, int interlaced){ | |
984 int ymax= s->me.ymax>>interlaced; | |
985 int ymin= s->me.ymin>>interlaced; | |
986 | |
987 if(mv[0] < s->me.xmin) mv[0] = s->me.xmin; | |
988 if(mv[0] > s->me.xmax) mv[0] = s->me.xmax; | |
989 if(mv[1] < ymin) mv[1] = ymin; | |
990 if(mv[1] > ymax) mv[1] = ymax; | |
991 } | |
992 | |
983 static inline int check_input_motion(MpegEncContext * s, int mb_x, int mb_y, int p_type){ | 993 static inline int check_input_motion(MpegEncContext * s, int mb_x, int mb_y, int p_type){ |
984 MotionEstContext * const c= &s->me; | 994 MotionEstContext * const c= &s->me; |
985 Picture *p= s->current_picture_ptr; | 995 Picture *p= s->current_picture_ptr; |
986 int mb_xy= mb_x + mb_y*s->mb_stride; | 996 int mb_xy= mb_x + mb_y*s->mb_stride; |
987 int xy= 2*mb_x + 2*mb_y*s->b8_stride; | 997 int xy= 2*mb_x + 2*mb_y*s->b8_stride; |
992 int x, y, i; | 1002 int x, y, i; |
993 int d=0; | 1003 int d=0; |
994 me_cmp_func cmpf= s->dsp.sse[0]; | 1004 me_cmp_func cmpf= s->dsp.sse[0]; |
995 me_cmp_func chroma_cmpf= s->dsp.sse[1]; | 1005 me_cmp_func chroma_cmpf= s->dsp.sse[1]; |
996 | 1006 |
997 assert(p_type==0 || !USES_LIST(mb_type, 1)); | 1007 if(p_type && USES_LIST(mb_type, 1)){ |
1008 av_log(c->avctx, AV_LOG_ERROR, "backward motion vector in P frame\n"); | |
1009 return INT_MAX; | |
1010 } | |
998 assert(IS_INTRA(mb_type) || USES_LIST(mb_type,0) || USES_LIST(mb_type,1)); | 1011 assert(IS_INTRA(mb_type) || USES_LIST(mb_type,0) || USES_LIST(mb_type,1)); |
999 | 1012 |
1013 for(i=0; i<4; i++){ | |
1014 int xy= s->block_index[i]; | |
1015 clip_input_mv(s, p->motion_val[0][xy], !!IS_INTERLACED(mb_type)); | |
1016 clip_input_mv(s, p->motion_val[1][xy], !!IS_INTERLACED(mb_type)); | |
1017 } | |
1018 | |
1000 if(IS_INTERLACED(mb_type)){ | 1019 if(IS_INTERLACED(mb_type)){ |
1001 int xy2= xy + s->b8_stride; | 1020 int xy2= xy + s->b8_stride; |
1002 s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTRA; | 1021 s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTRA; |
1003 c->stride<<=1; | 1022 c->stride<<=1; |
1004 c->uvstride<<=1; | 1023 c->uvstride<<=1; |
1005 | 1024 |
1006 if(!(s->flags & CODEC_FLAG_INTERLACED_ME)){ | 1025 if(!(s->flags & CODEC_FLAG_INTERLACED_ME)){ |
1007 av_log(c->avctx, AV_LOG_ERROR, "Interlaced macroblock selected but interlaced motion estimation disabled\n"); | 1026 av_log(c->avctx, AV_LOG_ERROR, "Interlaced macroblock selected but interlaced motion estimation disabled\n"); |
1008 return -1; | 1027 return INT_MAX; |
1009 } | 1028 } |
1010 | 1029 |
1011 if(USES_LIST(mb_type, 0)){ | 1030 if(USES_LIST(mb_type, 0)){ |
1012 int field_select0= p->ref_index[0][xy ]; | 1031 int field_select0= p->ref_index[0][xy ]; |
1013 int field_select1= p->ref_index[0][xy2]; | 1032 int field_select1= p->ref_index[0][xy2]; |
1064 c->stride>>=1; | 1083 c->stride>>=1; |
1065 c->uvstride>>=1; | 1084 c->uvstride>>=1; |
1066 }else if(IS_8X8(mb_type)){ | 1085 }else if(IS_8X8(mb_type)){ |
1067 if(!(s->flags & CODEC_FLAG_4MV)){ | 1086 if(!(s->flags & CODEC_FLAG_4MV)){ |
1068 av_log(c->avctx, AV_LOG_ERROR, "4MV macroblock selected but 4MV encoding disabled\n"); | 1087 av_log(c->avctx, AV_LOG_ERROR, "4MV macroblock selected but 4MV encoding disabled\n"); |
1069 return -1; | 1088 return INT_MAX; |
1070 } | 1089 } |
1071 cmpf= s->dsp.sse[1]; | 1090 cmpf= s->dsp.sse[1]; |
1072 chroma_cmpf= s->dsp.sse[1]; | 1091 chroma_cmpf= s->dsp.sse[1]; |
1073 init_mv4_ref(c); | 1092 init_mv4_ref(c); |
1074 for(i=0; i<4; i++){ | 1093 for(i=0; i<4; i++){ |
1721 int fmin, bmin, dmin, fbmin, bimin, fimin; | 1740 int fmin, bmin, dmin, fbmin, bimin, fimin; |
1722 int type=0; | 1741 int type=0; |
1723 const int xy = mb_y*s->mb_stride + mb_x; | 1742 const int xy = mb_y*s->mb_stride + mb_x; |
1724 init_ref(c, s->new_picture.data, s->last_picture.data, s->next_picture.data, 16*mb_x, 16*mb_y, 2); | 1743 init_ref(c, s->new_picture.data, s->last_picture.data, s->next_picture.data, 16*mb_x, 16*mb_y, 2); |
1725 | 1744 |
1745 get_limits(s, 16*mb_x, 16*mb_y); | |
1726 | 1746 |
1727 c->skip=0; | 1747 c->skip=0; |
1728 if(c->avctx->me_threshold){ | 1748 if(c->avctx->me_threshold){ |
1729 int vard= (check_input_motion(s, mb_x, mb_y, 0)+128)>>8; | 1749 int vard= (check_input_motion(s, mb_x, mb_y, 0)+128)>>8; |
1730 | 1750 |