Browse code

reduce dependancy between motion estimation and MpegEncContext this is practically just a s/s->me./c->/

Originally committed as revision 3123 to svn://svn.ffmpeg.org/ffmpeg/trunk

Michael Niedermayer authored on 2004/05/11 09:58:08
Showing 2 changed files
... ...
@@ -49,14 +49,14 @@ static inline int sad_hpel_motion_search(MpegEncContext * s,
49 49
                                   int src_index, int ref_index,
50 50
                                   int size, int h);
51 51
 
52
-static inline int update_map_generation(MpegEncContext * s)
52
+static inline int update_map_generation(MotionEstContext *c)
53 53
 {
54
-    s->me.map_generation+= 1<<(ME_MAP_MV_BITS*2);
55
-    if(s->me.map_generation==0){
56
-        s->me.map_generation= 1<<(ME_MAP_MV_BITS*2);
57
-        memset(s->me.map, 0, sizeof(uint32_t)*ME_MAP_SIZE);
54
+    c->map_generation+= 1<<(ME_MAP_MV_BITS*2);
55
+    if(c->map_generation==0){
56
+        c->map_generation= 1<<(ME_MAP_MV_BITS*2);
57
+        memset(c->map, 0, sizeof(uint32_t)*ME_MAP_SIZE);
58 58
     }
59
-    return s->me.map_generation;
59
+    return c->map_generation;
60 60
 }
61 61
 
62 62
 /* shape adaptive search stuff */
... ...
@@ -77,8 +77,7 @@ static int minima_cmp(const void *a, const void *b){
77 77
 #define FLAG_CHROMA 2
78 78
 #define FLAG_DIRECT 4
79 79
 
80
-static inline void init_ref(MpegEncContext *s, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index){
81
-    MotionEstContext * const c= &s->me;
80
+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){
82 81
     const int offset[3]= {
83 82
           y*c->  stride + x,
84 83
         ((y*c->uvstride + x)>>1),
... ...
@@ -247,35 +246,35 @@ void ff_init_me(MpegEncContext *s){
247 247
     ff_set_cmp(&s->dsp, s->dsp.me_sub_cmp, s->avctx->me_sub_cmp);
248 248
     ff_set_cmp(&s->dsp, s->dsp.mb_cmp, s->avctx->mb_cmp);
249 249
     
250
-    s->me.flags    = get_flags(s, 0, s->avctx->me_cmp    &FF_CMP_CHROMA);
251
-    s->me.sub_flags= get_flags(s, 0, s->avctx->me_sub_cmp&FF_CMP_CHROMA);
252
-    s->me.mb_flags = get_flags(s, 0, s->avctx->mb_cmp    &FF_CMP_CHROMA);
250
+    c->flags    = get_flags(s, 0, s->avctx->me_cmp    &FF_CMP_CHROMA);
251
+    c->sub_flags= get_flags(s, 0, s->avctx->me_sub_cmp&FF_CMP_CHROMA);
252
+    c->mb_flags = get_flags(s, 0, s->avctx->mb_cmp    &FF_CMP_CHROMA);
253 253
 
254 254
 /*FIXME s->no_rounding b_type*/
255 255
     if(s->flags&CODEC_FLAG_QPEL){
256
-        s->me.sub_motion_search= qpel_motion_search;
256
+        c->sub_motion_search= qpel_motion_search;
257 257
         c->qpel_avg= s->dsp.avg_qpel_pixels_tab;
258 258
         if(s->no_rounding) c->qpel_put= s->dsp.put_no_rnd_qpel_pixels_tab;
259 259
         else               c->qpel_put= s->dsp.put_qpel_pixels_tab;
260 260
     }else{
261 261
         if(s->avctx->me_sub_cmp&FF_CMP_CHROMA)
262
-            s->me.sub_motion_search= hpel_motion_search;
262
+            c->sub_motion_search= hpel_motion_search;
263 263
         else if(   s->avctx->me_sub_cmp == FF_CMP_SAD 
264 264
                 && s->avctx->    me_cmp == FF_CMP_SAD 
265 265
                 && s->avctx->    mb_cmp == FF_CMP_SAD)
266
-            s->me.sub_motion_search= sad_hpel_motion_search; // 2050 vs. 2450 cycles
266
+            c->sub_motion_search= sad_hpel_motion_search; // 2050 vs. 2450 cycles
267 267
         else
268
-            s->me.sub_motion_search= hpel_motion_search;
268
+            c->sub_motion_search= hpel_motion_search;
269 269
         c->hpel_avg= s->dsp.avg_pixels_tab;
270 270
         if(s->no_rounding) c->hpel_put= s->dsp.put_no_rnd_pixels_tab;
271 271
         else               c->hpel_put= s->dsp.put_pixels_tab;
272 272
     }
273 273
     if(s->linesize){
274
-        s->me.stride  = s->linesize; 
275
-        s->me.uvstride= s->uvlinesize;
274
+        c->stride  = s->linesize; 
275
+        c->uvstride= s->uvlinesize;
276 276
     }else{
277
-        s->me.stride  = 16*s->mb_width + 32;
278
-        s->me.uvstride=  8*s->mb_width + 16;
277
+        c->stride  = 16*s->mb_width + 32;
278
+        c->uvstride=  8*s->mb_width + 16;
279 279
     }
280 280
 
281 281
     c->temp= c->scratchpad;
... ...
@@ -548,16 +547,17 @@ static inline int sad_hpel_motion_search(MpegEncContext * s,
548 548
                                   int src_index, int ref_index,
549 549
                                   int size, int h)
550 550
 {
551
-    const int penalty_factor= s->me.sub_penalty_factor;
551
+    MotionEstContext * const c= &s->me;
552
+    const int penalty_factor= c->sub_penalty_factor;
552 553
     int mx, my, dminh;
553 554
     uint8_t *pix, *ptr;
554
-    int stride= s->me.stride;
555
-    const int flags= s->me.sub_flags;
555
+    int stride= c->stride;
556
+    const int flags= c->sub_flags;
556 557
     LOAD_COMMON
557 558
     
558 559
     assert(flags == 0);
559 560
 
560
-    if(s->me.skip){
561
+    if(c->skip){
561 562
 //    printf("S");
562 563
         *mx_ptr = 0;
563 564
         *my_ptr = 0;
... ...
@@ -565,11 +565,11 @@ static inline int sad_hpel_motion_search(MpegEncContext * s,
565 565
     }
566 566
 //    printf("N");
567 567
         
568
-    pix = s->me.src[src_index][0];
568
+    pix = c->src[src_index][0];
569 569
 
570 570
     mx = *mx_ptr;
571 571
     my = *my_ptr;
572
-    ptr = s->me.ref[ref_index][0] + (my * stride) + mx;
572
+    ptr = c->ref[ref_index][0] + (my * stride) + mx;
573 573
     
574 574
     dminh = dmin;
575 575
 
... ...
@@ -679,20 +679,21 @@ static inline void set_p_mv_tables(MpegEncContext * s, int mx, int my, int mv4)
679 679
  */
680 680
 static inline void get_limits(MpegEncContext *s, int x, int y)
681 681
 {
682
+    MotionEstContext * const c= &s->me;
682 683
 /*
683
-    if(s->avctx->me_range) s->me.range= s->avctx->me_range >> 1;
684
-    else                   s->me.range= 16;
684
+    if(s->avctx->me_range) c->range= s->avctx->me_range >> 1;
685
+    else                   c->range= 16;
685 686
 */
686 687
     if (s->unrestricted_mv) {
687
-        s->me.xmin = - x - 16;
688
-        s->me.ymin = - y - 16;
689
-        s->me.xmax = - x + s->mb_width *16;
690
-        s->me.ymax = - y + s->mb_height*16;
688
+        c->xmin = - x - 16;
689
+        c->ymin = - y - 16;
690
+        c->xmax = - x + s->mb_width *16;
691
+        c->ymax = - y + s->mb_height*16;
691 692
     } else {
692
-        s->me.xmin = - x;
693
-        s->me.ymin = - y;
694
-        s->me.xmax = - x + s->mb_width *16 - 16;
695
-        s->me.ymax = - y + s->mb_height*16 - 16;
693
+        c->xmin = - x;
694
+        c->ymin = - y;
695
+        c->xmax = - x + s->mb_width *16 - 16;
696
+        c->ymax = - y + s->mb_height*16 - 16;
696 697
     }
697 698
 }
698 699
 
... ...
@@ -719,7 +720,7 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
719 719
     int same=1;
720 720
     const int stride= s->linesize;
721 721
     const int uvstride= s->uvlinesize;
722
-    uint8_t *mv_penalty= s->me.current_mv_penalty;
722
+    uint8_t *mv_penalty= c->current_mv_penalty;
723 723
 
724 724
     init_mv4_ref(s);
725 725
     
... ...
@@ -734,39 +735,39 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
734 734
         P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0];
735 735
         P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1];
736 736
 
737
-        if(P_LEFT[0]       > (s->me.xmax<<shift)) P_LEFT[0]       = (s->me.xmax<<shift);
737
+        if(P_LEFT[0]       > (c->xmax<<shift)) P_LEFT[0]       = (c->xmax<<shift);
738 738
 
739 739
         /* special case for first line */
740 740
         if (s->first_slice_line && block<2) {
741
-            s->me.pred_x= pred_x4= P_LEFT[0];
742
-            s->me.pred_y= pred_y4= P_LEFT[1];
741
+            c->pred_x= pred_x4= P_LEFT[0];
742
+            c->pred_y= pred_y4= P_LEFT[1];
743 743
         } else {
744 744
             P_TOP[0]      = s->current_picture.motion_val[0][mot_xy - mot_stride             ][0];
745 745
             P_TOP[1]      = s->current_picture.motion_val[0][mot_xy - mot_stride             ][1];
746 746
             P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][0];
747 747
             P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][1];
748
-            if(P_TOP[1]      > (s->me.ymax<<shift)) P_TOP[1]     = (s->me.ymax<<shift);
749
-            if(P_TOPRIGHT[0] < (s->me.xmin<<shift)) P_TOPRIGHT[0]= (s->me.xmin<<shift);
750
-            if(P_TOPRIGHT[0] > (s->me.xmax<<shift)) P_TOPRIGHT[0]= (s->me.xmax<<shift);
751
-            if(P_TOPRIGHT[1] > (s->me.ymax<<shift)) P_TOPRIGHT[1]= (s->me.ymax<<shift);
748
+            if(P_TOP[1]      > (c->ymax<<shift)) P_TOP[1]     = (c->ymax<<shift);
749
+            if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift);
750
+            if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift);
751
+            if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift);
752 752
     
753 753
             P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
754 754
             P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
755 755
 
756
-            s->me.pred_x= pred_x4 = P_MEDIAN[0];
757
-            s->me.pred_y= pred_y4 = P_MEDIAN[1];
756
+            c->pred_x= pred_x4 = P_MEDIAN[0];
757
+            c->pred_y= pred_y4 = P_MEDIAN[1];
758 758
         }
759 759
         P_MV1[0]= mx;
760 760
         P_MV1[1]= my;
761 761
 
762 762
         dmin4 = epzs_motion_search4(s, &mx4, &my4, P, block, block, s->p_mv_table, (1<<16)>>shift);
763 763
 
764
-        dmin4= s->me.sub_motion_search(s, &mx4, &my4, dmin4, block, block, size, h);
764
+        dmin4= c->sub_motion_search(s, &mx4, &my4, dmin4, block, block, size, h);
765 765
         
766 766
         if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){
767 767
             int dxy;
768 768
             const int offset= ((block&1) + (block>>1)*stride)*8;
769
-            uint8_t *dest_y = s->me.scratchpad + offset;
769
+            uint8_t *dest_y = c->scratchpad + offset;
770 770
             if(s->quarter_sample){
771 771
                 uint8_t *ref= c->ref[block][0] + (mx4>>2) + (my4>>2)*stride;
772 772
                 dxy = ((my4 & 3) << 2) | (mx4 & 3);
... ...
@@ -784,7 +785,7 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
784 784
                 else
785 785
                     s->dsp.put_pixels_tab       [1][dxy](dest_y    , ref    , stride, h);
786 786
             }
787
-            dmin_sum+= (mv_penalty[mx4-pred_x4] + mv_penalty[my4-pred_y4])*s->me.mb_penalty_factor;
787
+            dmin_sum+= (mv_penalty[mx4-pred_x4] + mv_penalty[my4-pred_y4])*c->mb_penalty_factor;
788 788
         }else
789 789
             dmin_sum+= dmin4;
790 790
 
... ...
@@ -806,7 +807,7 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
806 806
         return INT_MAX;
807 807
     
808 808
     if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){
809
-        dmin_sum += s->dsp.mb_cmp[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*16*stride, s->me.scratchpad, stride, 16);
809
+        dmin_sum += s->dsp.mb_cmp[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*16*stride, c->scratchpad, stride, 16);
810 810
     }
811 811
     
812 812
     if(s->avctx->mb_cmp&FF_CMP_CHROMA){
... ...
@@ -821,19 +822,19 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
821 821
         offset= (s->mb_x*8 + (mx>>1)) + (s->mb_y*8 + (my>>1))*s->uvlinesize;
822 822
        
823 823
         if(s->no_rounding){
824
-            s->dsp.put_no_rnd_pixels_tab[1][dxy](s->me.scratchpad    , s->last_picture.data[1] + offset, s->uvlinesize, 8);
825
-            s->dsp.put_no_rnd_pixels_tab[1][dxy](s->me.scratchpad+8  , s->last_picture.data[2] + offset, s->uvlinesize, 8);
824
+            s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad    , s->last_picture.data[1] + offset, s->uvlinesize, 8);
825
+            s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad+8  , s->last_picture.data[2] + offset, s->uvlinesize, 8);
826 826
         }else{
827
-            s->dsp.put_pixels_tab       [1][dxy](s->me.scratchpad    , s->last_picture.data[1] + offset, s->uvlinesize, 8);
828
-            s->dsp.put_pixels_tab       [1][dxy](s->me.scratchpad+8  , s->last_picture.data[2] + offset, s->uvlinesize, 8);
827
+            s->dsp.put_pixels_tab       [1][dxy](c->scratchpad    , s->last_picture.data[1] + offset, s->uvlinesize, 8);
828
+            s->dsp.put_pixels_tab       [1][dxy](c->scratchpad+8  , s->last_picture.data[2] + offset, s->uvlinesize, 8);
829 829
         }
830 830
 
831
-        dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, s->me.scratchpad  , s->uvlinesize, 8);
832
-        dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, s->me.scratchpad+8, s->uvlinesize, 8);
831
+        dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad  , s->uvlinesize, 8);
832
+        dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad+8, s->uvlinesize, 8);
833 833
     }
834 834
     
835
-    s->me.pred_x= mx;
836
-    s->me.pred_y= my;
835
+    c->pred_x= mx;
836
+    c->pred_y= my;
837 837
 
