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;
126  int *coeffs;
127  void *tmp_ptr;
128 
129  for (chan = 0; chan < s->channels; chan++) {
130  if (FFMAX(1, s->nmean) >= UINT_MAX / sizeof(int32_t)) {
131  av_log(s->avctx, AV_LOG_ERROR, "nmean too large\n");
132  return AVERROR_INVALIDDATA;
133  }
134  if (s->blocksize + s->nwrap >= UINT_MAX / sizeof(int32_t) ||
135  s->blocksize + s->nwrap <= (unsigned)s->nwrap) {
137  "s->blocksize + s->nwrap too large\n");
138  return AVERROR_INVALIDDATA;
139  }
140 
141  tmp_ptr =
142  av_realloc(s->offset[chan], sizeof(int32_t) * FFMAX(1, s->nmean));
143  if (!tmp_ptr)
144  return AVERROR(ENOMEM);
145  s->offset[chan] = tmp_ptr;
146 
147  tmp_ptr = av_realloc(s->decoded_base[chan], (s->blocksize + s->nwrap) *
148  sizeof(s->decoded_base[0][0]));
149  if (!tmp_ptr)
150  return AVERROR(ENOMEM);
151  s->decoded_base[chan] = tmp_ptr;
152  for (i = 0; i < s->nwrap; i++)
153  s->decoded_base[chan][i] = 0;
154  s->decoded[chan] = s->decoded_base[chan] + s->nwrap;
155  }
156 
157  coeffs = av_realloc(s->coeffs, s->nwrap * sizeof(*s->coeffs));
158  if (!coeffs)
159  return AVERROR(ENOMEM);
160  s->coeffs = coeffs;
161 
162  return 0;
163 }
164 
165 static inline unsigned int get_uint(ShortenContext *s, int k)
166 {
167  if (s->version != 0)
169  return get_ur_golomb_shorten(&s->gb, k);
170 }
171 
173 {
174  int i;
175 
176  if (s->bitshift != 0)
177  for (i = 0; i < s->blocksize; i++)
178  buffer[i] <<= s->bitshift;
179 }
180 
182 {
183  int32_t mean = 0;
184  int chan, i;
185  int nblock = FFMAX(1, s->nmean);
186  /* initialise offset */
187  switch (s->internal_ftype) {
188  case TYPE_U8:
190  mean = 0x80;
191  break;
192  case TYPE_S16HL:
193  case TYPE_S16LH:
195  break;
196  default:
197  av_log(s->avctx, AV_LOG_ERROR, "unknown audio type\n");
198  return AVERROR_PATCHWELCOME;
199  }
200 
201  for (chan = 0; chan < s->channels; chan++)
202  for (i = 0; i < nblock; i++)
203  s->offset[chan][i] = mean;
204  return 0;
205 }
206 
208  int header_size)
209 {
210  int len, bps;
211  short wave_format;
212  const uint8_t *end= header + header_size;
213 
214  if (bytestream_get_le32(&header) != MKTAG('R', 'I', 'F', 'F')) {
215  av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n");
216  return AVERROR_INVALIDDATA;
217  }
218 
219  header += 4; /* chunk size */
220 
221  if (bytestream_get_le32(&header) != MKTAG('W', 'A', 'V', 'E')) {
222  av_log(avctx, AV_LOG_ERROR, "missing WAVE tag\n");
223  return AVERROR_INVALIDDATA;
224  }
225 
226  while (bytestream_get_le32(&header) != MKTAG('f', 'm', 't', ' ')) {
227  len = bytestream_get_le32(&header);
228  if (len<0 || end - header - 8 < len)
229  return AVERROR_INVALIDDATA;
230  header += len;
231  }
232  len = bytestream_get_le32(&header);
233 
234  if (len < 16) {
235  av_log(avctx, AV_LOG_ERROR, "fmt chunk was too short\n");
236  return AVERROR_INVALIDDATA;
237  }
238 
239  wave_format = bytestream_get_le16(&header);
240 
241  switch (wave_format) {
242  case WAVE_FORMAT_PCM:
243  break;
244  default:
245  av_log(avctx, AV_LOG_ERROR, "unsupported wave format\n");
246  return AVERROR(ENOSYS);
247  }
248 
249  header += 2; // skip channels (already got from shorten header)
250  avctx->sample_rate = bytestream_get_le32(&header);
251  header += 4; // skip bit rate (represents original uncompressed bit rate)
252  header += 2; // skip block align (not needed)
253  bps = bytestream_get_le16(&header);
254  avctx->bits_per_coded_sample = bps;
255 
256  if (bps != 16 && bps != 8) {
257  av_log(avctx, AV_LOG_ERROR, "unsupported number of bits per sample: %d\n", bps);
258  return AVERROR(ENOSYS);
259  }
260 
261  len -= 16;
262  if (len > 0)
263  av_log(avctx, AV_LOG_INFO, "%d header bytes unparsed\n", len);
264 
265  return 0;
266 }
267 
268 static const int fixed_coeffs[3][3] = {
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 (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  coeffs = fixed_coeffs[pred_order - 1];
298  qshift = 0;
299  }
300 
301  /* subtract offset from previous samples to use in prediction */
302  if (command == FN_QLPC && coffset)
303  for (i = -pred_order; i < 0; i++)
304  s->decoded[channel][i] -= coffset;
305 
306  /* decode residual and do LPC prediction */
307  init_sum = pred_order ? (command == FN_QLPC ? s->lpcqoffset : 0) : coffset;
308  for (i = 0; i < s->blocksize; i++) {
309  sum = init_sum;
310  for (j = 0; j < pred_order; j++)
311  sum += coeffs[j] * s->decoded[channel][i - j - 1];
312  s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) +
313  (sum >> qshift);
314  }
315 
316  /* add offset to current samples */
317  if (command == FN_QLPC && coffset)
318  for (i = 0; i < s->blocksize; i++)
319  s->decoded[channel][i] += coffset;
320 
321  return 0;
322 }
323 
325 {
326  int i, ret;
327  int maxnlpc = 0;
328  /* shorten signature */
329  if (get_bits_long(&s->gb, 32) != AV_RB32("ajkg")) {
330  av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic 'ajkg'\n");
331  return AVERROR_INVALIDDATA;
332  }
333 
334  s->lpcqoffset = 0;
336  s->nmean = -1;
337  s->version = get_bits(&s->gb, 8);
339 
340  s->channels = get_uint(s, CHANSIZE);
341  if (!s->channels) {
342  av_log(s->avctx, AV_LOG_ERROR, "No channels reported\n");
343  return AVERROR_INVALIDDATA;
344  }
345  if (s->channels > MAX_CHANNELS) {
346  av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels);
347  s->channels = 0;
348  return AVERROR_INVALIDDATA;
349  }
350  s->avctx->channels = s->channels;
351 
352  /* get blocksize if version > 0 */
353  if (s->version > 0) {
354  int skip_bytes;
355  unsigned blocksize;
356 
357  blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE));
358  if (!blocksize || blocksize > MAX_BLOCKSIZE) {
360  "invalid or unsupported block size: %d\n",
361  blocksize);
362  return AVERROR(EINVAL);
363  }
364  s->blocksize = blocksize;
365 
366  maxnlpc = get_uint(s, LPCQSIZE);
367  s->nmean = get_uint(s, 0);
368 
369  skip_bytes = get_uint(s, NSKIPSIZE);
370  for (i = 0; i < skip_bytes; i++)
371  skip_bits(&s->gb, 8);
372  }
373  s->nwrap = FFMAX(NWRAP, maxnlpc);
374 
375  if ((ret = allocate_buffers(s)) < 0)
376  return ret;
377 
378  if ((ret = init_offset(s)) < 0)
379  return ret;
380 
381  if (s->version > 1)
383 
386  "missing verbatim section at beginning of stream\n");
387  return AVERROR_INVALIDDATA;
388  }
389 
391  if (s->header_size >= OUT_BUFFER_SIZE ||
393  av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n",
394  s->header_size);
395  return AVERROR_INVALIDDATA;
396  }
397 
398  for (i = 0; i < s->header_size; i++)
400 
401  if ((ret = decode_wave_header(s->avctx, s->header, s->header_size)) < 0)
402  return ret;
403 
404  s->cur_chan = 0;
405  s->bitshift = 0;
406 
407  s->got_header = 1;
408 
409  return 0;
410 }
411 
413  int *got_frame_ptr, AVPacket *avpkt)
414 {
415  AVFrame *frame = data;
416  const uint8_t *buf = avpkt->data;
417  int buf_size = avpkt->size;
418  ShortenContext *s = avctx->priv_data;
419  int i, input_buf_size = 0;
420  int ret;
421 
422  /* allocate internal bitstream buffer */
423  if (s->max_framesize == 0) {
424  void *tmp_ptr;
425  s->max_framesize = 8192; // should hopefully be enough for the first header
427  s->max_framesize);
428  if (!tmp_ptr) {
429  av_log(avctx, AV_LOG_ERROR, "error allocating bitstream buffer\n");
430  return AVERROR(ENOMEM);
431  }
432  s->bitstream = tmp_ptr;
433  }
434 
435  /* append current packet data to bitstream buffer */
436  if (1 && s->max_framesize) { //FIXME truncated
437  buf_size = FFMIN(buf_size, s->max_framesize - s->bitstream_size);
438  input_buf_size = buf_size;
439 
440  if (s->bitstream_index + s->bitstream_size + buf_size >
442  memmove(s->bitstream, &s->bitstream[s->bitstream_index],
443  s->bitstream_size);
444  s->bitstream_index = 0;
445  }
446  if (buf)
447  memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf,
448  buf_size);
449  buf = &s->bitstream[s->bitstream_index];
450  buf_size += s->bitstream_size;
451  s->bitstream_size = buf_size;
452 
453  /* do not decode until buffer has at least max_framesize bytes or
454  * the end of the file has been reached */
455  if (buf_size < s->max_framesize && avpkt->data) {
456  *got_frame_ptr = 0;
457  return input_buf_size;
458  }
459  }
460  /* init and position bitstream reader */
461  init_get_bits(&s->gb, buf, buf_size * 8);
462  skip_bits(&s->gb, s->bitindex);
463 
464  /* process header or next subblock */
465  if (!s->got_header) {
466  if ((ret = read_header(s)) < 0)
467  return ret;
468  *got_frame_ptr = 0;
469  goto finish_frame;
470  }
471 
472  /* if quit command was read previously, don't decode anything */
473  if (s->got_quit_command) {
474  *got_frame_ptr = 0;
475  return avpkt->size;
476  }
477 
478  s->cur_chan = 0;
479  while (s->cur_chan < s->channels) {
480  unsigned cmd;
481  int len;
482 
483  if (get_bits_left(&s->gb) < 3 + FNSIZE) {
484  *got_frame_ptr = 0;
485  break;
486  }
487 
488  cmd = get_ur_golomb_shorten(&s->gb, FNSIZE);
489 
490  if (cmd > FN_VERBATIM) {
491  av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd);
492  *got_frame_ptr = 0;
493  break;
494  }
495 
496  if (!is_audio_command[cmd]) {
497  /* process non-audio command */
498  switch (cmd) {
499  case FN_VERBATIM:
501  while (len--)
503  break;
504  case FN_BITSHIFT:
506  break;
507  case FN_BLOCKSIZE: {
508  unsigned blocksize = get_uint(s, av_log2(s->blocksize));
509  if (blocksize > s->blocksize) {
510  av_log(avctx, AV_LOG_ERROR,
511  "Increasing block size is not supported\n");
512  return AVERROR_PATCHWELCOME;
513  }
514  if (!blocksize || blocksize > MAX_BLOCKSIZE) {
515  av_log(avctx, AV_LOG_ERROR, "invalid or unsupported "
516  "block size: %d\n", blocksize);
517  return AVERROR(EINVAL);
518  }
519  s->blocksize = blocksize;
520  break;
521  }
522  case FN_QUIT:
523  s->got_quit_command = 1;
524  break;
525  }
526  if (cmd == FN_BLOCKSIZE || cmd == FN_QUIT) {
527  *got_frame_ptr = 0;
528  break;
529  }
530  } else {
531  /* process audio command */
532  int residual_size = 0;
533  int channel = s->cur_chan;
534  int32_t coffset;
535 
536  /* get Rice code for residual decoding */
537  if (cmd != FN_ZERO) {
538  residual_size = get_ur_golomb_shorten(&s->gb, ENERGYSIZE);
539  /* This is a hack as version 0 differed in the definition
540  * of get_sr_golomb_shorten(). */
541  if (s->version == 0)
542  residual_size--;
543  }
544 
545  /* calculate sample offset using means from previous blocks */
546  if (s->nmean == 0)
547  coffset = s->offset[channel][0];
548  else {
549  int32_t sum = (s->version < 2) ? 0 : s->nmean / 2;
550  for (i = 0; i < s->nmean; i++)
551  sum += s->offset[channel][i];
552  coffset = sum / s->nmean;
553  if (s->version >= 2)
554  coffset = s->bitshift == 0 ? coffset : coffset >> s->bitshift - 1 >> 1;
555  }
556 
557  /* decode samples for this channel */
558  if (cmd == FN_ZERO) {
559  for (i = 0; i < s->blocksize; i++)
560  s->decoded[channel][i] = 0;
561  } else {
562  if ((ret = decode_subframe_lpc(s, cmd, channel,
563  residual_size, coffset)) < 0)
564  return ret;
565  }
566 
567  /* update means with info from the current block */
568  if (s->nmean > 0) {
569  int32_t sum = (s->version < 2) ? 0 : s->blocksize / 2;
570  for (i = 0; i < s->blocksize; i++)
571  sum += s->decoded[channel][i];
572 
573  for (i = 1; i < s->nmean; i++)
574  s->offset[channel][i - 1] = s->offset[channel][i];
575 
576  if (s->version < 2)
577  s->offset[channel][s->nmean - 1] = sum / s->blocksize;
578  else
579  s->offset[channel][s->nmean - 1] = (sum / s->blocksize) << s->bitshift;
580  }
581 
582  /* copy wrap samples for use with next block */
583  for (i = -s->nwrap; i < 0; i++)
584  s->decoded[channel][i] = s->decoded[channel][i + s->blocksize];
585 
586  /* shift samples to add in unused zero bits which were removed
587  * during encoding */
588  fix_bitshift(s, s->decoded[channel]);
589 
590  /* if this is the last channel in the block, output the samples */
591  s->cur_chan++;
592  if (s->cur_chan == s->channels) {
593  uint8_t *samples_u8;
594  int16_t *samples_s16;
595  int chan;
596 
597  /* get output buffer */
598  frame->nb_samples = s->blocksize;
599  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
600  return ret;
601 
602  for (chan = 0; chan < s->channels; chan++) {
603  samples_u8 = ((uint8_t **)frame->extended_data)[chan];
604  samples_s16 = ((int16_t **)frame->extended_data)[chan];
605  for (i = 0; i < s->blocksize; i++) {
606  switch (s->internal_ftype) {
607  case TYPE_U8:
608  *samples_u8++ = av_clip_uint8(s->decoded[chan][i]);
609  break;
610  case TYPE_S16HL:
611  case TYPE_S16LH:
612  *samples_s16++ = av_clip_int16(s->decoded[chan][i]);
613  break;
614  }
615  }
616  }
617 
618  *got_frame_ptr = 1;
619  }
620  }
621  }
622  if (s->cur_chan < s->channels)
623  *got_frame_ptr = 0;
624 
626  s->bitindex = get_bits_count(&s->gb) - 8 * (get_bits_count(&s->gb) / 8);
627  i = get_bits_count(&s->gb) / 8;
628  if (i > buf_size) {
629  av_log(s->avctx, AV_LOG_ERROR, "overread: %d\n", i - buf_size);
630  s->bitstream_size = 0;
631  s->bitstream_index = 0;
632  return AVERROR_INVALIDDATA;
633  }
634  if (s->bitstream_size) {
635  s->bitstream_index += i;
636  s->bitstream_size -= i;
637  return input_buf_size;
638  } else
639  return i;
640 }
641 
643 {
644  ShortenContext *s = avctx->priv_data;
645  int i;
646 
647  for (i = 0; i < s->channels; i++) {
648  s->decoded[i] = NULL;
649  av_freep(&s->decoded_base[i]);
650  av_freep(&s->offset[i]);
651  }
652  av_freep(&s->bitstream);
653  av_freep(&s->coeffs);
654 
655  return 0;
656 }
657 
659  .name = "shorten",
660  .type = AVMEDIA_TYPE_AUDIO,
661  .id = AV_CODEC_ID_SHORTEN,
662  .priv_data_size = sizeof(ShortenContext),
666  .capabilities = CODEC_CAP_DELAY | CODEC_CAP_DR1,
667  .long_name = NULL_IF_CONFIG_SMALL("Shorten"),
668  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
671 };
#define NSKIPSIZE
Definition: shorten.c:61
const char * s
Definition: avisynth_c.h:668
#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:76
#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:240
int internal_ftype
Definition: shorten.c:106
static int init_offset(ShortenContext *s)
Definition: shorten.c:181
#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
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:141
static int finish_frame(AVCodecContext *avctx, AVFrame *pict)
Definition: rv34.c:1570
AVCodec ff_shorten_decoder
Definition: shorten.c:658
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
initialize output if(nPeaks >3)%at least 3 peaks in spectrum for trying to find f0 nf0peaks
static av_cold int shorten_decode_init(AVCodecContext *avctx)
Definition: shorten.c:115
enum AVSampleFormat sample_fmt
audio sample format
uint8_t
#define av_cold
Definition: attributes.h:78
#define AV_RB32
end end
static const int fixed_coeffs[3][3]
Definition: shorten.c:268
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
#define LPCQSIZE
Definition: shorten.c:49
static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header, int header_size)
Definition: shorten.c:207
uint8_t * data
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:193
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
struct ShortenContext ShortenContext
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
AVCodecContext * avctx
Definition: shorten.c:86
int32_t * decoded_base[MAX_CHANNELS]
Definition: shorten.c:93
frame
Definition: stft.m:14
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:557
int min_framesize
Definition: shorten.c:89
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.
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Spectrum Plot time data
unsigned channels
Definition: shorten.c:90
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:246
const char * name
Name of the codec implementation.
#define FN_BLOCKSIZE
Definition: shorten.c:72
#define FFMAX(a, b)
Definition: common.h:56
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:172
int got_quit_command
Definition: shorten.c:112
#define FFMIN(a, b)
Definition: common.h:58
ret
Definition: avfilter.c:821
#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
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
for k
NULL
Definition: eval.c:55
#define CHANSIZE
Definition: shorten.c:48
int sample_rate
samples per second
uint8_t header[OUT_BUFFER_SIZE]
Definition: shorten.c:101
#define CANONICAL_HEADER_SIZE
Definition: shorten.c:83
int bitstream_size
Definition: shorten.c:97
main external API structure.
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:375
static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags)
Definition: vf_drawtext.c:596
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:148
static av_cold int shorten_decode_close(AVCodecContext *avctx)
Definition: shorten.c:642
void * buf
Definition: avisynth_c.h:594
#define MAX_CHANNELS
Definition: shorten.c:36
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:265
synthesis window for stochastic i
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:379
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:306
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
#define TYPE_S16HL
Definition: shorten.c:55
static unsigned int get_uint(ShortenContext *s, int k)
Definition: shorten.c:165
#define DEFAULT_BLOCK_SIZE
Definition: shorten.c:45
#define ULONGSIZE
Definition: shorten.c:41
static int shorten_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: shorten.c:412
common internal api header.
uint8_t * bitstream
Definition: shorten.c:96
AVSampleFormat
Audio Sample Formats.
Definition: samplefmt.h:49
the buffer and buffer reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFilterBuffer structures They must not be accessed but through references stored in AVFilterBufferRef structures Several references can point to the same buffer
unsigned bps
Definition: movenc.c:895
#define FN_ZERO
Definition: shorten.c:75
int max_framesize
Definition: shorten.c:89
int bitstream_index
Definition: shorten.c:98
int header_size
Definition: shorten.c:100
int32_t * offset[MAX_CHANNELS]
Definition: shorten.c:94
#define WAVE_FORMAT_PCM
Definition: shorten.c:43
unsigned 8 bits, planar
Definition: samplefmt.h:57
int len
int channels
number of audio channels
#define av_log2
Definition: intmath.h:89
signed 16 bits, planar
Definition: samplefmt.h:58
#define AV_LOG_INFO
Definition: log.h:156
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: crystalhd.c:868
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:324
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:117
static unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k)
read unsigned golomb rice code (shorten).
Definition: golomb.h:366
#define MKTAG(a, b, c, d)
Definition: common.h:282
exp golomb vlc stuff
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:127
for(j=16;j >0;--j)
#define TYPE_U8
Definition: shorten.c:54
#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:373