#include <vlc_sout.h>
#include <vlc_codec.h>
+#ifdef PTW32_STATIC_LIB
+#include <pthread.h>
+#endif
#include <x264.h>
#define SOUT_CFG_PREFIX "sout-x264-"
#define WEIGHTB_LONGTEXT N_( "Weighted prediction for B-frames.")
#define ME_TEXT N_("Integer pixel motion estimation method")
+#if X264_BUILD >= 58 /* r728 */
+#define ME_LONGTEXT N_( "Selects the motion estimation algorithm: "\
+ " - dia: diamond search, radius 1 (fast)\n" \
+ " - hex: hexagonal search, radius 2\n" \
+ " - umh: uneven multi-hexagon search (better but slower)\n" \
+ " - esa: exhaustive search (extremely slow, primarily for testing)\n" \
+ " - tesa: hadamard exhaustive search (extremely slow, primarily for testing)\n" )
+#else
#define ME_LONGTEXT N_( "Selects the motion estimation algorithm: "\
" - dia: diamond search, radius 1 (fast)\n" \
" - hex: hexagonal search, radius 2\n" \
" - umh: uneven multi-hexagon search (better but slower)\n" \
" - esa: exhaustive search (extremely slow, primarily for testing)\n" )
+#endif
#if X264_BUILD >= 24
#define MERANGE_TEXT N_("Maximum motion vector search range")
#define AUD_TEXT N_("Access unit delimiters")
#define AUD_LONGTEXT N_( "Generate access unit delimiter NAL units.")
-#if X264_BUILD >= 24
+#if X264_BUILD >= 24 && X264_BUILD < 58
static const char *enc_me_list[] =
{ "dia", "hex", "umh", "esa" };
static const char *enc_me_list_text[] =
{ N_("dia"), N_("hex"), N_("umh"), N_("esa") };
#endif
+#if X264_BUILD >= 58 /* r728 */
+static const char *enc_me_list[] =
+ { "dia", "hex", "umh", "esa", "tesa" };
+static const char *enc_me_list_text[] =
+ { N_("dia"), N_("hex"), N_("umh"), N_("esa"), N_("tesa") };
+#endif
+
static const char *enc_analyse_list[] =
{ "none", "fast", "normal", "slow", "all" };
static const char *enc_analyse_list_text[] =
change_string_list( direct_pred_list, direct_pred_list_text, 0 );
#if X264_BUILD >= 52 /* r573 */
- add_integer( SOUT_CFG_PREFIX "direct-8x8", 0, NULL, DIRECT_PRED_SIZE_TEXT,
+ add_integer( SOUT_CFG_PREFIX "direct-8x8", -1, NULL, DIRECT_PRED_SIZE_TEXT,
DIRECT_PRED_SIZE_LONGTEXT, VLC_FALSE );
change_integer_range( -1, 1 );
#endif
return VLC_EGENERIC;
}
+ /* X264_POINTVER or X264_VERSION are not available */
+ msg_Dbg ( p_enc, "version x264 0.%d.X", X264_BUILD );
+
#if X264_BUILD < 37
if( p_enc->fmt_in.video.i_width % 16 != 0 ||
p_enc->fmt_in.video.i_height % 16 != 0 )
var_Get( p_enc, SOUT_CFG_PREFIX "qpstep", &val );
if( val.i_int >= 0 && val.i_int <= 51 ) p_sys->param.rc.i_qp_step = val.i_int;
var_Get( p_enc, SOUT_CFG_PREFIX "qpmin", &val );
- if( val.i_int >= 0 && val.i_int <= 51 ) i_qmin = val.i_int;
+ if( val.i_int >= 0 && val.i_int <= 51 )
+ {
+ i_qmin = val.i_int;
+ p_sys->param.rc.i_qp_min = i_qmin;
+ }
var_Get( p_enc, SOUT_CFG_PREFIX "qpmax", &val );
- if( val.i_int >= 0 && val.i_int <= 51 ) i_qmax = val.i_int;
+ if( val.i_int >= 0 && val.i_int <= 51 )
+ {
+ i_qmax = val.i_int;
+ p_sys->param.rc.i_qp_max = i_qmax;
+ }
var_Get( p_enc, SOUT_CFG_PREFIX "qp", &val );
if( val.i_int >= 0 && val.i_int <= 51 )
if( i_qmin > val.i_int ) i_qmin = val.i_int;
if( i_qmax < val.i_int ) i_qmax = val.i_int;
+ p_sys->param.rc.i_rc_method = X264_RC_CQP;
#if X264_BUILD >= 0x000a
p_sys->param.rc.i_qp_constant = val.i_int;
p_sys->param.rc.i_qp_min = i_qmin;
{
p_sys->param.analyse.i_me_method = X264_ME_ESA;
}
- if( val.psz_string ) free( val.psz_string );
+ #if X264_BUILD >= 58 /* r728 */
+ else if( !strcmp( val.psz_string, "tesa" ) )
+ {
+ p_sys->param.analyse.i_me_method = X264_ME_TESA;
+ }
+ #endif
+ free( val.psz_string );
var_Get( p_enc, SOUT_CFG_PREFIX "merange", &val );
if( val.i_int >= 0 && val.i_int <= 64 )
p_sys->param.analyse.i_direct_mv_pred = X264_DIRECT_PRED_AUTO;
}
#endif
- if( val.psz_string ) free( val.psz_string );
+ free( val.psz_string );
var_Get( p_enc, SOUT_CFG_PREFIX "psnr", &val );
p_sys->param.analyse.b_psnr = val.b_bool;
p_sys->param.analyse.inter |= X264_ANALYSE_I8x8;
#endif
}
- if( val.psz_string ) free( val.psz_string );
+ free( val.psz_string );
#if X264_BUILD >= 30
var_Get( p_enc, SOUT_CFG_PREFIX "8x8dct", &val );
p_sys->param.cpu &= ~X264_CPU_SSE2;
}
+ /* BUILD 29 adds support for multi-threaded encoding while BUILD 49 (r543)
+ also adds support for threads = 0 for automatically selecting an optimal
+ value (cores * 1.5) based on detected CPUs. Default behavior for x264 is
+ threads = 1, however VLC usage differs and uses threads = 0 (auto) by
+ default unless ofcourse transcode threads is explicitly specified.. */
#if X264_BUILD >= 29
- /* As of r543 x264 will autodetect the number of cpus and will set
- the number of threads accordingly unless ofcourse the number of
- threads is explicitly specified... */
- if( p_enc->i_threads >= 1 )
- p_sys->param.i_threads = p_enc->i_threads;
+ p_sys->param.i_threads = p_enc->i_threads;
#endif
var_Get( p_enc, SOUT_CFG_PREFIX "stats", &val );
p_sys->param.rc.b_stat_read = val.i_int & 2;
}
+ /* We need to initialize pthreadw32 before we open the encoder,
+ but only oncce for the whole application. Since pthreadw32
+ doesn't keep a refcount, do it ourselves. */
+#ifdef PTW32_STATIC_LIB
+ vlc_value_t lock, count;
+
+ var_Create( p_enc->p_libvlc, "pthread_win32_mutex", VLC_VAR_MUTEX );
+ var_Get( p_enc->p_libvlc, "pthread_win32_mutex", &lock );
+ vlc_mutex_lock( lock.p_address );
+
+ var_Create( p_enc->p_libvlc, "pthread_win32_count", VLC_VAR_INTEGER );
+ var_Get( p_enc->p_libvlc, "pthread_win32_count", &count );
+
+ if( count.i_int == 0 )
+ {
+ msg_Dbg( p_enc, "initializing pthread-win32" );
+ if( !pthread_win32_process_attach_np() || !pthread_win32_thread_attach_np() )
+ {
+ msg_Warn( p_enc, "pthread Win32 Initialization failed" );
+ vlc_mutex_unlock( lock.p_address );
+ return VLC_EGENERIC;
+ }
+ }
+
+ count.i_int++;
+ var_Set( p_enc->p_libvlc, "pthread_win32_count", count );
+ vlc_mutex_unlock( lock.p_address );
+
+#endif
+
/* Open the encoder */
p_sys->h = x264_encoder_open( &p_sys->param );
p_enc->fmt_out.p_extra = realloc( p_enc->fmt_out.p_extra, p_enc->fmt_out.i_extra + i_size );
- memcpy( p_enc->fmt_out.p_extra + p_enc->fmt_out.i_extra,
- p_sys->p_buffer, i_size );
+ memcpy( (uint8_t*)p_enc->fmt_out.p_extra + p_enc->fmt_out.i_extra,
+ p_sys->p_buffer, i_size );
p_enc->fmt_out.i_extra += i_size;
}
{
encoder_t *p_enc = (encoder_t *)p_this;
encoder_sys_t *p_sys = p_enc->p_sys;
-
- if( p_sys->psz_stat_name )
- free( p_sys->psz_stat_name );
+
+ free( p_sys->psz_stat_name );
x264_encoder_close( p_sys->h );
+
+#ifdef PTW32_STATIC_LIB
+ vlc_value_t lock, count;
+
+ var_Create( p_enc->p_libvlc, "pthread_win32_mutex", VLC_VAR_MUTEX );
+ var_Get( p_enc->p_libvlc, "pthread_win32_mutex", &lock );
+ vlc_mutex_lock( lock.p_address );
+
+ var_Create( p_enc->p_libvlc, "pthread_win32_count", VLC_VAR_INTEGER );
+ var_Get( p_enc->p_libvlc, "pthread_win32_count", &count );
+ count.i_int--;
+ var_Set( p_enc->p_libvlc, "pthread_win32_count", count );
+
+ if( count.i_int == 0 )
+ {
+ pthread_win32_thread_detach_np();
+ pthread_win32_process_detach_np();
+ msg_Dbg( p_enc, "pthread-win32 deinitialized" );
+ }
+ vlc_mutex_unlock( lock.p_address );
+#endif
+
free( p_sys->p_buffer );
free( p_sys );
}