]> git.sesse.net Git - vlc/blobdiff - modules/codec/araw.c
* all: a little compil fix and more sanity checks (needed for wma).
[vlc] / modules / codec / araw.c
index 188846676a2a34e28054d917cd597ce8e90e049d..ae7dd17d75d79494eb389b4c820ccd488ab20e0a 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************
  * araw.c: Pseudo audio decoder; for raw pcm data
  *****************************************************************************
- * Copyright (C) 2001, 2002 VideoLAN
- * $Id: araw.c,v 1.14 2003/03/11 17:40:40 fenrir Exp $
+ * Copyright (C) 2001, 2003 VideoLAN
+ * $Id: araw.c,v 1.24 2003/11/16 21:07:30 gbazin Exp $
  *
  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  *
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
+#include <stdlib.h>                                      /* malloc(), free() */
+
 #include <vlc/vlc.h>
-#include <vlc/aout.h>
 #include <vlc/decoder.h>
 #include <vlc/input.h>
 
-#include <stdlib.h>                                      /* malloc(), free() */
-#include <string.h>                                              /* strdup() */
 #include "codecs.h"
-/*****************************************************************************
- * Local prototypes
- *****************************************************************************/
-
-typedef struct adec_thread_s
-{
-    WAVEFORMATEX    *p_wf;
-
-    /* The bit stream structure handles the PES stream at the bit level */
-//    bit_stream_t        bit_stream;
-
-    /* Input properties */
-    decoder_fifo_t *p_fifo;
-    int16_t        *p_logtos16;  // used with m/alaw to s16
-
-    /* Output properties */
-    aout_instance_t *   p_aout;       /* opaque */
-    aout_input_t *      p_aout_input; /* opaque */
-    audio_sample_format_t output_format;
-
-    audio_date_t        date;
-    mtime_t             pts;
-
-} adec_thread_t;
-
-static int  OpenDecoder    ( vlc_object_t * );
-
-static int  RunDecoder     ( decoder_fifo_t * );
-static int  InitThread     ( adec_thread_t * );
-static void DecodeThread   ( adec_thread_t * );
-static void EndThread      ( adec_thread_t * );
 
 /*****************************************************************************
  * Module descriptor
  *****************************************************************************/
+static int  DecoderOpen ( vlc_object_t * );
+static void DecoderClose( vlc_object_t * );
+
+static int  EncoderOpen ( vlc_object_t * );
+static void EncoderClose( vlc_object_t * );
 
 vlc_module_begin();
-    set_description( _("Pseudo Raw/Log Audio decoder") );
+    /* audio decoder module */
+    set_description( _("Raw/Log Audio decoder") );
     set_capability( "decoder", 50 );
-    set_callbacks( OpenDecoder, NULL );
-vlc_module_end();
+    set_callbacks( DecoderOpen, DecoderClose );
 
+    /* audio encoder submodule */
+    add_submodule();
+    set_description( _("Raw audio encoder") );
+    set_capability( "encoder", 10 );
+    set_callbacks( EncoderOpen, EncoderClose );
+vlc_module_end();
 
 /*****************************************************************************
- * OpenDecoder: probe the decoder and return score
- *****************************************************************************
- * Tries to launch a decoder and return score so that the interface is able
- * to choose.
+ * Local prototypes
  *****************************************************************************/
-static int OpenDecoder( vlc_object_t *p_this )
-{
-    decoder_fifo_t *p_fifo = (decoder_fifo_t*) p_this;
-
-    switch( p_fifo->i_fourcc )
-    {
-        case VLC_FOURCC('a','r','a','w'): /* from wav/avi/asf file */
-        case VLC_FOURCC('t','w','o','s'): /* _signed_ big endian samples (mov)*/
-        case VLC_FOURCC('s','o','w','t'): /* _signed_ little endian samples (mov)*/
-
-        case VLC_FOURCC('a','l','a','w'):
-        case VLC_FOURCC('u','l','a','w'):
-            p_fifo->pf_run = RunDecoder;
-            return VLC_SUCCESS;
+static aout_buffer_t *DecodeBlock( decoder_t *, block_t ** );
+static block_t *EncoderEncode( encoder_t *, aout_buffer_t * );
 
-        default:
-            return VLC_EGENERIC;
-    }
+struct decoder_sys_t
+{
+    int16_t *p_logtos16;  /* used with m/alaw to int16_t */
 
-}
+    audio_date_t end_date;
+};
 
 static int pi_channels_maps[6] =
 {
@@ -186,361 +151,373 @@ static int16_t alawtos16[256] =
 };
 
 /*****************************************************************************
- * RunDecoder: this function is called just after the thread is created
+ * DecoderOpen: probe the decoder and return score
  *****************************************************************************/
