FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
alsdec.c File Reference
#include <inttypes.h>
#include "avcodec.h"
#include "get_bits.h"
#include "unary.h"
#include "mpeg4audio.h"
#include "bgmc.h"
#include "bswapdsp.h"
#include "codec_internal.h"
#include "decode.h"
#include "internal.h"
#include "mlz.h"
#include "libavutil/samplefmt.h"
#include "libavutil/crc.h"
#include "libavutil/softfloat_ieee754.h"
#include "libavutil/intfloat.h"
#include "libavutil/intreadwrite.h"
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  ALSSpecificConfig
 
struct  ALSChannelData
 
struct  ALSDecContext
 
struct  ALSBlockData
 

Macros

#define MISSING_ERR(cond, str, errval)
 
#define INTERLEAVE_OUTPUT(bps)
 

Enumerations

enum  RA_Flag { RA_FLAG_NONE, RA_FLAG_FRAMES, RA_FLAG_HEADER }
 

Functions

static av_cold void dprint_specific_config (ALSDecContext *ctx)
 
static av_cold int read_specific_config (ALSDecContext *ctx)
 Read an ALSSpecificConfig from a buffer into the output struct. More...
 
static int check_specific_config (ALSDecContext *ctx)
 Check the ALSSpecificConfig for unsupported features. More...
 
static void parse_bs_info (const uint32_t bs_info, unsigned int n, unsigned int div, unsigned int **div_blocks, unsigned int *num_blocks)
 Parse the bs_info field to extract the block partitioning used in block switching mode, refer to ISO/IEC 14496-3, section 11.6.2. More...
 
static int32_t decode_rice (GetBitContext *gb, unsigned int k)
 Read and decode a Rice codeword. More...
 
static void parcor_to_lpc (unsigned int k, const int32_t *par, int32_t *cof)
 Convert PARCOR coefficient k to direct filter coefficient. More...
 
static void get_block_sizes (ALSDecContext *ctx, unsigned int *div_blocks, uint32_t *bs_info)
 Read block switching field if necessary and set actual block sizes. More...
 
static int read_const_block_data (ALSDecContext *ctx, ALSBlockData *bd)
 Read the block data for a constant block. More...
 
static void decode_const_block_data (ALSDecContext *ctx, ALSBlockData *bd)
 Decode the block data for a constant block. More...
 
static int read_var_block_data (ALSDecContext *ctx, ALSBlockData *bd)
 Read the block data for a non-constant block. More...
 
static int decode_var_block_data (ALSDecContext *ctx, ALSBlockData *bd)
 Decode the block data for a non-constant block. More...
 
static int read_block (ALSDecContext *ctx, ALSBlockData *bd)
 Read the block data. More...
 
static int decode_block (ALSDecContext *ctx, ALSBlockData *bd)
 Decode the block data. More...
 
static int read_decode_block (ALSDecContext *ctx, ALSBlockData *bd)
 Read and decode block data successively. More...
 
static void zero_remaining (unsigned int b, unsigned int b_max, const unsigned int *div_blocks, int32_t *buf)
 Compute the number of samples left to decode for the current frame and sets these samples to zero. More...
 
static int decode_blocks_ind (ALSDecContext *ctx, unsigned int ra_frame, unsigned int c, const unsigned int *div_blocks, unsigned int *js_blocks)
 Decode blocks independently. More...
 
static int decode_blocks (ALSDecContext *ctx, unsigned int ra_frame, unsigned int c, const unsigned int *div_blocks, unsigned int *js_blocks)
 Decode blocks dependently. More...
 
static int als_weighting (GetBitContext *gb, int k, int off)
 
static int read_channel_data (ALSDecContext *ctx, ALSChannelData *cd, int c)
 Read the channel data. More...
 
static int revert_channel_correlation (ALSDecContext *ctx, ALSBlockData *bd, ALSChannelData **cd, int *reverted, unsigned int offset, int c)
 Recursively reverts the inter-channel correlation for a block. More...
 
