#include "avcodec.h"
#include "internal.h"
#include "get_bits.h"
#include "put_bits.h"
#include "dsputil.h"
#include "wma.h"
Go to the source code of this file.
Data Structures | |
struct | WmallChannelCtx |
frame specific decoder context for a single channel More... | |
struct | WmallChannelGrp |
channel group for channel transformations More... | |
struct | WmallDecodeCtx |
main decoder context More... | |
Defines | |
#define | WMALL_MAX_CHANNELS 8 |
current decoder limitations | |
#define | MAX_SUBFRAMES 32 |
max number of subframes per channel | |
#define | MAX_BANDS 29 |
max number of scale factor bands | |
#define | MAX_FRAMESIZE 32768 |
maximum compressed frame size | |
#define | WMALL_BLOCK_MIN_BITS 6 |
log2 of min block size | |
#define | WMALL_BLOCK_MAX_BITS 12 |
log2 of max block size | |
#define | WMALL_BLOCK_MAX_SIZE (1 << WMALL_BLOCK_MAX_BITS) |
maximum block size | |
#define | WMALL_BLOCK_SIZES (WMALL_BLOCK_MAX_BITS - WMALL_BLOCK_MIN_BITS + 1) |
possible block sizes | |
#define | VLCBITS 9 |
#define | SCALEVLCBITS 8 |
#define | VEC4MAXDEPTH ((HUFF_VEC4_MAXBITS+VLCBITS-1)/VLCBITS) |
#define | VEC2MAXDEPTH ((HUFF_VEC2_MAXBITS+VLCBITS-1)/VLCBITS) |
#define | VEC1MAXDEPTH ((HUFF_VEC1_MAXBITS+VLCBITS-1)/VLCBITS) |
#define | SCALEMAXDEPTH ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS) |
#define | SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS) |
#define | dprintf(pctx,...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__) |
#define | PRINT(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %d\n", a, b); |
#define | PRINT_HEX(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %x\n", a, b); |
Functions | |
static void av_cold | dump_context (WmallDecodeCtx *s) |
helper function to print the most important members of the context | |
static void | dump_int_buffer (uint8_t *buffer, int size, int length, int delimiter) |
static av_cold int | decode_end (AVCodecContext *avctx) |
Uninitialize the decoder and free all resources. | |
static av_cold int | decode_init (AVCodecContext *avctx) |
Initialize the decoder. | |
static int | decode_subframe_length (WmallDecodeCtx *s, int offset) |
Decode the subframe length. | |
static int | decode_tilehdr (WmallDecodeCtx *s) |
Decode how the data in the frame is split into subframes. | |
static int | my_log2 (unsigned int i) |
static void | decode_ac_filter (WmallDecodeCtx *s) |
static void | decode_mclms (WmallDecodeCtx *s) |
static void | 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) |
Resets filter parameters and transient area at new seekable tile. | |
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 int | lms_predict (WmallDecodeCtx *s, int ich, int ilms) |
static void | lms_update (WmallDecodeCtx *s, int ich, int ilms, int input, int residue) |
static void | use_high_update_speed (WmallDecodeCtx *s, int ich) |
static void | use_normal_update_speed (WmallDecodeCtx *s, int ich) |
static void | revert_cdlms (WmallDecodeCtx *s, int ch, int coef_begin, int coef_end) |
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) |
Decode a single subframe (block). | |
static int | decode_frame (WmallDecodeCtx *s) |
Decode one WMA frame. | |
static int | remaining_bits (WmallDecodeCtx *s, GetBitContext *gb) |
Calculate remaining input buffer length. | |
static void | save_bits (WmallDecodeCtx *s, GetBitContext *gb, int len, int append) |
Fill the bit reservoir with a (partial) frame. | |
static int | decode_packet (AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) |
Decode a single WMA packet. | |
static void | flush (AVCodecContext *avctx) |
Clear decoder buffers (for seeking). | |
Variables | |
static float | sin64 [33] |
sinus table for decorrelation | |
static int | num_logged_tiles = 0 |
static int | num_logged_subframes = 0 |
static int | num_lms_update_call = 0 |
AVCodec | ff_wmalossless_decoder |
wmall decoder |
The decoding therefore consists of the following steps:
The compressed wmall bitstream is split into individual packets. Every such packet contains one or more wma frames. The compressed frames may have a variable length and frames may cross packet boundaries. Common to all wmall frames is the number of samples that are stored in a frame. The number of samples and a few other decode flags are stored as extradata that has to be passed to the decoder.
The wmall frames themselves are again split into a variable number of subframes. Every subframe contains the data for 2^N time domain samples where N varies between 7 and 12.
Example wmall bitstream (in samples):
|| packet 0 || packet 1 || packet 2 packets --------------------------------------------------- || frame 0 || frame 1 || frame 2 || frames --------------------------------------------------- || | | || | | | || || subframes of channel 0 --------------------------------------------------- || | | || | | | || || subframes of channel 1 ---------------------------------------------------
The frame layouts for the individual channels of a wma frame does not need to be the same.
However, if the offsets and lengths of several subframes of a frame are the same, the subframes of the channels can be grouped. Every group may then use special coding techniques like M/S stereo coding to improve the compression ratio. These channel transformations do not need to be applied to a whole subframe. Instead, they can also work on individual scale factor bands (see below). The coefficients that carry the audio signal in the frequency domain are transmitted as huffman-coded vectors with 4, 2 and 1 elements. In addition to that, the encoder can switch to a runlevel coding scheme by transmitting subframe_length / 128 zero coefficients.
Before the audio signal can be converted to the time domain, the coefficients have to be rescaled and inverse quantized. A subframe is therefore split into several scale factor bands that get scaled individually. Scale factors are submitted for every frame but they might be shared between the subframes of a channel. Scale factors are initially DPCM-coded. Once scale factors are shared, the differences are transmitted as runlevel codes. Every subframe length and offset combination in the frame layout shares a common quantization factor that can be adjusted for every channel by a modifier. After the inverse quantization, the coefficients get processed by an IMDCT. The resulting values are then windowed with a sine window and the first half of the values are added to the second half of the output from the previous subframe in order to reconstruct the output samples.
Definition in file wmalosslessdec.c.
#define dprintf | ( | pctx, | |||
... | ) | av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__) |
Definition at line 291 of file wmalosslessdec.c.
Referenced by decode_frame(), decode_init(), decode_packet(), and decode_subframe().
#define MAX_BANDS 29 |
max number of scale factor bands
Definition at line 100 of file wmalosslessdec.c.
Referenced by decode_init().
#define MAX_FRAMESIZE 32768 |
maximum compressed frame size
Definition at line 101 of file wmalosslessdec.c.
Referenced by aw_parse_coords(), aw_pulse_set1(), aw_pulse_set2(), decode_init(), postfilter(), save_bits(), synth_block_fcb_acb(), synth_block_hardcoded(), synth_frame(), and synth_superframe().
#define MAX_SUBFRAMES 32 |
max number of subframes per channel
Definition at line 99 of file wmalosslessdec.c.
Referenced by decode_init(), and decode_tilehdr().
#define PRINT | ( | a, | |||
b | ) | av_log(s->avctx, AV_LOG_DEBUG, " %s = %d\n", a, b); |
Referenced by dump_context(), hex_dump_internal(), and pkt_dump_internal().
#define PRINT_HEX | ( | a, | |||
b | ) | av_log(s->avctx, AV_LOG_DEBUG, " %s = %x\n", a, b); |
Referenced by dump_context().
#define SCALEMAXDEPTH ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS) |
#define SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS) |
#define SCALEVLCBITS 8 |
Definition at line 110 of file wmalosslessdec.c.
Referenced by decode_init(), and decode_scale_factors().
#define VEC1MAXDEPTH ((HUFF_VEC1_MAXBITS+VLCBITS-1)/VLCBITS) |
#define VEC2MAXDEPTH ((HUFF_VEC2_MAXBITS+VLCBITS-1)/VLCBITS) |
#define VEC4MAXDEPTH ((HUFF_VEC4_MAXBITS+VLCBITS-1)/VLCBITS) |
#define VLCBITS 9 |
Definition at line 109 of file wmalosslessdec.c.
#define WMALL_BLOCK_MAX_BITS 12 |
#define WMALL_BLOCK_MAX_SIZE (1 << WMALL_BLOCK_MAX_BITS) |
#define WMALL_BLOCK_MIN_BITS 6 |
#define WMALL_BLOCK_SIZES (WMALL_BLOCK_MAX_BITS - WMALL_BLOCK_MIN_BITS + 1) |
#define WMALL_MAX_CHANNELS 8 |
current decoder limitations
max number of handled channels
Definition at line 98 of file wmalosslessdec.c.
Referenced by decode_init(), and decode_tilehdr().
static void clear_codec_buffers | ( | WmallDecodeCtx * | s | ) | [static] |
static void decode_ac_filter | ( | WmallDecodeCtx * | s | ) | [static] |
static void decode_cdlms | ( | WmallDecodeCtx * | s | ) | [static] |
static int decode_channel_residues | ( | WmallDecodeCtx * | s, | |
int | ch, | |||
int | tile_size | |||
) | [static] |
static av_cold int decode_end | ( | AVCodecContext * | avctx | ) | [static] |
Uninitialize the decoder and free all resources.
avctx | codec context |
Definition at line 333 of file wmalosslessdec.c.
static int decode_frame | ( | WmallDecodeCtx * | s | ) | [static] |
Decode one WMA frame.
s | codec context |
check for potential output buffer overflow
return an error if no frame could be decoded at all
get frame length
decode tile information
read drc info
no idea what these are for, might be the number of samples that need to be skipped at the beginning or end of a stream
usually true for the first frame
sometimes true for the last frame
reset subframe states
decode all subframes
FIXME: not sure if this is always an error
skip the rest of the frame data
decode trailer bit
Definition at line 1239 of file wmalosslessdec.c.
static av_cold int decode_init | ( | AVCodecContext * | avctx | ) | [static] |
Initialize the decoder.
avctx | codec context |
dump the extradata
generic init
frame info
get frame len
init previous block len
subframe info
extract lfe channel position
Definition at line 349 of file wmalosslessdec.c.
static void decode_lpc | ( | WmallDecodeCtx * | s | ) | [static] |
static void decode_mclms | ( | WmallDecodeCtx * | s | ) | [static] |
static int decode_packet | ( | AVCodecContext * | avctx, | |
void * | data, | |||
int * | data_size, | |||
AVPacket * | avpkt | |||
) | [static] |
Decode a single WMA packet.
avctx | codec context | |
data | the output buffer | |
data_size | number of bytes that were written to the output buffer | |
avpkt | input packet |
sanity check for the buffer length
parse packet header
get number of bits that need to be added to the previous frame
check for packet loss
append the previous frame data to the remaining data from the previous packet to create a full frame
decode the cross packet frame if it is valid
reset number of saved bits so that the decoder does not start to decode incomplete frames in the s->len_prefix == 0 case
when the frames do not have a length prefix, we don't know the compressed length of the individual frames however, we know what part of a new packet belongs to the previous frame therefore we save the incoming packet first, then we append the "previous frame" data from the next packet so that we get a buffer that only contains full frames
save the rest of the data so that it can be decoded with the next packet
Definition at line 1413 of file wmalosslessdec.c.
static int decode_subframe | ( | WmallDecodeCtx * | s | ) | [static] |
Decode a single subframe (block).
s | codec context |
reset channel context and find the next block offset and size == the next block of the channel with the smallest number of decoded samples
get a list of all channels that contain the estimated block
substract already processed samples
and count if there are multiple subframes that match our profile
check if the frame will be complete after processing the estimated block
handled one subframe
Definition at line 1071 of file wmalosslessdec.c.
static int decode_subframe_length | ( | WmallDecodeCtx * | s, | |
int | offset | |||
) | [static] |
Decode the subframe length.
s | context | |
offset | sample offset in the frame |
no need to read from the bitstream when only one length is possible
sanity check the length
Definition at line 450 of file wmalosslessdec.c.
Referenced by 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.
s | context |
< sum of samples for all currently known subframes of a channel
< flag indicating if a channel contains the current subframe
< number of channels that contain the current subframe
< flag indicating that all channels use the same subfra2me offsets and sizes
< smallest sum of samples (channels with this length will be processed first)
reset tiling information
loop until the frame data is split between the subframes
check which channels contain the subframe
get subframe length, subframe_len == 0 is not allowed
add subframes to the individual channels and find new min_channel_len
Definition at line 494 of file wmalosslessdec.c.
Referenced by decode_frame().
static void av_cold dump_context | ( | WmallDecodeCtx * | s | ) | [static] |
helper function to print the most important members of the context
s | context |
Definition at line 302 of file wmalosslessdec.c.
Referenced by decode_init().
static void dump_int_buffer | ( | uint8_t * | buffer, | |
int | size, | |||
int | length, | |||
int | delimiter | |||
) | [static] |
Definition at line 316 of file wmalosslessdec.c.
static void flush | ( | AVCodecContext * | avctx | ) | [static] |
Clear decoder buffers (for seeking).
avctx | codec context |
reset output buffer as a part of it is used during the windowing of a new frame
Definition at line 1536 of file wmalosslessdec.c.
static int lms_predict | ( | WmallDecodeCtx * | s, | |
int | ich, | |||
int | ilms | |||
) | [static] |
static void lms_update | ( | WmallDecodeCtx * | s, | |
int | ich, | |||
int | ilms, | |||
int | input, | |||
int | residue | |||
) | [static] |
static void mclms_predict | ( | WmallDecodeCtx * | s, | |
int | icoef, | |||
int * | pred | |||
) | [static] |
static void mclms_update | ( | WmallDecodeCtx * | s, | |
int | icoef, | |||
int * | pred | |||
) | [static] |
static int my_log2 | ( | unsigned int | i | ) | [static] |
static int remaining_bits | ( | WmallDecodeCtx * | s, | |
GetBitContext * | gb | |||
) | [static] |
Calculate remaining input buffer length.
s | codec context | |
gb | bitstream reader context |
Definition at line 1348 of file wmalosslessdec.c.
Referenced by decode_packet().
static void reset_codec | ( | WmallDecodeCtx * | s | ) | [static] |
Resets filter parameters and transient area at new seekable tile.
Definition at line 783 of file wmalosslessdec.c.
Referenced by decode_subframe().
static void revert_acfilter | ( | WmallDecodeCtx * | s, | |
int | tile_size | |||
) | [static] |
static void revert_cdlms | ( | WmallDecodeCtx * | s, | |
int | ch, | |||
int | coef_begin, | |||
int | coef_end | |||
) | [static] |
static void revert_inter_ch_decorr | ( | WmallDecodeCtx * | s, | |
int | tile_size | |||
) | [static] |
static void revert_mclms | ( | WmallDecodeCtx * | s, | |
int | tile_size | |||
) | [static] |
static void save_bits | ( | WmallDecodeCtx * | s, | |
GetBitContext * | gb, | |||
int | len, | |||
int | append | |||
) | [static] |
Fill the bit reservoir with a (partial) frame.
s | codec context | |
gb | bitstream reader context | |
len | length of the partial frame | |
append | decides wether to reset the buffer or not |
when the frame data does not need to be concatenated, the input buffer is resetted and additional bits from the previous frame are copyed and skipped later so that a fast byte copy is possible
Definition at line 1360 of file wmalosslessdec.c.
Referenced by decode_packet().
static void use_high_update_speed | ( | WmallDecodeCtx * | s, | |
int | ich | |||
) | [static] |
static void use_normal_update_speed | ( | WmallDecodeCtx * | s, | |
int | ich | |||
) | [static] |
Initial value:
{ "wmalossless", AVMEDIA_TYPE_AUDIO, CODEC_ID_WMALOSSLESS, sizeof(WmallDecodeCtx), decode_init, NULL, decode_end, decode_packet, .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_EXPERIMENTAL, .flush= flush, .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 9 Lossless"), }
Definition at line 1552 of file wmalosslessdec.c.
int num_lms_update_call = 0 [static] |
Definition at line 296 of file wmalosslessdec.c.
int num_logged_subframes = 0 [static] |
int num_logged_tiles = 0 [static] |
Definition at line 294 of file wmalosslessdec.c.
float sin64[33] [static] |
sinus table for decorrelation
Definition at line 117 of file wmalosslessdec.c.
Referenced by decode_decorrelation_matrix(), and decode_init().