changeset 288:f82cce6cb182 libavcodec

10l (motion_val was uninitilized) 20l (first frame of a gop could be a p-frame sometimes) add hq flag to MpegEncContext
author michaelni
date Sun, 24 Mar 2002 04:16:51 +0000
parents 32a3dcce2e9b
children 648e9245546d
files motion_est.c mpegvideo.c mpegvideo.h
diffstat 3 files changed, 33 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/motion_est.c	Sat Mar 23 20:21:33 2002 +0000
+++ b/motion_est.c	Sun Mar 24 04:16:51 2002 +0000
@@ -579,7 +579,6 @@
     int mx, my, mx1, my1, d, xx, yy, dminh;
     UINT8 *pix, *ptr;
 
-    
     mx = *mx_ptr;
     my = *my_ptr;
     ptr = s->last_picture[0] + (my * s->linesize) + mx;
@@ -678,17 +677,18 @@
     case ME_PHODS:
 	dmin = phods_motion_search(s, &mx, &my, range / 2, xmin, ymin, xmax, ymax);
         break;
-    case ME_X1: // just reserving some space for experiments ...
+    case ME_X1:
     case ME_EPZS:
-        rel_xmin= xmin - s->mb_x*16;
-        rel_xmax= xmax - s->mb_x*16;
-        rel_ymin= ymin - s->mb_y*16;
-        rel_ymax= ymax - s->mb_y*16;
-        if(s->out_format == FMT_H263){
+       {
             static const int off[4]= {2, 1, 1, -1};
             const int mot_stride = s->mb_width*2 + 2;
             const int mot_xy = (s->mb_y*2 + 1)*mot_stride + s->mb_x*2 + 1;
-         
+
+            rel_xmin= xmin - s->mb_x*16;
+            rel_xmax= xmax - s->mb_x*16;
+            rel_ymin= ymin - s->mb_y*16;
+            rel_ymax= ymax - s->mb_y*16;
+
             P[0][0] = s->motion_val[mot_xy    ][0];
             P[0][1] = s->motion_val[mot_xy    ][1];
             P[1][0] = s->motion_val[mot_xy - 1][0];
@@ -697,8 +697,8 @@
 
             /* special case for first line */
             if ((s->mb_y == 0 || s->first_slice_line || s->first_gob_line)) {
-                pred_x = P[1][0];
-                pred_y = P[1][1];
+                P[4][0] = P[1][0];
+                P[4][1] = P[1][1];
             } else {
                 P[2][0] = s->motion_val[mot_xy - mot_stride             ][0];
                 P[2][1] = s->motion_val[mot_xy - mot_stride             ][1];
@@ -708,38 +708,16 @@
                 if(P[3][0] < (rel_xmin<<shift)) P[3][0]= (rel_xmin<<shift);
                 if(P[3][1] > (rel_ymax<<shift)) P[3][1]= (rel_ymax<<shift);
         
-                P[4][0]= pred_x = mid_pred(P[1][0], P[2][0], P[3][0]);
-                P[4][1]= pred_y = mid_pred(P[1][1], P[2][1], P[3][1]);
-            }
-        }else {
-            const int xy= s->mb_y*s->mb_width + s->mb_x;
-            pred_x= s->last_mv[0][0][0];
-            pred_y= s->last_mv[0][0][1];
-
-            P[0][0]= s->mv_table[0][xy  ];
-            P[0][1]= s->mv_table[1][xy  ];
-            if(s->mb_x == 0){
-                P[1][0]= 0;
-                P[1][1]= 0;
-            }else{
-                P[1][0]= s->mv_table[0][xy-1];
-                P[1][1]= s->mv_table[1][xy-1];
-                if(P[1][0] > (rel_xmax<<shift)) P[1][0]= (rel_xmax<<shift);
-            }
-    
-            if (!(s->mb_y == 0 || s->first_slice_line || s->first_gob_line)) {
-                P[2][0] = s->mv_table[0][xy - s->mb_width];
-                P[2][1] = s->mv_table[1][xy - s->mb_width];
-                P[3][0] = s->mv_table[0][xy - s->mb_width+1];
-                P[3][1] = s->mv_table[1][xy - s->mb_width+1];
-                if(P[2][1] > (rel_ymax<<shift)) P[2][1]= (rel_ymax<<shift);
-                if(P[3][0] > (rel_xmax<<shift)) P[3][0]= (rel_xmax<<shift);
-                if(P[3][0] < (rel_xmin<<shift)) P[3][0]= (rel_xmin<<shift);
-                if(P[3][1] > (rel_ymax<<shift)) P[3][1]= (rel_ymax<<shift);
-        
                 P[4][0]= mid_pred(P[1][0], P[2][0], P[3][0]);
                 P[4][1]= mid_pred(P[1][1], P[2][1], P[3][1]);
             }
+            if(s->out_format == FMT_H263){
+                pred_x = P[4][0];
+                pred_y = P[4][1];
+            }else { /* mpeg1 at least */
+                pred_x= P[1][0];
+                pred_y= P[1][1];
+            }
         }
         dmin = epzs_motion_search(s, &mx, &my, P, pred_x, pred_y, rel_xmin, rel_ymin, rel_xmax, rel_ymax);
  
--- a/mpegvideo.c	Sat Mar 23 20:21:33 2002 +0000
+++ b/mpegvideo.c	Sun Mar 24 04:16:51 2002 +0000
@@ -174,7 +174,7 @@
         }
     }
     