static SoftFloat_IEEE754 multiply (SoftFloat_IEEE754 a, SoftFloat_IEEE754 b)
 multiply two softfloats and handle the rounding off More...
 
static int read_diff_float_data (ALSDecContext *ctx, unsigned int ra_frame)
 Read and decode the floating point sample data. More...
 
static int read_frame_data (ALSDecContext *ctx, unsigned int ra_frame)
 Read the frame data. More...
 
static int decode_frame (AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
 Decode an ALS frame. More...
 
static av_cold int decode_end (AVCodecContext *avctx)
 Uninitialize the ALS decoder. More...
 
static av_cold int decode_init (AVCodecContext *avctx)
 Initialize the ALS decoder. More...
 
static av_cold void flush (AVCodecContext *avctx)
 Flush (reset) the frame ID after seeking. More...
 

Variables

static const int8_t parcor_rice_table [3][20][2]
 Rice parameters and corresponding index offsets for decoding the indices of scaled PARCOR values. More...
 
static const int16_t parcor_scaled_values []
 Scaled PARCOR values used for the first two PARCOR coefficients. More...
 
static const uint8_t ltp_gain_values [4][4]
 Gain values of p(0) for long-term prediction. More...
 
static const int16_t mcc_weightings []
 Inter-channel weighting factors for multi-channel correlation. More...
 
static const uint8_t tail_code [16][6]
 Tail codes used in arithmetic coding using block Gilbert-Moore codes. More...
 
const FFCodec ff_als_decoder
 

Detailed Description

MPEG-4 ALS decoder

Author
Thilo Borgmann <thilo.borgmann at mail.de>

Definition in file alsdec.c.

Macro Definition Documentation

◆ MISSING_ERR

#define MISSING_ERR (   cond,
  str,
  errval 
)
Value:
{ \
if (cond) { \
avpriv_report_missing_feature(ctx->avctx, \
str); \
error = errval; \
} \
}

◆ INTERLEAVE_OUTPUT

#define INTERLEAVE_OUTPUT (   bps)
Value:
{ \
int##bps##_t *dest = (int##bps##_t*)frame->data[0]; \
int32_t *raw_samples = ctx->raw_samples[0]; \
int raw_step = channels > 1 ? ctx->raw_samples[1] - raw_samples : 1; \
shift = bps - ctx->avctx->bits_per_raw_sample; \
if (!ctx->cs_switch) { \
for (sample = 0; sample < ctx->cur_frame_length; sample++) \
for (c = 0; c < channels; c++) \
*dest++ = raw_samples[c*raw_step + sample] * (1U << shift); \
} else { \
for (sample = 0; sample < ctx->cur_frame_length; sample++) \
for (c = 0; c < channels; c++) \
*dest++ = raw_samples[sconf->chan_pos[c]*raw_step + sample] * (1U << shift);\
} \
}

Enumeration Type Documentation

◆ RA_Flag

enum RA_Flag
Enumerator
RA_FLAG_NONE 
RA_FLAG_FRAMES 
RA_FLAG_HEADER 

Definition at line 153 of file alsdec.c.

Function Documentation

◆ dprint_specific_config()

static av_cold void dprint_specific_config ( ALSDecContext ctx)
static

Definition at line 264 of file alsdec.c.

Referenced by read_specific_config().

◆ read_specific_config()

static av_cold int read_specific_config ( ALSDecContext ctx)
static

Read an ALSSpecificConfig from a buffer into the output struct.

Definition at line 294 of file alsdec.c.

Referenced by decode_init().

◆ check_specific_config()

static int check_specific_config ( ALSDecContext ctx)
static

Check the ALSSpecificConfig for unsupported features.

Definition at line 457 of file alsdec.c.

Referenced by decode_init().

◆ parse_bs_info()

static void parse_bs_info ( const uint32_t  bs_info,
unsigned int  n,
unsigned int  div,
unsigned int **  div_blocks,
unsigned int num_blocks 
)
static

Parse the bs_info field to extract the block partitioning used in block switching mode, refer to ISO/IEC 14496-3, section 11.6.2.

