FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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  int 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++) {
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 = (val << bits) | get_bits(gb, bits);
224  return val;
225 }
226 
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  ctx->filter_bits = (ctx->filter_params - 2) >> 6;
238  ctx->filter_length = ctx->filter_params - (ctx->filter_bits << 6) - 1;
239 
240  if (ctx->filter_params == FILTER_RAW) {
241  for (i = 0; i < length; i++)
242  dst[i] = get_bits(gb, bits);
243  ctx->bias[ch] = 0;
244  return 0;
245  }
246 
247  ctx->bias[ch] = get_vlc2(gb, set->bias.table, 9, 2);
248  ctx->bias[ch] = extend_code(gb, ctx->bias[ch], 127, 4);
249 
250  if (ctx->filter_params == FILTER_NONE) {
251  memset(dst, 0, sizeof(*dst) * length);
252  return 0;
253  }
254 
255  if (ctx->filter_params > 1) {
256  int cmode = 0, coeff = 0;
257  VLC *vlc = set->filter_coeffs[ctx->filter_bits] + 5;
258 
259  add_bits = ctx->filter_bits;
260 
261  for (i = 0; i < ctx->filter_length; i++) {
262  t = get_vlc2(gb, vlc[cmode].table, vlc[cmode].bits, 2);
263  t = extend_code(gb, t, 21, add_bits);
264  if (!cmode)
265  coeff -= 12 << add_bits;
266  coeff = t - coeff;
267  ctx->filter[i] = coeff;
268 
269  cmode = coeff >> add_bits;
270  if (cmode < 0) {
271  cmode = -1 - av_log2(-cmode);
272  if (cmode < -5)
273  cmode = -5;
274  } else if (cmode > 0) {
275  cmode = 1 + av_log2(cmode);
276  if (cmode > 5)
277  cmode = 5;
278  }
279  }
280  }
281 
282  code_params = get_vlc2(gb, set->coding_mode.table, set->coding_mode.bits, 2);
283  if (code_params >= 15) {
284  add_bits = av_clip((code_params / 5 - 3) / 2, 0, 10);
285  if (add_bits > 9 && (code_params % 5) != 2)
286  add_bits--;
287  range = 10;
288  range2 = 21;
289  code_vlc = set->long_codes + code_params - 15;
290  } else {
291  add_bits = 0;
292  range = 6;
293  range2 = 13;
294  code_vlc = set->short_codes + code_params;
295  }
296 
297  for (i = 0; i < length; i += 2) {
298  int code1, code2;
299 
300  t = get_vlc2(gb, code_vlc->table, code_vlc->bits, 2);
301  code1 = t / range2;
302  code2 = t % range2;
303  dst[i] = extend_code(gb, code1, range, 0) << add_bits;
304  dst[i + 1] = extend_code(gb, code2, range, 0) << add_bits;
305  if (add_bits) {
306  dst[i] |= get_bits(gb, add_bits);
307  dst[i + 1] |= get_bits(gb, add_bits);
308  }
309  }
310 
311  return 0;
312 }
313 
314 static void apply_lpc(RALFContext *ctx, int ch, int length, int bits)
315 {
316  int i, j, acc;
317  int *audio = ctx->channel_data[ch];
318  int bias = 1 << (ctx->filter_bits - 1);
319  int max_clip = (1 << bits) - 1, min_clip = -max_clip - 1;
320 
321  for (i = 1; i < length; i++) {
322  int flen = FFMIN(ctx->filter_length, i);
323 
324  acc = 0;
325  for (j = 0; j < flen; j++)
326  acc += ctx->filter[j] * audio[i - j - 1];
327  if (acc < 0) {
328  acc = (acc + bias - 1) >> ctx->filter_bits;
329  acc = FFMAX(acc, min_clip);
330  } else {
331  acc = (acc + bias) >> ctx->filter_bits;
332  acc = FFMIN(acc, max_clip);
333  }
334  audio[i] += acc;
335  }
336 }
337 
339  int16_t *dst0, int16_t *dst1)
340 {
341  RALFContext *ctx = avctx->priv_data;
342  int len, ch, ret;
343  int dmode, mode[2], bits[2];
344  int *ch0, *ch1;
345  int i, t, t2;
346 
347  len = 12 - get_unary(gb, 0, 6);
348 
349  if (len <= 7) len ^= 1; // codes for length = 6 and 7 are swapped
350  len = 1 << len;
351 
352  if (ctx->sample_offset + len > ctx->max_frame_size) {
353  av_log(avctx, AV_LOG_ERROR,
354  "Decoder's stomach is crying, it ate too many samples\n");
355  return AVERROR_INVALIDDATA;
356  }
357 
358  if (avctx->channels > 1)
359  dmode = get_bits(gb, 2) + 1;
360  else
361  dmode = 0;
362 
363  mode[0] = (dmode == 4) ? 1 : 0;
364  mode[1] = (dmode >= 2) ? 2 : 0;
365  bits[0] = 16;
366  bits[1] = (mode[1] == 2) ? 17 : 16;
367 
368  for (ch = 0; ch < avctx->channels; ch++) {
369  if ((ret = decode_channel(ctx, gb, ch, len, mode[ch], bits[ch])) < 0)
370  return ret;
371  if (ctx->filter_params > 1 && ctx->filter_params != FILTER_RAW) {
372  ctx->filter_bits += 3;
373  apply_lpc(ctx, ch, len, bits[ch]);
374  }
375  if (get_bits_left(gb) < 0)
376  return AVERROR_INVALIDDATA;
377  }
378  ch0 = ctx->channel_data[0];
379  ch1 = ctx->channel_data[1];
380  switch (dmode) {
381  case 0:
382  for (i = 0; i < len; i++)
383  dst0[i] = ch0[i] + ctx->bias[0];
384  break;
385  case 1:
386  for (i = 0; i < len; i++) {
387  dst0[i] = ch0[i] + ctx->bias[0];
388  dst1[i] = ch1[i] + ctx->bias[1];
389  }
390  break;
391  case 2:
392  for (i = 0; i < len; i++) {
393  ch0[i] += ctx->bias[0];
394  dst0[i] = ch0[i];
395  dst1[i] = ch0[i] - (ch1[i] + ctx->bias[1]);
396  }
397  break;
398  case 3:
399  for (i = 0; i < len; i++) {
400  t = ch0[i] + ctx->bias[0];
401  t2 = ch1[i] + ctx->bias[1];
402  dst0[i] = t + t2;
403  dst1[i] = t;
404  }
405  break;
406  case 4:
407  for (i = 0; i < len; i++) {
408  t = ch1[i] + ctx->bias[1];
409  t2 = ((ch0[i] + ctx->bias[0]) << 1) | (t & 1);
410  dst0[i] = (t2 + t) / 2;
411  dst1[i] = (t2 - t) / 2;
412  }
413  break;
414  }
415 
416  ctx->sample_offset += len;
417 
418  return 0;
419 }
420 
421 static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr,
422  AVPacket *avpkt)
423 {
424  RALFContext *ctx = avctx->priv_data;
425  AVFrame *frame = data;
426  int16_t *samples0;
427  int16_t *samples1;
428  int ret;
429  GetBitContext gb;
430  int table_size, table_bytes, i;
431  const uint8_t *src, *block_pointer;
432  int src_size;
433  int bytes_left;
434 
435  if (ctx->has_pkt) {
436  ctx->has_pkt = 0;
437  table_bytes = (AV_RB16(avpkt->data) + 7) >> 3;
438  if (table_bytes + 3 > avpkt->size || avpkt->size > RALF_MAX_PKT_SIZE) {
439  av_log(avctx, AV_LOG_ERROR, "Wrong packet's breath smells of wrong data!\n");
440  return AVERROR_INVALIDDATA;
441  }
442  if (memcmp(ctx->pkt, avpkt->data, 2 + table_bytes)) {
443  av_log(avctx, AV_LOG_ERROR, "Wrong packet tails are wrong!\n");
444  return AVERROR_INVALIDDATA;
445  }
446 
447  src = ctx->pkt;
448  src_size = RALF_MAX_PKT_SIZE + avpkt->size;
449  memcpy(ctx->pkt + RALF_MAX_PKT_SIZE, avpkt->data + 2 + table_bytes,
450  avpkt->size - 2 - table_bytes);
451  } else {
452  if (avpkt->size == RALF_MAX_PKT_SIZE) {
453  memcpy(ctx->pkt, avpkt->data, avpkt->size);
454  ctx->has_pkt = 1;
455  *got_frame_ptr = 0;
456 
457  return avpkt->size;
458  }
459  src = avpkt->data;
460  src_size = avpkt->size;
461  }
462 
463  frame->nb_samples = ctx->max_frame_size;
464  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
465  return ret;
466  samples0 = (int16_t *)frame->data[0];
467  samples1 = (int16_t *)frame->data[1];
468 
469  if (src_size < 5) {
470  av_log(avctx, AV_LOG_ERROR, "too short packets are too short!\n");
471  return AVERROR_INVALIDDATA;
472  }
473  table_size = AV_RB16(src);
474  table_bytes = (table_size + 7) >> 3;
475  if (src_size < table_bytes + 3) {
476  av_log(avctx, AV_LOG_ERROR, "short packets are short!\n");
477  return AVERROR_INVALIDDATA;
478  }
479  init_get_bits(&gb, src + 2, table_size);
480  ctx->num_blocks = 0;
481  while (get_bits_left(&gb) > 0) {
482  ctx->block_size[ctx->num_blocks] = get_bits(&gb, 13 + avctx->channels);
483  if (get_bits1(&gb)) {
484  ctx->block_pts[ctx->num_blocks] = get_bits(&gb, 9);
485  } else {
486  ctx->block_pts[ctx->num_blocks] = 0;
487  }
488  ctx->num_blocks++;
489  }
490 
491  block_pointer = src + table_bytes + 2;
492  bytes_left = src_size - table_bytes - 2;
493  ctx->sample_offset = 0;
494  for (i = 0; i < ctx->num_blocks; i++) {
495  if (bytes_left < ctx->block_size[i]) {
496  av_log(avctx, AV_LOG_ERROR, "I'm pedaling backwards\n");
497  break;
498  }
499  init_get_bits(&gb, block_pointer, ctx->block_size[i] * 8);
500  if (decode_block(avctx, &gb, samples0 + ctx->sample_offset,
501  samples1 + ctx->sample_offset) < 0) {
502  av_log(avctx, AV_LOG_ERROR, "Sir, I got carsick in your office. Not decoding the rest of packet.\n");
503  break;
504  }
505  block_pointer += ctx->block_size[i];
506  bytes_left -= ctx->block_size[i];
507  }
508 
509  frame->nb_samples = ctx->sample_offset;
510  *got_frame_ptr = ctx->sample_offset > 0;
511 
512  return avpkt->size;
513 }
514 
515 static void decode_flush(AVCodecContext *avctx)
516 {
517  RALFContext *ctx = avctx->priv_data;
518 
519  ctx->has_pkt = 0;
520 }
521 
522 
524  .name = "ralf",
525  .long_name = NULL_IF_CONFIG_SMALL("RealAudio Lossless"),
526  .type = AVMEDIA_TYPE_AUDIO,
527  .id = AV_CODEC_ID_RALF,
528  .priv_data_size = sizeof(RALFContext),
529  .init = decode_init,
530  .close = decode_close,
531  .decode = decode_frame,
532  .flush = decode_flush,
533  .capabilities = AV_CODEC_CAP_DR1,
534  .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
536 };
#define NULL
Definition: coverity.c:32
int max_frame_size
Definition: ralf.c:54
const char const char void * val
Definition: avisynth_c.h:771
#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:184
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
static void flush(AVCodecContext *avctx)
int num_blocks
number of blocks inside the frame
Definition: ralf.c:65
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:247
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
int acc
Definition: yuv2rgb.c:546
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:275
int size
Definition: avcodec.h:1602
VLC filter_params
Definition: ralf.c:42
int av_log2(unsigned v)
Definition: intmath.c:26
#define AV_CH_LAYOUT_STEREO
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:87
AVCodec.
Definition: avcodec.h:3600
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)
Definition: swresample.c:59
Macro definitions for various function/variable attributes.
static const uint8_t bias_def[3][128]
Definition: ralfdata.h:123
#define MAX_ELEMS
Definition: ralf.c:74
#define FILTER_NONE
Definition: ralf.c:38
static const uint8_t filter_coeffs_def[3][10][11][24]
Definition: ralfdata.h:188
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
uint8_t bits
Definition: crc.c:296
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2446
uint8_t
#define av_cold
Definition: attributes.h:82
mode
Definition: f_perms.c:27
int sample_offset
Definition: ralf.c:66
static int decode_block(AVCodecContext *avctx, GetBitContext *gb, int16_t *dst0, int16_t *dst1)
Definition: ralf.c:338
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1791
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:87
static AVFrame * frame
uint8_t * data
Definition: avcodec.h:1601
bitstream reader API header.
int version
Definition: ralf.c:53
#define av_log(a,...)
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:568
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
static int get_ue_golomb(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to 8190.
Definition: golomb.h:53
int filter_bits
filter precision for the current channel data
Definition: ralf.c:60
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Definition: ralf.c:421
int has_pkt
Definition: ralf.c:71
static void decode_flush(AVCodecContext *avctx)
Definition: ralf.c:515
static const struct endianess table[]
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
static av_cold int decode_close(AVCodecContext *avctx)
Definition: ralf.c:106
static int decode_channel(RALFContext *ctx, GetBitContext *gb, int ch, int length, int mode, int bits)
Definition: ralf.c:227
static const uint8_t long_codes_def[3][125][224]
Definition: ralfdata.h:2036
#define RALF_MAX_PKT_SIZE
Definition: ralf.c:50
VLC coding_mode
Definition: ralf.c:44
GLsizei GLsizei * length
Definition: opengl_enc.c:115
const char * name
Name of the codec implementation.
Definition: avcodec.h:3607
#define FFMAX(a, b)
Definition: common.h:94
Definition: vlc.h:26
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2489
int32_t channel_data[2][4096]
Definition: ralf.c:56
VLCSet sets[3]
Definition: ralf.c:55
audio channel layout utility functions
#define FILTER_COEFFS_ELEMENTS
Definition: ralfdata.h:31
#define FFMIN(a, b)
Definition: common.h:96
#define FILTER_RAW
Definition: ralf.c:39
#define SHORT_CODES_ELEMENTS
Definition: ralfdata.h:32
int32_t
AVFormatContext * ctx
Definition: movenc.c:48
static const uint8_t coding_mode_def[3][72]
Definition: ralfdata.h:163
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:535
#define src
Definition: vp9dsp.c:530
int bits
Definition: vlc.h:27
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
int32_t filter[64]
Definition: ralf.c:61
int filter_params
combined filter parameters for the current channel data
Definition: ralf.c:58
uint8_t pkt[16384]
Definition: ralf.c:70
Libavcodec external API header.
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
int sample_rate
samples per second
Definition: avcodec.h:2438
AVCodec ff_ralf_decoder
Definition: ralf.c:523
#define FILTERPARAM_ELEMENTS
Definition: ralfdata.h:28
main external API structure.
Definition: avcodec.h:1676
static VLC code_vlc
Definition: wnv1.c:45
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: utils.c:947
VLC long_codes[125]
Definition: ralf.c:47
int extradata_size
Definition: avcodec.h:1792
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:299
Definition: ralf.c:41
static av_cold int init_ralf_vlc(VLC *vlc, const uint8_t *data, int elems)
Definition: ralf.c:76
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:406
VLC short_codes[15]
Definition: ralf.c:46
VLC filter_coeffs[10][11]
Definition: ralf.c:45
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:198
int block_size[1<< 12]
size of the blocks
Definition: ralf.c:67
int block_pts[1<< 12]
block start time (in milliseconds)
Definition: ralf.c:68
#define CODING_MODE_ELEMENTS
Definition: ralfdata.h:30
common internal api header.
if(ret< 0)
Definition: vf_mcdeint.c:282
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
Definition: unary.h:33
static const uint8_t short_codes_def[3][15][88]
Definition: ralfdata.h:1577
VLC bias
Definition: ralf.c:43
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;if(channels==1){in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);}ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map){switch(av_get_bytes_per_sample(in_fmt)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8:ctx->simd_f=cpy8;break;}}if(HAVE_YASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;}if(ctx->out_simd_align_mask){intplanes=out->planar?out->ch_count:1;unsignedm=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;}if(ctx->simd_f &&!ctx->ch_map &&!misaligned){off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){if(out->planar==in->planar){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
Definition: audioconvert.c:56
int filter_length
length of the filter for the current channel data
Definition: ralf.c:59
void * priv_data
Definition: avcodec.h:1718
static av_cold int decode_init(AVCodecContext *avctx)
Definition: ralf.c:127
static int extend_code(GetBitContext *gb, int val, int range, int bits)
Definition: ralf.c:213
int len
int channels
number of audio channels
Definition: avcodec.h:2439
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
static const uint8_t filter_param_def[3][324]
Definition: ralfdata.h:35
static const double coeff[2][5]
Definition: vf_owdenoise.c:72
int bias[2]
a constant value added to channel data after filtering
Definition: ralf.c:63
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:701
#define BIAS_ELEMENTS
Definition: ralfdata.h:29
signed 16 bits, planar
Definition: samplefmt.h:67
static int decode(AVCodecContext *avctx, AVFrame *frame, int *got_frame, AVPacket *pkt)
Definition: ffmpeg.c:2035
#define LONG_CODES_ELEMENTS
Definition: ralfdata.h:33
#define AV_CH_LAYOUT_MONO
static void apply_lpc(RALFContext *ctx, int ch, int length, int bits)
Definition: ralf.c:314
exp golomb vlc stuff
This structure stores compressed data.
Definition: avcodec.h:1578
void ff_free_vlc(VLC *vlc)
Definition: bitstream.c:360
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:241
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:959
for(j=16;j >0;--j)
#define t2
Definition: regdef.h:30