comparison motion_est_template.c @ 2014:15c885db82a8 libavcodec

reduce dependancy between motion estimation and MpegEncContext this is practically just a s/s->me./c->/
author michael
date Tue, 11 May 2004 00:58:08 +0000
parents a3c60fa850dc
children 3ab8f3e2ae6a
comparison
equal deleted inserted replaced
2013:85e547a18d87 2014:15c885db82a8
23 * Motion estimation template. 23 * Motion estimation template.
24 */ 24 */
25 25
26 //lets hope gcc will remove the unused vars ...(gcc 3.2.2 seems to do it ...) 26 //lets hope gcc will remove the unused vars ...(gcc 3.2.2 seems to do it ...)
27 #define LOAD_COMMON\ 27 #define LOAD_COMMON\
28 uint32_t * const score_map= s->me.score_map;\ 28 uint32_t * const score_map= c->score_map;\
29 const int xmin= s->me.xmin;\ 29 const int xmin= c->xmin;\
30 const int ymin= s->me.ymin;\ 30 const int ymin= c->ymin;\
31 const int xmax= s->me.xmax;\ 31 const int xmax= c->xmax;\
32 const int ymax= s->me.ymax;\ 32 const int ymax= c->ymax;\
33 uint8_t *mv_penalty= s->me.current_mv_penalty;\ 33 uint8_t *mv_penalty= c->current_mv_penalty;\
34 const int pred_x= s->me.pred_x;\ 34 const int pred_x= c->pred_x;\
35 const int pred_y= s->me.pred_y;\ 35 const int pred_y= c->pred_y;\
36 36
37 #define CHECK_HALF_MV(dx, dy, x, y)\ 37 #define CHECK_HALF_MV(dx, dy, x, y)\
38 {\ 38 {\
39 const int hx= 2*(x)+(dx);\ 39 const int hx= 2*(x)+(dx);\
40 const int hy= 2*(y)+(dy);\ 40 const int hy= 2*(y)+(dy);\
51 { 51 {
52 const int xx = 16 * s->mb_x + 8*(n&1); 52 const int xx = 16 * s->mb_x + 8*(n&1);
53 const int yy = 16 * s->mb_y + 8*(n>>1); 53 const int yy = 16 * s->mb_y + 8*(n>>1);
54 const int mx = *mx_ptr; 54 const int mx = *mx_ptr;
55 const int my = *my_ptr; 55 const int my = *my_ptr;
56 const int penalty_factor= s->me.sub_penalty_factor; 56 const int penalty_factor= c->sub_penalty_factor;
57 57
58 LOAD_COMMON 58 LOAD_COMMON
59 59
60 // INIT; 60 // INIT;
61 //FIXME factorize 61 //FIXME factorize
71 cmpf= s->dsp.me_cmp[size]; 71 cmpf= s->dsp.me_cmp[size];
72 chroma_cmpf= s->dsp.me_cmp[size+1]; 72 chroma_cmpf= s->dsp.me_cmp[size+1];
73 cmp_sub= s->dsp.me_sub_cmp[size]; 73 cmp_sub= s->dsp.me_sub_cmp[size];
74 chroma_cmp_sub= s->dsp.me_sub_cmp[size+1]; 74 chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
75 75
76 if(s->me.skip){ //FIXME somehow move up (benchmark) 76 if(c->skip){ //FIXME somehow move up (benchmark)
77 *mx_ptr = 0; 77 *mx_ptr = 0;
78 *my_ptr = 0; 78 *my_ptr = 0;
79 return dmin; 79 return dmin;
80 } 80 }
81 81
115 static int hpel_motion_search(MpegEncContext * s, 115 static int hpel_motion_search(MpegEncContext * s,
116 int *mx_ptr, int *my_ptr, int dmin, 116 int *mx_ptr, int *my_ptr, int dmin,
117 int src_index, int ref_index, 117 int src_index, int ref_index,
118 int size, int h) 118 int size, int h)
119 { 119 {
120 MotionEstContext * const c= &s->me;
120 const int mx = *mx_ptr; 121 const int mx = *mx_ptr;
121 const int my = *my_ptr; 122 const int my = *my_ptr;
122 const int penalty_factor= s->me.sub_penalty_factor; 123 const int penalty_factor= c->sub_penalty_factor;
123 me_cmp_func cmp_sub, chroma_cmp_sub; 124 me_cmp_func cmp_sub, chroma_cmp_sub;
124 int bx=2*mx, by=2*my; 125 int bx=2*mx, by=2*my;
125 126
126 LOAD_COMMON 127 LOAD_COMMON
127 int flags= s->me.sub_flags; 128 int flags= c->sub_flags;
128 129
129 //FIXME factorize 130 //FIXME factorize
130 131
131 cmp_sub= s->dsp.me_sub_cmp[size]; 132 cmp_sub= s->dsp.me_sub_cmp[size];
132 chroma_cmp_sub= s->dsp.me_sub_cmp[size+1]; 133 chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
133 134
134 if(s->me.skip){ //FIXME move out of hpel? 135 if(c->skip){ //FIXME move out of hpel?
135 *mx_ptr = 0; 136 *mx_ptr = 0;
136 *my_ptr = 0; 137 *my_ptr = 0;
137 return dmin; 138 return dmin;
138 } 139 }
139 140
146 if (mx > xmin && mx < xmax && 147 if (mx > xmin && mx < xmax &&
147 my > ymin && my < ymax) { 148 my > ymin && my < ymax) {
148 int d= dmin; 149 int d= dmin;
149 const int index= (my<<ME_MAP_SHIFT) + mx; 150 const int index= (my<<ME_MAP_SHIFT) + mx;
150 const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] 151 const int t= score_map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
151 + (mv_penalty[bx - pred_x] + mv_penalty[by-2 - pred_y])*s->me.penalty_factor; 152 + (mv_penalty[bx - pred_x] + mv_penalty[by-2 - pred_y])*c->penalty_factor;
152 const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)] 153 const int l= score_map[(index- 1 )&(ME_MAP_SIZE-1)]
153 + (mv_penalty[bx-2 - pred_x] + mv_penalty[by - pred_y])*s->me.penalty_factor; 154 + (mv_penalty[bx-2 - pred_x] + mv_penalty[by - pred_y])*c->penalty_factor;
154 const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)] 155 const int r= score_map[(index+ 1 )&(ME_MAP_SIZE-1)]
155 + (mv_penalty[bx+2 - pred_x] + mv_penalty[by - pred_y])*s->me.penalty_factor; 156 + (mv_penalty[bx+2 - pred_x] + mv_penalty[by - pred_y])*c->penalty_factor;
156 const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] 157 const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
157 + (mv_penalty[bx - pred_x] + mv_penalty[by+2 - pred_y])*s->me.penalty_factor; 158 + (mv_penalty[bx - pred_x] + mv_penalty[by+2 - pred_y])*c->penalty_factor;
158 159
159 #if 1 160 #if 1
160 int key; 161 int key;
161 int map_generation= s->me.map_generation; 162 int map_generation= c->map_generation;
162 #ifndef NDEBUG 163 #ifndef NDEBUG
163 uint32_t *map= s->me.map; 164 uint32_t *map= c->map;
164 #endif 165 #endif
165 key= ((my-1)<<ME_MAP_MV_BITS) + (mx) + map_generation; 166 key= ((my-1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
166 assert(map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key); 167 assert(map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);
167 key= ((my+1)<<ME_MAP_MV_BITS) + (mx) + map_generation; 168 key= ((my+1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
168 assert(map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key); 169 assert(map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);
222 223
223 static int inline get_mb_score(MpegEncContext * s, int mx, int my, int src_index, 224 static int inline get_mb_score(MpegEncContext * s, int mx, int my, int src_index,
224 int ref_index) 225 int ref_index)
225 { 226 {
226 // const int check_luma= s->dsp.me_sub_cmp != s->dsp.mb_cmp; 227 // const int check_luma= s->dsp.me_sub_cmp != s->dsp.mb_cmp;
228 MotionEstContext * const c= &s->me;
227 const int size= 0; 229 const int size= 0;
228 const int h= 16; 230 const int h= 16;
229 const int penalty_factor= s->me.mb_penalty_factor; 231 const int penalty_factor= c->mb_penalty_factor;
230 const int flags= s->me.mb_flags; 232 const int flags= c->mb_flags;
231 const int qpel= flags & FLAG_QPEL; 233 const int qpel= flags & FLAG_QPEL;
232 const int mask= 1+2*qpel; 234 const int mask= 1+2*qpel;
233 me_cmp_func cmp_sub, chroma_cmp_sub; 235 me_cmp_func cmp_sub, chroma_cmp_sub;
234 int d; 236 int d;
235 237
238 //FIXME factorize 240 //FIXME factorize
239 241
240 cmp_sub= s->dsp.mb_cmp[size]; 242 cmp_sub= s->dsp.mb_cmp[size];
241 chroma_cmp_sub= s->dsp.mb_cmp[size+1]; 243 chroma_cmp_sub= s->dsp.mb_cmp[size+1];
242 244
243 assert(!s->me.skip); 245 assert(!c->skip);
244 assert(s->avctx->me_sub_cmp != s->avctx->mb_cmp); 246 assert(s->avctx->me_sub_cmp != s->avctx->mb_cmp);
245 247
246 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); 248 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);
247 //FIXME check cbp before adding penalty for (0,0) vector 249 //FIXME check cbp before adding penalty for (0,0) vector
248 if(mx || my || size>0) 250 if(mx || my || size>0)
263 static int qpel_motion_search(MpegEncContext * s, 265 static int qpel_motion_search(MpegEncContext * s,
264 int *mx_ptr, int *my_ptr, int dmin, 266 int *mx_ptr, int *my_ptr, int dmin,
265 int src_index, int ref_index, 267 int src_index, int ref_index,
266 int size, int h) 268 int size, int h)
267 { 269 {
270 MotionEstContext * const c= &s->me;
268 const int mx = *mx_ptr; 271 const int mx = *mx_ptr;
269 const int my = *my_ptr; 272 const int my = *my_ptr;
270 const int penalty_factor= s->me.sub_penalty_factor; 273 const int penalty_factor= c->sub_penalty_factor;
271 const int map_generation= s->me.map_generation; 274 const int map_generation= c->map_generation;
272 const int subpel_quality= s->avctx->me_subpel_quality; 275 const int subpel_quality= s->avctx->me_subpel_quality;
273 uint32_t *map= s->me.map; 276 uint32_t *map= c->map;
274 me_cmp_func cmpf, chroma_cmpf; 277 me_cmp_func cmpf, chroma_cmpf;
275 me_cmp_func cmp_sub, chroma_cmp_sub; 278 me_cmp_func cmp_sub, chroma_cmp_sub;
276 279
277 LOAD_COMMON 280 LOAD_COMMON
278 int flags= s->me.sub_flags; 281 int flags= c->sub_flags;
279 282
280 cmpf= s->dsp.me_cmp[size]; 283 cmpf= s->dsp.me_cmp[size];
281 chroma_cmpf= s->dsp.me_cmp[size+1]; //factorize FIXME 284 chroma_cmpf= s->dsp.me_cmp[size+1]; //factorize FIXME
282 //FIXME factorize 285 //FIXME factorize
283 286
284 cmp_sub= s->dsp.me_sub_cmp[size]; 287 cmp_sub= s->dsp.me_sub_cmp[size];
285 chroma_cmp_sub= s->dsp.me_sub_cmp[size+1]; 288 chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
286 289
287 if(s->me.skip){ //FIXME somehow move up (benchmark) 290 if(c->skip){ //FIXME somehow move up (benchmark)
288 *mx_ptr = 0; 291 *mx_ptr = 0;
289 *my_ptr = 0; 292 *my_ptr = 0;
290 return dmin; 293 return dmin;
291 } 294 }
292 295
328 331
329 if((nx&3)==0 && (ny&3)==0) continue; 332 if((nx&3)==0 && (ny&3)==0) continue;
330 333
331 score += 1024*(mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor; 334 score += 1024*(mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
332 335
333 // if(nx&1) score-=1024*s->me.penalty_factor; 336 // if(nx&1) score-=1024*c->penalty_factor;
334 // if(ny&1) score-=1024*s->me.penalty_factor; 337 // if(ny&1) score-=1024*c->penalty_factor;
335 338
336 for(i=0; i<8; i++){ 339 for(i=0; i<8; i++){
337 if(score < best[i]){ 340 if(score < best[i]){
338 memmove(&best[i+1], &best[i], sizeof(int)*(7-i)); 341 memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
339 memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i)); 342 memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
373 int i; 376 int i;
374 377
375 if((nx&3)==0 && (ny&3)==0) continue; 378 if((nx&3)==0 && (ny&3)==0) continue;
376 379
377 score += 32*(mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor; 380 score += 32*(mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
378 // if(nx&1) score-=32*s->me.penalty_factor; 381 // if(nx&1) score-=32*c->penalty_factor;
379 // if(ny&1) score-=32*s->me.penalty_factor; 382 // if(ny&1) score-=32*c->penalty_factor;
380 383
381 for(i=0; i<8; i++){ 384 for(i=0; i<8; i++){
382 if(score < best[i]){ 385 if(score < best[i]){
383 memmove(&best[i+1], &best[i], sizeof(int)*(7-i)); 386 memmove(&best[i+1], &best[i], sizeof(int)*(7-i));
384 memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i)); 387 memmove(&best_pos[i+1][0], &best_pos[i][0], sizeof(int)*2*(7-i));
529 if( (x)>(xmax<<(S)) ) printf("%d %d %d %d %d xmax" #v, xmax, (x), (y), s->mb_x, s->mb_y);\ 532 if( (x)>(xmax<<(S)) ) printf("%d %d %d %d %d xmax" #v, xmax, (x), (y), s->mb_x, s->mb_y);\
530 if( (y)<(ymin<<(S)) ) printf("%d %d %d %d %d ymin" #v, ymin, (x), (y), s->mb_x, s->mb_y);\ 533 if( (y)<(ymin<<(S)) ) printf("%d %d %d %d %d ymin" #v, ymin, (x), (y), s->mb_x, s->mb_y);\
531 if( (y)>(ymax<<(S)) ) printf("%d %d %d %d %d ymax" #v, ymax, (x), (y), s->mb_x, s->mb_y);\ 534 if( (y)>(ymax<<(S)) ) printf("%d %d %d %d %d ymax" #v, ymax, (x), (y), s->mb_x, s->mb_y);\
532 535
533 #define LOAD_COMMON2\ 536 #define LOAD_COMMON2\
534 uint32_t *map= s->me.map;\ 537 uint32_t *map= c->map;\
535 const int qpel= flags&FLAG_QPEL;\ 538 const int qpel= flags&FLAG_QPEL;\
536 const int shift= 1+qpel;\ 539 const int shift= 1+qpel;\
537 540
538 static always_inline int small_diamond_search(MpegEncContext * s, int *best, int dmin, 541 static always_inline int small_diamond_search(MpegEncContext * s, int *best, int dmin,
539 int src_index, int ref_index, int const penalty_factor, 542 int src_index, int ref_index, int const penalty_factor,
540 int size, int h, int flags) 543 int size, int h, int flags)
541 { 544 {
545 MotionEstContext * const c= &s->me;
542 me_cmp_func cmpf, chroma_cmpf; 546 me_cmp_func cmpf, chroma_cmpf;
543 int next_dir=-1; 547 int next_dir=-1;
544 LOAD_COMMON 548 LOAD_COMMON
545 LOAD_COMMON2 549 LOAD_COMMON2
546 int map_generation= s->me.map_generation; 550 int map_generation= c->map_generation;
547 551
548 cmpf= s->dsp.me_cmp[size]; 552 cmpf= s->dsp.me_cmp[size];
549 chroma_cmpf= s->dsp.me_cmp[size+1]; 553 chroma_cmpf= s->dsp.me_cmp[size+1];
550 554
551 { /* ensure that the best point is in the MAP as h/qpel refinement needs it */ 555 { /* ensure that the best point is in the MAP as h/qpel refinement needs it */
578 582
579 static int funny_diamond_search(MpegEncContext * s, int *best, int dmin, 583 static int funny_diamond_search(MpegEncContext * s, int *best, int dmin,
580 int src_index, int ref_index, int const penalty_factor, 584 int src_index, int ref_index, int const penalty_factor,
581 int size, int h, int flags) 585 int size, int h, int flags)
582 { 586 {
587 MotionEstContext * const c= &s->me;
583 me_cmp_func cmpf, chroma_cmpf; 588 me_cmp_func cmpf, chroma_cmpf;
584 int dia_size; 589 int dia_size;
585 LOAD_COMMON 590 LOAD_COMMON
586 LOAD_COMMON2 591 LOAD_COMMON2
587 int map_generation= s->me.map_generation; 592 int map_generation= c->map_generation;
588 593
589 cmpf= s->dsp.me_cmp[size]; 594 cmpf= s->dsp.me_cmp[size];
590 chroma_cmpf= s->dsp.me_cmp[size+1]; 595 chroma_cmpf= s->dsp.me_cmp[size+1];
591 596
592 for(dia_size=1; dia_size<=4; dia_size++){ 597 for(dia_size=1; dia_size<=4; dia_size++){
668 #define MAX_SAB_SIZE 16 673 #define MAX_SAB_SIZE 16
669 static int sab_diamond_search(MpegEncContext * s, int *best, int dmin, 674 static int sab_diamond_search(MpegEncContext * s, int *best, int dmin,
670 int src_index, int ref_index, int const penalty_factor, 675 int src_index, int ref_index, int const penalty_factor,
671 int size, int h, int flags) 676 int size, int h, int flags)
672 { 677 {
678 MotionEstContext * const c= &s->me;
673 me_cmp_func cmpf, chroma_cmpf; 679 me_cmp_func cmpf, chroma_cmpf;
674 Minima minima[MAX_SAB_SIZE]; 680 Minima minima[MAX_SAB_SIZE];
675 const int minima_count= ABS(s->me.dia_size); 681 const int minima_count= ABS(c->dia_size);
676 int i, j; 682 int i, j;
677 LOAD_COMMON 683 LOAD_COMMON
678 LOAD_COMMON2 684 LOAD_COMMON2
679 int map_generation= s->me.map_generation; 685 int map_generation= c->map_generation;
680 686
681 cmpf= s->dsp.me_cmp[size]; 687 cmpf= s->dsp.me_cmp[size];
682 chroma_cmpf= s->dsp.me_cmp[size+1]; 688 chroma_cmpf= s->dsp.me_cmp[size+1];
683 689
684 for(j=i=0; i<ME_MAP_SIZE; i++){ 690 for(j=i=0; i<ME_MAP_SIZE; i++){
747 753
748 static int var_diamond_search(MpegEncContext * s, int *best, int dmin, 754 static int var_diamond_search(MpegEncContext * s, int *best, int dmin,
749 int src_index, int ref_index, int const penalty_factor, 755 int src_index, int ref_index, int const penalty_factor,
750 int size, int h, int flags) 756 int size, int h, int flags)
751 { 757 {
758 MotionEstContext * const c= &s->me;
752 me_cmp_func cmpf, chroma_cmpf; 759 me_cmp_func cmpf, chroma_cmpf;
753 int dia_size; 760 int dia_size;
754 LOAD_COMMON 761 LOAD_COMMON
755 LOAD_COMMON2 762 LOAD_COMMON2
756 int map_generation= s->me.map_generation; 763 int map_generation= c->map_generation;
757 764
758 cmpf= s->dsp.me_cmp[size]; 765 cmpf= s->dsp.me_cmp[size];
759 chroma_cmpf= s->dsp.me_cmp[size+1]; 766 chroma_cmpf= s->dsp.me_cmp[size+1];
760 767
761 for(dia_size=1; dia_size<=s->me.dia_size; dia_size++){ 768 for(dia_size=1; dia_size<=c->dia_size; dia_size++){
762 int dir, start, end; 769 int dir, start, end;
763 const int x= best[0]; 770 const int x= best[0];
764 const int y= best[1]; 771 const int y= best[1];
765 772
766 start= FFMAX(0, y + dia_size - ymax); 773 start= FFMAX(0, y + dia_size - ymax);
822 } 829 }
823 830
824 static always_inline int diamond_search(MpegEncContext * s, int *best, int dmin, 831 static always_inline int diamond_search(MpegEncContext * s, int *best, int dmin,
825 int src_index, int ref_index, int const penalty_factor, 832 int src_index, int ref_index, int const penalty_factor,
826 int size, int h, int flags){ 833 int size, int h, int flags){
827 if(s->me.dia_size==-1) 834 MotionEstContext * const c= &s->me;
835 if(c->dia_size==-1)
828 return funny_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags); 836 return funny_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
829 else if(s->me.dia_size<-1) 837 else if(c->dia_size<-1)
830 return sab_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags); 838 return sab_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
831 else if(s->me.dia_size<2) 839 else if(c->dia_size<2)
832 return small_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags); 840 return small_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
833 else 841 else
834 return var_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags); 842 return var_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
835 } 843 }
836 844
837 static always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx_ptr, int *my_ptr, 845 static always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx_ptr, int *my_ptr,
838 int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2], 846 int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
839 int ref_mv_scale, int flags) 847 int ref_mv_scale, int flags)
840 { 848 {
849 MotionEstContext * const c= &s->me;
841 int best[2]={0, 0}; 850 int best[2]={0, 0};
842 int d, dmin; 851 int d, dmin;
843 int map_generation; 852 int map_generation;
844 const int penalty_factor= s->me.penalty_factor; 853 const int penalty_factor= c->penalty_factor;
845 const int size=0; 854 const int size=0;
846 const int h=16; 855 const int h=16;
847 const int ref_mv_stride= s->mb_stride; //pass as arg FIXME 856 const int ref_mv_stride= s->mb_stride; //pass as arg FIXME
848 const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride; //add to last_mv beforepassing FIXME 857 const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride; //add to last_mv beforepassing FIXME
849 me_cmp_func cmpf, chroma_cmpf; 858 me_cmp_func cmpf, chroma_cmpf;
852 LOAD_COMMON2 861 LOAD_COMMON2
853 862
854 cmpf= s->dsp.me_cmp[size]; 863 cmpf= s->dsp.me_cmp[size];
855 chroma_cmpf= s->dsp.me_cmp[size+1]; 864 chroma_cmpf= s->dsp.me_cmp[size+1];
856 865
857 map_generation= update_map_generation(s); 866 map_generation= update_map_generation(c);
858 867
859 dmin= cmp(s, 0, 0, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags); 868 dmin= cmp(s, 0, 0, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
860 map[0]= map_generation; 869 map[0]= map_generation;
861 score_map[0]= dmin; 870 score_map[0]= dmin;
862 871
869 if(dmin<256 && ( P_LEFT[0] |P_LEFT[1] 878 if(dmin<256 && ( P_LEFT[0] |P_LEFT[1]
870 |P_TOP[0] |P_TOP[1] 879 |P_TOP[0] |P_TOP[1]
871 |P_TOPRIGHT[0]|P_TOPRIGHT[1])==0){ 880 |P_TOPRIGHT[0]|P_TOPRIGHT[1])==0){
872 *mx_ptr= 0; 881 *mx_ptr= 0;
873 *my_ptr= 0; 882 *my_ptr= 0;
874 s->me.skip=1; 883 c->skip=1;
875 return dmin; 884 return dmin;
876 } 885 }
877 CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift) 886 CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
878 if(dmin>256*2){ 887 if(dmin>256*2){
879 CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16, 888 CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16,
882 CHECK_MV(P_TOP[0] >>shift, P_TOP[1] >>shift) 891 CHECK_MV(P_TOP[0] >>shift, P_TOP[1] >>shift)
883 CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift) 892 CHECK_MV(P_TOPRIGHT[0]>>shift, P_TOPRIGHT[1]>>shift)
884 } 893 }
885 } 894 }
886 if(dmin>256*4){ 895 if(dmin>256*4){
887 if(s->me.pre_pass){ 896 if(c->pre_pass){
888 CHECK_CLIPED_MV((last_mv[ref_mv_xy-1][0]*ref_mv_scale + (1<<15))>>16, 897 CHECK_CLIPED_MV((last_mv[ref_mv_xy-1][0]*ref_mv_scale + (1<<15))>>16,
889 (last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16) 898 (last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16)
890 if(!s->first_slice_line) 899 if(!s->first_slice_line)
891 CHECK_CLIPED_MV((last_mv[ref_mv_xy-ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16, 900 CHECK_CLIPED_MV((last_mv[ref_mv_xy-ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16,
892 (last_mv[ref_mv_xy-ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16) 901 (last_mv[ref_mv_xy-ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
934 //this function is dedicated to the braindamaged gcc 943 //this function is dedicated to the braindamaged gcc
935 static inline int epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr, 944 static inline int epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_ptr,
936 int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2], 945 int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2],
937 int ref_mv_scale) 946 int ref_mv_scale)
938 { 947 {
948 MotionEstContext * const c= &s->me;
939 //FIXME convert other functions in the same way if faster 949 //FIXME convert other functions in the same way if faster
940 switch(s->me.flags){ 950 switch(c->flags){
941 case 0: 951 case 0:
942 return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, 0); 952 return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, 0);
943 // case FLAG_QPEL: 953 // case FLAG_QPEL:
944 // return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, FLAG_QPEL); 954 // return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, FLAG_QPEL);
945 default: 955 default:
946 return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, s->me.flags); 956 return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, c->flags);
947 } 957 }
948 } 958 }
949 959
950 static int epzs_motion_search4(MpegEncContext * s, 960 static int epzs_motion_search4(MpegEncContext * s,
951 int *mx_ptr, int *my_ptr, int P[10][2], 961 int *mx_ptr, int *my_ptr, int P[10][2],
952 int src_index, int ref_index, int16_t (*last_mv)[2], 962 int src_index, int ref_index, int16_t (*last_mv)[2],
953 int ref_mv_scale) 963 int ref_mv_scale)
954 { 964 {
965 MotionEstContext * const c= &s->me;
955 int best[2]={0, 0}; 966 int best[2]={0, 0};
956 int d, dmin; 967 int d, dmin;
957 int map_generation; 968 int map_generation;
958 const int penalty_factor= s->me.penalty_factor; 969 const int penalty_factor= c->penalty_factor;
959 const int size=1; 970 const int size=1;
960 const int h=8; 971 const int h=8;
961 const int ref_mv_stride= s->mb_stride; 972 const int ref_mv_stride= s->mb_stride;
962 const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride; 973 const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
963 me_cmp_func cmpf, chroma_cmpf; 974 me_cmp_func cmpf, chroma_cmpf;
964 LOAD_COMMON 975 LOAD_COMMON
965 int flags= s->me.flags; 976 int flags= c->flags;
966 LOAD_COMMON2 977 LOAD_COMMON2
967 978
968 cmpf= s->dsp.me_cmp[size]; 979 cmpf= s->dsp.me_cmp[size];
969 chroma_cmpf= s->dsp.me_cmp[size+1]; 980 chroma_cmpf= s->dsp.me_cmp[size+1];
970 981
971 map_generation= update_map_generation(s); 982 map_generation= update_map_generation(c);
972 983
973 dmin = 1000000; 984 dmin = 1000000;
974 //printf("%d %d %d %d //",xmin, ymin, xmax, ymax); 985 //printf("%d %d %d %d //",xmin, ymin, xmax, ymax);
975 /* first line */ 986 /* first line */
976 if (s->first_slice_line) { 987 if (s->first_slice_line) {
1011 static int epzs_motion_search2(MpegEncContext * s, 1022 static int epzs_motion_search2(MpegEncContext * s,
1012 int *mx_ptr, int *my_ptr, int P[10][2], 1023 int *mx_ptr, int *my_ptr, int P[10][2],
1013 int src_index, int ref_index, int16_t (*last_mv)[2], 1024 int src_index, int ref_index, int16_t (*last_mv)[2],
1014 int ref_mv_scale) 1025 int ref_mv_scale)
1015 { 1026 {
1027 MotionEstContext * const c= &s->me;
1016 int best[2]={0, 0}; 1028 int best[2]={0, 0};
1017 int d, dmin; 1029 int d, dmin;
1018 int map_generation; 1030 int map_generation;
1019 const int penalty_factor= s->me.penalty_factor; 1031 const int penalty_factor= c->penalty_factor;
1020 const int size=0; //FIXME pass as arg 1032 const int size=0; //FIXME pass as arg
1021 const int h=8; 1033 const int h=8;
1022 const int ref_mv_stride= s->mb_stride; 1034 const int ref_mv_stride= s->mb_stride;
1023 const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride; 1035 const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
1024 me_cmp_func cmpf, chroma_cmpf; 1036 me_cmp_func cmpf, chroma_cmpf;
1025 LOAD_COMMON 1037 LOAD_COMMON
1026 int flags= s->me.flags; 1038 int flags= c->flags;
1027 LOAD_COMMON2 1039 LOAD_COMMON2
1028 1040
1029 cmpf= s->dsp.me_cmp[size]; 1041 cmpf= s->dsp.me_cmp[size];
1030 chroma_cmpf= s->dsp.me_cmp[size+1]; 1042 chroma_cmpf= s->dsp.me_cmp[size+1];
1031 1043
1032 map_generation= update_map_generation(s); 1044 map_generation= update_map_generation(c);
1033 1045
1034 dmin = 1000000; 1046 dmin = 1000000;
1035 //printf("%d %d %d %d //",xmin, ymin, xmax, ymax); 1047 //printf("%d %d %d %d //",xmin, ymin, xmax, ymax);
1036 /* first line */ 1048 /* first line */
1037 if (s->first_slice_line) { 1049 if (s->first_slice_line) {