Commit f09289e8 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

DirectSound: merge memory allocation for sys and notif

This removes one error case and simplifies a bit.
parent f664c1b0
...@@ -44,7 +44,6 @@ ...@@ -44,7 +44,6 @@
*****************************************************************************/ *****************************************************************************/
typedef struct notification_thread_t typedef struct notification_thread_t
{ {
audio_output_t *p_aout;
int i_frame_size; /* size in bytes of one frame */ int i_frame_size; /* size in bytes of one frame */
int i_write_slot; /* current write position in our circular buffer */ int i_write_slot; /* current write position in our circular buffer */
...@@ -75,7 +74,7 @@ struct aout_sys_t ...@@ -75,7 +74,7 @@ struct aout_sys_t
* takes care of mixing all the * takes care of mixing all the
* secondary buffers into the primary) */ * secondary buffers into the primary) */
notification_thread_t *p_notif; /* DirectSoundThread id */ notification_thread_t notif; /* DirectSoundThread id */
int i_frame_size; /* Size in bytes of one frame */ int i_frame_size; /* Size in bytes of one frame */
...@@ -290,28 +289,20 @@ static int OpenAudio( vlc_object_t *p_this ) ...@@ -290,28 +289,20 @@ static int OpenAudio( vlc_object_t *p_this )
} }
/* Now we need to setup our DirectSound play notification structure */ /* Now we need to setup our DirectSound play notification structure */
p_aout->sys->p_notif = calloc( 1, sizeof( *p_aout->sys->p_notif ) ); vlc_atomic_set(&p_aout->sys->notif.abort, 0);
if( unlikely( !p_aout->sys->p_notif ) ) p_aout->sys->notif.event = CreateEvent( 0, FALSE, FALSE, 0 );
{ if( unlikely(p_aout->sys->notif.event == NULL) )
CloseAudio( VLC_OBJECT(p_aout) ); abort();
return VLC_ENOMEM; p_aout->sys->notif.i_frame_size = p_aout->sys->i_frame_size;
}
p_aout->sys->p_notif->p_aout = p_aout;
vlc_atomic_set(&p_aout->sys->p_notif->abort, 0);
p_aout->sys->p_notif->event = CreateEvent( 0, FALSE, FALSE, 0 );
p_aout->sys->p_notif->i_frame_size = p_aout->sys->i_frame_size;
/* then launch the notification thread */ /* then launch the notification thread */
msg_Dbg( p_aout, "creating DirectSoundThread" ); msg_Dbg( p_aout, "creating DirectSoundThread" );
if( vlc_clone( &p_aout->sys->p_notif->thread, if( vlc_clone( &p_aout->sys->notif.thread, DirectSoundThread, p_aout,
DirectSoundThread, p_aout->sys->p_notif,
VLC_THREAD_PRIORITY_HIGHEST ) ) VLC_THREAD_PRIORITY_HIGHEST ) )
{ {
msg_Err( p_aout, "cannot create DirectSoundThread" ); msg_Err( p_aout, "cannot create DirectSoundThread" );
CloseHandle( p_aout->sys->p_notif->event ); CloseHandle( p_aout->sys->notif.event );
free( p_aout->sys->p_notif ); p_aout->sys->notif.event = NULL;
p_aout->sys->p_notif = NULL;
CloseAudio( VLC_OBJECT(p_aout) ); CloseAudio( VLC_OBJECT(p_aout) );
return VLC_EGENERIC; return VLC_EGENERIC;
} }
...@@ -569,13 +560,13 @@ static void Probe( audio_output_t * p_aout ) ...@@ -569,13 +560,13 @@ static void Probe( audio_output_t * p_aout )
static void Play( audio_output_t *p_aout, block_t *p_buffer ) static void Play( audio_output_t *p_aout, block_t *p_buffer )
{ {
/* get the playing date of the first aout buffer */ /* get the playing date of the first aout buffer */
p_aout->sys->p_notif->start_date = p_buffer->i_pts; p_aout->sys->notif.start_date = p_buffer->i_pts;
/* fill in the first samples (zeroes) */ /* fill in the first samples (zeroes) */
FillBuffer( p_aout, 0, NULL ); FillBuffer( p_aout, 0, NULL );
/* wake up the audio output thread */ /* wake up the audio output thread */
SetEvent( p_aout->sys->p_notif->event ); SetEvent( p_aout->sys->notif.event );
aout_PacketPlay( p_aout, p_buffer ); aout_PacketPlay( p_aout, p_buffer );
p_aout->pf_play = aout_PacketPlay; p_aout->pf_play = aout_PacketPlay;
...@@ -599,15 +590,15 @@ static void CloseAudioCommon( vlc_object_t *p_this ) ...@@ -599,15 +590,15 @@ static void CloseAudioCommon( vlc_object_t *p_this )
msg_Dbg( p_aout, "closing audio device" ); msg_Dbg( p_aout, "closing audio device" );
/* kill the position notification thread, if any */ /* kill the position notification thread, if any */
if( p_sys->p_notif ) if( p_sys->notif.event != NULL )
{ {
vlc_atomic_set(&p_aout->sys->p_notif->abort, 1); vlc_atomic_set(&p_aout->sys->notif.abort, 1);
/* wake up the audio thread if needed */ /* wake up the audio thread if needed */
if( p_aout->pf_play == Play ) if( p_aout->pf_play == Play )
SetEvent( p_sys->p_notif->event ); SetEvent( p_sys->notif.event );
vlc_join( p_sys->p_notif->thread, NULL ); vlc_join( p_sys->notif.thread, NULL );
free( p_sys->p_notif ); CloseHandle( p_sys->notif.event );
} }
/* release the secondary buffer */ /* release the secondary buffer */
...@@ -938,8 +929,8 @@ static void DestroyDSBuffer( audio_output_t *p_aout ) ...@@ -938,8 +929,8 @@ static void DestroyDSBuffer( audio_output_t *p_aout )
static int FillBuffer( audio_output_t *p_aout, int i_frame, static int FillBuffer( audio_output_t *p_aout, int i_frame,
aout_buffer_t *p_buffer ) aout_buffer_t *p_buffer )
{ {
notification_thread_t *p_notif = p_aout->sys->p_notif;
aout_sys_t *p_sys = p_aout->sys; aout_sys_t *p_sys = p_aout->sys;
notification_thread_t *p_notif = &p_sys->notif;
void *p_write_position, *p_wrap_around; void *p_write_position, *p_wrap_around;
unsigned long l_bytes1, l_bytes2; unsigned long l_bytes1, l_bytes2;
HRESULT dsresult; HRESULT dsresult;
...@@ -1008,8 +999,8 @@ static int FillBuffer( audio_output_t *p_aout, int i_frame, ...@@ -1008,8 +999,8 @@ static int FillBuffer( audio_output_t *p_aout, int i_frame,
*****************************************************************************/ *****************************************************************************/
static void* DirectSoundThread( void *data ) static void* DirectSoundThread( void *data )
{ {
notification_thread_t *p_notif = (notification_thread_t*)data; audio_output_t *p_aout = (audio_output_t *)data;
audio_output_t *p_aout = p_notif->p_aout; notification_thread_t *p_notif = &p_aout->sys->notif;
mtime_t last_time; mtime_t last_time;
int canc = vlc_savecancel (); int canc = vlc_savecancel ();
...@@ -1101,9 +1092,6 @@ static void* DirectSoundThread( void *data ) ...@@ -1101,9 +1092,6 @@ static void* DirectSoundThread( void *data )
/* make sure the buffer isn't playing */ /* make sure the buffer isn't playing */
IDirectSoundBuffer_Stop( p_aout->sys->p_dsbuffer ); IDirectSoundBuffer_Stop( p_aout->sys->p_dsbuffer );
/* free the event */
CloseHandle( p_notif->event );
vlc_restorecancel (canc); vlc_restorecancel (canc);
msg_Dbg( p_aout, "DirectSoundThread exiting" ); msg_Dbg( p_aout, "DirectSoundThread exiting" );
return NULL; return NULL;
......
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