FFmpeg
Data Structures | Macros | Functions | Variables
wmalosslessdec.c File Reference
#include <inttypes.h>
#include "libavutil/attributes.h"
#include "libavutil/avassert.h"
#include "libavutil/mem_internal.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "decode.h"
#include "get_bits.h"
#include "put_bits.h"
#include "lossless_audiodsp.h"
#include "wma_common.h"

Go to the source code of this file.

Data Structures

struct  WmallChannelCtx
 frame-specific decoder context for a single channel More...
 
struct  WmallDecodeCtx
 main decoder context More...
 

Macros

#define WMALL_MAX_CHANNELS   8
 current decoder limitations More...
 
#define MAX_SUBFRAMES   32
 max number of subframes per channel More...
 
#define MAX_BANDS   29
 max number of scale factor bands More...
 
#define MAX_FRAMESIZE   32768
 maximum compressed frame size More...
 
#define MAX_ORDER   256
 
#define WMALL_BLOCK_MIN_BITS   6
 log2 of min block size More...
 
#define WMALL_BLOCK_MAX_BITS   14
 log2 of max block size More...
 
#define WMALL_BLOCK_MAX_SIZE   (1 << WMALL_BLOCK_MAX_BITS)
 maximum block size More...
 
#define WMALL_BLOCK_SIZES   (WMALL_BLOCK_MAX_BITS - WMALL_BLOCK_MIN_BITS + 1)
 possible block sizes More...
 
#define WMALL_COEFF_PAD_SIZE   16
 pad coef buffers with 0 for use with SIMD More...
 
#define WMASIGN(x)   (((x) > 0) - ((x) < 0))
 Get sign of integer (1 for positive, -1 for negative and 0 for zero) More...
 
#define CD_LMS(bits, ROUND)
 

Functions

static av_cold int decode_init (AVCodecContext *avctx)
 
static int decode_subframe_length (WmallDecodeCtx *s, int offset)
 Decode the subframe length. More...
 
static int decode_tilehdr (WmallDecodeCtx *s)
 Decode how the data in the frame is split into subframes. More...
 
static void decode_ac_filter (WmallDecodeCtx *s)
 
static void decode_mclms (WmallDecodeCtx *s)
 
static int decode_cdlms (WmallDecodeCtx *s)
 
static int decode_channel_residues (WmallDecodeCtx *s, int ch, int tile_size)
 
static void decode_lpc (WmallDecodeCtx *s)
 
static void clear_codec_buffers (WmallDecodeCtx *s)
 
static void reset_codec (WmallDecodeCtx *s)
 Reset filter parameters and transient area at new seekable tile. More...
 
static void mclms_update (WmallDecodeCtx *s, int icoef, int *pred)
 
static void mclms_predict (WmallDecodeCtx *s, int icoef, int *pred)
 
static void revert_mclms (WmallDecodeCtx *s, int tile_size)
 
static void use_high_update_speed (WmallDecodeCtx *s, int ich)
 
static void use_normal_update_speed (WmallDecodeCtx *s, int ich)
 
static void revert_inter_ch_decorr (WmallDecodeCtx *s, int tile_size)
 
static void revert_acfilter (WmallDecodeCtx *s, int tile_size)
 
static int decode_subframe (WmallDecodeCtx *s)
 
static int decode_frame (WmallDecodeCtx *s)
 Decode one WMA frame. More...
 
static int remaining_bits (WmallDecodeCtx *s, GetBitContext *gb)
 Calculate remaining input buffer length. More...
 
static void save_bits (WmallDecodeCtx *s, GetBitContext *gb, int len, int append)
 Fill the bit reservoir with a (partial) frame. More...
 
static int decode_packet (AVCodecContext *avctx, AVFrame *rframe, int *got_frame_ptr, AVPacket *avpkt)
 
static void flush (AVCodecContext *avctx)
 
static av_cold int decode_close (AVCodecContext *avctx)
 

Variables

const FFCodec ff_wmalossless_decoder
 

Macro Definition Documentation

◆ WMALL_MAX_CHANNELS

#define WMALL_MAX_CHANNELS   8

current decoder limitations

max number of handled channels

Definition at line 40 of file wmalosslessdec.c.

◆ MAX_SUBFRAMES

#define MAX_SUBFRAMES   32

max number of subframes per channel

Definition at line 41 of file wmalosslessdec.c.

◆ MAX_BANDS

#define MAX_BANDS   29

max number of scale factor bands

Definition at line 42 of file wmalosslessdec.c.

