Commit 06895b5b authored by Eric Petit's avatar Eric Petit

modules/gui/beos/AudioOutput.cpp: cleaning

parent a0764279
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* AudioOutput.cpp: BeOS audio output * AudioOutput.cpp: BeOS audio output
***************************************************************************** *****************************************************************************
* Copyright (C) 1999, 2000, 2001 VideoLAN * Copyright (C) 1999, 2000, 2001 VideoLAN
* $Id: AudioOutput.cpp,v 1.27 2003/01/14 15:31:12 titer Exp $ * $Id: AudioOutput.cpp,v 1.28 2003/05/07 19:20:23 titer Exp $
* *
* Authors: Jean-Marc Dressler <polux@via.ecp.fr> * Authors: Jean-Marc Dressler <polux@via.ecp.fr>
* Samuel Hocevar <sam@zoy.org> * Samuel Hocevar <sam@zoy.org>
...@@ -46,48 +46,56 @@ extern "C" ...@@ -46,48 +46,56 @@ extern "C"
* aout_sys_t: BeOS audio output method descriptor * aout_sys_t: BeOS audio output method descriptor
*****************************************************************************/ *****************************************************************************/
typedef struct aout_sys_t typedef struct latency_t
{ {
BSoundPlayer *p_player; VLC_COMMON_MEMBERS
vlc_mutex_t lock;
BSoundPlayer * p_player;
mtime_t latency; mtime_t latency;
} latency_t;
typedef struct aout_sys_t
{
BSoundPlayer * p_player;
latency_t * p_latency;
} aout_sys_t; } aout_sys_t;
/***************************************************************************** /*****************************************************************************
* Local prototypes. * Local prototypes.
*****************************************************************************/ *****************************************************************************/
static void Play ( void *p_aout, void *p_buffer, size_t size, static void Play ( void * p_aout, void * p_buffer, size_t size,
const media_raw_audio_format &format ); const media_raw_audio_format & format );
static void DoNothing ( aout_instance_t *p_aout ); static void DoNothing ( aout_instance_t * p_aout );
static int CheckLatency ( aout_instance_t *p_aout ); static int CheckLatency ( latency_t * p_latency );
/***************************************************************************** /*****************************************************************************
* OpenAudio * OpenAudio
*****************************************************************************/ *****************************************************************************/
int E_(OpenAudio) ( vlc_object_t * p_this ) int E_(OpenAudio) ( vlc_object_t * p_this )
{ {
aout_instance_t *p_aout = (aout_instance_t*) p_this; aout_instance_t * p_aout = (aout_instance_t*) p_this;
p_aout->output.p_sys = (aout_sys_t *) malloc( sizeof( aout_sys_t ) ); p_aout->output.p_sys = (aout_sys_t*) malloc( sizeof( aout_sys_t ) );
if( p_aout->output.p_sys == NULL ) if( p_aout->output.p_sys == NULL )
{ {
msg_Err( p_aout, "Not enough memory" ); msg_Err( p_aout, "Not enough memory" );
return -1; return -1;
} }
aout_sys_t *p_sys = p_aout->output.p_sys; aout_sys_t * p_sys = p_aout->output.p_sys;
aout_VolumeSoftInit( p_aout ); aout_VolumeSoftInit( p_aout );
int i_nb_channels = aout_FormatNbChannels( &p_aout->output.output ); int i_nb_channels = aout_FormatNbChannels( &p_aout->output.output );
/* BSoundPlayer does not support more than 2 channels AFAIK */ /* BSoundPlayer does not support more than 2 channels AFAIK */
if ( i_nb_channels > 2 ) if( i_nb_channels > 2 )
{ {
i_nb_channels = 2; i_nb_channels = 2;
p_aout->output.output.i_physical_channels p_aout->output.output.i_physical_channels
= AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT; = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT;
} }
media_raw_audio_format *p_format; media_raw_audio_format * p_format;
p_format = (media_raw_audio_format*) p_format = (media_raw_audio_format*)
malloc( sizeof( media_raw_audio_format ) ); malloc( sizeof( media_raw_audio_format ) );
...@@ -114,18 +122,17 @@ int E_(OpenAudio) ( vlc_object_t * p_this ) ...@@ -114,18 +122,17 @@ int E_(OpenAudio) ( vlc_object_t * p_this )
return -1; return -1;
} }
/* FIXME FIXME FIXME /* FIXME
* We should check BSoundPlayer Latency() everytime we call * We should check BSoundPlayer Latency() everytime we call
* aout_OutputNextBuffer(). Unfortunatly, it does not seem to work * aout_OutputNextBuffer(). Unfortunatly, it does not seem to work
* correctly: on my computer, it hangs for about 5 seconds at the * correctly: on my computer, it hangs for about 5 seconds at the
* beginning of the file. This is not acceptable, so we will start * beginning of the file. This is not acceptable, so we will start
* playing the file with a default latency (my computer's one ;p ) * playing the file with a default latency (my computer's one ;p )
* and we create a thread who's going to update it ASAP. According * and we create a thread which is going to update it ASAP. */
* to what I've seen, the latency is almost constant most of the p_sys->p_latency = (latency_t*) vlc_object_create( p_aout, sizeof(latency_t) );
* time anyway -- titer */ p_sys->p_latency->p_player = p_sys->p_player;
p_sys->latency = 16209; p_sys->p_latency->latency = 27613;
vlc_mutex_init( p_aout, &p_sys->lock ); if( vlc_thread_create( p_sys->p_latency, "latency", CheckLatency,
if( vlc_thread_create( p_aout, "latency", CheckLatency,
VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) ) VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
{ {
msg_Err( p_aout, "cannot create Latency thread" ); msg_Err( p_aout, "cannot create Latency thread" );
...@@ -140,16 +147,17 @@ int E_(OpenAudio) ( vlc_object_t * p_this ) ...@@ -140,16 +147,17 @@ int E_(OpenAudio) ( vlc_object_t * p_this )
/***************************************************************************** /*****************************************************************************
* CloseAudio * CloseAudio
*****************************************************************************/ *****************************************************************************/
void E_(CloseAudio) ( vlc_object_t *p_this ) void E_(CloseAudio) ( vlc_object_t * p_this )
{ {
aout_instance_t * p_aout = (aout_instance_t *) p_this; aout_instance_t * p_aout = (aout_instance_t *) p_this;
aout_sys_t * p_sys = (aout_sys_t *) p_aout->output.p_sys; aout_sys_t * p_sys = (aout_sys_t *) p_aout->output.p_sys;
p_aout->b_die = VLC_TRUE; /* Stop the latency thread */
vlc_thread_join( p_aout ); p_sys->p_latency->b_die = VLC_TRUE;
p_aout->b_die = VLC_FALSE; vlc_thread_join( p_sys->p_latency );
vlc_mutex_destroy( &p_sys->lock ); vlc_object_destroy( p_sys->p_latency );
/* Clean up */
p_sys->p_player->Stop(); p_sys->p_player->Stop();
delete p_sys->p_player; delete p_sys->p_player;
free( p_sys ); free( p_sys );
...@@ -158,30 +166,27 @@ void E_(CloseAudio) ( vlc_object_t *p_this ) ...@@ -158,30 +166,27 @@ void E_(CloseAudio) ( vlc_object_t *p_this )
/***************************************************************************** /*****************************************************************************
* Play * Play
*****************************************************************************/ *****************************************************************************/
static void Play( void *aout, void *p_buffer, size_t i_size, static void Play( void * _p_aout, void * _p_buffer, size_t i_size,
const media_raw_audio_format &format ) const media_raw_audio_format &format )
{ {
aout_instance_t *p_aout = (aout_instance_t*)aout; aout_instance_t * p_aout = (aout_instance_t*) _p_aout;
aout_sys_t *p_sys = (aout_sys_t*)p_aout->output.p_sys; float * p_buffer = (float*) _p_buffer;
aout_buffer_t * p_aout_buffer; aout_sys_t * p_sys = (aout_sys_t*) p_aout->output.p_sys;
mtime_t play_time = 0;
/* FIXME (see above) */ /* FIXME (see above) */
vlc_mutex_lock( &p_sys->lock ); mtime_t play_time = mdate() + p_sys->p_latency->latency;
play_time = mdate() + p_sys->latency;
vlc_mutex_unlock( &p_sys->lock );
p_aout_buffer = aout_OutputNextBuffer( p_aout, play_time, VLC_FALSE ); aout_buffer_t * p_aout_buffer =
aout_OutputNextBuffer( p_aout, play_time, VLC_FALSE );
if( p_aout_buffer != NULL ) if( p_aout_buffer != NULL )
{ {
p_aout->p_vlc->pf_memcpy( (float*)p_buffer, p_aout->p_vlc->pf_memcpy( p_buffer, p_aout_buffer->p_buffer, i_size );
p_aout_buffer->p_buffer, i_size );
aout_BufferFree( p_aout_buffer ); aout_BufferFree( p_aout_buffer );
} }
else else
{ {
p_aout->p_vlc->pf_memset( (float*)p_buffer, 0, i_size ); p_aout->p_vlc->pf_memset( p_buffer, 0, i_size );
} }
} }
...@@ -196,26 +201,11 @@ static void DoNothing( aout_instance_t *p_aout ) ...@@ -196,26 +201,11 @@ static void DoNothing( aout_instance_t *p_aout )
/***************************************************************************** /*****************************************************************************
* CheckLatency * CheckLatency
*****************************************************************************/ *****************************************************************************/
static int CheckLatency( aout_instance_t *p_aout ) static int CheckLatency( latency_t * p_latency )
{ {
aout_sys_t *p_sys = (aout_sys_t*)p_aout->output.p_sys; while( !p_latency->b_die )
mtime_t last_check = 0;
mtime_t latency;
while( !p_aout->b_die )
{
/* check every 0.1 second */
if( mdate() > last_check + 100000 )
{ {
latency = p_sys->p_player->Latency(); p_latency->latency = p_latency->p_player->Latency();
if( latency > 0 )
{
vlc_mutex_lock( &p_sys->lock );
p_sys->latency = latency;
vlc_mutex_unlock( &p_sys->lock );
}
last_check = mdate();
}
snooze( 5000 ); snooze( 5000 );
} }
return VLC_SUCCESS; return VLC_SUCCESS;
......
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