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  WavpackFrameContext **fdec = av_realloc_array(c->fdec, c->fdec_num + 1, sizeof(*c->fdec));
977 
978  if (!fdec)
979  return -1;
980  c->fdec = fdec;
981 
982  c->fdec[c->fdec_num] = av_mallocz(sizeof(**c->fdec));
983  if (!c->fdec[c->fdec_num])
984  return -1;
985  c->fdec_num++;
986  c->fdec[c->fdec_num - 1]->avctx = c->avctx;
987 
988  return 0;
989 }
990 
992 {
993  int i;
994 
995  s->dsd_channels = 0;
996  ff_refstruct_unref(&s->dsdctx);
997 
998  if (!channels)
999  return 0;
1000 
1001  if (channels > INT_MAX / sizeof(*s->dsdctx))
1002  return AVERROR(EINVAL);
1003 
1004  s->dsdctx = ff_refstruct_allocz(channels * sizeof(*s->dsdctx));
1005  if (!s->dsdctx)
1006  return AVERROR(ENOMEM);
1007  s->dsd_channels = channels;
1008 
1009  for (i = 0; i < channels; i++)
1010  memset(s->dsdctx[i].buf, 0x69, sizeof(s->dsdctx[i].buf));
1011 
1012  return 0;
1013 }
1014 
1015 #if HAVE_THREADS
1016 static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
1017 {
1018  WavpackContext *fsrc = src->priv_data;
1019  WavpackContext *fdst = dst->priv_data;
1020  int ret;
1021 
1022  if (dst == src)
1023  return 0;
1024 
1026  if (fsrc->curr_frame.f->data[0]) {
1027  if ((ret = ff_thread_ref_frame(&fdst->curr_frame, &fsrc->curr_frame)) < 0)
1028  return ret;
1029  }
1030 
1031  ff_refstruct_replace(&fdst->dsdctx, fsrc->dsdctx);
1032  fdst->dsd_channels = fsrc->dsd_channels;
1033 
1034  return 0;
1035 }
1036 #endif
1037 
1039 {
1040  WavpackContext *s = avctx->priv_data;
1041 
1042  s->avctx = avctx;
1043 
1044  s->fdec_num = 0;
1045 
1046  s->curr_frame.f = av_frame_alloc();
1047  s->prev_frame.f = av_frame_alloc();
1048 
1049  if (!s->curr_frame.f || !s->prev_frame.f)
1050  return AVERROR(ENOMEM);
1051 
1052  ff_init_dsd_data();
1053 
1054  return 0;
1055 }
1056 
1058 {
1059  WavpackContext *s = avctx->priv_data;
1060 
1061  for (int i = 0; i < s->fdec_num; i++)
1062  av_freep(&s->fdec[i]);
1063  av_freep(&s->fdec);
1064  s->fdec_num = 0;
1065 
1066  ff_thread_release_ext_buffer(&s->curr_frame);
1067  av_frame_free(&s->curr_frame.f);
1068 
1069  ff_thread_release_ext_buffer(&s->prev_frame);
1070  av_frame_free(&s->prev_frame.f);
1071 
1072  ff_refstruct_unref(&s->dsdctx);
1073 
1074  return 0;
1075 }
1076 
1077 static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
1078  const uint8_t *buf, int buf_size)
1079 {
1080  WavpackContext *wc = avctx->priv_data;
1082  GetByteContext gb;
1083  enum AVSampleFormat sample_fmt;
1084  void *samples_l = NULL, *samples_r = NULL;
1085  int ret;
1086  int got_terms = 0, got_weights = 0, got_samples = 0,
1087  got_entropy = 0, got_pcm = 0, got_float = 0, got_hybrid = 0;
1088  int got_dsd = 0;
1089  int i, j, id, size, ssize, weights, t;
1090  int bpp, chan = 0, orig_bpp, sample_rate = 0, rate_x = 1, dsd_mode = 0;
1091  int multiblock;
1092  uint64_t chmask = 0;
1093 
1094  if (block_no >= wc->fdec_num && wv_alloc_frame_context(wc) < 0) {
1095  av_log(avctx, AV_LOG_ERROR, "Error creating frame decode context\n");
1096  return AVERROR_INVALIDDATA;
1097  }
1098 
1099  s = wc->fdec[block_no];
1100 
1101  memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr));
1102  memset(s->ch, 0, sizeof(s->ch));
1103  s->extra_bits = 0;
1104  s->and = s->or = s->shift = 0;
1105  s->got_extra_bits = 0;
1106 
1107  bytestream2_init(&gb, buf, buf_size);
1108 
1109  s->samples = bytestream2_get_le32(&gb);
1110  if (s->samples != wc->samples) {
1111  av_log(avctx, AV_LOG_ERROR, "Mismatching number of samples in "
1112  "a sequence: %d and %d\n", wc->samples, s->samples);
1113  return AVERROR_INVALIDDATA;
1114  }
1115  s->frame_flags = bytestream2_get_le32(&gb);
1116 
1117  if (s->frame_flags & (WV_FLOAT_DATA | WV_DSD_DATA))
1118  sample_fmt = AV_SAMPLE_FMT_FLTP;
1119  else if ((s->frame_flags & 0x03) <= 1)
1120  sample_fmt = AV_SAMPLE_FMT_S16P;
1121  else
1122  sample_fmt = AV_SAMPLE_FMT_S32P;
1123 
1124  if (wc->ch_offset && avctx->sample_fmt != sample_fmt)
1125  return AVERROR_INVALIDDATA;
1126 
1127  bpp = av_get_bytes_per_sample(sample_fmt);
1128  orig_bpp = ((s->frame_flags & 0x03) + 1) << 3;
1129  multiblock = (s->frame_flags & WV_SINGLE_BLOCK) != WV_SINGLE_BLOCK;
1130 
1131  s->stereo = !(s->frame_flags & WV_MONO);
1132  s->stereo_in = (s->frame_flags & WV_FALSE_STEREO) ? 0 : s->stereo;
1133  s->joint = s->frame_flags & WV_JOINT_STEREO;
1134  s->hybrid = s->frame_flags & WV_HYBRID_MODE;
1135  s->hybrid_bitrate = s->frame_flags & WV_HYBRID_BITRATE;
1136  s->post_shift = bpp * 8 - orig_bpp + ((s->frame_flags >> 13) & 0x1f);
1137  if (s->post_shift < 0 || s->post_shift > 31) {
1138  return AVERROR_INVALIDDATA;
1139  }
1140  s->hybrid_maxclip = ((1LL << (orig_bpp - 1)) - 1);
1141  s->hybrid_minclip = ((-1UL << (orig_bpp - 1)));
1142  s->CRC = bytestream2_get_le32(&gb);
1143 
1144  // parse metadata blocks
1145  while (bytestream2_get_bytes_left(&gb)) {
1146  id = bytestream2_get_byte(&gb);
1147  size = bytestream2_get_byte(&gb);
1148  if (id & WP_IDF_LONG)
1149  size |= (bytestream2_get_le16u(&gb)) << 8;
1150  size <<= 1; // size is specified in words
1151  ssize = size;
1152  if (id & WP_IDF_ODD)
1153  size--;
1154  if (size < 0) {
1155  av_log(avctx, AV_LOG_ERROR,
1156  "Got incorrect block %02X with size %i\n", id, size);
1157  break;
1158  }
1159  if (bytestream2_get_bytes_left(&gb) < ssize) {
1160  av_log(avctx, AV_LOG_ERROR,
1161  "Block size %i is out of bounds\n", size);
1162  break;
1163  }
1164  switch (id & WP_IDF_MASK) {
1165  case WP_ID_DECTERMS:
1166  if (size > MAX_TERMS) {
1167  av_log(avctx, AV_LOG_ERROR, "Too many decorrelation terms\n");
1168  s->terms = 0;
1169  bytestream2_skip(&gb, ssize);
1170  continue;
1171  }
1172  s->terms = size;
1173  for (i = 0; i < s->terms; i++) {
1174  uint8_t val = bytestream2_get_byte(&gb);
1175  s->decorr[s->terms - i - 1].value = (val & 0x1F) - 5;
1176  s->decorr[s->terms - i - 1].delta = val >> 5;
1177  }
1178  got_terms = 1;
1179  break;
1180  case WP_ID_DECWEIGHTS:
1181  if (!got_terms) {
1182  av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
1183  continue;
1184  }
1185  weights = size >> s->stereo_in;
1186  if (weights > MAX_TERMS || weights > s->terms) {
1187  av_log(avctx, AV_LOG_ERROR, "Too many decorrelation weights\n");
1188  bytestream2_skip(&gb, ssize);
1189  continue;
1190  }
1191  for (i = 0; i < weights; i++) {
1192  t = (int8_t)bytestream2_get_byte(&gb);
1193  s->decorr[s->terms - i - 1].weightA = t * (1 << 3);
1194  if (s->decorr[s->terms - i - 1].weightA > 0)
1195  s->decorr[s->terms - i - 1].weightA +=
1196  (s->decorr[s->terms - i - 1].weightA + 64) >> 7;
1197  if (s->stereo_in) {
1198  t = (int8_t)bytestream2_get_byte(&gb);
1199  s->decorr[s->terms - i - 1].weightB = t * (1 << 3);
1200  if (s->decorr[s->terms - i - 1].weightB > 0)
1201  s->decorr[s->terms - i - 1].weightB +=
1202  (s->decorr[s->terms - i - 1].weightB + 64) >> 7;
1203  }
1204  }
1205  got_weights = 1;
1206  break;
1207  case WP_ID_DECSAMPLES:
1208  if (!got_terms) {
1209  av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
1210  continue;
1211  }
1212  t = 0;
1213  for (i = s->terms - 1; (i >= 0) && (t < size); i--) {
1214  Decorr *decorr = &s->decorr[i];
1215 
1216  if (decorr->value > 8) {
1217  decorr->samplesA[0] =
1218  wp_exp2(bytestream2_get_le16(&gb));
1219  decorr->samplesA[1] =
1220  wp_exp2(bytestream2_get_le16(&gb));
1221 
1222  if (s->stereo_in) {
1223  decorr->samplesB[0] =
1224  wp_exp2(bytestream2_get_le16(&gb));
1225  decorr->samplesB[1] =
1226  wp_exp2(bytestream2_get_le16(&gb));
1227  t += 4;
1228  }
1229  t += 4;
1230  } else if (decorr->value < 0) {
1231  decorr->samplesA[0] =
1232  wp_exp2(bytestream2_get_le16(&gb));
1233  decorr->samplesB[0] =
1234  wp_exp2(bytestream2_get_le16(&gb));
1235  t += 4;
1236  } else {
1237  for (j = 0; j < decorr->value; j++) {
1238  decorr->samplesA[j] =
1239  wp_exp2(bytestream2_get_le16(&gb));
1240  if (s->stereo_in) {
1241  decorr->samplesB[j] =
1242  wp_exp2(bytestream2_get_le16(&gb));
1243  }
1244  }
1245  t += decorr->value * 2 * (s->stereo_in + 1);
1246  }
1247  }
1248  got_samples = 1;
1249  break;
1250  case WP_ID_ENTROPY:
1251  if (size != 6 * (s->stereo_in + 1)) {
1252  av_log(avctx, AV_LOG_ERROR,
1253  "Entropy vars size should be %i, got %i.\n",
1254  6 * (s->stereo_in + 1), size);
1255  bytestream2_skip(&gb, ssize);
1256  continue;
1257  }
1258  for (j = 0; j <= s->stereo_in; j++)
1259  for (i = 0; i < 3; i++) {
1260  s->ch[j].median[i] = wp_exp2(bytestream2_get_le16(&gb));
1261  }
1262  got_entropy = 1;
1263  break;
1264  case WP_ID_HYBRID:
1265  if (s->hybrid_bitrate) {
1266  for (i = 0; i <= s->stereo_in; i++) {
1267  s->ch[i].slow_level = wp_exp2(bytestream2_get_le16(&gb));
1268  size -= 2;
1269  }
1270  }
1271  for (i = 0; i < (s->stereo_in + 1); i++) {
1272  s->ch[i].bitrate_acc = bytestream2_get_le16(&gb) << 16;
1273  size -= 2;
1274  }
1275  if (size > 0) {
1276  for (i = 0; i < (s->stereo_in + 1); i++) {
1277  s->ch[i].bitrate_delta =
1278  wp_exp2((int16_t)bytestream2_get_le16(&gb));
1279  }
1280  } else {
1281  for (i = 0; i < (s->stereo_in + 1); i++)
1282  s->ch[i].bitrate_delta = 0;
1283  }
1284  got_hybrid = 1;
1285  break;
1286  case WP_ID_INT32INFO: {
1287  uint8_t val[4];
1288  if (size != 4) {
1289  av_log(avctx, AV_LOG_ERROR,
1290  "Invalid INT32INFO, size = %i\n",
1291  size);
1292  bytestream2_skip(&gb, ssize - 4);
1293  continue;
1294  }
1295  bytestream2_get_buffer(&gb, val, 4);
1296  if (val[0] > 30) {
1297  av_log(avctx, AV_LOG_ERROR,
1298  "Invalid INT32INFO, extra_bits = %d (> 30)\n", val[0]);
1299  continue;
1300  } else {
1301  s->extra_bits = val[0];
1302  }
1303  if (val[1])
1304  s->shift = val[1];
1305  if (val[2]) {
1306  s->and = s->or = 1;
1307  s->shift = val[2];
1308  }
1309  if (val[3]) {
1310  s->and = 1;
1311  s->shift = val[3];
1312  }
1313  if (s->shift > 31) {
1314  av_log(avctx, AV_LOG_ERROR,
1315  "Invalid INT32INFO, shift = %d (> 31)\n", s->shift);
1316  s->and = s->or = s->shift = 0;
1317  continue;
1318  }
1319  /* original WavPack decoder forces 32-bit lossy sound to be treated
1320  * as 24-bit one in order to have proper clipping */
1321  if (s->hybrid && bpp == 4 && s->post_shift < 8 && s->shift > 8) {
1322  s->post_shift += 8;
1323  s->shift -= 8;
1324  s->hybrid_maxclip >>= 8;
1325  s->hybrid_minclip >>= 8;
1326  }
1327  break;
1328  }
1329  case WP_ID_FLOATINFO:
1330  if (size != 4) {
1331  av_log(avctx, AV_LOG_ERROR,
1332  "Invalid FLOATINFO, size = %i\n", size);
1333  bytestream2_skip(&gb, ssize);
1334  continue;
1335  }
1336  s->float_flag = bytestream2_get_byte(&gb);
1337  s->float_shift = bytestream2_get_byte(&gb);
1338  s->float_max_exp = bytestream2_get_byte(&gb);
1339  if (s->float_shift > 31) {
1340  av_log(avctx, AV_LOG_ERROR,
1341  "Invalid FLOATINFO, shift = %d (> 31)\n", s->float_shift);
1342  s->float_shift = 0;
1343  continue;
1344  }
1345  got_float = 1;
1346  bytestream2_skip(&gb, 1);
1347  break;
1348  case WP_ID_DATA:
1349  if ((ret = init_get_bits8(&s->gb, gb.buffer, size)) < 0)
1350  return ret;
1351  bytestream2_skip(&gb, size);
1352  got_pcm = 1;
1353  break;
1354  case WP_ID_DSD_DATA:
1355  if (size < 2) {
1356  av_log(avctx, AV_LOG_ERROR, "Invalid DSD_DATA, size = %i\n",
1357  size);
1358  bytestream2_skip(&gb, ssize);
1359  continue;
1360  }
1361  rate_x = bytestream2_get_byte(&gb);
1362  if (rate_x > 30)
1363  return AVERROR_INVALIDDATA;
1364  rate_x = 1 << rate_x;
1365  dsd_mode = bytestream2_get_byte(&gb);
1366  if (dsd_mode && dsd_mode != 1 && dsd_mode != 3) {
1367  av_log(avctx, AV_LOG_ERROR, "Invalid DSD encoding mode: %d\n",
1368  dsd_mode);
1369  return AVERROR_INVALIDDATA;
1370  }
1371  bytestream2_init(&s->gbyte, gb.buffer, size-2);
1372  bytestream2_skip(&gb, size-2);
1373  got_dsd = 1;
1374  break;
1375  case WP_ID_EXTRABITS:
1376  if (size <= 4) {
1377  av_log(avctx, AV_LOG_ERROR, "Invalid EXTRABITS, size = %i\n",
1378  size);
1379  bytestream2_skip(&gb, size);
1380  continue;
1381  }
1382  if ((ret = init_get_bits8(&s->gb_extra_bits, gb.buffer, size)) < 0)
1383  return ret;
1384  s->crc_extra_bits = get_bits_long(&s->gb_extra_bits, 32);
1385  bytestream2_skip(&gb, size);
1386  s->got_extra_bits = 1;
1387  break;
1388  case WP_ID_CHANINFO:
1389  if (size <= 1) {
1390  av_log(avctx, AV_LOG_ERROR,
1391  "Insufficient channel information\n");
1392  return AVERROR_INVALIDDATA;
1393  }
1394  chan = bytestream2_get_byte(&gb);
1395  switch (size - 2) {
1396  case 0:
1397  chmask = bytestream2_get_byte(&gb);
1398  break;
1399  case 1:
1400  chmask = bytestream2_get_le16(&gb);
1401  break;
1402  case 2:
1403  chmask = bytestream2_get_le24(&gb);
1404  break;
1405  case 3:
1406  chmask = bytestream2_get_le32(&gb);
1407  break;
1408  case 4:
1409  size = bytestream2_get_byte(&gb);
1410  chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
1411  chan += 1;
1412  chmask = bytestream2_get_le24(&gb);
1413  break;
1414  case 5:
1415  size = bytestream2_get_byte(&gb);
1416  chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
1417  chan += 1;
1418  chmask = bytestream2_get_le32(&gb);
1419  break;
1420  default:
1421  av_log(avctx, AV_LOG_ERROR, "Invalid channel info size %d\n",
1422  size);
1423  }
1424  break;
1425  case WP_ID_SAMPLE_RATE:
1426  if (size != 3) {
1427  av_log(avctx, AV_LOG_ERROR, "Invalid custom sample rate.\n");
1428  return AVERROR_INVALIDDATA;
1429  }
1430  sample_rate = bytestream2_get_le24(&gb);
1431  break;
1432  default:
1433  bytestream2_skip(&gb, size);
1434  }
1435  if (id & WP_IDF_ODD)
1436  bytestream2_skip(&gb, 1);
1437  }
1438 
1439  if (got_pcm) {
1440  if (!got_terms) {
1441  av_log(avctx, AV_LOG_ERROR, "No block with decorrelation terms\n");
1442  return AVERROR_INVALIDDATA;
1443  }
1444  if (!got_weights) {
1445  av_log(avctx, AV_LOG_ERROR, "No block with decorrelation weights\n");
1446  return AVERROR_INVALIDDATA;
1447  }
1448  if (!got_samples) {
1449  av_log(avctx, AV_LOG_ERROR, "No block with decorrelation samples\n");
1450  return AVERROR_INVALIDDATA;
1451  }
1452  if (!got_entropy) {
1453  av_log(avctx, AV_LOG_ERROR, "No block with entropy info\n");
1454  return AVERROR_INVALIDDATA;
1455  }
1456  if (s->hybrid && !got_hybrid) {
1457  av_log(avctx, AV_LOG_ERROR, "Hybrid config not found\n");
1458  return AVERROR_INVALIDDATA;
1459  }
1460  if (!got_float && sample_fmt == AV_SAMPLE_FMT_FLTP) {
1461  av_log(avctx, AV_LOG_ERROR, "Float information not found\n");
1462  return AVERROR_INVALIDDATA;
1463  }
1464  if (s->got_extra_bits && sample_fmt != AV_SAMPLE_FMT_FLTP) {
1465  const int size = get_bits_left(&s->gb_extra_bits);
1466  const int wanted = s->samples * s->extra_bits << s->stereo_in;
1467  if (size < wanted) {
1468  av_log(avctx, AV_LOG_ERROR, "Too small EXTRABITS\n");
1469  s->got_extra_bits = 0;
1470  }
1471  }
1472  }
1473 
1474  if (!got_pcm && !got_dsd) {
1475  av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n");
1476  return AVERROR_INVALIDDATA;
1477  }
1478 
1479  if ((got_pcm && wc->modulation != MODULATION_PCM) ||
1480  (got_dsd && wc->modulation != MODULATION_DSD)) {
1481  av_log(avctx, AV_LOG_ERROR, "Invalid PCM/DSD mix encountered\n");
1482  return AVERROR_INVALIDDATA;
1483  }
1484 
1485  if (!wc->ch_offset) {
1486  AVChannelLayout new_ch_layout = { 0 };
1487  int new_samplerate;
1488  int sr = (s->frame_flags >> 23) & 0xf;
1489  if (sr == 0xf) {
1490  if (!sample_rate) {
1491  av_log(avctx, AV_LOG_ERROR, "Custom sample rate missing.\n");
1492  return AVERROR_INVALIDDATA;
1493  }
1494  new_samplerate = sample_rate;
1495  } else
1496  new_samplerate = wv_rates[sr];
1497 
1498  if (new_samplerate * (uint64_t)rate_x > INT_MAX)
1499  return AVERROR_INVALIDDATA;
1500  new_samplerate *= rate_x;
1501 
1502  if (multiblock) {
1503  if (chmask) {
1504  av_channel_layout_from_mask(&new_ch_layout, chmask);
1505  if (chan && new_ch_layout.nb_channels != chan) {
1506  av_log(avctx, AV_LOG_ERROR, "Channel mask does not match the channel count\n");
1507  return AVERROR_INVALIDDATA;
1508  }
1509  } else {
1510  av_channel_layout_default(&new_ch_layout, chan);
1511  }
1512  } else {
1513  av_channel_layout_default(&new_ch_layout, s->stereo + 1);
1514  }
1515 
1516  /* clear DSD state if stream properties change */
1517  if (new_ch_layout.nb_channels != wc->dsd_channels ||
1518  av_channel_layout_compare(&new_ch_layout, &avctx->ch_layout) ||
1519  new_samplerate != avctx->sample_rate ||
1520  !!got_dsd != !!wc->dsdctx) {
1521  ret = wv_dsd_reset(wc, got_dsd ? new_ch_layout.nb_channels : 0);
1522  if (ret < 0) {
1523  av_log(avctx, AV_LOG_ERROR, "Error reinitializing the DSD context\n");
1524  return ret;
1525  }
1527  }
1528  av_channel_layout_copy(&avctx->ch_layout, &new_ch_layout);
1529  avctx->sample_rate = new_samplerate;
1530  avctx->sample_fmt = sample_fmt;
1531  avctx->bits_per_raw_sample = orig_bpp;
1532 
1535 
1536  /* get output buffer */
1537  wc->curr_frame.f->nb_samples = s->samples;
1538  ret = ff_thread_get_ext_buffer(avctx, &wc->curr_frame,
1540  if (ret < 0)
1541  return ret;
1542 
1543  wc->frame = wc->curr_frame.f;
1544  ff_thread_finish_setup(avctx);
1545  }
1546 
1547  if (wc->ch_offset + s->stereo >= avctx->ch_layout.nb_channels) {
1548  av_log(avctx, AV_LOG_WARNING, "Too many channels coded in a packet.\n");
1549  return ((avctx->err_recognition & AV_EF_EXPLODE) || !wc->ch_offset) ? AVERROR_INVALIDDATA : 0;
1550  }
1551 
1552  samples_l = wc->frame->extended_data[wc->ch_offset];
1553  if (s->stereo)
1554  samples_r = wc->frame->extended_data[wc->ch_offset + 1];
1555 
1556  wc->ch_offset += 1 + s->stereo;
1557 
1558  if (s->stereo_in) {
1559  if (got_dsd) {
1560  if (dsd_mode == 3) {
1561  ret = wv_unpack_dsd_high(s, samples_l, samples_r);
1562  } else if (dsd_mode == 1) {
1563  ret = wv_unpack_dsd_fast(s, samples_l, samples_r);
1564  } else {
1565  ret = wv_unpack_dsd_copy(s, samples_l, samples_r);
1566  }
1567  } else {
1568  ret = wv_unpack_stereo(s, &s->gb, samples_l, samples_r, avctx->sample_fmt);
1569  }
1570  if (ret < 0)
1571  return ret;
1572  } else {
1573  if (got_dsd) {
1574  if (dsd_mode == 3) {
1575  ret = wv_unpack_dsd_high(s, samples_l, NULL);
1576  } else if (dsd_mode == 1) {
1577  ret = wv_unpack_dsd_fast(s, samples_l, NULL);
1578  } else {
1579  ret = wv_unpack_dsd_copy(s, samples_l, NULL);
1580  }
1581  } else {
1582  ret = wv_unpack_mono(s, &s->gb, samples_l, avctx->sample_fmt);
1583  }
1584  if (ret < 0)
1585  return ret;
1586 
1587  if (s->stereo)
1588  memcpy(samples_r, samples_l, bpp * s->samples);
1589  }
1590 
1591  return 0;
1592 }
1593 
1595 {
1596  WavpackContext *s = avctx->priv_data;
1597 
1598  wv_dsd_reset(s, 0);
1599 }
1600 
1601 static int dsd_channel(AVCodecContext *avctx, void *frmptr, int jobnr, int threadnr)
1602 {
1603  const WavpackContext *s = avctx->priv_data;
1604  AVFrame *frame = frmptr;
1605 
1606  ff_dsd2pcm_translate (&s->dsdctx [jobnr], s->samples, 0,
1607  (uint8_t *)frame->extended_data[jobnr], 4,
1608  (float *)frame->extended_data[jobnr], 1);
1609 
1610  return 0;
1611 }
1612 
1613 static int wavpack_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
1614  int *got_frame_ptr, AVPacket *avpkt)
1615 {
1616  WavpackContext *s = avctx->priv_data;
1617  const uint8_t *buf = avpkt->data;
1618  int buf_size = avpkt->size;
1619  int frame_size, ret, frame_flags;
1620 
1621  if (avpkt->size <= WV_HEADER_SIZE)
1622  return AVERROR_INVALIDDATA;
1623 
1624  s->frame = NULL;
1625  s->block = 0;
1626  s->ch_offset = 0;
1627 
1628  /* determine number of samples */
1629  s->samples = AV_RL32(buf + 20);
1630  frame_flags = AV_RL32(buf + 24);
1631  if (s->samples <= 0 || s->samples > WV_MAX_SAMPLES) {
1632  av_log(avctx, AV_LOG_ERROR, "Invalid number of samples: %d\n",
1633  s->samples);
1634  return AVERROR_INVALIDDATA;
1635  }
1636 
1637  s->modulation = (frame_flags & WV_DSD_DATA) ? MODULATION_DSD : MODULATION_PCM;
1638 
1639  while (buf_size > WV_HEADER_SIZE) {
1640  frame_size = AV_RL32(buf + 4) - 12;
1641  buf += 20;
1642  buf_size -= 20;
1643  if (frame_size <= 0 || frame_size > buf_size) {
1644  av_log(avctx, AV_LOG_ERROR,
1645  "Block %d has invalid size (size %d vs. %d bytes left)\n",
1646  s->block, frame_size, buf_size);
1648  goto error;
1649  }
1650  if ((ret = wavpack_decode_block(avctx, s->block, buf, frame_size)) < 0)
1651  goto error;
1652  s->block++;
1653  buf += frame_size;
1654  buf_size -= frame_size;
1655  }
1656 
1657  if (s->ch_offset != avctx->ch_layout.nb_channels) {
1658  av_log(avctx, AV_LOG_ERROR, "Not enough channels coded in a packet.\n");
1660  goto error;
1661  }
1662 
1663  ff_thread_await_progress(&s->prev_frame, INT_MAX, 0);
1664  ff_thread_release_ext_buffer(&s->prev_frame);
1665 
1666  if (s->modulation == MODULATION_DSD)
1667  avctx->execute2(avctx, dsd_channel, s->frame, NULL, avctx->ch_layout.nb_channels);
1668 
1669  ff_thread_report_progress(&s->curr_frame, INT_MAX, 0);
1670 
1671  if ((ret = av_frame_ref(rframe, s->frame)) < 0)
1672  return ret;
1673 
1674  *got_frame_ptr = 1;
1675 
1676  return avpkt->size;
1677 
1678 error:
1679  if (s->frame) {
1680  ff_thread_await_progress(&s->prev_frame, INT_MAX, 0);
1681  ff_thread_release_ext_buffer(&s->prev_frame);
1682  ff_thread_report_progress(&s->curr_frame, INT_MAX, 0);
1683  }
1684 
1685  return ret;
1686 }
1687 
1689  .p.name = "wavpack",
1690  CODEC_LONG_NAME("WavPack"),
1691  .p.type = AVMEDIA_TYPE_AUDIO,
1692  .p.id = AV_CODEC_ID_WAVPACK,
1693  .priv_data_size = sizeof(WavpackContext),
1695  .close = wavpack_decode_end,
1697  .flush = wavpack_decode_flush,
1699  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
1701  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
1703 };
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:98
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:695
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
WP_ID_HYBRID
@ WP_ID_HYBRID
Definition: wavpack.h:76
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1050
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:1420
wavpack_decode_flush
static void wavpack_decode_flush(AVCodecContext *avctx)
Definition: wavpack.c:1594
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:130
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:344
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:522
WavpackFrameContext::post_shift
int post_shift
Definition: wavpack.c:84
WV_MONO
@ WV_MONO
Definition: wvdec.c:33
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:313
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:409
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:365
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:1065
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:1688
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:1077
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:118
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:573
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:287
PRECISION
#define PRECISION
Definition: wavpack.c:53
s
#define s(width, name)
Definition: cbs_vp9.c:198
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:215
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:425
frame_size
int frame_size
Definition: mxfenc.c:2422
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
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:242
GetByteContext::buffer
const uint8_t * buffer
Definition: bytestream.h:34
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:1574
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:850
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
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
threadframe.h
wavpack_decode_frame
static int wavpack_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame_ptr, AVPacket *avpkt)
Definition: wavpack.c:1613
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:996
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:74
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
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:365
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:523
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:354
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:303
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:1057
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:80
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:800
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:830
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:424
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:1057
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:405
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:968
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:160
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
id
enum AVCodecID id
Definition: dts2pts.c:364
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
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:1038
AVCodecContext
main external API structure.
Definition: avcodec.h:445
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:439
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:499
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:472
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:465
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:991
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:409
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:1631
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:120
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:1601