FFmpeg
Data Structures | Macros | Functions | Variables
mlpdec.c File Reference
#include "config_components.h"
#include <stdint.h>
#include "avcodec.h"
#include "libavutil/internal.h"
#include "libavutil/intreadwrite.h"
#include "libavutil/channel_layout.h"
#include "libavutil/mem_internal.h"
#include "libavutil/thread.h"
#include "libavutil/opt.h"
#include "codec_internal.h"
#include "get_bits.h"
#include "internal.h"
#include "libavutil/crc.h"
#include "parser.h"
#include "mlp_parse.h"
#include "mlpdsp.h"
#include "mlp.h"
#include "config.h"

Go to the source code of this file.

Data Structures

struct  SubStream
 
struct  MLPDecodeContext
 

Macros

#define VLC_BITS   9
 number of bits used for VLC lookup - longest Huffman code is 9 More...
 
#define VLC_STATIC_SIZE   512
 
#define PARAM_BLOCKSIZE   (1 << 7)
 
#define PARAM_MATRIX   (1 << 6)
 
#define PARAM_OUTSHIFT   (1 << 5)
 
#define PARAM_QUANTSTEP   (1 << 4)
 
#define PARAM_FIR   (1 << 3)
 
#define PARAM_IIR   (1 << 2)
 
#define PARAM_HUFFOFFSET   (1 << 1)
 
#define PARAM_PRESENCE   (1 << 0)
 
#define MSB_MASK(bits)   (-(1 << (bits)))
 
#define OFFSET(x)   offsetof(MLPDecodeContext, x)
 
#define FLAGS   (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM)
 

Functions

static int mlp_channel_layout_subset (AVChannelLayout *layout, uint64_t mask)
 
static enum AVChannel thd_channel_layout_extract_channel (uint64_t channel_layout, int index)
 
static av_cold void init_static (void)
 Initialize static data, constant between all invocations of the codec. More...
 
static int32_t calculate_sign_huff (MLPDecodeContext *m, unsigned int substr, unsigned int ch)
 
static int read_huff_channels (MLPDecodeContext *m, GetBitContext *gbp, unsigned int substr, unsigned int pos)
 Read a sample, consisting of either, both or neither of entropy-coded MSBs and plain LSBs. More...
 
static av_cold int mlp_decode_init (AVCodecContext *avctx)
 
static int read_major_sync (MLPDecodeContext *m, GetBitContext *gb)
 Read a major sync info header - contains high level information about the stream - sample rate, channel arrangement etc. More...
 
static int read_restart_header (MLPDecodeContext *m, GetBitContext *gbp, const uint8_t *buf, unsigned int substr)
 Read a restart header from a block in a substream. More...
 
static int read_filter_params (MLPDecodeContext *m, GetBitContext *gbp, unsigned int substr, unsigned int channel, unsigned int filter)
 Read parameters for one of the prediction filters. More...
 
static int read_matrix_params (MLPDecodeContext *m, unsigned int substr, GetBitContext *gbp)
 Read parameters for primitive matrices. More...
 
static int read_channel_params (MLPDecodeContext *m, unsigned int substr, GetBitContext *gbp, unsigned int ch)
 Read channel parameters. More...
 
static int read_decoding_params (MLPDecodeContext *m, GetBitContext *gbp, unsigned int substr)
 Read decoding parameters that change more often than those in the restart header. More...
 
static void filter_channel (MLPDecodeContext *m, unsigned int substr, unsigned int channel)
 Generate PCM samples using the prediction filters and residual values read from the data stream, and update the filter state. More...
 
static int read_block_data (MLPDecodeContext *m, GetBitContext *gbp, unsigned int substr)
 Read a block of PCM residual data (or actual if no filtering active). More...
 
static void generate_2_noise_channels (MLPDecodeContext *m, unsigned int substr)
 Noise generation functions. More...
 
static void fill_noise_buffer (MLPDecodeContext *m, unsigned int substr)
 Generate a block of noise, used when restart sync word == 0x31eb. More...
 
static int output_data (MLPDecodeContext *m, unsigned int substr, AVFrame *frame, int *got_frame_ptr)
 Write the audio data into the output buffer. More...
 
