LCOV - code coverage report
Current view: top level - libavcodec - adpcm.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 830 1035 80.2 %
Date: 2017-12-14 01:15:32 Functions: 12 15 80.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2001-2003 The FFmpeg project
       3             :  *
       4             :  * first version by Francois Revol (revol@free.fr)
       5             :  * fringe ADPCM codecs (e.g., DK3, DK4, Westwood)
       6             :  *   by Mike Melanson (melanson@pcisys.net)
       7             :  * CD-ROM XA ADPCM codec by BERO
       8             :  * EA ADPCM decoder by Robin Kay (komadori@myrealbox.com)
       9             :  * EA ADPCM R1/R2/R3 decoder by Peter Ross (pross@xvid.org)
      10             :  * EA IMA EACS decoder by Peter Ross (pross@xvid.org)
      11             :  * EA IMA SEAD decoder by Peter Ross (pross@xvid.org)
      12             :  * EA ADPCM XAS decoder by Peter Ross (pross@xvid.org)
      13             :  * MAXIS EA ADPCM decoder by Robert Marston (rmarston@gmail.com)
      14             :  * THP ADPCM decoder by Marco Gerards (mgerards@xs4all.nl)
      15             :  *
      16             :  * This file is part of FFmpeg.
      17             :  *
      18             :  * FFmpeg is free software; you can redistribute it and/or
      19             :  * modify it under the terms of the GNU Lesser General Public
      20             :  * License as published by the Free Software Foundation; either
      21             :  * version 2.1 of the License, or (at your option) any later version.
      22             :  *
      23             :  * FFmpeg is distributed in the hope that it will be useful,
      24             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      25             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      26             :  * Lesser General Public License for more details.
      27             :  *
      28             :  * You should have received a copy of the GNU Lesser General Public
      29             :  * License along with FFmpeg; if not, write to the Free Software
      30             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      31             :  */
      32             : #include "avcodec.h"
      33             : #include "get_bits.h"
      34             : #include "bytestream.h"
      35             : #include "adpcm.h"
      36             : #include "adpcm_data.h"
      37             : #include "internal.h"
      38             : 
      39             : /**
      40             :  * @file
      41             :  * ADPCM decoders
      42             :  * Features and limitations:
      43             :  *
      44             :  * Reference documents:
      45             :  * http://wiki.multimedia.cx/index.php?title=Category:ADPCM_Audio_Codecs
      46             :  * http://www.pcisys.net/~melanson/codecs/simpleaudio.html [dead]
      47             :  * http://www.geocities.com/SiliconValley/8682/aud3.txt [dead]
      48             :  * http://openquicktime.sourceforge.net/
      49             :  * XAnim sources (xa_codec.c) http://xanim.polter.net/
      50             :  * http://www.cs.ucla.edu/~leec/mediabench/applications.html [dead]
      51             :  * SoX source code http://sox.sourceforge.net/
      52             :  *
      53             :  * CD-ROM XA:
      54             :  * http://ku-www.ss.titech.ac.jp/~yatsushi/xaadpcm.html [dead]
      55             :  * vagpack & depack http://homepages.compuserve.de/bITmASTER32/psx-index.html [dead]
      56             :  * readstr http://www.geocities.co.jp/Playtown/2004/
      57             :  */
      58             : 
      59             : /* These are for CD-ROM XA ADPCM */
      60             : static const int xa_adpcm_table[5][2] = {
      61             :     {   0,   0 },
      62             :     {  60,   0 },
      63             :     { 115, -52 },
      64             :     {  98, -55 },
      65             :     { 122, -60 }
      66             : };
      67             : 
      68             : static const int ea_adpcm_table[] = {
      69             :     0,  240,  460,  392,
      70             :     0,    0, -208, -220,
      71             :     0,    1,    3,    4,
      72             :     7,    8,   10,   11,
      73             :     0,   -1,   -3,   -4
      74             : };
      75             : 
      76             : // padded to zero where table size is less then 16
      77             : static const int swf_index_tables[4][16] = {
      78             :     /*2*/ { -1, 2 },
      79             :     /*3*/ { -1, -1, 2, 4 },
      80             :     /*4*/ { -1, -1, -1, -1, 2, 4, 6, 8 },
      81             :     /*5*/ { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 }
      82             : };
      83             : 
      84             : /* end of tables */
      85             : 
      86             : typedef struct ADPCMDecodeContext {
      87             :     ADPCMChannelStatus status[14];
      88             :     int vqa_version;                /**< VQA version. Used for ADPCM_IMA_WS */
      89             :     int has_status;
      90             : } ADPCMDecodeContext;
      91             : 
      92         132 : static av_cold int adpcm_decode_init(AVCodecContext * avctx)
      93             : {
      94         132 :     ADPCMDecodeContext *c = avctx->priv_data;
      95         132 :     unsigned int min_channels = 1;
      96         132 :     unsigned int max_channels = 2;
      97             : 
      98         132 :     switch(avctx->codec->id) {
      99           8 :     case AV_CODEC_ID_ADPCM_DTK:
     100             :     case AV_CODEC_ID_ADPCM_EA:
     101           8 :         min_channels = 2;
     102           8 :         break;
     103          12 :     case AV_CODEC_ID_ADPCM_AFC:
     104             :     case AV_CODEC_ID_ADPCM_EA_R1:
     105             :     case AV_CODEC_ID_ADPCM_EA_R2:
     106             :     case AV_CODEC_ID_ADPCM_EA_R3:
     107             :     case AV_CODEC_ID_ADPCM_EA_XAS:
     108          12 :         max_channels = 6;
     109          12 :         break;
     110           0 :     case AV_CODEC_ID_ADPCM_MTAF:
     111           0 :         min_channels = 2;
     112           0 :         max_channels = 8;
     113           0 :         break;
     114           0 :     case AV_CODEC_ID_ADPCM_PSX:
     115           0 :         max_channels = 8;
     116           0 :         break;
     117           8 :     case AV_CODEC_ID_ADPCM_IMA_DAT4:
     118             :     case AV_CODEC_ID_ADPCM_THP:
     119             :     case AV_CODEC_ID_ADPCM_THP_LE:
     120           8 :         max_channels = 14;
     121           8 :         break;
     122             :     }
     123         132 :     if (avctx->channels < min_channels || avctx->channels > max_channels) {
     124           0 :         av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
     125           0 :         return AVERROR(EINVAL);
     126             :     }
     127             : 
     128         132 :     switch(avctx->codec->id) {
     129           2 :     case AV_CODEC_ID_ADPCM_CT:
     130           2 :         c->status[0].step = c->status[1].step = 511;
     131           2 :         break;
     132          10 :     case AV_CODEC_ID_ADPCM_IMA_WAV:
     133          10 :         if (avctx->bits_per_coded_sample < 2 || avctx->bits_per_coded_sample > 5)
     134           0 :             return AVERROR_INVALIDDATA;
     135          10 :         break;
     136           3 :     case AV_CODEC_ID_ADPCM_IMA_APC:
     137           3 :         if (avctx->extradata && avctx->extradata_size >= 8) {
     138           2 :             c->status[0].predictor = AV_RL32(avctx->extradata);
     139           2 :             c->status[1].predictor = AV_RL32(avctx->extradata + 4);
     140             :         }
     141           3 :         break;
     142           4 :     case AV_CODEC_ID_ADPCM_IMA_WS:
     143           4 :         if (avctx->extradata && avctx->extradata_size >= 2)
     144           3 :             c->vqa_version = AV_RL16(avctx->extradata);
     145           4 :         break;
     146         113 :     default:
     147         113 :         break;
     148             :     }
     149             : 
     150         132 :     switch(avctx->codec->id) {
     151          56 :         case AV_CODEC_ID_ADPCM_AICA:
     152             :         case AV_CODEC_ID_ADPCM_IMA_DAT4:
     153             :         case AV_CODEC_ID_ADPCM_IMA_QT:
     154             :         case AV_CODEC_ID_ADPCM_IMA_WAV:
     155             :         case AV_CODEC_ID_ADPCM_4XM:
     156             :         case AV_CODEC_ID_ADPCM_XA:
     157             :         case AV_CODEC_ID_ADPCM_EA_R1:
     158             :         case AV_CODEC_ID_ADPCM_EA_R2:
     159             :         case AV_CODEC_ID_ADPCM_EA_R3:
     160             :         case AV_CODEC_ID_ADPCM_EA_XAS:
     161             :         case AV_CODEC_ID_ADPCM_THP:
     162             :         case AV_CODEC_ID_ADPCM_THP_LE:
     163             :         case AV_CODEC_ID_ADPCM_AFC:
     164             :         case AV_CODEC_ID_ADPCM_DTK:
     165             :         case AV_CODEC_ID_ADPCM_PSX:
     166             :         case AV_CODEC_ID_ADPCM_MTAF:
     167          56 :             avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
     168          56 :             break;
     169           4 :         case AV_CODEC_ID_ADPCM_IMA_WS:
     170           4 :             avctx->sample_fmt = c->vqa_version == 3 ? AV_SAMPLE_FMT_S16P :
     171             :                                                       AV_SAMPLE_FMT_S16;
     172           4 :             break;
     173          72 :         default:
     174          72 :             avctx->sample_fmt = AV_SAMPLE_FMT_S16;
     175             :     }
     176             : 
     177         132 :     return 0;
     178             : }
     179             : 
     180     9768100 : static inline int16_t adpcm_ima_expand_nibble(ADPCMChannelStatus *c, int8_t nibble, int shift)
     181             : {
     182             :     int step_index;
     183             :     int predictor;
     184             :     int sign, delta, diff, step;
     185             : 
     186     9768100 :     step = ff_adpcm_step_table[c->step_index];
     187     9768100 :     step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble];
     188     9768100 :     step_index = av_clip(step_index, 0, 88);
     189             : 
     190     9768100 :     sign = nibble & 8;
     191     9768100 :     delta = nibble & 7;
     192             :     /* perform direct multiplication instead of series of jumps proposed by
     193             :      * the reference ADPCM implementation since modern CPUs can do the mults
     194             :      * quickly enough */
     195     9768100 :     diff = ((2 * delta + 1) * step) >> shift;
     196     9768100 :     predictor = c->predictor;
     197     9768100 :     if (sign) predictor -= diff;
     198     4930690 :     else predictor += diff;
     199             : 
     200     9768100 :     c->predictor = av_clip_int16(predictor);
     201     9768100 :     c->step_index = step_index;
     202             : 
     203     9768100 :     return (int16_t)c->predictor;
     204             : }
     205             : 
     206           0 : static inline int16_t adpcm_ima_wav_expand_nibble(ADPCMChannelStatus *c, GetBitContext *gb, int bps)
     207             : {
     208             :     int nibble, step_index, predictor, sign, delta, diff, step, shift;
     209             : 
     210           0 :     shift = bps - 1;
     211           0 :     nibble = get_bits_le(gb, bps),
     212           0 :     step = ff_adpcm_step_table[c->step_index];
     213           0 :     step_index = c->step_index + ff_adpcm_index_tables[bps - 2][nibble];
     214           0 :     step_index = av_clip(step_index, 0, 88);
     215             : 
     216           0 :     sign = nibble & (1 << shift);
     217           0 :     delta = av_mod_uintp2(nibble, shift);
     218           0 :     diff = ((2 * delta + 1) * step) >> shift;
     219           0 :     predictor = c->predictor;
     220           0 :     if (sign) predictor -= diff;
     221           0 :     else predictor += diff;
     222             : 
     223           0 :     c->predictor = av_clip_int16(predictor);
     224           0 :     c->step_index = step_index;
     225             : 
     226           0 :     return (int16_t)c->predictor;
     227             : }
     228             : 
     229     2972672 : static inline int adpcm_ima_qt_expand_nibble(ADPCMChannelStatus *c, int nibble, int shift)
     230             : {
     231             :     int step_index;
     232             :     int predictor;
     233             :     int diff, step;
     234             : 
     235     2972672 :     step = ff_adpcm_step_table[c->step_index];
     236     2972672 :     step_index = c->step_index + ff_adpcm_index_table[nibble];
     237     2972672 :     step_index = av_clip(step_index, 0, 88);
     238             : 
     239     2972672 :     diff = step >> 3;
     240     2972672 :     if (nibble & 4) diff += step;
     241     2972672 :     if (nibble & 2) diff += step >> 1;
     242     2972672 :     if (nibble & 1) diff += step >> 2;
     243             : 
     244     2972672 :     if (nibble & 8)
     245     1480232 :         predictor = c->predictor - diff;
     246             :     else
     247     1492440 :         predictor = c->predictor + diff;
     248             : 
     249     2972672 :     c->predictor = av_clip_int16(predictor);
     250     2972672 :     c->step_index = step_index;
     251             : 
     252     2972672 :     return c->predictor;
     253             : }
     254             : 
     255     2229948 : static inline int16_t adpcm_ms_expand_nibble(ADPCMChannelStatus *c, int nibble)
     256             : {
     257             :     int predictor;
     258             : 
     259     2229948 :     predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 64;
     260     2229948 :     predictor += ((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta;
     261             : 
     262     2229948 :     c->sample2 = c->sample1;
     263     2229948 :     c->sample1 = av_clip_int16(predictor);
     264     2229948 :     c->idelta = (ff_adpcm_AdaptationTable[(int)nibble] * c->idelta) >> 8;
     265     2229948 :     if (c->idelta < 16) c->idelta = 16;
     266     2229948 :     if (c->idelta > INT_MAX/768) {
     267           0 :         av_log(NULL, AV_LOG_WARNING, "idelta overflow\n");
     268           0 :         c->idelta = INT_MAX/768;
     269             :     }
     270             : 
     271     2229948 :     return c->sample1;
     272             : }
     273             : 
     274       55124 : static inline int16_t adpcm_ima_oki_expand_nibble(ADPCMChannelStatus *c, int nibble)
     275             : {
     276             :     int step_index, predictor, sign, delta, diff, step;
     277             : 
     278       55124 :     step = ff_adpcm_oki_step_table[c->step_index];
     279       55124 :     step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble];
     280       55124 :     step_index = av_clip(step_index, 0, 48);
     281             : 
     282       55124 :     sign = nibble & 8;
     283       55124 :     delta = nibble & 7;
     284       55124 :     diff = ((2 * delta + 1) * step) >> 3;
     285       55124 :     predictor = c->predictor;
     286       55124 :     if (sign) predictor -= diff;
     287       29772 :     else predictor += diff;
     288             : 
     289       55124 :     c->predictor = av_clip_intp2(predictor, 11);
     290       55124 :     c->step_index = step_index;
     291             : 
     292       55124 :     return c->predictor << 4;
     293             : }
     294             : 
     295      524192 : static inline int16_t adpcm_ct_expand_nibble(ADPCMChannelStatus *c, int8_t nibble)
     296             : {
     297             :     int sign, delta, diff;
     298             :     int new_step;
     299             : 
     300      524192 :     sign = nibble & 8;
     301      524192 :     delta = nibble & 7;
     302             :     /* perform direct multiplication instead of series of jumps proposed by
     303             :      * the reference ADPCM implementation since modern CPUs can do the mults
     304             :      * quickly enough */
     305      524192 :     diff = ((2 * delta + 1) * c->step) >> 3;
     306             :     /* predictor update is not so trivial: predictor is multiplied on 254/256 before updating */
     307      524192 :     c->predictor = ((c->predictor * 254) >> 8) + (sign ? -diff : diff);
     308      524192 :     c->predictor = av_clip_int16(c->predictor);
     309             :     /* calculate new step and clamp it to range 511..32767 */
     310      524192 :     new_step = (ff_adpcm_AdaptationTable[nibble & 7] * c->step) >> 8;
     311      524192 :     c->step = av_clip(new_step, 511, 32767);
     312             : 
     313      524192 :     return (int16_t)c->predictor;
     314             : }
     315             : 
     316      313380 : static inline int16_t adpcm_sbpro_expand_nibble(ADPCMChannelStatus *c, int8_t nibble, int size, int shift)
     317             : {
     318             :     int sign, delta, diff;
     319             : 
     320      313380 :     sign = nibble & (1<<(size-1));
     321      313380 :     delta = nibble & ((1<<(size-1))-1);
     322      313380 :     diff = delta << (7 + c->step + shift);
     323             : 
     324             :     /* clamp result */
     325      313380 :     c->predictor = av_clip(c->predictor + (sign ? -diff : diff), -16384,16256);
     326             : 
     327             :     /* calculate new step */
     328      313380 :     if (delta >= (2*size - 3) && c->step < 3)
     329       75080 :         c->step++;
     330      238300 :     else if (delta == 0 && c->step > 0)
     331       75080 :         c->step--;
     332             : 
     333      313380 :     return (int16_t) c->predictor;
     334             : }
     335             : 
     336     1105920 : static inline int16_t adpcm_yamaha_expand_nibble(ADPCMChannelStatus *c, uint8_t nibble)
     337             : {
     338     1105920 :     if(!c->step) {
     339           5 :         c->predictor = 0;
     340           5 :         c->step = 127;
     341             :     }
     342             : 
     343     1105920 :     c->predictor += (c->step * ff_adpcm_yamaha_difflookup[nibble]) / 8;
     344     1105920 :     c->predictor = av_clip_int16(c->predictor);
     345     1105920 :     c->step = (c->step * ff_adpcm_yamaha_indexscale[nibble]) >> 8;
     346     1105920 :     c->step = av_clip(c->step, 127, 24576);
     347     1105920 :     return c->predictor;
     348             : }
     349             : 
     350           0 : static inline int16_t adpcm_mtaf_expand_nibble(ADPCMChannelStatus *c, uint8_t nibble)
     351             : {
     352           0 :     c->predictor += ff_adpcm_mtaf_stepsize[c->step][nibble];
     353           0 :     c->predictor = av_clip_int16(c->predictor);
     354           0 :     c->step += ff_adpcm_index_table[nibble];
     355           0 :     c->step = av_clip_uintp2(c->step, 5);
     356           0 :     return c->predictor;
     357             : }
     358             : 
     359         666 : static int xa_decode(AVCodecContext *avctx, int16_t *out0, int16_t *out1,
     360             :                      const uint8_t *in, ADPCMChannelStatus *left,
     361             :                      ADPCMChannelStatus *right, int channels, int sample_offset)
     362             : {
     363             :     int i, j;
     364             :     int shift,filter,f0,f1;
     365             :     int s_1,s_2;
     366             :     int d,s,t;
     367             : 
     368         666 :     out0 += sample_offset;
     369         666 :     if (channels == 1)
     370           0 :         out1 = out0 + 28;
     371             :     else
     372         666 :         out1 += sample_offset;
     373             : 
     374        3330 :     for(i=0;i<4;i++) {
     375        2664 :         shift  = 12 - (in[4+i*2] & 15);
     376        2664 :         filter = in[4+i*2] >> 4;
     377        2664 :         if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table)) {
     378           0 :             avpriv_request_sample(avctx, "unknown XA-ADPCM filter %d", filter);
     379           0 :             filter=0;
     380             :         }
     381        2664 :         f0 = xa_adpcm_table[filter][0];
     382        2664 :         f1 = xa_adpcm_table[filter][1];
     383             : 
     384        2664 :         s_1 = left->sample1;
     385        2664 :         s_2 = left->sample2;
     386             : 
     387       77256 :         for(j=0;j<28;j++) {
     388       74592 :             d = in[16+i+j*4];
     389             : 
     390       74592 :             t = sign_extend(d, 4);
     391       74592 :             s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
     392       74592 :             s_2 = s_1;
     393       74592 :             s_1 = av_clip_int16(s);
     394       74592 :             out0[j] = s_1;
     395             :         }
     396             : 
     397        2664 :         if (channels == 2) {
     398        2664 :             left->sample1 = s_1;
     399        2664 :             left->sample2 = s_2;
     400        2664 :             s_1 = right->sample1;
     401        2664 :             s_2 = right->sample2;
     402             :         }
     403             : 
     404        2664 :         shift  = 12 - (in[5+i*2] & 15);
     405        2664 :         filter = in[5+i*2] >> 4;
     406        2664 :         if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table)) {
     407           0 :             avpriv_request_sample(avctx, "unknown XA-ADPCM filter %d", filter);
     408           0 :             filter=0;
     409             :         }
     410             : 
     411        2664 :         f0 = xa_adpcm_table[filter][0];
     412        2664 :         f1 = xa_adpcm_table[filter][1];
     413             : 
     414       77256 :         for(j=0;j<28;j++) {
     415       74592 :             d = in[16+i+j*4];
     416             : 
     417       74592 :             t = sign_extend(d >> 4, 4);
     418       74592 :             s = ( t<<shift ) + ((s_1*f0 + s_2*f1+32)>>6);
     419       74592 :             s_2 = s_1;
     420       74592 :             s_1 = av_clip_int16(s);
     421       74592 :             out1[j] = s_1;
     422             :         }
     423             : 
     424        2664 :         if (channels == 2) {
     425        2664 :             right->sample1 = s_1;
     426        2664 :             right->sample2 = s_2;
     427             :         } else {
     428           0 :             left->sample1 = s_1;
     429           0 :             left->sample2 = s_2;
     430             :         }
     431             : 
     432        2664 :         out0 += 28 * (3 - channels);
     433        2664 :         out1 += 28 * (3 - channels);
     434             :     }
     435             : 
     436         666 :     return 0;
     437             : }
     438             : 
     439         260 : static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_size, int16_t *samples)
     440             : {
     441         260 :     ADPCMDecodeContext *c = avctx->priv_data;
     442             :     GetBitContext gb;
     443             :     const int *table;
     444             :     int k0, signmask, nb_bits, count;
     445         260 :     int size = buf_size*8;
     446             :     int i;
     447             : 
     448         260 :     init_get_bits(&gb, buf, size);
     449             : 
     450             :     //read bits & initial values
     451         260 :     nb_bits = get_bits(&gb, 2)+2;
     452         260 :     table = swf_index_tables[nb_bits-2];
     453         260 :     k0 = 1 << (nb_bits-2);
     454         260 :     signmask = 1 << (nb_bits-1);
     455             : 
     456         780 :     while (get_bits_count(&gb) <= size - 22*avctx->channels) {
     457         780 :         for (i = 0; i < avctx->channels; i++) {
     458         520 :             *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
     459         520 :             c->status[i].step_index = get_bits(&gb, 6);
     460             :         }
     461             : 
     462      532480 :         for (count = 0; get_bits_count(&gb) <= size - nb_bits*avctx->channels && count < 4095; count++) {
     463             :             int i;
     464             : 
     465     1596660 :             for (i = 0; i < avctx->channels; i++) {
     466             :                 // similar to IMA adpcm
     467     1064440 :                 int delta = get_bits(&gb, nb_bits);
     468     1064440 :                 int step = ff_adpcm_step_table[c->status[i].step_index];
     469     1064440 :                 int vpdiff = 0; // vpdiff = (delta+0.5)*step/4
     470     1064440 :                 int k = k0;
     471             : 
     472             :                 do {
     473     3193320 :                     if (delta & k)
     474     1328304 :                         vpdiff += step;
     475     3193320 :                     step >>= 1;
     476     3193320 :                     k >>= 1;
     477     3193320 :                 } while(k);
     478     1064440 :                 vpdiff += step;
     479             : 
     480     1064440 :                 if (delta & signmask)
     481      535145 :                     c->status[i].predictor -= vpdiff;
     482             :                 else
     483      529295 :                     c->status[i].predictor += vpdiff;
     484             : 
     485     1064440 :                 c->status[i].step_index += table[delta & (~signmask)];
     486             : 
     487     1064440 :                 c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88);
     488     1064440 :                 c->status[i].predictor = av_clip_int16(c->status[i].predictor);
     489             : 
     490     1064440 :                 *samples++ = c->status[i].predictor;
     491             :             }
     492             :         }
     493             :     }
     494         260 : }
     495             : 
     496             : /**
     497             :  * Get the number of samples that will be decoded from the packet.
     498             :  * In one case, this is actually the maximum number of samples possible to
     499             :  * decode with the given buf_size.
     500             :  *
     501             :  * @param[out] coded_samples set to the number of samples as coded in the
     502             :  *                           packet, or 0 if the codec does not encode the
     503             :  *                           number of samples in each frame.
     504             :  * @param[out] approx_nb_samples set to non-zero if the number of samples
     505             :  *                               returned is an approximation.
     506             :  */
     507       36079 : static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb,
     508             :                           int buf_size, int *coded_samples, int *approx_nb_samples)
     509             : {
     510       36079 :     ADPCMDecodeContext *s = avctx->priv_data;
     511       36079 :     int nb_samples        = 0;
     512       36079 :     int ch                = avctx->channels;
     513       36079 :     int has_coded_samples = 0;
     514             :     int header_size;
     515             : 
     516       36079 :     *coded_samples = 0;
     517       36079 :     *approx_nb_samples = 0;
     518             : 
     519       36079 :     if(ch <= 0)
     520           0 :         return 0;
     521             : 
     522       36079 :     switch (avctx->codec->id) {
     523             :     /* constant, only check buf_size */
     524         600 :     case AV_CODEC_ID_ADPCM_EA_XAS:
     525         600 :         if (buf_size < 76 * ch)
     526           0 :             return 0;
     527         600 :         nb_samples = 128;
     528         600 :         break;
     529       26342 :     case AV_CODEC_ID_ADPCM_IMA_QT:
     530       26342 :         if (buf_size < 34 * ch)
     531           0 :             return 0;
     532       26342 :         nb_samples = 64;
     533       26342 :         break;
     534             :     /* simple 4-bit adpcm */
     535         475 :     case AV_CODEC_ID_ADPCM_CT:
     536             :     case AV_CODEC_ID_ADPCM_IMA_APC:
     537             :     case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
     538             :     case AV_CODEC_ID_ADPCM_IMA_OKI:
     539             :     case AV_CODEC_ID_ADPCM_IMA_WS:
     540             :     case AV_CODEC_ID_ADPCM_YAMAHA:
     541             :     case AV_CODEC_ID_ADPCM_AICA:
     542         475 :         nb_samples = buf_size * 2 / ch;
     543         475 :         break;
     544             :     }
     545       36079 :     if (nb_samples)
     546       27417 :         return nb_samples;
     547             : 
     548             :     /* simple 4-bit adpcm, with header */
     549        8662 :     header_size = 0;
     550        8662 :     switch (avctx->codec->id) {
     551         145 :         case AV_CODEC_ID_ADPCM_4XM:
     552             :         case AV_CODEC_ID_ADPCM_IMA_DAT4:
     553         145 :         case AV_CODEC_ID_ADPCM_IMA_ISS:     header_size = 4 * ch;      break;
     554         161 :         case AV_CODEC_ID_ADPCM_IMA_AMV:     header_size = 8;           break;
     555         350 :         case AV_CODEC_ID_ADPCM_IMA_SMJPEG:  header_size = 4 * ch;      break;
     556             :     }
     557        8662 :     if (header_size > 0)
     558         656 :         return (buf_size - header_size) * 2 / ch;
     559             : 
     560             :     /* more complex formats */
     561        8006 :     switch (avctx->codec->id) {
     562         158 :     case AV_CODEC_ID_ADPCM_EA:
     563         158 :         has_coded_samples = 1;
     564         158 :         *coded_samples  = bytestream2_get_le32(gb);
     565         158 :         *coded_samples -= *coded_samples % 28;
     566         158 :         nb_samples      = (buf_size - 12) / 30 * 28;
     567         158 :         break;
     568          47 :     case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
     569          47 :         has_coded_samples = 1;
     570          47 :         *coded_samples = bytestream2_get_le32(gb);
     571          47 :         nb_samples     = (buf_size - (4 + 8 * ch)) * 2 / ch;
     572          47 :         break;
     573          30 :     case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
     574          30 :         nb_samples = (buf_size - ch) / ch * 2;
     575          30 :         break;
     576         400 :     case AV_CODEC_ID_ADPCM_EA_R1:
     577             :     case AV_CODEC_ID_ADPCM_EA_R2:
     578             :     case AV_CODEC_ID_ADPCM_EA_R3:
     579             :         /* maximum number of samples */
     580             :         /* has internal offsets and a per-frame switch to signal raw 16-bit */
     581         400 :         has_coded_samples = 1;
     582         400 :         switch (avctx->codec->id) {
     583          95 :         case AV_CODEC_ID_ADPCM_EA_R1:
     584          95 :             header_size    = 4 + 9 * ch;
     585          95 :             *coded_samples = bytestream2_get_le32(gb);
     586          95 :             break;
     587         180 :         case AV_CODEC_ID_ADPCM_EA_R2:
     588         180 :             header_size    = 4 + 5 * ch;
     589         180 :             *coded_samples = bytestream2_get_le32(gb);
     590         180 :             break;
     591         125 :         case AV_CODEC_ID_ADPCM_EA_R3:
     592         125 :             header_size    = 4 + 5 * ch;
     593         125 :             *coded_samples = bytestream2_get_be32(gb);
     594         125 :             break;
     595             :         }
     596         400 :         *coded_samples -= *coded_samples % 28;
     597         400 :         nb_samples      = (buf_size - header_size) * 2 / ch;
     598         400 :         nb_samples     -= nb_samples % 28;
     599         400 :         *approx_nb_samples = 1;
     600         400 :         break;
     601         642 :     case AV_CODEC_ID_ADPCM_IMA_DK3:
     602         642 :         if (avctx->block_align > 0)
     603         642 :             buf_size = FFMIN(buf_size, avctx->block_align);
     604         642 :         nb_samples = ((buf_size - 16) * 2 / 3 * 4) / ch;
     605         642 :         break;
     606         649 :     case AV_CODEC_ID_ADPCM_IMA_DK4:
     607         649 :         if (avctx->block_align > 0)
     608         649 :             buf_size = FFMIN(buf_size, avctx->block_align);
     609         649 :         if (buf_size < 4 * ch)
     610           0 :             return AVERROR_INVALIDDATA;
     611         649 :         nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch;
     612         649 :         break;
     613        1000 :     case AV_CODEC_ID_ADPCM_IMA_RAD:
     614        1000 :         if (avctx->block_align > 0)
     615        1000 :             buf_size = FFMIN(buf_size, avctx->block_align);
     616        1000 :         nb_samples = (buf_size - 4 * ch) * 2 / ch;
     617        1000 :         break;
     618        1668 :     case AV_CODEC_ID_ADPCM_IMA_WAV:
     619             :     {
     620        1668 :         int bsize = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
     621        1668 :         int bsamples = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
     622        1668 :         if (avctx->block_align > 0)
     623        1668 :             buf_size = FFMIN(buf_size, avctx->block_align);
     624        1668 :         if (buf_size < 4 * ch)
     625           0 :             return AVERROR_INVALIDDATA;
     626        1668 :         nb_samples = 1 + (buf_size - 4 * ch) / (bsize * ch) * bsamples;
     627        1668 :         break;
     628             :     }
     629        2943 :     case AV_CODEC_ID_ADPCM_MS:
     630        2943 :         if (avctx->block_align > 0)
     631        2943 :             buf_size = FFMIN(buf_size, avctx->block_align);
     632        2943 :         nb_samples = (buf_size - 6 * ch) * 2 / ch;
     633        2943 :         break;
     634           0 :     case AV_CODEC_ID_ADPCM_MTAF:
     635           0 :         if (avctx->block_align > 0)
     636           0 :             buf_size = FFMIN(buf_size, avctx->block_align);
     637           0 :         nb_samples = (buf_size - 16 * (ch / 2)) * 2 / ch;
     638           0 :         break;
     639          57 :     case AV_CODEC_ID_ADPCM_SBPRO_2:
     640             :     case AV_CODEC_ID_ADPCM_SBPRO_3:
     641             :     case AV_CODEC_ID_ADPCM_SBPRO_4:
     642             :     {
     643             :         int samples_per_byte;
     644          57 :         switch (avctx->codec->id) {
     645          13 :         case AV_CODEC_ID_ADPCM_SBPRO_2: samples_per_byte = 4; break;
     646          18 :         case AV_CODEC_ID_ADPCM_SBPRO_3: samples_per_byte = 3; break;
     647          26 :         case AV_CODEC_ID_ADPCM_SBPRO_4: samples_per_byte = 2; break;
     648             :         }
     649          57 :         if (!s->status[0].step_index) {
     650           3 :             if (buf_size < ch)
     651           0 :                 return AVERROR_INVALIDDATA;
     652           3 :             nb_samples++;
     653           3 :             buf_size -= ch;
     654             :         }
     655          57 :         nb_samples += buf_size * samples_per_byte / ch;
     656          57 :         break;
     657             :     }
     658         260 :     case AV_CODEC_ID_ADPCM_SWF:
     659             :     {
     660         260 :         int buf_bits       = buf_size * 8 - 2;
     661         260 :         int nbits          = (bytestream2_get_byte(gb) >> 6) + 2;
     662         260 :         int block_hdr_size = 22 * ch;
     663         260 :         int block_size     = block_hdr_size + nbits * ch * 4095;
     664         260 :         int nblocks        = buf_bits / block_size;
     665         260 :         int bits_left      = buf_bits - nblocks * block_size;
     666         260 :         nb_samples         = nblocks * 4096;
     667         260 :         if (bits_left >= block_hdr_size)
     668         260 :             nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch);
     669         260 :         break;
     670             :     }
     671          71 :     case AV_CODEC_ID_ADPCM_THP:
     672             :     case AV_CODEC_ID_ADPCM_THP_LE:
     673          71 :         if (avctx->extradata) {
     674           0 :             nb_samples = buf_size * 14 / (8 * ch);
     675           0 :             break;
     676             :         }
     677          71 :         has_coded_samples = 1;
     678          71 :         bytestream2_skip(gb, 4); // channel size
     679         142 :         *coded_samples  = (avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE) ?
     680         142 :                           bytestream2_get_le32(gb) :
     681          71 :                           bytestream2_get_be32(gb);
     682          71 :         buf_size       -= 8 + 36 * ch;
     683          71 :         buf_size       /= ch;
     684          71 :         nb_samples      = buf_size / 8 * 14;
     685          71 :         if (buf_size % 8 > 1)
     686           0 :             nb_samples     += (buf_size % 8 - 1) * 2;
     687          71 :         *approx_nb_samples = 1;
     688          71 :         break;
     689          12 :     case AV_CODEC_ID_ADPCM_AFC:
     690          12 :         nb_samples = buf_size / (9 * ch) * 16;
     691          12 :         break;
     692          37 :     case AV_CODEC_ID_ADPCM_XA:
     693          37 :         nb_samples = (buf_size / 128) * 224 / ch;
     694          37 :         break;
     695          32 :     case AV_CODEC_ID_ADPCM_DTK:
     696             :     case AV_CODEC_ID_ADPCM_PSX:
     697          32 :         nb_samples = buf_size / (16 * ch) * 28;
     698          32 :         break;
     699             :     }
     700             : 
     701             :     /* validate coded sample count */
     702        8006 :     if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples))
     703           0 :         return AVERROR_INVALIDDATA;
     704             : 
     705        8006 :     return nb_samples;
     706             : }
     707             : 
     708       36079 : static int adpcm_decode_frame(AVCodecContext *avctx, void *data,
     709             :                               int *got_frame_ptr, AVPacket *avpkt)
     710             : {
     711       36079 :     AVFrame *frame     = data;
     712       36079 :     const uint8_t *buf = avpkt->data;
     713       36079 :     int buf_size = avpkt->size;
     714       36079 :     ADPCMDecodeContext *c = avctx->priv_data;
     715             :     ADPCMChannelStatus *cs;
     716             :     int n, m, channel, i;
     717             :     int16_t *samples;
     718             :     int16_t **samples_p;
     719             :     int st; /* stereo */
     720             :     int count1, count2;
     721             :     int nb_samples, coded_samples, approx_nb_samples, ret;
     722             :     GetByteContext gb;
     723             : 
     724       36079 :     bytestream2_init(&gb, buf, buf_size);
     725       36079 :     nb_samples = get_nb_samples(avctx, &gb, buf_size, &coded_samples, &approx_nb_samples);
     726       36079 :     if (nb_samples <= 0) {
     727           0 :         av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n");
     728           0 :         return AVERROR_INVALIDDATA;
     729             :     }
     730             : 
     731             :     /* get output buffer */
     732       36079 :     frame->nb_samples = nb_samples;
     733       36079 :     if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
     734           0 :         return ret;
     735       36079 :     samples = (int16_t *)frame->data[0];
     736       36079 :     samples_p = (int16_t **)frame->extended_data;
     737             : 
     738             :     /* use coded_samples when applicable */
     739             :     /* it is always <= nb_samples, so the output buffer will be large enough */
     740       36079 :     if (coded_samples) {
     741         676 :         if (!approx_nb_samples && coded_samples != nb_samples)
     742           0 :             av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n");
     743         676 :         frame->nb_samples = nb_samples = coded_samples;
     744             :     }
     745             : 
     746       36079 :     st = avctx->channels == 2 ? 1 : 0;
     747             : 
     748       36079 :     switch(avctx->codec->id) {
     749       26342 :     case AV_CODEC_ID_ADPCM_IMA_QT:
     750             :         /* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples).
     751             :            Channel data is interleaved per-chunk. */
     752       69990 :         for (channel = 0; channel < avctx->channels; channel++) {
     753             :             int predictor;
     754             :             int step_index;
     755       43648 :             cs = &(c->status[channel]);
     756             :             /* (pppppp) (piiiiiii) */
     757             : 
     758             :             /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */
     759       43648 :             predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
     760       43648 :             step_index = predictor & 0x7F;
     761       43648 :             predictor &= ~0x7F;
     762             : 
     763       43648 :             if (cs->step_index == step_index) {
     764       43648 :                 int diff = predictor - cs->predictor;
     765       43648 :                 if (diff < 0)
     766       39464 :                     diff = - diff;
     767       43648 :                 if (diff > 0x7f)
     768          30 :                     goto update;
     769             :             } else {
     770           0 :             update:
     771          30 :                 cs->step_index = step_index;
     772          30 :                 cs->predictor = predictor;
     773             :             }
     774             : 
     775       43648 :             if (cs->step_index > 88u){
     776           0 :                 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
     777           0 :                        channel, cs->step_index);
     778           0 :                 return AVERROR_INVALIDDATA;
     779             :             }
     780             : 
     781       43648 :             samples = samples_p[channel];
     782             : 
     783     1440384 :             for (m = 0; m < 64; m += 2) {
     784     1396736 :                 int byte = bytestream2_get_byteu(&gb);
     785     1396736 :                 samples[m    ] = adpcm_ima_qt_expand_nibble(cs, byte & 0x0F, 3);
     786     1396736 :                 samples[m + 1] = adpcm_ima_qt_expand_nibble(cs, byte >> 4  , 3);
     787             :             }
     788             :         }
     789       26342 :         break;
     790        1668 :     case AV_CODEC_ID_ADPCM_IMA_WAV:
     791        5004 :         for(i=0; i<avctx->channels; i++){
     792        3336 :             cs = &(c->status[i]);
     793        3336 :             cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16);
     794             : 
     795        3336 :             cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
     796        3336 :             if (cs->step_index > 88u){
     797           0 :                 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
     798           0 :                        i, cs->step_index);
     799           0 :                 return AVERROR_INVALIDDATA;
     800             :             }
     801             :         }
     802             : 
     803        1668 :         if (avctx->bits_per_coded_sample != 4) {
     804           0 :             int samples_per_block = ff_adpcm_ima_block_samples[avctx->bits_per_coded_sample - 2];
     805           0 :             int block_size = ff_adpcm_ima_block_sizes[avctx->bits_per_coded_sample - 2];
     806           0 :             uint8_t temp[20 + AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
     807             :             GetBitContext g;
     808             : 
     809           0 :             for (n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
     810           0 :                 for (i = 0; i < avctx->channels; i++) {
     811             :                     int j;
     812             : 
     813           0 :                     cs = &c->status[i];
     814           0 :                     samples = &samples_p[i][1 + n * samples_per_block];
     815           0 :                     for (j = 0; j < block_size; j++) {
     816           0 :                         temp[j] = buf[4 * avctx->channels + block_size * n * avctx->channels +
     817           0 :                                         (j % 4) + (j / 4) * (avctx->channels * 4) + i * 4];
     818             :                     }
     819           0 :                     ret = init_get_bits8(&g, (const uint8_t *)&temp, block_size);
     820           0 :                     if (ret < 0)
     821           0 :                         return ret;
     822           0 :                     for (m = 0; m < samples_per_block; m++) {
     823           0 :                         samples[m] = adpcm_ima_wav_expand_nibble(cs, &g,
     824             :                                           avctx->bits_per_coded_sample);
     825             :                     }
     826             :                 }
     827             :             }
     828           0 :             bytestream2_skip(&gb, avctx->block_align - avctx->channels * 4);
     829             :         } else {
     830      140160 :         for (n = 0; n < (nb_samples - 1) / 8; n++) {
     831      415476 :             for (i = 0; i < avctx->channels; i++) {
     832      276984 :                 cs = &c->status[i];
     833      276984 :                 samples = &samples_p[i][1 + n * 8];
     834     1384920 :                 for (m = 0; m < 8; m += 2) {
     835     1107936 :                     int v = bytestream2_get_byteu(&gb);
     836     1107936 :                     samples[m    ] = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
     837     1107936 :                     samples[m + 1] = adpcm_ima_expand_nibble(cs, v >> 4  , 3);
     838             :                 }
     839             :             }
     840             :         }
     841             :         }
     842        1668 :         break;
     843          26 :     case AV_CODEC_ID_ADPCM_4XM:
     844          78 :         for (i = 0; i < avctx->channels; i++)
     845          52 :             c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
     846             : 
     847          78 :         for (i = 0; i < avctx->channels; i++) {
     848          52 :             c->status[i].step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
     849          52 :             if (c->status[i].step_index > 88u) {
     850           0 :                 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
     851           0 :                        i, c->status[i].step_index);
     852           0 :                 return AVERROR_INVALIDDATA;
     853             :             }
     854             :         }
     855             : 
     856          78 :         for (i = 0; i < avctx->channels; i++) {
     857          52 :             samples = (int16_t *)frame->data[i];
     858          52 :             cs = &c->status[i];
     859       38276 :             for (n = nb_samples >> 1; n > 0; n--) {
     860       38224 :                 int v = bytestream2_get_byteu(&gb);
     861       38224 :                 *samples++ = adpcm_ima_expand_nibble(cs, v & 0x0F, 4);
     862       38224 :                 *samples++ = adpcm_ima_expand_nibble(cs, v >> 4  , 4);
     863             :             }
     864             :         }
     865          26 :         break;
     866        2943 :     case AV_CODEC_ID_ADPCM_MS:
     867             :     {
     868             :         int block_predictor;
     869             : 
     870        2943 :         block_predictor = bytestream2_get_byteu(&gb);
     871        2943 :         if (block_predictor > 6) {
     872           0 :             av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[0] = %d\n",
     873             :                    block_predictor);
     874           0 :             return AVERROR_INVALIDDATA;
     875             :         }
     876        2943 :         c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
     877        2943 :         c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
     878        2943 :         if (st) {
     879        2895 :             block_predictor = bytestream2_get_byteu(&gb);
     880        2895 :             if (block_predictor > 6) {
     881           0 :                 av_log(avctx, AV_LOG_ERROR, "ERROR: block_predictor[1] = %d\n",
     882             :                        block_predictor);
     883           0 :                 return AVERROR_INVALIDDATA;
     884             :             }
     885        2895 :             c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor];
     886        2895 :             c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor];
     887             :         }
     888        2943 :         c->status[0].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
     889        2943 :         if (st){
     890        2895 :             c->status[1].idelta = sign_extend(bytestream2_get_le16u(&gb), 16);
     891             :         }
     892             : 
     893        2943 :         c->status[0].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
     894        2943 :         if (st) c->status[1].sample1 = sign_extend(bytestream2_get_le16u(&gb), 16);
     895        2943 :         c->status[0].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
     896        2943 :         if (st) c->status[1].sample2 = sign_extend(bytestream2_get_le16u(&gb), 16);
     897             : 
     898        2943 :         *samples++ = c->status[0].sample2;
     899        2943 :         if (st) *samples++ = c->status[1].sample2;
     900        2943 :         *samples++ = c->status[0].sample1;
     901        2943 :         if (st) *samples++ = c->status[1].sample1;
     902     1117917 :         for(n = (nb_samples - 2) >> (1 - st); n > 0; n--) {
     903     1114974 :             int byte = bytestream2_get_byteu(&gb);
     904     1114974 :             *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], byte >> 4  );
     905     1114974 :             *samples++ = adpcm_ms_expand_nibble(&c->status[st], byte & 0x0F);
     906             :         }
     907        2943 :         break;
     908             :     }
     909           0 :     case AV_CODEC_ID_ADPCM_MTAF:
     910           0 :         for (channel = 0; channel < avctx->channels; channel+=2) {
     911           0 :             bytestream2_skipu(&gb, 4);
     912           0 :             c->status[channel    ].step      = bytestream2_get_le16u(&gb) & 0x1f;
     913           0 :             c->status[channel + 1].step      = bytestream2_get_le16u(&gb) & 0x1f;
     914           0 :             c->status[channel    ].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
     915           0 :             bytestream2_skipu(&gb, 2);
     916           0 :             c->status[channel + 1].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
     917           0 :             bytestream2_skipu(&gb, 2);
     918           0 :             for (n = 0; n < nb_samples; n+=2) {
     919           0 :                 int v = bytestream2_get_byteu(&gb);
     920           0 :                 samples_p[channel][n    ] = adpcm_mtaf_expand_nibble(&c->status[channel], v & 0x0F);
     921           0 :                 samples_p[channel][n + 1] = adpcm_mtaf_expand_nibble(&c->status[channel], v >> 4  );
     922             :             }
     923           0 :             for (n = 0; n < nb_samples; n+=2) {
     924           0 :                 int v = bytestream2_get_byteu(&gb);
     925           0 :                 samples_p[channel + 1][n    ] = adpcm_mtaf_expand_nibble(&c->status[channel + 1], v & 0x0F);
     926           0 :                 samples_p[channel + 1][n + 1] = adpcm_mtaf_expand_nibble(&c->status[channel + 1], v >> 4  );
     927             :             }
     928             :         }
     929           0 :         break;
     930         649 :     case AV_CODEC_ID_ADPCM_IMA_DK4:
     931        1947 :         for (channel = 0; channel < avctx->channels; channel++) {
     932        1298 :             cs = &c->status[channel];
     933        1298 :             cs->predictor  = *samples++ = sign_extend(bytestream2_get_le16u(&gb), 16);
     934        1298 :             cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
     935        1298 :             if (cs->step_index > 88u){
     936           0 :                 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
     937           0 :                        channel, cs->step_index);
     938           0 :                 return AVERROR_INVALIDDATA;
     939             :             }
     940             :         }
     941     1324609 :         for (n = (nb_samples - 1) >> (1 - st); n > 0; n--) {
     942     1323960 :             int v = bytestream2_get_byteu(&gb);
     943     1323960 :             *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4  , 3);
     944     1323960 :             *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
     945             :         }
     946         649 :         break;
     947         642 :     case AV_CODEC_ID_ADPCM_IMA_DK3:
     948             :     {
     949         642 :         int last_byte = 0;
     950             :         int nibble;
     951         642 :         int decode_top_nibble_next = 0;
     952             :         int diff_channel;
     953         642 :         const int16_t *samples_end = samples + avctx->channels * nb_samples;
     954             : 
     955         642 :         bytestream2_skipu(&gb, 10);
     956         642 :         c->status[0].predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);
     957         642 :         c->status[1].predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);
     958         642 :         c->status[0].step_index = bytestream2_get_byteu(&gb);
     959         642 :         c->status[1].step_index = bytestream2_get_byteu(&gb);
     960         642 :         if (c->status[0].step_index > 88u || c->status[1].step_index > 88u){
     961           0 :             av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i/%i\n",
     962           0 :                    c->status[0].step_index, c->status[1].step_index);
     963           0 :             return AVERROR_INVALIDDATA;
     964             :         }
     965             :         /* sign extend the predictors */
     966         642 :         diff_channel = c->status[1].predictor;
     967             : 
     968             :         /* DK3 ADPCM support macro */
     969             : #define DK3_GET_NEXT_NIBBLE() \
     970             :     if (decode_top_nibble_next) { \
     971             :         nibble = last_byte >> 4; \
     972             :         decode_top_nibble_next = 0; \
     973             :     } else { \
     974             :         last_byte = bytestream2_get_byteu(&gb); \
     975             :         nibble = last_byte & 0x0F; \
     976             :         decode_top_nibble_next = 1; \
     977             :     }
     978             : 
     979      870552 :         while (samples < samples_end) {
     980             : 
     981             :             /* for this algorithm, c->status[0] is the sum channel and
     982             :              * c->status[1] is the diff channel */
     983             : 
     984             :             /* process the first predictor of the sum channel */
     985      869268 :             DK3_GET_NEXT_NIBBLE();
     986      869268 :             adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
     987             : 
     988             :             /* process the diff channel predictor */
     989      869268 :             DK3_GET_NEXT_NIBBLE();
     990      869268 :             adpcm_ima_expand_nibble(&c->status[1], nibble, 3);
     991             : 
     992             :             /* process the first pair of stereo PCM samples */
     993      869268 :             diff_channel = (diff_channel + c->status[1].predictor) / 2;
     994      869268 :             *samples++ = c->status[0].predictor + c->status[1].predictor;
     995      869268 :             *samples++ = c->status[0].predictor - c->status[1].predictor;
     996             : 
     997             :             /* process the second predictor of the sum channel */
     998      869268 :             DK3_GET_NEXT_NIBBLE();
     999      869268 :             adpcm_ima_expand_nibble(&c->status[0], nibble, 3);
    1000             : 
    1001             :             /* process the second pair of stereo PCM samples */
    1002      869268 :             diff_channel = (diff_channel + c->status[1].predictor) / 2;
    1003      869268 :             *samples++ = c->status[0].predictor + c->status[1].predictor;
    1004      869268 :             *samples++ = c->status[0].predictor - c->status[1].predictor;
    1005             :         }
    1006             : 
    1007         642 :         if ((bytestream2_tell(&gb) & 1))
    1008         642 :             bytestream2_skip(&gb, 1);
    1009         642 :         break;
    1010             :     }
    1011         119 :     case AV_CODEC_ID_ADPCM_IMA_ISS:
    1012         238 :         for (channel = 0; channel < avctx->channels; channel++) {
    1013         119 :             cs = &c->status[channel];
    1014         119 :             cs->predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);
    1015         119 :             cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
    1016         119 :             if (cs->step_index > 88u){
    1017           0 :                 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
    1018           0 :                        channel, cs->step_index);
    1019           0 :                 return AVERROR_INVALIDDATA;
    1020             :             }
    1021             :         }
    1022             : 
    1023       60571 :         for (n = nb_samples >> (1 - st); n > 0; n--) {
    1024             :             int v1, v2;
    1025       60452 :             int v = bytestream2_get_byteu(&gb);
    1026             :             /* nibbles are swapped for mono */
    1027       60452 :             if (st) {
    1028           0 :                 v1 = v >> 4;
    1029           0 :                 v2 = v & 0x0F;
    1030             :             } else {
    1031       60452 :                 v2 = v >> 4;
    1032       60452 :                 v1 = v & 0x0F;
    1033             :             }
    1034       60452 :             *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3);
    1035       60452 :             *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3);
    1036             :         }
    1037         119 :         break;
    1038           0 :     case AV_CODEC_ID_ADPCM_IMA_DAT4:
    1039           0 :         for (channel = 0; channel < avctx->channels; channel++) {
    1040           0 :             cs = &c->status[channel];
    1041           0 :             samples = samples_p[channel];
    1042           0 :             bytestream2_skip(&gb, 4);
    1043           0 :             for (n = 0; n < nb_samples; n += 2) {
    1044           0 :                 int v = bytestream2_get_byteu(&gb);
    1045           0 :                 *samples++ = adpcm_ima_expand_nibble(cs, v >> 4  , 3);
    1046           0 :                 *samples++ = adpcm_ima_expand_nibble(cs, v & 0x0F, 3);
    1047             :             }
    1048             :         }
    1049           0 :         break;
    1050         179 :     case AV_CODEC_ID_ADPCM_IMA_APC:
    1051      732418 :         while (bytestream2_get_bytes_left(&gb) > 0) {
    1052      732060 :             int v = bytestream2_get_byteu(&gb);
    1053      732060 :             *samples++ = adpcm_ima_expand_nibble(&c->status[0],  v >> 4  , 3);
    1054      732060 :             *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3);
    1055             :         }
    1056         179 :         break;
    1057           7 :     case AV_CODEC_ID_ADPCM_IMA_OKI:
    1058       27576 :         while (bytestream2_get_bytes_left(&gb) > 0) {
    1059       27562 :             int v = bytestream2_get_byteu(&gb);
    1060       27562 :             *samples++ = adpcm_ima_oki_expand_nibble(&c->status[0],  v >> 4  );
    1061       27562 :             *samples++ = adpcm_ima_oki_expand_nibble(&c->status[st], v & 0x0F);
    1062             :         }
    1063           7 :         break;
    1064        1000 :     case AV_CODEC_ID_ADPCM_IMA_RAD:
    1065        3000 :         for (channel = 0; channel < avctx->channels; channel++) {
    1066        2000 :             cs = &c->status[channel];
    1067        2000 :             cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
    1068        2000 :             cs->predictor  = sign_extend(bytestream2_get_le16u(&gb), 16);
    1069        2000 :             if (cs->step_index > 88u){
    1070           0 :                 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
    1071           0 :                        channel, cs->step_index);
    1072           0 :                 return AVERROR_INVALIDDATA;
    1073             :             }
    1074             :         }
    1075       17000 :         for (n = 0; n < nb_samples / 2; n++) {
    1076             :             int byte[2];
    1077             : 
    1078       16000 :             byte[0] = bytestream2_get_byteu(&gb);
    1079       16000 :             if (st)
    1080       16000 :                 byte[1] = bytestream2_get_byteu(&gb);
    1081       48000 :             for(channel = 0; channel < avctx->channels; channel++) {
    1082       32000 :                 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] & 0x0F, 3);
    1083             :             }
    1084       48000 :             for(channel = 0; channel < avctx->channels; channel++) {
    1085       32000 :                 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] >> 4  , 3);
    1086             :             }
    1087             :         }
    1088        1000 :         break;
    1089          40 :     case AV_CODEC_ID_ADPCM_IMA_WS:
    1090          40 :         if (c->vqa_version == 3) {
    1091           0 :             for (channel = 0; channel < avctx->channels; channel++) {
    1092           0 :                 int16_t *smp = samples_p[channel];
    1093             : 
    1094           0 :                 for (n = nb_samples / 2; n > 0; n--) {
    1095           0 :                     int v = bytestream2_get_byteu(&gb);
    1096           0 :                     *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v >> 4  , 3);
    1097           0 :                     *smp++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
    1098             :                 }
    1099             :             }
    1100             :         } else {
    1101       34217 :             for (n = nb_samples / 2; n > 0; n--) {
    1102       68354 :                 for (channel = 0; channel < avctx->channels; channel++) {
    1103       34177 :                     int v = bytestream2_get_byteu(&gb);
    1104       34177 :                     *samples++  = adpcm_ima_expand_nibble(&c->status[channel], v >> 4  , 3);
    1105       34177 :                     samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
    1106             :                 }
    1107       34177 :                 samples += avctx->channels;
    1108             :             }
    1109             :         }
    1110          40 :         bytestream2_seek(&gb, 0, SEEK_END);
    1111          40 :         break;
    1112          37 :     case AV_CODEC_ID_ADPCM_XA:
    1113             :     {
    1114          37 :         int16_t *out0 = samples_p[0];
    1115          37 :         int16_t *out1 = samples_p[1];
    1116          37 :         int samples_per_block = 28 * (3 - avctx->channels) * 4;
    1117          37 :         int sample_offset = 0;
    1118         740 :         while (bytestream2_get_bytes_left(&gb) >= 128) {
    1119         666 :             if ((ret = xa_decode(avctx, out0, out1, buf + bytestream2_tell(&gb),
    1120             :                                  &c->status[0], &c->status[1],
    1121             :                                  avctx->channels, sample_offset)) < 0)
    1122           0 :                 return ret;
    1123         666 :             bytestream2_skipu(&gb, 128);
    1124         666 :             sample_offset += samples_per_block;
    1125             :         }
    1126          37 :         break;
    1127             :     }
    1128          47 :     case AV_CODEC_ID_ADPCM_IMA_EA_EACS:
    1129         141 :         for (i=0; i<=st; i++) {
    1130          94 :             c->status[i].step_index = bytestream2_get_le32u(&gb);
    1131          94 :             if (c->status[i].step_index > 88u) {
    1132           0 :                 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
    1133           0 :                        i, c->status[i].step_index);
    1134           0 :                 return AVERROR_INVALIDDATA;
    1135             :             }
    1136             :         }
    1137         141 :         for (i=0; i<=st; i++)
    1138          94 :             c->status[i].predictor  = bytestream2_get_le32u(&gb);
    1139             : 
    1140       69043 :         for (n = nb_samples >> (1 - st); n > 0; n--) {
    1141       68996 :             int byte   = bytestream2_get_byteu(&gb);
    1142       68996 :             *samples++ = adpcm_ima_expand_nibble(&c->status[0],  byte >> 4,   3);
    1143       68996 :             *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 3);
    1144             :         }
    1145          47 :         break;
    1146          49 :     case AV_CODEC_ID_ADPCM_IMA_EA_SEAD:
    1147       71441 :         for (n = nb_samples >> (1 - st); n > 0; n--) {
    1148       71392 :             int byte = bytestream2_get_byteu(&gb);
    1149       71392 :             *samples++ = adpcm_ima_expand_nibble(&c->status[0],  byte >> 4,   6);
    1150       71392 :             *samples++ = adpcm_ima_expand_nibble(&c->status[st], byte & 0x0F, 6);
    1151             :         }
    1152          49 :         break;
    1153         158 :     case AV_CODEC_ID_ADPCM_EA:
    1154             :     {
    1155             :         int previous_left_sample, previous_right_sample;
    1156             :         int current_left_sample, current_right_sample;
    1157             :         int next_left_sample, next_right_sample;
    1158             :         int coeff1l, coeff2l, coeff1r, coeff2r;
    1159             :         int shift_left, shift_right;
    1160             : 
    1161             :         /* Each EA ADPCM frame has a 12-byte header followed by 30-byte pieces,
    1162             :            each coding 28 stereo samples. */
    1163             : 
    1164         158 :         if(avctx->channels != 2)
    1165           0 :             return AVERROR_INVALIDDATA;
    1166             : 
    1167         158 :         current_left_sample   = sign_extend(bytestream2_get_le16u(&gb), 16);
    1168         158 :         previous_left_sample  = sign_extend(bytestream2_get_le16u(&gb), 16);
    1169         158 :         current_right_sample  = sign_extend(bytestream2_get_le16u(&gb), 16);
    1170         158 :         previous_right_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
    1171             : 
    1172        8454 :         for (count1 = 0; count1 < nb_samples / 28; count1++) {
    1173        8296 :             int byte = bytestream2_get_byteu(&gb);
    1174        8296 :             coeff1l = ea_adpcm_table[ byte >> 4       ];
    1175        8296 :             coeff2l = ea_adpcm_table[(byte >> 4  ) + 4];
    1176        8296 :             coeff1r = ea_adpcm_table[ byte & 0x0F];
    1177        8296 :             coeff2r = ea_adpcm_table[(byte & 0x0F) + 4];
    1178             : 
    1179        8296 :             byte = bytestream2_get_byteu(&gb);
    1180        8296 :             shift_left  = 20 - (byte >> 4);
    1181        8296 :             shift_right = 20 - (byte & 0x0F);
    1182             : 
    1183      240584 :             for (count2 = 0; count2 < 28; count2++) {
    1184      232288 :                 byte = bytestream2_get_byteu(&gb);
    1185      232288 :                 next_left_sample  = sign_extend(byte >> 4, 4) << shift_left;
    1186      232288 :                 next_right_sample = sign_extend(byte,      4) << shift_right;
    1187             : 
    1188      464576 :                 next_left_sample = (next_left_sample +
    1189      464576 :                     (current_left_sample * coeff1l) +
    1190      464576 :                     (previous_left_sample * coeff2l) + 0x80) >> 8;
    1191      464576 :                 next_right_sample = (next_right_sample +
    1192      464576 :                     (current_right_sample * coeff1r) +
    1193      464576 :                     (previous_right_sample * coeff2r) + 0x80) >> 8;
    1194             : 
    1195      232288 :                 previous_left_sample = current_left_sample;
    1196      232288 :                 current_left_sample = av_clip_int16(next_left_sample);
    1197      232288 :                 previous_right_sample = current_right_sample;
    1198      232288 :                 current_right_sample = av_clip_int16(next_right_sample);
    1199      232288 :                 *samples++ = current_left_sample;
    1200      232288 :                 *samples++ = current_right_sample;
    1201             :             }
    1202             :         }
    1203             : 
    1204         158 :         bytestream2_skip(&gb, 2); // Skip terminating 0x0000
    1205             : 
    1206         158 :         break;
    1207             :     }
    1208          30 :     case AV_CODEC_ID_ADPCM_EA_MAXIS_XA:
    1209             :     {
    1210             :         int coeff[2][2], shift[2];
    1211             : 
    1212          90 :         for(channel = 0; channel < avctx->channels; channel++) {
    1213          60 :             int byte = bytestream2_get_byteu(&gb);
    1214         180 :             for (i=0; i<2; i++)
    1215         120 :                 coeff[channel][i] = ea_adpcm_table[(byte >> 4) + 4*i];
    1216          60 :             shift[channel] = 20 - (byte & 0x0F);
    1217             :         }
    1218         450 :         for (count1 = 0; count1 < nb_samples / 2; count1++) {
    1219             :             int byte[2];
    1220             : 
    1221         420 :             byte[0] = bytestream2_get_byteu(&gb);
    1222         420 :             if (st) byte[1] = bytestream2_get_byteu(&gb);
    1223        1260 :             for(i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */
    1224        2520 :                 for(channel = 0; channel < avctx->channels; channel++) {
    1225        1680 :                     int sample = sign_extend(byte[channel] >> i, 4) << shift[channel];
    1226        3360 :                     sample = (sample +
    1227        3360 :                              c->status[channel].sample1 * coeff[channel][0] +
    1228        3360 :                              c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8;
    1229        1680 :                     c->status[channel].sample2 = c->status[channel].sample1;
    1230        1680 :                     c->status[channel].sample1 = av_clip_int16(sample);
    1231        1680 :                     *samples++ = c->status[channel].sample1;
    1232             :                 }
    1233             :             }
    1234             :         }
    1235          30 :         bytestream2_seek(&gb, 0, SEEK_END);
    1236          30 :         break;
    1237             :     }
    1238         400 :     case AV_CODEC_ID_ADPCM_EA_R1:
    1239             :     case AV_CODEC_ID_ADPCM_EA_R2:
    1240             :     case AV_CODEC_ID_ADPCM_EA_R3: {
    1241             :         /* channel numbering
    1242             :            2chan: 0=fl, 1=fr
    1243             :            4chan: 0=fl, 1=rl, 2=fr, 3=rr
    1244             :            6chan: 0=fl, 1=c,  2=fr, 3=rl,  4=rr, 5=sub */
    1245         400 :         const int big_endian = avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R3;
    1246             :         int previous_sample, current_sample, next_sample;
    1247             :         int coeff1, coeff2;
    1248             :         int shift;
    1249             :         unsigned int channel;
    1250             :         uint16_t *samplesC;
    1251         400 :         int count = 0;
    1252             :         int offsets[6];
    1253             : 
    1254        1200 :         for (channel=0; channel<avctx->channels; channel++)
    1255        1600 :             offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
    1256         800 :                                              bytestream2_get_le32(&gb)) +
    1257         800 :                                (avctx->channels + 1) * 4;
    1258             : 
    1259        1200 :         for (channel=0; channel<avctx->channels; channel++) {
    1260         800 :             bytestream2_seek(&gb, offsets[channel], SEEK_SET);
    1261         800 :             samplesC = samples_p[channel];
    1262             : 
    1263         800 :             if (avctx->codec->id == AV_CODEC_ID_ADPCM_EA_R1) {
    1264         190 :                 current_sample  = sign_extend(bytestream2_get_le16(&gb), 16);
    1265         190 :                 previous_sample = sign_extend(bytestream2_get_le16(&gb), 16);
    1266             :             } else {
    1267         610 :                 current_sample  = c->status[channel].predictor;
    1268         610 :                 previous_sample = c->status[channel].prev_sample;
    1269             :             }
    1270             : 
    1271       41992 :             for (count1 = 0; count1 < nb_samples / 28; count1++) {
    1272       41192 :                 int byte = bytestream2_get_byte(&gb);
    1273       41192 :                 if (byte == 0xEE) {  /* only seen in R2 and R3 */
    1274          12 :                     current_sample  = sign_extend(bytestream2_get_be16(&gb), 16);
    1275          12 :                     previous_sample = sign_extend(bytestream2_get_be16(&gb), 16);
    1276             : 
    1277         348 :                     for (count2=0; count2<28; count2++)
    1278         336 :                         *samplesC++ = sign_extend(bytestream2_get_be16(&gb), 16);
    1279             :                 } else {
    1280       41180 :                     coeff1 = ea_adpcm_table[ byte >> 4     ];
    1281       41180 :                     coeff2 = ea_adpcm_table[(byte >> 4) + 4];
    1282       41180 :                     shift = 20 - (byte & 0x0F);
    1283             : 
    1284     1194220 :                     for (count2=0; count2<28; count2++) {
    1285     1153040 :                         if (count2 & 1)
    1286      576520 :                             next_sample = sign_extend(byte,    4) << shift;
    1287             :                         else {
    1288      576520 :                             byte = bytestream2_get_byte(&gb);
    1289      576520 :                             next_sample = sign_extend(byte >> 4, 4) << shift;
    1290             :                         }
    1291             : 
    1292     2306080 :                         next_sample += (current_sample  * coeff1) +
    1293     1153040 :                                        (previous_sample * coeff2);
    1294     1153040 :                         next_sample = av_clip_int16(next_sample >> 8);
    1295             : 
    1296     1153040 :                         previous_sample = current_sample;
    1297     1153040 :                         current_sample  = next_sample;
    1298     1153040 :                         *samplesC++ = current_sample;
    1299             :                     }
    1300             :                 }
    1301             :             }
    1302         800 :             if (!count) {
    1303         400 :                 count = count1;
    1304         400 :             } else if (count != count1) {
    1305           0 :                 av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\n");
    1306           0 :                 count = FFMAX(count, count1);
    1307             :             }
    1308             : 
    1309         800 :             if (avctx->codec->id != AV_CODEC_ID_ADPCM_EA_R1) {
    1310         610 :                 c->status[channel].predictor   = current_sample;
    1311         610 :                 c->status[channel].prev_sample = previous_sample;
    1312             :             }
    1313             :         }
    1314             : 
    1315         400 :         frame->nb_samples = count * 28;
    1316         400 :         bytestream2_seek(&gb, 0, SEEK_END);
    1317         400 :         break;
    1318             :     }
    1319         600 :     case AV_CODEC_ID_ADPCM_EA_XAS:
    1320        1200 :         for (channel=0; channel<avctx->channels; channel++) {
    1321             :             int coeff[2][4], shift[4];
    1322         600 :             int16_t *s = samples_p[channel];
    1323        3000 :             for (n = 0; n < 4; n++, s += 32) {
    1324        2400 :                 int val = sign_extend(bytestream2_get_le16u(&gb), 16);
    1325        7200 :                 for (i=0; i<2; i++)
    1326        4800 :                     coeff[i][n] = ea_adpcm_table[(val&0x0F)+4*i];
    1327        2400 :                 s[0] = val & ~0x0F;
    1328             : 
    1329        2400 :                 val = sign_extend(bytestream2_get_le16u(&gb), 16);
    1330        2400 :                 shift[n] = 20 - (val & 0x0F);
    1331        2400 :                 s[1] = val & ~0x0F;
    1332             :             }
    1333             : 
    1334        9600 :             for (m=2; m<32; m+=2) {
    1335        9000 :                 s = &samples_p[channel][m];
    1336       45000 :                 for (n = 0; n < 4; n++, s += 32) {
    1337             :                     int level, pred;
    1338       36000 :                     int byte = bytestream2_get_byteu(&gb);
    1339             : 
    1340       36000 :                     level = sign_extend(byte >> 4, 4) << shift[n];
    1341       36000 :                     pred  = s[-1] * coeff[0][n] + s[-2] * coeff[1][n];
    1342       36000 :                     s[0]  = av_clip_int16((level + pred + 0x80) >> 8);
    1343             : 
    1344       36000 :                     level = sign_extend(byte, 4) << shift[n];
    1345       36000 :                     pred  = s[0] * coeff[0][n] + s[-1] * coeff[1][n];
    1346       36000 :                     s[1]  = av_clip_int16((level + pred + 0x80) >> 8);
    1347             :                 }
    1348             :             }
    1349             :         }
    1350         600 :         break;
    1351         161 :     case AV_CODEC_ID_ADPCM_IMA_AMV:
    1352         161 :         c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
    1353         161 :         c->status[0].step_index = bytestream2_get_byteu(&gb);
    1354         161 :         bytestream2_skipu(&gb, 5);
    1355         161 :         if (c->status[0].step_index > 88u) {
    1356           0 :             av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",
    1357           0 :                    c->status[0].step_index);
    1358           0 :             return AVERROR_INVALIDDATA;
    1359             :         }
    1360             : 
    1361      111112 :         for (n = nb_samples >> (1 - st); n > 0; n--) {
    1362      110951 :             int v = bytestream2_get_byteu(&gb);
    1363             : 
    1364      110951 :             *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4, 3);
    1365      110951 :             *samples++ = adpcm_ima_expand_nibble(&c->status[0], v & 0xf, 3);
    1366             :         }
    1367         161 :         break;
    1368         350 :     case AV_CODEC_ID_ADPCM_IMA_SMJPEG:
    1369         700 :         for (i = 0; i < avctx->channels; i++) {
    1370         350 :             c->status[i].predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
    1371         350 :             c->status[i].step_index = bytestream2_get_byteu(&gb);
    1372         350 :             bytestream2_skipu(&gb, 1);
    1373         350 :             if (c->status[i].step_index > 88u) {
    1374           0 :                 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n",
    1375           0 :                        c->status[i].step_index);
    1376           0 :                 return AVERROR_INVALIDDATA;
    1377             :             }
    1378             :         }
    1379             : 
    1380       89950 :         for (n = nb_samples >> (1 - st); n > 0; n--) {
    1381       89600 :             int v = bytestream2_get_byteu(&gb);
    1382             : 
    1383       89600 :             *samples++ = adpcm_ima_qt_expand_nibble(&c->status[0 ], v >> 4, 3);
    1384       89600 :             *samples++ = adpcm_ima_qt_expand_nibble(&c->status[st], v & 0xf, 3);
    1385             :         }
    1386         350 :         break;
    1387          64 :     case AV_CODEC_ID_ADPCM_CT:
    1388      262160 :         for (n = nb_samples >> (1 - st); n > 0; n--) {
    1389      262096 :             int v = bytestream2_get_byteu(&gb);
    1390      262096 :             *samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4  );
    1391      262096 :             *samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F);
    1392             :         }
    1393          64 :         break;
    1394          57 :     case AV_CODEC_ID_ADPCM_SBPRO_4:
    1395             :     case AV_CODEC_ID_ADPCM_SBPRO_3:
    1396             :     case AV_CODEC_ID_ADPCM_SBPRO_2:
    1397          57 :         if (!c->status[0].step_index) {
    1398             :             /* the first byte is a raw sample */
    1399           3 :             *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
    1400           3 :             if (st)
    1401           0 :                 *samples++ = 128 * (bytestream2_get_byteu(&gb) - 0x80);
    1402           3 :             c->status[0].step_index = 1;
    1403           3 :             nb_samples--;
    1404             :         }
    1405          57 :         if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_4) {
    1406       52256 :             for (n = nb_samples >> (1 - st); n > 0; n--) {
    1407       52230 :                 int byte = bytestream2_get_byteu(&gb);
    1408       52230 :                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
    1409       52230 :                                                        byte >> 4,   4, 0);
    1410       52230 :                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
    1411       52230 :                                                        byte & 0x0F, 4, 0);
    1412             :             }
    1413          31 :         } else if (avctx->codec->id == AV_CODEC_ID_ADPCM_SBPRO_3) {
    1414       34838 :             for (n = (nb_samples<<st) / 3; n > 0; n--) {
    1415       34820 :                 int byte = bytestream2_get_byteu(&gb);
    1416       34820 :                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
    1417       34820 :                                                         byte >> 5        , 3, 0);
    1418       34820 :                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
    1419       34820 :                                                        (byte >> 2) & 0x07, 3, 0);
    1420       34820 :                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
    1421       34820 :                                                         byte & 0x03,       2, 0);
    1422             :             }
    1423             :         } else {
    1424       26128 :             for (n = nb_samples >> (2 - st); n > 0; n--) {
    1425       26115 :                 int byte = bytestream2_get_byteu(&gb);
    1426       26115 :                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
    1427       26115 :                                                         byte >> 6        , 2, 2);
    1428       26115 :                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
    1429       26115 :                                                        (byte >> 4) & 0x03, 2, 2);
    1430       26115 :                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[0],
    1431       26115 :                                                        (byte >> 2) & 0x03, 2, 2);
    1432       26115 :                 *samples++ = adpcm_sbpro_expand_nibble(&c->status[st],
    1433       26115 :                                                         byte & 0x03,       2, 2);
    1434             :             }
    1435             :         }
    1436          57 :         break;
    1437         260 :     case AV_CODEC_ID_ADPCM_SWF:
    1438         260 :         adpcm_swf_decode(avctx, buf, buf_size, samples);
    1439         260 :         bytestream2_seek(&gb, 0, SEEK_END);
    1440         260 :         break;
    1441         136 :     case AV_CODEC_ID_ADPCM_YAMAHA:
    1442      553096 :         for (n = nb_samples >> (1 - st); n > 0; n--) {
    1443      552960 :             int v = bytestream2_get_byteu(&gb);
    1444      552960 :             *samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F);
    1445      552960 :             *samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4  );
    1446             :         }
    1447         136 :         break;
    1448           0 :     case AV_CODEC_ID_ADPCM_AICA:
    1449           0 :         if (!c->has_status) {
    1450           0 :             for (channel = 0; channel < avctx->channels; channel++)
    1451           0 :                 c->status[channel].step = 0;
    1452           0 :             c->has_status = 1;
    1453             :         }
    1454           0 :         for (channel = 0; channel < avctx->channels; channel++) {
    1455           0 :             samples = samples_p[channel];
    1456           0 :             for (n = nb_samples >> 1; n > 0; n--) {
    1457           0 :                 int v = bytestream2_get_byteu(&gb);
    1458           0 :                 *samples++ = adpcm_yamaha_expand_nibble(&c->status[channel], v & 0x0F);
    1459           0 :                 *samples++ = adpcm_yamaha_expand_nibble(&c->status[channel], v >> 4  );
    1460             :             }
    1461             :         }
    1462           0 :         break;
    1463          12 :     case AV_CODEC_ID_ADPCM_AFC:
    1464             :     {
    1465             :         int samples_per_block;
    1466             :         int blocks;
    1467             : 
    1468          12 :         if (avctx->extradata && avctx->extradata_size == 1 && avctx->extradata[0]) {
    1469           0 :             samples_per_block = avctx->extradata[0] / 16;
    1470           0 :             blocks = nb_samples / avctx->extradata[0];
    1471             :         } else {
    1472          12 :             samples_per_block = nb_samples / 16;
    1473          12 :             blocks = 1;
    1474             :         }
    1475             : 
    1476          24 :         for (m = 0; m < blocks; m++) {
    1477          36 :         for (channel = 0; channel < avctx->channels; channel++) {
    1478          24 :             int prev1 = c->status[channel].sample1;
    1479          24 :             int prev2 = c->status[channel].sample2;
    1480             : 
    1481          24 :             samples = samples_p[channel] + m * 16;
    1482             :             /* Read in every sample for this channel.  */
    1483       26904 :             for (i = 0; i < samples_per_block; i++) {
    1484       26880 :                 int byte = bytestream2_get_byteu(&gb);
    1485       26880 :                 int scale = 1 << (byte >> 4);
    1486       26880 :                 int index = byte & 0xf;
    1487       26880 :                 int factor1 = ff_adpcm_afc_coeffs[0][index];
    1488       26880 :                 int factor2 = ff_adpcm_afc_coeffs[1][index];
    1489             : 
    1490             :                 /* Decode 16 samples.  */
    1491      456960 :                 for (n = 0; n < 16; n++) {
    1492             :                     int32_t sampledat;
    1493             : 
    1494      430080 :                     if (n & 1) {
    1495      215040 :                         sampledat = sign_extend(byte, 4);
    1496             :                     } else {
    1497      215040 :                         byte = bytestream2_get_byteu(&gb);
    1498      215040 :                         sampledat = sign_extend(byte >> 4, 4);
    1499             :                     }
    1500             : 
    1501      860160 :                     sampledat = ((prev1 * factor1 + prev2 * factor2) +
    1502      430080 :                                  ((sampledat * scale) << 11)) >> 11;
    1503      430080 :                     *samples = av_clip_int16(sampledat);
    1504      430080 :                     prev2 = prev1;
    1505      430080 :                     prev1 = *samples++;
    1506             :                 }
    1507             :             }
    1508             : 
    1509          24 :             c->status[channel].sample1 = prev1;
    1510          24 :             c->status[channel].sample2 = prev2;
    1511             :         }
    1512             :         }
    1513          12 :         bytestream2_seek(&gb, 0, SEEK_END);
    1514          12 :         break;
    1515             :     }
    1516          71 :     case AV_CODEC_ID_ADPCM_THP:
    1517             :     case AV_CODEC_ID_ADPCM_THP_LE:
    1518             :     {
    1519             :         int table[14][16];
    1520             :         int ch;
    1521             : 
    1522             : #define THP_GET16(g) \
    1523             :     sign_extend( \
    1524             :         avctx->codec->id == AV_CODEC_ID_ADPCM_THP_LE ? \
    1525             :         bytestream2_get_le16u(&(g)) : \
    1526             :         bytestream2_get_be16u(&(g)), 16)
    1527             : 
    1528          71 :         if (avctx->extradata) {
    1529             :             GetByteContext tb;
    1530           0 :             if (avctx->extradata_size < 32 * avctx->channels) {
    1531           0 :                 av_log(avctx, AV_LOG_ERROR, "Missing coeff table\n");
    1532           0 :                 return AVERROR_INVALIDDATA;
    1533             :             }
    1534             : 
    1535           0 :             bytestream2_init(&tb, avctx->extradata, avctx->extradata_size);
    1536           0 :             for (i = 0; i < avctx->channels; i++)
    1537           0 :                 for (n = 0; n < 16; n++)
    1538           0 :                     table[i][n] = THP_GET16(tb);
    1539             :         } else {
    1540         213 :             for (i = 0; i < avctx->channels; i++)
    1541        2414 :                 for (n = 0; n < 16; n++)
    1542        2272 :                     table[i][n] = THP_GET16(gb);
    1543             : 
    1544          71 :             if (!c->has_status) {
    1545             :                 /* Initialize the previous sample.  */
    1546           3 :                 for (i = 0; i < avctx->channels; i++) {
    1547           2 :                     c->status[i].sample1 = THP_GET16(gb);
    1548           2 :                     c->status[i].sample2 = THP_GET16(gb);
    1549             :                 }
    1550           1 :                 c->has_status = 1;
    1551             :             } else {
    1552          70 :                 bytestream2_skip(&gb, avctx->channels * 4);
    1553             :             }
    1554             :         }
    1555             : 
    1556         213 :         for (ch = 0; ch < avctx->channels; ch++) {
    1557         142 :             samples = samples_p[ch];
    1558             : 
    1559             :             /* Read in every sample for this channel.  */
    1560       10982 :             for (i = 0; i < (nb_samples + 13) / 14; i++) {
    1561       10840 :                 int byte = bytestream2_get_byteu(&gb);
    1562       10840 :                 int index = (byte >> 4) & 7;
    1563       10840 :                 unsigned int exp = byte & 0x0F;
    1564       10840 :                 int factor1 = table[ch][index * 2];
    1565       10840 :                 int factor2 = table[ch][index * 2 + 1];
    1566             : 
    1567             :                 /* Decode 14 samples.  */
    1568      162600 :                 for (n = 0; n < 14 && (i * 14 + n < nb_samples); n++) {
    1569             :                     int32_t sampledat;
    1570             : 
    1571      151760 :                     if (n & 1) {
    1572       75880 :                         sampledat = sign_extend(byte, 4);
    1573             :                     } else {
    1574       75880 :                         byte = bytestream2_get_byteu(&gb);
    1575       75880 :                         sampledat = sign_extend(byte >> 4, 4);
    1576             :                     }
    1577             : 
    1578      303520 :                     sampledat = ((c->status[ch].sample1 * factor1
    1579      151760 :                                 + c->status[ch].sample2 * factor2) >> 11) + (sampledat << exp);
    1580      151760 :                     *samples = av_clip_int16(sampledat);
    1581      151760 :                     c->status[ch].sample2 = c->status[ch].sample1;
    1582      151760 :                     c->status[ch].sample1 = *samples++;
    1583             :                 }
    1584             :             }
    1585             :         }
    1586          71 :         break;
    1587             :     }
    1588          32 :     case AV_CODEC_ID_ADPCM_DTK:
    1589          96 :         for (channel = 0; channel < avctx->channels; channel++) {
    1590          64 :             samples = samples_p[channel];
    1591             : 
    1592             :             /* Read in every sample for this channel.  */
    1593        2112 :             for (i = 0; i < nb_samples / 28; i++) {
    1594             :                 int byte, header;
    1595        2048 :                 if (channel)
    1596        1024 :                     bytestream2_skipu(&gb, 1);
    1597        2048 :                 header = bytestream2_get_byteu(&gb);
    1598        2048 :                 bytestream2_skipu(&gb, 3 - channel);
    1599             : 
    1600             :                 /* Decode 28 samples.  */
    1601       59392 :                 for (n = 0; n < 28; n++) {
    1602             :                     int32_t sampledat, prev;
    1603             : 
    1604       57344 :                     switch (header >> 4) {
    1605        3388 :                     case 1:
    1606        3388 :                         prev = (c->status[channel].sample1 * 0x3c);
    1607        3388 :                         break;
    1608       50876 :                     case 2:
    1609       50876 :                         prev = (c->status[channel].sample1 * 0x73) - (c->status[channel].sample2 * 0x34);
    1610       50876 :                         break;
    1611        2744 :                     case 3:
    1612        2744 :                         prev = (c->status[channel].sample1 * 0x62) - (c->status[channel].sample2 * 0x37);
    1613        2744 :                         break;
    1614         336 :                     default:
    1615         336 :                         prev = 0;
    1616             :                     }
    1617             : 
    1618       57344 :                     prev = av_clip_intp2((prev + 0x20) >> 6, 21);
    1619             : 
    1620       57344 :                     byte = bytestream2_get_byteu(&gb);
    1621       57344 :                     if (!channel)
    1622       28672 :                         sampledat = sign_extend(byte, 4);
    1623             :                     else
    1624       28672 :                         sampledat = sign_extend(byte >> 4, 4);
    1625             : 
    1626       57344 :                     sampledat = (((sampledat << 12) >> (header & 0xf)) << 6) + prev;
    1627       57344 :                     *samples++ = av_clip_int16(sampledat >> 6);
    1628       57344 :                     c->status[channel].sample2 = c->status[channel].sample1;
    1629       57344 :                     c->status[channel].sample1 = sampledat;
    1630             :                 }
    1631             :             }
    1632          64 :             if (!channel)
    1633          32 :                 bytestream2_seek(&gb, 0, SEEK_SET);
    1634             :         }
    1635          32 :         break;
    1636           0 :     case AV_CODEC_ID_ADPCM_PSX:
    1637           0 :         for (channel = 0; channel < avctx->channels; channel++) {
    1638           0 :             samples = samples_p[channel];
    1639             : 
    1640             :             /* Read in every sample for this channel.  */
    1641           0 :             for (i = 0; i < nb_samples / 28; i++) {
    1642             :                 int filter, shift, flag, byte;
    1643             : 
    1644           0 :                 filter = bytestream2_get_byteu(&gb);
    1645           0 :                 shift  = filter & 0xf;
    1646           0 :                 filter = filter >> 4;
    1647           0 :                 if (filter >= FF_ARRAY_ELEMS(xa_adpcm_table))
    1648           0 :                     return AVERROR_INVALIDDATA;
    1649           0 :                 flag   = bytestream2_get_byteu(&gb);
    1650             : 
    1651             :                 /* Decode 28 samples.  */
    1652           0 :                 for (n = 0; n < 28; n++) {
    1653           0 :                     int sample = 0, scale;
    1654             : 
    1655           0 :                     if (flag < 0x07) {
    1656           0 :                         if (n & 1) {
    1657           0 :                             scale = sign_extend(byte >> 4, 4);
    1658             :                         } else {
    1659           0 :                             byte  = bytestream2_get_byteu(&gb);
    1660           0 :                             scale = sign_extend(byte, 4);
    1661             :                         }
    1662             : 
    1663           0 :                         scale  = scale << 12;
    1664           0 :                         sample = (int)((scale >> shift) + (c->status[channel].sample1 * xa_adpcm_table[filter][0] + c->status[channel].sample2 * xa_adpcm_table[filter][1]) / 64);
    1665             :                     }
    1666           0 :                     *samples++ = av_clip_int16(sample);
    1667           0 :                     c->status[channel].sample2 = c->status[channel].sample1;
    1668           0 :                     c->status[channel].sample1 = sample;
    1669             :                 }
    1670             :             }
    1671             :         }
    1672           0 :         break;
    1673             : 
    1674           0 :     default:
    1675           0 :         return -1;
    1676             :     }
    1677             : 
    1678       36079 :     if (avpkt->size && bytestream2_tell(&gb) == 0) {
    1679           0 :         av_log(avctx, AV_LOG_ERROR, "Nothing consumed\n");
    1680           0 :         return AVERROR_INVALIDDATA;
    1681             :     }
    1682             : 
    1683       36079 :     *got_frame_ptr = 1;
    1684             : 
    1685       36079 :     if (avpkt->size < bytestream2_tell(&gb)) {
    1686           0 :         av_log(avctx, AV_LOG_ERROR, "Overread of %d < %d\n", avpkt->size, bytestream2_tell(&gb));
    1687           0 :         return avpkt->size;
    1688             :     }
    1689             : 
    1690       36079 :     return bytestream2_tell(&gb);
    1691             : }
    1692             : 
    1693           0 : static void adpcm_flush(AVCodecContext *avctx)
    1694             : {
    1695           0 :     ADPCMDecodeContext *c = avctx->priv_data;
    1696           0 :     c->has_status = 0;
    1697           0 : }
    1698             : 
    1699             : 
    1700             : static const enum AVSampleFormat sample_fmts_s16[]  = { AV_SAMPLE_FMT_S16,
    1701             :                                                         AV_SAMPLE_FMT_NONE };
    1702             : static const enum AVSampleFormat sample_fmts_s16p[] = { AV_SAMPLE_FMT_S16P,
    1703             :                                                         AV_SAMPLE_FMT_NONE };
    1704             : static const enum AVSampleFormat sample_fmts_both[] = { AV_SAMPLE_FMT_S16,
    1705             :                                                         AV_SAMPLE_FMT_S16P,
    1706             :                                                         AV_SAMPLE_FMT_NONE };
    1707             : 
    1708             : #define ADPCM_DECODER(id_, sample_fmts_, name_, long_name_) \
    1709             : AVCodec ff_ ## name_ ## _decoder = {                        \
    1710             :     .name           = #name_,                               \
    1711             :     .long_name      = NULL_IF_CONFIG_SMALL(long_name_),     \
    1712             :     .type           = AVMEDIA_TYPE_AUDIO,                   \
    1713             :     .id             = id_,                                  \
    1714             :     .priv_data_size = sizeof(ADPCMDecodeContext),           \
    1715             :     .init           = adpcm_decode_init,                    \
    1716             :     .decode         = adpcm_decode_frame,                   \
    1717             :     .flush          = adpcm_flush,                          \
    1718             :     .capabilities   = AV_CODEC_CAP_DR1,                     \
    1719             :     .sample_fmts    = sample_fmts_,                         \
    1720             : }
    1721             : 
    1722             : /* Note: Do not forget to add new entries to the Makefile as well. */
    1723             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_4XM,         sample_fmts_s16p, adpcm_4xm,         "ADPCM 4X Movie");
    1724             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_AFC,         sample_fmts_s16p, adpcm_afc,         "ADPCM Nintendo Gamecube AFC");
    1725             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_AICA,        sample_fmts_s16p, adpcm_aica,        "ADPCM Yamaha AICA");
    1726             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_CT,          sample_fmts_s16,  adpcm_ct,          "ADPCM Creative Technology");
    1727             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_DTK,         sample_fmts_s16p, adpcm_dtk,         "ADPCM Nintendo Gamecube DTK");
    1728             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA,          sample_fmts_s16,  adpcm_ea,          "ADPCM Electronic Arts");
    1729             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_MAXIS_XA, sample_fmts_s16,  adpcm_ea_maxis_xa, "ADPCM Electronic Arts Maxis CDROM XA");
    1730             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R1,       sample_fmts_s16p, adpcm_ea_r1,       "ADPCM Electronic Arts R1");
    1731             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R2,       sample_fmts_s16p, adpcm_ea_r2,       "ADPCM Electronic Arts R2");
    1732             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_R3,       sample_fmts_s16p, adpcm_ea_r3,       "ADPCM Electronic Arts R3");
    1733             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_EA_XAS,      sample_fmts_s16p, adpcm_ea_xas,      "ADPCM Electronic Arts XAS");
    1734             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_AMV,     sample_fmts_s16,  adpcm_ima_amv,     "ADPCM IMA AMV");
    1735             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_APC,     sample_fmts_s16,  adpcm_ima_apc,     "ADPCM IMA CRYO APC");
    1736             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DAT4,    sample_fmts_s16,  adpcm_ima_dat4,    "ADPCM IMA Eurocom DAT4");
    1737             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DK3,     sample_fmts_s16,  adpcm_ima_dk3,     "ADPCM IMA Duck DK3");
    1738             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_DK4,     sample_fmts_s16,  adpcm_ima_dk4,     "ADPCM IMA Duck DK4");
    1739             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_EA_EACS, sample_fmts_s16,  adpcm_ima_ea_eacs, "ADPCM IMA Electronic Arts EACS");
    1740             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_EA_SEAD, sample_fmts_s16,  adpcm_ima_ea_sead, "ADPCM IMA Electronic Arts SEAD");
    1741             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_ISS,     sample_fmts_s16,  adpcm_ima_iss,     "ADPCM IMA Funcom ISS");
    1742             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_OKI,     sample_fmts_s16,  adpcm_ima_oki,     "ADPCM IMA Dialogic OKI");
    1743             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_QT,      sample_fmts_s16p, adpcm_ima_qt,      "ADPCM IMA QuickTime");
    1744             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_RAD,     sample_fmts_s16,  adpcm_ima_rad,     "ADPCM IMA Radical");
    1745             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_SMJPEG,  sample_fmts_s16,  adpcm_ima_smjpeg,  "ADPCM IMA Loki SDL MJPEG");
    1746             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WAV,     sample_fmts_s16p, adpcm_ima_wav,     "ADPCM IMA WAV");
    1747             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_IMA_WS,      sample_fmts_both, adpcm_ima_ws,      "ADPCM IMA Westwood");
    1748             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_MS,          sample_fmts_s16,  adpcm_ms,          "ADPCM Microsoft");
    1749             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_MTAF,        sample_fmts_s16p, adpcm_mtaf,        "ADPCM MTAF");
    1750             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_PSX,         sample_fmts_s16p, adpcm_psx,         "ADPCM Playstation");
    1751             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_2,     sample_fmts_s16,  adpcm_sbpro_2,     "ADPCM Sound Blaster Pro 2-bit");
    1752             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_3,     sample_fmts_s16,  adpcm_sbpro_3,     "ADPCM Sound Blaster Pro 2.6-bit");
    1753             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_SBPRO_4,     sample_fmts_s16,  adpcm_sbpro_4,     "ADPCM Sound Blaster Pro 4-bit");
    1754             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_SWF,         sample_fmts_s16,  adpcm_swf,         "ADPCM Shockwave Flash");
    1755             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_THP_LE,      sample_fmts_s16p, adpcm_thp_le,      "ADPCM Nintendo THP (little-endian)");
    1756             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_THP,         sample_fmts_s16p, adpcm_thp,         "ADPCM Nintendo THP");
    1757             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_XA,          sample_fmts_s16p, adpcm_xa,          "ADPCM CDROM XA");
    1758             : ADPCM_DECODER(AV_CODEC_ID_ADPCM_YAMAHA,      sample_fmts_s16,  adpcm_yamaha,      "ADPCM Yamaha");

Generated by: LCOV version 1.13