]> git.sesse.net Git - vlc/blobdiff - plugins/mpeg_adec/mpeg_adec.c
* ALL: the first libvlc commit.
[vlc] / plugins / mpeg_adec / mpeg_adec.c
index 0e163131977df7d728c5452e74361097a4191d86..31057f0bcedb25ab51351cece6510a472794dae7 100644 (file)
@@ -2,7 +2,7 @@
  * mpeg_adec.c: MPEG audio decoder thread
  *****************************************************************************
  * Copyright (C) 1999-2001 VideoLAN
- * $Id: mpeg_adec.c,v 1.12 2002/01/10 04:11:25 sam Exp $
+ * $Id: mpeg_adec.c,v 1.24 2002/06/01 12:32:00 sam Exp $
  *
  * Authors: Michel Kaempf <maxx@via.ecp.fr>
  *          Michel Lespinasse <walken@via.ecp.fr>
 #include <stdlib.h>                                      /* malloc(), free() */
 #include <string.h>
 
-#include <videolan/vlc.h>
-
-#include "audio_output.h"               /* aout_fifo_t (for audio_decoder.h) */
-
-#include "stream_control.h"
-#include "input_ext-dec.h"
+#include <vlc/vlc.h>
+#include <vlc/decoder.h>
+#include <vlc/aout.h>
 
 #include "mpeg_adec_generic.h"
 #include "mpeg_adec.h"
@@ -45,8 +42,8 @@
 /*****************************************************************************
  * Local Prototypes
  *****************************************************************************/
-static int   decoder_Probe ( probedata_t * );
-static int   decoder_Run   ( decoder_config_t * );
+static int   decoder_Probe ( u8 * );
+static int   decoder_Run   ( decoder_fifo_t * );
 static void  EndThread     ( adec_thread_t * );
 static void  DecodeThread  ( adec_thread_t * );
 
@@ -55,8 +52,8 @@ static void  DecodeThread  ( adec_thread_t * );
  *****************************************************************************/
 void _M( adec_getfunctions )( function_list_t * p_function_list )
 {
-    p_function_list->pf_probe = decoder_Probe;
-    p_function_list->functions.dec.pf_run = decoder_Run;
+    p_function_list->functions.dec.pf_probe = decoder_Probe;
+    p_function_list->functions.dec.pf_run   = decoder_Run;
 }
 
 /*****************************************************************************
@@ -66,8 +63,8 @@ MODULE_CONFIG_START
 MODULE_CONFIG_STOP
 
 MODULE_INIT_START
-    SET_DESCRIPTION( "Mpeg I layer 1/2 audio decoder" )
-    ADD_CAPABILITY( DECODER, 100 )
+    SET_DESCRIPTION( _("MPEG I/II layer 1/2 audio decoder") )
+    ADD_CAPABILITY( DECODER, 50 )
     ADD_REQUIREMENT( FPU )
     ADD_SHORTCUT( "builtin" )
 MODULE_INIT_STOP
@@ -82,35 +79,31 @@ MODULE_DEACTIVATE_STOP
 /*****************************************************************************
  * decoder_Probe: probe the decoder and return score
  *****************************************************************************/
-static int decoder_Probe( probedata_t *p_data )
+static int decoder_Probe( u8 *pi_type )
 {
-    return( ( p_data->i_type == MPEG1_AUDIO_ES
-               || p_data->i_type == MPEG2_AUDIO_ES ) ? 100 : 0 );
+    return( ( *pi_type == MPEG1_AUDIO_ES
+               || *pi_type == MPEG2_AUDIO_ES ) ? 0 : -1 );
 }
 
 /*****************************************************************************
  * decoder_Run: initialize, go inside main loop, detroy
  *****************************************************************************/
