26 #define BITSTREAM_READER_LE
41 #define DSD_BYTE_READY(low,high) (!(((low) ^ (high)) & 0xff000000))
44 #define PTABLE_BINS (1<<PTABLE_BITS)
45 #define PTABLE_MASK (PTABLE_BINS-1)
48 #define DOWN 0x00010000
52 #define VALUE_ONE (1 << PRECISION)
53 #define PRECISION_USE 12
57 #define MAX_HISTORY_BITS 5
58 #define MAX_HISTORY_BINS (1 << MAX_HISTORY_BITS)
59 #define MAX_BIN_BYTES 1280
98 #define WV_MAX_FRAME_DECODERS 14
119 #define LEVEL_DECAY(a) (((a) + 0x80) >> 8)
128 e = (1 << (p + 1)) - k - 1;
139 for (
i = 0;
i <=
ctx->stereo_in;
i++) {
140 if (
ctx->ch[
i].bitrate_acc > UINT_MAX -
ctx->ch[
i].bitrate_delta)
142 ctx->ch[
i].bitrate_acc +=
ctx->ch[
i].bitrate_delta;
143 br[
i] =
ctx->ch[
i].bitrate_acc >> 16;
146 if (
ctx->stereo_in &&
ctx->hybrid_bitrate) {
147 int balance = (sl[1] - sl[0] + br[1] + 1) >> 1;
148 if (balance > br[0]) {
151 }
else if (-balance > br[0]) {
155 br[1] = br[0] + balance;
156 br[0] = br[0] - balance;
159 for (
i = 0;
i <=
ctx->stereo_in;
i++) {
160 if (
ctx->hybrid_bitrate) {
161 if (sl[
i] - br[
i] > -0x100)
164 ctx->ch[
i].error_limit = 0;
182 if ((
ctx->ch[0].median[0] < 2U) && (
ctx->ch[1].median[0] < 2U) &&
183 !
ctx->zero && !
ctx->one) {
202 memset(
ctx->ch[0].median, 0,
sizeof(
ctx->ch[0].median));
203 memset(
ctx->ch[1].median, 0,
sizeof(
ctx->ch[1].median));
267 if (!
c->error_limit) {
268 if (
add >= 0x2000000U) {
276 int mid = (
base * 2U +
add + 1) >> 1;
277 while (
add >
c->error_limit) {
284 add = mid - (unsigned)
base - 1;
285 mid = (
base * 2U +
add + 1) >> 1;
290 if (
ctx->hybrid_bitrate)
292 return sign ? ~ret : ret;
309 S *= 1 <<
s->extra_bits;
311 if (
s->got_extra_bits &&
314 *crc = *crc * 9 + (
S & 0xffff) * 3 + ((
unsigned)
S >> 16);
318 bit = (
S &
s->and) |
s->or;
324 return bit <<
s->post_shift;
335 int exp =
s->float_max_exp;
337 if (
s->got_extra_bits) {
338 const int max_bits = 1 + 23 + 8 + 1;
346 S *= 1U <<
s->float_shift;
350 if (
S >= 0x1000000U) {
351 if (
s->got_extra_bits &&
get_bits1(&
s->gb_extra_bits))
358 exp =
s->float_max_exp;
366 (
s->got_extra_bits &&
370 }
else if (
s->got_extra_bits &&
376 exp =
s->float_max_exp;
385 if (
s->float_max_exp >= 25)
395 *crc = *crc * 27 +
S * 9 +
exp * 3 + sign;
397 value.u = (sign << 31) | (
exp << 23) |
S;
402 uint32_t crc_extra_bits)
408 if (
s->got_extra_bits && crc_extra_bits !=
s->crc_extra_bits) {
418 int value = 0x808000, rate = rate_i << 8;
420 for (
int c = (rate + 128) >> 8;
c--;)
427 if (
value > 0x010000) {
428 rate += (rate * rate_s + 128) >> 8;
430 for (
int c = (rate + 64) >> 7;
c--;)
444 uint8_t *dst_l = dst_left, *dst_r = dst_right;
445 int total_samples =
s->samples, stereo = dst_r ? 1 : 0;
448 uint32_t low, high,
value;
453 rate_i = bytestream2_get_byte(&
s->gbyte);
454 rate_s = bytestream2_get_byte(&
s->gbyte);
464 sp->fltr1 = bytestream2_get_byte(&
s->gbyte) << (
PRECISION - 8);
465 sp->fltr2 = bytestream2_get_byte(&
s->gbyte) << (
PRECISION - 8);
466 sp->fltr3 = bytestream2_get_byte(&
s->gbyte) << (
PRECISION - 8);
467 sp->fltr4 = bytestream2_get_byte(&
s->gbyte) << (
PRECISION - 8);
468 sp->fltr5 = bytestream2_get_byte(&
s->gbyte) << (
PRECISION - 8);
470 sp->factor = bytestream2_get_byte(&
s->gbyte) & 0xff;
471 sp->factor |= (bytestream2_get_byte(&
s->gbyte) << 8) & 0xff00;
472 sp->factor = (
int32_t)((uint32_t)
sp->factor << 16) >> 16;
475 value = bytestream2_get_be32(&
s->gbyte);
479 while (total_samples--) {
482 sp[0].value =
sp[0].fltr1 -
sp[0].fltr5 + ((
sp[0].fltr6 *
sp[0].factor) >> 2);
485 sp[1].value =
sp[1].fltr1 -
sp[1].fltr5 + ((
sp[1].fltr6 *
sp[1].factor) >> 2);
489 uint32_t
split = low + ((high - low) >> 8) * (*pp >> 16);
504 value = (
value << 8) | bytestream2_get_byte(&
s->gbyte);
505 high = (high << 8) | 0xff;
509 sp[0].value +=
sp[0].fltr6 * 8;
510 sp[0].byte = (
sp[0].byte << 1) | (
sp[0].fltr0 & 1);
511 sp[0].factor += (((
sp[0].value ^
sp[0].fltr0) >> 31) | 1) &
515 sp[0].fltr3 += (
sp[0].fltr2 -
sp[0].fltr3) >> 4;
516 sp[0].fltr4 += (
sp[0].fltr3 -
sp[0].fltr4) >> 4;
517 sp[0].value = (
sp[0].fltr4 -
sp[0].fltr5) >> 4;
518 sp[0].fltr5 +=
sp[0].value;
519 sp[0].fltr6 += (
sp[0].value -
sp[0].fltr6) >> 3;
520 sp[0].value =
sp[0].fltr1 -
sp[0].fltr5 + ((
sp[0].fltr6 *
sp[0].factor) >> 2);
526 split = low + ((high - low) >> 8) * (*pp >> 16);
541 value = (
value << 8) | bytestream2_get_byte(&
s->gbyte);
542 high = (high << 8) | 0xff;
546 sp[1].value +=
sp[1].fltr6 * 8;
547 sp[1].byte = (
sp[1].byte << 1) | (
sp[1].fltr0 & 1);
548 sp[1].factor += (((
sp[1].value ^
sp[1].fltr0) >> 31) | 1) &
552 sp[1].fltr3 += (
sp[1].fltr2 -
sp[1].fltr3) >> 4;
553 sp[1].fltr4 += (
sp[1].fltr3 -
sp[1].fltr4) >> 4;
554 sp[1].value = (
sp[1].fltr4 -
sp[1].fltr5) >> 4;
555 sp[1].fltr5 +=
sp[1].value;
556 sp[1].fltr6 += (
sp[1].value -
sp[1].fltr6) >> 3;
557 sp[1].value =
sp[1].fltr1 -
sp[1].fltr5 + ((
sp[1].fltr6 *
sp[1].factor) >> 2);
561 sp[0].factor -= (
sp[0].factor + 512) >> 10;
575 memset(dst_left, 0x69,
s->samples * 4);
578 memset(dst_right, 0x69,
s->samples * 4);
586 uint8_t *dst_l = dst_left, *dst_r = dst_right;
587 uint8_t history_bits, max_probability;
588 int total_summed_probabilities = 0;
589 int total_samples =
s->samples;
590 uint8_t *vlb =
s->value_lookup_buffer;
591 int history_bins, p0, p1, chan;
593 uint32_t low, high,
value;
598 history_bits = bytestream2_get_byte(&
s->gbyte);
603 history_bins = 1 << history_bits;
604 max_probability = bytestream2_get_byte(&
s->gbyte);
606 if (max_probability < 0xff) {
608 uint8_t *outend = outptr +
sizeof(*
s->probabilities) * history_bins;
611 int code = bytestream2_get_byte(&
s->gbyte);
613 if (
code > max_probability) {
614 int zcount =
code - max_probability;
616 while (outptr < outend && zcount--)
626 if (outptr < outend ||
631 sizeof(*
s->probabilities) * history_bins);
636 for (p0 = 0; p0 < history_bins; p0++) {
639 for (
int i = 0;
i < 256;
i++)
640 s->summed_probabilities[p0][
i] = sum_values +=
s->probabilities[p0][
i];
643 total_summed_probabilities += sum_values;
645 if (total_summed_probabilities > history_bins *
MAX_BIN_BYTES)
648 s->value_lookup[p0] = vlb;
650 for (
int i = 0;
i < 256;
i++) {
651 int c =
s->probabilities[p0][
i];
663 low = 0; high = 0xffffffff;
664 value = bytestream2_get_be32(&
s->gbyte);
669 while (total_samples--) {
672 if (!
s->summed_probabilities[p0][255])
675 mult = (high - low) /
s->summed_probabilities[p0][255];
679 value = bytestream2_get_be32(&
s->gbyte);
683 mult = high /
s->summed_probabilities[p0][255];
691 if (
index >=
s->summed_probabilities[p0][255])
695 if ((*dst_l =
code =
s->value_lookup[p0][
index]))
696 low +=
s->summed_probabilities[p0][
code-1] *
mult;
701 low +=
s->summed_probabilities[p0][
code-1] *
mult;
715 high = low +
s->probabilities[p0][
code] *
mult - 1;
719 p0 =
code & (history_bins-1);
722 p1 =
code & (history_bins-1);
726 value = (
value << 8) | bytestream2_get_byte(&
s->gbyte);
727 high = (high << 8) | 0xff;
736 memset(dst_left, 0x69,
s->samples * 4);
739 memset(dst_right, 0x69,
s->samples * 4);
747 uint8_t *dst_l = dst_left, *dst_r = dst_right;
748 int total_samples =
s->samples;
754 while (total_samples--) {
768 memset(dst_left, 0x69,
s->samples * 4);
771 memset(dst_right, 0x69,
s->samples * 4);
778 void *dst_l,
void *dst_r,
const int type)
784 uint32_t crc = 0xFFFFFFFF;
785 uint32_t crc_extra_bits = 0xFFFFFFFF;
786 int16_t *dst16_l = dst_l;
787 int16_t *dst16_r = dst_r;
790 float *dstfl_l = dst_l;
791 float *dstfl_r = dst_r;
793 s->one =
s->zero =
s->zeroes = 0;
801 for (
i = 0;
i <
s->terms;
i++) {
802 t =
s->decorr[
i].value;
806 A = 2U *
s->decorr[
i].samplesA[0] -
s->decorr[
i].samplesA[1];
807 B = 2U *
s->decorr[
i].samplesB[0] -
s->decorr[
i].samplesB[1];
809 A = (
int)(3U *
s->decorr[
i].samplesA[0] -
s->decorr[
i].samplesA[1]) >> 1;
810 B = (
int)(3U *
s->decorr[
i].samplesB[0] -
s->decorr[
i].samplesB[1]) >> 1;
812 s->decorr[
i].samplesA[1] =
s->decorr[
i].samplesA[0];
813 s->decorr[
i].samplesB[1] =
s->decorr[
i].samplesB[0];
816 A =
s->decorr[
i].samplesA[
pos];
817 B =
s->decorr[
i].samplesB[
pos];
821 L2 =
L + ((
s->decorr[
i].weightA * (
int64_t)
A + 512) >> 10);
824 L2 =
L + (unsigned)((
int)(
s->decorr[
i].weightA * (unsigned)
A + 512) >> 10);
825 R2 =
R + (unsigned)((
int)(
s->decorr[
i].weightB * (unsigned)
B + 512) >> 10);
828 s->decorr[
i].weightA -= ((((
L ^
A) >> 30) & 2) - 1) *
s->decorr[
i].delta;
830 s->decorr[
i].weightB -= ((((
R ^
B) >> 30) & 2) - 1) *
s->decorr[
i].delta;
831 s->decorr[
i].samplesA[j] =
L = L2;
832 s->decorr[
i].samplesB[j] =
R =
R2;
833 }
else if (t == -1) {
835 L2 =
L + ((
s->decorr[
i].weightA * (
int64_t)
s->decorr[
i].samplesA[0] + 512) >> 10);
837 L2 =
L + (unsigned)((
int)(
s->decorr[
i].weightA * (unsigned)
s->decorr[
i].samplesA[0] + 512) >> 10);
841 R2 =
R + ((
s->decorr[
i].weightB * (
int64_t)L2 + 512) >> 10);
843 R2 =
R + (unsigned)((
int)(
s->decorr[
i].weightB * (unsigned)L2 + 512) >> 10);
846 s->decorr[
i].samplesA[0] =
R;
849 R2 =
R + ((
s->decorr[
i].weightB * (
int64_t)
s->decorr[
i].samplesB[0] + 512) >> 10);
851 R2 =
R + (unsigned)((
int)(
s->decorr[
i].weightB * (unsigned)
s->decorr[
i].samplesB[0] + 512) >> 10);
856 R2 =
s->decorr[
i].samplesA[0];
857 s->decorr[
i].samplesA[0] =
R;
861 L2 =
L + ((
s->decorr[
i].weightA * (
int64_t)
R2 + 512) >> 10);
863 L2 =
L + (unsigned)((
int)(
s->decorr[
i].weightA * (unsigned)
R2 + 512) >> 10);
866 s->decorr[
i].samplesB[0] =
L;
879 L += (unsigned)(
R -= (
unsigned)(
L >> 1));
880 crc = (crc * 3 +
L) * 3 +
R;
893 }
while (!last && count < s->samples);
895 if (last && count < s->samples) {
909 void *dst,
const int type)
915 uint32_t crc = 0xFFFFFFFF;
916 uint32_t crc_extra_bits = 0xFFFFFFFF;
917 int16_t *dst16 = dst;
921 s->one =
s->zero =
s->zeroes = 0;
927 for (
i = 0;
i <
s->terms;
i++) {
928 t =
s->decorr[
i].value;
931 A = 2U *
s->decorr[
i].samplesA[0] -
s->decorr[
i].samplesA[1];
933 A = (
int)(3U *
s->decorr[
i].samplesA[0] -
s->decorr[
i].samplesA[1]) >> 1;
934 s->decorr[
i].samplesA[1] =
s->decorr[
i].samplesA[0];
937 A =
s->decorr[
i].samplesA[
pos];
941 S =
T + ((
s->decorr[
i].weightA * (
int64_t)
A + 512) >> 10);
943 S =
T + (unsigned)((
int)(
s->decorr[
i].weightA * (unsigned)
A + 512) >> 10);
945 s->decorr[
i].weightA -= ((((
T ^
A) >> 30) & 2) - 1) *
s->decorr[
i].delta;
946 s->decorr[
i].samplesA[j] =
T =
S;
959 }
while (!last && count < s->samples);
961 if (last && count < s->samples) {
981 if (!
c->fdec[
c->fdec_num])
984 c->fdec[
c->fdec_num - 1]->avctx =
c->avctx;
1000 if (
channels > INT_MAX /
sizeof(*
s->dsdctx))
1010 memset(
s->dsdctx[
i].buf, 0x69,
sizeof(
s->dsdctx[
i].buf));
1056 if (!
s->curr_frame.f || !
s->prev_frame.f)
1068 for (
int i = 0;
i <
s->fdec_num;
i++)
1084 const uint8_t *buf,
int buf_size)
1090 void *samples_l =
NULL, *samples_r =
NULL;
1092 int got_terms = 0, got_weights = 0, got_samples = 0,
1093 got_entropy = 0, got_pcm = 0, got_float = 0, got_hybrid = 0;
1096 int bpp, chan = 0, orig_bpp,
sample_rate = 0, rate_x = 1, dsd_mode = 0;
1098 uint64_t chmask = 0;
1105 s = wc->
fdec[block_no];
1113 memset(
s->ch, 0,
sizeof(
s->ch));
1115 s->and =
s->or =
s->shift = 0;
1116 s->got_extra_bits = 0;
1120 s->samples = bytestream2_get_le32(&gb);
1123 "a sequence: %d and %d\n", wc->
samples,
s->samples);
1126 s->frame_flags = bytestream2_get_le32(&gb);
1130 else if ((
s->frame_flags & 0x03) <= 1)
1139 orig_bpp = ((
s->frame_flags & 0x03) + 1) << 3;
1142 s->stereo = !(
s->frame_flags &
WV_MONO);
1147 s->post_shift = bpp * 8 - orig_bpp + ((
s->frame_flags >> 13) & 0x1f);
1148 if (
s->post_shift < 0 ||
s->post_shift > 31) {
1151 s->hybrid_maxclip = ((1LL << (orig_bpp - 1)) - 1);
1152 s->hybrid_minclip = ((-1UL << (orig_bpp - 1)));
1153 s->CRC = bytestream2_get_le32(&gb);
1157 id = bytestream2_get_byte(&gb);
1158 size = bytestream2_get_byte(&gb);
1160 size |= (bytestream2_get_le16u(&gb)) << 8;
1167 "Got incorrect block %02X with size %i\n",
id,
size);
1172 "Block size %i is out of bounds\n",
size);
1184 for (
i = 0;
i <
s->terms;
i++) {
1186 s->decorr[
s->terms -
i - 1].value = (
val & 0x1F) - 5;
1187 s->decorr[
s->terms -
i - 1].delta =
val >> 5;
1203 t = (int8_t)bytestream2_get_byte(&gb);
1204 s->decorr[
s->terms -
i - 1].weightA = t * (1 << 3);
1205 if (
s->decorr[
s->terms -
i - 1].weightA > 0)
1206 s->decorr[
s->terms -
i - 1].weightA +=
1207 (
s->decorr[
s->terms -
i - 1].weightA + 64) >> 7;
1209 t = (int8_t)bytestream2_get_byte(&gb);
1210 s->decorr[
s->terms -
i - 1].weightB = t * (1 << 3);
1211 if (
s->decorr[
s->terms -
i - 1].weightB > 0)
1212 s->decorr[
s->terms -
i - 1].weightB +=
1213 (
s->decorr[
s->terms -
i - 1].weightB + 64) >> 7;
1224 for (
i =
s->terms - 1; (
i >= 0) && (t <
size);
i--) {
1225 if (
s->decorr[
i].value > 8) {
1226 s->decorr[
i].samplesA[0] =
1227 wp_exp2(bytestream2_get_le16(&gb));
1228 s->decorr[
i].samplesA[1] =
1229 wp_exp2(bytestream2_get_le16(&gb));
1232 s->decorr[
i].samplesB[0] =
1233 wp_exp2(bytestream2_get_le16(&gb));
1234 s->decorr[
i].samplesB[1] =
1235 wp_exp2(bytestream2_get_le16(&gb));
1239 }
else if (
s->decorr[
i].value < 0) {
1240 s->decorr[
i].samplesA[0] =
1241 wp_exp2(bytestream2_get_le16(&gb));
1242 s->decorr[
i].samplesB[0] =
1243 wp_exp2(bytestream2_get_le16(&gb));
1246 for (j = 0; j <
s->decorr[
i].value; j++) {
1247 s->decorr[
i].samplesA[j] =
1248 wp_exp2(bytestream2_get_le16(&gb));
1250 s->decorr[
i].samplesB[j] =
1251 wp_exp2(bytestream2_get_le16(&gb));
1254 t +=
s->decorr[
i].value * 2 * (
s->stereo_in + 1);
1260 if (
size != 6 * (
s->stereo_in + 1)) {
1262 "Entropy vars size should be %i, got %i.\n",
1263 6 * (
s->stereo_in + 1),
size);
1267 for (j = 0; j <=
s->stereo_in; j++)
1268 for (
i = 0;
i < 3;
i++) {
1269 s->ch[j].median[
i] =
wp_exp2(bytestream2_get_le16(&gb));
1274 if (
s->hybrid_bitrate) {
1275 for (
i = 0;
i <=
s->stereo_in;
i++) {
1276 s->ch[
i].slow_level =
wp_exp2(bytestream2_get_le16(&gb));
1280 for (
i = 0;
i < (
s->stereo_in + 1);
i++) {
1281 s->ch[
i].bitrate_acc = bytestream2_get_le16(&gb) << 16;
1285 for (
i = 0;
i < (
s->stereo_in + 1);
i++) {
1286 s->ch[
i].bitrate_delta =
1287 wp_exp2((int16_t)bytestream2_get_le16(&gb));
1290 for (
i = 0;
i < (
s->stereo_in + 1);
i++)
1291 s->ch[
i].bitrate_delta = 0;
1299 "Invalid INT32INFO, size = %i\n",
1307 "Invalid INT32INFO, extra_bits = %d (> 30)\n",
val[0]);
1309 }
else if (
val[0]) {
1310 s->extra_bits =
val[0];
1311 }
else if (
val[1]) {
1313 }
else if (
val[2]) {
1316 }
else if (
val[3]) {
1320 if (
s->shift > 31) {
1322 "Invalid INT32INFO, shift = %d (> 31)\n",
s->shift);
1323 s->and =
s->or =
s->shift = 0;
1328 if (
s->hybrid && bpp == 4 &&
s->post_shift < 8 &&
s->shift > 8) {
1331 s->hybrid_maxclip >>= 8;
1332 s->hybrid_minclip >>= 8;
1339 "Invalid FLOATINFO, size = %i\n",
size);
1343 s->float_flag = bytestream2_get_byte(&gb);
1344 s->float_shift = bytestream2_get_byte(&gb);
1345 s->float_max_exp = bytestream2_get_byte(&gb);
1346 if (
s->float_shift > 31) {
1348 "Invalid FLOATINFO, shift = %d (> 31)\n",
s->float_shift);
1368 rate_x = bytestream2_get_byte(&gb);
1371 rate_x = 1 << rate_x;
1372 dsd_mode = bytestream2_get_byte(&gb);
1373 if (dsd_mode && dsd_mode != 1 && dsd_mode != 3) {
1393 s->got_extra_bits = 1;
1398 "Insufficient channel information\n");
1401 chan = bytestream2_get_byte(&gb);
1404 chmask = bytestream2_get_byte(&gb);
1407 chmask = bytestream2_get_le16(&gb);
1410 chmask = bytestream2_get_le24(&gb);
1413 chmask = bytestream2_get_le32(&gb);
1416 size = bytestream2_get_byte(&gb);
1417 chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
1421 " instead of %i.\n", chan, avctx->
channels);
1422 chmask = bytestream2_get_le24(&gb);
1425 size = bytestream2_get_byte(&gb);
1426 chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
1430 " instead of %i.\n", chan, avctx->
channels);
1431 chmask = bytestream2_get_le32(&gb);
1471 if (
s->hybrid && !got_hybrid) {
1481 const int wanted =
s->samples *
s->extra_bits <<
s->stereo_in;
1482 if (
size < wanted) {
1484 s->got_extra_bits = 0;
1489 if (!got_pcm && !got_dsd) {
1501 int new_channels = avctx->
channels;
1504 int sr = (
s->frame_flags >> 23) & 0xf;
1514 if (new_samplerate * (uint64_t)rate_x > INT_MAX)
1516 new_samplerate *= rate_x;
1520 new_channels = chan;
1522 new_chmask = chmask;
1524 new_channels =
s->stereo ? 2 : 1;
1539 !!got_dsd != !!wc->
dsdctx) {
1578 if (dsd_mode == 3) {
1580 }
else if (dsd_mode == 1) {
1592 if (dsd_mode == 3) {
1594 }
else if (dsd_mode == 1) {
1606 memcpy(samples_r, samples_l, bpp *
s->samples);
1632 int *got_frame_ptr,
AVPacket *avpkt)
1636 int buf_size = avpkt->
size;
1648 frame_flags =
AV_RL32(buf + 24);
1661 if (frame_size <= 0 || frame_size > buf_size) {
1663 "Block %d has invalid size (size %d vs. %d bytes left)\n",
static void flush(AVCodecContext *avctx)
static double val(void *priv, double ch)
static char * split(char *message, char delim)
Libavcodec external API header.
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
#define AV_EF_EXPLODE
abort decoding on minor error detection
static av_cold int init(AVCodecContext *avctx)
refcounted data buffer API
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
#define u(width, name, range_min, range_max)
#define bit(string, value)
audio channel layout utility functions
#define FFSWAP(type, a, b)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
static float add(float src0, float src1)
av_cold void ff_init_dsd_data(void)
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)
channel
Use these values when setting the channel map with ebur128_set_channel().
bitstream reader API header.
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
static int get_bits_left(GetBitContext *gb)
static unsigned int get_bits1(GetBitContext *s)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
#define AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_STEREO
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
AVBufferRef * av_buffer_allocz(buffer_size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
int av_buffer_replace(AVBufferRef **pdst, AVBufferRef *src)
Ensure dst refers to the same data as src.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_FLTP
float, planar
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
static const int weights[]
static int16_t mult(Float11 *f1, Float11 *f2)
#define FF_CODEC_CAP_ALLOCATE_PROGRESS
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
static const struct PPFilter filters[]
static const uint16_t table[]
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
FF_ENABLE_DEPRECATION_WARNINGS int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
void ff_thread_await_progress(ThreadFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
static int shift(int a, int b)
A reference to a data buffer.
uint8_t * data
The data buffer.
main external API structure.
enum AVSampleFormat sample_fmt
audio sample format
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int sample_rate
samples per second
int channels
number of audio channels
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.
uint64_t channel_layout
Audio channel layout.
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
const char * name
Name of the codec implementation.
This structure describes decoded (raw) audio or video data.
int nb_samples
number of audio samples (per channel) described by this frame
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
uint8_t ** extended_data
pointers to the data planes/channels.
This structure stores compressed data.
WavpackFrameContext * fdec[WV_MAX_FRAME_DECODERS]
uint16_t summed_probabilities[MAX_HISTORY_BINS][256]
uint8_t value_lookup_buffer[MAX_HISTORY_BINS *MAX_BIN_BYTES]
GetBitContext gb_extra_bits
uint8_t probabilities[MAX_HISTORY_BINS][256]
uint8_t * value_lookup[MAX_HISTORY_BINS]
static void error(const char *err)
static volatile int checksum
static int get_unary_0_33(GetBitContext *gb)
Get unary code terminated by a 0 with a maximum length of 33.
static int wv_unpack_dsd_fast(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S)
static int wavpack_decode_block(AVCodecContext *avctx, int block_no, const uint8_t *buf, int buf_size)
static int wv_unpack_dsd_copy(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
static void wavpack_decode_flush(AVCodecContext *avctx)
#define WV_MAX_FRAME_DECODERS
static av_cold int wavpack_decode_end(AVCodecContext *avctx)
static int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, void *dst, const int type)
static int wv_unpack_dsd_high(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
static int update_error_limit(WavpackFrameContext *ctx)
static int wv_dsd_reset(WavpackContext *s, int channels)
static int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, void *dst_l, void *dst_r, const int type)
static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb, int channel, int *last)
static int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc, unsigned S)
static int wavpack_decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static int dsd_channel(AVCodecContext *avctx, void *frmptr, int jobnr, int threadnr)
AVCodec ff_wavpack_decoder
#define DSD_BYTE_READY(low, high)
static av_cold int wv_alloc_frame_context(WavpackContext *c)
static av_always_inline unsigned get_tail(GetBitContext *gb, int k)
static void init_ptable(int *table, int rate_i, int rate_s)
static av_cold int wavpack_decode_init(AVCodecContext *avctx)
static int wv_check_crc(WavpackFrameContext *s, uint32_t crc, uint32_t crc_extra_bits)
#define WV_FLT_SHIFT_SENT
static av_always_inline int wp_exp2(int16_t val)
#define WV_FLT_SHIFT_SAME
#define WV_HYBRID_BITRATE
#define WV_FLT_SHIFT_ONES
static const int wv_rates[16]
static av_always_inline int wp_log2(uint32_t val)
#define UPDATE_WEIGHT_CLIP(weight, delta, samples, in)