FFmpeg
wavpack.c
Go to the documentation of this file.
1 /*
2  * WavPack lossless audio decoder
3  * Copyright (c) 2006,2011 Konstantin Shishkov
4  * Copyright (c) 2020 David Bryant
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with FFmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include "libavutil/buffer.h"
25 
26 #define BITSTREAM_READER_LE
27 #include "avcodec.h"
28 #include "bytestream.h"
29 #include "codec_internal.h"
30 #include "get_bits.h"
31 #include "refstruct.h"
32 #include "thread.h"
33 #include "threadframe.h"
34 #include "unary.h"
35 #include "wavpack.h"
36 #include "dsd.h"
37 
38 /**
39  * @file
40  * WavPack lossless audio decoder
41  */
42 
43 #define DSD_BYTE_READY(low,high) (!(((low) ^ (high)) & 0xff000000))
44 
45 #define PTABLE_BITS 8
46 #define PTABLE_BINS (1<<PTABLE_BITS)
47 #define PTABLE_MASK (PTABLE_BINS-1)
48 
49 #define UP 0x010000fe
50 #define DOWN 0x00010000
51 #define DECAY 8
52 
53 #define PRECISION 20
54 #define VALUE_ONE (1 << PRECISION)
55 #define PRECISION_USE 12
56 
57 #define RATE_S 20
58 
59 #define MAX_HISTORY_BITS 5
60 #define MAX_HISTORY_BINS (1 << MAX_HISTORY_BITS)
61 #define MAX_BIN_BYTES 1280 // for value_lookup, per bin (2k - 512 - 256)
62 
63 typedef enum {
64  MODULATION_PCM, // pulse code modulation
65  MODULATION_DSD // pulse density modulation (aka DSD)
66 } Modulation;
67 
68 typedef struct WavpackFrameContext {
72  int joint;
73  uint32_t CRC;
76  uint32_t crc_extra_bits;
78  int samples;
79  int terms;
81  int zero, one, zeroes;
83  int and, or, shift;
91 
99 
100 typedef struct WavpackContext {
102 
104  int fdec_num;
105 
106  int block;
107  int samples;
109 
113 
114  DSDContext *dsdctx; ///< RefStruct reference
117 
118 #define LEVEL_DECAY(a) (((a) + 0x80) >> 8)
119 
120 static av_always_inline unsigned get_tail(GetBitContext *gb, unsigned k)
121 {
122  int p, e, res;
123 
124  if (k < 1)
125  return 0;
126  p = av_log2(k);
127  e = (1LL << (p + 1)) - k - 1;
128  res = get_bits_long(gb, p);
129  if (res >= e)
130  res = res * 2U - e + get_bits1(gb);
131  return res;
132 }
133 
135 {
136  int i, br[2], sl[2];
137 
138  for (i = 0; i <= ctx->stereo_in; i++) {
139  if (ctx->ch[i].bitrate_acc > UINT_MAX - ctx->ch[i].bitrate_delta)
140  return AVERROR_INVALIDDATA;
141  ctx->ch[i].bitrate_acc += ctx->ch[i].bitrate_delta;
142  br[i] = ctx->ch[i].bitrate_acc >> 16;
143  sl[i] = LEVEL_DECAY(ctx->ch[i].slow_level);
144  }
145  if (ctx->stereo_in && ctx->hybrid_bitrate) {
146  int balance = (sl[1] - sl[0] + br[1] + 1) >> 1;
147  if (balance > br[0]) {
148  br[1] = br[0] * 2;
149  br[0] = 0;
150  } else if (-balance > br[0]) {
151  br[0] *= 2;
152  br[1] = 0;
153  } else {
154  br[1] = br[0] + balance;
155  br[0] = br[0] - balance;
156  }
157  }
158  for (i = 0; i <= ctx->stereo_in; i++) {
159  if (ctx->hybrid_bitrate) {
160  if (sl[i] - br[i] > -0x100)
161  ctx->ch[i].error_limit = wp_exp2(sl[i] - br[i] + 0x100);
162  else
163  ctx->ch[i].error_limit = 0;
164  } else {
165  ctx->ch[i].error_limit = wp_exp2(br[i]);
166  }
167  }
168 
169  return 0;
170 }
171 
173  int channel, int *last)
174 {
175  int t, t2;
176  int sign, base, add, ret;
177  WvChannel *c = &ctx->ch[channel];
178 
179  *last = 0;
180 
181  if ((ctx->ch[0].median[0] < 2U) && (ctx->ch[1].median[0] < 2U) &&
182  !ctx->zero && !ctx->one) {
183  if (ctx->zeroes) {
184  ctx->zeroes--;
185  if (ctx->zeroes) {
186  c->slow_level -= LEVEL_DECAY(c->slow_level);
187  return 0;
188  }
189  } else {
190  t = get_unary_0_33(gb);
191  if (t >= 2) {
192  if (t >= 32 || get_bits_left(gb) < t - 1)
193  goto error;
194  t = get_bits_long(gb, t - 1) | (1 << (t - 1));
195  } else {
196  if (get_bits_left(gb) < 0)
197  goto error;
198  }
199  ctx->zeroes = t;
200  if (ctx->zeroes) {
201  memset(ctx->ch[0].median, 0, sizeof(ctx->ch[0].median));
202  memset(ctx->ch[1].median, 0, sizeof(ctx->ch[1].median));
203  c->slow_level -= LEVEL_DECAY(c->slow_level);
204  return 0;
205  }
206  }
207  }
208 
209  if (ctx->zero) {
210  t = 0;
211  ctx->zero = 0;
212  } else {
213  t = get_unary_0_33(gb);
214  if (get_bits_left(gb) < 0)
215  goto error;
216  if (t == 16) {
217  t2 = get_unary_0_33(gb);
218  if (t2 < 2) {
219  if (get_bits_left(gb) < 0)
220  goto error;
221  t += t2;
222  } else {
223  if (t2 >= 32 || get_bits_left(gb) < t2 - 1)
224  goto error;
225  t += get_bits_long(gb, t2 - 1) | (1 << (t2 - 1));
226  }
227  }
228 
229  if (ctx->one) {
230  ctx->one = t & 1;
231  t = (t >> 1) + 1;
232  } else {
233  ctx->one = t & 1;
234  t >>= 1;
235  }
236  ctx->zero = !ctx->one;
237  }
238 
239  if (ctx->hybrid && !channel) {
240  if (update_error_limit(ctx) < 0)
241  goto error;
242  }
243 
244  if (!t) {
245  base = 0;
246  add = GET_MED(0) - 1;
247  DEC_MED(0);
248  } else if (t == 1) {
249  base = GET_MED(0);
250  add = GET_MED(1) - 1;
251  INC_MED(0);
252  DEC_MED(1);
253  } else if (t == 2) {
254  base = GET_MED(0) + GET_MED(1);
255  add = GET_MED(2) - 1;
256  INC_MED(0);
257  INC_MED(1);
258  DEC_MED(2);
259  } else {
260  base = GET_MED(0) + GET_MED(1) + GET_MED(2) * (t - 2U);
261  add = GET_MED(2) - 1;
262  INC_MED(0);
263  INC_MED(1);
264  INC_MED(2);
265  }
266  if (!c->error_limit) {
267  ret = base + get_tail(gb, add);
268  if (get_bits_left(gb) <= 0)
269  goto error;
270  } else {
271  int mid = (base * 2U + add + 1) >> 1;
272  while (add > c->error_limit) {
273  if (get_bits_left(gb) <= 0)
274  goto error;
275  if (get_bits1(gb)) {
276  add -= (mid - (unsigned)base);
277  base = mid;
278  } else
279  add = mid - (unsigned)base - 1;
280  mid = (base * 2U + add + 1) >> 1;
281  }
282  ret = mid;
283  }
284  sign = get_bits1(gb);
285  if (ctx->hybrid_bitrate)
286  c->slow_level += wp_log2(ret) - LEVEL_DECAY(c->slow_level);
287  return sign ? ~ret : ret;
288 
289 error:
290  ret = get_bits_left(gb);
291  if (ret <= 0) {
292  av_log(ctx->avctx, AV_LOG_ERROR, "Too few bits (%d) left\n", ret);
293  }
294  *last = 1;
295  return 0;
296 }
297 
298 static inline int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc,
299  unsigned S)
300 {
301  unsigned bit;
302 
303  if (s->extra_bits) {
304  S *= 1 << s->extra_bits;
305 
306  if (s->got_extra_bits &&
307  get_bits_left(&s->gb_extra_bits) >= s->extra_bits) {
308  S |= get_bits_long(&s->gb_extra_bits, s->extra_bits);
309  *crc = *crc * 9 + (S & 0xffff) * 3 + ((unsigned)S >> 16);
310  }
311  }
312 
313  bit = (S & s->and) | s->or;
314  bit = ((S + bit) << s->shift) - bit;
315 
316  if (s->hybrid)
317  bit = av_clip(bit, s->hybrid_minclip, s->hybrid_maxclip);
318 
319  return bit << s->post_shift;
320 }
321 
322 static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S)
323 {
324  union {
325  float f;
326  uint32_t u;
327  } value;
328 
329  unsigned int sign;
330  int exp = s->float_max_exp;
331 
332  if (s->got_extra_bits) {
333  const int max_bits = 1 + 23 + 8 + 1;
334  const int left_bits = get_bits_left(&s->gb_extra_bits);
335 
336  if (left_bits + 8 * AV_INPUT_BUFFER_PADDING_SIZE < max_bits)
337  return 0.0;
338  }
339 
340  if (S) {
341  S *= 1U << s->float_shift;
342  sign = S < 0;
343  if (sign)
344  S = -(unsigned)S;
345  if (S >= 0x1000000U) {
346  if (s->got_extra_bits && get_bits1(&s->gb_extra_bits))
347  S = get_bits(&s->gb_extra_bits, 23);
348  else
349  S = 0;
350  exp = 255;
351  } else if (exp) {
352  int shift = 23 - av_log2(S);
353  exp = s->float_max_exp;
354  if (exp <= shift)
355  shift = --exp;
356  exp -= shift;
357 
358  if (shift) {
359  S <<= shift;
360  if ((s->float_flag & WV_FLT_SHIFT_ONES) ||
361  (s->got_extra_bits &&
362  (s->float_flag & WV_FLT_SHIFT_SAME) &&
363  get_bits1(&s->gb_extra_bits))) {
364  S |= (1 << shift) - 1;
365  } else if (s->got_extra_bits &&
366  (s->float_flag & WV_FLT_SHIFT_SENT)) {
367  S |= get_bits(&s->gb_extra_bits, shift);
368  }
369  }
370  } else {
371  exp = s->float_max_exp;
372  }
373  S &= 0x7fffff;
374  } else {
375  sign = 0;
376  exp = 0;
377  if (s->got_extra_bits && (s->float_flag & WV_FLT_ZERO_SENT)) {
378  if (get_bits1(&s->gb_extra_bits)) {
379  S = get_bits(&s->gb_extra_bits, 23);
380  if (s->float_max_exp >= 25)
381  exp = get_bits(&s->gb_extra_bits, 8);
382  sign = get_bits1(&s->gb_extra_bits);
383  } else {
384  if (s->float_flag & WV_FLT_ZERO_SIGN)
385  sign = get_bits1(&s->gb_extra_bits);
386  }
387  }
388  }
389 
390  *crc = *crc * 27 + S * 9 + exp * 3 + sign;
391 
392  value.u = (sign << 31) | (exp << 23) | S;
393  return value.f;
394 }
395 
396 static inline int wv_check_crc(WavpackFrameContext *s, uint32_t crc,
397  uint32_t crc_extra_bits)
398 {
399  if (crc != s->CRC) {
400  av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
401  return AVERROR_INVALIDDATA;
402  }
403  if (s->got_extra_bits && crc_extra_bits != s->crc_extra_bits) {
404  av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
405  return AVERROR_INVALIDDATA;
406  }
407 
408  return 0;
409 }
410 
411 static void init_ptable(int *table, int rate_i, int rate_s)
412 {
413  int value = 0x808000, rate = rate_i << 8;
414 
415  for (int c = (rate + 128) >> 8; c--;)
416  value += (DOWN - value) >> DECAY;
417 
418  for (int i = 0; i < PTABLE_BINS/2; i++) {
419  table[i] = value;
420  table[PTABLE_BINS-1-i] = 0x100ffff - value;
421 
422  if (value > 0x010000) {
423  rate += (rate * rate_s + 128) >> 8;
424 
425  for (int c = (rate + 64) >> 7; c--;)
426  value += (DOWN - value) >> DECAY;
427  }
428  }
429 }
430 
431 typedef struct {
432  int32_t value, fltr0, fltr1, fltr2, fltr3, fltr4, fltr5, fltr6, factor;
433  unsigned int byte;
434 } DSDfilters;
435 
436 static int wv_unpack_dsd_high(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
437 {
438  uint32_t checksum = 0xFFFFFFFF;
439  uint8_t *dst_l = dst_left, *dst_r = dst_right;
440  int total_samples = s->samples, stereo = dst_r ? 1 : 0;
441  DSDfilters filters[2], *sp = filters;
442  int rate_i, rate_s;
443  uint32_t low, high, value;
444 
445  if (bytestream2_get_bytes_left(&s->gbyte) < (stereo ? 20 : 13))
446  return AVERROR_INVALIDDATA;
447 
448  rate_i = bytestream2_get_byte(&s->gbyte);
449  rate_s = bytestream2_get_byte(&s->gbyte);
450 
451  if (rate_s != RATE_S)
452  return AVERROR_INVALIDDATA;
453 
454  init_ptable(s->ptable, rate_i, rate_s);
455 
456  for (int channel = 0; channel < stereo + 1; channel++) {
458 
459  sp->fltr1 = bytestream2_get_byte(&s->gbyte) << (PRECISION - 8);
460  sp->fltr2 = bytestream2_get_byte(&s->gbyte) << (PRECISION - 8);
461  sp->fltr3 = bytestream2_get_byte(&s->gbyte) << (PRECISION - 8);
462  sp->fltr4 = bytestream2_get_byte(&s->gbyte) << (PRECISION - 8);
463  sp->fltr5 = bytestream2_get_byte(&s->gbyte) << (PRECISION - 8);
464  sp->fltr6 = 0;
465  sp->factor = bytestream2_get_byte(&s->gbyte) & 0xff;
466  sp->factor |= (bytestream2_get_byte(&s->gbyte) << 8) & 0xff00;
467  sp->factor = (int32_t)((uint32_t)sp->factor << 16) >> 16;
468  }
469 
470  value = bytestream2_get_be32(&s->gbyte);
471  high = 0xffffffff;
472  low = 0x0;
473 
474  while (total_samples--) {
475  int bitcount = 8;
476 
477  sp[0].value = sp[0].fltr1 - sp[0].fltr5 + ((sp[0].fltr6 * sp[0].factor) >> 2);
478 
479  if (stereo)
480  sp[1].value = sp[1].fltr1 - sp[1].fltr5 + ((sp[1].fltr6 * sp[1].factor) >> 2);
481 
482  while (bitcount--) {
483  int32_t *pp = s->ptable + ((sp[0].value >> (PRECISION - PRECISION_USE)) & PTABLE_MASK);
484  uint32_t split = low + ((high - low) >> 8) * (*pp >> 16);
485 
486  if (value <= split) {
487  high = split;
488  *pp += (UP - *pp) >> DECAY;
489  sp[0].fltr0 = -1;
490  } else {
491  low = split + 1;
492  *pp += (DOWN - *pp) >> DECAY;
493  sp[0].fltr0 = 0;
494  }
495 
496  if (DSD_BYTE_READY(high, low) && !bytestream2_get_bytes_left(&s->gbyte))
497  return AVERROR_INVALIDDATA;
498  while (DSD_BYTE_READY(high, low) && bytestream2_get_bytes_left(&s->gbyte)) {
499  value = (value << 8) | bytestream2_get_byte(&s->gbyte);
500  high = (high << 8) | 0xff;
501  low <<= 8;
502  }
503 
504  sp[0].value += sp[0].fltr6 * 8;
505  sp[0].byte = (sp[0].byte << 1) | (sp[0].fltr0 & 1);
506  sp[0].factor += (((sp[0].value ^ sp[0].fltr0) >> 31) | 1) &
507  ((sp[0].value ^ (sp[0].value - (sp[0].fltr6 * 16))) >> 31);
508  sp[0].fltr1 += ((sp[0].fltr0 & VALUE_ONE) - sp[0].fltr1) >> 6;
509  sp[0].fltr2 += ((sp[0].fltr0 & VALUE_ONE) - sp[0].fltr2) >> 4;
510  sp[0].fltr3 += (sp[0].fltr2 - sp[0].fltr3) >> 4;
511  sp[0].fltr4 += (sp[0].fltr3 - sp[0].fltr4) >> 4;
512  sp[0].value = (sp[0].fltr4 - sp[0].fltr5) >> 4;
513  sp[0].fltr5 += sp[0].value;
514  sp[0].fltr6 += (sp[0].value - sp[0].fltr6) >> 3;
515  sp[0].value = sp[0].fltr1 - sp[0].fltr5 + ((sp[0].fltr6 * sp[0].factor) >> 2);
516 
517  if (!stereo)
518  continue;
519 
520  pp = s->ptable + ((sp[1].value >> (PRECISION - PRECISION_USE)) & PTABLE_MASK);
521  split = low + ((high - low) >> 8) * (*pp >> 16);
522 
523  if (value <= split) {
524  high = split;
525  *pp += (UP - *pp) >> DECAY;
526  sp[1].fltr0 = -1;
527  } else {
528  low = split + 1;
529  *pp += (DOWN - *pp) >> DECAY;
530  sp[1].fltr0 = 0;
531  }
532 
533  if (DSD_BYTE_READY(high, low) && !bytestream2_get_bytes_left(&s->gbyte))
534  return AVERROR_INVALIDDATA;
535  while (DSD_BYTE_READY(high, low) && bytestream2_get_bytes_left(&s->gbyte)) {
536  value = (value << 8) | bytestream2_get_byte(&s->gbyte);
537  high = (high << 8) | 0xff;
538  low <<= 8;
539  }
540 
541  sp[1].value += sp[1].fltr6 * 8;
542  sp[1].byte = (sp[1].byte << 1) | (sp[1].fltr0 & 1);
543  sp[1].factor += (((sp[1].value ^ sp[1].fltr0) >> 31) | 1) &
544  ((sp[1].value ^ (sp[1].value - (sp[1].fltr6 * 16))) >> 31);
545  sp[1].fltr1 += ((sp[1].fltr0 & VALUE_ONE) - sp[1].fltr1) >> 6;
546  sp[1].fltr2 += ((sp[1].fltr0 & VALUE_ONE) - sp[1].fltr2) >> 4;
547  sp[1].fltr3 += (sp[1].fltr2 - sp[1].fltr3) >> 4;
548  sp[1].fltr4 += (sp[1].fltr3 - sp[1].fltr4) >> 4;
549  sp[1].value = (sp[1].fltr4 - sp[1].fltr5) >> 4;
550  sp[1].fltr5 += sp[1].value;
551  sp[1].fltr6 += (sp[1].value - sp[1].fltr6) >> 3;
552  sp[1].value = sp[1].fltr1 - sp[1].fltr5 + ((sp[1].fltr6 * sp[1].factor) >> 2);
553  }
554 
555  checksum += (checksum << 1) + (*dst_l = sp[0].byte & 0xff);
556  sp[0].factor -= (sp[0].factor + 512) >> 10;
557  dst_l += 4;
558 
559  if (stereo) {
560  checksum += (checksum << 1) + (*dst_r = filters[1].byte & 0xff);
561  filters[1].factor -= (filters[1].factor + 512) >> 10;
562  dst_r += 4;
563  }
564  }
565 
566  if (wv_check_crc(s, checksum, 0)) {
567  if (s->avctx->err_recognition & AV_EF_CRCCHECK)
568  return AVERROR_INVALIDDATA;
569 
570  memset(dst_left, 0x69, s->samples * 4);
571 
572  if (dst_r)
573  memset(dst_right, 0x69, s->samples * 4);
574  }
575 
576  return 0;
577 }
578 
579 static int wv_unpack_dsd_fast(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
580 {
581  uint8_t *dst_l = dst_left, *dst_r = dst_right;
582  uint8_t history_bits, max_probability;
583  int total_summed_probabilities = 0;
584  int total_samples = s->samples;
585  uint8_t *vlb = s->value_lookup_buffer;
586  int history_bins, p0, p1, chan;
587  uint32_t checksum = 0xFFFFFFFF;
588  uint32_t low, high, value;
589 
590  if (!bytestream2_get_bytes_left(&s->gbyte))
591  return AVERROR_INVALIDDATA;
592 
593  history_bits = bytestream2_get_byte(&s->gbyte);
594 
595  if (!bytestream2_get_bytes_left(&s->gbyte) || history_bits > MAX_HISTORY_BITS)
596  return AVERROR_INVALIDDATA;
597 
598  history_bins = 1 << history_bits;
599  max_probability = bytestream2_get_byte(&s->gbyte);
600 
601  if (max_probability < 0xff) {
602  uint8_t *outptr = (uint8_t *)s->probabilities;
603  uint8_t *outend = outptr + sizeof(*s->probabilities) * history_bins;
604 
605  while (outptr < outend && bytestream2_get_bytes_left(&s->gbyte)) {
606  int code = bytestream2_get_byte(&s->gbyte);
607 
608  if (code > max_probability) {
609  int zcount = code - max_probability;
610 
611  while (outptr < outend && zcount--)
612  *outptr++ = 0;
613  } else if (code) {
614  *outptr++ = code;
615  }
616  else {
617  break;
618  }
619  }
620 
621  if (outptr < outend ||
622  (bytestream2_get_bytes_left(&s->gbyte) && bytestream2_get_byte(&s->gbyte)))
623  return AVERROR_INVALIDDATA;
624  } else if (bytestream2_get_bytes_left(&s->gbyte) > (int)sizeof(*s->probabilities) * history_bins) {
625  bytestream2_get_buffer(&s->gbyte, (uint8_t *)s->probabilities,
626  sizeof(*s->probabilities) * history_bins);
627  } else {
628  return AVERROR_INVALIDDATA;
629  }
630 
631  for (p0 = 0; p0 < history_bins; p0++) {
632  int32_t sum_values = 0;
633 
634  for (int i = 0; i < 256; i++)
635  s->summed_probabilities[p0][i] = sum_values += s->probabilities[p0][i];
636 
637  if (sum_values) {
638  total_summed_probabilities += sum_values;
639 
640  if (total_summed_probabilities > history_bins * MAX_BIN_BYTES)
641  return AVERROR_INVALIDDATA;
642 
643  s->value_lookup[p0] = vlb;
644 
645  for (int i = 0; i < 256; i++) {
646  int c = s->probabilities[p0][i];
647 
648  while (c--)
649  *vlb++ = i;
650  }
651  }
652  }
653 
654  if (bytestream2_get_bytes_left(&s->gbyte) < 4)
655  return AVERROR_INVALIDDATA;
656 
657  chan = p0 = p1 = 0;
658  low = 0; high = 0xffffffff;
659  value = bytestream2_get_be32(&s->gbyte);
660 
661  if (dst_r)
662  total_samples *= 2;
663 
664  while (total_samples--) {
665  unsigned int mult, index, code;
666 
667  if (!s->summed_probabilities[p0][255])
668  return AVERROR_INVALIDDATA;
669 
670  mult = (high - low) / s->summed_probabilities[p0][255];
671 
672  if (!mult) {
673  if (bytestream2_get_bytes_left(&s->gbyte) >= 4)
674  value = bytestream2_get_be32(&s->gbyte);
675 
676  low = 0;
677  high = 0xffffffff;
678  mult = high / s->summed_probabilities[p0][255];
679 
680  if (!mult)
681  return AVERROR_INVALIDDATA;
682  }
683 
684  index = (value - low) / mult;
685 
686  if (index >= s->summed_probabilities[p0][255])
687  return AVERROR_INVALIDDATA;
688 
689  if (!dst_r) {
690  if ((*dst_l = code = s->value_lookup[p0][index]))
691  low += s->summed_probabilities[p0][code-1] * mult;
692 
693  dst_l += 4;
694  } else {
695  if ((code = s->value_lookup[p0][index]))
696  low += s->summed_probabilities[p0][code-1] * mult;
697 
698  if (chan) {
699  *dst_r = code;
700  dst_r += 4;
701  }
702  else {
703  *dst_l = code;
704  dst_l += 4;
705  }
706 
707  chan ^= 1;
708  }
709 
710  high = low + s->probabilities[p0][code] * mult - 1;
711  checksum += (checksum << 1) + code;
712 
713  if (!dst_r) {
714  p0 = code & (history_bins-1);
715  } else {
716  p0 = p1;
717  p1 = code & (history_bins-1);
718  }
719 
720  while (DSD_BYTE_READY(high, low) && bytestream2_get_bytes_left(&s->gbyte)) {
721  value = (value << 8) | bytestream2_get_byte(&s->gbyte);
722  high = (high << 8) | 0xff;
723  low <<= 8;
724  }
725  }
726 
727  if (wv_check_crc(s, checksum, 0)) {
728  if (s->avctx->err_recognition & AV_EF_CRCCHECK)
729  return AVERROR_INVALIDDATA;
730 
731  memset(dst_left, 0x69, s->samples * 4);
732 
733  if (dst_r)
734  memset(dst_right, 0x69, s->samples * 4);
735  }
736 
737  return 0;
738 }
739 
740 static int wv_unpack_dsd_copy(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
741 {
742  uint8_t *dst_l = dst_left, *dst_r = dst_right;
743  int total_samples = s->samples;
744  uint32_t checksum = 0xFFFFFFFF;
745 
746  if (bytestream2_get_bytes_left(&s->gbyte) != total_samples * (dst_r ? 2 : 1))
747  return AVERROR_INVALIDDATA;
748 
749  while (total_samples--) {
750  checksum += (checksum << 1) + (*dst_l = bytestream2_get_byte(&s->gbyte));
751  dst_l += 4;
752 
753  if (dst_r) {
754  checksum += (checksum << 1) + (*dst_r = bytestream2_get_byte(&s->gbyte));
755  dst_r += 4;
756  }
757  }
758 
759  if (wv_check_crc(s, checksum, 0)) {
760  if (s->avctx->err_recognition & AV_EF_CRCCHECK)
761  return AVERROR_INVALIDDATA;
762 
763  memset(dst_left, 0x69, s->samples * 4);
764 
765  if (dst_r)
766  memset(dst_right, 0x69, s->samples * 4);
767  }
768 
769  return 0;
770 }
771 
773  void *dst_l, void *dst_r, const int type)
774 {
775  int i, j, count = 0;
776  int last, t;
777  int A, B, L, L2, R, R2;
778  int pos = 0;
779  uint32_t crc = 0xFFFFFFFF;
780  uint32_t crc_extra_bits = 0xFFFFFFFF;
781  int16_t *dst16_l = dst_l;
782  int16_t *dst16_r = dst_r;
783  int32_t *dst32_l = dst_l;
784  int32_t *dst32_r = dst_r;
785  float *dstfl_l = dst_l;
786  float *dstfl_r = dst_r;
787 
788  s->one = s->zero = s->zeroes = 0;
789  do {
790  L = wv_get_value(s, gb, 0, &last);
791  if (last)
792  break;
793  R = wv_get_value(s, gb, 1, &last);
794  if (last)
795  break;
796  for (i = 0; i < s->terms; i++) {
797  Decorr *decorr = &s->decorr[i];
798 
799  t = decorr->value;
800  if (t > 0) {
801  if (t > 8) {
802  if (t & 1) {
803  A = 2U * decorr->samplesA[0] - decorr->samplesA[1];
804  B = 2U * decorr->samplesB[0] - decorr->samplesB[1];
805  } else {
806  A = (int)(3U * decorr->samplesA[0] - decorr->samplesA[1]) >> 1;
807  B = (int)(3U * decorr->samplesB[0] - decorr->samplesB[1]) >> 1;
808  }
809  decorr->samplesA[1] = decorr->samplesA[0];
810  decorr->samplesB[1] = decorr->samplesB[0];
811  j = 0;
812  } else {
813  A = decorr->samplesA[pos];
814  B = decorr->samplesB[pos];
815  j = (pos + t) & 7;
816  }
817  if (type != AV_SAMPLE_FMT_S16P) {
818  L2 = L + ((decorr->weightA * (int64_t)A + 512) >> 10);
819  R2 = R + ((decorr->weightB * (int64_t)B + 512) >> 10);
820  } else {
821  L2 = L + (unsigned)((int)(decorr->weightA * (unsigned)A + 512) >> 10);
822  R2 = R + (unsigned)((int)(decorr->weightB * (unsigned)B + 512) >> 10);
823  }
824  if (A && L)
825  decorr->weightA -= ((((L ^ A) >> 30) & 2) - 1) * decorr->delta;
826  if (B && R)
827  decorr->weightB -= ((((R ^ B) >> 30) & 2) - 1) * decorr->delta;
828  decorr->samplesA[j] = L = L2;
829  decorr->samplesB[j] = R = R2;
830  } else if (t == -1) {
831  if (type != AV_SAMPLE_FMT_S16P)
832  L2 = L + ((decorr->weightA * (int64_t)decorr->samplesA[0] + 512) >> 10);
833  else
834  L2 = L + (unsigned)((int)(decorr->weightA * (unsigned)decorr->samplesA[0] + 512) >> 10);
835  UPDATE_WEIGHT_CLIP(decorr->weightA, decorr->delta, decorr->samplesA[0], L);
836  L = L2;
837  if (type != AV_SAMPLE_FMT_S16P)
838  R2 = R + ((decorr->weightB * (int64_t)L2 + 512) >> 10);
839  else
840  R2 = R + (unsigned)((int)(decorr->weightB * (unsigned)L2 + 512) >> 10);
841  UPDATE_WEIGHT_CLIP(decorr->weightB, decorr->delta, L2, R);
842  R = R2;
843  decorr->samplesA[0] = R;
844  } else {
845  if (type != AV_SAMPLE_FMT_S16P)
846  R2 = R + ((decorr->weightB * (int64_t)decorr->samplesB[0] + 512) >> 10);
847  else
848  R2 = R + (unsigned)((int)(decorr->weightB * (unsigned)decorr->samplesB[0] + 512) >> 10);
849  UPDATE_WEIGHT_CLIP(decorr->weightB, decorr->delta, decorr->samplesB[0], R);
850  R = R2;
851 
852  if (t == -3) {
853  R2 = decorr->samplesA[0];
854  decorr->samplesA[0] = R;
855  }
856 
857  if (type != AV_SAMPLE_FMT_S16P)
858  L2 = L + ((decorr->weightA * (int64_t)R2 + 512) >> 10);
859  else
860  L2 = L + (unsigned)((int)(decorr->weightA * (unsigned)R2 + 512) >> 10);
861  UPDATE_WEIGHT_CLIP(decorr->weightA, decorr->delta, R2, L);
862  L = L2;
863  decorr->samplesB[0] = L;
864  }
865  }
866 
867  if (type == AV_SAMPLE_FMT_S16P) {
868  if (FFABS((int64_t)L) + FFABS((int64_t)R) > (1<<19)) {
869  av_log(s->avctx, AV_LOG_ERROR, "sample %d %d too large\n", L, R);
870  return AVERROR_INVALIDDATA;
871  }
872  }
873 
874  pos = (pos + 1) & 7;
875  if (s->joint)
876  L += (unsigned)(R -= (unsigned)(L >> 1));
877  crc = (crc * 3 + L) * 3 + R;
878 
879  if (type == AV_SAMPLE_FMT_FLTP) {
880  *dstfl_l++ = wv_get_value_float(s, &crc_extra_bits, L);
881  *dstfl_r++ = wv_get_value_float(s, &crc_extra_bits, R);
882  } else if (type == AV_SAMPLE_FMT_S32P) {
883  *dst32_l++ = wv_get_value_integer(s, &crc_extra_bits, L);
884  *dst32_r++ = wv_get_value_integer(s, &crc_extra_bits, R);
885  } else {
886  *dst16_l++ = wv_get_value_integer(s, &crc_extra_bits, L);
887  *dst16_r++ = wv_get_value_integer(s, &crc_extra_bits, R);
888  }
889  count++;
890  } while (!last && count < s->samples);
891 
892  if (last && count < s->samples) {
894  memset((uint8_t*)dst_l + count*size, 0, (s->samples-count)*size);
895  memset((uint8_t*)dst_r + count*size, 0, (s->samples-count)*size);
896  }
897 
898  if ((s->avctx->err_recognition & AV_EF_CRCCHECK) &&
899  wv_check_crc(s, crc, crc_extra_bits))
900  return AVERROR_INVALIDDATA;
901 
902  return 0;
903 }
904 
906  void *dst, const int type)
907 {
908  int i, j, count = 0;
909  int last, t;
910  int A, S, T;
911  int pos = 0;
912  uint32_t crc = 0xFFFFFFFF;
913  uint32_t crc_extra_bits = 0xFFFFFFFF;
914  int16_t *dst16 = dst;
915  int32_t *dst32 = dst;
916  float *dstfl = dst;
917 
918  s->one = s->zero = s->zeroes = 0;
919  do {
920  T = wv_get_value(s, gb, 0, &last);
921  S = 0;
922  if (last)
923  break;
924  for (i = 0; i < s->terms; i++) {
925  Decorr *decorr = &s->decorr[i];
926 
927  t = decorr->value;
928  if (t > 8) {
929  if (t & 1)
930  A = 2U * decorr->samplesA[0] - decorr->samplesA[1];
931  else
932  A = (int)(3U * decorr->samplesA[0] - decorr->samplesA[1]) >> 1;
933  decorr->samplesA[1] = decorr->samplesA[0];
934  j = 0;
935  } else {
936  A = decorr->samplesA[pos];
937  j = (pos + t) & 7;
938  }
939  if (type != AV_SAMPLE_FMT_S16P)
940  S = T + ((decorr->weightA * (int64_t)A + 512) >> 10);
941  else
942  S = T + (unsigned)((int)(decorr->weightA * (unsigned)A + 512) >> 10);
943  if (A && T)
944  decorr->weightA -= ((((T ^ A) >> 30) & 2) - 1) * decorr->delta;
945  decorr->samplesA[j] = T = S;
946  }
947  pos = (pos + 1) & 7;
948  crc = crc * 3 + S;
949 
950  if (type == AV_SAMPLE_FMT_FLTP) {
951  *dstfl++ = wv_get_value_float(s, &crc_extra_bits, S);
952  } else if (type == AV_SAMPLE_FMT_S32P) {
953  *dst32++ = wv_get_value_integer(s, &crc_extra_bits, S);
954  } else {
955  *dst16++ = wv_get_value_integer(s, &crc_extra_bits, S);
956  }
957  count++;
958  } while (!last && count < s->samples);
959 
960  if (last && count < s->samples) {
962  memset((uint8_t*)dst + count*size, 0, (s->samples-count)*size);
963  }
964 
965  if (s->avctx->err_recognition & AV_EF_CRCCHECK) {
966  int ret = wv_check_crc(s, crc, crc_extra_bits);
967  if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE)
968  return ret;
969  }
970 
971  return 0;
972 }
973 
975 {
976  c->fdec = av_realloc_f(c->fdec, c->fdec_num + 1, sizeof(*c->fdec));
977  if (!c->fdec)
978  return -1;
979 
980  c->fdec[c->fdec_num] = av_mallocz(sizeof(**c->fdec));
981  if (!c->fdec[c->fdec_num])
982  return -1;
983  c->fdec_num++;
984  c->fdec[c->fdec_num - 1]->avctx = c->avctx;
985 
986  return 0;
987 }
988 
990 {
991  int i;
992 
993  s->dsd_channels = 0;
994  ff_refstruct_unref(&s->dsdctx);
995 
996  if (!channels)
997  return 0;
998 
999  if (channels > INT_MAX / sizeof(*s->dsdctx))
1000  return AVERROR(EINVAL);
1001 
1002  s->dsdctx = ff_refstruct_allocz(channels * sizeof(*s->dsdctx));
1003  if (!s->dsdctx)
1004  return AVERROR(ENOMEM);
1005  s->dsd_channels = channels;
1006 
1007  for (i = 0; i < channels; i++)
1008  memset(s->dsdctx[i].buf, 0x69, sizeof(s->dsdctx[i].buf));
1009 
1010  return 0;
1011 }
1012 
1013 #if HAVE_THREADS
1014 static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
1015 {
1016  WavpackContext *fsrc = src->priv_data;
1017  WavpackContext *fdst = dst->priv_data;
1018  int ret;
1019 
1020  if (dst == src)
1021  return 0;
1022 
1024  if (fsrc->curr_frame.f->data[0]) {
1025  if ((ret = ff_thread_ref_frame(&fdst->curr_frame, &fsrc->curr_frame)) < 0)
1026  return ret;
1027  }
1028 
1029  ff_refstruct_replace(&fdst->dsdctx, fsrc->dsdctx);
1030  fdst->dsd_channels = fsrc->dsd_channels;
1031 
1032  return 0;
1033 }
1034 #endif
1035 
1037 {
1038  WavpackContext *s = avctx->priv_data;
1039 
1040  s->avctx = avctx;
1041 
1042  s->fdec_num = 0;
1043 
1044  s->curr_frame.f = av_frame_alloc();
1045  s->prev_frame.f = av_frame_alloc();
1046 
1047  if (!s->curr_frame.f || !s->prev_frame.f)
1048  return AVERROR(ENOMEM);
1049 
1050  ff_init_dsd_data();
1051 
1052  return 0;
1053 }
1054 
1056 {
1057  WavpackContext *s = avctx->priv_data;
1058 
1059  for (int i = 0; i < s->fdec_num; i++)
1060  av_freep(&s->fdec[i]);
1061  av_freep(&s->fdec);
1062  s->fdec_num = 0;
1063 
1064  ff_thread_release_ext_buffer(&s->curr_frame);
1065  av_frame_free(&s->curr_frame.f);
1066 
1067  ff_thread_release_ext_buffer(&s->prev_frame);
1068  av_frame_free(&s->prev_frame.f);
1069 
1070  ff_refstruct_unref(&s->dsdctx);
1071 
1072  return 0;
1073 }
1074 
1075 static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
1076  const uint8_t *buf, int buf_size)
1077 {
1078  WavpackContext *wc = avctx->priv_data;
1080  GetByteContext gb;
1081  enum AVSampleFormat sample_fmt;
1082  void *samples_l = NULL, *samples_r = NULL;
1083  int ret;
1084  int got_terms = 0, got_weights = 0, got_samples = 0,
1085  got_entropy = 0, got_pcm = 0, got_float = 0, got_hybrid = 0;
1086  int got_dsd = 0;
1087  int i, j, id, size, ssize, weights, t;
1088  int bpp, chan = 0, orig_bpp, sample_rate = 0, rate_x = 1, dsd_mode = 0;
1089  int multiblock;
1090  uint64_t chmask = 0;
1091 
1092  if (block_no >= wc->fdec_num && wv_alloc_frame_context(wc) < 0) {
1093  av_log(avctx, AV_LOG_ERROR, "Error creating frame decode context\n");
1094  return AVERROR_INVALIDDATA;
1095  }
1096 
1097  s = wc->fdec[block_no];
1098  if (!s) {
1099  av_log(avctx, AV_LOG_ERROR, "Context for block %d is not present\n",
1100  block_no);
1101  return AVERROR_INVALIDDATA;
1102  }
1103 
1104  memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr));
1105  memset(s->ch, 0, sizeof(s->ch));
1106  s->extra_bits = 0;
1107  s->and = s->or = s->shift = 0;
1108  s->got_extra_bits = 0;
1109 
1110  bytestream2_init(&gb, buf, buf_size);
1111 
1112  s->samples = bytestream2_get_le32(&gb);
1113  if (s->samples != wc->samples) {
1114  av_log(avctx, AV_LOG_ERROR, "Mismatching number of samples in "
1115  "a sequence: %d and %d\n", wc->samples, s->samples);
1116  return AVERROR_INVALIDDATA;
1117  }
1118  s->frame_flags = bytestream2_get_le32(&gb);
1119 
1120  if (s->frame_flags & (WV_FLOAT_DATA | WV_DSD_DATA))
1121  sample_fmt = AV_SAMPLE_FMT_FLTP;
1122  else if ((s->frame_flags & 0x03) <= 1)
1123  sample_fmt = AV_SAMPLE_FMT_S16P;
1124  else
1125  sample_fmt = AV_SAMPLE_FMT_S32P;
1126 
1127  if (wc->ch_offset && avctx->sample_fmt != sample_fmt)
1128  return AVERROR_INVALIDDATA;
1129 
1130  bpp = av_get_bytes_per_sample(sample_fmt);
1131  orig_bpp = ((s->frame_flags & 0x03) + 1) << 3;
1132  multiblock = (s->frame_flags & WV_SINGLE_BLOCK) != WV_SINGLE_BLOCK;
1133 
1134  s->stereo = !(s->frame_flags & WV_MONO);
1135  s->stereo_in = (s->frame_flags & WV_FALSE_STEREO) ? 0 : s->stereo;
1136  s->joint = s->frame_flags & WV_JOINT_STEREO;
1137  s->hybrid = s->frame_flags & WV_HYBRID_MODE;
1138  s->hybrid_bitrate = s->frame_flags & WV_HYBRID_BITRATE;
1139  s->post_shift = bpp * 8 - orig_bpp + ((s->frame_flags >> 13) & 0x1f);
1140  if (s->post_shift < 0 || s->post_shift > 31) {
1141  return AVERROR_INVALIDDATA;
1142  }
1143  s->hybrid_maxclip = ((1LL << (orig_bpp - 1)) - 1);
1144  s->hybrid_minclip = ((-1UL << (orig_bpp - 1)));
1145  s->CRC = bytestream2_get_le32(&gb);
1146 
1147  // parse metadata blocks
1148  while (bytestream2_get_bytes_left(&gb)) {
1149  id = bytestream2_get_byte(&gb);
1150  size = bytestream2_get_byte(&gb);
1151  if (id & WP_IDF_LONG)
1152  size |= (bytestream2_get_le16u(&gb)) << 8;
1153  size <<= 1; // size is specified in words
1154  ssize = size;
1155  if (id & WP_IDF_ODD)
1156  size--;
1157  if (size < 0) {
1158  av_log(avctx, AV_LOG_ERROR,
1159  "Got incorrect block %02X with size %i\n", id, size);
1160  break;
1161  }
1162  if (bytestream2_get_bytes_left(&gb) < ssize) {
1163  av_log(avctx, AV_LOG_ERROR,
1164  "Block size %i is out of bounds\n", size);
1165  break;
1166  }
1167  switch (id & WP_IDF_MASK) {
1168  case WP_ID_DECTERMS:
1169  if (size > MAX_TERMS) {
1170  av_log(avctx, AV_LOG_ERROR, "Too many decorrelation terms\n");
1171  s->terms = 0;
1172  bytestream2_skip(&gb, ssize);
1173  continue;
1174  }
1175  s->terms = size;
1176  for (i = 0; i < s->terms; i++) {
1177  uint8_t val = bytestream2_get_byte(&gb);
1178  s->decorr[s->terms - i - 1].value = (val & 0x1F) - 5;
1179  s->decorr[s->terms - i - 1].delta = val >> 5;
1180  }
1181  got_terms = 1;
1182  break;
1183  case WP_ID_DECWEIGHTS:
1184  if (!got_terms) {
1185  av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
1186  continue;
1187  }
1188  weights = size >> s->stereo_in;
1189  if (weights > MAX_TERMS || weights > s->terms) {
1190  av_log(avctx, AV_LOG_ERROR, "Too many decorrelation weights\n");
1191  bytestream2_skip(&gb, ssize);
1192  continue;
1193  }
1194  for (i = 0; i < weights; i++) {
1195  t = (int8_t)bytestream2_get_byte(&gb);
1196  s->decorr[s->terms - i - 1].weightA = t * (1 << 3);
1197  if (s->decorr[s->terms - i - 1].weightA > 0)
1198  s->decorr[s->terms - i - 1].weightA +=
1199  (s->decorr[s->terms - i - 1].weightA + 64) >> 7;
1200  if (s->stereo_in) {
1201  t = (int8_t)bytestream2_get_byte(&gb);
1202  s->decorr[s->terms - i - 1].weightB = t * (1 << 3);
1203  if (s->decorr[s->terms - i - 1].weightB > 0)
1204  s->decorr[s->terms - i - 1].weightB +=
1205  (s->decorr[s->terms - i - 1].weightB + 64) >> 7;
1206  }
1207  }
1208  got_weights = 1;
1209  break;
1210  case WP_ID_DECSAMPLES:
1211  if (!got_terms) {
1212  av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
1213  continue;
1214  }
1215  t = 0;
1216  for (i = s->terms - 1; (i >= 0) && (t < size); i--) {
1217  Decorr *decorr = &s->decorr[i];
1218 
1219  if (decorr->value > 8) {
1220  decorr->samplesA[0] =
1221  wp_exp2(bytestream2_get_le16(&gb));
1222  decorr->samplesA[1] =
1223  wp_exp2(bytestream2_get_le16(&gb));
1224 
1225  if (s->stereo_in) {
1226  decorr->samplesB[0] =
1227  wp_exp2(bytestream2_get_le16(&gb));
1228  decorr->samplesB[1] =
1229  wp_exp2(bytestream2_get_le16(&gb));
1230  t += 4;
1231  }
1232  t += 4;
1233  } else if (decorr->value < 0) {
1234  decorr->samplesA[0] =
1235  wp_exp2(bytestream2_get_le16(&gb));
1236  decorr->samplesB[0] =
1237  wp_exp2(bytestream2_get_le16(&gb));
1238  t += 4;
1239  } else {
1240  for (j = 0; j < decorr->value; j++) {
1241  decorr->samplesA[j] =
1242  wp_exp2(bytestream2_get_le16(&gb));
1243  if (s->stereo_in) {
1244  decorr->samplesB[j] =
1245  wp_exp2(bytestream2_get_le16(&gb));
1246  }
1247  }
1248  t += decorr->value * 2 * (s->stereo_in + 1);
1249  }
1250  }
1251  got_samples = 1;
1252  break;
1253  case WP_ID_ENTROPY:
1254  if (size != 6 * (s->stereo_in + 1)) {
1255  av_log(avctx, AV_LOG_ERROR,
1256  "Entropy vars size should be %i, got %i.\n",
1257  6 * (s->stereo_in + 1), size);
1258  bytestream2_skip(&gb, ssize);
1259  continue;
1260  }
1261  for (j = 0; j <= s->stereo_in; j++)
1262  for (i = 0; i < 3; i++) {
1263  s->ch[j].median[i] = wp_exp2(bytestream2_get_le16(&gb));
1264  }
1265  got_entropy = 1;
1266  break;
1267  case WP_ID_HYBRID:
1268  if (s->hybrid_bitrate) {
1269  for (i = 0; i <= s->stereo_in; i++) {
1270  s->ch[i].slow_level = wp_exp2(bytestream2_get_le16(&gb));
1271  size -= 2;
1272  }
1273  }
1274  for (i = 0; i < (s->stereo_in + 1); i++) {
1275  s->ch[i].bitrate_acc = bytestream2_get_le16(&gb) << 16;
1276  size -= 2;
1277  }
1278  if (size > 0) {
1279  for (i = 0; i < (s->stereo_in + 1); i++) {
1280  s->ch[i].bitrate_delta =
1281  wp_exp2((int16_t)bytestream2_get_le16(&gb));
1282  }
1283  } else {
1284  for (i = 0; i < (s->stereo_in + 1); i++)
1285  s->ch[i].bitrate_delta = 0;
1286  }
1287  got_hybrid = 1;
1288  break;
1289  case WP_ID_INT32INFO: {
1290  uint8_t val[4];
1291  if (size != 4) {
1292  av_log(avctx, AV_LOG_ERROR,
1293  "Invalid INT32INFO, size = %i\n",
1294  size);
1295  bytestream2_skip(&gb, ssize - 4);
1296  continue;
1297  }
1298  bytestream2_get_buffer(&gb, val, 4);
1299  if (val[0] > 30) {
1300  av_log(avctx, AV_LOG_ERROR,
1301  "Invalid INT32INFO, extra_bits = %d (> 30)\n", val[0]);
1302  continue;
1303  } else {
1304  s->extra_bits = val[0];
1305  }
1306  if (val[1])
1307  s->shift = val[1];
1308  if (val[2]) {
1309  s->and = s->or = 1;
1310  s->shift = val[2];
1311  }
1312  if (val[3]) {
1313  s->and = 1;
1314  s->shift = val[3];
1315  }
1316  if (s->shift > 31) {
1317  av_log(avctx, AV_LOG_ERROR,
1318  "Invalid INT32INFO, shift = %d (> 31)\n", s->shift);
1319  s->and = s->or = s->shift = 0;
1320  continue;
1321  }
1322  /* original WavPack decoder forces 32-bit lossy sound to be treated
1323  * as 24-bit one in order to have proper clipping */
1324  if (s->hybrid && bpp == 4 && s->post_shift < 8 && s->shift > 8) {
1325  s->post_shift += 8;
1326  s->shift -= 8;
1327  s->hybrid_maxclip >>= 8;
1328  s->hybrid_minclip >>= 8;
1329  }
1330  break;
1331  }
1332  case WP_ID_FLOATINFO:
1333  if (size != 4) {
1334  av_log(avctx, AV_LOG_ERROR,
1335  "Invalid FLOATINFO, size = %i\n", size);
1336  bytestream2_skip(&gb, ssize);
1337  continue;
1338  }
1339  s->float_flag = bytestream2_get_byte(&gb);
1340  s->float_shift = bytestream2_get_byte(&gb);
1341  s->float_max_exp = bytestream2_get_byte(&gb);
1342  if (s->float_shift > 31) {
1343  av_log(avctx, AV_LOG_ERROR,
1344  "Invalid FLOATINFO, shift = %d (> 31)\n", s->float_shift);
1345  s->float_shift = 0;
1346  continue;
1347  }
1348  got_float = 1;
1349  bytestream2_skip(&gb, 1);
1350  break;
1351  case WP_ID_DATA:
1352  if ((ret = init_get_bits8(&s->gb, gb.buffer, size)) < 0)
1353  return ret;
1354  bytestream2_skip(&gb, size);
1355  got_pcm = 1;
1356  break;
1357  case WP_ID_DSD_DATA:
1358  if (size < 2) {
1359  av_log(avctx, AV_LOG_ERROR, "Invalid DSD_DATA, size = %i\n",
1360  size);
1361  bytestream2_skip(&gb, ssize);
1362  continue;
1363  }
1364  rate_x = bytestream2_get_byte(&gb);
1365  if (rate_x > 30)
1366  return AVERROR_INVALIDDATA;
1367  rate_x = 1 << rate_x;
1368  dsd_mode = bytestream2_get_byte(&gb);
1369  if (dsd_mode && dsd_mode != 1 && dsd_mode != 3) {
1370  av_log(avctx, AV_LOG_ERROR, "Invalid DSD encoding mode: %d\n",
1371  dsd_mode);
1372  return AVERROR_INVALIDDATA;
1373  }
1374  bytestream2_init(&s->gbyte, gb.buffer, size-2);
1375  bytestream2_skip(&gb, size-2);
1376  got_dsd = 1;
1377  break;
1378  case WP_ID_EXTRABITS:
1379  if (size <= 4) {
1380  av_log(avctx, AV_LOG_ERROR, "Invalid EXTRABITS, size = %i\n",
1381  size);
1382  bytestream2_skip(&gb, size);
1383  continue;
1384  }
1385  if ((ret = init_get_bits8(&s->gb_extra_bits, gb.buffer, size)) < 0)
1386  return ret;
1387  s->crc_extra_bits = get_bits_long(&s->gb_extra_bits, 32);
1388  bytestream2_skip(&gb, size);
1389  s->got_extra_bits = 1;
1390  break;
1391  case WP_ID_CHANINFO:
1392  if (size <= 1) {
1393  av_log(avctx, AV_LOG_ERROR,
1394  "Insufficient channel information\n");
1395  return AVERROR_INVALIDDATA;
1396  }
1397  chan = bytestream2_get_byte(&gb);
1398  switch (size - 2) {
1399  case 0:
1400  chmask = bytestream2_get_byte(&gb);
1401  break;
1402  case 1:
1403  chmask = bytestream2_get_le16(&gb);
1404  break;
1405  case 2:
1406  chmask = bytestream2_get_le24(&gb);
1407  break;
1408  case 3:
1409  chmask = bytestream2_get_le32(&gb);
1410  break;
1411  case 4:
1412  size = bytestream2_get_byte(&gb);
1413  chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
1414  chan += 1;
1415  chmask = bytestream2_get_le24(&gb);
1416  break;
1417  case 5:
1418  size = bytestream2_get_byte(&gb);
1419  chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
1420  chan += 1;
1421  chmask = bytestream2_get_le32(&gb);
1422  break;
1423  default:
1424  av_log(avctx, AV_LOG_ERROR, "Invalid channel info size %d\n",
1425  size);
1426  }
1427  break;
1428  case WP_ID_SAMPLE_RATE:
1429  if (size != 3) {
1430  av_log(avctx, AV_LOG_ERROR, "Invalid custom sample rate.\n");
1431  return AVERROR_INVALIDDATA;
1432  }
1433  sample_rate = bytestream2_get_le24(&gb);
1434  break;
1435  default:
1436  bytestream2_skip(&gb, size);
1437  }
1438  if (id & WP_IDF_ODD)
1439  bytestream2_skip(&gb, 1);
1440  }
1441 
1442  if (got_pcm) {
1443  if (!got_terms) {
1444  av_log(avctx, AV_LOG_ERROR, "No block with decorrelation terms\n");
1445  return AVERROR_INVALIDDATA;
1446  }
1447  if (!got_weights) {
1448  av_log(avctx, AV_LOG_ERROR, "No block with decorrelation weights\n");
1449  return AVERROR_INVALIDDATA;
1450  }
1451  if (!got_samples) {
1452  av_log(avctx, AV_LOG_ERROR, "No block with decorrelation samples\n");
1453  return AVERROR_INVALIDDATA;
1454  }
1455  if (!got_entropy) {
1456  av_log(avctx, AV_LOG_ERROR, "No block with entropy info\n");
1457  return AVERROR_INVALIDDATA;
1458  }
1459  if (s->hybrid && !got_hybrid) {
1460  av_log(avctx, AV_LOG_ERROR, "Hybrid config not found\n");
1461  return AVERROR_INVALIDDATA;
1462  }
1463  if (!got_float && sample_fmt == AV_SAMPLE_FMT_FLTP) {
1464  av_log(avctx, AV_LOG_ERROR, "Float information not found\n");
1465  return AVERROR_INVALIDDATA;
1466  }
1467  if (s->got_extra_bits && sample_fmt != AV_SAMPLE_FMT_FLTP) {
1468  const int size = get_bits_left(&s->gb_extra_bits);
1469  const int wanted = s->samples * s->extra_bits << s->stereo_in;
1470  if (size < wanted) {
1471  av_log(avctx, AV_LOG_ERROR, "Too small EXTRABITS\n");
1472  s->got_extra_bits = 0;
1473  }
1474  }
1475  }
1476 
1477  if (!got_pcm && !got_dsd) {
1478  av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n");
1479  return AVERROR_INVALIDDATA;
1480  }
1481 
1482  if ((got_pcm && wc->modulation != MODULATION_PCM) ||
1483  (got_dsd && wc->modulation != MODULATION_DSD)) {
1484  av_log(avctx, AV_LOG_ERROR, "Invalid PCM/DSD mix encountered\n");
1485  return AVERROR_INVALIDDATA;
1486  }
1487 
1488  if (!wc->ch_offset) {
1489  AVChannelLayout new_ch_layout = { 0 };
1490  int new_samplerate;
1491  int sr = (s->frame_flags >> 23) & 0xf;
1492  if (sr == 0xf) {
1493  if (!sample_rate) {
1494  av_log(avctx, AV_LOG_ERROR, "Custom sample rate missing.\n");
1495  return AVERROR_INVALIDDATA;
1496  }
1497  new_samplerate = sample_rate;
1498  } else
1499  new_samplerate = wv_rates[sr];
1500 
1501  if (new_samplerate * (uint64_t)rate_x > INT_MAX)
1502  return AVERROR_INVALIDDATA;
1503  new_samplerate *= rate_x;
1504 
1505  if (multiblock) {
1506  if (chmask) {
1507  av_channel_layout_from_mask(&new_ch_layout, chmask);
1508  if (chan && new_ch_layout.nb_channels != chan) {
1509  av_log(avctx, AV_LOG_ERROR, "Channel mask does not match the channel count\n");
1510  return AVERROR_INVALIDDATA;
1511  }
1512  } else {
1513  av_channel_layout_default(&new_ch_layout, chan);
1514  }
1515  } else {
1516  av_channel_layout_default(&new_ch_layout, s->stereo + 1);
1517  }
1518 
1519  /* clear DSD state if stream properties change */
1520  if (new_ch_layout.nb_channels != wc->dsd_channels ||
1521  av_channel_layout_compare(&new_ch_layout, &avctx->ch_layout) ||
1522  new_samplerate != avctx->sample_rate ||
1523  !!got_dsd != !!wc->dsdctx) {
1524  ret = wv_dsd_reset(wc, got_dsd ? new_ch_layout.nb_channels : 0);
1525  if (ret < 0) {
1526  av_log(avctx, AV_LOG_ERROR, "Error reinitializing the DSD context\n");
1527  return ret;
1528  }
1530  }
1531  av_channel_layout_copy(&avctx->ch_layout, &new_ch_layout);
1532  avctx->sample_rate = new_samplerate;
1533  avctx->sample_fmt = sample_fmt;
1534  avctx->bits_per_raw_sample = orig_bpp;
1535 
1538 
1539  /* get output buffer */
1540  wc->curr_frame.f->nb_samples = s->samples;
1541  ret = ff_thread_get_ext_buffer(avctx, &wc->curr_frame,
1543  if (ret < 0)
1544  return ret;
1545 
1546  wc->frame = wc->curr_frame.f;
1547  ff_thread_finish_setup(avctx);
1548  }
1549 
1550  if (wc->ch_offset + s->stereo >= avctx->ch_layout.nb_channels) {
1551  av_log(avctx, AV_LOG_WARNING, "Too many channels coded in a packet.\n");
1552  return ((avctx->err_recognition & AV_EF_EXPLODE) || !wc->ch_offset) ? AVERROR_INVALIDDATA : 0;
1553  }
1554 
1555  samples_l = wc->frame->extended_data[wc->ch_offset];
1556  if (s->stereo)
1557  samples_r = wc->frame->extended_data[wc->ch_offset + 1];
1558 
1559  wc->ch_offset += 1 + s->stereo;
1560 
1561  if (s->stereo_in) {
1562  if (got_dsd) {
1563  if (dsd_mode == 3) {
1564  ret = wv_unpack_dsd_high(s, samples_l, samples_r);
1565  } else if (dsd_mode == 1) {
1566  ret = wv_unpack_dsd_fast(s, samples_l, samples_r);
1567  } else {
1568  ret = wv_unpack_dsd_copy(s, samples_l, samples_r);
1569  }
1570  } else {
1571  ret = wv_unpack_stereo(s, &s->gb, samples_l, samples_r, avctx->sample_fmt);
1572  }
1573  if (ret < 0)
1574  return ret;
1575  } else {
1576  if (got_dsd) {
1577  if (dsd_mode == 3) {
1578  ret = wv_unpack_dsd_high(s, samples_l, NULL);
1579  } else if (dsd_mode == 1) {
1580  ret = wv_unpack_dsd_fast(s, samples_l, NULL);
1581  } else {
1582  ret = wv_unpack_dsd_copy(s, samples_l, NULL);
1583  }
1584  } else {
1585  ret = wv_unpack_mono(s, &s->gb, samples_l, avctx->sample_fmt);
1586  }
1587  if (ret < 0)
1588  return ret;
1589 
1590  if (s->stereo)
1591  memcpy(samples_r, samples_l, bpp * s->samples);
1592  }
1593 
1594  return 0;
1595 }
1596 
1598 {
1599  WavpackContext *s = avctx->priv_data;
1600 
1601  wv_dsd_reset(s, 0);
1602 }
1603 
1604 static int dsd_channel(AVCodecContext *avctx, void *frmptr, int jobnr, int threadnr)
1605 {
1606  const WavpackContext *s = avctx->priv_data;
1607  AVFrame *frame = frmptr;
1608 
1609  ff_dsd2pcm_translate (&s->dsdctx [jobnr], s->samples, 0,
1610  (uint8_t *)frame->extended_data[jobnr], 4,
1611  (float *)frame->extended_data[jobnr], 1);
1612 
1613  return 0;
1614 }
1615 
1616 static int wavpack_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
1617  int *got_frame_ptr, AVPacket *avpkt)
1618 {
1619  WavpackContext *s = avctx->priv_data;
1620  const uint8_t *buf = avpkt->data;
1621  int buf_size = avpkt->size;
1622  int frame_size, ret, frame_flags;
1623 
1624  if (avpkt->size <= WV_HEADER_SIZE)
1625  return AVERROR_INVALIDDATA;
1626 
1627  s->frame = NULL;
1628  s->block = 0;
1629  s->ch_offset = 0;
1630 
1631  /* determine number of samples */
1632  s->samples = AV_RL32(buf + 20);
1633  frame_flags = AV_RL32(buf + 24);
1634  if (s->samples <= 0 || s->samples > WV_MAX_SAMPLES) {
1635  av_log(avctx, AV_LOG_ERROR, "Invalid number of samples: %d\n",
1636  s->samples);
1637  return AVERROR_INVALIDDATA;
1638  }
1639 
1640  s->modulation = (frame_flags & WV_DSD_DATA) ? MODULATION_DSD : MODULATION_PCM;
1641 
1642  while (buf_size > WV_HEADER_SIZE) {
1643  frame_size = AV_RL32(buf + 4) - 12;
1644  buf += 20;
1645  buf_size -= 20;
1646  if (frame_size <= 0 || frame_size > buf_size) {
1647  av_log(avctx, AV_LOG_ERROR,
1648  "Block %d has invalid size (size %d vs. %d bytes left)\n",
1649  s->block, frame_size, buf_size);
1651  goto error;
1652  }
1653  if ((ret = wavpack_decode_block(avctx, s->block, buf, frame_size)) < 0)
1654  goto error;
1655  s->block++;
1656  buf += frame_size;
1657  buf_size -= frame_size;
1658  }
1659 
1660  if (s->ch_offset != avctx->ch_layout.nb_channels) {
1661  av_log(avctx, AV_LOG_ERROR, "Not enough channels coded in a packet.\n");
1663  goto error;
1664  }
1665 
1666  ff_thread_await_progress(&s->prev_frame, INT_MAX, 0);
1667  ff_thread_release_ext_buffer(&s->prev_frame);
1668 
1669  if (s->modulation == MODULATION_DSD)
1670  avctx->execute2(avctx, dsd_channel, s->frame, NULL, avctx->ch_layout.nb_channels);
1671 
1672  ff_thread_report_progress(&s->curr_frame, INT_MAX, 0);
1673 
1674  if ((ret = av_frame_ref(rframe, s->frame)) < 0)
1675  return ret;
1676 
1677  *got_frame_ptr = 1;
1678 
1679  return avpkt->size;
1680 
1681 error:
1682  if (s->frame) {
1683  ff_thread_await_progress(&s->prev_frame, INT_MAX, 0);
1684  ff_thread_release_ext_buffer(&s->prev_frame);
1685  ff_thread_report_progress(&s->curr_frame, INT_MAX, 0);
1686  }
1687 
1688  return ret;
1689 }
1690 
1692  .p.name = "wavpack",
1693  CODEC_LONG_NAME("WavPack"),
1694  .p.type = AVMEDIA_TYPE_AUDIO,
1695  .p.id = AV_CODEC_ID_WAVPACK,
1696  .priv_data_size = sizeof(WavpackContext),
1698  .close = wavpack_decode_end,
1700  .flush = wavpack_decode_flush,
1702  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
1704  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
1706 };
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
WavpackFrameContext::joint
int joint
Definition: wavpack.c:72
WV_HYBRID_BITRATE
#define WV_HYBRID_BITRATE
Definition: wavpack.h:45
A
#define A(x)
Definition: vpx_arith.h:28
WavpackFrameContext::decorr
Decorr decorr[MAX_TERMS]
Definition: wavpack.c:80
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
WavpackContext::avctx
AVCodecContext * avctx
Definition: wavpack.c:101
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
L2
F H1 F F H1 F F F F H1<-F-------F-------F v v v H2 H3 H2 ^ ^ ^ F-------F-------F-> H1<-F-------F-------F|||||||||F H1 F|||||||||F H1 Funavailable fullpel samples(outside the picture for example) shall be equalto the closest available fullpel sampleSmaller pel interpolation:--------------------------if diag_mc is set then points which lie on a line between 2 vertically, horizontally or diagonally adjacent halfpel points shall be interpolatedlinearly with rounding to nearest and halfway values rounded up.points which lie on 2 diagonals at the same time should only use the onediagonal not containing the fullpel point F--> O q O<--h1-> O q O<--F v \/v \/v O O O O O O O|/|\|q q q q q|/|\|O O O O O O O ^/\ ^/\ ^ h2--> O q O<--h3-> O q O<--h2 v \/v \/v O O O O O O O|\|/|q q q q q|\|/|O O O O O O O ^/\ ^/\ ^ F--> O q O<--h1-> O q O<--Fthe remaining points shall be bilinearly interpolated from theup to 4 surrounding halfpel and fullpel points, again rounding should be tonearest and halfway values rounded upcompliant Snow decoders MUST support 1-1/8 pel luma and 1/2-1/16 pel chromainterpolation at leastOverlapped block motion compensation:-------------------------------------FIXMELL band prediction:===================Each sample in the LL0 subband is predicted by the median of the left, top andleft+top-topleft samples, samples outside the subband shall be considered tobe 0. To reverse this prediction in the decoder apply the following.for(y=0;y< height;y++){ for(x=0;x< width;x++){ sample[y][x]+=median(sample[y-1][x], sample[y][x-1], sample[y-1][x]+sample[y][x-1]-sample[y-1][x-1]);}}sample[-1][ *]=sample[ *][-1]=0;width, height here are the width and height of the LL0 subband not of the finalvideoDequantization:===============FIXMEWavelet Transform:==================Snow supports 2 wavelet transforms, the symmetric biorthogonal 5/3 integertransform and an integer approximation of the symmetric biorthogonal 9/7daubechies wavelet.2D IDWT(inverse discrete wavelet transform) --------------------------------------------The 2D IDWT applies a 2D filter recursively, each time combining the4 lowest frequency subbands into a single subband until only 1 subbandremains.The 2D filter is done by first applying a 1D filter in the vertical directionand then applying it in the horizontal one. --------------- --------------- --------------- ---------------|LL0|HL0|||||||||||||---+---|HL1||L0|H0|HL1||LL1|HL1|||||LH0|HH0|||||||||||||-------+-------|-> L1 H1 LH1 HH1 LH1 HH1 LH1 HH1 L2
Definition: snow.txt:554
WP_ID_DSD_DATA
@ WP_ID_DSD_DATA
Definition: wavpack.h:84
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: defs.h:51
av_clip
#define av_clip
Definition: common.h:96
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
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:694
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
WP_ID_HYBRID
@ WP_ID_HYBRID
Definition: wavpack.h:76
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1064
WP_ID_FLOATINFO
@ WP_ID_FLOATINFO
Definition: wavpack.h:78
GetByteContext
Definition: bytestream.h:33
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:250
WV_MAX_SAMPLES
#define WV_MAX_SAMPLES
Definition: wavpack.h:60
MAX_TERMS
#define MAX_TERMS
Definition: wavpack.h:30
wv_unpack_dsd_high
static int wv_unpack_dsd_high(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
Definition: wavpack.c:436
WavpackFrameContext::CRC
uint32_t CRC
Definition: wavpack.c:73
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1412
wavpack_decode_flush
static void wavpack_decode_flush(AVCodecContext *avctx)
Definition: wavpack.c:1597
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:421
DECAY
#define DECAY
Definition: wavpack.c:51
MODULATION_PCM
@ MODULATION_PCM
Definition: wavpack.c:64
WP_ID_DECWEIGHTS
@ WP_ID_DECWEIGHTS
Definition: wavpack.h:73
WV_FLT_SHIFT_ONES
#define WV_FLT_SHIFT_ONES
Definition: wavpack.h:54
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:100
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
WavpackContext::prev_frame
ThreadFrame prev_frame
Definition: wavpack.c:111
WP_IDF_LONG
@ WP_IDF_LONG
Definition: wavpack.h:66
AVPacket::data
uint8_t * data
Definition: packet.h:491
WavpackFrameContext::post_shift
int post_shift
Definition: wavpack.c:84
WV_MONO
@ WV_MONO
Definition: wvdec.c:32
table
static const uint16_t table[]
Definition: prosumer.c:205
AV_SAMPLE_FMT_S32P
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition: samplefmt.h:65
R
#define R
Definition: huffyuv.h:44
WV_FLT_ZERO_SIGN
#define WV_FLT_ZERO_SIGN
Definition: wavpack.h:58
FFCodec
Definition: codec_internal.h:127
WavpackFrameContext::stereo
int stereo
Definition: wavpack.c:71
base
uint8_t base
Definition: vp3data.h:128
PRECISION_USE
#define PRECISION_USE
Definition: wavpack.c:55
WvChannel
Definition: wavpack.h:99
Decorr::weightA
int weightA
Definition: wavpack.h:91
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:317
dsd.h
WV_FLOAT_DATA
#define WV_FLOAT_DATA
Definition: wavpack.h:38
thread.h
ff_thread_await_progress
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before ff_thread_await_progress() has been called on them. reget_buffer() and buffer age optimizations no longer work. *The contents of buffers must not be written to after ff_thread_report_progress() has been called on them. This includes draw_edges(). Porting codecs to frame threading
sample_rate
sample_rate
Definition: ffmpeg_filter.c:368
ThreadFrame::f
AVFrame * f
Definition: threadframe.h:28
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
MODULATION_DSD
@ MODULATION_DSD
Definition: wavpack.c:65
WavpackContext::frame
AVFrame * frame
Definition: wavpack.c:110
WavpackContext::fdec_num
int fdec_num
Definition: wavpack.c:104
bit
#define bit(string, value)
Definition: cbs_mpeg2.c:56
S
#define S(s, c, i)
Definition: flacdsp_template.c:46
wv_unpack_dsd_copy
static int wv_unpack_dsd_copy(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
Definition: wavpack.c:740
WavpackContext
Definition: wavpack.c:100
MAX_HISTORY_BINS
#define MAX_HISTORY_BINS
Definition: wavpack.c:60
bytestream2_skip
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:168
WP_ID_DATA
@ WP_ID_DATA
Definition: wavpack.h:80
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
update_error_limit
static int update_error_limit(WavpackFrameContext *ctx)
Definition: wavpack.c:134
Decorr
Definition: wavpack.h:88
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
WP_ID_SAMPLE_RATE
@ WP_ID_SAMPLE_RATE
Definition: wavpack.h:85
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2107
WavpackFrameContext::got_extra_bits
int got_extra_bits
Definition: wavpack.c:75
WP_ID_ENTROPY
@ WP_ID_ENTROPY
Definition: wavpack.h:75
WavpackFrameContext::ch
WvChannel ch[2]
Definition: wavpack.c:90
GetBitContext
Definition: get_bits.h:108
ff_wavpack_decoder
const FFCodec ff_wavpack_decoder
Definition: wavpack.c:1691
Modulation
Modulation
Definition: wavpack.c:63
val
static double val(void *priv, double ch)
Definition: aeval.c:78
type
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 type
Definition: writing_filters.txt:86
wavpack_decode_block
static int wavpack_decode_block(AVCodecContext *avctx, int block_no, const uint8_t *buf, int buf_size)
Definition: wavpack.c:1075
WavpackContext::curr_frame
ThreadFrame curr_frame
Definition: wavpack.c:111
MAX_BIN_BYTES
#define MAX_BIN_BYTES
Definition: wavpack.c:61
WV_DSD_DATA
#define WV_DSD_DATA
Definition: wavpack.h:41
refstruct.h
wp_log2
static av_always_inline int wp_log2(uint32_t val)
Definition: wavpack.h:150
MAX_HISTORY_BITS
#define MAX_HISTORY_BITS
Definition: wavpack.c:59
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:88
T
#define T(x)
Definition: vpx_arith.h:29
mult
static int16_t mult(Float11 *f1, Float11 *f2)
Definition: g726.c:60
Decorr::delta
int delta
Definition: wavpack.h:89
WavpackFrameContext::shift
int shift
Definition: wavpack.c:83
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
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:545
ff_thread_report_progress
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
Definition: pthread_frame.c:589
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:306
PRECISION
#define PRECISION
Definition: wavpack.c:53
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_GET_BUFFER_FLAG_REF
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:421
frame_size
int frame_size
Definition: mxfenc.c:2311
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
WP_ID_EXTRABITS
@ WP_ID_EXTRABITS
Definition: wavpack.h:82
wv_rates
static const int wv_rates[16]
Definition: wavpack.h:124
av_channel_layout_from_mask
FF_ENABLE_DEPRECATION_WARNINGS 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:399
GetByteContext::buffer
const uint8_t * buffer
Definition: bytestream.h:34
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
filters
#define filters(fmt, type, inverse, clp, inverset, clip, one, clip_fn, packed)
Definition: af_crystalizer.c:54
B
#define B
Definition: huffyuv.h:42
wp_exp2
static av_always_inline int wp_exp2(int16_t val)
Definition: wavpack.h:133
WavpackFrameContext::summed_probabilities
uint16_t summed_probabilities[MAX_HISTORY_BINS][256]
Definition: wavpack.c:95
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1517
ctx
AVFormatContext * ctx
Definition: movenc.c:48
Decorr::value
int value
Definition: wavpack.h:90
channels
channels
Definition: aptx.h:31
get_bits.h
WavpackFrameContext::hybrid
int hybrid
Definition: wavpack.c:85
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
frame
static AVFrame * frame
Definition: demux_decode.c:54
ff_thread_ref_frame
int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
Definition: utils.c:871
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:65
if
if(ret)
Definition: filter_design.txt:179
WavpackFrameContext::gb
GetBitContext gb
Definition: wavpack.c:74
AV_CODEC_CAP_FRAME_THREADS
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
Definition: codec.h:110
av_realloc_f
#define av_realloc_f(p, o, n)
Definition: tableprint_vlc.h:32
threadframe.h
wavpack_decode_frame
static int wavpack_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame_ptr, AVPacket *avpkt)
Definition: wavpack.c:1616
WV_FALSE_STEREO
#define WV_FALSE_STEREO
Definition: wavpack.h:40
NULL
#define NULL
Definition: coverity.c:32
WavpackFrameContext::hybrid_minclip
int hybrid_minclip
Definition: wavpack.c:86
DSD_BYTE_READY
#define DSD_BYTE_READY(low, high)
Definition: wavpack.c:43
WavpackContext::dsdctx
DSDContext * dsdctx
RefStruct reference.
Definition: wavpack.c:114
WavpackContext::fdec
WavpackFrameContext ** fdec
Definition: wavpack.c:103
WV_HEADER_SIZE
#define WV_HEADER_SIZE
Definition: wavpack.h:33
WV_SINGLE_BLOCK
#define WV_SINGLE_BLOCK
Definition: wavpack.h:52
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:388
VALUE_ONE
#define VALUE_ONE
Definition: wavpack.c:54
ff_thread_release_ext_buffer
void ff_thread_release_ext_buffer(ThreadFrame *f)
Unref a ThreadFrame.
Definition: pthread_frame.c:1012
bytestream2_get_buffer
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:267
ff_refstruct_allocz
static void * ff_refstruct_allocz(size_t size)
Equivalent to ff_refstruct_alloc_ext(size, 0, NULL, NULL)
Definition: refstruct.h:105
WavpackContext::ch_offset
int ch_offset
Definition: wavpack.c:108
UPDATE_THREAD_CONTEXT
#define UPDATE_THREAD_CONTEXT(func)
Definition: codec_internal.h:281
get_unary_0_33
static int get_unary_0_33(GetBitContext *gb)
Get unary code terminated by a 0 with a maximum length of 33.
Definition: unary.h:59
AV_EF_CRCCHECK
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
Definition: defs.h:48
exp
int8_t exp
Definition: eval.c:72
WavpackFrameContext::one
int one
Definition: wavpack.c:81
LEVEL_DECAY
#define LEVEL_DECAY(a)
Definition: wavpack.c:118
index
int index
Definition: gxfenc.c:89
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
wv_get_value_integer
static int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc, unsigned S)
Definition: wavpack.c:298
bytestream2_get_bytes_left
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:158
WavpackFrameContext::or
int or
Definition: wavpack.c:83
DSDfilters::value
int32_t value
Definition: wavpack.c:432
AV_CODEC_CAP_CHANNEL_CONF
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
Definition: codec.h:106
WavpackFrameContext::gbyte
GetByteContext gbyte
Definition: wavpack.c:92
ff_init_dsd_data
av_cold void ff_init_dsd_data(void)
Definition: dsd.c:89
f
f
Definition: af_crystalizer.c:121
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
AVPacket::size
int size
Definition: packet.h:492
av_frame_ref
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:361
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:307
codec_internal.h
shift
static int shift(int a, int b)
Definition: bonk.c:262
wv_check_crc
static int wv_check_crc(WavpackFrameContext *s, uint32_t crc, uint32_t crc_extra_bits)
Definition: wavpack.c:396
sp
#define sp
Definition: regdef.h:63
WavpackFrameContext::float_flag
int float_flag
Definition: wavpack.c:87
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1080
R2
#define R2
Definition: simple_idct.c:172
size
int size
Definition: twinvq_data.h:10344
FF_CODEC_CAP_ALLOCATE_PROGRESS
#define FF_CODEC_CAP_ALLOCATE_PROGRESS
Definition: codec_internal.h:69
WavpackFrameContext::crc_extra_bits
uint32_t crc_extra_bits
Definition: wavpack.c:76
DSDfilters
Definition: wavpack.c:431
WP_IDF_ODD
@ WP_IDF_ODD
Definition: wavpack.h:65
WavpackContext::block
int block
Definition: wavpack.c:106
DSDfilters::byte
unsigned int byte
Definition: wavpack.c:433
WavpackFrameContext::hybrid_maxclip
int hybrid_maxclip
Definition: wavpack.c:86
Decorr::samplesA
int samplesA[MAX_TERM]
Definition: wavpack.h:93
buffer.h
split
static char * split(char *message, char delim)
Definition: af_channelmap.c:81
RATE_S
#define RATE_S
Definition: wavpack.c:57
init_ptable
static void init_ptable(int *table, int rate_i, int rate_s)
Definition: wavpack.c:411
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:114
WP_ID_DECTERMS
@ WP_ID_DECTERMS
Definition: wavpack.h:72
WV_FLT_SHIFT_SENT
#define WV_FLT_SHIFT_SENT
Definition: wavpack.h:56
unary.h
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:64
av_channel_layout_compare
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
Definition: channel_layout.c:942
wv_unpack_stereo
static int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, void *dst_l, void *dst_r, const int type)
Definition: wavpack.c:772
av_channel_layout_default
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
Definition: channel_layout.c:972
wv_unpack_mono
static int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, void *dst, const int type)
Definition: wavpack.c:905
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:420
WavpackFrameContext::float_max_exp
int float_max_exp
Definition: wavpack.c:89
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
wavpack_decode_end
static av_cold int wavpack_decode_end(AVCodecContext *avctx)
Definition: wavpack.c:1055
WavpackContext::samples
int samples
Definition: wavpack.c:107
av_get_bytes_per_sample
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:108
WavpackFrameContext::samples
int samples
Definition: wavpack.c:78
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:401
get_tail
static av_always_inline unsigned get_tail(GetBitContext *gb, unsigned k)
Definition: wavpack.c:120
weights
static const int weights[]
Definition: hevc_pel.c:32
WavpackFrameContext::and
int and
Definition: wavpack.c:83
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
xf
#define xf(width, name, var, range_min, range_max, subs,...)
Definition: cbs_av1.c:590
av_always_inline
#define av_always_inline
Definition: attributes.h:49
value
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 default value
Definition: writing_filters.txt:86
PTABLE_BINS
#define PTABLE_BINS
Definition: wavpack.c:46
wavpack.h
WP_ID_CHANINFO
@ WP_ID_CHANINFO
Definition: wavpack.h:83
WV_FLT_SHIFT_SAME
#define WV_FLT_SHIFT_SAME
Definition: wavpack.h:55
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:254
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
update_thread_context
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have update_thread_context() run it in the next thread. Add AV_CODEC_CAP_FRAME_THREADS to the codec capabilities. There will be very little speed gain at this point but it should work. If there are inter-frame dependencies
WavpackFrameContext::zero
int zero
Definition: wavpack.c:81
UP
#define UP
Definition: wavpack.c:49
DSDContext
Per-channel buffer.
Definition: dsd.h:41
ff_thread_get_ext_buffer
int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around ff_get_buffer() for frame-multithreaded codecs.
Definition: pthread_frame.c:984
avcodec.h
ff_dsd2pcm_translate
void ff_dsd2pcm_translate(DSDContext *s, size_t samples, int lsbf, const uint8_t *src, ptrdiff_t src_stride, float *dst, ptrdiff_t dst_stride)
Definition: dsd.c:95
WavpackFrameContext::value_lookup_buffer
uint8_t value_lookup_buffer[MAX_HISTORY_BINS *MAX_BIN_BYTES]
Definition: wavpack.c:94
WP_ID_DECSAMPLES
@ WP_ID_DECSAMPLES
Definition: wavpack.h:74
ret
ret
Definition: filter_design.txt:187
wv_unpack_dsd_fast
static int wv_unpack_dsd_fast(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
Definition: wavpack.c:579
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
WavpackFrameContext::zeroes
int zeroes
Definition: wavpack.c:81
GET_MED
#define GET_MED(n)
Definition: wavpack.h:106
ff_refstruct_replace
void ff_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
Definition: refstruct.c:156
pos
unsigned int pos
Definition: spdifenc.c:413
DOWN
#define DOWN
Definition: wavpack.c:50
ff_thread_finish_setup
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call ff_thread_finish_setup() afterwards. If some code can 't be moved
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
WV_FLT_ZERO_SENT
#define WV_FLT_ZERO_SENT
Definition: wavpack.h:57
id
enum AVCodecID id
Definition: dts2pts_bsf.c:364
WavpackFrameContext::gb_extra_bits
GetBitContext gb_extra_bits
Definition: wavpack.c:77
WavpackFrameContext::terms
int terms
Definition: wavpack.c:79
WavpackContext::modulation
Modulation modulation
Definition: wavpack.c:112
WavpackFrameContext
Definition: wavpack.c:68
wavpack_decode_init
static av_cold int wavpack_decode_init(AVCodecContext *avctx)
Definition: wavpack.c:1036
AVCodecContext
main external API structure.
Definition: avcodec.h:441
ThreadFrame
Definition: threadframe.h:27
WavpackFrameContext::stereo_in
int stereo_in
Definition: wavpack.c:71
channel_layout.h
t2
#define t2
Definition: regdef.h:30
UPDATE_WEIGHT_CLIP
#define UPDATE_WEIGHT_CLIP(weight, delta, samples, in)
Definition: wavpack.h:111
wv_get_value
static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb, int channel, int *last)
Definition: wavpack.c:172
WavpackFrameContext::ptable
int ptable[PTABLE_BINS]
Definition: wavpack.c:93
WavpackFrameContext::hybrid_bitrate
int hybrid_bitrate
Definition: wavpack.c:85
Decorr::weightB
int weightB
Definition: wavpack.h:92
wv_get_value_float
static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S)
Definition: wavpack.c:322
L
#define L(x)
Definition: vpx_arith.h:36
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
factor
static const int factor[16]
Definition: vf_pp7.c:78
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:647
WV_HYBRID_MODE
#define WV_HYBRID_MODE
Definition: wavpack.h:43
INC_MED
#define INC_MED(n)
Definition: wavpack.h:108
wv_alloc_frame_context
static av_cold int wv_alloc_frame_context(WavpackContext *c)
Definition: wavpack.c:974
DEC_MED
#define DEC_MED(n)
Definition: wavpack.h:107
PTABLE_MASK
#define PTABLE_MASK
Definition: wavpack.c:47
WavpackFrameContext::probabilities
uint8_t probabilities[MAX_HISTORY_BINS][256]
Definition: wavpack.c:96
WV_JOINT_STEREO
#define WV_JOINT_STEREO
Definition: wavpack.h:36
WavpackFrameContext::frame_flags
int frame_flags
Definition: wavpack.c:70
AVPacket
This structure stores compressed data.
Definition: packet.h:468
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:468
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
WavpackFrameContext::extra_bits
int extra_bits
Definition: wavpack.c:82
int32_t
int32_t
Definition: audioconvert.c:56
bytestream.h
bytestream2_init
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
WavpackFrameContext::avctx
AVCodecContext * avctx
Definition: wavpack.c:69
AV_CODEC_ID_WAVPACK
@ AV_CODEC_ID_WAVPACK
Definition: codec_id.h:467
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
WP_ID_INT32INFO
@ WP_ID_INT32INFO
Definition: wavpack.h:79
wv_dsd_reset
static int wv_dsd_reset(WavpackContext *s, int channels)
Definition: wavpack.c:989
WavpackFrameContext::value_lookup
uint8_t * value_lookup[MAX_HISTORY_BINS]
Definition: wavpack.c:97
WavpackFrameContext::float_shift
int float_shift
Definition: wavpack.c:88
int
int
Definition: ffmpeg_filter.c:368
AVCodecContext::execute2
int(* execute2)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count)
The codec may call this to execute several independent things.
Definition: avcodec.h:1581
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
Decorr::samplesB
int samplesB[MAX_TERM]
Definition: wavpack.h:94
ff_refstruct_unref
void ff_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:116
channel
channel
Definition: ebur128.h:39
WavpackContext::dsd_channels
int dsd_channels
Definition: wavpack.c:115
WP_IDF_MASK
@ WP_IDF_MASK
Definition: wavpack.h:63
dsd_channel
static int dsd_channel(AVCodecContext *avctx, void *frmptr, int jobnr, int threadnr)
Definition: wavpack.c:1604