]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/dcadec.c
Merge commit '25609b63d2e07d26d610f485a22082d32c96c0f5'
[ffmpeg] / libavcodec / dcadec.c
index bb47ebc1422aab12e70d7e91a95e199452f038d8..fbd5dee5b20082ff3b6ce78c1dc520e75a4580b2 100644 (file)
@@ -400,7 +400,7 @@ typedef struct {
     int scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][2];    ///< scale factors (2 if transient)
     int joint_huff[DCA_PRIM_CHANNELS_MAX];                       ///< joint subband scale factors codebook
     int joint_scale_factor[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< joint subband scale factors
-    int downmix_coef[DCA_PRIM_CHANNELS_MAX][2];                  ///< stereo downmix coefficients
+    float downmix_coef[DCA_PRIM_CHANNELS_MAX][2];                ///< stereo downmix coefficients
     int dynrange_coef;                                           ///< dynamic range coefficient
 
     int high_freq_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS];       ///< VQ encoded high frequency subbands
@@ -958,8 +958,8 @@ static int dca_subframe_header(DCAContext *s, int base_channel, int block_index)
     if (!base_channel && s->prim_channels > 2) {
         if (s->downmix) {
             for (j = base_channel; j < s->prim_channels; j++) {
-                s->downmix_coef[j][0] = get_bits(&s->gb, 7);
-                s->downmix_coef[j][1] = get_bits(&s->gb, 7);
+                s->downmix_coef[j][0] = dca_downmix_coeffs[get_bits(&s->gb, 7)];
+                s->downmix_coef[j][1] = dca_downmix_coeffs[get_bits(&s->gb, 7)];
             }
         } else {
             int am = s->amode & DCA_CHANNEL_MASK;
@@ -975,8 +975,8 @@ static int dca_subframe_header(DCAContext *s, int base_channel, int block_index)
             }
 
             for (j = base_channel; j < s->prim_channels; j++) {
-                s->downmix_coef[j][0] = dca_default_coeffs[am][j][0];
-                s->downmix_coef[j][1] = dca_default_coeffs[am][j][1];
+                s->downmix_coef[j][0] = dca_downmix_coeffs[dca_default_coeffs[am][j][0]];
+                s->downmix_coef[j][1] = dca_downmix_coeffs[dca_default_coeffs[am][j][1]];
             }
         }
     }
@@ -1084,9 +1084,9 @@ static int dca_subframe_header(DCAContext *s, int base_channel, int block_index)
         av_log(s->avctx, AV_LOG_DEBUG, "Downmix coeffs:\n");
         for (j = 0; j < s->prim_channels; j++) {
             av_log(s->avctx, AV_LOG_DEBUG, "Channel 0, %d = %f\n", j,
-                   dca_downmix_coeffs[s->downmix_coef[j][0]]);
+                   s->downmix_coef[j][0]);
             av_log(s->avctx, AV_LOG_DEBUG, "Channel 1, %d = %f\n", j,
-                   dca_downmix_coeffs[s->downmix_coef[j][1]]);
+                   s->downmix_coef[j][1]);
         }
         av_log(s->avctx, AV_LOG_DEBUG, "\n");
     }
@@ -1185,18 +1185,12 @@ static void lfe_interpolation_fir(DCAContext *s, int decimation_select,
     }
 
 static void dca_downmix(float **samples, int srcfmt,
-                        int downmix_coef[DCA_PRIM_CHANNELS_MAX][2],
+                        float coef[DCA_PRIM_CHANNELS_MAX][2],
                         const int8_t *channel_mapping)
 {
     int c, l, r, sl, sr, s;
     int i;
     float t, u, v;
-    float coef[DCA_PRIM_CHANNELS_MAX][2];
-
-    for (i = 0; i < DCA_PRIM_CHANNELS_MAX; i++) {
-        coef[i][0] = dca_downmix_coeffs[downmix_coef[i][0]];
-        coef[i][1] = dca_downmix_coeffs[downmix_coef[i][1]];
-    }
 
     switch (srcfmt) {
     case DCA_MONO:
@@ -1449,7 +1443,8 @@ static int dca_filter_channels(DCAContext *s, int block_index)
     }
 
     /* Down mixing */
-    if (s->avctx->request_channels == 2 && s->prim_channels > 2) {
+    if (s->prim_channels > 2 &&
+        s->avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
         dca_downmix(s->samples_chanptr, s->amode, s->downmix_coef, s->channel_order_tab);
     }
 
@@ -2233,10 +2228,15 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data,
     { /* xxx should also do MA extensions */
         if (s->amode < 16) {
             avctx->channel_layout = dca_core_channel_layout[s->amode];
-
+#if FF_API_REQUEST_CHANNELS
+FF_DISABLE_DEPRECATION_WARNINGS
             if (s->xch_present && (!avctx->request_channels ||
                                    avctx->request_channels
                                    > num_core_channels + !!s->lfe)) {
+FF_ENABLE_DEPRECATION_WARNINGS
+#else
+            if (s->xch_present) {
+#endif
                 avctx->channel_layout |= AV_CH_BACK_CENTER;
                 if (s->lfe) {
                     avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
@@ -2265,7 +2265,8 @@ static int dca_decode_frame(AVCodecContext *avctx, void *data,
                 return AVERROR_INVALIDDATA;
             }
 
-            if (avctx->request_channels == 2 && s->prim_channels > 2) {
+            if (s->prim_channels > 2 &&
+                avctx->request_channel_layout == AV_CH_LAYOUT_STEREO) {
                 channels = 2;
                 s->output = DCA_STEREO;
                 avctx->channel_layout = AV_CH_LAYOUT_STEREO;
@@ -2480,9 +2481,15 @@ static av_cold int dca_decode_init(AVCodecContext *avctx)
     avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
 
     /* allow downmixing to stereo */
-    if (avctx->channels > 2 && avctx->request_channels == 2) {
-        avctx->channels = avctx->request_channels;
-    }
+#if FF_API_REQUEST_CHANNELS
+FF_DISABLE_DEPRECATION_WARNINGS
+    if (avctx->request_channels == 2)
+        avctx->request_channel_layout = AV_CH_LAYOUT_STEREO;
+FF_ENABLE_DEPRECATION_WARNINGS
+#endif
+    if (avctx->channels > 2 &&
+        avctx->request_channel_layout == AV_CH_LAYOUT_STEREO)
+        avctx->channels = 2;
 
     return 0;
 }