-static int RunDecoder( decoder_fifo_t *p_fifo )
+static int DecoderOpen( vlc_object_t *p_this )
 {
-    adec_thread_t *p_adec;
-    int b_error;
+    decoder_t *p_dec = (decoder_t*)p_this;
+    decoder_sys_t *p_sys;
 
-    if( !( p_adec = malloc( sizeof( adec_thread_t ) ) ) )
+    switch( p_dec->fmt_in.i_codec )
     {
-        msg_Err( p_fifo, "out of memory" );
-        DecoderError( p_fifo );
-        return( -1 );
+    /* from wav/avi/asf file */
+    case VLC_FOURCC('a','r','a','w'):
+    /* _signed_ big endian samples (mov)*/
+    case VLC_FOURCC('t','w','o','s'):
+    /* _signed_ little endian samples (mov)*/
+    case VLC_FOURCC('s','o','w','t'):
+
+    case VLC_FOURCC('a','l','a','w'):
+    case VLC_FOURCC('u','l','a','w'):
+        break;
+
+    default:
+        return VLC_EGENERIC;
     }
-    memset( p_adec, 0, sizeof( adec_thread_t ) );
-
-    p_adec->p_fifo = p_fifo;
 
-    if( InitThread( p_adec ) != 0 )
+    /* Allocate the memory needed to store the decoder's structure */
+    if( ( p_dec->p_sys = p_sys =
+          (decoder_sys_t *)malloc(sizeof(decoder_sys_t)) ) == NULL )
     {
-        DecoderError( p_fifo );
-        return( -1 );
+        msg_Err( p_dec, "out of memory" );
+        return VLC_EGENERIC;
     }
 
-    while( ( !p_adec->p_fifo->b_die )&&( !p_adec->p_fifo->b_error ) )
+    if( p_dec->fmt_in.audio.i_channels <= 0 ||
+        p_dec->fmt_in.audio.i_channels > 5 )
     {
-        DecodeThread( p_adec );
+        msg_Err( p_dec, "bad channels count(1-5)" );
+        return VLC_EGENERIC;
     }
 
-
-    if( ( b_error = p_adec->p_fifo->b_error ) )
+    if( p_dec->fmt_in.audio.i_rate <= 0 )
     {
-        DecoderError( p_adec->p_fifo );
+        msg_Err( p_dec, "bad samplerate" );
+        return VLC_EGENERIC;
     }
 
-    EndThread( p_adec );
-    if( b_error )
-    {
-        return( -1 );
-    }
-
-    return( 0 );
-}
-
-
-#define FREE( p ) if( p ) free( p ); p = NULL
-#define GetWLE( p ) \
-    ( *(u8*)(p) + ( *((u8*)(p)+1) << 8 ) )
+    p_sys->p_logtos16 = NULL;
 
-#define GetDWLE( p ) \
-    (  *(u8*)(p) + ( *((u8*)(p)+1) << 8 ) + \
-        ( *((u8*)(p)+2) << 16 ) + ( *((u8*)(p)+3) << 24 ) )
+    msg_Dbg( p_dec, "samplerate:%dHz channels:%d bits/sample:%d",
+             p_dec->fmt_in.audio.i_rate, p_dec->fmt_in.audio.i_channels,
+             p_dec->fmt_in.audio.i_bitspersample );
 