Definition at line 481 of file alsdec.c.

Referenced by get_block_sizes().

◆ decode_rice()

static int32_t decode_rice ( GetBitContext gb,
unsigned int  k 
)
static

Read and decode a Rice codeword.

Definition at line 504 of file alsdec.c.

Referenced by als_weighting(), and read_var_block_data().

◆ parcor_to_lpc()

static void parcor_to_lpc ( unsigned int  k,
const int32_t par,
int32_t cof 
)
static

Convert PARCOR coefficient k to direct filter coefficient.

Definition at line 522 of file alsdec.c.

Referenced by decode_var_block_data().

◆ get_block_sizes()

static void get_block_sizes ( ALSDecContext ctx,
unsigned int div_blocks,
uint32_t *  bs_info 
)
static

Read block switching field if necessary and set actual block sizes.

Also assure that the block sizes of the last frame correspond to the actual number of samples.

Definition at line 542 of file alsdec.c.

Referenced by read_frame_data().

◆ read_const_block_data()

static int read_const_block_data ( ALSDecContext ctx,
ALSBlockData bd 
)
static

Read the block data for a constant block.

Definition at line 595 of file alsdec.c.

Referenced by read_block().

◆ decode_const_block_data()

static void decode_const_block_data ( ALSDecContext ctx,
ALSBlockData bd 
)
static

Decode the block data for a constant block.

Definition at line 625 of file alsdec.c.

Referenced by decode_block().

◆ read_var_block_data()

static int read_var_block_data ( ALSDecContext ctx,
ALSBlockData bd 
)
static

Read the block data for a non-constant block.

Definition at line 639 of file alsdec.c.

Referenced by read_block().

◆ decode_var_block_data()

static int decode_var_block_data ( ALSDecContext ctx,
ALSBlockData bd 
)
static

Decode the block data for a non-constant block.

Definition at line 914 of file alsdec.c.

Referenced by decode_block().

◆ read_block()

static int read_block ( ALSDecContext ctx,
ALSBlockData bd 
)
static

Read the block data.

Definition at line 1023 of file alsdec.c.

Referenced by read_decode_block(), and read_frame_data().

◆ decode_block()

static int decode_block ( ALSDecContext ctx,
ALSBlockData bd 
)
static

Decode the block data.

Definition at line 1050 of file alsdec.c.

Referenced by read_decode_block(), and read_frame_data().

◆ read_decode_block()

static int read_decode_block ( ALSDecContext ctx,
ALSBlockData bd 
)
static

Read and decode block data successively.

Definition at line 1076 of file alsdec.c.

Referenced by decode_blocks(), and decode_blocks_ind().

◆ zero_remaining()

static void zero_remaining ( unsigned int  b,
unsigned int  b_max,
const unsigned int div_blocks,
int32_t buf 
)
static

Compute the number of samples left to decode for the current frame and sets these samples to zero.

Definition at line 1090 of file alsdec.c.

Referenced by decode_blocks(), and decode_blocks_ind().

◆ decode_blocks_ind()

static int decode_blocks_ind ( ALSDecContext ctx,
unsigned int  ra_frame,
unsigned int  c,
const unsigned int div_blocks,
unsigned int js_blocks 
)
static

Decode blocks independently.

Definition at line 1105 of file alsdec.c.

Referenced by read_frame_data().

◆ decode_blocks()

static int decode_blocks ( ALSDecContext ctx,
unsigned int  ra_frame,
unsigned int  c,
const unsigned int div_blocks,
unsigned int js_blocks 
)
static

Decode blocks dependently.

Definition at line 1145 of file alsdec.c.

Referenced by read_frame_data().

◆ als_weighting()

static int als_weighting ( GetBitContext gb,
int  k,
int  off 
)
inlinestatic

Definition at line 1229 of file alsdec.c.

Referenced by read_channel_data().

◆ read_channel_data()

static int read_channel_data ( ALSDecContext ctx,
ALSChannelData cd,
int  c 
)
static

Read the channel data.

