| 775 | } |
| 776 | |
| 777 | static int parse_common_header(DCAXllDecoder *s) |
| 778 | { |
| 779 | int stream_ver, header_size, frame_size_nbits, nframesegs_log2; |
| 780 | |
| 781 | // XLL extension sync word |
| 782 | if (get_bits_long(&s->gb, 32) != DCA_SYNCWORD_XLL) { |
| 783 | av_log(s->avctx, AV_LOG_VERBOSE, "Invalid XLL sync word\n"); |
| 784 | return AVERROR(EAGAIN); |
| 785 | } |
| 786 | |
| 787 | // Version number |
| 788 | stream_ver = get_bits(&s->gb, 4) + 1; |
| 789 | if (stream_ver > 1) { |
| 790 | avpriv_request_sample(s->avctx, "XLL stream version %d", stream_ver); |
| 791 | return AVERROR_PATCHWELCOME; |
| 792 | } |
| 793 | |
| 794 | // Lossless frame header length |
| 795 | header_size = get_bits(&s->gb, 8) + 1; |
| 796 | |
| 797 | // Check CRC |
| 798 | if (ff_dca_check_crc(s->avctx, &s->gb, 32, header_size * 8)) { |
| 799 | av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL common header checksum\n"); |
| 800 | return AVERROR_INVALIDDATA; |
| 801 | } |
| 802 | |
| 803 | // Number of bits used to read frame size |
| 804 | frame_size_nbits = get_bits(&s->gb, 5) + 1; |
| 805 | |
| 806 | // Number of bytes in a lossless frame |
| 807 | s->frame_size = get_bits_long(&s->gb, frame_size_nbits); |
| 808 | if (s->frame_size < 0 || s->frame_size >= DCA_XLL_PBR_BUFFER_MAX) { |
| 809 | av_log(s->avctx, AV_LOG_ERROR, "Invalid XLL frame size (%d bytes)\n", s->frame_size); |
| 810 | return AVERROR_INVALIDDATA; |
| 811 | } |
| 812 | s->frame_size++; |
| 813 | |
| 814 | // Number of channels sets per frame |
| 815 | s->nchsets = get_bits(&s->gb, 4) + 1; |
| 816 | if (s->nchsets > DCA_XLL_CHSETS_MAX) { |
| 817 | avpriv_request_sample(s->avctx, "%d XLL channel sets", s->nchsets); |
| 818 | return AVERROR_PATCHWELCOME; |
| 819 | } |
| 820 | |
| 821 | // Number of segments per frame |
| 822 | nframesegs_log2 = get_bits(&s->gb, 4); |
| 823 | s->nframesegs = 1 << nframesegs_log2; |
| 824 | if (s->nframesegs > 1024) { |
| 825 | av_log(s->avctx, AV_LOG_ERROR, "Too many segments per XLL frame\n"); |
| 826 | return AVERROR_INVALIDDATA; |
| 827 | } |
| 828 | |
| 829 | // Samples in segment per one frequency band for the first channel set |
| 830 | // Maximum value is 256 for sampling frequencies <= 48 kHz |
| 831 | // Maximum value is 512 for sampling frequencies > 48 kHz |
| 832 | s->nsegsamples_log2 = get_bits(&s->gb, 4); |
| 833 | if (!s->nsegsamples_log2) { |
| 834 | av_log(s->avctx, AV_LOG_ERROR, "Too few samples per XLL segment\n"); |
no test coverage detected