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 #define WV_MAX_FRAME_DECODERS 14
100 
101 typedef struct WavpackContext {
103 
105  int fdec_num;
106 
107  int block;
108  int samples;
110 
114 
119 
120 #define LEVEL_DECAY(a) (((a) + 0x80) >> 8)
121 
122 static av_always_inline unsigned get_tail(GetBitContext *gb, unsigned k)
123 {
124  int p, e, res;
125 
126  if (k < 1)
127  return 0;
128  p = av_log2(k);
129  e = (1LL << (p + 1)) - k - 1;
130  res = get_bits_long(gb, p);
131  if (res >= e)
132  res = (res << 1) - e + get_bits1(gb);
133  return res;
134 }
135 
137 {
138  int i, br[2], sl[2];
139 
140  for (i = 0; i <= ctx->stereo_in; i++) {
141  if (ctx->ch[i].bitrate_acc > UINT_MAX - ctx->ch[i].bitrate_delta)
142  return AVERROR_INVALIDDATA;
143  ctx->ch[i].bitrate_acc += ctx->ch[i].bitrate_delta;
144  br[i] = ctx->ch[i].bitrate_acc >> 16;
145  sl[i] = LEVEL_DECAY(ctx->ch[i].slow_level);
146  }
147  if (ctx->stereo_in && ctx->hybrid_bitrate) {
148  int balance = (sl[1] - sl[0] + br[1] + 1) >> 1;
149  if (balance > br[0]) {
150  br[1] = br[0] * 2;
151  br[0] = 0;
152  } else if (-balance > br[0]) {
153  br[0] *= 2;
154  br[1] = 0;
155  } else {
156  br[1] = br[0] + balance;
157  br[0] = br[0] - balance;
158  }
159  }
160  for (i = 0; i <= ctx->stereo_in; i++) {
161  if (ctx->hybrid_bitrate) {
162  if (sl[i] - br[i] > -0x100)
163  ctx->ch[i].error_limit = wp_exp2(sl[i] - br[i] + 0x100);
164  else
165  ctx->ch[i].error_limit = 0;
166  } else {
167  ctx->ch[i].error_limit = wp_exp2(br[i]);
168  }
169  }
170 
171  return 0;
172 }
173 
175  int channel, int *last)
176 {
177  int t, t2;
178  int sign, base, add, ret;
179  WvChannel *c = &ctx->ch[channel];
180 
181  *last = 0;
182 
183  if ((ctx->ch[0].median[0] < 2U) && (ctx->ch[1].median[0] < 2U) &&
184  !ctx->zero && !ctx->one) {
185  if (ctx->zeroes) {
186  ctx->zeroes--;
187  if (ctx->zeroes) {
188  c->slow_level -= LEVEL_DECAY(c->slow_level);
189  return 0;
190  }
191  } else {
192  t = get_unary_0_33(gb);
193  if (t >= 2) {
194  if (t >= 32 || get_bits_left(gb) < t - 1)
195  goto error;
196  t = get_bits_long(gb, t - 1) | (1 << (t - 1));
197  } else {
198  if (get_bits_left(gb) < 0)
199  goto error;
200  }
201  ctx->zeroes = t;
202  if (ctx->zeroes) {
203  memset(ctx->ch[0].median, 0, sizeof(ctx->ch[0].median));
204  memset(ctx->ch[1].median, 0, sizeof(ctx->ch[1].median));
205  c->slow_level -= LEVEL_DECAY(c->slow_level);
206  return 0;
207  }
208  }
209  }
210 
211  if (ctx->zero) {
212  t = 0;
213  ctx->zero = 0;
214  } else {
215  t = get_unary_0_33(gb);
216  if (get_bits_left(gb) < 0)
217  goto error;
218  if (t == 16) {
219  t2 = get_unary_0_33(gb);
220  if (t2 < 2) {
221  if (get_bits_left(gb) < 0)
222  goto error;
223  t += t2;
224  } else {
225  if (t2 >= 32 || get_bits_left(gb) < t2 - 1)
226  goto error;
227  t += get_bits_long(gb, t2 - 1) | (1 << (t2 - 1));
228  }
229  }
230 
231  if (ctx->one) {
232  ctx->one = t & 1;
233  t = (t >> 1) + 1;
234  } else {
235  ctx->one = t & 1;
236  t >>= 1;
237  }
238  ctx->zero = !ctx->one;
239  }
240 
241  if (ctx->hybrid && !channel) {
242  if (update_error_limit(ctx) < 0)
243  goto error;
244  }
245 
246  if (!t) {
247  base = 0;
248  add = GET_MED(0) - 1;
249  DEC_MED(0);
250  } else if (t == 1) {
251  base = GET_MED(0);
252  add = GET_MED(1) - 1;
253  INC_MED(0);
254  DEC_MED(1);
255  } else if (t == 2) {
256  base = GET_MED(0) + GET_MED(1);
257  add = GET_MED(2) - 1;
258  INC_MED(0);
259  INC_MED(1);
260  DEC_MED(2);
261  } else {
262  base = GET_MED(0) + GET_MED(1) + GET_MED(2) * (t - 2U);
263  add = GET_MED(2) - 1;
264  INC_MED(0);
265  INC_MED(1);
266  INC_MED(2);
267  }
268  if (!c->error_limit) {
269  ret = base + get_tail(gb, add);
270  if (get_bits_left(gb) <= 0)
271  goto error;
272  } else {
273  int mid = (base * 2U + add + 1) >> 1;
274  while (add > c->error_limit) {
275  if (get_bits_left(gb) <= 0)
276  goto error;
277  if (get_bits1(gb)) {
278  add -= (mid - (unsigned)base);
279  base = mid;
280  } else
281  add = mid - (unsigned)base - 1;
282  mid = (base * 2U + add + 1) >> 1;
283  }
284  ret = mid;
285  }
286  sign = get_bits1(gb);
287  if (ctx->hybrid_bitrate)
288  c->slow_level += wp_log2(ret) - LEVEL_DECAY(c->slow_level);
289  return sign ? ~ret : ret;
290 
291 error:
292  ret = get_bits_left(gb);
293  if (ret <= 0) {
294  av_log(ctx->avctx, AV_LOG_ERROR, "Too few bits (%d) left\n", ret);
295  }
296  *last = 1;
297  return 0;
298 }
299 
300 static inline int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc,
301  unsigned S)
302 {
303  unsigned bit;
304 
305  if (s->extra_bits) {
306  S *= 1 << s->extra_bits;
307 
308  if (s->got_extra_bits &&
309  get_bits_left(&s->gb_extra_bits) >= s->extra_bits) {
310  S |= get_bits_long(&s->gb_extra_bits, s->extra_bits);
311  *crc = *crc * 9 + (S & 0xffff) * 3 + ((unsigned)S >> 16);
312  }
313  }
314 
315  bit = (S & s->and) | s->or;
316  bit = ((S + bit) << s->shift) - bit;
317 
318  if (s->hybrid)
319  bit = av_clip(bit, s->hybrid_minclip, s->hybrid_maxclip);
320 
321  return bit << s->post_shift;
322 }
323 
324 static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S)
325 {
326  union {
327  float f;
328  uint32_t u;
329  } value;
330 
331  unsigned int sign;
332  int exp = s->float_max_exp;
333 
334  if (s->got_extra_bits) {
335  const int max_bits = 1 + 23 + 8 + 1;
336  const int left_bits = get_bits_left(&s->gb_extra_bits);
337 
338  if (left_bits + 8 * AV_INPUT_BUFFER_PADDING_SIZE < max_bits)
339  return 0.0;
340  }
341 
342  if (S) {
343  S *= 1U << s->float_shift;
344  sign = S < 0;
345  if (sign)
346  S = -(unsigned)S;
347  if (S >= 0x1000000U) {
348  if (s->got_extra_bits && get_bits1(&s->gb_extra_bits))
349  S = get_bits(&s->gb_extra_bits, 23);
350  else
351  S = 0;
352  exp = 255;
353  } else if (exp) {
354  int shift = 23 - av_log2(S);
355  exp = s->float_max_exp;
356  if (exp <= shift)
357  shift = --exp;
358  exp -= shift;
359 
360  if (shift) {
361  S <<= shift;
362  if ((s->float_flag & WV_FLT_SHIFT_ONES) ||
363  (s->got_extra_bits &&
364  (s->float_flag & WV_FLT_SHIFT_SAME) &&
365  get_bits1(&s->gb_extra_bits))) {
366  S |= (1 << shift) - 1;
367  } else if (s->got_extra_bits &&
368  (s->float_flag & WV_FLT_SHIFT_SENT)) {
369  S |= get_bits(&s->gb_extra_bits, shift);
370  }
371  }
372  } else {
373  exp = s->float_max_exp;
374  }
375  S &= 0x7fffff;
376  } else {
377  sign = 0;
378  exp = 0;
379  if (s->got_extra_bits && (s->float_flag & WV_FLT_ZERO_SENT)) {
380  if (get_bits1(&s->gb_extra_bits)) {
381  S = get_bits(&s->gb_extra_bits, 23);
382  if (s->float_max_exp >= 25)
383  exp = get_bits(&s->gb_extra_bits, 8);
384  sign = get_bits1(&s->gb_extra_bits);
385  } else {
386  if (s->float_flag & WV_FLT_ZERO_SIGN)
387  sign = get_bits1(&s->gb_extra_bits);
388  }
389  }
390  }
391 
392  *crc = *crc * 27 + S * 9 + exp * 3 + sign;
393 
394  value.u = (sign << 31) | (exp << 23) | S;
395  return value.f;
396 }
397 
398 static inline int wv_check_crc(WavpackFrameContext *s, uint32_t crc,
399  uint32_t crc_extra_bits)
400 {
401  if (crc != s->CRC) {
402  av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
403  return AVERROR_INVALIDDATA;
404  }
405  if (s->got_extra_bits && crc_extra_bits != s->crc_extra_bits) {
406  av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
407  return AVERROR_INVALIDDATA;
408  }
409 
410  return 0;
411 }
412 
413 static void init_ptable(int *table, int rate_i, int rate_s)
414 {
415  int value = 0x808000, rate = rate_i << 8;
416 
417  for (int c = (rate + 128) >> 8; c--;)
418  value += (DOWN - value) >> DECAY;
419 
420  for (int i = 0; i < PTABLE_BINS/2; i++) {
421  table[i] = value;
422  table[PTABLE_BINS-1-i] = 0x100ffff - value;
423 
424  if (value > 0x010000) {
425  rate += (rate * rate_s + 128) >> 8;
426 
427  for (int c = (rate + 64) >> 7; c--;)
428  value += (DOWN - value) >> DECAY;
429  }
430  }
431 }
432 
433 typedef struct {
434  int32_t value, fltr0, fltr1, fltr2, fltr3, fltr4, fltr5, fltr6, factor;
435  unsigned int byte;
436 } DSDfilters;
437 
438 static int wv_unpack_dsd_high(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
439 {
440  uint32_t checksum = 0xFFFFFFFF;
441  uint8_t *dst_l = dst_left, *dst_r = dst_right;
442  int total_samples = s->samples, stereo = dst_r ? 1 : 0;
443  DSDfilters filters[2], *sp = filters;
444  int rate_i, rate_s;
445  uint32_t low, high, value;
446 
447  if (bytestream2_get_bytes_left(&s->gbyte) < (stereo ? 20 : 13))
448  return AVERROR_INVALIDDATA;
449 
450  rate_i = bytestream2_get_byte(&s->gbyte);
451  rate_s = bytestream2_get_byte(&s->gbyte);
452 
453  if (rate_s != RATE_S)
454  return AVERROR_INVALIDDATA;
455 
456  init_ptable(s->ptable, rate_i, rate_s);
457 
458  for (int channel = 0; channel < stereo + 1; channel++) {
460 
461  sp->fltr1 = bytestream2_get_byte(&s->gbyte) << (PRECISION - 8);
462  sp->fltr2 = bytestream2_get_byte(&s->gbyte) << (PRECISION - 8);
463  sp->fltr3 = bytestream2_get_byte(&s->gbyte) << (PRECISION - 8);
464  sp->fltr4 = bytestream2_get_byte(&s->gbyte) << (PRECISION - 8);
465  sp->fltr5 = bytestream2_get_byte(&s->gbyte) << (PRECISION - 8);
466  sp->fltr6 = 0;
467  sp->factor = bytestream2_get_byte(&s->gbyte) & 0xff;
468  sp->factor |= (bytestream2_get_byte(&s->gbyte) << 8) & 0xff00;
469  sp->factor = (int32_t)((uint32_t)sp->factor << 16) >> 16;
470  }
471 
472  value = bytestream2_get_be32(&s->gbyte);
473  high = 0xffffffff;
474  low = 0x0;
475 
476  while (total_samples--) {
477  int bitcount = 8;
478 
479  sp[0].value = sp[0].fltr1 - sp[0].fltr5 + ((sp[0].fltr6 * sp[0].factor) >> 2);
480 
481  if (stereo)
482  sp[1].value = sp[1].fltr1 - sp[1].fltr5 + ((sp[1].fltr6 * sp[1].factor) >> 2);
483 
484  while (bitcount--) {
485  int32_t *pp = s->ptable + ((sp[0].value >> (PRECISION - PRECISION_USE)) & PTABLE_MASK);
486  uint32_t split = low + ((high - low) >> 8) * (*pp >> 16);
487 
488  if (value <= split) {
489  high = split;
490  *pp += (UP - *pp) >> DECAY;
491  sp[0].fltr0 = -1;
492  } else {
493  low = split + 1;
494  *pp += (DOWN - *pp) >> DECAY;
495  sp[0].fltr0 = 0;
496  }
497 
498  if (DSD_BYTE_READY(high, low) && !bytestream2_get_bytes_left(&s->gbyte))
499  return AVERROR_INVALIDDATA;
500  while (DSD_BYTE_READY(high, low) && bytestream2_get_bytes_left(&s->gbyte)) {
501  value = (value << 8) | bytestream2_get_byte(&s->gbyte);
502  high = (high << 8) | 0xff;
503  low <<= 8;
504  }
505 
506  sp[0].value += sp[0].fltr6 * 8;
507  sp[0].byte = (sp[0].byte << 1) | (sp[0].fltr0 & 1);
508  sp[0].factor += (((sp[0].value ^ sp[0].fltr0) >> 31) | 1) &
509  ((sp[0].value ^ (sp[0].value - (sp[0].fltr6 * 16))) >> 31);
510  sp[0].fltr1 += ((sp[0].fltr0 & VALUE_ONE) - sp[0].fltr1) >> 6;
511  sp[0].fltr2 += ((sp[0].fltr0 & VALUE_ONE) - sp[0].fltr2) >> 4;
512  sp[0].fltr3 += (sp[0].fltr2 - sp[0].fltr3) >> 4;
513  sp[0].fltr4 += (sp[0].fltr3 - sp[0].fltr4) >> 4;
514  sp[0].value = (sp[0].fltr4 - sp[0].fltr5) >> 4;
515  sp[0].fltr5 += sp[0].value;
516  sp[0].fltr6 += (sp[0].value - sp[0].fltr6) >> 3;
517  sp[0].value = sp[0].fltr1 - sp[0].fltr5 + ((sp[0].fltr6 * sp[0].factor) >> 2);
518 
519  if (!stereo)
520  continue;
521 
522  pp = s->ptable + ((sp[1].value >> (PRECISION - PRECISION_USE)) & PTABLE_MASK);
523  split = low + ((high - low) >> 8) * (*pp >> 16);
524 
525  if (value <= split) {
526  high = split;
527  *pp += (UP - *pp) >> DECAY;
528  sp[1].fltr0 = -1;
529  } else {
530  low = split + 1;
531  *pp += (DOWN - *pp) >> DECAY;
532  sp[1].fltr0 = 0;
533  }
534 
535  if (DSD_BYTE_READY(high, low) && !bytestream2_get_bytes_left(&s->gbyte))
536  return AVERROR_INVALIDDATA;
537  while (DSD_BYTE_READY(high, low) && bytestream2_get_bytes_left(&s->gbyte)) {
538  value = (value << 8) | bytestream2_get_byte(&s->gbyte);
539  high = (high << 8) | 0xff;
540  low <<= 8;
541  }
542 
543  sp[1].value += sp[1].fltr6 * 8;
544  sp[1].byte = (sp[1].byte << 1) | (sp[1].fltr0 & 1);
545  sp[1].factor += (((sp[1].value ^ sp[1].fltr0) >> 31) | 1) &
546  ((sp[1].value ^ (sp[1].value - (sp[1].fltr6 * 16))) >> 31);
547  sp[1].fltr1 += ((sp[1].fltr0 & VALUE_ONE) - sp[1].fltr1) >> 6;
548  sp[1].fltr2 += ((sp[1].fltr0 & VALUE_ONE) - sp[1].fltr2) >> 4;
549  sp[1].fltr3 += (sp[1].fltr2 - sp[1].fltr3) >> 4;
550  sp[1].fltr4 += (sp[1].fltr3 - sp[1].fltr4) >> 4;
551  sp[1].value = (sp[1].fltr4 - sp[1].fltr5) >> 4;
552  sp[1].fltr5 += sp[1].value;
553  sp[1].fltr6 += (sp[1].value - sp[1].fltr6) >> 3;
554  sp[1].value = sp[1].fltr1 - sp[1].fltr5 + ((sp[1].fltr6 * sp[1].factor) >> 2);
555  }
556 
557  checksum += (checksum << 1) + (*dst_l = sp[0].byte & 0xff);
558  sp[0].factor -= (sp[0].factor + 512) >> 10;
559  dst_l += 4;
560 
561  if (stereo) {
562  checksum += (checksum << 1) + (*dst_r = filters[1].byte & 0xff);
563  filters[1].factor -= (filters[1].factor + 512) >> 10;
564  dst_r += 4;
565  }
566  }
567 
568  if (wv_check_crc(s, checksum, 0)) {
569  if (s->avctx->err_recognition & AV_EF_CRCCHECK)
570  return AVERROR_INVALIDDATA;
571 
572  memset(dst_left, 0x69, s->samples * 4);
573 
574  if (dst_r)
575  memset(dst_right, 0x69, s->samples * 4);
576  }
577 
578  return 0;
579 }
580 
581 static int wv_unpack_dsd_fast(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
582 {
583  uint8_t *dst_l = dst_left, *dst_r = dst_right;
584  uint8_t history_bits, max_probability;
585  int total_summed_probabilities = 0;
586  int total_samples = s->samples;
587  uint8_t *vlb = s->value_lookup_buffer;
588  int history_bins, p0, p1, chan;
589  uint32_t checksum = 0xFFFFFFFF;
590  uint32_t low, high, value;
591 
592  if (!bytestream2_get_bytes_left(&s->gbyte))
593  return AVERROR_INVALIDDATA;
594 
595  history_bits = bytestream2_get_byte(&s->gbyte);
596 
597  if (!bytestream2_get_bytes_left(&s->gbyte) || history_bits > MAX_HISTORY_BITS)
598  return AVERROR_INVALIDDATA;
599 
600  history_bins = 1 << history_bits;
601  max_probability = bytestream2_get_byte(&s->gbyte);
602 
603  if (max_probability < 0xff) {
604  uint8_t *outptr = (uint8_t *)s->probabilities;
605  uint8_t *outend = outptr + sizeof(*s->probabilities) * history_bins;
606 
607  while (outptr < outend && bytestream2_get_bytes_left(&s->gbyte)) {
608  int code = bytestream2_get_byte(&s->gbyte);
609 
610  if (code > max_probability) {
611  int zcount = code - max_probability;
612 
613  while (outptr < outend && zcount--)
614  *outptr++ = 0;
615  } else if (code) {
616  *outptr++ = code;
617  }
618  else {
619  break;
620  }
621  }
622 
623  if (outptr < outend ||
624  (bytestream2_get_bytes_left(&s->gbyte) && bytestream2_get_byte(&s->gbyte)))
625  return AVERROR_INVALIDDATA;
626  } else if (bytestream2_get_bytes_left(&s->gbyte) > (int)sizeof(*s->probabilities) * history_bins) {
627  bytestream2_get_buffer(&s->gbyte, (uint8_t *)s->probabilities,
628  sizeof(*s->probabilities) * history_bins);
629  } else {
630  return AVERROR_INVALIDDATA;
631  }
632 
633  for (p0 = 0; p0 < history_bins; p0++) {
634  int32_t sum_values = 0;
635 
636  for (int i = 0; i < 256; i++)
637  s->summed_probabilities[p0][i] = sum_values += s->probabilities[p0][i];
638 
639  if (sum_values) {
640  total_summed_probabilities += sum_values;
641 
642  if (total_summed_probabilities > history_bins * MAX_BIN_BYTES)
643  return AVERROR_INVALIDDATA;
644 
645  s->value_lookup[p0] = vlb;
646 
647  for (int i = 0; i < 256; i++) {
648  int c = s->probabilities[p0][i];
649 
650  while (c--)
651  *vlb++ = i;
652  }
653  }
654  }
655 
656  if (bytestream2_get_bytes_left(&s->gbyte) < 4)
657  return AVERROR_INVALIDDATA;
658 
659  chan = p0 = p1 = 0;
660  low = 0; high = 0xffffffff;
661  value = bytestream2_get_be32(&s->gbyte);
662 
663  if (dst_r)
664  total_samples *= 2;
665 
666  while (total_samples--) {
667  unsigned int mult, index, code;
668 
669  if (!s->summed_probabilities[p0][255])
670  return AVERROR_INVALIDDATA;
671 
672  mult = (high - low) / s->summed_probabilities[p0][255];
673 
674  if (!mult) {
675  if (bytestream2_get_bytes_left(&s->gbyte) >= 4)
676  value = bytestream2_get_be32(&s->gbyte);
677 
678  low = 0;
679  high = 0xffffffff;
680  mult = high / s->summed_probabilities[p0][255];
681 
682  if (!mult)
683  return AVERROR_INVALIDDATA;
684  }
685 
686  index = (value - low) / mult;
687 
688  if (index >= s->summed_probabilities[p0][255])
689  return AVERROR_INVALIDDATA;
690 
691  if (!dst_r) {
692  if ((*dst_l = code = s->value_lookup[p0][index]))
693  low += s->summed_probabilities[p0][code-1] * mult;
694 
695  dst_l += 4;
696  } else {
697  if ((code = s->value_lookup[p0][index]))
698  low += s->summed_probabilities[p0][code-1] * mult;
699 
700  if (chan) {
701  *dst_r = code;
702  dst_r += 4;
703  }
704  else {
705  *dst_l = code;
706  dst_l += 4;
707  }
708 
709  chan ^= 1;
710  }
711 
712  high = low + s->probabilities[p0][code] * mult - 1;
713  checksum += (checksum << 1) + code;
714 
715  if (!dst_r) {
716  p0 = code & (history_bins-1);
717  } else {
718  p0 = p1;
719  p1 = code & (history_bins-1);
720  }
721 
722  while (DSD_BYTE_READY(high, low) && bytestream2_get_bytes_left(&s->gbyte)) {
723  value = (value << 8) | bytestream2_get_byte(&s->gbyte);
724  high = (high << 8) | 0xff;
725  low <<= 8;
726  }
727  }
728 
729  if (wv_check_crc(s, checksum, 0)) {
730  if (s->avctx->err_recognition & AV_EF_CRCCHECK)
731  return AVERROR_INVALIDDATA;
732 
733  memset(dst_left, 0x69, s->samples * 4);
734 
735  if (dst_r)
736  memset(dst_right, 0x69, s->samples * 4);
737  }
738 
739  return 0;
740 }
741 
742 static int wv_unpack_dsd_copy(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
743 {
744  uint8_t *dst_l = dst_left, *dst_r = dst_right;
745  int total_samples = s->samples;
746  uint32_t checksum = 0xFFFFFFFF;
747 
748  if (bytestream2_get_bytes_left(&s->gbyte) != total_samples * (dst_r ? 2 : 1))
749  return AVERROR_INVALIDDATA;
750 
751  while (total_samples--) {
752  checksum += (checksum << 1) + (*dst_l = bytestream2_get_byte(&s->gbyte));
753  dst_l += 4;
754 
755  if (dst_r) {
756  checksum += (checksum << 1) + (*dst_r = bytestream2_get_byte(&s->gbyte));
757  dst_r += 4;
758  }
759  }
760 
761  if (wv_check_crc(s, checksum, 0)) {
762  if (s->avctx->err_recognition & AV_EF_CRCCHECK)
763  return AVERROR_INVALIDDATA;
764 
765  memset(dst_left, 0x69, s->samples * 4);
766 
767  if (dst_r)
768  memset(dst_right, 0x69, s->samples * 4);
769  }
770 
771  return 0;
772 }
773 
775  void *dst_l, void *dst_r, const int type)
776 {
777  int i, j, count = 0;
778  int last, t;
779  int A, B, L, L2, R, R2;
780  int pos = 0;
781  uint32_t crc = 0xFFFFFFFF;
782  uint32_t crc_extra_bits = 0xFFFFFFFF;
783  int16_t *dst16_l = dst_l;
784  int16_t *dst16_r = dst_r;
785  int32_t *dst32_l = dst_l;
786  int32_t *dst32_r = dst_r;
787  float *dstfl_l = dst_l;
788  float *dstfl_r = dst_r;
789 
790  s->one = s->zero = s->zeroes = 0;
791  do {
792  L = wv_get_value(s, gb, 0, &last);
793  if (last)
794  break;
795  R = wv_get_value(s, gb, 1, &last);
796  if (last)
797  break;
798  for (i = 0; i < s->terms; i++) {
799  t = s->decorr[i].value;
800  if (t > 0) {
801  if (t > 8) {
802  if (t & 1) {
803  A = 2U * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1];
804  B = 2U * s->decorr[i].samplesB[0] - s->decorr[i].samplesB[1];
805  } else {
806  A = (int)(3U * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1]) >> 1;
807  B = (int)(3U * s->decorr[i].samplesB[0] - s->decorr[i].samplesB[1]) >> 1;
808  }
809  s->decorr[i].samplesA[1] = s->decorr[i].samplesA[0];
810  s->decorr[i].samplesB[1] = s->decorr[i].samplesB[0];
811  j = 0;
812  } else {
813  A = s->decorr[i].samplesA[pos];
814  B = s->decorr[i].samplesB[pos];
815  j = (pos + t) & 7;
816  }
817  if (type != AV_SAMPLE_FMT_S16P) {
818  L2 = L + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10);
819  R2 = R + ((s->decorr[i].weightB * (int64_t)B + 512) >> 10);
820  } else {
821  L2 = L + (unsigned)((int)(s->decorr[i].weightA * (unsigned)A + 512) >> 10);
822  R2 = R + (unsigned)((int)(s->decorr[i].weightB * (unsigned)B + 512) >> 10);
823  }
824  if (A && L)
825  s->decorr[i].weightA -= ((((L ^ A) >> 30) & 2) - 1) * s->decorr[i].delta;
826  if (B && R)
827  s->decorr[i].weightB -= ((((R ^ B) >> 30) & 2) - 1) * s->decorr[i].delta;
828  s->decorr[i].samplesA[j] = L = L2;
829  s->decorr[i].samplesB[j] = R = R2;
830  } else if (t == -1) {
831  if (type != AV_SAMPLE_FMT_S16P)
832  L2 = L + ((s->decorr[i].weightA * (int64_t)s->decorr[i].samplesA[0] + 512) >> 10);
833  else
834  L2 = L + (unsigned)((int)(s->decorr[i].weightA * (unsigned)s->decorr[i].samplesA[0] + 512) >> 10);
835  UPDATE_WEIGHT_CLIP(s->decorr[i].weightA, s->decorr[i].delta, s->decorr[i].samplesA[0], L);
836  L = L2;
837  if (type != AV_SAMPLE_FMT_S16P)
838  R2 = R + ((s->decorr[i].weightB * (int64_t)L2 + 512) >> 10);
839  else
840  R2 = R + (unsigned)((int)(s->decorr[i].weightB * (unsigned)L2 + 512) >> 10);
841  UPDATE_WEIGHT_CLIP(s->decorr[i].weightB, s->decorr[i].delta, L2, R);
842  R = R2;
843  s->decorr[i].samplesA[0] = R;
844  } else {
845  if (type != AV_SAMPLE_FMT_S16P)
846  R2 = R + ((s->decorr[i].weightB * (int64_t)s->decorr[i].samplesB[0] + 512) >> 10);
847  else
848  R2 = R + (unsigned)((int)(s->decorr[i].weightB * (unsigned)s->decorr[i].samplesB[0] + 512) >> 10);
849  UPDATE_WEIGHT_CLIP(s->decorr[i].weightB, s->decorr[i].delta, s->decorr[i].samplesB[0], R);
850  R = R2;
851 
852  if (t == -3) {
853  R2 = s->decorr[i].samplesA[0];
854  s->decorr[i].samplesA[0] = R;
855  }
856 
857  if (type != AV_SAMPLE_FMT_S16P)
858  L2 = L + ((s->decorr[i].weightA * (int64_t)R2 + 512) >> 10);
859  else
860  L2 = L + (unsigned)((int)(s->decorr[i].weightA * (unsigned)R2 + 512) >> 10);
861  UPDATE_WEIGHT_CLIP(s->decorr[i].weightA, s->decorr[i].delta, R2, L);
862  L = L2;
863  s->decorr[i].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  t = s->decorr[i].value;
926  if (t > 8) {
927  if (t & 1)
928  A = 2U * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1];
929  else
930  A = (int)(3U * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1]) >> 1;
931  s->decorr[i].samplesA[1] = s->decorr[i].samplesA[0];
932  j = 0;
933  } else {
934  A = s->decorr[i].samplesA[pos];
935  j = (pos + t) & 7;
936  }
937  if (type != AV_SAMPLE_FMT_S16P)
938  S = T + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10);
939  else
940  S = T + (unsigned)((int)(s->decorr[i].weightA * (unsigned)A + 512) >> 10);
941  if (A && T)
942  s->decorr[i].weightA -= ((((T ^ A) >> 30) & 2) - 1) * s->decorr[i].delta;
943  s->decorr[i].samplesA[j] = T = S;
944  }
945  pos = (pos + 1) & 7;
946  crc = crc * 3 + S;
947 
948  if (type == AV_SAMPLE_FMT_FLTP) {
949  *dstfl++ = wv_get_value_float(s, &crc_extra_bits, S);
950  } else if (type == AV_SAMPLE_FMT_S32P) {
951  *dst32++ = wv_get_value_integer(s, &crc_extra_bits, S);
952  } else {
953  *dst16++ = wv_get_value_integer(s, &crc_extra_bits, S);
954  }
955  count++;
956  } while (!last && count < s->samples);
957 
958  if (last && count < s->samples) {
960  memset((uint8_t*)dst + count*size, 0, (s->samples-count)*size);
961  }
962 
963  if (s->avctx->err_recognition & AV_EF_CRCCHECK) {
964  int ret = wv_check_crc(s, crc, crc_extra_bits);
965  if (ret < 0 && s->avctx->err_recognition & AV_EF_EXPLODE)
966  return ret;
967  }
968 
969  return 0;
970 }
971 
973 {
974  if (c->fdec_num == WV_MAX_FRAME_DECODERS)
975  return -1;
976 
977  c->fdec[c->fdec_num] = av_mallocz(sizeof(**c->fdec));
978  if (!c->fdec[c->fdec_num])
979  return -1;
980  c->fdec_num++;
981  c->fdec[c->fdec_num - 1]->avctx = c->avctx;
982 
983  return 0;
984 }
985 
987 {
988  int i;
989 
990  s->dsdctx = NULL;
991  s->dsd_channels = 0;
992  av_buffer_unref(&s->dsd_ref);
993 
994  if (!channels)
995  return 0;
996 
997  if (channels > INT_MAX / sizeof(*s->dsdctx))
998  return AVERROR(EINVAL);
999 
1000  s->dsd_ref = av_buffer_allocz(channels * sizeof(*s->dsdctx));
1001  if (!s->dsd_ref)
1002  return AVERROR(ENOMEM);
1003  s->dsdctx = (DSDContext*)s->dsd_ref->data;
1004  s->dsd_channels = channels;
1005 
1006  for (i = 0; i < channels; i++)
1007  memset(s->dsdctx[i].buf, 0x69, sizeof(s->dsdctx[i].buf));
1008 
1009  return 0;
1010 }
1011 
1012 #if HAVE_THREADS
1013 static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
1014 {
1015  WavpackContext *fsrc = src->priv_data;
1016  WavpackContext *fdst = dst->priv_data;
1017  int ret;
1018 
1019  if (dst == src)
1020  return 0;
1021 
1023  if (fsrc->curr_frame.f->data[0]) {
1024  if ((ret = ff_thread_ref_frame(&fdst->curr_frame, &fsrc->curr_frame)) < 0)
1025  return ret;
1026  }
1027 
1028  fdst->dsdctx = NULL;
1029  fdst->dsd_channels = 0;
1030  ret = av_buffer_replace(&fdst->dsd_ref, fsrc->dsd_ref);
1031  if (ret < 0)
1032  return ret;
1033  if (fsrc->dsd_ref) {
1034  fdst->dsdctx = (DSDContext*)fdst->dsd_ref->data;
1035  fdst->dsd_channels = fsrc->dsd_channels;
1036  }
1037 
1038  return 0;
1039 }
1040 #endif
1041 
1043 {
1044  WavpackContext *s = avctx->priv_data;
1045 
1046  s->avctx = avctx;
1047 
1048  s->fdec_num = 0;
1049 
1050  s->curr_frame.f = av_frame_alloc();
1051  s->prev_frame.f = av_frame_alloc();
1052 
1053  if (!s->curr_frame.f || !s->prev_frame.f)
1054  return AVERROR(ENOMEM);
1055 
1056  ff_init_dsd_data();
1057 
1058  return 0;
1059 }
1060 
1062 {
1063  WavpackContext *s = avctx->priv_data;
1064 
1065  for (int i = 0; i < s->fdec_num; i++)
1066  av_freep(&s->fdec[i]);
1067  s->fdec_num = 0;
1068 
1069  ff_thread_release_ext_buffer(avctx, &s->curr_frame);
1070  av_frame_free(&s->curr_frame.f);
1071 
1072  ff_thread_release_ext_buffer(avctx, &s->prev_frame);
1073  av_frame_free(&s->prev_frame.f);
1074 
1075  av_buffer_unref(&s->dsd_ref);
1076 
1077  return 0;
1078 }
1079 
1080 static int wavpack_decode_block(AVCodecContext *avctx, int block_no,
1081  const uint8_t *buf, int buf_size)
1082 {
1083  WavpackContext *wc = avctx->priv_data;
1085  GetByteContext gb;
1086  enum AVSampleFormat sample_fmt;
1087  void *samples_l = NULL, *samples_r = NULL;
1088  int ret;
1089  int got_terms = 0, got_weights = 0, got_samples = 0,
1090  got_entropy = 0, got_pcm = 0, got_float = 0, got_hybrid = 0;
1091  int got_dsd = 0;
1092  int i, j, id, size, ssize, weights, t;
1093  int bpp, chan = 0, orig_bpp, sample_rate = 0, rate_x = 1, dsd_mode = 0;
1094  int multiblock;
1095  uint64_t chmask = 0;
1096 
1097  if (block_no >= wc->fdec_num && wv_alloc_frame_context(wc) < 0) {
1098  av_log(avctx, AV_LOG_ERROR, "Error creating frame decode context\n");
1099  return AVERROR_INVALIDDATA;
1100  }
1101 
1102  s = wc->fdec[block_no];
1103  if (!s) {
1104  av_log(avctx, AV_LOG_ERROR, "Context for block %d is not present\n",
1105  block_no);
1106  return AVERROR_INVALIDDATA;
1107  }
1108 
1109  memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr));
1110  memset(s->ch, 0, sizeof(s->ch));
1111  s->extra_bits = 0;
1112  s->and = s->or = s->shift = 0;
1113  s->got_extra_bits = 0;
1114 
1115  bytestream2_init(&gb, buf, buf_size);
1116 
1117  s->samples = bytestream2_get_le32(&gb);
1118  if (s->samples != wc->samples) {
1119  av_log(avctx, AV_LOG_ERROR, "Mismatching number of samples in "
1120  "a sequence: %d and %d\n", wc->samples, s->samples);
1121  return AVERROR_INVALIDDATA;
1122  }
1123  s->frame_flags = bytestream2_get_le32(&gb);
1124 
1125  if (s->frame_flags & (WV_FLOAT_DATA | WV_DSD_DATA))
1126  sample_fmt = AV_SAMPLE_FMT_FLTP;
1127  else if ((s->frame_flags & 0x03) <= 1)
1128  sample_fmt = AV_SAMPLE_FMT_S16P;
1129  else
1130  sample_fmt = AV_SAMPLE_FMT_S32P;
1131 
1132  if (wc->ch_offset && avctx->sample_fmt != sample_fmt)
1133  return AVERROR_INVALIDDATA;
1134 
1135  bpp = av_get_bytes_per_sample(sample_fmt);
1136  orig_bpp = ((s->frame_flags & 0x03) + 1) << 3;
1137  multiblock = (s->frame_flags & WV_SINGLE_BLOCK) != WV_SINGLE_BLOCK;
1138 
1139  s->stereo = !(s->frame_flags & WV_MONO);
1140  s->stereo_in = (s->frame_flags & WV_FALSE_STEREO) ? 0 : s->stereo;
1141  s->joint = s->frame_flags & WV_JOINT_STEREO;
1142  s->hybrid = s->frame_flags & WV_HYBRID_MODE;
1143  s->hybrid_bitrate = s->frame_flags & WV_HYBRID_BITRATE;
1144  s->post_shift = bpp * 8 - orig_bpp + ((s->frame_flags >> 13) & 0x1f);
1145  if (s->post_shift < 0 || s->post_shift > 31) {
1146  return AVERROR_INVALIDDATA;
1147  }
1148  s->hybrid_maxclip = ((1LL << (orig_bpp - 1)) - 1);
1149  s->hybrid_minclip = ((-1UL << (orig_bpp - 1)));
1150  s->CRC = bytestream2_get_le32(&gb);
1151 
1152  // parse metadata blocks
1153  while (bytestream2_get_bytes_left(&gb)) {
1154  id = bytestream2_get_byte(&gb);
1155  size = bytestream2_get_byte(&gb);
1156  if (id & WP_IDF_LONG)
1157  size |= (bytestream2_get_le16u(&gb)) << 8;
1158  size <<= 1; // size is specified in words
1159  ssize = size;
1160  if (id & WP_IDF_ODD)
1161  size--;
1162  if (size < 0) {
1163  av_log(avctx, AV_LOG_ERROR,
1164  "Got incorrect block %02X with size %i\n", id, size);
1165  break;
1166  }
1167  if (bytestream2_get_bytes_left(&gb) < ssize) {
1168  av_log(avctx, AV_LOG_ERROR,
1169  "Block size %i is out of bounds\n", size);
1170  break;
1171  }
1172  switch (id & WP_IDF_MASK) {
1173  case WP_ID_DECTERMS:
1174  if (size > MAX_TERMS) {
1175  av_log(avctx, AV_LOG_ERROR, "Too many decorrelation terms\n");
1176  s->terms = 0;
1177  bytestream2_skip(&gb, ssize);
1178  continue;
1179  }
1180  s->terms = size;
1181  for (i = 0; i < s->terms; i++) {
1182  uint8_t val = bytestream2_get_byte(&gb);
1183  s->decorr[s->terms - i - 1].value = (val & 0x1F) - 5;
1184  s->decorr[s->terms - i - 1].delta = val >> 5;
1185  }
1186  got_terms = 1;
1187  break;
1188  case WP_ID_DECWEIGHTS:
1189  if (!got_terms) {
1190  av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
1191  continue;
1192  }
1193  weights = size >> s->stereo_in;
1194  if (weights > MAX_TERMS || weights > s->terms) {
1195  av_log(avctx, AV_LOG_ERROR, "Too many decorrelation weights\n");
1196  bytestream2_skip(&gb, ssize);
1197  continue;
1198  }
1199  for (i = 0; i < weights; i++) {
1200  t = (int8_t)bytestream2_get_byte(&gb);
1201  s->decorr[s->terms - i - 1].weightA = t * (1 << 3);
1202  if (s->decorr[s->terms - i - 1].weightA > 0)
1203  s->decorr[s->terms - i - 1].weightA +=
1204  (s->decorr[s->terms - i - 1].weightA + 64) >> 7;
1205  if (s->stereo_in) {
1206  t = (int8_t)bytestream2_get_byte(&gb);
1207  s->decorr[s->terms - i - 1].weightB = t * (1 << 3);
1208  if (s->decorr[s->terms - i - 1].weightB > 0)
1209  s->decorr[s->terms - i - 1].weightB +=
1210  (s->decorr[s->terms - i - 1].weightB + 64) >> 7;
1211  }
1212  }
1213  got_weights = 1;
1214  break;
1215  case WP_ID_DECSAMPLES:
1216  if (!got_terms) {
1217  av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n");
1218  continue;
1219  }
1220  t = 0;
1221  for (i = s->terms - 1; (i >= 0) && (t < size); i--) {
1222  if (s->decorr[i].value > 8) {
1223  s->decorr[i].samplesA[0] =
1224  wp_exp2(bytestream2_get_le16(&gb));
1225  s->decorr[i].samplesA[1] =
1226  wp_exp2(bytestream2_get_le16(&gb));
1227 
1228  if (s->stereo_in) {
1229  s->decorr[i].samplesB[0] =
1230  wp_exp2(bytestream2_get_le16(&gb));
1231  s->decorr[i].samplesB[1] =
1232  wp_exp2(bytestream2_get_le16(&gb));
1233  t += 4;
1234  }
1235  t += 4;
1236  } else if (s->decorr[i].value < 0) {
1237  s->decorr[i].samplesA[0] =
1238  wp_exp2(bytestream2_get_le16(&gb));
1239  s->decorr[i].samplesB[0] =
1240  wp_exp2(bytestream2_get_le16(&gb));
1241  t += 4;
1242  } else {
1243  for (j = 0; j < s->decorr[i].value; j++) {
1244  s->decorr[i].samplesA[j] =
1245  wp_exp2(bytestream2_get_le16(&gb));
1246  if (s->stereo_in) {
1247  s->decorr[i].samplesB[j] =
1248  wp_exp2(bytestream2_get_le16(&gb));
1249  }
1250  }
1251  t += s->decorr[i].value * 2 * (s->stereo_in + 1);
1252  }
1253  }
1254  got_samples = 1;
1255  break;
1256  case WP_ID_ENTROPY:
1257  if (size != 6 * (s->stereo_in + 1)) {
1258  av_log(avctx, AV_LOG_ERROR,
1259  "Entropy vars size should be %i, got %i.\n",
1260  6 * (s->stereo_in + 1), size);
1261  bytestream2_skip(&gb, ssize);
1262  continue;
1263  }
1264  for (j = 0; j <= s->stereo_in; j++)
1265  for (i = 0; i < 3; i++) {
1266  s->ch[j].median[i] = wp_exp2(bytestream2_get_le16(&gb));
1267  }
1268  got_entropy = 1;
1269  break;
1270  case WP_ID_HYBRID:
1271  if (s->hybrid_bitrate) {
1272  for (i = 0; i <= s->stereo_in; i++) {
1273  s->ch[i].slow_level = wp_exp2(bytestream2_get_le16(&gb));
1274  size -= 2;
1275  }
1276  }
1277  for (i = 0; i < (s->stereo_in + 1); i++) {
1278  s->ch[i].bitrate_acc = bytestream2_get_le16(&gb) << 16;
1279  size -= 2;
1280  }
1281  if (size > 0) {
1282  for (i = 0; i < (s->stereo_in + 1); i++) {
1283  s->ch[i].bitrate_delta =
1284  wp_exp2((int16_t)bytestream2_get_le16(&gb));
1285  }
1286  } else {
1287  for (i = 0; i < (s->stereo_in + 1); i++)
1288  s->ch[i].bitrate_delta = 0;
1289  }
1290  got_hybrid = 1;
1291  break;
1292  case WP_ID_INT32INFO: {
1293  uint8_t val[4];
1294  if (size != 4) {
1295  av_log(avctx, AV_LOG_ERROR,
1296  "Invalid INT32INFO, size = %i\n",
1297  size);
1298  bytestream2_skip(&gb, ssize - 4);
1299  continue;
1300  }
1301  bytestream2_get_buffer(&gb, val, 4);
1302  if (val[0] > 30) {
1303  av_log(avctx, AV_LOG_ERROR,
1304  "Invalid INT32INFO, extra_bits = %d (> 30)\n", val[0]);
1305  continue;
1306  } else {
1307  s->extra_bits = val[0];
1308  }
1309  if (val[1])
1310  s->shift = val[1];
1311  if (val[2]) {
1312  s->and = s->or = 1;
1313  s->shift = val[2];
1314  }
1315  if (val[3]) {
1316  s->and = 1;
1317  s->shift = val[3];
1318  }
1319  if (s->shift > 31) {
1320  av_log(avctx, AV_LOG_ERROR,
1321  "Invalid INT32INFO, shift = %d (> 31)\n", s->shift);
1322  s->and = s->or = s->shift = 0;
1323  continue;
1324  }
1325  /* original WavPack decoder forces 32-bit lossy sound to be treated
1326  * as 24-bit one in order to have proper clipping */
1327  if (s->hybrid && bpp == 4 && s->post_shift < 8 && s->shift > 8) {
1328  s->post_shift += 8;
1329  s->shift -= 8;
1330  s->hybrid_maxclip >>= 8;
1331  s->hybrid_minclip >>= 8;
1332  }
1333  break;
1334  }
1335  case WP_ID_FLOATINFO:
1336  if (size != 4) {
1337  av_log(avctx, AV_LOG_ERROR,
1338  "Invalid FLOATINFO, size = %i\n", size);
1339  bytestream2_skip(&gb, ssize);
1340  continue;
1341  }
1342  s->float_flag = bytestream2_get_byte(&gb);
1343  s->float_shift = bytestream2_get_byte(&gb);
1344  s->float_max_exp = bytestream2_get_byte(&gb);
1345  if (s->float_shift > 31) {
1346  av_log(avctx, AV_LOG_ERROR,
1347  "Invalid FLOATINFO, shift = %d (> 31)\n", s->float_shift);
1348  s->float_shift = 0;
1349  continue;
1350  }
1351  got_float = 1;
1352  bytestream2_skip(&gb, 1);
1353  break;
1354  case WP_ID_DATA:
1355  if ((ret = init_get_bits8(&s->gb, gb.buffer, size)) < 0)
1356  return ret;
1357  bytestream2_skip(&gb, size);
1358  got_pcm = 1;
1359  break;
1360  case WP_ID_DSD_DATA:
1361  if (size < 2) {
1362  av_log(avctx, AV_LOG_ERROR, "Invalid DSD_DATA, size = %i\n",
1363  size);
1364  bytestream2_skip(&gb, ssize);
1365  continue;
1366  }
1367  rate_x = bytestream2_get_byte(&gb);
1368  if (rate_x > 30)
1369  return AVERROR_INVALIDDATA;
1370  rate_x = 1 << rate_x;
1371  dsd_mode = bytestream2_get_byte(&gb);
1372  if (dsd_mode && dsd_mode != 1 && dsd_mode != 3) {
1373  av_log(avctx, AV_LOG_ERROR, "Invalid DSD encoding mode: %d\n",
1374  dsd_mode);
1375  return AVERROR_INVALIDDATA;
1376  }
1377  bytestream2_init(&s->gbyte, gb.buffer, size-2);
1378  bytestream2_skip(&gb, size-2);
1379  got_dsd = 1;
1380  break;
1381  case WP_ID_EXTRABITS:
1382  if (size <= 4) {
1383  av_log(avctx, AV_LOG_ERROR, "Invalid EXTRABITS, size = %i\n",
1384  size);
1385  bytestream2_skip(&gb, size);
1386  continue;
1387  }
1388  if ((ret = init_get_bits8(&s->gb_extra_bits, gb.buffer, size)) < 0)
1389  return ret;
1390  s->crc_extra_bits = get_bits_long(&s->gb_extra_bits, 32);
1391  bytestream2_skip(&gb, size);
1392  s->got_extra_bits = 1;
1393  break;
1394  case WP_ID_CHANINFO:
1395  if (size <= 1) {
1396  av_log(avctx, AV_LOG_ERROR,
1397  "Insufficient channel information\n");
1398  return AVERROR_INVALIDDATA;
1399  }
1400  chan = bytestream2_get_byte(&gb);
1401  switch (size - 2) {
1402  case 0:
1403  chmask = bytestream2_get_byte(&gb);
1404  break;
1405  case 1:
1406  chmask = bytestream2_get_le16(&gb);
1407  break;
1408  case 2:
1409  chmask = bytestream2_get_le24(&gb);
1410  break;
1411  case 3:
1412  chmask = bytestream2_get_le32(&gb);
1413  break;
1414  case 4:
1415  size = bytestream2_get_byte(&gb);
1416  chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
1417  chan += 1;
1418  if (avctx->ch_layout.nb_channels != chan)
1419  av_log(avctx, AV_LOG_WARNING, "%i channels signalled"
1420  " instead of %i.\n", chan, avctx->ch_layout.nb_channels);
1421  chmask = bytestream2_get_le24(&gb);
1422  break;
1423  case 5:
1424  size = bytestream2_get_byte(&gb);
1425  chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
1426  chan += 1;
1427  if (avctx->ch_layout.nb_channels != chan)
1428  av_log(avctx, AV_LOG_WARNING, "%i channels signalled"
1429  " instead of %i.\n", chan, avctx->ch_layout.nb_channels);
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  ret = av_channel_layout_copy(&new_ch_layout, &avctx->ch_layout);
1523  if (ret < 0) {
1524  av_log(avctx, AV_LOG_ERROR, "Error copying channel layout\n");
1525  return ret;
1526  }
1527  }
1528  } else {
1529  av_channel_layout_default(&new_ch_layout, s->stereo + 1);
1530  }
1531 
1532  /* clear DSD state if stream properties change */
1533  if (new_ch_layout.nb_channels != wc->dsd_channels ||
1534  av_channel_layout_compare(&new_ch_layout, &avctx->ch_layout) ||
1535  new_samplerate != avctx->sample_rate ||
1536  !!got_dsd != !!wc->dsdctx) {
1537  ret = wv_dsd_reset(wc, got_dsd ? new_ch_layout.nb_channels : 0);
1538  if (ret < 0) {
1539  av_log(avctx, AV_LOG_ERROR, "Error reinitializing the DSD context\n");
1540  return ret;
1541  }
1543  }
1544  av_channel_layout_copy(&avctx->ch_layout, &new_ch_layout);
1545  avctx->sample_rate = new_samplerate;
1546  avctx->sample_fmt = sample_fmt;
1547  avctx->bits_per_raw_sample = orig_bpp;
1548 
1551 
1552  /* get output buffer */
1553  wc->curr_frame.f->nb_samples = s->samples;
1554  ret = ff_thread_get_ext_buffer(avctx, &wc->curr_frame,
1556  if (ret < 0)
1557  return ret;
1558 
1559  wc->frame = wc->curr_frame.f;
1560  ff_thread_finish_setup(avctx);
1561  }
1562 
1563  if (wc->ch_offset + s->stereo >= avctx->ch_layout.nb_channels) {
1564  av_log(avctx, AV_LOG_WARNING, "Too many channels coded in a packet.\n");
1565  return ((avctx->err_recognition & AV_EF_EXPLODE) || !wc->ch_offset) ? AVERROR_INVALIDDATA : 0;
1566  }
1567 
1568  samples_l = wc->frame->extended_data[wc->ch_offset];
1569  if (s->stereo)
1570  samples_r = wc->frame->extended_data[wc->ch_offset + 1];
1571 
1572  wc->ch_offset += 1 + s->stereo;
1573 
1574  if (s->stereo_in) {
1575  if (got_dsd) {
1576  if (dsd_mode == 3) {
1577  ret = wv_unpack_dsd_high(s, samples_l, samples_r);
1578  } else if (dsd_mode == 1) {
1579  ret = wv_unpack_dsd_fast(s, samples_l, samples_r);
1580  } else {
1581  ret = wv_unpack_dsd_copy(s, samples_l, samples_r);
1582  }
1583  } else {
1584  ret = wv_unpack_stereo(s, &s->gb, samples_l, samples_r, avctx->sample_fmt);
1585  }
1586  if (ret < 0)
1587  return ret;
1588  } else {
1589  if (got_dsd) {
1590  if (dsd_mode == 3) {
1591  ret = wv_unpack_dsd_high(s, samples_l, NULL);
1592  } else if (dsd_mode == 1) {
1593  ret = wv_unpack_dsd_fast(s, samples_l, NULL);
1594  } else {
1595  ret = wv_unpack_dsd_copy(s, samples_l, NULL);
1596  }
1597  } else {
1598  ret = wv_unpack_mono(s, &s->gb, samples_l, avctx->sample_fmt);
1599  }
1600  if (ret < 0)
1601  return ret;
1602 
1603  if (s->stereo)
1604  memcpy(samples_r, samples_l, bpp * s->samples);
1605  }
1606 
1607  return 0;
1608 }
1609 
1611 {
1612  WavpackContext *s = avctx->priv_data;
1613 
1614  wv_dsd_reset(s, 0);
1615 }
1616 
1617 static int dsd_channel(AVCodecContext *avctx, void *frmptr, int jobnr, int threadnr)
1618 {
1619  const WavpackContext *s = avctx->priv_data;
1620  AVFrame *frame = frmptr;
1621 
1622  ff_dsd2pcm_translate (&s->dsdctx [jobnr], s->samples, 0,
1623  (uint8_t *)frame->extended_data[jobnr], 4,
1624  (float *)frame->extended_data[jobnr], 1);
1625 
1626  return 0;
1627 }
1628 
1629 static int wavpack_decode_frame(AVCodecContext *avctx, AVFrame *rframe,
1630  int *got_frame_ptr, AVPacket *avpkt)
1631 {
1632  WavpackContext *s = avctx->priv_data;
1633  const uint8_t *buf = avpkt->data;
1634  int buf_size = avpkt->size;
1635  int frame_size, ret, frame_flags;
1636 
1637  if (avpkt->size <= WV_HEADER_SIZE)
1638  return AVERROR_INVALIDDATA;
1639 
1640  s->frame = NULL;
1641  s->block = 0;
1642  s->ch_offset = 0;
1643 
1644  /* determine number of samples */
1645  s->samples = AV_RL32(buf + 20);
1646  frame_flags = AV_RL32(buf + 24);
1647  if (s->samples <= 0 || s->samples > WV_MAX_SAMPLES) {
1648  av_log(avctx, AV_LOG_ERROR, "Invalid number of samples: %d\n",
1649  s->samples);
1650  return AVERROR_INVALIDDATA;
1651  }
1652 
1653  s->modulation = (frame_flags & WV_DSD_DATA) ? MODULATION_DSD : MODULATION_PCM;
1654 
1655  while (buf_size > WV_HEADER_SIZE) {
1656  frame_size = AV_RL32(buf + 4) - 12;
1657  buf += 20;
1658  buf_size -= 20;
1659  if (frame_size <= 0 || frame_size > buf_size) {
1660  av_log(avctx, AV_LOG_ERROR,
1661  "Block %d has invalid size (size %d vs. %d bytes left)\n",
1662  s->block, frame_size, buf_size);
1664  goto error;
1665  }
1666  if ((ret = wavpack_decode_block(avctx, s->block, buf, frame_size)) < 0)
1667  goto error;
1668  s->block++;
1669  buf += frame_size;
1670  buf_size -= frame_size;
1671  }
1672 
1673  if (s->ch_offset != avctx->ch_layout.nb_channels) {
1674  av_log(avctx, AV_LOG_ERROR, "Not enough channels coded in a packet.\n");
1676  goto error;
1677  }
1678 
1679  ff_thread_await_progress(&s->prev_frame, INT_MAX, 0);
1680  ff_thread_release_ext_buffer(avctx, &s->prev_frame);
1681 
1682  if (s->modulation == MODULATION_DSD)
1683  avctx->execute2(avctx, dsd_channel, s->frame, NULL, avctx->ch_layout.nb_channels);
1684 
1685  ff_thread_report_progress(&s->curr_frame, INT_MAX, 0);
1686 
1687  if ((ret = av_frame_ref(rframe, s->frame)) < 0)
1688  return ret;
1689 
1690  *got_frame_ptr = 1;
1691 
1692  return avpkt->size;
1693 
1694 error:
1695  if (s->frame) {
1696  ff_thread_await_progress(&s->prev_frame, INT_MAX, 0);
1697  ff_thread_release_ext_buffer(avctx, &s->prev_frame);
1698  ff_thread_report_progress(&s->curr_frame, INT_MAX, 0);
1699  }
1700 
1701  return ret;
1702 }
1703 
1705  .p.name = "wavpack",
1706  CODEC_LONG_NAME("WavPack"),
1707  .p.type = AVMEDIA_TYPE_AUDIO,
1708  .p.id = AV_CODEC_ID_WAVPACK,
1709  .priv_data_size = sizeof(WavpackContext),
1711  .close = wavpack_decode_end,
1713  .flush = wavpack_decode_flush,
1715  .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS |
1717  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
1719 };
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:102
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:95
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:839
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:1190
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1007
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:262
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:438
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:1351
wavpack_decode_flush
static void wavpack_decode_flush(AVCodecContext *avctx)
Definition: wavpack.c:1610
get_bits_long
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
Definition: get_bits.h:546
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:116
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
WavpackContext::prev_frame
ThreadFrame prev_frame
Definition: wavpack.c:112
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:119
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
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:156
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:346
MODULATION_DSD
@ MODULATION_DSD
Definition: wavpack.c:64
WavpackContext::frame
AVFrame * frame
Definition: wavpack.c:111
WavpackContext::fdec_num
int fdec_num
Definition: wavpack.c:105
bit
#define bit(string, value)
Definition: cbs_mpeg2.c:58
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:742
WavpackContext
Definition: wavpack.c:101
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:379
update_error_limit
static int update_error_limit(WavpackFrameContext *ctx)
Definition: wavpack.c:136
Decorr
Definition: wavpack.h:88
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:123
WP_ID_SAMPLE_RATE
@ WP_ID_SAMPLE_RATE
Definition: wavpack.h:85
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2059
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:61
ff_wavpack_decoder
const FFCodec ff_wavpack_decoder
Definition: wavpack.c:1704
Modulation
Modulation
Definition: wavpack.c:62
val
static double val(void *priv, double ch)
Definition: aeval.c:77
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:1080
WavpackContext::curr_frame
ThreadFrame curr_frame
Definition: wavpack.c:112
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:104
T
#define T(x)
Definition: vpx_arith.h:29
mult
static int16_t mult(Float11 *f1, Float11 *f2)
Definition: g726.c:60
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:667
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:632
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:298
PRECISION
#define PRECISION
Definition: wavpack.c:52
s
#define s(width, name)
Definition: cbs_vp9.c:256
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:376
frame_size
int frame_size
Definition: mxfenc.c:2202
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:391
GetByteContext::buffer
const uint8_t * buffer
Definition: bytestream.h:34
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:363
filters
#define filters(fmt, type, inverse, clp, inverset, clip, one, clip_fn, packed)
Definition: af_crystalizer.c:55
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:1451
ctx
AVFormatContext * ctx
Definition: movenc.c:48
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:264
ff_thread_ref_frame
int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
Definition: utils.c:885
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:64
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:113
threadframe.h
wavpack_decode_frame
static int wavpack_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame_ptr, AVPacket *avpkt)
Definition: wavpack.c:1629
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:116
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:498
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:109
UPDATE_THREAD_CONTEXT
#define UPDATE_THREAD_CONTEXT(func)
Definition: codec_internal.h:273
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:120
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:300
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:434
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:109
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:122
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:353
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:253
wv_check_crc
static int wv_check_crc(WavpackFrameContext *s, uint32_t crc, uint32_t crc_extra_bits)
Definition: wavpack.c:398
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:1023
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:433
WP_IDF_ODD
@ WP_IDF_ODD
Definition: wavpack.h:65
WavpackContext::block
int block
Definition: wavpack.c:107
DSDfilters::byte
unsigned int byte
Definition: wavpack.c:435
WavpackFrameContext::hybrid_maxclip
int hybrid_maxclip
Definition: wavpack.c:85
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:413
AV_CODEC_CAP_SLICE_THREADS
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
Definition: codec.h:117
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:932
WavpackContext::fdec
WavpackFrameContext * fdec[WV_MAX_FRAME_DECODERS]
Definition: wavpack.c:104
wv_unpack_stereo
static int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, void *dst_l, void *dst_r, const int type)
Definition: wavpack.c:774
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:962
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:405
WavpackContext::dsd_ref
AVBufferRef * dsd_ref
Definition: wavpack.c:115
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:269
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:1061
WavpackContext::samples
int samples
Definition: wavpack.c:108
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:386
get_tail
static av_always_inline unsigned get_tail(GetBitContext *gb, unsigned k)
Definition: wavpack.c:122
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:664
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:264
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:211
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:1092
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:581
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:412
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
WV_MAX_FRAME_DECODERS
#define WV_MAX_FRAME_DECODERS
Definition: wavpack.c:99
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:362
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:113
WavpackFrameContext
Definition: wavpack.c:67
wavpack_decode_init
static av_cold int wavpack_decode_init(AVCodecContext *avctx)
Definition: wavpack.c:1042
AVCodecContext
main external API structure.
Definition: avcodec.h:398
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:174
WavpackFrameContext::ptable
int ptable[PTABLE_BINS]
Definition: wavpack.c:92
WavpackFrameContext::hybrid_bitrate
int hybrid_bitrate
Definition: wavpack.c:84
wv_get_value_float
static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S)
Definition: wavpack.c:324
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:76
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:639
add
static float add(float src0, float src1)
Definition: dnn_backend_native_layer_mathbinary.c:35
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:972
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:425
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:460
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:986
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:156
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:1536
av_log2
int av_log2(unsigned v)
Definition: intmath.c:26
channel
channel
Definition: ebur128.h:39
WavpackContext::dsd_channels
int dsd_channels
Definition: wavpack.c:117
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:1617