changeset 952:f348d302a51e libavcodec

pre motion estimation cleanup/bugfix
author michaelni
date Thu, 02 Jan 2003 12:48:09 +0000
parents ad264a7d4f94
children 9eb066d6e0db
files motion_est.c motion_est_template.c mpegvideo.c mpegvideo.h
diffstat 4 files changed, 30 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/motion_est.c	Thu Jan 02 01:29:35 2003 +0000
+++ b/motion_est.c	Thu Jan 02 12:48:09 2003 +0000
@@ -803,7 +803,7 @@
         if(P_LEFT[0]       > (rel_xmax4<<shift)) P_LEFT[0]       = (rel_xmax4<<shift);
 
         /* special case for first line */
-        if ((s->mb_y == 0 || s->first_slice_line) && block<2) {
+        if (s->mb_y == 0 && block<2) {
             pred_x4= P_LEFT[0];
             pred_y4= P_LEFT[1];
         } else {
@@ -904,11 +904,7 @@
 
             if(P_LEFT[0]       > (rel_xmax<<shift)) P_LEFT[0]       = (rel_xmax<<shift);
 
-            /* special case for first line */
-            if ((mb_y == 0 || s->first_slice_line)) {
-                pred_x= P_LEFT[0];
-                pred_y= P_LEFT[1];
-            } else {
+            if(mb_y) {
                 P_TOP[0]      = s->motion_val[mot_xy - mot_stride    ][0];
                 P_TOP[1]      = s->motion_val[mot_xy - mot_stride    ][1];
                 P_TOPRIGHT[0] = s->motion_val[mot_xy - mot_stride + 2][0];
@@ -927,7 +923,11 @@
                     pred_x= P_LEFT[0];
                     pred_y= P_LEFT[1];
                 }
+            }else{
+                pred_x= P_LEFT[0];
+                pred_y= P_LEFT[1];
             }
+
         }
         dmin = s->me.motion_search[0](s, 0, &mx, &my, P, pred_x, pred_y, rel_xmin, rel_ymin, rel_xmax, rel_ymax, 
                                       &s->last_picture, s->p_mv_table, (1<<16)>>shift, mv_penalty);
@@ -1055,6 +1055,8 @@
     if (mb_y == s->mb_height-1) {
         pred_x= P_LEFT[0];
         pred_y= P_LEFT[1];
+        P_TOP[0]= P_TOPRIGHT[0]= P_MEDIAN[0]=
+        P_TOP[1]= P_TOPRIGHT[1]= P_MEDIAN[1]= 0; //FIXME 
     } else {
         P_TOP[0]      = s->p_mv_table[xy + mv_stride    ][0];
         P_TOP[1]      = s->p_mv_table[xy + mv_stride    ][1];
@@ -1067,17 +1069,12 @@
         P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]);
         P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]);
 
-        if(s->out_format == FMT_H263){
-            pred_x = P_MEDIAN[0];
-            pred_y = P_MEDIAN[1];
-        }else { /* mpeg1 at least */
-            pred_x= P_LEFT[0];
-            pred_y= P_LEFT[1];
-        }
+        pred_x = P_MEDIAN[0];
+        pred_y = P_MEDIAN[1];
     }
     dmin = s->me.motion_search[0](s, 0, &mx, &my, P, pred_x, pred_y, rel_xmin, rel_ymin, rel_xmax, rel_ymax, 
                                   &s->last_picture, s->p_mv_table, (1<<16)>>shift, mv_penalty);
-        
+
     s->p_mv_table[xy][0] = mx<<shift;
     s->p_mv_table[xy][1] = my<<shift;
     
@@ -1140,8 +1137,7 @@
             if(P_LEFT[0]       > (rel_xmax<<shift)) P_LEFT[0]       = (rel_xmax<<shift);
 
             /* special case for first line */