◆ MAX_FRAMESIZE

#define MAX_FRAMESIZE   32768

maximum compressed frame size

Definition at line 43 of file wmalosslessdec.c.

◆ MAX_ORDER

#define MAX_ORDER   256

Definition at line 44 of file wmalosslessdec.c.

◆ WMALL_BLOCK_MIN_BITS

#define WMALL_BLOCK_MIN_BITS   6

log2 of min block size

Definition at line 46 of file wmalosslessdec.c.

◆ WMALL_BLOCK_MAX_BITS

#define WMALL_BLOCK_MAX_BITS   14

log2 of max block size

Definition at line 47 of file wmalosslessdec.c.

◆ WMALL_BLOCK_MAX_SIZE

#define WMALL_BLOCK_MAX_SIZE   (1 << WMALL_BLOCK_MAX_BITS)

maximum block size

Definition at line 48 of file wmalosslessdec.c.

◆ WMALL_BLOCK_SIZES

#define WMALL_BLOCK_SIZES   (WMALL_BLOCK_MAX_BITS - WMALL_BLOCK_MIN_BITS + 1)

possible block sizes

Definition at line 49 of file wmalosslessdec.c.

◆ WMALL_COEFF_PAD_SIZE

#define WMALL_COEFF_PAD_SIZE   16

pad coef buffers with 0 for use with SIMD

Definition at line 51 of file wmalosslessdec.c.

◆ WMASIGN

#define WMASIGN (   x)    (((x) > 0) - ((x) < 0))

Get sign of integer (1 for positive, -1 for negative and 0 for zero)

Definition at line 179 of file wmalosslessdec.c.

◆ CD_LMS

#define CD_LMS (   bits,
  ROUND 
)

Definition at line 733 of file wmalosslessdec.c.

Function Documentation

◆ decode_init()

static av_cold int decode_init ( AVCodecContext avctx)
static

Definition at line 181 of file wmalosslessdec.c.

◆ decode_subframe_length()

static int decode_subframe_length ( WmallDecodeCtx s,
int  offset 
)
static

Decode the subframe length.

Parameters
scontext
offsetsample offset in the frame
Returns
decoded subframe length on success, < 0 in case of an error

Definition at line 295 of file wmalosslessdec.c.

Referenced by decode_tilehdr().

◆ decode_tilehdr()

static int decode_tilehdr ( WmallDecodeCtx s)
static

Decode how the data in the frame is split into subframes.

Every WMA frame contains the encoded data for a fixed number of samples per channel. The data for every channel might be split into several subframes. This function will reconstruct the list of subframes for every channel.

If the subframes are not evenly split, the algorithm estimates the channels with the lowest number of total samples. Afterwards, for each of these channels a bit is read from the bitstream that indicates if the channel contains a subframe with the next subframe size that is going to be read from the bitstream or not. If a channel contains such a subframe, the subframe size gets added to the channel's subframe list. The algorithm repeats these steps until the frame is properly divided between the individual channels.

Parameters
scontext
Returns
0 on success, < 0 in case of an error

Definition at line 337 of file wmalosslessdec.c.

Referenced by decode_frame().

◆ decode_ac_filter()

static void decode_ac_filter ( WmallDecodeCtx s)
static

Definition at line 422 of file wmalosslessdec.c.

Referenced by decode_subframe().

◆ decode_mclms()

static void decode_mclms ( WmallDecodeCtx s)
static

Definition at line 432 of file wmalosslessdec.c.

Referenced by decode_subframe().

◆ decode_cdlms()

static int decode_cdlms ( WmallDecodeCtx s)
static

Definition at line 455 of file wmalosslessdec.c.

Referenced by decode_subframe().

◆ decode_channel_residues()

static int decode_channel_residues ( WmallDecodeCtx s,
int  ch,
int  tile_size 
)
static

Definition at line 512 of file wmalosslessdec.c.

Referenced by decode_subframe().

◆ decode_lpc()

static void decode_lpc ( WmallDecodeCtx s)
static

Definition at line 569 of file wmalosslessdec.c.

Referenced by decode_subframe().

◆ clear_codec_buffers()

static void clear_codec_buffers ( WmallDecodeCtx s)
static

Definition at line 581 of file wmalosslessdec.c.

Referenced by decode_subframe().

◆ reset_codec()

static void reset_codec ( WmallDecodeCtx s)
static

Reset filter parameters and transient area at new seekable tile.

Definition at line 610 of file wmalosslessdec.c.

Referenced by decode_subframe().

◆ mclms_update()