-static int decoder_Run ( decoder_config_t * p_config )
+static int decoder_Run ( decoder_fifo_t * p_fifo )
 {
     adec_thread_t   * p_adec;
     
-    intf_DbgMsg("mpeg_adec debug: thread launched, initializing.");
-    
     /* Allocate the memory needed to store the thread's structure */
     if ( (p_adec = (adec_thread_t *)malloc (sizeof(adec_thread_t))) == NULL ) 
     {
-        intf_ErrMsg ( "adec error: not enough memory for"
-                      " adec_CreateThread() to create the new thread" );
-        DecoderError( p_config->p_decoder_fifo );
+        msg_Err( p_fifo, "out of memory" );
+        DecoderError( p_fifo );
         return 0;
     }
     
     /*
      * Initialize the thread properties
      */
-    p_adec->p_config = p_config;
-    p_adec->p_fifo = p_config->p_decoder_fifo;
+    p_adec->p_fifo = p_fifo;
 
     /* 
      * Initilize the banks
@@ -123,15 +116,12 @@ static int decoder_Run ( decoder_config_t * p_config )
     /*
      * Initialize bit stream 
      */
-    p_adec->p_config->pf_init_bit_stream( &p_adec->bit_stream,
-        p_adec->p_config->p_decoder_fifo, NULL, NULL );
+    InitBitstream( &p_adec->bit_stream, p_adec->p_fifo, NULL, NULL );
 
     /* We do not create the audio output fifo now, but
        it will be created when the first frame is received */
     p_adec->p_aout_fifo = NULL;
 
-    intf_DbgMsg("mpeg_adec debug: thread initialized, decoding begins.");
-
     p_adec->i_sync = 0;
 
     /* Audio decoder thread's main loop */
@@ -153,7 +143,7 @@ static int decoder_Run ( decoder_config_t * p_config )
 }
 
 /*
- * Following finctions are local to this module
+ * Following functions are local to this module
  */
 
 /*****************************************************************************
@@ -161,7 +151,7 @@ static int decoder_Run ( decoder_config_t * p_config )
  *****************************************************************************/
 static void DecodeThread( adec_thread_t * p_adec )
 {
-    s16 * buffer;
+    s16 *p_buffer;
     adec_sync_info_t sync_info;
 
     if( ! adec_SyncFrame (p_adec, &sync_info) )
@@ -172,25 +162,28 @@ static void DecodeThread( adec_thread_t * p_adec )
         /* Create the output fifo if it doesn't exist yet */
         if( p_adec->p_aout_fifo == NULL )
         {
-            int fifo_type;
-            int channels;
+            int i_channels;
             
-            if( sync_info.b_stereo )
+            if( !config_GetInt( p_adec->p_fifo, "mono" ) )
             {
-                fifo_type = AOUT_ADEC_STEREO_FIFO;
-                channels = 2;
+                msg_Dbg( p_adec->p_fifo, "setting stereo output" );
+                i_channels = 2;
+            }
+            else if( sync_info.b_stereo )
+            {
+                i_channels = 2;
             }
             else
             {
-                fifo_type = AOUT_ADEC_MONO_FIFO;
-                channels = 1;
+                i_channels = 1;
             }
-            p_adec->p_aout_fifo = aout_CreateFifo( fifo_type, channels,
-                    sync_info.sample_rate, 0, ADEC_FRAME_SIZE, NULL );
+            p_adec->p_aout_fifo =
+               aout_CreateFifo( p_adec->p_fifo->p_this,
+                                AOUT_FIFO_PCM, i_channels,
+                                sync_info.sample_rate, ADEC_FRAME_SIZE, NULL );
             if( p_adec->p_aout_fifo == NULL)
             {
-                intf_ErrMsg( "adec error: failed to create Audio Output "
-                        "Fifo." );
+                msg_Err( p_adec->p_fifo, "failed to create aout fifo" );
                 p_adec->p_fifo->b_error = 1;
                 return;
             }
@@ -198,24 +191,19 @@ static void DecodeThread( adec_thread_t * p_adec )
 
         p_adec->i_sync = 1;
 
-        p_adec->p_aout_fifo->l_rate = sync_info.sample_rate;
-
-        buffer = ((s16 *)p_adec->p_aout_fifo->buffer)
-                    + (p_adec->p_aout_fifo->l_end_frame * ADEC_FRAME_SIZE);
+        p_buffer = ((s16 *)p_adec->p_aout_fifo->buffer)
+                    + (p_adec->p_aout_fifo->i_end_frame * ADEC_FRAME_SIZE);
 
-        if( p_adec->p_fifo->p_first->i_pts )
+        CurrentPTS( &p_adec->bit_stream,
+            &p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->i_end_frame],
+            NULL );
+        if( !p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->i_end_frame] )
         {
-            p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] =
-                p_adec->p_fifo->p_first->i_pts;
-            p_adec->p_fifo->p_first->i_pts = 0;
-        }
-        else
-        {
-            p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->l_end_frame] =
+            p_adec->p_aout_fifo->date[p_adec->p_aout_fifo->i_end_frame] =
                 LAST_MDATE;
         }
 
-        if( adec_DecodeFrame (p_adec, buffer) )
+        if( adec_DecodeFrame (p_adec, p_buffer) )
         {
             /* Ouch, failed decoding... We'll have to resync */
             p_adec->i_sync = 0;
@@ -223,9 +211,8 @@ static void DecodeThread( adec_thread_t * p_adec )
         else
         {
             vlc_mutex_lock (&p_adec->p_aout_fifo->data_lock);
-
-            p_adec->p_aout_fifo->l_end_frame =
-                (p_adec->p_aout_fifo->l_end_frame + 1) & AOUT_FIFO_SIZE;
+            p_adec->p_aout_fifo->i_end_frame =
+                (p_adec->p_aout_fifo->i_end_frame + 1) & AOUT_FIFO_SIZE;
             vlc_cond_signal (&p_adec->p_aout_fifo->data_wait);
             vlc_mutex_unlock (&p_adec->p_aout_fifo->data_lock);
         }
@@ -240,8 +227,6 @@ static void DecodeThread( adec_thread_t * p_adec )
  *****************************************************************************/
 static void EndThread ( adec_thread_t *p_adec )
 {
-    intf_DbgMsg ( "adec debug: destroying audio decoder thread %p", p_adec );
-
     /* If the audio output fifo was created, we destroy it */
     if ( p_adec->p_aout_fifo != NULL ) 
     {
@@ -254,7 +239,5 @@ static void EndThread ( adec_thread_t *p_adec )
     }
     /* Destroy descriptor */
     free( p_adec );
-
-    intf_DbgMsg ("adec debug: audio decoder thread %p destroyed", p_adec);
 }