Browse code

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: Mans Rullgard <mans@mansr.com>

Mans Rullgard authored on 2011/10/10 04:18:34
Showing 3 changed files
... ...
@@ -52,7 +52,7 @@ static inline int sad_hpel_motion_search(MpegEncContext * s,
52 52
                                   int src_index, int ref_index,
53 53
                                   int size, int h);
54 54
 
55
-static inline int update_map_generation(MotionEstContext *c)
55
+static inline unsigned update_map_generation(MotionEstContext *c)
56 56
 {
57 57
     c->map_generation+= 1<<(ME_MAP_MV_BITS*2);
58 58
     if(c->map_generation==0){
... ...
@@ -89,8 +89,8 @@ static int hpel_motion_search(MpegEncContext * s,
89 89
         const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
90 90
                      + (mv_penalty[bx   - pred_x] + mv_penalty[by+2 - pred_y])*c->penalty_factor;
91 91
 
92
-        int key;
93
-        int map_generation= c->map_generation;
92
+        unsigned key;
93
+        unsigned map_generation= c->map_generation;
94 94
 #ifndef NDEBUG
95 95
         uint32_t *map= c->map;
96 96
 #endif
... ...
@@ -208,7 +208,7 @@ static int qpel_motion_search(MpegEncContext * s,
208 208
     const int mx = *mx_ptr;
209 209
     const int my = *my_ptr;
210 210
     const int penalty_factor= c->sub_penalty_factor;
211
-    const int map_generation= c->map_generation;
211
+    const unsigned map_generation = c->map_generation;
212 212
     const int subpel_quality= c->avctx->me_subpel_quality;
213 213
     uint32_t *map= c->map;
214 214
     me_cmp_func cmpf, chroma_cmpf;
... ...
@@ -354,7 +354,7 @@ static int qpel_motion_search(MpegEncContext * s,
354 354
 
355 355
 #define CHECK_MV(x,y)\
356 356
 {\
357
-    const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
357
+    const unsigned key = ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
358 358
     const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
359 359
     assert((x) >= xmin);\
360 360
     assert((x) <= xmax);\
... ...
@@ -382,7 +382,7 @@ static int qpel_motion_search(MpegEncContext * s,
382 382
 
383 383
 #define CHECK_MV_DIR(x,y,new_dir)\
384 384
 {\
385
-    const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
385
+    const unsigned key = ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
386 386
     const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
387 387
 /*printf("check_mv_dir %d %d %d\n", x, y, new_dir);*/\
388 388
     if(map[index]!=key){\
... ...
@@ -420,13 +420,13 @@ static av_always_inline int small_diamond_search(MpegEncContext * s, int *best,
420 420
     int next_dir=-1;
421 421
     LOAD_COMMON
422 422
     LOAD_COMMON2
423
-    int map_generation= c->map_generation;
423
+    unsigned map_generation = c->map_generation;
424 424
 
425 425
     cmpf= s->dsp.me_cmp[size];
426 426
     chroma_cmpf= s->dsp.me_cmp[size+1];
427 427
 
428 428
     { /* ensure that the best point is in the MAP as h/qpel refinement needs it */
429
-        const int key= (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;
429
+        const unsigned key = (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;
430 430
         const int index= ((best[1]<<ME_MAP_SHIFT) + best[0])&(ME_MAP_SIZE-1);
431 431
         if(map[index]!=key){ //this will be executed only very rarey
432 432
             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 462
     int dia_size;
463 463
     LOAD_COMMON
464 464
     LOAD_COMMON2
465
-    int map_generation= c->map_generation;
465
+    unsigned map_generation = c->map_generation;
466 466
 
467 467
     cmpf= s->dsp.me_cmp[size];
468 468
     chroma_cmpf= s->dsp.me_cmp[size+1];
... ...
@@ -503,7 +503,7 @@ static int hex_search(MpegEncContext * s, int *best, int dmin,
503 503
     me_cmp_func cmpf, chroma_cmpf;
504 504
     LOAD_COMMON
505 505
     LOAD_COMMON2
506
-    int map_generation= c->map_generation;
506
+    unsigned map_generation = c->map_generation;
507 507
     int x,y,d;
508 508
     const int dec= dia_size & (dia_size-1);
509 509
 
... ...
@@ -537,7 +537,7 @@ static int l2s_dia_search(MpegEncContext * s, int *best, int dmin,
537 537
     me_cmp_func cmpf, chroma_cmpf;
538 538
     LOAD_COMMON
539 539
     LOAD_COMMON2
540
-    int map_generation= c->map_generation;
540
+    unsigned map_generation = c->map_generation;
541 541
     int x,y,i,d;
542 542
     int dia_size= c->dia_size&0xFF;
543 543
     const int dec= dia_size & (dia_size-1);
... ...
@@ -575,7 +575,7 @@ static int umh_search(MpegEncContext * s, int *best, int dmin,
575 575
     me_cmp_func cmpf, chroma_cmpf;
576 576
     LOAD_COMMON
577 577
     LOAD_COMMON2
578
-    int map_generation= c->map_generation;
578
+    unsigned map_generation = c->map_generation;
579 579
     int x,y,x2,y2, i, j, d;
580 580
     const int dia_size= c->dia_size&0xFE;
581 581
     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 622
     me_cmp_func cmpf, chroma_cmpf;
623 623
     LOAD_COMMON
624 624
     LOAD_COMMON2
625
-    int map_generation= c->map_generation;
625
+    unsigned map_generation = c->map_generation;
626 626
     int x,y, d;
627 627
     const int dia_size= c->dia_size&0xFF;
628 628
 
... ...
@@ -651,7 +651,7 @@ static int full_search(MpegEncContext * s, int *best, int dmin,
651 651
 
652 652
 #define SAB_CHECK_MV(ax,ay)\
653 653
 {\
654
-    const int key= ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
654
+    const unsigned key = ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
655 655
     const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\
656 656
 /*printf("sab check %d %d\n", ax, ay);*/\
657 657
     if(map[index]!=key){\
... ...
@@ -690,7 +690,7 @@ static int sab_diamond_search(MpegEncContext * s, int *best, int dmin,
690 690
     int i, j;
691 691
     LOAD_COMMON
692 692
     LOAD_COMMON2
693
-    int map_generation= c->map_generation;
693
+    unsigned map_generation = c->map_generation;
694 694
 
695 695
     cmpf= s->dsp.me_cmp[size];
696 696
     chroma_cmpf= s->dsp.me_cmp[size+1];
... ...
@@ -775,7 +775,7 @@ static int var_diamond_search(MpegEncContext * s, int *best, int dmin,
775 775
     int dia_size;
776 776
     LOAD_COMMON
777 777
     LOAD_COMMON2
778
-    int map_generation= c->map_generation;
778
+    unsigned map_generation = c->map_generation;
779 779
 
780 780
     cmpf= s->dsp.me_cmp[size];
781 781
     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 867
     int d;                   ///< the score (cmp + penalty) of any given mv
868 868
     int dmin;                /**< the best value of d, i.e. the score
869 869
                                corresponding to the mv stored in best[]. */
870
-    int map_generation;
870
+    unsigned map_generation;
871 871
     int penalty_factor;
872 872
     const int ref_mv_stride= s->mb_stride; //pass as arg  FIXME
873 873
     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 995
     MotionEstContext * const c= &s->me;
996 996
     int best[2]={0, 0};
997 997
     int d, dmin;
998
-    int map_generation;
998
+    unsigned map_generation;
999 999
     const int penalty_factor= c->penalty_factor;
1000 1000
     const int size=1;
1001 1001
     const int h=8;
... ...
@@ -1055,7 +1055,7 @@ static int epzs_motion_search2(MpegEncContext * s,
1055 1055
     MotionEstContext * const c= &s->me;
1056 1056
     int best[2]={0, 0};
1057 1057
     int d, dmin;
1058
-    int map_generation;
1058
+    unsigned map_generation;
1059 1059
     const int penalty_factor= c->penalty_factor;
1060 1060
     const int size=0; //FIXME pass as arg
1061 1061
     const int h=8;
... ...
@@ -154,7 +154,7 @@ typedef struct MotionEstContext{
154 154
     int best_bits;
155 155
     uint32_t *map;                     ///< map to avoid duplicate evaluations
156 156
     uint32_t *score_map;               ///< map to store the scores
157
-    int map_generation;
157
+    unsigned map_generation;
158 158
     int pre_penalty_factor;
159 159
     int penalty_factor;                /**< an estimate of the bits required to
160 160
                                         code a given mv value, e.g. (1,0) takes