diff options
Diffstat (limited to 'libavcodec/mpegvideo_motion.c')
-rw-r--r-- | libavcodec/mpegvideo_motion.c | 112 |
1 files changed, 63 insertions, 49 deletions
diff --git a/libavcodec/mpegvideo_motion.c b/libavcodec/mpegvideo_motion.c index cbf200f..09061d8 100644 --- a/libavcodec/mpegvideo_motion.c +++ b/libavcodec/mpegvideo_motion.c @@ -4,25 +4,26 @@ * * 4MV & hq & B-frame encoding stuff 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 */ #include <string.h> +#include "libavutil/avassert.h" #include "libavutil/internal.h" #include "avcodec.h" #include "dsputil.h" @@ -37,7 +38,8 @@ static void gmc1_motion(MpegEncContext *s, uint8_t **ref_picture) { uint8_t *ptr; - int offset, src_x, src_y, linesize, uvlinesize; + int src_x, src_y; + ptrdiff_t offset, linesize, uvlinesize; int motion_x, motion_y; int emu=0; @@ -59,13 +61,13 @@ static void gmc1_motion(MpegEncContext *s, ptr = ref_picture[0] + (src_y * linesize) + src_x; - if(s->flags&CODEC_FLAG_EMU_EDGE){ if( (unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0) || (unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)){ - s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos); + s->vdsp.emulated_edge_mc(s->edge_emu_buffer, linesize, + ptr, linesize, 17, 17, src_x, src_y, + s->h_edge_pos, s->v_edge_pos); ptr= s->edge_emu_buffer; } - } if((motion_x|motion_y)&7){ s->dsp.gmc1(dest_y , ptr , linesize, 16, motion_x&15, motion_y&15, 128 - s->no_rounding); @@ -98,19 +100,21 @@ static void gmc1_motion(MpegEncContext *s, offset = (src_y * uvlinesize) + src_x; ptr = ref_picture[1] + offset; - if(s->flags&CODEC_FLAG_EMU_EDGE){ if( (unsigned)src_x >= FFMAX((s->h_edge_pos>>1) - 9, 0) || (unsigned)src_y >= FFMAX((s->v_edge_pos>>1) - 9, 0)){ - s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); + s->vdsp.emulated_edge_mc(s->edge_emu_buffer, uvlinesize, + ptr, uvlinesize, 9, 9, src_x, src_y, + s->h_edge_pos>>1, s->v_edge_pos>>1); ptr= s->edge_emu_buffer; emu=1; } - } s->dsp.gmc1(dest_cb, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); ptr = ref_picture[2] + offset; if(emu){ - s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); + s->vdsp.emulated_edge_mc(s->edge_emu_buffer, uvlinesize, + ptr, uvlinesize, 9, 9, src_x, src_y, + s->h_edge_pos>>1, s->v_edge_pos>>1); ptr= s->edge_emu_buffer; } s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding); @@ -198,8 +202,9 @@ static inline int hpel_motion(MpegEncContext *s, if(s->unrestricted_mv && (s->flags&CODEC_FLAG_EMU_EDGE)){ if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&1) - 8, 0) || (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y&1) - 8, 0)){ - s->vdsp.emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, 9, 9, - src_x, src_y, s->h_edge_pos, s->v_edge_pos); + s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize, + src, s->linesize, 9, 9, + src_x, src_y, s->h_edge_pos, s->v_edge_pos); src= s->edge_emu_buffer; emu=1; } @@ -289,19 +294,19 @@ if(s->quarter_sample) "MPEG motion vector out of boundary (%d %d)\n", src_x, src_y); return; } - s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, - 17, 17+field_based, - src_x, src_y<<field_based, - s->h_edge_pos, s->v_edge_pos); + s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize, + ptr_y, s->linesize, 17, 17+field_based, + src_x, src_y<<field_based, + s->h_edge_pos, s->v_edge_pos); ptr_y = s->edge_emu_buffer; if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize; - s->vdsp.emulated_edge_mc(uvbuf , + s->vdsp.emulated_edge_mc(uvbuf, s->uvlinesize, ptr_cb, s->uvlinesize, 9, 9+field_based, uvsrc_x, uvsrc_y<<field_based, s->h_edge_pos>>1, s->v_edge_pos>>1); - s->vdsp.emulated_edge_mc(uvbuf+16, + s->vdsp.emulated_edge_mc(uvbuf+16, s->uvlinesize, ptr_cr, s->uvlinesize, 9, 9+field_based, uvsrc_x, uvsrc_y<<field_based, @@ -437,7 +442,7 @@ static inline void obmc_motion(MpegEncContext *s, int i; uint8_t *ptr[5]; - assert(s->quarter_sample==0); + av_assert2(s->quarter_sample==0); for(i=0; i<5; i++){ if(i && mv[i][0]==mv[MID][0] && mv[i][1]==mv[MID][1]){ @@ -462,7 +467,8 @@ static inline void qpel_motion(MpegEncContext *s, int motion_x, int motion_y, int h) { uint8_t *ptr_y, *ptr_cb, *ptr_cr; - int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, linesize, uvlinesize; + int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos; + ptrdiff_t linesize, uvlinesize; dxy = ((motion_y & 3) << 2) | (motion_x & 3); src_x = s->mb_x * 16 + (motion_x >> 2); @@ -502,20 +508,23 @@ static inline void qpel_motion(MpegEncContext *s, if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&3) - 16, 0) || (unsigned)src_y > FFMAX( v_edge_pos - (motion_y&3) - h , 0)){ - s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, - 17, 17+field_based, src_x, src_y<<field_based, - s->h_edge_pos, s->v_edge_pos); + s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize, + ptr_y, s->linesize, + 17, 17+field_based, src_x, src_y<<field_based, + s->h_edge_pos, s->v_edge_pos); ptr_y= s->edge_emu_buffer; if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize; - s->vdsp.emulated_edge_mc(uvbuf, ptr_cb, s->uvlinesize, - 9, 9 + field_based, - uvsrc_x, uvsrc_y<<field_based, - s->h_edge_pos>>1, s->v_edge_pos>>1); - s->vdsp.emulated_edge_mc(uvbuf + 16, ptr_cr, s->uvlinesize, - 9, 9 + field_based, - uvsrc_x, uvsrc_y<<field_based, - s->h_edge_pos>>1, s->v_edge_pos>>1); + s->vdsp.emulated_edge_mc(uvbuf, s->uvlinesize, + ptr_cb, s->uvlinesize, + 9, 9 + field_based, + uvsrc_x, uvsrc_y<<field_based, + s->h_edge_pos>>1, s->v_edge_pos>>1); + s->vdsp.emulated_edge_mc(uvbuf + 16, s->uvlinesize, + ptr_cr, s->uvlinesize, + 9, 9 + field_based, + uvsrc_x, uvsrc_y<<field_based, + s->h_edge_pos>>1, s->v_edge_pos>>1); ptr_cb= uvbuf; ptr_cr= uvbuf + 16; } @@ -555,7 +564,8 @@ static void chroma_4mv_motion(MpegEncContext *s, op_pixels_func *pix_op, int mx, int my) { - int dxy, emu=0, src_x, src_y, offset; + int dxy, emu=0, src_x, src_y; + ptrdiff_t offset; uint8_t *ptr; /* In case of 8X8, we construct a single chroma motion vector @@ -581,9 +591,9 @@ static void chroma_4mv_motion(MpegEncContext *s, if(s->flags&CODEC_FLAG_EMU_EDGE){ if( (unsigned)src_x > FFMAX((s->h_edge_pos>>1) - (dxy &1) - 8, 0) || (unsigned)src_y > FFMAX((s->v_edge_pos>>1) - (dxy>>1) - 8, 0)){ - s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, - 9, 9, src_x, src_y, - s->h_edge_pos>>1, s->v_edge_pos>>1); + s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->uvlinesize, + ptr, s->uvlinesize, 9, 9, src_x, src_y, + s->h_edge_pos>>1, s->v_edge_pos>>1); ptr= s->edge_emu_buffer; emu=1; } @@ -592,9 +602,9 @@ static void chroma_4mv_motion(MpegEncContext *s, ptr = ref_picture[2] + offset; if(emu){ - s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, - 9, 9, src_x, src_y, - s->h_edge_pos>>1, s->v_edge_pos>>1); + s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->uvlinesize, + ptr, s->uvlinesize, 9, 9, src_x, src_y, + s->h_edge_pos>>1, s->v_edge_pos>>1); ptr= s->edge_emu_buffer; } pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8); @@ -647,7 +657,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, const int mot_stride= s->b8_stride; const int mot_xy= mb_x*2 + mb_y*2*mot_stride; - assert(!s->mb_skipped); + av_assert2(!s->mb_skipped); AV_COPY32(mv_cache[1][1], cur_frame->motion_val[0][mot_xy ]); AV_COPY32(mv_cache[1][2], cur_frame->motion_val[0][mot_xy + 1]); @@ -761,10 +771,10 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, if(s->flags&CODEC_FLAG_EMU_EDGE){ if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&3) - 8, 0) || (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y&3) - 8, 0)){ - s->vdsp.emulated_edge_mc(s->edge_emu_buffer, ptr, - s->linesize, 9, 9, - src_x, src_y, - s->h_edge_pos, s->v_edge_pos); + s->vdsp.emulated_edge_mc(s->edge_emu_buffer, s->linesize, + ptr, s->linesize, 9, 9, + src_x, src_y, + s->h_edge_pos, s->v_edge_pos); ptr= s->edge_emu_buffer; } } @@ -813,7 +823,8 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, s->mv[dir][1][0], s->mv[dir][1][1], 8, mb_y); } } else { - if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != AV_PICTURE_TYPE_B && !s->first_field){ + if( s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != AV_PICTURE_TYPE_B && !s->first_field + || !ref_picture[0]){ ref_picture = s->current_picture_ptr->f.data; } @@ -827,8 +838,8 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, for(i=0; i<2; i++){ uint8_t ** ref2picture; - if(s->picture_structure == s->field_select[dir][i] + 1 - || s->pict_type == AV_PICTURE_TYPE_B || s->first_field){ + if((s->picture_structure == s->field_select[dir][i] + 1 + || s->pict_type == AV_PICTURE_TYPE_B || s->first_field) && ref_picture[0]){ ref2picture= ref_picture; }else{ ref2picture = s->current_picture_ptr->f.data; @@ -857,6 +868,9 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, pix_op = s->hdsp.avg_pixels_tab; } }else{ + if (!ref_picture[0]) { + ref_picture = s->current_picture_ptr->f.data; + } for(i=0; i<2; i++){ mpeg_motion(s, dest_y, dest_cb, dest_cr, s->picture_structure != i+1, @@ -873,7 +887,7 @@ static av_always_inline void MPV_motion_internal(MpegEncContext *s, } } break; - default: assert(0); + default: av_assert2(0); } } |