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.

664 lines
20KB

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