static UNUSED x264_pthread_mutex_t cost_ref_mutex = X264_PTHREAD_MUTEX_INITIALIZER;
static uint16_t x264_cost_i4x4_mode[(QP_MAX+2)*32];
-float *x264_analyse_prepare_costs( x264_t *h )
-{
- float *logs = x264_malloc( (2*4*2048+1)*sizeof(float) );
- if( !logs )
- return NULL;
- logs[0] = 0.718f;
- for( int i = 1; i <= 2*4*2048; i++ )
- logs[i] = log2f(i+1)*2 + 1.718f;
- return logs;
-}
-
-int x264_analyse_init_costs( x264_t *h, float *logs, int qp )
+static int init_costs( x264_t *h, float *logs, int qp )
{
int lambda = x264_lambda_tab[qp];
if( h->cost_mv[qp] )
return -1;
}
+int x264_analyse_init_costs( x264_t *h )
+{
+ float *logs = x264_malloc( (2*4*2048+1) * sizeof(float) );
+ if( !logs )
+ return -1;
+
+ logs[0] = 0.718f;
+ for( int i = 1; i <= 2*4*2048; i++ )
+ logs[i] = log2f( i+1 ) * 2.0f + 1.718f;
+
+ for( int qp = X264_MIN( h->param.rc.i_qp_min, QP_MAX_SPEC ); qp <= h->param.rc.i_qp_max; qp++ )
+ if( init_costs( h, logs, qp ) )
+ goto fail;
+
+ if( init_costs( h, logs, X264_LOOKAHEAD_QP ) )
+ goto fail;
+
+ x264_free( logs );
+ return 0;
+fail:
+ x264_free( logs );
+ return -1;
+}
+
void x264_analyse_free_costs( x264_t *h )
{
for( int i = 0; i < QP_MAX+1; i++ )
#ifndef X264_ANALYSE_H
#define X264_ANALYSE_H
-float *x264_analyse_prepare_costs( x264_t *h );
-int x264_analyse_init_costs( x264_t *h, float *logs, int qp );
+int x264_analyse_init_costs( x264_t *h );
void x264_analyse_free_costs( x264_t *h );
void x264_analyse_weight_frame( x264_t *h, int end );
void x264_macroblock_analyse( x264_t *h );
{
x264_t *h;
char buf[1000], *p;
- int qp, i_slicetype_length;
+ int i_slicetype_length;
CHECKED_MALLOCZERO( h, sizeof(x264_t) );
p += sprintf( p, " none!" );
x264_log( h, X264_LOG_INFO, "%s\n", buf );
- float *logs = x264_analyse_prepare_costs( h );
- if( !logs )
+ if( x264_analyse_init_costs( h ) )
goto fail;
- for( qp = X264_MIN( h->param.rc.i_qp_min, QP_MAX_SPEC ); qp <= h->param.rc.i_qp_max; qp++ )
- if( x264_analyse_init_costs( h, logs, qp ) )
- goto fail;
- if( x264_analyse_init_costs( h, logs, X264_LOOKAHEAD_QP ) )
- goto fail;
- x264_free( logs );
static const uint16_t cost_mv_correct[7] = { 24, 47, 95, 189, 379, 757, 1515 };
/* Checks for known miscompilation issues. */