838 838
     switch(s->avctx->mb_cmp&0xFF){
839 839
     /*case FF_CMP_SSE:
... ...
@@ -841,7 +842,7 @@ static inline int h263_mv4_search(MpegEncContext *s, int mx, int my, int shift)
841 841
     case FF_CMP_RD:
842 842
         return dmin_sum;
843 843
     default:
844
-        return dmin_sum+ 11*s->me.mb_penalty_factor;
844
+        return dmin_sum+ 11*c->mb_penalty_factor;
845 845
     }
846 846
 }
847 847
 
... ...
@@ -898,8 +899,8 @@ static int interlaced_search(MpegEncContext *s, int ref_index,
898 898
             P_LEFT[1] = mv_table[xy - 1][1];
899 899
             if(P_LEFT[0]       > (c->xmax<<1)) P_LEFT[0]       = (c->xmax<<1);
900 900
             
901
-            s->me.pred_x= P_LEFT[0];
902
-            s->me.pred_y= P_LEFT[1];
901
+            c->pred_x= P_LEFT[0];
902
+            c->pred_y= P_LEFT[1];
903 903
             
904 904
             if(!s->first_slice_line){
905 905
                 P_TOP[0]      = mv_table[xy - mot_stride][0];
... ...
@@ -937,7 +938,7 @@ static int interlaced_search(MpegEncContext *s, int ref_index,
937 937
                     s->dsp.put_pixels_tab       [size][dxy](c->scratchpad, ref    , stride, h);
938 938
                 }
939 939
                 dmin= s->dsp.mb_cmp[size](s, c->src[block][0], c->scratchpad, stride, h);
940
-                dmin+= (mv_penalty[mx_i-s->me.pred_x] + mv_penalty[my_i-s->me.pred_y] + 1)*c->mb_penalty_factor;
940
+                dmin+= (mv_penalty[mx_i-c->pred_x] + mv_penalty[my_i-c->pred_y] + 1)*c->mb_penalty_factor;
941 941
             }else
942 942
                 dmin+= c->mb_penalty_factor; //field_select bits
943 943
                 
... ...
@@ -1117,19 +1118,19 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
1117 1117
     int mb_type=0;
1118 1118
     Picture * const pic= &s->current_picture;
1119 1119
     
1120
-    init_ref(s, s->new_picture.data, s->last_picture.data, NULL, 16*mb_x, 16*mb_y, 0);
1120
+    init_ref(c, s->new_picture.data, s->last_picture.data, NULL, 16*mb_x, 16*mb_y, 0);
1121 1121
 
1122 1122
     assert(s->quarter_sample==0 || s->quarter_sample==1);
1123
-    assert(s->linesize == s->me.stride);
1124
-    assert(s->uvlinesize == s->me.uvstride);
1123
+    assert(s->linesize == c->stride);
1124
+    assert(s->uvlinesize == c->uvstride);
1125 1125
 
1126
-    s->me.penalty_factor    = get_penalty_factor(s, s->avctx->me_cmp);
1127
-    s->me.sub_penalty_factor= get_penalty_factor(s, s->avctx->me_sub_cmp);
1128
-    s->me.mb_penalty_factor = get_penalty_factor(s, s->avctx->mb_cmp);
1129
-    s->me.current_mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV;
1126
+    c->penalty_factor    = get_penalty_factor(s, s->avctx->me_cmp);
1127
+    c->sub_penalty_factor= get_penalty_factor(s, s->avctx->me_sub_cmp);
1128
+    c->mb_penalty_factor = get_penalty_factor(s, s->avctx->mb_cmp);
1129
+    c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;
1130 1130
 
1131 1131
     get_limits(s, 16*mb_x, 16*mb_y);
1132
-    s->me.skip=0;
1132
+    c->skip=0;
1133 1133
 
1134 1134
     /* intra / predictive decision */
1135 1135
     pix = c->src[0][0];
... ...
@@ -1191,16 +1192,16 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
1191 1191
             P_LEFT[0]       = s->current_picture.motion_val[0][mot_xy - 1][0];
1192 1192
             P_LEFT[1]       = s->current_picture.motion_val[0][mot_xy - 1][1];
1193 1193
 
1194
-            if(P_LEFT[0]       > (s->me.xmax<<shift)) P_LEFT[0]       = (s->me.xmax<<shift);
1194
+            if(P_LEFT[0]       > (c->xmax<<shift)) P_LEFT[0]       = (c->xmax<<shift);
1195 1195
 
1196 1196
             if(!s->first_slice_line) {
1197 1197
                 P_TOP[0]      = s->current_picture.motion_val[0][mot_xy - mot_stride    ][0];
1198 1198
                 P_TOP[1]      = s->current_picture.motion_val[0][mot_xy - mot_stride    ][1];
1199 1199
                 P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][0];
1200 1200
                 P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][1];
1201
-                if(P_TOP[1]      > (s->me.ymax<<shift)) P_TOP[1]     = (s->me.ymax<<shift);
1202
-                if(P_TOPRIGHT[0] < (s->me.xmin<<shift)) P_TOPRIGHT[0]= (s->me.xmin<<shift);
1203
-                if(P_TOPRIGHT[1] > (s->me.ymax<<shift)) P_TOPRIGHT[1]= (s->me.ymax<<shift);
1201
+                if(P_TOP[1]      > (c->ymax<<shift)) P_TOP[1]     = (c->ymax<<shift);
1202
+                if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift);
1203
+                if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift);
1204 1204
         
1205 1205
                 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
1206 1206
                 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
... ...
@@ -1243,7 +1244,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
1243 1243
             s->scene_change_score+= s->qscale;
1244 1244
 
1245 1245
         if(mb_type == CANDIDATE_MB_TYPE_INTER){
1246
-            s->me.sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
1246
+            c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
1247 1247
             set_p_mv_tables(s, mx, my, 1);
1248 1248
         }else{
1249 1249
             mx <<=shift;
... ...
@@ -1267,7 +1268,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
1267 1267
             mb_type|= CANDIDATE_MB_TYPE_INTRA;
1268 1268
         if (varc*2 + 200 > vard){
1269 1269
             mb_type|= CANDIDATE_MB_TYPE_INTER;
1270
-            s->me.sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
1270
+            c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
1271 1271
             if(s->flags&CODEC_FLAG_MV0)
1272 1272
                 if(mx || my)
1273 1273
                     mb_type |= CANDIDATE_MB_TYPE_SKIPED; //FIXME check difference
... ...
@@ -1276,7 +1277,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
1276 1276
             my <<=shift;
1277 1277
         }
1278 1278
         if((s->flags&CODEC_FLAG_4MV)
1279
-           && !s->me.skip && varc>50 && vard>10){
1279
+           && !c->skip && varc>50 && vard>10){
1280 1280
             if(h263_mv4_search(s, mx, my, shift) < INT_MAX)
1281 1281
                 mb_type|=CANDIDATE_MB_TYPE_INTER4V;
1282 1282
 
... ...
@@ -1284,7 +1285,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
1284 1284
         }else
1285 1285
             set_p_mv_tables(s, mx, my, 1);
1286 1286
         if((s->flags&CODEC_FLAG_INTERLACED_ME)
1287
-           && !s->me.skip){ //FIXME varc/d checks
1287
+           && !c->skip){ //FIXME varc/d checks
1288 1288
             if(interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 0) < INT_MAX)
1289 1289
                 mb_type |= CANDIDATE_MB_TYPE_INTER_I;
1290 1290
         }
... ...
@@ -1292,12 +1293,12 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
1292 1292
         int intra_score, i;
1293 1293
         mb_type= CANDIDATE_MB_TYPE_INTER;
1294 1294
 
1295
-        dmin= s->me.sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
1296
-        if(s->avctx->me_sub_cmp != s->avctx->mb_cmp && !s->me.skip)
1295
+        dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
1296
+        if(s->avctx->me_sub_cmp != s->avctx->mb_cmp && !c->skip)
1297 1297
             dmin= get_mb_score(s, mx, my, 0, 0);
1298 1298
 
1299 1299
         if((s->flags&CODEC_FLAG_4MV)
1300
-           && !s->me.skip && varc>50 && vard>10){
1300
+           && !c->skip && varc>50 && vard>10){
1301 1301
             int dmin4= h263_mv4_search(s, mx, my, shift);
1302 1302
             if(dmin4 < dmin){
1303 1303
                 mb_type= CANDIDATE_MB_TYPE_INTER4V;
... ...
@@ -1305,7 +1306,7 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
1305 1305
             }
1306 1306
         }
1307 1307
         if((s->flags&CODEC_FLAG_INTERLACED_ME)
1308
-           && !s->me.skip){ //FIXME varc/d checks
1308
+           && !c->skip){ //FIXME varc/d checks
1309 1309
             int dmin_i= interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 0);
1310 1310
             if(dmin_i < dmin){
1311 1311
                 mb_type = CANDIDATE_MB_TYPE_INTER_I;
... ...
@@ -1324,13 +1325,13 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
1324 1324
             mean*= 0x01010101;
1325 1325
             
1326 1326
             for(i=0; i<16; i++){
1327
-                *(uint32_t*)(&s->me.scratchpad[i*s->linesize+ 0]) = mean;
1328
-                *(uint32_t*)(&s->me.scratchpad[i*s->linesize+ 4]) = mean;
1329
-                *(uint32_t*)(&s->me.scratchpad[i*s->linesize+ 8]) = mean;
1330
-                *(uint32_t*)(&s->me.scratchpad[i*s->linesize+12]) = mean;
1327
+                *(uint32_t*)(&c->scratchpad[i*s->linesize+ 0]) = mean;
1328
+                *(uint32_t*)(&c->scratchpad[i*s->linesize+ 4]) = mean;
1329
+                *(uint32_t*)(&c->scratchpad[i*s->linesize+ 8]) = mean;
1330
+                *(uint32_t*)(&c->scratchpad[i*s->linesize+12]) = mean;
1331 1331
             }
1332 1332
 
1333
-            intra_score= s->dsp.mb_cmp[0](s, s->me.scratchpad, pix, s->linesize, 16);
1333
+            intra_score= s->dsp.mb_cmp[0](s, c->scratchpad, pix, s->linesize, 16);
1334 1334
         }
1335 1335
 #if 0 //FIXME
