* aout_directx.c: Windows DirectX audio output method
*****************************************************************************
* Copyright (C) 2001 VideoLAN
- * $Id: aout_directx.c,v 1.21 2002/05/21 07:48:50 gbazin Exp $
+ * $Id: aout_directx.c,v 1.22 2002/06/01 12:31:58 sam Exp $
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
*
#include <fcntl.h> /* open(), O_WRONLY */
#include <string.h> /* strerror() */
-#include <stdio.h> /* "intf_msg.h" */
#include <stdlib.h> /* calloc(), malloc(), free() */
-#include <videolan/vlc.h>
+#include <vlc/vlc.h>
+#include <vlc/aout.h>
#include <mmsystem.h>
#include <dsound.h>
-#include "audio_output.h" /* aout_thread_t */
-
/*****************************************************************************
* DirectSound GUIDs.
* Defining them here allows us to get rid of the dxguid library during
* It describes the direct sound specific properties of an audio device.
*****************************************************************************/
-typedef struct aout_sys_s
+struct aout_sys_s
{
LPDIRECTSOUND p_dsobject; /* main Direct Sound object */
long l_buffer_size; /* secondary sound buffer size */
long l_write_position; /* next write position for the buffer */
- volatile boolean_t b_buffer_underflown; /* buffer underflow detection */
+ volatile vlc_bool_t b_buffer_underflown; /* buffer underflow detection */
volatile long l_data_played_from_beginning; /* for underflow detection */
volatile long l_data_written_from_beginning; /* for underflow detection */
DSBPOSITIONNOTIFY notification_events[2]; /* play notification events */
- boolean_t b_notification_thread_die; /* flag to kill the thread */
-
-} aout_sys_t;
+ vlc_bool_t b_notification_thread_die; /* flag to kill the thread */
+};
/*****************************************************************************
* Local prototypes.
HRESULT dsresult;
DSBUFFERDESC dsbuffer_desc;
- intf_WarnMsg( 3, "aout: DirectX aout_Open ");
+ msg_Dbg( p_aout, "aout_Open" );
/* Allocate structure */
p_aout->p_sys = malloc( sizeof( aout_sys_t ) );
if( p_aout->p_sys == NULL )
{
- intf_ErrMsg( "aout error: %s", strerror(ENOMEM) );
+ msg_Err( p_aout, "out of memory" );
return( 1 );
}
/* Initialise DirectSound */
if( DirectxInitDSound( p_aout ) )
{
- intf_WarnMsg( 3, "aout: can't initialise DirectSound ");
+ msg_Warn( p_aout, "cannot initialize DirectSound" );
return( 1 );
}
memset( &dsbuffer_desc, 0, sizeof(DSBUFFERDESC) );
dsbuffer_desc.dwSize = sizeof(DSBUFFERDESC);
dsbuffer_desc.dwFlags = DSBCAPS_PRIMARYBUFFER;
- intf_WarnMsg( 3, "aout: Create direct sound primary buffer ");
+ msg_Warn( p_aout, "create direct sound primary buffer" );
dsresult = IDirectSound_CreateSoundBuffer(p_aout->p_sys->p_dsobject,
&dsbuffer_desc,
&p_aout->p_sys->p_dsbuffer_primary,
NULL);
if( dsresult != DS_OK )
{
- intf_WarnMsg( 3, "aout: can't create direct sound primary buffer ");
+ msg_Warn( p_aout, "cannot create direct sound primary buffer" );
IDirectSound_Release( p_aout->p_sys->p_dsobject );
p_aout->p_sys->p_dsobject = NULL;
p_aout->p_sys->p_dsbuffer_primary = NULL;
CreateEvent( NULL, FALSE, FALSE, NULL );
/* then launch the notification thread */
- intf_WarnMsg( 3, "aout: aout_Open creating DirectSoundThread" );
- if( vlc_thread_create( &p_aout->p_sys->notification_thread_id,
+ msg_Dbg( p_aout, "creating DirectSoundThread" );
+ if( vlc_thread_create( p_aout, &p_aout->p_sys->notification_thread_id,
"DirectSound Notification Thread",
(void *) DirectSoundThread, (void *) p_aout) )
{
- intf_ErrMsg( "aout error: can't create DirectSoundThread" );
- intf_ErrMsg("aout error: %s", strerror(ENOMEM));
+ msg_Err( p_aout, "cannot create DirectSoundThread" );
/* Let's go on anyway */
}
WAVEFORMATEX *p_waveformat;
unsigned long i_size_struct;
- intf_WarnMsg( 3, "aout: DirectX aout_SetFormat ");
+ msg_Dbg( p_aout, "aout_SetFormat" );
/* Set the format of Direct Sound primary buffer */
p_aout->p_sys->p_dsbuffer_primary,
p_waveformat );
}
- else intf_WarnMsg( 3, "aout: can't get primary buffer format" );
+ else msg_Warn( p_aout, "cannot get primary buffer format" );
if( dsresult != DS_OK )
- intf_WarnMsg( 3, "aout: can't set primary buffer format" );
+ msg_Warn( p_aout, "cannot set primary buffer format" );
/* Now we need to take care of Direct Sound secondary buffer */
/* then create a new secondary buffer */
if( DirectxCreateSecondaryBuffer( p_aout ) )
{
- intf_WarnMsg( 3, "aout: DirectX aout_SetFormat cannot create buffer");
+ msg_Warn( p_aout, "cannot create buffer" );
vlc_mutex_unlock( &p_aout->p_sys->buffer_lock );
return( 1 );
}
if( p_aout->p_sys->b_buffer_underflown )
{
- intf_WarnMsg( 3, "aout: DirectX aout_GetBufInfo underflow");
+ msg_Warn( p_aout, "aout_GetBufInfo underflow" );
return( i_buffer_limit );
}
&l_play_position, &l_notused);
if( dsresult != DS_OK )
{
- intf_WarnMsg(3,"aout: DirectX aout_GetBufInfo cannot get current pos");
+ msg_Warn( p_aout, "aout_GetBufInfo cannot get current pos" );
return( i_buffer_limit );
}
+ p_aout->p_sys->l_write_position);
#if 0
- intf_WarnMsg( 3, "aout: DirectX aout_GetBufInfo: %li", l_result);
+ msg_Dbg( p_aout, "aout_GetBufInfo: %i", i_result);
#endif
return l_result;
}
&p_aout->p_sys->l_write_position );
if( dsresult != DS_OK )
{
- intf_WarnMsg( 3, "aout: aout_Play can'get buffer position");
+ msg_Warn( p_aout, "cannot get buffer position" );
p_aout->p_sys->l_write_position = 0;
}
- intf_WarnMsg( 3, "aout: aout_Play underflow");
+ msg_Warn( p_aout, "aout_Play underflow" );
/* reinitialise the underflow detection counters */
p_aout->p_sys->b_buffer_underflown = 0;
p_aout->p_sys->l_data_written_from_beginning = 0;
}
if( dsresult != DS_OK )
{
- intf_WarnMsg( 3, "aout: DirectX aout_Play can't lock buffer");
+ msg_Warn( p_aout, "aout_Play cannot lock buffer" );
vlc_mutex_unlock( &p_aout->p_sys->buffer_lock );
return;
}
}
if( dsresult != DS_OK )
{
- intf_WarnMsg( 3, "aout: DirectX aout_Play can't play buffer");
+ msg_Warn( p_aout, "aout_Play cannot play buffer" );
return;
}
static void aout_Close( aout_thread_t *p_aout )
{
- intf_WarnMsg( 3, "aout: DirectX aout_Close ");
+ msg_Dbg( p_aout, "aout_Close" );
/* kill the position notification thread */
p_aout->p_sys->b_notification_thread_die = 1;
SetEvent( p_aout->p_sys->notification_events[0].hEventNotify );
- vlc_thread_join( p_aout->p_sys->notification_thread_id );
+ vlc_thread_join( p_aout, p_aout->p_sys->notification_thread_id );
vlc_mutex_destroy( &p_aout->p_sys->buffer_lock );
/* release the secondary buffer */
p_aout->p_sys->hdsound_dll = LoadLibrary("DSOUND.DLL");
if( p_aout->p_sys->hdsound_dll == NULL )
{
- intf_WarnMsg( 3, "aout: can't open DSOUND.DLL ");
+ msg_Warn( p_aout, "cannot open DSOUND.DLL" );
return( 1 );
}
if( OurDirectSoundCreate == NULL )
{
- intf_WarnMsg( 3, "aout: GetProcAddress FAILED ");
+ msg_Warn( p_aout, "GetProcAddress FAILED" );
FreeLibrary( p_aout->p_sys->hdsound_dll );
p_aout->p_sys->hdsound_dll = NULL;
return( 1 );
/* Create the direct sound object */
if( OurDirectSoundCreate(NULL, &p_aout->p_sys->p_dsobject, NULL) != DS_OK )
{
- intf_WarnMsg( 3, "aout: can't create a direct sound device ");
+ msg_Warn( p_aout, "cannot create a direct sound device" );
p_aout->p_sys->p_dsobject = NULL;
FreeLibrary( p_aout->p_sys->hdsound_dll );
p_aout->p_sys->hdsound_dll = NULL;
GetDesktopWindow(),
DSSCL_EXCLUSIVE) )
{
- intf_WarnMsg( 3, "aout: can't set direct sound cooperative level ");
+ msg_Warn( p_aout, "cannot set direct sound cooperative level" );
}
return( 0 );
&p_aout->p_sys->p_dsbuffer,
NULL) != DS_OK )
{
- intf_WarnMsg( 3, "aout: can't create direct sound secondary buffer ");
+ msg_Warn( p_aout, "cannot create direct sound secondary buffer" );
p_aout->p_sys->p_dsbuffer = NULL;
return( 1 );
}
p_aout->p_sys->l_buffer_size = dsbcaps.dwBufferBytes;
p_aout->p_sys->l_write_position = 0;
- intf_WarnMsg( 3, "aout: DirectX DirectxCreateSecondaryBuffer: %li",
- p_aout->p_sys->l_buffer_size);
+ msg_Dbg( p_aout, "DirectxCreateSecondaryBuffer: %li",
+ p_aout->p_sys->l_buffer_size );
/* Now the secondary buffer is created, we need to setup its position
* notification */
&IID_IDirectSoundNotify,
(LPVOID *)&p_aout->p_sys->p_dsnotify ) )
{
- intf_WarnMsg( 3, "aout: DirectX can't get Notify interface" );
+ msg_Warn( p_aout, "cannot get Notify interface" );
/* Go on anyway */
p_aout->p_sys->p_dsnotify = NULL;
return( 0 );
2,
p_aout->p_sys->notification_events ) )
{
- intf_WarnMsg( 3, "aout: DirectX can't set position Notification" );
+ msg_Warn( p_aout, "cannot set position Notification" );
/* Go on anyway */
}
if( !SetThreadPriority( GetCurrentThread(),
THREAD_PRIORITY_ABOVE_NORMAL ) )
{
- intf_WarnMsg( 3, "aout: DirectSoundThread could not renice itself" );
+ msg_Warn( p_aout, "DirectSoundThread could not renice itself" );
}
- intf_WarnMsg( 3, "aout: DirectSoundThread ready" );
+ msg_Dbg( p_aout, "DirectSoundThread ready" );
while( !p_aout->p_sys->b_notification_thread_die )
{
/* detect wrap-around */
if( l_data_in_buffer < (-l_buffer_size/2) )
{
- intf_WarnMsg(3,"aout: DirectSoundThread wrap around: %li", l_data_in_buffer);
+ msg_Dbg( p_aout, "DirectSoundThread wrap around: %li",
+ l_data_in_buffer );
l_data_in_buffer += l_buffer_size;
}
/* detect underflow */
if( l_data_in_buffer <= 0 )
{
- intf_WarnMsg(3,"aout: DirectSoundThread underflow: %li", l_data_in_buffer);
+ msg_Warn( p_aout,
+ "DirectSoundThread underflow: %li", l_data_in_buffer );
p_aout->p_sys->b_buffer_underflown = 1;
p_aout->p_sys->l_write_position =
(l_play_position + l_buffer_size/2) % l_buffer_size;
}
if( dsresult != DS_OK )
{
- intf_WarnMsg( 3, "aout: DirectX aout_Play can't lock buffer");
+ msg_Warn( p_aout, "aout_Play cannot lock buffer" );
vlc_mutex_unlock( &p_aout->p_sys->buffer_lock );
return;
}
CloseHandle( notification_events[0] );
CloseHandle( notification_events[1] );
- intf_WarnMsg( 3, "aout: DirectSoundThread exiting" );
+ msg_Dbg( p_aout, "DirectSoundThread exiting" );
}