25 #include "libavutil/attributes.h"
26 #include "libavutil/avassert.h"
36 #define WMALL_MAX_CHANNELS 8
37 #define MAX_SUBFRAMES 32
39 #define MAX_FRAMESIZE 32768
42 #define WMALL_BLOCK_MIN_BITS 6
43 #define WMALL_BLOCK_MAX_BITS 14
44 #define WMALL_BLOCK_MAX_SIZE (1 << WMALL_BLOCK_MAX_BITS)
45 #define WMALL_BLOCK_SIZES (WMALL_BLOCK_MAX_BITS - WMALL_BLOCK_MIN_BITS + 1)
178 unsigned int channel_mask;
179 int i, log2_max_num_subframes;
191 channel_mask =
AV_RL32(edata_ptr + 2);
228 for (i = 0; i < avctx->
channels; i++)
252 if (channel_mask & 8) {
254 for (mask = 1; mask < 16; mask <<= 1)
255 if (channel_mask & mask)
285 int frame_len_ratio, subframe_len,
len;
296 if (subframe_len < s->min_samples_per_subframe ||
330 int fixed_channel_layout = 0;
331 int min_channel_len = 0;
340 fixed_channel_layout = 1;
344 int subframe_len, in_use = 0;
348 if (num_samples[c] == min_channel_len) {
349 if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
351 contains_subframe[
c] = in_use = 1;
354 contains_subframe[
c] = in_use = 1;
357 contains_subframe[
c] = 0;
362 "Found empty subframe\n");
370 min_channel_len += subframe_len;
374 if (contains_subframe[c]) {
377 "broken frame: num subframes > 31\n");
381 num_samples[
c] += subframe_len;
385 "channel len(%d) > samples_per_frame(%d)\n",
389 }
else if (num_samples[c] <= min_channel_len) {
390 if (num_samples[c] < min_channel_len) {
391 channels_for_cur_subframe = 0;
392 min_channel_len = num_samples[
c];
394 ++channels_for_cur_subframe;
397 }
while (min_channel_len < s->samples_per_frame);
426 int i, send_coef_bits;
428 if (1 << cbits < s->mclms_scaling + 1)
431 send_coef_bits = (cbits ?
get_bits(&s->
gb, cbits) : 0) + 2;
438 for (c = 0; c < i; c++)
455 "Order[%d][%d] %d > max (%d), not supported\n",
465 if (cdlms_send_coef) {
467 int cbits, shift_l, shift_r, j;
493 unsigned int ave_mean;
516 for (; i < tile_size; i++) {
517 int quo = 0, rem, rem_bits, residue;
530 rem_bits = av_ceil_log2(ave_mean);
532 residue = (quo << rem_bits) + rem;
539 residue = -(residue >> 1) - 1;
541 residue = residue >> 1;
575 for (ilms = 0; ilms < s->
cdlms_ttl[ich]; ilms++) {
595 for (ilms = 0; ilms < s->
cdlms_ttl[ich]; ilms++)
607 int i, j, ich, pred_error;
612 for (ich = 0; ich < num_channels; ich++) {
614 if (pred_error > 0) {
615 for (i = 0; i < order * num_channels; i++)
618 for (j = 0; j < ich; j++) {
624 }
else if (pred_error < 0) {
625 for (i = 0; i < order * num_channels; i++)
628 for (j = 0; j < ich; j++) {
637 for (ich = num_channels - 1; ich >= 0; ich--) {
655 2 * order * num_channels);
658 2 * order * num_channels);
669 for (ich = 0; ich < num_channels; ich++) {
673 for (i = 0; i < order * num_channels; i++)
676 for (i = 0; i < ich; i++)
688 for (icoef = 0; icoef < tile_size; icoef++) {
699 for (icoef = 0; icoef < s->
cdlms[ich][ilms].
order; icoef++)
707 int input,
int residue)
714 for (icoef = 0; icoef < s->
cdlms[ich][ilms].
order; icoef++)
717 }
else if (residue > 0) {
718 for (icoef = 0; icoef < s->
cdlms[ich][ilms].
order; icoef++)
750 int ilms, recent, icoef;
751 for (ilms = s->
cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
756 for (icoef = 0; icoef < s->
cdlms[ich][ilms].
order; icoef++)
759 for (icoef = 0; icoef < s->
cdlms[ich][ilms].
order; icoef++)
768 int ilms, recent, icoef;
769 for (ilms = s->
cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
774 for (icoef = 0; icoef < s->
cdlms[ich][ilms].
order; icoef++)
784 int coef_begin,
int coef_end)
786 int icoef,
pred, ilms, num_lms, residue, input;
789 for (ilms = num_lms - 1; ilms >= 0; ilms--) {
790 for (icoef = coef_begin; icoef < coef_end; icoef++) {
807 for (icoef = 0; icoef < tile_size; icoef++) {
823 for (i = 0; i < order; i++) {
825 for (j = 0; j < order; j++) {
827 pred += filter_coeffs[j] * prevvalues[j - i];
834 for (i = order; i < tile_size; i++) {
836 for (j = 0; j < order; j++)
841 for (j = 0; j < order; j++)
851 int i, j, rawpcm_tile, padding_zeroes,
res;
917 "Waiting for seekable tile\n");
937 "inverse LPC filter");
953 "Invalid number of padding bits in raw PCM tile\n");
957 "total %d bits, remain=%d\n", bits,
960 for (j = 0; j < subframe_len; j++)
985 for (j = 0; j < subframe_len; j++)
993 for (j = 0; j < subframe_len; j++) {
1023 int more_frames = 0,
len = 0, i,
ret;
1093 "frame[%i] would have to skip %i bits\n", s->
frame_num,
1157 align =
FFMIN(align, len);
1177 int buf_size = avpkt->
size;
1178 int num_bits_prev_frame, packet_sequence_number, spliced_packet;
1188 if (buf_size < avctx->block_align) {
1199 packet_sequence_number =
get_bits(gb, 4);
1217 if (num_bits_prev_frame > 0) {
1219 if (num_bits_prev_frame >= remaining_packet_bits) {
1220 num_bits_prev_frame = remaining_packet_bits;
1226 save_bits(s, gb, num_bits_prev_frame, 1);
1229 if (num_bits_prev_frame < remaining_packet_bits && !s->packet_loss)
1232 av_dlog(avctx,
"ignoring %x previously saved bits\n",
1308 .
name =
"wmalossless",
static void decode_ac_filter(WmallDecodeCtx *s)
int16_t prev_block_len
length of the previous block
int16_t lms_prevvalues[MAX_ORDER *2]
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_PATCHWELCOME
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
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
int acfilter_prevvalues[WMALL_MAX_CHANNELS][16]
uint8_t ** extended_data
pointers to the data planes/channels.
void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
Copy the content of src to the bitstream.
PutBitContext pb
context for filling the frame_data buffer
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
uint8_t cur_subframe
current subframe number
static void decode_mclms(WmallDecodeCtx *s)
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
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]
static int lms_predict(WmallDecodeCtx *s, int ich, int ilms)
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)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int8_t channels_for_cur_subframe
number of channels that contain the subframe
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
if((e=av_dict_get(options,"", NULL, AV_DICT_IGNORE_SUFFIX)))
int16_t subframe_len
current subframe length
uint16_t decoded_samples
number of already processed samples
GetBitContext pgb
bitstream reader context for the packet
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
enum AVSampleFormat sample_fmt
audio sample format
int8_t num_channels
number of channels in the stream (same as AVCodecContext.num_channels)
static const uint8_t offset[511][2]
static void reset_codec(WmallDecodeCtx *s)
Reset filter parameters and transient area at new seekable tile.
const char * name
Name of the codec implementation.
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)
uint16_t min_samples_per_subframe
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
static const uint8_t frame_size[4]
int buf_bit_size
buffer size in bits
static int get_bits_left(GetBitContext *gb)
#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...
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. ...
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
int8_t channel_indexes_for_cur_subframe[WMALL_MAX_CHANNELS]
uint8_t frame_data[MAX_FRAMESIZE+FF_INPUT_BUFFER_PADDING_SIZE]
compressed frame data
static int decode_subframe(WmallDecodeCtx *s)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static int decode_cdlms(WmallDecodeCtx *s)
static void revert_acfilter(WmallDecodeCtx *s, int tile_size)
#define WMALL_BLOCK_MAX_SIZE
maximum block size
Libavcodec external API header.
#define av_unused
Disable warnings about deprecated features This is useful for sections of code kept for backward comp...
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)
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
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
static int decode_channel_residues(WmallDecodeCtx *s, int ch, int tile_size)
int16_t mclms_coeffs_cur[4]
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)
uint16_t samples_per_frame
number of samples to output
static const float pred[4]
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.
static void close(AVCodecParserContext *s)
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everythnig contained in src to dst and reset src.
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)
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]
int64_t acfilter_coeffs[16]
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 avpriv_report_missing_feature(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
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...
uint16_t subframe_len[MAX_SUBFRAMES]
subframe length in samples
int ave_sum[WMALL_MAX_CHANNELS]
WmallChannelCtx channel[WMALL_MAX_CHANNELS]
per channel data
struct WmallDecodeCtx::@106 cdlms[WMALL_MAX_CHANNELS][9]
#define MAX_FRAMESIZE
maximum compressed frame size
common internal api header.
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
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]
#define AVERROR_INVALIDDATA
int16_t mclms_coeffs[128]
int channels
number of audio channels
AVCodec ff_wmalossless_decoder
static enum AVSampleFormat sample_fmts[]
int16_t lms_updates[MAX_ORDER *2]
static void flush(AVCodecContext *avctx)
int len_prefix
frame is prefixed with its length
static int decode_frame(WmallDecodeCtx *s)
Decode one WMA frame.
static int decode(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int transient[WMALL_MAX_CHANNELS]
int num_saved_bits
saved number of bits
int subframe_offset
subframe offset in the bit reservoir
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 lms_update(WmallDecodeCtx *s, int ich, int ilms, int input, int residue)
static void revert_mclms(WmallDecodeCtx *s, int tile_size)