]> git.sesse.net Git - vlc/blobdiff - plugins/ac3_adec/ac3_adec.c
* Fixed detection of the esd plugin.
[vlc] / plugins / ac3_adec / ac3_adec.c
index 211f0b17771ed5ca1d08581a00859164ee81fd04..1e52142e464527770090c3a3b8d46c7013fbb7eb 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * ac3_adec.c: ac3 decoder module main file
  *****************************************************************************
- * Copyright (C) 1999, 2000 VideoLAN
- * $Id: ac3_adec.c,v 1.3 2001/11/15 17:39:12 sam Exp $
+ * Copyright (C) 1999-2001 VideoLAN
+ * $Id: ac3_adec.c,v 1.12 2001/12/31 04:53:33 sam Exp $
  *
  * Authors: Michel Lespinasse <walken@zoy.org>
  *
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  *****************************************************************************/
 
-/*
- * TODO :
- *
- * - vérifier l'état de la fifo de sortie avant d'y stocker les samples
- *   décodés ;
- * - vlc_cond_signal() / vlc_cond_wait()
- *
- */
-#define MODULE_NAME ac3_adec
-#include "modules_inner.h"
-
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include "defs.h"
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>                                              /* getpid() */
-#endif
-
 #include <stdlib.h>                                      /* malloc(), free() */
 #include <string.h>                                              /* memset() */
 
-#include "config.h"
-#include "common.h"
-#include "threads.h"
-#include "mtime.h"
-#include "intf_msg.h"                        /* intf_DbgMsg(), intf_ErrMsg() */
+#include <videolan/vlc.h>
 
-#include "audio_output.h"
+#ifdef HAVE_UNISTD_H
+#   include <unistd.h>                                           /* getpid() */
+#endif
 
-#include "modules.h"
-#include "modules_export.h"
+#include "audio_output.h"
 
 #include "stream_control.h"
 #include "input_ext-dec.h"
 /*****************************************************************************
  * Local prototypes
  *****************************************************************************/
-static int      ac3_adec_Probe      ( probedata_t * );
-static int      ac3_adec_Run         ( decoder_config_t * );
-static int      ac3_adec_Init        (ac3dec_thread_t * p_adec);
-static void     ac3_adec_ErrorThread (ac3dec_thread_t * p_adec);
-static void     ac3_adec_EndThread   (ac3dec_thread_t * p_adec);
-static void     BitstreamCallback    ( bit_stream_t *p_bit_stream,
-                                              boolean_t b_new_pes );
+static int  decoder_Probe     ( probedata_t * );
+static int  decoder_Run       ( decoder_config_t * );
+static int  InitThread        ( ac3dec_thread_t * p_adec );
+static void EndThread         ( ac3dec_thread_t * p_adec );
+static void BitstreamCallback ( bit_stream_t *p_bit_stream,
+                                boolean_t b_new_pes );
 
 /*****************************************************************************
  * Capabilities
  *****************************************************************************/
 void _M( adec_getfunctions )( function_list_t * p_function_list )
 {
-    p_function_list->pf_probe = ac3_adec_Probe;
-    p_function_list->functions.dec.pf_RunThread = ac3_adec_Run;
+    p_function_list->pf_probe = decoder_Probe;
+    p_function_list->functions.dec.pf_run = decoder_Run;
 }
 
 /*****************************************************************************
  * Build configuration tree.
  *****************************************************************************/
 MODULE_CONFIG_START
-ADD_WINDOW( "Configuration for ac3 decoder module" )
-    ADD_COMMENT( "Nothing to configure" )
 MODULE_CONFIG_STOP
 
 MODULE_INIT_START
-    p_module->i_capabilities = MODULE_CAPABILITY_DEC;
-    p_module->psz_longname = "Ac3 sofware decoder";
+    SET_DESCRIPTION( "software AC3 decoder" )
+    ADD_CAPABILITY( DECODER, 50 )
 MODULE_INIT_STOP
 
 MODULE_ACTIVATE_START
@@ -108,20 +85,20 @@ MODULE_DEACTIVATE_STOP
 
 
 /*****************************************************************************
- * ac3_adec_Probe: probe the decoder and return score
+ * decoder_Probe: probe the decoder and return score
  *****************************************************************************
  * Tries to launch a decoder and return score so that the interface is able 
  * to chose.
  *****************************************************************************/
