/*
* The simplest mpeg encoder (well, it was the simplest!)
- * Copyright (c) 2000,2001 Fabrice Bellard.
+ * Copyright (c) 2000,2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of FFmpeg.
+ * 4MV & hq & B-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at>
*
- * FFmpeg is free software; you can redistribute it and/or
+ * This file is part of Libav.
+ *
+ * Libav 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.
*
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav 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 FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * 4MV & hq & b-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at>
*/
/**
- * @file mpegvideo_common.h
+ * @file
* The simplest mpeg encoder (well, it was the simplest!).
*/
-#ifndef MPEGVIDEO_COMMON_H
-#define MPEGVIDEO_COMMON_H
+#ifndef AVCODEC_MPEGVIDEO_COMMON_H
+#define AVCODEC_MPEGVIDEO_COMMON_H
+#include <string.h>
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
#include "faandct.h"
#include <limits.h>
-int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
-int dct_quantize_trellis_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
-void denoise_dct_c(MpegEncContext *s, DCTELEM *block);
-void copy_picture(Picture *dst, Picture *src);
-
-/**
- * allocates a Picture
- * The pixels are allocated/set by calling get_buffer() if shared=0
- */
-int alloc_picture(MpegEncContext *s, Picture *pic, int shared);
+int ff_dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
/**
- * sets the given MpegEncContext to common defaults (same for encoding and decoding).
- * the changed fields will not depend upon the prior state of the MpegEncContext.
+ * Set the given MpegEncContext to common defaults (same for encoding and decoding).
+ * The changed fields will not depend upon the prior state of the MpegEncContext.
*/
-void MPV_common_defaults(MpegEncContext *s);
+void ff_MPV_common_defaults(MpegEncContext *s);
static inline void gmc1_motion(MpegEncContext *s,
uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
ptr = ref_picture[0] + (src_y * linesize) + src_x;
if(s->flags&CODEC_FLAG_EMU_EDGE){
- if( (unsigned)src_x >= s->h_edge_pos - 17
- || (unsigned)src_y >= s->v_edge_pos - 17){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos);
+ if( (unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0)
+ || (unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)){
+ s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos);
ptr= s->edge_emu_buffer;
}
}
}
}
- if(s->flags&CODEC_FLAG_GRAY) return;
+ if(CONFIG_GRAY && s->flags&CODEC_FLAG_GRAY) return;
motion_x= s->sprite_offset[1][0];
motion_y= s->sprite_offset[1][1];
offset = (src_y * uvlinesize) + src_x;
ptr = ref_picture[1] + offset;
if(s->flags&CODEC_FLAG_EMU_EDGE){
- if( (unsigned)src_x >= (s->h_edge_pos>>1) - 9
- || (unsigned)src_y >= (s->v_edge_pos>>1) - 9){
- ff_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);
+ if( (unsigned)src_x >= FFMAX((s->h_edge_pos>>1) - 9, 0)
+ || (unsigned)src_y >= FFMAX((s->v_edge_pos>>1) - 9, 0)){
+ s->dsp.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);
ptr= s->edge_emu_buffer;
emu=1;
}
ptr = ref_picture[2] + offset;
if(emu){
- ff_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->dsp.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);
ptr= s->edge_emu_buffer;
}
s->dsp.gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->no_rounding);
a+1, (1<<(2*a+1)) - s->no_rounding,
s->h_edge_pos, s->v_edge_pos);
- if(s->flags&CODEC_FLAG_GRAY) return;
+ if(CONFIG_GRAY && s->flags&CODEC_FLAG_GRAY) return;
ox= s->sprite_offset[1][0] + s->sprite_delta[0][0]*s->mb_x*8 + s->sprite_delta[0][1]*s->mb_y*8;
oy= s->sprite_offset[1][1] + s->sprite_delta[1][0]*s->mb_x*8 + s->sprite_delta[1][1]*s->mb_y*8;
src += src_y * stride + src_x;
if(s->unrestricted_mv && (s->flags&CODEC_FLAG_EMU_EDGE)){
- if( (unsigned)src_x > h_edge_pos - (motion_x&1) - w
- || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){
- ff_emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<<field_based,
+ if( (unsigned)src_x > FFMAX(h_edge_pos - (motion_x&1) - w, 0)
+ || (unsigned)src_y > FFMAX(v_edge_pos - (motion_y&1) - h, 0)){
+ s->dsp.emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<<field_based,
src_x, src_y<<field_based, h_edge_pos, s->v_edge_pos);
src= s->edge_emu_buffer;
emu=1;
return emu;
}
-/* apply one mpeg motion vector to the three components */
-static av_always_inline void mpeg_motion(MpegEncContext *s,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int field_based, int bottom_field, int field_select,
- uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
- int motion_x, int motion_y, int h)
+static av_always_inline
+void mpeg_motion_internal(MpegEncContext *s,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ int field_based, int bottom_field, int field_select,
+ uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
+ int motion_x, int motion_y, int h, int is_mpeg12, int mb_y)
{
uint8_t *ptr_y, *ptr_cb, *ptr_cr;
- int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize;
+ int dxy, uvdxy, mx, my, src_x, src_y,
+ uvsrc_x, uvsrc_y, v_edge_pos, uvlinesize, linesize;
#if 0
if(s->quarter_sample)
#endif
v_edge_pos = s->v_edge_pos >> field_based;
- linesize = s->current_picture.linesize[0] << field_based;
- uvlinesize = s->current_picture.linesize[1] << field_based;
+ linesize = s->current_picture.f.linesize[0] << field_based;
+ uvlinesize = s->current_picture.f.linesize[1] << field_based;
dxy = ((motion_y & 1) << 1) | (motion_x & 1);
src_x = s->mb_x* 16 + (motion_x >> 1);
- src_y =(s->mb_y<<(4-field_based)) + (motion_y >> 1);
+ src_y =( mb_y<<(4-field_based)) + (motion_y >> 1);
- if (s->out_format == FMT_H263) {
+ if (!is_mpeg12 && s->out_format == FMT_H263) {
if((s->workaround_bugs & FF_BUG_HPEL_CHROMA) && field_based){
mx = (motion_x>>1)|(motion_x&1);
my = motion_y >>1;
uvdxy = ((my & 1) << 1) | (mx & 1);
uvsrc_x = s->mb_x* 8 + (mx >> 1);
- uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1);
+ uvsrc_y =( mb_y<<(3-field_based))+ (my >> 1);
}else{
uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1);
uvsrc_x = src_x>>1;
uvsrc_y = src_y>>1;
}
- }else if(s->out_format == FMT_H261){//even chroma mv's are full pel in H261
+ }else if(!is_mpeg12 && s->out_format == FMT_H261){//even chroma mv's are full pel in H261
mx = motion_x / 4;
my = motion_y / 4;
uvdxy = 0;
uvsrc_x = s->mb_x*8 + mx;
- uvsrc_y = s->mb_y*8 + my;
+ uvsrc_y = mb_y*8 + my;
} else {
if(s->chroma_y_shift){
mx = motion_x / 2;
my = motion_y / 2;
uvdxy = ((my & 1) << 1) | (mx & 1);
uvsrc_x = s->mb_x* 8 + (mx >> 1);
- uvsrc_y = (s->mb_y<<(3-field_based)) + (my >> 1);
+ uvsrc_y =( mb_y<<(3-field_based))+ (my >> 1);
} else {
if(s->chroma_x_shift){
//Chroma422
ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
- if( (unsigned)src_x > s->h_edge_pos - (motion_x&1) - 16
- || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){
- if(s->codec_id == CODEC_ID_MPEG2VIDEO ||
+ if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&1) - 16, 0)
+ || (unsigned)src_y > FFMAX( v_edge_pos - (motion_y&1) - h , 0)){
+ if(is_mpeg12 || s->codec_id == CODEC_ID_MPEG2VIDEO ||
s->codec_id == CODEC_ID_MPEG1VIDEO){
- av_log(s->avctx,AV_LOG_DEBUG,"MPEG motion vector out of boundary\n");
- return ;
+ av_log(s->avctx,AV_LOG_DEBUG,
+ "MPEG motion vector out of boundary (%d %d)\n", src_x, src_y);
+ return;
}
- ff_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->dsp.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);
ptr_y = s->edge_emu_buffer;
- if(!(s->flags&CODEC_FLAG_GRAY)){
+ if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize;
- ff_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);
- ff_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->dsp.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->dsp.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);
ptr_cb= uvbuf;
ptr_cr= uvbuf+16;
}
pix_op[0][dxy](dest_y, ptr_y, linesize, h);
- if(!(s->flags&CODEC_FLAG_GRAY)){
- pix_op[s->chroma_x_shift][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift);
- pix_op[s->chroma_x_shift][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift);
+ if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
+ pix_op[s->chroma_x_shift][uvdxy]
+ (dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift);
+ pix_op[s->chroma_x_shift][uvdxy]
+ (dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift);
}
- if((ENABLE_H261_ENCODER || ENABLE_H261_DECODER) && s->out_format == FMT_H261){
+ if(!is_mpeg12 && (CONFIG_H261_ENCODER || CONFIG_H261_DECODER) &&
+ s->out_format == FMT_H261){
ff_h261_loop_filter(s);
}
}
+/* apply one mpeg motion vector to the three components */
+static av_always_inline
+void mpeg_motion(MpegEncContext *s,
+ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
+ int field_based, int bottom_field, int field_select,
+ uint8_t **ref_picture, op_pixels_func (*pix_op)[4],
+ int motion_x, int motion_y, int h, int mb_y)
+{
+#if !CONFIG_SMALL
+ if(s->out_format == FMT_MPEG1)
+ mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based,
+ bottom_field, field_select, ref_picture, pix_op,
+ motion_x, motion_y, h, 1, mb_y);
+ else
+#endif
+ mpeg_motion_internal(s, dest_y, dest_cb, dest_cr, field_based,
+ bottom_field, field_select, ref_picture, pix_op,
+ motion_x, motion_y, h, 0, mb_y);
+}
//FIXME move to dsputil, avg variant, 16x16 version
static inline void put_obmc(uint8_t *dst, uint8_t *src[5], int stride){
ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
- if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 16
- || (unsigned)src_y > v_edge_pos - (motion_y&3) - h ){
- ff_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);
+ 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->dsp.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);
ptr_y= s->edge_emu_buffer;
- if(!(s->flags&CODEC_FLAG_GRAY)){
+ if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize;
- ff_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);
- ff_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->dsp.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->dsp.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);
ptr_cb= uvbuf;
ptr_cr= uvbuf + 16;
}
qpix_op[1][dxy](dest_y , ptr_y , linesize);
qpix_op[1][dxy](dest_y+8, ptr_y+8, linesize);
}
- if(!(s->flags&CODEC_FLAG_GRAY)){
+ if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){
pix_op[1][uvdxy](dest_cr, ptr_cr, uvlinesize, h >> 1);
pix_op[1][uvdxy](dest_cb, ptr_cb, uvlinesize, h >> 1);
}
}
/**
- * h263 chorma 4mv motion compensation.
+ * h263 chroma 4mv motion compensation.
*/
static inline void chroma_4mv_motion(MpegEncContext *s,
uint8_t *dest_cb, uint8_t *dest_cr,
src_x = s->mb_x * 8 + mx;
src_y = s->mb_y * 8 + my;
- src_x = av_clip(src_x, -8, s->width/2);
- if (src_x == s->width/2)
+ src_x = av_clip(src_x, -8, (s->width >> 1));
+ if (src_x == (s->width >> 1))
dxy &= ~1;
- src_y = av_clip(src_y, -8, s->height/2);
- if (src_y == s->height/2)
+ src_y = av_clip(src_y, -8, (s->height >> 1));
+ if (src_y == (s->height >> 1))
dxy &= ~2;
- offset = (src_y * (s->uvlinesize)) + src_x;
+ offset = src_y * s->uvlinesize + src_x;
ptr = ref_picture[1] + offset;
if(s->flags&CODEC_FLAG_EMU_EDGE){
- if( (unsigned)src_x > (s->h_edge_pos>>1) - (dxy &1) - 8
- || (unsigned)src_y > (s->v_edge_pos>>1) - (dxy>>1) - 8){
- ff_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);
+ 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->dsp.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);
ptr= s->edge_emu_buffer;
emu=1;
}
ptr = ref_picture[2] + offset;
if(emu){
- ff_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->dsp.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);
ptr= s->edge_emu_buffer;
}
pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8);
* @param dest_cr chroma cr/v destination pointer
* @param dir direction (0->forward, 1->backward)
* @param ref_picture array[3] of pointers to the 3 planes of the reference picture
- * @param pic_op halfpel motion compensation function (average or put normally)
- * @param pic_op qpel motion compensation function (average or put normally)
+ * @param pix_op halfpel motion compensation function (average or put normally)
+ * @param qpix_op qpel motion compensation function (average or put normally)
* the motion vectors are taken from s->mv and the MV type from s->mv_type
*/
-static inline void MPV_motion(MpegEncContext *s,
- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
- int dir, uint8_t **ref_picture,
- op_pixels_func (*pix_op)[4], qpel_mc_func (*qpix_op)[16])
+static av_always_inline void MPV_motion_internal(MpegEncContext *s,
+ uint8_t *dest_y, uint8_t *dest_cb,
+ uint8_t *dest_cr, int dir,
+ uint8_t **ref_picture,
+ op_pixels_func (*pix_op)[4],
+ qpel_mc_func (*qpix_op)[16], int is_mpeg12)
{
int dxy, mx, my, src_x, src_y, motion_x, motion_y;
int mb_x, mb_y, i;
prefetch_motion(s, ref_picture, dir);
- if(s->obmc && s->pict_type != B_TYPE){
+ if(!is_mpeg12 && s->obmc && s->pict_type != AV_PICTURE_TYPE_B){
int16_t mv_cache[4][4][2];
const int xy= s->mb_x + s->mb_y*s->mb_stride;
const int mot_stride= s->b8_stride;
assert(!s->mb_skipped);
- memcpy(mv_cache[1][1], s->current_picture.motion_val[0][mot_xy ], sizeof(int16_t)*4);
- memcpy(mv_cache[2][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4);
- memcpy(mv_cache[3][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4);
+ memcpy(mv_cache[1][1], s->current_picture.f.motion_val[0][mot_xy ], sizeof(int16_t) * 4);
+ memcpy(mv_cache[2][1], s->current_picture.f.motion_val[0][mot_xy + mot_stride], sizeof(int16_t) * 4);
+ memcpy(mv_cache[3][1], s->current_picture.f.motion_val[0][mot_xy + mot_stride], sizeof(int16_t) * 4);
- if(mb_y==0 || IS_INTRA(s->current_picture.mb_type[xy-s->mb_stride])){
+ if (mb_y == 0 || IS_INTRA(s->current_picture.f.mb_type[xy - s->mb_stride])) {
memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4);
}else{
- memcpy(mv_cache[0][1], s->current_picture.motion_val[0][mot_xy-mot_stride], sizeof(int16_t)*4);
+ memcpy(mv_cache[0][1], s->current_picture.f.motion_val[0][mot_xy - mot_stride], sizeof(int16_t) * 4);
}
- if(mb_x==0 || IS_INTRA(s->current_picture.mb_type[xy-1])){
- *(int32_t*)mv_cache[1][0]= *(int32_t*)mv_cache[1][1];
- *(int32_t*)mv_cache[2][0]= *(int32_t*)mv_cache[2][1];
+ if (mb_x == 0 || IS_INTRA(s->current_picture.f.mb_type[xy - 1])) {
+ AV_COPY32(mv_cache[1][0], mv_cache[1][1]);
+ AV_COPY32(mv_cache[2][0], mv_cache[2][1]);
}else{
- *(int32_t*)mv_cache[1][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1];
- *(int32_t*)mv_cache[2][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1+mot_stride];
+ AV_COPY32(mv_cache[1][0], s->current_picture.f.motion_val[0][mot_xy - 1]);
+ AV_COPY32(mv_cache[2][0], s->current_picture.f.motion_val[0][mot_xy - 1 + mot_stride]);
}
- if(mb_x+1>=s->mb_width || IS_INTRA(s->current_picture.mb_type[xy+1])){
- *(int32_t*)mv_cache[1][3]= *(int32_t*)mv_cache[1][2];
- *(int32_t*)mv_cache[2][3]= *(int32_t*)mv_cache[2][2];
+ if (mb_x + 1 >= s->mb_width || IS_INTRA(s->current_picture.f.mb_type[xy + 1])) {
+ AV_COPY32(mv_cache[1][3], mv_cache[1][2]);
+ AV_COPY32(mv_cache[2][3], mv_cache[2][2]);
}else{
- *(int32_t*)mv_cache[1][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2];
- *(int32_t*)mv_cache[2][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2+mot_stride];
+ AV_COPY32(mv_cache[1][3], s->current_picture.f.motion_val[0][mot_xy + 2]);
+ AV_COPY32(mv_cache[2][3], s->current_picture.f.motion_val[0][mot_xy + 2 + mot_stride]);
}
mx = 0;
mx += mv[0][0];
my += mv[0][1];
}
- if(!(s->flags&CODEC_FLAG_GRAY))
+ if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY))
chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);
return;
gmc_motion(s, dest_y, dest_cb, dest_cr,
ref_picture);
}
- }else if(s->quarter_sample){
+ }else if(!is_mpeg12 && s->quarter_sample){
qpel_motion(s, dest_y, dest_cb, dest_cr,
0, 0, 0,
ref_picture, pix_op, qpix_op,
s->mv[dir][0][0], s->mv[dir][0][1], 16);
- }else if(ENABLE_WMV2 && s->mspel){
+ }else if(!is_mpeg12 && (CONFIG_WMV2_DECODER || CONFIG_WMV2_ENCODER) && s->mspel){
ff_mspel_motion(s, dest_y, dest_cb, dest_cr,
ref_picture, pix_op,
s->mv[dir][0][0], s->mv[dir][0][1], 16);
mpeg_motion(s, dest_y, dest_cb, dest_cr,
0, 0, 0,
ref_picture, pix_op,
- s->mv[dir][0][0], s->mv[dir][0][1], 16);
+ s->mv[dir][0][0], s->mv[dir][0][1], 16, mb_y);
}
break;
case MV_TYPE_8X8:
+ if (!is_mpeg12) {
mx = 0;
my = 0;
if(s->quarter_sample){
ptr = ref_picture[0] + (src_y * s->linesize) + (src_x);
if(s->flags&CODEC_FLAG_EMU_EDGE){
- if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 8
- || (unsigned)src_y > s->v_edge_pos - (motion_y&3) - 8 ){
- ff_emulated_edge_mc(s->edge_emu_buffer, ptr, s->linesize, 9, 9, src_x, src_y, s->h_edge_pos, s->v_edge_pos);
+ 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->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr,
+ s->linesize, 9, 9,
+ src_x, src_y,
+ s->h_edge_pos, s->v_edge_pos);
ptr= s->edge_emu_buffer;
}
}
}
}
- if(!(s->flags&CODEC_FLAG_GRAY))
+ if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY))
chroma_4mv_motion(s, dest_cb, dest_cr, ref_picture, pix_op[1], mx, my);
+ }
break;
case MV_TYPE_FIELD:
if (s->picture_structure == PICT_FRAME) {
- if(s->quarter_sample){
+ if(!is_mpeg12 && s->quarter_sample){
for(i=0; i<2; i++){
qpel_motion(s, dest_y, dest_cb, dest_cr,
1, i, s->field_select[dir][i],
mpeg_motion(s, dest_y, dest_cb, dest_cr,
1, 0, s->field_select[dir][0],
ref_picture, pix_op,
- s->mv[dir][0][0], s->mv[dir][0][1], 8);
+ s->mv[dir][0][0], s->mv[dir][0][1], 8, mb_y);
/* bottom field */
mpeg_motion(s, dest_y, dest_cb, dest_cr,
1, 1, s->field_select[dir][1],
ref_picture, pix_op,
- s->mv[dir][1][0], s->mv[dir][1][1], 8);
+ 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 != B_TYPE && !s->first_field){
- ref_picture= s->current_picture_ptr->data;
+ if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != AV_PICTURE_TYPE_B && !s->first_field){
+ ref_picture = s->current_picture_ptr->f.data;
}
mpeg_motion(s, dest_y, dest_cb, dest_cr,
0, 0, s->field_select[dir][0],
ref_picture, pix_op,
- s->mv[dir][0][0], s->mv[dir][0][1], 16);
+ s->mv[dir][0][0], s->mv[dir][0][1], 16, mb_y>>1);
}
break;
case MV_TYPE_16X8:
for(i=0; i<2; i++){
uint8_t ** ref2picture;
- if(s->picture_structure == s->field_select[dir][i] + 1 || s->pict_type == B_TYPE || s->first_field){
+ if(s->picture_structure == s->field_select[dir][i] + 1
+ || s->pict_type == AV_PICTURE_TYPE_B || s->first_field){
ref2picture= ref_picture;
}else{
- ref2picture= s->current_picture_ptr->data;
+ ref2picture = s->current_picture_ptr->f.data;
}
mpeg_motion(s, dest_y, dest_cb, dest_cr,
0, 0, s->field_select[dir][i],
ref2picture, pix_op,
- s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8);
+ s->mv[dir][i][0], s->mv[dir][i][1] + 16*i, 8, mb_y>>1);
dest_y += 16*s->linesize;
dest_cb+= (16>>s->chroma_y_shift)*s->uvlinesize;
mpeg_motion(s, dest_y, dest_cb, dest_cr,
1, j, j^i,
ref_picture, pix_op,
- s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], 8);
+ s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], 8, mb_y);
}
pix_op = s->dsp.avg_pixels_tab;
}
mpeg_motion(s, dest_y, dest_cb, dest_cr,
0, 0, s->picture_structure != i+1,
ref_picture, pix_op,
- s->mv[dir][2*i][0],s->mv[dir][2*i][1],16);
+ s->mv[dir][2*i][0],s->mv[dir][2*i][1],16, mb_y>>1);
// after put we make avg of the same block
pix_op=s->dsp.avg_pixels_tab;
//opposite parity is always in the same frame if this is second field
if(!s->first_field){
- ref_picture = s->current_picture_ptr->data;
+ ref_picture = s->current_picture_ptr->f.data;
}
}
}
}
}
-#endif /* MPEGVIDEO_COMMON_H */
+static inline void MPV_motion(MpegEncContext *s,
+ uint8_t *dest_y, uint8_t *dest_cb,
+ uint8_t *dest_cr, int dir,
+ uint8_t **ref_picture,
+ op_pixels_func (*pix_op)[4],
+ qpel_mc_func (*qpix_op)[16])
+{
+#if !CONFIG_SMALL
+ if(s->out_format == FMT_MPEG1)
+ MPV_motion_internal(s, dest_y, dest_cb, dest_cr, dir,
+ ref_picture, pix_op, qpix_op, 1);
+ else
+#endif
+ MPV_motion_internal(s, dest_y, dest_cb, dest_cr, dir,
+ ref_picture, pix_op, qpix_op, 0);
+}
+#endif /* AVCODEC_MPEGVIDEO_COMMON_H */