Hotfix for some bugs in VBV emergency
authorAnton Mitrofanov <BugMaster@narod.ru>
Sat, 29 Jan 2011 20:43:34 +0000 (12:43 -0800)
committerJason Garrett-Glaser <jason@x264.com>
Sat, 29 Jan 2011 20:46:35 +0000 (12:46 -0800)
encoder/cabac.c
encoder/cavlc.c
encoder/encoder.c
encoder/set.c
x264.c

index a553190..6333737 100644 (file)
@@ -265,9 +265,9 @@ static void x264_cabac_mb_qp_delta( x264_t *h, x264_cabac_t *cb )
     if( i_dqp != 0 )
     {
         int val = i_dqp <= 0 ? (-2*i_dqp) : (2*i_dqp - 1);
-        /* dqp is interpreted modulo (QP_MAX+1) */
-        if( val >= QP_MAX && val != QP_MAX+1 )
-            val = 2*QP_MAX+1 - val;
+        /* dqp is interpreted modulo (QP_MAX_SPEC+1) */
+        if( val >= QP_MAX_SPEC && val != QP_MAX_SPEC+1 )
+            val = 2*QP_MAX_SPEC+1 - val;
         do
         {
             x264_cabac_encode_decision( cb, 60 + ctx, 1 );
index 4d6b1dd..720cd18 100644 (file)
@@ -222,10 +222,10 @@ static void cavlc_qp_delta( x264_t *h )
 
     if( i_dqp )
     {
-        if( i_dqp < -(QP_MAX+1)/2 )
-            i_dqp += QP_MAX+1;
-        else if( i_dqp > QP_MAX/2 )
-            i_dqp -= QP_MAX+1;
+        if( i_dqp < -(QP_MAX_SPEC+1)/2 )
+            i_dqp += QP_MAX_SPEC+1;
+        else if( i_dqp > QP_MAX_SPEC/2 )
+            i_dqp -= QP_MAX_SPEC+1;
     }
     bs_write_se( s, i_dqp );
 }
index 217bfa8..0182c8c 100644 (file)
@@ -1066,7 +1066,7 @@ x264_t *x264_encoder_open( x264_param_t *param )
     x264_log( h, X264_LOG_INFO, "%s\n", buf );
 
     int qp_max = h->param.rc.i_qp_max == QP_MAX_SPEC ? QP_MAX : h->param.rc.i_qp_max;
-    for( qp = h->param.rc.i_qp_min; qp <= qp_max; qp++ )
+    for( qp = X264_MIN( h->param.rc.i_qp_min, QP_MAX_SPEC ); qp <= qp_max; qp++ )
         if( x264_analyse_init_costs( h, qp ) )
             goto fail;
     if( x264_analyse_init_costs( h, X264_LOOKAHEAD_QP ) )
index ee19574..077eeae 100644 (file)
@@ -445,7 +445,7 @@ void x264_pps_init( x264_pps_t *pps, int i_id, x264_param_t *param, x264_sps_t *
     pps->b_weighted_pred = param->analyse.i_weighted_pred > 0;
     pps->b_weighted_bipred = param->analyse.b_weighted_bipred ? 2 : 0;
 
-    pps->i_pic_init_qp = param->rc.i_rc_method == X264_RC_ABR ? 26 + QP_BD_OFFSET : param->rc.i_qp_constant;
+    pps->i_pic_init_qp = param->rc.i_rc_method == X264_RC_ABR ? 26 + QP_BD_OFFSET : SPEC_QP( param->rc.i_qp_constant );
     pps->i_pic_init_qs = 26 + QP_BD_OFFSET;
 
     pps->i_chroma_qp_index_offset = param->analyse.i_chroma_qp_offset;
diff --git a/x264.c b/x264.c
index c0d7a0f..c6261d8 100644 (file)
--- a/x264.c
+++ b/x264.c
@@ -568,7 +568,7 @@ static void help( x264_param_t *defaults, int longhelp )
     H0( "\n" );
     H1( "  -q, --qp <integer>          Force constant QP (0-%d, 0=lossless)\n", QP_MAX );
     H0( "  -B, --bitrate <integer>     Set bitrate (kbit/s)\n" );
-    H0( "      --crf <float>           Quality-based VBR (%d-51) [%.1f]\n", 51 - QP_MAX, defaults->rc.f_rf_constant );
+    H0( "      --crf <float>           Quality-based VBR (%d-51) [%.1f]\n", 51 - QP_MAX_SPEC, defaults->rc.f_rf_constant );
     H1( "      --rc-lookahead <integer> Number of frames for frametype lookahead [%d]\n", defaults->rc.i_lookahead );
     H0( "      --vbv-maxrate <integer> Max local bitrate (kbit/s) [%d]\n", defaults->rc.i_vbv_max_bitrate );
     H0( "      --vbv-bufsize <integer> Set size of the VBV buffer (kbit) [%d]\n", defaults->rc.i_vbv_buffer_size );