~ubuntu-branches/ubuntu/utopic/ffmpeg-debian/utopic

« back to all changes in this revision

Viewing changes to libavcodec/ac3dec.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-11-15 19:44:29 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081115194429-zwlw86ht1rctd8z9
Tags: 3:0.svn20081115-1ubuntu1
* merge from debian.
* keep myself in the maintainer field. If you are touching this or the
  'ffmpeg' package in multiverse, please get in touch with me. Both
  source packages come from the same packaging branch.
* drop dependency on faad.

Show diffs side-by-side

added added

removed removed

Lines of Context:
711
711
}
712
712
 
713
713
/**
 
714
 * Decode band structure for coupling, spectral extension, or enhanced coupling.
 
715
 * @param[in] gbc bit reader context
 
716
 * @param[in] blk block number
 
717
 * @param[in] eac3 flag to indicate E-AC-3
 
718
 * @param[in] ecpl flag to indicate enhanced coupling
 
719
 * @param[in] start_subband subband number for start of range
 
720
 * @param[in] end_subband subband number for end of range
 
721
 * @param[in] default_band_struct default band structure table
 
722
 * @param[out] band_struct decoded band structure
 
723
 * @param[out] num_subbands number of subbands (optionally NULL)
 
724
 * @param[out] num_bands number of bands (optionally NULL)
 
725
 * @param[out] band_sizes array containing the number of bins in each band (optionally NULL)
 
726
 */
 
727
static void decode_band_structure(GetBitContext *gbc, int blk, int eac3,
 
728
                                  int ecpl, int start_subband, int end_subband,
 
729
                                  const uint8_t *default_band_struct,
 
730
                                  uint8_t *band_struct, int *num_subbands,
 
731
                                  int *num_bands, int *band_sizes)
 
732
{
 
733
    int subbnd, bnd, n_subbands, n_bands, bnd_sz[22];
 
734
 
 
735
    n_subbands = end_subband - start_subband;
 
736
 
 
737
    /* decode band structure from bitstream or use default */
 
738
    if (!eac3 || get_bits1(gbc)) {
 
739
        for (subbnd = 0; subbnd < n_subbands - 1; subbnd++) {
 
740
            band_struct[subbnd] = get_bits1(gbc);
 
741
        }
 
742
    } else if (!blk) {
 
743
        memcpy(band_struct,
 
744
               &default_band_struct[start_subband+1],
 
745
               n_subbands-1);
 
746
    }
 
747
    band_struct[n_subbands-1] = 0;
 
748
 
 
749
    /* calculate number of bands and band sizes based on band structure.
 
750
       note that the first 4 subbands in enhanced coupling span only 6 bins
 
751
       instead of 12. */
 
752
    if (num_bands || band_sizes ) {
 
753
        n_bands = n_subbands;
 
754
        bnd_sz[0] = ecpl ? 6 : 12;
 
755
        for (bnd = 0, subbnd = 1; subbnd < n_subbands; subbnd++) {
 
756
            int subbnd_size = (ecpl && subbnd < 4) ? 6 : 12;
 
757
            if (band_struct[subbnd-1]) {
 
758
                n_bands--;
 
759
                bnd_sz[bnd] += subbnd_size;
 
760
            } else {
 
761
                bnd_sz[++bnd] = subbnd_size;
 
762
            }
 
763
        }
 
764
    }
 
765
 
 
766
    /* set optional output params */
 
767
    if (num_subbands)
 
768
        *num_subbands = n_subbands;
 
769
    if (num_bands)
 
770
        *num_bands = n_bands;
 
771
    if (band_sizes)
 
772
        memcpy(band_sizes, bnd_sz, sizeof(int)*n_bands);
 
773
}
 
774
 
 
775
/**
714
776
 * Decode a single audio block from the AC-3 bitstream.
715
777
 */
716
778
static int decode_audio_block(AC3DecodeContext *s, int blk)
772
834
            s->cpl_in_use[blk] = get_bits1(gbc);
