]> granicus.if.org Git - libx264/commitdiff
Fix corruption when using encoder_reconfig() with some parameters
authorAnton Mitrofanov <BugMaster@narod.ru>
Sat, 23 Apr 2016 19:45:44 +0000 (22:45 +0300)
committerHenrik Gramner <henrik@gramner.com>
Mon, 13 Jun 2016 19:53:45 +0000 (21:53 +0200)
Changing parameters that affects SPS, like --ref for example, wasn't
behaving correctly previously.

Probably a regression in r2373.

encoder/encoder.c
encoder/set.c
encoder/set.h

index 66f83575b45c7c2cfe7b37ce0eed4947343660b2..b614198aa28fb51de365090fa1d90d147799368b 100644 (file)
@@ -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
index 63560db976b44b0afe19d7331f55d78c3b01c60f..778add727a6df595f81f4c08ac6b389487eefdbf 100644 (file)
@@ -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 );
index 2202721e5f30c66e5ca82292e3b78f9d7184c657..bb2108664567a0b1a7597adabcf9532848425eeb 100644 (file)
@@ -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 );