-
-/*****************************************************************************
- * InitThread: initialize data before entering main loop
- *****************************************************************************/
-static int InitThread( adec_thread_t * p_adec )
-{
-    if( ( p_adec->p_wf = (WAVEFORMATEX*)p_adec->p_fifo->p_waveformatex ) == NULL )
-    {
-        msg_Err( p_adec->p_fifo, "unknown raw format" );
-        return( -1 );
-    }
-
-    /* fixing some values */
-    if( ( p_adec->p_wf->wFormatTag  == WAVE_FORMAT_PCM ||
-          p_adec->p_wf->wFormatTag  == WAVE_FORMAT_IEEE_FLOAT )&&
-        !p_adec->p_wf->nBlockAlign )
+    if( 0 /* p_wf->wFormatTag == WAVE_FORMAT_IEEE_FLOAT */ )
     {
-        p_adec->p_wf->nBlockAlign =
-            p_adec->p_wf->nChannels *
-                ( ( p_adec->p_wf->wBitsPerSample + 7 ) / 8 );
-    }
-
-    msg_Dbg( p_adec->p_fifo,
-             "raw format: samplerate:%dHz channels:%d bits/sample:%d blockalign:%d",
-             p_adec->p_wf->nSamplesPerSec,
-             p_adec->p_wf->nChannels,
-             p_adec->p_wf->wBitsPerSample,
-             p_adec->p_wf->nBlockAlign );
-
-    /* Initialize the thread properties */
-    p_adec->p_logtos16 = NULL;
-    if( p_adec->p_wf->wFormatTag  == WAVE_FORMAT_IEEE_FLOAT )
-    {
-        switch( ( p_adec->p_wf->wBitsPerSample + 7 ) / 8 )
+        switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
         {
-            case( 4 ):
-                p_adec->output_format.i_format = VLC_FOURCC('f','l','3','2');
-                break;
-            case( 8 ):
-                p_adec->output_format.i_format = VLC_FOURCC('f','l','6','4');
-                break;
-            default:
-                msg_Err( p_adec->p_fifo, "bad parameters(bits/sample)" );
-                return( -1 );
+        case 4:
+            p_dec->fmt_out.i_codec = VLC_FOURCC('f','l','3','2');
+            break;
+        case 8:
+            p_dec->fmt_out.i_codec = VLC_FOURCC('f','l','6','4');
+            break;
+        default:
+            msg_Err( p_dec, "bad parameters(bits/sample)" );
+            return VLC_EGENERIC;
         }
     }
     else
     {
-        if( p_adec->p_fifo->i_fourcc == VLC_FOURCC( 't', 'w', 'o', 's' ) )
+        if( p_dec->fmt_in.i_codec == VLC_FOURCC( 't', 'w', 'o', 's' ) )
         {
-            switch( ( p_adec->p_wf->wBitsPerSample + 7 ) / 8 )
+            switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
             {
-                case( 1 ):
-                    p_adec->output_format.i_format = VLC_FOURCC('s','8',' ',' ');
-                    break;
-                case( 2 ):
-                    p_adec->output_format.i_format = VLC_FOURCC('s','1','6','b');
-                    break;
-                case( 3 ):
-                    p_adec->output_format.i_format = VLC_FOURCC('s','2','4','b');
-                    break;
-                case( 4 ):
-                    p_adec->output_format.i_format = VLC_FOURCC('s','3','2','b');
-                    break;
-                default:
-                    msg_Err( p_adec->p_fifo, "bad parameters(bits/sample)" );
-                    return( -1 );
+            case 1:
+                p_dec->fmt_out.i_codec = VLC_FOURCC('s','8',' ',' ');
+                break;
+            case 2:
+                p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','b');
+                break;
+            case 3:
+                p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','b');
+                break;
+            case 4:
+                p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','b');
+                break;
+            default:
+                msg_Err( p_dec, "bad parameters(bits/sample)" );
+                return VLC_EGENERIC;
             }
         }
-        else if( p_adec->p_fifo->i_fourcc == VLC_FOURCC( 's', 'o', 'w', 't' ) )
+        else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 's', 'o', 'w', 't' ) )
         {
-            switch( ( p_adec->p_wf->wBitsPerSample + 7 ) / 8 )
+            switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
             {
-                case( 1 ):
-                    p_adec->output_format.i_format = VLC_FOURCC('s','8',' ',' ');
-                    break;
-                case( 2 ):
-                    p_adec->output_format.i_format = VLC_FOURCC('s','1','6','l');
-                    break;
-                case( 3 ):
-                    p_adec->output_format.i_format = VLC_FOURCC('s','2','4','l');
-                    break;
-                case( 4 ):
-                    p_adec->output_format.i_format = VLC_FOURCC('s','3','2','l');
-                    break;
-                default:
-                    msg_Err( p_adec->p_fifo, "bad parameters(bits/sample)" );
-                    return( -1 );
+            case 1:
+                p_dec->fmt_out.i_codec = VLC_FOURCC('s','8',' ',' ');
+                break;
+            case 2:
+                p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','l');
+                break;
+            case 3:
+                p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','l');
+                break;
+            case 4:
+                p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','l');
+                break;
+            default:
+                msg_Err( p_dec, "bad parameters(bits/sample)" );
+                return VLC_EGENERIC;
             }
         }
