FFmpeg
wmalosslessdec.c
Go to the documentation of this file.
1 /*
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
7  *
8  * This file is part of FFmpeg.
9  *
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.
14  *
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.
19  *
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
23  */
24 
25 #include <inttypes.h>
26 
27 #include "libavutil/attributes.h"
28 #include "libavutil/avassert.h"
29 #include "libavutil/mem.h"
30 #include "libavutil/mem_internal.h"
31 
32 #include "avcodec.h"
33 #include "codec_internal.h"
34 #include "decode.h"
35 #include "get_bits.h"
36 #include "put_bits.h"
37 #include "lossless_audiodsp.h"
38 #include "wma_common.h"
39 
40 /** current decoder limitations */
41 #define WMALL_MAX_CHANNELS 8 ///< max number of handled channels
42 #define MAX_SUBFRAMES 32 ///< max number of subframes per channel
43 #define MAX_BANDS 29 ///< max number of scale factor bands
44 #define MAX_FRAMESIZE 32768 ///< maximum compressed frame size
45 #define MAX_ORDER 256
46 
47 #define WMALL_BLOCK_MIN_BITS 6 ///< log2 of min block size
48 #define WMALL_BLOCK_MAX_BITS 14 ///< log2 of max block size
49 #define WMALL_BLOCK_MAX_SIZE (1 << WMALL_BLOCK_MAX_BITS) ///< maximum block size
50 #define WMALL_BLOCK_SIZES (WMALL_BLOCK_MAX_BITS - WMALL_BLOCK_MIN_BITS + 1) ///< possible block sizes
51 
52 #define WMALL_COEFF_PAD_SIZE 16 ///< pad coef buffers with 0 for use with SIMD
53 
54 /**
55  * @brief frame-specific decoder context for a single channel
56  */
57 typedef struct WmallChannelCtx {
58  int16_t prev_block_len; ///< length of the previous block
59  uint8_t transmit_coefs;
60  uint8_t num_subframes;
61  uint16_t subframe_len[MAX_SUBFRAMES]; ///< subframe length in samples
62  uint16_t subframe_offsets[MAX_SUBFRAMES]; ///< subframe positions in the current frame
63  uint8_t cur_subframe; ///< current subframe number
64  uint16_t decoded_samples; ///< number of already processed samples
65  int quant_step; ///< quantization step for the current subframe
66  int transient_counter; ///< number of transient samples from the beginning of the transient zone
68 
69 /**
70  * @brief main decoder context
71  */
72 typedef struct WmallDecodeCtx {
73  /* generic decoder variables */
76  LLAudDSPContext dsp; ///< accelerated DSP functions
77  uint8_t *frame_data; ///< compressed frame data
78  int max_frame_size; ///< max bitstream size
79  PutBitContext pb; ///< context for filling the frame_data buffer
80 
81  /* frame size dependent frame information (set during initialization) */
82  uint32_t decode_flags; ///< used compression features
83  int len_prefix; ///< frame is prefixed with its length
84  int dynamic_range_compression; ///< frame contains DRC data
85  uint8_t bits_per_sample; ///< integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1.0])
86  uint16_t samples_per_frame; ///< number of samples to output
87  uint16_t log2_frame_size;
88  int8_t num_channels; ///< number of channels in the stream (same as AVCodecContext.num_channels)
89  int8_t lfe_channel; ///< lfe channel index
91  uint8_t subframe_len_bits; ///< number of bits used for the subframe length
92  uint8_t max_subframe_len_bit; ///< flag indicating that the subframe is of maximum size when the first subframe length bit is 1
94 
95  /* packet decode state */
96  GetBitContext pgb; ///< bitstream reader context for the packet
97  int next_packet_start; ///< start offset of the next WMA packet in the demuxer packet
98  uint8_t packet_offset; ///< offset to the frame in the packet
99  uint8_t packet_sequence_number; ///< current packet number
100  int num_saved_bits; ///< saved number of bits
101  int frame_offset; ///< frame offset in the bit reservoir
102  int subframe_offset; ///< subframe offset in the bit reservoir
103  uint8_t packet_loss; ///< set in case of bitstream error
104  uint8_t packet_done; ///< set when a packet is fully decoded
105 
106  /* frame decode state */
107  uint32_t frame_num; ///< current frame number (not used for decoding)
108  GetBitContext gb; ///< bitstream reader context
109  int buf_bit_size; ///< buffer size in bits
110  int16_t *samples_16[WMALL_MAX_CHANNELS]; ///< current sample buffer pointer (16-bit)
111  int32_t *samples_32[WMALL_MAX_CHANNELS]; ///< current sample buffer pointer (24-bit)
112  uint8_t drc_gain; ///< gain for the DRC tool
113  int8_t skip_frame; ///< skip output step
114  int8_t parsed_all_subframes; ///< all subframes decoded?
115 
116  /* subframe/block decode state */
117  int16_t subframe_len; ///< current subframe length
118  int8_t channels_for_cur_subframe; ///< number of channels that contain the subframe
120 
122 
123  // WMA Lossless-specific
124 
126  uint8_t do_ac_filter;
128  uint8_t do_mclms;
129  uint8_t do_lpc;
130 
133  int16_t acfilter_coeffs[16];
135 
136  int8_t mclms_order;
143 
146 
147  struct {
148  int order;
149  int scaling;
150  int coefsend;
151  int bitsend;
152  DECLARE_ALIGNED(16, int16_t, coefs)[MAX_ORDER + WMALL_COEFF_PAD_SIZE/sizeof(int16_t)];
154  DECLARE_ALIGNED(16, int16_t, lms_updates)[MAX_ORDER * 2 + WMALL_COEFF_PAD_SIZE/sizeof(int16_t)];
155  int recent;
157 
159 
160  int bV3RTM;
161 
164 
165  int transient[WMALL_MAX_CHANNELS];
168 
170 
172 
178 
179 /** Get sign of integer (1 for positive, -1 for negative and 0 for zero) */
180 #define WMASIGN(x) (((x) > 0) - ((x) < 0))
181 
183 {
184  WmallDecodeCtx *s = avctx->priv_data;
185  uint8_t *edata_ptr = avctx->extradata;
186  unsigned int channel_mask;
187  int i, log2_max_num_subframes;
188 
189  if (avctx->block_align <= 0 || avctx->block_align > (1<<21)) {
190  av_log(avctx, AV_LOG_ERROR, "block_align is not set or invalid\n");
191  return AVERROR(EINVAL);
192  }
193 
194  if (avctx->extradata_size >= 18) {
195  s->decode_flags = AV_RL16(edata_ptr + 14);
196  channel_mask = AV_RL32(edata_ptr + 2);
197  s->bits_per_sample = AV_RL16(edata_ptr);
198  if (s->bits_per_sample == 16)
200  else if (s->bits_per_sample == 24) {
202  avctx->bits_per_raw_sample = 24;
203  } else {
204  av_log(avctx, AV_LOG_ERROR, "Unknown bit-depth: %"PRIu8"\n",
205  s->bits_per_sample);
206  return AVERROR_INVALIDDATA;
207  }
208  /* dump the extradata */
209  for (i = 0; i < avctx->extradata_size; i++)
210  ff_dlog(avctx, "[%x] ", avctx->extradata[i]);
211  ff_dlog(avctx, "\n");
212 
213  } else {
214  avpriv_request_sample(avctx, "Unsupported extradata size");
215  return AVERROR_PATCHWELCOME;
216  }
217 
218  if (channel_mask) {
220  av_channel_layout_from_mask(&avctx->ch_layout, channel_mask);
221  }
222  av_assert0(avctx->ch_layout.nb_channels >= 0);
224  avpriv_request_sample(avctx,
225  "More than " AV_STRINGIFY(WMALL_MAX_CHANNELS) " channels");
226  return AVERROR_PATCHWELCOME;
227  }
228 
229  s->num_channels = avctx->ch_layout.nb_channels;
230 
231  /* extract lfe channel position */
232  s->lfe_channel = -1;
233 
234  if (channel_mask & 8) {
235  unsigned int mask;
236  for (mask = 1; mask < 16; mask <<= 1)
237  if (channel_mask & mask)
238  ++s->lfe_channel;
239  }
240 
241  s->max_frame_size = MAX_FRAMESIZE * avctx->ch_layout.nb_channels;
242  s->frame_data = av_mallocz(s->max_frame_size + AV_INPUT_BUFFER_PADDING_SIZE);
243  if (!s->frame_data)
244  return AVERROR(ENOMEM);
245 
246  s->avctx = avctx;
247  ff_llauddsp_init(&s->dsp);
248  init_put_bits(&s->pb, s->frame_data, s->max_frame_size);
249 
250  /* generic init */
251  s->log2_frame_size = av_log2(avctx->block_align) + 4;
252 
253  /* frame info */
254  s->skip_frame = 1; /* skip first frame */
255  s->packet_loss = 1;
256  s->len_prefix = s->decode_flags & 0x40;
257 
258  /* get frame len */
259  s->samples_per_frame = 1 << ff_wma_get_frame_len_bits(avctx->sample_rate,
260  3, s->decode_flags);
261  av_assert0(s->samples_per_frame <= WMALL_BLOCK_MAX_SIZE);
262 
263  /* init previous block len */
264  for (i = 0; i < avctx->ch_layout.nb_channels; i++)
265  s->channel[i].prev_block_len = s->samples_per_frame;
266 
267  /* subframe info */
268  log2_max_num_subframes = (s->decode_flags & 0x38) >> 3;
269  s->max_num_subframes = 1 << log2_max_num_subframes;
270  s->max_subframe_len_bit = 0;
271  s->subframe_len_bits = av_log2(log2_max_num_subframes) + 1;
272 
273  s->min_samples_per_subframe = s->samples_per_frame / s->max_num_subframes;
274  s->dynamic_range_compression = s->decode_flags & 0x80;
275  s->bV3RTM = s->decode_flags & 0x100;
276 
277  if (s->max_num_subframes > MAX_SUBFRAMES) {
278  av_log(avctx, AV_LOG_ERROR, "invalid number of subframes %"PRIu8"\n",
279  s->max_num_subframes);
280  return AVERROR_INVALIDDATA;
281  }
282 
283  s->frame = av_frame_alloc();
284  if (!s->frame)
285  return AVERROR(ENOMEM);
286 
287  return 0;
288 }
289 
290 /**
291  * @brief Decode the subframe length.
292  * @param s context
293  * @param offset sample offset in the frame
294  * @return decoded subframe length on success, < 0 in case of an error
295  */
297 {
298  int frame_len_ratio, subframe_len, len;
299 
300  /* no need to read from the bitstream when only one length is possible */
301  if (offset == s->samples_per_frame - s->min_samples_per_subframe)
302  return s->min_samples_per_subframe;
303 
304  len = av_log2(s->max_num_subframes - 1) + 1;
305  frame_len_ratio = get_bits(&s->gb, len);
306  subframe_len = s->min_samples_per_subframe * (frame_len_ratio + 1);
307 
308  /* sanity check the length */
309  if (subframe_len < s->min_samples_per_subframe ||
310  subframe_len > s->samples_per_frame) {
311  av_log(s->avctx, AV_LOG_ERROR, "broken frame: subframe_len %i\n",
312  subframe_len);
313  return AVERROR_INVALIDDATA;
314  }
315  return subframe_len;
316 }
317 
318 /**
319  * @brief Decode how the data in the frame is split into subframes.
320  * Every WMA frame contains the encoded data for a fixed number of
321  * samples per channel. The data for every channel might be split
322  * into several subframes. This function will reconstruct the list of
323  * subframes for every channel.
324  *
325  * If the subframes are not evenly split, the algorithm estimates the
326  * channels with the lowest number of total samples.
327  * Afterwards, for each of these channels a bit is read from the
328  * bitstream that indicates if the channel contains a subframe with the
329  * next subframe size that is going to be read from the bitstream or not.
330  * If a channel contains such a subframe, the subframe size gets added to
331  * the channel's subframe list.
332  * The algorithm repeats these steps until the frame is properly divided
333  * between the individual channels.
334  *
335  * @param s context
336  * @return 0 on success, < 0 in case of an error
337  */
339 {
340  uint16_t num_samples[WMALL_MAX_CHANNELS] = { 0 }; /* sum of samples for all currently known subframes of a channel */
341  uint8_t contains_subframe[WMALL_MAX_CHANNELS]; /* flag indicating if a channel contains the current subframe */
342  int channels_for_cur_subframe = s->num_channels; /* number of channels that contain the current subframe */
343  int fixed_channel_layout = 0; /* flag indicating that all channels use the same subfra2me offsets and sizes */
344  int min_channel_len = 0; /* smallest sum of samples (channels with this length will be processed first) */
345  int c, tile_aligned;
346 
347  /* reset tiling information */
348  for (c = 0; c < s->num_channels; c++)
349  s->channel[c].num_subframes = 0;
350 
351  tile_aligned = get_bits1(&s->gb);
352  if (s->max_num_subframes == 1 || tile_aligned)
353  fixed_channel_layout = 1;
354 
355  /* loop until the frame data is split between the subframes */
356  do {
357  int subframe_len, in_use = 0;
358 
359  /* check which channels contain the subframe */
360  for (c = 0; c < s->num_channels; c++) {
361  if (num_samples[c] == min_channel_len) {
362  if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
363  (min_channel_len == s->samples_per_frame - s->min_samples_per_subframe)) {
364  contains_subframe[c] = 1;
365  } else {
366  contains_subframe[c] = get_bits1(&s->gb);
367  }
368  in_use |= contains_subframe[c];
369  } else
370  contains_subframe[c] = 0;
371  }
372 
373  if (!in_use) {
374  av_log(s->avctx, AV_LOG_ERROR,
375  "Found empty subframe\n");
376  return AVERROR_INVALIDDATA;
377  }
378 
379  /* get subframe length, subframe_len == 0 is not allowed */
380  if ((subframe_len = decode_subframe_length(s, min_channel_len)) <= 0)
381  return AVERROR_INVALIDDATA;
382  /* add subframes to the individual channels and find new min_channel_len */
383  min_channel_len += subframe_len;
384  for (c = 0; c < s->num_channels; c++) {
385  WmallChannelCtx *chan = &s->channel[c];
386 
387  if (contains_subframe[c]) {
388  if (chan->num_subframes >= MAX_SUBFRAMES) {
389  av_log(s->avctx, AV_LOG_ERROR,
390  "broken frame: num subframes > 31\n");
391  return AVERROR_INVALIDDATA;
392  }
393  chan->subframe_len[chan->num_subframes] = subframe_len;
394  num_samples[c] += subframe_len;
395  ++chan->num_subframes;
396  if (num_samples[c] > s->samples_per_frame) {
397  av_log(s->avctx, AV_LOG_ERROR, "broken frame: "
398  "channel len(%"PRIu16") > samples_per_frame(%"PRIu16")\n",
399  num_samples[c], s->samples_per_frame);
400  return AVERROR_INVALIDDATA;
401  }
402  } else if (num_samples[c] <= min_channel_len) {
403  if (num_samples[c] < min_channel_len) {
404  channels_for_cur_subframe = 0;
405  min_channel_len = num_samples[c];
406  }
407  ++channels_for_cur_subframe;
408  }
409  }
410  } while (min_channel_len < s->samples_per_frame);
411 
412  for (c = 0; c < s->num_channels; c++) {
413  int i, offset = 0;
414  for (i = 0; i < s->channel[c].num_subframes; i++) {
415  s->channel[c].subframe_offsets[i] = offset;
416  offset += s->channel[c].subframe_len[i];
417  }
418  }
419 
420  return 0;
421 }
422 
424 {
425  int i;
426  s->acfilter_order = get_bits(&s->gb, 4) + 1;
427  s->acfilter_scaling = get_bits(&s->gb, 4);
428 
429  for (i = 0; i < s->acfilter_order; i++)
430  s->acfilter_coeffs[i] = get_bitsz(&s->gb, s->acfilter_scaling) + 1;
431 }
432 
434 {
435  s->mclms_order = (get_bits(&s->gb, 4) + 1) * 2;
436  s->mclms_scaling = get_bits(&s->gb, 4);
437  if (get_bits1(&s->gb)) {
438  int i, send_coef_bits;
439  int cbits = av_log2(s->mclms_scaling + 1);
440  if (1 << cbits < s->mclms_scaling + 1)
441  cbits++;
442 
443  send_coef_bits = get_bitsz(&s->gb, cbits) + 2;
444 
445  for (i = 0; i < s->mclms_order * s->num_channels * s->num_channels; i++)
446  s->mclms_coeffs[i] = get_bits(&s->gb, send_coef_bits);
447 
448  for (i = 0; i < s->num_channels; i++) {
449  int c;
450  for (c = 0; c < i; c++)
451  s->mclms_coeffs_cur[i * s->num_channels + c] = get_bits(&s->gb, send_coef_bits);
452  }
453  }
454 }
455 
457 {
458  int c, i;
459  int cdlms_send_coef = get_bits1(&s->gb);
460 
461  for (c = 0; c < s->num_channels; c++) {
462  s->cdlms_ttl[c] = get_bits(&s->gb, 3) + 1;
463  for (i = 0; i < s->cdlms_ttl[c]; i++) {
464  s->cdlms[c][i].order = (get_bits(&s->gb, 7) + 1) * 8;
465  if (s->cdlms[c][i].order > MAX_ORDER) {
466  av_log(s->avctx, AV_LOG_ERROR,
467  "Order[%d][%d] %d > max (%d), not supported\n",
468  c, i, s->cdlms[c][i].order, MAX_ORDER);
469  s->cdlms[0][0].order = 0;
470  return AVERROR_INVALIDDATA;
471  }
472  if(s->cdlms[c][i].order & 8 && s->bits_per_sample == 16) {
473  static int warned;
474  if(!warned)
475  avpriv_request_sample(s->avctx, "CDLMS of order %d",
476  s->cdlms[c][i].order);
477  warned = 1;
478  }
479  }
480 
481  for (i = 0; i < s->cdlms_ttl[c]; i++)
482  s->cdlms[c][i].scaling = get_bits(&s->gb, 4);
483 
484  if (cdlms_send_coef) {
485  for (i = 0; i < s->cdlms_ttl[c]; i++) {
486  int cbits, shift_l, shift_r, j;
487  cbits = av_log2(s->cdlms[c][i].order);
488  if ((1 << cbits) < s->cdlms[c][i].order)
489  cbits++;
490  s->cdlms[c][i].coefsend = get_bits(&s->gb, cbits) + 1;
491 
492  cbits = av_log2(s->cdlms[c][i].scaling + 1);
493  if ((1 << cbits) < s->cdlms[c][i].scaling + 1)
494  cbits++;
495 
496  s->cdlms[c][i].bitsend = get_bitsz(&s->gb, cbits) + 2;
497  shift_l = 32 - s->cdlms[c][i].bitsend;
498  shift_r = 32 - s->cdlms[c][i].scaling - 2;
499  for (j = 0; j < s->cdlms[c][i].coefsend; j++)
500  s->cdlms[c][i].coefs[j] =
501  (get_bits(&s->gb, s->cdlms[c][i].bitsend) << shift_l) >> shift_r;
502  }
503  }
504 
505  for (i = 0; i < s->cdlms_ttl[c]; i++)
506  memset(s->cdlms[c][i].coefs + s->cdlms[c][i].order,
508  }
509 
510  return 0;
511 }
512 
513 static int decode_channel_residues(WmallDecodeCtx *s, int ch, int tile_size)
514 {
515  int i = 0;
516  unsigned int ave_mean;
517  s->transient[ch] = get_bits1(&s->gb);
518  if (s->transient[ch]) {
519  s->transient_pos[ch] = get_bits(&s->gb, av_log2(tile_size));
520  if (s->transient_pos[ch])
521  s->transient[ch] = 0;
522  s->channel[ch].transient_counter =
523  FFMAX(s->channel[ch].transient_counter, s->samples_per_frame / 2);
524  } else if (s->channel[ch].transient_counter)
525  s->transient[ch] = 1;
526 
527  if (s->seekable_tile) {
528  ave_mean = get_bits(&s->gb, s->bits_per_sample);
529  s->ave_sum[ch] = ave_mean << (s->movave_scaling + 1);
530  }
531 
532  if (s->seekable_tile) {
533  if (s->do_inter_ch_decorr)
534  s->channel_residues[ch][0] = get_sbits_long(&s->gb, s->bits_per_sample + 1);
535  else
536  s->channel_residues[ch][0] = get_sbits_long(&s->gb, s->bits_per_sample);
537  i++;
538  }
539  for (; i < tile_size; i++) {
540  int rem, rem_bits;
541  unsigned quo = 0, residue;
542  while(get_bits1(&s->gb)) {
543  quo++;
544  if (get_bits_left(&s->gb) <= 0)
545  return -1;
546  }
547  if (quo >= 32)
548  quo += get_bits_long(&s->gb, get_bits(&s->gb, 5) + 1);
549 
550  ave_mean = (s->ave_sum[ch] + (1 << s->movave_scaling)) >> (s->movave_scaling + 1);
551  if (ave_mean <= 1)
552  residue = quo;
553  else {
554  rem_bits = av_ceil_log2(ave_mean);
555  rem = get_bits_long(&s->gb, rem_bits);
556  residue = (quo << rem_bits) + rem;
557  }
558 
559  s->ave_sum[ch] = residue + s->ave_sum[ch] -
560  (s->ave_sum[ch] >> s->movave_scaling);
561 
562  residue = (residue >> 1) ^ -(residue & 1);
563  s->channel_residues[ch][i] = residue;
564  }
565 
566  return 0;
567 
568 }
569 
571 {
572  int ch, i, cbits;
573  s->lpc_order = get_bits(&s->gb, 5) + 1;
574  s->lpc_scaling = get_bits(&s->gb, 4);
575  s->lpc_intbits = get_bits(&s->gb, 3) + 1;
576  cbits = s->lpc_scaling + s->lpc_intbits;
577  for (ch = 0; ch < s->num_channels; ch++)
578  for (i = 0; i < s->lpc_order; i++)
579  s->lpc_coefs[ch][i] = get_sbits(&s->gb, cbits);
580 }
581 
583 {
584  int ich, ilms;
585 
586  memset(s->acfilter_coeffs, 0, sizeof(s->acfilter_coeffs));
587  memset(s->acfilter_prevvalues, 0, sizeof(s->acfilter_prevvalues));
588  memset(s->lpc_coefs, 0, sizeof(s->lpc_coefs));
589 
590  memset(s->mclms_coeffs, 0, sizeof(s->mclms_coeffs));
591  memset(s->mclms_coeffs_cur, 0, sizeof(s->mclms_coeffs_cur));
592  memset(s->mclms_prevvalues, 0, sizeof(s->mclms_prevvalues));
593  memset(s->mclms_updates, 0, sizeof(s->mclms_updates));
594 
595  for (ich = 0; ich < s->num_channels; ich++) {
596  for (ilms = 0; ilms < s->cdlms_ttl[ich]; ilms++) {
597  memset(s->cdlms[ich][ilms].coefs, 0,
598  sizeof(s->cdlms[ich][ilms].coefs));
599  memset(s->cdlms[ich][ilms].lms_prevvalues, 0,
600  sizeof(s->cdlms[ich][ilms].lms_prevvalues));
601  memset(s->cdlms[ich][ilms].lms_updates, 0,
602  sizeof(s->cdlms[ich][ilms].lms_updates));
603  }
604  s->ave_sum[ich] = 0;
605  }
606 }
607 
608 /**
609  * @brief Reset filter parameters and transient area at new seekable tile.
610  */
612 {
613  int ich, ilms;
614  s->mclms_recent = s->mclms_order * s->num_channels;
615  for (ich = 0; ich < s->num_channels; ich++) {
616  for (ilms = 0; ilms < s->cdlms_ttl[ich]; ilms++)
617  s->cdlms[ich][ilms].recent = s->cdlms[ich][ilms].order;
618  /* first sample of a seekable subframe is considered as the starting of
619  a transient area which is samples_per_frame samples long */
620  s->channel[ich].transient_counter = s->samples_per_frame;
621  s->transient[ich] = 1;
622  s->transient_pos[ich] = 0;
623  }
624 }
625 
626 static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred)
627 {
628  int i, j, ich, pred_error;
629  int order = s->mclms_order;
630  int num_channels = s->num_channels;
631  int range = 1 << (s->bits_per_sample - 1);
632 
633  for (ich = 0; ich < num_channels; ich++) {
634  pred_error = s->channel_residues[ich][icoef] - (unsigned)pred[ich];
635  if (pred_error > 0) {
636  for (i = 0; i < order * num_channels; i++)
637  s->mclms_coeffs[i + ich * order * num_channels] +=
638  s->mclms_updates[s->mclms_recent + i];
639  for (j = 0; j < ich; j++)
640  s->mclms_coeffs_cur[ich * num_channels + j] += WMASIGN(s->channel_residues[j][icoef]);
641  } else if (pred_error < 0) {
642  for (i = 0; i < order * num_channels; i++)
643  s->mclms_coeffs[i + ich * order * num_channels] -=
644  s->mclms_updates[s->mclms_recent + i];
645  for (j = 0; j < ich; j++)
646  s->mclms_coeffs_cur[ich * num_channels + j] -= WMASIGN(s->channel_residues[j][icoef]);
647  }
648  }
649 
650  for (ich = num_channels - 1; ich >= 0; ich--) {
651  s->mclms_recent--;
652  s->mclms_prevvalues[s->mclms_recent] = av_clip(s->channel_residues[ich][icoef],
653  -range, range - 1);
654  s->mclms_updates[s->mclms_recent] = WMASIGN(s->channel_residues[ich][icoef]);
655  }
656 
657  if (s->mclms_recent == 0) {
658  memcpy(&s->mclms_prevvalues[order * num_channels],
659  s->mclms_prevvalues,
660  sizeof(int32_t) * order * num_channels);
661  memcpy(&s->mclms_updates[order * num_channels],
662  s->mclms_updates,
663  sizeof(int32_t) * order * num_channels);
664  s->mclms_recent = num_channels * order;
665  }
666 }
667 
668 static void mclms_predict(WmallDecodeCtx *s, int icoef, int *pred)
669 {
670  int ich, i;
671  int order = s->mclms_order;
672  int num_channels = s->num_channels;
673 
674  for (ich = 0; ich < num_channels; ich++) {
675  pred[ich] = 0;
676  if (!s->is_channel_coded[ich])
677  continue;
678  for (i = 0; i < order * num_channels; i++)
679  pred[ich] += (uint32_t)s->mclms_prevvalues[i + s->mclms_recent] *
680  s->mclms_coeffs[i + order * num_channels * ich];
681  for (i = 0; i < ich; i++)
682  pred[ich] += (uint32_t)s->channel_residues[i][icoef] *
683  s->mclms_coeffs_cur[i + num_channels * ich];
684  pred[ich] += (1U << s->mclms_scaling) >> 1;
685  pred[ich] >>= s->mclms_scaling;
686  s->channel_residues[ich][icoef] += (unsigned)pred[ich];
687  }
688 }
689 
690 static void revert_mclms(WmallDecodeCtx *s, int tile_size)
691 {
692  int icoef, pred[WMALL_MAX_CHANNELS] = { 0 };
693  for (icoef = 0; icoef < tile_size; icoef++) {
694  mclms_predict(s, icoef, pred);
695  mclms_update(s, icoef, pred);
696  }
697 }
698 
699 static void use_high_update_speed(WmallDecodeCtx *s, int ich)
700 {
701  int ilms, recent, icoef;
702  for (ilms = s->cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
703  recent = s->cdlms[ich][ilms].recent;
704  if (s->update_speed[ich] == 16)
705  continue;
706  if (s->bV3RTM) {
707  for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
708  s->cdlms[ich][ilms].lms_updates[icoef + recent] *= 2;
709  } else {
710  for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
711  s->cdlms[ich][ilms].lms_updates[icoef] *= 2;
712  }
713  }
714  s->update_speed[ich] = 16;
715 }
716 
718 {
719  int ilms, recent, icoef;
720  for (ilms = s->cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
721  recent = s->cdlms[ich][ilms].recent;
722  if (s->update_speed[ich] == 8)
723  continue;
724  if (s->bV3RTM)
725  for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
726  s->cdlms[ich][ilms].lms_updates[icoef + recent] /= 2;
727  else
728  for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++)
729  s->cdlms[ich][ilms].lms_updates[icoef] /= 2;
730  }
731  s->update_speed[ich] = 8;
732 }
733 
734 #define CD_LMS(bits, ROUND) \
735 static void lms_update ## bits (WmallDecodeCtx *s, int ich, int ilms, int input) \
736 { \
737  int recent = s->cdlms[ich][ilms].recent; \
738  int range = 1 << s->bits_per_sample - 1; \
739  int order = s->cdlms[ich][ilms].order; \
740  int ##bits##_t *prev = (int##bits##_t *)s->cdlms[ich][ilms].lms_prevvalues; \
741  \
742  if (recent) \
743  recent--; \
744  else { \
745  memcpy(prev + order, prev, (bits/8) * order); \
746  memcpy(s->cdlms[ich][ilms].lms_updates + order, \
747  s->cdlms[ich][ilms].lms_updates, \
748  sizeof(*s->cdlms[ich][ilms].lms_updates) * order); \
749  recent = order - 1; \
750  } \
751  \
752  prev[recent] = av_clip(input, -range, range - 1); \
753  s->cdlms[ich][ilms].lms_updates[recent] = WMASIGN(input) * s->update_speed[ich]; \
754  \
755  s->cdlms[ich][ilms].lms_updates[recent + (order >> 4)] >>= 2; \
756  s->cdlms[ich][ilms].lms_updates[recent + (order >> 3)] >>= 1; \
757  s->cdlms[ich][ilms].recent = recent; \
758  memset(s->cdlms[ich][ilms].lms_updates + recent + order, 0, \
759  sizeof(s->cdlms[ich][ilms].lms_updates) - \
760  sizeof(*s->cdlms[ich][ilms].lms_updates)*(recent+order)); \
761 } \
762  \
763 static void revert_cdlms ## bits (WmallDecodeCtx *s, int ch, \
764  int coef_begin, int coef_end) \
765 { \
766  int icoef, ilms, num_lms, residue, input; \
767  unsigned pred;\
768  \
769  num_lms = s->cdlms_ttl[ch]; \
770  for (ilms = num_lms - 1; ilms >= 0; ilms--) { \
771  for (icoef = coef_begin; icoef < coef_end; icoef++) { \
772  int##bits##_t *prevvalues = (int##bits##_t *)s->cdlms[ch][ilms].lms_prevvalues; \
773  pred = (1 << s->cdlms[ch][ilms].scaling) >> 1; \
774  residue = s->channel_residues[ch][icoef]; \
775  pred += s->dsp.scalarproduct_and_madd_int## bits (s->cdlms[ch][ilms].coefs, \
776  prevvalues + s->cdlms[ch][ilms].recent, \
777  s->cdlms[ch][ilms].lms_updates + \
778  s->cdlms[ch][ilms].recent, \
779  FFALIGN(s->cdlms[ch][ilms].order, ROUND), \
780  WMASIGN(residue)); \
781  input = residue + (unsigned)((int)pred >> s->cdlms[ch][ilms].scaling); \
782  lms_update ## bits(s, ch, ilms, input); \
783  s->channel_residues[ch][icoef] = input; \
784  } \
785  } \
786 }
787 
789 CD_LMS(32, 8)
790 
791 static void revert_inter_ch_decorr(WmallDecodeCtx *s, int tile_size)
792 {
793  if (s->num_channels != 2)
794  return;
795  else if (s->is_channel_coded[0] || s->is_channel_coded[1]) {
796  int icoef;
797  for (icoef = 0; icoef < tile_size; icoef++) {
798  s->channel_residues[0][icoef] -= (unsigned)(s->channel_residues[1][icoef] >> 1);
799  s->channel_residues[1][icoef] += (unsigned) s->channel_residues[0][icoef];
800  }
801  }
802 }
803 
804 static void revert_acfilter(WmallDecodeCtx *s, int tile_size)
805 {
806  int ich, pred, i, j;
807  int16_t *filter_coeffs = s->acfilter_coeffs;
808  int scaling = s->acfilter_scaling;
809  int order = s->acfilter_order;
810 
811  for (ich = 0; ich < s->num_channels; ich++) {
812  int *prevvalues = s->acfilter_prevvalues[ich];
813  for (i = 0; i < order; i++) {
814  pred = 0;
815  for (j = 0; j < order; j++) {
816  if (i <= j)
817  pred += (uint32_t)filter_coeffs[j] * prevvalues[j - i];
818  else
819  pred += (uint32_t)s->channel_residues[ich][i - j - 1] * filter_coeffs[j];
820  }
821  pred >>= scaling;
822  s->channel_residues[ich][i] += (unsigned)pred;
823  }
824  for (i = order; i < tile_size; i++) {
825  pred = 0;
826  for (j = 0; j < order; j++)
827  pred += (uint32_t)s->channel_residues[ich][i - j - 1] * filter_coeffs[j];
828  pred >>= scaling;
829  s->channel_residues[ich][i] += (unsigned)pred;
830  }
831  for (j = order - 1; j >= 0; j--)
832  if (tile_size <= j) {
833  prevvalues[j] = prevvalues[j - tile_size];
834  }else
835  prevvalues[j] = s->channel_residues[ich][tile_size - j - 1];
836  }
837 }
838 
840 {
841  int offset = s->samples_per_frame;
842  int subframe_len = s->samples_per_frame;
843  int total_samples = s->samples_per_frame * s->num_channels;
844  int i, j, rawpcm_tile, padding_zeroes, res;
845 
846  s->subframe_offset = get_bits_count(&s->gb);
847 
848  /* reset channel context and find the next block offset and size
849  == the next block of the channel with the smallest number of
850  decoded samples */
851  for (i = 0; i < s->num_channels; i++) {
852  if (offset > s->channel[i].decoded_samples) {
853  offset = s->channel[i].decoded_samples;
854  subframe_len =
855  s->channel[i].subframe_len[s->channel[i].cur_subframe];
856  }
857  }
858 
859  /* get a list of all channels that contain the estimated block */
860  s->channels_for_cur_subframe = 0;
861  for (i = 0; i < s->num_channels; i++) {
862  const int cur_subframe = s->channel[i].cur_subframe;
863  /* subtract already processed samples */
864  total_samples -= s->channel[i].decoded_samples;
865 
866  /* and count if there are multiple subframes that match our profile */
867  if (offset == s->channel[i].decoded_samples &&
868  subframe_len == s->channel[i].subframe_len[cur_subframe]) {
869  total_samples -= s->channel[i].subframe_len[cur_subframe];
870  s->channel[i].decoded_samples +=
871  s->channel[i].subframe_len[cur_subframe];
872  s->channel_indexes_for_cur_subframe[s->channels_for_cur_subframe] = i;
873  ++s->channels_for_cur_subframe;
874  }
875  }
876 
877  /* check if the frame will be complete after processing the
878  estimated block */
879  if (!total_samples)
880  s->parsed_all_subframes = 1;
881 
882 
883  s->seekable_tile = get_bits1(&s->gb);
884  if (s->seekable_tile) {
886 
887  s->do_arith_coding = get_bits1(&s->gb);
888  if (s->do_arith_coding) {
889  avpriv_request_sample(s->avctx, "Arithmetic coding");
890  return AVERROR_PATCHWELCOME;
891  }
892  s->do_ac_filter = get_bits1(&s->gb);
893  s->do_inter_ch_decorr = get_bits1(&s->gb);
894  s->do_mclms = get_bits1(&s->gb);
895 
896  if (s->do_ac_filter)
898 
899  if (s->do_mclms)
900  decode_mclms(s);
901 
902  if ((res = decode_cdlms(s)) < 0)
903  return res;
904  s->movave_scaling = get_bits(&s->gb, 3);
905  s->quant_stepsize = get_bits(&s->gb, 8) + 1;
906 
907  reset_codec(s);
908  }
909 
910  rawpcm_tile = get_bits1(&s->gb);
911 
912  if (!rawpcm_tile && !s->cdlms[0][0].order) {
913  av_log(s->avctx, AV_LOG_DEBUG,
914  "Waiting for seekable tile\n");
915  av_frame_unref(s->frame);
916  return -1;
917  }
918 
919 
920  for (i = 0; i < s->num_channels; i++)
921  s->is_channel_coded[i] = 1;
922 
923  if (!rawpcm_tile) {
924  for (i = 0; i < s->num_channels; i++)
925  s->is_channel_coded[i] = get_bits1(&s->gb);
926 
927  if (s->bV3RTM) {
928  // LPC
929  s->do_lpc = get_bits1(&s->gb);
930  if (s->do_lpc) {
931  decode_lpc(s);
932  avpriv_request_sample(s->avctx, "Expect wrong output since "
933  "inverse LPC filter");
934  }
935  } else
936  s->do_lpc = 0;
937  }
938 
939  if (get_bits_left(&s->gb) < 1)
940  return AVERROR_INVALIDDATA;
941 
942  if (get_bits1(&s->gb))
943  padding_zeroes = get_bits(&s->gb, 5);
944  else
945  padding_zeroes = 0;
946 
947  if (rawpcm_tile) {
948  int bits = s->bits_per_sample - padding_zeroes;
949  if (bits <= 0) {
950  av_log(s->avctx, AV_LOG_ERROR,
951  "Invalid number of padding bits in raw PCM tile\n");
952  return AVERROR_INVALIDDATA;
953  }
954  ff_dlog(s->avctx, "RAWPCM %d bits per sample. "
955  "total %d bits, remain=%d\n", bits,
956  bits * s->num_channels * subframe_len, get_bits_count(&s->gb));
957  for (i = 0; i < s->num_channels; i++)
958  for (j = 0; j < subframe_len; j++)
959  s->channel_residues[i][j] = get_sbits_long(&s->gb, bits);
960  } else {
961  if (s->bits_per_sample < padding_zeroes)
962  return AVERROR_INVALIDDATA;
963  for (i = 0; i < s->num_channels; i++) {
964  if (s->is_channel_coded[i]) {
965  decode_channel_residues(s, i, subframe_len);
966  if (s->seekable_tile)
968  else
970  if (s->bits_per_sample > 16)
971  revert_cdlms32(s, i, 0, subframe_len);
972  else
973  revert_cdlms16(s, i, 0, subframe_len);
974  } else {
975  memset(s->channel_residues[i], 0, sizeof(**s->channel_residues) * subframe_len);
976  }
977  }
978 
979  if (s->do_mclms)
980  revert_mclms(s, subframe_len);
981  if (s->do_inter_ch_decorr)
982  revert_inter_ch_decorr(s, subframe_len);
983  if (s->do_ac_filter)
984  revert_acfilter(s, subframe_len);
985 
986  /* Dequantize */
987  if (s->quant_stepsize != 1)
988  for (i = 0; i < s->num_channels; i++)
989  for (j = 0; j < subframe_len; j++)
990  s->channel_residues[i][j] *= (unsigned)s->quant_stepsize;
991  }
992 
993  /* Write to proper output buffer depending on bit-depth */
994  for (i = 0; i < s->channels_for_cur_subframe; i++) {
995  int c = s->channel_indexes_for_cur_subframe[i];
996  int subframe_len = s->channel[c].subframe_len[s->channel[c].cur_subframe];
997 
998  for (j = 0; j < subframe_len; j++) {
999  if (s->bits_per_sample == 16) {
1000  *s->samples_16[c]++ = (int16_t) s->channel_residues[c][j] * (1 << padding_zeroes);
1001  } else {
1002  *s->samples_32[c]++ = s->channel_residues[c][j] * (256U << padding_zeroes);
1003  }
1004  }
1005  }
1006 
1007  /* handled one subframe */
1008  for (i = 0; i < s->channels_for_cur_subframe; i++) {
1009  int c = s->channel_indexes_for_cur_subframe[i];
1010  if (s->channel[c].cur_subframe >= s->channel[c].num_subframes) {
1011  av_log(s->avctx, AV_LOG_ERROR, "broken subframe\n");
1012  return AVERROR_INVALIDDATA;
1013  }
1014  ++s->channel[c].cur_subframe;
1015  }
1016  return 0;
1017 }
1018 
1019 /**
1020  * @brief Decode one WMA frame.
1021  * @param s codec context
1022  * @return 0 if the trailer bit indicates that this is the last frame,
1023  * 1 if there are additional frames
1024  */
1026 {
1027  GetBitContext* gb = &s->gb;
1028  int more_frames = 0, len = 0, i, ret;
1029 
1030  s->frame->nb_samples = s->samples_per_frame;
1031  if ((ret = ff_get_buffer(s->avctx, s->frame, 0)) < 0) {
1032  /* return an error if no frame could be decoded at all */
1033  s->packet_loss = 1;
1034  s->frame->nb_samples = 0;
1035  return ret;
1036  }
1037  for (i = 0; i < s->num_channels; i++) {
1038  s->samples_16[i] = (int16_t *)s->frame->extended_data[i];
1039  s->samples_32[i] = (int32_t *)s->frame->extended_data[i];
1040  }
1041 
1042  /* get frame length */
1043  if (s->len_prefix)
1044  len = get_bits(gb, s->log2_frame_size);
1045 
1046  /* decode tile information */
1047  if ((ret = decode_tilehdr(s))) {
1048  s->packet_loss = 1;
1049  av_frame_unref(s->frame);
1050  return ret;
1051  }
1052 
1053  /* read drc info */
1054  if (s->dynamic_range_compression)
1055  s->drc_gain = get_bits(gb, 8);
1056 
1057  /* no idea what these are for, might be the number of samples
1058  that need to be skipped at the beginning or end of a stream */
1059  if (get_bits1(gb)) {
1060  int av_unused skip;
1061 
1062  /* usually true for the first frame */
1063  if (get_bits1(gb)) {
1064  skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
1065  ff_dlog(s->avctx, "start skip: %i\n", skip);
1066  }
1067 
1068  /* sometimes true for the last frame */
1069  if (get_bits1(gb)) {
1070  skip = get_bits(gb, av_log2(s->samples_per_frame * 2));
1071  ff_dlog(s->avctx, "end skip: %i\n", skip);
1072  s->frame->nb_samples -= skip;
1073  if (s->frame->nb_samples <= 0)
1074  return AVERROR_INVALIDDATA;
1075  }
1076 
1077  }
1078 
1079  /* reset subframe states */
1080  s->parsed_all_subframes = 0;
1081  for (i = 0; i < s->num_channels; i++) {
1082  s->channel[i].decoded_samples = 0;
1083  s->channel[i].cur_subframe = 0;
1084  }
1085 
1086  /* decode all subframes */
1087  while (!s->parsed_all_subframes) {
1088  int decoded_samples = s->channel[0].decoded_samples;
1089  if (decode_subframe(s) < 0) {
1090  s->packet_loss = 1;
1091  if (s->frame->nb_samples)
1092  s->frame->nb_samples = decoded_samples;
1093  return 0;
1094  }
1095  }
1096 
1097  ff_dlog(s->avctx, "Frame done\n");
1098 
1099  s->skip_frame = 0;
1100 
1101  if (s->len_prefix) {
1102  if (len != (get_bits_count(gb) - s->frame_offset) + 2) {
1103  /* FIXME: not sure if this is always an error */
1104  av_log(s->avctx, AV_LOG_ERROR,
1105  "frame[%"PRIu32"] would have to skip %i bits\n",
1106  s->frame_num,
1107  len - (get_bits_count(gb) - s->frame_offset) - 1);
1108  s->packet_loss = 1;
1109  return 0;
1110  }
1111 
1112  /* skip the rest of the frame data */
1113  skip_bits_long(gb, len - (get_bits_count(gb) - s->frame_offset) - 1);
1114  }
1115 
1116  /* decode trailer bit */
1117  more_frames = get_bits1(gb);
1118  ++s->frame_num;
1119  return more_frames;
1120 }
1121 
1122 /**
1123  * @brief Calculate remaining input buffer length.
1124  * @param s codec context
1125  * @param gb bitstream reader context
1126  * @return remaining size in bits
1127  */
1129 {
1130  return s->buf_bit_size - get_bits_count(gb);
1131 }
1132 
1133 /**
1134  * @brief Fill the bit reservoir with a (partial) frame.
1135  * @param s codec context
1136  * @param gb bitstream reader context
1137  * @param len length of the partial frame
1138  * @param append decides whether to reset the buffer or not
1139  */
1140 static void save_bits(WmallDecodeCtx *s, GetBitContext* gb, int len,
1141  int append)
1142 {
1143  int buflen;
1145 
1146  /* when the frame data does not need to be concatenated, the input buffer
1147  is reset and additional bits from the previous frame are copied
1148  and skipped later so that a fast byte copy is possible */
1149 
1150  if (!append) {
1151  s->frame_offset = get_bits_count(gb) & 7;
1152  s->num_saved_bits = s->frame_offset;
1153  init_put_bits(&s->pb, s->frame_data, s->max_frame_size);
1154  }
1155 
1156  buflen = (s->num_saved_bits + len + 8) >> 3;
1157 
1158  if (len <= 0 || buflen > s->max_frame_size) {
1159  avpriv_request_sample(s->avctx, "Too small input buffer");
1160  s->packet_loss = 1;
1161  s->num_saved_bits = 0;
1162  return;
1163  }
1164 
1165  s->num_saved_bits += len;
1166  if (!append) {
1167  ff_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3),
1168  s->num_saved_bits);
1169  } else {
1170  int align = 8 - (get_bits_count(gb) & 7);
1171  align = FFMIN(align, len);
1172  put_bits(&s->pb, align, get_bits(gb, align));
1173  len -= align;
1174  ff_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), len);
1175  }
1176  skip_bits_long(gb, len);
1177 
1178  tmp = s->pb;
1179  flush_put_bits(&tmp);
1180 
1181  init_get_bits(&s->gb, s->frame_data, s->num_saved_bits);
1182  skip_bits(&s->gb, s->frame_offset);
1183 }
1184 
1185 static int decode_packet(AVCodecContext *avctx, AVFrame *rframe,
1186  int *got_frame_ptr, AVPacket* avpkt)
1187 {
1188  WmallDecodeCtx *s = avctx->priv_data;
1189  GetBitContext* gb = &s->pgb;
1190  const uint8_t* buf = avpkt->data;
1191  int buf_size = avpkt->size;
1192  int num_bits_prev_frame, packet_sequence_number, spliced_packet;
1193 
1194  s->frame->nb_samples = 0;
1195 
1196  if (!buf_size) {
1197  s->packet_done = 0;
1198  if (s->num_saved_bits <= get_bits_count(&s->gb))
1199  return 0;
1200  if (!decode_frame(s))
1201  s->num_saved_bits = 0;
1202  } else if (s->packet_done || s->packet_loss) {
1203  s->packet_done = 0;
1204 
1205  s->next_packet_start = buf_size - FFMIN(avctx->block_align, buf_size);
1206  buf_size = FFMIN(avctx->block_align, buf_size);
1207  s->buf_bit_size = buf_size << 3;
1208 
1209  /* parse packet header */
1210  init_get_bits(gb, buf, s->buf_bit_size);
1211  packet_sequence_number = get_bits(gb, 4);
1212  skip_bits(gb, 1); // Skip seekable_frame_in_packet, currently unused
1213  spliced_packet = get_bits1(gb);
1214  if (spliced_packet)
1215  avpriv_request_sample(avctx, "Bitstream splicing");
1216 
1217  /* get number of bits that need to be added to the previous frame */
1218  num_bits_prev_frame = get_bits(gb, s->log2_frame_size);
1219 
1220  /* check for packet loss */
1221  if (!s->packet_loss &&
1222  ((s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) {
1223  s->packet_loss = 1;
1224  av_log(avctx, AV_LOG_ERROR,
1225  "Packet loss detected! seq %"PRIx8" vs %x\n",
1226  s->packet_sequence_number, packet_sequence_number);
1227  }
1228  s->packet_sequence_number = packet_sequence_number;
1229 
1230  if (num_bits_prev_frame > 0) {
1231  int remaining_packet_bits = s->buf_bit_size - get_bits_count(gb);
1232  if (num_bits_prev_frame >= remaining_packet_bits) {
1233  num_bits_prev_frame = remaining_packet_bits;
1234  s->packet_done = 1;
1235  }
1236 
1237  /* Append the previous frame data to the remaining data from the
1238  * previous packet to create a full frame. */
1239  save_bits(s, gb, num_bits_prev_frame, 1);
1240 
1241  /* decode the cross packet frame if it is valid */
1242  if (num_bits_prev_frame < remaining_packet_bits && !s->packet_loss)
1243  decode_frame(s);
1244  } else if (s->num_saved_bits - s->frame_offset) {
1245  ff_dlog(avctx, "ignoring %x previously saved bits\n",
1246  s->num_saved_bits - s->frame_offset);
1247  }
1248 
1249  if (s->packet_loss) {
1250  /* Reset number of saved bits so that the decoder does not start
1251  * to decode incomplete frames in the s->len_prefix == 0 case. */
1252  s->num_saved_bits = 0;
1253  s->packet_loss = 0;
1254  init_put_bits(&s->pb, s->frame_data, s->max_frame_size);
1255  }
1256 
1257  } else {
1258  int frame_size;
1259 
1260  s->buf_bit_size = (avpkt->size - s->next_packet_start) << 3;
1261  init_get_bits(gb, avpkt->data, s->buf_bit_size);
1262  skip_bits(gb, s->packet_offset);
1263 
1264  if (s->len_prefix && remaining_bits(s, gb) > s->log2_frame_size &&
1265  (frame_size = show_bits(gb, s->log2_frame_size)) &&
1266  frame_size <= remaining_bits(s, gb)) {
1267  save_bits(s, gb, frame_size, 0);
1268 
1269  if (!s->packet_loss)
1270  s->packet_done = !decode_frame(s);
1271  } else if (!s->len_prefix
1272  && s->num_saved_bits > get_bits_count(&s->gb)) {
1273  /* when the frames do not have a length prefix, we don't know the
1274  * compressed length of the individual frames however, we know what
1275  * part of a new packet belongs to the previous frame therefore we
1276  * save the incoming packet first, then we append the "previous
1277  * frame" data from the next packet so that we get a buffer that
1278  * only contains full frames */
1279  s->packet_done = !decode_frame(s);
1280  } else {
1281  s->packet_done = 1;
1282  }
1283  }
1284 
1285  if (remaining_bits(s, gb) < 0) {
1286  av_log(avctx, AV_LOG_ERROR, "Overread %d\n", -remaining_bits(s, gb));
1287  s->packet_loss = 1;
1288  }
1289 
1290  if (s->packet_done && !s->packet_loss &&
1291  remaining_bits(s, gb) > 0) {
1292  /* save the rest of the data so that it can be decoded
1293  * with the next packet */
1294  save_bits(s, gb, remaining_bits(s, gb), 0);
1295  }
1296 
1297  *got_frame_ptr = s->frame->nb_samples > 0;
1298  av_frame_move_ref(rframe, s->frame);
1299 
1300  s->packet_offset = get_bits_count(gb) & 7;
1301 
1302  return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3;
1303 }
1304 
1305 static void flush(AVCodecContext *avctx)
1306 {
1307  WmallDecodeCtx *s = avctx->priv_data;
1308  s->packet_loss = 1;
1309  s->packet_done = 0;
1310  s->num_saved_bits = 0;
1311  s->frame_offset = 0;
1312  s->next_packet_start = 0;
1313  s->cdlms[0][0].order = 0;
1314  s->frame->nb_samples = 0;
1315  init_put_bits(&s->pb, s->frame_data, s->max_frame_size);
1316 }
1317 
1319 {
1320  WmallDecodeCtx *s = avctx->priv_data;
1321 
1322  av_frame_free(&s->frame);
1323  av_freep(&s->frame_data);
1324 
1325  return 0;
1326 }
1327 
1329  .p.name = "wmalossless",
1330  CODEC_LONG_NAME("Windows Media Audio Lossless"),
1331  .p.type = AVMEDIA_TYPE_AUDIO,
1332  .p.id = AV_CODEC_ID_WMALOSSLESS,
1333  .priv_data_size = sizeof(WmallDecodeCtx),
1334  .init = decode_init,
1335  .close = decode_close,
1337  .flush = flush,
1338  .p.capabilities =
1339 #if FF_API_SUBFRAMES
1340  AV_CODEC_CAP_SUBFRAMES |
1341 #endif
1343  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
1344  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16P,
1347 };
WmallChannelCtx::num_subframes
uint8_t num_subframes
Definition: wmalosslessdec.c:60
MAX_SUBFRAMES
#define MAX_SUBFRAMES
max number of subframes per channel
Definition: wmalosslessdec.c:42
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:278
WmallDecodeCtx::frame_num
uint32_t frame_num
current frame number (not used for decoding)
Definition: wmalosslessdec.c:107
av_clip
#define av_clip
Definition: common.h:100
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
WmallChannelCtx::cur_subframe
uint8_t cur_subframe
current subframe number
Definition: wmalosslessdec.c:63
WmallChannelCtx::subframe_len
uint16_t subframe_len[MAX_SUBFRAMES]
subframe length in samples
Definition: wmalosslessdec.c:61
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:695
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
WmallChannelCtx::subframe_offsets
uint16_t subframe_offsets[MAX_SUBFRAMES]
subframe positions in the current frame
Definition: wmalosslessdec.c:62
mem_internal.h
WmallDecodeCtx::packet_done
uint8_t packet_done
set when a packet is fully decoded
Definition: wmalosslessdec.c:104
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1050
WmallChannelCtx::transmit_coefs
uint8_t transmit_coefs
Definition: wmalosslessdec.c:59
WmallDecodeCtx::next_packet_start
int next_packet_start
start offset of the next WMA packet in the demuxer packet
Definition: wmalosslessdec.c:97
WmallDecodeCtx::subframe_offset
int subframe_offset
subframe offset in the bit reservoir
Definition: wmalosslessdec.c:102
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:421
WmallDecodeCtx::frame_offset
int frame_offset
frame offset in the bit reservoir
Definition: wmalosslessdec.c:101
WmallDecodeCtx::packet_loss
uint8_t packet_loss
set in case of bitstream error
Definition: wmalosslessdec.c:103
init_put_bits
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
Definition: put_bits.h:62
decode_frame
static int decode_frame(WmallDecodeCtx *s)
Decode one WMA frame.
Definition: wmalosslessdec.c:1025
append
static uint8_t * append(uint8_t *buf, const uint8_t *src, int size)
Definition: mjpeg2jpeg.c:59
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:266
av_unused
#define av_unused
Definition: attributes.h:131
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:160
decode_subframe
static int decode_subframe(WmallDecodeCtx *s)
Definition: wmalosslessdec.c:839
WmallDecodeCtx::mclms_scaling
int8_t mclms_scaling
Definition: wmalosslessdec.c:137
WmallDecodeCtx::cdlms_ttl
int cdlms_ttl[WMALL_MAX_CHANNELS]
Definition: wmalosslessdec.c:158
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
put_bits
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
Definition: j2kenc.c:223
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
WMALL_BLOCK_MAX_SIZE
#define WMALL_BLOCK_MAX_SIZE
maximum block size
Definition: wmalosslessdec.c:49
AVPacket::data
uint8_t * data
Definition: packet.h:520
AV_SAMPLE_FMT_S32P
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition: samplefmt.h:65
WmallDecodeCtx::movave_scaling
int movave_scaling
Definition: wmalosslessdec.c:144
WmallDecodeCtx::channel_indexes_for_cur_subframe
int8_t channel_indexes_for_cur_subframe[WMALL_MAX_CHANNELS]
Definition: wmalosslessdec.c:119
FFCodec
Definition: codec_internal.h:126
decode_cdlms
static int decode_cdlms(WmallDecodeCtx *s)
Definition: wmalosslessdec.c:456
decode_close
static av_cold int decode_close(AVCodecContext *avctx)
Definition: wmalosslessdec.c:1318
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
ff_wmalossless_decoder
const FFCodec ff_wmalossless_decoder
Definition: wmalosslessdec.c:1328
mclms_predict
static void mclms_predict(WmallDecodeCtx *s, int icoef, int *pred)
Definition: wmalosslessdec.c:668
WmallDecodeCtx::update_speed
int update_speed[WMALL_MAX_CHANNELS]
Definition: wmalosslessdec.c:163
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:321
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:514
WmallDecodeCtx::do_lpc
uint8_t do_lpc
Definition: wmalosslessdec.c:129
WmallDecodeCtx::num_saved_bits
int num_saved_bits
saved number of bits
Definition: wmalosslessdec.c:100
decode_mclms
static void decode_mclms(WmallDecodeCtx *s)
Definition: wmalosslessdec.c:433
ff_llauddsp_init
av_cold void ff_llauddsp_init(LLAudDSPContext *c)
Definition: lossless_audiodsp.c:57
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:381
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
WMALL_COEFF_PAD_SIZE
#define WMALL_COEFF_PAD_SIZE
pad coef buffers with 0 for use with SIMD
Definition: wmalosslessdec.c:52
ff_copy_bits
void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
Copy the content of src to the bitstream.
Definition: bitstream.c:49
clear_codec_buffers
static void clear_codec_buffers(WmallDecodeCtx *s)
Definition: wmalosslessdec.c:582
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:130
WmallDecodeCtx::max_frame_size
int max_frame_size
max bitstream size
Definition: wmalosslessdec.c:78
av_ceil_log2
#define av_ceil_log2
Definition: common.h:97
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:1065
WmallDecodeCtx::samples_per_frame
uint16_t samples_per_frame
number of samples to output
Definition: wmalosslessdec.c:86
reset_codec
static void reset_codec(WmallDecodeCtx *s)
Reset filter parameters and transient area at new seekable tile.
Definition: wmalosslessdec.c:611
WmallDecodeCtx::min_samples_per_subframe
uint16_t min_samples_per_subframe
Definition: wmalosslessdec.c:93
WmallChannelCtx::decoded_samples
uint16_t decoded_samples
number of already processed samples
Definition: wmalosslessdec.c:64
GetBitContext
Definition: get_bits.h:108
WmallDecodeCtx::lms_updates
int16_t lms_updates[MAX_ORDER *2+WMALL_COEFF_PAD_SIZE/sizeof(int16_t)]
Definition: wmalosslessdec.c:154
WmallDecodeCtx::do_inter_ch_decorr
uint8_t do_inter_ch_decorr
Definition: wmalosslessdec.c:127
save_bits
static void save_bits(WmallDecodeCtx *s, GetBitContext *gb, int len, int append)
Fill the bit reservoir with a (partial) frame.
Definition: wmalosslessdec.c:1140
remaining_bits
static int remaining_bits(WmallDecodeCtx *s, GetBitContext *gb)
Calculate remaining input buffer length.
Definition: wmalosslessdec.c:1128
WmallDecodeCtx::avctx
AVCodecContext * avctx
Definition: wmalosslessdec.c:74
WmallDecodeCtx::mclms_recent
int mclms_recent
Definition: wmalosslessdec.c:142
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:148
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
WmallDecodeCtx::len_prefix
int len_prefix
frame is prefixed with its length
Definition: wmalosslessdec.c:83
mask
static const uint16_t mask[17]
Definition: lzw.c:38
WmallDecodeCtx::frame
AVFrame * frame
Definition: wmalosslessdec.c:75
WmallDecodeCtx::scaling
int scaling
Definition: wmalosslessdec.c:149
wma_common.h
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:524
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:286
MAX_ORDER
#define MAX_ORDER
Definition: wmalosslessdec.c:45
s
#define s(width, name)
Definition: cbs_vp9.c:198
WmallDecodeCtx::channel_residues
int channel_residues[WMALL_MAX_CHANNELS][WMALL_BLOCK_MAX_SIZE]
Definition: wmalosslessdec.c:171
decode_subframe_length
static int decode_subframe_length(WmallDecodeCtx *s, int offset)
Decode the subframe length.
Definition: wmalosslessdec.c:296
WmallDecodeCtx::lms_prevvalues
int32_t lms_prevvalues[MAX_ORDER *2+WMALL_COEFF_PAD_SIZE/sizeof(int16_t)]
Definition: wmalosslessdec.c:153
frame_size
int frame_size
Definition: mxfenc.c:2424
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
av_channel_layout_from_mask
int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
Definition: channel_layout.c:247
bits
uint8_t bits
Definition: vp3data.h:128
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1575
get_sbits
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:320
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
decode.h
get_bits.h
AV_RL16
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
Definition: bytestream.h:94
LLAudDSPContext
Definition: lossless_audiodsp.h:28
WmallDecodeCtx::lpc_coefs
int lpc_coefs[WMALL_MAX_CHANNELS][40]
Definition: wmalosslessdec.c:173
PutBitContext
Definition: put_bits.h:50
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:271
use_normal_update_speed
static void use_normal_update_speed(WmallDecodeCtx *s, int ich)
Definition: wmalosslessdec.c:717
WmallDecodeCtx::mclms_prevvalues
int32_t mclms_prevvalues[WMALL_MAX_CHANNELS *2 *32]
Definition: wmalosslessdec.c:140
if
if(ret)
Definition: filter_design.txt:179
GetBitContext::buffer
const uint8_t * buffer
Definition: get_bits.h:109
MAX_FRAMESIZE
#define MAX_FRAMESIZE
maximum compressed frame size
Definition: wmalosslessdec.c:44
WmallDecodeCtx::buf_bit_size
int buf_bit_size
buffer size in bits
Definition: wmalosslessdec.c:109
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:64
WmallChannelCtx::transient_counter
int transient_counter
number of transient samples from the beginning of the transient zone
Definition: wmalosslessdec.c:66
AV_CODEC_ID_WMALOSSLESS
@ AV_CODEC_ID_WMALOSSLESS
Definition: codec_id.h:478
WmallDecodeCtx::log2_frame_size
uint16_t log2_frame_size
Definition: wmalosslessdec.c:87
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
WmallDecodeCtx::samples_32
int32_t * samples_32[WMALL_MAX_CHANNELS]
current sample buffer pointer (24-bit)
Definition: wmalosslessdec.c:111
WmallChannelCtx::quant_step
int quant_step
quantization step for the current subframe
Definition: wmalosslessdec.c:65
WmallDecodeCtx::recent
int recent
Definition: wmalosslessdec.c:155
WmallDecodeCtx::bitsend
int bitsend
Definition: wmalosslessdec.c:151
WmallDecodeCtx::mclms_updates
int32_t mclms_updates[WMALL_MAX_CHANNELS *2 *32]
Definition: wmalosslessdec.c:141
WMALL_MAX_CHANNELS
#define WMALL_MAX_CHANNELS
current decoder limitations
Definition: wmalosslessdec.c:41
WmallDecodeCtx::bits_per_sample
uint8_t bits_per_sample
integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1....
Definition: wmalosslessdec.c:85
WmallDecodeCtx::order
int order
Definition: wmalosslessdec.c:148
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
WmallDecodeCtx::packet_offset
uint8_t packet_offset
offset to the frame in the packet
Definition: wmalosslessdec.c:98
WmallDecodeCtx::acfilter_coeffs
int16_t acfilter_coeffs[16]
Definition: wmalosslessdec.c:133
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
decode_tilehdr
static int decode_tilehdr(WmallDecodeCtx *s)
Decode how the data in the frame is split into subframes.
Definition: wmalosslessdec.c:338
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1575
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:366
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
WmallDecodeCtx::bV3RTM
int bV3RTM
Definition: wmalosslessdec.c:160
AVPacket::size
int size
Definition: packet.h:521
codec_internal.h
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:109
WmallDecodeCtx::channels_for_cur_subframe
int8_t channels_for_cur_subframe
number of channels that contain the subframe
Definition: wmalosslessdec.c:118
WmallDecodeCtx::mclms_coeffs
int16_t mclms_coeffs[WMALL_MAX_CHANNELS *WMALL_MAX_CHANNELS *32]
Definition: wmalosslessdec.c:138
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
WmallDecodeCtx::gb
GetBitContext gb
bitstream reader context
Definition: wmalosslessdec.c:108
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1057
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
WmallDecodeCtx::acfilter_prevvalues
int acfilter_prevvalues[WMALL_MAX_CHANNELS][16]
Definition: wmalosslessdec.c:134
WmallDecodeCtx::do_ac_filter
uint8_t do_ac_filter
Definition: wmalosslessdec.c:126
WmallChannelCtx
frame-specific decoder context for a single channel
Definition: wmalosslessdec.c:57
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2464
WmallDecodeCtx::packet_sequence_number
uint8_t packet_sequence_number
current packet number
Definition: wmalosslessdec.c:99
use_high_update_speed
static void use_high_update_speed(WmallDecodeCtx *s, int ich)
Definition: wmalosslessdec.c:699
align
static const uint8_t *BS_FUNC() align(BSCTX *bc)
Skip bits to a byte boundary.
Definition: bitstream_template.h:411
WmallDecodeCtx::samples_16
int16_t * samples_16[WMALL_MAX_CHANNELS]
current sample buffer pointer (16-bit)
Definition: wmalosslessdec.c:110
decode_ac_filter
static void decode_ac_filter(WmallDecodeCtx *s)
Definition: wmalosslessdec.c:423
WmallDecodeCtx::num_channels
int8_t num_channels
number of channels in the stream (same as AVCodecContext.num_channels)
Definition: wmalosslessdec.c:88
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
attributes.h
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:64
WmallDecodeCtx::decode_flags
uint32_t decode_flags
used compression features
Definition: wmalosslessdec.c:82
WmallDecodeCtx::seekable_tile
int seekable_tile
Definition: wmalosslessdec.c:167
WmallDecodeCtx::lpc_scaling
int lpc_scaling
Definition: wmalosslessdec.c:175
mclms_update
static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred)
Definition: wmalosslessdec.c:626
revert_inter_ch_decorr
static void revert_inter_ch_decorr(WmallDecodeCtx *s, int tile_size)
Definition: wmalosslessdec.c:791
WmallDecodeCtx::quant_stepsize
int quant_stepsize
Definition: wmalosslessdec.c:145
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
WmallDecodeCtx::subframe_len
int16_t subframe_len
current subframe length
Definition: wmalosslessdec.c:117
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:523
show_bits
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:371
WmallDecodeCtx::max_subframe_len_bit
uint8_t max_subframe_len_bit
flag indicating that the subframe is of maximum size when the first subframe length bit is 1
Definition: wmalosslessdec.c:92
WmallDecodeCtx::is_channel_coded
int is_channel_coded[WMALL_MAX_CHANNELS]
Definition: wmalosslessdec.c:162
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
WmallDecodeCtx::drc_gain
uint8_t drc_gain
gain for the DRC tool
Definition: wmalosslessdec.c:112
revert_acfilter
static void revert_acfilter(WmallDecodeCtx *s, int tile_size)
Definition: wmalosslessdec.c:804
WmallDecodeCtx::pgb
GetBitContext pgb
bitstream reader context for the packet
Definition: wmalosslessdec.c:96
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:633
AV_STRINGIFY
#define AV_STRINGIFY(s)
Definition: macros.h:66
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:606
WmallDecodeCtx
main decoder context
Definition: wmalosslessdec.c:72
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
WmallDecodeCtx::max_num_subframes
uint8_t max_num_subframes
Definition: wmalosslessdec.c:90
len
int len
Definition: vorbis_enc_data.h:426
WmallDecodeCtx::dsp
LLAudDSPContext dsp
accelerated DSP functions
Definition: wmalosslessdec.c:76
avcodec.h
WmallDecodeCtx::coefsend
int coefsend
Definition: wmalosslessdec.c:150
WmallDecodeCtx::mclms_order
int8_t mclms_order
Definition: wmalosslessdec.c:136
WmallDecodeCtx::skip_frame
int8_t skip_frame
skip output step
Definition: wmalosslessdec.c:113
ret
ret
Definition: filter_design.txt:187
pred
static const float pred[4]
Definition: siprdata.h:259
AVCodecContext::block_align
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
Definition: avcodec.h:1083
WmallDecodeCtx::acfilter_order
int8_t acfilter_order
Definition: wmalosslessdec.c:131
lossless_audiodsp.h
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
U
#define U(x)
Definition: vpx_arith.h:37
WmallDecodeCtx::coefs
int16_t coefs[MAX_ORDER+WMALL_COEFF_PAD_SIZE/sizeof(int16_t)]
Definition: wmalosslessdec.c:152
AVCodecContext
main external API structure.
Definition: avcodec.h:445
WmallDecodeCtx::transient_pos
int transient_pos[WMALL_MAX_CHANNELS]
Definition: wmalosslessdec.c:166
ff_wma_get_frame_len_bits
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.
Definition: wma_common.c:32
revert_mclms
static void revert_mclms(WmallDecodeCtx *s, int tile_size)
Definition: wmalosslessdec.c:690
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:437
decode_init
static av_cold int decode_init(AVCodecContext *avctx)
Definition: wmalosslessdec.c:182
AV_CODEC_CAP_DELAY
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:76
decode_lpc
static void decode_lpc(WmallDecodeCtx *s)
Definition: wmalosslessdec.c:570
decode_channel_residues
static int decode_channel_residues(WmallDecodeCtx *s, int ch, int tile_size)
Definition: wmalosslessdec.c:513
WmallDecodeCtx::mclms_coeffs_cur
int16_t mclms_coeffs_cur[WMALL_MAX_CHANNELS *WMALL_MAX_CHANNELS]
Definition: wmalosslessdec.c:139
WmallDecodeCtx::cdlms
struct WmallDecodeCtx::@275 cdlms[WMALL_MAX_CHANNELS][9]
mem.h
get_bitsz
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
Definition: get_bits.h:351
WmallDecodeCtx::pb
PutBitContext pb
context for filling the frame_data buffer
Definition: wmalosslessdec.c:79
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:36
flush_put_bits
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
Definition: put_bits.h:143
WmallChannelCtx::prev_block_len
int16_t prev_block_len
length of the previous block
Definition: wmalosslessdec.c:58
WmallDecodeCtx::lpc_order
int lpc_order
Definition: wmalosslessdec.c:174
AVPacket
This structure stores compressed data.
Definition: packet.h:497
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
WmallDecodeCtx::do_mclms
uint8_t do_mclms
Definition: wmalosslessdec.c:128
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
decode_packet
static int decode_packet(AVCodecContext *avctx, AVFrame *rframe, int *got_frame_ptr, AVPacket *avpkt)
Definition: wmalosslessdec.c:1185
WMASIGN
#define WMASIGN(x)
Get sign of integer (1 for positive, -1 for negative and 0 for zero)
Definition: wmalosslessdec.c:180
int32_t
int32_t
Definition: audioconvert.c:56
WmallDecodeCtx::acfilter_scaling
int8_t acfilter_scaling
Definition: wmalosslessdec.c:132
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
WmallDecodeCtx::lfe_channel
int8_t lfe_channel
lfe channel index
Definition: wmalosslessdec.c:89
WmallDecodeCtx::ave_sum
unsigned ave_sum[WMALL_MAX_CHANNELS]
Definition: wmalosslessdec.c:169
CD_LMS
#define CD_LMS(bits, ROUND)
Definition: wmalosslessdec.c:734
get_sbits_long
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
Definition: get_bits.h:471
put_bits.h
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
WmallDecodeCtx::subframe_len_bits
uint8_t subframe_len_bits
number of bits used for the subframe length
Definition: wmalosslessdec.c:91
WmallDecodeCtx::do_arith_coding
uint8_t do_arith_coding
Definition: wmalosslessdec.c:125
skip
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
Definition: bitstream_template.h:375
WmallDecodeCtx::lpc_intbits
int lpc_intbits
Definition: wmalosslessdec.c:176
channel
channel
Definition: ebur128.h:39
WmallDecodeCtx::dynamic_range_compression
int dynamic_range_compression
frame contains DRC data
Definition: wmalosslessdec.c:84
flush
static void flush(AVCodecContext *avctx)
Definition: wmalosslessdec.c:1305
WmallDecodeCtx::frame_data
uint8_t * frame_data
compressed frame data
Definition: wmalosslessdec.c:77
WmallDecodeCtx::parsed_all_subframes
int8_t parsed_all_subframes
all subframes decoded?
Definition: wmalosslessdec.c:114