Go to the documentation of this file.
113 #define WMAPRO_MAX_CHANNELS 8
114 #define MAX_SUBFRAMES 32
116 #define MAX_FRAMESIZE 32768
117 #define XMA_MAX_STREAMS 8
118 #define XMA_MAX_CHANNELS_STREAM 2
119 #define XMA_MAX_CHANNELS (XMA_MAX_STREAMS * XMA_MAX_CHANNELS_STREAM)
121 #define WMAPRO_BLOCK_MIN_BITS 6
122 #define WMAPRO_BLOCK_MAX_BITS 13
123 #define WMAPRO_BLOCK_MIN_SIZE (1 << WMAPRO_BLOCK_MIN_BITS)
124 #define WMAPRO_BLOCK_MAX_SIZE (1 << WMAPRO_BLOCK_MAX_BITS)
125 #define WMAPRO_BLOCK_SIZES (WMAPRO_BLOCK_MAX_BITS - WMAPRO_BLOCK_MIN_BITS + 1)
129 #define SCALEVLCBITS 8
130 #define VEC4MAXDEPTH ((HUFF_VEC4_MAXBITS+VLCBITS-1)/VLCBITS)
131 #define VEC2MAXDEPTH ((HUFF_VEC2_MAXBITS+VLCBITS-1)/VLCBITS)
132 #define VEC1MAXDEPTH ((HUFF_VEC1_MAXBITS+VLCBITS-1)/VLCBITS)
133 #define SCALEMAXDEPTH ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS)
134 #define SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS)
269 #define PRINT(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %d\n", a, b);
270 #define PRINT_HEX(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %"PRIx32"\n", a, b);
272 PRINT(
"ed sample bit depth",
s->bits_per_sample);
273 PRINT_HEX(
"ed decode flags",
s->decode_flags);
274 PRINT(
"samples per frame",
s->samples_per_frame);
275 PRINT(
"log2 frame size",
s->log2_frame_size);
276 PRINT(
"max num subframes",
s->max_num_subframes);
277 PRINT(
"len prefix",
s->len_prefix);
278 PRINT(
"num channels",
s->nb_channels);
324 static VLCElem vlc_buf[2108 + 3912];
352 for (
int i = 0;
i < 33;
i++)
368 unsigned int channel_mask;
370 int log2_max_num_subframes;
371 int num_possible_block_sizes;
394 s->decode_flags = 0x10d6;
395 s->bits_per_sample = 16;
402 s->decode_flags = 0x10d6;
403 s->bits_per_sample = 16;
405 s->nb_channels = edata_ptr[32 + ((edata_ptr[0]==3)?0:8) + 4*num_stream + 0];
407 s->decode_flags = 0x10d6;
408 s->bits_per_sample = 16;
410 s->nb_channels = edata_ptr[8 + 20*num_stream + 17];
412 s->decode_flags =
AV_RL16(edata_ptr+14);
413 channel_mask =
AV_RL32(edata_ptr+2);
414 s->bits_per_sample =
AV_RL16(edata_ptr);
417 if (
s->bits_per_sample > 32 ||
s->bits_per_sample < 1) {
428 if (
s->log2_frame_size > 25) {
437 s->len_prefix = (
s->decode_flags & 0x40);
446 s->samples_per_frame = 1 <<
bits;
448 s->samples_per_frame = 512;
452 log2_max_num_subframes = ((
s->decode_flags & 0x38) >> 3);
453 s->max_num_subframes = 1 << log2_max_num_subframes;
454 if (
s->max_num_subframes == 16 ||
s->max_num_subframes == 4)
455 s->max_subframe_len_bit = 1;
456 s->subframe_len_bits =
av_log2(log2_max_num_subframes) + 1;
458 num_possible_block_sizes = log2_max_num_subframes + 1;
459 s->min_samples_per_subframe =
s->samples_per_frame /
s->max_num_subframes;
460 s->dynamic_range_compression = (
s->decode_flags & 0x80);
464 s->max_num_subframes);
470 s->min_samples_per_subframe);
474 if (
s->avctx->sample_rate <= 0) {
479 if (
s->nb_channels <= 0) {
494 for (
i = 0;
i <
s->nb_channels;
i++)
495 s->channel[
i].prev_block_len =
s->samples_per_frame;
500 if (channel_mask & 8) {
503 if (channel_mask &
mask)
510 for (
i = 0;
i < num_possible_block_sizes;
i++) {
511 int subframe_len =
s->samples_per_frame >>
i;
516 s->sfb_offsets[
i][0] = 0;
518 for (x = 0; x <
MAX_BANDS-1 &&
s->sfb_offsets[
i][band - 1] < subframe_len; x++) {
521 if (
offset >
s->sfb_offsets[
i][band - 1])
524 if (
offset >= subframe_len)
527 s->sfb_offsets[
i][band - 1] = subframe_len;
528 s->num_sfb[
i] = band - 1;
529 if (
s->num_sfb[
i] <= 0) {
541 for (
i = 0;
i < num_possible_block_sizes;
i++) {
543 for (
b = 0;
b <
s->num_sfb[
i];
b++) {
546 +
s->sfb_offsets[
i][
b + 1] - 1) <<
i) >> 1;
547 for (x = 0; x < num_possible_block_sizes; x++) {
549 while (
s->sfb_offsets[x][v + 1] << x <
offset) {
553 s->sf_offsets[
i][x][
b] = v;
565 / (1ll << (
s->bits_per_sample - 1));
579 for (
i = 0;
i < num_possible_block_sizes;
i++) {
580 int block_size =
s->samples_per_frame >>
i;
581 int cutoff = (440*block_size + 3LL * (
s->avctx->sample_rate >> 1) - 1)
582 /
s->avctx->sample_rate;
583 s->subwoofer_cutoffs[
i] =
av_clip(cutoff, 4, block_size);
622 int frame_len_shift = 0;
626 if (
offset ==
s->samples_per_frame -
s->min_samples_per_subframe)
627 return s->min_samples_per_subframe;
633 if (
s->max_subframe_len_bit) {
635 frame_len_shift = 1 +
get_bits(&
s->gb,
s->subframe_len_bits-1);
637 frame_len_shift =
get_bits(&
s->gb,
s->subframe_len_bits);
639 subframe_len =
s->samples_per_frame >> frame_len_shift;
642 if (subframe_len < s->min_samples_per_subframe ||
643 subframe_len >
s->samples_per_frame) {
675 int channels_for_cur_subframe =
s->nb_channels;
676 int fixed_channel_layout = 0;
677 int min_channel_len = 0;
687 for (
c = 0;
c <
s->nb_channels;
c++)
688 s->channel[
c].num_subframes = 0;
691 fixed_channel_layout = 1;
698 for (
c = 0;
c <
s->nb_channels;
c++) {
699 if (num_samples[
c] == min_channel_len) {
700 if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
701 (min_channel_len ==
s->samples_per_frame -
s->min_samples_per_subframe))
702 contains_subframe[
c] = 1;
706 contains_subframe[
c] = 0;
714 min_channel_len += subframe_len;
715 for (
c = 0;
c <
s->nb_channels;
c++) {
718 if (contains_subframe[
c]) {
721 "broken frame: num subframes > 31\n");
725 num_samples[
c] += subframe_len;
727 if (num_samples[
c] >
s->samples_per_frame) {
729 "channel len > samples_per_frame\n");
732 }
else if (num_samples[
c] <= min_channel_len) {
733 if (num_samples[
c] < min_channel_len) {
734 channels_for_cur_subframe = 0;
735 min_channel_len = num_samples[
c];
737 ++channels_for_cur_subframe;
740 }
while (min_channel_len < s->samples_per_frame);
742 for (
c = 0;
c <
s->nb_channels;
c++) {
745 for (
i = 0;
i <
s->channel[
c].num_subframes;
i++) {
746 ff_dlog(
s->avctx,
"frame[%"PRIu32
"] channel[%i] subframe[%i]"
747 " len %i\n",
s->frame_num,
c,
i,
748 s->channel[
c].subframe_len[
i]);
749 s->channel[
c].subframe_offset[
i] =
offset;
780 for (x = 0; x <
i; x++) {
782 for (y = 0; y <
i + 1; y++) {
785 int n = rotation_offset[
offset + x];
791 cosv =
sin64[32 - n];
793 sinv =
sin64[64 - n];
794 cosv = -
sin64[n - 32];
798 (v1 * sinv) - (v2 * cosv);
800 (v1 * cosv) + (v2 * sinv);
822 if (
s->nb_channels > 1) {
823 int remaining_channels =
s->channels_for_cur_subframe;
827 "Channel transform bit");
831 for (
s->num_chgroups = 0; remaining_channels &&
832 s->num_chgroups <
s->channels_for_cur_subframe;
s->num_chgroups++) {
839 if (remaining_channels > 2) {
840 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
841 int channel_idx =
s->channel_indexes_for_cur_subframe[
i];
842 if (!
s->channel[channel_idx].grouped
845 s->channel[channel_idx].grouped = 1;
846 *channel_data++ =
s->channel[channel_idx].coeffs;
851 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
852 int channel_idx =
s->channel_indexes_for_cur_subframe[
i];
853 if (!
s->channel[channel_idx].grouped)
854 *channel_data++ =
s->channel[channel_idx].coeffs;
855 s->channel[channel_idx].grouped = 1;
864 "Unknown channel transform type");
869 if (
s->nb_channels == 2) {
891 "Coupled channels > 6");
907 for (
i = 0;
i <
s->num_bands;
i++) {
931 static const uint32_t fval_tab[16] = {
932 0x00000000, 0x3f800000, 0x40000000, 0x40400000,
933 0x40800000, 0x40a00000, 0x40c00000, 0x40e00000,
934 0x41000000, 0x41100000, 0x41200000, 0x41300000,
935 0x41400000, 0x41500000, 0x41600000, 0x41700000,
946 ff_dlog(
s->avctx,
"decode coefficients for channel %i\n",
c);
961 while ((
s->transmit_num_vec_coeffs || !rl_mode) &&
970 for (
i = 0;
i < 4;
i += 2) {
983 vals[
i] = fval_tab[idx >> 4 ];
984 vals[
i+1] = fval_tab[idx & 0xF];
988 vals[0] = fval_tab[ idx >> 12 ];
989 vals[1] = fval_tab[(idx >> 8) & 0xF];
990 vals[2] = fval_tab[(idx >> 4) & 0xF];
991 vals[3] = fval_tab[ idx & 0xF];
995 for (
i = 0;
i < 4;
i++) {
1001 ci->
coeffs[cur_coeff] = 0;
1004 rl_mode |= (++num_zeros >
s->subframe_len >> 8);
1011 if (cur_coeff < s->subframe_len) {
1014 memset(&ci->
coeffs[cur_coeff], 0,
1015 sizeof(*ci->
coeffs) * (
s->subframe_len - cur_coeff));
1018 cur_coeff,
s->subframe_len,
1019 s->subframe_len,
s->esc_len, 0);
1040 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1041 int c =
s->channel_indexes_for_cur_subframe[
i];
1044 s->channel[
c].scale_factors =
s->channel[
c].saved_scale_factors[!
s->channel[
c].scale_factor_idx];
1045 sf_end =
s->channel[
c].scale_factors +
s->num_bands;
1052 if (
s->channel[
c].reuse_sf) {
1053 const int8_t* sf_offsets =
s->sf_offsets[
s->table_idx][
s->channel[
c].table_idx];
1055 for (
b = 0;
b <
s->num_bands;
b++)
1056 s->channel[
c].scale_factors[
b] =
1057 s->channel[
c].saved_scale_factors[
s->channel[
c].scale_factor_idx][*sf_offsets++];
1060 if (!
s->channel[
c].cur_subframe ||
get_bits1(&
s->gb)) {
1062 if (!
s->channel[
c].reuse_sf) {
1065 s->channel[
c].scale_factor_step =
get_bits(&
s->gb, 2) + 1;
1066 val = 45 /
s->channel[
c].scale_factor_step;
1067 for (sf =
s->channel[
c].scale_factors; sf < sf_end; sf++) {
1074 for (
i = 0;
i <
s->num_bands;
i++) {
1085 sign = (
code & 1) - 1;
1087 }
else if (idx == 1) {
1096 if (
i >=
s->num_bands) {
1098 "invalid scale factor coding\n");
1101 s->channel[
c].scale_factors[
i] += (
val ^ sign) - sign;
1105 s->channel[
c].scale_factor_idx = !
s->channel[
c].scale_factor_idx;
1106 s->channel[
c].table_idx =
s->table_idx;
1107 s->channel[
c].reuse_sf = 1;
1111 s->channel[
c].max_scale_factor =
s->channel[
c].scale_factors[0];
1112 for (sf =
s->channel[
c].scale_factors + 1; sf < sf_end; sf++) {
1113 s->channel[
c].max_scale_factor =
1114 FFMAX(
s->channel[
c].max_scale_factor, *sf);
1129 for (
i = 0;
i <
s->num_chgroups;
i++) {
1130 if (
s->chgroup[
i].transform) {
1132 const int num_channels =
s->chgroup[
i].num_channels;
1133 float** ch_data =
s->chgroup[
i].channel_data;
1134 float** ch_end = ch_data + num_channels;
1135 const int8_t* tb =
s->chgroup[
i].transform_band;
1139 for (sfb =
s->cur_sfb_offsets;
1140 sfb < s->cur_sfb_offsets +
s->num_bands; sfb++) {
1144 for (y = sfb[0]; y <
FFMIN(sfb[1],
s->subframe_len); y++) {
1145 const float* mat =
s->chgroup[
i].decorrelation_matrix;
1146 const float* data_end =
data + num_channels;
1147 float* data_ptr =
data;
1150 for (ch = ch_data; ch < ch_end; ch++)
1151 *data_ptr++ = (*ch)[y];
1153 for (ch = ch_data; ch < ch_end; ch++) {
1156 while (data_ptr < data_end)
1157 sum += *data_ptr++ * *mat++;
1162 }
else if (
s->nb_channels == 2) {
1163 int len =
FFMIN(sfb[1],
s->subframe_len) - sfb[0];
1164 s->fdsp->vector_fmul_scalar(ch_data[0] + sfb[0],
1165 ch_data[0] + sfb[0],
1167 s->fdsp->vector_fmul_scalar(ch_data[1] + sfb[0],
1168 ch_data[1] + sfb[0],
1183 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1184 int c =
s->channel_indexes_for_cur_subframe[
i];
1186 int winlen =
s->channel[
c].prev_block_len;
1187 float* start =
s->channel[
c].coeffs - (winlen >> 1);
1189 if (
s->subframe_len < winlen) {
1190 start += (winlen -
s->subframe_len) >> 1;
1191 winlen =
s->subframe_len;
1198 s->fdsp->vector_fmul_window(start, start, start + winlen,
1201 s->channel[
c].prev_block_len =
s->subframe_len;
1212 int offset =
s->samples_per_frame;
1213 int subframe_len =
s->samples_per_frame;
1215 int total_samples =
s->samples_per_frame *
s->nb_channels;
1216 int transmit_coeffs = 0;
1217 int cur_subwoofer_cutoff;
1225 for (
i = 0;
i <
s->nb_channels;
i++) {
1226 s->channel[
i].grouped = 0;
1227 if (
offset >
s->channel[
i].decoded_samples) {
1228 offset =
s->channel[
i].decoded_samples;
1230 s->channel[
i].subframe_len[
s->channel[
i].cur_subframe];
1235 "processing subframe with offset %i len %i\n",
offset, subframe_len);
1238 s->channels_for_cur_subframe = 0;
1239 for (
i = 0;
i <
s->nb_channels;
i++) {
1240 const int cur_subframe =
s->channel[
i].cur_subframe;
1242 total_samples -=
s->channel[
i].decoded_samples;
1245 if (
offset ==
s->channel[
i].decoded_samples &&
1246 subframe_len ==
s->channel[
i].subframe_len[cur_subframe]) {
1247 total_samples -=
s->channel[
i].subframe_len[cur_subframe];
1248 s->channel[
i].decoded_samples +=
1249 s->channel[
i].subframe_len[cur_subframe];
1250 s->channel_indexes_for_cur_subframe[
s->channels_for_cur_subframe] =
i;
1251 ++
s->channels_for_cur_subframe;
1258 s->parsed_all_subframes = 1;
1261 ff_dlog(
s->avctx,
"subframe is part of %i channels\n",
1262 s->channels_for_cur_subframe);
1265 s->table_idx =
av_log2(
s->samples_per_frame/subframe_len);
1266 s->num_bands =
s->num_sfb[
s->table_idx];
1267 s->cur_sfb_offsets =
s->sfb_offsets[
s->table_idx];
1268 cur_subwoofer_cutoff =
s->subwoofer_cutoffs[
s->table_idx];
1271 offset +=
s->samples_per_frame >> 1;
1273 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1274 int c =
s->channel_indexes_for_cur_subframe[
i];
1276 s->channel[
c].coeffs = &
s->channel[
c].out[
offset];
1279 s->subframe_len = subframe_len;
1280 s->esc_len =
av_log2(
s->subframe_len - 1) + 1;
1285 if (!(num_fill_bits =
get_bits(&
s->gb, 2))) {
1290 if (num_fill_bits >= 0) {
1311 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1312 int c =
s->channel_indexes_for_cur_subframe[
i];
1313 if ((
s->channel[
c].transmit_coefs =
get_bits1(&
s->gb)))
1314 transmit_coeffs = 1;
1318 if (transmit_coeffs) {
1320 int quant_step = 90 *
s->bits_per_sample >> 4;
1323 if ((
s->transmit_num_vec_coeffs =
get_bits1(&
s->gb))) {
1324 int num_bits =
av_log2((
s->subframe_len + 3)/4) + 1;
1325 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1326 int c =
s->channel_indexes_for_cur_subframe[
i];
1327 int num_vec_coeffs =
get_bits(&
s->gb, num_bits) << 2;
1328 if (num_vec_coeffs >
s->subframe_len) {
1333 s->channel[
c].num_vec_coeffs = num_vec_coeffs;
1336 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1337 int c =
s->channel_indexes_for_cur_subframe[
i];
1338 s->channel[
c].num_vec_coeffs =
s->subframe_len;
1345 const int sign = (
step == 31) - 1;
1351 quant_step += ((
quant +
step) ^ sign) - sign;
1353 if (quant_step < 0) {
1359 if (
s->channels_for_cur_subframe == 1) {
1360 s->channel[
s->channel_indexes_for_cur_subframe[0]].quant_step = quant_step;
1363 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1364 int c =
s->channel_indexes_for_cur_subframe[
i];
1365 s->channel[
c].quant_step = quant_step;
1368 s->channel[
c].quant_step +=
get_bits(&
s->gb, modifier_len) + 1;
1370 ++
s->channel[
c].quant_step;
1380 ff_dlog(
s->avctx,
"BITSTREAM: subframe header length was %i\n",
1384 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1385 int c =
s->channel_indexes_for_cur_subframe[
i];
1386 if (
s->channel[
c].transmit_coefs &&
1390 memset(
s->channel[
c].coeffs, 0,
1391 sizeof(*
s->channel[
c].coeffs) * subframe_len);
1394 ff_dlog(
s->avctx,
"BITSTREAM: subframe length was %i\n",
1397 if (transmit_coeffs) {
1402 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1403 int c =
s->channel_indexes_for_cur_subframe[
i];
1404 const int* sf =
s->channel[
c].scale_factors;
1407 if (
c ==
s->lfe_channel)
1408 memset(&
s->tmp[cur_subwoofer_cutoff], 0,
sizeof(*
s->tmp) *
1409 (subframe_len - cur_subwoofer_cutoff));
1412 for (
b = 0;
b <
s->num_bands;
b++) {
1413 const int end =
FFMIN(
s->cur_sfb_offsets[
b+1],
s->subframe_len);
1414 const int exp =
s->channel[
c].quant_step -
1415 (
s->channel[
c].max_scale_factor - *sf++) *
1416 s->channel[
c].scale_factor_step;
1418 int start =
s->cur_sfb_offsets[
b];
1419 s->fdsp->vector_fmul_scalar(
s->tmp + start,
1420 s->channel[
c].coeffs + start,
1421 quant, end - start);
1425 tx_fn(tx,
s->channel[
c].coeffs,
s->tmp,
sizeof(
float));
1433 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1434 int c =
s->channel_indexes_for_cur_subframe[
i];
1435 if (
s->channel[
c].cur_subframe >=
s->channel[
c].num_subframes) {
1439 ++
s->channel[
c].cur_subframe;
1454 int more_frames = 0;
1462 ff_dlog(
s->avctx,
"decoding frame with length %x\n",
len);
1473 for (
i = 0;
i <
s->nb_channels *
s->nb_channels;
i++)
1479 if (
s->dynamic_range_compression) {
1481 ff_dlog(
s->avctx,
"drc_gain %i\n",
s->drc_gain);
1491 s->trim_start =
s->trim_end = 0;
1494 ff_dlog(
s->avctx,
"BITSTREAM: frame header length was %i\n",
1498 s->parsed_all_subframes = 0;
1499 for (
i = 0;
i <
s->nb_channels;
i++) {
1500 s->channel[
i].decoded_samples = 0;
1501 s->channel[
i].cur_subframe = 0;
1502 s->channel[
i].reuse_sf = 0;
1506 while (!
s->parsed_all_subframes) {
1514 for (
i = 0;
i <
s->nb_channels;
i++)
1515 memcpy(
frame->extended_data[
i],
s->channel[
i].out,
1516 s->samples_per_frame *
sizeof(*
s->channel[
i].out));
1518 for (
i = 0;
i <
s->nb_channels;
i++) {
1520 memcpy(&
s->channel[
i].out[0],
1521 &
s->channel[
i].out[
s->samples_per_frame],
1522 s->samples_per_frame *
sizeof(*
s->channel[
i].out) >> 1);
1525 if (
s->skip_frame) {
1533 if (
s->len_prefix) {
1537 "frame[%"PRIu32
"] would have to skip %i bits\n",
1587 s->num_saved_bits =
s->frame_offset;
1589 buflen = (
s->num_saved_bits +
len + 7) >> 3;
1601 s->num_saved_bits +=
len;
1627 const uint8_t* buf = avpkt->
data;
1628 int buf_size = avpkt->
size;
1629 int num_bits_prev_frame;
1630 int packet_sequence_number;
1645 for (
i = 0;
i <
s->nb_channels;
i++) {
1646 memset(
frame->extended_data[
i], 0,
1647 s->samples_per_frame *
sizeof(*
s->channel[
i].out));
1649 memcpy(
frame->extended_data[
i],
s->channel[
i].out,
1650 s->samples_per_frame *
sizeof(*
s->channel[
i].out) >> 1);
1658 else if (
s->packet_done ||
s->packet_loss) {
1676 s->buf_bit_size = buf_size << 3;
1683 packet_sequence_number =
get_bits(gb, 4);
1687 ff_dlog(avctx,
"packet[%"PRId64
"]: number of frames %d\n", avctx->
frame_num, num_frames);
1688 packet_sequence_number = 0;
1692 num_bits_prev_frame =
get_bits(gb,
s->log2_frame_size);
1696 ff_dlog(avctx,
"packet[%"PRId64
"]: skip packets %d\n", avctx->
frame_num,
s->skip_packets);
1700 num_bits_prev_frame);
1704 ((
s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) {
1707 "Packet loss detected! seq %"PRIx8
" vs %x\n",
1708 s->packet_sequence_number, packet_sequence_number);
1710 s->packet_sequence_number = packet_sequence_number;
1712 if (num_bits_prev_frame > 0) {
1714 if (num_bits_prev_frame >= remaining_packet_bits) {
1715 num_bits_prev_frame = remaining_packet_bits;
1722 ff_dlog(avctx,
"accumulated %x bits of frame data\n",
1723 s->num_saved_bits -
s->frame_offset);
1726 if (!
s->packet_loss)
1728 }
else if (
s->num_saved_bits -
s->frame_offset) {
1729 ff_dlog(avctx,
"ignoring %x previously saved bits\n",
1730 s->num_saved_bits -
s->frame_offset);
1733 if (
s->packet_loss) {
1737 s->num_saved_bits = 0;
1743 if (avpkt->
size <
s->next_packet_start) {
1748 s->buf_bit_size = (avpkt->
size -
s->next_packet_start) << 3;
1757 if (!
s->packet_loss)
1759 }
else if (!
s->len_prefix
1779 if (
s->packet_done && !
s->packet_loss &&
1791 if (
s->trim_start <
frame->nb_samples) {
1792 for (
int ch = 0; ch <
frame->ch_layout.nb_channels; ch++)
1793 frame->extended_data[ch] +=
s->trim_start * 4;
1795 frame->nb_samples -=
s->trim_start;
1804 if (
s->trim_end <
frame->nb_samples) {
1805 frame->nb_samples -=
s->trim_end;
1824 int *got_frame_ptr,
AVPacket *avpkt)
1830 frame->nb_samples =
s->samples_per_frame;
1840 int *got_frame_ptr,
AVPacket *avpkt)
1843 int got_stream_frame_ptr = 0;
1844 int i,
ret = 0, eof = 0;
1846 if (!
s->frames[
s->current_stream]->data[0]) {
1848 s->frames[
s->current_stream]->nb_samples = 512;
1851 }
else if (
s->frames[
s->current_stream]->nb_samples != 512) {
1854 s->frames[
s->current_stream]->nb_samples = 512;
1859 if (!
s->xma[
s->current_stream].eof_done) {
1861 &got_stream_frame_ptr, avpkt);
1867 for (
i = 0;
i <
s->num_streams;
i++) {
1868 if (!
s->xma[
i].eof_done &&
s->frames[
i]->data[0]) {
1870 &got_stream_frame_ptr, avpkt);
1873 eof &=
s->xma[
i].eof_done;
1877 if (
s->xma[0].trim_start)
1878 s->trim_start =
s->xma[0].trim_start;
1879 if (
s->xma[0].trim_end)
1880 s->trim_end =
s->xma[0].trim_end;
1883 if (got_stream_frame_ptr) {
1884 const int nb_samples =
s->frames[
s->current_stream]->nb_samples;
1885 void *
left[1] = {
s->frames[
s->current_stream]->extended_data[0] };
1886 void *right[1] = {
s->frames[
s->current_stream]->extended_data[1] };
1889 if (
s->xma[
s->current_stream].nb_channels > 1)
1891 }
else if (
ret < 0) {
1892 s->current_stream = 0;
1899 if (
s->xma[
s->current_stream].packet_done ||
1900 s->xma[
s->current_stream].packet_loss) {
1901 int nb_samples = INT_MAX;
1904 if (
s->xma[
s->current_stream].skip_packets != 0) {
1907 min[0] =
s->xma[0].skip_packets;
1910 for (
i = 1;
i <
s->num_streams;
i++) {
1911 if (
s->xma[
i].skip_packets <
min[0]) {
1912 min[0] =
s->xma[
i].skip_packets;
1917 s->current_stream =
min[1];
1921 for (
i = 0;
i <
s->num_streams;
i++) {
1922 s->xma[
i].skip_packets =
FFMAX(0,
s->xma[
i].skip_packets - 1);
1926 if (!eof && avpkt->
size)
1927 nb_samples -=
FFMIN(nb_samples, 4096);
1930 if ((nb_samples > 0 || eof || !avpkt->
size) && !
s->flushed) {
1934 nb_samples -=
av_clip(
s->trim_end +
s->trim_start - 128 - 64, 0, nb_samples);
1938 frame->nb_samples = nb_samples;
1942 for (
i = 0;
i <
s->num_streams;
i++) {
1943 const int start_ch =
s->start_channel[
i];
1944 void *
left[1] = {
frame->extended_data[start_ch + 0] };
1947 if (
s->xma[
i].nb_channels > 1) {
1948 void *right[1] = {
frame->extended_data[start_ch + 1] };
1953 *got_frame_ptr = nb_samples > 0;
1963 int i,
ret, start_channels = 0;
2006 for (
i = 0;
i <
s->num_streams;
i++) {
2014 s->start_channel[
i] = start_channels;
2015 start_channels +=
s->xma[
i].nb_channels;
2023 if (!
s->samples[0][
i] || !
s->samples[1][
i])
2035 for (
i = 0;
i <
s->num_streams;
i++) {
2054 for (
i = 0;
i <
s->nb_channels;
i++)
2055 memset(
s->channel[
i].out, 0,
s->samples_per_frame *
2056 sizeof(*
s->channel[
i].out));
2058 s->skip_packets = 0;
2084 for (
i = 0;
i <
s->num_streams;
i++)
2087 s->current_stream = 0;
2104 #if FF_API_SUBFRAMES
2105 AV_CODEC_CAP_SUBFRAMES |
2125 #if FF_API_SUBFRAMES
2126 AV_CODEC_CAP_SUBFRAMES |
2145 #if FF_API_SUBFRAMES
2146 AV_CODEC_CAP_SUBFRAMES |
uint16_t num_vec_coeffs
number of vector coded coefficients
void av_audio_fifo_free(AVAudioFifo *af)
Free an AVAudioFifo.
static const float *const default_decorrelation[]
default decorrelation matrix offsets
static av_cold int xma_decode_init(AVCodecContext *avctx)
int subframe_offset
subframe offset in the bit reservoir
@ AV_SAMPLE_FMT_FLTP
float, planar
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
static av_always_inline double ff_exp10(double x)
Compute 10^x for floating point values.
#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)
static int decode_subframe(WMAProDecodeCtx *s)
Decode a single subframe (block).
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
GetBitContext gb
bitstream reader context
uint16_t samples_per_frame
number of samples to output
SINETABLE_CONST float *const ff_sine_windows[]
int8_t scale_factor_step
scaling step for the current subframe
static const uint8_t vec4_lens[HUFF_VEC4_SIZE]
static void wmapro_window(WMAProDecodeCtx *s)
Apply sine window and reconstruct the output buffer.
#define WMAPRO_BLOCK_MAX_BITS
log2 of max block size
uint16_t min_samples_per_subframe
int sample_rate
samples per second
uint16_t subframe_offset[MAX_SUBFRAMES]
subframe positions in the current frame
static int decode_tilehdr(WMAProDecodeCtx *s)
Decode how the data in the frame is split into subframes.
int av_audio_fifo_write(AVAudioFifo *af, void *const *data, int nb_samples)
Write data to an AVAudioFifo.
static VLCElem vec2_vlc[562]
2 coefficients per symbol
static const uint8_t vec2_table[HUFF_VEC2_SIZE][2]
int skip_samples
Number of audio samples to skip at the start of the next decoded frame.
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static uint8_t * append(uint8_t *buf, const uint8_t *src, int size)
static int get_bits_count(const GetBitContext *s)
static const uint16_t coef0_run[HUFF_COEF0_SIZE]
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVCodecContext * avctx
codec context for av_log
This structure describes decoded (raw) audio or video data.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But a word about which is also called distortion Distortion can be quantified by almost any quality measurement one chooses the sum of squared differences is used but more complex methods that consider psychovisual effects can be used as well It makes no difference in this discussion First step
static av_cold int wmapro_decode_init(AVCodecContext *avctx)
Initialize the decoder.
static void flush(WMAProDecodeCtx *s)
static av_cold int get_rate(AVCodecContext *avctx)
#define WMAPRO_BLOCK_MIN_SIZE
minimum block size
static int decode_scale_factors(WMAProDecodeCtx *s)
Extract scale factors from the bitstream.
int ff_wma_run_level_decode(AVCodecContext *avctx, GetBitContext *gb, const VLCElem *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.
#define WMAPRO_BLOCK_MAX_SIZE
maximum block size
enum AVChannelOrder order
Channel order used in this layout.
static av_always_inline uint32_t av_float2int(float f)
Reinterpret a float as a 32-bit integer.
static VLCElem vec4_vlc[604]
4 coefficients per symbol
int nb_channels
Number of channels in this layout.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
PutBitContext pb
context for filling the frame_data buffer
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
static av_cold int decode_init(WMAProDecodeCtx *s, AVCodecContext *avctx, int num_stream)
Initialize the decoder.
static av_cold int decode_end(WMAProDecodeCtx *s)
Uninitialize the decoder and free all resources.
static const VLCElem * coef_vlc[2]
coefficient run length vlc codes
int16_t sfb_offsets[WMAPRO_BLOCK_SIZES][MAX_BANDS]
scale factor band offsets (multiples of 4)
static void skip_bits(GetBitContext *s, int n)
static float sin64[33]
sine table for decorrelation
#define HUFF_SCALE_RL_SIZE
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
Copy the content of src to the bitstream.
static SDL_Window * window
Context for an Audio FIFO Buffer.
AVCodec p
The public AVCodec.
static VLCElem vec1_vlc[562]
1 coefficient per symbol
AVChannelLayout ch_layout
Audio channel layout.
static const uint16_t coef0_syms[HUFF_COEF0_SIZE]
static av_cold int wmapro_decode_end(AVCodecContext *avctx)
uint8_t num_chgroups
number of channel groups
uint8_t drc_gain
gain for the DRC tool
static int put_bits_left(PutBitContext *s)
int flags
AV_CODEC_FLAG_*.
static double val(void *priv, double ch)
int8_t num_bands
number of scale factor bands
float tmp[WMAPRO_BLOCK_MAX_SIZE]
IMDCT output buffer.
int8_t sf_offsets[WMAPRO_BLOCK_SIZES][WMAPRO_BLOCK_SIZES][MAX_BANDS]
scale factor resample matrix
WMAProChannelGrp chgroup[WMAPRO_MAX_CHANNELS]
channel group information
int max_scale_factor
maximum scale factor for the current subframe
int quant_step
quantization step for the current subframe
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
uint8_t table_idx
index in sf_offsets for the scale factor reference block
static int decode_subframe_length(WMAProDecodeCtx *s, int offset)
Decode the subframe length.
static VLCElem sf_vlc[616]
scale factor DPCM vlc
static const uint8_t quant[64]
float out[WMAPRO_BLOCK_MAX_SIZE+WMAPRO_BLOCK_MAX_SIZE/2]
output buffer
static int ff_thread_once(char *control, void(*routine)(void))
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int buf_bit_size
buffer size in bits
#define FF_ARRAY_ELEMS(a)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
const FFCodec ff_xma1_decoder
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
uint8_t subframe_len_bits
number of bits used for the subframe length
For static VLCs, the number of bits can often be hardcoded at each get_vlc2() callsite.
static void decode_decorrelation_matrix(WMAProDecodeCtx *s, WMAProChannelGrp *chgroup)
Calculate a decorrelation matrix from the bitstream parameters.
frame specific decoder context for a single channel
@ AV_TX_FLOAT_MDCT
Standard MDCT with a sample data type of float, double or int32_t, respecively.
int * scale_factors
pointer to the scale factor values used for decoding
#define FF_CODEC_DECODE_CB(func)
int8_t skip_frame
skip output step
int16_t subwoofer_cutoffs[WMAPRO_BLOCK_SIZES]
subwoofer cutoff values
uint32_t decode_flags
used compression features
const FFCodec ff_xma2_decoder
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
uint8_t packet_loss
set in case of bitstream error
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.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static void inverse_channel_transform(WMAProDecodeCtx *s)
Reconstruct the individual channel data.
static int get_sbits(GetBitContext *s, int n)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_RL16
WMAProDecodeCtx xma[XMA_MAX_STREAMS]
#define CODEC_LONG_NAME(str)
static int decode_coeffs(WMAProDecodeCtx *s, int c)
Extract the coefficients from the bitstream.
#define XMA_MAX_CHANNELS_STREAM
int16_t prev_block_len
length of the previous block
int8_t transmit_num_vec_coeffs
number of vector coded coefficients is part of the bitstream
int8_t channel_indexes_for_cur_subframe[WMAPRO_MAX_CHANNELS]
uint8_t grouped
channel is part of a group
int start_channel[XMA_MAX_STREAMS]
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
static void wmapro_flush(AVCodecContext *avctx)
Clear decoder buffers (for seeking).
const float * windows[WMAPRO_BLOCK_SIZES]
windows for the different block sizes
AVAudioFifo * av_audio_fifo_alloc(enum AVSampleFormat sample_fmt, int channels, int nb_samples)
Allocate an AVAudioFifo.
int8_t transform
transform on / off
static const uint8_t vec1_table[HUFF_VEC1_SIZE][2]
struct AVCodecInternal * internal
Private context used for internal data.
static unsigned int get_bits1(GetBitContext *s)
int8_t nb_channels
number of channels in stream (XMA1/2)
static void xma_flush(AVCodecContext *avctx)
#define WMAPRO_MAX_CHANNELS
current decoder limitations
channel group for channel transformations
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
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 const uint8_t scale_rl_level[HUFF_SCALE_RL_SIZE]
uint8_t eof_done
set when EOF reached and extra subframe is written (XMA1/2)
uint32_t frame_num
current frame number (not used for decoding)
static int decode_packet(AVCodecContext *avctx, WMAProDecodeCtx *s, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
float * coeffs
pointer to the subframe decode buffer
#define DECLARE_ALIGNED(n, t, v)
uint8_t len_prefix
frame is prefixed with its length
static const uint16_t critical_freq[]
frequencies to divide the frequency spectrum into scale factor bands
static const uint8_t scale_table[]
#define WMAPRO_BLOCK_SIZES
possible block sizes
enum AVSampleFormat sample_fmt
audio sample format
uint8_t frame_data[MAX_FRAMESIZE+AV_INPUT_BUFFER_PADDING_SIZE]
compressed frame data
int av_audio_fifo_read(AVAudioFifo *af, void *const *data, int nb_samples)
Read data from an AVAudioFifo.
static av_cold void decode_init_static(void)
int8_t scale_factor_idx
index for the transmitted scale factor values (used for resampling)
#define MAX_SUBFRAMES
max number of subframes per channel
AVAudioFifo * samples[2][XMA_MAX_STREAMS]
static const uint8_t *BS_FUNC() align(BSCTX *bc)
Skip bits to a byte boundary.
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 offset
int av_audio_fifo_size(AVAudioFifo *af)
Get the current number of samples in the AVAudioFifo available for reading.
int8_t transform_band[MAX_BANDS]
controls if the transform is enabled for a certain band
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
uint8_t max_num_subframes
int8_t reuse_sf
share scale factors between subframes
int next_packet_start
start offset of the next wma packet in the demuxer packet
#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 int put_bits_count(PutBitContext *s)
uint8_t cur_subframe
current subframe number
static const uint8_t scale_rl_run[HUFF_SCALE_RL_SIZE]
uint16_t decoded_samples
number of already processed samples
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
static int xma_decode_packet(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static const float coef1_level[HUFF_COEF1_SIZE]
av_tx_fn tx_fn[WMAPRO_BLOCK_SIZES]
AVSampleFormat
Audio sample formats.
#define MAX_BANDS
max number of scale factor bands
static const uint16_t coef1_run[HUFF_COEF1_SIZE]
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
const char * name
Name of the codec implementation.
uint16_t trim_start
number of samples to skip at start
tables for wmapro decoding
GetBitContext pgb
bitstream reader context for the packet
int64_t frame_num
Frame counter, set by libavcodec.
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
static void save_bits(WMAProDecodeCtx *s, GetBitContext *gb, int len, int append)
Fill the bit reservoir with a (partial) frame.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
uint8_t num_channels
number of channels in the group
static int wmapro_decode_packet(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Decode a single WMA packet.
static av_cold void dump_context(WMAProDecodeCtx *s)
helper function to print the most important members of the context
#define AV_INPUT_BUFFER_PADDING_SIZE
static int decode_frame(WMAProDecodeCtx *s, AVFrame *frame, int *got_frame_ptr)
Decode one WMA frame.
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
int8_t channels_for_cur_subframe
number of channels that contain the subframe
main external API structure.
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.
int8_t esc_len
length of escaped coefficients
uint8_t table_idx
index for the num_sfb, sfb_offsets, sf_offsets and subwoofer_cutoffs tables
int8_t num_sfb[WMAPRO_BLOCK_SIZES]
scale factor bands per block size
uint16_t subframe_len[MAX_SUBFRAMES]
subframe length in samples
void ff_init_ff_sine_windows(int index)
initialize the specified entry of ff_sine_windows
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
uint8_t bits_per_sample
integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1....
uint8_t max_subframe_len_bit
flag indicating that the subframe is of maximum size when the first subframe length bit is 1
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
uint8_t packet_offset
frame offset in the packet
uint8_t skip_packets
packets to skip to find next packet in a stream (XMA1/2)
float * channel_data[WMAPRO_MAX_CHANNELS]
transformation coefficients
const av_cold VLCElem * ff_vlc_init_tables_from_lengths(VLCInitState *state, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags)
AVTXContext * tx[WMAPRO_BLOCK_SIZES]
MDCT context per block size.
int saved_scale_factors[2][MAX_BANDS]
resampled and (previously) transmitted scale factor values
int frame_offset
frame offset in the bit reservoir
AVFrame * frames[XMA_MAX_STREAMS]
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
uint8_t packet_done
set when a packet is fully decoded
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
#define avpriv_request_sample(...)
static av_cold int xma_decode_end(AVCodecContext *avctx)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
int8_t lfe_channel
lfe channel index
static const uint8_t scale_rl_table[HUFF_SCALE_RL_SIZE][2]
uint16_t trim_end
number of samples to skip at end
#define VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vlc_table, nb_bits, nb_codes, lens, lens_wrap, syms, syms_wrap, syms_size, offset, flags)
static const uint16_t vec4_syms[HUFF_VEC4_SIZE]
int16_t * cur_sfb_offsets
sfb offsets for the current block
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static int decode_channel_transform(WMAProDecodeCtx *s)
Decode channel transformation parameters.
int16_t subframe_len
current subframe length
#define VLC_INIT_STATE(_table)
int8_t parsed_all_subframes
all subframes decoded?
This structure stores compressed data.
static const uint8_t coef0_lens[HUFF_COEF0_SIZE]
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
static const float coef0_level[HUFF_COEF0_SIZE]
#define MAX_FRAMESIZE
maximum compressed frame size
uint8_t packet_sequence_number
current packet number
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
uint8_t dynamic_range_compression
frame contains DRC data
static int remaining_bits(WMAProDecodeCtx *s, GetBitContext *gb)
Calculate remaining input buffer length.
void av_audio_fifo_reset(AVAudioFifo *af)
Reset the AVAudioFifo buffer.
unsigned int ff_wma_get_large_val(GetBitContext *gb)
Decode an uncompressed coefficient.
#define FF_DEBUG_BITSTREAM
int num_saved_bits
saved number of bits
float decorrelation_matrix[WMAPRO_MAX_CHANNELS *WMAPRO_MAX_CHANNELS]
static void BS_FUNC() skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
const FFCodec ff_wmapro_decoder
wmapro decoder
static const uint8_t coef1_table[HUFF_COEF1_SIZE][2]
static VLCElem sf_rl_vlc[1406]
scale factor run length vlc
#define WMAPRO_BLOCK_MIN_BITS
log2 of min block size