/*****************************************************************************
* dec.c : audio output API towards decoders
*****************************************************************************
- * Copyright (C) 2002 VideoLAN
- * $Id: dec.c,v 1.3 2002/12/06 10:10:39 sam Exp $
+ * Copyright (C) 2002-2004 VideoLAN
+ * $Id$
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
*
#include "audio_output.h"
#include "aout_internal.h"
+#include <vlc/input.h> /* for input_thread_t and i_pts_delay */
/*
* Creation/Deletion
/*****************************************************************************
* 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. */
p_input->b_changed = 0;
p_input->b_error = 1;
+ aout_FormatPrepare( p_format );
memcpy( &p_input->input, p_format,
sizeof(audio_sample_format_t) );
- aout_FormatPrepare( &p_input->input );
p_aout->pp_inputs[p_aout->i_nb_inputs] = p_input;
p_aout->i_nb_inputs++;
{
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 )
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;
+ vlc_object_release( p_input_thread );
+ }
+ else
+ {
+ p_input->i_pts_delay = DEFAULT_PTS_DELAY;
+ p_input->i_pts_delay += p_input->i_desync;
+ }
+
return p_input;
}
{
return NULL;
}
+ vlc_object_attach( *pp_aout, p_this->p_vlc );
}
else
{
}
}
- return DecNew( *pp_aout, p_format );
+ return DecNew( p_this, *pp_aout, p_format );
}
/*****************************************************************************
{
aout_OutputDelete( p_aout );
aout_MixerDelete( p_aout );
+ 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" );
+ }
}
vlc_mutex_unlock( &p_aout->mixer_lock );
return -1;
}
+ /* 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());
+ aout_BufferFree( p_buffer );
+ return -1;
+ }
+
p_buffer->end_date = p_buffer->start_date
+ (mtime_t)(p_buffer->i_nb_samples * 1000000)
/ p_input->input.i_rate;
return 0;
}
-