-        else if( p_adec->p_fifo->i_fourcc == VLC_FOURCC( 'a', 'r', 'a', 'w' ) )
+        else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'a', 'r', 'a', 'w' ) )
         {
-            switch( ( p_adec->p_wf->wBitsPerSample + 7 ) / 8 )
+            switch( ( p_dec->fmt_in.audio.i_bitspersample + 7 ) / 8 )
             {
-                case( 1 ):
-                    p_adec->output_format.i_format = VLC_FOURCC('u','8',' ',' ');
-                    break;
-                case( 2 ):
-                    p_adec->output_format.i_format = VLC_FOURCC('s','1','6','l');
-                    break;
-                case( 3 ):
-                    p_adec->output_format.i_format = VLC_FOURCC('s','2','4','l');
-                    break;
-                case( 4 ):
-                    p_adec->output_format.i_format = VLC_FOURCC('s','3','2','l');
-                    break;
-                default:
-                    msg_Err( p_adec->p_fifo, "bad parameters(bits/sample)" );
-                    return( -1 );
+            case 1:
+                p_dec->fmt_out.i_codec = VLC_FOURCC('u','8',' ',' ');
+                break;
+            case 2:
+                p_dec->fmt_out.i_codec = VLC_FOURCC('s','1','6','l');
+                break;
+            case 3:
+                p_dec->fmt_out.i_codec = VLC_FOURCC('s','2','4','l');
+                break;
+            case 4:
+                p_dec->fmt_out.i_codec = VLC_FOURCC('s','3','2','l');
+                break;
+            default:
+                msg_Err( p_dec, "bad parameters(bits/sample)" );
+                return VLC_EGENERIC;
             }
         }
-        else if( p_adec->p_fifo->i_fourcc == VLC_FOURCC( 'a', 'l', 'a', 'w' ) )
+        else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'a', 'l', 'a', 'w' ) )
         {
-            p_adec->output_format.i_format = AOUT_FMT_S16_NE;
-            p_adec->p_logtos16  = alawtos16;
+            p_dec->fmt_out.i_codec = AOUT_FMT_S16_NE;
+            p_sys->p_logtos16  = alawtos16;
+            p_dec->fmt_in.audio.i_bitspersample = 8;
         }
-        else if( p_adec->p_fifo->i_fourcc == VLC_FOURCC( 'u', 'l', 'a', 'w' ) )
+        else if( p_dec->fmt_in.i_codec == VLC_FOURCC( 'u', 'l', 'a', 'w' ) )
         {
-            p_adec->output_format.i_format = AOUT_FMT_S16_NE;
-            p_adec->p_logtos16  = ulawtos16;
+            p_dec->fmt_out.i_codec = AOUT_FMT_S16_NE;
+            p_sys->p_logtos16  = ulawtos16;
+            p_dec->fmt_in.audio.i_bitspersample = 8;
         }
     }
-    p_adec->output_format.i_rate = p_adec->p_wf->nSamplesPerSec;
 
-    if( p_adec->p_wf->nChannels <= 0 ||
-            p_adec->p_wf->nChannels > 5 )
-    {
-        msg_Err( p_adec->p_fifo, "bad channels count(1-5)" );
-        return( -1 );
-    }
+    /* Set output properties */
+    p_dec->fmt_out.i_cat = AUDIO_ES;
+    p_dec->fmt_out.audio.i_rate = p_dec->fmt_in.audio.i_rate;
+    p_dec->fmt_out.audio.i_channels = p_dec->fmt_in.audio.i_channels;
+    p_dec->fmt_out.audio.i_physical_channels =
+        p_dec->fmt_out.audio.i_original_channels =
+            pi_channels_maps[p_dec->fmt_in.audio.i_channels];
 