static int read_access_unit (AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
 Read an access unit from the stream. More...
 
static void mlp_decode_flush (AVCodecContext *avctx)
 

Variables

static enum AVChannel thd_channel_order []
 
static VLC huff_vlc [3]
 
static const int8_t noise_table [256]
 Data table used for TrueHD noise generation function. More...
 
static const AVOption options []
 
static const AVClass mlp_decoder_class
 
static const AVClass truehd_decoder_class
 

Detailed Description

MLP decoder

Definition in file mlpdec.c.

Macro Definition Documentation

◆ VLC_BITS

#define VLC_BITS   9

number of bits used for VLC lookup - longest Huffman code is 9

Definition at line 53 of file mlpdec.c.

◆ VLC_STATIC_SIZE

#define VLC_STATIC_SIZE   512

Definition at line 54 of file mlpdec.c.

◆ PARAM_BLOCKSIZE

#define PARAM_BLOCKSIZE   (1 << 7)

Definition at line 95 of file mlpdec.c.

◆ PARAM_MATRIX

#define PARAM_MATRIX   (1 << 6)

Definition at line 96 of file mlpdec.c.

◆ PARAM_OUTSHIFT

#define PARAM_OUTSHIFT   (1 << 5)

Definition at line 97 of file mlpdec.c.

◆ PARAM_QUANTSTEP

#define PARAM_QUANTSTEP   (1 << 4)

Definition at line 98 of file mlpdec.c.

◆ PARAM_FIR

#define PARAM_FIR   (1 << 3)

Definition at line 99 of file mlpdec.c.

◆ PARAM_IIR

#define PARAM_IIR   (1 << 2)

Definition at line 100 of file mlpdec.c.

◆ PARAM_HUFFOFFSET

#define PARAM_HUFFOFFSET   (1 << 1)

Definition at line 101 of file mlpdec.c.

◆ PARAM_PRESENCE

#define PARAM_PRESENCE   (1 << 0)

Definition at line 102 of file mlpdec.c.

◆ MSB_MASK

#define MSB_MASK (   bits)    (-(1 << (bits)))

Definition at line 952 of file mlpdec.c.

◆ OFFSET

#define OFFSET (   x)    offsetof(MLPDecodeContext, x)

Definition at line 1396 of file mlpdec.c.

◆ FLAGS

Definition at line 1397 of file mlpdec.c.

Function Documentation

◆ mlp_channel_layout_subset()

static int mlp_channel_layout_subset ( AVChannelLayout layout,
uint64_t  mask 
)
static

Definition at line 195 of file mlpdec.c.

Referenced by read_restart_header().

◆ thd_channel_layout_extract_channel()

static enum AVChannel thd_channel_layout_extract_channel ( uint64_t  channel_layout,
int  index 
)
static

Definition at line 202 of file mlpdec.c.

Referenced by read_restart_header().

◆ init_static()

static av_cold void init_static ( void  )
static

Initialize static data, constant between all invocations of the codec.

Definition at line 220 of file mlpdec.c.

Referenced by mlp_decode_init().

◆ calculate_sign_huff()

static int32_t calculate_sign_huff ( MLPDecodeContext m,
unsigned int  substr,
unsigned int  ch 
)
inlinestatic

Definition at line 234 of file mlpdec.c.

Referenced by read_decoding_params().

◆ read_huff_channels()

static int read_huff_channels ( MLPDecodeContext m,
GetBitContext gbp,
unsigned int  substr,
unsigned int  pos 
)
inlinestatic

Read a sample, consisting of either, both or neither of entropy-coded MSBs and plain LSBs.

Definition at line 255 of file mlpdec.c.

Referenced by read_block_data().

◆ mlp_decode_init()

static av_cold int mlp_decode_init ( AVCodecContext avctx)
static

Definition at line 291 of file mlpdec.c.

◆ read_major_sync()

static int read_major_sync ( MLPDecodeContext m,
GetBitContext gb 
)
static

Read a major sync info header - contains high level information about the stream - sample rate, channel arrangement etc.

Most of this information is not actually necessary for decoding, only for playback.

Definition at line 320 of file mlpdec.c.

Referenced by read_access_unit().

◆ read_restart_header()

static int read_restart_header ( MLPDecodeContext m,
GetBitContext gbp,
const uint8_t *  buf,
unsigned int  substr 
)
static

Read a restart header from a block in a substream.

This contains parameters required to decode the audio that do not change very often. Generally (always) present only in blocks following a major sync.

Definition at line 502 of file mlpdec.c.

Referenced by read_access_unit().

◆ read_filter_params()

static int read_filter_params ( MLPDecodeContext m,
GetBitContext gbp,
unsigned int  substr,
unsigned int  channel,
unsigned int  filter 
)
static

Read parameters for one of the prediction filters.

Definition at line 674 of file mlpdec.c.

Referenced by read_channel_params().

◆ read_matrix_params()

static int read_matrix_params ( MLPDecodeContext m,
unsigned int  substr,
GetBitContext gbp 
)
static

Read parameters for primitive matrices.

Definition at line 749 of file mlpdec.c.

Referenced by read_decoding_params().

◆ read_channel_params()

static int read_channel_params ( MLPDecodeContext m,
unsigned int  substr,
GetBitContext gbp,
unsigned int  ch 
)
static

Read channel parameters.

Definition at line 817 of file mlpdec.c.

Referenced by read_decoding_params().

◆ read_decoding_params()

static int read_decoding_params ( MLPDecodeContext m,
GetBitContext gbp,
unsigned int  substr 
)
static

Read decoding parameters that change more often than those in the restart header.

Definition at line 874 of file mlpdec.c.

Referenced by read_access_unit().

◆ filter_channel()

static void filter_channel ( MLPDecodeContext m,
unsigned int  substr,
unsigned int  channel 
)
static

Generate PCM samples using the prediction filters and residual values read from the data stream, and update the filter state.

Definition at line 957 of file mlpdec.c.

Referenced by read_block_data().

◆ read_block_data()

static int read_block_data ( MLPDecodeContext m,
GetBitContext gbp,
unsigned int  substr 
)
static

Read a block of PCM residual data (or actual if no filtering active).

Definition at line 984 of file mlpdec.c.

Referenced by read_access_unit().

◆ generate_2_noise_channels()

static void generate_2_noise_channels ( MLPDecodeContext m,
unsigned int  substr 
)
static

Noise generation functions.

I'm not sure what these are for - they seem to be some kind of pseudorandom sequence generators, used to generate noise data which is used when the channels are rematrixed. I'm not sure if they provide a practical benefit to compression, or just obfuscate the decoder. Are they for some kind of dithering? Generate two channels of noise, used in the matrix when restart sync word == 0x31ea.

Definition at line 1055 of file mlpdec.c.

Referenced by output_data().

◆ fill_noise_buffer()

static void fill_noise_buffer ( MLPDecodeContext m,
unsigned int  substr 
)
static

Generate a block of noise, used when restart sync word == 0x31eb.

Definition at line 1075 of file mlpdec.c.

Referenced by output_data().

◆ output_data()

static int output_data ( MLPDecodeContext m,
unsigned int  substr,
AVFrame frame,
int got_frame_ptr 
)
static

Write the audio data into the output buffer.

Definition at line 1092 of file mlpdec.c.

Referenced by apng_do_inverse_blend(), free_data_planes(), read_access_unit(), and test_function().

◆ read_access_unit()

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

Read an access unit from the stream.

Returns
negative on error, 0 if not enough data is present in the input stream, otherwise the number of bytes consumed.

Definition at line 1167 of file mlpdec.c.

◆ mlp_decode_flush()

static void mlp_decode_flush ( AVCodecContext avctx)
static

Definition at line 1383 of file mlpdec.c.

Variable Documentation

◆ thd_channel_order

enum AVChannel thd_channel_order[]
static

◆ huff_vlc

VLC huff_vlc[3]
static

Definition at line 216 of file mlpdec.c.

Referenced by init_static(), and read_huff_channels().

◆ noise_table

const int8_t noise_table[256]
static
Initial value:
= {
30, 51, 22, 54, 3, 7, -4, 38, 14, 55, 46, 81, 22, 58, -3, 2,
52, 31, -7, 51, 15, 44, 74, 30, 85, -17, 10, 33, 18, 80, 28, 62,
10, 32, 23, 69, 72, 26, 35, 17, 73, 60, 8, 56, 2, 6, -2, -5,
51, 4, 11, 50, 66, 76, 21, 44, 33, 47, 1, 26, 64, 48, 57, 40,
38, 16, -10, -28, 92, 22, -18, 29, -10, 5, -13, 49, 19, 24, 70, 34,
61, 48, 30, 14, -6, 25, 58, 33, 42, 60, 67, 17, 54, 17, 22, 30,
67, 44, -9, 50, -11, 43, 40, 32, 59, 82, 13, 49, -14, 55, 60, 36,
48, 49, 31, 47, 15, 12, 4, 65, 1, 23, 29, 39, 45, -2, 84, 69,
0, 72, 37, 57, 27, 41, -15, -16, 35, 31, 14, 61, 24, 0, 27, 24,
16, 41, 55, 34, 53, 9, 56, 12, 25, 29, 53, 5, 20, -20, -8, 20,
13, 28, -3, 78, 38, 16, 11, 62, 46, 29, 21, 24, 46, 65, 43, -23,
89, 18, 74, 21, 38, -12, 19, 12, -19, 8, 15, 33, 4, 57, 9, -8,
36, 35, 26, 28, 7, 83, 63, 79, 75, 11, 3, 87, 37, 47, 34, 40,
39, 19, 20, 42, 27, 34, 39, 77, 13, 42, 59, 64, 45, -1, 32, 37,
45, -5, 53, -6, 7, 36, 50, 23, 6, 32, 9, -21, 18, 71, 27, 52,
-25, 31, 35, 42, -1, 68, 63, 52, 26, 43, 66, 37, 41, 25, 40, 70,
}

Data table used for TrueHD noise generation function.

Definition at line 1026 of file mlpdec.c.

Referenced by fill_noise_buffer(), and main().

◆ options

const AVOption options[]
static
Initial value:
= {
{ "downmix", "Request a specific channel layout from the decoder", OFFSET(downmix_layout),
AV_OPT_TYPE_CHLAYOUT, {.str = NULL}, .flags = FLAGS },
{ NULL },
}

Definition at line 1398 of file mlpdec.c.

◆ mlp_decoder_class

const AVClass mlp_decoder_class
static
Initial value:
= {
.class_name = "MLP decoder",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 1404 of file mlpdec.c.

◆ truehd_decoder_class

const AVClass truehd_decoder_class
static
Initial value:
= {
.class_name = "TrueHD decoder",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 1411 of file mlpdec.c.

AV_CHAN_BACK_RIGHT
@ AV_CHAN_BACK_RIGHT
Definition: channel_layout.h:49
AV_CHAN_TOP_FRONT_LEFT
@ AV_CHAN_TOP_FRONT_LEFT
Definition: channel_layout.h:56
AV_CHAN_LOW_FREQUENCY_2
@ AV_CHAN_LOW_FREQUENCY_2
Definition: channel_layout.h:70
FLAGS
#define FLAGS
Definition: mlpdec.c:1397
AV_CHAN_LOW_FREQUENCY
@ AV_CHAN_LOW_FREQUENCY
Definition: channel_layout.h:47
OFFSET
#define OFFSET(x)
Definition: mlpdec.c:1396
AV_CHAN_FRONT_RIGHT_OF_CENTER
@ AV_CHAN_FRONT_RIGHT_OF_CENTER
Definition: channel_layout.h:51
AV_CHAN_TOP_FRONT_RIGHT
@ AV_CHAN_TOP_FRONT_RIGHT
Definition: channel_layout.h:58
AV_CHAN_FRONT_RIGHT
@ AV_CHAN_FRONT_RIGHT
Definition: channel_layout.h:45
AV_CHAN_TOP_FRONT_CENTER
@ AV_CHAN_TOP_FRONT_CENTER
Definition: channel_layout.h:57
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_CHAN_FRONT_LEFT
@ AV_CHAN_FRONT_LEFT
Definition: channel_layout.h:44
AV_CHAN_FRONT_LEFT_OF_CENTER
@ AV_CHAN_FRONT_LEFT_OF_CENTER
Definition: channel_layout.h:50
AV_OPT_TYPE_CHLAYOUT
@ AV_OPT_TYPE_CHLAYOUT
Definition: opt.h:245
AV_CHAN_SIDE_RIGHT
@ AV_CHAN_SIDE_RIGHT
Definition: channel_layout.h:54
AV_CHAN_BACK_LEFT
@ AV_CHAN_BACK_LEFT
Definition: channel_layout.h:48
options
static const AVOption options[]
Definition: mlpdec.c:1398
AV_CHAN_BACK_CENTER
@ AV_CHAN_BACK_CENTER
Definition: channel_layout.h:52
AV_CHAN_WIDE_LEFT
@ AV_CHAN_WIDE_LEFT
Definition: channel_layout.h:66
AV_CHAN_SIDE_LEFT
@ AV_CHAN_SIDE_LEFT
Definition: channel_layout.h:53
AV_CHAN_FRONT_CENTER
@ AV_CHAN_FRONT_CENTER
Definition: channel_layout.h:46
AV_CHAN_SURROUND_DIRECT_RIGHT
@ AV_CHAN_SURROUND_DIRECT_RIGHT
Definition: channel_layout.h:69
AV_CHAN_WIDE_RIGHT
@ AV_CHAN_WIDE_RIGHT
Definition: channel_layout.h:67
AV_CHAN_SURROUND_DIRECT_LEFT
@ AV_CHAN_SURROUND_DIRECT_LEFT
Definition: channel_layout.h:68
AV_CHAN_TOP_CENTER
@ AV_CHAN_TOP_CENTER
Definition: channel_layout.h:55