-static int ac3_adec_Probe( probedata_t *p_data )
+static int decoder_Probe( probedata_t *p_data )
 {
     return ( p_data->i_type == AC3_AUDIO_ES ) ? 50 : 0;
 }
 
 /*****************************************************************************
- * ac3_adec_Run: this function is called just after the thread is created
+ * decoder_Run: this function is called just after the thread is created
  *****************************************************************************/
-static int ac3_adec_Run ( decoder_config_t * p_config )
+static int decoder_Run ( decoder_config_t * p_config )
 {
     ac3dec_thread_t *   p_ac3thread;
     int sync;
@@ -134,7 +111,8 @@ static int ac3_adec_Run ( decoder_config_t * p_config )
     if( p_ac3thread == NULL )
     {
         intf_ErrMsg ( "ac3_adec error: not enough memory "
-                      "for ac3_adec_Run() to allocate p_ac3thread" );
+                      "for decoder_Run() to allocate p_ac3thread" );
+        DecoderError( p_config->p_decoder_fifo );
         return( -1 );
     }
    
@@ -142,9 +120,10 @@ static int ac3_adec_Run ( decoder_config_t * p_config )
      * Initialize the thread properties
      */
     p_ac3thread->p_config = p_config;
-    if( ac3_adec_Init( p_ac3thread ) )
+    if( InitThread( p_ac3thread ) )
     {
         intf_ErrMsg( "ac3_adec error: could not initialize thread" );
+        DecoderError( p_config->p_decoder_fifo );
         free( p_ac3thread );
         return( -1 );
     }
@@ -178,12 +157,12 @@ static int ac3_adec_Run ( decoder_config_t * p_config )
             sync = 1;
         }
 