-    p_adec->output_format.i_physical_channels =
-            p_adec->output_format.i_original_channels =
-            pi_channels_maps[p_adec->p_wf->nChannels];
-    p_adec->p_aout = NULL;
-    p_adec->p_aout_input = NULL;
-
-    /* **** Create a new audio output **** */
-    aout_DateInit( &p_adec->date, p_adec->output_format.i_rate );
-    p_adec->p_aout_input = aout_DecNew( p_adec->p_fifo,
-                                        &p_adec->p_aout,
-                                        &p_adec->output_format );
-    if( !p_adec->p_aout_input )
-    {
-        msg_Err( p_adec->p_fifo, "cannot create aout" );
-        return( -1 );
-    }
+    aout_DateInit( &p_sys->end_date, p_dec->fmt_out.audio.i_rate );
+    aout_DateSet( &p_sys->end_date, 0 );
 
-    /* Init the BitStream */
-//    InitBitstream( &p_adec->bit_stream, p_adec->p_fifo,
-//                   NULL, NULL );
+    p_dec->pf_decode_audio = DecodeBlock;
 
-    return( 0 );
+    return VLC_SUCCESS;
 }
 
-static void GetPESData( u8 *p_buf, int i_max, pes_packet_t *p_pes )
+/****************************************************************************
+ * DecodeBlock: the whole thing
+ ****************************************************************************
+ * This function must be fed with whole samples (see nBlockAlign).
+ ****************************************************************************/
+static aout_buffer_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
 {
-    int i_copy;
-    int i_count;
+    decoder_sys_t *p_sys = p_dec->p_sys;
+    block_t *p_block;
+    int i_samples;
 
-    data_packet_t   *p_data;
+    if( !pp_block || !*pp_block ) return NULL;
 
-    i_count = 0;
-    p_data = p_pes->p_first;
-    while( p_data != NULL && i_count < i_max )
+    p_block = *pp_block;
+
+    if( p_block->i_pts != 0 &&
+        p_block->i_pts != aout_DateGet( &p_sys->end_date ) )
     {
+        aout_DateSet( &p_sys->end_date, p_block->i_pts );
+    }
+    else if( !aout_DateGet( &p_sys->end_date ) )
+    {
+        /* We've just started the stream, wait for the first PTS. */
+        block_Release( p_block );
+        return NULL;
+    }
+
+    /* Don't re-use the same pts twice */
+    p_block->i_pts = 0;
+
+    i_samples = p_block->i_buffer * 8 / p_dec->fmt_in.audio.i_bitspersample /
+        p_dec->fmt_in.audio.i_channels;
+
 
-        i_copy = __MIN( p_data->p_payload_end - p_data->p_payload_start, i_max - i_count );
+    /* Create chunks of max 1024 samples */
+    if( i_samples > 0 )
+    {
+        aout_buffer_t *p_out;
+        i_samples = __MIN( i_samples, 1024 );
 
-        if( i_copy > 0 )
+        p_out = p_dec->pf_aout_buffer_new( p_dec, i_samples );
+        if( p_out == NULL )
         {
-            memcpy( p_buf,
-                    p_data->p_payload_start,
-                    i_copy );
+            block_Release( p_block );
+            return NULL;
         }
 
-        p_data = p_data->p_next;
-        i_count += i_copy;
-        p_buf   += i_copy;
-    }
+        p_out->start_date = aout_DateGet( &p_sys->end_date );
+        p_out->end_date   = aout_DateIncrement( &p_sys->end_date, i_samples );
 
-    if( i_count < i_max )
-    {
-        memset( p_buf, 0, i_max - i_count );
+        if( p_sys->p_logtos16 )
+        {
+            int16_t *s = (int16_t*)p_out->p_buffer;
+            unsigned int i;
+
+            for( i = 0; i < p_out->i_nb_bytes / 2; i++ )
+            {
+                *s++ = p_sys->p_logtos16[*p_block->p_buffer++];
+                p_block->i_buffer++;
+            }
+        }
+        else
+        {
+            memcpy( p_out->p_buffer, p_block->p_buffer, p_out->i_nb_bytes );
+            p_block->p_buffer += p_out->i_nb_bytes;
+            p_block->i_buffer -= p_out->i_nb_bytes;
+        }
+
+        return p_out;
     }
+
+    block_Release( p_block );
+    return NULL;
 }
 
 /*****************************************************************************
- * DecodeThread: decodes a frame
+ * DecoderClose: decoder destruction
  *****************************************************************************/