1336 1336
         /* get chroma score */
... ...
@@ -1348,15 +1349,15 @@ void ff_estimate_p_frame_motion(MpegEncContext * s,
1348 1348
                 
1349 1349
                 mean*= 0x01010101;
1350 1350
                 for(i=0; i<8; i++){
1351
-                    *(uint32_t*)(&s->me.scratchpad[i*s->uvlinesize+ 0]) = mean;
1352
-                    *(uint32_t*)(&s->me.scratchpad[i*s->uvlinesize+ 4]) = mean;
1351
+                    *(uint32_t*)(&c->scratchpad[i*s->uvlinesize+ 0]) = mean;
1352
+                    *(uint32_t*)(&c->scratchpad[i*s->uvlinesize+ 4]) = mean;
1353 1353
                 }
1354 1354
                 
1355
-                intra_score+= s->dsp.mb_cmp[1](s, s->me.scratchpad, dest_c, s->uvlinesize);
1355
+                intra_score+= s->dsp.mb_cmp[1](s, c->scratchpad, dest_c, s->uvlinesize);
1356 1356
             }                
1357 1357
         }
1358 1358
 #endif
1359
-        intra_score += s->me.mb_penalty_factor*16;
1359
+        intra_score += c->mb_penalty_factor*16;
1360 1360
         