773
835
        if (s->cpl_in_use[blk]) {
774
836
            /* coupling in use */
775
 
            int cpl_begin_freq, cpl_end_freq;
 
837
            int cpl_start_subband, cpl_end_subband;
776
838
 
777
839
            if (channel_mode < AC3_CHMODE_STEREO) {
778
840
                av_log(s->avctx, AV_LOG_ERROR, "coupling not allowed in mono or dual-mono\n");
801
863
 
802
864
            /* coupling frequency range */
803
865
            /* TODO: modify coupling end freq if spectral extension is used */
804
 
            cpl_begin_freq = get_bits(gbc, 4);
805
 
            cpl_end_freq = get_bits(gbc, 4);
806
 
            if (3 + cpl_end_freq - cpl_begin_freq < 0) {
807
 
                av_log(s->avctx, AV_LOG_ERROR, "3+cplendf = %d < cplbegf = %d\n", 3+cpl_end_freq, cpl_begin_freq);
 
866
            cpl_start_subband = get_bits(gbc, 4);
 
867
            cpl_end_subband   = get_bits(gbc, 4) + 3;
 
868
            s->num_cpl_subbands = cpl_end_subband - cpl_start_subband;
 
869
            if (s->num_cpl_subbands < 0) {
 
870
                av_log(s->avctx, AV_LOG_ERROR, "invalid coupling range (%d > %d)\n",
 
871
                       cpl_start_subband, cpl_end_subband);
808
872
                return -1;
809
873
            }
810
 
            s->num_cpl_bands = s->num_cpl_subbands = 3 + cpl_end_freq - cpl_begin_freq;
811
 
            s->start_freq[CPL_CH] = cpl_begin_freq * 12 + 37;
812
 
            s->end_freq[CPL_CH] = cpl_end_freq * 12 + 73;
813
 
 
814
 
            /* coupling band structure */
815
 
            if (!s->eac3 || get_bits1(gbc)) {
816
 
                for (bnd = 0; bnd < s->num_cpl_subbands - 1; bnd++) {
817
 
                    s->cpl_band_struct[bnd] = get_bits1(gbc);
818
 
                }
819
 
            } else if (!blk) {
820
 
                memcpy(s->cpl_band_struct,
821
 
                       &ff_eac3_default_cpl_band_struct[cpl_begin_freq+1],
822
 
                       s->num_cpl_subbands-1);
823
 
            }
824
 
            s->cpl_band_struct[s->num_cpl_subbands-1] = 0;
825
 
 
826
 
            /* calculate number of coupling bands based on band structure */
827
 
            for (bnd = 0; bnd < s->num_cpl_subbands-1; bnd++) {
828
 
                s->num_cpl_bands -= s->cpl_band_struct[bnd];
829
 
            }
 
874
            s->start_freq[CPL_CH] = cpl_start_subband * 12 + 37;
 
875
            s->end_freq[CPL_CH]   = cpl_end_subband   * 12 + 37;
 
876
 
 
877
           decode_band_structure(gbc, blk, s->eac3, 0,
 
878
                                 cpl_start_subband, cpl_end_subband,
 
879
                                 ff_eac3_default_cpl_band_struct,
 
880
                                 s->cpl_band_struct, &s->num_cpl_subbands,
 
881
                                 &s->num_cpl_bands, NULL);
830
882
        } else {
831
883
            /* coupling not in use */
832
884
            for (ch = 1; ch <= fbw_channels; ch++) {
916
968
            else {
917
969
                int bandwidth_code = get_bits(gbc, 6);
918
970
                if (bandwidth_code > 60) {
919
 
                    av_log(s->avctx, AV_LOG_ERROR, "bandwidth code = %d > 60", bandwidth_code);
 
971
                    av_log(s->avctx, AV_LOG_ERROR, "bandwidth code = %d > 60\n", bandwidth_code);
920
972
                    return -1;
921
973
                }
922
974
                s->end_freq[ch] = bandwidth_code * 3 + 73;