X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fmotion_est.c;h=9cf1203be0590f5ec27f5ef2bd833365f1279ffc;hb=033a86f9bb6fd59ca71d4951b8e2e27cdc1b29d9;hp=2aa89786a1ad3b89cfff6147291c33de9df45508;hpb=33ad8c3cab30ebf8a08c891a5ec8cbcba15feabb;p=ffmpeg diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c index 2aa89786a1a..9cf1203be05 100644 --- a/libavcodec/motion_est.c +++ b/libavcodec/motion_est.c @@ -30,7 +30,7 @@ #include #include #include -#include "libavutil/intmath.h" + #include "avcodec.h" #include "dsputil.h" #include "mathops.h" @@ -39,15 +39,13 @@ #undef NDEBUG #include -#define SQ(a) ((a)*(a)) - #define P_LEFT P[1] #define P_TOP P[2] #define P_TOPRIGHT P[3] #define P_MEDIAN P[4] #define P_MV1 P[9] -static inline int sad_hpel_motion_search(MpegEncContext * s, +static int sad_hpel_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h); @@ -304,8 +302,9 @@ int ff_init_me(MpegEncContext *s){ av_log(s->avctx, AV_LOG_ERROR, "ME_MAP size is too small for SAB diamond\n"); return -1; } - //special case of snow is needed because snow uses its own iterative ME code - if(s->me_method!=ME_ZERO && s->me_method!=ME_EPZS && s->me_method!=ME_X1 && s->avctx->codec_id != CODEC_ID_SNOW){ + if (s->me_method != ME_ZERO && + s->me_method != ME_EPZS && + s->me_method != ME_X1) { av_log(s->avctx, AV_LOG_ERROR, "me_method is only allowed to be set to zero and epzs; for hex,umh,full and others see dia_size\n"); return -1; } @@ -356,33 +355,22 @@ int ff_init_me(MpegEncContext *s){ /* 8x8 fullpel search would need a 4x4 chroma compare, which we do * not have yet, and even if we had, the motion estimation code * does not expect it. */ - if(s->codec_id != CODEC_ID_SNOW){ - if((c->avctx->me_cmp&FF_CMP_CHROMA)/* && !s->dsp.me_cmp[2]*/){ - s->dsp.me_cmp[2]= zero_cmp; - } - if((c->avctx->me_sub_cmp&FF_CMP_CHROMA) && !s->dsp.me_sub_cmp[2]){ - s->dsp.me_sub_cmp[2]= zero_cmp; - } - c->hpel_put[2][0]= c->hpel_put[2][1]= - c->hpel_put[2][2]= c->hpel_put[2][3]= zero_hpel; + if((c->avctx->me_cmp&FF_CMP_CHROMA)/* && !s->dsp.me_cmp[2]*/){ + s->dsp.me_cmp[2]= zero_cmp; + } + if((c->avctx->me_sub_cmp&FF_CMP_CHROMA) && !s->dsp.me_sub_cmp[2]){ + s->dsp.me_sub_cmp[2]= zero_cmp; } + c->hpel_put[2][0]= c->hpel_put[2][1]= + c->hpel_put[2][2]= c->hpel_put[2][3]= zero_hpel; - if(s->codec_id == CODEC_ID_H261){ + if(s->codec_id == AV_CODEC_ID_H261){ c->sub_motion_search= no_sub_motion_search; } return 0; } -static inline void no_motion_search(MpegEncContext * s, - int *mx_ptr, int *my_ptr) -{ - *mx_ptr = 16 * s->mb_x; - *my_ptr = 16 * s->mb_y; -} - -#define Z_THRESHOLD 256 - #define CHECK_SAD_HALF_MV(suffix, x, y) \ {\ d= s->dsp.pix_abs[size][(x?1:0)+(y?2:0)](NULL, pix, ptr+((x)>>1), stride, h);\ @@ -390,7 +378,7 @@ static inline void no_motion_search(MpegEncContext * s, COPY3_IF_LT(dminh, d, dx, x, dy, y)\ } -static inline int sad_hpel_motion_search(MpegEncContext * s, +static int sad_hpel_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h) @@ -406,12 +394,10 @@ static inline int sad_hpel_motion_search(MpegEncContext * s, assert(flags == 0); if(c->skip){ -// printf("S"); *mx_ptr = 0; *my_ptr = 0; return dmin; } -// printf("N"); pix = c->src[src_index][0]; @@ -1040,9 +1026,8 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, switch(s->me_method) { case ME_ZERO: default: - no_motion_search(s, &mx, &my); - mx-= mb_x*16; - my-= mb_y*16; + mx = 0; + my = 0; dmin = 0; break; case ME_X1: @@ -1152,7 +1137,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip) - dmin= ff_get_mb_score(s, mx, my, 0, 0, 0, 16, 1); + dmin= get_mb_score(s, mx, my, 0, 0, 0, 16, 1); if((s->flags&CODEC_FLAG_4MV) && !c->skip && varc>50<<8 && vard>10<<8){ @@ -1283,10 +1268,9 @@ static int ff_estimate_motion_b(MpegEncContext * s, switch(s->me_method) { case ME_ZERO: default: - no_motion_search(s, &mx, &my); + mx = 0; + my = 0; dmin = 0; - mx-= mb_x*16; - my-= mb_y*16; break; case ME_X1: case ME_EPZS: @@ -1325,9 +1309,8 @@ static int ff_estimate_motion_b(MpegEncContext * s, dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, ref_index, 0, 16); if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip) - dmin= ff_get_mb_score(s, mx, my, 0, ref_index, 0, 16, 1); + dmin= get_mb_score(s, mx, my, 0, ref_index, 0, 16, 1); -//printf("%d %d %d %d//", s->mb_x, s->mb_y, mx, my); // s->mb_type[mb_y*s->mb_width + mb_x]= mb_type; mv_table[mot_xy][0]= mx; mv_table[mot_xy][1]= my; @@ -1424,9 +1407,8 @@ static inline int bidir_refine(MpegEncContext * s, int mb_x, int mb_y) #define HASH(fx,fy,bx,by) ((fx)+17*(fy)+63*(bx)+117*(by)) #define HASH8(fx,fy,bx,by) ((uint8_t)HASH(fx,fy,bx,by)) int hashidx= HASH(motion_fx,motion_fy, motion_bx, motion_by); - uint8_t map[256]; + uint8_t map[256] = { 0 }; - memset(map,0,sizeof(map)); map[hashidx&255] = 1; fbmin= check_bidir_mv(s, motion_fx, motion_fy, @@ -1638,7 +1620,7 @@ static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y) dmin = hpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip) - dmin= ff_get_mb_score(s, mx, my, 0, 0, 0, 16, 1); + dmin= get_mb_score(s, mx, my, 0, 0, 0, 16, 1); get_limits(s, 16*mb_x, 16*mb_y); //restore c->?min/max, maybe not needed @@ -1665,7 +1647,7 @@ void ff_estimate_b_frame_motion(MpegEncContext * s, c->skip=0; - if (s->codec_id == CODEC_ID_MPEG4 && s->next_picture.f.mbskip_table[xy]) { + if (s->codec_id == AV_CODEC_ID_MPEG4 && s->next_picture.f.mbskip_table[xy]) { int score= direct_search(s, mb_x, mb_y); //FIXME just check 0,0 score= ((unsigned)(score*score + 128*256))>>16; @@ -1727,7 +1709,7 @@ void ff_estimate_b_frame_motion(MpegEncContext * s, } } - if (s->codec_id == CODEC_ID_MPEG4) + if (s->codec_id == AV_CODEC_ID_MPEG4) dmin= direct_search(s, mb_x, mb_y); else dmin= INT_MAX; @@ -1737,11 +1719,11 @@ void ff_estimate_b_frame_motion(MpegEncContext * s, c->skip=0; bmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code) + 2*penalty_factor; -//printf(" %d %d ", s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]); + av_dlog(s, " %d %d ", s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]); c->skip=0; fbmin= bidir_refine(s, mb_x, mb_y) + penalty_factor; -//printf("%d %d %d %d\n", dmin, fmin, bmin, fbmin); + av_dlog(s, "%d %d %d %d\n", dmin, fmin, bmin, fbmin); if(s->flags & CODEC_FLAG_INTERLACED_ME){ //FIXME mb type penalty @@ -1798,7 +1780,7 @@ void ff_estimate_b_frame_motion(MpegEncContext * s, } //FIXME something smarter if(dmin>256*256*16) type&= ~CANDIDATE_MB_TYPE_DIRECT; //do not try direct mode if it is invalid for this MB - if(s->codec_id == CODEC_ID_MPEG4 && type&CANDIDATE_MB_TYPE_DIRECT && s->flags&CODEC_FLAG_MV0 && *(uint32_t*)s->b_direct_mv_table[xy]) + if(s->codec_id == AV_CODEC_ID_MPEG4 && type&CANDIDATE_MB_TYPE_DIRECT && s->flags&CODEC_FLAG_MV0 && *(uint32_t*)s->b_direct_mv_table[xy]) type |= CANDIDATE_MB_TYPE_DIRECT0; } @@ -1817,7 +1799,7 @@ int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type) if(s->msmpeg4_version) range= FFMIN(range, 16); - else if(s->codec_id == CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL) + else if(s->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL) range= FFMIN(range, 256); for(i=0; i<8; i++) score[i]= s->mb_num*(8-i); @@ -1851,15 +1833,9 @@ int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type) best_score= score[i]; best_fcode= i; } -// printf("%d %d\n", i, score[i]); } -// printf("fcode: %d type: %d\n", i, s->pict_type); return best_fcode; -/* for(i=0; i<=MAX_FCODE; i++){ - printf("%d ", mv_num[i]); - } - printf("\n");*/ }else{ return 1; } @@ -1875,11 +1851,10 @@ void ff_fix_long_p_mvs(MpegEncContext * s) range = (((s->out_format == FMT_MPEG1 || s->msmpeg4_version) ? 8 : 16) << f_code); assert(range <= 16 || !s->msmpeg4_version); - assert(range <=256 || !(s->codec_id == CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL)); + assert(range <=256 || !(s->codec_id == AV_CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL)); if(c->avctx->me_range && range > c->avctx->me_range) range= c->avctx->me_range; -//printf("%d no:%d %d//\n", clip, noclip, f_code); if(s->flags&CODEC_FLAG_4MV){ const int wrap= s->b8_stride;