[x264-devel] Fix corruption when using encoder_reconfig() with some parameters

Anton Mitrofanov git at videolan.org
Mon Jun 13 23:44:53 CEST 2016


x264 | branch: master | Anton Mitrofanov <BugMaster at narod.ru> | Sat Apr 23 22:45:44 2016 +0300| [928bd9d5def4f0ca5071ea176a11b816a01e6495] | committer: Henrik Gramner

Fix corruption when using encoder_reconfig() with some parameters

Changing parameters that affects SPS, like --ref for example, wasn't
behaving correctly previously.

Probably a regression in r2373.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=928bd9d5def4f0ca5071ea176a11b816a01e6495
---

 encoder/encoder.c |    3 ++-
 encoder/set.c     |   33 +++++++++++++++++++--------------
 encoder/set.h     |    1 +
 3 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/encoder/encoder.c b/encoder/encoder.c
index 66f8357..b614198 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -1144,6 +1144,7 @@ static int x264_validate_parameters( x264_t *h, int b_open )
     if( h->param.analyse.i_subpel_refine >= 10 && (h->param.analyse.i_trellis != 2 || !h->param.rc.i_aq_mode) )
         h->param.analyse.i_subpel_refine = 9;
 
+    if( b_open )
     {
         const x264_level_t *l = x264_levels;
         if( h->param.i_level_idc < 0 )
@@ -1813,7 +1814,7 @@ int x264_encoder_reconfig_apply( x264_t *h, x264_param_t *param )
 
     mbcmp_init( h );
     if( !ret )
-        x264_sps_init( h->sps, h->param.i_sps_id, &h->param );
+        x264_sps_init_reconfigurable( h->sps, &h->param );
 
     /* Supported reconfiguration options (1-pass only):
      * vbv-maxrate
diff --git a/encoder/set.c b/encoder/set.c
index 63560db..778add7 100644
--- a/encoder/set.c
+++ b/encoder/set.c
@@ -184,20 +184,7 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
     sps->b_mb_adaptive_frame_field = param->b_interlaced;
     sps->b_direct8x8_inference = 1;
 
-    sps->crop.i_left   = param->crop_rect.i_left;
-    sps->crop.i_top    = param->crop_rect.i_top;
-    sps->crop.i_right  = param->crop_rect.i_right + sps->i_mb_width*16 - param->i_width;
-    sps->crop.i_bottom = (param->crop_rect.i_bottom + sps->i_mb_height*16 - param->i_height) >> !sps->b_frame_mbs_only;
-    sps->b_crop = sps->crop.i_left  || sps->crop.i_top ||
-                  sps->crop.i_right || sps->crop.i_bottom;
-
-    sps->vui.b_aspect_ratio_info_present = 0;
-    if( param->vui.i_sar_width > 0 && param->vui.i_sar_height > 0 )
-    {
-        sps->vui.b_aspect_ratio_info_present = 1;
-        sps->vui.i_sar_width = param->vui.i_sar_width;
-        sps->vui.i_sar_height= param->vui.i_sar_height;
-    }
+    x264_sps_init_reconfigurable( sps, param );
 
     sps->vui.b_overscan_info_present = param->vui.i_overscan > 0 && param->vui.i_overscan <= 2;
     if( sps->vui.b_overscan_info_present )
@@ -262,6 +249,24 @@ void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param )
     }
 }
 
+void x264_sps_init_reconfigurable( x264_sps_t *sps, x264_param_t *param )
+{
+    sps->crop.i_left   = param->crop_rect.i_left;
+    sps->crop.i_top    = param->crop_rect.i_top;
+    sps->crop.i_right  = param->crop_rect.i_right + sps->i_mb_width*16 - param->i_width;
+    sps->crop.i_bottom = (param->crop_rect.i_bottom + sps->i_mb_height*16 - param->i_height) >> !sps->b_frame_mbs_only;
+    sps->b_crop = sps->crop.i_left  || sps->crop.i_top ||
+                  sps->crop.i_right || sps->crop.i_bottom;
+
+    sps->vui.b_aspect_ratio_info_present = 0;
+    if( param->vui.i_sar_width > 0 && param->vui.i_sar_height > 0 )
+    {
+        sps->vui.b_aspect_ratio_info_present = 1;
+        sps->vui.i_sar_width = param->vui.i_sar_width;
+        sps->vui.i_sar_height= param->vui.i_sar_height;
+    }
+}
+
 void x264_sps_write( bs_t *s, x264_sps_t *sps )
 {
     bs_realign( s );
diff --git a/encoder/set.h b/encoder/set.h
index 2202721..bb21086 100644
--- a/encoder/set.h
+++ b/encoder/set.h
@@ -28,6 +28,7 @@
 #define X264_ENCODER_SET_H
 
 void x264_sps_init( x264_sps_t *sps, int i_id, x264_param_t *param );
+void x264_sps_init_reconfigurable( x264_sps_t *sps, x264_param_t *param );
 void x264_sps_write( bs_t *s, x264_sps_t *sps );
 void x264_pps_init( x264_pps_t *pps, int i_id, x264_param_t *param, x264_sps_t *sps );
 void x264_pps_write( bs_t *s, x264_sps_t *sps, x264_pps_t *pps );



More information about the x264-devel mailing list