[vlc-devel] [PATCH 3/3] codec: x264: remove duplicate checks on configuration range

Zhao Zhili quinkblack at foxmail.com
Tue Aug 28 05:50:06 CEST 2018


The range is already limited by change_integer_range.

Some code also checks whether the configuration has the default value or
not, and don't assign to x264_param_t if it's the default value. It
based on the precondition that the default values are the same as x264
param_default() set.
---
 modules/codec/x264.c | 64 ++++++++++++++++------------------------------------
 1 file changed, 20 insertions(+), 44 deletions(-)

diff --git a/modules/codec/x264.c b/modules/codec/x264.c
index 0efd802..97bc823 100644
--- a/modules/codec/x264.c
+++ b/modules/codec/x264.c
@@ -953,31 +953,20 @@ static int  Open ( vlc_object_t *p_this )
     else /* Set default to CRF */
     {
         i_val = var_GetInteger( p_enc, SOUT_CFG_PREFIX "crf" );
-        if( i_val > 0 && i_val <= 51 )
-        {
-            p_sys->param.rc.f_rf_constant = i_val;
-            p_sys->param.rc.i_rc_method = X264_RC_CRF;
-        }
+        p_sys->param.rc.f_rf_constant = i_val;
+        p_sys->param.rc.i_rc_method = X264_RC_CRF;
     }
 
     i_val = var_GetInteger( p_enc, SOUT_CFG_PREFIX "qpstep" );
-    if( i_val >= 0 && i_val <= 51 ) p_sys->param.rc.i_qp_step = i_val;
+    p_sys->param.rc.i_qp_step = i_val;
 
-    i_val = var_GetInteger( p_enc, SOUT_CFG_PREFIX "qpmin" );
-    if( i_val >= 0 && i_val <= 51 )
-    {
-        i_qmin = i_val;
-        p_sys->param.rc.i_qp_min = i_qmin;
-    }
-    i_val = var_GetInteger( p_enc, SOUT_CFG_PREFIX "qpmax" );
-    if( i_val >= 0 && i_val <= 51 )
-    {
-        i_qmax = i_val;
-        p_sys->param.rc.i_qp_max = i_qmax;
-    }
+    i_qmin = var_GetInteger( p_enc, SOUT_CFG_PREFIX "qpmin" );
+    p_sys->param.rc.i_qp_min = i_qmin;
+    i_qmax = var_GetInteger( p_enc, SOUT_CFG_PREFIX "qpmax" );
+    p_sys->param.rc.i_qp_max = i_qmax;
 
     i_val = var_GetInteger( p_enc, SOUT_CFG_PREFIX "qp" );
-    if( i_val >= 0 && i_val <= 51 )
+    if( i_val >= 0 )
     {
         if( i_qmin > i_val ) i_qmin = i_val;
         if( i_qmax < i_val ) i_qmax = i_val;
@@ -1088,8 +1077,7 @@ static int  Open ( vlc_object_t *p_this )
     p_sys->param.b_bluray_compat = var_GetBool( p_enc, SOUT_CFG_PREFIX "bluray-compat" );
 
     i_val = var_GetInteger( p_enc, SOUT_CFG_PREFIX "bframes" );
-    if( i_val >= 0 && i_val <= 16 && i_val != 3 )
-        p_sys->param.i_bframe = i_val;
+    p_sys->param.i_bframe = i_val;
 
     p_sys->param.b_intra_refresh = var_GetBool( p_enc, SOUT_CFG_PREFIX "intra-refresh" );
 
@@ -1110,12 +1098,10 @@ static int  Open ( vlc_object_t *p_this )
     free( psz_val );
 
     i_val = var_GetInteger( p_enc, SOUT_CFG_PREFIX "ref" );
-    if( i_val > 0 && i_val <= 15 && i_val != 3 )
-        p_sys->param.i_frame_reference = i_val;
+    p_sys->param.i_frame_reference = i_val;
 
     i_val = var_GetInteger( p_enc, SOUT_CFG_PREFIX "scenecut" );
-    if( i_val >= -1 && i_val <= 100 && i_val != 40 )
-        p_sys->param.i_scenecut_threshold = i_val;
+    p_sys->param.i_scenecut_threshold = i_val;
 
     p_sys->param.b_deterministic = var_GetBool( p_enc,
                         SOUT_CFG_PREFIX "non-deterministic" );
@@ -1155,8 +1141,7 @@ static int  Open ( vlc_object_t *p_this )
     free( psz_val );
 
     i_val = var_GetInteger( p_enc, SOUT_CFG_PREFIX "merange" );
-    if( i_val >= 0 && i_val <= 64 && i_val != 16 )
-        p_sys->param.analyse.i_me_range = i_val;
+    p_sys->param.analyse.i_me_range = i_val;
 
     p_sys->param.analyse.i_mv_range = var_GetInteger( p_enc,
                                     SOUT_CFG_PREFIX "mvrange" );
@@ -1191,12 +1176,10 @@ static int  Open ( vlc_object_t *p_this )
        p_sys->param.analyse.i_weighted_pred = var_GetInteger( p_enc, SOUT_CFG_PREFIX "weightp" );
 
     i_val = var_GetInteger( p_enc, SOUT_CFG_PREFIX "b-adapt" );
-    if( i_val != 1 )
-       p_sys->param.i_bframe_adaptive = i_val;
+    p_sys->param.i_bframe_adaptive = i_val;
 
     i_val = var_GetInteger( p_enc, SOUT_CFG_PREFIX "b-bias" );
-    if( i_val >= -100 && i_val <= 100 && i_val != 0)
-        p_sys->param.i_bframe_bias = i_val;
+    p_sys->param.i_bframe_bias = i_val;
 
     p_sys->param.analyse.b_chroma_me = var_GetBool( p_enc,
                                     SOUT_CFG_PREFIX "chroma-me" );
@@ -1207,28 +1190,24 @@ static int  Open ( vlc_object_t *p_this )
                                     SOUT_CFG_PREFIX "mixed-refs" );
 
     i_val = var_GetInteger( p_enc, SOUT_CFG_PREFIX "trellis" );
