]> git.sesse.net Git - vlc/blobdiff - src/audio_output/dec.c
* src/*: got rid of the #ifdef HAVE_ERRNO_H.
[vlc] / src / audio_output / dec.c
index 8a5d9277df20f4169844432c0dd9ac10e1128f9f..225c4a3029c5573c0e4582aab251866fb908ad0c 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * 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>
  *
@@ -35,6 +35,7 @@
 
 #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. */
@@ -69,9 +72,9 @@ static aout_input_t * DecNew( aout_instance_t * p_aout,
 
     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++;
@@ -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,28 @@ 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;
+        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;
 }
 
@@ -151,6 +164,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 +172,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 );
 }
 
 /*****************************************************************************
@@ -200,6 +214,14 @@ int aout_DecDelete( aout_instance_t * p_aout, aout_input_t * p_input )
     {
         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 );
@@ -277,6 +299,19 @@ int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input,
         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;
@@ -327,4 +362,3 @@ int aout_DecPlay( aout_instance_t * p_aout, aout_input_t * p_input,
 
     return 0;
 }
-