107 #define WMAPRO_MAX_CHANNELS 8
108 #define MAX_SUBFRAMES 32
110 #define MAX_FRAMESIZE 32768
111 #define XMA_MAX_STREAMS 8
112 #define XMA_MAX_CHANNELS_STREAM 2
113 #define XMA_MAX_CHANNELS (XMA_MAX_STREAMS * XMA_MAX_CHANNELS_STREAM)
115 #define WMAPRO_BLOCK_MIN_BITS 6
116 #define WMAPRO_BLOCK_MAX_BITS 13
117 #define WMAPRO_BLOCK_MIN_SIZE (1 << WMAPRO_BLOCK_MIN_BITS)
118 #define WMAPRO_BLOCK_MAX_SIZE (1 << WMAPRO_BLOCK_MAX_BITS)
119 #define WMAPRO_BLOCK_SIZES (WMAPRO_BLOCK_MAX_BITS - WMAPRO_BLOCK_MIN_BITS + 1)
123 #define SCALEVLCBITS 8
124 #define VEC4MAXDEPTH ((HUFF_VEC4_MAXBITS+VLCBITS-1)/VLCBITS)
125 #define VEC2MAXDEPTH ((HUFF_VEC2_MAXBITS+VLCBITS-1)/VLCBITS)
126 #define VEC1MAXDEPTH ((HUFF_VEC1_MAXBITS+VLCBITS-1)/VLCBITS)
127 #define SCALEMAXDEPTH ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS)
128 #define SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS)
259 #define PRINT(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %d\n", a, b);
260 #define PRINT_HEX(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %"PRIx32"\n", a, b);
262 PRINT(
"ed sample bit depth",
s->bits_per_sample);
263 PRINT_HEX(
"ed decode flags",
s->decode_flags);
264 PRINT(
"samples per frame",
s->samples_per_frame);
265 PRINT(
"log2 frame size",
s->log2_frame_size);
266 PRINT(
"max num subframes",
s->max_num_subframes);
267 PRINT(
"len prefix",
s->len_prefix);
268 PRINT(
"num channels",
s->nb_channels);
320 unsigned int channel_mask;
322 int log2_max_num_subframes;
323 int num_possible_block_sizes;
346 s->decode_flags = 0x10d6;
347 s->bits_per_sample = 16;
354 s->decode_flags = 0x10d6;
355 s->bits_per_sample = 16;
357 s->nb_channels = edata_ptr[32 + ((edata_ptr[0]==3)?0:8) + 4*num_stream + 0];
359 s->decode_flags = 0x10d6;
360 s->bits_per_sample = 16;
362 s->nb_channels = edata_ptr[8 + 20*num_stream + 17];
364 s->decode_flags =
AV_RL16(edata_ptr+14);
365 channel_mask =
AV_RL32(edata_ptr+2);
366 s->bits_per_sample =
AV_RL16(edata_ptr);
369 if (
s->bits_per_sample > 32 ||
s->bits_per_sample < 1) {
380 if (
s->log2_frame_size > 25) {
392 s->len_prefix = (
s->decode_flags & 0x40);
401 s->samples_per_frame = 1 <<
bits;
403 s->samples_per_frame = 512;
407 log2_max_num_subframes = ((
s->decode_flags & 0x38) >> 3);
408 s->max_num_subframes = 1 << log2_max_num_subframes;
409 if (
s->max_num_subframes == 16 ||
s->max_num_subframes == 4)
410 s->max_subframe_len_bit = 1;
411 s->subframe_len_bits =
av_log2(log2_max_num_subframes) + 1;
413 num_possible_block_sizes = log2_max_num_subframes + 1;
414 s->min_samples_per_subframe =
s->samples_per_frame /
s->max_num_subframes;
415 s->dynamic_range_compression = (
s->decode_flags & 0x80);
419 s->max_num_subframes);
425 s->min_samples_per_subframe);
429 if (
s->avctx->sample_rate <= 0) {
434 if (
s->nb_channels <= 0) {
449 for (
i = 0;
i <
s->nb_channels;
i++)
450 s->channel[
i].prev_block_len =
s->samples_per_frame;
455 if (channel_mask & 8) {
458 if (channel_mask &
mask)
493 for (
i = 0;
i < num_possible_block_sizes;
i++) {
494 int subframe_len =
s->samples_per_frame >>
i;
499 s->sfb_offsets[
i][0] = 0;
501 for (x = 0; x <
MAX_BANDS-1 &&
s->sfb_offsets[
i][band - 1] < subframe_len; x++) {
504 if (
offset >
s->sfb_offsets[
i][band - 1])
507 if (
offset >= subframe_len)
510 s->sfb_offsets[
i][band - 1] = subframe_len;
511 s->num_sfb[
i] = band - 1;
512 if (
s->num_sfb[
i] <= 0) {
524 for (
i = 0;
i < num_possible_block_sizes;
i++) {
526 for (
b = 0;
b <
s->num_sfb[
i];
b++) {
529 +
s->sfb_offsets[
i][
b + 1] - 1) <<
i) >> 1;
530 for (x = 0; x < num_possible_block_sizes; x++) {
532 while (
s->sfb_offsets[x][v + 1] << x <
offset) {
536 s->sf_offsets[
i][x][
b] = v;
549 / (1ll << (
s->bits_per_sample - 1)));
559 for (
i = 0;
i < num_possible_block_sizes;
i++) {
560 int block_size =
s->samples_per_frame >>
i;
561 int cutoff = (440*block_size + 3LL * (
s->avctx->sample_rate >> 1) - 1)
562 /
s->avctx->sample_rate;
563 s->subwoofer_cutoffs[
i] =
av_clip(cutoff, 4, block_size);
567 for (
i = 0;
i < 33;
i++)
598 int frame_len_shift = 0;
602 if (
offset ==
s->samples_per_frame -
s->min_samples_per_subframe)
603 return s->min_samples_per_subframe;
609 if (
s->max_subframe_len_bit) {
611 frame_len_shift = 1 +
get_bits(&
s->gb,
s->subframe_len_bits-1);
613 frame_len_shift =
get_bits(&
s->gb,
s->subframe_len_bits);
615 subframe_len =
s->samples_per_frame >> frame_len_shift;
618 if (subframe_len < s->min_samples_per_subframe ||
619 subframe_len >
s->samples_per_frame) {
651 int channels_for_cur_subframe =
s->nb_channels;
652 int fixed_channel_layout = 0;
653 int min_channel_len = 0;
663 for (
c = 0;
c <
s->nb_channels;
c++)
664 s->channel[
c].num_subframes = 0;
667 fixed_channel_layout = 1;
674 for (
c = 0;
c <
s->nb_channels;
c++) {
675 if (num_samples[
c] == min_channel_len) {
676 if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
677 (min_channel_len ==
s->samples_per_frame -
s->min_samples_per_subframe))
678 contains_subframe[
c] = 1;
682 contains_subframe[
c] = 0;
690 min_channel_len += subframe_len;
691 for (
c = 0;
c <
s->nb_channels;
c++) {
694 if (contains_subframe[
c]) {
697 "broken frame: num subframes > 31\n");
701 num_samples[
c] += subframe_len;
703 if (num_samples[
c] >
s->samples_per_frame) {
705 "channel len > samples_per_frame\n");
708 }
else if (num_samples[
c] <= min_channel_len) {
709 if (num_samples[
c] < min_channel_len) {
710 channels_for_cur_subframe = 0;
711 min_channel_len = num_samples[
c];
713 ++channels_for_cur_subframe;
716 }
while (min_channel_len < s->samples_per_frame);
718 for (
c = 0;
c <
s->nb_channels;
c++) {
721 for (
i = 0;
i <
s->channel[
c].num_subframes;
i++) {
722 ff_dlog(
s->avctx,
"frame[%"PRIu32
"] channel[%i] subframe[%i]"
723 " len %i\n",
s->frame_num,
c,
i,
724 s->channel[
c].subframe_len[
i]);
725 s->channel[
c].subframe_offset[
i] =
offset;
756 for (x = 0; x <
i; x++) {
758 for (y = 0; y <
i + 1; y++) {
761 int n = rotation_offset[
offset + x];
767 cosv =
sin64[32 - n];
769 sinv =
sin64[64 - n];
770 cosv = -
sin64[n - 32];
774 (v1 * sinv) - (v2 * cosv);
776 (v1 * cosv) + (v2 * sinv);
798 if (
s->nb_channels > 1) {
799 int remaining_channels =
s->channels_for_cur_subframe;
803 "Channel transform bit");
807 for (
s->num_chgroups = 0; remaining_channels &&
808 s->num_chgroups <
s->channels_for_cur_subframe;
s->num_chgroups++) {
815 if (remaining_channels > 2) {
816 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
817 int channel_idx =
s->channel_indexes_for_cur_subframe[
i];
818 if (!
s->channel[channel_idx].grouped
821 s->channel[channel_idx].grouped = 1;
822 *channel_data++ =
s->channel[channel_idx].coeffs;
827 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
828 int channel_idx =
s->channel_indexes_for_cur_subframe[
i];
829 if (!
s->channel[channel_idx].grouped)
830 *channel_data++ =
s->channel[channel_idx].coeffs;
831 s->channel[channel_idx].grouped = 1;
840 "Unknown channel transform type");
845 if (
s->nb_channels == 2) {
867 "Coupled channels > 6");
883 for (
i = 0;
i <
s->num_bands;
i++) {
907 static const uint32_t fval_tab[16] = {
908 0x00000000, 0x3f800000, 0x40000000, 0x40400000,
909 0x40800000, 0x40a00000, 0x40c00000, 0x40e00000,
910 0x41000000, 0x41100000, 0x41200000, 0x41300000,
911 0x41400000, 0x41500000, 0x41600000, 0x41700000,
922 ff_dlog(
s->avctx,
"decode coefficients for channel %i\n",
c);
937 while ((
s->transmit_num_vec_coeffs || !rl_mode) &&
946 for (
i = 0;
i < 4;
i += 2) {
971 for (
i = 0;
i < 4;
i++) {
977 ci->
coeffs[cur_coeff] = 0;
980 rl_mode |= (++num_zeros >
s->subframe_len >> 8);
987 if (cur_coeff < s->subframe_len) {
990 memset(&ci->
coeffs[cur_coeff], 0,
991 sizeof(*ci->
coeffs) * (
s->subframe_len - cur_coeff));
994 cur_coeff,
s->subframe_len,
995 s->subframe_len,
s->esc_len, 0);
1016 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1017 int c =
s->channel_indexes_for_cur_subframe[
i];
1020 s->channel[
c].scale_factors =
s->channel[
c].saved_scale_factors[!
s->channel[
c].scale_factor_idx];
1021 sf_end =
s->channel[
c].scale_factors +
s->num_bands;
1028 if (
s->channel[
c].reuse_sf) {
1029 const int8_t* sf_offsets =
s->sf_offsets[
s->table_idx][
s->channel[
c].table_idx];
1031 for (
b = 0;
b <
s->num_bands;
b++)
1032 s->channel[
c].scale_factors[
b] =
1033 s->channel[
c].saved_scale_factors[
s->channel[
c].scale_factor_idx][*sf_offsets++];
1036 if (!
s->channel[
c].cur_subframe ||
get_bits1(&
s->gb)) {
1038 if (!
s->channel[
c].reuse_sf) {
1041 s->channel[
c].scale_factor_step =
get_bits(&
s->gb, 2) + 1;
1042 val = 45 /
s->channel[
c].scale_factor_step;
1043 for (sf =
s->channel[
c].scale_factors; sf < sf_end; sf++) {
1050 for (
i = 0;
i <
s->num_bands;
i++) {
1061 sign = (
code & 1) - 1;
1062 skip = (
code & 0x3f) >> 1;
1063 }
else if (idx == 1) {
1072 if (
i >=
s->num_bands) {
1074 "invalid scale factor coding\n");
1077 s->channel[
c].scale_factors[
i] += (
val ^ sign) - sign;
1081 s->channel[
c].scale_factor_idx = !
s->channel[
c].scale_factor_idx;
1082 s->channel[
c].table_idx =
s->table_idx;
1083 s->channel[
c].reuse_sf = 1;
1087 s->channel[
c].max_scale_factor =
s->channel[
c].scale_factors[0];
1088 for (sf =
s->channel[
c].scale_factors + 1; sf < sf_end; sf++) {
1089 s->channel[
c].max_scale_factor =
1090 FFMAX(
s->channel[
c].max_scale_factor, *sf);
1105 for (
i = 0;
i <
s->num_chgroups;
i++) {
1106 if (
s->chgroup[
i].transform) {
1108 const int num_channels =
s->chgroup[
i].num_channels;
1109 float** ch_data =
s->chgroup[
i].channel_data;
1110 float** ch_end = ch_data + num_channels;
1111 const int8_t*
tb =
s->chgroup[
i].transform_band;
1115 for (sfb =
s->cur_sfb_offsets;
1116 sfb < s->cur_sfb_offsets +
s->num_bands; sfb++) {
1120 for (y = sfb[0]; y <
FFMIN(sfb[1],
s->subframe_len); y++) {
1121 const float* mat =
s->chgroup[
i].decorrelation_matrix;
1122 const float* data_end =
data + num_channels;
1123 float* data_ptr =
data;
1126 for (ch = ch_data; ch < ch_end; ch++)
1127 *data_ptr++ = (*ch)[y];
1129 for (ch = ch_data; ch < ch_end; ch++) {
1132 while (data_ptr < data_end)
1133 sum += *data_ptr++ * *mat++;
1138 }
else if (
s->nb_channels == 2) {
1139 int len =
FFMIN(sfb[1],
s->subframe_len) - sfb[0];
1140 s->fdsp->vector_fmul_scalar(ch_data[0] + sfb[0],
1141 ch_data[0] + sfb[0],
1143 s->fdsp->vector_fmul_scalar(ch_data[1] + sfb[0],
1144 ch_data[1] + sfb[0],
1159 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1160 int c =
s->channel_indexes_for_cur_subframe[
i];
1162 int winlen =
s->channel[
c].prev_block_len;
1163 float* start =
s->channel[
c].coeffs - (winlen >> 1);
1165 if (
s->subframe_len < winlen) {
1166 start += (winlen -
s->subframe_len) >> 1;
1167 winlen =
s->subframe_len;
1174 s->fdsp->vector_fmul_window(start, start, start + winlen,
1177 s->channel[
c].prev_block_len =
s->subframe_len;
1188 int offset =
s->samples_per_frame;
1189 int subframe_len =
s->samples_per_frame;
1191 int total_samples =
s->samples_per_frame *
s->nb_channels;
1192 int transmit_coeffs = 0;
1193 int cur_subwoofer_cutoff;
1201 for (
i = 0;
i <
s->nb_channels;
i++) {
1202 s->channel[
i].grouped = 0;
1203 if (
offset >
s->channel[
i].decoded_samples) {
1204 offset =
s->channel[
i].decoded_samples;
1206 s->channel[
i].subframe_len[
s->channel[
i].cur_subframe];
1211 "processing subframe with offset %i len %i\n",
offset, subframe_len);
1214 s->channels_for_cur_subframe = 0;
1215 for (
i = 0;
i <
s->nb_channels;
i++) {
1216 const int cur_subframe =
s->channel[
i].cur_subframe;
1218 total_samples -=
s->channel[
i].decoded_samples;
1221 if (
offset ==
s->channel[
i].decoded_samples &&
1222 subframe_len ==
s->channel[
i].subframe_len[cur_subframe]) {
1223 total_samples -=
s->channel[
i].subframe_len[cur_subframe];
1224 s->channel[
i].decoded_samples +=
1225 s->channel[
i].subframe_len[cur_subframe];
1226 s->channel_indexes_for_cur_subframe[
s->channels_for_cur_subframe] =
i;
1227 ++
s->channels_for_cur_subframe;
1234 s->parsed_all_subframes = 1;
1237 ff_dlog(
s->avctx,
"subframe is part of %i channels\n",
1238 s->channels_for_cur_subframe);
1241 s->table_idx =
av_log2(
s->samples_per_frame/subframe_len);
1242 s->num_bands =
s->num_sfb[
s->table_idx];
1243 s->cur_sfb_offsets =
s->sfb_offsets[
s->table_idx];
1244 cur_subwoofer_cutoff =
s->subwoofer_cutoffs[
s->table_idx];
1247 offset +=
s->samples_per_frame >> 1;
1249 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1250 int c =
s->channel_indexes_for_cur_subframe[
i];
1252 s->channel[
c].coeffs = &
s->channel[
c].out[
offset];
1255 s->subframe_len = subframe_len;
1256 s->esc_len =
av_log2(
s->subframe_len - 1) + 1;
1261 if (!(num_fill_bits =
get_bits(&
s->gb, 2))) {
1266 if (num_fill_bits >= 0) {
1287 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1288 int c =
s->channel_indexes_for_cur_subframe[
i];
1289 if ((
s->channel[
c].transmit_coefs =
get_bits1(&
s->gb)))
1290 transmit_coeffs = 1;
1294 if (transmit_coeffs) {
1296 int quant_step = 90 *
s->bits_per_sample >> 4;
1299 if ((
s->transmit_num_vec_coeffs =
get_bits1(&
s->gb))) {
1300 int num_bits =
av_log2((
s->subframe_len + 3)/4) + 1;
1301 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1302 int c =
s->channel_indexes_for_cur_subframe[
i];
1303 int num_vec_coeffs =
get_bits(&
s->gb, num_bits) << 2;
1304 if (num_vec_coeffs >
s->subframe_len) {
1309 s->channel[
c].num_vec_coeffs = num_vec_coeffs;
1312 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1313 int c =
s->channel_indexes_for_cur_subframe[
i];
1314 s->channel[
c].num_vec_coeffs =
s->subframe_len;
1320 if (step == -32 || step == 31) {
1321 const int sign = (step == 31) - 1;
1327 quant_step += ((
quant + step) ^ sign) - sign;
1329 if (quant_step < 0) {
1335 if (
s->channels_for_cur_subframe == 1) {
1336 s->channel[
s->channel_indexes_for_cur_subframe[0]].quant_step = quant_step;
1339 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1340 int c =
s->channel_indexes_for_cur_subframe[
i];
1341 s->channel[
c].quant_step = quant_step;
1344 s->channel[
c].quant_step +=
get_bits(&
s->gb, modifier_len) + 1;
1346 ++
s->channel[
c].quant_step;
1356 ff_dlog(
s->avctx,
"BITSTREAM: subframe header length was %i\n",
1360 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1361 int c =
s->channel_indexes_for_cur_subframe[
i];
1362 if (
s->channel[
c].transmit_coefs &&
1366 memset(
s->channel[
c].coeffs, 0,
1367 sizeof(*
s->channel[
c].coeffs) * subframe_len);
1370 ff_dlog(
s->avctx,
"BITSTREAM: subframe length was %i\n",
1373 if (transmit_coeffs) {
1377 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1378 int c =
s->channel_indexes_for_cur_subframe[
i];
1379 const int* sf =
s->channel[
c].scale_factors;
1382 if (
c ==
s->lfe_channel)
1383 memset(&
s->tmp[cur_subwoofer_cutoff], 0,
sizeof(*
s->tmp) *
1384 (subframe_len - cur_subwoofer_cutoff));
1387 for (
b = 0;
b <
s->num_bands;
b++) {
1388 const int end =
FFMIN(
s->cur_sfb_offsets[
b+1],
s->subframe_len);
1389 const int exp =
s->channel[
c].quant_step -
1390 (
s->channel[
c].max_scale_factor - *sf++) *
1391 s->channel[
c].scale_factor_step;
1393 int start =
s->cur_sfb_offsets[
b];
1394 s->fdsp->vector_fmul_scalar(
s->tmp + start,
1395 s->channel[
c].coeffs + start,
1396 quant, end - start);
1408 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1409 int c =
s->channel_indexes_for_cur_subframe[
i];
1410 if (
s->channel[
c].cur_subframe >=
s->channel[
c].num_subframes) {
1414 ++
s->channel[
c].cur_subframe;
1429 int more_frames = 0;
1437 ff_dlog(
s->avctx,
"decoding frame with length %x\n",
len);
1448 for (
i = 0;
i <
s->nb_channels *
s->nb_channels;
i++)
1454 if (
s->dynamic_range_compression) {
1456 ff_dlog(
s->avctx,
"drc_gain %i\n",
s->drc_gain);
1467 ff_dlog(
s->avctx,
"start skip: %i\n", skip);
1473 ff_dlog(
s->avctx,
"end skip: %i\n", skip);
1478 ff_dlog(
s->avctx,
"BITSTREAM: frame header length was %i\n",
1482 s->parsed_all_subframes = 0;
1483 for (
i = 0;
i <
s->nb_channels;
i++) {
1484 s->channel[
i].decoded_samples = 0;
1485 s->channel[
i].cur_subframe = 0;
1486 s->channel[
i].reuse_sf = 0;
1490 while (!
s->parsed_all_subframes) {
1498 for (
i = 0;
i <
s->nb_channels;
i++)
1500 s->samples_per_frame *
sizeof(*
s->channel[
i].out));
1502 for (
i = 0;
i <
s->nb_channels;
i++) {
1504 memcpy(&
s->channel[
i].out[0],
1505 &
s->channel[
i].out[
s->samples_per_frame],
1506 s->samples_per_frame *
sizeof(*
s->channel[
i].out) >> 1);
1509 if (
s->skip_frame) {
1517 if (
s->len_prefix) {
1521 "frame[%"PRIu32
"] would have to skip %i bits\n",
1571 s->num_saved_bits =
s->frame_offset;
1573 buflen = (
s->num_saved_bits +
len + 7) >> 3;
1585 s->num_saved_bits +=
len;
1612 int buf_size = avpkt->
size;
1613 int num_bits_prev_frame;
1614 int packet_sequence_number;
1629 for (
i = 0;
i <
s->nb_channels;
i++) {
1631 s->samples_per_frame *
sizeof(*
s->channel[
i].out));
1634 s->samples_per_frame *
sizeof(*
s->channel[
i].out) >> 1);
1645 else if (
s->packet_done ||
s->packet_loss) {
1663 s->buf_bit_size = buf_size << 3;
1668 packet_sequence_number =
get_bits(gb, 4);
1673 packet_sequence_number = 0;
1677 num_bits_prev_frame =
get_bits(gb,
s->log2_frame_size);
1685 num_bits_prev_frame);
1689 ((
s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) {
1692 "Packet loss detected! seq %"PRIx8
" vs %x\n",
1693 s->packet_sequence_number, packet_sequence_number);
1695 s->packet_sequence_number = packet_sequence_number;
1697 if (num_bits_prev_frame > 0) {
1699 if (num_bits_prev_frame >= remaining_packet_bits) {
1700 num_bits_prev_frame = remaining_packet_bits;
1707 ff_dlog(avctx,
"accumulated %x bits of frame data\n",
1708 s->num_saved_bits -
s->frame_offset);
1711 if (!
s->packet_loss)
1713 }
else if (
s->num_saved_bits -
s->frame_offset) {
1714 ff_dlog(avctx,
"ignoring %x previously saved bits\n",
1715 s->num_saved_bits -
s->frame_offset);
1718 if (
s->packet_loss) {
1722 s->num_saved_bits = 0;
1728 if (avpkt->
size <
s->next_packet_start) {
1733 s->buf_bit_size = (avpkt->
size -
s->next_packet_start) << 3;
1740 if (!
s->packet_loss)
1742 }
else if (!
s->len_prefix
1762 if (
s->packet_done && !
s->packet_loss &&
1784 int *got_frame_ptr,
AVPacket *avpkt)
1801 int *got_frame_ptr,
AVPacket *avpkt)
1804 int got_stream_frame_ptr = 0;
1808 if (!
s->frames[
s->current_stream]->data[0]) {
1809 s->frames[
s->current_stream]->nb_samples = 512;
1810 if ((ret =
ff_get_buffer(avctx,
s->frames[
s->current_stream], 0)) < 0) {
1815 ret =
decode_packet(avctx, &
s->xma[
s->current_stream],
s->frames[
s->current_stream],
1816 &got_stream_frame_ptr, avpkt);
1818 if (got_stream_frame_ptr &&
s->offset[
s->current_stream] >= 64) {
1819 got_stream_frame_ptr = 0;
1824 if (got_stream_frame_ptr) {
1825 int start_ch =
s->start_channel[
s->current_stream];
1826 memcpy(&
s->samples[start_ch + 0][
s->offset[
s->current_stream] * 512],
1827 s->frames[
s->current_stream]->extended_data[0], 512 * 4);
1828 if (
s->xma[
s->current_stream].nb_channels > 1)
1829 memcpy(&
s->samples[start_ch + 1][
s->offset[
s->current_stream] * 512],
1830 s->frames[
s->current_stream]->extended_data[1], 512 * 4);
1831 s->offset[
s->current_stream]++;
1832 }
else if (ret < 0) {
1833 memset(
s->offset, 0,
sizeof(
s->offset));
1834 s->current_stream = 0;
1841 if (
s->xma[
s->current_stream].packet_done ||
1842 s->xma[
s->current_stream].packet_loss) {
1845 if (
s->xma[
s->current_stream].skip_packets != 0) {
1848 min[0] =
s->xma[0].skip_packets;
1851 for (
i = 1;
i <
s->num_streams;
i++) {
1852 if (
s->xma[
i].skip_packets <
min[0]) {
1853 min[0] =
s->xma[
i].skip_packets;
1858 s->current_stream =
min[1];
1862 for (
i = 0;
i <
s->num_streams;
i++) {
1863 s->xma[
i].skip_packets =
FFMAX(0,
s->xma[
i].skip_packets - 1);
1867 for (
i = 0;
i <
s->num_streams;
i++) {
1878 for (
i = 0;
i <
s->num_streams;
i++) {
1879 int start_ch =
s->start_channel[
i];
1881 if (
s->xma[
i].nb_channels > 1)
1886 memmove(
s->samples[start_ch + 0],
s->samples[start_ch + 0] +
frame->
nb_samples,
s->offset[
i] * 4 * 512);
1887 if (
s->xma[
i].nb_channels > 1)
1888 memmove(
s->samples[start_ch + 1],
s->samples[start_ch + 1] +
frame->
nb_samples,
s->offset[
i] * 4 * 512);
1902 int i, ret, start_channels = 0;
1909 s->num_streams = (avctx->
channels + 1) / 2;
1939 for (
i = 0;
i <
s->num_streams;
i++) {
1947 s->start_channel[
i] = start_channels;
1948 start_channels +=
s->xma[
i].nb_channels;
1950 if (start_channels != avctx->
channels)
1961 for (
i = 0;
i <
s->num_streams;
i++) {
1975 for (
i = 0;
i <
s->nb_channels;
i++)
1976 memset(
s->channel[
i].out, 0,
s->samples_per_frame *
1977 sizeof(*
s->channel[
i].out));
1979 s->skip_packets = 0;
2000 for (
i = 0;
i <
s->num_streams;
i++)
2003 memset(
s->offset, 0,
sizeof(
s->offset));
2004 s->current_stream = 0;
static enum AVSampleFormat sample_fmts[]
static double val(void *priv, double ch)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
#define FF_DEBUG_BITSTREAM
static av_cold int init(AVCodecContext *avctx)
void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
Copy the content of src to the bitstream.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
channel
Use these values when setting the channel map with ebur128_set_channel().
internal math functions header
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
static SDL_Window * window
bitstream reader API header.
static int get_sbits(GetBitContext *s, int n)
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
static int get_bits_left(GetBitContext *gb)
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
static int get_bits_count(const GetBitContext *s)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
#define AV_CODEC_CAP_SUBFRAMES
Codec can output multiple frames per AVPacket Normally demuxers return one frame at a time,...
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
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_DEBUG
Stuff which is only useful for libav* developers.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_FLTP
float, planar
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static const uint16_t mask[17]
static uint8_t * append(uint8_t *buf, const uint8_t *src, int size)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int put_bits_count(PutBitContext *s)
static int put_bits_left(PutBitContext *s)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
void ff_init_ff_sine_windows(int index)
initialize the specified entry of ff_sine_windows
SINETABLE_CONST float *const ff_sine_windows[]
#define FF_ARRAY_ELEMS(a)
main external API structure.
enum AVSampleFormat sample_fmt
audio sample format
int sample_rate
samples per second
int frame_number
Frame counter, set by libavcodec.
int flags
AV_CODEC_FLAG_*.
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
int channels
number of audio channels
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
uint64_t channel_layout
Audio channel layout.
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 ** extended_data
pointers to the data planes/channels.
This structure stores compressed data.
void(* imdct_half)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
VLC_TYPE(* table)[2]
code, bits
frame specific decoder context for a single channel
int16_t prev_block_len
length of the previous block
int quant_step
quantization step for the current subframe
uint16_t num_vec_coeffs
number of vector coded coefficients
uint8_t table_idx
index in sf_offsets for the scale factor reference block
float * coeffs
pointer to the subframe decode buffer
uint16_t subframe_offset[MAX_SUBFRAMES]
subframe positions in the current frame
uint8_t cur_subframe
current subframe number
int * scale_factors
pointer to the scale factor values used for decoding
int8_t scale_factor_step
scaling step for the current subframe
int8_t reuse_sf
share scale factors between subframes
uint8_t grouped
channel is part of a group
float out[WMAPRO_BLOCK_MAX_SIZE+WMAPRO_BLOCK_MAX_SIZE/2]
output buffer
int max_scale_factor
maximum scale factor for the current subframe
uint16_t decoded_samples
number of already processed samples
int saved_scale_factors[2][MAX_BANDS]
resampled and (previously) transmitted scale factor values
int8_t scale_factor_idx
index for the transmitted scale factor values (used for resampling)
uint16_t subframe_len[MAX_SUBFRAMES]
subframe length in samples
channel group for channel transformations
int8_t transform_band[MAX_BANDS]
controls if the transform is enabled for a certain band
float decorrelation_matrix[WMAPRO_MAX_CHANNELS *WMAPRO_MAX_CHANNELS]
float * channel_data[WMAPRO_MAX_CHANNELS]
transformation coefficients
int8_t transform
transform on / off
uint8_t num_channels
number of channels in the group
int num_saved_bits
saved number of bits
uint8_t packet_sequence_number
current packet number
int8_t parsed_all_subframes
all subframes decoded?
WMAProChannelGrp chgroup[WMAPRO_MAX_CHANNELS]
channel group information
GetBitContext gb
bitstream reader context
int8_t esc_len
length of escaped coefficients
int8_t channels_for_cur_subframe
number of channels that contain the subframe
uint32_t frame_num
current frame number (not used for decoding)
int16_t subwoofer_cutoffs[WMAPRO_BLOCK_SIZES]
subwoofer cutoff values
int8_t channel_indexes_for_cur_subframe[WMAPRO_MAX_CHANNELS]
uint8_t len_prefix
frame is prefixed with its length
int frame_offset
frame offset in the bit reservoir
int16_t sfb_offsets[WMAPRO_BLOCK_SIZES][MAX_BANDS]
scale factor band offsets (multiples of 4)
uint32_t decode_flags
used compression features
uint16_t samples_per_frame
number of samples to output
uint8_t packet_done
set when a packet is fully decoded
int8_t nb_channels
number of channels in stream (XMA1/2)
FFTContext mdct_ctx[WMAPRO_BLOCK_SIZES]
MDCT context per block size.
AVCodecContext * avctx
codec context for av_log
int subframe_offset
subframe offset in the bit reservoir
uint8_t eof_done
set when EOF reached and extra subframe is written (XMA1/2)
int buf_bit_size
buffer size in bits
uint8_t dynamic_range_compression
frame contains DRC data
int16_t subframe_len
current subframe length
uint8_t max_subframe_len_bit
flag indicating that the subframe is of maximum size when the first subframe length bit is 1
int8_t skip_frame
skip output step
uint8_t num_chgroups
number of channel groups
int8_t lfe_channel
lfe channel index
uint8_t table_idx
index for the num_sfb, sfb_offsets, sf_offsets and subwoofer_cutoffs tables
int16_t * cur_sfb_offsets
sfb offsets for the current block
uint8_t subframe_len_bits
number of bits used for the subframe length
uint8_t packet_loss
set in case of bitstream error
int8_t num_bands
number of scale factor bands
uint8_t drc_gain
gain for the DRC tool
uint8_t frame_data[MAX_FRAMESIZE+AV_INPUT_BUFFER_PADDING_SIZE]
compressed frame data
uint8_t max_num_subframes
float tmp[WMAPRO_BLOCK_MAX_SIZE]
IMDCT output buffer.
int next_packet_start
start offset of the next wma packet in the demuxer packet
int8_t num_sfb[WMAPRO_BLOCK_SIZES]
scale factor bands per block size
PutBitContext pb
context for filling the frame_data buffer
uint8_t bits_per_sample
integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1....
GetBitContext pgb
bitstream reader context for the packet
uint16_t min_samples_per_subframe
uint8_t packet_offset
frame offset in the packet
int8_t sf_offsets[WMAPRO_BLOCK_SIZES][WMAPRO_BLOCK_SIZES][MAX_BANDS]
scale factor resample matrix
uint8_t skip_packets
packets to skip to find next packet in a stream (XMA1/2)
int8_t transmit_num_vec_coeffs
number of vector coded coefficients is part of the bitstream
const float * windows[WMAPRO_BLOCK_SIZES]
windows for the different block sizes
int offset[XMA_MAX_STREAMS]
WMAProDecodeCtx xma[XMA_MAX_STREAMS]
AVFrame * frames[XMA_MAX_STREAMS]
float samples[XMA_MAX_CHANNELS][512 *64]
int start_channel[XMA_MAX_STREAMS]
#define avpriv_request_sample(...)
static const uint8_t offset[127][2]
#define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)
int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb, VLC *vlc, const float *level_table, const uint16_t *run_table, int version, WMACoef *ptr, int offset, int num_coefs, int block_len, int frame_len_bits, int coef_nb_bits)
Decode run level compressed coefficients.
unsigned int ff_wma_get_large_val(GetBitContext *gb)
Decode an uncompressed coefficient.
av_cold int ff_wma_get_frame_len_bits(int sample_rate, int version, unsigned int decode_flags)
Get the samples per frame for this stream.
static const uint8_t coef1_huffbits[555]
static const uint8_t coef0_huffbits[666]
static const uint32_t coef1_huffcodes[555]
static const uint32_t coef0_huffcodes[666]
tables for wmapro decoding
static const uint8_t vec2_huffbits[HUFF_VEC2_SIZE]
static const uint8_t symbol_to_vec2[HUFF_VEC2_SIZE]
static const uint16_t vec1_huffcodes[HUFF_VEC1_SIZE]
static const uint8_t scale_huffbits[HUFF_SCALE_SIZE]
static const uint16_t symbol_to_vec4[HUFF_VEC4_SIZE]
#define HUFF_SCALE_RL_SIZE
static const uint8_t scale_rl_level[HUFF_SCALE_RL_SIZE]
static const uint16_t coef1_run[HUFF_COEF1_SIZE]
static const uint8_t vec1_huffbits[HUFF_VEC1_SIZE]
static const uint8_t vec4_huffbits[HUFF_VEC4_SIZE]
static const uint8_t scale_rl_run[HUFF_SCALE_RL_SIZE]
static const uint16_t coef0_run[HUFF_COEF0_SIZE]
static const uint16_t vec4_huffcodes[HUFF_VEC4_SIZE]
static const float *const default_decorrelation[]
default decorrelation matrix offsets
static const uint16_t scale_huffcodes[HUFF_SCALE_SIZE]
static const float coef0_level[HUFF_COEF0_SIZE]
static const uint16_t vec2_huffcodes[HUFF_VEC2_SIZE]
static const float coef1_level[HUFF_COEF1_SIZE]
static const uint8_t scale_rl_huffbits[HUFF_SCALE_RL_SIZE]
static const uint16_t critical_freq[]
frequencies to divide the frequency spectrum into scale factor bands
static const uint32_t scale_rl_huffcodes[HUFF_SCALE_RL_SIZE]
#define MAX_BANDS
max number of scale factor bands
static VLC sf_vlc
scale factor DPCM vlc
static void wmapro_window(WMAProDecodeCtx *s)
Apply sine window and reconstruct the output buffer.
static int remaining_bits(WMAProDecodeCtx *s, GetBitContext *gb)
Calculate remaining input buffer length.
#define WMAPRO_BLOCK_MAX_SIZE
maximum block size
#define WMAPRO_BLOCK_SIZES
possible block sizes
static av_cold void dump_context(WMAProDecodeCtx *s)
helper function to print the most important members of the context
#define WMAPRO_BLOCK_MIN_SIZE
minimum block size
static void wmapro_flush(AVCodecContext *avctx)
Clear decoder buffers (for seeking).
static void xma_flush(AVCodecContext *avctx)
static VLC vec4_vlc
4 coefficients per symbol
static float sin64[33]
sine table for decorrelation
#define WMAPRO_BLOCK_MIN_BITS
log2 of min block size
static int decode_frame(WMAProDecodeCtx *s, AVFrame *frame, int *got_frame_ptr)
Decode one WMA frame.
static av_cold int decode_init(WMAProDecodeCtx *s, AVCodecContext *avctx, int num_stream)
Initialize the decoder.
static av_cold int xma_decode_init(AVCodecContext *avctx)
static av_cold int xma_decode_end(AVCodecContext *avctx)
static av_cold int get_rate(AVCodecContext *avctx)
static VLC coef_vlc[2]
coefficient run length vlc codes
static void save_bits(WMAProDecodeCtx *s, GetBitContext *gb, int len, int append)
Fill the bit reservoir with a (partial) frame.
static int decode_channel_transform(WMAProDecodeCtx *s)
Decode channel transformation parameters.
static VLC vec2_vlc
2 coefficients per symbol
static int xma_decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
static void decode_decorrelation_matrix(WMAProDecodeCtx *s, WMAProChannelGrp *chgroup)
Calculate a decorrelation matrix from the bitstream parameters.
static VLC vec1_vlc
1 coefficient per symbol
static VLC sf_rl_vlc
scale factor run length vlc
static void inverse_channel_transform(WMAProDecodeCtx *s)
Reconstruct the individual channel data.
static int wmapro_decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Decode a single WMA packet.
#define MAX_SUBFRAMES
max number of subframes per channel
static void flush(WMAProDecodeCtx *s)
static int decode_subframe_length(WMAProDecodeCtx *s, int offset)
Decode the subframe length.
static int decode_subframe(WMAProDecodeCtx *s)
Decode a single subframe (block).
static av_cold int wmapro_decode_end(AVCodecContext *avctx)
AVCodec ff_wmapro_decoder
wmapro decoder
static av_cold int wmapro_decode_init(AVCodecContext *avctx)
Initialize the decoder.
static int decode_packet(AVCodecContext *avctx, WMAProDecodeCtx *s, void *data, int *got_frame_ptr, AVPacket *avpkt)
static int decode_coeffs(WMAProDecodeCtx *s, int c)
Extract the coefficients from the bitstream.
#define XMA_MAX_CHANNELS_STREAM
#define WMAPRO_BLOCK_MAX_BITS
log2 of max block size
#define MAX_FRAMESIZE
maximum compressed frame size
static int decode_tilehdr(WMAProDecodeCtx *s)
Decode how the data in the frame is split into subframes.
static av_cold int decode_end(WMAProDecodeCtx *s)
Uninitialize the decoder and free all resources.
static int decode_scale_factors(WMAProDecodeCtx *s)
Extract scale factors from the bitstream.
#define WMAPRO_MAX_CHANNELS
current decoder limitations