]> git.sesse.net Git - ffmpeg/blob - libavcodec/wmalosslessdec.c
Implement reset_codec()
[ffmpeg] / libavcodec / wmalosslessdec.c
1 /*
2  * Wmall compatible 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  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23
24 /**
25  * @file
26  * @brief wmall decoder implementation
27  * Wmall is an MDCT based codec comparable to wma standard or AAC.
28  * The decoding therefore consists of the following steps:
29  * - bitstream decoding
30  * - reconstruction of per-channel data
31  * - rescaling and inverse quantization
32  * - IMDCT
33  * - windowing and overlapp-add
34  *
35  * The compressed wmall bitstream is split into individual packets.
36  * Every such packet contains one or more wma frames.
37  * The compressed frames may have a variable length and frames may
38  * cross packet boundaries.
39  * Common to all wmall frames is the number of samples that are stored in
40  * a frame.
41  * The number of samples and a few other decode flags are stored
42  * as extradata that has to be passed to the decoder.
43  *
44  * The wmall frames themselves are again split into a variable number of
45  * subframes. Every subframe contains the data for 2^N time domain samples
46  * where N varies between 7 and 12.
47  *
48  * Example wmall bitstream (in samples):
49  *
50  * ||   packet 0           || packet 1 || packet 2      packets
51  * ---------------------------------------------------
52  * || frame 0      || frame 1       || frame 2    ||    frames
53  * ---------------------------------------------------
54  * ||   |      |   ||   |   |   |   ||            ||    subframes of channel 0
55  * ---------------------------------------------------
56  * ||      |   |   ||   |   |   |   ||            ||    subframes of channel 1
57  * ---------------------------------------------------
58  *
59  * The frame layouts for the individual channels of a wma frame does not need
60  * to be the same.
61  *
62  * However, if the offsets and lengths of several subframes of a frame are the
63  * same, the subframes of the channels can be grouped.
64  * Every group may then use special coding techniques like M/S stereo coding
65  * to improve the compression ratio. These channel transformations do not
66  * need to be applied to a whole subframe. Instead, they can also work on
67  * individual scale factor bands (see below).
68  * The coefficients that carry the audio signal in the frequency domain
69  * are transmitted as huffman-coded vectors with 4, 2 and 1 elements.
70  * In addition to that, the encoder can switch to a runlevel coding scheme
71  * by transmitting subframe_length / 128 zero coefficients.
72  *
73  * Before the audio signal can be converted to the time domain, the
74  * coefficients have to be rescaled and inverse quantized.
75  * A subframe is therefore split into several scale factor bands that get
76  * scaled individually.
77  * Scale factors are submitted for every frame but they might be shared
78  * between the subframes of a channel. Scale factors are initially DPCM-coded.
79  * Once scale factors are shared, the differences are transmitted as runlevel
80  * codes.
81  * Every subframe length and offset combination in the frame layout shares a
82  * common quantization factor that can be adjusted for every channel by a
83  * modifier.
84  * After the inverse quantization, the coefficients get processed by an IMDCT.
85  * The resulting values are then windowed with a sine window and the first half
86  * of the values are added to the second half of the output from the previous
87  * subframe in order to reconstruct the output samples.
88  */
89
90 #include "avcodec.h"
91 #include "internal.h"
92 #include "get_bits.h"
93 #include "put_bits.h"
94 #include "dsputil.h"
95 #include "wma.h"
96
97 /** current decoder limitations */
98 #define WMALL_MAX_CHANNELS    8                             ///< max number of handled channels
99 #define MAX_SUBFRAMES  32                                    ///< max number of subframes per channel
100 #define MAX_BANDS      29                                    ///< max number of scale factor bands
101 #define MAX_FRAMESIZE  32768                                 ///< maximum compressed frame size
102
103 #define WMALL_BLOCK_MIN_BITS  6                                           ///< log2 of min block size
104 #define WMALL_BLOCK_MAX_BITS 12                                           ///< log2 of max block size
105 #define WMALL_BLOCK_MAX_SIZE (1 << WMALL_BLOCK_MAX_BITS)                 ///< maximum block size
106 #define WMALL_BLOCK_SIZES    (WMALL_BLOCK_MAX_BITS - WMALL_BLOCK_MIN_BITS + 1) ///< possible block sizes
107
108
109 #define VLCBITS            9
110 #define SCALEVLCBITS       8
111 #define VEC4MAXDEPTH    ((HUFF_VEC4_MAXBITS+VLCBITS-1)/VLCBITS)
112 #define VEC2MAXDEPTH    ((HUFF_VEC2_MAXBITS+VLCBITS-1)/VLCBITS)
113 #define VEC1MAXDEPTH    ((HUFF_VEC1_MAXBITS+VLCBITS-1)/VLCBITS)
114 #define SCALEMAXDEPTH   ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS)
115 #define SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS)
116
117 static float            sin64[33];        ///< sinus table for decorrelation
118
119 /**
120  * @brief frame specific decoder context for a single channel
121  */
122 typedef struct {
123     int16_t  prev_block_len;                          ///< length of the previous block
124     uint8_t  transmit_coefs;
125     uint8_t  num_subframes;
126     uint16_t subframe_len[MAX_SUBFRAMES];             ///< subframe length in samples
127     uint16_t subframe_offset[MAX_SUBFRAMES];          ///< subframe positions in the current frame
128     uint8_t  cur_subframe;                            ///< current subframe number
129     uint16_t decoded_samples;                         ///< number of already processed samples
130     uint8_t  grouped;                                 ///< channel is part of a group
131     int      quant_step;                              ///< quantization step for the current subframe
132     int8_t   reuse_sf;                                ///< share scale factors between subframes
133     int8_t   scale_factor_step;                       ///< scaling step for the current subframe
134     int      max_scale_factor;                        ///< maximum scale factor for the current subframe
135     int      saved_scale_factors[2][MAX_BANDS];       ///< resampled and (previously) transmitted scale factor values
136     int8_t   scale_factor_idx;                        ///< index for the transmitted scale factor values (used for resampling)
137     int*     scale_factors;                           ///< pointer to the scale factor values used for decoding
138     uint8_t  table_idx;                               ///< index in sf_offsets for the scale factor reference block
139     float*   coeffs;                                  ///< pointer to the subframe decode buffer
140     uint16_t num_vec_coeffs;                          ///< number of vector coded coefficients
141     DECLARE_ALIGNED(16, float, out)[WMALL_BLOCK_MAX_SIZE + WMALL_BLOCK_MAX_SIZE / 2]; ///< output buffer
142 } WmallChannelCtx;
143
144 /**
145  * @brief channel group for channel transformations
146  */
147 typedef struct {
148     uint8_t num_channels;                                     ///< number of channels in the group
149     int8_t  transform;                                        ///< transform on / off
150     int8_t  transform_band[MAX_BANDS];                        ///< controls if the transform is enabled for a certain band
151     float   decorrelation_matrix[WMALL_MAX_CHANNELS*WMALL_MAX_CHANNELS];
152     float*  channel_data[WMALL_MAX_CHANNELS];                ///< transformation coefficients
153 } WmallChannelGrp;
154
155 /**
156  * @brief main decoder context
157  */
158 typedef struct WmallDecodeCtx {
159     /* generic decoder variables */
160     AVCodecContext*  avctx;                         ///< codec context for av_log
161     DSPContext       dsp;                           ///< accelerated DSP functions
162     uint8_t          frame_data[MAX_FRAMESIZE +
163                       FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data
164     PutBitContext    pb;                            ///< context for filling the frame_data buffer
165     FFTContext       mdct_ctx[WMALL_BLOCK_SIZES];  ///< MDCT context per block size
166     DECLARE_ALIGNED(16, float, tmp)[WMALL_BLOCK_MAX_SIZE]; ///< IMDCT output buffer
167     float*           windows[WMALL_BLOCK_SIZES];   ///< windows for the different block sizes
168
169     /* frame size dependent frame information (set during initialization) */
170     uint32_t         decode_flags;                  ///< used compression features
171     uint8_t          len_prefix;                    ///< frame is prefixed with its length
172     uint8_t          dynamic_range_compression;     ///< frame contains DRC data
173     uint8_t          bits_per_sample;               ///< integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1.0])
174     uint16_t         samples_per_frame;             ///< number of samples to output
175     uint16_t         log2_frame_size;
176     int8_t           num_channels;                  ///< number of channels in the stream (same as AVCodecContext.num_channels)
177     int8_t           lfe_channel;                   ///< lfe channel index
178     uint8_t          max_num_subframes;
179     uint8_t          subframe_len_bits;             ///< number of bits used for the subframe length
180     uint8_t          max_subframe_len_bit;          ///< flag indicating that the subframe is of maximum size when the first subframe length bit is 1
181     uint16_t         min_samples_per_subframe;
182     int8_t           num_sfb[WMALL_BLOCK_SIZES];   ///< scale factor bands per block size
183     int16_t          sfb_offsets[WMALL_BLOCK_SIZES][MAX_BANDS];                    ///< scale factor band offsets (multiples of 4)
184     int8_t           sf_offsets[WMALL_BLOCK_SIZES][WMALL_BLOCK_SIZES][MAX_BANDS]; ///< scale factor resample matrix
185     int16_t          subwoofer_cutoffs[WMALL_BLOCK_SIZES]; ///< subwoofer cutoff values
186
187     /* packet decode state */
188     GetBitContext    pgb;                           ///< bitstream reader context for the packet
189     int              next_packet_start;             ///< start offset of the next wma packet in the demuxer packet
190     uint8_t          packet_offset;                 ///< frame offset in the packet
191     uint8_t          packet_sequence_number;        ///< current packet number
192     int              num_saved_bits;                ///< saved number of bits
193     int              frame_offset;                  ///< frame offset in the bit reservoir
194     int              subframe_offset;               ///< subframe offset in the bit reservoir
195     uint8_t          packet_loss;                   ///< set in case of bitstream error
196     uint8_t          packet_done;                   ///< set when a packet is fully decoded
197
198     /* frame decode state */
199     uint32_t         frame_num;                     ///< current frame number (not used for decoding)
200     GetBitContext    gb;                            ///< bitstream reader context
201     int              buf_bit_size;                  ///< buffer size in bits
202     float*           samples;                       ///< current samplebuffer pointer
203     float*           samples_end;                   ///< maximum samplebuffer pointer
204     uint8_t          drc_gain;                      ///< gain for the DRC tool
205     int8_t           skip_frame;                    ///< skip output step
206     int8_t           parsed_all_subframes;          ///< all subframes decoded?
207
208     /* subframe/block decode state */
209     int16_t          subframe_len;                  ///< current subframe length
210     int8_t           channels_for_cur_subframe;     ///< number of channels that contain the subframe
211     int8_t           channel_indexes_for_cur_subframe[WMALL_MAX_CHANNELS];
212     int8_t           num_bands;                     ///< number of scale factor bands
213     int8_t           transmit_num_vec_coeffs;       ///< number of vector coded coefficients is part of the bitstream
214     int16_t*         cur_sfb_offsets;               ///< sfb offsets for the current block
215     uint8_t          table_idx;                     ///< index for the num_sfb, sfb_offsets, sf_offsets and subwoofer_cutoffs tables
216     int8_t           esc_len;                       ///< length of escaped coefficients
217
218     uint8_t          num_chgroups;                  ///< number of channel groups
219     WmallChannelGrp chgroup[WMALL_MAX_CHANNELS];    ///< channel group information
220
221     WmallChannelCtx channel[WMALL_MAX_CHANNELS];    ///< per channel data
222
223     // WMA lossless
224     
225     uint8_t do_arith_coding;
226     uint8_t do_ac_filter;
227     uint8_t do_inter_ch_decorr;
228     uint8_t do_mclms;
229     uint8_t do_lpc;
230
231     int8_t acfilter_order;
232     int8_t acfilter_scaling;
233     int acfilter_coeffs[16];
234
235     int8_t mclms_order;
236     int8_t mclms_scaling;
237     int16_t mclms_coeffs[128];
238     int16_t mclms_coeffs_cur[4];
239     int mclms_prevvalues[64];   // FIXME: should be 32-bit / 16-bit depending on bit-depth
240     int16_t mclms_updates[64];
241     int mclms_recent;
242
243     int movave_scaling;
244     int quant_stepsize;
245
246     struct {
247         int order;
248         int scaling;
249         int coefsend;
250         int bitsend;
251         int16_t coefs[256];
252     int lms_prevvalues[512];    // FIXME: see above
253     int16_t lms_updates[512];   // and here too
254     int recent;
255     } cdlms[2][9];              /* XXX: Here, 2 is the max. no. of channels allowed,
256                                         9 is the maximum no. of filters per channel.
257                                         Question is, why 2 if WMALL_MAX_CHANNELS == 8 */
258
259
260     int cdlms_ttl[2];
261
262     int bV3RTM;
263
264     int is_channel_coded[2];    // XXX: same question as above applies here too (and below)
265     int update_speed[2];
266
267     int transient[2];
268     int transient_pos[2];
269     int seekable_tile;
270
271     int ave_sum[2];
272
273     int channel_residues[2][2048];
274
275
276     int lpc_coefs[2][40];
277     int lpc_order;
278     int lpc_scaling;
279     int lpc_intbits;
280
281     int channel_coeffs[2][2048];
282
283 } WmallDecodeCtx;
284
285
286 #undef dprintf
287 #define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__)
288
289
290 /**
291  *@brief helper function to print the most important members of the context
292  *@param s context
293  */
294 static void av_cold dump_context(WmallDecodeCtx *s)
295 {
296 #define PRINT(a, b)     av_log(s->avctx, AV_LOG_DEBUG, " %s = %d\n", a, b);
297 #define PRINT_HEX(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %x\n", a, b);
298
299     PRINT("ed sample bit depth", s->bits_per_sample);
300     PRINT_HEX("ed decode flags", s->decode_flags);
301     PRINT("samples per frame",   s->samples_per_frame);
302     PRINT("log2 frame size",     s->log2_frame_size);
303     PRINT("max num subframes",   s->max_num_subframes);
304     PRINT("len prefix",          s->len_prefix);
305     PRINT("num channels",        s->num_channels);
306 }
307
308 /**
309  *@brief Uninitialize the decoder and free all resources.
310  *@param avctx codec context
311  *@return 0 on success, < 0 otherwise
312  */
313 static av_cold int decode_end(AVCodecContext *avctx)
314 {
315     WmallDecodeCtx *s = avctx->priv_data;
316     int i;
317
318     for (i = 0; i < WMALL_BLOCK_SIZES; i++)
319         ff_mdct_end(&s->mdct_ctx[i]);
320
321     return 0;
322 }
323
324 /**
325  *@brief Initialize the decoder.
326  *@param avctx codec context
327  *@return 0 on success, -1 otherwise
328  */
329 static av_cold int decode_init(AVCodecContext *avctx)
330 {
331     WmallDecodeCtx *s = avctx->priv_data;
332     uint8_t *edata_ptr = avctx->extradata;
333     unsigned int channel_mask;
334     int i;
335     int log2_max_num_subframes;
336     int num_possible_block_sizes;
337
338     s->avctx = avctx;
339     dsputil_init(&s->dsp, avctx);
340     init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE);
341
342     avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
343
344     if (avctx->extradata_size >= 18) {
345         s->decode_flags    = AV_RL16(edata_ptr+14);
346         channel_mask       = AV_RL32(edata_ptr+2);
347         s->bits_per_sample = AV_RL16(edata_ptr);
348         /** dump the extradata */
349         for (i = 0; i < avctx->extradata_size; i++)
350             dprintf(avctx, "[%x] ", avctx->extradata[i]);
351         dprintf(avctx, "\n");
352
353     } else {
354         av_log_ask_for_sample(avctx, "Unknown extradata size\n");
355         return AVERROR_INVALIDDATA;
356     }
357
358     /** generic init */
359     s->log2_frame_size = av_log2(avctx->block_align) + 4;
360
361     /** frame info */
362     s->skip_frame  = 1; /* skip first frame */
363     s->packet_loss = 1;
364     s->len_prefix  = (s->decode_flags & 0x40);
365
366     /** get frame len */
367     s->samples_per_frame = 1 << ff_wma_get_frame_len_bits(avctx->sample_rate,
368                                                           3, s->decode_flags);
369
370     /** init previous block len */
371     for (i = 0; i < avctx->channels; i++)
372         s->channel[i].prev_block_len = s->samples_per_frame;
373
374     /** subframe info */
375     log2_max_num_subframes  = ((s->decode_flags & 0x38) >> 3);
376     s->max_num_subframes    = 1 << log2_max_num_subframes;
377     s->max_subframe_len_bit = 0;
378     s->subframe_len_bits    = av_log2(log2_max_num_subframes) + 1;
379
380     num_possible_block_sizes     = log2_max_num_subframes + 1;
381     s->min_samples_per_subframe  = s->samples_per_frame / s->max_num_subframes;
382     s->dynamic_range_compression = (s->decode_flags & 0x80);
383
384     s->bV3RTM = s->decode_flags & 0x100;
385
386     if (s->max_num_subframes > MAX_SUBFRAMES) {
387         av_log(avctx, AV_LOG_ERROR, "invalid number of subframes %i\n",
388                s->max_num_subframes);
389         return AVERROR_INVALIDDATA;
390     }
391
392     s->num_channels = avctx->channels;
393
394     /** extract lfe channel position */
395     s->lfe_channel = -1;
396
397     if (channel_mask & 8) {
398         unsigned int mask;
399         for (mask = 1; mask < 16; mask <<= 1) {
400             if (channel_mask & mask)
401                 ++s->lfe_channel;
402         }
403     }
404
405     if (s->num_channels < 0) {
406         av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n", s->num_channels);
407         return AVERROR_INVALIDDATA;
408     } else if (s->num_channels > WMALL_MAX_CHANNELS) {
409         av_log_ask_for_sample(avctx, "unsupported number of channels\n");
410         return AVERROR_PATCHWELCOME;
411     }
412
413     avctx->channel_layout = channel_mask;
414     return 0;
415 }
416
417 /**
418  *@brief Decode the subframe length.
419  *@param s context
420  *@param offset sample offset in the frame
421  *@return decoded subframe length on success, < 0 in case of an error
422  */
423 static int decode_subframe_length(WmallDecodeCtx *s, int offset)
424 {
425     int frame_len_ratio;
426     int subframe_len, len;
427
428     /** no need to read from the bitstream when only one length is possible */
429     if (offset == s->samples_per_frame - s->min_samples_per_subframe)
430         return s->min_samples_per_subframe;
431
432     len = av_log2(s->max_num_subframes - 1) + 1;
433     frame_len_ratio = get_bits(&s->gb, len);
434
435     subframe_len = s->min_samples_per_subframe * (frame_len_ratio + 1);
436
437     /** sanity check the length */
438     if (subframe_len < s->min_samples_per_subframe ||
439         subframe_len > s->samples_per_frame) {
440         av_log(s->avctx, AV_LOG_ERROR, "broken frame: subframe_len %i\n",
441                subframe_len);
442         return AVERROR_INVALIDDATA;
443     }
444     return subframe_len;
445 }
446
447 /**
448  *@brief Decode how the data in the frame is split into subframes.
449  *       Every WMA frame contains the encoded data for a fixed number of
450  *       samples per channel. The data for every channel might be split
451  *       into several subframes. This function will reconstruct the list of
452  *       subframes for every channel.
453  *
454  *       If the subframes are not evenly split, the algorithm estimates the
455  *       channels with the lowest number of total samples.
456  *       Afterwards, for each of these channels a bit is read from the
457  *       bitstream that indicates if the channel contains a subframe with the
458  *       next subframe size that is going to be read from the bitstream or not.
459  *       If a channel contains such a subframe, the subframe size gets added to
460  *       the channel's subframe list.
461  *       The algorithm repeats these steps until the frame is properly divided
462  *       between the individual channels.
463  *
464  *@param s context
465  *@return 0 on success, < 0 in case of an error
466  */
467 static int decode_tilehdr(WmallDecodeCtx *s)
468 {
469     uint16_t num_samples[WMALL_MAX_CHANNELS];        /**< sum of samples for all currently known subframes of a channel */
470     uint8_t  contains_subframe[WMALL_MAX_CHANNELS];  /**< flag indicating if a channel contains the current subframe */
471     int channels_for_cur_subframe = s->num_channels;  /**< number of channels that contain the current subframe */
472     int fixed_channel_layout = 0;                     /**< flag indicating that all channels use the same subfra2me offsets and sizes */
473     int min_channel_len = 0;                          /**< smallest sum of samples (channels with this length will be processed first) */
474     int c;
475
476     /* Should never consume more than 3073 bits (256 iterations for the
477      * while loop when always the minimum amount of 128 samples is substracted
478      * from missing samples in the 8 channel case).
479      * 1 + BLOCK_MAX_SIZE * MAX_CHANNELS / BLOCK_MIN_SIZE * (MAX_CHANNELS  + 4)
480      */
481
482     /** reset tiling information */
483     for (c = 0; c < s->num_channels; c++)
484         s->channel[c].num_subframes = 0;
485
486     memset(num_samples, 0, sizeof(num_samples));
487
488     if (s->max_num_subframes == 1 || get_bits1(&s->gb))
489         fixed_channel_layout = 1;
490
491     /** loop until the frame data is split between the subframes */
492     do {
493         int subframe_len;
494
495         /** check which channels contain the subframe */
496         for (c = 0; c < s->num_channels; c++) {
497             if (num_samples[c] == min_channel_len) {
498                 if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
499                     (min_channel_len == s->samples_per_frame - s->min_samples_per_subframe)) {
500                     contains_subframe[c] = 1;
501                 }                   
502                 else {
503                     contains_subframe[c] = get_bits1(&s->gb);
504                 }
505             } else
506                 contains_subframe[c] = 0;
507         }
508
509         /** get subframe length, subframe_len == 0 is not allowed */
510         if ((subframe_len = decode_subframe_length(s, min_channel_len)) <= 0)
511             return AVERROR_INVALIDDATA;
512         /** add subframes to the individual channels and find new min_channel_len */
513         min_channel_len += subframe_len;
514         for (c = 0; c < s->num_channels; c++) {
515             WmallChannelCtx* chan = &s->channel[c];
516
517             if (contains_subframe[c]) {
518                 if (chan->num_subframes >= MAX_SUBFRAMES) {
519                     av_log(s->avctx, AV_LOG_ERROR,
520                            "broken frame: num subframes > 31\n");
521                     return AVERROR_INVALIDDATA;
522                 }
523                 chan->subframe_len[chan->num_subframes] = subframe_len;
524                 num_samples[c] += subframe_len;
525                 ++chan->num_subframes;
526                 if (num_samples[c] > s->samples_per_frame) {
527                     av_log(s->avctx, AV_LOG_ERROR, "broken frame: "
528                            "channel len(%d) > samples_per_frame(%d)\n",
529                            num_samples[c], s->samples_per_frame);
530                     return AVERROR_INVALIDDATA;
531                 }
532             } else if (num_samples[c] <= min_channel_len) {
533                 if (num_samples[c] < min_channel_len) {
534                     channels_for_cur_subframe = 0;
535                     min_channel_len = num_samples[c];
536                 }
537                 ++channels_for_cur_subframe;
538             }
539         }
540     } while (min_channel_len < s->samples_per_frame);
541
542     for (c = 0; c < s->num_channels; c++) {
543         int i;
544         int offset = 0;
545         for (i = 0; i < s->channel[c].num_subframes; i++) {
546             s->channel[c].subframe_offset[i] = offset;
547             offset += s->channel[c].subframe_len[i];
548         }
549     }
550
551     return 0;
552 }
553
554
555 static int my_log2(unsigned int i)
556 {
557     unsigned int iLog2 = 0;
558     while ((i >> iLog2) > 1)
559         iLog2++;
560     return iLog2;
561 }
562
563
564 /**
565  *
566  */
567 static void decode_ac_filter(WmallDecodeCtx *s)
568 {
569     int i;
570     s->acfilter_order = get_bits(&s->gb, 4) + 1;
571     s->acfilter_scaling = get_bits(&s->gb, 4);
572
573     for(i = 0; i < s->acfilter_order; i++) {
574         s->acfilter_coeffs[i] = get_bits(&s->gb, s->acfilter_scaling) + 1;
575     }
576 }
577
578
579 /**
580  *
581  */
582 static void decode_mclms(WmallDecodeCtx *s)
583 {
584     s->mclms_order = (get_bits(&s->gb, 4) + 1) * 2;
585     s->mclms_scaling = get_bits(&s->gb, 4);
586     if(get_bits1(&s->gb)) {
587         // mclms_send_coef
588         int i;
589         int send_coef_bits;
590         int cbits = av_log2(s->mclms_scaling + 1);
591         assert(cbits == my_log2(s->mclms_scaling + 1));
592         if(1 << cbits < s->mclms_scaling + 1)
593             cbits++;
594
595         send_coef_bits = (cbits ? get_bits(&s->gb, cbits) : 0) + 2;
596
597         for(i = 0; i < s->mclms_order * s->num_channels * s->num_channels; i++) {
598             s->mclms_coeffs[i] = get_bits(&s->gb, send_coef_bits);
599         }           
600
601         for(i = 0; i < s->num_channels; i++) {
602             int c;
603             for(c = 0; c < i; c++) {
604                 s->mclms_coeffs_cur[i * s->num_channels + c] = get_bits(&s->gb, send_coef_bits);
605             }
606         }
607     }
608 }
609
610
611 /**
612  *
613  */
614 static void decode_cdlms(WmallDecodeCtx *s)
615 {
616     int c, i;
617     int cdlms_send_coef = get_bits1(&s->gb);
618
619     for(c = 0; c < s->num_channels; c++) {
620         s->cdlms_ttl[c] = get_bits(&s->gb, 3) + 1;
621         for(i = 0; i < s->cdlms_ttl[c]; i++) {
622             s->cdlms[c][i].order = (get_bits(&s->gb, 7) + 1) * 8;
623         }
624
625         for(i = 0; i < s->cdlms_ttl[c]; i++) {
626             s->cdlms[c][i].scaling = get_bits(&s->gb, 4);
627         }
628
629         if(cdlms_send_coef) {
630             for(i = 0; i < s->cdlms_ttl[c]; i++) {
631                 int cbits, shift_l, shift_r, j;
632                 cbits = av_log2(s->cdlms[c][i].order);
633                 if(1 << cbits < s->cdlms[c][i].order)
634                     cbits++;
635                 s->cdlms[c][i].coefsend = get_bits(&s->gb, cbits) + 1;
636
637                 cbits = av_log2(s->cdlms[c][i].scaling + 1);
638                 if(1 << cbits < s->cdlms[c][i].scaling + 1)
639                     cbits++;
640                 
641                 s->cdlms[c][i].bitsend = get_bits(&s->gb, cbits) + 2;
642                 shift_l = 32 - s->cdlms[c][i].bitsend;
643                 shift_r = 32 - 2 - s->cdlms[c][i].scaling;
644                 for(j = 0; j < s->cdlms[c][i].coefsend; j++) {
645                     s->cdlms[c][i].coefs[j] = 
646                         (get_bits(&s->gb, s->cdlms[c][i].bitsend) << shift_l) >> shift_r;
647                 }
648             }
649         }
650     }
651 }
652
653 /**
654  *
655  */
656 static int decode_channel_residues(WmallDecodeCtx *s, int ch, int tile_size)
657 {
658     int i = 0;
659     unsigned int ave_mean;
660     s->transient[ch] = get_bits1(&s->gb);
661     if(s->transient[ch])
662         s->transient_pos[ch] = get_bits(&s->gb, av_log2(tile_size));
663     
664     if(s->seekable_tile) {
665         ave_mean = get_bits(&s->gb, s->bits_per_sample);
666         s->ave_sum[ch] = ave_mean << (s->movave_scaling + 1);
667 //      s->ave_sum[ch] *= 2;
668     }
669
670     if(s->seekable_tile) {
671         if(s->do_inter_ch_decorr)
672             s->channel_residues[ch][0] = get_sbits(&s->gb, s->bits_per_sample + 1);
673         else
674             s->channel_residues[ch][0] = get_sbits(&s->gb, s->bits_per_sample);
675         i++;
676     }
677     for(; i < tile_size; i++) {
678         int quo = 0, rem, rem_bits, residue;
679         while(get_bits1(&s->gb))
680             quo++;
681         if(quo >= 32)
682             quo += get_bits_long(&s->gb, get_bits(&s->gb, 5) + 1);
683
684         ave_mean = (s->ave_sum[ch] + (1 << s->movave_scaling)) >> (s->movave_scaling + 1);
685         rem_bits = av_ceil_log2(ave_mean);
686         rem = rem_bits ? get_bits(&s->gb, rem_bits) : 0;
687         residue = (quo << rem_bits) + rem;
688
689         s->ave_sum[ch] = residue + s->ave_sum[ch] - (s->ave_sum[ch] >> s->movave_scaling);
690
691         if(residue & 1)
692             residue = -(residue >> 1) - 1;
693         else
694             residue = residue >> 1;
695         s->channel_residues[ch][i] = residue;
696
697 //      dprintf(s->avctx, "%5d: %5d %10d %12d %12d %5d %-16d %04x\n",i, quo, ave_mean, s->ave_sum[ch], rem, rem_bits, s->channel_residues[ch][i], show_bits(&s->gb, 16));
698     }
699
700     return 0;
701
702 }
703
704
705 /**
706  *
707  */
708 static void
709 decode_lpc(WmallDecodeCtx *s)
710 {
711     int ch, i, cbits;
712     s->lpc_order = get_bits(&s->gb, 5) + 1;
713     s->lpc_scaling = get_bits(&s->gb, 4);
714     s->lpc_intbits = get_bits(&s->gb, 3) + 1;
715     cbits = s->lpc_scaling + s->lpc_intbits;
716     for(ch = 0; ch < s->num_channels; ch++) {
717         for(i = 0; i < s->lpc_order; i++) {
718             s->lpc_coefs[ch][i] = get_sbits(&s->gb, cbits);
719         }
720     }
721 }
722
723
724 static void clear_codec_buffers(WmallDecodeCtx *s)
725 {
726     int ich, ilms;
727
728     memset(s->acfilter_coeffs, 0,     16 * sizeof(int));
729     memset(s->lpc_coefs      , 0, 40 * 2 * sizeof(int));
730
731     memset(s->mclms_coeffs    , 0, 128 * sizeof(int16_t));
732     memset(s->mclms_coeffs_cur, 0,   4 * sizeof(int16_t));
733     memset(s->mclms_prevvalues, 0,  64 * sizeof(int));
734     memset(s->mclms_updates   , 0,  64 * sizeof(int16_t));
735
736     for (ich = 0; ich < s->num_channels; ich++) {
737         for (ilms = 0; ilms < s->cdlms_ttl[ich]; ilms++) {
738             memset(s->cdlms[ich][ilms].coefs         , 0, 256 * sizeof(int16_t));
739             memset(s->cdlms[ich][ilms].lms_prevvalues, 0, 512 * sizeof(int));
740             memset(s->cdlms[ich][ilms].lms_updates   , 0, 512 * sizeof(int16_t));
741         }
742         s->ave_sum[ich] = 0;
743     }
744 }
745
746 static void reset_codec(WmallDecodeCtx *s)
747 {
748     int ich, ilms;
749     s->mclms_recent = s->mclms_order * s->num_channels;
750     for (ich = 0; ich < s->num_channels; ich++)
751         for (ilms = 0; ilms < s->cdlms_ttl[ich]; ilms++)
752             s->cdlms[ich][ilms].recent = s->cdlms[ich][ilms].order;
753 }
754
755
756
757 /**
758  *@brief Decode a single subframe (block).
759  *@param s codec context
760  *@return 0 on success, < 0 when decoding failed
761  */
762 static int decode_subframe(WmallDecodeCtx *s)
763 {
764     int offset = s->samples_per_frame;
765     int subframe_len = s->samples_per_frame;
766     int i;
767     int total_samples   = s->samples_per_frame * s->num_channels;
768     int rawpcm_tile;
769     int padding_zeroes;
770
771     s->subframe_offset = get_bits_count(&s->gb);
772
773     /** reset channel context and find the next block offset and size
774         == the next block of the channel with the smallest number of
775         decoded samples
776     */
777     for (i = 0; i < s->num_channels; i++) {
778         s->channel[i].grouped = 0;
779         if (offset > s->channel[i].decoded_samples) {
780             offset = s->channel[i].decoded_samples;
781             subframe_len =
782                 s->channel[i].subframe_len[s->channel[i].cur_subframe];
783         }
784     }
785
786     /** get a list of all channels that contain the estimated block */
787     s->channels_for_cur_subframe = 0;
788     for (i = 0; i < s->num_channels; i++) {
789         const int cur_subframe = s->channel[i].cur_subframe;
790         /** substract already processed samples */
791         total_samples -= s->channel[i].decoded_samples;
792
793         /** and count if there are multiple subframes that match our profile */
794         if (offset == s->channel[i].decoded_samples &&
795             subframe_len == s->channel[i].subframe_len[cur_subframe]) {
796             total_samples -= s->channel[i].subframe_len[cur_subframe];
797             s->channel[i].decoded_samples +=
798                 s->channel[i].subframe_len[cur_subframe];
799             s->channel_indexes_for_cur_subframe[s->channels_for_cur_subframe] = i;
800             ++s->channels_for_cur_subframe;
801         }
802     }
803
804     /** check if the frame will be complete after processing the
805         estimated block */
806     if (!total_samples)
807         s->parsed_all_subframes = 1;
808
809
810     s->seekable_tile = get_bits1(&s->gb);
811     if(s->seekable_tile) {
812         s->do_arith_coding    = get_bits1(&s->gb);
813         if(s->do_arith_coding) {
814             dprintf(s->avctx, "do_arith_coding == 1");
815             abort();
816         }
817         s->do_ac_filter       = get_bits1(&s->gb);
818         s->do_inter_ch_decorr = get_bits1(&s->gb);
819         s->do_mclms           = get_bits1(&s->gb);
820         
821         if(s->do_ac_filter)
822             decode_ac_filter(s);
823
824         if(s->do_mclms)
825             decode_mclms(s);
826
827         decode_cdlms(s);
828         s->movave_scaling = get_bits(&s->gb, 3);
829         s->quant_stepsize = get_bits(&s->gb, 8) + 1;
830     }
831
832     rawpcm_tile = get_bits1(&s->gb);
833
834     for(i = 0; i < s->num_channels; i++) {
835         s->is_channel_coded[i] = 1;
836     }
837
838     if(!rawpcm_tile) {
839
840         for(i = 0; i < s->num_channels; i++) {
841             s->is_channel_coded[i] = get_bits1(&s->gb);
842         }
843
844         if(s->bV3RTM) {
845             // LPC
846             s->do_lpc = get_bits1(&s->gb);
847             if(s->do_lpc) {
848                 decode_lpc(s);
849             }
850         } else {
851             s->do_lpc = 0;
852         }
853     }
854
855
856     if(get_bits1(&s->gb)) {
857         padding_zeroes = get_bits(&s->gb, 5);
858     } else {
859         padding_zeroes = 0;
860     }
861
862     if(rawpcm_tile) {
863         
864         int bits = s->bits_per_sample - padding_zeroes;
865         int j;
866         dprintf(s->avctx, "RAWPCM %d bits per sample. total %d bits, remain=%d\n", bits,
867                 bits * s->num_channels * subframe_len, get_bits_count(&s->gb));
868         for(i = 0; i < s->num_channels; i++) {
869             for(j = 0; j < subframe_len; j++) {
870                 s->channel_coeffs[i][j] = get_sbits(&s->gb, bits);
871 //              dprintf(s->avctx, "PCM[%d][%d] = 0x%04x\n", i, j, s->channel_coeffs[i][j]);
872             }
873         }
874     } else {
875         for(i = 0; i < s->num_channels; i++)
876             if(s->is_channel_coded[i])
877                 decode_channel_residues(s, i, subframe_len);
878     }
879
880     /** handled one subframe */
881
882     for (i = 0; i < s->channels_for_cur_subframe; i++) {
883         int c = s->channel_indexes_for_cur_subframe[i];
884         if (s->channel[c].cur_subframe >= s->channel[c].num_subframes) {
885             av_log(s->avctx, AV_LOG_ERROR, "broken subframe\n");
886             return AVERROR_INVALIDDATA;
887         }
888         ++s->channel[c].cur_subframe;
889     }
890     return 0;
891 }
892
893 /**
894  *@brief Decode one WMA frame.
895  *@param s codec context
896  *@return 0 if the trailer bit indicates that this is the last frame,
897  *        1 if there are additional frames
898  */
899 static int decode_frame(WmallDecodeCtx *s)
900 {
901     GetBitContext* gb = &s->gb;
902     int more_frames = 0;
903     int len = 0;
904     int i;
905
906     /** check for potential output buffer overflow */
907     if (s->num_channels * s->samples_per_frame > s->samples_end - s->samples) {
908         /** return an error if no frame could be decoded at all */
909         av_log(s->avctx, AV_LOG_ERROR,
910                "not enough space for the output samples\n");
911         s->packet_loss = 1;
912         return 0;
913     }
914
915     /** get frame length */
916     if (s->len_prefix)
917         len = get_bits(gb, s->log2_frame_size);
918
919     /** decode tile information */
920     if (decode_tilehdr(s)) {
921         s->packet_loss = 1;
922         return 0;
923     }
924
925     /** read drc info */
926     if (s->dynamic_range_compression) {
927         s->drc_gain = get_bits(gb, 8);
928     }
929
930     /** no idea what these are for, might be the number of samples
931         that need to be skipped at the beginning or end of a stream */
932     if (get_bits1(gb)) {
933         int skip;
934
935         /** usually true for the first frame */
936         if (get_bits1(gb)) {
937             skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
938             dprintf(s->avctx, "start skip: %i\n", skip);
939         }
940
941         /** sometimes true for the last frame */
942         if (get_bits1(gb)) {
943             skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
944             dprintf(s->avctx, "end skip: %i\n", skip);
945         }
946
947     }
948
949     /** reset subframe states */
950     s->parsed_all_subframes = 0;
951     for (i = 0; i < s->num_channels; i++) {
952         s->channel[i].decoded_samples = 0;
953         s->channel[i].cur_subframe    = 0;
954         s->channel[i].reuse_sf        = 0;
955     }
956
957     /** decode all subframes */
958     while (!s->parsed_all_subframes) {
959         if (decode_subframe(s) < 0) {
960             s->packet_loss = 1;
961             return 0;
962         }
963     }
964
965     dprintf(s->avctx, "Frame done\n");
966
967     if (s->skip_frame) {
968         s->skip_frame = 0;
969     } else
970         s->samples += s->num_channels * s->samples_per_frame;
971
972     if (s->len_prefix) {
973         if (len != (get_bits_count(gb) - s->frame_offset) + 2) {
974             /** FIXME: not sure if this is always an error */
975             av_log(s->avctx, AV_LOG_ERROR,
976                    "frame[%i] would have to skip %i bits\n", s->frame_num,
977                    len - (get_bits_count(gb) - s->frame_offset) - 1);
978             s->packet_loss = 1;
979             return 0;
980         }
981
982         /** skip the rest of the frame data */
983         skip_bits_long(gb, len - (get_bits_count(gb) - s->frame_offset) - 1);
984     } else {
985 /*
986         while (get_bits_count(gb) < s->num_saved_bits && get_bits1(gb) == 0) {
987             dprintf(s->avctx, "skip1\n");
988         }
989 */
990     }
991
992     /** decode trailer bit */
993     more_frames = get_bits1(gb);
994     ++s->frame_num;
995     return more_frames;
996 }
997
998 /**
999  *@brief Calculate remaining input buffer length.
1000  *@param s codec context
1001  *@param gb bitstream reader context
1002  *@return remaining size in bits
1003  */
1004 static int remaining_bits(WmallDecodeCtx *s, GetBitContext *gb)
1005 {
1006     return s->buf_bit_size - get_bits_count(gb);
1007 }
1008
1009 /**
1010  *@brief Fill the bit reservoir with a (partial) frame.
1011  *@param s codec context
1012  *@param gb bitstream reader context
1013  *@param len length of the partial frame
1014  *@param append decides wether to reset the buffer or not
1015  */
1016 static void save_bits(WmallDecodeCtx *s, GetBitContext* gb, int len,
1017                       int append)
1018 {
1019     int buflen;
1020
1021     /** when the frame data does not need to be concatenated, the input buffer
1022         is resetted and additional bits from the previous frame are copyed
1023         and skipped later so that a fast byte copy is possible */
1024
1025     if (!append) {
1026         s->frame_offset = get_bits_count(gb) & 7;
1027         s->num_saved_bits = s->frame_offset;
1028         init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE);
1029     }
1030
1031     buflen = (s->num_saved_bits + len + 8) >> 3;
1032
1033     if (len <= 0 || buflen > MAX_FRAMESIZE) {
1034         av_log_ask_for_sample(s->avctx, "input buffer too small\n");
1035         s->packet_loss = 1;
1036         return;
1037     }
1038
1039     s->num_saved_bits += len;
1040     if (!append) {
1041         avpriv_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3),
1042                      s->num_saved_bits);
1043     } else {
1044         int align = 8 - (get_bits_count(gb) & 7);
1045         align = FFMIN(align, len);
1046         put_bits(&s->pb, align, get_bits(gb, align));
1047         len -= align;
1048         avpriv_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), len);
1049     }
1050     skip_bits_long(gb, len);
1051
1052     {
1053         PutBitContext tmp = s->pb;
1054         flush_put_bits(&tmp);
1055     }
1056
1057     init_get_bits(&s->gb, s->frame_data, s->num_saved_bits);
1058     skip_bits(&s->gb, s->frame_offset);
1059 }
1060
1061 /**
1062  *@brief Decode a single WMA packet.
1063  *@param avctx codec context
1064  *@param data the output buffer
1065  *@param data_size number of bytes that were written to the output buffer
1066  *@param avpkt input packet
1067  *@return number of bytes that were read from the input buffer
1068  */
1069 static int decode_packet(AVCodecContext *avctx,
1070                          void *data, int *data_size, AVPacket* avpkt)
1071 {
1072     WmallDecodeCtx *s = avctx->priv_data;
1073     GetBitContext* gb  = &s->pgb;
1074     const uint8_t* buf = avpkt->data;
1075     int buf_size       = avpkt->size;
1076     int num_bits_prev_frame;
1077     int packet_sequence_number;
1078
1079     s->samples       = data;
1080     s->samples_end   = (float*)((int8_t*)data + *data_size);
1081     *data_size = 0;
1082
1083     if (s->packet_done || s->packet_loss) {
1084         s->packet_done = 0;
1085
1086         /** sanity check for the buffer length */
1087         if (buf_size < avctx->block_align)
1088             return 0;
1089
1090         s->next_packet_start = buf_size - avctx->block_align;
1091         buf_size = avctx->block_align;
1092         s->buf_bit_size = buf_size << 3;
1093
1094         /** parse packet header */
1095         init_get_bits(gb, buf, s->buf_bit_size);
1096         packet_sequence_number = get_bits(gb, 4);
1097         int seekable_frame_in_packet = get_bits1(gb);
1098         int spliced_packet = get_bits1(gb);
1099
1100         /** get number of bits that need to be added to the previous frame */
1101         num_bits_prev_frame = get_bits(gb, s->log2_frame_size);
1102
1103         /** check for packet loss */
1104         if (!s->packet_loss &&
1105             ((s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) {
1106             s->packet_loss = 1;
1107             av_log(avctx, AV_LOG_ERROR, "Packet loss detected! seq %x vs %x\n",
1108                    s->packet_sequence_number, packet_sequence_number);
1109         }
1110         s->packet_sequence_number = packet_sequence_number;
1111
1112         if (num_bits_prev_frame > 0) {
1113             int remaining_packet_bits = s->buf_bit_size - get_bits_count(gb);
1114             if (num_bits_prev_frame >= remaining_packet_bits) {
1115                 num_bits_prev_frame = remaining_packet_bits;
1116                 s->packet_done = 1;
1117             }
1118
1119             /** append the previous frame data to the remaining data from the
1120                 previous packet to create a full frame */
1121             save_bits(s, gb, num_bits_prev_frame, 1);
1122
1123             /** decode the cross packet frame if it is valid */
1124             if (!s->packet_loss)
1125                 decode_frame(s);
1126         } else if (s->num_saved_bits - s->frame_offset) {
1127             dprintf(avctx, "ignoring %x previously saved bits\n",
1128                     s->num_saved_bits - s->frame_offset);
1129         }
1130
1131         if (s->packet_loss) {
1132             /** reset number of saved bits so that the decoder
1133                 does not start to decode incomplete frames in the
1134                 s->len_prefix == 0 case */
1135             s->num_saved_bits = 0;
1136             s->packet_loss = 0;
1137         }
1138
1139     } else {
1140         int frame_size;
1141
1142         s->buf_bit_size = (avpkt->size - s->next_packet_start) << 3;
1143         init_get_bits(gb, avpkt->data, s->buf_bit_size);
1144         skip_bits(gb, s->packet_offset);
1145         
1146         if (s->len_prefix && remaining_bits(s, gb) > s->log2_frame_size &&
1147             (frame_size = show_bits(gb, s->log2_frame_size)) &&
1148             frame_size <= remaining_bits(s, gb)) {
1149             save_bits(s, gb, frame_size, 0);
1150             s->packet_done = !decode_frame(s);
1151         } else if (!s->len_prefix
1152                    && s->num_saved_bits > get_bits_count(&s->gb)) {
1153             /** when the frames do not have a length prefix, we don't know
1154                 the compressed length of the individual frames
1155                 however, we know what part of a new packet belongs to the
1156                 previous frame
1157                 therefore we save the incoming packet first, then we append
1158                 the "previous frame" data from the next packet so that
1159                 we get a buffer that only contains full frames */
1160             s->packet_done = !decode_frame(s);
1161         } else {
1162             s->packet_done = 1;
1163         }
1164     }
1165
1166     if (s->packet_done && !s->packet_loss &&
1167         remaining_bits(s, gb) > 0) {
1168         /** save the rest of the data so that it can be decoded
1169             with the next packet */
1170         save_bits(s, gb, remaining_bits(s, gb), 0);
1171     }
1172
1173     *data_size = 0; // (int8_t *)s->samples - (int8_t *)data;
1174     s->packet_offset = get_bits_count(gb) & 7;
1175
1176     return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3;
1177 }
1178
1179 /**
1180  *@brief Clear decoder buffers (for seeking).
1181  *@param avctx codec context
1182  */
1183 static void flush(AVCodecContext *avctx)
1184 {
1185     WmallDecodeCtx *s = avctx->priv_data;
1186     int i;
1187     /** reset output buffer as a part of it is used during the windowing of a
1188         new frame */
1189     for (i = 0; i < s->num_channels; i++)
1190         memset(s->channel[i].out, 0, s->samples_per_frame *
1191                sizeof(*s->channel[i].out));
1192     s->packet_loss = 1;
1193 }
1194
1195
1196 /**
1197  *@brief wmall decoder
1198  */
1199 AVCodec ff_wmalossless_decoder = {
1200     "wmalossless",
1201     AVMEDIA_TYPE_AUDIO,
1202     CODEC_ID_WMALOSSLESS,
1203     sizeof(WmallDecodeCtx),
1204     decode_init,
1205     NULL,
1206     decode_end,
1207     decode_packet,
1208     .capabilities = CODEC_CAP_SUBFRAMES,
1209     .flush= flush,
1210     .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 9 Lossless"),
1211 };