Merge commit '6b7b8585d73548f08b98959df39d80b97677662f'
authorMichael Niedermayer <michaelni@gmx.at>
Fri, 23 May 2014 17:01:12 +0000 (19:01 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Fri, 23 May 2014 17:01:12 +0000 (19:01 +0200)
* commit '6b7b8585d73548f08b98959df39d80b97677662f':
  dca: Convert dca_dmixtable to integers

Conflicts:
libavcodec/dcadec.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/dcadata.h
libavcodec/dcadec.c

Simple merge
@@@ -2076,33 -1693,15 +2076,40 @@@ static void dca_exss_parse_header(DCACo
  
      /* not parsed further, we were only interested in the extensions mask
       * from the asset header */
 +
 +        j = get_bits_count(&s->gb);
 +        if (start_posn + hdrsize * 8 > j)
 +            skip_bits_long(&s->gb, start_posn + hdrsize * 8 - j);
 +
 +        for (i = 0; i < num_assets; i++) {
 +            start_posn = get_bits_count(&s->gb);
 +            mkr        = get_bits_long(&s->gb, 32);
 +
 +            /* parse extensions that we know about */
 +            if (mkr == 0x655e315e) {
 +                dca_xbr_parse_frame(s);
 +            } else if (mkr == 0x47004a03) {
 +                dca_xxch_decode_frame(s);
 +                s->core_ext_mask |= DCA_EXT_XXCH; /* xxx use for chan reordering */
 +            } else {
 +                av_log(s->avctx, AV_LOG_DEBUG,
 +                       "DTS-ExSS: unknown marker = 0x%08x\n", mkr);
 +            }
 +
 +            /* skip to end of block */
 +            j = get_bits_count(&s->gb);
 +            if (start_posn + asset_size[i] * 8 > j)
 +                skip_bits_long(&s->gb, start_posn + asset_size[i] * 8 - j);
 +        }
  }
  
+ static float dca_dmix_code(unsigned code)
+ {
+     int sign = (code >> 8) - 1;
+     code &= 0xff;
+     return ldexpf((dca_dmixtable[code] ^ sign) - sign, -15);
+ }
  /**
   * Main frame decoding function
   * FIXME add arguments
@@@ -2162,55 -1751,6 +2169,49 @@@ static int dca_decode_frame(AVCodecCont
      /* record number of core channels incase less than max channels are requested */
      num_core_channels = s->prim_channels;
  
-                 int sign, code;
 +    if (s->prim_channels + !!s->lfe > 2 &&
 +        avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
 +            /* Stereo downmix coefficients
 +             *
 +             * The decoder can only downmix to 2-channel, so we need to ensure
 +             * embedded downmix coefficients are actually targeting 2-channel.
 +             */
 +            if (s->core_downmix && (s->core_downmix_amode == DCA_STEREO ||
 +                                    s->core_downmix_amode == DCA_STEREO_TOTAL)) {
-                     sign = s->core_downmix_codes[i][0] & 0x100 ? 1 : -1;
-                     code = s->core_downmix_codes[i][0] & 0x0FF;
-                     s->downmix_coef[i][0] = (!code ? 0.0f :
-                                              sign * dca_dmixtable[code - 1]);
-                     sign = s->core_downmix_codes[i][1] & 0x100 ? 1 : -1;
-                     code = s->core_downmix_codes[i][1] & 0x0FF;
-                     s->downmix_coef[i][1] = (!code ? 0.0f :
-                                              sign * dca_dmixtable[code - 1]);
 +                for (i = 0; i < num_core_channels + !!s->lfe; i++) {
++                    /* Range checked earlier */
++                    s->downmix_coef[i][0] = dca_dmix_code(s->core_downmix_codes[i][0]);
++                    s->downmix_coef[i][1] = dca_dmix_code(s->core_downmix_codes[i][1]);
 +                }
 +                s->output = s->core_downmix_amode;
 +            } else {
 +                int am = s->amode & DCA_CHANNEL_MASK;
 +                if (am >= FF_ARRAY_ELEMS(dca_default_coeffs)) {
 +                    av_log(s->avctx, AV_LOG_ERROR,
 +                           "Invalid channel mode %d\n", am);
 +                    return AVERROR_INVALIDDATA;
 +                }
 +                if (num_core_channels + !!s->lfe >
 +                    FF_ARRAY_ELEMS(dca_default_coeffs[0])) {
 +                    avpriv_request_sample(s->avctx, "Downmixing %d channels",
 +                                          s->prim_channels + !!s->lfe);
 +                    return AVERROR_PATCHWELCOME;
 +                }
 +                for (i = 0; i < num_core_channels + !!s->lfe; i++) {
 +                    s->downmix_coef[i][0] = dca_default_coeffs[am][i][0];
 +                    s->downmix_coef[i][1] = dca_default_coeffs[am][i][1];
 +                }
 +            }
 +            av_dlog(s->avctx, "Stereo downmix coeffs:\n");
 +            for (i = 0; i < num_core_channels + !!s->lfe; i++) {
 +                av_dlog(s->avctx, "L, input channel %d = %f\n", i,
 +                        s->downmix_coef[i][0]);
 +                av_dlog(s->avctx, "R, input channel %d = %f\n", i,
 +                        s->downmix_coef[i][1]);
 +            }
 +            av_dlog(s->avctx, "\n");
 +    }
 +
      if (s->ext_coding)
          s->core_ext_mask = dca_ext_audio_descr_mask[s->ext_descr];
      else