-    if( i_val >= 0 && i_val <= 2 && i_val != 1 )
-        p_sys->param.analyse.i_trellis = i_val;
+    p_sys->param.analyse.i_trellis = i_val;
 
     if( !var_GetBool( p_enc, SOUT_CFG_PREFIX "fast-pskip" ) )
        p_sys->param.analyse.b_fast_pskip = var_GetBool( p_enc,
                                     SOUT_CFG_PREFIX "fast-pskip" );
 
     i_val = var_GetInteger( p_enc, SOUT_CFG_PREFIX "nr" );
-    if( i_val > 0 && i_val <= 1000 )
-        p_sys->param.analyse.i_noise_reduction = i_val;
+    p_sys->param.analyse.i_noise_reduction = i_val;
 
     if( !var_GetBool( p_enc, SOUT_CFG_PREFIX "dct-decimate" ) )
        p_sys->param.analyse.b_dct_decimate = var_GetBool( p_enc,
                                     SOUT_CFG_PREFIX "dct-decimate" );
 
     i_val = var_GetInteger( p_enc, SOUT_CFG_PREFIX "deadzone-inter" );
-    if( i_val >= 0 && i_val <= 32 && i_val != 21 )
-        p_sys->param.analyse.i_luma_deadzone[0] = i_val;
+    p_sys->param.analyse.i_luma_deadzone[0] = i_val;
 
     i_val = var_GetInteger( p_enc, SOUT_CFG_PREFIX "deadzone-intra" );
-    if( i_val >= 0 && i_val <= 32 && i_val != 11)
-        p_sys->param.analyse.i_luma_deadzone[1] = i_val;
+    p_sys->param.analyse.i_luma_deadzone[1] = i_val;
 
     if( !var_GetBool( p_enc, SOUT_CFG_PREFIX "asm" ) )
         p_sys->param.cpu = 0;
@@ -1340,7 +1319,7 @@ static int  Open ( vlc_object_t *p_this )
     }
 
     i_val = var_GetInteger( p_enc, SOUT_CFG_PREFIX "pass" );
-    if( i_val > 0 && i_val <= 3 )
+    if( i_val > 0 )
     {
         p_sys->param.rc.b_stat_write = i_val & 1;
         p_sys->param.rc.b_stat_read = i_val & 2;
@@ -1369,10 +1348,7 @@ static int  Open ( vlc_object_t *p_this )
     vlc_mutex_unlock( &pthread_win32_mutex );
 #endif
 
-    if( var_GetInteger( p_enc, SOUT_CFG_PREFIX "lookahead" ) != 40 )
-    {
-       p_sys->param.rc.i_lookahead = var_GetInteger( p_enc, SOUT_CFG_PREFIX "lookahead" );
-    }
+    p_sys->param.rc.i_lookahead = var_GetInteger( p_enc, SOUT_CFG_PREFIX "lookahead" );
 
     /* We don't want repeated headers, we repeat p_extra ourself if needed */
     p_sys->param.b_repeat_headers = 0;
-- 
2.9.5





More information about the vlc-devel mailing list