summaryrefslogtreecommitdiffstats
path: root/libhb/ports.c
diff options
context:
space:
mode:
authorhandbrake <[email protected]>2007-01-03 01:11:09 +0000
committerhandbrake <[email protected]>2007-01-03 01:11:09 +0000
commit79de879241d42814c3db4f897ad6a632ebe42a7f (patch)
tree44ac1a61c3b493e5cc2f99322a4ade200a6c29e3 /libhb/ports.c
parent4a04f3ecd4d15ad7a47bc797e991f412c426b05f (diff)
Changes to make HandBrake build on Windows using the Cygwin environment:
root configure file: I added this to the "case $SYSTEM in" switch statement: CYGWIN_NT*) DEFINES="$DEFINES SYS_CYGWIN USE_PTHREAD" LINKLIBS="$LINKLIBS -lpthread" ;; Also, for each existing OS type that is using -lpthread, I added USE_PTHREAD to their DEFINES. Then libhb/ports.c was changed to use pthread code based on the value of USE_PTHREAD, instead of checking each different OS value that used pthreading, so it's a bit easier to read and maintain. root Jamfile: Jam doesn't seem to understand CYGWIN, so $(OS) is defined as UNKNOWN. Check for this, and if this it true then set $(OS) to CYGWIN. Since CSS doesn't work (yet) on CYGWIN/Windows, I also changed Jamfile to not include libdvdcss.a in the library list for CYGWIN. contrib/Jamfile: For CYGWIN, don't build libdvdcss, and don't specify it's path for libdvdread. There are also a few changes to use new patchfiles for Cygwin for a few of the libraries. x264: Change configure script so that it doesn't include -mno-cygwin flags for CYGWIN platform. Created patchfile patch-x264-cygwin.patch for this, which is used by Jamfile. The -mno-cygwin flags cause the library not to link correctly with HBTest.exe. The -mno-cygwin flag is used to create an object file or library that doesn't depend on cygwin1.dll if you're using MinGW, but I'm not (yet). libxvidcore: Change configure script so that it doesn't include -mno-cygwin flags for CYGWIN platform. Change configure script so that it uses libxvidcore.a as the lib name instead of xvidcore.a for CYGWIN. Created patchfile patch-xvidcore-cygwin.patch that contains the 2 above changes and is used by Jamfile. Renamed patch-xvidcore.patch to patch-xvidcore-macosx.patch and updated Jamfile as appropriate -- an attempt to keep the patches being applied only when needed for a particular platform. ffmpeg: libavcodec/mpegaudiodec.c uses llrint(), which apparently isn't availble with Cygwin, so I changed the file to use lrint() which is available. llrint() returns a long long, lrint() returns a long. In the places where llrint() was being called, the return value of llrint() was being assigned to an element in an array of unsigned ints, so llrint() (long long) shouldn't be needed, and lrint() (long) should be fine. Created patchfile patch-ffmpeg-cygwin.patch that contains this change, and is used by Jamfile. libhb/ports.c: Commented out a number of things that were broken with the current SYS_CYGWIN code. The most notable change was to not use Windows threading for CYGWIN, and instead use pthreading. All the places where the OS type was being checked to determine whether or not to use pthreading were changed so that the USE_PTHREAD define is checked instead. There seems to be some problem with the Windows threading code in ports.c, because if I enable it then x264 encodes will either crash or lock-up HBTest.exe. Perhaps this is related to mixing threading models, since x264 is compiled with pthread support, and so maybe mixing pthread with Windows threading in the same process is a bad thing. test/test.c: Need to #include sys/time.h, time.h, unistd.h to compile. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@84 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb/ports.c')
-rw-r--r--libhb/ports.c116
1 files changed, 60 insertions, 56 deletions
diff --git a/libhb/ports.c b/libhb/ports.c
index 20c2cae94..bdeadc1f8 100644
--- a/libhb/ports.c
+++ b/libhb/ports.c
@@ -10,21 +10,23 @@
#if defined( SYS_BEOS )
#include <OS.h>
#include <signal.h>
-#elif defined( SYS_DARWIN ) || defined( SYS_LINUX ) || defined( SYS_FREEBSD )
-#include <pthread.h>
#elif defined( SYS_CYGWIN )
#include <windows.h>
#endif
-#ifdef SYS_CYGWIN
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#else
+#if USE_PTHREAD
+#include <pthread.h>
+#endif
+
+//#ifdef SYS_CYGWIN
+//#include <winsock2.h>
+//#include <ws2tcpip.h>
+//#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
-#endif
+//#endif
#include "hb.h"
@@ -35,6 +37,7 @@
* On Win32, we implement a gettimeofday emulation here because
* libdvdread and libmp4v2 use it without checking.
************************************************************************/
+/*
#ifdef SYS_CYGWIN
struct timezone
{
@@ -49,6 +52,7 @@ int gettimeofday( struct timeval * tv, struct timezone * tz )
return 0;
}
#endif
+*/
uint64_t hb_get_date()
{
@@ -204,11 +208,11 @@ void hb_get_tempory_filename( hb_handle_t * h, char name[1024],
***********************************************************************/
void hb_mkdir( char * name )
{
-#ifdef SYS_CYGWIN
- mkdir( name );
-#else
+//#ifdef SYS_CYGWIN
+// mkdir( name );
+//#else
mkdir( name, 0755 );
-#endif
+//#endif
}
/************************************************************************
@@ -226,10 +230,10 @@ struct hb_thread_s
#if defined( SYS_BEOS )
thread_id thread;
-#elif defined( SYS_DARWIN ) || defined( SYS_LINUX ) || defined( SYS_FREEBSD )
+#elif USE_PTHREAD
pthread_t thread;
-#elif defined( SYS_CYGWIN )
- HANDLE thread;
+//#elif defined( SYS_CYGWIN )
+// HANDLE thread;
#endif
};
@@ -295,17 +299,17 @@ hb_thread_t * hb_thread_init( char * name, void (* function)(void *),
name, priority, t );
resume_thread( t->thread );
-#elif defined( SYS_DARWIN ) || defined( SYS_LINUX ) || defined( SYS_FREEBSD )
+#elif USE_PTHREAD
pthread_create( &t->thread, NULL,
(void * (*)( void * )) hb_thread_func, t );
-#elif defined( SYS_CYGWIN )
- t->thread = CreateThread( NULL, 0,
- (LPTHREAD_START_ROUTINE) hb_thread_func, t, 0, NULL );
-
- /* Maybe use THREAD_PRIORITY_LOWEST instead */
- if( priority == HB_LOW_PRIORITY )
- SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL );
+//#elif defined( SYS_CYGWIN )
+// t->thread = CreateThread( NULL, 0,
+// (LPTHREAD_START_ROUTINE) hb_thread_func, t, 0, NULL );
+//
+// /* Maybe use THREAD_PRIORITY_LOWEST instead */
+// if( priority == HB_LOW_PRIORITY )
+// SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL );
#endif
hb_log( "thread %d started (\"%s\")", t->thread, t->name );
@@ -326,11 +330,11 @@ void hb_thread_close( hb_thread_t ** _t )
long exit_value;
wait_for_thread( t->thread, &exit_value );
-#elif defined( SYS_DARWIN ) || defined( SYS_LINUX ) || defined( SYS_FREEBSD )
+#elif USE_PTHREAD
pthread_join( t->thread, NULL );
-#elif defined( SYS_CYGWIN )
- WaitForSingleObject( t->thread, INFINITE );
+//#elif defined( SYS_CYGWIN )
+// WaitForSingleObject( t->thread, INFINITE );
#endif
hb_log( "thread %d joined (\"%s\")",
@@ -365,10 +369,10 @@ struct hb_lock_s
{
#if defined( SYS_BEOS )
sem_id sem;
-#elif defined( SYS_DARWIN ) || defined( SYS_LINUX ) || defined( SYS_FREEBSD )
+#elif USE_PTHREAD
pthread_mutex_t mutex;
-#elif defined( SYS_CYGWIN )
- HANDLE mutex;
+//#elif defined( SYS_CYGWIN )
+// HANDLE mutex;
#endif
};
@@ -386,10 +390,10 @@ hb_lock_t * hb_lock_init()
#if defined( SYS_BEOS )
l->sem = create_sem( 1, "sem" );
-#elif defined( SYS_DARWIN ) || defined( SYS_LINUX ) || defined( SYS_FREEBSD )
+#elif USE_PTHREAD
pthread_mutex_init( &l->mutex, NULL );
-#elif defined( SYS_CYGWIN )
- l->mutex = CreateMutex( 0, FALSE, 0 );
+//#elif defined( SYS_CYGWIN )
+// l->mutex = CreateMutex( 0, FALSE, 0 );
#endif
return l;
@@ -401,10 +405,10 @@ void hb_lock_close( hb_lock_t ** _l )
#if defined( SYS_BEOS )
delete_sem( l->sem );
-#elif defined( SYS_DARWIN ) || defined( SYS_LINUX ) || defined( SYS_FREEBSD )
+#elif USE_PTHREAD
pthread_mutex_destroy( &l->mutex );
-#elif defined( SYS_CYGWIN )
- CloseHandle( l->mutex );
+//#elif defined( SYS_CYGWIN )
+// CloseHandle( l->mutex );
#endif
free( l );
@@ -415,10 +419,10 @@ void hb_lock( hb_lock_t * l )
{
#if defined( SYS_BEOS )
acquire_sem( l->sem );
-#elif defined( SYS_DARWIN ) || defined( SYS_LINUX ) || defined( SYS_FREEBSD )
+#elif USE_PTHREAD
pthread_mutex_lock( &l->mutex );
-#elif defined( SYS_CYGWIN )
- WaitForSingleObject( l->mutex, INFINITE );
+//#elif defined( SYS_CYGWIN )
+// WaitForSingleObject( l->mutex, INFINITE );
#endif
}
@@ -426,10 +430,10 @@ void hb_unlock( hb_lock_t * l )
{
#if defined( SYS_BEOS )
release_sem( l->sem );
-#elif defined( SYS_DARWIN ) || defined( SYS_LINUX ) || defined( SYS_FREEBSD )
+#elif USE_PTHREAD
pthread_mutex_unlock( &l->mutex );
-#elif defined( SYS_CYGWIN )
- ReleaseMutex( l->mutex );
+//#elif defined( SYS_CYGWIN )
+// ReleaseMutex( l->mutex );
#endif
}
@@ -440,10 +444,10 @@ struct hb_cond_s
{
#if defined( SYS_BEOS )
int thread;
-#elif defined( SYS_DARWIN ) || defined( SYS_LINUX ) || defined( SYS_FREEBSD )
+#elif USE_PTHREAD
pthread_cond_t cond;
-#elif defined( SYS_CYGWIN )
- HANDLE event;
+//#elif defined( SYS_CYGWIN )
+// HANDLE event;
#endif
};
@@ -462,10 +466,10 @@ hb_cond_t * hb_cond_init()
#if defined( SYS_BEOS )
c->thread = -1;
-#elif defined( SYS_DARWIN ) || defined( SYS_LINUX ) || defined( SYS_FREEBSD )
+#elif USE_PTHREAD
pthread_cond_init( &c->cond, NULL );
-#elif defined( SYS_CYGWIN )
- c->event = CreateEvent( NULL, FALSE, FALSE, NULL );
+//#elif defined( SYS_CYGWIN )
+// c->event = CreateEvent( NULL, FALSE, FALSE, NULL );
#endif
return c;
@@ -476,10 +480,10 @@ void hb_cond_close( hb_cond_t ** _c )
hb_cond_t * c = *_c;
#if defined( SYS_BEOS )
-#elif defined( SYS_DARWIN ) || defined( SYS_LINUX ) || defined( SYS_FREEBSD )
+#elif USE_PTHREAD
pthread_cond_destroy( &c->cond );
-#elif defined( SYS_CYGWIN )
- CloseHandle( c->event );
+//#elif defined( SYS_CYGWIN )
+// CloseHandle( c->event );
#endif
free( c );
@@ -494,11 +498,11 @@ void hb_cond_wait( hb_cond_t * c, hb_lock_t * lock )
suspend_thread( c->thread );
acquire_sem( lock->sem );
c->thread = -1;
-#elif defined( SYS_DARWIN ) || defined( SYS_LINUX ) || defined( SYS_FREEBSD )
+#elif USE_PTHREAD
pthread_cond_wait( &c->cond, &lock->mutex );
-#elif defined( SYS_CYGWIN )
- SignalObjectAndWait( lock->mutex, c->event, INFINITE, FALSE );
- WaitForSingleObject( lock->mutex, INFINITE );
+//#elif defined( SYS_CYGWIN )
+// SignalObjectAndWait( lock->mutex, c->event, INFINITE, FALSE );
+// WaitForSingleObject( lock->mutex, INFINITE );
#endif
}
@@ -519,10 +523,10 @@ void hb_cond_signal( hb_cond_t * c )
thread is actually suspended before we resume it */
snooze( 5000 );
}
-#elif defined( SYS_DARWIN ) || defined( SYS_LINUX ) || defined( SYS_FREEBSD )
+#elif USE_PTHREAD
pthread_cond_signal( &c->cond );
-#elif defined( SYS_CYGWIN )
- PulseEvent( c->event );
+//#elif defined( SYS_CYGWIN )
+// PulseEvent( c->event );
#endif
}