]> git.sesse.net Git - vlc/commitdiff
* fix pthread support for x264 on win32
authorBenjamin Pracht <bigben@videolan.org>
Mon, 11 Feb 2008 01:06:37 +0000 (01:06 +0000)
committerBenjamin Pracht <bigben@videolan.org>
Mon, 11 Feb 2008 01:06:37 +0000 (01:06 +0000)
  - Not sure at all the configure.ac part is right, anyone more knowledgable, please check.

configure.ac
extras/contrib/src/Patches/x264-svn-win32.patch
modules/codec/x264.c

index 53d994284cfece292de47d9854c9995abb9f0e8d..9458ce250c907d3228b98e1625d0d4dd9ad7c38f 100644 (file)
@@ -3741,10 +3741,10 @@ if test "${enable_x264}" != "no"; then
       AC_MSG_RESULT(yes)
       VLC_ADD_CPPFLAGS([x264],[-I${real_x264_tree}])
       VLC_ADD_LIBS([x264],[-L${real_x264_tree}])
-      LDFLAGS="${LDFLAGS_save} ${LIBS_x264} ${THREAD_LIB}"
-      AC_CHECK_LIB(x264, x264_encoder_open, [
-        VLC_ADD_BUILTINS([x264])
-        VLC_ADD_LIBS([x264],[-lx264])
+      PKG_CHECK_MODULES(X264,x264, [
+        VLC_ADD_PLUGINS([x264])
+        VLC_ADD_LDFLAGS([x264],[${X264_LIBS}])
+        VLC_ADD_CFLAGS([x264],[${X264_CFLAGS}])
       ],[
         AC_MSG_ERROR([the specified tree hasn't been compiled])
       ])
@@ -3754,11 +3754,11 @@ if test "${enable_x264}" != "no"; then
       AC_MSG_ERROR([the specified tree doesn't have x264.h])
     fi
   else
-    LDFLAGS="${LDFLAGS_save} ${LIBS_x264} ${THREAD_LIB}"
     AC_CHECK_HEADERS(x264.h, [
-      AC_CHECK_LIB(x264, x264_encoder_open, [
+      PKG_CHECK_MODULES(X264,x264, [
         VLC_ADD_PLUGINS([x264])
-        VLC_ADD_LIBS([x264],[-lx264])
+        VLC_ADD_LDFLAGS([x264],[${X264_LIBS}])
+        VLC_ADD_CFLAGS([x264],[${X264_CFLAGS}])
       ],[
         if test "${enable_x264}" = "yes"; then
             AC_MSG_ERROR([Could not find libx264 on your system: you may get it from http://www.videolan.org/x264.html])
index 047f9f64502df2d9a890f705eaca2684646e5cf9..b578a798bef0746bafd65cc6456f86f939cc5877 100644 (file)
@@ -1,8 +1,16 @@
 Index: configure
 ===================================================================
---- configure  (revision 672)
+--- configure  (revision 736)
 +++ configure  (working copy)
-@@ -339,13 +339,13 @@
+@@ -338,6 +338,7 @@
+ # autodetect options that weren't forced nor disabled
+ libpthread=""
++extradef=""
+ if test "$pthread" = "auto" ; then
+     pthread="no"
+     case $SYS in
+@@ -345,16 +346,18 @@
              pthread="yes"
              ;;
          MINGW|CYGWIN)
@@ -19,7 +27,12 @@ Index: configure
                  pthread="yes"
                  libpthread="-lpthreadGC2 -lwsock32"
                  CFLAGS="$CFLAGS -DPTW32_STATIC_LIB"
-@@ -428,6 +428,10 @@
++              extradef="-DPTW32_STATIC_LIB"
++
+             fi
+             ;;
+         *)
+@@ -438,6 +441,10 @@
  ASFLAGS=$ASFLAGS
  GTK=$gtk
  EXE=$EXE
@@ -30,11 +43,20 @@ Index: configure
  VIS=$vis
  HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
  DEVNULL=$DEVNULL
+@@ -480,7 +487,7 @@
+ Description: H.264 (MPEG4 AVC) encoder library
+ Version: $(grep POINTVER < config.h | sed -e 's/.* "//; s/".*//')
+ Libs: $pclibs
+-Cflags: -I$includedir
++Cflags: -I$includedir $extradef
+ EOF
 Index: Makefile
 ===================================================================
---- Makefile   (revision 672)
+--- Makefile   (revision 736)
 +++ Makefile   (working copy)
-@@ -73,8 +73,8 @@
+@@ -74,8 +74,8 @@
  default: $(DEP) x264$(EXE)
  
  libx264.a: .depend $(OBJS) $(OBJASM)
@@ -45,7 +67,7 @@ Index: Makefile
  
  $(SONAME): .depend $(OBJS) $(OBJASM)
        $(CC) -shared -o $@ $(OBJS) $(OBJASM) -Wl,-soname,$(SONAME) $(LDFLAGS)
-@@ -93,7 +93,7 @@
+@@ -94,7 +94,7 @@
  %.o: %.asm
        $(AS) $(ASFLAGS) -o $@ $<
  # delete local/anonymous symbols, so they don't show up in oprofile
@@ -54,7 +76,7 @@ Index: Makefile
  
  .depend: config.mak
        rm -f .depend
-@@ -146,14 +146,14 @@
+@@ -149,14 +149,14 @@
        rm -rf test/
        $(MAKE) -C gtk distclean
  
index d1d8a5df9241d454968b85e86c6da9a453a1b1d6..26ddf677ad2c6932728bffc1bf1febc948960b5b 100644 (file)
@@ -33,6 +33,9 @@
 #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-"
@@ -1182,6 +1185,34 @@ 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 */
+#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 );
 
@@ -1310,6 +1341,28 @@ static void Close( vlc_object_t *p_this )
         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 );
 }