1361 1361
         if(intra_score < dmin){
1362 1362
             mb_type= CANDIDATE_MB_TYPE_INTRA;
... ...
@@ -1382,20 +1383,20 @@ int ff_pre_estimate_p_frame_motion(MpegEncContext * s,
1382 1382
     int P[10][2];
1383 1383
     const int shift= 1+s->quarter_sample;
1384 1384
     const int xy= mb_x + mb_y*s->mb_stride;
1385
-    init_ref(s, s->new_picture.data, s->last_picture.data, NULL, 16*mb_x, 16*mb_y, 0);
1385
+    init_ref(c, s->new_picture.data, s->last_picture.data, NULL, 16*mb_x, 16*mb_y, 0);
1386 1386
     
1387 1387
     assert(s->quarter_sample==0 || s->quarter_sample==1);
1388 1388
 
1389
-    s->me.pre_penalty_factor    = get_penalty_factor(s, s->avctx->me_pre_cmp);
1390
-    s->me.current_mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV;
1389
+    c->pre_penalty_factor    = get_penalty_factor(s, s->avctx->me_pre_cmp);
1390
+    c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;
1391 1391
 
1392 1392
     get_limits(s, 16*mb_x, 16*mb_y);
1393
-    s->me.skip=0;
1393
+    c->skip=0;
1394 1394
 
1395 1395
     P_LEFT[0]       = s->p_mv_table[xy + 1][0];
1396 1396
     P_LEFT[1]       = s->p_mv_table[xy + 1][1];
1397 1397
 
1398
-    if(P_LEFT[0]       < (s->me.xmin<<shift)) P_LEFT[0]       = (s->me.xmin<<shift);
1398
+    if(P_LEFT[0]       < (c->xmin<<shift)) P_LEFT[0]       = (c->xmin<<shift);
1399 1399
 
1400 1400
     /* special case for first line */
1401 1401
     if (s->first_slice_line) {
... ...
@@ -1408,9 +1409,9 @@ int ff_pre_estimate_p_frame_motion(MpegEncContext * s,
1408 1408
         P_TOP[1]      = s->p_mv_table[xy + s->mb_stride    ][1];
1409 1409
         P_TOPRIGHT[0] = s->p_mv_table[xy + s->mb_stride - 1][0];
1410 1410
         P_TOPRIGHT[1] = s->p_mv_table[xy + s->mb_stride - 1][1];
1411
-        if(P_TOP[1]      < (s->me.ymin<<shift)) P_TOP[1]     = (s->me.ymin<<shift);
1412
-        if(P_TOPRIGHT[0] > (s->me.xmax<<shift)) P_TOPRIGHT[0]= (s->me.xmax<<shift);
1413
-        if(P_TOPRIGHT[1] < (s->me.ymin<<shift)) P_TOPRIGHT[1]= (s->me.ymin<<shift);
1411
+        if(P_TOP[1]      < (c->ymin<<shift)) P_TOP[1]     = (c->ymin<<shift);
1412
+        if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift);
1413
+        if(P_TOPRIGHT[1] < (c->ymin<<shift)) P_TOPRIGHT[1]= (c->ymin<<shift);
1414 1414
     
1415 1415
         P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
1416 1416
         P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
... ...
@@ -1430,18 +1431,19 @@ int ff_pre_estimate_p_frame_motion(MpegEncContext * s,
1430 1430
 static int ff_estimate_motion_b(MpegEncContext * s,
1431 1431
                        int mb_x, int mb_y, int16_t (*mv_table)[2], int ref_index, int f_code)
1432 1432
 {
1433
+    MotionEstContext * const c= &s->me;
1433 1434
     int mx, my, dmin;
1434 1435
     int P[10][2];
1435 1436
     const int shift= 1+s->quarter_sample;
1436 1437
     const int mot_stride = s->mb_stride;
1437 1438
     const int mot_xy = mb_y*mot_stride + mb_x;
1438
-    uint8_t * const mv_penalty= s->me.mv_penalty[f_code] + MAX_MV;
1439
+    uint8_t * const mv_penalty= c->mv_penalty[f_code] + MAX_MV;
1439 1440
     int mv_scale;
1440 1441
         
1441
-    s->me.penalty_factor    = get_penalty_factor(s, s->avctx->me_cmp);
1442
-    s->me.sub_penalty_factor= get_penalty_factor(s, s->avctx->me_sub_cmp);
1443
-    s->me.mb_penalty_factor = get_penalty_factor(s, s->avctx->mb_cmp);
1444
-    s->me.current_mv_penalty= mv_penalty;
1442
+    c->penalty_factor    = get_penalty_factor(s, s->avctx->me_cmp);
1443
+    c->sub_penalty_factor= get_penalty_factor(s, s->avctx->me_sub_cmp);
1444
+    c->mb_penalty_factor = get_penalty_factor(s, s->avctx->mb_cmp);
1445
+    c->current_mv_penalty= mv_penalty;
1445 1446
 
1446 1447
     get_limits(s, 16*mb_x, 16*mb_y);
1447 1448
 
... ...
@@ -1476,7 +1478,7 @@ static int ff_estimate_motion_b(MpegEncContext * s,
1476 1476
             P_LEFT[0]        = mv_table[mot_xy - 1][0];
1477 1477
             P_LEFT[1]        = mv_table[mot_xy - 1][1];
1478 1478
 
1479
-            if(P_LEFT[0]       > (s->me.xmax<<shift)) P_LEFT[0]       = (s->me.xmax<<shift);
1479
+            if(P_LEFT[0]       > (c->xmax<<shift)) P_LEFT[0]       = (c->xmax<<shift);
1480 1480
 
1481 1481
             /* special case for first line */
1482 1482
             if (!s->first_slice_line) {
... ...
@@ -1484,15 +1486,15 @@ static int ff_estimate_motion_b(MpegEncContext * s,
1484 1484
                 P_TOP[1] = mv_table[mot_xy - mot_stride             ][1];
1485 1485
                 P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1         ][0];
1486 1486
                 P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1         ][1];
1487
-                if(P_TOP[1] > (s->me.ymax<<shift)) P_TOP[1]= (s->me.ymax<<shift);
1488
-                if(P_TOPRIGHT[0] < (s->me.xmin<<shift)) P_TOPRIGHT[0]= (s->me.xmin<<shift);
1489
-                if(P_TOPRIGHT[1] > (s->me.ymax<<shift)) P_TOPRIGHT[1]= (s->me.ymax<<shift);
1487
+                if(P_TOP[1] > (c->ymax<<shift)) P_TOP[1]= (c->ymax<<shift);
1488
+                if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift);
1489
+                if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift);
1490 1490
         
1491 1491
                 P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
1492 1492
                 P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
1493 1493
             }
1494
-            s->me.pred_x= P_LEFT[0];
1495
-            s->me.pred_y= P_LEFT[1];
1494
+            c->pred_x= P_LEFT[0];
1495
+            c->pred_y= P_LEFT[1];
1496 1496
         }
1497 1497
         
1498 1498
         if(mv_table == s->b_forw_mv_table){
... ...
@@ -1506,9 +1508,9 @@ static int ff_estimate_motion_b(MpegEncContext * s,
1506 1506
         break;
1507 1507
     }
1508 1508
     
1509
-    dmin= s->me.sub_motion_search(s, &mx, &my, dmin, 0, ref_index, 0, 16);
1509
+    dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, ref_index, 0, 16);
1510 1510
                                    
1511
-    if(s->avctx->me_sub_cmp != s->avctx->mb_cmp && !s->me.skip)
1511
+    if(s->avctx->me_sub_cmp != s->avctx->mb_cmp && !c->skip)
1512 1512
         dmin= get_mb_score(s, mx, my, 0, ref_index);
1513 1513
 
1514 1514
 //printf("%d %d %d %d//", s->mb_x, s->mb_y, mx, my);
... ...
@@ -1530,10 +1532,10 @@ static inline int check_bidir_mv(MpegEncContext * s,
1530 1530
     //FIXME better f_code prediction (max mv & distance)
1531 1531
     //FIXME pointers
1532 1532
     MotionEstContext * const c= &s->me;
1533
-    uint8_t * const mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV; // f_code of the prev frame
1534
-    int stride= s->me.stride;
1535
-    int uvstride= s->me.uvstride;
1536
-    uint8_t *dest_y = s->me.scratchpad;
1533
+    uint8_t * const mv_penalty= c->mv_penalty[s->f_code] + MAX_MV; // f_code of the prev frame
1534
+    int stride= c->stride;
1535
+    int uvstride= c->uvstride;
1536
+    uint8_t *dest_y = c->scratchpad;
1537 1537
     uint8_t *ptr;
1538 1538
     int dxy;
1539 1539
     int src_x, src_y;
... ...
@@ -1572,8 +1574,8 @@ static inline int check_bidir_mv(MpegEncContext * s,
1572 1572
         s->dsp.avg_pixels_tab[size][dxy](dest_y    , ptr    , stride, h);
1573 1573
     }
1574 1574
 
1575
-    fbmin = (mv_penalty[motion_fx-pred_fx] + mv_penalty[motion_fy-pred_fy])*s->me.mb_penalty_factor
1576
-           +(mv_penalty[motion_bx-pred_bx] + mv_penalty[motion_by-pred_by])*s->me.mb_penalty_factor
1575
+    fbmin = (mv_penalty[motion_fx-pred_fx] + mv_penalty[motion_fy-pred_fy])*c->mb_penalty_factor
1576
+           +(mv_penalty[motion_bx-pred_bx] + mv_penalty[motion_by-pred_by])*c->mb_penalty_factor
1577 1577
            + s->dsp.mb_cmp[size](s, src_data[0], dest_y, stride, h); //FIXME new_pic
1578 1578
            
1579 1579
     if(s->avctx->mb_cmp&FF_CMP_CHROMA){
... ...
@@ -1611,6 +1613,7 @@ static inline int bidir_refine(MpegEncContext * s, int mb_x, int mb_y)
1611 1611
 
1612 1612
 static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y)
1613 1613
 {
1614
+    MotionEstContext * const c= &s->me;
1614 1615
     int P[10][2];
1615 1616
     const int mot_stride = s->mb_stride;
1616 1617
     const int mot_xy = mb_y*mot_stride + mb_x;
... ...
@@ -1621,7 +1624,7 @@ static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y)
1621 1621
     int mx, my, xmin, xmax, ymin, ymax;
1622 1622
     int16_t (*mv_table)[2]= s->b_direct_mv_table;
1623 1623
     
1624
-    s->me.current_mv_penalty= s->me.mv_penalty[1] + MAX_MV;
1624
+    c->current_mv_penalty= c->mv_penalty[1] + MAX_MV;
1625 1625
     ymin= xmin=(-32)>>shift;
1626 1626
     ymax= xmax=   31>>shift;
1627 1627
 
... ...
@@ -1635,22 +1638,22 @@ static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y)
1635 1635
         int index= s->block_index[i];
1636 1636
         int min, max;
1637 1637
     
1638
-        s->me.co_located_mv[i][0]= s->next_picture.motion_val[0][index][0];
1639
-        s->me.co_located_mv[i][1]= s->next_picture.motion_val[0][index][1];
1640
-        s->me.direct_basis_mv[i][0]= s->me.co_located_mv[i][0]*time_pb/time_pp + ((i& 1)<<(shift+3));
1641
-        s->me.direct_basis_mv[i][1]= s->me.co_located_mv[i][1]*time_pb/time_pp + ((i>>1)<<(shift+3));
1642
-//        s->me.direct_basis_mv[1][i][0]= s->me.co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(shift+3);
1643
-//        s->me.direct_basis_mv[1][i][1]= s->me.co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(shift+3);
1644
-
1645
-        max= FFMAX(s->me.direct_basis_mv[i][0], s->me.direct_basis_mv[i][0] - s->me.co_located_mv[i][0])>>shift;
1646
-        min= FFMIN(s->me.direct_basis_mv[i][0], s->me.direct_basis_mv[i][0] - s->me.co_located_mv[i][0])>>shift;
1638
+        c->co_located_mv[i][0]= s->next_picture.motion_val[0][index][0];
1639
+        c->co_located_mv[i][1]= s->next_picture.motion_val[0][index][1];
1640
+        c->direct_basis_mv[i][0]= c->co_located_mv[i][0]*time_pb/time_pp + ((i& 1)<<(shift+3));
1641
+        c->direct_basis_mv[i][1]= c->co_located_mv[i][1]*time_pb/time_pp + ((i>>1)<<(shift+3));
1642
+//        c->direct_basis_mv[1][i][0]= c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(shift+3);
1643
+//        c->direct_basis_mv[1][i][1]= c->co_located_mv[i][1]*(time_pb - time_pp)/time_pp + ((i>>1)<<(shift+3);
1644
+
1645
+        max= FFMAX(c->direct_basis_mv[i][0], c->direct_basis_mv[i][0] - c->co_located_mv[i][0])>>shift;
1646
+        min= FFMIN(c->direct_basis_mv[i][0], c->direct_basis_mv[i][0] - c->co_located_mv[i][0])>>shift;
1647 1647
         max+= 16*mb_x + 1; // +-1 is for the simpler rounding
1648 1648
         min+= 16*mb_x - 1;
1649 1649
         xmax= FFMIN(xmax, s->width - max);
1650 1650
         xmin= FFMAX(xmin, - 16     - min);
1651 1651
 
1652
-        max= FFMAX(s->me.direct_basis_mv[i][1], s->me.direct_basis_mv[i][1] - s->me.co_located_mv[i][1])>>shift;
1653
-        min= FFMIN(s->me.direct_basis_mv[i][1], s->me.direct_basis_mv[i][1] - s->me.co_located_mv[i][1])>>shift;
1652
+        max= FFMAX(c->direct_basis_mv[i][1], c->direct_basis_mv[i][1] - c->co_located_mv[i][1])>>shift;
1653
+        min= FFMIN(c->direct_basis_mv[i][1], c->direct_basis_mv[i][1] - c->co_located_mv[i][1])>>shift;
1654 1654
         max+= 16*mb_y + 1; // +-1 is for the simpler rounding
1655 1655
         min+= 16*mb_y - 1;
1656 1656
         ymax= FFMIN(ymax, s->height - max);
... ...
@@ -1668,14 +1671,14 @@ static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y)
1668 1668
         return 256*256*256*64;
1669 1669
     }
1670 1670
     
1671
-    s->me.xmin= xmin;
1672
-    s->me.ymin= ymin;
1673
-    s->me.xmax= xmax;
1674
-    s->me.ymax= ymax;
1675
-    s->me.flags     |= FLAG_DIRECT;
1676
-    s->me.sub_flags |= FLAG_DIRECT;
1677
-    s->me.pred_x=0;
1678
-    s->me.pred_y=0;
1671
+    c->xmin= xmin;
1672
+    c->ymin= ymin;
1673
+    c->xmax= xmax;
1674
+    c->ymax= ymax;
1675
+    c->flags     |= FLAG_DIRECT;
1676
+    c->sub_flags |= FLAG_DIRECT;
1677
+    c->pred_x=0;
1678
+    c->pred_y=0;
1679 1679
 
1680 1680
     P_LEFT[0]        = clip(mv_table[mot_xy - 1][0], xmin<<shift, xmax<<shift);
1681 1681
     P_LEFT[1]        = clip(mv_table[mot_xy - 1][1], ymin<<shift, ymax<<shift);
... ...
@@ -1692,20 +1695,20 @@ static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y)
1692 1692
     }
1693 1693
  
