From fb163e84b3de0289ffff7c4ba3831c90595a1ebf Mon Sep 17 00:00:00 2001
From: Dennis van Amerongen <trax@videolan.org>
Date: Thu, 14 Feb 2008 21:11:06 +0000
Subject: [PATCH] * modules/codec/x264.c: fix threads=0 (auto) which is the
 default setting for VLC but wasn't propogated to x264 which kept using its
 default threads=1 (thanks pengvado for spotting the problem). This fix gives
 a major performance boost on multi cpu systems when using the default
 settings.

---
 modules/codec/x264.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/modules/codec/x264.c b/modules/codec/x264.c
index c33d487cfe13..5f56815603b5 100644
--- a/modules/codec/x264.c
+++ b/modules/codec/x264.c
@@ -1165,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 );
@@ -1188,7 +1189,9 @@ 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 ouurselves */
+    /* 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;
 
-- 
GitLab