-        if (DECODER_FIFO_START(*p_ac3thread->p_fifo)->i_pts)
+        if (p_ac3thread->p_fifo->p_first->i_pts)
         {
             p_ac3thread->p_aout_fifo->date[
                 p_ac3thread->p_aout_fifo->l_end_frame] =
-                DECODER_FIFO_START(*p_ac3thread->p_fifo)->i_pts;
-            DECODER_FIFO_START(*p_ac3thread->p_fifo)->i_pts = 0;
+                p_ac3thread->p_fifo->p_first->i_pts;
+            p_ac3thread->p_fifo->p_first->i_pts = 0;
         } else {
             p_ac3thread->p_aout_fifo->date[
                 p_ac3thread->p_aout_fifo->l_end_frame] =
@@ -220,11 +199,11 @@ static int ac3_adec_Run ( decoder_config_t * p_config )
     /* If b_error is set, the ac3 decoder thread enters the error loop */
     if (p_ac3thread->p_fifo->b_error)
     {
-        ac3_adec_ErrorThread (p_ac3thread);
+        DecoderError( p_ac3thread->p_fifo );
     }
 
     /* End of the ac3 decoder thread */
-    ac3_adec_EndThread (p_ac3thread);
+    EndThread (p_ac3thread);
 
     free( p_ac3thread );
 
@@ -233,9 +212,9 @@ static int ac3_adec_Run ( decoder_config_t * p_config )
 
 
 /*****************************************************************************
- * ac3_adec_Init: initialize data before entering main loop
+ * InitThread: initialize data before entering main loop
  *****************************************************************************/
-static int ac3_adec_Init( ac3dec_thread_t * p_ac3thread )
+static int InitThread( ac3dec_thread_t * p_ac3thread )
 {
     /*
      * Thread properties 
@@ -247,7 +226,9 @@ static int ac3_adec_Init( ac3dec_thread_t * p_ac3thread )
      * Choose the best downmix module
      */
 #define DOWNMIX p_ac3thread->ac3_decoder->downmix
-    DOWNMIX.p_module = module_Need( MODULE_CAPABILITY_DOWNMIX, NULL );
+    DOWNMIX.p_module = module_Need( MODULE_CAPABILITY_DOWNMIX,
+                               main_GetPszVariable( DOWNMIX_METHOD_VAR, NULL ),
+                               NULL );
 
     if( DOWNMIX.p_module == NULL )
     {
@@ -273,7 +254,9 @@ static int ac3_adec_Init( ac3dec_thread_t * p_ac3thread )
     p_ac3thread->ac3_decoder->imdct = memalign(16, sizeof(imdct_t));
     
 #define IMDCT p_ac3thread->ac3_decoder->imdct
-    IMDCT->p_module = module_Need( MODULE_CAPABILITY_IMDCT, NULL );
+    IMDCT->p_module = module_Need( MODULE_CAPABILITY_IMDCT,
+                               main_GetPszVariable( IMDCT_METHOD_VAR, NULL ),
+                               NULL );
 
     if( IMDCT->p_module == NULL )
     {
@@ -329,17 +312,9 @@ static int ac3_adec_Init( ac3dec_thread_t * p_ac3thread )
     intf_DbgMsg ( "ac3_adec debug: ac3_adec thread (%p) initialized", 
                   p_ac3thread );
 
-    /*
-     * Bit stream
-     */
-    p_ac3thread->p_config->pf_init_bit_stream(
-            &p_ac3thread->ac3_decoder->bit_stream,
-            p_ac3thread->p_config->p_decoder_fifo,
-            BitstreamCallback, (void *) p_ac3thread );
-    
     /* Creating the audio output fifo */
     p_ac3thread->p_aout_fifo = aout_CreateFifo( AOUT_ADEC_STEREO_FIFO, 2, 0, 0,
-                                               AC3DEC_FRAME_SIZE, NULL  );
+                                                AC3DEC_FRAME_SIZE, NULL  );
     if ( p_ac3thread->p_aout_fifo == NULL )
     {
         free( IMDCT->w_1 );
@@ -374,6 +349,14 @@ static int ac3_adec_Init( ac3dec_thread_t * p_ac3thread )
         return( -1 );
     }
 
+    /*
+     * Bit stream
+     */
+    p_ac3thread->p_config->pf_init_bit_stream(
+            &p_ac3thread->ac3_decoder->bit_stream,
+            p_ac3thread->p_config->p_decoder_fifo,
+            BitstreamCallback, (void *) p_ac3thread );
+    
     intf_DbgMsg("ac3dec debug: ac3 decoder thread %p initialized", p_ac3thread);
     
     return( 0 );
@@ -381,39 +364,9 @@ static int ac3_adec_Init( ac3dec_thread_t * p_ac3thread )
 
 
 /*****************************************************************************
- * ac3_adec_ErrorThread : ac3 decoder's RunThread() error loop
- *****************************************************************************/
-static void ac3_adec_ErrorThread (ac3dec_thread_t * p_ac3thread)
-{
-    /* We take the lock, because we are going to read/write the start/end
-     * indexes of the decoder fifo */
-    vlc_mutex_lock (&p_ac3thread->p_fifo->data_lock);
-
-    /* Wait until a `die' order is sent */
-    while (!p_ac3thread->p_fifo->b_die)
-    {
-        /* Trash all received PES packets */
-        while (!DECODER_FIFO_ISEMPTY(*p_ac3thread->p_fifo))
-        {
-            p_ac3thread->p_fifo->pf_delete_pes(
-                    p_ac3thread->p_fifo->p_packets_mgt,
-                    DECODER_FIFO_START(*p_ac3thread->p_fifo));
-            DECODER_FIFO_INCSTART (*p_ac3thread->p_fifo);
-        }
-
-        /* Waiting for the input thread to put new PES packets in the fifo */
-        vlc_cond_wait (&p_ac3thread->p_fifo->data_wait,
-                       &p_ac3thread->p_fifo->data_lock);
-    }
-
-    /* We can release the lock before leaving */
-    vlc_mutex_unlock (&p_ac3thread->p_fifo->data_lock);
-}
-
-/*****************************************************************************
- * ac3_adec_EndThread : ac3 decoder thread destruction
+ * EndThread : ac3 decoder thread destruction
  *****************************************************************************/
-static void ac3_adec_EndThread (ac3dec_thread_t * p_ac3thread)
+static void EndThread (ac3dec_thread_t * p_ac3thread)
 {
     intf_DbgMsg ("ac3dec debug: destroying ac3 decoder thread %p", p_ac3thread);