30 #ifndef AVCODEC_MPEGVIDEO_COMMON_H
31 #define AVCODEC_MPEGVIDEO_COMMON_H
57 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
58 uint8_t **ref_picture)
62 int motion_x, motion_y;
71 src_x = av_clip(src_x, -16, s->
width);
72 if (src_x == s->
width)
74 src_y = av_clip(src_y, -16, s->
height);
81 ptr = ref_picture[0] + (src_y *
linesize) + src_x;
91 if((motion_x|motion_y)&7){
92 s->
dsp.
gmc1(dest_y , ptr , linesize, 16, motion_x&15, motion_y&15, 128 - s->
no_rounding);
93 s->
dsp.
gmc1(dest_y+8, ptr+8, linesize, 16, motion_x&15, motion_y&15, 128 - s->
no_rounding);
97 dxy= ((motion_x>>3)&1) | ((motion_y>>2)&2);
113 src_x = av_clip(src_x, -8, s->
width>>1);
114 if (src_x == s->
width>>1)
116 src_y = av_clip(src_y, -8, s->
height>>1);
117 if (src_y == s->
height>>1)
121 ptr = ref_picture[1] + offset;
130 s->
dsp.
gmc1(dest_cb, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->
no_rounding);
132 ptr = ref_picture[2] + offset;
137 s->
dsp.
gmc1(dest_cr, ptr, uvlinesize, 8, motion_x&15, motion_y&15, 128 - s->
no_rounding);
143 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
144 uint8_t **ref_picture)
154 ptr = ref_picture[0];
159 s->
dsp.
gmc(dest_y, ptr, linesize, 16,
166 s->
dsp.
gmc(dest_y+8, ptr, linesize, 16,
179 ptr = ref_picture[1];
180 s->
dsp.
gmc(dest_cb, ptr, uvlinesize, 8,
188 ptr = ref_picture[2];
189 s->
dsp.
gmc(dest_cr, ptr, uvlinesize, 8,
199 uint8_t *
dest, uint8_t *src,
201 int src_x,
int src_y,
205 int motion_x,
int motion_y)
210 dxy = ((motion_y & 1) << 1) | (motion_x & 1);
211 src_x += motion_x >> 1;
212 src_y += motion_y >> 1;
215 src_x = av_clip(src_x, -16, width);
218 src_y = av_clip(src_y, -16, height);
221 src += src_y * stride + src_x;
224 if( (
unsigned)src_x >
FFMAX(h_edge_pos - (motion_x&1) - w, 0)
225 || (
unsigned)src_y >
FFMAX(v_edge_pos - (motion_y&1) - h, 0)){
227 src_x, src_y<<field_based, h_edge_pos, s->
v_edge_pos);
240 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
243 int motion_x,
int motion_y,
int h,
int is_mpeg12,
int mb_y)
245 uint8_t *ptr_y, *ptr_cb, *ptr_cr;
246 int dxy, uvdxy, mx, my, src_x, src_y,
262 dxy = ((motion_y & 1) << 1) | (motion_x & 1);
263 src_x = s->
mb_x* 16 + (motion_x >> 1);
264 src_y =( mb_y<<(4-field_based)) + (motion_y >> 1);
268 mx = (motion_x>>1)|(motion_x&1);
270 uvdxy = ((my & 1) << 1) | (mx & 1);
271 uvsrc_x = s->
mb_x* 8 + (mx >> 1);
272 uvsrc_y =( mb_y<<(3-field_based))+ (my >> 1);
274 uvdxy = dxy | (motion_y & 2) | ((motion_x & 2) >> 1);
282 uvsrc_x = s->
mb_x*8 + mx;
283 uvsrc_y = mb_y*8 + my;
288 uvdxy = ((my & 1) << 1) | (mx & 1);
289 uvsrc_x = s->
mb_x* 8 + (mx >> 1);
290 uvsrc_y =( mb_y<<(3-field_based))+ (my >> 1);
295 uvdxy = ((motion_y & 1) << 1) | (mx & 1);
296 uvsrc_x = s->
mb_x* 8 + (mx >> 1);
307 ptr_y = ref_picture[0] + src_y * linesize + src_x;
308 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
309 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
312 || (unsigned)src_y >
FFMAX( v_edge_pos - (motion_y&1) - h , 0)){
316 "MPEG motion vector out of boundary (%d %d)\n", src_x, src_y);
321 src_x, src_y<<field_based,
329 uvsrc_x, uvsrc_y<<field_based,
334 uvsrc_x, uvsrc_y<<field_based,
353 pix_op[0][dxy](dest_y, ptr_y,
linesize, h);
369 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
370 int field_based,
int bottom_field,
int field_select,
372 int motion_x,
int motion_y,
int h,
int mb_y)
377 bottom_field, field_select, ref_picture, pix_op,
378 motion_x, motion_y, h, 1, mb_y);
382 bottom_field, field_select, ref_picture, pix_op,
383 motion_x, motion_y, h, 0, mb_y);
389 uint8_t *
const top = src[1];
390 uint8_t *
const left = src[2];
391 uint8_t *
const mid = src[0];
392 uint8_t *
const right = src[3];
393 uint8_t *
const bottom= src[4];
394 #define OBMC_FILTER(x, t, l, m, r, b)\
395 dst[x]= (t*top[x] + l*left[x] + m*mid[x] + r*right[x] + b*bottom[x] + 4)>>3
396 #define OBMC_FILTER4(x, t, l, m, r, b)\
397 OBMC_FILTER(x , t, l, m, r, b);\
398 OBMC_FILTER(x+1 , t, l, m, r, b);\
399 OBMC_FILTER(x +stride, t, l, m, r, b);\
400 OBMC_FILTER(x+1+stride, t, l, m, r, b);
440 uint8_t *
dest, uint8_t *src,
441 int src_x,
int src_y,
452 if(i && mv[i][0]==mv[
MID][0] && mv[i][1]==mv[
MID][1]){
469 uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr,
470 int field_based,
int bottom_field,
int field_select,
473 int motion_x,
int motion_y,
int h)
475 uint8_t *ptr_y, *ptr_cb, *ptr_cr;
476 int dxy, uvdxy, mx, my, src_x, src_y, uvsrc_x, uvsrc_y,
v_edge_pos,
linesize,
uvlinesize;
478 dxy = ((motion_y & 3) << 2) | (motion_x & 3);
479 src_x = s->
mb_x * 16 + (motion_x >> 2);
480 src_y = s->
mb_y * (16 >> field_based) + (motion_y >> 2);
483 linesize = s->
linesize << field_based;
490 static const int rtab[8]= {0,0,1,1,0,0,0,1};
491 mx= (motion_x>>1) + rtab[motion_x&7];
492 my= (motion_y>>1) + rtab[motion_y&7];
494 mx= (motion_x>>1)|(motion_x&1);
495 my= (motion_y>>1)|(motion_y&1);
503 uvdxy= (mx&1) | ((my&1)<<1);
507 uvsrc_x = s->
mb_x * 8 + mx;
508 uvsrc_y = s->
mb_y * (8 >> field_based) + my;
510 ptr_y = ref_picture[0] + src_y * linesize + src_x;
511 ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x;
512 ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x;
515 || (unsigned)src_y >
FFMAX( v_edge_pos - (motion_y&3) - h , 0)){
517 17, 17+field_based, src_x, src_y<<field_based,
524 uvsrc_x, uvsrc_y<<field_based,
528 uvsrc_x, uvsrc_y<<field_based,
536 qpix_op[0][dxy](dest_y, ptr_y,
linesize);
551 qpix_op[1][dxy](dest_y , ptr_y ,
linesize);
552 qpix_op[1][dxy](dest_y+8, ptr_y+8,
linesize);
555 pix_op[1][uvdxy](dest_cr, ptr_cr,
uvlinesize, h >> 1);
556 pix_op[1][uvdxy](dest_cb, ptr_cb,
uvlinesize, h >> 1);
564 uint8_t *dest_cb, uint8_t *dest_cr,
565 uint8_t **ref_picture,
568 int dxy, emu=0, src_x, src_y, offset;
576 dxy = ((my & 1) << 1) | (mx & 1);
580 src_x = s->
mb_x * 8 + mx;
581 src_y = s->
mb_y * 8 + my;
582 src_x = av_clip(src_x, -8, (s->
width >> 1));
583 if (src_x == (s->
width >> 1))
585 src_y = av_clip(src_y, -8, (s->
height >> 1));
586 if (src_y == (s->
height >> 1))
590 ptr = ref_picture[1] + offset;
603 ptr = ref_picture[2] + offset;
617 const int mx= (s->
mv[dir][0][0]>>shift) + 16*s->
mb_x + 8;
618 const int my= (s->
mv[dir][0][1]>>shift) + 16*s->
mb_y;
638 uint8_t *dest_y, uint8_t *dest_cb,
639 uint8_t *dest_cr,
int dir,
640 uint8_t **ref_picture,
644 int dxy, mx, my, src_x, src_y, motion_x, motion_y;
654 int16_t mv_cache[4][4][2];
657 const int mot_xy= mb_x*2 + mb_y*2*mot_stride;
666 memcpy(mv_cache[0][1], mv_cache[1][1],
sizeof(int16_t)*4);
672 AV_COPY32(mv_cache[1][0], mv_cache[1][1]);
673 AV_COPY32(mv_cache[2][0], mv_cache[2][1]);
680 AV_COPY32(mv_cache[1][3], mv_cache[1][2]);
681 AV_COPY32(mv_cache[2][3], mv_cache[2][2]);
690 const int x= (i&1)+1;
691 const int y= (i>>1)+1;
693 {mv_cache[y][x ][0], mv_cache[y][x ][1]},
694 {mv_cache[y-1][x][0], mv_cache[y-1][x][1]},
695 {mv_cache[y][x-1][0], mv_cache[y][x-1][1]},
696 {mv_cache[y][x+1][0], mv_cache[y][x+1][1]},
697 {mv_cache[y+1][x][0], mv_cache[y+1][x][1]}};
701 mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8,
727 ref_picture, pix_op, qpix_op,
728 s->
mv[dir][0][0], s->
mv[dir][0][1], 16);
733 s->
mv[dir][0][0], s->
mv[dir][0][1], 16);
739 s->
mv[dir][0][0], s->
mv[dir][0][1], 16, mb_y);
748 motion_x = s->
mv[dir][i][0];
749 motion_y = s->
mv[dir][i][1];
751 dxy = ((motion_y & 3) << 2) | (motion_x & 3);
752 src_x = mb_x * 16 + (motion_x >> 2) + (i & 1) * 8;
753 src_y = mb_y * 16 + (motion_y >> 2) + (i >>1) * 8;
756 src_x = av_clip(src_x, -16, s->
width);
757 if (src_x == s->
width)
759 src_y = av_clip(src_y, -16, s->
height);
763 ptr = ref_picture[0] + (src_y * s->
linesize) + (src_x);
774 dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->
linesize;
775 qpix_op[1][dxy](dest, ptr, s->
linesize);
777 mx += s->
mv[dir][i][0]/2;
778 my += s->
mv[dir][i][1]/2;
783 ref_picture[0], 0, 0,
784 mb_x * 16 + (i & 1) * 8, mb_y * 16 + (i >>1) * 8,
788 s->
mv[dir][i][0], s->
mv[dir][i][1]);
790 mx += s->
mv[dir][i][0];
791 my += s->
mv[dir][i][1];
805 ref_picture, pix_op, qpix_op,
806 s->
mv[dir][i][0], s->
mv[dir][i][1], 8);
813 s->
mv[dir][0][0], s->
mv[dir][0][1], 8, mb_y);
818 s->
mv[dir][1][0], s->
mv[dir][1][1], 8, mb_y);
828 s->
mv[dir][0][0], s->
mv[dir][0][1], 16, mb_y>>1);
833 uint8_t ** ref2picture;
837 ref2picture= ref_picture;
845 s->
mv[dir][i][0], s->
mv[dir][i][1] + 16*i, 8, mb_y>>1);
860 s->
mv[dir][2*i + j][0], s->
mv[dir][2*i + j][1], 8, mb_y);
869 s->
mv[dir][2*i][0],s->
mv[dir][2*i][1],16, mb_y>>1);
886 uint8_t *dest_y, uint8_t *dest_cb,
887 uint8_t *dest_cr,
int dir,
888 uint8_t **ref_picture,
895 ref_picture, pix_op, qpix_op, 1);
899 ref_picture, pix_op, qpix_op, 0);
void(* emulated_edge_mc)(uint8_t *buf, const uint8_t *src, int linesize, int block_w, int block_h, int src_x, int src_y, int w, int h)
Motion estimation with emulated edge values.
op_pixels_func put_pixels_tab[4][4]
Halfpel motion compensation with rounding (a+b+1)>>1.
#define MV_TYPE_FIELD
2 vectors, one per field
int sprite_warping_accuracy
void(* prefetch)(void *mem, int stride, int h)
static void put_obmc(uint8_t *dst, uint8_t *src[5], int stride)
int v_edge_pos
horizontal / vertical position of the right/bottom edge (pixel replication)
#define FF_BUG_HPEL_CHROMA
int obmc
overlapped block motion compensation
static void obmc_motion(MpegEncContext *s, uint8_t *dest, uint8_t *src, int src_x, int src_y, op_pixels_func *pix_op, int16_t mv[5][2])
int real_sprite_warping_points
static void gmc_motion(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t **ref_picture)
#define OBMC_FILTER4(x, t, l, m, r, b)
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)
motion compensation of a single macroblock
static void qpel_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], qpel_mc_func(*qpix_op)[16], int motion_x, int motion_y, int h)
enum OutputFormat out_format
output format
void(* qpel_mc_func)(uint8_t *dst, uint8_t *src, int stride)
int no_rounding
apply no rounding to motion compensation (MPEG4, msmpeg4, ...) for b-frames rounding mode is always 0...
Picture current_picture
copy of the current picture structure.
op_pixels_func avg_pixels_tab[4][4]
Halfpel motion compensation with rounding (a+b+1)>>1.
#define FF_BUG_QPEL_CHROMA2
#define CODEC_FLAG_GRAY
Only decode/encode grayscale.
int sprite_offset[2][2]
sprite offset[isChroma][isMVY]
preferred ID for MPEG-1/2 video decoding
static int ff_h263_round_chroma(int x)
int mb_skipped
MUST BE SET only during DECODING.
int unrestricted_mv
mv can point outside of the coded picture
uint8_t * edge_emu_buffer
temporary buffer for if MVs point to out-of-frame data
void av_log(void *avcl, int level, const char *fmt,...)
int quarter_sample
1->qpel, 0->half pel ME/MC
op_pixels_func put_no_rnd_pixels_tab[4][4]
Halfpel motion compensation with no rounding (a+b)>>1.
#define CODEC_FLAG_EMU_EDGE
Don't draw edges.
int sprite_delta[2][2]
sprite_delta [isY][isMVY]
Picture * current_picture_ptr
pointer to the current picture
void ff_mspel_motion(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t **ref_picture, op_pixels_func(*pix_op)[4], int motion_x, int motion_y, int h)
#define OBMC_FILTER(x, t, l, m, r, b)
static void chroma_4mv_motion(MpegEncContext *s, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t **ref_picture, op_pixels_func *pix_op, int mx, int my)
h263 chroma 4mv motion compensation.
#define FF_BUG_QPEL_CHROMA
int first_field
is 1 for the first field of a field picture 0 otherwise
static void prefetch_motion(MpegEncContext *s, uint8_t **pix, int dir)
void(* op_pixels_func)(uint8_t *block, const uint8_t *pixels, int line_size, int h)
static const int8_t mv[256][2]
uint32_t * mb_type
macroblock type table mb_type_base + mb_width + 2
#define MV_TYPE_16X16
1 vector for the whole mb
int alloc_picture(MpegEncContext *s, Picture *pic, int shared)
Allocate a Picture.
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
int height
picture size. must be a multiple of 16
int16_t(*[2] motion_val)[2]
motion vector table
#define MV_TYPE_16X8
2 vectors, one per 16x8 block
void(* gmc1)(uint8_t *dst, uint8_t *src, int srcStride, int h, int x16, int y16, int rounder)
translational global motion compensation.
DSPContext dsp
pointers for accelerated dsp functions
static void gmc1_motion(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, uint8_t **ref_picture)
void MPV_common_defaults(MpegEncContext *s)
Set the given MpegEncContext to common defaults (same for encoding and decoding). ...
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
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)
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
int b8_stride
2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
struct AVCodecContext * avctx
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
void(* gmc)(uint8_t *dst, uint8_t *src, int stride, int h, int ox, int oy, int dxx, int dxy, int dyx, int dyy, int shift, int r, int width, int height)
global motion compensation.
uint8_t * obmc_scratchpad
static int hpel_motion(MpegEncContext *s, uint8_t *dest, uint8_t *src, int field_based, int field_select, int src_x, int src_y, int width, int height, int stride, int h_edge_pos, int v_edge_pos, int w, int h, op_pixels_func *pix_op, int motion_x, int motion_y)
#define MV_TYPE_DMV
2 vectors, special mpeg2 Dual Prime Vectors
static 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])
int linesize
line size, in bytes, may be different from width
int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow)
int flags
AVCodecContext.flags (HQ, MV4, ...)
int workaround_bugs
workaround bugs in encoders which cannot be detected automatically
void ff_h261_loop_filter(MpegEncContext *s)
#define MV_TYPE_8X8
4 vectors (h263, mpeg4 4MV)
int uvlinesize
line size, for chroma in bytes, may be different from width
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)