[x264-devel] commit: Fix free callback, add x264_encoder_parameters function ( Jason Garrett-Glaser )

git version control git at videolan.org
Thu Jan 14 05:51:06 CET 2010


x264 | branch: master | Jason Garrett-Glaser <darkshikari at gmail.com> | Sun Jan 10 15:14:02 2010 -0500| [d260e6bf125e2a3b8541bf589c5d41094601fd21] | committer: Jason Garrett-Glaser 

Fix free callback, add x264_encoder_parameters function
x264 would try to use the passed param struct after freeing if the param_free callback was set.
Probably didn't cause any issues, as probably no programs used the callback in this location yet.

A new x264_encoder_parameters function is now available in the API.
This function lets the calling application grab the current state of the encoder's parameters.
Use this in x264cli to ensure that the param struct used for set_param is updated with whatever changes x264_encoder_open has made to it.

Patch partially by Anton Mitrofanov <BugMaster at narod.ru>.

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

 encoder/encoder.c |   20 ++++++++++++++------
 x264.c            |    2 ++
 x264.h            |   10 +++++++++-
 3 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/encoder/encoder.c b/encoder/encoder.c
index b2ddafb..f97df1b 100644
--- a/encoder/encoder.c
+++ b/encoder/encoder.c
@@ -853,7 +853,7 @@ x264_t *x264_encoder_open( x264_param_t *param )
     if( h->param.rc.psz_stat_in )
         h->param.rc.psz_stat_in = strdup( h->param.rc.psz_stat_in );
 
-    x264_set_aspect_ratio( h, param, 1 );
+    x264_set_aspect_ratio( h, &h->param, 1 );
 
     x264_reduce_fraction( &h->param.i_fps_num, &h->param.i_fps_den );
     x264_reduce_fraction( &h->param.i_timebase_num, &h->param.i_timebase_den );
@@ -941,19 +941,19 @@ x264_t *x264_encoder_open( x264_param_t *param )
     for( i=0; x264_cpu_names[i].flags; i++ )
     {
         if( !strcmp(x264_cpu_names[i].name, "SSE2")
-            && param->cpu & (X264_CPU_SSE2_IS_FAST|X264_CPU_SSE2_IS_SLOW) )
+            && h->param.cpu & (X264_CPU_SSE2_IS_FAST|X264_CPU_SSE2_IS_SLOW) )
             continue;
         if( !strcmp(x264_cpu_names[i].name, "SSE3")
-            && (param->cpu & X264_CPU_SSSE3 || !(param->cpu & X264_CPU_CACHELINE_64)) )
+            && (h->param.cpu & X264_CPU_SSSE3 || !(h->param.cpu & X264_CPU_CACHELINE_64)) )
             continue;
         if( !strcmp(x264_cpu_names[i].name, "SSE4.1")
-            && (param->cpu & X264_CPU_SSE42) )
+            && (h->param.cpu & X264_CPU_SSE42) )
             continue;
-        if( (param->cpu & x264_cpu_names[i].flags) == x264_cpu_names[i].flags
+        if( (h->param.cpu & x264_cpu_names[i].flags) == x264_cpu_names[i].flags
             && (!i || x264_cpu_names[i].flags != x264_cpu_names[i-1].flags) )
             p += sprintf( p, " %s", x264_cpu_names[i].name );
     }
-    if( !param->cpu )
+    if( !h->param.cpu )
         p += sprintf( p, " none!" );
     x264_log( h, X264_LOG_INFO, "%s\n", buf );
 
@@ -1104,6 +1104,14 @@ int x264_encoder_reconfig( x264_t *h, x264_param_t *param )
     return x264_validate_parameters( h );
 }
 
+/****************************************************************************
+ * x264_encoder_parameters:
+ ****************************************************************************/
+void x264_encoder_parameters( x264_t *h, x264_param_t *param )
+{
+    memcpy( param, &h->thread[h->i_thread_phase]->param, sizeof(x264_param_t) );
+}
+
 /* internal usage */
 static void x264_nal_start( x264_t *h, int i_type, int i_ref_idc )
 {
diff --git a/x264.c b/x264.c
index 4834961..8c280aa 100644
--- a/x264.c
+++ b/x264.c
@@ -1447,6 +1447,8 @@ static int  Encode( x264_param_t *param, cli_opt_t *opt )
         return -1;
     }
 
+    x264_encoder_parameters( h, param );
+
     if( output.set_param( opt->hout, param ) )
     {
         fprintf( stderr, "x264 [error]: can't set outfile param\n" );
diff --git a/x264.h b/x264.h
index f760e72..1223df7 100644
--- a/x264.h
+++ b/x264.h
@@ -35,7 +35,7 @@
 
 #include <stdarg.h>
 
-#define X264_BUILD 82
+#define X264_BUILD 83
 
 /* x264_t:
  *      opaque handler for encoder */
@@ -483,6 +483,14 @@ x264_t *x264_encoder_open( x264_param_t * );
  *      if the change should apply to some particular frame, use x264_picture_t->param instead.
  *      returns 0 on success, negative on parameter validation error. */
 int     x264_encoder_reconfig( x264_t *, x264_param_t * );
+/* x264_encoder_parameters:
+ *      copies the current internal set of parameters to the pointer provided
+ *      by the caller.  useful when the calling application needs to know
+ *      how x264_encoder_open has changed the parameters, or the current state
+ *      of the encoder after multiple x264_encoder_reconfig calls.
+ *      note that the data accessible through pointers in the returned param struct
+ *      (e.g. filenames) should not be modified by the calling application. */
+void    x264_encoder_parameters( x264_t *, x264_param_t * );
 /* x264_encoder_headers:
  *      return the SPS and PPS that will be used for the whole stream.
  *      if i_nal > 0, returns the total size of all NAL payloads.



More information about the x264-devel mailing list