X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Faudio_output%2Fdec.c;h=cecd5839318f85f623b78c8e2331fcbd7d0eb841;hb=4aa2cbe41bb61d3c000681b8829912b79b779a9f;hp=b02ffb44fade25235ba746cdda52c293d5d190bf;hpb=fb3612d9ecd723953ee70609d2bfb230abc8c787;p=vlc diff --git a/src/audio_output/dec.c b/src/audio_output/dec.c index b02ffb44fa..cecd583931 100644 --- a/src/audio_output/dec.c +++ b/src/audio_output/dec.c @@ -1,8 +1,8 @@ /***************************************************************************** * dec.c : audio output API towards decoders ***************************************************************************** - * Copyright (C) 2002 VideoLAN - * $Id: dec.c,v 1.8 2003/02/26 18:15:33 massiot Exp $ + * Copyright (C) 2002-2004 the VideoLAN team + * $Id$ * * Authors: Christophe Massiot * @@ -18,7 +18,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/ /***************************************************************************** @@ -35,6 +35,7 @@ #include "audio_output.h" #include "aout_internal.h" +#include /* for input_thread_t and i_pts_delay */ /* * Creation/Deletion @@ -43,10 +44,12 @@ /***************************************************************************** * aout_DecNew : create a decoder *****************************************************************************/ -static aout_input_t * DecNew( aout_instance_t * p_aout, +static aout_input_t * DecNew( vlc_object_t * p_this, aout_instance_t * p_aout, audio_sample_format_t * p_format ) { aout_input_t * p_input; + input_thread_t * p_input_thread; + vlc_value_t val; /* We can only be called by the decoder, so no need to lock * p_input->lock. */ @@ -80,14 +83,8 @@ static aout_input_t * DecNew( aout_instance_t * p_aout, { int i; - if ( var_Type( p_aout, "audio-device" ) != 0 ) - { - var_Destroy( p_aout, "audio-device" ); - } - if ( var_Type( p_aout, "audio-channels" ) != 0 ) - { - var_Destroy( p_aout, "audio-channels" ); - } + var_Destroy( p_aout, "audio-device" ); + var_Destroy( p_aout, "audio-channels" ); /* Recreate the output using the new format. */ if ( aout_OutputNew( p_aout, p_format ) < 0 ) @@ -123,12 +120,30 @@ static aout_input_t * DecNew( aout_instance_t * p_aout, return NULL; } - aout_MixerNew( p_aout ); - aout_InputNew( p_aout, p_input ); vlc_mutex_unlock( &p_aout->mixer_lock ); + var_Create( p_this, "audio-desync", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT ); + var_Get( p_this, "audio-desync", &val ); + p_input->i_desync = val.i_int * 1000; + + p_input_thread = (input_thread_t *)vlc_object_find( p_this, + VLC_OBJECT_INPUT, FIND_PARENT ); + if( p_input_thread ) + { + p_input->i_pts_delay = p_input_thread->i_pts_delay; + p_input->i_pts_delay += p_input->i_desync; + p_input->p_input_thread = p_input_thread; + vlc_object_release( p_input_thread ); + } + else + { + p_input->i_pts_delay = DEFAULT_PTS_DELAY; + p_input->i_pts_delay += p_input->i_desync; + p_input->p_input_thread = NULL; + } + return p_input; } @@ -151,6 +166,7 @@ aout_input_t * __aout_DecNew( vlc_object_t * p_this, { return NULL; } + vlc_object_attach( *pp_aout, p_this->p_vlc ); } else { @@ -158,7 +174,7 @@ aout_input_t * __aout_DecNew( vlc_object_t * p_this, } } - return DecNew( *pp_aout, p_format ); + return DecNew( p_this, *pp_aout, p_format ); } /***************************************************************************** @@ -285,10 +301,20 @@ int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input, return -1; } - if ( p_buffer->start_date > mdate() + AOUT_MAX_ADVANCE_TIME ) + /* Apply the desynchronisation requested by the user */ + p_buffer->start_date += p_input->i_desync; + p_buffer->end_date += p_input->i_desync; + + if ( p_buffer->start_date > mdate() + p_input->i_pts_delay + + AOUT_MAX_ADVANCE_TIME ) { msg_Warn( p_aout, "received buffer in the future ("I64Fd")", p_buffer->start_date - mdate()); + if( p_input->p_input_thread ) + { + stats_UpdateInteger( p_input->p_input_thread, STATS_LOST_ABUFFERS, 1, + NULL ); + } aout_BufferFree( p_buffer ); return -1; } @@ -339,8 +365,12 @@ int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input, /* Run the mixer if it is able to run. */ vlc_mutex_lock( &p_aout->mixer_lock ); aout_MixerRun( p_aout ); + if( p_input->p_input_thread ) + { + stats_UpdateInteger( p_input->p_input_thread, + STATS_PLAYED_ABUFFERS, 1, NULL ); + } vlc_mutex_unlock( &p_aout->mixer_lock ); return 0; } -