Go to the documentation of this file.
26 #define BITSTREAM_READER_LE
42 #define DSD_BYTE_READY(low,high) (!(((low) ^ (high)) & 0xff000000))
45 #define PTABLE_BINS (1<<PTABLE_BITS)
46 #define PTABLE_MASK (PTABLE_BINS-1)
49 #define DOWN 0x00010000
53 #define VALUE_ONE (1 << PRECISION)
54 #define PRECISION_USE 12
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)
99 #define WV_MAX_FRAME_DECODERS 14
120 #define LEVEL_DECAY(a) (((a) + 0x80) >> 8)
129 e = (1 << (p + 1)) - k - 1;
140 for (
i = 0;
i <=
ctx->stereo_in;
i++) {
141 if (
ctx->ch[
i].bitrate_acc > UINT_MAX -
ctx->ch[
i].bitrate_delta)
143 ctx->ch[
i].bitrate_acc +=
ctx->ch[
i].bitrate_delta;
144 br[
i] =
ctx->ch[
i].bitrate_acc >> 16;
147 if (
ctx->stereo_in &&
ctx->hybrid_bitrate) {
148 int balance = (sl[1] - sl[0] + br[1] + 1) >> 1;
149 if (balance > br[0]) {
152 }
else if (-balance > br[0]) {
156 br[1] = br[0] + balance;
157 br[0] = br[0] - balance;
160 for (
i = 0;
i <=
ctx->stereo_in;
i++) {
161 if (
ctx->hybrid_bitrate) {
162 if (sl[
i] - br[
i] > -0x100)
165 ctx->ch[
i].error_limit = 0;
183 if ((
ctx->ch[0].median[0] < 2
U) && (
ctx->ch[1].median[0] < 2
U) &&
184 !
ctx->zero && !
ctx->one) {
203 memset(
ctx->ch[0].median, 0,
sizeof(
ctx->ch[0].median));
204 memset(
ctx->ch[1].median, 0,
sizeof(
ctx->ch[1].median));
268 if (!
c->error_limit) {
269 if (
add >= 0x2000000U) {
277 int mid = (
base * 2
U +
add + 1) >> 1;
278 while (
add >
c->error_limit) {
285 add = mid - (unsigned)
base - 1;
291 if (
ctx->hybrid_bitrate)
310 S *= 1 <<
s->extra_bits;
312 if (
s->got_extra_bits &&
315 *crc = *crc * 9 + (
S & 0xffff) * 3 + ((
unsigned)
S >> 16);
319 bit = (
S &
s->and) |
s->or;
325 return bit <<
s->post_shift;
336 int exp =
s->float_max_exp;
338 if (
s->got_extra_bits) {
339 const int max_bits = 1 + 23 + 8 + 1;
347 S *= 1
U <<
s->float_shift;
351 if (
S >= 0x1000000U) {
352 if (
s->got_extra_bits &&
get_bits1(&
s->gb_extra_bits))
359 exp =
s->float_max_exp;
367 (
s->got_extra_bits &&
371 }
else if (
s->got_extra_bits &&
377 exp =
s->float_max_exp;
386 if (
s->float_max_exp >= 25)
396 *crc = *crc * 27 +
S * 9 +
exp * 3 + sign;
398 value.u = (sign << 31) | (
exp << 23) |
S;
403 uint32_t crc_extra_bits)
409 if (
s->got_extra_bits && crc_extra_bits !=
s->crc_extra_bits) {
419 int value = 0x808000, rate = rate_i << 8;
421 for (
int c = (rate + 128) >> 8;
c--;)
428 if (
value > 0x010000) {
429 rate += (rate * rate_s + 128) >> 8;
431 for (
int c = (rate + 64) >> 7;
c--;)
444 uint32_t checksum = 0xFFFFFFFF;
445 uint8_t *dst_l = dst_left, *dst_r = dst_right;
446 int total_samples =
s->samples, stereo = dst_r ? 1 : 0;
449 uint32_t low, high,
value;
454 rate_i = bytestream2_get_byte(&
s->gbyte);
455 rate_s = bytestream2_get_byte(&
s->gbyte);
465 sp->fltr1 = bytestream2_get_byte(&
s->gbyte) << (
PRECISION - 8);
466 sp->fltr2 = bytestream2_get_byte(&
s->gbyte) << (
PRECISION - 8);
467 sp->fltr3 = bytestream2_get_byte(&
s->gbyte) << (
PRECISION - 8);
468 sp->fltr4 = bytestream2_get_byte(&
s->gbyte) << (
PRECISION - 8);
469 sp->fltr5 = bytestream2_get_byte(&
s->gbyte) << (
PRECISION - 8);
471 sp->factor = bytestream2_get_byte(&
s->gbyte) & 0xff;
472 sp->factor |= (bytestream2_get_byte(&
s->gbyte) << 8) & 0xff00;
473 sp->factor = (
int32_t)((uint32_t)
sp->factor << 16) >> 16;
476 value = bytestream2_get_be32(&
s->gbyte);
480 while (total_samples--) {
483 sp[0].value =
sp[0].fltr1 -
sp[0].fltr5 + ((
sp[0].fltr6 *
sp[0].factor) >> 2);
486 sp[1].value =
sp[1].fltr1 -
sp[1].fltr5 + ((
sp[1].fltr6 *
sp[1].factor) >> 2);
490 uint32_t
split = low + ((high - low) >> 8) * (*pp >> 16);
503 value = (
value << 8) | bytestream2_get_byte(&
s->gbyte);
504 high = (high << 8) | 0xff;
508 sp[0].value +=
sp[0].fltr6 * 8;
509 sp[0].byte = (
sp[0].byte << 1) | (
sp[0].fltr0 & 1);
510 sp[0].factor += (((
sp[0].value ^
sp[0].fltr0) >> 31) | 1) &
514 sp[0].fltr3 += (
sp[0].fltr2 -
sp[0].fltr3) >> 4;
515 sp[0].fltr4 += (
sp[0].fltr3 -
sp[0].fltr4) >> 4;
516 sp[0].value = (
sp[0].fltr4 -
sp[0].fltr5) >> 4;
517 sp[0].fltr5 +=
sp[0].value;
518 sp[0].fltr6 += (
sp[0].value -
sp[0].fltr6) >> 3;
519 sp[0].value =
sp[0].fltr1 -
sp[0].fltr5 + ((
sp[0].fltr6 *
sp[0].factor) >> 2);
525 split = low + ((high - low) >> 8) * (*pp >> 16);
538 value = (
value << 8) | bytestream2_get_byte(&
s->gbyte);
539 high = (high << 8) | 0xff;
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) &
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);
557 checksum += (checksum << 1) + (*dst_l =
sp[0].
byte & 0xff);
558 sp[0].factor -= (
sp[0].factor + 512) >> 10;
562 checksum += (checksum << 1) + (*dst_r =
filters[1].
byte & 0xff);
572 memset(dst_left, 0x69,
s->samples * 4);
575 memset(dst_right, 0x69,
s->samples * 4);
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;
595 history_bits = bytestream2_get_byte(&
s->gbyte);
600 history_bins = 1 << history_bits;
601 max_probability = bytestream2_get_byte(&
s->gbyte);
603 if (max_probability < 0xff) {
604 uint8_t *outptr = (uint8_t *)
s->probabilities;
605 uint8_t *outend = outptr +
sizeof(*
s->probabilities) * history_bins;
608 int code = bytestream2_get_byte(&
s->gbyte);
610 if (
code > max_probability) {
611 int zcount =
code - max_probability;
613 while (outptr < outend && zcount--)
623 if (outptr < outend ||
628 sizeof(*
s->probabilities) * history_bins);
633 for (p0 = 0; p0 < history_bins; p0++) {
636 for (
int i = 0;
i < 256;
i++)
637 s->summed_probabilities[p0][
i] = sum_values +=
s->probabilities[p0][
i];
640 total_summed_probabilities += sum_values;
642 if (total_summed_probabilities > history_bins *
MAX_BIN_BYTES)
645 s->value_lookup[p0] = vlb;
647 for (
int i = 0;
i < 256;
i++) {
648 int c =
s->probabilities[p0][
i];
660 low = 0; high = 0xffffffff;
661 value = bytestream2_get_be32(&
s->gbyte);
666 while (total_samples--) {
669 if (!
s->summed_probabilities[p0][255])
672 mult = (high - low) /
s->summed_probabilities[p0][255];
676 value = bytestream2_get_be32(&
s->gbyte);
680 mult = high /
s->summed_probabilities[p0][255];
688 if (
index >=
s->summed_probabilities[p0][255])
692 if ((*dst_l =
code =
s->value_lookup[p0][
index]))
693 low +=
s->summed_probabilities[p0][
code-1] *
mult;
698 low +=
s->summed_probabilities[p0][
code-1] *
mult;
712 high = low +
s->probabilities[p0][
code] *
mult - 1;
713 checksum += (checksum << 1) +
code;
716 p0 =
code & (history_bins-1);
719 p1 =
code & (history_bins-1);
723 value = (
value << 8) | bytestream2_get_byte(&
s->gbyte);
724 high = (high << 8) | 0xff;
733 memset(dst_left, 0x69,
s->samples * 4);
736 memset(dst_right, 0x69,
s->samples * 4);
744 uint8_t *dst_l = dst_left, *dst_r = dst_right;
745 int total_samples =
s->samples;
746 uint32_t checksum = 0xFFFFFFFF;
751 while (total_samples--) {
752 checksum += (checksum << 1) + (*dst_l = bytestream2_get_byte(&
s->gbyte));
756 checksum += (checksum << 1) + (*dst_r = bytestream2_get_byte(&
s->gbyte));
765 memset(dst_left, 0x69,
s->samples * 4);
768 memset(dst_right, 0x69,
s->samples * 4);
775 void *dst_l,
void *dst_r,
const int type)
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;
787 float *dstfl_l = dst_l;
788 float *dstfl_r = dst_r;
790 s->one =
s->zero =
s->zeroes = 0;
798 for (
i = 0;
i <
s->terms;
i++) {
799 t =
s->decorr[
i].value;
803 A = 2
U *
s->decorr[
i].samplesA[0] -
s->decorr[
i].samplesA[1];
804 B = 2
U *
s->decorr[
i].samplesB[0] -
s->decorr[
i].samplesB[1];
806 A = (
int)(3
U *
s->decorr[
i].samplesA[0] -
s->decorr[
i].samplesA[1]) >> 1;
807 B = (
int)(3
U *
s->decorr[
i].samplesB[0] -
s->decorr[
i].samplesB[1]) >> 1;
809 s->decorr[
i].samplesA[1] =
s->decorr[
i].samplesA[0];
810 s->decorr[
i].samplesB[1] =
s->decorr[
i].samplesB[0];
813 A =
s->decorr[
i].samplesA[
pos];
814 B =
s->decorr[
i].samplesB[
pos];
818 L2 =
L + ((
s->decorr[
i].weightA * (int64_t)
A + 512) >> 10);
819 R2 =
R + ((
s->decorr[
i].weightB * (int64_t)
B + 512) >> 10);
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);
825 s->decorr[
i].weightA -= ((((
L ^
A) >> 30) & 2) - 1) *
s->decorr[
i].delta;
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) {
832 L2 =
L + ((
s->decorr[
i].weightA * (int64_t)
s->decorr[
i].samplesA[0] + 512) >> 10);
834 L2 =
L + (unsigned)((
int)(
s->decorr[
i].weightA * (unsigned)
s->decorr[
i].samplesA[0] + 512) >> 10);
838 R2 =
R + ((
s->decorr[
i].weightB * (int64_t)
L2 + 512) >> 10);
840 R2 =
R + (unsigned)((
int)(
s->decorr[
i].weightB * (unsigned)
L2 + 512) >> 10);
843 s->decorr[
i].samplesA[0] =
R;
846 R2 =
R + ((
s->decorr[
i].weightB * (int64_t)
s->decorr[
i].samplesB[0] + 512) >> 10);
848 R2 =
R + (unsigned)((
int)(
s->decorr[
i].weightB * (unsigned)
s->decorr[
i].samplesB[0] + 512) >> 10);
853 R2 =
s->decorr[
i].samplesA[0];
854 s->decorr[
i].samplesA[0] =
R;
858 L2 =
L + ((
s->decorr[
i].weightA * (int64_t)
R2 + 512) >> 10);
860 L2 =
L + (unsigned)((
int)(
s->decorr[
i].weightA * (unsigned)
R2 + 512) >> 10);
863 s->decorr[
i].samplesB[0] =
L;
876 L += (unsigned)(
R -= (
unsigned)(
L >> 1));
877 crc = (crc * 3 +
L) * 3 +
R;
890 }
while (!last && count < s->
samples);
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);
906 void *dst,
const int type)
912 uint32_t crc = 0xFFFFFFFF;
913 uint32_t crc_extra_bits = 0xFFFFFFFF;
914 int16_t *dst16 = dst;
918 s->one =
s->zero =
s->zeroes = 0;
924 for (
i = 0;
i <
s->terms;
i++) {
925 t =
s->decorr[
i].value;
928 A = 2
U *
s->decorr[
i].samplesA[0] -
s->decorr[
i].samplesA[1];
930 A = (
int)(3
U *
s->decorr[
i].samplesA[0] -
s->decorr[
i].samplesA[1]) >> 1;
931 s->decorr[
i].samplesA[1] =
s->decorr[
i].samplesA[0];
934 A =
s->decorr[
i].samplesA[
pos];
938 S =
T + ((
s->decorr[
i].weightA * (int64_t)
A + 512) >> 10);
940 S =
T + (unsigned)((
int)(
s->decorr[
i].weightA * (unsigned)
A + 512) >> 10);
942 s->decorr[
i].weightA -= ((((
T ^
A) >> 30) & 2) - 1) *
s->decorr[
i].delta;
943 s->decorr[
i].samplesA[j] =
T =
S;
956 }
while (!last && count < s->
samples);
958 if (last && count < s->
samples) {
960 memset((uint8_t*)dst + count*
size, 0, (
s->samples-count)*
size);
978 if (!
c->fdec[
c->fdec_num])
981 c->fdec[
c->fdec_num - 1]->avctx =
c->avctx;
997 if (
channels > INT_MAX /
sizeof(*
s->dsdctx))
1007 memset(
s->dsdctx[
i].buf, 0x69,
sizeof(
s->dsdctx[
i].buf));
1053 if (!
s->curr_frame.f || !
s->prev_frame.f)
1065 for (
int i = 0;
i <
s->fdec_num;
i++)
1081 const uint8_t *buf,
int buf_size)
1087 void *samples_l =
NULL, *samples_r =
NULL;
1089 int got_terms = 0, got_weights = 0, got_samples = 0,
1090 got_entropy = 0, got_pcm = 0, got_float = 0, got_hybrid = 0;
1093 int bpp, chan = 0, orig_bpp,
sample_rate = 0, rate_x = 1, dsd_mode = 0;
1095 uint64_t chmask = 0;
1102 s = wc->
fdec[block_no];
1110 memset(
s->ch, 0,
sizeof(
s->ch));
1112 s->and =
s->or =
s->shift = 0;
1113 s->got_extra_bits = 0;
1117 s->samples = bytestream2_get_le32(&gb);
1120 "a sequence: %d and %d\n", wc->
samples,
s->samples);
1123 s->frame_flags = bytestream2_get_le32(&gb);
1127 else if ((
s->frame_flags & 0x03) <= 1)
1136 orig_bpp = ((
s->frame_flags & 0x03) + 1) << 3;
1139 s->stereo = !(
s->frame_flags &
WV_MONO);
1144 s->post_shift = bpp * 8 - orig_bpp + ((
s->frame_flags >> 13) & 0x1f);
1145 if (
s->post_shift < 0 ||
s->post_shift > 31) {
1148 s->hybrid_maxclip = ((1LL << (orig_bpp - 1)) - 1);
1149 s->hybrid_minclip = ((-1UL << (orig_bpp - 1)));
1150 s->CRC = bytestream2_get_le32(&gb);
1154 id = bytestream2_get_byte(&gb);
1155 size = bytestream2_get_byte(&gb);
1157 size |= (bytestream2_get_le16u(&gb)) << 8;
1164 "Got incorrect block %02X with size %i\n",
id,
size);
1169 "Block size %i is out of bounds\n",
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;
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;
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;
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));
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));
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));
1243 for (j = 0; j <
s->decorr[
i].value; j++) {
1244 s->decorr[
i].samplesA[j] =
1245 wp_exp2(bytestream2_get_le16(&gb));
1247 s->decorr[
i].samplesB[j] =
1248 wp_exp2(bytestream2_get_le16(&gb));
1251 t +=
s->decorr[
i].value * 2 * (
s->stereo_in + 1);
1257 if (
size != 6 * (
s->stereo_in + 1)) {
1259 "Entropy vars size should be %i, got %i.\n",
1260 6 * (
s->stereo_in + 1),
size);
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));
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));
1277 for (
i = 0;
i < (
s->stereo_in + 1);
i++) {
1278 s->ch[
i].bitrate_acc = bytestream2_get_le16(&gb) << 16;
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));
1287 for (
i = 0;
i < (
s->stereo_in + 1);
i++)
1288 s->ch[
i].bitrate_delta = 0;
1296 "Invalid INT32INFO, size = %i\n",
1304 "Invalid INT32INFO, extra_bits = %d (> 30)\n",
val[0]);
1307 s->extra_bits =
val[0];
1319 if (
s->shift > 31) {
1321 "Invalid INT32INFO, shift = %d (> 31)\n",
s->shift);
1322 s->and =
s->or =
s->shift = 0;
1327 if (
s->hybrid && bpp == 4 &&
s->post_shift < 8 &&
s->shift > 8) {
1330 s->hybrid_maxclip >>= 8;
1331 s->hybrid_minclip >>= 8;
1338 "Invalid FLOATINFO, size = %i\n",
size);
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) {
1347 "Invalid FLOATINFO, shift = %d (> 31)\n",
s->float_shift);
1367 rate_x = bytestream2_get_byte(&gb);
1370 rate_x = 1 << rate_x;
1371 dsd_mode = bytestream2_get_byte(&gb);
1372 if (dsd_mode && dsd_mode != 1 && dsd_mode != 3) {
1392 s->got_extra_bits = 1;
1397 "Insufficient channel information\n");
1400 chan = bytestream2_get_byte(&gb);
1403 chmask = bytestream2_get_byte(&gb);
1406 chmask = bytestream2_get_le16(&gb);
1409 chmask = bytestream2_get_le24(&gb);
1412 chmask = bytestream2_get_le32(&gb);
1415 size = bytestream2_get_byte(&gb);
1416 chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
1421 chmask = bytestream2_get_le24(&gb);
1424 size = bytestream2_get_byte(&gb);
1425 chan |= (bytestream2_get_byte(&gb) & 0xF) << 8;
1430 chmask = bytestream2_get_le32(&gb);
1468 if (
s->hybrid && !got_hybrid) {
1478 const int wanted =
s->samples *
s->extra_bits <<
s->stereo_in;
1479 if (
size < wanted) {
1481 s->got_extra_bits = 0;
1486 if (!got_pcm && !got_dsd) {
1500 int sr = (
s->frame_flags >> 23) & 0
xf;
1510 if (new_samplerate * (uint64_t)rate_x > INT_MAX)
1512 new_samplerate *= rate_x;
1536 !!got_dsd != !!wc->
dsdctx) {
1576 if (dsd_mode == 3) {
1578 }
else if (dsd_mode == 1) {
1590 if (dsd_mode == 3) {
1592 }
else if (dsd_mode == 1) {
1604 memcpy(samples_r, samples_l, bpp *
s->samples);
1623 (uint8_t *)
frame->extended_data[jobnr], 4,
1624 (
float *)
frame->extended_data[jobnr], 1);
1630 int *got_frame_ptr,
AVPacket *avpkt)
1633 const uint8_t *buf = avpkt->
data;
1634 int buf_size = avpkt->
size;
1646 frame_flags =
AV_RL32(buf + 24);
1659 if (frame_size <= 0 || frame_size > buf_size) {
1661 "Block %d has invalid size (size %d vs. %d bytes left)\n",
1705 .
p.
name =
"wavpack",
static void error(const char *err)
#define WV_HYBRID_BITRATE
@ AV_SAMPLE_FMT_FLTP
float, planar
#define AV_LOG_WARNING
Something somehow does not look correct.
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
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
static int get_bits_left(GetBitContext *gb)
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
void ff_thread_release_ext_buffer(AVCodecContext *avctx, ThreadFrame *f)
Unref a ThreadFrame.
int sample_rate
samples per second
#define u(width, name, range_min, range_max)
uint8_t * data
The data buffer.
static int wv_unpack_dsd_high(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
static void wavpack_decode_flush(AVCodecContext *avctx)
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
#define WV_FLT_SHIFT_ONES
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
static const uint16_t table[]
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
int nb_channels
Number of channels in this layout.
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
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
#define bit(string, value)
static int wv_unpack_dsd_copy(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static int update_error_limit(WavpackFrameContext *ctx)
AVCodec p
The public AVCodec.
AVChannelLayout ch_layout
Audio channel layout.
const FFCodec ff_wavpack_decoder
static double val(void *priv, double ch)
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
static int wavpack_decode_block(AVCodecContext *avctx, int block_no, const uint8_t *buf, int buf_size)
static av_always_inline int wp_log2(uint32_t val)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static int16_t mult(Float11 *f1, Float11 *f2)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
#define FF_CODEC_DECODE_CB(func)
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
static const int wv_rates[16]
#define filters(fmt, type, inverse, clp, inverset, clip, one, clip_fn, packed)
static av_always_inline int wp_exp2(int16_t val)
uint16_t summed_probabilities[MAX_HISTORY_BINS][256]
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
static int wavpack_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame_ptr, AVPacket *avpkt)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
#define DSD_BYTE_READY(low, high)
static unsigned int get_bits1(GetBitContext *s)
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, uint8_t *dst, unsigned int size)
void av_channel_layout_default(AVChannelLayout *ch_layout, int nb_channels)
Get the default channel layout for a given number of channels.
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
#define AV_EF_EXPLODE
abort decoding on minor error detection
static int get_unary_0_33(GetBitContext *gb)
Get unary code terminated by a 0 with a maximum length of 33.
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
static int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc, unsigned S)
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
#define AV_CODEC_CAP_CHANNEL_CONF
Codec should fill in channel configuration and samplerate instead of container.
av_cold void ff_init_dsd_data(void)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
An AVChannelLayout holds information about the channel layout of audio data.
static int wv_check_crc(WavpackFrameContext *s, uint32_t crc, uint32_t crc_extra_bits)
enum AVSampleFormat sample_fmt
audio sample format
#define FF_CODEC_CAP_ALLOCATE_PROGRESS
static char * split(char *message, char delim)
static void init_ptable(int *table, int rate_i, int rate_s)
#define AV_CODEC_CAP_SLICE_THREADS
Codec supports slice-based (or partition-based) multithreading.
#define WV_FLT_SHIFT_SENT
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
WavpackFrameContext * fdec[WV_MAX_FRAME_DECODERS]
static int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, void *dst_l, void *dst_r, const int type)
static int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, void *dst, const int type)
int nb_samples
number of audio samples (per channel) described by this frame
#define i(width, name, range_min, range_max)
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
static av_cold int wavpack_decode_end(AVCodecContext *avctx)
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
uint8_t ** extended_data
pointers to the data planes/channels.
static const int weights[]
AVSampleFormat
Audio sample formats.
#define xf(width, name, var, range_min, range_max, subs,...)
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
#define WV_FLT_SHIFT_SAME
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
static av_always_inline unsigned get_tail(GetBitContext *gb, int k)
const char * name
Name of the codec implementation.
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
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around ff_get_buffer() for frame-multithreaded codecs.
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)
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.
uint8_t value_lookup_buffer[MAX_HISTORY_BINS *MAX_BIN_BYTES]
AVBufferRef * av_buffer_allocz(size_t size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
static int wv_unpack_dsd_fast(WavpackFrameContext *s, uint8_t *dst_left, uint8_t *dst_right)
#define FFSWAP(type, a, b)
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
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
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
#define WV_MAX_FRAME_DECODERS
#define AV_INPUT_BUFFER_PADDING_SIZE
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
GetBitContext gb_extra_bits
static av_cold int wavpack_decode_init(AVCodecContext *avctx)
main external API structure.
#define UPDATE_WEIGHT_CLIP(weight, delta, samples, in)
static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb, int channel, int *last)
static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S)
Filter the word “frame” indicates either a video frame or a group of audio samples
static const int factor[16]
static int shift(int a, int b)
static float add(float src0, float src1)
static av_cold int wv_alloc_frame_context(WavpackContext *c)
A reference to a data buffer.
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
uint8_t probabilities[MAX_HISTORY_BINS][256]
This structure stores compressed data.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int wv_dsd_reset(WavpackContext *s, int channels)
uint8_t * value_lookup[MAX_HISTORY_BINS]
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.
static int dsd_channel(AVCodecContext *avctx, void *frmptr, int jobnr, int threadnr)