You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1694 lines
65KB

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