42 #define SQ(a) ((a)*(a))
46 #define P_TOPRIGHT P[3]
51 int *mx_ptr,
int *my_ptr,
int dmin,
52 int src_index,
int ref_index,
79 #define FLAG_QPEL 1 //must be 1
83 static inline void init_ref(
MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3],
int x,
int y,
int ref_index){
84 const int offset[3]= {
91 c->
src[0][i]= src [i] + offset[i];
92 c->
ref[0][i]= ref [i] + offset[i];
96 c->
ref[ref_index][i]= ref2[i] + offset[i];
108 const int size,
const int h,
int ref_index,
int src_index,
112 const int hx= subx + (x<<(1+qpel));
113 const int hy= suby + (y<<(1+qpel));
114 uint8_t *
const *
const ref= c->
ref[ref_index];
115 uint8_t *
const *
const src= c->
src[src_index];
118 assert(x >= c->
xmin && hx <= c->xmax<<(qpel+1) && y >= c->
ymin && hy <= c->ymax<<(qpel+1));
119 if(x >= c->
xmin && hx <= c->xmax<<(qpel+1) && y >= c->
ymin && hy <= c->ymax<<(qpel+1)){
122 const int mask= 2*qpel+1;
130 int fxy= (fx&
mask) + ((fy&mask)<<(qpel+1));
131 int bxy= (bx&
mask) + ((by&mask)<<(qpel+1));
133 uint8_t *dst= c->
temp + 8*(i&1) + 8*stride*(i>>1);
147 int fxy= (fx&
mask) + ((fy&mask)<<(qpel+1));
148 int bxy= (bx&
mask) + ((by&mask)<<(qpel+1));
160 assert((fx>>1) + 16*s->
mb_x >= -16);
161 assert((fy>>1) + 16*s->
mb_y >= -16);
162 assert((fx>>1) + 16*s->
mb_x <= s->
width);
164 assert((bx>>1) + 16*s->
mb_x >= -16);
165 assert((by>>1) + 16*s->
mb_y >= -16);
166 assert((bx>>1) + 16*s->
mb_x <= s->
width);
173 d = cmp_func(s, c->
temp, src[0], stride, 16);
180 const int size,
const int h,
int ref_index,
int src_index,
185 const int dxy= subx + (suby<<(1+qpel));
186 const int hx= subx + (x<<(1+qpel));
187 const int hy= suby + (y<<(1+qpel));
188 uint8_t *
const *
const ref= c->
ref[ref_index];
189 uint8_t *
const *
const src= c->
src[src_index];
201 uvdxy= (cx&1) + 2*(cy&1);
207 uvdxy= dxy | (x&1) | (2*(y&1));
209 d = cmp_func(s, c->
temp, src[0], stride, h);
211 d = cmp_func(s, src[0], ref[0] + x + y*stride, stride, h);
213 uvdxy= (x&1) + 2*(y&1);
217 c->
hpel_put[size+1][uvdxy](uvtemp , ref[1] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);
218 c->
hpel_put[size+1][uvdxy](uvtemp+8, ref[2] + (x>>1) + (y>>1)*uvstride, uvstride, h>>1);
219 d += chroma_cmp_func(s, uvtemp , src[1], uvstride, h>>1);
220 d += chroma_cmp_func(s, uvtemp+8, src[2], uvstride, h>>1);
226 int ref_index,
int src_index,
228 return cmp_inline(s,x,y,0,0,0,16,ref_index,src_index, cmp_func, chroma_cmp_func, 0, 0);
232 const int size,
const int h,
int ref_index,
int src_index,
235 return cmp_direct_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&
FLAG_QPEL);
237 return cmp_inline(s,x,y,0,0,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0, flags&
FLAG_CHROMA);
242 const int size,
const int h,
int ref_index,
int src_index,
245 return cmp_direct_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&
FLAG_QPEL);
247 return cmp_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags&
FLAG_QPEL, flags&
FLAG_CHROMA);
255 const int size,
const int h,
int ref_index,
int src_index,
259 && flags==0 && h==16 && size==0 && subx==0 && suby==0){
260 return cmp_simple(s,x,y,ref_index,src_index, cmp_func, chroma_cmp_func);
262 && subx==0 && suby==0){
263 return cmp_fpel_internal(s,x,y,size,h,ref_index,src_index, cmp_func, chroma_cmp_func,flags);
265 return cmp_internal(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, flags);
270 const int size,
const int h,
int ref_index,
int src_index,
273 return cmp_direct_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0);
275 return cmp_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 0, flags&
FLAG_CHROMA);
280 const int size,
const int h,
int ref_index,
int src_index,
283 return cmp_direct_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 1);
285 return cmp_inline(s,x,y,subx,suby,size,h,ref_index,src_index, cmp_func, chroma_cmp_func, 1, flags&
FLAG_CHROMA);
309 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");
315 if(cache_size < 2*dia_size && !c->
stride){
378 int *mx_ptr,
int *my_ptr)
380 *mx_ptr = 16 * s->
mb_x;
381 *my_ptr = 16 * s->
mb_y;
384 #define Z_THRESHOLD 256
386 #define CHECK_SAD_HALF_MV(suffix, x, y) \
388 d= s->dsp.pix_abs[size][(x?1:0)+(y?2:0)](NULL, pix, ptr+((x)>>1), stride, h);\
389 d += (mv_penalty[pen_x + x] + mv_penalty[pen_y + y])*penalty_factor;\
390 COPY3_IF_LT(dminh, d, dx, x, dy, y)\
394 int *mx_ptr,
int *my_ptr,
int dmin,
395 int src_index,
int ref_index,
416 pix = c->
src[src_index][0];
420 ptr = c->
ref[ref_index][0] + (my *
stride) + mx;
424 if (mx > xmin && mx < xmax &&
425 my > ymin && my < ymax) {
430 const int l= score_map[(index- 1 )&(
ME_MAP_SIZE-1)];
543 c->
xmin = (x > 15) ? - 15 : 0;
544 c->
ymin = (y > 15) ? - 15 : 0;
564 c->
ref[1][0] = c->
ref[0][0] + 8;
566 c->
ref[3][0] = c->
ref[2][0] + 8;
567 c->
src[1][0] = c->
src[0][0] + 8;
569 c->
src[3][0] = c->
src[2][0] + 8;
579 int dmin_sum=0, mx4_sum=0, my4_sum=0;
586 for(block=0; block<4; block++){
588 int pred_x4, pred_y4;
590 static const int off[4]= {2, 1, 1, -1};
628 const int offset= ((block&1) + (block>>1)*
stride)*8;
632 dxy = ((my4 & 3) << 2) | (mx4 & 3);
640 dxy = ((my4 & 1) << 1) | (mx4 & 1);
647 dmin_sum+= (mv_penalty[mx4-pred_x4] + mv_penalty[my4-pred_y4])*c->
mb_penalty_factor;
662 if(mx4 != mx || my4 != my) same=0;
679 dxy = ((my & 1) << 1) | (mx & 1);
722 int16_t (*
mv_tables[2][2])[2], uint8_t *field_select_tables[2],
int mx,
int my,
int user_field_select)
734 const int xy= s->
mb_x + s->
mb_y*mot_stride;
742 for(block=0; block<2; block++){
744 int best_dmin= INT_MAX;
747 for(field_select=0; field_select<2; field_select++){
748 int dmin, mx_i, my_i;
751 if(user_field_select){
752 assert(field_select==0 || field_select==1);
753 assert(field_select_tables[block][xy]==0 || field_select_tables[block][xy]==1);
754 if(field_select_tables[block][xy] != field_select)
758 P_LEFT[0] = mv_table[xy - 1][0];
759 P_LEFT[1] = mv_table[xy - 1][1];
766 P_TOP[0] = mv_table[xy - mot_stride][0];
767 P_TOP[1] = mv_table[xy - mot_stride][1];
768 P_TOPRIGHT[0] = mv_table[xy - mot_stride + 1][0];
769 P_TOPRIGHT[1] = mv_table[xy - mot_stride + 1][1];
781 dmin =
epzs_motion_search2(s, &mx_i, &my_i, P, block, field_select+ref_index, mv_table, (1<<16)>>1);
783 dmin= c->
sub_motion_search(s, &mx_i, &my_i, dmin, block, field_select+ref_index, size, h);
785 mv_table[xy][0]= mx_i;
786 mv_table[xy][1]= my_i;
792 uint8_t *ref= c->
ref[field_select+ref_index][0] + (mx_i>>1) + (my_i>>1)*
stride;
793 dxy = ((my_i & 1) << 1) | (mx_i & 1);
805 dmin += field_select !=
block;
807 if(dmin < best_dmin){
809 best_field= field_select;
815 if(mv_table[xy][0] != mx) same=0;
816 if(mv_table[xy][1]&1) same=0;
817 if(mv_table[xy][1]*2 != my) same=0;
818 if(best_field != block) same=0;
821 field_select_tables[
block][xy]= best_field;
822 dmin_sum += best_dmin;
844 int ymax= s->
me.
ymax>>interlaced;
845 int ymin= s->
me.
ymin>>interlaced;
849 if(mv[1] < ymin) mv[1] = ymin;
850 if(mv[1] > ymax) mv[1] = ymax;
861 int mask= (1<<shift)-1;
891 int field_select0= p->
f.
ref_index[0][4*mb_xy ];
892 int field_select1= p->
f.
ref_index[0][4*mb_xy+2];
893 assert(field_select0==0 ||field_select0==1);
894 assert(field_select1==0 ||field_select1==1);
913 d =
cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select0, 0, cmpf, chroma_cmpf, flags);
916 d+=
cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select1, 1, cmpf, chroma_cmpf, flags);
919 int field_select0 = p->
f.
ref_index[1][4 * mb_xy ];
920 int field_select1 = p->
f.
ref_index[1][4 * mb_xy + 2];
921 assert(field_select0==0 ||field_select0==1);
922 assert(field_select1==0 ||field_select1==1);
937 d =
cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select0+2, 0, cmpf, chroma_cmpf, flags);
940 d+=
cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select1+2, 1, cmpf, chroma_cmpf, flags);
945 }
else if(
IS_8X8(mb_type)){
951 chroma_cmpf= s->
dsp.
sse[1];
957 d+=
cmp(s, x>>shift, y>>shift, x&mask, y&mask, 1, 8, i, i, cmpf, chroma_cmpf, flags);
975 d =
cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 16, 0, 0, cmpf, chroma_cmpf, flags);
982 d =
cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 16, 2, 0, cmpf, chroma_cmpf, flags);
994 int sum, mx, my, dmin;
1123 if (vard*2 + 200*256 > varc)
1125 if (varc*2 + 200*256 > vard || s->
qscale > 24){
1137 && !c->
skip && varc>50<<8 && vard>10<<8){
1158 && !c->
skip && varc>50<<8 && vard>10<<8){
1179 intra_score= varc - 500;
1181 unsigned mean = (sum+128)>>8;
1184 for(i=0; i<16; i++){
1195 if(intra_score < dmin){
1265 int mb_x,
int mb_y, int16_t (*mv_table)[2],
int ref_index,
int f_code)
1272 const int mot_xy = mb_y*mot_stride + mb_x;
1294 P_LEFT[0] = mv_table[mot_xy - 1][0];
1295 P_LEFT[1] = mv_table[mot_xy - 1][1];
1301 P_TOP[0] = mv_table[mot_xy - mot_stride ][0];
1302 P_TOP[1] = mv_table[mot_xy - mot_stride ][1];
1303 P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1 ][0];
1304 P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1 ][1];
1334 mv_table[mot_xy][0]= mx;
1335 mv_table[mot_xy][1]= my;
1341 int motion_fx,
int motion_fy,
1342 int motion_bx,
int motion_by,
1343 int pred_fx,
int pred_fy,
1344 int pred_bx,
int pred_by,
1359 uint8_t **src_data= c->
src[0];
1360 uint8_t **ref_data= c->
ref[0];
1361 uint8_t **ref2_data= c->
ref[2];
1364 dxy = ((motion_fy & 3) << 2) | (motion_fx & 3);
1365 src_x = motion_fx >> 2;
1366 src_y = motion_fy >> 2;
1368 ptr = ref_data[0] + (src_y *
stride) + src_x;
1371 dxy = ((motion_by & 3) << 2) | (motion_bx & 3);
1372 src_x = motion_bx >> 2;
1373 src_y = motion_by >> 2;
1375 ptr = ref2_data[0] + (src_y *
stride) + src_x;
1378 dxy = ((motion_fy & 1) << 1) | (motion_fx & 1);
1379 src_x = motion_fx >> 1;
1380 src_y = motion_fy >> 1;
1382 ptr = ref_data[0] + (src_y *
stride) + src_x;
1385 dxy = ((motion_by & 1) << 1) | (motion_bx & 1);
1386 src_x = motion_bx >> 1;
1387 src_y = motion_by >> 1;
1389 ptr = ref2_data[0] + (src_y *
stride) + src_x;
1393 fbmin = (mv_penalty_f[motion_fx-pred_fx] + mv_penalty_f[motion_fy-pred_fy])*c->
mb_penalty_factor
1394 +(mv_penalty_b[motion_bx-pred_bx] + mv_penalty_b[motion_by-pred_by])*c->
mb_penalty_factor
1409 const int xy = mb_y *mot_stride + mb_x;
1421 const int shift= 1+qpel;
1422 const int xmin= c->
xmin<<shift;
1423 const int ymin= c->
ymin<<shift;
1424 const int xmax= c->
xmax<<shift;
1425 const int ymax= c->
ymax<<shift;
1426 #define HASH(fx,fy,bx,by) ((fx)+17*(fy)+63*(bx)+117*(by))
1427 #define HASH8(fx,fy,bx,by) ((uint8_t)HASH(fx,fy,bx,by))
1428 int hashidx=
HASH(motion_fx,motion_fy, motion_bx, motion_by);
1431 memset(map,0,
sizeof(map));
1432 map[hashidx&255] = 1;
1435 motion_bx, motion_by,
1442 static const uint8_t limittab[5]={0,8,32,64,80};
1444 static const int8_t vect[][4]={
1445 { 0, 0, 0, 1}, { 0, 0, 0,-1}, { 0, 0, 1, 0}, { 0, 0,-1, 0}, { 0, 1, 0, 0}, { 0,-1, 0, 0}, { 1, 0, 0, 0}, {-1, 0, 0, 0},
1447 { 0, 0, 1, 1}, { 0, 0,-1,-1}, { 0, 1, 1, 0}, { 0,-1,-1, 0}, { 1, 1, 0, 0}, {-1,-1, 0, 0}, { 1, 0, 0, 1}, {-1, 0, 0,-1},
1448 { 0, 1, 0, 1}, { 0,-1, 0,-1}, { 1, 0, 1, 0}, {-1, 0,-1, 0},
1449 { 0, 0,-1, 1}, { 0, 0, 1,-1}, { 0,-1, 1, 0}, { 0, 1,-1, 0}, {-1, 1, 0, 0}, { 1,-1, 0, 0}, { 1, 0, 0,-1}, {-1, 0, 0, 1},
1450 { 0,-1, 0, 1}, { 0, 1, 0,-1}, {-1, 0, 1, 0}, { 1, 0,-1, 0},
1452 { 0, 1, 1, 1}, { 0,-1,-1,-1}, { 1, 1, 1, 0}, {-1,-1,-1, 0}, { 1, 1, 0, 1}, {-1,-1, 0,-1}, { 1, 0, 1, 1}, {-1, 0,-1,-1},
1453 { 0,-1, 1, 1}, { 0, 1,-1,-1}, {-1, 1, 1, 0}, { 1,-1,-1, 0}, { 1, 1, 0,-1}, {-1,-1, 0, 1}, { 1, 0,-1, 1}, {-1, 0, 1,-1},
1454 { 0, 1,-1, 1}, { 0,-1, 1,-1}, { 1,-1, 1, 0}, {-1, 1,-1, 0}, {-1, 1, 0, 1}, { 1,-1, 0,-1}, { 1, 0, 1,-1}, {-1, 0,-1, 1},
1455 { 0, 1, 1,-1}, { 0,-1,-1, 1}, { 1, 1,-1, 0}, {-1,-1, 1, 0}, { 1,-1, 0, 1}, {-1, 1, 0,-1}, {-1, 0, 1, 1}, { 1, 0,-1,-1},
1457 { 1, 1, 1, 1}, {-1,-1,-1,-1},
1458 { 1, 1, 1,-1}, {-1,-1,-1, 1}, { 1, 1,-1, 1}, {-1,-1, 1,-1}, { 1,-1, 1, 1}, {-1, 1,-1,-1}, {-1, 1, 1, 1}, { 1,-1,-1,-1},
1459 { 1, 1,-1,-1}, {-1,-1, 1, 1}, { 1,-1,-1, 1}, {-1, 1, 1,-1}, { 1,-1, 1,-1}, {-1, 1,-1, 1},
1461 static const uint8_t
hash[]={
1462 HASH8( 0, 0, 0, 1),
HASH8( 0, 0, 0,-1),
HASH8( 0, 0, 1, 0),
HASH8( 0, 0,-1, 0),
HASH8( 0, 1, 0, 0),
HASH8( 0,-1, 0, 0),
HASH8( 1, 0, 0, 0),
HASH8(-1, 0, 0, 0),
1464 HASH8( 0, 0, 1, 1),
HASH8( 0, 0,-1,-1),
HASH8( 0, 1, 1, 0),
HASH8( 0,-1,-1, 0),
HASH8( 1, 1, 0, 0),
HASH8(-1,-1, 0, 0),
HASH8( 1, 0, 0, 1),
HASH8(-1, 0, 0,-1),
1465 HASH8( 0, 1, 0, 1),
HASH8( 0,-1, 0,-1),
HASH8( 1, 0, 1, 0),
HASH8(-1, 0,-1, 0),
1466 HASH8( 0, 0,-1, 1),
HASH8( 0, 0, 1,-1),
HASH8( 0,-1, 1, 0),
HASH8( 0, 1,-1, 0),
HASH8(-1, 1, 0, 0),
HASH8( 1,-1, 0, 0),
HASH8( 1, 0, 0,-1),
HASH8(-1, 0, 0, 1),
1467 HASH8( 0,-1, 0, 1),
HASH8( 0, 1, 0,-1),
HASH8(-1, 0, 1, 0),
HASH8( 1, 0,-1, 0),
1469 HASH8( 0, 1, 1, 1),
HASH8( 0,-1,-1,-1),
HASH8( 1, 1, 1, 0),
HASH8(-1,-1,-1, 0),
HASH8( 1, 1, 0, 1),
HASH8(-1,-1, 0,-1),
HASH8( 1, 0, 1, 1),
HASH8(-1, 0,-1,-1),
1470 HASH8( 0,-1, 1, 1),
HASH8( 0, 1,-1,-1),
HASH8(-1, 1, 1, 0),
HASH8( 1,-1,-1, 0),
HASH8( 1, 1, 0,-1),
HASH8(-1,-1, 0, 1),
HASH8( 1, 0,-1, 1),
HASH8(-1, 0, 1,-1),
1471 HASH8( 0, 1,-1, 1),
HASH8( 0,-1, 1,-1),
HASH8( 1,-1, 1, 0),
HASH8(-1, 1,-1, 0),
HASH8(-1, 1, 0, 1),
HASH8( 1,-1, 0,-1),
HASH8( 1, 0, 1,-1),
HASH8(-1, 0,-1, 1),
1472 HASH8( 0, 1, 1,-1),
HASH8( 0,-1,-1, 1),
HASH8( 1, 1,-1, 0),
HASH8(-1,-1, 1, 0),
HASH8( 1,-1, 0, 1),
HASH8(-1, 1, 0,-1),
HASH8(-1, 0, 1, 1),
HASH8( 1, 0,-1,-1),
1475 HASH8( 1, 1, 1,-1),
HASH8(-1,-1,-1, 1),
HASH8( 1, 1,-1, 1),
HASH8(-1,-1, 1,-1),
HASH8( 1,-1, 1, 1),
HASH8(-1, 1,-1,-1),
HASH8(-1, 1, 1, 1),
HASH8( 1,-1,-1,-1),
1476 HASH8( 1, 1,-1,-1),
HASH8(-1,-1, 1, 1),
HASH8( 1,-1,-1, 1),
HASH8(-1, 1, 1,-1),
HASH8( 1,-1, 1,-1),
HASH8(-1, 1,-1, 1),
1479 #define CHECK_BIDIR(fx,fy,bx,by)\
1480 if( !map[(hashidx+HASH(fx,fy,bx,by))&255]\
1481 &&(fx<=0 || motion_fx+fx<=xmax) && (fy<=0 || motion_fy+fy<=ymax) && (bx<=0 || motion_bx+bx<=xmax) && (by<=0 || motion_by+by<=ymax)\
1482 &&(fx>=0 || motion_fx+fx>=xmin) && (fy>=0 || motion_fy+fy>=ymin) && (bx>=0 || motion_bx+bx>=xmin) && (by>=0 || motion_by+by>=ymin)){\
1484 map[(hashidx+HASH(fx,fy,bx,by))&255] = 1;\
1485 score= check_bidir_mv(s, motion_fx+fx, motion_fy+fy, motion_bx+bx, motion_by+by, pred_fx, pred_fy, pred_bx, pred_by, 0, 16);\
1487 hashidx += HASH(fx,fy,bx,by);\
1496 #define CHECK_BIDIR2(a,b,c,d)\
1497 CHECK_BIDIR(a,b,c,d)\
1498 CHECK_BIDIR(-(a),-(b),-(c),-(d))
1510 for(i=8; i<limit; i++){
1511 int fx= motion_fx+vect[i][0];
1512 int fy= motion_fy+vect[i][1];
1513 int bx= motion_bx+vect[i][2];
1514 int by= motion_by+vect[i][3];
1516 int a= (xmax -
FFMAX(fx,bx))|(
FFMIN(fx,bx) - xmin);
1517 int b= (ymax -
FFMAX(fy,by))|(
FFMIN(fy,by) - ymin);
1519 map[(hashidx+hash[i])&255] = 1;
1521 if(!map[(hashidx+hash[i])&255]){
1523 map[(hashidx+hash[i])&255] = 1;
1524 score=
check_bidir_mv(s, fx, fy, bx, by, pred_fx, pred_fy, pred_bx, pred_by, 0, 16);
1537 borderdist=
FFMIN(a,b);
1558 const int mot_xy = mb_y*mot_stride + mb_x;
1561 const int time_pp= s->
pp_time;
1562 const int time_pb= s->
pb_time;
1563 int mx, my, xmin, xmax, ymin, ymax;
1567 ymin= xmin=(-32)>>shift;
1568 ymax= xmax= 31>>shift;
1592 xmin=
FFMAX(xmin, - 16 - min);
1599 ymin=
FFMAX(ymin, - 16 - min);
1604 assert(xmax <= 15 && ymax <= 15 && xmin >= -16 && ymin >= -16);
1606 if(xmax < 0 || xmin >0 || ymax < 0 || ymin > 0){
1610 return 256*256*256*64;
1622 P_LEFT[0] = av_clip(mv_table[mot_xy - 1][0], xmin<<shift, xmax<<shift);
1623 P_LEFT[1] = av_clip(mv_table[mot_xy - 1][1], ymin<<shift, ymax<<shift);
1627 P_TOP[0] = av_clip(mv_table[mot_xy - mot_stride ][0], xmin<<shift, xmax<<shift);
1628 P_TOP[1] = av_clip(mv_table[mot_xy - mot_stride ][1], ymin<<shift, ymax<<shift);
1629 P_TOPRIGHT[0] = av_clip(mv_table[mot_xy - mot_stride + 1 ][0], xmin<<shift, xmax<<shift);
1630 P_TOPRIGHT[1] = av_clip(mv_table[mot_xy - mot_stride + 1 ][1], ymin<<shift, ymax<<shift);
1647 mv_table[mot_xy][0]= mx;
1648 mv_table[mot_xy][1]= my;
1660 int fmin, bmin, dmin, fbmin, bimin, fimin;
1662 const int xy = mb_y*s->
mb_stride + mb_x;
1673 score= ((unsigned)(score*score + 128*256))>>16;
1760 fimin= bimin= INT_MAX;
1787 score= ((unsigned)(score*score + 128*256))>>16;
1798 if(fimin < INT_MAX && bimin < INT_MAX){
1818 int best_score=-10000000;
1821 range=
FFMIN(range, 16);
1823 range=
FFMIN(range, 256);
1825 for(i=0; i<8; i++) score[i]= s->
mb_num*(8-i);
1832 int mx= mv_table[xy][0];
1833 int my= mv_table[xy][1];
1838 if(mx >= range || mx < -range ||
1839 my >= range || my < -range)
1842 for(j=0; j<fcode && j<8; j++){
1852 if(score[i] > best_score){
1853 best_score= score[i];
1873 const int f_code= s->
f_code;
1879 assert(range <= 16 || !s->msmpeg4_version);
1897 for(block=0; block<4; block++){
1898 int off= (block& 1) + (block>>1)*
wrap;
1902 if( mx >=range || mx <-range
1903 || my >=range || my <-range){
1904 s->
mb_type[i] &= ~CANDIDATE_MB_TYPE_INTER4V;
1922 int16_t (*mv_table)[2],
int f_code,
int type,
int truncate)
1925 int y, h_range, v_range;
1933 v_range= field_select_table ? range>>1 : range;
1941 if(field_select_table==
NULL || field_select_table[xy] == field_select){
1942 if( mv_table[xy][0] >=h_range || mv_table[xy][0] <-h_range
1943 || mv_table[xy][1] >=v_range || mv_table[xy][1] <-v_range){
1946 if (mv_table[xy][0] > h_range-1) mv_table[xy][0]= h_range-1;
1947 else if(mv_table[xy][0] < -h_range ) mv_table[xy][0]= -h_range;
1948 if (mv_table[xy][1] > v_range-1) mv_table[xy][1]= v_range-1;
1949 else if(mv_table[xy][1] < -v_range ) mv_table[xy][1]= -v_range;
uint8_t * scratchpad
data area for the ME algo, so that the ME does not need to malloc/free
static int minima_cmp(const void *a, const void *b)
static int cmp_qpel(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
static unsigned update_map_generation(MotionEstContext *c)
op_pixels_func put_pixels_tab[4][4]
Halfpel motion compensation with rounding (a+b+1)>>1.
void ff_estimate_b_frame_motion(MpegEncContext *s, int mb_x, int mb_y)
#define CODEC_FLAG_MV0
Always try a MB with MV=<0,0>.
static int epzs_motion_search2(MpegEncContext *s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, int16_t(*last_mv)[2], int ref_mv_scale)
static int check_bidir_mv(MpegEncContext *s, int motion_fx, int motion_fy, int motion_bx, int motion_by, int pred_fx, int pred_fy, int pred_bx, int pred_by, int size, int h)
int skip
set if ME is skipped for the current MB
int16_t(* p_mv_table)[2]
MV table (1MV per MB) p-frame encoding.
static void get_limits(MpegEncContext *s, int x, int y)
get fullpel ME search limits.
uint8_t * fcode_tab
smallest fcode needed for each MV
void ff_estimate_p_frame_motion(MpegEncContext *s, int mb_x, int mb_y)
uint8_t * mb_mean
Table for MB luminance.
static void init_mv4_ref(MotionEstContext *c)
#define CANDIDATE_MB_TYPE_BACKWARD_I
uint16_t * mb_var
Table for MB variances.
#define CANDIDATE_MB_TYPE_BIDIR
uint8_t * current_mv_penalty
static int hash(int head, const int add)
Hash function adding character.
#define CANDIDATE_MB_TYPE_INTRA
int msmpeg4_version
0=not msmpeg4, 1=mp41, 2=mp42, 3=mp43/divx3 4=wmv1/7 5=wmv2/8
int(* me_cmp_func)(void *s, uint8_t *blk1, uint8_t *blk2, int line_size, int h)
static int ff_estimate_motion_b(MpegEncContext *s, int mb_x, int mb_y, int16_t(*mv_table)[2], int ref_index, int f_code)
static int cmp_simple(MpegEncContext *s, const int x, const int y, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func)
static void no_motion_search(MpegEncContext *s, int *mx_ptr, int *my_ptr)
int16_t(*[2][2] p_field_mv_table)[2]
MV table (2MV per MB) interlaced p-frame encoding.
static int bidir_refine(MpegEncContext *s, int mb_x, int mb_y)
int mb_num
number of MBs of a picture
int16_t(* b_back_mv_table)[2]
MV table (1MV per MB) backward mode b-frame encoding.
int(* pix_sum)(uint8_t *pix, int line_size)
static int cmp_internal(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
#define USES_LIST(a, list)
does this mb use listX, note does not work if subMBs
static av_const unsigned int ff_sqrt(unsigned int a)
op_pixels_func(* hpel_put)[4]
enum OutputFormat out_format
output format
int me_range
maximum motion estimation search range in subpel units If 0 then no limit.
int pre_dia_size
ME prepass diamond size & shape.
Motion estimation context.
qpel_mc_func(* qpel_put)[16]
me_cmp_func me_pre_cmp[6]
int no_rounding
apply no rounding to motion compensation (MPEG4, msmpeg4, ...) for b-frames rounding mode is always 0...
int me_cmp
motion estimation comparison function
Picture current_picture
copy of the current picture structure.
#define CODEC_FLAG_4MV
4 MV per MB allowed / advanced prediction for H.263.
op_pixels_func avg_pixels_tab[4][4]
Halfpel motion compensation with rounding (a+b+1)>>1.
enhanced predictive zonal search
int16_t(* b_bidir_forw_mv_table)[2]
MV table (1MV per MB) bidir mode b-frame encoding.
uint8_t(* mv_penalty)[MAX_MV *2+1]
amount of bits needed to encode a MV
static int get_flags(MotionEstContext *c, int direct, int chroma)
void ff_set_cmp(DSPContext *c, me_cmp_func *cmp, int type)
int mb_threshold
Macroblock threshold below which the user specified macroblock types will be used.
uint16_t pp_time
time distance between the last 2 p,s,i frames
op_pixels_func(* hpel_avg)[4]
int ff_epzs_motion_search(MpegEncContext *s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, int16_t(*last_mv)[2], int ref_mv_scale, int size, int h)
int mb_height
number of MBs horizontally & vertically
#define CHECK_BIDIR2(a, b, c, d)
qpel_mc_func put_qpel_pixels_tab[2][16]
#define CANDIDATE_MB_TYPE_FORWARD
preferred ID for MPEG-1/2 video decoding
#define CANDIDATE_MB_TYPE_DIRECT
int ff_get_mb_score(MpegEncContext *s, int mx, int my, int src_index, int ref_index, int size, int h, int add_rate)
static int ff_h263_round_chroma(int x)
static const uint16_t mask[17]
static int epzs_motion_search4(MpegEncContext *s, int *mx_ptr, int *my_ptr, int P[10][2], int src_index, int ref_index, int16_t(*last_mv)[2], int ref_mv_scale)
static int no_sub_motion_search(MpegEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
qpel_mc_func avg_qpel_pixels_tab[2][16]
int me_sub_cmp
subpixel motion estimation comparison function
static uint8_t fcode_tab[MAX_MV *2+1]
Minimal fcode that a motion vector component would need.
int unrestricted_mv
mv can point outside of the coded picture
static void init_interlaced_ref(MpegEncContext *s, int ref_index)
#define CANDIDATE_MB_TYPE_INTER
void av_log(void *avcl, int level, const char *fmt,...)
int quarter_sample
1->qpel, 0->half pel ME/MC
uint16_t * mb_type
Table for candidate MB types for encoding.
op_pixels_func put_no_rnd_pixels_tab[4][4]
Halfpel motion compensation with no rounding (a+b)>>1.
uint8_t *[2][2] b_field_select_table
Motion estimation template.
int me_method
ME algorithm.
static int cmp_fpel_internal(MpegEncContext *s, const int x, const int y, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
Picture new_picture
copy of the source picture structure for encoding.
static int hpel_motion_search(MpegEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
#define av_builtin_constant_p(x)
Picture * current_picture_ptr
pointer to the current picture
#define CANDIDATE_MB_TYPE_INTER4V
#define FF_MB_DECISION_SIMPLE
uses mb_cmp
static int interlaced_search(MpegEncContext *s, int ref_index, int16_t(*mv_tables[2][2])[2], uint8_t *field_select_tables[2], int mx, int my, int user_field_select)
static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
compares a block (either a full macroblock or a partition thereof) against a proposed motion-compensa...
int mb_decision
macroblock decision mode
#define CANDIDATE_MB_TYPE_BACKWARD
#define CANDIDATE_MB_TYPE_SKIPPED
int block_index[6]
index to current MB in block based arrays with edges
static int qpel_motion_search(MpegEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
static void clip_input_mv(MpegEncContext *s, int16_t *mv, int interlaced)
int penalty_factor
an estimate of the bits required to code a given mv value, e.g.
#define HASH8(fx, fy, bx, by)
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 first_slice_line
used in mpeg4 too to handle resync markers
static int check_input_motion(MpegEncContext *s, int mb_x, int mb_y, int p_type)
uint16_t * mc_mb_var
Table for motion compensated MB variances.
unsigned int lambda2
(lambda*lambda) >> FF_LAMBDA_SHIFT
int me_threshold
Motion estimation threshold below which no motion estimation is performed, but instead the user speci...
#define CHECK_SAD_HALF_MV(suffix, x, y)
static int get_penalty_factor(int lambda, int lambda2, int type)
int height
picture size. must be a multiple of 16
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int16_t(*[2] motion_val)[2]
motion vector table
static int direct_search(MpegEncContext *s, int mb_x, int mb_y)
#define CODEC_FLAG_QPEL
Use qpel MC.
void ff_fix_long_p_mvs(MpegEncContext *s)
int16_t(*[2][2][2] b_field_mv_table)[2]
MV table (4MV per MB) interlaced b-frame encoding.
#define FF_COMPLIANCE_NORMAL
static av_always_inline int cmp_direct_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel)
int8_t * ref_index[2]
motion reference frame index the order in which these are stored can depend on the codec...
DSPContext dsp
pointers for accelerated dsp functions
int(* pix_norm1)(uint8_t *pix, int line_size)
int f_code
forward MV resolution
int ff_pre_estimate_p_frame_motion(MpegEncContext *s, int mb_x, int mb_y)
#define CANDIDATE_MB_TYPE_BIDIR_I
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
static void set_p_mv_tables(MpegEncContext *s, int mx, int my, int mv4)
#define CANDIDATE_MB_TYPE_FORWARD_I
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)
int16_t(* b_bidir_back_mv_table)[2]
MV table (1MV per MB) bidir mode b-frame encoding.
int ff_init_me(MpegEncContext *s)
uint8_t *[2] p_field_select_table
int16_t(* b_direct_mv_table)[2]
MV table (1MV per MB) direct mode b-frame encoding.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
qpel_mc_func(* qpel_avg)[16]
#define CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
int16_t(* b_forw_mv_table)[2]
MV table (1MV per MB) forward mode b-frame encoding.
int b8_stride
2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
struct AVCodecContext * avctx
static uint8_t mv_penalty[MAX_FCODE+1][MAX_MV *2+1]
Table of number of bits a motion vector component needs.
int mb_cmp
macroblock comparison function (not supported yet)
int direct_basis_mv[4][2]
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
no search, that is use 0,0 vector whenever one is needed
Picture last_picture
copy of the previous picture structure.
int co_located_mv[4][2]
mv from last P-frame for direct mode ME
uint32_t * map
map to avoid duplicate evaluations
static int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
#define CANDIDATE_MB_TYPE_DIRECT0
int dia_size
ME diamond size & shape.
static void init_ref(MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index)
static int cmp_hpel(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
int ff_get_best_fcode(MpegEncContext *s, int16_t(*mv_table)[2], int type)
static int zero_cmp(void *s, uint8_t *a, uint8_t *b, int stride, int h)
Picture next_picture
copy of the next picture structure.
int linesize
line size, in bytes, may be different from width
uint8_t * mbskip_table
mbskip_table[mb]>=1 if MB didn't change stride= mb_width = (width+15)>>4
void ff_fix_long_mvs(MpegEncContext *s, uint8_t *field_select_table, int field_select, int16_t(*mv_table)[2], int f_code, int type, int truncate)
int flags
AVCodecContext.flags (HQ, MV4, ...)
qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16]
static av_always_inline int cmp_inline(MpegEncContext *s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, int qpel, int chroma)
me_cmp_func me_sub_cmp[6]
#define MV_TYPE_8X8
4 vectors (h263, mpeg4 4MV)
int b_code
backward MV resolution for B Frames (mpeg4)
int me_pre_cmp
motion estimation prepass comparison function
int uvlinesize
line size, for chroma in bytes, may be different from width
int(* sub_motion_search)(struct MpegEncContext *s, int *mx_ptr, int *my_ptr, int dmin, int src_index, int ref_index, int size, int h)
int strict_std_compliance
strictly follow the standard (MPEG4, ...).
static void zero_hpel(uint8_t *a, const uint8_t *b, int stride, int h)
#define CANDIDATE_MB_TYPE_INTER_I
unsigned int lambda
lagrange multipler used in rate distortion
#define HASH(fx, fy, bx, by)
uint16_t pb_time
time distance between the last b and p,s,i frame