Commit 78c94529 authored by Benjamin Pracht's avatar Benjamin Pracht

* fix pthread support for x264 on win32
  - Not sure at all the configure.ac part is right, anyone more knowledgable, please check.
parent e6e14e4e
...@@ -3741,10 +3741,10 @@ if test "${enable_x264}" != "no"; then ...@@ -3741,10 +3741,10 @@ if test "${enable_x264}" != "no"; then
AC_MSG_RESULT(yes) AC_MSG_RESULT(yes)
VLC_ADD_CPPFLAGS([x264],[-I${real_x264_tree}]) VLC_ADD_CPPFLAGS([x264],[-I${real_x264_tree}])
VLC_ADD_LIBS([x264],[-L${real_x264_tree}]) VLC_ADD_LIBS([x264],[-L${real_x264_tree}])
LDFLAGS="${LDFLAGS_save} ${LIBS_x264} ${THREAD_LIB}" PKG_CHECK_MODULES(X264,x264, [
AC_CHECK_LIB(x264, x264_encoder_open, [ VLC_ADD_PLUGINS([x264])
VLC_ADD_BUILTINS([x264]) VLC_ADD_LDFLAGS([x264],[${X264_LIBS}])
VLC_ADD_LIBS([x264],[-lx264]) VLC_ADD_CFLAGS([x264],[${X264_CFLAGS}])
],[ ],[
AC_MSG_ERROR([the specified tree hasn't been compiled]) AC_MSG_ERROR([the specified tree hasn't been compiled])
]) ])
...@@ -3754,11 +3754,11 @@ if test "${enable_x264}" != "no"; then ...@@ -3754,11 +3754,11 @@ if test "${enable_x264}" != "no"; then
AC_MSG_ERROR([the specified tree doesn't have x264.h]) AC_MSG_ERROR([the specified tree doesn't have x264.h])
fi fi
else else
LDFLAGS="${LDFLAGS_save} ${LIBS_x264} ${THREAD_LIB}"
AC_CHECK_HEADERS(x264.h, [ AC_CHECK_HEADERS(x264.h, [
AC_CHECK_LIB(x264, x264_encoder_open, [ PKG_CHECK_MODULES(X264,x264, [
VLC_ADD_PLUGINS([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 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]) AC_MSG_ERROR([Could not find libx264 on your system: you may get it from http://www.videolan.org/x264.html])
......
Index: configure Index: configure
=================================================================== ===================================================================
--- configure (revision 672) --- configure (revision 736)
+++ configure (working copy) +++ 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" pthread="yes"
;; ;;
MINGW|CYGWIN) MINGW|CYGWIN)
...@@ -19,7 +27,12 @@ Index: configure ...@@ -19,7 +27,12 @@ Index: configure
pthread="yes" pthread="yes"
libpthread="-lpthreadGC2 -lwsock32" libpthread="-lpthreadGC2 -lwsock32"
CFLAGS="$CFLAGS -DPTW32_STATIC_LIB" CFLAGS="$CFLAGS -DPTW32_STATIC_LIB"
@@ -428,6 +428,10 @@ + extradef="-DPTW32_STATIC_LIB"
+
fi
;;
*)
@@ -438,6 +441,10 @@
ASFLAGS=$ASFLAGS ASFLAGS=$ASFLAGS
GTK=$gtk GTK=$gtk
EXE=$EXE EXE=$EXE
...@@ -30,11 +43,20 @@ Index: configure ...@@ -30,11 +43,20 @@ Index: configure
VIS=$vis VIS=$vis
HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG HAVE_GETOPT_LONG=$HAVE_GETOPT_LONG
DEVNULL=$DEVNULL 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 Index: Makefile
=================================================================== ===================================================================
--- Makefile (revision 672) --- Makefile (revision 736)
+++ Makefile (working copy) +++ Makefile (working copy)
@@ -73,8 +73,8 @@ @@ -74,8 +74,8 @@
default: $(DEP) x264$(EXE) default: $(DEP) x264$(EXE)
libx264.a: .depend $(OBJS) $(OBJASM) libx264.a: .depend $(OBJS) $(OBJASM)
...@@ -45,7 +67,7 @@ Index: Makefile ...@@ -45,7 +67,7 @@ Index: Makefile
$(SONAME): .depend $(OBJS) $(OBJASM) $(SONAME): .depend $(OBJS) $(OBJASM)
$(CC) -shared -o $@ $(OBJS) $(OBJASM) -Wl,-soname,$(SONAME) $(LDFLAGS) $(CC) -shared -o $@ $(OBJS) $(OBJASM) -Wl,-soname,$(SONAME) $(LDFLAGS)
@@ -93,7 +93,7 @@ @@ -94,7 +94,7 @@
%.o: %.asm %.o: %.asm
$(AS) $(ASFLAGS) -o $@ $< $(AS) $(ASFLAGS) -o $@ $<
# delete local/anonymous symbols, so they don't show up in oprofile # delete local/anonymous symbols, so they don't show up in oprofile
...@@ -54,7 +76,7 @@ Index: Makefile ...@@ -54,7 +76,7 @@ Index: Makefile
.depend: config.mak .depend: config.mak
rm -f .depend rm -f .depend
@@ -146,14 +146,14 @@ @@ -149,14 +149,14 @@
rm -rf test/ rm -rf test/
$(MAKE) -C gtk distclean $(MAKE) -C gtk distclean
......
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
#include <vlc_sout.h> #include <vlc_sout.h>
#include <vlc_codec.h> #include <vlc_codec.h>
#ifdef PTW32_STATIC_LIB
#include <pthread.h>
#endif
#include <x264.h> #include <x264.h>
#define SOUT_CFG_PREFIX "sout-x264-" #define SOUT_CFG_PREFIX "sout-x264-"
...@@ -1182,6 +1185,34 @@ static int Open ( vlc_object_t *p_this ) ...@@ -1182,6 +1185,34 @@ static int Open ( vlc_object_t *p_this )
p_sys->param.rc.b_stat_read = val.i_int & 2; 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 */ /* Open the encoder */
p_sys->h = x264_encoder_open( &p_sys->param ); p_sys->h = x264_encoder_open( &p_sys->param );
...@@ -1310,6 +1341,28 @@ static void Close( vlc_object_t *p_this ) ...@@ -1310,6 +1341,28 @@ static void Close( vlc_object_t *p_this )
free( p_sys->psz_stat_name ); free( p_sys->psz_stat_name );
x264_encoder_close( p_sys->h ); 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->p_buffer );
free( p_sys ); free( p_sys );
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment