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;
209 s->decode_flags =
AV_RL16(edata_ptr + 14);
210 channel_mask =
AV_RL32(edata_ptr + 2);
211 s->bits_per_sample =
AV_RL16(edata_ptr);
212 if (
s->bits_per_sample == 16)
214 else if (
s->bits_per_sample == 24) {
238 s->len_prefix =
s->decode_flags & 0x40;
247 s->channel[
i].prev_block_len =
s->samples_per_frame;
250 log2_max_num_subframes = (
s->decode_flags & 0x38) >> 3;
251 s->max_num_subframes = 1 << log2_max_num_subframes;
252 s->max_subframe_len_bit = 0;
253 s->subframe_len_bits =
av_log2(log2_max_num_subframes) + 1;
255 s->min_samples_per_subframe =
s->samples_per_frame /
s->max_num_subframes;
256 s->dynamic_range_compression =
s->decode_flags & 0x80;
257 s->bV3RTM =
s->decode_flags & 0x100;
261 s->max_num_subframes);
270 if (channel_mask & 8) {
273 if (channel_mask &
mask)
293 int frame_len_ratio, subframe_len,
len;
296 if (
offset ==
s->samples_per_frame -
s->min_samples_per_subframe)
297 return s->min_samples_per_subframe;
301 subframe_len =
s->min_samples_per_subframe * (frame_len_ratio + 1);
304 if (subframe_len < s->min_samples_per_subframe ||
305 subframe_len >
s->samples_per_frame) {
337 int channels_for_cur_subframe =
s->num_channels;
338 int fixed_channel_layout = 0;
339 int min_channel_len = 0;
343 for (
c = 0;
c <
s->num_channels;
c++)
344 s->channel[
c].num_subframes = 0;
347 if (
s->max_num_subframes == 1 || tile_aligned)
348 fixed_channel_layout = 1;
352 int subframe_len, in_use = 0;
355 for (
c = 0;
c <
s->num_channels;
c++) {
356 if (num_samples[
c] == min_channel_len) {
357 if (fixed_channel_layout || channels_for_cur_subframe == 1 ||
358 (min_channel_len ==
s->samples_per_frame -
s->min_samples_per_subframe)) {
359 contains_subframe[
c] = 1;
363 in_use |= contains_subframe[
c];
365 contains_subframe[
c] = 0;
370 "Found empty subframe\n");
378 min_channel_len += subframe_len;
379 for (
c = 0;
c <
s->num_channels;
c++) {
382 if (contains_subframe[
c]) {
385 "broken frame: num subframes > 31\n");
389 num_samples[
c] += subframe_len;
391 if (num_samples[
c] >
s->samples_per_frame) {
393 "channel len(%"PRIu16
") > samples_per_frame(%"PRIu16
")\n",
394 num_samples[
c],
s->samples_per_frame);
397 }
else if (num_samples[
c] <= min_channel_len) {
398 if (num_samples[
c] < min_channel_len) {
399 channels_for_cur_subframe = 0;
400 min_channel_len = num_samples[
c];
402 ++channels_for_cur_subframe;
405 }
while (min_channel_len < s->samples_per_frame);
407 for (
c = 0;
c <
s->num_channels;
c++) {
409 for (
i = 0;
i <
s->channel[
c].num_subframes;
i++) {
410 s->channel[
c].subframe_offsets[
i] =
offset;
424 for (
i = 0;
i <
s->acfilter_order;
i++)
425 s->acfilter_coeffs[
i] =
get_bitsz(&
s->gb,
s->acfilter_scaling) + 1;
430 s->mclms_order = (
get_bits(&
s->gb, 4) + 1) * 2;
433 int i, send_coef_bits;
434 int cbits =
av_log2(
s->mclms_scaling + 1);
435 if (1 << cbits < s->mclms_scaling + 1)
438 send_coef_bits =
get_bitsz(&
s->gb, cbits) + 2;
440 for (
i = 0;
i <
s->mclms_order *
s->num_channels *
s->num_channels;
i++)
441 s->mclms_coeffs[
i] =
get_bits(&
s->gb, send_coef_bits);
443 for (
i = 0;
i <
s->num_channels;
i++) {
445 for (
c = 0;
c <
i;
c++)
446 s->mclms_coeffs_cur[
i *
s->num_channels +
c] =
get_bits(&
s->gb, send_coef_bits);
456 for (
c = 0;
c <
s->num_channels;
c++) {
458 for (
i = 0;
i <
s->cdlms_ttl[
c];
i++) {
462 "Order[%d][%d] %d > max (%d), not supported\n",
464 s->cdlms[0][0].order = 0;
467 if(
s->cdlms[
c][
i].order & 8 &&
s->bits_per_sample == 16) {
471 s->cdlms[
c][
i].order);
476 for (
i = 0;
i <
s->cdlms_ttl[
c];
i++)
479 if (cdlms_send_coef) {
480 for (
i = 0;
i <
s->cdlms_ttl[
c];
i++) {
481 int cbits, shift_l, shift_r, j;
483 if ((1 << cbits) <
s->cdlms[
c][
i].order)
488 if ((1 << cbits) <
s->cdlms[
c][
i].scaling + 1)
492 shift_l = 32 -
s->cdlms[
c][
i].bitsend;
493 shift_r = 32 -
s->cdlms[
c][
i].scaling - 2;
494 for (j = 0; j <
s->cdlms[
c][
i].coefsend; j++)
495 s->cdlms[
c][
i].coefs[j] =
496 (
get_bits(&
s->gb,
s->cdlms[
c][
i].bitsend) << shift_l) >> shift_r;
500 for (
i = 0;
i <
s->cdlms_ttl[
c];
i++)
501 memset(
s->cdlms[
c][
i].coefs +
s->cdlms[
c][
i].order,
511 unsigned int ave_mean;
513 if (
s->transient[
ch]) {
515 if (
s->transient_pos[
ch])
516 s->transient[
ch] = 0;
517 s->channel[
ch].transient_counter =
518 FFMAX(
s->channel[
ch].transient_counter,
s->samples_per_frame / 2);
519 }
else if (
s->channel[
ch].transient_counter)
520 s->transient[
ch] = 1;
522 if (
s->seekable_tile) {
523 ave_mean =
get_bits(&
s->gb,
s->bits_per_sample);
524 s->ave_sum[
ch] = ave_mean << (
s->movave_scaling + 1);
527 if (
s->seekable_tile) {
528 if (
s->do_inter_ch_decorr)
534 for (;
i < tile_size;
i++) {
536 unsigned quo = 0, residue;
545 ave_mean = (
s->ave_sum[
ch] + (1 <<
s->movave_scaling)) >> (
s->movave_scaling + 1);
549 rem_bits = av_ceil_log2(ave_mean);
551 residue = (quo << rem_bits) + rem;
554 s->ave_sum[
ch] = residue +
s->ave_sum[
ch] -
555 (
s->ave_sum[
ch] >>
s->movave_scaling);
557 residue = (residue >> 1) ^ -(residue & 1);
558 s->channel_residues[
ch][
i] = residue;
571 cbits =
s->lpc_scaling +
s->lpc_intbits;
572 for (
ch = 0;
ch <
s->num_channels;
ch++)
573 for (
i = 0;
i <
s->lpc_order;
i++)
581 memset(
s->acfilter_coeffs, 0,
sizeof(
s->acfilter_coeffs));
582 memset(
s->acfilter_prevvalues, 0,
sizeof(
s->acfilter_prevvalues));
583 memset(
s->lpc_coefs, 0,
sizeof(
s->lpc_coefs));
585 memset(
s->mclms_coeffs, 0,
sizeof(
s->mclms_coeffs));
586 memset(
s->mclms_coeffs_cur, 0,
sizeof(
s->mclms_coeffs_cur));
587 memset(
s->mclms_prevvalues, 0,
sizeof(
s->mclms_prevvalues));
588 memset(
s->mclms_updates, 0,
sizeof(
s->mclms_updates));
590 for (ich = 0; ich <
s->num_channels; ich++) {
591 for (ilms = 0; ilms <
s->cdlms_ttl[ich]; ilms++) {
592 memset(
s->cdlms[ich][ilms].coefs, 0,
593 sizeof(
s->cdlms[ich][ilms].coefs));
594 memset(
s->cdlms[ich][ilms].lms_prevvalues, 0,
595 sizeof(
s->cdlms[ich][ilms].lms_prevvalues));
596 memset(
s->cdlms[ich][ilms].lms_updates, 0,
597 sizeof(
s->cdlms[ich][ilms].lms_updates));
609 s->mclms_recent =
s->mclms_order *
s->num_channels;
610 for (ich = 0; ich <
s->num_channels; ich++) {
611 for (ilms = 0; ilms <
s->cdlms_ttl[ich]; ilms++)
612 s->cdlms[ich][ilms].recent =
s->cdlms[ich][ilms].order;
615 s->channel[ich].transient_counter =
s->samples_per_frame;
616 s->transient[ich] = 1;
617 s->transient_pos[ich] = 0;
623 int i, j, ich, pred_error;
624 int order =
s->mclms_order;
625 int num_channels =
s->num_channels;
626 int range = 1 << (
s->bits_per_sample - 1);
628 for (ich = 0; ich < num_channels; ich++) {
629 pred_error =
s->channel_residues[ich][icoef] - (unsigned)
pred[ich];
630 if (pred_error > 0) {
631 for (
i = 0;
i < order * num_channels;
i++)
632 s->mclms_coeffs[
i + ich * order * num_channels] +=
633 s->mclms_updates[
s->mclms_recent +
i];
634 for (j = 0; j < ich; j++)
635 s->mclms_coeffs_cur[ich * num_channels + j] +=
WMASIGN(
s->channel_residues[j][icoef]);
636 }
else if (pred_error < 0) {
637 for (
i = 0;
i < order * num_channels;
i++)
638 s->mclms_coeffs[
i + ich * order * num_channels] -=
639 s->mclms_updates[
s->mclms_recent +
i];
640 for (j = 0; j < ich; j++)
641 s->mclms_coeffs_cur[ich * num_channels + j] -=
WMASIGN(
s->channel_residues[j][icoef]);
645 for (ich = num_channels - 1; ich >= 0; ich--) {
647 s->mclms_prevvalues[
s->mclms_recent] = av_clip(
s->channel_residues[ich][icoef],
649 s->mclms_updates[
s->mclms_recent] =
WMASIGN(
s->channel_residues[ich][icoef]);
652 if (
s->mclms_recent == 0) {
653 memcpy(&
s->mclms_prevvalues[order * num_channels],
655 sizeof(
int32_t) * order * num_channels);
656 memcpy(&
s->mclms_updates[order * num_channels],
658 sizeof(
int32_t) * order * num_channels);
659 s->mclms_recent = num_channels * order;
666 int order =
s->mclms_order;
667 int num_channels =
s->num_channels;
669 for (ich = 0; ich < num_channels; ich++) {
671 if (!
s->is_channel_coded[ich])
673 for (
i = 0;
i < order * num_channels;
i++)
674 pred[ich] += (uint32_t)
s->mclms_prevvalues[
i +
s->mclms_recent] *
675 s->mclms_coeffs[
i + order * num_channels * ich];
676 for (
i = 0;
i < ich;
i++)
677 pred[ich] += (uint32_t)
s->channel_residues[
i][icoef] *
678 s->mclms_coeffs_cur[
i + num_channels * ich];
679 pred[ich] += (1
U <<
s->mclms_scaling) >> 1;
680 pred[ich] >>=
s->mclms_scaling;
681 s->channel_residues[ich][icoef] += (unsigned)
pred[ich];
688 for (icoef = 0; icoef < tile_size; icoef++) {
696 int ilms, recent, icoef;
697 for (ilms =
s->cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
698 recent =
s->cdlms[ich][ilms].recent;
699 if (
s->update_speed[ich] == 16)
702 for (icoef = 0; icoef <
s->cdlms[ich][ilms].order; icoef++)
703 s->cdlms[ich][ilms].lms_updates[icoef + recent] *= 2;
705 for (icoef = 0; icoef <
s->cdlms[ich][ilms].order; icoef++)
706 s->cdlms[ich][ilms].lms_updates[icoef] *= 2;
709 s->update_speed[ich] = 16;
714 int ilms, recent, icoef;
715 for (ilms =
s->cdlms_ttl[ich] - 1; ilms >= 0; ilms--) {
716 recent =
s->cdlms[ich][ilms].recent;
717 if (
s->update_speed[ich] == 8)
720 for (icoef = 0; icoef <
s->cdlms[ich][ilms].order; icoef++)
721 s->cdlms[ich][ilms].lms_updates[icoef + recent] /= 2;
723 for (icoef = 0; icoef <
s->cdlms[ich][ilms].order; icoef++)
724 s->cdlms[ich][ilms].lms_updates[icoef] /= 2;
726 s->update_speed[ich] = 8;
729 #define CD_LMS(bits, ROUND) \
730 static void lms_update ## bits (WmallDecodeCtx *s, int ich, int ilms, int input) \
732 int recent = s->cdlms[ich][ilms].recent; \
733 int range = 1 << s->bits_per_sample - 1; \
734 int order = s->cdlms[ich][ilms].order; \
735 int ##bits##_t *prev = (int##bits##_t *)s->cdlms[ich][ilms].lms_prevvalues; \
740 memcpy(prev + order, prev, (bits/8) * order); \
741 memcpy(s->cdlms[ich][ilms].lms_updates + order, \
742 s->cdlms[ich][ilms].lms_updates, \
743 sizeof(*s->cdlms[ich][ilms].lms_updates) * order); \
744 recent = order - 1; \
747 prev[recent] = av_clip(input, -range, range - 1); \
748 s->cdlms[ich][ilms].lms_updates[recent] = WMASIGN(input) * s->update_speed[ich]; \
750 s->cdlms[ich][ilms].lms_updates[recent + (order >> 4)] >>= 2; \
751 s->cdlms[ich][ilms].lms_updates[recent + (order >> 3)] >>= 1; \
752 s->cdlms[ich][ilms].recent = recent; \
753 memset(s->cdlms[ich][ilms].lms_updates + recent + order, 0, \
754 sizeof(s->cdlms[ich][ilms].lms_updates) - \
755 sizeof(*s->cdlms[ich][ilms].lms_updates)*(recent+order)); \
758 static void revert_cdlms ## bits (WmallDecodeCtx *s, int ch, \
759 int coef_begin, int coef_end) \
761 int icoef, pred, ilms, num_lms, residue, input; \
763 num_lms = s->cdlms_ttl[ch]; \
764 for (ilms = num_lms - 1; ilms >= 0; ilms--) { \
765 for (icoef = coef_begin; icoef < coef_end; icoef++) { \
766 int##bits##_t *prevvalues = (int##bits##_t *)s->cdlms[ch][ilms].lms_prevvalues; \
767 pred = (1 << s->cdlms[ch][ilms].scaling) >> 1; \
768 residue = s->channel_residues[ch][icoef]; \
769 pred += s->dsp.scalarproduct_and_madd_int## bits (s->cdlms[ch][ilms].coefs, \
770 prevvalues + s->cdlms[ch][ilms].recent, \
771 s->cdlms[ch][ilms].lms_updates + \
772 s->cdlms[ch][ilms].recent, \
773 FFALIGN(s->cdlms[ch][ilms].order, ROUND), \
775 input = residue + (unsigned)(pred >> s->cdlms[ch][ilms].scaling); \
776 lms_update ## bits(s, ch, ilms, input); \
777 s->channel_residues[ch][icoef] = input; \
780 if (bits <= 16) emms_c(); \
788 if (
s->num_channels != 2)
790 else if (
s->is_channel_coded[0] ||
s->is_channel_coded[1]) {
792 for (icoef = 0; icoef < tile_size; icoef++) {
793 s->channel_residues[0][icoef] -= (unsigned)(
s->channel_residues[1][icoef] >> 1);
794 s->channel_residues[1][icoef] += (unsigned)
s->channel_residues[0][icoef];
802 int16_t *filter_coeffs =
s->acfilter_coeffs;
803 int scaling =
s->acfilter_scaling;
804 int order =
s->acfilter_order;
806 for (ich = 0; ich <
s->num_channels; ich++) {
807 int *prevvalues =
s->acfilter_prevvalues[ich];
808 for (
i = 0;
i < order;
i++) {
810 for (j = 0; j < order; j++) {
812 pred += (uint32_t)filter_coeffs[j] * prevvalues[j -
i];
814 pred += (uint32_t)
s->channel_residues[ich][
i - j - 1] * filter_coeffs[j];
817 s->channel_residues[ich][
i] += (unsigned)
pred;
819 for (
i = order;
i < tile_size;
i++) {
821 for (j = 0; j < order; j++)
822 pred += (uint32_t)
s->channel_residues[ich][
i - j - 1] * filter_coeffs[j];
824 s->channel_residues[ich][
i] += (unsigned)
pred;
826 for (j = order - 1; j >= 0; j--)
827 if (tile_size <= j) {
828 prevvalues[j] = prevvalues[j - tile_size];
830 prevvalues[j] =
s->channel_residues[ich][tile_size - j - 1];
836 int offset =
s->samples_per_frame;
837 int subframe_len =
s->samples_per_frame;
838 int total_samples =
s->samples_per_frame *
s->num_channels;
839 int i, j, rawpcm_tile, padding_zeroes, res;
846 for (
i = 0;
i <
s->num_channels;
i++) {
847 if (
offset >
s->channel[
i].decoded_samples) {
848 offset =
s->channel[
i].decoded_samples;
850 s->channel[
i].subframe_len[
s->channel[
i].cur_subframe];
855 s->channels_for_cur_subframe = 0;
856 for (
i = 0;
i <
s->num_channels;
i++) {
857 const int cur_subframe =
s->channel[
i].cur_subframe;
859 total_samples -=
s->channel[
i].decoded_samples;
862 if (
offset ==
s->channel[
i].decoded_samples &&
863 subframe_len ==
s->channel[
i].subframe_len[cur_subframe]) {
864 total_samples -=
s->channel[
i].subframe_len[cur_subframe];
865 s->channel[
i].decoded_samples +=
866 s->channel[
i].subframe_len[cur_subframe];
867 s->channel_indexes_for_cur_subframe[
s->channels_for_cur_subframe] =
i;
868 ++
s->channels_for_cur_subframe;
875 s->parsed_all_subframes = 1;
879 if (
s->seekable_tile) {
883 if (
s->do_arith_coding) {
907 if (!rawpcm_tile && !
s->cdlms[0][0].order) {
909 "Waiting for seekable tile\n");
915 for (
i = 0;
i <
s->num_channels;
i++)
916 s->is_channel_coded[
i] = 1;
919 for (
i = 0;
i <
s->num_channels;
i++)
928 "inverse LPC filter");
941 int bits =
s->bits_per_sample - padding_zeroes;
944 "Invalid number of padding bits in raw PCM tile\n");
947 ff_dlog(
s->avctx,
"RAWPCM %d bits per sample. "
948 "total %d bits, remain=%d\n",
bits,
950 for (
i = 0;
i <
s->num_channels;
i++)
951 for (j = 0; j < subframe_len; j++)
954 if (
s->bits_per_sample < padding_zeroes)
956 for (
i = 0;
i <
s->num_channels;
i++) {
957 if (
s->is_channel_coded[
i]) {
959 if (
s->seekable_tile)
963 if (
s->bits_per_sample > 16)
964 revert_cdlms32(
s,
i, 0, subframe_len);
966 revert_cdlms16(
s,
i, 0, subframe_len);
968 memset(
s->channel_residues[
i], 0,
sizeof(**
s->channel_residues) * subframe_len);
974 if (
s->do_inter_ch_decorr)
980 if (
s->quant_stepsize != 1)
981 for (
i = 0;
i <
s->num_channels;
i++)
982 for (j = 0; j < subframe_len; j++)
983 s->channel_residues[
i][j] *= (
unsigned)
s->quant_stepsize;
987 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
988 int c =
s->channel_indexes_for_cur_subframe[
i];
989 int subframe_len =
s->channel[
c].subframe_len[
s->channel[
c].cur_subframe];
991 for (j = 0; j < subframe_len; j++) {
992 if (
s->bits_per_sample == 16) {
993 *
s->samples_16[
c]++ = (int16_t)
s->channel_residues[
c][j] * (1 << padding_zeroes);
995 *
s->samples_32[
c]++ =
s->channel_residues[
c][j] * (256
U << padding_zeroes);
1001 for (
i = 0;
i <
s->channels_for_cur_subframe;
i++) {
1002 int c =
s->channel_indexes_for_cur_subframe[
i];
1003 if (
s->channel[
c].cur_subframe >=
s->channel[
c].num_subframes) {
1007 ++
s->channel[
c].cur_subframe;
1021 int more_frames = 0,
len = 0,
i,
ret;
1023 s->frame->nb_samples =
s->samples_per_frame;
1027 s->frame->nb_samples = 0;
1030 for (
i = 0;
i <
s->num_channels;
i++) {
1031 s->samples_16[
i] = (int16_t *)
s->frame->extended_data[
i];
1032 s->samples_32[
i] = (
int32_t *)
s->frame->extended_data[
i];
1047 if (
s->dynamic_range_compression)
1058 ff_dlog(
s->avctx,
"start skip: %i\n", skip);
1064 ff_dlog(
s->avctx,
"end skip: %i\n", skip);
1065 s->frame->nb_samples -= skip;
1066 if (
s->frame->nb_samples <= 0)
1073 s->parsed_all_subframes = 0;
1074 for (
i = 0;
i <
s->num_channels;
i++) {
1075 s->channel[
i].decoded_samples = 0;
1076 s->channel[
i].cur_subframe = 0;
1080 while (!
s->parsed_all_subframes) {
1081 int decoded_samples =
s->channel[0].decoded_samples;
1084 if (
s->frame->nb_samples)
1085 s->frame->nb_samples = decoded_samples;
1094 if (
s->len_prefix) {
1098 "frame[%"PRIu32
"] would have to skip %i bits\n",
1145 s->num_saved_bits =
s->frame_offset;
1149 buflen = (
s->num_saved_bits +
len + 8) >> 3;
1151 if (len <= 0 || buflen >
s->max_frame_size) {
1154 s->num_saved_bits = 0;
1158 s->num_saved_bits +=
len;
1184 int buf_size = avpkt->
size;
1185 int num_bits_prev_frame, packet_sequence_number, spliced_packet;
1187 s->frame->nb_samples = 0;
1192 s->num_saved_bits = 0;
1193 }
else if (
s->packet_done ||
s->packet_loss) {
1201 s->buf_bit_size = buf_size << 3;
1205 packet_sequence_number =
get_bits(gb, 4);
1212 num_bits_prev_frame =
get_bits(gb,
s->log2_frame_size);
1215 if (!
s->packet_loss &&
1216 ((
s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) {
1219 "Packet loss detected! seq %"PRIx8
" vs %x\n",
1220 s->packet_sequence_number, packet_sequence_number);
1222 s->packet_sequence_number = packet_sequence_number;
1224 if (num_bits_prev_frame > 0) {
1226 if (num_bits_prev_frame >= remaining_packet_bits) {
1227 num_bits_prev_frame = remaining_packet_bits;
1236 if (num_bits_prev_frame < remaining_packet_bits && !s->packet_loss)
1238 }
else if (
s->num_saved_bits -
s->frame_offset) {
1239 ff_dlog(avctx,
"ignoring %x previously saved bits\n",
1240 s->num_saved_bits -
s->frame_offset);
1243 if (
s->packet_loss) {
1246 s->num_saved_bits = 0;
1254 s->buf_bit_size = (avpkt->
size -
s->next_packet_start) << 3;
1263 if (!
s->packet_loss)
1265 }
else if (!
s->len_prefix
1284 if (
s->packet_done && !
s->packet_loss &&
1291 *got_frame_ptr =
s->frame->nb_samples > 0;
1304 s->num_saved_bits = 0;
1305 s->frame_offset = 0;
1306 s->next_packet_start = 0;
1307 s->cdlms[0][0].order = 0;
1308 s->frame->nb_samples = 0;
1323 .
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.
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
struct WmallDecodeCtx::@189 cdlms[WMALL_MAX_CHANNELS][9]
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
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.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
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]
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/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(UINT64_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 *(UINT64_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 *(UINT64_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 &&HAVE_MMX) 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
#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.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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.
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.
#define AV_INPUT_BUFFER_PADDING_SIZE
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?