Merge commit '45ff7c93dd84a254cc96acc589e5ac3d7bd16bce'
authorMichael Niedermayer <michaelni@gmx.at>
Tue, 16 Sep 2014 18:31:02 +0000 (20:31 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Tue, 16 Sep 2014 18:31:02 +0000 (20:31 +0200)
* commit '45ff7c93dd84a254cc96acc589e5ac3d7bd16bce':
  dca: K&R formatting cosmetics

Conflicts:
libavcodec/dca_parser.c
libavcodec/dcadec.c

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

Simple merge
@@@ -35,9 -35,9 +35,9 @@@ typedef struct DCAParseContext 
  } DCAParseContext;
  
  #define IS_MARKER(state, i, buf, buf_size) \
-  ((state == DCA_MARKER_14B_LE && (i < buf_size-2) && (buf[i+1] & 0xF0) == 0xF0 && buf[i+2] == 0x07) \
-  || (state == DCA_MARKER_14B_BE && (i < buf_size-2) && buf[i+1] == 0x07 && (buf[i+2] & 0xF0) == 0xF0) \
-  || state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE || state == DCA_HD_MARKER)
+     ((state == DCA_MARKER_14B_LE && (i < buf_size - 2) && (buf[i + 1] & 0xF0) == 0xF0 &&  buf[i + 2]         == 0x07) || \
+      (state == DCA_MARKER_14B_BE && (i < buf_size - 2) &&  buf[i + 1]         == 0x07 && (buf[i + 2] & 0xF0) == 0xF0) || \
 -      state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE)
++      state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE || state == DCA_HD_MARKER)
  
  /**
   * Find the end of the current frame in the bitstream.
@@@ -58,8 -58,12 +58,8 @@@ static int dca_find_frame_end(DCAParseC
          for (i = 0; i < buf_size; i++) {
              state = (state << 8) | buf[i];
              if (IS_MARKER(state, i, buf, buf_size)) {
 -                if (pc1->lastmarker && state == pc1->lastmarker) {
 -                    start_found = 1;
 -                    i++;
 -                    break;
 -                } else if (!pc1->lastmarker) {
 +                if (!pc1->lastmarker || state == pc1->lastmarker || pc1->lastmarker == DCA_HD_MARKER) {
-                     start_found = 1;
+                     start_found     = 1;
                      pc1->lastmarker = state;
                      i++;
                      break;
              state = (state << 8) | buf[i];
              if (state == DCA_HD_MARKER && !pc1->hd_pos)
                  pc1->hd_pos = pc1->size;
 -            if (state == pc1->lastmarker && IS_MARKER(state, i, buf, buf_size)) {
 +            if (IS_MARKER(state, i, buf, buf_size) && (state == pc1->lastmarker || pc1->lastmarker == DCA_HD_MARKER)) {
-                 if(pc1->framesize > pc1->size)
+                 if (pc1->framesize > pc1->size)
                      continue;
                  pc->frame_start_found = 0;
-                 pc->state = -1;
-                 pc1->size = 0;
+                 pc->state             = -1;
+                 pc1->size             = 0;
                  return i - 3;
              }
          }
Simple merge
  #include "libavutil/mathematics.h"
  #include "libavutil/opt.h"
  #include "libavutil/samplefmt.h"
  #include "avcodec.h"
- #include "fft.h"
- #include "get_bits.h"
- #include "dcadata.h"
- #include "dcahuff.h"
  #include "dca.h"
- #include "mathops.h"
- #include "synth_filter.h"
+ #include "dcadata.h"
  #include "dcadsp.h"
+ #include "dcahuff.h"
+ #include "fft.h"
  #include "fmtconvert.h"
+ #include "get_bits.h"
  #include "internal.h"
 -#include "put_bits.h"
+ #include "mathops.h"
+ #include "synth_filter.h"
  
  #if ARCH_ARM
  #   include "arm/dca.h"
@@@ -816,12 -650,11 +816,11 @@@ static int dca_parse_frame_header(DCACo
  #endif
  
      /* Primary audio coding header */
