to the DVD drive for the whole iovec.
* Fixed _win32_dvdcss_aread to work around the WinASPI32 64kb transfer
size restriction.
* New and theoretically better Win32 pthread implementation which fixes a
problem I was having when changing title on a DVD (netlist related).
vlc_cond_multicast may or may not work.
* Fixed the "quit" event handling in directx/vout_events.c.
* dvd_ifo.c now takes into account error messages from UDFFindFile.
* Temporarily disabled aout_Probe() in aout_SDL (this function
is creating an awful lot of problems - libSDL bug ).
#===================#
HEAD
-
+ * dvdcss_readv() optimisations for Win32.
+ * Fixed _win32_dvdcss_aread() to work around the WinASPI32 64kb transfer
+ size restriction.
+ * New and theoretically better Win32 pthread implementation.
+ * dvd_ifo.c now takes into account error messages from UDFFindFile.
+ * Fixed the "quit" event handling in directx/vout_events.c.
+ * Temporarily disabled aout_Probe() in aout_SDL (libSDL bug).
* libdvdcss segfault fixes.
* Tuned constants, since it seems to make people happy.
* Fixed the "paused movie won't restart" bug.
* Fixed 2 Win32 bugs in libdvdcss (in _win32_dvdcss_readv), one of them
should have prevented the Win9x dvd input from working.
* Moved the "if(Win2k)" out of the loop in _win32_dvdcss_readv.
- * Put a readv() function in input_iovec.h, the input_es now compiles.
- * Modified input_ts to use this function.
+ * Put a readv() function in input_iovec.h, the input_es plugin now compiles
+ (Win32).
+ * Modified input_ts to use readv() in input_iovec.h (Win32).
* Fixed an initialisation bug in vout_directx.c.
- * Right clicking on the mouse now displays the navigation menu.
+ * Right clicking on the mouse displays the navigation menu (DirectX plugin).
* Fixed audio/video synchro bug with esd, should fix buggy sound due
to 44100-48000 Hz conversions.
* The Win32 GetMessage function has been isolated in a thread. This has
* libdvdcss.c: DVD reading library.
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
- * $Id: libdvdcss.c,v 1.8 2001/07/25 00:23:40 sam Exp $
+ * $Id: libdvdcss.c,v 1.9 2001/07/25 08:41:21 gbazin Exp $
*
* Authors: Stéphane Borel <stef@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
*****************************************************************************/
#if defined( WIN32 )
static int _win32_dvdcss_readv ( int i_fd, struct iovec *p_iovec,
- int i_num_buffers );
+ int i_num_buffers, char *p_tmp_buffer );
static int _win32_dvdcss_aopen ( char c_drive, dvdcss_handle dvdcss );
static int _win32_dvdcss_aclose ( int i_fd );
static int _win32_dvdcss_aseek ( int i_fd, int i_blocks, int i_method );
}
}
+ /* initialise readv temporary buffer */
+ dvdcss->p_readv_buffer = NULL;
+ dvdcss->i_readv_buf_size = 0;
+
#else
dvdcss->i_fd = open( psz_target, 0 );
{
_win32_dvdcss_aclose( dvdcss->i_fd );
}
+
+ /* Free readv temporary buffer */
+ if( dvdcss->p_readv_buffer )
+ {
+ free( dvdcss->p_readv_buffer );
+ dvdcss->p_readv_buffer = NULL;
+ dvdcss->i_readv_buf_size = 0;
+ }
+
#else
close( dvdcss->i_fd );
+
#endif
return 0;
int i_read;
#if defined( WIN32 )
- i_read = _win32_dvdcss_readv( dvdcss->i_fd, p_iovec, i_blocks );
+ /* Check the size of the readv temp buffer, just in case we need to
+ * realloc something bigger */
+ if( dvdcss->i_readv_buf_size < i_blocks * DVDCSS_BLOCK_SIZE )
+ {
+ dvdcss->i_readv_buf_size = i_blocks * DVDCSS_BLOCK_SIZE;
+
+ if( dvdcss->p_readv_buffer ) free( dvdcss->p_readv_buffer );
+
+ /* Allocate a buffer which will be used as a temporary storage
+ * for readv */
+ dvdcss->p_readv_buffer = malloc( dvdcss->i_readv_buf_size );
+ if( !dvdcss->p_readv_buffer )
+ {
+ _dvdcss_error( dvdcss, " failed (readv)" );
+ return -1;
+ }
+ }
+
+ i_read = _win32_dvdcss_readv( dvdcss->i_fd, p_iovec, i_blocks,
+ dvdcss->p_readv_buffer );
return i_read;
+
#else
i_read = readv( dvdcss->i_fd, p_iovec, i_blocks );
return i_read / DVDCSS_BLOCK_SIZE;
+
#endif
}
+
#if defined( WIN32 )
/*****************************************************************************
* _win32_dvdcss_aread for win9x
*****************************************************************************/
static int _win32_dvdcss_readv( int i_fd, struct iovec *p_iovec,
- int i_num_buffers )
+ int i_num_buffers, char *p_tmp_buffer )
{
- int i_index, i_len, i_total = 0;
- unsigned char *p_base;
- int i_blocks;
+ int i_index;
+ int i_blocks, i_blocks_total = 0;
- if( WIN2K )
+ for( i_index = i_num_buffers; i_index; i_index-- )
{
- for( i_index = i_num_buffers; i_index; i_index-- )
- {
- i_len = p_iovec->iov_len;
- p_base = p_iovec->iov_base;
+ i_blocks_total += p_iovec[i_index-1].iov_len;
+ }
- if( i_len > 0 )
- {
- unsigned long int i_bytes;
- if( !ReadFile( (HANDLE) i_fd, p_base, i_len, &i_bytes, NULL ) )
- {
- return -1;
- /* One of the reads failed, too bad.
- We won't even bother returning the reads that went well,
- and like in the posix spec the file postition is left
- unspecified after a failure */
- }
- i_blocks = i_bytes / DVDCSS_BLOCK_SIZE;
-
- i_total += i_blocks;
-
- if( i_blocks != (i_len / DVDCSS_BLOCK_SIZE) )
- {
- /* we reached the end of the file */
- return i_total;
- }
+ if( i_blocks_total <= 0 ) return 0;
- }
+ i_blocks_total /= DVDCSS_BLOCK_SIZE;
- p_iovec++;
+ if( WIN2K )
+ {
+ unsigned long int i_bytes;
+ if( !ReadFile( (HANDLE)i_fd, p_tmp_buffer,
+ i_blocks_total * DVDCSS_BLOCK_SIZE, &i_bytes, NULL ) )
+ {
+ return -1;
+ /* The read failed... too bad.
+ As in the posix spec the file postition is left
+ unspecified after a failure */
}
+ i_blocks = i_bytes / DVDCSS_BLOCK_SIZE;
}
else /* Win9x */
{
- for( i_index = i_num_buffers; i_index; i_index-- )
+ i_blocks = _win32_dvdcss_aread( i_fd, p_tmp_buffer, i_blocks_total );
+ if( i_blocks < 0 )
{
- i_len = p_iovec->iov_len / DVDCSS_BLOCK_SIZE;
- p_base = p_iovec->iov_base;
-
- if( i_len > 0 )
- {
- i_blocks = _win32_dvdcss_aread( i_fd, p_base, i_len );
- if( i_blocks < 0 )
- {
- return -1; /* idem */
- }
-
- i_total += i_blocks;
-
- if( i_blocks != i_len )
- {
- /* we reached the end of the file or a signal interrupted
- the read */
- return i_total;
- }
- }
-
- p_iovec++;
+ return -1; /* idem */
}
}
- return i_total;
+ /* We just have to copy the content of the temp buffer into the iovecs */
+ i_index = 0;
+ i_blocks_total = i_blocks;
+ while( i_blocks_total > 0 )
+ {
+ memcpy( p_iovec[i_index].iov_base,
+ &p_tmp_buffer[(i_blocks - i_blocks_total) * DVDCSS_BLOCK_SIZE],
+ p_iovec[i_index].iov_len );
+ /* if we read less blocks than asked, we'll just end up copying
+ garbage, this isn't an issue as we return the number of
+ blocks actually read */
+ i_blocks_total -= ( p_iovec[i_index].iov_len / DVDCSS_BLOCK_SIZE );
+ i_index++;
+ }
+
+ return i_blocks;
}
/*****************************************************************************
int i, j, i_hostadapters;
long (*lpGetSupport)( void );
long (*lpSendCommand)( void* );
-
+
hASPI = LoadLibrary( "wnaspi32.dll" );
if( hASPI == NULL )
{
(FARPROC) lpGetSupport = GetProcAddress( hASPI, "GetASPI32SupportInfo" );
(FARPROC) lpSendCommand = GetProcAddress( hASPI, "SendASPI32Command" );
-
+
if(lpGetSupport == NULL || lpSendCommand == NULL )
{
_dvdcss_debug( dvdcss, "unable to get aspi function pointers" );
lpSendCommand( (void*) &srbDiskInfo );
- if( srbDiskInfo.SRB_Status == SS_COMP &&
- srbDiskInfo.SRB_Int13HDriveInfo == c_drive )
+ if( (srbDiskInfo.SRB_Status == SS_COMP) &&
+ (srbDiskInfo.SRB_Int13HDriveInfo == c_drive) )
{
fd->i_sid = MAKEWORD( i, j );
return (int) fd;
free( (void*) fd );
FreeLibrary( hASPI );
_dvdcss_debug( dvdcss, "unable to get haid and target (aspi)" );
-
- return( -1 );
+ return( -1 );
}
/*****************************************************************************
static int _win32_dvdcss_aread( int i_fd, void *p_data, int i_blocks )
{
HANDLE hEvent;
- DWORD dwStart, dwLen;
struct SRB_ExecSCSICmd ssc;
struct w32_aspidev *fd = (struct w32_aspidev *) i_fd;
- memset( &ssc, 0, sizeof( ssc ) );
-
- dwStart = fd->i_blocks;
- dwLen = i_blocks;
-
+ /* Create the transfer completion event */
hEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
if( hEvent == NULL )
{
return -1;
}
+ memset( &ssc, 0, sizeof( ssc ) );
+
ssc.SRB_Cmd = SC_EXEC_SCSI_CMD;
ssc.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
ssc.SRB_HaId = LOBYTE( fd->i_sid );
ssc.SRB_Target = HIBYTE( fd->i_sid );
ssc.SRB_SenseLen = SENSE_LEN;
- ssc.SRB_PostProc = (LPVOID) hEvent;
-
- ssc.SRB_BufLen = dwLen * DVDCSS_BLOCK_SIZE;
+
+ ssc.SRB_PostProc = (LPVOID) hEvent;
ssc.SRB_BufPointer = p_data;
ssc.SRB_CDBLen = 12;
-
+
ssc.CDBByte[0] = 0xA8; /* RAW */
- ssc.CDBByte[2] = (UCHAR) dwStart >> 24;
- ssc.CDBByte[3] = (UCHAR) (dwStart >> 16) & 0xff;
- ssc.CDBByte[4] = (UCHAR) (dwStart >> 8) & 0xff;
- ssc.CDBByte[5] = (UCHAR) (dwStart) & 0xff;
- ssc.CDBByte[6] = (UCHAR) dwLen >> 24;
- ssc.CDBByte[7] = (UCHAR) (dwLen >> 16) & 0xff;
- ssc.CDBByte[8] = (UCHAR) (dwLen >> 8) & 0xff;
- ssc.CDBByte[9] = (UCHAR) (dwLen) & 0xff;
-
- ResetEvent( hEvent );
- if( fd->lpSendCommand( (void*) &ssc ) == SS_PENDING )
+ ssc.CDBByte[2] = (UCHAR) (fd->i_blocks >> 24);
+ ssc.CDBByte[3] = (UCHAR) (fd->i_blocks >> 16) & 0xff;
+ ssc.CDBByte[4] = (UCHAR) (fd->i_blocks >> 8) & 0xff;
+ ssc.CDBByte[5] = (UCHAR) (fd->i_blocks) & 0xff;
+
+ /* We have to break down the reads into 64kb pieces (ASPI restriction) */
+ if( i_blocks > 32 )
{
- WaitForSingleObject( hEvent, INFINITE );
+ ssc.SRB_BufLen = 32 * DVDCSS_BLOCK_SIZE;
+ ssc.CDBByte[9] = 32;
+ fd->i_blocks += 32;
+
+ /* Initiate transfer */
+ ResetEvent( hEvent );
+ fd->lpSendCommand( (void*) &ssc );
+
+ /* transfer the next 64kb (_win32_dvdcss_aread is called recursively)
+ * We need to check the status of the read on return */
+ if( _win32_dvdcss_aread( i_fd, p_data + 32 * DVDCSS_BLOCK_SIZE,
+ i_blocks - 32) < 0 )
+ {
+ return -1;
+ }
}
+ else
+ {
+ /* This is the last transfer */
+ ssc.SRB_BufLen = i_blocks * DVDCSS_BLOCK_SIZE;
+ ssc.CDBByte[9] = (UCHAR) i_blocks;
+ fd->i_blocks += i_blocks;
+ /* Initiate transfer */
+ ResetEvent( hEvent );
+ fd->lpSendCommand( (void*) &ssc );
+
+ }
+
+ /* If the command has still not been processed, wait until it's finished */
+ if( ssc.SRB_Status == SS_PENDING )
+ {
+ WaitForSingleObject( hEvent, INFINITE );
+ }
CloseHandle( hEvent );
+ /* check that the transfer went as planned */
if( ssc.SRB_Status != SS_COMP )
{
- return -1;
+ return -1;
}
-
- fd->i_blocks += i_blocks;
return i_blocks;
}
* private.h: private DVD reading library data
*****************************************************************************
* Copyright (C) 1998-2001 VideoLAN
- * $Id: libdvdcss.h,v 1.5 2001/07/25 00:23:40 sam Exp $
+ * $Id: libdvdcss.h,v 1.6 2001/07/25 08:41:21 gbazin Exp $
*
* Authors: Stéphane Borel <stef@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
boolean_t b_errors;
boolean_t b_debug;
+#if defined( WIN32 )
+ char *p_readv_buffer;
+ int i_readv_buf_size;
+#endif
};
/*****************************************************************************
* This header provides a portable threads implementation.
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
- * $Id: threads.h,v 1.20 2001/07/18 14:21:00 massiot Exp $
+ * $Id: threads.h,v 1.21 2001/07/25 08:41:21 gbazin Exp $
*
* Authors: Jean-Marc Dressler <polux@via.ecp.fr>
* Samuel Hocevar <sam@via.ecp.fr>
# include <kernel/scheduler.h>
# include <byteorder.h>
-#elif defined( WIN32 ) /* Win32 with MinGW32 compiler */
+#elif defined( WIN32 )
# include <windows.h>
# include <process.h>
} vlc_cond_t;
#elif defined( WIN32 )
-typedef HANDLE vlc_thread_t;
-typedef HANDLE vlc_mutex_t;
-typedef HANDLE vlc_cond_t;
+typedef HANDLE vlc_thread_t;
+typedef CRITICAL_SECTION vlc_mutex_t;
+
+typedef struct
+{
+ int i_waiting_threads;
+ HANDLE signal;
+} vlc_cond_t;
+
typedef unsigned (__stdcall *PTHREAD_START) (void *);
#endif
struct itimerval itimer;
} wrapper_t;
-#endif
+
+#ifdef WIN32
+struct itimerval
+{
+ struct timeval it_value;
+ struct timeval it_interval;
+};
+
+int setitimer(int kind, const struct itimerval* itnew,
+ struct itimerval* itold);
+
+#define ITIMER_REAL 1
+#define ITIMER_PROF 2
+
+#endif /* WIN32 */
+
+#endif /* PROFILING */
/*****************************************************************************
* vlc_threads_init: initialize threads system
return B_OK;
#elif defined( WIN32 )
- *p_mutex = CreateMutex(0,FALSE,0);
- return (*p_mutex?0:1);
+ InitializeCriticalSection( p_mutex );
+ return 0;
#endif
}
return err;
#elif defined( WIN32 )
- WaitForSingleObject( *p_mutex, INFINITE );
+ EnterCriticalSection( p_mutex );
return 0;
#endif
return B_OK;
#elif defined( WIN32 )
- ReleaseMutex( *p_mutex );
+ LeaveCriticalSection( p_mutex );
return 0;
#endif
return B_OK;
#elif defined( WIN32 )
- CloseHandle(*p_mutex);
+ DeleteCriticalSection( p_mutex );
return 0;
#endif
return 0;
#elif defined( WIN32 )
+ /* initialise counter */
+ p_condvar->i_waiting_threads = 0;
+
/* Create an auto-reset event. */
- *p_condvar = CreateEvent( NULL, /* no security */
- FALSE, /* auto-reset event */
- FALSE, /* non-signaled initially */
- NULL ); /* unnamed */
+ p_condvar->signal = CreateEvent( NULL, /* no security */
+ FALSE, /* auto-reset event */
+ FALSE, /* non-signaled initially */
+ NULL ); /* unnamed */
- return( *p_condvar ? 0 : 1 );
+ return( !p_condvar->signal );
#endif
}
return 0;
#elif defined( WIN32 )
- /* Try to release one waiting thread. */
- PulseEvent ( *p_condvar );
+ /* Release one waiting thread if one is available. */
+ /* For this trick to work properly, the vlc_cond_signal must be surrounded
+ * by a mutex. This will prevent another thread from stealing the signal */
+ while( p_condvar->i_waiting_threads )
+ {
+ PulseEvent( p_condvar->signal );
+ Sleep( 0 ); /* deschedule the current thread */
+ }
return 0;
#endif
return 0;
#elif defined( WIN32 )
- /* Try to release one waiting thread. */
- PulseEvent ( *p_condvar );
+ /* Release all waiting threads. */
+ /* For this trick to work properly, the vlc_cond_signal must be surrounded
+ * by a mutex. This will prevent another thread from stealing the signal */
+ while( p_condvar->i_waiting_threads )
+ {
+ PulseEvent( p_condvar->signal );
+ Sleep( 0 ); /* deschedule the current thread */
+ }
return 0;
#endif
return 0;
#elif defined( WIN32 )
- /* Release the <external_mutex> here and wait for the event
- * to become signaled, due to <pthread_cond_signal> being
- * called. */
+ /* The ideal would be to use a function which atomically releases the
+ * mutex and initiate the waiting.
+ * Unfortunately only the SignalObjectAndWait function does this and it's
+ * only supported on WinNT/2K, furthermore it cannot take multiple
+ * events as parameters.
+ *
+ * The solution we use should however fulfill all our needs (even though
+ * it is not a correct pthreads implementation)
+ */
+ int i_result;
+
+ p_condvar->i_waiting_threads ++;
+
+ /* Release the mutex */
vlc_mutex_unlock( p_mutex );
- WaitForSingleObject( *p_condvar, INFINITE );
+ i_result = WaitForSingleObject( p_condvar->signal, INFINITE);
+
+ /* maybe we should protect this with a mutex ? */
+ p_condvar->i_waiting_threads --;
/* Reacquire the mutex before returning. */
vlc_mutex_lock( p_mutex );
- return 0;
+
+ return( i_result == WAIT_FAILED );
#endif
}
return 0;
#elif defined( WIN32 )
- CloseHandle( *p_condvar );
- return 0;
+ return( !CloseHandle( p_condvar->signal ) );
#endif
}
* vlc_thread_create: create a thread
*****************************************************************************/
static __inline__ int vlc_thread_create( vlc_thread_t *p_thread,
- char *psz_name, vlc_thread_func_t func,
+ char *psz_name,
+ vlc_thread_func_t func,
void *p_data )
{
int i_ret;
return func( p_data );
}
#endif
-
* aout_directx.c: Windows DirectX audio output method
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
- * $Id: aout_directx.c,v 1.5 2001/07/12 20:44:52 reno Exp $
+ * $Id: aout_directx.c,v 1.6 2001/07/25 08:41:21 gbazin Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
*
: (p_aout->p_sys->l_buffer_size - l_play_position
+ p_aout->p_sys->l_write_position) /2 ;
+#if 0
intf_WarnMsg( 5, "aout: DirectX aout_GetBufInfo: %li", l_result);
+#endif
return l_result;
}
* vout_events.c: Windows DirectX video output events handler
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
- * $Id: vout_events.c,v 1.2 2001/07/12 23:06:54 gbazin Exp $
+ * $Id: vout_events.c,v 1.3 2001/07/25 08:41:21 gbazin Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
*
case WM_RBUTTONUP:
intf_WarnMsg( 4, "vout: vout_Manage WM_RBUTTONUP" );
- /* FIXME: need locking ! */
p_main->p_intf->b_menu_change = 1;
break;
{
case VK_ESCAPE:
case VK_F12:
- p_main->p_intf->b_die = 1;
+ PostQuitMessage( 0 );
break;
}
TranslateMessage(&msg);
{
case 'q':
case 'Q':
- p_main->p_intf->b_die = 1;
+ PostQuitMessage( 0 );
break;
case 'f': /* switch to fullscreen */
/* Set thread Status */
p_vout->p_sys->i_event_thread_status = THREAD_OVER;
- return;
}
* dvd_ifo.c: Functions for ifo parsing
*****************************************************************************
* Copyright (C) 1999-2001 VideoLAN
- * $Id: dvd_ifo.c,v 1.34 2001/06/20 07:43:48 sam Exp $
+ * $Id: dvd_ifo.c,v 1.35 2001/07/25 08:41:21 gbazin Exp $
*
* Authors: Stéphane Borel <stef@via.ecp.fr>
* German Tischler <tanis@gaspode.franken.de>
/* find the start sector of video information on the dvd */
p_ifo->i_start = UDFFindFile( p_ifo->dvdhandle, "/VIDEO_TS/VIDEO_TS.IFO" );
+ if( !p_ifo->i_start ) return -1;
p_tmp = FillBuffer( p_ifo, p_buf, p_ifo->i_start );
//i_start = p_ifo->i_pos;
* vdec_idct.c : common IDCT functions
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
- * $Id: vdec_idct.c,v 1.2 2001/07/17 09:48:07 massiot Exp $
+ * $Id: vdec_idct.c,v 1.3 2001/07/25 08:41:21 gbazin Exp $
*
* Authors: Gaël Hendryckx <jimmy@via.ecp.fr>
*
*****************************************************************************/
#include "defs.h"
+#include <stdlib.h> /* malloc() */
#include <string.h> /* memcpy(), memset() */
#include "config.h"
* aout_sdl.c : audio sdl functions library
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
- * $Id: aout_sdl.c,v 1.14 2001/07/12 20:44:52 reno Exp $
+ * $Id: aout_sdl.c,v 1.15 2001/07/25 08:41:21 gbazin Exp $
*
* Authors: Michel Kaempf <maxx@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org>
*****************************************************************************/
static int aout_Probe( probedata_t *p_data )
{
+#if 0
SDL_AudioSpec desired, obtained;
/* Start AudioSDL */
/* Otherwise, there are good chances we can use this plugin, return 100. */
intf_DbgMsg( "aout: SDL_OpenAudio successfully run" );
SDL_CloseAudio();
+#endif
if( TestMethod( AOUT_METHOD_VAR, "sdl" ) )
{