-static void DecodeThread( adec_thread_t *p_adec )
+static void DecoderClose( vlc_object_t *p_this )
 {
-    aout_buffer_t   *p_aout_buffer;
-    int             i_samples; // per channels
-    int             i_size;
-    uint8_t         *p_data, *p;
-    pes_packet_t    *p_pes;
-
-    /* **** get samples count **** */
-    input_ExtractPES( p_adec->p_fifo, &p_pes );
-    if( !p_pes )
-    {
-        p_adec->p_fifo->b_error = 1;
-        return;
-    }
-    i_size = p_pes->i_pes_size;
+    decoder_t *p_dec = (decoder_t *)p_this;
+
+    free( p_dec->p_sys );
+}
 
-    if( p_adec->p_wf->nBlockAlign > 0 )
+/*****************************************************************************
+ * EncoderOpen:
+ *****************************************************************************/
+static int EncoderOpen( vlc_object_t *p_this )
+{
+    encoder_t *p_enc = (encoder_t *)p_this;
+
+    if( p_enc->fmt_in.i_codec != VLC_FOURCC( 's', '1', '6', 'b' ) &&
+        p_enc->fmt_in.i_codec != VLC_FOURCC( 's', '1', '6', 'l' ) )
     {
-        i_size -= i_size % p_adec->p_wf->nBlockAlign;
+        msg_Warn( p_enc, "unhandled input format" );
+        return VLC_EGENERIC;
     }
-    if( i_size <= 0 || i_size < p_adec->p_wf->nBlockAlign )
+
+    switch( p_enc->fmt_out.i_codec )
     {
-        input_DeletePES( p_adec->p_fifo->p_packets_mgt, p_pes );
-        return;
+        case VLC_FOURCC( 's', '1', '6', 'b' ):
+        case VLC_FOURCC( 's', '1', '6', 'l' ):
+        case VLC_FOURCC( 'u', '8', ' ', ' ' ):
+        case VLC_FOURCC( 's', '8', ' ', ' ' ):
+#if 0
+        -> could be easyly done with table look up
+        case VLC_FOURCC( 'a', 'l', 'a', 'w' ):
+        case VLC_FOURCC( 'u', 'l', 'a', 'w' ):
+#endif
+            break;
+        default:
+            return VLC_EGENERIC;
     }
 
-    i_samples = i_size /
-                ( ( p_adec->p_wf->wBitsPerSample + 7 ) / 8 ) /
-                p_adec->p_wf->nChannels;
-
-//    msg_Warn( p_adec->p_fifo, "got %d samples (%d bytes)", i_samples, i_size );
-    p_adec->pts = p_pes->i_pts;
+    p_enc->p_sys = NULL;
+    p_enc->pf_encode_audio = EncoderEncode;
 
-    /* **** Now we can output these samples **** */
+    return VLC_SUCCESS;
+}
 
-    if( p_adec->pts != 0 && p_adec->pts != aout_DateGet( &p_adec->date ) )
-    {
-        aout_DateSet( &p_adec->date, p_adec->pts );
-    }
-    else if( !aout_DateGet( &p_adec->date ) )
-    {
-        return;
-    }
+/*****************************************************************************
+ * EncoderClose:
+ *****************************************************************************/
+static void EncoderClose ( vlc_object_t *p_this )
+{
+    return;
+}
 
