FFmpeg  2.8.15
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
shorten.c
Go to the documentation of this file.
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 /**
23  * @file
24  * Shorten decoder
25  * @author Jeff Muizelaar
26  *
27  */
28 
29 #include <limits.h>
30 #include "avcodec.h"
31 #include "bytestream.h"
32 #include "get_bits.h"
33 #include "golomb.h"
34 #include "internal.h"
35 
36 #define MAX_CHANNELS 8
37 #define MAX_BLOCKSIZE 65535
38 
39 #define OUT_BUFFER_SIZE 16384
40 
41 #define ULONGSIZE 2
42 
43 #define WAVE_FORMAT_PCM 0x0001
44 
45 #define DEFAULT_BLOCK_SIZE 256
46 
47 #define TYPESIZE 4
48 #define CHANSIZE 0
49 #define LPCQSIZE 2
50 #define ENERGYSIZE 3
51 #define BITSHIFTSIZE 2
52 
53 #define TYPE_S8 1
54 #define TYPE_U8 2
55 #define TYPE_S16HL 3
56 #define TYPE_U16HL 4
57 #define TYPE_S16LH 5
58 #define TYPE_U16LH 6
59 
60 #define NWRAP 3
61 #define NSKIPSIZE 1
62 
63 #define LPCQUANT 5
64 #define V2LPCQOFFSET (1 << LPCQUANT)
65 
66 #define FNSIZE 2
67 #define FN_DIFF0 0
68 #define FN_DIFF1 1
69 #define FN_DIFF2 2
70 #define FN_DIFF3 3
71 #define FN_QUIT 4
72 #define FN_BLOCKSIZE 5
73 #define FN_BITSHIFT 6
74 #define FN_QLPC 7
75 #define FN_ZERO 8
76 #define FN_VERBATIM 9
77 
78 /** indicates if the FN_* command is audio or non-audio */
79 static const uint8_t is_audio_command[10] = { 1, 1, 1, 1, 0, 0, 0, 1, 1, 0 };
80 
81 #define VERBATIM_CKSIZE_SIZE 5
82 #define VERBATIM_BYTE_SIZE 8
83 #define CANONICAL_HEADER_SIZE 44
84 
85 typedef struct ShortenContext {
88 
90  unsigned channels;
91 
95  int *coeffs;
102  int version;
103  int cur_chan;
104  int bitshift;
105  int nmean;
107  int nwrap;
109  int bitindex;
114 
116 {
117  ShortenContext *s = avctx->priv_data;
118  s->avctx = avctx;
119 
120  return 0;
121 }
122 
124 {
125  int i, chan, err;
126 
127  for (chan = 0; chan < s->channels; chan++) {
128  if (FFMAX(1, s->nmean) >= UINT_MAX / sizeof(int32_t)) {
129  av_log(s->avctx, AV_LOG_ERROR, "nmean too large\n");
130  return AVERROR_INVALIDDATA;
131  }
132  if (s->blocksize + (uint64_t)s->nwrap >= UINT_MAX / sizeof(int32_t)) {
134  "s->blocksize + s->nwrap too large\n");
135  return AVERROR_INVALIDDATA;
136  }
137 
138  if ((err = av_reallocp_array(&s->offset[chan],
139  sizeof(int32_t),
140  FFMAX(1, s->nmean))) < 0)
141  return err;
142 
143  if ((err = av_reallocp_array(&s->decoded_base[chan], (s->blocksize + s->nwrap),
144  sizeof(s->decoded_base[0][0]))) < 0)
145  return err;
146  for (i = 0; i < s->nwrap; i++)
147  s->decoded_base[chan][i] = 0;
148  s->decoded[chan] = s->decoded_base[chan] + s->nwrap;
149  }
150 
151  if ((err = av_reallocp_array(&s->coeffs, s->nwrap, sizeof(*s->coeffs))) < 0)
152  return err;
153 
154  return 0;
155 }
156 
157 static inline unsigned int get_uint(ShortenContext *s, int k)
158 {
159  if (s->version != 0) {
161  if (k > 31U)
162  return AVERROR_INVALIDDATA;
163  }
164  return get_ur_golomb_shorten(&s->gb, k);
165 }
166 
168 {
169  int i;
170 
171  if (s->bitshift != 0)
172  for (i = 0; i < s->blocksize; i++)
173  buffer[i] <<= s->bitshift;
174 }
175 
177 {
178  int32_t mean = 0;
179  int chan, i;
180  int nblock = FFMAX(1, s->nmean);
181  /* initialise offset */
182  switch (s->internal_ftype) {
183  case TYPE_U8:
185  mean = 0x80;
186  break;
187  case TYPE_S16HL:
188  case TYPE_S16LH:
190  break;
191  default:
192  av_log(s->avctx, AV_LOG_ERROR, "unknown audio type\n");
193  return AVERROR_PATCHWELCOME;
194  }
195 
196  for (chan = 0; chan < s->channels; chan++)
197  for (i = 0; i < nblock; i++)
198  s->offset[chan][i] = mean;
199  return 0;
200 }
201 
203  int header_size)
204 {
205  int len, bps;
206  short wave_format;
207  GetByteContext gb;
208 
209  bytestream2_init(&gb, header, header_size);
210 
211  if (bytestream2_get_le32(&gb) != MKTAG('R', 'I', 'F', 'F')) {
212  av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
213  return AVERROR_INVALIDDATA;
214  }
215 
216  bytestream2_skip(&gb, 4); /* chunk size */
217 
218  if (bytestream2_get_le32(&gb) != MKTAG('W', 'A', 'V', 'E')) {
219  av_log(avctx, AV_LOG_ERROR, "missing WAVE tag\n");
220  return AVERROR_INVALIDDATA;
221  }
222 
223  while (bytestream2_get_le32(&gb) != MKTAG('f', 'm', 't', ' ')) {
224  len = bytestream2_get_le32(&gb);
225  bytestream2_skip(&gb, len);
226  if (len < 0 || bytestream2_get_bytes_left(&gb) < 16) {
227  av_log(avctx, AV_LOG_ERROR, "no fmt chunk found\n");
228  return AVERROR_INVALIDDATA;
229  }
230  }
231  len = bytestream2_get_le32(&gb);
232 
233  if (len < 16) {
234  av_log(avctx, AV_LOG_ERROR, "fmt chunk was too short\n");
235  return AVERROR_INVALIDDATA;
236  }
237 
238  wave_format = bytestream2_get_le16(&gb);
239 
240  switch (wave_format) {
241  case WAVE_FORMAT_PCM:
242  break;
243  default:
244  av_log(avctx, AV_LOG_ERROR, "unsupported wave format\n");
245  return AVERROR(ENOSYS);
246  }
247 
248  bytestream2_skip(&gb, 2); // skip channels (already got from shorten header)
249  avctx->sample_rate = bytestream2_get_le32(&gb);
250  bytestream2_skip(&gb, 4); // skip bit rate (represents original uncompressed bit rate)
251  bytestream2_skip(&gb, 2); // skip block align (not needed)
252  bps = bytestream2_get_le16(&gb);
253  avctx->bits_per_coded_sample = bps;
254 
255  if (bps != 16 && bps != 8) {
256  av_log(avctx, AV_LOG_ERROR, "unsupported number of bits per sample: %d\n", bps);
257  return AVERROR(ENOSYS);
258  }
259 
260  len -= 16;
261  if (len > 0)
262  av_log(avctx, AV_LOG_INFO, "%d header bytes unparsed\n", len);
263 
264  return 0;
265 }
266 
267 static const int fixed_coeffs[][3] = {
268  { 0, 0, 0 },
269  { 1, 0, 0 },
270  { 2, -1, 0 },
271  { 3, -3, 1 }
272 };
273 
274 static int decode_subframe_lpc(ShortenContext *s, int command, int channel,
275  int residual_size, int32_t coffset)
276 {
277  int pred_order, sum, qshift, init_sum, i, j;
278  const int *coeffs;
279 
280  if (command == FN_QLPC) {
281  /* read/validate prediction order */
282  pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE);
283  if ((unsigned)pred_order > s->nwrap) {
284  av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\n",
285  pred_order);
286  return AVERROR(EINVAL);
287  }
288  /* read LPC coefficients */
289  for (i = 0; i < pred_order; i++)
290  s->coeffs[i] = get_sr_golomb_shorten(&s->gb, LPCQUANT);
291  coeffs = s->coeffs;
292 
293  qshift = LPCQUANT;
294  } else {
295  /* fixed LPC coeffs */
296  pred_order = command;
297  if (pred_order >= FF_ARRAY_ELEMS(fixed_coeffs)) {
298  av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\n",
299  pred_order);
300  return AVERROR_INVALIDDATA;
301  }
302  coeffs = fixed_coeffs[pred_order];
303  qshift = 0;
304  }
305 
306  /* subtract offset from previous samples to use in prediction */
307  if (command == FN_QLPC && coffset)
308  for (i = -pred_order; i < 0; i++)
309  s->decoded[channel][i] -= coffset;
310 
311  /* decode residual and do LPC prediction */
312  init_sum = pred_order ? (command == FN_QLPC ? s->lpcqoffset : 0) : coffset;
313  for (i = 0; i < s->blocksize; i++) {
314  sum = init_sum;
315  for (j = 0; j < pred_order; j++)
316  sum += coeffs[j] * (unsigned)s->decoded[channel][i - j - 1];
317  s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) +
318  (sum >> qshift);
319  }
320 
321  /* add offset to current samples */
322  if (command == FN_QLPC && coffset)
323  for (i = 0; i < s->blocksize; i++)
324  s->decoded[channel][i] += coffset;
325 
326  return 0;
327 }
328 
330 {
331  int i, ret;
332  int maxnlpc = 0;
333  /* shorten signature */
334  if (get_bits_long(&s->gb, 32) != AV_RB32("ajkg")) {
335  av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic 'ajkg'\n");
336  return AVERROR_INVALIDDATA;
337  }
338 
339  s->lpcqoffset = 0;
341  s->nmean = -1;
342  s->version = get_bits(&s->gb, 8);
344 
345  s->channels = get_uint(s, CHANSIZE);
346  if (!s->channels) {
347  av_log(s->avctx, AV_LOG_ERROR, "No channels reported\n");
348  return AVERROR_INVALIDDATA;
349  }
350  if (s->channels > MAX_CHANNELS) {
351  av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels);
352  s->channels = 0;
353  return AVERROR_INVALIDDATA;
354  }
355  s->avctx->channels = s->channels;
356 
357  /* get blocksize if version > 0 */
358  if (s->version > 0) {
359  int skip_bytes;
360  unsigned blocksize;
361 
362  blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE));
363  if (!blocksize || blocksize > MAX_BLOCKSIZE) {
365  "invalid or unsupported block size: %d\n",
366  blocksize);
367  return AVERROR(EINVAL);
368  }
369  s->blocksize = blocksize;
370 
371  maxnlpc = get_uint(s, LPCQSIZE);
372  if (maxnlpc > 1024U) {
373  av_log(s->avctx, AV_LOG_ERROR, "maxnlpc is: %d\n", maxnlpc);
374  return AVERROR_INVALIDDATA;
375  }
376  s->nmean = get_uint(s, 0);
377  if (s->nmean > 32768U) {
378  av_log(s->avctx, AV_LOG_ERROR, "nmean is: %d\n", s->nmean);
379  return AVERROR_INVALIDDATA;
380  }
381 
382  skip_bytes = get_uint(s, NSKIPSIZE);
383  if ((unsigned)skip_bytes > get_bits_left(&s->gb)/8) {
384  av_log(s->avctx, AV_LOG_ERROR, "invalid skip_bytes: %d\n", skip_bytes);
385  return AVERROR_INVALIDDATA;
386  }
387 
388  for (i = 0; i < skip_bytes; i++)
389  skip_bits(&s->gb, 8);
390  }
391  s->nwrap = FFMAX(NWRAP, maxnlpc);
392 
393  if ((ret = allocate_buffers(s)) < 0)
394  return ret;
395 
396  if ((ret = init_offset(s)) < 0)
397  return ret;
398 
399  if (s->version > 1)
401 
404  "missing verbatim section at beginning of stream\n");
405  return AVERROR_INVALIDDATA;
406  }
407 
409  if (s->header_size >= OUT_BUFFER_SIZE ||
411  av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n",
412  s->header_size);
413  return AVERROR_INVALIDDATA;
414  }
415 
416  for (i = 0; i < s->header_size; i++)
418 
419  if ((ret = decode_wave_header(s->avctx, s->header, s->header_size)) < 0)
420  return ret;
421 
422  s->cur_chan = 0;
423  s->bitshift = 0;
424 
425  s->got_header = 1;
426 
427  return 0;
428 }
429 
430 static int shorten_decode_frame(AVCodecContext *avctx, void *data,
431  int *got_frame_ptr, AVPacket *avpkt)
432 {
433  AVFrame *frame = data;
434  const uint8_t *buf = avpkt->data;
435  int buf_size = avpkt->size;
436  ShortenContext *s = avctx->priv_data;
437  int i, input_buf_size = 0;
438  int ret;
439 
440  /* allocate internal bitstream buffer */
441  if (s->max_framesize == 0) {
442  void *tmp_ptr;
443  s->max_framesize = 8192; // should hopefully be enough for the first header
446  if (!tmp_ptr) {
447  av_log(avctx, AV_LOG_ERROR, "error allocating bitstream buffer\n");
448  return AVERROR(ENOMEM);
449  }
450  memset(tmp_ptr, 0, s->allocated_bitstream_size);
451  s->bitstream = tmp_ptr;
452  }
453 
454  /* append current packet data to bitstream buffer */
455  if (1 && s->max_framesize) { //FIXME truncated
456  buf_size = FFMIN(buf_size, s->max_framesize - s->bitstream_size);
457  input_buf_size = buf_size;
458 
461  memmove(s->bitstream, &s->bitstream[s->bitstream_index],
462  s->bitstream_size);
463  s->bitstream_index = 0;
464  }
465  if (buf)
466  memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf,
467  buf_size);
468  buf = &s->bitstream[s->bitstream_index];
469  buf_size += s->bitstream_size;
470  s->bitstream_size = buf_size;
471 
472  /* do not decode until buffer has at least max_framesize bytes or
473  * the end of the file has been reached */
474  if (buf_size < s->max_framesize && avpkt->data) {
475  *got_frame_ptr = 0;
476  return input_buf_size;
477  }
478  }
479  /* init and position bitstream reader */
480  if ((ret = init_get_bits8(&s->gb, buf, buf_size)) < 0)
481  return ret;
482  skip_bits(&s->gb, s->bitindex);
483 
484  /* process header or next subblock */
485  if (!s->got_header) {
486  if ((ret = read_header(s)) < 0)
487  return ret;
488  *got_frame_ptr = 0;
489  goto finish_frame;
490  }
491 
492  /* if quit command was read previously, don't decode anything */
493  if (s->got_quit_command) {
494  *got_frame_ptr = 0;
495  return avpkt->size;
496  }
497 
498  s->cur_chan = 0;
499  while (s->cur_chan < s->channels) {
500  unsigned cmd;
501  int len;
502 
503  if (get_bits_left(&s->gb) < 3 + FNSIZE) {
504  *got_frame_ptr = 0;
505  break;
506  }
507 
508  cmd = get_ur_golomb_shorten(&s->gb, FNSIZE);
509 
510  if (cmd > FN_VERBATIM) {
511  av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd);
512  *got_frame_ptr = 0;
513  break;
514  }
515 
516  if (!is_audio_command[cmd]) {
517  /* process non-audio command */
518  switch (cmd) {
519  case FN_VERBATIM:
521  while (len--)
523  break;
524  case FN_BITSHIFT: {
525  unsigned bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE);
526  if (bitshift > 31) {
527  av_log(avctx, AV_LOG_ERROR, "bitshift %d is invalid\n",
528  bitshift);
529  return AVERROR_INVALIDDATA;
530  }
531  s->bitshift = bitshift;
532  break;
533  }
534  case FN_BLOCKSIZE: {
535  unsigned blocksize = get_uint(s, av_log2(s->blocksize));
536  if (blocksize > s->blocksize) {
537  av_log(avctx, AV_LOG_ERROR,
538  "Increasing block size is not supported\n");
539  return AVERROR_PATCHWELCOME;
540  }
541  if (!blocksize || blocksize > MAX_BLOCKSIZE) {
542  av_log(avctx, AV_LOG_ERROR, "invalid or unsupported "
543  "block size: %d\n", blocksize);
544  return AVERROR(EINVAL);
545  }
546  s->blocksize = blocksize;
547  break;
548  }
549  case FN_QUIT:
550  s->got_quit_command = 1;
551  break;
552  }
553  if (cmd == FN_BLOCKSIZE || cmd == FN_QUIT) {
554  *got_frame_ptr = 0;
555  break;
556  }
557  } else {
558  /* process audio command */
559  int residual_size = 0;
560  int channel = s->cur_chan;
561  int32_t coffset;
562 
563  /* get Rice code for residual decoding */
564  if (cmd != FN_ZERO) {
565  residual_size = get_ur_golomb_shorten(&s->gb, ENERGYSIZE);
566  /* This is a hack as version 0 differed in the definition
567  * of get_sr_golomb_shorten(). */
568  if (s->version == 0)
569  residual_size--;
570  }
571 
572  /* calculate sample offset using means from previous blocks */
573  if (s->nmean == 0)
574  coffset = s->offset[channel][0];
575  else {
576  int32_t sum = (s->version < 2) ? 0 : s->nmean / 2;
577  for (i = 0; i < s->nmean; i++)
578  sum += (unsigned)s->offset[channel][i];
579  coffset = sum / s->nmean;
580  if (s->version >= 2)
581  coffset = s->bitshift == 0 ? coffset : coffset >> s->bitshift - 1 >> 1;
582  }
583 
584  /* decode samples for this channel */
585  if (cmd == FN_ZERO) {
586  for (i = 0; i < s->blocksize; i++)
587  s->decoded[channel][i] = 0;
588  } else {
589  if ((ret = decode_subframe_lpc(s, cmd, channel,
590  residual_size, coffset)) < 0)
591  return ret;
592  }
593 
594  /* update means with info from the current block */
595  if (s->nmean > 0) {
596  int64_t sum = (s->version < 2) ? 0 : s->blocksize / 2;
597  for (i = 0; i < s->blocksize; i++)
598  sum += s->decoded[channel][i];
599 
600  for (i = 1; i < s->nmean; i++)
601  s->offset[channel][i - 1] = s->offset[channel][i];
602 
603  if (s->version < 2)
604  s->offset[channel][s->nmean - 1] = sum / s->blocksize;
605  else
606  s->offset[channel][s->nmean - 1] = (sum / s->blocksize) << s->bitshift;
607  }
608 
609  /* copy wrap samples for use with next block */
610  for (i = -s->nwrap; i < 0; i++)
611  s->decoded[channel][i] = s->decoded[channel][i + s->blocksize];
612 
613  /* shift samples to add in unused zero bits which were removed
614  * during encoding */
615  fix_bitshift(s, s->decoded[channel]);
616 
617  /* if this is the last channel in the block, output the samples */
618  s->cur_chan++;
619  if (s->cur_chan == s->channels) {
620  uint8_t *samples_u8;
621  int16_t *samples_s16;
622  int chan;
623 
624  /* get output buffer */
625  frame->nb_samples = s->blocksize;
626  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
627  return ret;
628 
629  for (chan = 0; chan < s->channels; chan++) {
630  samples_u8 = ((uint8_t **)frame->extended_data)[chan];
631  samples_s16 = ((int16_t **)frame->extended_data)[chan];
632  for (i = 0; i < s->blocksize; i++) {
633  switch (s->internal_ftype) {
634  case TYPE_U8:
635  *samples_u8++ = av_clip_uint8(s->decoded[chan][i]);
636  break;
637  case TYPE_S16HL:
638  case TYPE_S16LH:
639  *samples_s16++ = av_clip_int16(s->decoded[chan][i]);
640  break;
641  }
642  }
643  }
644 
645  *got_frame_ptr = 1;
646  }
647  }
648  }
649  if (s->cur_chan < s->channels)
650  *got_frame_ptr = 0;
651 
653  s->bitindex = get_bits_count(&s->gb) - 8 * (get_bits_count(&s->gb) / 8);
654  i = get_bits_count(&s->gb) / 8;
655  if (i > buf_size) {
656  av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size);
657  s->bitstream_size = 0;
658  s->bitstream_index = 0;
659  return AVERROR_INVALIDDATA;
660  }
661  if (s->bitstream_size) {
662  s->bitstream_index += i;
663  s->bitstream_size -= i;
664  return input_buf_size;
665  } else
666  return i;
667 }
668 
670 {
671  ShortenContext *s = avctx->priv_data;
672  int i;
673 
674  for (i = 0; i < s->channels; i++) {
675  s->decoded[i] = NULL;
676  av_freep(&s->decoded_base[i]);
677  av_freep(&s->offset[i]);
678  }
679  av_freep(&s->bitstream);
680  av_freep(&s->coeffs);
681 
682  return 0;
683 }
684 
686  .name = "shorten",
687  .long_name = NULL_IF_CONFIG_SMALL("Shorten"),
688  .type = AVMEDIA_TYPE_AUDIO,
689  .id = AV_CODEC_ID_SHORTEN,
690  .priv_data_size = sizeof(ShortenContext),
692  .close = shorten_decode_close,
694  .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1,
695  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
698 };
#define NSKIPSIZE
Definition: shorten.c:61
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:631
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
This structure describes decoded (raw) audio or video data.
Definition: frame.h:171
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
#define ENERGYSIZE
Definition: shorten.c:50
#define VERBATIM_CKSIZE_SIZE
Definition: shorten.c:81
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:261
int internal_ftype
Definition: shorten.c:106
static int init_offset(ShortenContext *s)
Definition: shorten.c:176
#define FN_BITSHIFT
Definition: shorten.c:73
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define OUT_BUFFER_SIZE
Definition: shorten.c:39
unsigned int allocated_bitstream_size
Definition: shorten.c:99
int32_t * decoded[MAX_CHANNELS]
Definition: shorten.c:92
int size
Definition: avcodec.h:1434
static const int fixed_coeffs[][3]
Definition: shorten.c:267
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:133
static int finish_frame(AVCodecContext *avctx, AVFrame *pict)
Definition: rv34.c:1597
AVCodec.
Definition: avcodec.h:3482
AVCodec ff_shorten_decoder
Definition: shorten.c:685
static av_cold int shorten_decode_init(AVCodecContext *avctx)
Definition: shorten.c:115
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:882
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2280
uint8_t
#define av_cold
Definition: attributes.h:74
#define AV_RB32
Definition: intreadwrite.h:130
static AVFrame * frame
#define LPCQSIZE
Definition: shorten.c:49
static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header, int header_size)
Definition: shorten.c:202
uint8_t * data
Definition: avcodec.h:1433
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:213
GetBitContext gb
Definition: shorten.c:87
#define FNSIZE
Definition: shorten.c:66
bitstream reader API header.
#define FN_QLPC
Definition: shorten.c:74
#define FN_VERBATIM
Definition: shorten.c:76
static const uint8_t header[24]
Definition: sdr2.c:67
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
Definition: avcodec.h:3006
static av_unused const uint8_t * skip_bytes(CABACContext *c, int n)
Skip n bytes and reset the decoder.
AVCodecContext * avctx
Definition: shorten.c:86
int32_t * decoded_base[MAX_CHANNELS]
Definition: shorten.c:93
#define av_log(a,...)
#define U(x)
Definition: vp56_arith.h:37
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:594
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:215
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given block if it is not large enough, otherwise do nothing.
Definition: mem.c:480
int min_framesize
Definition: shorten.c:89
#define AVERROR(e)
Definition: error.h:43
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:164
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:178
static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:154
unsigned channels
Definition: shorten.c:90
const char * name
Name of the codec implementation.
Definition: avcodec.h:3489
#define FN_BLOCKSIZE
Definition: shorten.c:72
#define FFMAX(a, b)
Definition: common.h:90
Libavcodec external API header.
#define BITSHIFTSIZE
Definition: shorten.c:51
#define NWRAP
Definition: shorten.c:60
int got_header
Definition: shorten.c:111
static int allocate_buffers(ShortenContext *s)
Definition: shorten.c:123
static void fix_bitshift(ShortenContext *s, int32_t *buffer)
Definition: shorten.c:167
int got_quit_command
Definition: shorten.c:112
#define FFMIN(a, b)
Definition: common.h:92
#define MAX_BLOCKSIZE
Definition: shorten.c:37
int32_t
#define TYPESIZE
Definition: shorten.c:47
#define FN_QUIT
Definition: shorten.c:71
#define LPCQUANT
Definition: shorten.c:63
#define VERBATIM_BYTE_SIZE
Definition: shorten.c:82
unsigned 8 bits, planar
Definition: samplefmt.h:67
#define FF_ARRAY_ELEMS(a)
#define av_log2
Definition: intmath.h:100
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
#define CHANSIZE
Definition: shorten.c:48
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:59
int sample_rate
samples per second
Definition: avcodec.h:2272
uint8_t header[OUT_BUFFER_SIZE]
Definition: shorten.c:101
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:446
#define CANONICAL_HEADER_SIZE
Definition: shorten.c:83
int bitstream_size
Definition: shorten.c:97
main external API structure.
Definition: avcodec.h:1512
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Definition: vf_drawtext.c:765
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:1048
static av_cold int shorten_decode_close(AVCodecContext *avctx)
Definition: shorten.c:669
void * buf
Definition: avisynth_c.h:553
#define MAX_CHANNELS
Definition: shorten.c:36
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:298
int * coeffs
Definition: shorten.c:95
static int decode_subframe_lpc(ShortenContext *s, int command, int channel, int residual_size, int32_t coffset)
Definition: shorten.c:274
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:338
#define TYPE_S16HL
Definition: shorten.c:55
static unsigned int get_uint(ShortenContext *s, int k)
Definition: shorten.c:157
#define DEFAULT_BLOCK_SIZE
Definition: shorten.c:45
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Definition: ccaption_dec.c:521
#define ULONGSIZE
Definition: shorten.c:41
static int shorten_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: shorten.c:430
common internal api header.
if(ret< 0)
Definition: vf_mcdeint.c:280
uint8_t * bitstream
Definition: shorten.c:96
unsigned bps
Definition: movenc.c:1340
#define FN_ZERO
Definition: shorten.c:75
int max_framesize
Definition: shorten.c:89
int bitstream_index
Definition: shorten.c:98
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:636
int header_size
Definition: shorten.c:100
void * priv_data
Definition: avcodec.h:1554
int32_t * offset[MAX_CHANNELS]
Definition: shorten.c:94
#define WAVE_FORMAT_PCM
Definition: shorten.c:43
static const int16_t coeffs[]
int len
int channels
number of audio channels
Definition: avcodec.h:2273
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
#define av_freep(p)
signed 16 bits, planar
Definition: samplefmt.h:68
int32_t lpcqoffset
Definition: shorten.c:110
static const uint8_t is_audio_command[10]
indicates if the FN_* command is audio or non-audio
Definition: shorten.c:79
#define V2LPCQOFFSET
Definition: shorten.c:64
static int read_header(ShortenContext *s)
Definition: shorten.c:329
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:215
static unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k)
read unsigned golomb rice code (shorten).
Definition: golomb.h:387
#define MKTAG(a, b, c, d)
Definition: common.h:341
exp golomb vlc stuff
This structure stores compressed data.
Definition: avcodec.h:1410
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:225
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:857
for(j=16;j >0;--j)
#define TYPE_U8
Definition: shorten.c:54
GLuint buffer
Definition: opengl_enc.c:102
#define TYPE_S16LH
Definition: shorten.c:57
static int get_sr_golomb_shorten(GetBitContext *gb, int k)
read signed golomb rice code (shorten).
Definition: golomb.h:395