Go to the documentation of this file.
40 #define FILTER_RAW 642
51 #define RALF_MAX_PKT_SIZE 8192
75 #define MAX_ELEMS 644 // no RALF table uses more than that
81 int counts[17], prefixes[18];
86 for (
i = 0;
i <= 16;
i++)
88 for (
i = 0;
i < elems;
i++) {
89 cur_len = (nb ? *
data & 0xF : *
data >> 4) + 1;
91 max_bits =
FFMAX(max_bits, cur_len);
97 for (
i = 1;
i <= 16;
i++)
98 prefixes[
i + 1] = (prefixes[
i] + counts[
i]) << 1;
100 for (
i = 0;
i < elems;
i++)
101 codes[
i] = prefixes[lens[
i]]++;
104 lens, 1, 1, codes, 2, 2,
NULL, 0, 0, 0);
112 for (
i = 0;
i < 3;
i++) {
116 for (j = 0; j < 10; j++)
117 for (k = 0; k < 11; k++)
119 for (j = 0; j < 15; j++)
121 for (j = 0; j < 125; j++)
140 if (
ctx->version != 0x103) {
158 if (
ctx->max_frame_size > (1 << 20) || !
ctx->max_frame_size) {
160 ctx->max_frame_size);
164 for (
i = 0;
i < 3;
i++) {
176 for (j = 0; j < 10; j++) {
177 for (k = 0; k < 11; k++) {
185 for (j = 0; j < 15; j++) {
191 for (j = 0; j < 125; j++) {
206 }
else if (
val == range * 2) {
223 int *dst =
ctx->channel_data[ch];
225 ctx->filter_params =
get_vlc2(gb,
set->filter_params.table, 9, 2);
226 if (
ctx->filter_params > 1) {
227 ctx->filter_bits = (
ctx->filter_params - 2) >> 6;
228 ctx->filter_length =
ctx->filter_params - (
ctx->filter_bits << 6) - 1;
232 for (
i = 0;
i < length;
i++)
242 memset(dst, 0,
sizeof(*dst) * length);
246 if (
ctx->filter_params > 1) {
247 int cmode = 0,
coeff = 0;
248 VLC *vlc =
set->filter_coeffs[
ctx->filter_bits] + 5;
250 add_bits =
ctx->filter_bits;
252 for (
i = 0;
i <
ctx->filter_length;
i++) {
260 cmode =
coeff >> add_bits;
265 }
else if (cmode > 0) {
273 code_params =
get_vlc2(gb,
set->coding_mode.table,
set->coding_mode.bits, 2);
274 if (code_params >= 15) {
275 add_bits =
av_clip((code_params / 5 - 3) / 2, 0, 10);
276 if (add_bits > 9 && (code_params % 5) != 2)
288 for (
i = 0;
i < length;
i += 2) {
294 dst[
i] =
extend_code(gb, code1, range, 0) * (1
U << add_bits);
295 dst[
i + 1] =
extend_code(gb, code2, range, 0) * (1
U << add_bits);
308 int *audio =
ctx->channel_data[ch];
309 int bias = 1 << (
ctx->filter_bits - 1);
310 int max_clip = (1 <<
bits) - 1, min_clip = -max_clip - 1;
312 for (
i = 1;
i < length;
i++) {
316 for (j = 0; j < flen; j++)
317 acc += (
unsigned)
ctx->filter[j] * audio[
i - j - 1];
319 acc = (
acc + bias - 1) >>
ctx->filter_bits;
322 acc = ((unsigned)
acc + bias) >>
ctx->filter_bits;
330 int16_t *dst0, int16_t *dst1)
344 if (
ctx->sample_offset +
len >
ctx->max_frame_size) {
346 "Decoder's stomach is crying, it ate too many samples\n");
355 mode[0] = (dmode == 4) ? 1 : 0;
356 mode[1] = (dmode >= 2) ? 2 : 0;
364 ctx->filter_bits += 3;
370 ch0 =
ctx->channel_data[0];
371 ch1 =
ctx->channel_data[1];
375 dst0[
i] = ch0[
i] +
ctx->bias[0];
379 dst0[
i] = ch0[
i] +
ctx->bias[0];
380 dst1[
i] = ch1[
i] +
ctx->bias[1];
384 for (
i = 0;
i <
len;
i++) {
385 ch0[
i] +=
ctx->bias[0];
387 dst1[
i] = ch0[
i] - (ch1[
i] +
ctx->bias[1]);
391 for (
i = 0;
i <
len;
i++) {
392 t = ch0[
i] +
ctx->bias[0];
393 t2 = ch1[
i] +
ctx->bias[1];
399 for (
i = 0;
i <
len;
i++) {
400 t = ch1[
i] +
ctx->bias[1];
401 t2 = ((ch0[
i] +
ctx->bias[0]) * 2) | (t & 1);
402 dst0[
i] = (
int)(
t2 + t) / 2;
403 dst1[
i] = (
int)(
t2 - t) / 2;
408 ctx->sample_offset +=
len;
414 int *got_frame_ptr,
AVPacket *avpkt)
421 int table_size, table_bytes,
i;
422 const uint8_t *
src, *block_pointer;
433 if (memcmp(
ctx->pkt, avpkt->
data, 2 + table_bytes)) {
441 avpkt->
size - 2 - table_bytes);
451 src_size = avpkt->
size;
454 frame->nb_samples =
ctx->max_frame_size;
457 samples0 = (int16_t *)
frame->data[0];
458 samples1 = (int16_t *)
frame->data[1];
465 table_bytes = (table_size + 7) >> 3;
466 if (src_size < table_bytes + 3) {
479 ctx->block_pts[
ctx->num_blocks] = 0;
484 block_pointer =
src + table_bytes + 2;
485 bytes_left = src_size - table_bytes - 2;
486 ctx->sample_offset = 0;
487 for (
i = 0;
i <
ctx->num_blocks;
i++) {
488 if (bytes_left < ctx->block_size[
i]) {
494 samples1 +
ctx->sample_offset) < 0) {
495 av_log(avctx,
AV_LOG_ERROR,
"Sir, I got carsick in your office. Not decoding the rest of packet.\n");
498 block_pointer +=
ctx->block_size[
i];
499 bytes_left -=
ctx->block_size[
i];
502 frame->nb_samples =
ctx->sample_offset;
503 *got_frame_ptr =
ctx->sample_offset > 0;
#define LONG_CODES_ELEMENTS
static void decode_flush(AVCodecContext *avctx)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
static int get_bits_left(GetBitContext *gb)
int sample_rate
samples per second
int num_blocks
number of blocks inside the frame
static const uint8_t coding_mode_def[3][72]
This structure describes decoded (raw) audio or video data.
static av_cold int decode_close(AVCodecContext *avctx)
static int get_ue_golomb(GetBitContext *gb)
Read an unsigned Exp-Golomb code in the range 0 to 8190.
static const uint16_t table[]
int nb_channels
Number of channels in this layout.
static const uint8_t long_codes_def[3][125][224]
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
static const uint8_t short_codes_def[3][15][88]
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
AVCodec p
The public AVCodec.
AVChannelLayout ch_layout
Audio channel layout.
#define SHORT_CODES_ELEMENTS
static av_cold int decode_init(AVCodecContext *avctx)
static double val(void *priv, double ch)
int32_t channel_data[2][4096]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define FF_ARRAY_ELEMS(a)
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)
#define FF_CODEC_DECODE_CB(func)
#define FILTERPARAM_ELEMENTS
static const uint8_t filter_coeffs_def[3][10][11][24]
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int block_pts[1<< 12]
block start time (in milliseconds)
static unsigned int get_bits1(GetBitContext *s)
int block_size[1<< 12]
size of the blocks
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
static int get_unary(GetBitContext *gb, int stop, int len)
Get unary code of limited length.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
#define FILTER_COEFFS_ELEMENTS
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
static av_cold int init_ralf_vlc(VLC *vlc, const uint8_t *data, int elems)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
enum AVSampleFormat sample_fmt
audio sample format
unsigned bias[2]
a constant value added to channel data after filtering
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
static int extend_code(GetBitContext *gb, int val, int range, int bits)
static const uint8_t filter_param_def[3][324]
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
int filter_length
length of the filter for the current channel data
int filter_params
combined filter parameters for the current channel data
static const uint8_t bias_def[3][128]
static int decode_channel(RALFContext *ctx, GetBitContext *gb, int ch, int length, int mode, int bits)
#define RALF_MAX_PKT_SIZE
#define i(width, name, range_min, range_max)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int ff_init_vlc_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)
static void apply_lpc(RALFContext *ctx, int ch, int length, int bits)
AVSampleFormat
Audio sample formats.
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
const char * name
Name of the codec implementation.
void ff_free_vlc(VLC *vlc)
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
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
const FFCodec ff_ralf_decoder
main external API structure.
VLC filter_coeffs[10][11]
int filter_bits
filter precision for the current channel data
static int decode_block(AVCodecContext *avctx, GetBitContext *gb, int16_t *dst0, int16_t *dst1)
#define avpriv_request_sample(...)
#define CODING_MODE_ELEMENTS
This structure stores compressed data.
static const double coeff[2][5]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
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