Fix intra-refresh + hrd
authorKieran Kunhya <kierank@ob-encoder.com>
Tue, 27 Mar 2012 16:38:56 +0000 (17:38 +0100)
committerFiona Glaser <fiona@x264.com>
Tue, 27 Mar 2012 16:43:57 +0000 (09:43 -0700)
common/common.h
encoder/encoder.c
encoder/slicetype.c

index fab453e..a3149c0 100644 (file)
@@ -513,6 +513,7 @@ struct x264_t
     int64_t         i_cpb_delay_lookahead;
 
     int64_t         i_cpb_delay_pir_offset;
+    int64_t         i_cpb_delay_pir_offset_next;
 
     int             b_queued_intra_refresh;
     int64_t         i_last_idr_pts;
index 88897ef..e193e55 100644 (file)
@@ -2735,6 +2735,7 @@ int     x264_encoder_encode( x264_t *h,
     if( h->param.cpu&X264_CPU_SSE_MISALIGN )
         x264_cpu_mask_misalign_sse();
 #endif
+    h->i_cpb_delay_pir_offset = h->i_cpb_delay_pir_offset_next;
 
     /* no data out */
     *pi_nal = 0;
@@ -3125,7 +3126,7 @@ int     x264_encoder_encode( x264_t *h,
     }
 
     if( h->fenc->b_keyframe && h->param.b_intra_refresh )
-        h->i_cpb_delay_pir_offset = h->fenc->i_cpb_delay;
+        h->i_cpb_delay_pir_offset_next = h->fenc->i_cpb_delay;
 
     /* Init the rate control */
     /* FIXME: Include slice header bit cost. */
index af08184..0b20f66 100644 (file)
@@ -1067,7 +1067,8 @@ static void x264_calculate_durations( x264_t *h, x264_frame_t *cur_frame, x264_f
             prev_frame->i_cpb_duration += cur_frame->i_dpb_output_delay;
     }
 
-    if( cur_frame->b_keyframe )
+    // don't reset cpb delay for IDR frames when using intra-refresh
+    if( cur_frame->b_keyframe && !h->param.b_intra_refresh )
         *i_cpb_delay = 0;
 
     *i_cpb_delay += cur_frame->i_duration;