-            if ((mb_y == 0 || s->first_slice_line)) {
-            } else {
+            if (mb_y) {
                 P_TOP[0] = mv_table[mot_xy - mot_stride             ][0];
                 P_TOP[1] = mv_table[mot_xy - mot_stride             ][1];
                 P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1         ][0];
@@ -1332,8 +1328,7 @@
     P_LEFT[1]        = clip(mv_table[mot_xy - 1][1], ymin<<shift, ymax<<shift);
 
     /* special case for first line */
-    if ((mb_y == 0 || s->first_slice_line)) {
-    } else {
+    if (mb_y) {
         P_TOP[0]      = clip(mv_table[mot_xy - mot_stride             ][0], xmin<<shift, xmax<<shift);
         P_TOP[1]      = clip(mv_table[mot_xy - mot_stride             ][1], ymin<<shift, ymax<<shift);
         P_TOPRIGHT[0] = clip(mv_table[mot_xy - mot_stride + 1         ][0], xmin<<shift, xmax<<shift);
--- a/motion_est_template.c	Thu Jan 02 01:29:35 2003 +0000
+++ b/motion_est_template.c	Thu Jan 02 12:48:09 2003 +0000
@@ -835,7 +835,7 @@
     score_map[0]= dmin;
 
     /* first line */
-    if ((s->mb_y == 0 || s->first_slice_line)) {
+    if (s->mb_y == 0) {
         CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
         CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16, 
                         (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
@@ -858,10 +858,17 @@
         }
     }
     if(dmin>256*4){
-        CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16, 
-                        (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
-        CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16, 
-                        (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
+        if(s->me.pre_pass){
+            CHECK_CLIPED_MV((last_mv[ref_mv_xy-1][0]*ref_mv_scale + (1<<15))>>16, 
+                            (last_mv[ref_mv_xy-1][1]*ref_mv_scale + (1<<15))>>16)
+            CHECK_CLIPED_MV((last_mv[ref_mv_xy-ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16, 
+                            (last_mv[ref_mv_xy-ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
+        }else{
+            CHECK_CLIPED_MV((last_mv[ref_mv_xy+1][0]*ref_mv_scale + (1<<15))>>16, 
+                            (last_mv[ref_mv_xy+1][1]*ref_mv_scale + (1<<15))>>16)
+            CHECK_CLIPED_MV((last_mv[ref_mv_xy+ref_mv_stride][0]*ref_mv_scale + (1<<15))>>16, 
+                            (last_mv[ref_mv_xy+ref_mv_stride][1]*ref_mv_scale + (1<<15))>>16)
+        }
     }
 
     if(s->avctx->last_predictor_count){
@@ -938,7 +945,7 @@
     dmin = 1000000;
 //printf("%d %d %d %d //",xmin, ymin, xmax, ymax); 
     /* first line */
-    if ((s->mb_y == 0 || s->first_slice_line) && block<2) {
+    if (s->mb_y == 0 && block<2) {
 	CHECK_MV(P_LEFT[0]>>shift, P_LEFT[1]>>shift)
         CHECK_CLIPED_MV((last_mv[ref_mv_xy][0]*ref_mv_scale + (1<<15))>>16, 
                         (last_mv[ref_mv_xy][1]*ref_mv_scale + (1<<15))>>16)
--- a/mpegvideo.c	Thu Jan 02 01:29:35 2003 +0000
+++ b/mpegvideo.c	Thu Jan 02 12:48:09 2003 +0000
@@ -2789,9 +2789,10 @@
 
     /* Estimate motion for every MB */
     if(s->pict_type != I_TYPE){
-
         if(s->pict_type != B_TYPE){
             if((s->avctx->pre_me && s->last_non_b_pict_type==I_TYPE) || s->avctx->pre_me==2){
+                s->me.pre_pass=1;
+
                 for(mb_y=s->mb_height-1; mb_y >=0 ; mb_y--) {
                     for(mb_x=s->mb_width-1; mb_x >=0 ; mb_x--) {
                         s->mb_x = mb_x;
@@ -2799,6 +2800,7 @@
                         ff_pre_estimate_p_frame_motion(s, mb_x, mb_y);
                     }
                 }
+                s->me.pre_pass=0;
             }
         }
 
--- a/mpegvideo.h	Thu Jan 02 01:29:35 2003 +0000
+++ b/mpegvideo.h	Thu Jan 02 12:48:09 2003 +0000
@@ -141,6 +141,7 @@
     int map_generation;  
     int penalty_factor;
     int sub_penalty_factor;
+    int pre_pass;                      /* = 1 for the pre pass */
     UINT16 (*mv_penalty)[MAX_MV*2+1];  /* amount of bits needed to encode a MV */
     int (*sub_motion_search)(struct MpegEncContext * s,
 				  int *mx_ptr, int *my_ptr, int dmin,