static void mclms_update ( WmallDecodeCtx s,
int  icoef,
int pred 
)
static

Definition at line 625 of file wmalosslessdec.c.

Referenced by revert_mclms().

◆ mclms_predict()

static void mclms_predict ( WmallDecodeCtx s,
int  icoef,
int pred 
)
static

Definition at line 667 of file wmalosslessdec.c.

Referenced by revert_mclms().

◆ revert_mclms()

static void revert_mclms ( WmallDecodeCtx s,
int  tile_size 
)
static

Definition at line 689 of file wmalosslessdec.c.

Referenced by decode_subframe().

◆ use_high_update_speed()

static void use_high_update_speed ( WmallDecodeCtx s,
int  ich 
)
static

Definition at line 698 of file wmalosslessdec.c.

Referenced by decode_subframe().

◆ use_normal_update_speed()

static void use_normal_update_speed ( WmallDecodeCtx s,
int  ich 
)
static

Definition at line 716 of file wmalosslessdec.c.

Referenced by decode_subframe().

◆ revert_inter_ch_decorr()

static void revert_inter_ch_decorr ( WmallDecodeCtx s,
int  tile_size 
)
static

Definition at line 790 of file wmalosslessdec.c.

Referenced by decode_subframe().

◆ revert_acfilter()

static void revert_acfilter ( WmallDecodeCtx s,
int  tile_size 
)
static

Definition at line 803 of file wmalosslessdec.c.

Referenced by decode_subframe().

◆ decode_subframe()

static int decode_subframe ( WmallDecodeCtx s)
static

Definition at line 838 of file wmalosslessdec.c.

Referenced by decode_frame().

◆ decode_frame()

static int decode_frame ( WmallDecodeCtx s)
static

Decode one WMA frame.

Parameters
scodec context
Returns
0 if the trailer bit indicates that this is the last frame, 1 if there are additional frames

Definition at line 1024 of file wmalosslessdec.c.

Referenced by decode_packet().

◆ remaining_bits()

static int remaining_bits ( WmallDecodeCtx s,
GetBitContext gb 
)
static

Calculate remaining input buffer length.

Parameters
scodec context
gbbitstream reader context
Returns
remaining size in bits

Definition at line 1127 of file wmalosslessdec.c.

Referenced by decode_packet().

◆ save_bits()

static void save_bits ( WmallDecodeCtx s,
GetBitContext gb,
int  len,
int  append 
)
static

Fill the bit reservoir with a (partial) frame.

Parameters
scodec context
gbbitstream reader context
lenlength of the partial frame
appenddecides whether to reset the buffer or not

Definition at line 1139 of file wmalosslessdec.c.

Referenced by decode_packet().

◆ decode_packet()

static int decode_packet ( AVCodecContext avctx,
AVFrame rframe,
int got_frame_ptr,
AVPacket avpkt 
)
static

Definition at line 1184 of file wmalosslessdec.c.

◆ flush()

static void flush ( AVCodecContext avctx)
static

Definition at line 1304 of file wmalosslessdec.c.

◆ decode_close()

static av_cold int decode_close ( AVCodecContext avctx)
static

Definition at line 1317 of file wmalosslessdec.c.

Variable Documentation

◆ ff_wmalossless_decoder

const FFCodec ff_wmalossless_decoder
Initial value:
= {
.p.name = "wmalossless",
CODEC_LONG_NAME("Windows Media Audio Lossless"),
.p.type = AVMEDIA_TYPE_AUDIO,
.priv_data_size = sizeof(WmallDecodeCtx),
.close = decode_close,
.flush = flush,
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
.p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
}

Definition at line 1327 of file wmalosslessdec.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
AV_SAMPLE_FMT_S32P
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition: samplefmt.h:65
decode_close
static av_cold int decode_close(AVCodecContext *avctx)
Definition: wmalosslessdec.c:1317
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
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
AV_CODEC_ID_WMALOSSLESS
@ AV_CODEC_ID_WMALOSSLESS
Definition: codec_id.h:476
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
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:64
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
WmallDecodeCtx
main decoder context
Definition: wmalosslessdec.c:71
decode_init
static av_cold int decode_init(AVCodecContext *avctx)
Definition: wmalosslessdec.c:181
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:76
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
decode_packet
static int decode_packet(AVCodecContext *avctx, AVFrame *rframe, int *got_frame_ptr, AVPacket *avpkt)
Definition: wmalosslessdec.c:1184
flush
static void flush(AVCodecContext *avctx)
Definition: wmalosslessdec.c:1304