Definition at line 1238 of file alsdec.c.

Referenced by read_frame_data().

◆ revert_channel_correlation()

static int revert_channel_correlation ( ALSDecContext ctx,
ALSBlockData bd,
ALSChannelData **  cd,
int reverted,
unsigned int  offset,
int  c 
)
static

Recursively reverts the inter-channel correlation for a block.

Definition at line 1285 of file alsdec.c.

Referenced by read_frame_data().

◆ multiply()

static SoftFloat_IEEE754 multiply ( SoftFloat_IEEE754  a,
SoftFloat_IEEE754  b 
)
static

multiply two softfloats and handle the rounding off

Definition at line 1398 of file alsdec.c.

Referenced by checkasm_check_blend(), and read_diff_float_data().

◆ read_diff_float_data()

static int read_diff_float_data ( ALSDecContext ctx,
unsigned int  ra_frame 
)
static

Read and decode the floating point sample data.

Definition at line 1457 of file alsdec.c.

Referenced by read_frame_data().

◆ read_frame_data()

static int read_frame_data ( ALSDecContext ctx,
unsigned int  ra_frame 
)
static

Read the frame data.

< block sizes.

Definition at line 1640 of file alsdec.c.

Referenced by decode_frame().

◆ decode_frame()

static int decode_frame ( AVCodecContext avctx,
AVFrame frame,
int got_frame_ptr,
AVPacket avpkt 
)
static

Decode an ALS frame.

Definition at line 1799 of file alsdec.c.

◆ decode_end()

static av_cold int decode_end ( AVCodecContext avctx)
static

Uninitialize the ALS decoder.

Definition at line 1937 of file alsdec.c.

◆ decode_init()

static av_cold int decode_init ( AVCodecContext avctx)
static

Initialize the ALS decoder.

Definition at line 1989 of file alsdec.c.

◆ flush()

static av_cold void flush ( AVCodecContext avctx)
static

Flush (reset) the frame ID after seeking.

Definition at line 2175 of file alsdec.c.

Variable Documentation

◆ parcor_rice_table

const int8_t parcor_rice_table[3][20][2]
static
Initial value:
= {
{ {-52, 4}, {-29, 5}, {-31, 4}, { 19, 4}, {-16, 4},
{ 12, 3}, { -7, 3}, { 9, 3}, { -5, 3}, { 6, 3},
{ -4, 3}, { 3, 3}, { -3, 2}, { 3, 2}, { -2, 2},
{ 3, 2}, { -1, 2}, { 2, 2}, { -1, 2}, { 2, 2} },
{ {-58, 3}, {-42, 4}, {-46, 4}, { 37, 5}, {-36, 4},
{ 29, 4}, {-29, 4}, { 25, 4}, {-23, 4}, { 20, 4},
{-17, 4}, { 16, 4}, {-12, 4}, { 12, 3}, {-10, 4},
{ 7, 3}, { -4, 4}, { 3, 3}, { -1, 3}, { 1, 3} },
{ {-59, 3}, {-45, 5}, {-50, 4}, { 38, 4}, {-39, 4},
{ 32, 4}, {-30, 4}, { 25, 3}, {-23, 3}, { 20, 3},
{-20, 3}, { 16, 3}, {-13, 3}, { 10, 3}, { -7, 3},
{ 3, 3}, { 0, 3}, { -1, 3}, { 2, 3}, { -1, 2} }
}

Rice parameters and corresponding index offsets for decoding the indices of scaled PARCOR values.

The table chosen is set globally by the encoder and stored in ALSSpecificConfig.

Definition at line 52 of file alsdec.c.

Referenced by read_var_block_data().

◆ parcor_scaled_values

const int16_t parcor_scaled_values[]
static

Scaled PARCOR values used for the first two PARCOR coefficients.

To be indexed by the Rice coded indices. Generated by: parcor_scaled_values[i] = 32 + ((i * (i+1)) << 7) - (1 << 20) Actual values are divided by 32 in order to be stored in 16 bits.

Definition at line 73 of file alsdec.c.

