]> git.videolan.org Git - x264.git/commitdiff
Fix intra refresh behavior with I-frames
authorJason Garrett-Glaser <darkshikari@gmail.com>
Sat, 8 May 2010 18:58:22 +0000 (11:58 -0700)
committerJason Garrett-Glaser <darkshikari@gmail.com>
Sat, 8 May 2010 18:58:22 +0000 (11:58 -0700)
Intra refresh still allows I-frames (for scenecuts/etc).
Now I-frames count as a full refresh, as opposed to instantly triggering a refresh.

common/frame.h
encoder/encoder.c

index 357929eafe667fa74098012bd371e47cb385a060..e2766ad8f4c4d604206d55553a84d01a2989366a 100644 (file)
@@ -142,6 +142,7 @@ typedef struct x264_frame
     float   f_pir_position;
     int     i_pir_start_col;
     int     i_pir_end_col;
+    int     i_frames_since_pir;
 } x264_frame_t;
 
 /* synchronized frame list */
index 7ad4295b9675fe01a85a91688f637635efb193e5..7c5a64fb6734f1f40a843eb560013af3de44e4aa 100644 (file)
@@ -2375,25 +2375,31 @@ int     x264_encoder_encode( x264_t *h,
     h->i_nal_type = i_nal_type;
     h->i_nal_ref_idc = i_nal_ref_idc;
 
-    if( h->param.b_intra_refresh && h->fenc->i_type == X264_TYPE_P )
+    if( h->param.b_intra_refresh )
     {
-        int pocdiff = (h->fdec->i_poc - h->fref0[0]->i_poc)/2;
-        float increment = X264_MAX( ((float)h->sps->i_mb_width-1) / h->param.i_keyint_max, 1 );
-        int max_position = (int)(increment * h->param.i_keyint_max);
-        if( IS_X264_TYPE_I( h->fref0[0]->i_type ) )
-            h->fdec->f_pir_position = 0;
-        else
+        if( IS_X264_TYPE_I( h->fenc->i_type ) )
+        {
+            h->fdec->i_frames_since_pir = 0;
+            /* PIR is currently only supported with ref == 1, so any intra frame effectively refreshes
+             * the whole frame and counts as an intra refresh. */
+            h->fdec->f_pir_position = h->sps->i_mb_width;
+        }
+        else if( h->fenc->i_type == X264_TYPE_P )
         {
+            int pocdiff = (h->fdec->i_poc - h->fref0[0]->i_poc)/2;
+            float increment = X264_MAX( ((float)h->sps->i_mb_width-1) / h->param.i_keyint_max, 1 );
             h->fdec->f_pir_position = h->fref0[0]->f_pir_position;
-            if( h->fdec->f_pir_position+0.5 >= max_position )
+            h->fdec->i_frames_since_pir = h->fref0[0]->i_frames_since_pir + pocdiff;
+            if( h->fdec->i_frames_since_pir >= h->param.i_keyint_max )
             {
                 h->fdec->f_pir_position = 0;
+                h->fdec->i_frames_since_pir = 0;
                 h->fenc->b_keyframe = 1;
             }
+            h->fdec->i_pir_start_col = h->fdec->f_pir_position+0.5;
+            h->fdec->f_pir_position += increment * pocdiff;
+            h->fdec->i_pir_end_col = h->fdec->f_pir_position+0.5;
         }
-        h->fdec->i_pir_start_col = h->fdec->f_pir_position+0.5;
-        h->fdec->f_pir_position += increment * pocdiff;
-        h->fdec->i_pir_end_col = h->fdec->f_pir_position+0.5;
     }
 
     if( h->fenc->b_keyframe )