summaryrefslogtreecommitdiff
path: root/src/libffmpeg/libavcodec/motion_est_template.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libffmpeg/libavcodec/motion_est_template.c')
-rw-r--r--src/libffmpeg/libavcodec/motion_est_template.c88
1 files changed, 54 insertions, 34 deletions
diff --git a/src/libffmpeg/libavcodec/motion_est_template.c b/src/libffmpeg/libavcodec/motion_est_template.c
index 8cfb24955..d8101ec33 100644
--- a/src/libffmpeg/libavcodec/motion_est_template.c
+++ b/src/libffmpeg/libavcodec/motion_est_template.c
@@ -25,11 +25,11 @@
//lets hope gcc will remove the unused vars ...(gcc 3.2.2 seems to do it ...)
#define LOAD_COMMON\
- uint32_t * const score_map= c->score_map;\
- const int xmin= c->xmin;\
- const int ymin= c->ymin;\
- const int xmax= c->xmax;\
- const int ymax= c->ymax;\
+ uint32_t attribute_unused * const score_map= c->score_map;\
+ const int attribute_unused xmin= c->xmin;\
+ const int attribute_unused ymin= c->ymin;\
+ const int attribute_unused xmax= c->xmax;\
+ const int attribute_unused ymax= c->ymax;\
uint8_t *mv_penalty= c->current_mv_penalty;\
const int pred_x= c->pred_x;\
const int pred_y= c->pred_y;\
@@ -221,13 +221,21 @@ static int hpel_motion_search(MpegEncContext * s,
}
#endif
-static int inline get_mb_score(MpegEncContext * s, int mx, int my, int src_index,
- int ref_index)
+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)
+{
+ (*mx_ptr)<<=1;
+ (*my_ptr)<<=1;
+ return dmin;
+}
+
+int inline ff_get_mb_score(MpegEncContext * s, int mx, int my, int src_index,
+ int ref_index, int size, int h, int add_rate)
{
// const int check_luma= s->dsp.me_sub_cmp != s->dsp.mb_cmp;
MotionEstContext * const c= &s->me;
- const int size= 0;
- const int h= 16;
const int penalty_factor= c->mb_penalty_factor;
const int flags= c->mb_flags;
const int qpel= flags & FLAG_QPEL;
@@ -242,12 +250,12 @@ static int inline get_mb_score(MpegEncContext * s, int mx, int my, int src_index
cmp_sub= s->dsp.mb_cmp[size];
chroma_cmp_sub= s->dsp.mb_cmp[size+1];
- assert(!c->skip);
- assert(c->avctx->me_sub_cmp != c->avctx->mb_cmp);
+// assert(!c->skip);
+// assert(c->avctx->me_sub_cmp != c->avctx->mb_cmp);
d= cmp(s, mx>>(qpel+1), my>>(qpel+1), mx&mask, my&mask, size, h, ref_index, src_index, cmp_sub, chroma_cmp_sub, flags);
//FIXME check cbp before adding penalty for (0,0) vector
- if(mx || my || size>0)
+ if(add_rate && (mx || my || size>0))
d += (mv_penalty[mx - pred_x] + mv_penalty[my - pred_y])*penalty_factor;
return d;
@@ -323,15 +331,16 @@ static int qpel_motion_search(MpegEncContext * s,
for(ny= -3; ny <= 3; ny++){
for(nx= -3; nx <= 3; nx++){
- const int t2= nx*nx*(tr + tl - 2*t) + 4*nx*(tr-tl) + 32*t;
- const int c2= nx*nx*( r + l - 2*c) + 4*nx*( r- l) + 32*c;
- const int b2= nx*nx*(br + bl - 2*b) + 4*nx*(br-bl) + 32*b;
- int score= ny*ny*(b2 + t2 - 2*c2) + 4*ny*(b2 - t2) + 32*c2;
+ //FIXME this could overflow (unlikely though)
+ const int64_t t2= nx*nx*(tr + tl - 2*t) + 4*nx*(tr-tl) + 32*t;
+ const int64_t c2= nx*nx*( r + l - 2*c) + 4*nx*( r- l) + 32*c;
+ const int64_t b2= nx*nx*(br + bl - 2*b) + 4*nx*(br-bl) + 32*b;
+ int score= (ny*ny*(b2 + t2 - 2*c2) + 4*ny*(b2 - t2) + 32*c2 + 512)>>10;
int i;
if((nx&3)==0 && (ny&3)==0) continue;
- score += 1024*(mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
+ score += (mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
// if(nx&1) score-=1024*c->penalty_factor;
// if(ny&1) score-=1024*c->penalty_factor;
@@ -350,6 +359,7 @@ static int qpel_motion_search(MpegEncContext * s,
}
}else{
int tl;
+ //FIXME this could overflow (unlikely though)
const int cx = 4*(r - l);
const int cx2= r + l - 2*c;
const int cy = 4*(b - t);
@@ -372,6 +382,7 @@ static int qpel_motion_search(MpegEncContext * s,
for(ny= -3; ny <= 3; ny++){
for(nx= -3; nx <= 3; nx++){
+ //FIXME this could overflow (unlikely though)
int score= ny*nx*cxy + nx*nx*cx2 + ny*ny*cy2 + nx*cx + ny*cy + 32*c; //FIXME factor
int i;
@@ -487,6 +498,10 @@ static int qpel_motion_search(MpegEncContext * s,
{\
const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
+ assert((x) >= xmin);\
+ assert((x) <= xmax);\
+ assert((y) >= ymin);\
+ assert((y) <= ymax);\
/*printf("check_mv %d %d\n", x, y);*/\
if(map[index]!=key){\
d= cmp(s, x, y, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);\
@@ -670,7 +685,7 @@ if(256*256*256*64 % (stats[0]+1)==0){
}\
}
-#define MAX_SAB_SIZE 16
+#define MAX_SAB_SIZE ME_MAP_SIZE
static int sab_diamond_search(MpegEncContext * s, int *best, int dmin,
int src_index, int ref_index, int const penalty_factor,
int size, int h, int flags)
@@ -844,15 +859,13 @@ static always_inline int diamond_search(MpegEncContext * s, int *best, int dmin,
static always_inline int epzs_motion_search_internal(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 flags)
+ int ref_mv_scale, int flags, int size, int h)
{
MotionEstContext * const c= &s->me;
int best[2]={0, 0};
int d, dmin;
int map_generation;
- const int penalty_factor= c->penalty_factor;
- const int size=0;
- const int h=16;
+ int penalty_factor;
const int ref_mv_stride= s->mb_stride; //pass as arg FIXME
const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride; //add to last_mv beforepassing FIXME
me_cmp_func cmpf, chroma_cmpf;
@@ -860,11 +873,19 @@ static always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx
LOAD_COMMON
LOAD_COMMON2
- cmpf= s->dsp.me_cmp[size];
- chroma_cmpf= s->dsp.me_cmp[size+1];
+ if(c->pre_pass){
+ penalty_factor= c->pre_penalty_factor;
+ cmpf= s->dsp.me_pre_cmp[size];
+ chroma_cmpf= s->dsp.me_pre_cmp[size+1];
+ }else{
+ penalty_factor= c->penalty_factor;
+ cmpf= s->dsp.me_cmp[size];
+ chroma_cmpf= s->dsp.me_cmp[size+1];
+ }
map_generation= update_map_generation(c);
+ assert(cmpf);
dmin= cmp(s, 0, 0, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
map[0]= map_generation;
score_map[0]= dmin;
@@ -875,7 +896,7 @@ static always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx
CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
(last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
}else{
- if(dmin<256 && ( P_LEFT[0] |P_LEFT[1]
+ if(dmin<h*h && ( P_LEFT[0] |P_LEFT[1]
|P_TOP[0] |P_TOP[1]
|P_TOPRIGHT[0]|P_TOPRIGHT[1])==0){
*mx_ptr= 0;
@@ -884,7 +905,7 @@ static always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx
return dmin;
}
CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
- if(dmin>256*2){
+ if(dmin>h*h*2){
CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
(last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
CHECK_MV(P_LEFT[0] >>shift, P_LEFT[1] >>shift)
@@ -892,7 +913,7 @@ static always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx
CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
}
}
- if(dmin>256*4){
+ if(dmin>h*h*4){
if(c->pre_pass){
CHECK_CLIPED_MV((last_mv[ref_mv_xy-1][0]*ref_mv_scale + (1<<15))>>16,
(last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16)
@@ -941,19 +962,18 @@ static always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx
}
//this function is dedicated to the braindamaged gcc
-static inline int epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr,
+inline 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 ref_mv_scale, int size, int h)
{
MotionEstContext * const c= &s->me;
//FIXME convert other functions in the same way if faster
- switch(c->flags){
- case 0:
- return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, 0);
+ if(c->flags==0 && h==16 && size==0){
+ return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, 0, 0, 16);
// case FLAG_QPEL:
// return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, FLAG_QPEL);
- default:
- return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, c->flags);
+ }else{
+ return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, c->flags, size, h);
}
}