Commit 398d0eb3 authored by Fiona Glaser's avatar Fiona Glaser
Browse files

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@narod.ru>.
parent aa48c1fb
......@@ -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 )
{
......
......@@ -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" );
......
......@@ -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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment