Changeset def5f9e2207c9b20fc0e3c2c95b013ed63f8cc66

Show
Ignore:
Timestamp:
11/04/03 15:51:51 (5 years ago)
Author:
Laurent Aimar <fenrir@videolan.org>
git-committer:
Laurent Aimar <fenrir@videolan.org> 1067957511 +0000
git-parent:

[9498c61e75ec90ba9893894089b77d43097ce638]

git-author:
Laurent Aimar <fenrir@videolan.org> 1067957511 +0000
Message:
  • adpcm: converted to new API (need more testing).
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/codec/adpcm.c

    r7bb574f rdef5f9e  
    33 ***************************************************************************** 
    44 * Copyright (C) 2001, 2002 VideoLAN 
    5  * $Id: adpcm.c,v 1.13 2003/09/02 20:19:25 gbazin Exp $ 
     5 * $Id: adpcm.c,v 1.14 2003/11/04 14:51:51 fenrir Exp $ 
    66 * 
    77 * Authors: Laurent Aimar <fenrir@via.ecp.fr> 
     
    2727 * Documentation: http://www.pcisys.net/~melanson/codecs/adpcm.txt 
    2828 *****************************************************************************/ 
     29#include <stdlib.h>                                      /* malloc(), free() */ 
     30 
    2931#include <vlc/vlc.h> 
    3032#include <vlc/aout.h> 
     
    3234#include <vlc/input.h> 
    3335 
    34 #include <stdlib.h>                                      /* malloc(), free() */ 
    35 #include <string.h>                                              /* strdup() */ 
    3636#include "codecs.h" 
     37 
     38/***************************************************************************** 
     39 * Module descriptor 
     40 *****************************************************************************/ 
     41static int  Open    ( vlc_object_t * ); 
     42 
     43vlc_module_begin(); 
     44    set_description( _("ADPCM audio decoder") ); 
     45    set_capability( "decoder", 50 ); 
     46    set_callbacks( Open, NULL ); 
     47vlc_module_end(); 
     48 
     49 
    3750/***************************************************************************** 
    3851 * Local prototypes 
    3952 *****************************************************************************/ 
    40  
    41 #define ADPCM_IMA_QT    1 
    42 #define ADPCM_IMA_WAV   2 
    43 #define ADPCM_MS        3 
    44 #define ADPCM_DK3       4 
    45 #define ADPCM_DK4       5 
    46  
    47 typedef struct adec_thread_s 
    48 
    49     int i_codec; 
    50  
    51     WAVEFORMATEX    *p_wf; 
     53enum adpcm_codec_e 
     54
     55    ADPCM_IMA_QT, 
     56    ADPCM_IMA_WAV, 
     57    ADPCM_MS, 
     58    ADPCM_DK3, 
     59    ADPCM_DK4 
     60}; 
     61 
     62struct decoder_sys_t 
     63
     64    WAVEFORMATEX       *p_wf; 
     65    enum adpcm_codec_e codec; 
    5266 
    5367    int                 i_block; 
    54     uint8_t             *p_block; 
    5568    int                 i_samplesperblock; 
    5669 
    57     uint8_t             *p_buffer;      /* buffer for gather pes */  \ 
    58     int                 i_buffer;       /* bytes present in p_buffer */ 
    59  
    60     /* Input properties */ 
    61     decoder_fifo_t *p_fifo; 
    62  
    63     /* Output properties */ 
     70    /* audio output */ 
    6471    aout_instance_t *   p_aout;       /* opaque */ 
    6572    aout_input_t *      p_aout_input; /* opaque */ 
     
    6774 
    6875    audio_date_t        date; 
    69     mtime_t             pts; 
    70  
    71 } adec_thread_t; 
    72  
    73 static int  OpenDecoder    ( vlc_object_t * ); 
    74  
    75 static int  RunDecoder     ( decoder_fifo_t * ); 
    76 static int  InitThread     ( adec_thread_t * ); 
    77 static void DecodeThread   ( adec_thread_t * ); 
    78 static void EndThread      ( adec_thread_t * ); 
    79  
    80  
    81 static void DecodeAdpcmMs       ( adec_thread_t *, aout_buffer_t * ); 
    82 static void DecodeAdpcmImaWav   ( adec_thread_t *, aout_buffer_t * ); 
    83 static void DecodeAdpcmImaQT    ( adec_thread_t *, aout_buffer_t * ); 
    84 static void DecodeAdpcmDk4      ( adec_thread_t *, aout_buffer_t * ); 
    85 static void DecodeAdpcmDk3      ( adec_thread_t *, aout_buffer_t * ); 
    86  
    87 /***************************************************************************** 
    88  * Module descriptor 
    89  *****************************************************************************/ 
    90  
    91 vlc_module_begin(); 
    92     set_description( _("ADPCM audio decoder") ); 
    93     set_capability( "decoder", 50 ); 
    94     set_callbacks( OpenDecoder, NULL ); 
    95 vlc_module_end(); 
    96  
     76}; 
     77 
     78static int Init  ( decoder_t * ); 
     79static int Decode( decoder_t *, block_t * ); 
     80static int End   ( decoder_t * ); 
     81 
     82 
     83 
     84static void DecodeAdpcmMs       ( decoder_sys_t *, int16_t *, uint8_t * ); 
     85static void DecodeAdpcmImaWav   ( decoder_sys_t *, int16_t *, uint8_t * ); 
     86static void DecodeAdpcmImaQT    ( decoder_sys_t *, int16_t *, uint8_t * ); 
     87static void DecodeAdpcmDk4      ( decoder_sys_t *, int16_t *, uint8_t * ); 
     88static void DecodeAdpcmDk3      ( decoder_sys_t *, int16_t *, uint8_t * ); 
    9789 
    9890static int pi_channels_maps[6] = 
     
    150142 * to choose. 
    151143 *****************************************************************************/ 
    152 static int OpenDecoder( vlc_object_t *p_this ) 
     144static int Open( vlc_object_t *p_this ) 
    153145{ 
    154146    decoder_t *p_dec = (decoder_t*)p_this; 
     
    162154        case VLC_FOURCC('m','s',0x00,0x62): /* Duck DK3 ADPCM */ 
    163155 
    164             p_dec->pf_run = RunDecoder; 
     156            p_dec->pf_init   = Init; 
     157            p_dec->pf_decode = Decode; 
     158            p_dec->pf_end    = End; 
     159 
     160            p_dec->p_sys     = malloc( sizeof( decoder_sys_t ) ); 
    165161            return VLC_SUCCESS; 
    166162 
     
    171167 
    172168/***************************************************************************** 
    173  * RunDecoder: this function is called just after the thread is created 
     169 * Init: 
    174170 *****************************************************************************/ 
    175 static int RunDecoder( decoder_fifo_t *p_fifo ) 
    176 
    177     adec_thread_t *p_adec; 
    178     int b_error; 
    179  
    180     if( !( p_adec = malloc( sizeof( adec_thread_t ) ) ) ) 
    181     { 
    182         msg_Err( p_fifo, "out of memory" ); 
    183         DecoderError( p_fifo ); 
    184         return( -1 ); 
    185     } 
    186     memset( p_adec, 0, sizeof( adec_thread_t ) ); 
    187  
    188     p_adec->p_fifo = p_fifo; 
    189  
    190     if( InitThread( p_adec ) != 0 ) 
    191     { 
    192         DecoderError( p_fifo ); 
    193         return( -1 ); 
    194     } 
    195  
    196     while( ( !p_adec->p_fifo->b_die )&&( !p_adec->p_fifo->b_error ) ) 
    197     { 
    198         DecodeThread( p_adec ); 
    199     } 
    200  
    201  
    202     if( ( b_error = p_adec->p_fifo->b_error ) ) 
    203     { 
    204         DecoderError( p_adec->p_fifo ); 
    205     } 
    206  
    207     EndThread( p_adec ); 
    208     if( b_error ) 
    209     { 
    210         return( -1 ); 
    211     } 
    212  
    213     return( 0 ); 
    214 
    215  
    216  
    217 #define FREE( p ) if( p ) free( p ); p = NULL 
    218  
    219 /***************************************************************************** 
    220  * InitThread: initialize data before entering main loop 
    221  *****************************************************************************/ 
    222  
    223 static int InitThread( adec_thread_t * p_adec ) 
    224 
    225     if( ( p_adec->p_wf = (WAVEFORMATEX*)p_adec->p_fifo->p_waveformatex ) == NULL ) 
    226     { 
    227         msg_Err( p_adec->p_fifo, "missing format" ); 
    228         return( -1 ); 
    229     } 
    230     /* fourcc to codec */ 
    231     switch( p_adec->p_fifo->i_fourcc ) 
     171static int Init  ( decoder_t *p_dec ) 
     172
     173    decoder_sys_t *p_sys = p_dec->p_sys; 
     174 
     175    WAVEFORMATEX *p_wf; 
     176    if( ( p_wf = (WAVEFORMATEX*)p_dec->p_fifo->p_waveformatex ) == NULL ) 
     177    { 
     178        msg_Err( p_dec, "unknown raw format" ); 
     179        return VLC_EGENERIC; 
     180    } 
     181 
     182    if( p_wf->nChannels < 1 || p_wf->nChannels > 2 ) 
     183    { 
     184        msg_Err( p_dec, "bad channels count(1-2)" ); 
     185        return VLC_EGENERIC; 
     186    } 
     187    if( p_wf->nSamplesPerSec <= 0 ) 
     188    { 
     189        msg_Err( p_dec, "bad samplerate" ); 
     190        return VLC_EGENERIC; 
     191    } 
     192 
     193    p_sys->p_wf = p_wf; 
     194    switch( p_dec->p_fifo->i_fourcc ) 
    232195    { 
    233196        case VLC_FOURCC('i','m','a', '4'): /* IMA ADPCM */ 
    234             p_adec->i_codec = ADPCM_IMA_QT; 
     197            p_sys->codec = ADPCM_IMA_QT; 
    235198            break; 
    236199        case VLC_FOURCC('m','s',0x00,0x11): /* IMA ADPCM */ 
    237             p_adec->i_codec = ADPCM_IMA_WAV; 
     200            p_sys->codec = ADPCM_IMA_WAV; 
    238201            break; 
    239202        case VLC_FOURCC('m','s',0x00,0x02): /* MS ADPCM */ 
    240             p_adec->i_codec = ADPCM_MS; 
     203            p_sys->codec = ADPCM_MS; 
    241204            break; 
    242205        case VLC_FOURCC('m','s',0x00,0x61): /* Duck DK4 ADPCM */ 
    243             p_adec->i_codec = ADPCM_DK4; 
     206            p_sys->codec = ADPCM_DK4; 
    244207            break; 
    245208        case VLC_FOURCC('m','s',0x00,0x62): /* Duck DK3 ADPCM */ 
    246             p_adec->i_codec = ADPCM_DK3; 
    247             break; 
    248     } 
    249  
    250     if( p_adec->p_wf->nChannels < 1 || 
    251             p_adec->p_wf->nChannels > 2 ) 
    252     { 
    253         msg_Err( p_adec->p_fifo, "bad channels count(1-2)" ); 
    254         return( -1 ); 
    255     } 
    256     if( !( p_adec->i_block = p_adec->p_wf->nBlockAlign ) ) 
    257     { 
    258         if( p_adec->i_codec == ADPCM_IMA_QT ) 
    259         { 
    260             p_adec->i_block = 34 * p_adec->p_wf->nChannels; 
    261         } 
    262         else 
    263         { 
    264             p_adec->i_block = 1024; // XXX FIXME 
    265         } 
    266         msg_Warn( p_adec->p_fifo, 
    267                  "block size undefined, using %d default", 
    268                  p_adec->i_block ); 
    269     } 
    270     p_adec->p_block = NULL; 
     209            p_sys->codec = ADPCM_DK3; 
     210            break; 
     211    } 
     212 
     213    if( ( p_sys->i_block = p_wf->nBlockAlign ) <= 0 ) 
     214    { 
     215        p_sys->i_block = p_sys->codec==ADPCM_IMA_QT ? 34*p_wf->nChannels:1024; 
     216        msg_Warn( p_dec, "block size undefined, -> using %d", p_sys->i_block ); 
     217    } 
    271218 
    272219    /* calculate samples per block */ 
    273     switch( p_adec->i_codec ) 
     220    switch( p_sys->codec ) 
    274221    { 
    275222        case ADPCM_IMA_QT: 
    276             p_adec->i_samplesperblock = 64; 
     223            p_sys->i_samplesperblock = 64; 
    277224            break; 
    278225        case ADPCM_IMA_WAV: 
    279             p_adec->i_samplesperblock = 
    280                  2 * ( p_adec->i_block - 4 * p_adec->p_wf->nChannels )/ 
    281                  p_adec->p_wf->nChannels; 
     226            p_sys->i_samplesperblock = 
     227                 2 * ( p_sys->i_block - 4 * p_wf->nChannels )/ p_wf->nChannels; 
    282228                 break; 
    283229        case ADPCM_MS: 
    284             p_adec->i_samplesperblock = 
    285                 2 * ( p_adec->i_block - 7 * p_adec->p_wf->nChannels ) / 
    286                 p_adec->p_wf->nChannels + 2; 
     230            p_sys->i_samplesperblock = 
     231                2 * (p_sys->i_block - 7 * p_wf->nChannels)/p_wf->nChannels + 2; 
    287232            break; 
    288233        case ADPCM_DK4: 
    289             p_adec->i_samplesperblock = 
    290                2 * ( p_adec->i_block - 4 * p_adec->p_wf->nChannels ) / 
    291                p_adec->p_wf->nChannels + 1; 
     234            p_sys->i_samplesperblock = 
     235               2 * (p_sys->i_block - 4 * p_wf->nChannels)/p_wf->nChannels + 1; 
    292236            break; 
    293237        case ADPCM_DK3: 
    294             p_adec->p_wf->nChannels = 2; 
    295             p_adec->i_samplesperblock = ( 4 * ( p_adec->i_block - 16 ) + 2 )/ 3; 
    296             break; 
    297         default: 
    298             msg_Err( p_adec->p_fifo, "unknown adpcm variant" ); 
    299             return( -1 ); 
    300     } 
    301  
    302     msg_Dbg( p_adec->p_fifo, 
     238            p_wf->nChannels = 2; 
     239            p_sys->i_samplesperblock = ( 4 * ( p_sys->i_block - 16 ) + 2 )/ 3; 
     240            break; 
     241    } 
     242    msg_Dbg( p_dec, 
    303243             "format: samplerate:%dHz channels:%d bits/sample:%d blockalign:%d samplesperblock %d", 
    304              p_adec->p_wf->nSamplesPerSec, 
    305              p_adec->p_wf->nChannels, 
    306              p_adec->p_wf->wBitsPerSample, 
    307              p_adec->p_wf->nBlockAlign, 
    308              p_adec->i_samplesperblock ); 
    309  
    310     //p_adec->output_format.i_format = VLC_FOURCC('s','1','6','l'); 
    311     /* FIXME good way ? */ 
    312     p_adec->output_format.i_format = AOUT_FMT_S16_NE; 
    313     p_adec->output_format.i_rate = p_adec->p_wf->nSamplesPerSec; 
    314  
    315  
    316     p_adec->output_format.i_physical_channels = 
    317         p_adec->output_format.i_original_channels = 
    318             pi_channels_maps[p_adec->p_wf->nChannels]; 
    319     p_adec->p_aout = NULL; 
    320     p_adec->p_aout_input = NULL; 
    321  
    322     /* **** Create a new audio output **** */ 
    323     aout_DateInit( &p_adec->date, p_adec->output_format.i_rate ); 
    324     p_adec->p_aout_input = aout_DecNew( p_adec->p_fifo, 
    325                                         &p_adec->p_aout, 
    326                                         &p_adec->output_format ); 
    327     if( !p_adec->p_aout_input ) 
    328     { 
    329         msg_Err( p_adec->p_fifo, "cannot create aout" ); 
    330         return( -1 ); 
    331     } 
    332  
    333     /* Init the BitStream */ 
    334 //    InitBitstream( &p_adec->bit_stream, p_adec->p_fifo, 
    335 //                   NULL, NULL ); 
    336  
    337     return( 0 ); 
    338 
    339  
    340  
    341 static void GetPESData( uint8_t *p_buf, int i_max, pes_packet_t *p_pes ) 
    342 
    343     int i_copy; 
    344     int i_count; 
    345  
    346     data_packet_t   *p_data; 
    347  
    348     i_count = 0; 
    349     p_data = p_pes->p_first; 
    350     while( p_data != NULL && i_count < i_max ) 
    351     { 
    352  
    353         i_copy = __MIN( p_data->p_payload_end - p_data->p_payload_start, 
    354                         i_max - i_count ); 
    355  
    356         if( i_copy > 0 ) 
     244             p_wf->nSamplesPerSec, p_wf->nChannels, 
     245             p_wf->wBitsPerSample, p_wf->nBlockAlign, 
     246             p_sys->i_samplesperblock ); 
     247 
     248    p_sys->output_format.i_format = AOUT_FMT_S16_NE; 
     249    p_sys->output_format.i_rate = p_wf->nSamplesPerSec; 
     250    p_sys->output_format.i_physical_channels = 
     251    p_sys->output_format.i_original_channels = 
     252            pi_channels_maps[p_wf->nChannels]; 
     253 
     254    p_sys->p_aout = NULL; 
     255    p_sys->p_aout_input = aout_DecNew( p_dec, 
     256                                       &p_sys->p_aout, &p_sys->output_format); 
     257    if( p_sys->p_aout_input == NULL ) 
     258    { 
     259        msg_Err( p_dec, "cannot create aout" ); 
     260        return VLC_EGENERIC; 
     261    } 
     262 
     263    aout_DateInit( &p_sys->date, p_sys->output_format.i_rate ); 
     264    aout_DateSet( &p_sys->date, 0 ); 
     265 
     266    return VLC_SUCCESS; 
     267
     268 
     269/***************************************************************************** 
     270 * Decode: 
     271 *****************************************************************************/ 
     272static int Decode( decoder_t *p_dec, block_t *p_block ) 
     273
     274    decoder_sys_t *p_sys  = p_dec->p_sys; 
     275    mtime_t        i_pts  = p_block->i_pts; 
     276    uint8_t       *p_data = p_block->p_buffer; 
     277    int            i_data = p_block->i_buffer; 
     278 
     279    while( i_data >= p_sys->i_block ) 
     280    { 
     281        aout_buffer_t *out; 
     282 
     283        if( i_pts != 0 && i_pts != aout_DateGet( &p_sys->date ) ) 
    357284        { 
    358             memcpy( p_buf, 
    359                     p_data->p_payload_start, 
    360                     i_copy ); 
     285            aout_DateSet( &p_sys->date, i_pts ); 
    361286        } 
    362  
    363         p_data = p_data->p_next; 
    364         i_count += i_copy; 
    365         p_buf   += i_copy; 
    366     } 
    367  
    368     if( i_count < i_max ) 
    369     { 
    370         memset( p_buf, 0, i_max - i_count ); 
    371     } 
    372 
    373  
    374 /***************************************************************************** 
    375  * DecodeThread: decodes a frame 
    376  *****************************************************************************/ 
    377 static void DecodeThread( adec_thread_t *p_adec ) 
    378 
    379     aout_buffer_t   *p_aout_buffer; 
    380     pes_packet_t    *p_pes; 
    381  
    382     int             i_frame_size; 
    383  
    384     /* **** Get a new frames from streams **** */ 
    385     do 
    386     { 
    387         input_ExtractPES( p_adec->p_fifo, &p_pes ); 
    388         if( !p_pes ) 
     287        else if( !aout_DateGet( &p_sys->date ) ) 
    389288        { 
    390             p_adec->p_fifo->b_error = 1; 
    391             return; 
     289            return VLC_SUCCESS; 
    392290        } 
    393         if( p_pes->i_pts != 0 ) 
     291        i_pts = 0; 
     292 
     293        out = aout_DecNewBuffer( p_sys->p_aout, 
     294                                 p_sys->p_aout_input, 
     295                                 p_sys->i_samplesperblock ); 
     296        if( out == NULL ) 
    394297        { 
    395             p_adec->pts = p_pes->i_pts; 
     298            msg_Err( p_dec, "cannot get aout buffer" ); 
     299            return VLC_EGENERIC; 
    396300        } 
    397         i_frame_size = p_pes->i_pes_size; 
    398  
    399         if( i_frame_size > 0 ) 
    400         { 
    401             if( p_adec->i_buffer < i_frame_size + 16 ) 
    402             { 
    403                 FREE( p_adec->p_buffer ); 
    404                 p_adec->p_buffer = malloc( i_frame_size + 16 ); 
    405                 p_adec->i_buffer = i_frame_size + 16; 
    406             } 
    407  
    408             GetPESData( p_adec->p_buffer, p_adec->i_buffer, p_pes ); 
    409         } 
    410         input_DeletePES( p_adec->p_fifo->p_packets_mgt, p_pes ); 
    411  
    412     } while( i_frame_size <= 0 ); 
    413  
    414     for( p_adec->p_block = p_adec->p_buffer; 
    415          i_frame_size >= p_adec->i_block; 
    416          p_adec->p_block += p_adec->i_block, i_frame_size -= p_adec->i_block  ) 
    417     { 
    418         /* get output buffer */ 
    419         if( p_adec->pts != 0 && p_adec->pts != aout_DateGet( &p_adec->date ) ) 
    420         { 
    421             aout_DateSet( &p_adec->date, p_adec->pts ); 
    422         } 
    423         else if( !aout_DateGet( &p_adec->date ) ) 
    424         { 
    425             return; 
    426         } 
    427         p_adec->pts = 0; 
    428  
    429         p_aout_buffer = aout_DecNewBuffer( p_adec->p_aout, 
    430                                            p_adec->p_aout_input, 
    431                                            p_adec->i_samplesperblock ); 
    432         if( !p_aout_buffer ) 
    433         { 
    434             msg_Err( p_adec->p_fifo, "cannot get aout buffer" ); 
    435             p_adec->p_fifo->b_error = 1; 
    436             return; 
    437         } 
    438  
    439         p_aout_buffer->start_date = aout_DateGet( &p_adec->date ); 
    440         p_aout_buffer->end_date = aout_DateIncrement( &p_adec->date, 
    441                                                       p_adec->i_samplesperblock ); 
    442  
    443         /* decode */ 
    444  
    445         switch( p_adec->i_codec ) 
     301        out->start_date = aout_DateGet( &p_sys->date ); 
     302        out->end_date   = aout_DateIncrement( &p_sys->date, 
     303                                              p_sys->i_samplesperblock ); 
     304 
     305        switch( p_sys->codec ) 
    446306        { 
    447307            case ADPCM_IMA_QT: 
    448                 DecodeAdpcmImaQT( p_adec, p_aout_buffer ); 
     308                DecodeAdpcmImaQT( p_sys, (int16_t*)out->p_buffer, p_data ); 
    449309                break; 
    450310            case ADPCM_IMA_WAV: 
    451                 DecodeAdpcmImaWav( p_adec, p_aout_buffer ); 
     311                DecodeAdpcmImaWav( p_sys, (int16_t*)out->p_buffer, p_data ); 
    452312                break; 
    453313            case ADPCM_MS: 
    454                 DecodeAdpcmMs( p_adec, p_aout_buffer ); 
     314                DecodeAdpcmMs( p_sys, (int16_t*)out->p_buffer, p_data ); 
    455315                break; 
    456316            case ADPCM_DK4: 
    457                 DecodeAdpcmDk4( p_adec, p_aout_buffer ); 
     317                DecodeAdpcmDk4( p_sys, (int16_t*)out->p_buffer, p_data ); 
     318                break; 
    458319            case ADPCM_DK3: 
    459                 DecodeAdpcmDk3( p_adec, p_aout_buffer ); 
     320                DecodeAdpcmDk3( p_sys, (int16_t*)out->p_buffer, p_data ); 
     321                break; 
    460322            default: 
    461323                break; 
    462324        } 
    463  
    464  
    465         /* **** Now we can output these samples **** */ 
    466         aout_DecPlay( p_adec->p_aout, p_adec->p_aout_input, p_aout_buffer ); 
    467     } 
    468 
    469  
     325        aout_DecPlay( p_sys->p_aout, p_sys->p_aout_input, out ); 
     326 
     327        p_data += p_sys->i_block; 
     328        i_data -= p_sys->i_block; 
     329    } 
     330 
     331    return VLC_SUCCESS; 
     332
    470333 
    471334/***************************************************************************** 
    472  * EndThread : faad decoder thread destruction 
     335 * End: 
    473336 *****************************************************************************/ 
    474 static void EndThread (adec_thread_t *p_adec) 
    475 
    476     if( p_adec->p_aout_input ) 
    477     { 
    478         aout_DecDelete( p_adec->p_aout, p_adec->p_aout_input ); 
    479     } 
    480  
    481     msg_Dbg( p_adec->p_fifo, "adpcm audio decoder closed" ); 
    482  
    483     FREE( p_adec->p_buffer ); 
    484     free( p_adec ); 
    485 
     337static int End   ( decoder_t *p_dec ) 
     338
     339    decoder_sys_t *p_sys = p_dec->p_sys; 
     340 
     341    if( p_sys->p_aout_input ) 
     342    { 
     343        aout_DecDelete( p_sys->p_aout, p_sys->p_aout_input ); 
     344    } 
     345    free( p_sys ); 
     346 
     347    return VLC_SUCCESS; 
     348
     349 
    486350#define CLAMP( v, min, max ) \ 
    487351    if( (v) < (min) ) (v) = (min); \ 
     
    535399} 
    536400 
    537 static void DecodeAdpcmMs( adec_thread_t *p_adec, 
    538                            aout_buffer_t *p_aout_buffer) 
    539 
    540     uint8_t            *p_buffer; 
     401static void DecodeAdpcmMs( decoder_sys_t *p_sys, int16_t *p_sample, uint8_t *p_buffer ) 
     402
    541403    adpcm_ms_channel_t channel[2]; 
    542404    int i_nibbles; 
    543     uint16_t           *p_sample; 
    544405    int b_stereo; 
    545406    int i_block_predictor; 
    546407 
    547     p_buffer = p_adec->p_block; 
    548     b_stereo = p_adec->p_wf->nChannels == 2 ? 1 : 0; 
     408    b_stereo = p_sys->p_wf->nChannels == 2 ? 1 : 0; 
    549409 
    550410    GetByte( i_block_predictor ); 
     
    578438    } 
    579439 
    580     p_sample = (int16_t*)p_aout_buffer->p_buffer; 
    581  
    582     if( b_stereo ) 
    583     { 
    584         *p_sample = channel[0].i_sample2; p_sample++; 
    585         *p_sample = channel[1].i_sample2; p_sample++; 
    586         *p_sample = channel[0].i_sample1; p_sample++; 
    587         *p_sample = channel[1].i_sample1; p_sample++; 
     440    if( b_stereo ) 
     441    { 
     442        *p_sample++ = channel[0].i_sample2; 
     443        *p_sample++ = channel[1].i_sample2; 
     444        *p_sample++ = channel[0].i_sample1; 
     445        *p_sample++ = channel[1].i_sample1; 
    588446    } 
    589447    else 
    590448    { 
    591         *p_sample = channel[0].i_sample2; p_sample++
    592         *p_sample = channel[0].i_sample1; p_sample++
    593     } 
    594  
    595     for( i_nibbles =  2 *( p_adec->i_block - 7 * p_adec->p_wf->nChannels ); 
     449        *p_sample++ = channel[0].i_sample2
     450        *p_sample++ = channel[0].i_sample1
     451    } 
     452 
     453    for( i_nibbles =  2 *( p_sys->i_block - 7 * p_sys->p_wf->nChannels ); 
    596454         i_nibbles > 0; i_nibbles -= 2,p_buffer++ ) 
    597455    { 
    598         *p_sample = AdpcmMsExpandNibble( &channel[0], (*p_buffer) >> 4); 
    599         p_sample++; 
    600  
    601         *p_sample = AdpcmMsExpandNibble( &channel[b_stereo ? 1 : 0], 
    602                                          (*p_buffer)&0x0f); 
    603         p_sample++; 
    604     } 
    605  
    606  
     456        *p_sample++ = AdpcmMsExpandNibble( &channel[0], (*p_buffer) >> 4); 
     457        *p_sample++ = AdpcmMsExpandNibble( &channel[b_stereo ? 1 : 0], 
     458                                           (*p_buffer)&0x0f); 
     459    } 
    607460} 
    608461 
     
    640493} 
    641494 
    642 static void DecodeAdpcmImaWav( adec_thread_t *p_adec, 
    643                                aout_buffer_t *p_aout_buffer) 
    644 
    645     uint8_t                 *p_buffer; 
     495static void DecodeAdpcmImaWav( decoder_sys_t *p_sys, int16_t *p_sample, uint8_t *p_buffer ) 
     496
    646497    adpcm_ima_wav_channel_t channel[2]; 
    647498    int                     i_nibbles; 
    648     uint16_t                *p_sample; 
    649499    int                     b_stereo; 
    650500 
    651     p_buffer = p_adec->p_block; 
    652     b_stereo = p_adec->p_wf->nChannels == 2 ? 1 : 0; 
     501    b_stereo = p_sys->p_wf->nChannels == 2 ? 1 : 0; 
    653502 
    654503    GetWord( channel[0].i_predictor ); 
     
    665514    } 
    666515 
    667     p_sample = (int16_t*)p_aout_buffer->p_buffer; 
    668     if( b_stereo ) 
    669     { 
    670         for( i_nibbles = 2 * (p_adec->i_block - 8); 
     516    if( b_stereo ) 
     517    { 
     518        for( i_nibbles = 2 * (p_sys->i_block - 8); 
    671519             i_nibbles > 0; 
    672520             i_nibbles -= 16 ) 
     
    699547    else 
    700548    { 
    701         for( i_nibbles = 2 * (p_adec->i_block - 4); 
     549        for( i_nibbles = 2 * (p_sys->i_block - 4); 
    702550             i_nibbles > 0; 
    703551             i_nibbles -= 2, p_buffer++ ) 
    704552        { 
    705             *p_sample =AdpcmImaWavExpandNibble( &channel[0], (*p_buffer)&0x0f ); 
    706             p_sample++; 
    707             *p_sample =AdpcmImaWavExpandNibble( &channel[0], (*p_buffer) >> 4 ); 
    708             p_sample++; 
     553            *p_sample++ =AdpcmImaWavExpandNibble( &channel[0], (*p_buffer)&0x0f ); 
     554            *p_sample++ =AdpcmImaWavExpandNibble( &channel[0], (*p_buffer) >> 4 ); 
    709555        } 
    710556    } 
     
    714560 * Ima4 in QT file 
    715561 */ 
    716 static void DecodeAdpcmImaQT( adec_thread_t *p_adec, 
    717                               aout_buffer_t *p_aout_buffer ) 
    718 
    719     uint8_t                 *p_buffer; 
     562static void DecodeAdpcmImaQT( decoder_sys_t *p_sys, int16_t *p_sample, uint8_t *p_buffer ) 
     563
    720564    adpcm_ima_wav_channel_t channel[2]; 
    721565    int                     i_nibbles; 
    722     uint16_t                *p_sample; 
    723566    int                     i_ch; 
    724567    int                     i_step; 
    725568 
    726     p_buffer = p_adec->p_block; 
    727     i_step   = p_adec->p_wf->nChannels; 
    728  
    729     for( i_ch = 0; i_ch < p_adec->p_wf->nChannels; i_ch++ ) 
    730     { 
    731         p_sample = ((int16_t*)p_aout_buffer->p_buffer) + i_ch; 
     569    i_step   = p_sys->p_wf->nChannels; 
     570 
     571    for( i_ch = 0; i_ch < p_sys->p_wf->nChannels; i_ch++ ) 
     572    { 
    732573        /* load preambule */ 
    733574        channel[i_ch].i_predictor  = (int16_t)((( ( p_buffer[0] << 1 )|(  p_buffer[1] >> 7 ) ))<<7); 
     
    747588            p_buffer++; 
    748589        } 
     590 
     591        /* Next channel */ 
     592        p_sample += 1 - 64 * i_step; 
    749593    } 
    750594} 
     
    754598 */ 
    755599 
    756 static void DecodeAdpcmDk4( adec_thread_t *p_adec, 
    757                                aout_buffer_t *p_aout_buffer) 
    758 
    759     uint8_t                 *p_buffer; 
     600static void DecodeAdpcmDk4( decoder_sys_t *p_sys, int16_t *p_sample, uint8_t *p_buffer ) 
     601
    760602    adpcm_ima_wav_channel_t channel[2]; 
    761603    int                     i_nibbles; 
    762     uint16_t                *p_sample; 
    763604    int                     b_stereo; 
    764605 
    765     p_buffer = p_adec->p_block; 
    766     b_stereo = p_adec->p_wf->nChannels == 2 ? 1 : 0; 
     606    b_stereo = p_sys->p_wf->nChannels == 2 ? 1 : 0; 
    767607 
    768608    GetWord( channel[0].i_predictor ); 
     
    779619    } 
    780620 
    781     p_sample = (int16_t*)p_aout_buffer->p_buffer; 
    782  
    783621    /* first output predictor */ 
    784622    *p_sample++ = channel[0].i_predictor; 
     
    789627 
    790628    for( i_nibbles = 0; 
    791          i_nibbles < p_adec->i_block - 4 * (b_stereo ? 2:1 ); 
     629         i_nibbles < p_sys->i_block - 4 * (b_stereo ? 2:1 ); 
    792630         i_nibbles++ ) 
    793631    { 
     
    804642 * Dk3 
    805643 */ 
    806  
    807 static void DecodeAdpcmDk3( adec_thread_t *p_adec, 
    808                                aout_buffer_t *p_aout_buffer) 
    809 
    810     uint8_t                 *p_buffer, *p_end; 
     644static void DecodeAdpcmDk3( decoder_sys_t *p_sys, int16_t *p_sample, uint8_t *p_buffer ) 
     645
     646    uint8_t                 *p_end = &p_buffer[p_sys->i_block]; 
    811647    adpcm_ima_wav_channel_t sum; 
    812648    adpcm_ima_wav_channel_t diff; 
    813     uint16_t                *p_sample; 
    814649    int                     i_diff_value; 
    815650 
    816     p_buffer = p_adec->p_block; 
    817     p_end    = p_buffer + p_adec->i_block; 
    818  
    819651    p_buffer += 10; 
     652 
    820653    GetWord( sum.i_predictor ); 
    821654    GetWord( diff.i_predictor ); 
     
    823656    GetByte( diff.i_step_index ); 
    824657 
    825     p_sample = (int16_t*)p_aout_buffer->p_buffer; 
    826658    i_diff_value = diff.i_predictor; 
    827659    /* we process 6 nibbles at once */ 
    828     //for( i_group = 0; i_group < ( p_adec->i_block -16 ) / 3; i_group++ ) 
    829660    while( p_buffer + 1 <= p_end ) 
    830661    { 
     
    870701            *p_sample++ = sum.i_predictor - i_diff_value; 
    871702        } 
    872  
    873     } 
    874  
    875 
     703    } 
     704
     705