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