Go to the documentation of this file.
39 #define WMALL_MAX_CHANNELS 8
40 #define MAX_SUBFRAMES 32
42 #define MAX_FRAMESIZE 32768
45 #define WMALL_BLOCK_MIN_BITS 6
46 #define WMALL_BLOCK_MAX_BITS 14
47 #define WMALL_BLOCK_MAX_SIZE (1 << WMALL_BLOCK_MAX_BITS)
48 #define WMALL_BLOCK_SIZES (WMALL_BLOCK_MAX_BITS - WMALL_BLOCK_MIN_BITS + 1)
50 #define WMALL_COEFF_PAD_SIZE 16
178 #define WMASIGN(x) (((x) > 0) - ((x) < 0))
184 unsigned int channel_mask;
185 int i, log2_max_num_subframes;
212 s->decode_flags =
AV_RL16(edata_ptr + 14);
213 channel_mask =
AV_RL32(edata_ptr + 2);
214 s->bits_per_sample =
AV_RL16(edata_ptr);
215 if (
s->bits_per_sample == 16)
217 else if (
s->bits_per_sample == 24) {
241 s->len_prefix =
s->decode_flags & 0x40;
250 s->channel[
i].prev_block_len =
s->samples_per_frame;
253 log2_max_num_subframes = (
s->decode_flags & 0x38) >> 3;
254 s->max_num_subframes = 1 << log2_max_num_subframes;
255 s->max_subframe_len_bit = 0;
256 s->subframe_len_bits =
av_log2(log2_max_num_subframes) + 1;
258 s->min_samples_per_subframe =
s->samples_per_frame /
s->max_num_subframes;
259 s->dynamic_range_compression =
s->decode_flags & 0x80;
260 s->bV3RTM =
s->decode_flags & 0x100;
264 s->max_num_subframes);
273 if (channel_mask & 8) {
276 if (channel_mask &
mask)
296 int frame_len_ratio, subframe_len,
len;
299 if (
offset ==
s->samples_per_frame -
s->min_samples_per_subframe)
300 return s->min_samples_per_subframe;
304 subframe_len =
s->min_samples_per_subframe * (frame_len_ratio + 1);
307 if (subframe_len < s->min_samples_per_subframe ||
308 subframe_len >
s->samples_per_frame) {
340 int channels_for_cur_subframe =
s->num_channels;
341 int fixed_channel_layout = 0;
342 int min_channel_len = 0;
346 for (
c = 0;
c <
s->num_channels;
c++)
347 s->channel[
c].num_subframes = 0;
350 if (
s->max_num_subframes == 1 || tile_aligned)
351 fixed_channel_layout = 1;
355 int subframe_len, in_use = 0;
358 for (
c = 0;
c <
s->num_channels;
c++) {
359 if (num_samples[
c] == min_channel_len) {
360 if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
361 (min_channel_len ==
s->samples_per_frame -
s->min_samples_per_subframe)) {
362 contains_subframe[
c] = 1;
366 in_use |= contains_subframe[
c];
368 contains_subframe[
c] = 0;
373 "Found empty subframe\n");
381 min_channel_len += subframe_len;
382 for (
c = 0;
c <
s->num_channels;
c++) {
385 if (contains_subframe[
c]) {
388 "broken frame: num subframes > 31\n");
392 num_samples[
c] += subframe_len;
394 if (num_samples[
c] >
s->samples_per_frame) {
396 "channel len(%"PRIu16
") > samples_per_frame(%"PRIu16
")\n",
397 num_samples[
c],
s->samples_per_frame);
400 }
else if (num_samples[
c] <= min_channel_len) {
401 if (num_samples[
c] < min_channel_len) {
402 channels_for_cur_subframe = 0;
403 min_channel_len = num_samples[
c];
405 ++channels_for_cur_subframe;
408 }
while (min_channel_len < s->samples_per_frame);
410 for (
c = 0;
c <
s->num_channels;
c++) {
412 for (
i = 0;
i <
s->channel[
c].num_subframes;
i++) {
413 s->channel[
c].subframe_offsets[
i] =
offset;
427 for (
i = 0;
i <
s->acfilter_order;
i++)
428 s->acfilter_coeffs[
i] =
get_bitsz(&
s->gb,
s->acfilter_scaling) + 1;
433 s->mclms_order = (
get_bits(&
s->gb, 4) + 1) * 2;
436 int i, send_coef_bits;
437 int cbits =
av_log2(
s->mclms_scaling + 1);
438 if (1 << cbits < s->mclms_scaling + 1)
441 send_coef_bits =
get_bitsz(&
s->gb, cbits) + 2;
443 for (
i = 0;
i <
s->mclms_order *
s->num_channels *
s->num_channels;
i++)
444 s->mclms_coeffs[
i] =
get_bits(&
s->gb, send_coef_bits);
446 for (
i = 0;
i <
s->num_channels;
i++) {
448 for (
c = 0;
c <
i;
c++)
449 s->mclms_coeffs_cur[
i *
s->num_channels +
c] =
get_bits(&
s->gb, send_coef_bits);
459 for (
c = 0;
c <
s->num_channels;
c++) {
461 for (
i = 0;
i <
s->cdlms_ttl[
c];
i++) {
465 "Order[%d][%d] %d > max (%d), not supported\n",
467 s->cdlms[0][0].order = 0;
470 if(
s->cdlms[
c][
i].order & 8 &&
s->bits_per_sample == 16) {
474 s->cdlms[
c][
i].order);
479 for (
i = 0;
i <
s->cdlms_ttl[
c];
i++)
482 if (cdlms_send_coef) {
483 for (
i = 0;
i <
s->cdlms_ttl[
c];
i++) {
484 int cbits, shift_l, shift_r, j;
486 if ((1 << cbits) <
s->cdlms[
c][
i].order)
491 if ((1 << cbits) <
s->cdlms[
c][
i].scaling + 1)
495 shift_l = 32 -
s->cdlms[
c][
i].bitsend;
496 shift_r = 32 -
s->cdlms[
c][
i].scaling - 2;
497 for (j = 0; j <
s->cdlms[
c][
i].coefsend; j++)
498 s->cdlms[
c][
i].coefs[j] =
499 (
get_bits(&
s->gb,
s->cdlms[
c][
i].bitsend) << shift_l) >> shift_r;
503 for (
i = 0;
i <
s->cdlms_ttl[
c];
i++)
504 memset(
s->cdlms[
c][
i].coefs +
s->cdlms[
c][
i].order,
514 unsigned int ave_mean;
516 if (
s->transient[
ch]) {
518 if (
s->transient_pos[
ch])
519 s->transient[
ch] = 0;
520 s->channel[
ch].transient_counter =
521 FFMAX(
s->channel[
ch].transient_counter,
s->samples_per_frame / 2);
522 }
else if (
s->channel[
ch].transient_counter)
523 s->transient[
ch] = 1;
525 if (
s->seekable_tile) {
526 ave_mean =
get_bits(&
s->gb,
s->bits_per_sample);
527 s->ave_sum[
ch] = ave_mean << (
s->movave_scaling + 1);
530 if (
s->seekable_tile) {
531 if (
s->do_inter_ch_decorr)
537 for (;
i < tile_size;
i++) {
539 unsigned quo = 0, residue;
548 ave_mean = (
s->ave_sum[
ch] + (1 <<
s->movave_scaling)) >> (
s->movave_scaling + 1);
552 rem_bits = av_ceil_log2(ave_mean);
554 residue = (quo << rem_bits) + rem;
557 s->ave_sum[
ch] = residue +
s->ave_sum[
ch] -
558 (
s->ave_sum[
ch] >>
s->movave_scaling);
560 residue = (residue >> 1) ^ -(residue & 1);
561 s->channel_residues[
ch][
i] = residue;
574 cbits =
s->lpc_scaling +
s->lpc_intbits;
575 for (
ch = 0;
ch <
s->num_channels;
ch++)
576 for (
i = 0;
i <
s->lpc_order;
i++)
584 memset(
s->acfilter_coeffs, 0,
sizeof(
s->acfilter_coeffs));
585 memset(
s->acfilter_prevvalues, 0,
sizeof(
s->acfilter_prevvalues));
586 memset(
s->lpc_coefs, 0,
sizeof(
s->lpc_coefs));
588 memset(
s->mclms_coeffs, 0,
sizeof(
s->mclms_coeffs));
589 memset(
s->mclms_coeffs_cur, 0,
sizeof(
s->mclms_coeffs_cur));
590 memset(
s->mclms_prevvalues, 0,
sizeof(
s->mclms_prevvalues));
591 memset(
s->mclms_updates, 0,
sizeof(
s->mclms_updates));
593 for (ich = 0; ich <
s->num_channels; ich++) {
594 for (ilms = 0; ilms <
s->cdlms_ttl[ich]; ilms++) {
595 memset(
s->cdlms[ich][ilms].coefs, 0,
596 sizeof(
s->cdlms[ich][ilms].coefs));
597 memset(
s->cdlms[ich][ilms].lms_prevvalues, 0,
598 sizeof(
s->cdlms[ich][ilms].lms_prevvalues));
599 memset(
s->cdlms[ich][ilms].lms_updates, 0,
600 sizeof(
s->cdlms[ich][ilms].lms_updates));
612 s->mclms_recent =
s->mclms_order *
s->num_channels;
613 for (ich = 0; ich <
s->num_channels; ich++) {
614 for (ilms = 0; ilms <
s->cdlms_ttl[ich]; ilms++)
615 s->cdlms[ich][ilms].recent =
s->cdlms[ich][ilms].order;
618 s->channel[ich].transient_counter =
s->samples_per_frame;
619 s->transient[ich] = 1;
620 s->transient_pos[ich] = 0;
626 int i, j, ich, pred_error;
627 int order =
s->mclms_order;
628 int num_channels =
s->num_channels;
629 int range = 1 << (
s->bits_per_sample - 1);
631 for (ich = 0; ich < num_channels; ich++) {
632 pred_error =
s->channel_residues[ich][icoef] - (unsigned)
pred[ich];
633 if (pred_error > 0) {
634 for (
i = 0;
i < order * num_channels;
i++)
635 s->mclms_coeffs[
i + ich * order * num_channels] +=
636 s->mclms_updates[
s->mclms_recent +
i];
637 for (j = 0; j < ich; j++)
638 s->mclms_coeffs_cur[ich * num_channels + j] +=
WMASIGN(
s->channel_residues[j][icoef]);
639 }
else if (pred_error < 0) {
640 for (
i = 0;
i < order * num_channels;
i++)
641 s->mclms_coeffs[
i + ich * order * num_channels] -=
642 s->mclms_updates[
s->mclms_recent +
i];
643 for (j = 0; j < ich; j++)
644 s->mclms_coeffs_cur[ich * num_channels + j] -=
WMASIGN(
s->channel_residues[j][icoef]);
648 for (ich = num_channels - 1; ich >= 0; ich--) {
650 s->mclms_prevvalues[
s->mclms_recent] = av_clip(
s->channel_residues[ich][icoef],
652 s->mclms_updates[
s->mclms_recent] =
WMASIGN(
s->channel_residues[ich][icoef]);
655 if (
s->mclms_recent == 0) {
656 memcpy(&
s->mclms_prevvalues[order * num_channels],
658 sizeof(
int32_t) * order * num_channels);
659 memcpy(&
s->mclms_updates[order * num_channels],
661 sizeof(
int32_t) * order * num_channels);
662 s->mclms_recent = num_channels * order;
669 int order =
s->mclms_order;
670 int num_channels =
s->num_channels;
672 for (ich = 0; ich < num_channels; ich++) {
674 if (!
s->is_channel_coded[ich])
676 for (
i = 0;
i < order * num_channels;
i++)
677 pred[ich] += (uint32_t)
s->mclms_prevvalues[
i +
s->mclms_recent] *
678 s->mclms_coeffs[
i + order * num_channels * ich];
679 for (
i = 0;
i < ich;
i++)
680 pred[ich] += (uint32_t)
s->channel_residues[
i][icoef] *
681 s->mclms_coeffs_cur[
i + num_channels * ich];
682 pred[ich] += (1
U <<
s->mclms_scaling) >> 1;
683 pred[ich] >>=
s->mclms_scaling;
684 s->channel_residues[ich][icoef] += (unsigned)
pred[ich];
691 for (icoef = 0; icoef < tile_size; icoef++) {
699 int ilms, recent, icoef;
700 for (ilms =
s->cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
701 recent =
s->cdlms[ich][ilms].recent;
702 if (
s->update_speed[ich] == 16)
705 for (icoef = 0; icoef <
s->cdlms[ich][ilms].order; icoef++)
706 s->cdlms[ich][ilms].lms_updates[icoef + recent] *= 2;
708 for (icoef = 0; icoef <
s->cdlms[ich][ilms].order; icoef++)
709 s->cdlms[ich][ilms].lms_updates[icoef] *= 2;
712 s->update_speed[ich] = 16;
717 int ilms, recent, icoef;
718 for (ilms =
s->cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
719 recent =
s->cdlms[ich][ilms].recent;
720 if (
s->update_speed[ich] == 8)
723 for (icoef = 0; icoef <
s->cdlms[ich][ilms].order; icoef++)
724 s->cdlms[ich][ilms].lms_updates[icoef + recent] /= 2;
726 for (icoef = 0; icoef <
s->cdlms[ich][ilms].order; icoef++)
727 s->cdlms[ich][ilms].lms_updates[icoef] /= 2;
729 s->update_speed[ich] = 8;
732 #define CD_LMS(bits, ROUND) \
733 static void lms_update ## bits (WmallDecodeCtx *s, int ich, int ilms, int input) \
735 int recent = s->cdlms[ich][ilms].recent; \
736 int range = 1 << s->bits_per_sample - 1; \
737 int order = s->cdlms[ich][ilms].order; \
738 int ##bits##_t *prev = (int##bits##_t *)s->cdlms[ich][ilms].lms_prevvalues; \
743 memcpy(prev + order, prev, (bits/8) * order); \
744 memcpy(s->cdlms[ich][ilms].lms_updates + order, \
745 s->cdlms[ich][ilms].lms_updates, \
746 sizeof(*s->cdlms[ich][ilms].lms_updates) * order); \
747 recent = order - 1; \
750 prev[recent] = av_clip(input, -range, range - 1); \
751 s->cdlms[ich][ilms].lms_updates[recent] = WMASIGN(input) * s->update_speed[ich]; \
753 s->cdlms[ich][ilms].lms_updates[recent + (order >> 4)] >>= 2; \
754 s->cdlms[ich][ilms].lms_updates[recent + (order >> 3)] >>= 1; \
755 s->cdlms[ich][ilms].recent = recent; \
756 memset(s->cdlms[ich][ilms].lms_updates + recent + order, 0, \
757 sizeof(s->cdlms[ich][ilms].lms_updates) - \
758 sizeof(*s->cdlms[ich][ilms].lms_updates)*(recent+order)); \
761 static void revert_cdlms ## bits (WmallDecodeCtx *s, int ch, \
762 int coef_begin, int coef_end) \
764 int icoef, ilms, num_lms, residue, input; \
767 num_lms = s->cdlms_ttl[ch]; \
768 for (ilms = num_lms - 1; ilms >= 0; ilms--) { \
769 for (icoef = coef_begin; icoef < coef_end; icoef++) { \
770 int##bits##_t *prevvalues = (int##bits##_t *)s->cdlms[ch][ilms].lms_prevvalues; \
771 pred = (1 << s->cdlms[ch][ilms].scaling) >> 1; \
772 residue = s->channel_residues[ch][icoef]; \
773 pred += s->dsp.scalarproduct_and_madd_int## bits (s->cdlms[ch][ilms].coefs, \
774 prevvalues + s->cdlms[ch][ilms].recent, \
775 s->cdlms[ch][ilms].lms_updates + \
776 s->cdlms[ch][ilms].recent, \
777 FFALIGN(s->cdlms[ch][ilms].order, ROUND), \
779 input = residue + (unsigned)((int)pred >> s->cdlms[ch][ilms].scaling); \
780 lms_update ## bits(s, ch, ilms, input); \
781 s->channel_residues[ch][icoef] = input; \
784 if (bits <= 16) emms_c(); \
792 if (
s->num_channels != 2)
794 else if (
s->is_channel_coded[0] ||
s->is_channel_coded[1]) {
796 for (icoef = 0; icoef < tile_size; icoef++) {
797 s->channel_residues[0][icoef] -= (unsigned)(
s->channel_residues[1][icoef] >> 1);
798 s->channel_residues[1][icoef] += (unsigned)
s->channel_residues[0][icoef];
806 int16_t *filter_coeffs =
s->acfilter_coeffs;
807 int scaling =
s->acfilter_scaling;
808 int order =
s->acfilter_order;
810 for (ich = 0; ich <
s->num_channels; ich++) {
811 int *prevvalues =
s->acfilter_prevvalues[ich];
812 for (
i = 0;
i < order;
i++) {
814 for (j = 0; j < order; j++) {
816 pred += (uint32_t)filter_coeffs[j] * prevvalues[j -
i];
818 pred += (uint32_t)
s->channel_residues[ich][
i - j - 1] * filter_coeffs[j];
821 s->channel_residues[ich][
i] += (unsigned)
pred;
823 for (
i = order;
i < tile_size;
i++) {
825 for (j = 0; j < order; j++)
826 pred += (uint32_t)
s->channel_residues[ich][
i - j - 1] * filter_coeffs[j];
828 s->channel_residues[ich][
i] += (unsigned)
pred;
830 for (j = order - 1; j >= 0; j--)
831 if (tile_size <= j) {
832 prevvalues[j] = prevvalues[j - tile_size];
834 prevvalues[j] =
s->channel_residues[ich][tile_size - j - 1];
840 int offset =
s->samples_per_frame;
841 int subframe_len =
s->samples_per_frame;
842 int total_samples =
s->samples_per_frame *
s->num_channels;
843 int i, j, rawpcm_tile, padding_zeroes, res;
850 for (
i = 0;
i <
s->num_channels;
i++) {
851 if (
offset >
s->channel[
i].decoded_samples) {
852 offset =
s->channel[
i].decoded_samples;
854 s->channel[
i].subframe_len[
s->channel[
i].cur_subframe];
859 s->channels_for_cur_subframe = 0;
860 for (
i = 0;
i <
s->num_channels;
i++) {
861 const int cur_subframe =
s->channel[
i].cur_subframe;
863 total_samples -=
s->channel[
i].decoded_samples;
866 if (
offset ==
s->channel[
i].decoded_samples &&
867 subframe_len ==
s->channel[
i].subframe_len[cur_subframe]) {
868 total_samples -=
s->channel[
i].subframe_len[cur_subframe];
869 s->channel[
i].decoded_samples +=
870 s->channel[
i].subframe_len[cur_subframe];
871 s->channel_indexes_for_cur_subframe[
s->channels_for_cur_subframe] =
i;
872 ++
s->channels_for_cur_subframe;
879 s->parsed_all_subframes = 1;
883 if (
s->seekable_tile) {
887 if (
s->do_arith_coding) {
911 if (!rawpcm_tile && !
s->cdlms[0][0].order) {
913 "Waiting for seekable tile\n");
919 for (
i = 0;
i <
s->num_channels;
i++)
920 s->is_channel_coded[
i] = 1;
923 for (
i = 0;
i <
s->num_channels;
i++)
932 "inverse LPC filter");
947 int bits =
s->bits_per_sample - padding_zeroes;
950 "Invalid number of padding bits in raw PCM tile\n");
953 ff_dlog(
s->avctx,
"RAWPCM %d bits per sample. "
954 "total %d bits, remain=%d\n",
bits,
956 for (
i = 0;
i <
s->num_channels;
i++)
957 for (j = 0; j < subframe_len; j++)
960 if (
s->bits_per_sample < padding_zeroes)
962 for (
i = 0;
i <
s->num_channels;
i++) {
963 if (
s->is_channel_coded[
i]) {
965 if (
s->seekable_tile)
969 if (
s->bits_per_sample > 16)
970 revert_cdlms32(
s,
i, 0, subframe_len);
972 revert_cdlms16(
s,
i, 0, subframe_len);
974 memset(
s->channel_residues[
i], 0,
sizeof(**
s->channel_residues) * subframe_len);
980 if (
s->do_inter_ch_decorr)
986 if (
s->quant_stepsize != 1)
987 for (
i = 0;
i <
s->num_channels;
i++)
988 for (j = 0; j < subframe_len; j++)
989 s->channel_residues[
i][j] *= (
unsigned)
s->quant_stepsize;
993 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
994 int c =
s->channel_indexes_for_cur_subframe[
i];
995 int subframe_len =
s->channel[
c].subframe_len[
s->channel[
c].cur_subframe];
997 for (j = 0; j < subframe_len; j++) {
998 if (
s->bits_per_sample == 16) {
999 *
s->samples_16[
c]++ = (int16_t)
s->channel_residues[
c][j] * (1 << padding_zeroes);
1001 *
s->samples_32[
c]++ =
s->channel_residues[
c][j] * (256
U << padding_zeroes);
1007 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1008 int c =
s->channel_indexes_for_cur_subframe[
i];
1009 if (
s->channel[
c].cur_subframe >=
s->channel[
c].num_subframes) {
1013 ++
s->channel[
c].cur_subframe;
1027 int more_frames = 0,
len = 0,
i,
ret;
1029 s->frame->nb_samples =
s->samples_per_frame;
1033 s->frame->nb_samples = 0;
1036 for (
i = 0;
i <
s->num_channels;
i++) {
1037 s->samples_16[
i] = (int16_t *)
s->frame->extended_data[
i];
1038 s->samples_32[
i] = (
int32_t *)
s->frame->extended_data[
i];
1053 if (
s->dynamic_range_compression)
1064 ff_dlog(
s->avctx,
"start skip: %i\n", skip);
1070 ff_dlog(
s->avctx,
"end skip: %i\n", skip);
1071 s->frame->nb_samples -= skip;
1072 if (
s->frame->nb_samples <= 0)
1079 s->parsed_all_subframes = 0;
1080 for (
i = 0;
i <
s->num_channels;
i++) {
1081 s->channel[
i].decoded_samples = 0;
1082 s->channel[
i].cur_subframe = 0;
1086 while (!
s->parsed_all_subframes) {
1087 int decoded_samples =
s->channel[0].decoded_samples;
1090 if (
s->frame->nb_samples)
1091 s->frame->nb_samples = decoded_samples;
1100 if (
s->len_prefix) {
1104 "frame[%"PRIu32
"] would have to skip %i bits\n",
1151 s->num_saved_bits =
s->frame_offset;
1155 buflen = (
s->num_saved_bits +
len + 8) >> 3;
1157 if (len <= 0 || buflen >
s->max_frame_size) {
1160 s->num_saved_bits = 0;
1164 s->num_saved_bits +=
len;
1190 int buf_size = avpkt->
size;
1191 int num_bits_prev_frame, packet_sequence_number, spliced_packet;
1193 s->frame->nb_samples = 0;
1198 s->num_saved_bits = 0;
1199 }
else if (
s->packet_done ||
s->packet_loss) {
1207 s->buf_bit_size = buf_size << 3;
1211 packet_sequence_number =
get_bits(gb, 4);
1218 num_bits_prev_frame =
get_bits(gb,
s->log2_frame_size);
1221 if (!
s->packet_loss &&
1222 ((
s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) {
1225 "Packet loss detected! seq %"PRIx8
" vs %x\n",
1226 s->packet_sequence_number, packet_sequence_number);
1228 s->packet_sequence_number = packet_sequence_number;
1230 if (num_bits_prev_frame > 0) {
1232 if (num_bits_prev_frame >= remaining_packet_bits) {
1233 num_bits_prev_frame = remaining_packet_bits;
1242 if (num_bits_prev_frame < remaining_packet_bits && !s->packet_loss)
1244 }
else if (
s->num_saved_bits -
s->frame_offset) {
1245 ff_dlog(avctx,
"ignoring %x previously saved bits\n",
1246 s->num_saved_bits -
s->frame_offset);
1249 if (
s->packet_loss) {
1252 s->num_saved_bits = 0;
1260 s->buf_bit_size = (avpkt->
size -
s->next_packet_start) << 3;
1269 if (!
s->packet_loss)
1271 }
else if (!
s->len_prefix
1290 if (
s->packet_done && !
s->packet_loss &&
1297 *got_frame_ptr =
s->frame->nb_samples > 0;
1310 s->num_saved_bits = 0;
1311 s->frame_offset = 0;
1312 s->next_packet_start = 0;
1313 s->cdlms[0][0].order = 0;
1314 s->frame->nb_samples = 0;
1329 .
name =
"wmalossless",
#define MAX_SUBFRAMES
max number of subframes per channel
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
uint32_t frame_num
current frame number (not used for decoding)
static av_cold int init(AVCodecContext *avctx)
uint8_t cur_subframe
current subframe number
uint16_t subframe_len[MAX_SUBFRAMES]
subframe length in samples
static int get_bits_left(GetBitContext *gb)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static uint8_t * append(uint8_t *buf, const uint8_t *src, int size)
uint64_t channel_layout
Audio channel layout.
uint16_t subframe_offsets[MAX_SUBFRAMES]
subframe positions in the current frame
uint8_t packet_done
set when a packet is fully decoded
int sample_rate
samples per second
int next_packet_start
start offset of the next WMA packet in the demuxer packet
static enum AVSampleFormat sample_fmts[]
int subframe_offset
subframe offset in the bit reservoir
static unsigned int get_bits_long(GetBitContext *s, int n)
Read 0-32 bits.
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
int frame_offset
frame offset in the bit reservoir
uint8_t packet_loss
set in case of bitstream error
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int decode_frame(WmallDecodeCtx *s)
Decode one WMA frame.
static int get_bits_count(const GetBitContext *s)
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
static int decode_subframe(WmallDecodeCtx *s)
int cdlms_ttl[WMALL_MAX_CHANNELS]
This structure describes decoded (raw) audio or video data.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define WMALL_BLOCK_MAX_SIZE
maximum block size
AVCodec ff_wmalossless_decoder
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
int8_t channel_indexes_for_cur_subframe[WMALL_MAX_CHANNELS]
static int decode_cdlms(WmallDecodeCtx *s)
static av_cold int decode_close(AVCodecContext *avctx)
static void mclms_predict(WmallDecodeCtx *s, int icoef, int *pred)
int update_speed[WMALL_MAX_CHANNELS]
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
int num_saved_bits
saved number of bits
struct WmallDecodeCtx::@201 cdlms[WMALL_MAX_CHANNELS][9]
static void decode_mclms(WmallDecodeCtx *s)
av_cold void ff_llauddsp_init(LLAudDSPContext *c)
static void skip_bits(GetBitContext *s, int n)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define WMALL_COEFF_PAD_SIZE
pad coef buffers with 0 for use with SIMD
static void clear_codec_buffers(WmallDecodeCtx *s)
int max_frame_size
max bitstream size
uint16_t samples_per_frame
number of samples to output
static void reset_codec(WmallDecodeCtx *s)
Reset filter parameters and transient area at new seekable tile.
uint16_t min_samples_per_subframe
uint16_t decoded_samples
number of already processed samples
int16_t lms_updates[MAX_ORDER *2+WMALL_COEFF_PAD_SIZE/sizeof(int16_t)]
uint8_t do_inter_ch_decorr
static void save_bits(WmallDecodeCtx *s, GetBitContext *gb, int len, int append)
Fill the bit reservoir with a (partial) frame.
static int remaining_bits(WmallDecodeCtx *s, GetBitContext *gb)
Calculate remaining input buffer length.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int len_prefix
frame is prefixed with its length
static const uint16_t mask[17]
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
int channel_residues[WMALL_MAX_CHANNELS][WMALL_BLOCK_MAX_SIZE]
static int decode_subframe_length(WmallDecodeCtx *s, int offset)
Decode the subframe length.
int32_t lms_prevvalues[MAX_ORDER *2+WMALL_COEFF_PAD_SIZE/sizeof(int16_t)]
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
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
int lpc_coefs[WMALL_MAX_CHANNELS][40]
static void use_normal_update_speed(WmallDecodeCtx *s, int ich)
int32_t mclms_prevvalues[WMALL_MAX_CHANNELS *2 *32]
#define MAX_FRAMESIZE
maximum compressed frame size
int buf_bit_size
buffer size in bits
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int transient_counter
number of transient samples from the beginning of the transient zone
@ AV_CODEC_ID_WMALOSSLESS
static unsigned int get_bits1(GetBitContext *s)
int32_t * samples_32[WMALL_MAX_CHANNELS]
current sample buffer pointer (24-bit)
int quant_step
quantization step for the current subframe
int32_t mclms_updates[WMALL_MAX_CHANNELS *2 *32]
#define WMALL_MAX_CHANNELS
current decoder limitations
uint8_t bits_per_sample
integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1....
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
void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
Copy the content of src to the bitstream.
uint8_t packet_offset
offset to the frame in the packet
int16_t acfilter_coeffs[16]
static int decode_tilehdr(WmallDecodeCtx *s)
Decode how the data in the frame is split into subframes.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int8_t channels_for_cur_subframe
number of channels that contain the subframe
int16_t mclms_coeffs[WMALL_MAX_CHANNELS *WMALL_MAX_CHANNELS *32]
GetBitContext gb
bitstream reader context
enum AVSampleFormat sample_fmt
audio sample format
int acfilter_prevvalues[WMALL_MAX_CHANNELS][16]
frame-specific decoder context for a single channel
uint8_t packet_sequence_number
current packet number
static void use_high_update_speed(WmallDecodeCtx *s, int ich)
int16_t * samples_16[WMALL_MAX_CHANNELS]
current sample buffer pointer (16-bit)
static void decode_ac_filter(WmallDecodeCtx *s)
int8_t num_channels
number of channels in the stream (same as AVCodecContext.num_channels)
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
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
uint32_t decode_flags
used compression features
int channels
number of audio channels
#define DECLARE_ALIGNED(n, t, v)
static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred)
static void revert_inter_ch_decorr(WmallDecodeCtx *s, int tile_size)
#define i(width, name, range_min, range_max)
int16_t subframe_len
current subframe length
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
uint8_t max_subframe_len_bit
flag indicating that the subframe is of maximum size when the first subframe length bit is 1
int is_channel_coded[WMALL_MAX_CHANNELS]
AVSampleFormat
Audio sample formats.
uint8_t drc_gain
gain for the DRC tool
static void revert_acfilter(WmallDecodeCtx *s, int tile_size)
GetBitContext pgb
bitstream reader context for the packet
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Name of the codec implementation.
uint8_t max_num_subframes
LLAudDSPContext dsp
accelerated DSP functions
int8_t skip_frame
skip output step
static const float pred[4]
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs.
const AVS_VideoInfo int align
#define AV_INPUT_BUFFER_PADDING_SIZE
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
int16_t coefs[MAX_ORDER+WMALL_COEFF_PAD_SIZE/sizeof(int16_t)]
main external API structure.
int transient_pos[WMALL_MAX_CHANNELS]
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 void revert_mclms(WmallDecodeCtx *s, int tile_size)
static av_cold int decode_init(AVCodecContext *avctx)
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
static void decode_lpc(WmallDecodeCtx *s)
static int decode_channel_residues(WmallDecodeCtx *s, int ch, int tile_size)
int16_t mclms_coeffs_cur[WMALL_MAX_CHANNELS *WMALL_MAX_CHANNELS]
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
#define AV_CODEC_CAP_SUBFRAMES
Codec can output multiple frames per AVPacket Normally demuxers return one frame at a time,...
PutBitContext pb
context for filling the frame_data buffer
#define avpriv_request_sample(...)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
int16_t prev_block_len
length of the previous block
This structure stores compressed data.
#define WMASIGN(x)
Get sign of integer (1 for positive, -1 for negative and 0 for zero)
static int decode_packet(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
int8_t lfe_channel
lfe channel index
unsigned ave_sum[WMALL_MAX_CHANNELS]
#define CD_LMS(bits, ROUND)
static int get_sbits_long(GetBitContext *s, int n)
Read 0-32 bits as a signed integer.
uint8_t subframe_len_bits
number of bits used for the subframe length
int dynamic_range_compression
frame contains DRC data
static void flush(AVCodecContext *avctx)
uint8_t * frame_data
compressed frame data
int8_t parsed_all_subframes
all subframes decoded?