FFmpeg
ralf.c
Go to the documentation of this file.
1 /*
2  * RealAudio Lossless decoder
3  *
4  * Copyright (c) 2012 Konstantin Shishkov
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 /**
24  * @file
25  * This is a decoder for Real Audio Lossless format.
26  * Dedicated to the mastermind behind it, Ralph Wiggum.
27  */
28 
29 #include "libavutil/attributes.h"
31 #include "avcodec.h"
32 #include "get_bits.h"
33 #include "golomb.h"
34 #include "internal.h"
35 #include "unary.h"
36 #include "ralfdata.h"
37 
38 #define FILTER_NONE 0
39 #define FILTER_RAW 642
40 
41 typedef struct VLCSet {
45  VLC filter_coeffs[10][11];
48 } VLCSet;
49 
50 #define RALF_MAX_PKT_SIZE 8192
51 
52 typedef struct RALFContext {
53  int version;
57 
58  int filter_params; ///< combined filter parameters for the current channel data
59  int filter_length; ///< length of the filter for the current channel data
60  int filter_bits; ///< filter precision for the current channel data
62 
63  unsigned bias[2]; ///< a constant value added to channel data after filtering
64 
65  int num_blocks; ///< number of blocks inside the frame
67  int block_size[1 << 12]; ///< size of the blocks
68  int block_pts[1 << 12]; ///< block start time (in milliseconds)
69 
70  uint8_t pkt[16384];
71  int has_pkt;
72 } RALFContext;
73 
74 #define MAX_ELEMS 644 // no RALF table uses more than that
75 
76 static av_cold int init_ralf_vlc(VLC *vlc, const uint8_t *data, int elems)
77 {
78  uint8_t lens[MAX_ELEMS];
79  uint16_t codes[MAX_ELEMS];
80  int counts[17], prefixes[18];
81  int i, cur_len;
82  int max_bits = 0;
83  int nb = 0;
84 
85  for (i = 0; i <= 16; i++)
86  counts[i] = 0;
87  for (i = 0; i < elems; i++) {
88  cur_len = (nb ? *data & 0xF : *data >> 4) + 1;
89  counts[cur_len]++;
90  max_bits = FFMAX(max_bits, cur_len);
91  lens[i] = cur_len;
92  data += nb;
93  nb ^= 1;
94  }
95  prefixes[1] = 0;
96  for (i = 1; i <= 16; i++)
97  prefixes[i + 1] = (prefixes[i] + counts[i]) << 1;
98 
99  for (i = 0; i < elems; i++)
100  codes[i] = prefixes[lens[i]]++;
101 
102  return ff_init_vlc_sparse(vlc, FFMIN(max_bits, 9), elems,
103  lens, 1, 1, codes, 2, 2, NULL, 0, 0, 0);
104 }
105 
107 {
108  RALFContext *ctx = avctx->priv_data;
109  int i, j, k;
110 
111  for (i = 0; i < 3; i++) {
112  ff_free_vlc(&ctx->sets[i].filter_params);
113  ff_free_vlc(&ctx->sets[i].bias);
114  ff_free_vlc(&ctx->sets[i].coding_mode);
115  for (j = 0; j < 10; j++)
116  for (k = 0; k < 11; k++)
117  ff_free_vlc(&ctx->sets[i].filter_coeffs[j][k]);
118  for (j = 0; j < 15; j++)
119  ff_free_vlc(&ctx->sets[i].short_codes[j]);
120  for (j = 0; j < 125; j++)
121  ff_free_vlc(&ctx->sets[i].long_codes[j]);
122  }
123 
124  return 0;
125 }
126 
128 {
129  RALFContext *ctx = avctx->priv_data;
130  int i, j, k;
131  int ret;
132 
133  if (avctx->extradata_size < 24 || memcmp(avctx->extradata, "LSD:", 4)) {
134  av_log(avctx, AV_LOG_ERROR, "Extradata is not groovy, dude\n");
135  return AVERROR_INVALIDDATA;
136  }
137 
138  ctx->version = AV_RB16(avctx->extradata + 4);
139  if (ctx->version != 0x103) {
140  avpriv_request_sample(avctx, "Unknown version %X", ctx->version);
141  return AVERROR_PATCHWELCOME;
142  }
143 
144  avctx->channels = AV_RB16(avctx->extradata + 8);
145  avctx->sample_rate = AV_RB32(avctx->extradata + 12);
146  if (avctx->channels < 1 || avctx->channels > 2
147  || avctx->sample_rate < 8000 || avctx->sample_rate > 96000) {
148  av_log(avctx, AV_LOG_ERROR, "Invalid coding parameters %d Hz %d ch\n",
149  avctx->sample_rate, avctx->channels);
150  return AVERROR_INVALIDDATA;
151  }
153  avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO
155 
156  ctx->max_frame_size = AV_RB32(avctx->extradata + 16);
157  if (ctx->max_frame_size > (1 << 20) || !ctx->max_frame_size) {
158  av_log(avctx, AV_LOG_ERROR, "invalid frame size %d\n",
159  ctx->max_frame_size);
160  }
161  ctx->max_frame_size = FFMAX(ctx->max_frame_size, avctx->sample_rate);
162 
163  for (i = 0; i < 3; i++) {
164  ret = init_ralf_vlc(&ctx->sets[i].filter_params, filter_param_def[i],
166  if (ret < 0) {
167  decode_close(avctx);
168  return ret;
169  }
170  ret = init_ralf_vlc(&ctx->sets[i].bias, bias_def[i], BIAS_ELEMENTS);
171  if (ret < 0) {
172  decode_close(avctx);
173  return ret;
174  }
175  ret = init_ralf_vlc(&ctx->sets[i].coding_mode, coding_mode_def[i],
177  if (ret < 0) {
178  decode_close(avctx);
179  return ret;
180  }
181  for (j = 0; j < 10; j++) {
182  for (k = 0; k < 11; k++) {
183  ret = init_ralf_vlc(&ctx->sets[i].filter_coeffs[j][k],
184  filter_coeffs_def[i][j][k],
186  if (ret < 0) {
187  decode_close(avctx);
188  return ret;
189  }
190  }
191  }
192  for (j = 0; j < 15; j++) {
193  ret = init_ralf_vlc(&ctx->sets[i].short_codes[j],
195  if (ret < 0) {
196  decode_close(avctx);
197  return ret;
198  }
199  }
200  for (j = 0; j < 125; j++) {
201  ret = init_ralf_vlc(&ctx->sets[i].long_codes[j],
203  if (ret < 0) {
204  decode_close(avctx);
205  return ret;
206  }
207  }
208  }
209 
210  return 0;
211 }
212 
213 static inline int extend_code(GetBitContext *gb, int val, int range, int bits)
214 {
215  if (val == 0) {
216  val = -range - get_ue_golomb(gb);
217  } else if (val == range * 2) {
218  val = range + get_ue_golomb(gb);
219  } else {
220  val -= range;
221  }
222  if (bits)
223  val = ((unsigned)val << bits) | get_bits(gb, bits);
224  return val;
225 }
226 
227 static int decode_channel(RALFContext *ctx, GetBitContext *gb, int ch,
228  int length, int mode, int bits)
229 {
230  int i, t;
231  int code_params;
232  VLCSet *set = ctx->sets + mode;
233  VLC *code_vlc; int range, range2, add_bits;
234  int *dst = ctx->channel_data[ch];
235 
236  ctx->filter_params = get_vlc2(gb, set->filter_params.table, 9, 2);
237  if (ctx->filter_params > 1) {
238  ctx->filter_bits = (ctx->filter_params - 2) >> 6;
239  ctx->filter_length = ctx->filter_params - (ctx->filter_bits << 6) - 1;
240  }
241 
242  if (ctx->filter_params == FILTER_RAW) {
243  for (i = 0; i < length; i++)
244  dst[i] = get_bits(gb, bits);
245  ctx->bias[ch] = 0;
246  return 0;
247  }
248 
249  ctx->bias[ch] = get_vlc2(gb, set->bias.table, 9, 2);
250  ctx->bias[ch] = extend_code(gb, ctx->bias[ch], 127, 4);
251 
252  if (ctx->filter_params == FILTER_NONE) {
253  memset(dst, 0, sizeof(*dst) * length);
254  return 0;
255  }
256 
257  if (ctx->filter_params > 1) {
258  int cmode = 0, coeff = 0;
259  VLC *vlc = set->filter_coeffs[ctx->filter_bits] + 5;
260 
261  add_bits = ctx->filter_bits;
262 
263  for (i = 0; i < ctx->filter_length; i++) {
264  t = get_vlc2(gb, vlc[cmode].table, vlc[cmode].bits, 2);
265  t = extend_code(gb, t, 21, add_bits);
266  if (!cmode)
267  coeff -= 12U << add_bits;
268  coeff = (unsigned)t - coeff;
269  ctx->filter[i] = coeff;
270 
271  cmode = coeff >> add_bits;
272  if (cmode < 0) {
273  cmode = -1 - av_log2(-cmode);
274  if (cmode < -5)
275  cmode = -5;
276  } else if (cmode > 0) {
277  cmode = 1 + av_log2(cmode);
278  if (cmode > 5)
279  cmode = 5;
280  }
281  }
282  }
283 
284  code_params = get_vlc2(gb, set->coding_mode.table, set->coding_mode.bits, 2);
285  if (code_params >= 15) {
286  add_bits = av_clip((code_params / 5 - 3) / 2, 0, 10);
287  if (add_bits > 9 && (code_params % 5) != 2)
288  add_bits--;
289  range = 10;
290  range2 = 21;
291  code_vlc = set->long_codes + (code_params - 15);
292  } else {
293  add_bits = 0;
294  range = 6;
295  range2 = 13;
296  code_vlc = set->short_codes + code_params;
297  }
298 
299  for (i = 0; i < length; i += 2) {
300  int code1, code2;
301 
302  t = get_vlc2(gb, code_vlc->table, code_vlc->bits, 2);
303  code1 = t / range2;
304  code2 = t % range2;
305  dst[i] = extend_code(gb, code1, range, 0) * (1U << add_bits);
306  dst[i + 1] = extend_code(gb, code2, range, 0) * (1U << add_bits);
307  if (add_bits) {
308  dst[i] |= get_bits(gb, add_bits);
309  dst[i + 1] |= get_bits(gb, add_bits);
310  }
311  }
312 
313  return 0;
314 }
315 
316 static void apply_lpc(RALFContext *ctx, int ch, int length, int bits)
317 {
318  int i, j, acc;
319  int *audio = ctx->channel_data[ch];
320  int bias = 1 << (ctx->filter_bits - 1);
321  int max_clip = (1 << bits) - 1, min_clip = -max_clip - 1;
322 
323  for (i = 1; i < length; i++) {
324  int flen = FFMIN(ctx->filter_length, i);
325 
326  acc = 0;
327  for (j = 0; j < flen; j++)
328  acc += (unsigned)ctx->filter[j] * audio[i - j - 1];
329  if (acc < 0) {
330  acc = (acc + bias - 1) >> ctx->filter_bits;
331  acc = FFMAX(acc, min_clip);
332  } else {
333  acc = ((unsigned)acc + bias) >> ctx->filter_bits;
334  acc = FFMIN(acc, max_clip);
335  }
336  audio[i] += acc;
337  }
338 }
339 
341  int16_t *dst0, int16_t *dst1)
342 {
343  RALFContext *ctx = avctx->priv_data;
344  int len, ch, ret;
345  int dmode, mode[2], bits[2];
346  int *ch0, *ch1;
347  int i;
348  unsigned int t, t2;
349 
350  len = 12 - get_unary(gb, 0, 6);
351 
352  if (len <= 7) len ^= 1; // codes for length = 6 and 7 are swapped
353  len = 1 << len;
354 
355  if (ctx->sample_offset + len > ctx->max_frame_size) {
356  av_log(avctx, AV_LOG_ERROR,
357  "Decoder's stomach is crying, it ate too many samples\n");
358  return AVERROR_INVALIDDATA;
359  }
360 
361  if (avctx->channels > 1)
362  dmode = get_bits(gb, 2) + 1;
363  else
364  dmode = 0;
365 
366  mode[0] = (dmode == 4) ? 1 : 0;
367  mode[1] = (dmode >= 2) ? 2 : 0;
368  bits[0] = 16;
369  bits[1] = (mode[1] == 2) ? 17 : 16;
370 
371  for (ch = 0; ch < avctx->channels; ch++) {
372  if ((ret = decode_channel(ctx, gb, ch, len, mode[ch], bits[ch])) < 0)
373  return ret;
374  if (ctx->filter_params > 1 && ctx->filter_params != FILTER_RAW) {
375  ctx->filter_bits += 3;
376  apply_lpc(ctx, ch, len, bits[ch]);
377  }
378  if (get_bits_left(gb) < 0)
379  return AVERROR_INVALIDDATA;
380  }
381  ch0 = ctx->channel_data[0];
382  ch1 = ctx->channel_data[1];
383  switch (dmode) {
384  case 0:
385  for (i = 0; i < len; i++)
386  dst0[i] = ch0[i] + ctx->bias[0];
387  break;
388  case 1:
389  for (i = 0; i < len; i++) {
390  dst0[i] = ch0[i] + ctx->bias[0];
391  dst1[i] = ch1[i] + ctx->bias[1];
392  }
393  break;
394  case 2:
395  for (i = 0; i < len; i++) {
396  ch0[i] += ctx->bias[0];
397  dst0[i] = ch0[i];
398  dst1[i] = ch0[i] - (ch1[i] + ctx->bias[1]);
399  }
400  break;
401  case 3:
402  for (i = 0; i < len; i++) {
403  t = ch0[i] + ctx->bias[0];
404  t2 = ch1[i] + ctx->bias[1];
405  dst0[i] = t + t2;
406  dst1[i] = t;
407  }
408  break;
409  case 4:
410  for (i = 0; i < len; i++) {
411  t = ch1[i] + ctx->bias[1];
412  t2 = ((ch0[i] + ctx->bias[0]) * 2) | (t & 1);
413  dst0[i] = (int)(t2 + t) / 2;
414  dst1[i] = (int)(t2 - t) / 2;
415  }
416  break;
417  }
418 
419  ctx->sample_offset += len;
420 
421  return 0;
422 }
423 
424 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
425  AVPacket *avpkt)
426 {
427  RALFContext *ctx = avctx->priv_data;
428  AVFrame *frame = data;
429  int16_t *samples0;
430  int16_t *samples1;
431  int ret;
432  GetBitContext gb;
433  int table_size, table_bytes, i;
434  const uint8_t *src, *block_pointer;
435  int src_size;
436  int bytes_left;
437 
438  if (ctx->has_pkt) {
439  ctx->has_pkt = 0;
440  table_bytes = (AV_RB16(avpkt->data) + 7) >> 3;
441  if (table_bytes + 3 > avpkt->size || avpkt->size > RALF_MAX_PKT_SIZE) {
442  av_log(avctx, AV_LOG_ERROR, "Wrong packet's breath smells of wrong data!\n");
443  return AVERROR_INVALIDDATA;
444  }
445  if (memcmp(ctx->pkt, avpkt->data, 2 + table_bytes)) {
446  av_log(avctx, AV_LOG_ERROR, "Wrong packet tails are wrong!\n");
447  return AVERROR_INVALIDDATA;
448  }
449 
450  src = ctx->pkt;
451  src_size = RALF_MAX_PKT_SIZE + avpkt->size;
452  memcpy(ctx->pkt + RALF_MAX_PKT_SIZE, avpkt->data + 2 + table_bytes,
453  avpkt->size - 2 - table_bytes);
454  } else {
455  if (avpkt->size == RALF_MAX_PKT_SIZE) {
456  memcpy(ctx->pkt, avpkt->data, avpkt->size);
457  ctx->has_pkt = 1;
458  *got_frame_ptr = 0;
459 
460  return avpkt->size;
461  }
462  src = avpkt->data;
463  src_size = avpkt->size;
464  }
465 
466  frame->nb_samples = ctx->max_frame_size;
467  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
468  return ret;
469  samples0 = (int16_t *)frame->data[0];
470  samples1 = (int16_t *)frame->data[1];
471 
472  if (src_size < 5) {
473  av_log(avctx, AV_LOG_ERROR, "too short packets are too short!\n");
474  return AVERROR_INVALIDDATA;
475  }
476  table_size = AV_RB16(src);
477  table_bytes = (table_size + 7) >> 3;
478  if (src_size < table_bytes + 3) {
479  av_log(avctx, AV_LOG_ERROR, "short packets are short!\n");
480  return AVERROR_INVALIDDATA;
481  }
482  init_get_bits(&gb, src + 2, table_size);
483  ctx->num_blocks = 0;
484  while (get_bits_left(&gb) > 0) {
485  if (ctx->num_blocks >= FF_ARRAY_ELEMS(ctx->block_size))
486  return AVERROR_INVALIDDATA;
487  ctx->block_size[ctx->num_blocks] = get_bits(&gb, 13 + avctx->channels);
488  if (get_bits1(&gb)) {
489  ctx->block_pts[ctx->num_blocks] = get_bits(&gb, 9);
490  } else {
491  ctx->block_pts[ctx->num_blocks] = 0;
492  }
493  ctx->num_blocks++;
494  }
495 
496  block_pointer = src + table_bytes + 2;
497  bytes_left = src_size - table_bytes - 2;
498  ctx->sample_offset = 0;
499  for (i = 0; i < ctx->num_blocks; i++) {
500  if (bytes_left < ctx->block_size[i]) {
501  av_log(avctx, AV_LOG_ERROR, "I'm pedaling backwards\n");
502  break;
503  }
504  init_get_bits(&gb, block_pointer, ctx->block_size[i] * 8);
505  if (decode_block(avctx, &gb, samples0 + ctx->sample_offset,
506  samples1 + ctx->sample_offset) < 0) {
507  av_log(avctx, AV_LOG_ERROR, "Sir, I got carsick in your office. Not decoding the rest of packet.\n");
508  break;
509  }
510  block_pointer += ctx->block_size[i];
511  bytes_left -= ctx->block_size[i];
512  }
513 
514  frame->nb_samples = ctx->sample_offset;
515  *got_frame_ptr = ctx->sample_offset > 0;
516 
517  return avpkt->size;
518 }
519 
520 static void decode_flush(AVCodecContext *avctx)
521 {
522  RALFContext *ctx = avctx->priv_data;
523 
524  ctx->has_pkt = 0;
525 }
526 
527 
529  .name = "ralf",
530  .long_name = NULL_IF_CONFIG_SMALL("RealAudio Lossless"),
531  .type = AVMEDIA_TYPE_AUDIO,
532  .id = AV_CODEC_ID_RALF,
533  .priv_data_size = sizeof(RALFContext),
534  .init = decode_init,
535  .close = decode_close,
536  .decode = decode_frame,
537  .flush = decode_flush,
538  .capabilities = AV_CODEC_CAP_DR1,
539  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
541 };
LONG_CODES_ELEMENTS
#define LONG_CODES_ELEMENTS
Definition: ralfdata.h:33
decode_flush
static void decode_flush(AVCodecContext *avctx)
Definition: ralf.c:520
AVCodec
AVCodec.
Definition: codec.h:190
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:849
acc
int acc
Definition: yuv2rgb.c:555
AVCodecContext::channel_layout
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:1237
code_vlc
static VLC code_vlc
Definition: wnv1.c:45
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1186
RALFContext::num_blocks
int num_blocks
number of blocks inside the frame
Definition: ralf.c:65
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:716
coding_mode_def
static const uint8_t coding_mode_def[3][72]
Definition: ralfdata.h:163
AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_MONO
Definition: channel_layout.h:85
RALFContext
Definition: ralf.c:52
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:300
decode_close
static av_cold int decode_close(AVCodecContext *avctx)
Definition: ralf.c:106
get_ue_golomb
static int get_ue_golomb(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to 8190.
Definition: golomb.h:55
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:355
FILTER_RAW
#define FILTER_RAW
Definition: ralf.c:39
table
static const uint16_t table[]
Definition: prosumer.c:206
data
const char data[16]
Definition: mxf.c:91
decode_frame
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: ralf.c:424
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:797
RALFContext::has_pkt
int has_pkt
Definition: ralf.c:71
long_codes_def
static const uint8_t long_codes_def[3][125][224]
Definition: ralfdata.h:2036
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:659
BIAS_ELEMENTS
#define BIAS_ELEMENTS
Definition: ralfdata.h:29
short_codes_def
static const uint8_t short_codes_def[3][15][88]
Definition: ralfdata.h:1577
VLCSet
Definition: ralf.c:41
golomb.h
exp golomb vlc stuff
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
VLCSet::filter_params
VLC filter_params
Definition: ralf.c:42
U
#define U(x)
Definition: vp56_arith.h:37
SHORT_CODES_ELEMENTS
#define SHORT_CODES_ELEMENTS
Definition: ralfdata.h:32
decode_init
static av_cold int decode_init(AVCodecContext *avctx)
Definition: ralf.c:127
GetBitContext
Definition: get_bits.h:61
val
static double val(void *priv, double ch)
Definition: aeval.c:76
AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_STEREO
Definition: channel_layout.h:86
RALFContext::channel_data
int32_t channel_data[2][4096]
Definition: ralf.c:56
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
av_cold
#define av_cold
Definition: attributes.h:90
set
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)
Definition: swresample.c:59
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:628
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
bits
uint8_t bits
Definition: vp3data.h:202
MAX_ELEMS
#define MAX_ELEMS
Definition: ralf.c:74
ctx
AVFormatContext * ctx
Definition: movenc.c:48
FILTERPARAM_ELEMENTS
#define FILTERPARAM_ELEMENTS
Definition: ralfdata.h:28
get_bits.h
ff_ralf_decoder
AVCodec ff_ralf_decoder
Definition: ralf.c:528
ff_free_vlc
void ff_free_vlc(VLC *vlc)
Definition: bitstream.c:359
RALFContext::filter
int32_t filter[64]
Definition: ralf.c:61
AV_CODEC_ID_RALF
@ AV_CODEC_ID_RALF
Definition: codec_id.h:467
filter_coeffs_def
static const uint8_t filter_coeffs_def[3][10][11][24]
Definition: ralfdata.h:188
int32_t
int32_t
Definition: audio_convert.c:194
flush
static void flush(AVCodecContext *avctx)
Definition: aacdec_template.c:500
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
RALFContext::block_pts
int block_pts[1<< 12]
block start time (in milliseconds)
Definition: ralf.c:68
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
src
#define src
Definition: vp8dsp.c:254
RALFContext::block_size
int block_size[1<< 12]
size of the blocks
Definition: ralf.c:67
RALFContext::max_frame_size
int max_frame_size
Definition: ralf.c:54
ff_init_vlc_sparse
int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
Definition: bitstream.c:273
FILTER_NONE
#define FILTER_NONE
Definition: ralf.c:38
VLCSet::coding_mode
VLC coding_mode
Definition: ralf.c:44
get_unary
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
Definition: unary.h:46
for
for(j=16;j >0;--j)
Definition: h264pred_template.c:469
FILTER_COEFFS_ELEMENTS
#define FILTER_COEFFS_ELEMENTS
Definition: ralfdata.h:31
init_ralf_vlc
static av_cold int init_ralf_vlc(VLC *vlc, const uint8_t *data, int elems)
Definition: ralf.c:76
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1854
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:50
AVPacket::size
int size
Definition: packet.h:356
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
VLCSet::long_codes
VLC long_codes[125]
Definition: ralf.c:47
FFMAX
#define FFMAX(a, b)
Definition: common.h:94
RALFContext::pkt
uint8_t pkt[16384]
Definition: ralf.c:70
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1194
RALFContext::bias
unsigned bias[2]
a constant value added to channel data after filtering
Definition: ralf.c:63
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
AV_RB32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_RB32
Definition: bytestream.h:92
extend_code
static int extend_code(GetBitContext *gb, int val, int range, int bits)
Definition: ralf.c:213
FFMIN
#define FFMIN(a, b)
Definition: common.h:96
filter_param_def
static const uint8_t filter_param_def[3][324]
Definition: ralfdata.h:35
attributes.h
unary.h
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:67
RALFContext::filter_length
int filter_length
length of the filter for the current channel data
Definition: ralf.c:59
VLCSet::short_codes
VLC short_codes[15]
Definition: ralf.c:46
AVCodecContext::channels
int channels
number of audio channels
Definition: avcodec.h:1187
RALFContext::filter_params
int filter_params
combined filter parameters for the current channel data
Definition: ralf.c:58
bias_def
static const uint8_t bias_def[3][128]
Definition: ralfdata.h:123
decode_channel
static int decode_channel(RALFContext *ctx, GetBitContext *gb, int ch, int length, int mode, int bits)
Definition: ralf.c:227
RALF_MAX_PKT_SIZE
#define RALF_MAX_PKT_SIZE
Definition: ralf.c:50
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:627
apply_lpc
static void apply_lpc(RALFContext *ctx, int ch, int length, int bits)
Definition: ralf.c:316
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
uint8_t
uint8_t
Definition: audio_convert.c:194
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:197
len
int len
Definition: vorbis_enc_data.h:452
VLCSet::bias
VLC bias
Definition: ralf.c:43
avcodec.h
VLC::bits
int bits
Definition: vlc.h:27
ret
ret
Definition: filter_design.txt:187
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
RALFContext::version
int version
Definition: ralf.c:53
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen_template.c:38
AVCodecContext
main external API structure.
Definition: avcodec.h:526
channel_layout.h
t2
#define t2
Definition: regdef.h:30
mode
mode
Definition: ebur128.h:83
VLC
Definition: vlc.h:26
VLCSet::filter_coeffs
VLC filter_coeffs[10][11]
Definition: ralf.c:45
RALFContext::filter_bits
int filter_bits
filter precision for the current channel data
Definition: ralf.c:60
RALFContext::sample_offset
int sample_offset
Definition: ralf.c:66
decode_block
static int decode_block(AVCodecContext *avctx, GetBitContext *gb, int16_t *dst0, int16_t *dst1)
Definition: ralf.c:340
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:39
CODING_MODE_ELEMENTS
#define CODING_MODE_ELEMENTS
Definition: ralfdata.h:30
ralfdata.h
RALFContext::sets
VLCSet sets[3]
Definition: ralf.c:55
AVPacket
This structure stores compressed data.
Definition: packet.h:332
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:553
coeff
static const double coeff[2][5]
Definition: vf_owdenoise.c:72
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
int
int
Definition: ffmpeg_filter.c:192
VLC::table
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
AV_RB16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
Definition: bytestream.h:94