-    if (s->out_format == FMT_H263) {
+    if (s->out_format == FMT_H263 || s->encoding) {
         int size;
         /* MV prediction */
         size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);
@@ -295,6 +295,7 @@
     s->qblur= avctx->qblur;
     s->avctx = avctx;
     s->aspect_ratio_info= avctx->aspect_ratio_info;
+    s->hq= (avctx->flags & CODEC_FLAG_HQ);
     
     if (s->gop_size <= 1) {
         s->intra_only = 1;
@@ -506,7 +507,7 @@
 
     if (!s->intra_only) {
         /* first picture of GOP is intra */
-        if (s->picture_in_gop_number >= s->gop_size){
+        if (s->picture_in_gop_number % s->gop_size==0){
             s->picture_in_gop_number=0;
             s->pict_type = I_TYPE;
         }else
@@ -1097,6 +1098,8 @@
     for(mb_y=0; mb_y < s->mb_height; mb_y++) {
         for(mb_x=0; mb_x < s->mb_width; mb_x++) {
             int xy= mb_y * s->mb_width + mb_x;
+            const int mot_stride = s->mb_width*2 + 2;
+            int mot_xy = (mb_y*2 + 1)*mot_stride + mb_x*2 + 1;
             s->mb_x = mb_x;
             s->mb_y = mb_y;
 
@@ -1114,6 +1117,16 @@
             s->mb_type[xy] = s->mb_intra;
             s->mv_table[0][xy] = motion_x;
             s->mv_table[1][xy] = motion_y;
+
+            s->motion_val[mot_xy  ][0]= motion_x;
+            s->motion_val[mot_xy  ][1]= motion_y;
+            s->motion_val[mot_xy+1][0]= motion_x;
+            s->motion_val[mot_xy+1][1]= motion_y;
+            mot_xy += mot_stride;
+            s->motion_val[mot_xy  ][0]= motion_x;
+            s->motion_val[mot_xy  ][1]= motion_y;
+            s->motion_val[mot_xy+1][0]= motion_x;
+            s->motion_val[mot_xy+1][1]= motion_y;
         }
     }
     emms_c();
--- a/mpegvideo.h	Sat Mar 23 20:21:33 2002 +0000
+++ b/mpegvideo.h	Sun Mar 24 04:16:51 2002 +0000
@@ -65,6 +65,7 @@
     int qmax;         /* max qscale */
     int max_qdiff;    /* max qscale difference between frames */
     int encoding;     /* true if we are encoding (vs decoding) */
+    int hq;           /* set if CODEC_FLAG_HQ is used in AVCodecContext.flags */
     /* the following fields are managed internally by the encoder */
 
     /* bit output */