Referenced by read_var_block_data().

◆ ltp_gain_values

const uint8_t ltp_gain_values[4][4]
static
Initial value:
= {
{ 0, 8, 16, 24},
{32, 40, 48, 56},
{64, 70, 76, 82},
{88, 92, 96, 100}
}

Gain values of p(0) for long-term prediction.

To be indexed by the Rice coded indices.

Definition at line 112 of file alsdec.c.

Referenced by read_var_block_data().

◆ mcc_weightings

const int16_t mcc_weightings[]
static
Initial value:
= {
204, 192, 179, 166, 153, 140, 128, 115,
102, 89, 76, 64, 51, 38, 25, 12,
0, -12, -25, -38, -51, -64, -76, -89,
-102, -115, -128, -140, -153, -166, -179, -192
}

Inter-channel weighting factors for multi-channel correlation.

To be indexed by the Rice coded indices.

Definition at line 123 of file alsdec.c.

Referenced by als_weighting().

◆ tail_code

const uint8_t tail_code[16][6]
static
Initial value:
= {
{ 74, 44, 25, 13, 7, 3},
{ 68, 42, 24, 13, 7, 3},
{ 58, 39, 23, 13, 7, 3},
{126, 70, 37, 19, 10, 5},
{132, 70, 37, 20, 10, 5},
{124, 70, 38, 20, 10, 5},
{120, 69, 37, 20, 11, 5},
{116, 67, 37, 20, 11, 5},
{108, 66, 36, 20, 10, 5},
{102, 62, 36, 20, 10, 5},
{ 88, 58, 34, 19, 10, 5},
{162, 89, 49, 25, 13, 7},
{156, 87, 49, 26, 14, 7},
{150, 86, 47, 26, 14, 7},
{142, 84, 47, 26, 14, 7},
{131, 79, 46, 26, 14, 7}
}

Tail codes used in arithmetic coding using block Gilbert-Moore codes.

Definition at line 133 of file alsdec.c.

Referenced by read_var_block_data().

◆ ff_als_decoder

const FFCodec ff_als_decoder
Initial value:
= {
.p.name = "als",
CODEC_LONG_NAME("MPEG-4 Audio Lossless Coding (ALS)"),
.p.type = AVMEDIA_TYPE_AUDIO,
.priv_data_size = sizeof(ALSDecContext),
.close = decode_end,
.flush = flush,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
}

Definition at line 2183 of file alsdec.c.

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
decode_init
static av_cold int decode_init(AVCodecContext *avctx)
Initialize the ALS decoder.
Definition: alsdec.c:1989
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
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
ctx
AVFormatContext * ctx
Definition: movenc.c:48
channels
channels
Definition: aptx.h:31
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
if
if(ret)
Definition: filter_design.txt:179
decode_end
static av_cold int decode_end(AVCodecContext *avctx)
Uninitialize the ALS decoder.
Definition: alsdec.c:1937
AV_CODEC_ID_MP4ALS
@ AV_CODEC_ID_MP4ALS
Definition: codec_id.h:483
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
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:103
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
shift
static int shift(int a, int b)
Definition: bonk.c:257
bps
unsigned bps
Definition: movenc.c:1642
sample
#define sample
Definition: flacdsp_template.c:44
ALSDecContext
Definition: alsdec.c:196
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
U
#define U(x)
Definition: vpx_arith.h:37
decode_frame
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Decode an ALS frame.
Definition: alsdec.c:1799
flush
static av_cold void flush(AVCodecContext *avctx)
Flush (reset) the frame ID after seeking.
Definition: alsdec.c:2175
AV_CODEC_CAP_SUBFRAMES
#define AV_CODEC_CAP_SUBFRAMES
Codec can output multiple frames per AVPacket Normally demuxers return one frame at a time,...
Definition: codec.h:94
int32_t
int32_t
Definition: audioconvert.c:56
convert_header.str
string str
Definition: convert_header.py:20
cond
int(* cond)(enum AVPixelFormat pix_fmt)
Definition: pixdesc_query.c:28