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 "codec_internal.h"
33 #include "decode.h"
34 #include "get_bits.h"
35 #include "golomb.h"
36 #include "unary.h"
37 #include "ralfdata.h"
38 
39 #define FILTER_NONE 0
40 #define FILTER_RAW 642
41 
42 typedef struct VLCSet {
46  VLC filter_coeffs[10][11];
49 } VLCSet;
50 
51 #define RALF_MAX_PKT_SIZE 8192
52 
53 typedef struct RALFContext {
54  int version;
58 
59  int filter_params; ///< combined filter parameters for the current channel data
60  int filter_length; ///< length of the filter for the current channel data
61  int filter_bits; ///< filter precision for the current channel data
63 
64  unsigned bias[2]; ///< a constant value added to channel data after filtering
65 
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_vlc_init_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_vlc_free(&ctx->sets[i].filter_params);
113  ff_vlc_free(&ctx->sets[i].bias);
114  ff_vlc_free(&ctx->sets[i].coding_mode);
115  for (j = 0; j < 10; j++)
116  for (k = 0; k < 11; k++)
117  ff_vlc_free(&ctx->sets[i].filter_coeffs[j][k]);
118  for (j = 0; j < 15; j++)
119  ff_vlc_free(&ctx->sets[i].short_codes[j]);
120  for (j = 0; j < 125; j++)
121  ff_vlc_free(&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, channels;
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  channels = AV_RB16(avctx->extradata + 8);
145  avctx->sample_rate = AV_RB32(avctx->extradata + 12);
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, channels);
150  return AVERROR_INVALIDDATA;
151  }
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  return ret;
168  ret = init_ralf_vlc(&ctx->sets[i].bias, bias_def[i], BIAS_ELEMENTS);
169  if (ret < 0)
170  return ret;
171  ret = init_ralf_vlc(&ctx->sets[i].coding_mode, coding_mode_def[i],
173  if (ret < 0)
174  return ret;
175  for (j = 0; j < 10; j++) {
176  for (k = 0; k < 11; k++) {
177  ret = init_ralf_vlc(&ctx->sets[i].filter_coeffs[j][k],
178  filter_coeffs_def[i][j][k],
180  if (ret < 0)
181  return ret;
182  }
183  }
184  for (j = 0; j < 15; j++) {
185  ret = init_ralf_vlc(&ctx->sets[i].short_codes[j],
187  if (ret < 0)
188  return ret;
189  }
190  for (j = 0; j < 125; j++) {
191  ret = init_ralf_vlc(&ctx->sets[i].long_codes[j],
193  if (ret < 0)
194  return ret;
195  }
196  }
197 
198  return 0;
199 }
200 
201 static inline int extend_code(GetBitContext *gb, int val, int range, int bits)
202 {
203  if (val == 0) {
204  val = -range - get_ue_golomb(gb);
205  } else if (val == range * 2) {
206  val = range + get_ue_golomb(gb);
207  } else {
208  val -= range;
209  }
210  if (bits)
211  val = ((unsigned)val << bits) | get_bits(gb, bits);
212  return val;
213 }
214 
215 static int decode_channel(RALFContext *ctx, GetBitContext *gb, int ch,
216  int length, int mode, int bits)
217 {
218  int i, t;
219  int code_params;
220  VLCSet *set = ctx->sets + mode;
221  VLC *code_vlc; int range, range2, add_bits;
222  int *dst = ctx->channel_data[ch];
223 
224  ctx->filter_params = get_vlc2(gb, set->filter_params.table, 9, 2);
225  if (ctx->filter_params > 1) {
226  ctx->filter_bits = (ctx->filter_params - 2) >> 6;
227  ctx->filter_length = ctx->filter_params - (ctx->filter_bits << 6) - 1;
228  }
229 
230  if (ctx->filter_params == FILTER_RAW) {
231  for (i = 0; i < length; i++)
232  dst[i] = get_bits(gb, bits);
233  ctx->bias[ch] = 0;
234  return 0;
235  }
236 
237  ctx->bias[ch] = get_vlc2(gb, set->bias.table, 9, 2);
238  ctx->bias[ch] = extend_code(gb, ctx->bias[ch], 127, 4);
239 
240  if (ctx->filter_params == FILTER_NONE) {
241  memset(dst, 0, sizeof(*dst) * length);
242  return 0;
243  }
244 
245  if (ctx->filter_params > 1) {
246  int cmode = 0, coeff = 0;
247  VLC *vlc = set->filter_coeffs[ctx->filter_bits] + 5;
248 
249  add_bits = ctx->filter_bits;
250 
251  for (i = 0; i < ctx->filter_length; i++) {
252  t = get_vlc2(gb, vlc[cmode].table, vlc[cmode].bits, 2);
253  t = extend_code(gb, t, 21, add_bits);
254  if (!cmode)
255  coeff -= 12U << add_bits;
256  coeff = (unsigned)t - coeff;
257  ctx->filter[i] = coeff;
258 
259  cmode = coeff >> add_bits;
260  if (cmode < 0) {
261  cmode = -1 - av_log2(-cmode);
262  if (cmode < -5)
263  cmode = -5;
264  } else if (cmode > 0) {
265  cmode = 1 + av_log2(cmode);
266  if (cmode > 5)
267  cmode = 5;
268  }
269  }
270  }
271 
272  code_params = get_vlc2(gb, set->coding_mode.table, set->coding_mode.bits, 2);
273  if (code_params >= 15) {
274  add_bits = av_clip((code_params / 5 - 3) / 2, 0, 10);
275  if (add_bits > 9 && (code_params % 5) != 2)
276  add_bits--;
277  range = 10;
278  range2 = 21;
279  code_vlc = set->long_codes + (code_params - 15);
280  } else {
281  add_bits = 0;
282  range = 6;
283  range2 = 13;
284  code_vlc = set->short_codes + code_params;
285  }
286 
287  for (i = 0; i < length; i += 2) {
288  int code1, code2;
289 
290  t = get_vlc2(gb, code_vlc->table, code_vlc->bits, 2);
291  code1 = t / range2;
292  code2 = t % range2;
293  dst[i] = extend_code(gb, code1, range, 0) * (1U << add_bits);
294  dst[i + 1] = extend_code(gb, code2, range, 0) * (1U << add_bits);
295  if (add_bits) {
296  dst[i] |= get_bits(gb, add_bits);
297  dst[i + 1] |= get_bits(gb, add_bits);
298  }
299  }
300 
301  return 0;
302 }
303 
304 static void apply_lpc(RALFContext *ctx, int ch, int length, int bits)
305 {
306  int i, j, acc;
307  int *audio = ctx->channel_data[ch];
308  int bias = 1 << (ctx->filter_bits - 1);
309  int max_clip = (1 << bits) - 1, min_clip = -max_clip - 1;
310 
311  for (i = 1; i < length; i++) {
312  int flen = FFMIN(ctx->filter_length, i);
313 
314  acc = 0;
315  for (j = 0; j < flen; j++)
316  acc += (unsigned)ctx->filter[j] * audio[i - j - 1];
317  if (acc < 0) {
318  acc = (acc + bias - 1) >> ctx->filter_bits;
319  acc = FFMAX(acc, min_clip);
320  } else {
321  acc = ((unsigned)acc + bias) >> ctx->filter_bits;
322  acc = FFMIN(acc, max_clip);
323  }
324  audio[i] += acc;
325  }
326 }
327 
329  int16_t *dst0, int16_t *dst1)
330 {
331  RALFContext *ctx = avctx->priv_data;
332  int len, ch, ret;
333  int dmode, mode[2], bits[2];
334  int *ch0, *ch1;
335  int i;
336  unsigned int t, t2;
337 
338  len = 12 - get_unary(gb, 0, 6);
339 
340  if (len <= 7) len ^= 1; // codes for length = 6 and 7 are swapped
341  len = 1 << len;
342 
343  if (ctx->sample_offset + len > ctx->max_frame_size) {
344  av_log(avctx, AV_LOG_ERROR,
345  "Decoder's stomach is crying, it ate too many samples\n");
346  return AVERROR_INVALIDDATA;
347  }
348 
349  if (avctx->ch_layout.nb_channels > 1)
350  dmode = get_bits(gb, 2) + 1;
351  else
352  dmode = 0;
353 
354  mode[0] = (dmode == 4) ? 1 : 0;
355  mode[1] = (dmode >= 2) ? 2 : 0;
356  bits[0] = 16;
357  bits[1] = (mode[1] == 2) ? 17 : 16;
358 
359  for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++) {
360  if ((ret = decode_channel(ctx, gb, ch, len, mode[ch], bits[ch])) < 0)
361  return ret;
362  if (ctx->filter_params > 1 && ctx->filter_params != FILTER_RAW) {
363  ctx->filter_bits += 3;
364  apply_lpc(ctx, ch, len, bits[ch]);
365  }
366  if (get_bits_left(gb) < 0)
367  return AVERROR_INVALIDDATA;
368  }
369  ch0 = ctx->channel_data[0];
370  ch1 = ctx->channel_data[1];
371  switch (dmode) {
372  case 0:
373  for (i = 0; i < len; i++)
374  dst0[i] = ch0[i] + ctx->bias[0];
375  break;
376  case 1:
377  for (i = 0; i < len; i++) {
378  dst0[i] = ch0[i] + ctx->bias[0];
379  dst1[i] = ch1[i] + ctx->bias[1];
380  }
381  break;
382  case 2:
383  for (i = 0; i < len; i++) {
384  ch0[i] += ctx->bias[0];
385  dst0[i] = ch0[i];
386  dst1[i] = ch0[i] - (ch1[i] + ctx->bias[1]);
387  }
388  break;
389  case 3:
390  for (i = 0; i < len; i++) {
391  t = ch0[i] + ctx->bias[0];
392  t2 = ch1[i] + ctx->bias[1];
393  dst0[i] = t + t2;
394  dst1[i] = t;
395  }
396  break;
397  case 4:
398  for (i = 0; i < len; i++) {
399  t = ch1[i] + ctx->bias[1];
400  t2 = ((ch0[i] + ctx->bias[0]) * 2) | (t & 1);
401  dst0[i] = (int)(t2 + t) / 2;
402  dst1[i] = (int)(t2 - t) / 2;
403  }
404  break;
405  }
406 
407  ctx->sample_offset += len;
408 
409  return 0;
410 }
411 
413  int *got_frame_ptr, AVPacket *avpkt)
414 {
415  RALFContext *ctx = avctx->priv_data;
416  int16_t *samples0;
417  int16_t *samples1;
418  int ret;
419  GetBitContext gb;
420  int table_size, table_bytes, num_blocks;
421  const uint8_t *src, *block_pointer;
422  int src_size;
423  int bytes_left;
424 
425  if (ctx->has_pkt) {
426  ctx->has_pkt = 0;
427  table_bytes = (AV_RB16(avpkt->data) + 7) >> 3;
428  if (table_bytes + 3 > avpkt->size || avpkt->size > RALF_MAX_PKT_SIZE) {
429  av_log(avctx, AV_LOG_ERROR, "Wrong packet's breath smells of wrong data!\n");
430  return AVERROR_INVALIDDATA;
431  }
432  if (memcmp(ctx->pkt, avpkt->data, 2 + table_bytes)) {
433  av_log(avctx, AV_LOG_ERROR, "Wrong packet tails are wrong!\n");
434  return AVERROR_INVALIDDATA;
435  }
436 
437  src = ctx->pkt;
438  src_size = RALF_MAX_PKT_SIZE + avpkt->size;
439  memcpy(ctx->pkt + RALF_MAX_PKT_SIZE, avpkt->data + 2 + table_bytes,
440  avpkt->size - 2 - table_bytes);
441  } else {
442  if (avpkt->size == RALF_MAX_PKT_SIZE) {
443  memcpy(ctx->pkt, avpkt->data, avpkt->size);
444  ctx->has_pkt = 1;
445  *got_frame_ptr = 0;
446 
447  return avpkt->size;
448  }
449  src = avpkt->data;
450  src_size = avpkt->size;
451  }
452 
453  if (src_size < 5) {
454  av_log(avctx, AV_LOG_ERROR, "too short packets are too short!\n");
455  return AVERROR_INVALIDDATA;
456  }
457  table_size = AV_RB16(src);
458  table_bytes = (table_size + 7) >> 3;
459  if (src_size < table_bytes + 3) {
460  av_log(avctx, AV_LOG_ERROR, "short packets are short!\n");
461  return AVERROR_INVALIDDATA;
462  }
463  init_get_bits(&gb, src + 2, table_size);
464  num_blocks = 0;
465  while (get_bits_left(&gb) > 0) {
466  if (num_blocks >= FF_ARRAY_ELEMS(ctx->block_size))
467  return AVERROR_INVALIDDATA;
468  ctx->block_size[num_blocks] = get_bits(&gb, 13 + avctx->ch_layout.nb_channels);
469  if (get_bits1(&gb)) {
470  ctx->block_pts[num_blocks] = get_bits(&gb, 9);
471  } else {
472  ctx->block_pts[num_blocks] = 0;
473  }
474  num_blocks++;
475  }
476 
477  frame->nb_samples = ctx->max_frame_size;
478  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
479  return ret;
480  samples0 = (int16_t *)frame->data[0];
481  samples1 = (int16_t *)frame->data[1];
482  block_pointer = src + table_bytes + 2;
483  bytes_left = src_size - table_bytes - 2;
484  ctx->sample_offset = 0;
485  for (int i = 0; i < num_blocks; i++) {
486  if (bytes_left < ctx->block_size[i]) {
487  av_log(avctx, AV_LOG_ERROR, "I'm pedaling backwards\n");
488  break;
489  }
490  init_get_bits(&gb, block_pointer, ctx->block_size[i] * 8);
491  if (decode_block(avctx, &gb, samples0 + ctx->sample_offset,
492  samples1 + ctx->sample_offset) < 0) {
493  av_log(avctx, AV_LOG_ERROR, "Sir, I got carsick in your office. Not decoding the rest of packet.\n");
494  break;
495  }
496  block_pointer += ctx->block_size[i];
497  bytes_left -= ctx->block_size[i];
498  }
499 
500  frame->nb_samples = ctx->sample_offset;
501  *got_frame_ptr = ctx->sample_offset > 0;
502 
503  return avpkt->size;
504 }
505 
506 static void decode_flush(AVCodecContext *avctx)
507 {
508  RALFContext *ctx = avctx->priv_data;
509 
510  ctx->has_pkt = 0;
511 }
512 
513 
515  .p.name = "ralf",
516  CODEC_LONG_NAME("RealAudio Lossless"),
517  .p.type = AVMEDIA_TYPE_AUDIO,
518  .p.id = AV_CODEC_ID_RALF,
519  .priv_data_size = sizeof(RALFContext),
520  .init = decode_init,
521  .close = decode_close,
523  .flush = decode_flush,
524  .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
526  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
528  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
529 };
LONG_CODES_ELEMENTS
#define LONG_CODES_ELEMENTS
Definition: ralfdata.h:33
decode_flush
static void decode_flush(AVCodecContext *avctx)
Definition: ralf.c:506
av_clip
#define av_clip
Definition: common.h:98
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:694
acc
int acc
Definition: yuv2rgb.c:554
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1068
coding_mode_def
static const uint8_t coding_mode_def[3][72]
Definition: ralfdata.h:163
RALFContext
Definition: ralf.c:53
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
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:53
AVPacket::data
uint8_t * data
Definition: packet.h:522
FILTER_RAW
#define FILTER_RAW
Definition: ralf.c:40
table
static const uint16_t table[]
Definition: prosumer.c:205
data
const char data[16]
Definition: mxf.c:148
FFCodec
Definition: codec_internal.h:127
RALFContext::has_pkt
int has_pkt
Definition: ralf.c:71
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:323
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:514
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
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
VLCSet
Definition: ralf.c:42
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:335
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
VLCSet::filter_params
VLC filter_params
Definition: ralf.c:43
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2111
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:108
code_vlc
static VLCElem code_vlc[1<< CODE_VLC_BITS]
Definition: wnv1.c:42
val
static double val(void *priv, double ch)
Definition: aeval.c:78
RALFContext::channel_data
int32_t channel_data[2][4096]
Definition: ralf.c:57
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
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
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:547
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:306
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
bits
uint8_t bits
Definition: vp3data.h:128
MAX_ELEMS
#define MAX_ELEMS
Definition: ralf.c:74
ctx
AVFormatContext * ctx
Definition: movenc.c:48
channels
channels
Definition: aptx.h:31
decode.h
FILTERPARAM_ELEMENTS
#define FILTERPARAM_ELEMENTS
Definition: ralfdata.h:28
get_bits.h
RALFContext::filter
int32_t filter[64]
Definition: ralf.c:62
AV_CODEC_ID_RALF
@ AV_CODEC_ID_RALF
Definition: codec_id.h:500
filter_coeffs_def
static const uint8_t filter_coeffs_def[3][10][11][24]
Definition: ralfdata.h:188
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
frame
static AVFrame * frame
Definition: demux_decode.c:54
NULL
#define NULL
Definition: coverity.c:32
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
RALFContext::block_pts
int block_pts[1<< 12]
block start time (in milliseconds)
Definition: ralf.c:68
bias
static int bias(int x, int c)
Definition: vqcdec.c:114
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
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:55
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:652
FILTER_NONE
#define FILTER_NONE
Definition: ralf.c:39
VLCSet::coding_mode
VLC coding_mode
Definition: ralf.c:45
get_unary
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
Definition: unary.h:46
FILTER_COEFFS_ELEMENTS
#define FILTER_COEFFS_ELEMENTS
Definition: ralfdata.h:31
AV_CODEC_CAP_CHANNEL_CONF
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
Definition: codec.h:106
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:1618
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:523
codec_internal.h
VLCSet::long_codes
VLC long_codes[125]
Definition: ralf.c:48
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
RALFContext::pkt
uint8_t pkt[16384]
Definition: ralf.c:70
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1084
RALFContext::bias
unsigned bias[2]
a constant value added to channel data after filtering
Definition: ralf.c:64
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
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:96
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2646
extend_code
static int extend_code(GetBitContext *gb, int val, int range, int bits)
Definition: ralf.c:201
filter_param_def
static const uint8_t filter_param_def[3][324]
Definition: ralfdata.h:35
attributes.h
ff_vlc_init_sparse
int ff_vlc_init_sparse(VLC *vlc, 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)
Build VLC decoding tables suitable for use with get_vlc2().
Definition: vlc.c:250
unary.h
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:64
RALFContext::filter_length
int filter_length
length of the filter for the current channel data
Definition: ralf.c:60
VLCSet::short_codes
VLC short_codes[15]
Definition: ralf.c:47
av_channel_layout_default
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
Definition: channel_layout.c:1033
RALFContext::filter_params
int filter_params
combined filter parameters for the current channel data
Definition: ralf.c:59
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:215
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:420
RALF_MAX_PKT_SIZE
#define RALF_MAX_PKT_SIZE
Definition: ralf.c:51
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:546
apply_lpc
static void apply_lpc(RALFContext *ctx, int ch, int length, int bits)
Definition: ralf.c:304
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
len
int len
Definition: vorbis_enc_data.h:426
VLCSet::bias
VLC bias
Definition: ralf.c:44
decode_frame
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: ralf.c:412
avcodec.h
ff_vlc_free
void ff_vlc_free(VLC *vlc)
Definition: vlc.c:577
ret
ret
Definition: filter_design.txt:187
RALFContext::version
int version
Definition: ralf.c:54
U
#define U(x)
Definition: vpx_arith.h:37
ff_ralf_decoder
const FFCodec ff_ralf_decoder
Definition: ralf.c:514
AVCodecContext
main external API structure.
Definition: avcodec.h:445
channel_layout.h
t2
#define t2
Definition: regdef.h:30
mode
mode
Definition: ebur128.h:83
VLC
Definition: vlc.h:36
VLCSet::filter_coeffs
VLC filter_coeffs[10][11]
Definition: ralf.c:46
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:662
RALFContext::filter_bits
int filter_bits
filter precision for the current channel data
Definition: ralf.c:61
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:328
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
CODING_MODE_ELEMENTS
#define CODING_MODE_ELEMENTS
Definition: ralfdata.h:30
ralfdata.h
RALFContext::sets
VLCSet sets[3]
Definition: ralf.c:56
AVPacket
This structure stores compressed data.
Definition: packet.h:499
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
int32_t
int32_t
Definition: audioconvert.c:56
coeff
static const double coeff[2][5]
Definition: vf_owdenoise.c:79
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
int
int
Definition: ffmpeg_filter.c:424
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:98