1694 1694
     dmin = epzs_motion_search(s, &mx, &my, P, 0, 0, mv_table, 1<<(16-shift));
1695
-    if(s->me.sub_flags&FLAG_QPEL) 
1695
+    if(c->sub_flags&FLAG_QPEL) 
1696 1696
         dmin = qpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
1697 1697
     else
1698 1698
         dmin = hpel_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16);
1699 1699
     
1700
-    if(s->avctx->me_sub_cmp != s->avctx->mb_cmp && !s->me.skip)
1700
+    if(s->avctx->me_sub_cmp != s->avctx->mb_cmp && !c->skip)
1701 1701
         dmin= get_mb_score(s, mx, my, 0, 0);
1702 1702
     
1703
-    get_limits(s, 16*mb_x, 16*mb_y); //restore s->me.?min/max, maybe not needed
1703
+    get_limits(s, 16*mb_x, 16*mb_y); //restore c->?min/max, maybe not needed
1704 1704
 
1705 1705
     s->b_direct_mv_table[mot_xy][0]= mx;
1706 1706
     s->b_direct_mv_table[mot_xy][1]= my;
1707
-    s->me.flags     &= ~FLAG_DIRECT;
1708
-    s->me.sub_flags &= ~FLAG_DIRECT;
1707
+    c->flags     &= ~FLAG_DIRECT;
1708
+    c->sub_flags &= ~FLAG_DIRECT;
1709 1709
 
1710 1710
     return dmin;
1711 1711
 }
... ...
@@ -1713,14 +1716,15 @@ static inline int direct_search(MpegEncContext * s, int mb_x, int mb_y)
1713 1713
 void ff_estimate_b_frame_motion(MpegEncContext * s,
1714 1714
                              int mb_x, int mb_y)
1715 1715
 {
1716
-    const int penalty_factor= s->me.mb_penalty_factor;
1716
+    MotionEstContext * const c= &s->me;
1717
+    const int penalty_factor= c->mb_penalty_factor;
1717 1718
     int fmin, bmin, dmin, fbmin, bimin, fimin;
1718 1719
     int type=0;
1719 1720
     const int xy = mb_y*s->mb_stride + mb_x;
1720
-    init_ref(s, s->new_picture.data, s->last_picture.data, s->next_picture.data, 16*mb_x, 16*mb_y, 2);
1721
+    init_ref(c, s->new_picture.data, s->last_picture.data, s->next_picture.data, 16*mb_x, 16*mb_y, 2);
1721 1722
 
1722 1723
     
1723
-    s->me.skip=0;
1724
+    c->skip=0;
1724 1725
     if(s->avctx->me_threshold){
1725 1726
         int vard= (check_input_motion(s, mb_x, mb_y, 0)+128)>>8;
1726 1727
         
... ...
@@ -1747,23 +1751,23 @@ void ff_estimate_b_frame_motion(MpegEncContext * s,
1747 1747
                 direct_search(s, mb_x, mb_y);
1748 1748
             }
1749 1749
             if(type == CANDIDATE_MB_TYPE_FORWARD || type == CANDIDATE_MB_TYPE_BIDIR){
1750
-                s->me.skip=0;
1750
+                c->skip=0;
1751 1751
                 ff_estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code);
1752 1752
             }
1753 1753
             if(type == CANDIDATE_MB_TYPE_BACKWARD || type == CANDIDATE_MB_TYPE_BIDIR){
1754
-                s->me.skip=0;
1754
+                c->skip=0;
1755 1755
                 ff_estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code);
1756 1756
             }
1757 1757
             if(type == CANDIDATE_MB_TYPE_FORWARD_I || type == CANDIDATE_MB_TYPE_BIDIR_I){
1758
-                s->me.skip=0;
1759
-                s->me.current_mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV;
1758
+                c->skip=0;
1759
+                c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;
1760 1760
                 interlaced_search(s, 0,
1761 1761
                                         s->b_field_mv_table[0], s->b_field_select_table[0],
1762 1762
                                         s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1], 1);
1763 1763
             }
