Commit cb668476 authored by Mans Rullgard's avatar Mans Rullgard

motion_est: make MotionExtContext.map_generation unsigned

The way this value is used, it should be an unsigned type.
While the numerical value has no meaning, unsigned wraparound
is relied upon.
Signed-off-by: 's avatarMans Rullgard <mans@mansr.com>
parent 4c7a232f
...@@ -52,7 +52,7 @@ static inline int sad_hpel_motion_search(MpegEncContext * s, ...@@ -52,7 +52,7 @@ static inline int sad_hpel_motion_search(MpegEncContext * s,
int src_index, int ref_index, int src_index, int ref_index,
int size, int h); int size, int h);
static inline int update_map_generation(MotionEstContext *c) static inline unsigned update_map_generation(MotionEstContext *c)
{ {
c->map_generation+= 1<<(ME_MAP_MV_BITS*2); c->map_generation+= 1<<(ME_MAP_MV_BITS*2);
if(c->map_generation==0){ if(c->map_generation==0){
......
...@@ -89,8 +89,8 @@ static int hpel_motion_search(MpegEncContext * s, ...@@ -89,8 +89,8 @@ static int hpel_motion_search(MpegEncContext * s,
const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
+ (mv_penalty[bx - pred_x] + mv_penalty[by+2 - pred_y])*c->penalty_factor; + (mv_penalty[bx - pred_x] + mv_penalty[by+2 - pred_y])*c->penalty_factor;
int key; unsigned key;
int map_generation= c->map_generation; unsigned map_generation= c->map_generation;
#ifndef NDEBUG #ifndef NDEBUG
uint32_t *map= c->map; uint32_t *map= c->map;
#endif #endif
...@@ -208,7 +208,7 @@ static int qpel_motion_search(MpegEncContext * s, ...@@ -208,7 +208,7 @@ static int qpel_motion_search(MpegEncContext * s,
const int mx = *mx_ptr; const int mx = *mx_ptr;
const int my = *my_ptr; const int my = *my_ptr;
const int penalty_factor= c->sub_penalty_factor; const int penalty_factor= c->sub_penalty_factor;
const int map_generation= c->map_generation; const unsigned map_generation = c->map_generation;
const int subpel_quality= c->avctx->me_subpel_quality; const int subpel_quality= c->avctx->me_subpel_quality;
uint32_t *map= c->map; uint32_t *map= c->map;
me_cmp_func cmpf, chroma_cmpf; me_cmp_func cmpf, chroma_cmpf;
...@@ -354,7 +354,7 @@ static int qpel_motion_search(MpegEncContext * s, ...@@ -354,7 +354,7 @@ static int qpel_motion_search(MpegEncContext * s,
#define CHECK_MV(x,y)\ #define CHECK_MV(x,y)\
{\ {\
const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\ const unsigned key = ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\ const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
assert((x) >= xmin);\ assert((x) >= xmin);\
assert((x) <= xmax);\ assert((x) <= xmax);\
...@@ -382,7 +382,7 @@ static int qpel_motion_search(MpegEncContext * s, ...@@ -382,7 +382,7 @@ static int qpel_motion_search(MpegEncContext * s,
#define CHECK_MV_DIR(x,y,new_dir)\ #define CHECK_MV_DIR(x,y,new_dir)\
{\ {\
const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\ const unsigned key = ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\ const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
/*printf("check_mv_dir %d %d %d\n", x, y, new_dir);*/\ /*printf("check_mv_dir %d %d %d\n", x, y, new_dir);*/\
if(map[index]!=key){\ if(map[index]!=key){\
...@@ -420,13 +420,13 @@ static av_always_inline int small_diamond_search(MpegEncContext * s, int *best, ...@@ -420,13 +420,13 @@ static av_always_inline int small_diamond_search(MpegEncContext * s, int *best,
int next_dir=-1; int next_dir=-1;
LOAD_COMMON LOAD_COMMON
LOAD_COMMON2 LOAD_COMMON2
int map_generation= c->map_generation; unsigned map_generation = c->map_generation;
cmpf= s->dsp.me_cmp[size]; cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1]; chroma_cmpf= s->dsp.me_cmp[size+1];
{ /* ensure that the best point is in the MAP as h/qpel refinement needs it */ { /* ensure that the best point is in the MAP as h/qpel refinement needs it */
const int key= (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation; const unsigned key = (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;
const int index= ((best[1]<<ME_MAP_SHIFT) + best[0])&(ME_MAP_SIZE-1); const int index= ((best[1]<<ME_MAP_SHIFT) + best[0])&(ME_MAP_SIZE-1);
if(map[index]!=key){ //this will be executed only very rarey if(map[index]!=key){ //this will be executed only very rarey
score_map[index]= cmp(s, best[0], best[1], 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags); score_map[index]= cmp(s, best[0], best[1], 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
...@@ -462,7 +462,7 @@ static int funny_diamond_search(MpegEncContext * s, int *best, int dmin, ...@@ -462,7 +462,7 @@ static int funny_diamond_search(MpegEncContext * s, int *best, int dmin,
int dia_size; int dia_size;
LOAD_COMMON LOAD_COMMON
LOAD_COMMON2 LOAD_COMMON2
int map_generation= c->map_generation; unsigned map_generation = c->map_generation;
cmpf= s->dsp.me_cmp[size]; cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1]; chroma_cmpf= s->dsp.me_cmp[size+1];
...@@ -503,7 +503,7 @@ static int hex_search(MpegEncContext * s, int *best, int dmin, ...@@ -503,7 +503,7 @@ static int hex_search(MpegEncContext * s, int *best, int dmin,
me_cmp_func cmpf, chroma_cmpf; me_cmp_func cmpf, chroma_cmpf;
LOAD_COMMON LOAD_COMMON
LOAD_COMMON2 LOAD_COMMON2
int map_generation= c->map_generation; unsigned map_generation = c->map_generation;
int x,y,d; int x,y,d;
const int dec= dia_size & (dia_size-1); const int dec= dia_size & (dia_size-1);
...@@ -537,7 +537,7 @@ static int l2s_dia_search(MpegEncContext * s, int *best, int dmin, ...@@ -537,7 +537,7 @@ static int l2s_dia_search(MpegEncContext * s, int *best, int dmin,
me_cmp_func cmpf, chroma_cmpf; me_cmp_func cmpf, chroma_cmpf;
LOAD_COMMON LOAD_COMMON
LOAD_COMMON2 LOAD_COMMON2
int map_generation= c->map_generation; unsigned map_generation = c->map_generation;
int x,y,i,d; int x,y,i,d;
int dia_size= c->dia_size&0xFF; int dia_size= c->dia_size&0xFF;
const int dec= dia_size & (dia_size-1); const int dec= dia_size & (dia_size-1);
...@@ -575,7 +575,7 @@ static int umh_search(MpegEncContext * s, int *best, int dmin, ...@@ -575,7 +575,7 @@ static int umh_search(MpegEncContext * s, int *best, int dmin,
me_cmp_func cmpf, chroma_cmpf; me_cmp_func cmpf, chroma_cmpf;
LOAD_COMMON LOAD_COMMON
LOAD_COMMON2 LOAD_COMMON2
int map_generation= c->map_generation; unsigned map_generation = c->map_generation;
int x,y,x2,y2, i, j, d; int x,y,x2,y2, i, j, d;
const int dia_size= c->dia_size&0xFE; const int dia_size= c->dia_size&0xFE;
static const int hex[16][2]={{-4,-2}, {-4,-1}, {-4, 0}, {-4, 1}, {-4, 2}, static const int hex[16][2]={{-4,-2}, {-4,-1}, {-4, 0}, {-4, 1}, {-4, 2},
...@@ -622,7 +622,7 @@ static int full_search(MpegEncContext * s, int *best, int dmin, ...@@ -622,7 +622,7 @@ static int full_search(MpegEncContext * s, int *best, int dmin,
me_cmp_func cmpf, chroma_cmpf; me_cmp_func cmpf, chroma_cmpf;
LOAD_COMMON LOAD_COMMON
LOAD_COMMON2 LOAD_COMMON2
int map_generation= c->map_generation; unsigned map_generation = c->map_generation;
int x,y, d; int x,y, d;
const int dia_size= c->dia_size&0xFF; const int dia_size= c->dia_size&0xFF;
...@@ -651,7 +651,7 @@ static int full_search(MpegEncContext * s, int *best, int dmin, ...@@ -651,7 +651,7 @@ static int full_search(MpegEncContext * s, int *best, int dmin,
#define SAB_CHECK_MV(ax,ay)\ #define SAB_CHECK_MV(ax,ay)\
{\ {\
const int key= ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\ const unsigned key = ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\ const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\
/*printf("sab check %d %d\n", ax, ay);*/\ /*printf("sab check %d %d\n", ax, ay);*/\
if(map[index]!=key){\ if(map[index]!=key){\
...@@ -690,7 +690,7 @@ static int sab_diamond_search(MpegEncContext * s, int *best, int dmin, ...@@ -690,7 +690,7 @@ static int sab_diamond_search(MpegEncContext * s, int *best, int dmin,
int i, j; int i, j;
LOAD_COMMON LOAD_COMMON
LOAD_COMMON2 LOAD_COMMON2
int map_generation= c->map_generation; unsigned map_generation = c->map_generation;
cmpf= s->dsp.me_cmp[size]; cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1]; chroma_cmpf= s->dsp.me_cmp[size+1];
...@@ -775,7 +775,7 @@ static int var_diamond_search(MpegEncContext * s, int *best, int dmin, ...@@ -775,7 +775,7 @@ static int var_diamond_search(MpegEncContext * s, int *best, int dmin,
int dia_size; int dia_size;
LOAD_COMMON LOAD_COMMON
LOAD_COMMON2 LOAD_COMMON2
int map_generation= c->map_generation; unsigned map_generation = c->map_generation;
cmpf= s->dsp.me_cmp[size]; cmpf= s->dsp.me_cmp[size];
chroma_cmpf= s->dsp.me_cmp[size+1]; chroma_cmpf= s->dsp.me_cmp[size+1];
...@@ -867,7 +867,7 @@ static av_always_inline int epzs_motion_search_internal(MpegEncContext * s, int ...@@ -867,7 +867,7 @@ static av_always_inline int epzs_motion_search_internal(MpegEncContext * s, int
int d; ///< the score (cmp + penalty) of any given mv int d; ///< the score (cmp + penalty) of any given mv
int dmin; /**< the best value of d, i.e. the score int dmin; /**< the best value of d, i.e. the score
corresponding to the mv stored in best[]. */ corresponding to the mv stored in best[]. */
int map_generation; unsigned map_generation;
int penalty_factor; int penalty_factor;
const int ref_mv_stride= s->mb_stride; //pass as arg FIXME 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 const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride; //add to last_mv beforepassing FIXME
...@@ -995,7 +995,7 @@ static int epzs_motion_search4(MpegEncContext * s, ...@@ -995,7 +995,7 @@ static int epzs_motion_search4(MpegEncContext * s,
MotionEstContext * const c= &s->me; MotionEstContext * const c= &s->me;
int best[2]={0, 0}; int best[2]={0, 0};
int d, dmin; int d, dmin;
int map_generation; unsigned map_generation;
const int penalty_factor= c->penalty_factor; const int penalty_factor= c->penalty_factor;
const int size=1; const int size=1;
const int h=8; const int h=8;
...@@ -1055,7 +1055,7 @@ static int epzs_motion_search2(MpegEncContext * s, ...@@ -1055,7 +1055,7 @@ static int epzs_motion_search2(MpegEncContext * s,
MotionEstContext * const c= &s->me; MotionEstContext * const c= &s->me;
int best[2]={0, 0}; int best[2]={0, 0};
int d, dmin; int d, dmin;
int map_generation; unsigned map_generation;
const int penalty_factor= c->penalty_factor; const int penalty_factor= c->penalty_factor;
const int size=0; //FIXME pass as arg const int size=0; //FIXME pass as arg
const int h=8; const int h=8;
......
...@@ -154,7 +154,7 @@ typedef struct MotionEstContext{ ...@@ -154,7 +154,7 @@ typedef struct MotionEstContext{
int best_bits; int best_bits;
uint32_t *map; ///< map to avoid duplicate evaluations uint32_t *map; ///< map to avoid duplicate evaluations
uint32_t *score_map; ///< map to store the scores uint32_t *score_map; ///< map to store the scores
int map_generation; unsigned map_generation;
int pre_penalty_factor; int pre_penalty_factor;
int penalty_factor; /**< an estimate of the bits required to int penalty_factor; /**< an estimate of the bits required to
code a given mv value, e.g. (1,0) takes code a given mv value, e.g. (1,0) takes
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment