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.

674 lines
21KB

  1. /*
  2. * Shorten decoder
  3. * Copyright (c) 2005 Jeff Muizelaar
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. /**
  22. * @file
  23. * Shorten decoder
  24. * @author Jeff Muizelaar
  25. *
  26. */
  27. #include <limits.h>
  28. #include "avcodec.h"
  29. #include "bytestream.h"
  30. #include "get_bits.h"
  31. #include "golomb.h"
  32. #include "internal.h"
  33. #define MAX_CHANNELS 8
  34. #define MAX_BLOCKSIZE 65535
  35. #define OUT_BUFFER_SIZE 16384
  36. #define ULONGSIZE 2
  37. #define WAVE_FORMAT_PCM 0x0001
  38. #define DEFAULT_BLOCK_SIZE 256
  39. #define TYPESIZE 4
  40. #define CHANSIZE 0
  41. #define LPCQSIZE 2
  42. #define ENERGYSIZE 3
  43. #define BITSHIFTSIZE 2
  44. #define TYPE_S8 1
  45. #define TYPE_U8 2
  46. #define TYPE_S16HL 3
  47. #define TYPE_U16HL 4
  48. #define TYPE_S16LH 5
  49. #define TYPE_U16LH 6
  50. #define NWRAP 3
  51. #define NSKIPSIZE 1
  52. #define LPCQUANT 5
  53. #define V2LPCQOFFSET (1 << LPCQUANT)
  54. #define FNSIZE 2
  55. #define FN_DIFF0 0
  56. #define FN_DIFF1 1
  57. #define FN_DIFF2 2
  58. #define FN_DIFF3 3
  59. #define FN_QUIT 4
  60. #define FN_BLOCKSIZE 5
  61. #define FN_BITSHIFT 6
  62. #define FN_QLPC 7
  63. #define FN_ZERO 8
  64. #define FN_VERBATIM 9
  65. /** indicates if the FN_* command is audio or non-audio */
  66. static const uint8_t is_audio_command[10] = { 1, 1, 1, 1, 0, 0, 0, 1, 1, 0 };
  67. #define VERBATIM_CKSIZE_SIZE 5
  68. #define VERBATIM_BYTE_SIZE 8
  69. #define CANONICAL_HEADER_SIZE 44
  70. typedef struct ShortenContext {
  71. AVCodecContext *avctx;
  72. GetBitContext gb;
  73. int min_framesize, max_framesize;
  74. unsigned channels;
  75. int32_t *decoded[MAX_CHANNELS];
  76. int32_t *decoded_base[MAX_CHANNELS];
  77. int32_t *offset[MAX_CHANNELS];
  78. int *coeffs;
  79. uint8_t *bitstream;
  80. int bitstream_size;
  81. int bitstream_index;
  82. unsigned int allocated_bitstream_size;
  83. int header_size;
  84. uint8_t header[OUT_BUFFER_SIZE];
  85. int version;
  86. int cur_chan;
  87. int bitshift;
  88. int nmean;
  89. int internal_ftype;
  90. int nwrap;
  91. int blocksize;
  92. int bitindex;
  93. int32_t lpcqoffset;
  94. int got_header;
  95. int got_quit_command;
  96. } ShortenContext;
  97. static av_cold int shorten_decode_init(AVCodecContext *avctx)
  98. {
  99. ShortenContext *s = avctx->priv_data;
  100. s->avctx = avctx;
  101. return 0;
  102. }
  103. static int allocate_buffers(ShortenContext *s)
  104. {
  105. int i, chan;
  106. int *coeffs;
  107. void *tmp_ptr;
  108. for (chan = 0; chan < s->channels; chan++) {
  109. if (FFMAX(1, s->nmean) >= UINT_MAX / sizeof(int32_t)) {
  110. av_log(s->avctx, AV_LOG_ERROR, "nmean too large\n");
  111. return AVERROR_INVALIDDATA;
  112. }
  113. if (s->blocksize + s->nwrap >= UINT_MAX / sizeof(int32_t) ||
  114. s->blocksize + s->nwrap <= (unsigned)s->nwrap) {
  115. av_log(s->avctx, AV_LOG_ERROR,
  116. "s->blocksize + s->nwrap too large\n");
  117. return AVERROR_INVALIDDATA;
  118. }
  119. tmp_ptr =
  120. av_realloc(s->offset[chan], sizeof(int32_t) * FFMAX(1, s->nmean));
  121. if (!tmp_ptr)
  122. return AVERROR(ENOMEM);
  123. s->offset[chan] = tmp_ptr;
  124. tmp_ptr = av_realloc(s->decoded_base[chan], (s->blocksize + s->nwrap) *
  125. sizeof(s->decoded_base[0][0]));
  126. if (!tmp_ptr)
  127. return AVERROR(ENOMEM);
  128. s->decoded_base[chan] = tmp_ptr;
  129. for (i = 0; i < s->nwrap; i++)
  130. s->decoded_base[chan][i] = 0;
  131. s->decoded[chan] = s->decoded_base[chan] + s->nwrap;
  132. }
  133. coeffs = av_realloc(s->coeffs, s->nwrap * sizeof(*s->coeffs));
  134. if (!coeffs)
  135. return AVERROR(ENOMEM);
  136. s->coeffs = coeffs;
  137. return 0;
  138. }
  139. static inline unsigned int get_uint(ShortenContext *s, int k)
  140. {
  141. if (s->version != 0)
  142. k = get_ur_golomb_shorten(&s->gb, ULONGSIZE);
  143. return get_ur_golomb_shorten(&s->gb, k);
  144. }
  145. static void fix_bitshift(ShortenContext *s, int32_t *buffer)
  146. {
  147. int i;
  148. if (s->bitshift != 0)
  149. for (i = 0; i < s->blocksize; i++)
  150. buffer[i] <<= s->bitshift;
  151. }
  152. static int init_offset(ShortenContext *s)
  153. {
  154. int32_t mean = 0;
  155. int chan, i;
  156. int nblock = FFMAX(1, s->nmean);
  157. /* initialise offset */
  158. switch (s->internal_ftype) {
  159. case TYPE_U8:
  160. s->avctx->sample_fmt = AV_SAMPLE_FMT_U8P;
  161. mean = 0x80;
  162. break;
  163. case TYPE_S16HL:
  164. case TYPE_S16LH:
  165. s->avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
  166. break;
  167. default:
  168. av_log(s->avctx, AV_LOG_ERROR, "unknown audio type\n");
  169. return AVERROR_PATCHWELCOME;
  170. }
  171. for (chan = 0; chan < s->channels; chan++)
  172. for (i = 0; i < nblock; i++)
  173. s->offset[chan][i] = mean;
  174. return 0;
  175. }
  176. static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header,
  177. int header_size)
  178. {
  179. int len, bps;
  180. short wave_format;
  181. GetByteContext gb;
  182. bytestream2_init(&gb, header, header_size);
  183. if (bytestream2_get_le32(&gb) != MKTAG('R', 'I', 'F', 'F')) {
  184. av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
  185. return AVERROR_INVALIDDATA;
  186. }
  187. bytestream2_skip(&gb, 4); /* chunk size */
  188. if (bytestream2_get_le32(&gb) != MKTAG('W', 'A', 'V', 'E')) {
  189. av_log(avctx, AV_LOG_ERROR, "missing WAVE tag\n");
  190. return AVERROR_INVALIDDATA;
  191. }
  192. while (bytestream2_get_le32(&gb) != MKTAG('f', 'm', 't', ' ')) {
  193. len = bytestream2_get_le32(&gb);
  194. if (len<0 || bytestream2_get_bytes_left(&gb) - 8 < len)
  195. return AVERROR_INVALIDDATA;
  196. bytestream2_skip(&gb, len);
  197. }
  198. len = bytestream2_get_le32(&gb);
  199. if (len < 16) {
  200. av_log(avctx, AV_LOG_ERROR, "fmt chunk was too short\n");
  201. return AVERROR_INVALIDDATA;
  202. }
  203. wave_format = bytestream2_get_le16(&gb);
  204. switch (wave_format) {
  205. case WAVE_FORMAT_PCM:
  206. break;
  207. default:
  208. av_log(avctx, AV_LOG_ERROR, "unsupported wave format\n");
  209. return AVERROR(ENOSYS);
  210. }
  211. bytestream2_skip(&gb, 2); // skip channels (already got from shorten header)
  212. avctx->sample_rate = bytestream2_get_le32(&gb);
  213. bytestream2_skip(&gb, 4); // skip bit rate (represents original uncompressed bit rate)
  214. bytestream2_skip(&gb, 2); // skip block align (not needed)
  215. bps = bytestream2_get_le16(&gb);
  216. avctx->bits_per_coded_sample = bps;
  217. if (bps != 16 && bps != 8) {
  218. av_log(avctx, AV_LOG_ERROR, "unsupported number of bits per sample: %d\n", bps);
  219. return AVERROR(ENOSYS);
  220. }
  221. len -= 16;
  222. if (len > 0)
  223. av_log(avctx, AV_LOG_INFO, "%d header bytes unparsed\n", len);
  224. return 0;
  225. }
  226. static const int fixed_coeffs[3][3] = {
  227. { 1, 0, 0 },
  228. { 2, -1, 0 },
  229. { 3, -3, 1 }
  230. };
  231. static int decode_subframe_lpc(ShortenContext *s, int command, int channel,
  232. int residual_size, int32_t coffset)
  233. {
  234. int pred_order, sum, qshift, init_sum, i, j;
  235. const int *coeffs;
  236. if (command == FN_QLPC) {
  237. /* read/validate prediction order */
  238. pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE);
  239. if (pred_order > s->nwrap) {
  240. av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\n",
  241. pred_order);
  242. return AVERROR(EINVAL);
  243. }
  244. /* read LPC coefficients */
  245. for (i = 0; i < pred_order; i++)
  246. s->coeffs[i] = get_sr_golomb_shorten(&s->gb, LPCQUANT);
  247. coeffs = s->coeffs;
  248. qshift = LPCQUANT;
  249. } else {
  250. /* fixed LPC coeffs */
  251. pred_order = command;
  252. coeffs = fixed_coeffs[pred_order - 1];
  253. qshift = 0;
  254. }
  255. /* subtract offset from previous samples to use in prediction */
  256. if (command == FN_QLPC && coffset)
  257. for (i = -pred_order; i < 0; i++)
  258. s->decoded[channel][i] -= coffset;
  259. /* decode residual and do LPC prediction */
  260. init_sum = pred_order ? (command == FN_QLPC ? s->lpcqoffset : 0) : coffset;
  261. for (i = 0; i < s->blocksize; i++) {
  262. sum = init_sum;
  263. for (j = 0; j < pred_order; j++)
  264. sum += coeffs[j] * s->decoded[channel][i - j - 1];
  265. s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) +
  266. (sum >> qshift);
  267. }
  268. /* add offset to current samples */
  269. if (command == FN_QLPC && coffset)
  270. for (i = 0; i < s->blocksize; i++)
  271. s->decoded[channel][i] += coffset;
  272. return 0;
  273. }
  274. static int read_header(ShortenContext *s)
  275. {
  276. int i, ret;
  277. int maxnlpc = 0;
  278. /* shorten signature */
  279. if (get_bits_long(&s->gb, 32) != AV_RB32("ajkg")) {
  280. av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic 'ajkg'\n");
  281. return AVERROR_INVALIDDATA;
  282. }
  283. s->lpcqoffset = 0;
  284. s->blocksize = DEFAULT_BLOCK_SIZE;
  285. s->nmean = -1;
  286. s->version = get_bits(&s->gb, 8);
  287. s->internal_ftype = get_uint(s, TYPESIZE);
  288. s->channels = get_uint(s, CHANSIZE);
  289. if (!s->channels) {
  290. av_log(s->avctx, AV_LOG_ERROR, "No channels reported\n");
  291. return AVERROR_INVALIDDATA;
  292. }
  293. if (s->channels > MAX_CHANNELS) {
  294. av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels);
  295. s->channels = 0;
  296. return AVERROR_INVALIDDATA;
  297. }
  298. s->avctx->channels = s->channels;
  299. /* get blocksize if version > 0 */
  300. if (s->version > 0) {
  301. int skip_bytes;
  302. unsigned blocksize;
  303. blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE));
  304. if (!blocksize || blocksize > MAX_BLOCKSIZE) {
  305. av_log(s->avctx, AV_LOG_ERROR,
  306. "invalid or unsupported block size: %d\n",
  307. blocksize);
  308. return AVERROR(EINVAL);
  309. }
  310. s->blocksize = blocksize;
  311. maxnlpc = get_uint(s, LPCQSIZE);
  312. s->nmean = get_uint(s, 0);
  313. skip_bytes = get_uint(s, NSKIPSIZE);
  314. for (i = 0; i < skip_bytes; i++)
  315. skip_bits(&s->gb, 8);
  316. }
  317. s->nwrap = FFMAX(NWRAP, maxnlpc);
  318. if ((ret = allocate_buffers(s)) < 0)
  319. return ret;
  320. if ((ret = init_offset(s)) < 0)
  321. return ret;
  322. if (s->version > 1)
  323. s->lpcqoffset = V2LPCQOFFSET;
  324. if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) {
  325. av_log(s->avctx, AV_LOG_ERROR,
  326. "missing verbatim section at beginning of stream\n");
  327. return AVERROR_INVALIDDATA;
  328. }
  329. s->header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
  330. if (s->header_size >= OUT_BUFFER_SIZE ||
  331. s->header_size < CANONICAL_HEADER_SIZE) {
  332. av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n",
  333. s->header_size);
  334. return AVERROR_INVALIDDATA;
  335. }
  336. for (i = 0; i < s->header_size; i++)
  337. s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
  338. if ((ret = decode_wave_header(s->avctx, s->header, s->header_size)) < 0)
  339. return ret;
  340. s->cur_chan = 0;
  341. s->bitshift = 0;
  342. s->got_header = 1;
  343. return 0;
  344. }
  345. static int shorten_decode_frame(AVCodecContext *avctx, void *data,
  346. int *got_frame_ptr, AVPacket *avpkt)
  347. {
  348. AVFrame *frame = data;
  349. const uint8_t *buf = avpkt->data;
  350. int buf_size = avpkt->size;
  351. ShortenContext *s = avctx->priv_data;
  352. int i, input_buf_size = 0;
  353. int ret;
  354. /* allocate internal bitstream buffer */
  355. if (s->max_framesize == 0) {
  356. void *tmp_ptr;
  357. s->max_framesize = 8192; // should hopefully be enough for the first header
  358. tmp_ptr = av_fast_realloc(s->bitstream, &s->allocated_bitstream_size,
  359. s->max_framesize + FF_INPUT_BUFFER_PADDING_SIZE);
  360. if (!tmp_ptr) {
  361. av_log(avctx, AV_LOG_ERROR, "error allocating bitstream buffer\n");
  362. return AVERROR(ENOMEM);
  363. }
  364. s->bitstream = tmp_ptr;
  365. }
  366. /* append current packet data to bitstream buffer */
  367. if (1 && s->max_framesize) { //FIXME truncated
  368. buf_size = FFMIN(buf_size, s->max_framesize - s->bitstream_size);
  369. input_buf_size = buf_size;
  370. if (s->bitstream_index + s->bitstream_size + buf_size + FF_INPUT_BUFFER_PADDING_SIZE >
  371. s->allocated_bitstream_size) {
  372. memmove(s->bitstream, &s->bitstream[s->bitstream_index],
  373. s->bitstream_size);
  374. s->bitstream_index = 0;
  375. }
  376. if (buf)
  377. memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf,
  378. buf_size);
  379. buf = &s->bitstream[s->bitstream_index];
  380. buf_size += s->bitstream_size;
  381. s->bitstream_size = buf_size;
  382. /* do not decode until buffer has at least max_framesize bytes or
  383. * the end of the file has been reached */
  384. if (buf_size < s->max_framesize && avpkt->data) {
  385. *got_frame_ptr = 0;
  386. return input_buf_size;
  387. }
  388. }
  389. /* init and position bitstream reader */
  390. init_get_bits(&s->gb, buf, buf_size * 8);
  391. skip_bits(&s->gb, s->bitindex);
  392. /* process header or next subblock */
  393. if (!s->got_header) {
  394. if ((ret = read_header(s)) < 0)
  395. return ret;
  396. *got_frame_ptr = 0;
  397. goto finish_frame;
  398. }
  399. /* if quit command was read previously, don't decode anything */
  400. if (s->got_quit_command) {
  401. *got_frame_ptr = 0;
  402. return avpkt->size;
  403. }
  404. s->cur_chan = 0;
  405. while (s->cur_chan < s->channels) {
  406. unsigned cmd;
  407. int len;
  408. if (get_bits_left(&s->gb) < 3 + FNSIZE) {
  409. *got_frame_ptr = 0;
  410. break;
  411. }
  412. cmd = get_ur_golomb_shorten(&s->gb, FNSIZE);
  413. if (cmd > FN_VERBATIM) {
  414. av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd);
  415. *got_frame_ptr = 0;
  416. break;
  417. }
  418. if (!is_audio_command[cmd]) {
  419. /* process non-audio command */
  420. switch (cmd) {
  421. case FN_VERBATIM:
  422. len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE);
  423. while (len--)
  424. get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE);
  425. break;
  426. case FN_BITSHIFT:
  427. s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE);
  428. break;
  429. case FN_BLOCKSIZE: {
  430. unsigned blocksize = get_uint(s, av_log2(s->blocksize));
  431. if (blocksize > s->blocksize) {
  432. av_log(avctx, AV_LOG_ERROR,
  433. "Increasing block size is not supported\n");
  434. return AVERROR_PATCHWELCOME;
  435. }
  436. if (!blocksize || blocksize > MAX_BLOCKSIZE) {
  437. av_log(avctx, AV_LOG_ERROR, "invalid or unsupported "
  438. "block size: %d\n", blocksize);
  439. return AVERROR(EINVAL);
  440. }
  441. s->blocksize = blocksize;
  442. break;
  443. }
  444. case FN_QUIT:
  445. s->got_quit_command = 1;
  446. break;
  447. }
  448. if (cmd == FN_BLOCKSIZE || cmd == FN_QUIT) {
  449. *got_frame_ptr = 0;
  450. break;
  451. }
  452. } else {
  453. /* process audio command */
  454. int residual_size = 0;
  455. int channel = s->cur_chan;
  456. int32_t coffset;
  457. /* get Rice code for residual decoding */
  458. if (cmd != FN_ZERO) {
  459. residual_size = get_ur_golomb_shorten(&s->gb, ENERGYSIZE);
  460. /* This is a hack as version 0 differed in the definition
  461. * of get_sr_golomb_shorten(). */
  462. if (s->version == 0)
  463. residual_size--;
  464. }
  465. /* calculate sample offset using means from previous blocks */
  466. if (s->nmean == 0)
  467. coffset = s->offset[channel][0];
  468. else {
  469. int32_t sum = (s->version < 2) ? 0 : s->nmean / 2;
  470. for (i = 0; i < s->nmean; i++)
  471. sum += s->offset[channel][i];
  472. coffset = sum / s->nmean;
  473. if (s->version >= 2)
  474. coffset = s->bitshift == 0 ? coffset : coffset >> s->bitshift - 1 >> 1;
  475. }
  476. /* decode samples for this channel */
  477. if (cmd == FN_ZERO) {
  478. for (i = 0; i < s->blocksize; i++)
  479. s->decoded[channel][i] = 0;
  480. } else {
  481. if ((ret = decode_subframe_lpc(s, cmd, channel,
  482. residual_size, coffset)) < 0)
  483. return ret;
  484. }
  485. /* update means with info from the current block */
  486. if (s->nmean > 0) {
  487. int32_t sum = (s->version < 2) ? 0 : s->blocksize / 2;
  488. for (i = 0; i < s->blocksize; i++)
  489. sum += s->decoded[channel][i];
  490. for (i = 1; i < s->nmean; i++)
  491. s->offset[channel][i - 1] = s->offset[channel][i];
  492. if (s->version < 2)
  493. s->offset[channel][s->nmean - 1] = sum / s->blocksize;
  494. else
  495. s->offset[channel][s->nmean - 1] = (sum / s->blocksize) << s->bitshift;
  496. }
  497. /* copy wrap samples for use with next block */
  498. for (i = -s->nwrap; i < 0; i++)
  499. s->decoded[channel][i] = s->decoded[channel][i + s->blocksize];
  500. /* shift samples to add in unused zero bits which were removed
  501. * during encoding */
  502. fix_bitshift(s, s->decoded[channel]);
  503. /* if this is the last channel in the block, output the samples */
  504. s->cur_chan++;
  505. if (s->cur_chan == s->channels) {
  506. uint8_t *samples_u8;
  507. int16_t *samples_s16;
  508. int chan;
  509. /* get output buffer */
  510. frame->nb_samples = s->blocksize;
  511. if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
  512. return ret;
  513. for (chan = 0; chan < s->channels; chan++) {
  514. samples_u8 = ((uint8_t **)frame->extended_data)[chan];
  515. samples_s16 = ((int16_t **)frame->extended_data)[chan];
  516. for (i = 0; i < s->blocksize; i++) {
  517. switch (s->internal_ftype) {
  518. case TYPE_U8:
  519. *samples_u8++ = av_clip_uint8(s->decoded[chan][i]);
  520. break;
  521. case TYPE_S16HL:
  522. case TYPE_S16LH:
  523. *samples_s16++ = av_clip_int16(s->decoded[chan][i]);
  524. break;
  525. }
  526. }
  527. }
  528. *got_frame_ptr = 1;
  529. }
  530. }
  531. }
  532. if (s->cur_chan < s->channels)
  533. *got_frame_ptr = 0;
  534. finish_frame:
  535. s->bitindex = get_bits_count(&s->gb) - 8 * (get_bits_count(&s->gb) / 8);
  536. i = get_bits_count(&s->gb) / 8;
  537. if (i > buf_size) {
  538. av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size);
  539. s->bitstream_size = 0;
  540. s->bitstream_index = 0;
  541. return AVERROR_INVALIDDATA;
  542. }
  543. if (s->bitstream_size) {
  544. s->bitstream_index += i;
  545. s->bitstream_size -= i;
  546. return input_buf_size;
  547. } else
  548. return i;
  549. }
  550. static av_cold int shorten_decode_close(AVCodecContext *avctx)
  551. {
  552. ShortenContext *s = avctx->priv_data;
  553. int i;
  554. for (i = 0; i < s->channels; i++) {
  555. s->decoded[i] = NULL;
  556. av_freep(&s->decoded_base[i]);
  557. av_freep(&s->offset[i]);
  558. }
  559. av_freep(&s->bitstream);
  560. av_freep(&s->coeffs);
  561. return 0;
  562. }
  563. AVCodec ff_shorten_decoder = {
  564. .name = "shorten",
  565. .type = AVMEDIA_TYPE_AUDIO,
  566. .id = AV_CODEC_ID_SHORTEN,
  567. .priv_data_size = sizeof(ShortenContext),
  568. .init = shorten_decode_init,
  569. .close = shorten_decode_close,
  570. .decode = shorten_decode_frame,
  571. .capabilities = CODEC_CAP_DELAY | CODEC_CAP_DR1,
  572. .long_name = NULL_IF_CONFIG_SMALL("Shorten"),
  573. .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
  574. AV_SAMPLE_FMT_U8P,
  575. AV_SAMPLE_FMT_NONE },
  576. };