-    /* gather data */
-    p = p_data = malloc( i_size );
-    GetPESData( p_data, i_size, p_pes );
+/*****************************************************************************
+ * EncoderEncode:
+ *****************************************************************************/
+static block_t *EncoderEncode( encoder_t *p_enc, aout_buffer_t *p_aout_buf )
+{
+    block_t *p_block = NULL;
+    unsigned int i;
 
-    while( i_samples > 0 )
+    if( p_enc->fmt_in.i_codec == p_enc->fmt_out.i_codec )
     {
-        int i_copy;
-
-        i_copy = __MIN( i_samples, 1024 );
-        p_aout_buffer = aout_DecNewBuffer( p_adec->p_aout,
-                                           p_adec->p_aout_input,
-                                           i_copy );
-        if( !p_aout_buffer )
+        if( ( p_block = block_New( p_enc, p_aout_buf->i_nb_bytes ) ) )
         {
-            msg_Err( p_adec->p_fifo, "cannot get aout buffer" );
-            p_adec->p_fifo->b_error = 1;
-
-            free( p_data );
-            return;
+            memcpy( p_block->p_buffer, p_aout_buf->p_buffer,
+                    p_aout_buf->i_nb_bytes );
         }
-
-        p_aout_buffer->start_date = aout_DateGet( &p_adec->date );
-        p_aout_buffer->end_date = aout_DateIncrement( &p_adec->date,
-                                                      i_copy );
-
-        if( p_adec->p_logtos16 )
+    }
+    else if( p_enc->fmt_out.i_codec == VLC_FOURCC( 'u', '8', ' ', ' ' ) )
+    {
+        if( ( p_block = block_New( p_enc, p_aout_buf->i_nb_bytes / 2 ) ) )
         {
-            int16_t *s = (int16_t*)p_aout_buffer->p_buffer;
+            uint8_t *p_dst = (uint8_t*)p_block->p_buffer;
+            int8_t  *p_src = (int8_t*) p_aout_buf->p_buffer;
 
-            unsigned int     i;
+            if( p_enc->fmt_in.i_codec == VLC_FOURCC( 's', '1', '6', 'l' ) )
+            {
+                p_src++;
+            }
 
-            for( i = 0; i < p_aout_buffer->i_nb_bytes; i++ )
+            for( i = 0; i < p_aout_buf->i_nb_bytes / 2; i++ )
             {
-                *s++ = p_adec->p_logtos16[*p++];
+                *p_dst++ = *p_src + 128; p_src += 2;
             }
         }
-        else
+    }
+    else if( p_enc->fmt_out.i_codec == VLC_FOURCC( 's', '8', ' ', ' ' ) )
+    {
+        if( ( p_block = block_New( p_enc, p_aout_buf->i_nb_bytes / 2 ) ) )
         {
-            memcpy( p_aout_buffer->p_buffer,
-                    p,
-                    p_aout_buffer->i_nb_bytes );
-
-            p += p_aout_buffer->i_nb_bytes;
-        }
+            int8_t *p_dst = (int8_t*)p_block->p_buffer;
+            int8_t *p_src = (int8_t*)p_aout_buf->p_buffer;
 
-        aout_DecPlay( p_adec->p_aout, p_adec->p_aout_input, p_aout_buffer );
+            if( p_enc->fmt_in.i_codec == VLC_FOURCC( 's', '1', '6', 'l' ) )
+            {
+                p_src++;
+            }
 
-        i_samples -= i_copy;
+            for( i = 0; i < p_aout_buf->i_nb_bytes / 2; i++ )
+            {
+                *p_dst++ = *p_src; p_src += 2;
+            }
+        }
     }
+    else
+    {
+        /* endian swapping */
+        if( ( p_block = block_New( p_enc, p_aout_buf->i_nb_bytes ) ) )
+        {
+            uint8_t *p_dst = (uint8_t*)p_block->p_buffer;
+            uint8_t *p_src = (uint8_t*)p_aout_buf->p_buffer;
 
-    free( p_data );
-    input_DeletePES( p_adec->p_fifo->p_packets_mgt, p_pes );
-}
+            for( i = 0; i < p_aout_buf->i_nb_bytes / 2; i++ )
+            {
+                p_dst[0] = p_src[1];
+                p_dst[1] = p_src[0];
 
+                p_dst += 2;
+                p_src += 2;
+            }
+        }
+    }
 
-/*****************************************************************************
- * EndThread : faad decoder thread destruction
- *****************************************************************************/
-static void EndThread (adec_thread_t *p_adec)
-{
-    if( p_adec->p_aout_input )
+    if( p_block )
     {
-        aout_DecDelete( p_adec->p_aout, p_adec->p_aout_input );
+        p_block->i_dts = p_block->i_pts = p_aout_buf->start_date;
+        p_block->i_length = (int64_t)p_aout_buf->i_nb_samples *
+            (int64_t)1000000 / p_enc->fmt_in.audio.i_rate;
     }
 
-    msg_Dbg( p_adec->p_fifo, "raw audio decoder closed" );
-
-    free( p_adec );
+    return p_block;
 }
-
-