39 #define WMALL_MAX_CHANNELS 8
40 #define MAX_SUBFRAMES 32
42 #define MAX_FRAMESIZE 32768
45 #define WMALL_BLOCK_MIN_BITS 6
46 #define WMALL_BLOCK_MAX_BITS 14
47 #define WMALL_BLOCK_MAX_SIZE (1 << WMALL_BLOCK_MAX_BITS)
48 #define WMALL_BLOCK_SIZES (WMALL_BLOCK_MAX_BITS - WMALL_BLOCK_MIN_BITS + 1)
50 #define WMALL_COEFF_PAD_SIZE 16
179 #define WMASIGN(x) (((x) > 0) - ((x) < 0))
185 unsigned int channel_mask;
186 int i, log2_max_num_subframes;
199 channel_mask =
AV_RL32(edata_ptr + 2);
235 for (i = 0; i < avctx->
channels; i++)
259 if (channel_mask & 8) {
261 for (mask = 1; mask < 16; mask <<= 1)
262 if (channel_mask & mask)
292 int frame_len_ratio, subframe_len,
len;
303 if (subframe_len < s->min_samples_per_subframe ||
337 int fixed_channel_layout = 0;
338 int min_channel_len = 0;
347 fixed_channel_layout = 1;
351 int subframe_len, in_use = 0;
355 if (num_samples[c] == min_channel_len) {
356 if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
358 contains_subframe[
c] = 1;
362 in_use |= contains_subframe[
c];
364 contains_subframe[
c] = 0;
369 "Found empty subframe\n");
377 min_channel_len += subframe_len;
381 if (contains_subframe[c]) {
384 "broken frame: num subframes > 31\n");
388 num_samples[
c] += subframe_len;
392 "channel len(%"PRIu16
") > samples_per_frame(%"PRIu16
")\n",
396 }
else if (num_samples[c] <= min_channel_len) {
397 if (num_samples[c] < min_channel_len) {
398 channels_for_cur_subframe = 0;
399 min_channel_len = num_samples[
c];
401 ++channels_for_cur_subframe;
404 }
while (min_channel_len < s->samples_per_frame);
433 int i, send_coef_bits;
435 if (1 << cbits < s->mclms_scaling + 1)
438 send_coef_bits = (cbits ?
get_bits(&s->
gb, cbits) : 0) + 2;
445 for (c = 0; c < i; c++)
462 "Order[%d][%d] %d > max (%d), not supported\n",
479 if (cdlms_send_coef) {
481 int cbits, shift_l, shift_r, j;
511 unsigned int ave_mean;
534 for (; i < tile_size; i++) {
535 int quo = 0, rem, rem_bits, residue;
548 rem_bits = av_ceil_log2(ave_mean);
550 residue = (quo << rem_bits) + rem;
556 residue = (residue >> 1) ^ -(residue & 1);
590 for (ilms = 0; ilms < s->
cdlms_ttl[ich]; ilms++) {
610 for (ilms = 0; ilms < s->
cdlms_ttl[ich]; ilms++)
622 int i, j, ich, pred_error;
627 for (ich = 0; ich < num_channels; ich++) {
629 if (pred_error > 0) {
630 for (i = 0; i < order * num_channels; i++)
633 for (j = 0; j < ich; j++)
635 }
else if (pred_error < 0) {
636 for (i = 0; i < order * num_channels; i++)
639 for (j = 0; j < ich; j++)
644 for (ich = num_channels - 1; ich >= 0; ich--) {
654 sizeof(int16_t) * order * num_channels);
657 sizeof(int16_t) * order * num_channels);
668 for (ich = 0; ich < num_channels; ich++) {
672 for (i = 0; i < order * num_channels; i++)
675 for (i = 0; i < ich; i++)
687 for (icoef = 0; icoef < tile_size; icoef++) {
721 int ilms, recent, icoef;
722 for (ilms = s->
cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
727 for (icoef = 0; icoef < s->
cdlms[ich][ilms].
order; icoef++)
730 for (icoef = 0; icoef < s->
cdlms[ich][ilms].
order; icoef++)
739 int ilms, recent, icoef;
740 for (ilms = s->
cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
745 for (icoef = 0; icoef < s->
cdlms[ich][ilms].
order; icoef++)
755 int coef_begin,
int coef_end)
757 int icoef,
pred, ilms, num_lms, residue, input;
760 for (ilms = num_lms - 1; ilms >= 0; ilms--) {
761 for (icoef = coef_begin; icoef < coef_end; icoef++) {
786 for (icoef = 0; icoef < tile_size; icoef++) {
802 for (i = 0; i < order; i++) {
804 for (j = 0; j < order; j++) {
806 pred += filter_coeffs[j] * prevvalues[j - i];
813 for (i = order; i < tile_size; i++) {
815 for (j = 0; j < order; j++)
820 for (j = 0; j < order; j++)
830 int i, j, rawpcm_tile, padding_zeroes, res;
896 "Waiting for seekable tile\n");
916 "inverse LPC filter");
932 "Invalid number of padding bits in raw PCM tile\n");
936 "total %d bits, remain=%d\n", bits,
939 for (j = 0; j < subframe_len; j++)
964 for (j = 0; j < subframe_len; j++)
972 for (j = 0; j < subframe_len; j++) {
1002 int more_frames = 0,
len = 0, i,
ret;
1075 "frame[%"PRIu32
"] would have to skip %i bits\n",
1140 align =
FFMIN(align, len);
1160 int buf_size = avpkt->
size;
1161 int num_bits_prev_frame, packet_sequence_number, spliced_packet;
1171 if (buf_size < avctx->block_align) {
1182 packet_sequence_number =
get_bits(gb, 4);
1196 "Packet loss detected! seq %"PRIx8
" vs %x\n",
1201 if (num_bits_prev_frame > 0) {
1203 if (num_bits_prev_frame >= remaining_packet_bits) {
1204 num_bits_prev_frame = remaining_packet_bits;
1210 save_bits(s, gb, num_bits_prev_frame, 1);
1213 if (num_bits_prev_frame < remaining_packet_bits && !s->packet_loss)
1216 ff_dlog(avctx,
"ignoring %x previously saved bits\n",
1292 .
name =
"wmalossless",
static void decode_ac_filter(WmallDecodeCtx *s)
int16_t prev_block_len
length of the previous block
uint8_t subframe_len_bits
number of bits used for the subframe length
uint8_t bits_per_sample
integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1.0])
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
This structure describes decoded (raw) audio or video data.
uint8_t max_subframe_len_bit
flag indicating that the subframe is of maximum size when the first subframe length bit is 1 ...
uint8_t max_num_subframes
ptrdiff_t const GLvoid * data
uint16_t subframe_offsets[MAX_SUBFRAMES]
subframe positions in the current frame
int16_t mclms_updates[WMALL_MAX_CHANNELS *2 *32]
int32_t * samples_32[WMALL_MAX_CHANNELS]
current samplebuffer pointer (24-bit)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static void skip_bits_long(GetBitContext *s, int n)
static av_cold int init(AVCodecContext *avctx)
uint8_t drc_gain
gain for the DRC tool
static void lms_update(WmallDecodeCtx *s, int ich, int ilms, int input)
int acfilter_prevvalues[WMALL_MAX_CHANNELS][16]
void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
Copy the content of src to the bitstream.
#define DECLARE_ALIGNED(n, t, v)
PutBitContext pb
context for filling the frame_data buffer
uint8_t cur_subframe
current subframe number
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
LLAudDSPContext dsp
accelerated DSP functions
static void decode_mclms(WmallDecodeCtx *s)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int cdlms_ttl[WMALL_MAX_CHANNELS]
static int decode_subframe_length(WmallDecodeCtx *s, int offset)
Decode the subframe length.
int channel_coeffs[WMALL_MAX_CHANNELS][WMALL_BLOCK_MAX_SIZE]
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
static int get_sbits(GetBitContext *s, int n)
int8_t channels_for_cur_subframe
number of channels that contain the subframe
Macro definitions for various function/variable attributes.
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
uint8_t packet_sequence_number
current packet number
int16_t subframe_len
current subframe length
uint16_t decoded_samples
number of already processed samples
GetBitContext pgb
bitstream reader context for the packet
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
int quant_step
quantization step for the current subframe
int16_t coefs[MAX_ORDER+WMALL_COEFF_PAD_SIZE/sizeof(int16_t)]
enum AVSampleFormat sample_fmt
audio sample format
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int16_t acfilter_coeffs[16]
int8_t num_channels
number of channels in the stream (same as AVCodecContext.num_channels)
static void reset_codec(WmallDecodeCtx *s)
Reset filter parameters and transient area at new seekable tile.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int update_speed[WMALL_MAX_CHANNELS]
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
int is_channel_coded[WMALL_MAX_CHANNELS]
int frame_offset
frame offset in the bit reservoir
static uint8_t * append(uint8_t *buf, const uint8_t *src, int size)
#define WMASIGN(x)
Get sign of integer (1 for positive, -1 for negative and 0 for zero)
uint16_t min_samples_per_subframe
struct WmallDecodeCtx::@109 cdlms[WMALL_MAX_CHANNELS][9]
static int get_bits_count(const GetBitContext *s)
bitstream reader API header.
frame-specific decoder context for a single channel
int8_t lfe_channel
lfe channel index
int buf_bit_size
buffer size in bits
static int get_bits_left(GetBitContext *gb)
int16_t mclms_coeffs[WMALL_MAX_CHANNELS *WMALL_MAX_CHANNELS *32]
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static const uint16_t mask[17]
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static av_cold int decode_init(AVCodecContext *avctx)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
simple assert() macros that are a bit more flexible than ISO C assert().
int8_t channel_indexes_for_cur_subframe[WMALL_MAX_CHANNELS]
const char * name
Name of the codec implementation.
uint8_t frame_data[MAX_FRAMESIZE+FF_INPUT_BUFFER_PADDING_SIZE]
compressed frame data
static int decode_subframe(WmallDecodeCtx *s)
static int decode_cdlms(WmallDecodeCtx *s)
static void revert_acfilter(WmallDecodeCtx *s, int tile_size)
#define WMALL_BLOCK_MAX_SIZE
maximum block size
static const uint8_t offset[127][2]
Libavcodec external API header.
int channel_residues[WMALL_MAX_CHANNELS][WMALL_BLOCK_MAX_SIZE]
int8_t parsed_all_subframes
all subframes decoded?
uint64_t channel_layout
Audio channel layout.
static int decode_tilehdr(WmallDecodeCtx *s)
Decode how the data in the frame is split into subframes.
#define FF_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
static void use_high_update_speed(WmallDecodeCtx *s, int ich)
#define MAX_SUBFRAMES
max number of subframes per channel
static av_cold int decode_close(AVCodecContext *avctx)
uint8_t packet_loss
set in case of bitstream error
static void mclms_predict(WmallDecodeCtx *s, int icoef, int *pred)
static void clear_codec_buffers(WmallDecodeCtx *s)
uint32_t decode_flags
used compression features
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
static void revert_inter_ch_decorr(WmallDecodeCtx *s, int tile_size)
int8_t skip_frame
skip output step
uint8_t packet_offset
offset to the frame in the packet
av_cold void ff_llauddsp_init(LLAudDSPContext *c)
static int decode_channel_residues(WmallDecodeCtx *s, int ch, int tile_size)
uint8_t packet_done
set when a packet is fully decoded
static void revert_cdlms(WmallDecodeCtx *s, int ch, int coef_begin, int coef_end)
static void use_normal_update_speed(WmallDecodeCtx *s, int ich)
int16_t mclms_coeffs_cur[WMALL_MAX_CHANNELS *WMALL_MAX_CHANNELS]
uint16_t samples_per_frame
number of samples to output
static const float pred[4]
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
const AVS_VideoInfo int align
int next_packet_start
start offset of the next WMA packet in the demuxer packet
AVSampleFormat
Audio sample formats.
int sample_rate
samples per second
#define WMALL_MAX_CHANNELS
current decoder limitations
main external API structure.
int16_t * samples_16[WMALL_MAX_CHANNELS]
current samplebuffer pointer (16-bit)
static void decode_lpc(WmallDecodeCtx *s)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
int32_t(* scalarproduct_and_madd_int16)(int16_t *v1, const int16_t *v2, const int16_t *v3, int len, int mul)
Calculate scalar product of v1 and v2, and v1[i] += v3[i] * mul.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
int16_t mclms_prevvalues[WMALL_MAX_CHANNELS *2 *32]
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int remaining_bits(WmallDecodeCtx *s, GetBitContext *gb)
Calculate remaining input buffer length.
GetBitContext gb
bitstream reader context
uint32_t frame_num
current frame number (not used for decoding)
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
av_cold int ff_wma_get_frame_len_bits(int sample_rate, int version, unsigned int decode_flags)
Get the samples per frame for this stream.
uint8_t do_inter_ch_decorr
#define CODEC_CAP_SUBFRAMES
Codec can output multiple frames per AVPacket Normally demuxers return one frame at a time...
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
uint16_t subframe_len[MAX_SUBFRAMES]
subframe length in samples
int ave_sum[WMALL_MAX_CHANNELS]
WmallChannelCtx channel[WMALL_MAX_CHANNELS]
per channel data
#define MAX_FRAMESIZE
maximum compressed frame size
common internal api header.
#define WMALL_COEFF_PAD_SIZE
pad coef buffers with 0 for use with SIMD
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
int dynamic_range_compression
frame contains DRC data
int transient_counter
number of transient samples from the beginning of the transient zone
int16_t lms_prevvalues[MAX_ORDER *2+WMALL_COEFF_PAD_SIZE/sizeof(int16_t)]
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static void save_bits(WmallDecodeCtx *s, GetBitContext *gb, int len, int append)
Fill the bit reservoir with a (partial) frame.
int transient_pos[WMALL_MAX_CHANNELS]
int channels
number of audio channels
int16_t lms_updates[MAX_ORDER *2+WMALL_COEFF_PAD_SIZE/sizeof(int16_t)]
AVCodec ff_wmalossless_decoder
static enum AVSampleFormat sample_fmts[]
static void flush(AVCodecContext *avctx)
int len_prefix
frame is prefixed with its length
static int decode_frame(WmallDecodeCtx *s)
Decode one WMA frame.
int transient[WMALL_MAX_CHANNELS]
uint8_t ** extended_data
pointers to the data planes/channels.
int num_saved_bits
saved number of bits
int subframe_offset
subframe offset in the bit reservoir
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
int lpc_coefs[WMALL_MAX_CHANNELS][40]
static void revert_mclms(WmallDecodeCtx *s, int tile_size)