1764 1764
             if(type == CANDIDATE_MB_TYPE_BACKWARD_I || type == CANDIDATE_MB_TYPE_BIDIR_I){
1765
-                s->me.skip=0;
1766
-                s->me.current_mv_penalty= s->me.mv_penalty[s->b_code] + MAX_MV;
1765
+                c->skip=0;
1766
+                c->current_mv_penalty= c->mv_penalty[s->b_code] + MAX_MV;
1767 1767
                 interlaced_search(s, 2,
1768 1768
                                         s->b_field_mv_table[1], s->b_field_select_table[1],
1769 1769
                                         s->b_back_mv_table[xy][0], s->b_back_mv_table[xy][1], 1);
... ...
@@ -1777,25 +1781,25 @@ void ff_estimate_b_frame_motion(MpegEncContext * s,
1777 1777
     else
1778 1778
         dmin= INT_MAX;
1779 1779
 //FIXME penalty stuff for non mpeg4
1780
-    s->me.skip=0;
1780
+    c->skip=0;
1781 1781
     fmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_forw_mv_table, 0, s->f_code) + 3*penalty_factor;
1782 1782
     
1783
-    s->me.skip=0;
1783
+    c->skip=0;
1784 1784
     bmin= ff_estimate_motion_b(s, mb_x, mb_y, s->b_back_mv_table, 2, s->b_code) + 2*penalty_factor;
1785 1785
 //printf(" %d %d ", s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1]);
1786 1786
 
1787
-    s->me.skip=0;
1787
+    c->skip=0;
1788 1788
     fbmin= bidir_refine(s, mb_x, mb_y) + penalty_factor;
1789 1789
 //printf("%d %d %d %d\n", dmin, fmin, bmin, fbmin);
1790 1790
     
1791 1791
     if(s->flags & CODEC_FLAG_INTERLACED_ME){
1792 1792
 //FIXME mb type penalty
1793
-        s->me.skip=0;
1794
-        s->me.current_mv_penalty= s->me.mv_penalty[s->f_code] + MAX_MV;
1793
+        c->skip=0;
1794
+        c->current_mv_penalty= c->mv_penalty[s->f_code] + MAX_MV;
1795 1795
         fimin= interlaced_search(s, 0,
1796 1796
                                  s->b_field_mv_table[0], s->b_field_select_table[0],
1797 1797
                                  s->b_forw_mv_table[xy][0], s->b_forw_mv_table[xy][1], 0);
1798
-        s->me.current_mv_penalty= s->me.mv_penalty[s->b_code] + MAX_MV;
1798
+        c->current_mv_penalty= c->mv_penalty[s->b_code] + MAX_MV;
1799 1799
         bimin= interlaced_search(s, 2,
1800 1800
                                  s->b_field_mv_table[1], s->b_field_select_table[1],
1801 1801
                                  s->b_back_mv_table[xy][0], s->b_back_mv_table[xy][1], 0);
... ...
@@ -25,14 +25,14 @@
25 25
 
26 26
 //lets hope gcc will remove the unused vars ...(gcc 3.2.2 seems to do it ...)
27 27
 #define LOAD_COMMON\
28
-    uint32_t * const score_map= s->me.score_map;\
29
-    const int xmin= s->me.xmin;\
30
-    const int ymin= s->me.ymin;\
31
-    const int xmax= s->me.xmax;\
32
-    const int ymax= s->me.ymax;\
33
-    uint8_t *mv_penalty= s->me.current_mv_penalty;\
34
-    const int pred_x= s->me.pred_x;\
35
-    const int pred_y= s->me.pred_y;\
28
+    uint32_t * const score_map= c->score_map;\
29
+    const int xmin= c->xmin;\
30
+    const int ymin= c->ymin;\
31
+    const int xmax= c->xmax;\
32
+    const int ymax= c->ymax;\
33
+    uint8_t *mv_penalty= c->current_mv_penalty;\
34
+    const int pred_x= c->pred_x;\
35
+    const int pred_y= c->pred_y;\
36 36
 
37 37
 #define CHECK_HALF_MV(dx, dy, x, y)\
38 38
 {\
... ...
@@ -53,7 +53,7 @@ static int hpel_motion_search)(MpegEncContext * s,
53 53
     const int yy = 16 * s->mb_y + 8*(n>>1);
54 54
     const int mx = *mx_ptr;
55 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 58
     LOAD_COMMON
59 59
     
... ...
@@ -73,7 +73,7 @@ static int hpel_motion_search)(MpegEncContext * s,
73 73
     cmp_sub= s->dsp.me_sub_cmp[size];
74 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 77
         *mx_ptr = 0;
78 78
         *my_ptr = 0;
79 79
         return dmin;
... ...
@@ -117,21 +117,22 @@ static int hpel_motion_search(MpegEncContext * s,
117 117
                                   int src_index, int ref_index,
118 118
                                   int size, int h)
119 119
 {
120
+    MotionEstContext * const c= &s->me;
120 121
     const int mx = *mx_ptr;
121 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 124
     me_cmp_func cmp_sub, chroma_cmp_sub;
124 125
     int bx=2*mx, by=2*my;
125 126
 
126 127
     LOAD_COMMON
127
-    int flags= s->me.sub_flags;
128
+    int flags= c->sub_flags;
128 129
     
129 130
  //FIXME factorize
130 131
 
131 132
     cmp_sub= s->dsp.me_sub_cmp[size];
132 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 136
         *mx_ptr = 0;
136 137
         *my_ptr = 0;
137 138
         return dmin;
... ...
@@ -148,19 +149,19 @@ static int hpel_motion_search(MpegEncContext * s,
148 148
         int d= dmin;
149 149
         const int index= (my<<ME_MAP_SHIFT) + mx;
150 150
         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;
151
+                     + (mv_penalty[bx   - pred_x] + mv_penalty[by-2 - pred_y])*c->penalty_factor;
152 152
         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;
153
+                     + (mv_penalty[bx-2 - pred_x] + mv_penalty[by   - pred_y])*c->penalty_factor;
154 154
         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;
155
+                     + (mv_penalty[bx+2 - pred_x] + mv_penalty[by   - pred_y])*c->penalty_factor;
156 156
         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;
157
+                     + (mv_penalty[bx   - pred_x] + mv_penalty[by+2 - pred_y])*c->penalty_factor;
158 158
     
159 159
 #if 1
160 160
         int key;
161
-        int map_generation= s->me.map_generation;
161
+        int map_generation= c->map_generation;
162 162
 #ifndef NDEBUG
163
-        uint32_t *map= s->me.map;
163
+        uint32_t *map= c->map;
164 164
 #endif
165 165
         key= ((my-1)<<ME_MAP_MV_BITS) + (mx) + map_generation;
166 166
         assert(map[(index-(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)] == key);
... ...
@@ -224,10 +225,11 @@ static int inline get_mb_score(MpegEncContext * s, int mx, int my, int src_index
224 224
                                int ref_index)
225 225
 {
226 226
 //    const int check_luma= s->dsp.me_sub_cmp != s->dsp.mb_cmp;
227
+    MotionEstContext * const c= &s->me;
227 228
     const int size= 0;
228 229
     const int h= 16;
229
-    const int penalty_factor= s->me.mb_penalty_factor;
230
-    const int flags= s->me.mb_flags;
230
+    const int penalty_factor= c->mb_penalty_factor;
231
+    const int flags= c->mb_flags;
231 232
     const int qpel= flags & FLAG_QPEL;
232 233
     const int mask= 1+2*qpel;
233 234
     me_cmp_func cmp_sub, chroma_cmp_sub;
... ...
@@ -240,7 +242,7 @@ static int inline get_mb_score(MpegEncContext * s, int mx, int my, int src_index
240 240
     cmp_sub= s->dsp.mb_cmp[size];
241 241
     chroma_cmp_sub= s->dsp.mb_cmp[size+1];
242 242
     
243
-    assert(!s->me.skip);
243
+    assert(!c->skip);
244 244
     assert(s->avctx->me_sub_cmp != s->avctx->mb_cmp);
245 245
 
246 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);
... ...
@@ -265,17 +267,18 @@ static int qpel_motion_search(MpegEncContext * s,
265 265
                                   int src_index, int ref_index,                                  
266 266
                                   int size, int h)
267 267
 {
268
+    MotionEstContext * const c= &s->me;
268 269
     const int mx = *mx_ptr;
269 270
     const int my = *my_ptr;   
270
-    const int penalty_factor= s->me.sub_penalty_factor;
271
-    const int map_generation= s->me.map_generation;
271
+    const int penalty_factor= c->sub_penalty_factor;
272
+    const int map_generation= c->map_generation;
272 273
     const int subpel_quality= s->avctx->me_subpel_quality;
273
-    uint32_t *map= s->me.map;
274
+    uint32_t *map= c->map;
274 275
     me_cmp_func cmpf, chroma_cmpf;
275 276
     me_cmp_func cmp_sub, chroma_cmp_sub;
276 277
 
277 278
     LOAD_COMMON
278
-    int flags= s->me.sub_flags;
279
+    int flags= c->sub_flags;
279 280
     
280 281
     cmpf= s->dsp.me_cmp[size];
281 282
     chroma_cmpf= s->dsp.me_cmp[size+1]; //factorize FIXME
... ...
@@ -284,7 +287,7 @@ static int qpel_motion_search(MpegEncContext * s,
284 284
     cmp_sub= s->dsp.me_sub_cmp[size];
285 285
     chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
286 286
 
287
-    if(s->me.skip){ //FIXME somehow move up (benchmark)
287
+    if(c->skip){ //FIXME somehow move up (benchmark)
288 288
         *mx_ptr = 0;
289 289
         *my_ptr = 0;
290 290
         return dmin;
... ...
@@ -330,8 +333,8 @@ static int qpel_motion_search(MpegEncContext * s,
330 330
                     
331 331
                     score += 1024*(mv_penalty[4*mx + nx - pred_x] + mv_penalty[4*my + ny - pred_y])*penalty_factor;
332 332
                     
333
-//                    if(nx&1) score-=1024*s->me.penalty_factor;
334
-//                    if(ny&1) score-=1024*s->me.penalty_factor;
333
+//                    if(nx&1) score-=1024*c->penalty_factor;
334
+//                    if(ny&1) score-=1024*c->penalty_factor;
335 335
                     
336 336
                     for(i=0; i<8; i++){
337 337
                         if(score < best[i]){
... ...
@@ -375,8 +378,8 @@ static int qpel_motion_search(MpegEncContext * s,
375 375
                     if((nx&3)==0 && (ny&3)==0) continue;
376 376
                 
377 377
                     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;
379
-  //                  if(ny&1) score-=32*s->me.penalty_factor;
378
+//                    if(nx&1) score-=32*c->penalty_factor;
379
+  //                  if(ny&1) score-=32*c->penalty_factor;
380 380
                     
381 381
                     for(i=0; i<8; i++){
382 382
                         if(score < best[i]){
... ...
@@ -531,7 +534,7 @@ if( (y)<(ymin<<(S)) ) printf("%d %d %d %d %d ymin" #v, ymin, (x), (y), s->mb_x,
531 531
 if( (y)>(ymax<<(S)) ) printf("%d %d %d %d %d ymax" #v, ymax, (x), (y), s->mb_x, s->mb_y);\
532 532
 
533 533
 #define LOAD_COMMON2\
534
-    uint32_t *map= s->me.map;\
534
+    uint32_t *map= c->map;\
535 535
     const int qpel= flags&FLAG_QPEL;\
536 536
     const int shift= 1+qpel;\
537 537
 
... ...
@@ -539,11 +542,12 @@ static always_inline int small_diamond_search(MpegEncContext * s, int *best, int
539 539
                                        int src_index, int ref_index, int const penalty_factor,
540 540
                                        int size, int h, int flags)
541 541
 {
542
+    MotionEstContext * const c= &s->me;
542 543
     me_cmp_func cmpf, chroma_cmpf;
543 544
     int next_dir=-1;
544 545
     LOAD_COMMON
545 546
     LOAD_COMMON2
546
-    int map_generation= s->me.map_generation;
547
+    int map_generation= c->map_generation;
547 548
     
548 549
     cmpf= s->dsp.me_cmp[size];
549 550
     chroma_cmpf= s->dsp.me_cmp[size+1];
... ...
@@ -580,11 +584,12 @@ static int funny_diamond_search(MpegEncContext * s, int *best, int dmin,
580 580
                                        int src_index, int ref_index, int const penalty_factor,
581 581
                                        int size, int h, int flags)
582 582
 {
583
+    MotionEstContext * const c= &s->me;
583 584
     me_cmp_func cmpf, chroma_cmpf;
584 585
     int dia_size;
585 586
     LOAD_COMMON
586 587
     LOAD_COMMON2
587
-    int map_generation= s->me.map_generation;
588
+    int map_generation= c->map_generation;
588 589
     
589 590
     cmpf= s->dsp.me_cmp[size];
590 591
     chroma_cmpf= s->dsp.me_cmp[size+1];
... ...
@@ -670,13 +675,14 @@ static int sab_diamond_search(MpegEncContext * s, int *best, int dmin,
670 670
                                        int src_index, int ref_index, int const penalty_factor,
671 671
                                        int size, int h, int flags)
672 672
 {
673
+    MotionEstContext * const c= &s->me;
673 674
     me_cmp_func cmpf, chroma_cmpf;
674 675
     Minima minima[MAX_SAB_SIZE];
675
-    const int minima_count= ABS(s->me.dia_size);
676
+    const int minima_count= ABS(c->dia_size);
676 677
     int i, j;
677 678
     LOAD_COMMON
678 679
     LOAD_COMMON2
679
-    int map_generation= s->me.map_generation;
680
+    int map_generation= c->map_generation;
680 681
     
681 682
     cmpf= s->dsp.me_cmp[size];
682 683
     chroma_cmpf= s->dsp.me_cmp[size+1];
... ...
@@ -749,16 +755,17 @@ static int var_diamond_search(MpegEncContext * s, int *best, int dmin,
749 749
                                        int src_index, int ref_index, int const penalty_factor,
750 750
                                        int size, int h, int flags)
751 751
 {
752
+    MotionEstContext * const c= &s->me;
752 753
     me_cmp_func cmpf, chroma_cmpf;
753 754
     int dia_size;
754 755
     LOAD_COMMON
755 756
     LOAD_COMMON2
756
-    int map_generation= s->me.map_generation;
757
+    int map_generation= c->map_generation;
757 758
     
758 759
     cmpf= s->dsp.me_cmp[size];
759 760
     chroma_cmpf= s->dsp.me_cmp[size+1];
760 761
 
761
-    for(dia_size=1; dia_size<=s->me.dia_size; dia_size++){
762
+    for(dia_size=1; dia_size<=c->dia_size; dia_size++){
762 763
         int dir, start, end;
763 764
         const int x= best[0];
764 765
         const int y= best[1];
... ...
@@ -824,11 +831,12 @@ if(256*256*256*64 % (stats[0]+1)==0){
824 824
 static always_inline int diamond_search(MpegEncContext * s, int *best, int dmin,
825 825
                                        int src_index, int ref_index, int const penalty_factor,
826 826
                                        int size, int h, int flags){
827
-    if(s->me.dia_size==-1)
827
+    MotionEstContext * const c= &s->me;
828
+    if(c->dia_size==-1)
828 829
         return funny_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
829
-    else if(s->me.dia_size<-1)
830
+    else if(c->dia_size<-1)
830 831
         return   sab_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
831
-    else if(s->me.dia_size<2)
832
+    else if(c->dia_size<2)
832 833
         return small_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
833 834
     else
834 835
         return   var_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
... ...
@@ -838,10 +846,11 @@ static always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx
838 838
                              int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2], 
839 839
                              int ref_mv_scale, int flags)
840 840
 {
841
+    MotionEstContext * const c= &s->me;
841 842
     int best[2]={0, 0};
842 843
     int d, dmin;
843 844
     int map_generation;
844
-    const int penalty_factor= s->me.penalty_factor;
845
+    const int penalty_factor= c->penalty_factor;
845 846
     const int size=0;
846 847
     const int h=16;
847 848
     const int ref_mv_stride= s->mb_stride; //pass as arg  FIXME
... ...
@@ -854,7 +863,7 @@ static always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx
854 854
     cmpf= s->dsp.me_cmp[size];
855 855
     chroma_cmpf= s->dsp.me_cmp[size+1];
856 856
     
857
-    map_generation= update_map_generation(s);
857
+    map_generation= update_map_generation(c);
858 858
 
859 859
     dmin= cmp(s, 0, 0, 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
860 860
     map[0]= map_generation;
... ...
@@ -871,7 +880,7 @@ static always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx
871 871
                         |P_TOPRIGHT[0]|P_TOPRIGHT[1])==0){
872 872
             *mx_ptr= 0;
873 873
             *my_ptr= 0;
874
-            s->me.skip=1;
874
+            c->skip=1;
875 875
             return dmin;
876 876
         }
877 877
         CHECK_MV(P_MEDIAN[0]>>shift, P_MEDIAN[1]>>shift)
... ...
@@ -884,7 +893,7 @@ static always_inline int epzs_motion_search_internal(MpegEncContext * s, int *mx
884 884
         }
885 885
     }
886 886
     if(dmin>256*4){
887
-        if(s->me.pre_pass){
887
+        if(c->pre_pass){
888 888
             CHECK_CLIPED_MV((last_mv[ref_mv_xy-1][0]*ref_mv_scale + (1<<15))>>16, 
889 889
                             (last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16)
890 890
             if(!s->first_slice_line)
... ...
@@ -936,14 +945,15 @@ static inline int epzs_motion_search(MpegEncContext * s, int *mx_ptr, int *my_pt
936 936
                              int P[10][2], int src_index, int ref_index, int16_t (*last_mv)[2], 
937 937
                              int ref_mv_scale)
938 938
 {
939
+    MotionEstContext * const c= &s->me;
939 940
 //FIXME convert other functions in the same way if faster
940
-    switch(s->me.flags){
941
+    switch(c->flags){
941 942
     case 0:
942 943
         return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, 0);
943 944
 //    case FLAG_QPEL:
944 945
 //        return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, FLAG_QPEL);
945 946
     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);
947
+        return epzs_motion_search_internal(s, mx_ptr, my_ptr, P, src_index, ref_index, last_mv, ref_mv_scale, c->flags);
947 948
     }
948 949
 }
949 950
 
... ...
@@ -952,23 +962,24 @@ static int epzs_motion_search4(MpegEncContext * s,
952 952
                              int src_index, int ref_index, int16_t (*last_mv)[2], 
953 953
                              int ref_mv_scale)
954 954
 {
955
+    MotionEstContext * const c= &s->me;
955 956
     int best[2]={0, 0};
956 957
     int d, dmin; 
957 958
     int map_generation;
958
-    const int penalty_factor= s->me.penalty_factor;
959
+    const int penalty_factor= c->penalty_factor;
959 960
     const int size=1;
960 961
     const int h=8;
961 962
     const int ref_mv_stride= s->mb_stride;
962 963
     const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
963 964
     me_cmp_func cmpf, chroma_cmpf;
964 965
     LOAD_COMMON
965
-    int flags= s->me.flags;
966
+    int flags= c->flags;
966 967
     LOAD_COMMON2
967 968
     
968 969
     cmpf= s->dsp.me_cmp[size];
969 970
     chroma_cmpf= s->dsp.me_cmp[size+1];
970 971
 
971
-    map_generation= update_map_generation(s);
972
+    map_generation= update_map_generation(c);
972 973
 
973 974
     dmin = 1000000;
974 975
 //printf("%d %d %d %d //",xmin, ymin, xmax, ymax); 
... ...
@@ -1013,23 +1024,24 @@ static int epzs_motion_search2(MpegEncContext * s,
1013 1013
                              int src_index, int ref_index, int16_t (*last_mv)[2], 
1014 1014
                              int ref_mv_scale)
1015 1015
 {
1016
+    MotionEstContext * const c= &s->me;
1016 1017
     int best[2]={0, 0};
1017 1018
     int d, dmin; 
1018 1019
     int map_generation;
1019
-    const int penalty_factor= s->me.penalty_factor;
1020
+    const int penalty_factor= c->penalty_factor;
1020 1021
     const int size=0; //FIXME pass as arg
1021 1022
     const int h=8;
1022 1023
     const int ref_mv_stride= s->mb_stride;
1023 1024
     const int ref_mv_xy= s->mb_x + s->mb_y *ref_mv_stride;
1024 1025
     me_cmp_func cmpf, chroma_cmpf;
1025 1026
     LOAD_COMMON
1026
-    int flags= s->me.flags;
1027
+    int flags= c->flags;
1027 1028
     LOAD_COMMON2
1028 1029
     
1029 1030
     cmpf= s->dsp.me_cmp[size];
1030 1031
     chroma_cmpf= s->dsp.me_cmp[size+1];
1031 1032
 
1032
-    map_generation= update_map_generation(s);
1033
+    map_generation= update_map_generation(c);
1033 1034
 
1034 1035
     dmin = 1000000;
1035 1036
 //printf("%d %d %d %d //",xmin, ymin, xmax, ymax);