-     s->subframes         = get_bits(&s->gb, 4) + 1;
+     s->subframes = get_bits(&s->gb, 4) + 1;
  
 -    return dca_parse_audio_coding_header(s, 0);
 +    return dca_parse_audio_coding_header(s, 0, 0);
  }
  
  static inline int get_scale(GetBitContext *gb, int level, int value, int log2range)
  {
      if (level < 5) {
@@@ -994,9 -827,8 +993,9 @@@ static int dca_subframe_header(DCAConte
  
      /* Low frequency effect data */
      if (!base_channel && s->lfe) {
 +        int quant7;
          /* LFE samples */
-         int lfe_samples = 2 * s->lfe * (4 + block_index);
+         int lfe_samples    = 2 * s->lfe * (4 + block_index);
          int lfe_end_sample = 2 * s->lfe * (4 + block_index + s->subsubframes[s->current_subframe]);
          float lfe_scale;
  
@@@ -2129,9 -1714,8 +2132,9 @@@ static int dca_decode_frame(AVCodecCont
  {
      AVFrame *frame     = data;
      const uint8_t *buf = avpkt->data;
-     int buf_size = avpkt->size;
+     int buf_size       = avpkt->size;
 -
 +    int channel_mask;
 +    int channel_layout;
      int lfe_samples;
      int num_core_channels = 0;
      int i, ret;
  
      /* only scan for extensions if ext_descr was unknown or indicated a
       * supported XCh extension */
 -    if (s->core_ext_mask < 0 || s->core_ext_mask & DCA_EXT_XCH) {
 +    if (s->core_ext_mask < 0 || s->core_ext_mask & (DCA_EXT_XCH | DCA_EXT_XXCH)) {
          /* if ext_descr was unknown, clear s->core_ext_mask so that the
           * extensions scan can fill it up */
          s->core_ext_mask = FFMAX(s->core_ext_mask, 0);
  
  #if FF_API_REQUEST_CHANNELS
  FF_DISABLE_DEPRECATION_WARNINGS
 -        if (s->xch_present && !s->xch_disable &&
 -            (!avctx->request_channels ||
 -             avctx->request_channels > num_core_channels + !!s->lfe)) {
 +            if (s->xch_present && !s->xch_disable &&
 +                (!avctx->request_channels ||
 +                 avctx->request_channels > num_core_channels + !!s->lfe)) {
  FF_ENABLE_DEPRECATION_WARNINGS
  #else
 -        if (s->xch_present && !s->xch_disable) {
 +            if (s->xch_present && !s->xch_disable) {
  #endif
 -            avctx->channel_layout |= AV_CH_BACK_CENTER;
 -            if (s->lfe) {
 -                avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
 -                s->channel_order_tab = dca_channel_reorder_lfe_xch[s->amode];
 +                avctx->channel_layout |= AV_CH_BACK_CENTER;
 +                if (s->lfe) {
 +                    avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
 +                    s->channel_order_tab = dca_channel_reorder_lfe_xch[s->amode];
 +                } else {
 +                    s->channel_order_tab = dca_channel_reorder_nolfe_xch[s->amode];
 +                }
 +                if (s->channel_order_tab[s->xch_base_channel] < 0)
 +                    return AVERROR_INVALIDDATA;
              } else {
-                 channels = num_core_channels + !!s->lfe;
 -                s->channel_order_tab = dca_channel_reorder_nolfe_xch[s->amode];
++                channels       = num_core_channels + !!s->lfe;
 +                s->xch_present = 0; /* disable further xch processing */
 +                if (s->lfe) {
 +                    avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
 +                    s->channel_order_tab = dca_channel_reorder_lfe[s->amode];
 +                } else
 +                    s->channel_order_tab = dca_channel_reorder_nolfe[s->amode];
 +            }
 +
 +            if (channels > !!s->lfe &&
 +                s->channel_order_tab[channels - 1 - !!s->lfe] < 0)
 +                return AVERROR_INVALIDDATA;
 +
 +            if (av_get_channel_layout_nb_channels(avctx->channel_layout) != channels) {
 +                av_log(avctx, AV_LOG_ERROR, "Number of channels %d mismatches layout %d\n", channels, av_get_channel_layout_nb_channels(avctx->channel_layout));
 +                return AVERROR_INVALIDDATA;
              }
-                 channels = 2;
-                 s->output = s->prim_channels == 2 ? s->amode : DCA_STEREO;
 +
 +            if (num_core_channels + !!s->lfe > 2 &&
 +                avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
++                channels              = 2;
++                s->output             = s->prim_channels == 2 ? s->amode : DCA_STEREO;
 +                avctx->channel_layout = AV_CH_LAYOUT_STEREO;
 +            }
 +            else if (avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE) {
 +                static const int8_t dca_channel_order_native[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
 +                s->channel_order_tab = dca_channel_order_native;
 +            }
 +            s->lfe_index = dca_lfe_index[s->amode];
          } else {
 -            channels       = num_core_channels + !!s->lfe;
 -            s->xch_present = 0; /* disable further xch processing */
 -            if (s->lfe) {
 -                avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
 -                s->channel_order_tab = dca_channel_reorder_lfe[s->amode];
 -            } else
 -                s->channel_order_tab = dca_channel_reorder_nolfe[s->amode];
 +            av_log(avctx, AV_LOG_ERROR,
 +                   "Non standard configuration %d !\n", s->amode);
 +            return AVERROR_INVALIDDATA;
          }
  
 -        if (channels > !!s->lfe &&
 -            s->channel_order_tab[channels - 1 - !!s->lfe] < 0)
 -            return AVERROR_INVALIDDATA;
 +        s->xxch_dmix_embedded = 0;
 +    } else {
 +        /* we only get here if an XXCH channel set can be added to the mix */
 +        channel_mask = s->xxch_core_spkmask;
 +
 +        if (avctx->request_channels > 0
 +            && avctx->request_channels < s->prim_channels) {
 +            channels = num_core_channels + !!s->lfe;
 +            for (i = 0; i < s->xxch_chset && channels + s->xxch_chset_nch[i]
 +                                              <= avctx->request_channels; i++) {
 +                channels += s->xxch_chset_nch[i];
 +                channel_mask |= s->xxch_spk_masks[i];
 +            }
 +        } else {
 +            channels = s->prim_channels + !!s->lfe;
 +            for (i = 0; i < s->xxch_chset; i++) {
 +                channel_mask |= s->xxch_spk_masks[i];
 +            }
 +        }
  
 -        if (num_core_channels + !!s->lfe > 2 &&
 -            avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
 -            channels              = 2;
 -            s->output             = s->prim_channels == 2 ? s->amode : DCA_STEREO;
 -            avctx->channel_layout = AV_CH_LAYOUT_STEREO;
 +        /* Given the DTS spec'ed channel mask, generate an avcodec version */
 +        channel_layout = 0;
 +        for (i = 0; i < s->xxch_nbits_spk_mask; ++i) {
 +            if (channel_mask & (1 << i)) {
 +                channel_layout |= map_xxch_to_native[i];
 +            }
 +        }
  
 -            /* 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)) {
 -                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];
 +        /* make sure that we have managed to get equivalent dts/avcodec channel
 +         * masks in some sense -- unfortunately some channels could overlap */
 +        if (av_popcount(channel_mask) != av_popcount(channel_layout)) {
 +            av_log(avctx, AV_LOG_DEBUG,
 +                   "DTS-XXCH: Inconsistent avcodec/dts channel layouts\n");
 +            return AVERROR_INVALIDDATA;
 +        }
 +
 +        avctx->channel_layout = channel_layout;
 +
 +        if (!(avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE)) {
 +            /* Estimate DTS --> avcodec ordering table */
 +            for (chset = -1, j = 0; chset < s->xxch_chset; ++chset) {
 +                mask = chset >= 0 ? s->xxch_spk_masks[chset]
 +                                  : s->xxch_core_spkmask;
 +                for (i = 0; i < s->xxch_nbits_spk_mask; i++) {
 +                    if (mask & ~(DCA_XXCH_LFE1 | DCA_XXCH_LFE2) & (1 << i)) {
 +                        lavc = map_xxch_to_native[i];
 +                        posn = av_popcount(channel_layout & (lavc - 1));
 +                        s->xxch_order_tab[j++] = posn;
 +                    }
                  }
 +
              }
 -            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");
 +
 +            s->lfe_index = av_popcount(channel_layout & (AV_CH_LOW_FREQUENCY-1));
 +        } else { /* native ordering */
 +            for (i = 0; i < channels; i++)
 +                s->xxch_order_tab[i] = i;
 +
 +            s->lfe_index = channels - 1;
          }
 -    } else {
 -        av_log(avctx, AV_LOG_ERROR, "Non standard configuration %d !\n", s->amode);
 -        return AVERROR_INVALIDDATA;
 +
 +        s->channel_order_tab = s->xxch_order_tab;
 +    }
 +
 +    if (avctx->channels != channels) {
 +        if (avctx->channels)
 +            av_log(avctx, AV_LOG_INFO, "Number of channels changed in DCA decoder (%d -> %d)\n", avctx->channels, channels);
 +        avctx->channels = channels;
      }
 -    avctx->channels = channels;
  
      /* get output buffer */
      frame->nb_samples = 256 * (s->sample_blocks / 8);
 -    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
 -        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
 +    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
          return ret;
-     samples_flt = (float **)frame->extended_data;
 -    }
+     samples_flt = (float **) frame->extended_data;
  
      /* allocate buffer for extra channels if downmixing */
      if (avctx->channels < full_channels) {
Simple merge
Simple merge