2 * Windows Media Audio Lossless decoder
3 * Copyright (c) 2007 Baptiste Coudurier, Benjamin Larsson, Ulion
4 * Copyright (c) 2008 - 2011 Sascha Sommer, Benjamin Larsson
5 * Copyright (c) 2011 Andreas Ă–man
6 * Copyright (c) 2011 - 2012 Mashiat Sarker Shakkhar
8 * This file is part of FFmpeg.
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 #include "libavutil/attributes.h"
28 #include "libavutil/avassert.h"
34 #include "lossless_audiodsp.h"
36 #include "wma_common.h"
38 /** current decoder limitations */
39 #define WMALL_MAX_CHANNELS 8 ///< max number of handled channels
40 #define MAX_SUBFRAMES 32 ///< max number of subframes per channel
41 #define MAX_BANDS 29 ///< max number of scale factor bands
42 #define MAX_FRAMESIZE 32768 ///< maximum compressed frame size
45 #define WMALL_BLOCK_MIN_BITS 6 ///< log2 of min block size
46 #define WMALL_BLOCK_MAX_BITS 14 ///< log2 of max block size
47 #define WMALL_BLOCK_MAX_SIZE (1 << WMALL_BLOCK_MAX_BITS) ///< maximum block size
48 #define WMALL_BLOCK_SIZES (WMALL_BLOCK_MAX_BITS - WMALL_BLOCK_MIN_BITS + 1) ///< possible block sizes
50 #define WMALL_COEFF_PAD_SIZE 16 ///< pad coef buffers with 0 for use with SIMD
53 * @brief frame-specific decoder context for a single channel
55 typedef struct WmallChannelCtx {
56 int16_t prev_block_len; ///< length of the previous block
57 uint8_t transmit_coefs;
58 uint8_t num_subframes;
59 uint16_t subframe_len[MAX_SUBFRAMES]; ///< subframe length in samples
60 uint16_t subframe_offsets[MAX_SUBFRAMES]; ///< subframe positions in the current frame
61 uint8_t cur_subframe; ///< current subframe number
62 uint16_t decoded_samples; ///< number of already processed samples
63 int quant_step; ///< quantization step for the current subframe
64 int transient_counter; ///< number of transient samples from the beginning of the transient zone
68 * @brief main decoder context
70 typedef struct WmallDecodeCtx {
71 /* generic decoder variables */
72 AVCodecContext *avctx;
74 LLAudDSPContext dsp; ///< accelerated DSP functions
75 uint8_t *frame_data; ///< compressed frame data
76 int max_frame_size; ///< max bitstream size
77 PutBitContext pb; ///< context for filling the frame_data buffer
79 /* frame size dependent frame information (set during initialization) */
80 uint32_t decode_flags; ///< used compression features
81 int len_prefix; ///< frame is prefixed with its length
82 int dynamic_range_compression; ///< frame contains DRC data
83 uint8_t bits_per_sample; ///< integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1.0])
84 uint16_t samples_per_frame; ///< number of samples to output
85 uint16_t log2_frame_size;
86 int8_t num_channels; ///< number of channels in the stream (same as AVCodecContext.num_channels)
87 int8_t lfe_channel; ///< lfe channel index
88 uint8_t max_num_subframes;
89 uint8_t subframe_len_bits; ///< number of bits used for the subframe length
90 uint8_t max_subframe_len_bit; ///< flag indicating that the subframe is of maximum size when the first subframe length bit is 1
91 uint16_t min_samples_per_subframe;
93 /* packet decode state */
94 GetBitContext pgb; ///< bitstream reader context for the packet
95 int next_packet_start; ///< start offset of the next WMA packet in the demuxer packet
96 uint8_t packet_offset; ///< offset to the frame in the packet
97 uint8_t packet_sequence_number; ///< current packet number
98 int num_saved_bits; ///< saved number of bits
99 int frame_offset; ///< frame offset in the bit reservoir
100 int subframe_offset; ///< subframe offset in the bit reservoir
101 uint8_t packet_loss; ///< set in case of bitstream error
102 uint8_t packet_done; ///< set when a packet is fully decoded
104 /* frame decode state */
105 uint32_t frame_num; ///< current frame number (not used for decoding)
106 GetBitContext gb; ///< bitstream reader context
107 int buf_bit_size; ///< buffer size in bits
108 int16_t *samples_16[WMALL_MAX_CHANNELS]; ///< current sample buffer pointer (16-bit)
109 int32_t *samples_32[WMALL_MAX_CHANNELS]; ///< current sample buffer pointer (24-bit)
110 uint8_t drc_gain; ///< gain for the DRC tool
111 int8_t skip_frame; ///< skip output step
112 int8_t parsed_all_subframes; ///< all subframes decoded?
114 /* subframe/block decode state */
115 int16_t subframe_len; ///< current subframe length
116 int8_t channels_for_cur_subframe; ///< number of channels that contain the subframe
117 int8_t channel_indexes_for_cur_subframe[WMALL_MAX_CHANNELS];
119 WmallChannelCtx channel[WMALL_MAX_CHANNELS]; ///< per channel data
121 // WMA Lossless-specific
123 uint8_t do_arith_coding;
124 uint8_t do_ac_filter;
125 uint8_t do_inter_ch_decorr;
129 int8_t acfilter_order;
130 int8_t acfilter_scaling;
131 int16_t acfilter_coeffs[16];
132 int acfilter_prevvalues[WMALL_MAX_CHANNELS][16];
135 int8_t mclms_scaling;
136 int16_t mclms_coeffs[WMALL_MAX_CHANNELS * WMALL_MAX_CHANNELS * 32];
137 int16_t mclms_coeffs_cur[WMALL_MAX_CHANNELS * WMALL_MAX_CHANNELS];
138 int32_t mclms_prevvalues[WMALL_MAX_CHANNELS * 2 * 32];
139 int32_t mclms_updates[WMALL_MAX_CHANNELS * 2 * 32];
150 DECLARE_ALIGNED(16, int16_t, coefs)[MAX_ORDER + WMALL_COEFF_PAD_SIZE/sizeof(int16_t)];
151 DECLARE_ALIGNED(16, int32_t, lms_prevvalues)[MAX_ORDER * 2 + WMALL_COEFF_PAD_SIZE/sizeof(int16_t)];
152 DECLARE_ALIGNED(16, int16_t, lms_updates)[MAX_ORDER * 2 + WMALL_COEFF_PAD_SIZE/sizeof(int16_t)];
154 } cdlms[WMALL_MAX_CHANNELS][9];
156 int cdlms_ttl[WMALL_MAX_CHANNELS];
160 int is_channel_coded[WMALL_MAX_CHANNELS];
161 int update_speed[WMALL_MAX_CHANNELS];
163 int transient[WMALL_MAX_CHANNELS];
164 int transient_pos[WMALL_MAX_CHANNELS];
167 int ave_sum[WMALL_MAX_CHANNELS];
169 int channel_residues[WMALL_MAX_CHANNELS][WMALL_BLOCK_MAX_SIZE];
171 int lpc_coefs[WMALL_MAX_CHANNELS][40];
177 /** Get sign of integer (1 for positive, -1 for negative and 0 for zero) */
178 #define WMASIGN(x) (((x) > 0) - ((x) < 0))
180 static av_cold int decode_init(AVCodecContext *avctx)
182 WmallDecodeCtx *s = avctx->priv_data;
183 uint8_t *edata_ptr = avctx->extradata;
184 unsigned int channel_mask;
185 int i, log2_max_num_subframes;
187 if (avctx->block_align <= 0) {
188 av_log(avctx, AV_LOG_ERROR, "block_align is not set or invalid\n");
189 return AVERROR(EINVAL);
192 av_assert0(avctx->channels >= 0);
193 if (avctx->channels > WMALL_MAX_CHANNELS) {
194 avpriv_request_sample(avctx,
195 "More than " AV_STRINGIFY(WMALL_MAX_CHANNELS) " channels");
196 return AVERROR_PATCHWELCOME;
199 s->max_frame_size = MAX_FRAMESIZE * avctx->channels;
200 s->frame_data = av_mallocz(s->max_frame_size + AV_INPUT_BUFFER_PADDING_SIZE);
202 return AVERROR(ENOMEM);
205 ff_llauddsp_init(&s->dsp);
206 init_put_bits(&s->pb, s->frame_data, s->max_frame_size);
208 if (avctx->extradata_size >= 18) {
209 s->decode_flags = AV_RL16(edata_ptr + 14);
210 channel_mask = AV_RL32(edata_ptr + 2);
211 s->bits_per_sample = AV_RL16(edata_ptr);
212 if (s->bits_per_sample == 16)
213 avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
214 else if (s->bits_per_sample == 24) {
215 avctx->sample_fmt = AV_SAMPLE_FMT_S32P;
216 avctx->bits_per_raw_sample = 24;
218 av_log(avctx, AV_LOG_ERROR, "Unknown bit-depth: %"PRIu8"\n",
220 return AVERROR_INVALIDDATA;
222 /* dump the extradata */
223 for (i = 0; i < avctx->extradata_size; i++)
224 ff_dlog(avctx, "[%x] ", avctx->extradata[i]);
225 ff_dlog(avctx, "\n");
228 avpriv_request_sample(avctx, "Unsupported extradata size");
229 return AVERROR_PATCHWELCOME;
233 s->log2_frame_size = av_log2(avctx->block_align) + 4;
236 s->skip_frame = 1; /* skip first frame */
238 s->len_prefix = s->decode_flags & 0x40;
241 s->samples_per_frame = 1 << ff_wma_get_frame_len_bits(avctx->sample_rate,
243 av_assert0(s->samples_per_frame <= WMALL_BLOCK_MAX_SIZE);
245 /* init previous block len */
246 for (i = 0; i < avctx->channels; i++)
247 s->channel[i].prev_block_len = s->samples_per_frame;
250 log2_max_num_subframes = (s->decode_flags & 0x38) >> 3;
251 s->max_num_subframes = 1 << log2_max_num_subframes;
252 s->max_subframe_len_bit = 0;
253 s->subframe_len_bits = av_log2(log2_max_num_subframes) + 1;
255 s->min_samples_per_subframe = s->samples_per_frame / s->max_num_subframes;
256 s->dynamic_range_compression = s->decode_flags & 0x80;
257 s->bV3RTM = s->decode_flags & 0x100;
259 if (s->max_num_subframes > MAX_SUBFRAMES) {
260 av_log(avctx, AV_LOG_ERROR, "invalid number of subframes %"PRIu8"\n",
261 s->max_num_subframes);
262 return AVERROR_INVALIDDATA;
265 s->num_channels = avctx->channels;
267 /* extract lfe channel position */
270 if (channel_mask & 8) {
272 for (mask = 1; mask < 16; mask <<= 1)
273 if (channel_mask & mask)
277 s->frame = av_frame_alloc();
279 return AVERROR(ENOMEM);
281 avctx->channel_layout = channel_mask;
286 * @brief Decode the subframe length.
288 * @param offset sample offset in the frame
289 * @return decoded subframe length on success, < 0 in case of an error
291 static int decode_subframe_length(WmallDecodeCtx *s, int offset)
293 int frame_len_ratio, subframe_len, len;
295 /* no need to read from the bitstream when only one length is possible */
296 if (offset == s->samples_per_frame - s->min_samples_per_subframe)
297 return s->min_samples_per_subframe;
299 len = av_log2(s->max_num_subframes - 1) + 1;
300 frame_len_ratio = get_bits(&s->gb, len);
301 subframe_len = s->min_samples_per_subframe * (frame_len_ratio + 1);
303 /* sanity check the length */
304 if (subframe_len < s->min_samples_per_subframe ||
305 subframe_len > s->samples_per_frame) {
306 av_log(s->avctx, AV_LOG_ERROR, "broken frame: subframe_len %i\n",
308 return AVERROR_INVALIDDATA;
314 * @brief Decode how the data in the frame is split into subframes.
315 * Every WMA frame contains the encoded data for a fixed number of
316 * samples per channel. The data for every channel might be split
317 * into several subframes. This function will reconstruct the list of
318 * subframes for every channel.
320 * If the subframes are not evenly split, the algorithm estimates the
321 * channels with the lowest number of total samples.
322 * Afterwards, for each of these channels a bit is read from the
323 * bitstream that indicates if the channel contains a subframe with the
324 * next subframe size that is going to be read from the bitstream or not.
325 * If a channel contains such a subframe, the subframe size gets added to
326 * the channel's subframe list.
327 * The algorithm repeats these steps until the frame is properly divided
328 * between the individual channels.
331 * @return 0 on success, < 0 in case of an error
333 static int decode_tilehdr(WmallDecodeCtx *s)
335 uint16_t num_samples[WMALL_MAX_CHANNELS] = { 0 }; /* sum of samples for all currently known subframes of a channel */
336 uint8_t contains_subframe[WMALL_MAX_CHANNELS]; /* flag indicating if a channel contains the current subframe */
337 int channels_for_cur_subframe = s->num_channels; /* number of channels that contain the current subframe */
338 int fixed_channel_layout = 0; /* flag indicating that all channels use the same subfra2me offsets and sizes */
339 int min_channel_len = 0; /* smallest sum of samples (channels with this length will be processed first) */
342 /* reset tiling information */
343 for (c = 0; c < s->num_channels; c++)
344 s->channel[c].num_subframes = 0;
346 tile_aligned = get_bits1(&s->gb);
347 if (s->max_num_subframes == 1 || tile_aligned)
348 fixed_channel_layout = 1;
350 /* loop until the frame data is split between the subframes */
352 int subframe_len, in_use = 0;
354 /* check which channels contain the subframe */
355 for (c = 0; c < s->num_channels; c++) {
356 if (num_samples[c] == min_channel_len) {
357 if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
358 (min_channel_len == s->samples_per_frame - s->min_samples_per_subframe)) {
359 contains_subframe[c] = 1;
361 contains_subframe[c] = get_bits1(&s->gb);
363 in_use |= contains_subframe[c];
365 contains_subframe[c] = 0;
369 av_log(s->avctx, AV_LOG_ERROR,
370 "Found empty subframe\n");
371 return AVERROR_INVALIDDATA;
374 /* get subframe length, subframe_len == 0 is not allowed */
375 if ((subframe_len = decode_subframe_length(s, min_channel_len)) <= 0)
376 return AVERROR_INVALIDDATA;
377 /* add subframes to the individual channels and find new min_channel_len */
378 min_channel_len += subframe_len;
379 for (c = 0; c < s->num_channels; c++) {
380 WmallChannelCtx *chan = &s->channel[c];
382 if (contains_subframe[c]) {
383 if (chan->num_subframes >= MAX_SUBFRAMES) {
384 av_log(s->avctx, AV_LOG_ERROR,
385 "broken frame: num subframes > 31\n");
386 return AVERROR_INVALIDDATA;
388 chan->subframe_len[chan->num_subframes] = subframe_len;
389 num_samples[c] += subframe_len;
390 ++chan->num_subframes;
391 if (num_samples[c] > s->samples_per_frame) {
392 av_log(s->avctx, AV_LOG_ERROR, "broken frame: "
393 "channel len(%"PRIu16") > samples_per_frame(%"PRIu16")\n",
394 num_samples[c], s->samples_per_frame);
395 return AVERROR_INVALIDDATA;
397 } else if (num_samples[c] <= min_channel_len) {
398 if (num_samples[c] < min_channel_len) {
399 channels_for_cur_subframe = 0;
400 min_channel_len = num_samples[c];
402 ++channels_for_cur_subframe;
405 } while (min_channel_len < s->samples_per_frame);
407 for (c = 0; c < s->num_channels; c++) {
409 for (i = 0; i < s->channel[c].num_subframes; i++) {
410 s->channel[c].subframe_offsets[i] = offset;
411 offset += s->channel[c].subframe_len[i];
418 static void decode_ac_filter(WmallDecodeCtx *s)
421 s->acfilter_order = get_bits(&s->gb, 4) + 1;
422 s->acfilter_scaling = get_bits(&s->gb, 4);
424 for (i = 0; i < s->acfilter_order; i++)
425 s->acfilter_coeffs[i] = get_bitsz(&s->gb, s->acfilter_scaling) + 1;
428 static void decode_mclms(WmallDecodeCtx *s)
430 s->mclms_order = (get_bits(&s->gb, 4) + 1) * 2;
431 s->mclms_scaling = get_bits(&s->gb, 4);
432 if (get_bits1(&s->gb)) {
433 int i, send_coef_bits;
434 int cbits = av_log2(s->mclms_scaling + 1);
435 if (1 << cbits < s->mclms_scaling + 1)
438 send_coef_bits = get_bitsz(&s->gb, cbits) + 2;
440 for (i = 0; i < s->mclms_order * s->num_channels * s->num_channels; i++)
441 s->mclms_coeffs[i] = get_bits(&s->gb, send_coef_bits);
443 for (i = 0; i < s->num_channels; i++) {
445 for (c = 0; c < i; c++)
446 s->mclms_coeffs_cur[i * s->num_channels + c] = get_bits(&s->gb, send_coef_bits);
451 static int decode_cdlms(WmallDecodeCtx *s)
454 int cdlms_send_coef = get_bits1(&s->gb);
456 for (c = 0; c < s->num_channels; c++) {
457 s->cdlms_ttl[c] = get_bits(&s->gb, 3) + 1;
458 for (i = 0; i < s->cdlms_ttl[c]; i++) {
459 s->cdlms[c][i].order = (get_bits(&s->gb, 7) + 1) * 8;
460 if (s->cdlms[c][i].order > MAX_ORDER) {
461 av_log(s->avctx, AV_LOG_ERROR,
462 "Order[%d][%d] %d > max (%d), not supported\n",
463 c, i, s->cdlms[c][i].order, MAX_ORDER);
464 s->cdlms[0][0].order = 0;
465 return AVERROR_INVALIDDATA;
467 if(s->cdlms[c][i].order & 8 && s->bits_per_sample == 16) {
470 avpriv_request_sample(s->avctx, "CDLMS of order %d",
471 s->cdlms[c][i].order);
476 for (i = 0; i < s->cdlms_ttl[c]; i++)
477 s->cdlms[c][i].scaling = get_bits(&s->gb, 4);
479 if (cdlms_send_coef) {
480 for (i = 0; i < s->cdlms_ttl[c]; i++) {
481 int cbits, shift_l, shift_r, j;
482 cbits = av_log2(s->cdlms[c][i].order);
483 if ((1 << cbits) < s->cdlms[c][i].order)
485 s->cdlms[c][i].coefsend = get_bits(&s->gb, cbits) + 1;
487 cbits = av_log2(s->cdlms[c][i].scaling + 1);
488 if ((1 << cbits) < s->cdlms[c][i].scaling + 1)
491 s->cdlms[c][i].bitsend = get_bitsz(&s->gb, cbits) + 2;
492 shift_l = 32 - s->cdlms[c][i].bitsend;
493 shift_r = 32 - s->cdlms[c][i].scaling - 2;
494 for (j = 0; j < s->cdlms[c][i].coefsend; j++)
495 s->cdlms[c][i].coefs[j] =
496 (get_bits(&s->gb, s->cdlms[c][i].bitsend) << shift_l) >> shift_r;
500 for (i = 0; i < s->cdlms_ttl[c]; i++)
501 memset(s->cdlms[c][i].coefs + s->cdlms[c][i].order,
502 0, WMALL_COEFF_PAD_SIZE);
508 static int decode_channel_residues(WmallDecodeCtx *s, int ch, int tile_size)
511 unsigned int ave_mean;
512 s->transient[ch] = get_bits1(&s->gb);
513 if (s->transient[ch]) {
514 s->transient_pos[ch] = get_bits(&s->gb, av_log2(tile_size));
515 if (s->transient_pos[ch])
516 s->transient[ch] = 0;
517 s->channel[ch].transient_counter =
518 FFMAX(s->channel[ch].transient_counter, s->samples_per_frame / 2);
519 } else if (s->channel[ch].transient_counter)
520 s->transient[ch] = 1;
522 if (s->seekable_tile) {
523 ave_mean = get_bits(&s->gb, s->bits_per_sample);
524 s->ave_sum[ch] = ave_mean << (s->movave_scaling + 1);
527 if (s->seekable_tile) {
528 if (s->do_inter_ch_decorr)
529 s->channel_residues[ch][0] = get_sbits_long(&s->gb, s->bits_per_sample + 1);
531 s->channel_residues[ch][0] = get_sbits_long(&s->gb, s->bits_per_sample);
534 for (; i < tile_size; i++) {
536 unsigned quo = 0, residue;
537 while(get_bits1(&s->gb)) {
539 if (get_bits_left(&s->gb) <= 0)
543 quo += get_bits_long(&s->gb, get_bits(&s->gb, 5) + 1);
545 ave_mean = (s->ave_sum[ch] + (1 << s->movave_scaling)) >> (s->movave_scaling + 1);
549 rem_bits = av_ceil_log2(ave_mean);
550 rem = get_bits_long(&s->gb, rem_bits);
551 residue = (quo << rem_bits) + rem;
554 s->ave_sum[ch] = residue + s->ave_sum[ch] -
555 (s->ave_sum[ch] >> s->movave_scaling);
557 residue = (residue >> 1) ^ -(residue & 1);
558 s->channel_residues[ch][i] = residue;
565 static void decode_lpc(WmallDecodeCtx *s)
568 s->lpc_order = get_bits(&s->gb, 5) + 1;
569 s->lpc_scaling = get_bits(&s->gb, 4);
570 s->lpc_intbits = get_bits(&s->gb, 3) + 1;
571 cbits = s->lpc_scaling + s->lpc_intbits;
572 for (ch = 0; ch < s->num_channels; ch++)
573 for (i = 0; i < s->lpc_order; i++)
574 s->lpc_coefs[ch][i] = get_sbits(&s->gb, cbits);
577 static void clear_codec_buffers(WmallDecodeCtx *s)
581 memset(s->acfilter_coeffs, 0, sizeof(s->acfilter_coeffs));
582 memset(s->acfilter_prevvalues, 0, sizeof(s->acfilter_prevvalues));
583 memset(s->lpc_coefs, 0, sizeof(s->lpc_coefs));
585 memset(s->mclms_coeffs, 0, sizeof(s->mclms_coeffs));
586 memset(s->mclms_coeffs_cur, 0, sizeof(s->mclms_coeffs_cur));
587 memset(s->mclms_prevvalues, 0, sizeof(s->mclms_prevvalues));
588 memset(s->mclms_updates, 0, sizeof(s->mclms_updates));
590 for (ich = 0; ich < s->num_channels; ich++) {
591 for (ilms = 0; ilms < s->cdlms_ttl[ich]; ilms++) {
592 memset(s->cdlms[ich][ilms].coefs, 0,
593 sizeof(s->cdlms[ich][ilms].coefs));
594 memset(s->cdlms[ich][ilms].lms_prevvalues, 0,
595 sizeof(s->cdlms[ich][ilms].lms_prevvalues));
596 memset(s->cdlms[ich][ilms].lms_updates, 0,
597 sizeof(s->cdlms[ich][ilms].lms_updates));
604 * @brief Reset filter parameters and transient area at new seekable tile.
606 static void reset_codec(WmallDecodeCtx *s)
609 s->mclms_recent = s->mclms_order * s->num_channels;
610 for (ich = 0; ich < s->num_channels; ich++) {
611 for (ilms = 0; ilms < s->cdlms_ttl[ich]; ilms++)
612 s->cdlms[ich][ilms].recent = s->cdlms[ich][ilms].order;
613 /* first sample of a seekable subframe is considered as the starting of
614 a transient area which is samples_per_frame samples long */
615 s->channel[ich].transient_counter = s->samples_per_frame;
616 s->transient[ich] = 1;
617 s->transient_pos[ich] = 0;
621 static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred)
623 int i, j, ich, pred_error;
624 int order = s->mclms_order;
625 int num_channels = s->num_channels;
626 int range = 1 << (s->bits_per_sample - 1);
628 for (ich = 0; ich < num_channels; ich++) {
629 pred_error = s->channel_residues[ich][icoef] - (unsigned)pred[ich];
630 if (pred_error > 0) {
631 for (i = 0; i < order * num_channels; i++)
632 s->mclms_coeffs[i + ich * order * num_channels] +=
633 s->mclms_updates[s->mclms_recent + i];
634 for (j = 0; j < ich; j++)
635 s->mclms_coeffs_cur[ich * num_channels + j] += WMASIGN(s->channel_residues[j][icoef]);
636 } else if (pred_error < 0) {
637 for (i = 0; i < order * num_channels; i++)
638 s->mclms_coeffs[i + ich * order * num_channels] -=
639 s->mclms_updates[s->mclms_recent + i];
640 for (j = 0; j < ich; j++)
641 s->mclms_coeffs_cur[ich * num_channels + j] -= WMASIGN(s->channel_residues[j][icoef]);
645 for (ich = num_channels - 1; ich >= 0; ich--) {
647 s->mclms_prevvalues[s->mclms_recent] = av_clip(s->channel_residues[ich][icoef],
649 s->mclms_updates[s->mclms_recent] = WMASIGN(s->channel_residues[ich][icoef]);
652 if (s->mclms_recent == 0) {
653 memcpy(&s->mclms_prevvalues[order * num_channels],
655 sizeof(int32_t) * order * num_channels);
656 memcpy(&s->mclms_updates[order * num_channels],
658 sizeof(int32_t) * order * num_channels);
659 s->mclms_recent = num_channels * order;
663 static void mclms_predict(WmallDecodeCtx *s, int icoef, int *pred)
666 int order = s->mclms_order;
667 int num_channels = s->num_channels;
669 for (ich = 0; ich < num_channels; ich++) {
671 if (!s->is_channel_coded[ich])
673 for (i = 0; i < order * num_channels; i++)
674 pred[ich] += (uint32_t)s->mclms_prevvalues[i + s->mclms_recent] *
675 s->mclms_coeffs[i + order * num_channels * ich];
676 for (i = 0; i < ich; i++)
677 pred[ich] += (uint32_t)s->channel_residues[i][icoef] *
678 s->mclms_coeffs_cur[i + num_channels * ich];
679 pred[ich] += (1 << s->mclms_scaling) >> 1;
680 pred[ich] >>= s->mclms_scaling;
681 s->channel_residues[ich][icoef] += (unsigned)pred[ich];
685 static void revert_mclms(WmallDecodeCtx *s, int tile_size)
687 int icoef, pred[WMALL_MAX_CHANNELS] = { 0 };
688 for (icoef = 0; icoef < tile_size; icoef++) {
689 mclms_predict(s, icoef, pred);
690 mclms_update(s, icoef, pred);
694 static void use_high_update_speed(WmallDecodeCtx *s, int ich)
696 int ilms, recent, icoef;
697 for (ilms = s->cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
698 recent = s->cdlms[ich][ilms].recent;
699 if (s->update_speed[ich] == 16)
702 for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
703 s->cdlms[ich][ilms].lms_updates[icoef + recent] *= 2;
705 for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
706 s->cdlms[ich][ilms].lms_updates[icoef] *= 2;
709 s->update_speed[ich] = 16;
712 static void use_normal_update_speed(WmallDecodeCtx *s, int ich)
714 int ilms, recent, icoef;
715 for (ilms = s->cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
716 recent = s->cdlms[ich][ilms].recent;
717 if (s->update_speed[ich] == 8)
720 for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
721 s->cdlms[ich][ilms].lms_updates[icoef + recent] /= 2;
723 for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
724 s->cdlms[ich][ilms].lms_updates[icoef] /= 2;
726 s->update_speed[ich] = 8;
729 #define CD_LMS(bits, ROUND) \
730 static void lms_update ## bits (WmallDecodeCtx *s, int ich, int ilms, int input) \
732 int recent = s->cdlms[ich][ilms].recent; \
733 int range = 1 << s->bits_per_sample - 1; \
734 int order = s->cdlms[ich][ilms].order; \
735 int ##bits##_t *prev = (int##bits##_t *)s->cdlms[ich][ilms].lms_prevvalues; \
740 memcpy(prev + order, prev, (bits/8) * order); \
741 memcpy(s->cdlms[ich][ilms].lms_updates + order, \
742 s->cdlms[ich][ilms].lms_updates, \
743 sizeof(*s->cdlms[ich][ilms].lms_updates) * order); \
744 recent = order - 1; \
747 prev[recent] = av_clip(input, -range, range - 1); \
748 s->cdlms[ich][ilms].lms_updates[recent] = WMASIGN(input) * s->update_speed[ich]; \
750 s->cdlms[ich][ilms].lms_updates[recent + (order >> 4)] >>= 2; \
751 s->cdlms[ich][ilms].lms_updates[recent + (order >> 3)] >>= 1; \
752 s->cdlms[ich][ilms].recent = recent; \
753 memset(s->cdlms[ich][ilms].lms_updates + recent + order, 0, \
754 sizeof(s->cdlms[ich][ilms].lms_updates) - \
755 sizeof(*s->cdlms[ich][ilms].lms_updates)*(recent+order)); \
758 static void revert_cdlms ## bits (WmallDecodeCtx *s, int ch, \
759 int coef_begin, int coef_end) \
761 int icoef, pred, ilms, num_lms, residue, input; \
763 num_lms = s->cdlms_ttl[ch]; \
764 for (ilms = num_lms - 1; ilms >= 0; ilms--) { \
765 for (icoef = coef_begin; icoef < coef_end; icoef++) { \
766 int##bits##_t *prevvalues = (int##bits##_t *)s->cdlms[ch][ilms].lms_prevvalues; \
767 pred = (1 << s->cdlms[ch][ilms].scaling) >> 1; \
768 residue = s->channel_residues[ch][icoef]; \
769 pred += s->dsp.scalarproduct_and_madd_int## bits (s->cdlms[ch][ilms].coefs, \
770 prevvalues + s->cdlms[ch][ilms].recent, \
771 s->cdlms[ch][ilms].lms_updates + \
772 s->cdlms[ch][ilms].recent, \
773 FFALIGN(s->cdlms[ch][ilms].order, ROUND), \
775 input = residue + (unsigned)(pred >> s->cdlms[ch][ilms].scaling); \
776 lms_update ## bits(s, ch, ilms, input); \
777 s->channel_residues[ch][icoef] = input; \
780 if (bits <= 16) emms_c(); \
783 CD_LMS(16, WMALL_COEFF_PAD_SIZE)
786 static void revert_inter_ch_decorr(WmallDecodeCtx *s, int tile_size)
788 if (s->num_channels != 2)
790 else if (s->is_channel_coded[0] || s->is_channel_coded[1]) {
792 for (icoef = 0; icoef < tile_size; icoef++) {
793 s->channel_residues[0][icoef] -= s->channel_residues[1][icoef] >> 1;
794 s->channel_residues[1][icoef] += s->channel_residues[0][icoef];
799 static void revert_acfilter(WmallDecodeCtx *s, int tile_size)
802 int16_t *filter_coeffs = s->acfilter_coeffs;
803 int scaling = s->acfilter_scaling;
804 int order = s->acfilter_order;
806 for (ich = 0; ich < s->num_channels; ich++) {
807 int *prevvalues = s->acfilter_prevvalues[ich];
808 for (i = 0; i < order; i++) {
810 for (j = 0; j < order; j++) {
812 pred += (uint32_t)filter_coeffs[j] * prevvalues[j - i];
814 pred += (uint32_t)s->channel_residues[ich][i - j - 1] * filter_coeffs[j];
817 s->channel_residues[ich][i] += (unsigned)pred;
819 for (i = order; i < tile_size; i++) {
821 for (j = 0; j < order; j++)
822 pred += (uint32_t)s->channel_residues[ich][i - j - 1] * filter_coeffs[j];
824 s->channel_residues[ich][i] += (unsigned)pred;
826 for (j = order - 1; j >= 0; j--)
827 if (tile_size <= j) {
828 prevvalues[j] = prevvalues[j - tile_size];
830 prevvalues[j] = s->channel_residues[ich][tile_size - j - 1];
834 static int decode_subframe(WmallDecodeCtx *s)
836 int offset = s->samples_per_frame;
837 int subframe_len = s->samples_per_frame;
838 int total_samples = s->samples_per_frame * s->num_channels;
839 int i, j, rawpcm_tile, padding_zeroes, res;
841 s->subframe_offset = get_bits_count(&s->gb);
843 /* reset channel context and find the next block offset and size
844 == the next block of the channel with the smallest number of
846 for (i = 0; i < s->num_channels; i++) {
847 if (offset > s->channel[i].decoded_samples) {
848 offset = s->channel[i].decoded_samples;
850 s->channel[i].subframe_len[s->channel[i].cur_subframe];
854 /* get a list of all channels that contain the estimated block */
855 s->channels_for_cur_subframe = 0;
856 for (i = 0; i < s->num_channels; i++) {
857 const int cur_subframe = s->channel[i].cur_subframe;
858 /* subtract already processed samples */
859 total_samples -= s->channel[i].decoded_samples;
861 /* and count if there are multiple subframes that match our profile */
862 if (offset == s->channel[i].decoded_samples &&
863 subframe_len == s->channel[i].subframe_len[cur_subframe]) {
864 total_samples -= s->channel[i].subframe_len[cur_subframe];
865 s->channel[i].decoded_samples +=
866 s->channel[i].subframe_len[cur_subframe];
867 s->channel_indexes_for_cur_subframe[s->channels_for_cur_subframe] = i;
868 ++s->channels_for_cur_subframe;
872 /* check if the frame will be complete after processing the
875 s->parsed_all_subframes = 1;
878 s->seekable_tile = get_bits1(&s->gb);
879 if (s->seekable_tile) {
880 clear_codec_buffers(s);
882 s->do_arith_coding = get_bits1(&s->gb);
883 if (s->do_arith_coding) {
884 avpriv_request_sample(s->avctx, "Arithmetic coding");
885 return AVERROR_PATCHWELCOME;
887 s->do_ac_filter = get_bits1(&s->gb);
888 s->do_inter_ch_decorr = get_bits1(&s->gb);
889 s->do_mclms = get_bits1(&s->gb);
897 if ((res = decode_cdlms(s)) < 0)
899 s->movave_scaling = get_bits(&s->gb, 3);
900 s->quant_stepsize = get_bits(&s->gb, 8) + 1;
905 rawpcm_tile = get_bits1(&s->gb);
907 if (!rawpcm_tile && !s->cdlms[0][0].order) {
908 av_log(s->avctx, AV_LOG_DEBUG,
909 "Waiting for seekable tile\n");
910 av_frame_unref(s->frame);
915 for (i = 0; i < s->num_channels; i++)
916 s->is_channel_coded[i] = 1;
919 for (i = 0; i < s->num_channels; i++)
920 s->is_channel_coded[i] = get_bits1(&s->gb);
924 s->do_lpc = get_bits1(&s->gb);
927 avpriv_request_sample(s->avctx, "Expect wrong output since "
928 "inverse LPC filter");
935 if (get_bits1(&s->gb))
936 padding_zeroes = get_bits(&s->gb, 5);
941 int bits = s->bits_per_sample - padding_zeroes;
943 av_log(s->avctx, AV_LOG_ERROR,
944 "Invalid number of padding bits in raw PCM tile\n");
945 return AVERROR_INVALIDDATA;
947 ff_dlog(s->avctx, "RAWPCM %d bits per sample. "
948 "total %d bits, remain=%d\n", bits,
949 bits * s->num_channels * subframe_len, get_bits_count(&s->gb));
950 for (i = 0; i < s->num_channels; i++)
951 for (j = 0; j < subframe_len; j++)
952 s->channel_residues[i][j] = get_sbits_long(&s->gb, bits);
954 if (s->bits_per_sample < padding_zeroes)
955 return AVERROR_INVALIDDATA;
956 for (i = 0; i < s->num_channels; i++) {
957 if (s->is_channel_coded[i]) {
958 decode_channel_residues(s, i, subframe_len);
959 if (s->seekable_tile)
960 use_high_update_speed(s, i);
962 use_normal_update_speed(s, i);
963 if (s->bits_per_sample > 16)
964 revert_cdlms32(s, i, 0, subframe_len);
966 revert_cdlms16(s, i, 0, subframe_len);
968 memset(s->channel_residues[i], 0, sizeof(**s->channel_residues) * subframe_len);
973 revert_mclms(s, subframe_len);
974 if (s->do_inter_ch_decorr)
975 revert_inter_ch_decorr(s, subframe_len);
977 revert_acfilter(s, subframe_len);
980 if (s->quant_stepsize != 1)
981 for (i = 0; i < s->num_channels; i++)
982 for (j = 0; j < subframe_len; j++)
983 s->channel_residues[i][j] *= (unsigned)s->quant_stepsize;
986 /* Write to proper output buffer depending on bit-depth */
987 for (i = 0; i < s->channels_for_cur_subframe; i++) {
988 int c = s->channel_indexes_for_cur_subframe[i];
989 int subframe_len = s->channel[c].subframe_len[s->channel[c].cur_subframe];
991 for (j = 0; j < subframe_len; j++) {
992 if (s->bits_per_sample == 16) {
993 *s->samples_16[c]++ = (int16_t) s->channel_residues[c][j] * (1 << padding_zeroes);
995 *s->samples_32[c]++ = s->channel_residues[c][j] * (256 << padding_zeroes);
1000 /* handled one subframe */
1001 for (i = 0; i < s->channels_for_cur_subframe; i++) {
1002 int c = s->channel_indexes_for_cur_subframe[i];
1003 if (s->channel[c].cur_subframe >= s->channel[c].num_subframes) {
1004 av_log(s->avctx, AV_LOG_ERROR, "broken subframe\n");
1005 return AVERROR_INVALIDDATA;
1007 ++s->channel[c].cur_subframe;
1013 * @brief Decode one WMA frame.
1014 * @param s codec context
1015 * @return 0 if the trailer bit indicates that this is the last frame,
1016 * 1 if there are additional frames
1018 static int decode_frame(WmallDecodeCtx *s)
1020 GetBitContext* gb = &s->gb;
1021 int more_frames = 0, len = 0, i, ret;
1023 s->frame->nb_samples = s->samples_per_frame;
1024 if ((ret = ff_get_buffer(s->avctx, s->frame, 0)) < 0) {
1025 /* return an error if no frame could be decoded at all */
1027 s->frame->nb_samples = 0;
1030 for (i = 0; i < s->num_channels; i++) {
1031 s->samples_16[i] = (int16_t *)s->frame->extended_data[i];
1032 s->samples_32[i] = (int32_t *)s->frame->extended_data[i];
1035 /* get frame length */
1037 len = get_bits(gb, s->log2_frame_size);
1039 /* decode tile information */
1040 if ((ret = decode_tilehdr(s))) {
1042 av_frame_unref(s->frame);
1047 if (s->dynamic_range_compression)
1048 s->drc_gain = get_bits(gb, 8);
1050 /* no idea what these are for, might be the number of samples
1051 that need to be skipped at the beginning or end of a stream */
1052 if (get_bits1(gb)) {
1055 /* usually true for the first frame */
1056 if (get_bits1(gb)) {
1057 skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
1058 ff_dlog(s->avctx, "start skip: %i\n", skip);
1061 /* sometimes true for the last frame */
1062 if (get_bits1(gb)) {
1063 skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
1064 ff_dlog(s->avctx, "end skip: %i\n", skip);
1065 s->frame->nb_samples -= skip;
1066 if (s->frame->nb_samples <= 0)
1067 return AVERROR_INVALIDDATA;
1072 /* reset subframe states */
1073 s->parsed_all_subframes = 0;
1074 for (i = 0; i < s->num_channels; i++) {
1075 s->channel[i].decoded_samples = 0;
1076 s->channel[i].cur_subframe = 0;
1079 /* decode all subframes */
1080 while (!s->parsed_all_subframes) {
1081 int decoded_samples = s->channel[0].decoded_samples;
1082 if (decode_subframe(s) < 0) {
1084 if (s->frame->nb_samples)
1085 s->frame->nb_samples = decoded_samples;
1090 ff_dlog(s->avctx, "Frame done\n");
1094 if (s->len_prefix) {
1095 if (len != (get_bits_count(gb) - s->frame_offset) + 2) {
1096 /* FIXME: not sure if this is always an error */
1097 av_log(s->avctx, AV_LOG_ERROR,
1098 "frame[%"PRIu32"] would have to skip %i bits\n",
1100 len - (get_bits_count(gb) - s->frame_offset) - 1);
1105 /* skip the rest of the frame data */
1106 skip_bits_long(gb, len - (get_bits_count(gb) - s->frame_offset) - 1);
1109 /* decode trailer bit */
1110 more_frames = get_bits1(gb);
1116 * @brief Calculate remaining input buffer length.
1117 * @param s codec context
1118 * @param gb bitstream reader context
1119 * @return remaining size in bits
1121 static int remaining_bits(WmallDecodeCtx *s, GetBitContext *gb)
1123 return s->buf_bit_size - get_bits_count(gb);
1127 * @brief Fill the bit reservoir with a (partial) frame.
1128 * @param s codec context
1129 * @param gb bitstream reader context
1130 * @param len length of the partial frame
1131 * @param append decides whether to reset the buffer or not
1133 static void save_bits(WmallDecodeCtx *s, GetBitContext* gb, int len,
1139 /* when the frame data does not need to be concatenated, the input buffer
1140 is reset and additional bits from the previous frame are copied
1141 and skipped later so that a fast byte copy is possible */
1144 s->frame_offset = get_bits_count(gb) & 7;
1145 s->num_saved_bits = s->frame_offset;
1146 init_put_bits(&s->pb, s->frame_data, s->max_frame_size);
1149 buflen = (s->num_saved_bits + len + 8) >> 3;
1151 if (len <= 0 || buflen > s->max_frame_size) {
1152 avpriv_request_sample(s->avctx, "Too small input buffer");
1154 s->num_saved_bits = 0;
1158 s->num_saved_bits += len;
1160 avpriv_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3),
1163 int align = 8 - (get_bits_count(gb) & 7);
1164 align = FFMIN(align, len);
1165 put_bits(&s->pb, align, get_bits(gb, align));
1167 avpriv_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), len);
1169 skip_bits_long(gb, len);
1172 flush_put_bits(&tmp);
1174 init_get_bits(&s->gb, s->frame_data, s->num_saved_bits);
1175 skip_bits(&s->gb, s->frame_offset);
1178 static int decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr,
1181 WmallDecodeCtx *s = avctx->priv_data;
1182 GetBitContext* gb = &s->pgb;
1183 const uint8_t* buf = avpkt->data;
1184 int buf_size = avpkt->size;
1185 int num_bits_prev_frame, packet_sequence_number, spliced_packet;
1187 s->frame->nb_samples = 0;
1189 if (!buf_size && s->num_saved_bits > get_bits_count(&s->gb)) {
1191 if (!decode_frame(s))
1192 s->num_saved_bits = 0;
1193 } else if (s->packet_done || s->packet_loss) {
1199 s->next_packet_start = buf_size - FFMIN(avctx->block_align, buf_size);
1200 buf_size = FFMIN(avctx->block_align, buf_size);
1201 s->buf_bit_size = buf_size << 3;
1203 /* parse packet header */
1204 init_get_bits(gb, buf, s->buf_bit_size);
1205 packet_sequence_number = get_bits(gb, 4);
1206 skip_bits(gb, 1); // Skip seekable_frame_in_packet, currently unused
1207 spliced_packet = get_bits1(gb);
1209 avpriv_request_sample(avctx, "Bitstream splicing");
1211 /* get number of bits that need to be added to the previous frame */
1212 num_bits_prev_frame = get_bits(gb, s->log2_frame_size);
1214 /* check for packet loss */
1215 if (!s->packet_loss &&
1216 ((s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) {
1218 av_log(avctx, AV_LOG_ERROR,
1219 "Packet loss detected! seq %"PRIx8" vs %x\n",
1220 s->packet_sequence_number, packet_sequence_number);
1222 s->packet_sequence_number = packet_sequence_number;
1224 if (num_bits_prev_frame > 0) {
1225 int remaining_packet_bits = s->buf_bit_size - get_bits_count(gb);
1226 if (num_bits_prev_frame >= remaining_packet_bits) {
1227 num_bits_prev_frame = remaining_packet_bits;
1231 /* Append the previous frame data to the remaining data from the
1232 * previous packet to create a full frame. */
1233 save_bits(s, gb, num_bits_prev_frame, 1);
1235 /* decode the cross packet frame if it is valid */
1236 if (num_bits_prev_frame < remaining_packet_bits && !s->packet_loss)
1238 } else if (s->num_saved_bits - s->frame_offset) {
1239 ff_dlog(avctx, "ignoring %x previously saved bits\n",
1240 s->num_saved_bits - s->frame_offset);
1243 if (s->packet_loss) {
1244 /* Reset number of saved bits so that the decoder does not start
1245 * to decode incomplete frames in the s->len_prefix == 0 case. */
1246 s->num_saved_bits = 0;
1248 init_put_bits(&s->pb, s->frame_data, s->max_frame_size);
1254 s->buf_bit_size = (avpkt->size - s->next_packet_start) << 3;
1255 init_get_bits(gb, avpkt->data, s->buf_bit_size);
1256 skip_bits(gb, s->packet_offset);
1258 if (s->len_prefix && remaining_bits(s, gb) > s->log2_frame_size &&
1259 (frame_size = show_bits(gb, s->log2_frame_size)) &&
1260 frame_size <= remaining_bits(s, gb)) {
1261 save_bits(s, gb, frame_size, 0);
1263 if (!s->packet_loss)
1264 s->packet_done = !decode_frame(s);
1265 } else if (!s->len_prefix
1266 && s->num_saved_bits > get_bits_count(&s->gb)) {
1267 /* when the frames do not have a length prefix, we don't know the
1268 * compressed length of the individual frames however, we know what
1269 * part of a new packet belongs to the previous frame therefore we
1270 * save the incoming packet first, then we append the "previous
1271 * frame" data from the next packet so that we get a buffer that
1272 * only contains full frames */
1273 s->packet_done = !decode_frame(s);
1279 if (remaining_bits(s, gb) < 0) {
1280 av_log(avctx, AV_LOG_ERROR, "Overread %d\n", -remaining_bits(s, gb));
1284 if (s->packet_done && !s->packet_loss &&
1285 remaining_bits(s, gb) > 0) {
1286 /* save the rest of the data so that it can be decoded
1287 * with the next packet */
1288 save_bits(s, gb, remaining_bits(s, gb), 0);
1291 *got_frame_ptr = s->frame->nb_samples > 0;
1292 av_frame_move_ref(data, s->frame);
1294 s->packet_offset = get_bits_count(gb) & 7;
1296 return (s->packet_loss) ? AVERROR_INVALIDDATA : buf_size ? get_bits_count(gb) >> 3 : 0;
1299 static void flush(AVCodecContext *avctx)
1301 WmallDecodeCtx *s = avctx->priv_data;
1304 s->num_saved_bits = 0;
1305 s->frame_offset = 0;
1306 s->next_packet_start = 0;
1307 s->cdlms[0][0].order = 0;
1308 s->frame->nb_samples = 0;
1309 init_put_bits(&s->pb, s->frame_data, s->max_frame_size);
1312 static av_cold int decode_close(AVCodecContext *avctx)
1314 WmallDecodeCtx *s = avctx->priv_data;
1316 av_frame_free(&s->frame);
1317 av_freep(&s->frame_data);
1322 AVCodec ff_wmalossless_decoder = {
1323 .name = "wmalossless",
1324 .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio Lossless"),
1325 .type = AVMEDIA_TYPE_AUDIO,
1326 .id = AV_CODEC_ID_WMALOSSLESS,
1327 .priv_data_size = sizeof(WmallDecodeCtx),
1328 .init = decode_init,
1329 .close = decode_close,
1330 .decode = decode_packet,
1332 .capabilities = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY,
1333 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1334 .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
1336 AV_SAMPLE_FMT_NONE },