108 #define WMAPRO_MAX_CHANNELS 8
109 #define MAX_SUBFRAMES 32
111 #define MAX_FRAMESIZE 32768
112 #define XMA_MAX_STREAMS 8
113 #define XMA_MAX_CHANNELS_STREAM 2
114 #define XMA_MAX_CHANNELS (XMA_MAX_STREAMS * XMA_MAX_CHANNELS_STREAM)
116 #define WMAPRO_BLOCK_MIN_BITS 6
117 #define WMAPRO_BLOCK_MAX_BITS 13
118 #define WMAPRO_BLOCK_MIN_SIZE (1 << WMAPRO_BLOCK_MIN_BITS)
119 #define WMAPRO_BLOCK_MAX_SIZE (1 << WMAPRO_BLOCK_MAX_BITS)
120 #define WMAPRO_BLOCK_SIZES (WMAPRO_BLOCK_MAX_BITS - WMAPRO_BLOCK_MIN_BITS + 1)
124 #define SCALEVLCBITS 8
125 #define VEC4MAXDEPTH ((HUFF_VEC4_MAXBITS+VLCBITS-1)/VLCBITS)
126 #define VEC2MAXDEPTH ((HUFF_VEC2_MAXBITS+VLCBITS-1)/VLCBITS)
127 #define VEC1MAXDEPTH ((HUFF_VEC1_MAXBITS+VLCBITS-1)/VLCBITS)
128 #define SCALEMAXDEPTH ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS)
129 #define SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS)
260 #define PRINT(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %d\n", a, b);
261 #define PRINT_HEX(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %"PRIx32"\n", a, b);
263 PRINT(
"ed sample bit depth",
s->bits_per_sample);
264 PRINT_HEX(
"ed decode flags",
s->decode_flags);
265 PRINT(
"samples per frame",
s->samples_per_frame);
266 PRINT(
"log2 frame size",
s->log2_frame_size);
267 PRINT(
"max num subframes",
s->max_num_subframes);
268 PRINT(
"len prefix",
s->len_prefix);
269 PRINT(
"num channels",
s->nb_channels);
338 for (
int i = 0;
i < 33;
i++)
354 unsigned int channel_mask;
356 int log2_max_num_subframes;
357 int num_possible_block_sizes;
380 s->decode_flags = 0x10d6;
381 s->bits_per_sample = 16;
388 s->decode_flags = 0x10d6;
389 s->bits_per_sample = 16;
391 s->nb_channels = edata_ptr[32 + ((edata_ptr[0]==3)?0:8) + 4*num_stream + 0];
393 s->decode_flags = 0x10d6;
394 s->bits_per_sample = 16;
396 s->nb_channels = edata_ptr[8 + 20*num_stream + 17];
398 s->decode_flags =
AV_RL16(edata_ptr+14);
399 channel_mask =
AV_RL32(edata_ptr+2);
400 s->bits_per_sample =
AV_RL16(edata_ptr);
403 if (
s->bits_per_sample > 32 ||
s->bits_per_sample < 1) {
414 if (
s->log2_frame_size > 25) {
426 s->len_prefix = (
s->decode_flags & 0x40);
435 s->samples_per_frame = 1 <<
bits;
437 s->samples_per_frame = 512;
441 log2_max_num_subframes = ((
s->decode_flags & 0x38) >> 3);
442 s->max_num_subframes = 1 << log2_max_num_subframes;
443 if (
s->max_num_subframes == 16 ||
s->max_num_subframes == 4)
444 s->max_subframe_len_bit = 1;
445 s->subframe_len_bits =
av_log2(log2_max_num_subframes) + 1;
447 num_possible_block_sizes = log2_max_num_subframes + 1;
448 s->min_samples_per_subframe =
s->samples_per_frame /
s->max_num_subframes;
449 s->dynamic_range_compression = (
s->decode_flags & 0x80);
453 s->max_num_subframes);
459 s->min_samples_per_subframe);
463 if (
s->avctx->sample_rate <= 0) {
468 if (
s->nb_channels <= 0) {
483 for (
i = 0;
i <
s->nb_channels;
i++)
484 s->channel[
i].prev_block_len =
s->samples_per_frame;
489 if (channel_mask & 8) {
492 if (channel_mask &
mask)
499 for (
i = 0;
i < num_possible_block_sizes;
i++) {
500 int subframe_len =
s->samples_per_frame >>
i;
505 s->sfb_offsets[
i][0] = 0;
507 for (x = 0; x <
MAX_BANDS-1 &&
s->sfb_offsets[
i][band - 1] < subframe_len; x++) {
510 if (
offset >
s->sfb_offsets[
i][band - 1])
513 if (
offset >= subframe_len)
516 s->sfb_offsets[
i][band - 1] = subframe_len;
517 s->num_sfb[
i] = band - 1;
518 if (
s->num_sfb[
i] <= 0) {
530 for (
i = 0;
i < num_possible_block_sizes;
i++) {
532 for (
b = 0;
b <
s->num_sfb[
i];
b++) {
535 +
s->sfb_offsets[
i][
b + 1] - 1) <<
i) >> 1;
536 for (x = 0; x < num_possible_block_sizes; x++) {
538 while (
s->sfb_offsets[x][v + 1] << x <
offset) {
542 s->sf_offsets[
i][x][
b] = v;
555 / (1ll << (
s->bits_per_sample - 1)));
567 for (
i = 0;
i < num_possible_block_sizes;
i++) {
568 int block_size =
s->samples_per_frame >>
i;
569 int cutoff = (440*block_size + 3LL * (
s->avctx->sample_rate >> 1) - 1)
570 /
s->avctx->sample_rate;
571 s->subwoofer_cutoffs[
i] =
av_clip(cutoff, 4, block_size);
604 int frame_len_shift = 0;
608 if (
offset ==
s->samples_per_frame -
s->min_samples_per_subframe)
609 return s->min_samples_per_subframe;
615 if (
s->max_subframe_len_bit) {
617 frame_len_shift = 1 +
get_bits(&
s->gb,
s->subframe_len_bits-1);
619 frame_len_shift =
get_bits(&
s->gb,
s->subframe_len_bits);
621 subframe_len =
s->samples_per_frame >> frame_len_shift;
624 if (subframe_len < s->min_samples_per_subframe ||
625 subframe_len >
s->samples_per_frame) {
657 int channels_for_cur_subframe =
s->nb_channels;
658 int fixed_channel_layout = 0;
659 int min_channel_len = 0;
669 for (
c = 0;
c <
s->nb_channels;
c++)
670 s->channel[
c].num_subframes = 0;
673 fixed_channel_layout = 1;
680 for (
c = 0;
c <
s->nb_channels;
c++) {
681 if (num_samples[
c] == min_channel_len) {
682 if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
683 (min_channel_len ==
s->samples_per_frame -
s->min_samples_per_subframe))
684 contains_subframe[
c] = 1;
688 contains_subframe[
c] = 0;
696 min_channel_len += subframe_len;
697 for (
c = 0;
c <
s->nb_channels;
c++) {
700 if (contains_subframe[
c]) {
703 "broken frame: num subframes > 31\n");
707 num_samples[
c] += subframe_len;
709 if (num_samples[
c] >
s->samples_per_frame) {
711 "channel len > samples_per_frame\n");
714 }
else if (num_samples[
c] <= min_channel_len) {
715 if (num_samples[
c] < min_channel_len) {
716 channels_for_cur_subframe = 0;
717 min_channel_len = num_samples[
c];
719 ++channels_for_cur_subframe;
722 }
while (min_channel_len < s->samples_per_frame);
724 for (
c = 0;
c <
s->nb_channels;
c++) {
727 for (
i = 0;
i <
s->channel[
c].num_subframes;
i++) {
728 ff_dlog(
s->avctx,
"frame[%"PRIu32
"] channel[%i] subframe[%i]"
729 " len %i\n",
s->frame_num,
c,
i,
730 s->channel[
c].subframe_len[
i]);
731 s->channel[
c].subframe_offset[
i] =
offset;
762 for (x = 0; x <
i; x++) {
764 for (y = 0; y <
i + 1; y++) {
767 int n = rotation_offset[
offset + x];
773 cosv =
sin64[32 - n];
775 sinv =
sin64[64 - n];
776 cosv = -
sin64[n - 32];
780 (v1 * sinv) - (v2 * cosv);
782 (v1 * cosv) + (v2 * sinv);
804 if (
s->nb_channels > 1) {
805 int remaining_channels =
s->channels_for_cur_subframe;
809 "Channel transform bit");
813 for (
s->num_chgroups = 0; remaining_channels &&
814 s->num_chgroups <
s->channels_for_cur_subframe;
s->num_chgroups++) {
821 if (remaining_channels > 2) {
822 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
823 int channel_idx =
s->channel_indexes_for_cur_subframe[
i];
824 if (!
s->channel[channel_idx].grouped
827 s->channel[channel_idx].grouped = 1;
828 *channel_data++ =
s->channel[channel_idx].coeffs;
833 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
834 int channel_idx =
s->channel_indexes_for_cur_subframe[
i];
835 if (!
s->channel[channel_idx].grouped)
836 *channel_data++ =
s->channel[channel_idx].coeffs;
837 s->channel[channel_idx].grouped = 1;
846 "Unknown channel transform type");
851 if (
s->nb_channels == 2) {
873 "Coupled channels > 6");
889 for (
i = 0;
i <
s->num_bands;
i++) {
913 static const uint32_t fval_tab[16] = {
914 0x00000000, 0x3f800000, 0x40000000, 0x40400000,
915 0x40800000, 0x40a00000, 0x40c00000, 0x40e00000,
916 0x41000000, 0x41100000, 0x41200000, 0x41300000,
917 0x41400000, 0x41500000, 0x41600000, 0x41700000,
928 ff_dlog(
s->avctx,
"decode coefficients for channel %i\n",
c);
943 while ((
s->transmit_num_vec_coeffs || !rl_mode) &&
952 for (
i = 0;
i < 4;
i += 2) {
977 for (
i = 0;
i < 4;
i++) {
983 ci->
coeffs[cur_coeff] = 0;
986 rl_mode |= (++num_zeros >
s->subframe_len >> 8);
993 if (cur_coeff < s->subframe_len) {
996 memset(&ci->
coeffs[cur_coeff], 0,
997 sizeof(*ci->
coeffs) * (
s->subframe_len - cur_coeff));
1000 cur_coeff,
s->subframe_len,
1001 s->subframe_len,
s->esc_len, 0);
1022 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1023 int c =
s->channel_indexes_for_cur_subframe[
i];
1026 s->channel[
c].scale_factors =
s->channel[
c].saved_scale_factors[!
s->channel[
c].scale_factor_idx];
1027 sf_end =
s->channel[
c].scale_factors +
s->num_bands;
1034 if (
s->channel[
c].reuse_sf) {
1035 const int8_t* sf_offsets =
s->sf_offsets[
s->table_idx][
s->channel[
c].table_idx];
1037 for (
b = 0;
b <
s->num_bands;
b++)
1038 s->channel[
c].scale_factors[
b] =
1039 s->channel[
c].saved_scale_factors[
s->channel[
c].scale_factor_idx][*sf_offsets++];
1042 if (!
s->channel[
c].cur_subframe ||
get_bits1(&
s->gb)) {
1044 if (!
s->channel[
c].reuse_sf) {
1047 s->channel[
c].scale_factor_step =
get_bits(&
s->gb, 2) + 1;
1048 val = 45 /
s->channel[
c].scale_factor_step;
1049 for (sf =
s->channel[
c].scale_factors; sf < sf_end; sf++) {
1056 for (
i = 0;
i <
s->num_bands;
i++) {
1067 sign = (
code & 1) - 1;
1068 skip = (
code & 0x3f) >> 1;
1069 }
else if (idx == 1) {
1078 if (
i >=
s->num_bands) {
1080 "invalid scale factor coding\n");
1083 s->channel[
c].scale_factors[
i] += (
val ^ sign) - sign;
1087 s->channel[
c].scale_factor_idx = !
s->channel[
c].scale_factor_idx;
1088 s->channel[
c].table_idx =
s->table_idx;
1089 s->channel[
c].reuse_sf = 1;
1093 s->channel[
c].max_scale_factor =
s->channel[
c].scale_factors[0];
1094 for (sf =
s->channel[
c].scale_factors + 1; sf < sf_end; sf++) {
1095 s->channel[
c].max_scale_factor =
1096 FFMAX(
s->channel[
c].max_scale_factor, *sf);
1111 for (
i = 0;
i <
s->num_chgroups;
i++) {
1112 if (
s->chgroup[
i].transform) {
1114 const int num_channels =
s->chgroup[
i].num_channels;
1115 float** ch_data =
s->chgroup[
i].channel_data;
1116 float** ch_end = ch_data + num_channels;
1117 const int8_t*
tb =
s->chgroup[
i].transform_band;
1121 for (sfb =
s->cur_sfb_offsets;
1122 sfb < s->cur_sfb_offsets +
s->num_bands; sfb++) {
1126 for (y = sfb[0]; y <
FFMIN(sfb[1],
s->subframe_len); y++) {
1127 const float* mat =
s->chgroup[
i].decorrelation_matrix;
1128 const float* data_end =
data + num_channels;
1129 float* data_ptr =
data;
1132 for (ch = ch_data; ch < ch_end; ch++)
1133 *data_ptr++ = (*ch)[y];
1135 for (ch = ch_data; ch < ch_end; ch++) {
1138 while (data_ptr < data_end)
1139 sum += *data_ptr++ * *mat++;
1144 }
else if (
s->nb_channels == 2) {
1145 int len =
FFMIN(sfb[1],
s->subframe_len) - sfb[0];
1146 s->fdsp->vector_fmul_scalar(ch_data[0] + sfb[0],
1147 ch_data[0] + sfb[0],
1149 s->fdsp->vector_fmul_scalar(ch_data[1] + sfb[0],
1150 ch_data[1] + sfb[0],
1165 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1166 int c =
s->channel_indexes_for_cur_subframe[
i];
1168 int winlen =
s->channel[
c].prev_block_len;
1169 float* start =
s->channel[
c].coeffs - (winlen >> 1);
1171 if (
s->subframe_len < winlen) {
1172 start += (winlen -
s->subframe_len) >> 1;
1173 winlen =
s->subframe_len;
1180 s->fdsp->vector_fmul_window(start, start, start + winlen,
1183 s->channel[
c].prev_block_len =
s->subframe_len;
1194 int offset =
s->samples_per_frame;
1195 int subframe_len =
s->samples_per_frame;
1197 int total_samples =
s->samples_per_frame *
s->nb_channels;
1198 int transmit_coeffs = 0;
1199 int cur_subwoofer_cutoff;
1207 for (
i = 0;
i <
s->nb_channels;
i++) {
1208 s->channel[
i].grouped = 0;
1209 if (
offset >
s->channel[
i].decoded_samples) {
1210 offset =
s->channel[
i].decoded_samples;
1212 s->channel[
i].subframe_len[
s->channel[
i].cur_subframe];
1217 "processing subframe with offset %i len %i\n",
offset, subframe_len);
1220 s->channels_for_cur_subframe = 0;
1221 for (
i = 0;
i <
s->nb_channels;
i++) {
1222 const int cur_subframe =
s->channel[
i].cur_subframe;
1224 total_samples -=
s->channel[
i].decoded_samples;
1227 if (
offset ==
s->channel[
i].decoded_samples &&
1228 subframe_len ==
s->channel[
i].subframe_len[cur_subframe]) {
1229 total_samples -=
s->channel[
i].subframe_len[cur_subframe];
1230 s->channel[
i].decoded_samples +=
1231 s->channel[
i].subframe_len[cur_subframe];
1232 s->channel_indexes_for_cur_subframe[
s->channels_for_cur_subframe] =
i;
1233 ++
s->channels_for_cur_subframe;
1240 s->parsed_all_subframes = 1;
1243 ff_dlog(
s->avctx,
"subframe is part of %i channels\n",
1244 s->channels_for_cur_subframe);
1247 s->table_idx =
av_log2(
s->samples_per_frame/subframe_len);
1248 s->num_bands =
s->num_sfb[
s->table_idx];
1249 s->cur_sfb_offsets =
s->sfb_offsets[
s->table_idx];
1250 cur_subwoofer_cutoff =
s->subwoofer_cutoffs[
s->table_idx];
1253 offset +=
s->samples_per_frame >> 1;
1255 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1256 int c =
s->channel_indexes_for_cur_subframe[
i];
1258 s->channel[
c].coeffs = &
s->channel[
c].out[
offset];
1261 s->subframe_len = subframe_len;
1262 s->esc_len =
av_log2(
s->subframe_len - 1) + 1;
1267 if (!(num_fill_bits =
get_bits(&
s->gb, 2))) {
1272 if (num_fill_bits >= 0) {
1293 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1294 int c =
s->channel_indexes_for_cur_subframe[
i];
1295 if ((
s->channel[
c].transmit_coefs =
get_bits1(&
s->gb)))
1296 transmit_coeffs = 1;
1300 if (transmit_coeffs) {
1302 int quant_step = 90 *
s->bits_per_sample >> 4;
1305 if ((
s->transmit_num_vec_coeffs =
get_bits1(&
s->gb))) {
1306 int num_bits =
av_log2((
s->subframe_len + 3)/4) + 1;
1307 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1308 int c =
s->channel_indexes_for_cur_subframe[
i];
1309 int num_vec_coeffs =
get_bits(&
s->gb, num_bits) << 2;
1310 if (num_vec_coeffs >
s->subframe_len) {
1315 s->channel[
c].num_vec_coeffs = num_vec_coeffs;
1318 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1319 int c =
s->channel_indexes_for_cur_subframe[
i];
1320 s->channel[
c].num_vec_coeffs =
s->subframe_len;
1326 if (step == -32 || step == 31) {
1327 const int sign = (step == 31) - 1;
1333 quant_step += ((
quant + step) ^ sign) - sign;
1335 if (quant_step < 0) {
1341 if (
s->channels_for_cur_subframe == 1) {
1342 s->channel[
s->channel_indexes_for_cur_subframe[0]].quant_step = quant_step;
1345 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1346 int c =
s->channel_indexes_for_cur_subframe[
i];
1347 s->channel[
c].quant_step = quant_step;
1350 s->channel[
c].quant_step +=
get_bits(&
s->gb, modifier_len) + 1;
1352 ++
s->channel[
c].quant_step;
1362 ff_dlog(
s->avctx,
"BITSTREAM: subframe header length was %i\n",
1366 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1367 int c =
s->channel_indexes_for_cur_subframe[
i];
1368 if (
s->channel[
c].transmit_coefs &&
1372 memset(
s->channel[
c].coeffs, 0,
1373 sizeof(*
s->channel[
c].coeffs) * subframe_len);
1376 ff_dlog(
s->avctx,
"BITSTREAM: subframe length was %i\n",
1379 if (transmit_coeffs) {
1383 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1384 int c =
s->channel_indexes_for_cur_subframe[
i];
1385 const int* sf =
s->channel[
c].scale_factors;
1388 if (
c ==
s->lfe_channel)
1389 memset(&
s->tmp[cur_subwoofer_cutoff], 0,
sizeof(*
s->tmp) *
1390 (subframe_len - cur_subwoofer_cutoff));
1393 for (
b = 0;
b <
s->num_bands;
b++) {
1394 const int end =
FFMIN(
s->cur_sfb_offsets[
b+1],
s->subframe_len);
1395 const int exp =
s->channel[
c].quant_step -
1396 (
s->channel[
c].max_scale_factor - *sf++) *
1397 s->channel[
c].scale_factor_step;
1399 int start =
s->cur_sfb_offsets[
b];
1400 s->fdsp->vector_fmul_scalar(
s->tmp + start,
1401 s->channel[
c].coeffs + start,
1402 quant, end - start);
1414 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1415 int c =
s->channel_indexes_for_cur_subframe[
i];
1416 if (
s->channel[
c].cur_subframe >=
s->channel[
c].num_subframes) {
1420 ++
s->channel[
c].cur_subframe;
1435 int more_frames = 0;
1443 ff_dlog(
s->avctx,
"decoding frame with length %x\n",
len);
1454 for (
i = 0;
i <
s->nb_channels *
s->nb_channels;
i++)
1460 if (
s->dynamic_range_compression) {
1462 ff_dlog(
s->avctx,
"drc_gain %i\n",
s->drc_gain);
1473 ff_dlog(
s->avctx,
"start skip: %i\n", skip);
1479 ff_dlog(
s->avctx,
"end skip: %i\n", skip);
1484 ff_dlog(
s->avctx,
"BITSTREAM: frame header length was %i\n",
1488 s->parsed_all_subframes = 0;
1489 for (
i = 0;
i <
s->nb_channels;
i++) {
1490 s->channel[
i].decoded_samples = 0;
1491 s->channel[
i].cur_subframe = 0;
1492 s->channel[
i].reuse_sf = 0;
1496 while (!
s->parsed_all_subframes) {
1504 for (
i = 0;
i <
s->nb_channels;
i++)
1506 s->samples_per_frame *
sizeof(*
s->channel[
i].out));
1508 for (
i = 0;
i <
s->nb_channels;
i++) {
1510 memcpy(&
s->channel[
i].out[0],
1511 &
s->channel[
i].out[
s->samples_per_frame],
1512 s->samples_per_frame *
sizeof(*
s->channel[
i].out) >> 1);
1515 if (
s->skip_frame) {
1523 if (
s->len_prefix) {
1527 "frame[%"PRIu32
"] would have to skip %i bits\n",
1577 s->num_saved_bits =
s->frame_offset;
1579 buflen = (
s->num_saved_bits +
len + 7) >> 3;
1591 s->num_saved_bits +=
len;
1618 int buf_size = avpkt->
size;
1619 int num_bits_prev_frame;
1620 int packet_sequence_number;
1636 for (
i = 0;
i <
s->nb_channels;
i++) {
1638 s->samples_per_frame *
sizeof(*
s->channel[
i].out));
1641 s->samples_per_frame *
sizeof(*
s->channel[
i].out) >> 1);
1652 else if (
s->packet_done ||
s->packet_loss) {
1670 s->buf_bit_size = buf_size << 3;
1677 packet_sequence_number =
get_bits(gb, 4);
1682 packet_sequence_number = 0;
1686 num_bits_prev_frame =
get_bits(gb,
s->log2_frame_size);
1694 num_bits_prev_frame);
1698 ((
s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) {
1701 "Packet loss detected! seq %"PRIx8
" vs %x\n",
1702 s->packet_sequence_number, packet_sequence_number);
1704 s->packet_sequence_number = packet_sequence_number;
1706 if (num_bits_prev_frame > 0) {
1708 if (num_bits_prev_frame >= remaining_packet_bits) {
1709 num_bits_prev_frame = remaining_packet_bits;
1716 ff_dlog(avctx,
"accumulated %x bits of frame data\n",
1717 s->num_saved_bits -
s->frame_offset);
1720 if (!
s->packet_loss)
1722 }
else if (
s->num_saved_bits -
s->frame_offset) {
1723 ff_dlog(avctx,
"ignoring %x previously saved bits\n",
1724 s->num_saved_bits -
s->frame_offset);
1727 if (
s->packet_loss) {
1731 s->num_saved_bits = 0;
1737 if (avpkt->
size <
s->next_packet_start) {
1742 s->buf_bit_size = (avpkt->
size -
s->next_packet_start) << 3;
1751 if (!
s->packet_loss)
1753 }
else if (!
s->len_prefix
1773 if (
s->packet_done && !
s->packet_loss &&
1795 int *got_frame_ptr,
AVPacket *avpkt)
1812 int *got_frame_ptr,
AVPacket *avpkt)
1815 int got_stream_frame_ptr = 0;
1819 if (!
s->frames[
s->current_stream]->data[0]) {
1820 s->frames[
s->current_stream]->nb_samples = 512;
1821 if ((ret =
ff_get_buffer(avctx,
s->frames[
s->current_stream], 0)) < 0) {
1826 ret =
decode_packet(avctx, &
s->xma[
s->current_stream],
s->frames[
s->current_stream],
1827 &got_stream_frame_ptr, avpkt);
1829 if (got_stream_frame_ptr &&
s->offset[
s->current_stream] >= 64) {
1830 got_stream_frame_ptr = 0;
1835 if (got_stream_frame_ptr) {
1836 int start_ch =
s->start_channel[
s->current_stream];
1837 memcpy(&
s->samples[start_ch + 0][
s->offset[
s->current_stream] * 512],
1838 s->frames[
s->current_stream]->extended_data[0], 512 * 4);
1839 if (
s->xma[
s->current_stream].nb_channels > 1)
1840 memcpy(&
s->samples[start_ch + 1][
s->offset[
s->current_stream] * 512],
1841 s->frames[
s->current_stream]->extended_data[1], 512 * 4);
1842 s->offset[
s->current_stream]++;
1843 }
else if (ret < 0) {
1844 memset(
s->offset, 0,
sizeof(
s->offset));
1845 s->current_stream = 0;
1852 if (
s->xma[
s->current_stream].packet_done ||
1853 s->xma[
s->current_stream].packet_loss) {
1856 if (
s->xma[
s->current_stream].skip_packets != 0) {
1859 min[0] =
s->xma[0].skip_packets;
1862 for (
i = 1;
i <
s->num_streams;
i++) {
1863 if (
s->xma[
i].skip_packets <
min[0]) {
1864 min[0] =
s->xma[
i].skip_packets;
1869 s->current_stream =
min[1];
1873 for (
i = 0;
i <
s->num_streams;
i++) {
1874 s->xma[
i].skip_packets =
FFMAX(0,
s->xma[
i].skip_packets - 1);
1878 for (
i = 0;
i <
s->num_streams;
i++) {
1889 for (
i = 0;
i <
s->num_streams;
i++) {
1890 int start_ch =
s->start_channel[
i];
1892 if (
s->xma[
i].nb_channels > 1)
1897 memmove(
s->samples[start_ch + 0],
s->samples[start_ch + 0] +
frame->
nb_samples,
s->offset[
i] * 4 * 512);
1898 if (
s->xma[
i].nb_channels > 1)
1899 memmove(
s->samples[start_ch + 1],
s->samples[start_ch + 1] +
frame->
nb_samples,
s->offset[
i] * 4 * 512);
1913 int i, ret, start_channels = 0;
1920 s->num_streams = (avctx->
channels + 1) / 2;
1950 for (
i = 0;
i <
s->num_streams;
i++) {
1958 s->start_channel[
i] = start_channels;
1959 start_channels +=
s->xma[
i].nb_channels;
1961 if (start_channels != avctx->
channels)
1972 for (
i = 0;
i <
s->num_streams;
i++) {
1986 for (
i = 0;
i <
s->nb_channels;
i++)
1987 memset(
s->channel[
i].out, 0,
s->samples_per_frame *
1988 sizeof(*
s->channel[
i].out));
1990 s->skip_packets = 0;
2011 for (
i = 0;
i <
s->num_streams;
i++)
2014 memset(
s->offset, 0,
sizeof(
s->offset));
2015 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 init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
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_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...
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 int ff_thread_once(char *control, void(*routine)(void))
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 av_cold void decode_init_static(void)
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