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 "thread.h"
32 #include "threadframe.h"
33 #include "unary.h"
34 #include "wavpack.h"
35 #include "dsd.h"
36 
37 /**
38  * @file
39  * WavPack lossless audio decoder
40  */
41 
42 #define DSD_BYTE_READY(low,high) (!(((low) ^ (high)) & 0xff000000))
43 
44 #define PTABLE_BITS 8
45 #define PTABLE_BINS (1<<PTABLE_BITS)
46 #define PTABLE_MASK (PTABLE_BINS-1)
47 
48 #define UP 0x010000fe
49 #define DOWN 0x00010000
50 #define DECAY 8
51 
52 #define PRECISION 20
53 #define VALUE_ONE (1 << PRECISION)
54 #define PRECISION_USE 12
55 
56 #define RATE_S 20
57 
58 #define MAX_HISTORY_BITS 5
59 #define MAX_HISTORY_BINS (1 << MAX_HISTORY_BITS)
60 #define MAX_BIN_BYTES 1280 // for value_lookup, per bin (2k - 512 - 256)
61 
62 typedef enum {
63  MODULATION_PCM, // pulse code modulation
64  MODULATION_DSD // pulse density modulation (aka DSD)
65 } Modulation;
66 
67 typedef struct WavpackFrameContext {
71  int joint;
72  uint32_t CRC;
75  uint32_t crc_extra_bits;
77  int samples;
78  int terms;
80  int zero, one, zeroes;
82  int and, or, shift;
90 
98 
99 typedef struct WavpackContext {
101 
103  int fdec_num;
104 
105  int block;
106  int samples;
108 
112 
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->dsdctx = NULL;
994  s->dsd_channels = 0;
995  av_buffer_unref(&s->dsd_ref);
996 
997  if (!channels)
998  return 0;
999 
1000  if (channels > INT_MAX / sizeof(*s->dsdctx))
1001  return AVERROR(EINVAL);
1002 
1003  s->dsd_ref = av_buffer_allocz(channels * sizeof(*s->dsdctx));
1004  if (!s->dsd_ref)
1005  return AVERROR(ENOMEM);
1006  s->dsdctx = (DSDContext*)s->dsd_ref->data;
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  fdst->dsdctx = NULL;
1032  fdst->dsd_channels = 0;
1033  ret = av_buffer_replace(&fdst->dsd_ref, fsrc->dsd_ref);
1034  if (ret < 0)
1035  return ret;
1036  if (fsrc->dsd_ref) {
1037  fdst->dsdctx = (DSDContext*)fdst->dsd_ref->data;
1038  fdst->dsd_channels = fsrc->dsd_channels;
1039  }
1040 
1041  return 0;
1042 }
1043 #endif
1044 
1046 {
1047  WavpackContext *s = avctx->priv_data;
1048 
1049  s->avctx = avctx;
1050 
1051  s->fdec_num = 0;
1052 
1053  s->curr_frame.f = av_frame_alloc();
1054  s->prev_frame.f = av_frame_alloc();
1055 
1056  if (!s->curr_frame.f || !s->prev_frame.f)
1057  return AVERROR(ENOMEM);
1058 
1059  ff_init_dsd_data();
1060 
1061  return 0;
1062 }
1063 
1065 {
1066  WavpackContext *s = avctx->priv_data;
1067 
1068  for (int i = 0; i < s->fdec_num; i++)
1069  av_freep(&s->fdec[i]);
1070  av_freep(&s->fdec);
1071  s->fdec_num = 0;
1072 
1073  ff_thread_release_ext_buffer(avctx, &s->curr_frame);
1074  av_frame_free(&s->curr_frame.f);
1075 
1076  ff_thread_release_ext_buffer(avctx, &s->prev_frame);
1077  av_frame_free(&s->prev_frame.f);
1078 
1079  av_buffer_unref(&s->dsd_ref);
1080 
1081  return 0;
1082 }
1083 
1084 static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
1085  const uint8_t *buf, int buf_size)
1086 {
1087  WavpackContext *wc = avctx->priv_data;
1089  GetByteContext gb;
1090  enum AVSampleFormat sample_fmt;
1091  void *samples_l = NULL, *samples_r = NULL;
1092  int ret;
1093  int got_terms = 0, got_weights = 0, got_samples = 0,
1094  got_entropy = 0, got_pcm = 0, got_float = 0, got_hybrid = 0;
1095  int got_dsd = 0;
1096  int i, j, id, size, ssize, weights, t;
1097  int bpp, chan = 0, orig_bpp, sample_rate = 0, rate_x = 1, dsd_mode = 0;
1098  int multiblock;
1099  uint64_t chmask = 0;
1100 
1101  if (block_no >= wc->fdec_num && wv_alloc_frame_context(wc) < 0) {
1102  av_log(avctx, AV_LOG_ERROR, "Error creating frame decode context\n");
1103  return AVERROR_INVALIDDATA;
1104  }
1105 
1106  s = wc->fdec[block_no];
1107  if (!s) {
1108  av_log(avctx, AV_LOG_ERROR, "Context for block %d is not present\n",
1109  block_no);
1110  return AVERROR_INVALIDDATA;
1111  }
1112 
1113  memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr));
1114  memset(s->ch, 0, sizeof(s->ch));
1115  s->extra_bits = 0;
1116  s->and = s->or = s->shift = 0;
1117  s->got_extra_bits = 0;
1118 
1119  bytestream2_init(&gb, buf, buf_size);
1120 
1121  s->samples = bytestream2_get_le32(&gb);
1122  if (s->samples != wc->samples) {
1123  av_log(avctx, AV_LOG_ERROR, "Mismatching number of samples in "
1124  "a sequence: %d and %d\n", wc->samples, s->samples);
1125  return AVERROR_INVALIDDATA;
1126  }
1127  s->frame_flags = bytestream2_get_le32(&gb);
1128 
1129  if (s->frame_flags & (WV_FLOAT_DATA | WV_DSD_DATA))
1130  sample_fmt = AV_SAMPLE_FMT_FLTP;
1131  else if ((s->frame_flags & 0x03) <= 1)
1132  sample_fmt = AV_SAMPLE_FMT_S16P;
1133  else
1134  sample_fmt = AV_SAMPLE_FMT_S32P;
1135 
1136  if (wc->ch_offset && avctx->sample_fmt != sample_fmt)
1137  return AVERROR_INVALIDDATA;
1138 
1139  bpp = av_get_bytes_per_sample(sample_fmt);
1140  orig_bpp = ((s->frame_flags & 0x03) + 1) << 3;
1141  multiblock = (s->frame_flags & WV_SINGLE_BLOCK) != WV_SINGLE_BLOCK;
1142 
1143  s->stereo = !(s->frame_flags & WV_MONO);
1144  s->stereo_in = (s->frame_flags & WV_FALSE_STEREO) ? 0 : s->stereo;
1145  s->joint = s->frame_flags & WV_JOINT_STEREO;
1146  s->hybrid = s->frame_flags & WV_HYBRID_MODE;
1147  s->hybrid_bitrate = s->frame_flags & WV_HYBRID_BITRATE;
1148  s->post_shift = bpp * 8 - orig_bpp + ((s->frame_flags >> 13) & 0x1f);
1149  if (s->post_shift < 0 || s->post_shift > 31) {
1150  return AVERROR_INVALIDDATA;
1151  }
1152  s->hybrid_maxclip = ((1LL << (orig_bpp - 1)) - 1);
1153  s->hybrid_minclip = ((-1UL << (orig_bpp - 1)));
1154  s->CRC = bytestream2_get_le32(&gb);
1155 
1156  // parse metadata blocks
1157  while (bytestream2_get_bytes_left(&gb)) {
1158  id = bytestream2_get_byte(&gb);
1159  size = bytestream2_get_byte(&gb);
1160  if (id & WP_IDF_LONG)
1161  size |= (bytestream2_get_le16u(&gb)) << 8;
1162  size <<= 1; // size is specified in words
1163  ssize = size;
1164  if (id & WP_IDF_ODD)
1165  size--;
1166  if (size < 0) {
1167  av_log(avctx, AV_LOG_ERROR,
1168  "Got incorrect block %02X with size %i\n", id, size);
1169  break;
1170  }
1171  if (bytestream2_get_bytes_left(&gb) < ssize) {
1172  av_log(avctx, AV_LOG_ERROR,
1173  "Block size %i is out of bounds\n", size);
1174  break;
1175  }
1176  switch (id & WP_IDF_MASK) {
1177  case WP_ID_DECTERMS:
1178  if (size > MAX_TERMS) {
1179  av_log(avctx, AV_LOG_ERROR, "Too many decorrelation terms\n");
1180  s->terms = 0;
1181  bytestream2_skip(&gb, ssize);
1182  continue;
1183  }
1184  s->terms = size;
1185  for (i = 0; i < s->terms; i++) {
1186  uint8_t val = bytestream2_get_byte(&gb);
1187  s->decorr[s->terms - i - 1].value = (val & 0x1F) - 5;
1188  s->decorr[s->terms - i - 1].delta = val >> 5;
1189  }
1190  got_terms = 1;
1191  break;
1192  case WP_ID_DECWEIGHTS:
1193  if (!got_terms) {
1194  av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
1195  continue;
1196  }
1197  weights = size >> s->stereo_in;
1198  if (weights > MAX_TERMS || weights > s->terms) {
1199  av_log(avctx, AV_LOG_ERROR, "Too many decorrelation weights\n");
1200  bytestream2_skip(&gb, ssize);
1201  continue;
1202  }
1203  for (i = 0; i < weights; i++) {
1204  t = (int8_t)bytestream2_get_byte(&gb);
1205  s->decorr[s->terms - i - 1].weightA = t * (1 << 3);
1206  if (s->decorr[s->terms - i - 1].weightA > 0)
1207  s->decorr[s->terms - i - 1].weightA +=
1208  (s->decorr[s->terms - i - 1].weightA + 64) >> 7;
1209  if (s->stereo_in) {
1210  t = (int8_t)bytestream2_get_byte(&gb);
1211  s->decorr[s->terms - i - 1].weightB = t * (1 << 3);
1212  if (s->decorr[s->terms - i - 1].weightB > 0)
1213  s->decorr[s->terms - i - 1].weightB +=
1214  (s->decorr[s->terms - i - 1].weightB + 64) >> 7;
1215  }
1216  }
1217  got_weights = 1;
1218  break;
1219  case WP_ID_DECSAMPLES:
1220  if (!got_terms) {
1221  av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
1222  continue;
1223  }
1224  t = 0;
1225  for (i = s->terms - 1; (i >= 0) && (t < size); i--) {
1226  Decorr *decorr = &s->decorr[i];
1227 
1228  if (decorr->value > 8) {
1229  decorr->samplesA[0] =
1230  wp_exp2(bytestream2_get_le16(&gb));
1231  decorr->samplesA[1] =
1232  wp_exp2(bytestream2_get_le16(&gb));
1233 
1234  if (s->stereo_in) {
1235  decorr->samplesB[0] =
1236  wp_exp2(bytestream2_get_le16(&gb));
1237  decorr->samplesB[1] =
1238  wp_exp2(bytestream2_get_le16(&gb));
1239  t += 4;
1240  }
1241  t += 4;
1242  } else if (decorr->value < 0) {
1243  decorr->samplesA[0] =
1244  wp_exp2(bytestream2_get_le16(&gb));
1245  decorr->samplesB[0] =
1246  wp_exp2(bytestream2_get_le16(&gb));
1247  t += 4;
1248  } else {
1249  for (j = 0; j < decorr->value; j++) {
1250  decorr->samplesA[j] =
1251  wp_exp2(bytestream2_get_le16(&gb));
1252  if (s->stereo_in) {
1253  decorr->samplesB[j] =
1254  wp_exp2(bytestream2_get_le16(&gb));
1255  }
1256  }
1257  t += decorr->value * 2 * (s->stereo_in + 1);
1258  }
1259  }
1260  got_samples = 1;
1261  break;
1262  case WP_ID_ENTROPY:
1263  if (size != 6 * (s->stereo_in + 1)) {
1264  av_log(avctx, AV_LOG_ERROR,
1265  "Entropy vars size should be %i, got %i.\n",
1266  6 * (s->stereo_in + 1), size);
1267  bytestream2_skip(&gb, ssize);
1268  continue;
1269  }
1270  for (j = 0; j <= s->stereo_in; j++)
1271  for (i = 0; i < 3; i++) {
1272  s->ch[j].median[i] = wp_exp2(bytestream2_get_le16(&gb));
1273  }
1274  got_entropy = 1;
1275  break;
1276  case WP_ID_HYBRID:
1277  if (s->hybrid_bitrate) {
1278  for (i = 0; i <= s->stereo_in; i++) {
1279  s->ch[i].slow_level = wp_exp2(bytestream2_get_le16(&gb));
1280  size -= 2;
1281  }
1282  }
1283  for (i = 0; i < (s->stereo_in + 1); i++) {
1284  s->ch[i].bitrate_acc = bytestream2_get_le16(&gb) << 16;
1285  size -= 2;
1286  }
1287  if (size > 0) {
1288  for (i = 0; i < (s->stereo_in + 1); i++) {
1289  s->ch[i].bitrate_delta =
1290  wp_exp2((int16_t)bytestream2_get_le16(&gb));
1291  }
1292  } else {
1293  for (i = 0; i < (s->stereo_in + 1); i++)
1294  s->ch[i].bitrate_delta = 0;
1295  }
1296  got_hybrid = 1;
1297  break;
1298  case WP_ID_INT32INFO: {
1299  uint8_t val[4];
1300  if (size != 4) {
1301  av_log(avctx, AV_LOG_ERROR,
1302  "Invalid INT32INFO, size = %i\n",
1303  size);
1304  bytestream2_skip(&gb, ssize - 4);
1305  continue;
1306  }
1307  bytestream2_get_buffer(&gb, val, 4);
1308  if (val[0] > 30) {
1309  av_log(avctx, AV_LOG_ERROR,
1310  "Invalid INT32INFO, extra_bits = %d (> 30)\n", val[0]);
1311  continue;
1312  } else {
1313  s->extra_bits = val[0];
1314  }
1315  if (val[1])
1316  s->shift = val[1];
1317  if (val[2]) {
1318  s->and = s->or = 1;
1319  s->shift = val[2];
1320  }
1321  if (val[3]) {
1322  s->and = 1;
1323  s->shift = val[3];
1324  }
1325  if (s->shift > 31) {
1326  av_log(avctx, AV_LOG_ERROR,
1327  "Invalid INT32INFO, shift = %d (> 31)\n", s->shift);
1328  s->and = s->or = s->shift = 0;
1329  continue;
1330  }
1331  /* original WavPack decoder forces 32-bit lossy sound to be treated
1332  * as 24-bit one in order to have proper clipping */
1333  if (s->hybrid && bpp == 4 && s->post_shift < 8 && s->shift > 8) {
1334  s->post_shift += 8;
1335  s->shift -= 8;
1336  s->hybrid_maxclip >>= 8;
1337  s->hybrid_minclip >>= 8;
1338  }
1339  break;
1340  }
1341  case WP_ID_FLOATINFO:
1342  if (size != 4) {
1343  av_log(avctx, AV_LOG_ERROR,
1344  "Invalid FLOATINFO, size = %i\n", size);
1345  bytestream2_skip(&gb, ssize);
1346  continue;
1347  }
1348  s->float_flag = bytestream2_get_byte(&gb);
1349  s->float_shift = bytestream2_get_byte(&gb);
1350  s->float_max_exp = bytestream2_get_byte(&gb);
1351  if (s->float_shift > 31) {
1352  av_log(avctx, AV_LOG_ERROR,
1353  "Invalid FLOATINFO, shift = %d (> 31)\n", s->float_shift);
1354  s->float_shift = 0;
1355  continue;
1356  }
1357  got_float = 1;
1358  bytestream2_skip(&gb, 1);
1359  break;
1360  case WP_ID_DATA:
1361  if ((ret = init_get_bits8(&s->gb, gb.buffer, size)) < 0)
1362  return ret;
1363  bytestream2_skip(&gb, size);
1364  got_pcm = 1;
1365  break;
1366  case WP_ID_DSD_DATA:
1367  if (size < 2) {
1368  av_log(avctx, AV_LOG_ERROR, "Invalid DSD_DATA, size = %i\n",
1369  size);
1370  bytestream2_skip(&gb, ssize);
1371  continue;
1372  }
1373  rate_x = bytestream2_get_byte(&gb);
1374  if (rate_x > 30)
1375  return AVERROR_INVALIDDATA;
1376  rate_x = 1 << rate_x;
1377  dsd_mode = bytestream2_get_byte(&gb);
1378  if (dsd_mode && dsd_mode != 1 && dsd_mode != 3) {
1379  av_log(avctx, AV_LOG_ERROR, "Invalid DSD encoding mode: %d\n",
1380  dsd_mode);
1381  return AVERROR_INVALIDDATA;
1382  }
1383  bytestream2_init(&s->gbyte, gb.buffer, size-2);
1384  bytestream2_skip(&gb, size-2);
1385  got_dsd = 1;
1386  break;
1387  case WP_ID_EXTRABITS:
1388  if (size <= 4) {
1389  av_log(avctx, AV_LOG_ERROR, "Invalid EXTRABITS, size = %i\n",
1390  size);
1391  bytestream2_skip(&gb, size);
1392  continue;
1393  }
1394  if ((ret = init_get_bits8(&s->gb_extra_bits, gb.buffer, size)) < 0)
1395  return ret;
1396  s->crc_extra_bits = get_bits_long(&s->gb_extra_bits, 32);
1397  bytestream2_skip(&gb, size);
1398  s->got_extra_bits = 1;
1399  break;
1400  case WP_ID_CHANINFO:
1401  if (size <= 1) {
1402  av_log(avctx, AV_LOG_ERROR,
1403  "Insufficient channel information\n");
1404  return AVERROR_INVALIDDATA;
1405  }
1406  chan = bytestream2_get_byte(&gb);
1407  switch (size - 2) {
1408  case 0:
1409  chmask = bytestream2_get_byte(&gb);
1410  break;
1411  case 1:
1412  chmask = bytestream2_get_le16(&gb);
1413  break;
1414  case 2:
1415  chmask = bytestream2_get_le24(&gb);
1416  break;
1417  case 3:
1418  chmask = bytestream2_get_le32(&gb);
1419  break;
1420  case 4:
1421  size = bytestream2_get_byte(&gb);
1422  chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
1423  chan += 1;
1424  chmask = bytestream2_get_le24(&gb);
1425  break;
1426  case 5:
1427  size = bytestream2_get_byte(&gb);
1428  chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
1429  chan += 1;
1430  chmask = bytestream2_get_le32(&gb);
1431  break;
1432  default:
1433  av_log(avctx, AV_LOG_ERROR, "Invalid channel info size %d\n",
1434  size);
1435  }
1436  break;
1437  case WP_ID_SAMPLE_RATE:
1438  if (size != 3) {
1439  av_log(avctx, AV_LOG_ERROR, "Invalid custom sample rate.\n");
1440  return AVERROR_INVALIDDATA;
1441  }
1442  sample_rate = bytestream2_get_le24(&gb);
1443  break;
1444  default:
1445  bytestream2_skip(&gb, size);
1446  }
1447  if (id & WP_IDF_ODD)
1448  bytestream2_skip(&gb, 1);
1449  }
1450 
1451  if (got_pcm) {
1452  if (!got_terms) {
1453  av_log(avctx, AV_LOG_ERROR, "No block with decorrelation terms\n");
1454  return AVERROR_INVALIDDATA;
1455  }
1456  if (!got_weights) {
1457  av_log(avctx, AV_LOG_ERROR, "No block with decorrelation weights\n");
1458  return AVERROR_INVALIDDATA;
1459  }
1460  if (!got_samples) {
1461  av_log(avctx, AV_LOG_ERROR, "No block with decorrelation samples\n");
1462  return AVERROR_INVALIDDATA;
1463  }
1464  if (!got_entropy) {
1465  av_log(avctx, AV_LOG_ERROR, "No block with entropy info\n");
1466  return AVERROR_INVALIDDATA;
1467  }
1468  if (s->hybrid && !got_hybrid) {
1469  av_log(avctx, AV_LOG_ERROR, "Hybrid config not found\n");
1470  return AVERROR_INVALIDDATA;
1471  }
1472  if (!got_float && sample_fmt == AV_SAMPLE_FMT_FLTP) {
1473  av_log(avctx, AV_LOG_ERROR, "Float information not found\n");
1474  return AVERROR_INVALIDDATA;
1475  }
1476  if (s->got_extra_bits && sample_fmt != AV_SAMPLE_FMT_FLTP) {
1477  const int size = get_bits_left(&s->gb_extra_bits);
1478  const int wanted = s->samples * s->extra_bits << s->stereo_in;
1479  if (size < wanted) {
1480  av_log(avctx, AV_LOG_ERROR, "Too small EXTRABITS\n");
1481  s->got_extra_bits = 0;
1482  }
1483  }
1484  }
1485 
1486  if (!got_pcm && !got_dsd) {
1487  av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n");
1488  return AVERROR_INVALIDDATA;
1489  }
1490 
1491  if ((got_pcm && wc->modulation != MODULATION_PCM) ||
1492  (got_dsd && wc->modulation != MODULATION_DSD)) {
1493  av_log(avctx, AV_LOG_ERROR, "Invalid PCM/DSD mix encountered\n");
1494  return AVERROR_INVALIDDATA;
1495  }
1496 
1497  if (!wc->ch_offset) {
1498  AVChannelLayout new_ch_layout = { 0 };
1499  int new_samplerate;
1500  int sr = (s->frame_flags >> 23) & 0xf;
1501  if (sr == 0xf) {
1502  if (!sample_rate) {
1503  av_log(avctx, AV_LOG_ERROR, "Custom sample rate missing.\n");
1504  return AVERROR_INVALIDDATA;
1505  }
1506  new_samplerate = sample_rate;
1507  } else
1508  new_samplerate = wv_rates[sr];
1509 
1510  if (new_samplerate * (uint64_t)rate_x > INT_MAX)
1511  return AVERROR_INVALIDDATA;
1512  new_samplerate *= rate_x;
1513 
1514  if (multiblock) {
1515  if (chmask) {
1516  av_channel_layout_from_mask(&new_ch_layout, chmask);
1517  if (chan && new_ch_layout.nb_channels != chan) {
1518  av_log(avctx, AV_LOG_ERROR, "Channel mask does not match the channel count\n");
1519  return AVERROR_INVALIDDATA;
1520  }
1521  } else {
1522  av_channel_layout_default(&new_ch_layout, chan);
1523  }
1524  } else {
1525  av_channel_layout_default(&new_ch_layout, s->stereo + 1);
1526  }
1527 
1528  /* clear DSD state if stream properties change */
1529  if (new_ch_layout.nb_channels != wc->dsd_channels ||
1530  av_channel_layout_compare(&new_ch_layout, &avctx->ch_layout) ||
1531  new_samplerate != avctx->sample_rate ||
1532  !!got_dsd != !!wc->dsdctx) {
1533  ret = wv_dsd_reset(wc, got_dsd ? new_ch_layout.nb_channels : 0);
1534  if (ret < 0) {
1535  av_log(avctx, AV_LOG_ERROR, "Error reinitializing the DSD context\n");
1536  return ret;
1537  }
1539  }
1540  av_channel_layout_copy(&avctx->ch_layout, &new_ch_layout);
1541  avctx->sample_rate = new_samplerate;
1542  avctx->sample_fmt = sample_fmt;
1543  avctx->bits_per_raw_sample = orig_bpp;
1544 
1547 
1548  /* get output buffer */
1549  wc->curr_frame.f->nb_samples = s->samples;
1550  ret = ff_thread_get_ext_buffer(avctx, &wc->curr_frame,
1552  if (ret < 0)
1553  return ret;
1554 
1555  wc->frame = wc->curr_frame.f;
1556  ff_thread_finish_setup(avctx);
1557  }
1558 
1559  if (wc->ch_offset + s->stereo >= avctx->ch_layout.nb_channels) {
1560  av_log(avctx, AV_LOG_WARNING, "Too many channels coded in a packet.\n");
1561  return ((avctx->err_recognition & AV_EF_EXPLODE) || !wc->ch_offset) ? AVERROR_INVALIDDATA : 0;
1562  }
1563 
1564  samples_l = wc->frame->extended_data[wc->ch_offset];
1565  if (s->stereo)
1566  samples_r = wc->frame->extended_data[wc->ch_offset + 1];
1567 
1568  wc->ch_offset += 1 + s->stereo;
1569 
1570  if (s->stereo_in) {
1571  if (got_dsd) {
1572  if (dsd_mode == 3) {
1573  ret = wv_unpack_dsd_high(s, samples_l, samples_r);
1574  } else if (dsd_mode == 1) {
1575  ret = wv_unpack_dsd_fast(s, samples_l, samples_r);
1576  } else {
1577  ret = wv_unpack_dsd_copy(s, samples_l, samples_r);
1578  }
1579  } else {
1580  ret = wv_unpack_stereo(s, &s->gb, samples_l, samples_r, avctx->sample_fmt);
1581  }
1582  if (ret < 0)
1583  return ret;
1584  } else {
1585  if (got_dsd) {
1586  if (dsd_mode == 3) {
1587  ret = wv_unpack_dsd_high(s, samples_l, NULL);
1588  } else if (dsd_mode == 1) {
1589  ret = wv_unpack_dsd_fast(s, samples_l, NULL);
1590  } else {
1591  ret = wv_unpack_dsd_copy(s, samples_l, NULL);
1592  }
1593  } else {
1594  ret = wv_unpack_mono(s, &s->gb, samples_l, avctx->sample_fmt);
1595  }
1596  if (ret < 0)
1597  return ret;
1598 
1599  if (s->stereo)
1600  memcpy(samples_r, samples_l, bpp * s->samples);
1601  }
1602 
1603  return 0;
1604 }
1605 
1607 {
1608  WavpackContext *s = avctx->priv_data;
1609 
1610  wv_dsd_reset(s, 0);
1611 }
1612 
1613 static int dsd_channel(AVCodecContext *avctx, void *frmptr, int jobnr, int threadnr)
1614 {
1615  const WavpackContext *s = avctx->priv_data;
1616  AVFrame *frame = frmptr;
1617 
1618  ff_dsd2pcm_translate (&s->dsdctx [jobnr], s->samples, 0,
1619  (uint8_t *)frame->extended_data[jobnr], 4,
1620  (float *)frame->extended_data[jobnr], 1);
1621 
1622  return 0;
1623 }
1624 
1625 static int wavpack_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
1626  int *got_frame_ptr, AVPacket *avpkt)
1627 {
1628  WavpackContext *s = avctx->priv_data;
1629  const uint8_t *buf = avpkt->data;
1630  int buf_size = avpkt->size;
1631  int frame_size, ret, frame_flags;
1632 
1633  if (avpkt->size <= WV_HEADER_SIZE)
1634  return AVERROR_INVALIDDATA;
1635 
1636  s->frame = NULL;
1637  s->block = 0;
1638  s->ch_offset = 0;
1639 
1640  /* determine number of samples */
1641  s->samples = AV_RL32(buf + 20);
1642  frame_flags = AV_RL32(buf + 24);
1643  if (s->samples <= 0 || s->samples > WV_MAX_SAMPLES) {
1644  av_log(avctx, AV_LOG_ERROR, "Invalid number of samples: %d\n",
1645  s->samples);
1646  return AVERROR_INVALIDDATA;
1647  }
1648 
1649  s->modulation = (frame_flags & WV_DSD_DATA) ? MODULATION_DSD : MODULATION_PCM;
1650 
1651  while (buf_size > WV_HEADER_SIZE) {
1652  frame_size = AV_RL32(buf + 4) - 12;
1653  buf += 20;
1654  buf_size -= 20;
1655  if (frame_size <= 0 || frame_size > buf_size) {
1656  av_log(avctx, AV_LOG_ERROR,
1657  "Block %d has invalid size (size %d vs. %d bytes left)\n",
1658  s->block, frame_size, buf_size);
1660  goto error;
1661  }
1662  if ((ret = wavpack_decode_block(avctx, s->block, buf, frame_size)) < 0)
1663  goto error;
1664  s->block++;
1665  buf += frame_size;
1666  buf_size -= frame_size;
1667  }
1668 
1669  if (s->ch_offset != avctx->ch_layout.nb_channels) {
1670  av_log(avctx, AV_LOG_ERROR, "Not enough channels coded in a packet.\n");
1672  goto error;
1673  }
1674 
1675  ff_thread_await_progress(&s->prev_frame, INT_MAX, 0);
1676  ff_thread_release_ext_buffer(avctx, &s->prev_frame);
1677 
1678  if (s->modulation == MODULATION_DSD)
1679  avctx->execute2(avctx, dsd_channel, s->frame, NULL, avctx->ch_layout.nb_channels);
1680 
1681  ff_thread_report_progress(&s->curr_frame, INT_MAX, 0);
1682 
1683  if ((ret = av_frame_ref(rframe, s->frame)) < 0)
1684  return ret;
1685 
1686  *got_frame_ptr = 1;
1687 
1688  return avpkt->size;
1689 
1690 error:
1691  if (s->frame) {
1692  ff_thread_await_progress(&s->prev_frame, INT_MAX, 0);
1693  ff_thread_release_ext_buffer(avctx, &s->prev_frame);
1694  ff_thread_report_progress(&s->curr_frame, INT_MAX, 0);
1695  }
1696 
1697  return ret;
1698 }
1699 
1701  .p.name = "wavpack",
1702  CODEC_LONG_NAME("WavPack"),
1703  .p.type = AVMEDIA_TYPE_AUDIO,
1704  .p.id = AV_CODEC_ID_WAVPACK,
1705  .priv_data_size = sizeof(WavpackContext),
1707  .close = wavpack_decode_end,
1709  .flush = wavpack_decode_flush,
1711  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
1713  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
1715 };
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:31
WavpackFrameContext::joint
int joint
Definition: wavpack.c:71
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:79
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
WavpackContext::avctx
AVCodecContext * avctx
Definition: wavpack.c:100
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
ff_thread_release_ext_buffer
void ff_thread_release_ext_buffer(AVCodecContext *avctx, ThreadFrame *f)
Unref a ThreadFrame.
Definition: pthread_frame.c:1023
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1060
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:239
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
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:72
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1408
wavpack_decode_flush
static void wavpack_decode_flush(AVCodecContext *avctx)
Definition: wavpack.c:1606
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:50
MODULATION_PCM
@ MODULATION_PCM
Definition: wavpack.c:63
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:110
WP_IDF_LONG
@ WP_IDF_LONG
Definition: wavpack.h:66
AVPacket::data
uint8_t * data
Definition: packet.h:374
WavpackFrameContext::post_shift
int post_shift
Definition: wavpack.c:83
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:70
base
uint8_t base
Definition: vp3data.h:128
PRECISION_USE
#define PRECISION_USE
Definition: wavpack.c:54
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:311
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:331
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:64
WavpackContext::frame
AVFrame * frame
Definition: wavpack.c:109
WavpackContext::fdec_num
int fdec_num
Definition: wavpack.c:103
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:99
MAX_HISTORY_BINS
#define MAX_HISTORY_BINS
Definition: wavpack.c:59
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:2101
WavpackFrameContext::got_extra_bits
int got_extra_bits
Definition: wavpack.c:74
WP_ID_ENTROPY
@ WP_ID_ENTROPY
Definition: wavpack.h:75
WavpackFrameContext::ch
WvChannel ch[2]
Definition: wavpack.c:89
GetBitContext
Definition: get_bits.h:108
ff_wavpack_decoder
const FFCodec ff_wavpack_decoder
Definition: wavpack.c:1700
Modulation
Modulation
Definition: wavpack.c:62
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:1084
WavpackContext::curr_frame
ThreadFrame curr_frame
Definition: wavpack.c:110
MAX_BIN_BYTES
#define MAX_BIN_BYTES
Definition: wavpack.c:60
WV_DSD_DATA
#define WV_DSD_DATA
Definition: wavpack.h:41
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:58
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:82
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:586
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:306
PRECISION
#define PRECISION
Definition: wavpack.c:52
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:417
frame_size
int frame_size
Definition: mxfenc.c:2307
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:395
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:94
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1513
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:84
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
ff_thread_ref_frame
int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
Definition: utils.c:868
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:73
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:1625
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:85
av_buffer_unref
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition: buffer.c:139
DSD_BYTE_READY
#define DSD_BYTE_READY(low, high)
Definition: wavpack.c:42
WavpackContext::dsdctx
DSDContext * dsdctx
Definition: wavpack.c:114
WavpackContext::fdec
WavpackFrameContext ** fdec
Definition: wavpack.c:102
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:53
bytestream2_get_buffer
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
Definition: bytestream.h:267
WavpackContext::ch_offset
int ch_offset
Definition: wavpack.c:107
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:80
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:82
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:91
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:375
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:301
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
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:425
sp
#define sp
Definition: regdef.h:63
WavpackFrameContext::float_flag
int float_flag
Definition: wavpack.c:86
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1076
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:75
DSDfilters
Definition: wavpack.c:431
WP_IDF_ODD
@ WP_IDF_ODD
Definition: wavpack.h:65
WavpackContext::block
int block
Definition: wavpack.c:105
DSDfilters::byte
unsigned int byte
Definition: wavpack.c:433
WavpackFrameContext::hybrid_maxclip
int hybrid_maxclip
Definition: wavpack.c:85
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:56
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:938
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:968
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
WavpackContext::dsd_ref
AVBufferRef * dsd_ref
Definition: wavpack.c:113
WavpackFrameContext::float_max_exp
int float_max_exp
Definition: wavpack.c:88
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:244
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:1064
WavpackContext::samples
int samples
Definition: wavpack.c:106
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:77
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:82
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
xf
#define xf(width, name, var, range_min, range_max, subs,...)
Definition: cbs_av1.c:583
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:45
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
av_buffer_replace
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
Definition: buffer.c:233
WavpackFrameContext::zero
int zero
Definition: wavpack.c:80
UP
#define UP
Definition: wavpack.c:48
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:981
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:93
WP_ID_DECSAMPLES
@ WP_ID_DECSAMPLES
Definition: wavpack.h:74
av_buffer_allocz
AVBufferRef * av_buffer_allocz(size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:93
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
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
WavpackFrameContext::zeroes
int zeroes
Definition: wavpack.c:80
GET_MED
#define GET_MED(n)
Definition: wavpack.h:106
pos
unsigned int pos
Definition: spdifenc.c:413
DOWN
#define DOWN
Definition: wavpack.c:49
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:76
WavpackFrameContext::terms
int terms
Definition: wavpack.c:78
WavpackContext::modulation
Modulation modulation
Definition: wavpack.c:111
WavpackFrameContext
Definition: wavpack.c:67
wavpack_decode_init
static av_cold int wavpack_decode_init(AVCodecContext *avctx)
Definition: wavpack.c:1045
AVCodecContext
main external API structure.
Definition: avcodec.h:437
ThreadFrame
Definition: threadframe.h:27
WavpackFrameContext::stereo_in
int stereo_in
Definition: wavpack.c:70
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:92
WavpackFrameContext::hybrid_bitrate
int hybrid_bitrate
Definition: wavpack.c:84
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:643
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
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
DEC_MED
#define DEC_MED(n)
Definition: wavpack.h:107
PTABLE_MASK
#define PTABLE_MASK
Definition: wavpack.c:46
WavpackFrameContext::probabilities
uint8_t probabilities[MAX_HISTORY_BINS][256]
Definition: wavpack.c:95
WV_JOINT_STEREO
#define WV_JOINT_STEREO
Definition: wavpack.h:36
WavpackFrameContext::frame_flags
int frame_flags
Definition: wavpack.c:69
AVPacket
This structure stores compressed data.
Definition: packet.h:351
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:464
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:81
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:68
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:96
WavpackFrameContext::float_shift
int float_shift
Definition: wavpack.c:87
int
int
Definition: ffmpeg_filter.c:331
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:1577
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
Decorr::samplesB
int samplesB[MAX_TERM]
Definition: wavpack.h:94
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:1613