X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fcodec%2Fx264.c;h=ff4ec0cf1c9b0b51ca0fc92704a0bd50bfd49315;hb=4ce76d3a9d6b415b55d4095c3a74f2996059dbcd;hp=3942988fc7d6c9514ddb0bf828b6f66fe0973fe7;hpb=079a1818dc58b9dc81ca92b5217da2a8d599572f;p=vlc diff --git a/modules/codec/x264.c b/modules/codec/x264.c index 3942988fc7..ff4ec0cf1c 100644 --- a/modules/codec/x264.c +++ b/modules/codec/x264.c @@ -33,6 +33,9 @@ #include #include +#ifdef PTW32_STATIC_LIB +#include +#endif #include #define SOUT_CFG_PREFIX "sout-x264-" @@ -216,11 +219,20 @@ static void Close( vlc_object_t * ); #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") @@ -345,13 +357,20 @@ static void Close( vlc_object_t * ); #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[] = @@ -515,7 +534,7 @@ vlc_module_begin(); 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 @@ -696,6 +715,9 @@ static int Open ( vlc_object_t *p_this ) 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 ) @@ -917,7 +939,13 @@ static int Open ( vlc_object_t *p_this ) { 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 ) @@ -951,7 +979,7 @@ static int Open ( vlc_object_t *p_this ) 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; @@ -1093,7 +1121,7 @@ static int Open ( vlc_object_t *p_this ) 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 ); @@ -1137,12 +1165,13 @@ static int Open ( vlc_object_t *p_this ) 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 ); @@ -1160,6 +1189,36 @@ static int Open ( vlc_object_t *p_this ) 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 ); @@ -1284,10 +1343,31 @@ static void Close( vlc_object_t *p_this ) 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 ); }