diff options
Diffstat (limited to 'libavcodec/motion_est.c')
-rw-r--r-- | libavcodec/motion_est.c | 69 |
1 files changed, 40 insertions, 29 deletions
diff --git a/libavcodec/motion_est.c b/libavcodec/motion_est.c index 3577ada50c..013df37971 100644 --- a/libavcodec/motion_est.c +++ b/libavcodec/motion_est.c @@ -5,20 +5,20 @@ * * new motion estimation (X1/EPZS) by Michael Niedermayer <michaelni@gmx.at> * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -155,14 +155,14 @@ static av_always_inline int cmp_direct_inline(MpegEncContext *s, const int x, co c->qpel_avg[1][bxy](c->temp + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8*stride, stride); c->qpel_avg[1][bxy](c->temp + 8 + 8*stride, ref[8] + (bx>>2) + (by>>2)*stride + 8 + 8*stride, stride); }else{ - assert((fx>>1) + 16*s->mb_x >= -16); - assert((fy>>1) + 16*s->mb_y >= -16); - assert((fx>>1) + 16*s->mb_x <= s->width); - assert((fy>>1) + 16*s->mb_y <= s->height); - assert((bx>>1) + 16*s->mb_x >= -16); - assert((by>>1) + 16*s->mb_y >= -16); - assert((bx>>1) + 16*s->mb_x <= s->width); - assert((by>>1) + 16*s->mb_y <= s->height); + av_assert2((fx>>1) + 16*s->mb_x >= -16); + av_assert2((fy>>1) + 16*s->mb_y >= -16); + av_assert2((fx>>1) + 16*s->mb_x <= s->width); + av_assert2((fy>>1) + 16*s->mb_y <= s->height); + av_assert2((bx>>1) + 16*s->mb_x >= -16); + av_assert2((by>>1) + 16*s->mb_y >= -16); + av_assert2((bx>>1) + 16*s->mb_x <= s->width); + av_assert2((by>>1) + 16*s->mb_y <= s->height); c->hpel_put[0][fxy](c->temp, ref[0] + (fx>>1) + (fy>>1)*stride, stride, 16); c->hpel_avg[0][bxy](c->temp, ref[8] + (bx>>1) + (by>>1)*stride, stride, 16); @@ -523,8 +523,8 @@ static inline void get_limits(MpegEncContext *s, int x, int y) if (s->unrestricted_mv) { c->xmin = - x - 16; c->ymin = - y - 16; - c->xmax = - x + s->mb_width *16; - c->ymax = - y + s->mb_height*16; + c->xmax = - x + s->width; + c->ymax = - y + s->height; } else if (s->out_format == FMT_H261){ // Search range of H261 is different from other codec standards c->xmin = (x > 15) ? - 15 : 0; @@ -563,10 +563,11 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift) const int h=8; int block; int P[10][2]; - int dmin_sum=0, mx4_sum=0, my4_sum=0; + int dmin_sum=0, mx4_sum=0, my4_sum=0, i; int same=1; const int stride= c->stride; uint8_t *mv_penalty= c->current_mv_penalty; + int saftey_cliping= s->unrestricted_mv && (s->width&15) && (s->height&15); init_mv4_ref(c); @@ -578,6 +579,11 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift) const int mot_stride = s->b8_stride; const int mot_xy = s->block_index[block]; + if(saftey_cliping){ + c->xmax = - 16*s->mb_x + s->width - 8*(block &1); + c->ymax = - 16*s->mb_y + s->height - 8*(block>>1); + } + P_LEFT[0] = s->current_picture.f.motion_val[0][mot_xy - 1][0]; P_LEFT[1] = s->current_picture.f.motion_val[0][mot_xy - 1][1]; @@ -605,6 +611,11 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift) } P_MV1[0]= mx; P_MV1[1]= my; + if(saftey_cliping) + for(i=0; i<10; i++){ + if(P[i][0] > (c->xmax<<shift)) P[i][0]= (c->xmax<<shift); + if(P[i][1] > (c->ymax<<shift)) P[i][1]= (c->ymax<<shift); + } dmin4 = epzs_motion_search4(s, &mx4, &my4, P, block, block, s->p_mv_table, (1<<16)>>shift); @@ -736,8 +747,8 @@ static int interlaced_search(MpegEncContext *s, int ref_index, int16_t (*mv_table)[2]= mv_tables[block][field_select]; if(user_field_select){ - assert(field_select==0 || field_select==1); - assert(field_select_tables[block][xy]==0 || field_select_tables[block][xy]==1); + av_assert1(field_select==0 || field_select==1); + av_assert1(field_select_tables[block][xy]==0 || field_select_tables[block][xy]==1); if(field_select_tables[block][xy] != field_select) continue; } @@ -855,7 +866,7 @@ static inline int check_input_motion(MpegEncContext * s, int mb_x, int mb_y, int av_log(c->avctx, AV_LOG_ERROR, "backward motion vector in P frame\n"); return INT_MAX/2; } - assert(IS_INTRA(mb_type) || USES_LIST(mb_type,0) || USES_LIST(mb_type,1)); + av_assert0(IS_INTRA(mb_type) || USES_LIST(mb_type,0) || USES_LIST(mb_type,1)); for(i=0; i<4; i++){ int xy= s->block_index[i]; @@ -877,8 +888,8 @@ static inline int check_input_motion(MpegEncContext * s, int mb_x, int mb_y, int if(USES_LIST(mb_type, 0)){ int field_select0= p->f.ref_index[0][4*mb_xy ]; int field_select1= p->f.ref_index[0][4*mb_xy+2]; - assert(field_select0==0 ||field_select0==1); - assert(field_select1==0 ||field_select1==1); + av_assert0(field_select0==0 ||field_select0==1); + av_assert0(field_select1==0 ||field_select1==1); init_interlaced_ref(s, 0); if(p_type){ @@ -905,8 +916,8 @@ static inline int check_input_motion(MpegEncContext * s, int mb_x, int mb_y, int if(USES_LIST(mb_type, 1)){ int field_select0 = p->f.ref_index[1][4 * mb_xy ]; int field_select1 = p->f.ref_index[1][4 * mb_xy + 2]; - assert(field_select0==0 ||field_select0==1); - assert(field_select1==0 ||field_select1==1); + av_assert0(field_select0==0 ||field_select0==1); + av_assert0(field_select1==0 ||field_select1==1); init_interlaced_ref(s, 2); s->b_field_select_table[1][0][mb_xy]= field_select0; @@ -988,9 +999,9 @@ void ff_estimate_p_frame_motion(MpegEncContext * s, init_ref(c, s->new_picture.f.data, s->last_picture.f.data, NULL, 16*mb_x, 16*mb_y, 0); - assert(s->quarter_sample==0 || s->quarter_sample==1); - assert(s->linesize == c->stride); - assert(s->uvlinesize == c->uvstride); + av_assert0(s->quarter_sample==0 || s->quarter_sample==1); + av_assert0(s->linesize == c->stride); + av_assert0(s->uvlinesize == c->uvstride); c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp); c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp); @@ -1204,7 +1215,7 @@ int ff_pre_estimate_p_frame_motion(MpegEncContext * s, const int xy= mb_x + mb_y*s->mb_stride; init_ref(c, s->new_picture.f.data, s->last_picture.f.data, NULL, 16*mb_x, 16*mb_y, 0); - assert(s->quarter_sample==0 || s->quarter_sample==1); + av_assert0(s->quarter_sample==0 || s->quarter_sample==1); c->pre_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_pre_cmp); c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV; @@ -1847,12 +1858,12 @@ void ff_fix_long_p_mvs(MpegEncContext * s) MotionEstContext * const c= &s->me; const int f_code= s->f_code; int y, range; - assert(s->pict_type==AV_PICTURE_TYPE_P); + av_assert0(s->pict_type==AV_PICTURE_TYPE_P); 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 == AV_CODEC_ID_MPEG2VIDEO && s->avctx->strict_std_compliance >= FF_COMPLIANCE_NORMAL)); + av_assert0(range <= 16 || !s->msmpeg4_version); + av_assert0(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; |