38 #define WMALL_MAX_CHANNELS 8 39 #define MAX_SUBFRAMES 32 41 #define MAX_FRAMESIZE 32768 44 #define WMALL_BLOCK_MIN_BITS 6 45 #define WMALL_BLOCK_MAX_BITS 14 46 #define WMALL_BLOCK_MAX_SIZE (1 << WMALL_BLOCK_MAX_BITS) 47 #define WMALL_BLOCK_SIZES (WMALL_BLOCK_MAX_BITS - WMALL_BLOCK_MIN_BITS + 1) 180 unsigned int channel_mask;
181 int i, log2_max_num_subframes;
188 channel_mask =
AV_RL32(edata_ptr + 2);
225 for (i = 0; i < avctx->
channels; i++)
249 if (channel_mask & 8) {
251 for (mask = 1; mask < 16; mask <<= 1)
252 if (channel_mask & mask)
327 int fixed_channel_layout = 0;
328 int min_channel_len = 0;
337 fixed_channel_layout = 1;
345 if (num_samples[c] == min_channel_len) {
346 if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
348 contains_subframe[c] = in_use = 1;
351 contains_subframe[c] = in_use = 1;
354 contains_subframe[c] = 0;
359 "Found empty subframe\n");
371 if (contains_subframe[c]) {
374 "broken frame: num subframes > 31\n");
382 "channel len(%"PRIu16
") > samples_per_frame(%"PRIu16
")\n",
386 }
else if (num_samples[c] <= min_channel_len) {
387 if (num_samples[c] < min_channel_len) {
388 channels_for_cur_subframe = 0;
389 min_channel_len = num_samples[c];
423 int i, send_coef_bits;
428 send_coef_bits = (cbits ?
get_bits(&s->
gb, cbits) : 0) + 2;
435 for (c = 0; c < i; c++)
452 "Order[%d][%d] %d > max (%d), not supported\n",
462 if (cdlms_send_coef) {
464 int cbits, shift_l, shift_r, j;
490 unsigned int ave_mean;
513 for (; i < tile_size; i++) {
514 int quo = 0, rem, rem_bits, residue;
527 rem_bits = av_ceil_log2(ave_mean);
529 residue = (quo << rem_bits) + rem;
536 residue = -(residue >> 1) - 1;
538 residue = residue >> 1;
572 for (ilms = 0; ilms < s->
cdlms_ttl[ich]; ilms++) {
592 for (ilms = 0; ilms < s->
cdlms_ttl[ich]; ilms++)
604 int i, j, ich, pred_error;
611 if (pred_error > 0) {
615 for (j = 0; j < ich; j++) {
621 }
else if (pred_error < 0) {
625 for (j = 0; j < ich; j++) {
634 for (ich = num_channels - 1; ich >= 0; ich--) {
652 2 * order * num_channels);
655 2 * order * num_channels);
673 for (i = 0; i < ich; i++)
685 for (icoef = 0; icoef < tile_size; icoef++) {
696 for (icoef = 0; icoef < s->
cdlms[ich][ilms].
order; icoef++)
704 int input,
int residue)
711 for (icoef = 0; icoef < s->
cdlms[ich][ilms].
order; icoef++)
714 }
else if (residue > 0) {
715 for (icoef = 0; icoef < s->
cdlms[ich][ilms].
order; icoef++)
748 for (ilms = s->
cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
753 for (icoef = 0; icoef < s->
cdlms[ich][ilms].
order; icoef++)
756 for (icoef = 0; icoef < s->
cdlms[ich][ilms].
order; icoef++)
766 for (ilms = s->
cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
771 for (icoef = 0; icoef < s->
cdlms[ich][ilms].
order; icoef++)
781 int coef_begin,
int coef_end)
783 int icoef,
pred, ilms, num_lms, residue, input;
786 for (ilms = num_lms - 1; ilms >= 0; ilms--) {
787 for (icoef = coef_begin; icoef < coef_end; icoef++) {
804 for (icoef = 0; icoef < tile_size; icoef++) {
820 for (i = 0; i <
order; i++) {
822 for (j = 0; j <
order; j++) {
824 pred += filter_coeffs[j] * prevvalues[j - i];
831 for (i = order; i < tile_size; i++) {
833 for (j = 0; j <
order; j++)
838 for (j = 0; j <
order; j++)
848 int i, j, rawpcm_tile, padding_zeroes, res;
914 "Waiting for seekable tile\n");
934 "inverse LPC filter");
950 "Invalid number of padding bits in raw PCM tile\n");
954 "total %d bits, remain=%d\n", bits,
1020 int more_frames = 0,
len = 0, i, ret;
1026 "not enough space for the output samples\n");
1092 "frame[%"PRIu32
"] would have to skip %i bits\n",
1157 align =
FFMIN(align, len);
1177 int buf_size = avpkt->
size;
1186 if (buf_size < avctx->block_align)
1195 packet_sequence_number =
get_bits(gb, 4);
1209 "Packet loss detected! seq %"PRIx8
" vs %x\n",
1214 if (num_bits_prev_frame > 0) {
1216 if (num_bits_prev_frame >= remaining_packet_bits) {
1217 num_bits_prev_frame = remaining_packet_bits;
1223 save_bits(s, gb, num_bits_prev_frame, 1);
1226 if (num_bits_prev_frame < remaining_packet_bits && !s->
packet_loss)
1229 av_dlog(avctx,
"ignoring %x previously saved bits\n",
1305 .
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_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
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 unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
int channel_coeffs[2][WMALL_BLOCK_MAX_SIZE]
static void skip_bits_long(GetBitContext *s, int n)
uint8_t drc_gain
gain for the DRC tool
struct WmallDecodeCtx::@82 cdlms[2][9]
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
uint8_t cur_subframe
current subframe number
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everythnig contained in src to dst and reset src.
static void decode_mclms(WmallDecodeCtx *s)
static int decode_subframe_length(WmallDecodeCtx *s, int offset)
Decode the subframe length.
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)
int8_t channels_for_cur_subframe
number of channels that contain the subframe
Macro definitions for various function/variable attributes.
uint8_t packet_sequence_number
current packet number
int16_t subframe_len
current subframe length
uint16_t decoded_samples
number of already processed samples
av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (%s)\, 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)
GetBitContext pgb
bitstream reader context for the packet
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
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
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
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.
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
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)
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]
void av_log(void *avcl, int level, const char *fmt,...)
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 put_bits(PutBitContext *s, int n, unsigned int value)
Write up to 31 bits into a bitstream.
static void revert_acfilter(WmallDecodeCtx *s, int tile_size)
#define WMALL_BLOCK_MAX_SIZE
maximum block 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
static int decode_channel_residues(WmallDecodeCtx *s, int ch, int tile_size)
int acfilter_prevvalues[2][16]
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
if(ac->has_optimized_func)
static const float pred[4]
#define AVERROR_PATCHWELCOME
Not yet implemented in Libav, patches welcome.
int next_packet_start
start offset of the next WMA packet in the demuxer packet
Libavcodec external API header.
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)
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 av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
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
WmallChannelCtx channel[WMALL_MAX_CHANNELS]
per channel data
#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.
static av_cold int init(AVCodecParserContext *s)
int channels
number of audio channels
AVCodec ff_wmalossless_decoder
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.
int channel_residues[2][WMALL_BLOCK_MAX_SIZE]
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
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
static void lms_update(WmallDecodeCtx *s, int ich, int ilms, int input, int residue)
static void revert_mclms(WmallDecodeCtx *s, int tile_size)