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 
24 #include "libavutil/mem.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  return 0;
1053 }
1054 
1056 {
1057  WavpackContext *s = avctx->priv_data;
1058 
1059  for (int i = 0; i < s->fdec_num; i++)
1060  av_freep(&s->fdec[i]);
1061  av_freep(&s->fdec);
1062  s->fdec_num = 0;
1063 
1064  ff_thread_release_ext_buffer(&s->curr_frame);
1065  av_frame_free(&s->curr_frame.f);
1066 
1067  ff_thread_release_ext_buffer(&s->prev_frame);
1068  av_frame_free(&s->prev_frame.f);
1069 
1070  ff_refstruct_unref(&s->dsdctx);
1071 
1072  return 0;
1073 }
1074 
1075 static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
1076  const uint8_t *buf, int buf_size)
1077 {
1078  WavpackContext *wc = avctx->priv_data;
1080  GetByteContext gb;
1081  enum AVSampleFormat sample_fmt;
1082  void *samples_l = NULL, *samples_r = NULL;
1083  int ret;
1084  int got_terms = 0, got_weights = 0, got_samples = 0,
1085  got_entropy = 0, got_pcm = 0, got_float = 0, got_hybrid = 0;
1086  int got_dsd = 0;
1087  int i, j, id, size, ssize, weights, t;
1088  int bpp, chan = 0, orig_bpp, sample_rate = 0, rate_x = 1, dsd_mode = 0;
1089  int multiblock;
1090  uint64_t chmask = 0;
1091 
1092  if (block_no >= wc->fdec_num && wv_alloc_frame_context(wc) < 0) {
1093  av_log(avctx, AV_LOG_ERROR, "Error creating frame decode context\n");
1094  return AVERROR_INVALIDDATA;
1095  }
1096 
1097  s = wc->fdec[block_no];
1098 
1099  memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr));
1100  memset(s->ch, 0, sizeof(s->ch));
1101  s->extra_bits = 0;
1102  s->and = s->or = s->shift = 0;
1103  s->got_extra_bits = 0;
1104 
1105  bytestream2_init(&gb, buf, buf_size);
1106 
1107  s->samples = bytestream2_get_le32(&gb);
1108  if (s->samples != wc->samples) {
1109  av_log(avctx, AV_LOG_ERROR, "Mismatching number of samples in "
1110  "a sequence: %d and %d\n", wc->samples, s->samples);
1111  return AVERROR_INVALIDDATA;
1112  }
1113  s->frame_flags = bytestream2_get_le32(&gb);
1114 
1115  if (s->frame_flags & (WV_FLOAT_DATA | WV_DSD_DATA))
1116  sample_fmt = AV_SAMPLE_FMT_FLTP;
1117  else if ((s->frame_flags & 0x03) <= 1)
1118  sample_fmt = AV_SAMPLE_FMT_S16P;
1119  else
1120  sample_fmt = AV_SAMPLE_FMT_S32P;
1121 
1122  if (wc->ch_offset && avctx->sample_fmt != sample_fmt)
1123  return AVERROR_INVALIDDATA;
1124 
1125  bpp = av_get_bytes_per_sample(sample_fmt);
1126  orig_bpp = ((s->frame_flags & 0x03) + 1) << 3;
1127  multiblock = (s->frame_flags & WV_SINGLE_BLOCK) != WV_SINGLE_BLOCK;
1128 
1129  s->stereo = !(s->frame_flags & WV_MONO);
1130  s->stereo_in = (s->frame_flags & WV_FALSE_STEREO) ? 0 : s->stereo;
1131  s->joint = s->frame_flags & WV_JOINT_STEREO;
1132  s->hybrid = s->frame_flags & WV_HYBRID_MODE;
1133  s->hybrid_bitrate = s->frame_flags & WV_HYBRID_BITRATE;
1134  s->post_shift = bpp * 8 - orig_bpp + ((s->frame_flags >> 13) & 0x1f);
1135  if (s->post_shift < 0 || s->post_shift > 31) {
1136  return AVERROR_INVALIDDATA;
1137  }
1138  s->hybrid_maxclip = ((1LL << (orig_bpp - 1)) - 1);
1139  s->hybrid_minclip = ((-1UL << (orig_bpp - 1)));
1140  s->CRC = bytestream2_get_le32(&gb);
1141 
1142  // parse metadata blocks
1143  while (bytestream2_get_bytes_left(&gb)) {
1144  id = bytestream2_get_byte(&gb);
1145  size = bytestream2_get_byte(&gb);
1146  if (id & WP_IDF_LONG)
1147  size |= (bytestream2_get_le16u(&gb)) << 8;
1148  size <<= 1; // size is specified in words
1149  ssize = size;
1150  if (id & WP_IDF_ODD)
1151  size--;
1152  if (size < 0) {
1153  av_log(avctx, AV_LOG_ERROR,
1154  "Got incorrect block %02X with size %i\n", id, size);
1155  break;
1156  }
1157  if (bytestream2_get_bytes_left(&gb) < ssize) {
1158  av_log(avctx, AV_LOG_ERROR,
1159  "Block size %i is out of bounds\n", size);
1160  break;
1161  }
1162  switch (id & WP_IDF_MASK) {
1163  case WP_ID_DECTERMS:
1164  if (size > MAX_TERMS) {
1165  av_log(avctx, AV_LOG_ERROR, "Too many decorrelation terms\n");
1166  s->terms = 0;
1167  bytestream2_skip(&gb, ssize);
1168  continue;
1169  }
1170  s->terms = size;
1171  for (i = 0; i < s->terms; i++) {
1172  uint8_t val = bytestream2_get_byte(&gb);
1173  s->decorr[s->terms - i - 1].value = (val & 0x1F) - 5;
1174  s->decorr[s->terms - i - 1].delta = val >> 5;
1175  }
1176  got_terms = 1;
1177  break;
1178  case WP_ID_DECWEIGHTS:
1179  if (!got_terms) {
1180  av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
1181  continue;
1182  }
1183  weights = size >> s->stereo_in;
1184  if (weights > MAX_TERMS || weights > s->terms) {
1185  av_log(avctx, AV_LOG_ERROR, "Too many decorrelation weights\n");
1186  bytestream2_skip(&gb, ssize);
1187  continue;
1188  }
1189  for (i = 0; i < weights; i++) {
1190  t = (int8_t)bytestream2_get_byte(&gb);
1191  s->decorr[s->terms - i - 1].weightA = t * (1 << 3);
1192  if (s->decorr[s->terms - i - 1].weightA > 0)
1193  s->decorr[s->terms - i - 1].weightA +=
1194  (s->decorr[s->terms - i - 1].weightA + 64) >> 7;
1195  if (s->stereo_in) {
1196  t = (int8_t)bytestream2_get_byte(&gb);
1197  s->decorr[s->terms - i - 1].weightB = t * (1 << 3);
1198  if (s->decorr[s->terms - i - 1].weightB > 0)
1199  s->decorr[s->terms - i - 1].weightB +=
1200  (s->decorr[s->terms - i - 1].weightB + 64) >> 7;
1201  }
1202  }
1203  got_weights = 1;
1204  break;
1205  case WP_ID_DECSAMPLES:
1206  if (!got_terms) {
1207  av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
1208  continue;
1209  }
1210  t = 0;
1211  for (i = s->terms - 1; (i >= 0) && (t < size); i--) {
1212  Decorr *decorr = &s->decorr[i];
1213 
1214  if (decorr->value > 8) {
1215  decorr->samplesA[0] =
1216  wp_exp2(bytestream2_get_le16(&gb));
1217  decorr->samplesA[1] =
1218  wp_exp2(bytestream2_get_le16(&gb));
1219 
1220  if (s->stereo_in) {
1221  decorr->samplesB[0] =
1222  wp_exp2(bytestream2_get_le16(&gb));
1223  decorr->samplesB[1] =
1224  wp_exp2(bytestream2_get_le16(&gb));
1225  t += 4;
1226  }
1227  t += 4;
1228  } else if (decorr->value < 0) {
1229  decorr->samplesA[0] =
1230  wp_exp2(bytestream2_get_le16(&gb));
1231  decorr->samplesB[0] =
1232  wp_exp2(bytestream2_get_le16(&gb));
1233  t += 4;
1234  } else {
1235  for (j = 0; j < decorr->value; j++) {
1236  decorr->samplesA[j] =
1237  wp_exp2(bytestream2_get_le16(&gb));
1238  if (s->stereo_in) {
1239  decorr->samplesB[j] =
1240  wp_exp2(bytestream2_get_le16(&gb));
1241  }
1242  }
1243  t += decorr->value * 2 * (s->stereo_in + 1);
1244  }
1245  }
1246  got_samples = 1;
1247  break;
1248  case WP_ID_ENTROPY:
1249  if (size != 6 * (s->stereo_in + 1)) {
1250  av_log(avctx, AV_LOG_ERROR,
1251  "Entropy vars size should be %i, got %i.\n",
1252  6 * (s->stereo_in + 1), size);
1253  bytestream2_skip(&gb, ssize);
1254  continue;
1255  }
1256  for (j = 0; j <= s->stereo_in; j++)
1257  for (i = 0; i < 3; i++) {
1258  s->ch[j].median[i] = wp_exp2(bytestream2_get_le16(&gb));
1259  }
1260  got_entropy = 1;
1261  break;
1262  case WP_ID_HYBRID:
1263  if (s->hybrid_bitrate) {
1264  for (i = 0; i <= s->stereo_in; i++) {
1265  s->ch[i].slow_level = wp_exp2(bytestream2_get_le16(&gb));
1266  size -= 2;
1267  }
1268  }
1269  for (i = 0; i < (s->stereo_in + 1); i++) {
1270  s->ch[i].bitrate_acc = bytestream2_get_le16(&gb) << 16;
1271  size -= 2;
1272  }
1273  if (size > 0) {
1274  for (i = 0; i < (s->stereo_in + 1); i++) {
1275  s->ch[i].bitrate_delta =
1276  wp_exp2((int16_t)bytestream2_get_le16(&gb));
1277  }
1278  } else {
1279  for (i = 0; i < (s->stereo_in + 1); i++)
1280  s->ch[i].bitrate_delta = 0;
1281  }
1282  got_hybrid = 1;
1283  break;
1284  case WP_ID_INT32INFO: {
1285  uint8_t val[4];
1286  if (size != 4) {
1287  av_log(avctx, AV_LOG_ERROR,
1288  "Invalid INT32INFO, size = %i\n",
1289  size);
1290  bytestream2_skip(&gb, ssize - 4);
1291  continue;
1292  }
1293  bytestream2_get_buffer(&gb, val, 4);
1294  if (val[0] > 30) {
1295  av_log(avctx, AV_LOG_ERROR,
1296  "Invalid INT32INFO, extra_bits = %d (> 30)\n", val[0]);
1297  continue;
1298  } else {
1299  s->extra_bits = val[0];
1300  }
1301  if (val[1])
1302  s->shift = val[1];
1303  if (val[2]) {
1304  s->and = s->or = 1;
1305  s->shift = val[2];
1306  }
1307  if (val[3]) {
1308  s->and = 1;
1309  s->shift = val[3];
1310  }
1311  if (s->shift > 31) {
1312  av_log(avctx, AV_LOG_ERROR,
1313  "Invalid INT32INFO, shift = %d (> 31)\n", s->shift);
1314  s->and = s->or = s->shift = 0;
1315  continue;
1316  }
1317  /* original WavPack decoder forces 32-bit lossy sound to be treated
1318  * as 24-bit one in order to have proper clipping */
1319  if (s->hybrid && bpp == 4 && s->post_shift < 8 && s->shift > 8) {
1320  s->post_shift += 8;
1321  s->shift -= 8;
1322  s->hybrid_maxclip >>= 8;
1323  s->hybrid_minclip >>= 8;
1324  }
1325  break;
1326  }
1327  case WP_ID_FLOATINFO:
1328  if (size != 4) {
1329  av_log(avctx, AV_LOG_ERROR,
1330  "Invalid FLOATINFO, size = %i\n", size);
1331  bytestream2_skip(&gb, ssize);
1332  continue;
1333  }
1334  s->float_flag = bytestream2_get_byte(&gb);
1335  s->float_shift = bytestream2_get_byte(&gb);
1336  s->float_max_exp = bytestream2_get_byte(&gb);
1337  if (s->float_shift > 31) {
1338  av_log(avctx, AV_LOG_ERROR,
1339  "Invalid FLOATINFO, shift = %d (> 31)\n", s->float_shift);
1340  s->float_shift = 0;
1341  continue;
1342  }
1343  got_float = 1;
1344  bytestream2_skip(&gb, 1);
1345  break;
1346  case WP_ID_DATA:
1347  if ((ret = init_get_bits8(&s->gb, gb.buffer, size)) < 0)
1348  return ret;
1349  bytestream2_skip(&gb, size);
1350  got_pcm = 1;
1351  break;
1352  case WP_ID_DSD_DATA:
1353  if (size < 2) {
1354  av_log(avctx, AV_LOG_ERROR, "Invalid DSD_DATA, size = %i\n",
1355  size);
1356  bytestream2_skip(&gb, ssize);
1357  continue;
1358  }
1359  rate_x = bytestream2_get_byte(&gb);
1360  if (rate_x > 30)
1361  return AVERROR_INVALIDDATA;
1362  rate_x = 1 << rate_x;
1363  dsd_mode = bytestream2_get_byte(&gb);
1364  if (dsd_mode && dsd_mode != 1 && dsd_mode != 3) {
1365  av_log(avctx, AV_LOG_ERROR, "Invalid DSD encoding mode: %d\n",
1366  dsd_mode);
1367  return AVERROR_INVALIDDATA;
1368  }
1369  bytestream2_init(&s->gbyte, gb.buffer, size-2);
1370  bytestream2_skip(&gb, size-2);
1371  got_dsd = 1;
1372  break;
1373  case WP_ID_EXTRABITS:
1374  if (size <= 4) {
1375  av_log(avctx, AV_LOG_ERROR, "Invalid EXTRABITS, size = %i\n",
1376  size);
1377  bytestream2_skip(&gb, size);
1378  continue;
1379  }
1380  if ((ret = init_get_bits8(&s->gb_extra_bits, gb.buffer, size)) < 0)
1381  return ret;
1382  s->crc_extra_bits = get_bits_long(&s->gb_extra_bits, 32);
1383  bytestream2_skip(&gb, size);
1384  s->got_extra_bits = 1;
1385  break;
1386  case WP_ID_CHANINFO:
1387  if (size <= 1) {
1388  av_log(avctx, AV_LOG_ERROR,
1389  "Insufficient channel information\n");
1390  return AVERROR_INVALIDDATA;
1391  }
1392  chan = bytestream2_get_byte(&gb);
1393  switch (size - 2) {
1394  case 0:
1395  chmask = bytestream2_get_byte(&gb);
1396  break;
1397  case 1:
1398  chmask = bytestream2_get_le16(&gb);
1399  break;
1400  case 2:
1401  chmask = bytestream2_get_le24(&gb);
1402  break;
1403  case 3:
1404  chmask = bytestream2_get_le32(&gb);
1405  break;
1406  case 4:
1407  size = bytestream2_get_byte(&gb);
1408  chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
1409  chan += 1;
1410  chmask = bytestream2_get_le24(&gb);
1411  break;
1412  case 5:
1413  size = bytestream2_get_byte(&gb);
1414  chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
1415  chan += 1;
1416  chmask = bytestream2_get_le32(&gb);
1417  break;
1418  default:
1419  av_log(avctx, AV_LOG_ERROR, "Invalid channel info size %d\n",
1420  size);
1421  }
1422  break;
1423  case WP_ID_SAMPLE_RATE:
1424  if (size != 3) {
1425  av_log(avctx, AV_LOG_ERROR, "Invalid custom sample rate.\n");
1426  return AVERROR_INVALIDDATA;
1427  }
1428  sample_rate = bytestream2_get_le24(&gb);
1429  break;
1430  default:
1431  bytestream2_skip(&gb, size);
1432  }
1433  if (id & WP_IDF_ODD)
1434  bytestream2_skip(&gb, 1);
1435  }
1436 
1437  if (got_pcm) {
1438  if (!got_terms) {
1439  av_log(avctx, AV_LOG_ERROR, "No block with decorrelation terms\n");
1440  return AVERROR_INVALIDDATA;
1441  }
1442  if (!got_weights) {
1443  av_log(avctx, AV_LOG_ERROR, "No block with decorrelation weights\n");
1444  return AVERROR_INVALIDDATA;
1445  }
1446  if (!got_samples) {
1447  av_log(avctx, AV_LOG_ERROR, "No block with decorrelation samples\n");
1448  return AVERROR_INVALIDDATA;
1449  }
1450  if (!got_entropy) {
1451  av_log(avctx, AV_LOG_ERROR, "No block with entropy info\n");
1452  return AVERROR_INVALIDDATA;
1453  }
1454  if (s->hybrid && !got_hybrid) {
1455  av_log(avctx, AV_LOG_ERROR, "Hybrid config not found\n");
1456  return AVERROR_INVALIDDATA;
1457  }
1458  if (!got_float && sample_fmt == AV_SAMPLE_FMT_FLTP) {
1459  av_log(avctx, AV_LOG_ERROR, "Float information not found\n");
1460  return AVERROR_INVALIDDATA;
1461  }
1462  if (s->got_extra_bits && sample_fmt != AV_SAMPLE_FMT_FLTP) {
1463  const int size = get_bits_left(&s->gb_extra_bits);
1464  const int wanted = s->samples * s->extra_bits << s->stereo_in;
1465  if (size < wanted) {
1466  av_log(avctx, AV_LOG_ERROR, "Too small EXTRABITS\n");
1467  s->got_extra_bits = 0;
1468  }
1469  }
1470  }
1471 
1472  if (!got_pcm && !got_dsd) {
1473  av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n");
1474  return AVERROR_INVALIDDATA;
1475  }
1476 
1477  if ((got_pcm && wc->modulation != MODULATION_PCM) ||
1478  (got_dsd && wc->modulation != MODULATION_DSD)) {
1479  av_log(avctx, AV_LOG_ERROR, "Invalid PCM/DSD mix encountered\n");
1480  return AVERROR_INVALIDDATA;
1481  }
1482 
1483  if (!wc->ch_offset) {
1484  AVChannelLayout new_ch_layout = { 0 };
1485  int new_samplerate;
1486  int sr = (s->frame_flags >> 23) & 0xf;
1487  if (sr == 0xf) {
1488  if (!sample_rate) {
1489  av_log(avctx, AV_LOG_ERROR, "Custom sample rate missing.\n");
1490  return AVERROR_INVALIDDATA;
1491  }
1492  new_samplerate = sample_rate;
1493  } else
1494  new_samplerate = wv_rates[sr];
1495 
1496  if (new_samplerate * (uint64_t)rate_x > INT_MAX)
1497  return AVERROR_INVALIDDATA;
1498  new_samplerate *= rate_x;
1499 
1500  if (multiblock) {
1501  if (chmask) {
1502  av_channel_layout_from_mask(&new_ch_layout, chmask);
1503  if (chan && new_ch_layout.nb_channels != chan) {
1504  av_log(avctx, AV_LOG_ERROR, "Channel mask does not match the channel count\n");
1505  return AVERROR_INVALIDDATA;
1506  }
1507  } else {
1508  av_channel_layout_default(&new_ch_layout, chan);
1509  }
1510  } else {
1511  av_channel_layout_default(&new_ch_layout, s->stereo + 1);
1512  }
1513 
1514  /* clear DSD state if stream properties change */
1515  if (new_ch_layout.nb_channels != wc->dsd_channels ||
1516  av_channel_layout_compare(&new_ch_layout, &avctx->ch_layout) ||
1517  new_samplerate != avctx->sample_rate ||
1518  !!got_dsd != !!wc->dsdctx) {
1519  ret = wv_dsd_reset(wc, got_dsd ? new_ch_layout.nb_channels : 0);
1520  if (ret < 0) {
1521  av_log(avctx, AV_LOG_ERROR, "Error reinitializing the DSD context\n");
1522  return ret;
1523  }
1525  ff_init_dsd_data();
1526  }
1527  av_channel_layout_copy(&avctx->ch_layout, &new_ch_layout);
1528  avctx->sample_rate = new_samplerate;
1529  avctx->sample_fmt = sample_fmt;
1530  avctx->bits_per_raw_sample = orig_bpp;
1531 
1534 
1535  /* get output buffer */
1536  wc->curr_frame.f->nb_samples = s->samples;
1537  ret = ff_thread_get_ext_buffer(avctx, &wc->curr_frame,
1539  if (ret < 0)
1540  return ret;
1541 
1542  wc->frame = wc->curr_frame.f;
1543  ff_thread_finish_setup(avctx);
1544  }
1545 
1546  if (wc->ch_offset + s->stereo >= avctx->ch_layout.nb_channels) {
1547  av_log(avctx, AV_LOG_WARNING, "Too many channels coded in a packet.\n");
1548  return ((avctx->err_recognition & AV_EF_EXPLODE) || !wc->ch_offset) ? AVERROR_INVALIDDATA : 0;
1549  }
1550 
1551  samples_l = wc->frame->extended_data[wc->ch_offset];
1552  if (s->stereo)
1553  samples_r = wc->frame->extended_data[wc->ch_offset + 1];
1554 
1555  wc->ch_offset += 1 + s->stereo;
1556 
1557  if (s->stereo_in) {
1558  if (got_dsd) {
1559  if (dsd_mode == 3) {
1560  ret = wv_unpack_dsd_high(s, samples_l, samples_r);
1561  } else if (dsd_mode == 1) {
1562  ret = wv_unpack_dsd_fast(s, samples_l, samples_r);
1563  } else {
1564  ret = wv_unpack_dsd_copy(s, samples_l, samples_r);
1565  }
1566  } else {
1567  ret = wv_unpack_stereo(s, &s->gb, samples_l, samples_r, avctx->sample_fmt);
1568  }
1569  if (ret < 0)
1570  return ret;
1571  } else {
1572  if (got_dsd) {
1573  if (dsd_mode == 3) {
1574  ret = wv_unpack_dsd_high(s, samples_l, NULL);
1575  } else if (dsd_mode == 1) {
1576  ret = wv_unpack_dsd_fast(s, samples_l, NULL);
1577  } else {
1578  ret = wv_unpack_dsd_copy(s, samples_l, NULL);
1579  }
1580  } else {
1581  ret = wv_unpack_mono(s, &s->gb, samples_l, avctx->sample_fmt);
1582  }
1583  if (ret < 0)
1584  return ret;
1585 
1586  if (s->stereo)
1587  memcpy(samples_r, samples_l, bpp * s->samples);
1588  }
1589 
1590  return 0;
1591 }
1592 
1594 {
1595  WavpackContext *s = avctx->priv_data;
1596 
1597  wv_dsd_reset(s, 0);
1598 }
1599 
1600 static int dsd_channel(AVCodecContext *avctx, void *frmptr, int jobnr, int threadnr)
1601 {
1602  const WavpackContext *s = avctx->priv_data;
1603  AVFrame *frame = frmptr;
1604 
1605  ff_dsd2pcm_translate (&s->dsdctx [jobnr], s->samples, 0,
1606  (uint8_t *)frame->extended_data[jobnr], 4,
1607  (float *)frame->extended_data[jobnr], 1);
1608 
1609  return 0;
1610 }
1611 
1612 static int wavpack_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
1613  int *got_frame_ptr, AVPacket *avpkt)
1614 {
1615  WavpackContext *s = avctx->priv_data;
1616  const uint8_t *buf = avpkt->data;
1617  int buf_size = avpkt->size;
1618  int frame_size, ret, frame_flags;
1619 
1620  if (avpkt->size <= WV_HEADER_SIZE)
1621  return AVERROR_INVALIDDATA;
1622 
1623  s->frame = NULL;
1624  s->block = 0;
1625  s->ch_offset = 0;
1626 
1627  /* determine number of samples */
1628  s->samples = AV_RL32(buf + 20);
1629  frame_flags = AV_RL32(buf + 24);
1630  if (s->samples <= 0 || s->samples > WV_MAX_SAMPLES) {
1631  av_log(avctx, AV_LOG_ERROR, "Invalid number of samples: %d\n",
1632  s->samples);
1633  return AVERROR_INVALIDDATA;
1634  }
1635 
1636  s->modulation = (frame_flags & WV_DSD_DATA) ? MODULATION_DSD : MODULATION_PCM;
1637 
1638  while (buf_size > WV_HEADER_SIZE) {
1639  frame_size = AV_RL32(buf + 4) - 12;
1640  buf += 20;
1641  buf_size -= 20;
1642  if (frame_size <= 0 || frame_size > buf_size) {
1643  av_log(avctx, AV_LOG_ERROR,
1644  "Block %d has invalid size (size %d vs. %d bytes left)\n",
1645  s->block, frame_size, buf_size);
1647  goto error;
1648  }
1649  if ((ret = wavpack_decode_block(avctx, s->block, buf, frame_size)) < 0)
1650  goto error;
1651  s->block++;
1652  buf += frame_size;
1653  buf_size -= frame_size;
1654  }
1655 
1656  if (s->ch_offset != avctx->ch_layout.nb_channels) {
1657  av_log(avctx, AV_LOG_ERROR, "Not enough channels coded in a packet.\n");
1659  goto error;
1660  }
1661 
1662  ff_thread_await_progress(&s->prev_frame, INT_MAX, 0);
1663  ff_thread_release_ext_buffer(&s->prev_frame);
1664 
1665  if (s->modulation == MODULATION_DSD)
1666  avctx->execute2(avctx, dsd_channel, s->frame, NULL, avctx->ch_layout.nb_channels);
1667 
1668  ff_thread_report_progress(&s->curr_frame, INT_MAX, 0);
1669 
1670  if ((ret = av_frame_ref(rframe, s->frame)) < 0)
1671  return ret;
1672 
1673  *got_frame_ptr = 1;
1674 
1675  return avpkt->size;
1676 
1677 error:
1678  if (s->frame) {
1679  ff_thread_await_progress(&s->prev_frame, INT_MAX, 0);
1680  ff_thread_release_ext_buffer(&s->prev_frame);
1681  ff_thread_report_progress(&s->curr_frame, INT_MAX, 0);
1682  }
1683 
1684  return ret;
1685 }
1686 
1688  .p.name = "wavpack",
1689  CODEC_LONG_NAME("WavPack"),
1690  .p.type = AVMEDIA_TYPE_AUDIO,
1691  .p.id = AV_CODEC_ID_WAVPACK,
1692  .priv_data_size = sizeof(WavpackContext),
1694  .close = wavpack_decode_end,
1696  .flush = wavpack_decode_flush,
1698  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
1700  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
1702 };
error
static void error(const char *err)
Definition: target_bsf_fuzzer.c:32
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:99
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:251
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:1593
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:160
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
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:524
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:424
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:395
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:1687
Modulation
Modulation
Definition: wavpack.c:63
val
static double val(void *priv, double ch)
Definition: aeval.c:78
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
wavpack_decode_block
static int wavpack_decode_block(AVCodecContext *avctx, int block_no, const uint8_t *buf, int buf_size)
Definition: wavpack.c:1075
WavpackContext::curr_frame
ThreadFrame curr_frame
Definition: wavpack.c:111
MAX_BIN_BYTES
#define MAX_BIN_BYTES
Definition: wavpack.c:61
WV_DSD_DATA
#define WV_DSD_DATA
Definition: wavpack.h:41
refstruct.h
wp_log2
static av_always_inline int wp_log2(uint32_t val)
Definition: wavpack.h:150
MAX_HISTORY_BITS
#define MAX_HISTORY_BITS
Definition: wavpack.c:59
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:148
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:217
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:2423
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:243
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:49
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
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:73
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:1612
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:1008
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:73
WavpackFrameContext::one
int one
Definition: wavpack.c:81
LEVEL_DECAY
#define LEVEL_DECAY(a)
Definition: wavpack.c:118
index
int index
Definition: gxfenc.c:90
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:92
f
f
Definition: af_crystalizer.c:121
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:366
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:525
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:384
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:261
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
split
static char * split(char *message, char delim)
Definition: af_channelmap.c:81
RATE_S
#define RATE_S
Definition: wavpack.c:57
init_ptable
static void init_ptable(int *table, int rate_i, int rate_s)
Definition: wavpack.c:411
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:114
WP_ID_DECTERMS
@ WP_ID_DECTERMS
Definition: wavpack.h:72
WV_FLT_SHIFT_SENT
#define WV_FLT_SHIFT_SENT
Definition: wavpack.h:56
unary.h
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:64
av_channel_layout_compare
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
Definition: channel_layout.c:801
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:831
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:454
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:256
code
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some it can consider them to be part of the FIFO and delay acknowledging a status change accordingly Example code
Definition: filter_design.txt:178
wavpack_decode_end
static av_cold int wavpack_decode_end(AVCodecContext *avctx)
Definition: wavpack.c:1055
WavpackContext::samples
int samples
Definition: wavpack.c:107
av_get_bytes_per_sample
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:108
WavpackFrameContext::samples
int samples
Definition: wavpack.c:78
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:435
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:256
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:980
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:98
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
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: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:414
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:365
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:79
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:440
WV_HYBRID_MODE
#define WV_HYBRID_MODE
Definition: wavpack.h:43
INC_MED
#define INC_MED(n)
Definition: wavpack.h:108
mem.h
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:501
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:424
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:1600