]> granicus.if.org Git - handbrake/commitdiff
decavcodec: only allow in-decoder downmix if it matches the requested mix levels.
authorRodeo <tdskywalker@gmail.com>
Wed, 15 Jan 2014 00:09:56 +0000 (00:09 +0000)
committerRodeo <tdskywalker@gmail.com>
Wed, 15 Jan 2014 00:09:56 +0000 (00:09 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5973 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/decavcodec.c

index 42aa7e3c3e17c1562fac7a2f353be5b9a683a549..ca33d41721fad35f194267a76a28148bfd06b469 100644 (file)
@@ -302,31 +302,58 @@ static int decavcodecaInit( hb_work_object_t * w, hb_job_t * job )
             hb_error("decavcodecaInit: hb_audio_resample_init() failed");
             return 1;
         }
-        // some decoders can downmix using embedded coefficients,
-        // or dedicated audio substreams for a specific channel layout
-        switch (w->audio->config.out.mixdown)
+        /*
+         * Some audio decoders can downmix using embedded coefficients,
+         * or dedicated audio substreams for a specific channel layout.
+         *
+         * But some will e.g. use normalized mix coefficients unconditionally,
+         * so we need to make sure this matches what the user actually requested.
+         */
+        int avcodec_downmix = 0;
+        switch (w->codec_param)
         {
-            case HB_AMIXDOWN_MONO:
-                if (w->codec_param == AV_CODEC_ID_TRUEHD)
-                {
-                    // libavcodec can't decode TrueHD Mono (bug #356)
-                    // work around it by requesting Stereo and downmixing
-                    pv->context->request_channel_layout = AV_CH_LAYOUT_STEREO;
-                    break;
-                }
-                pv->context->request_channel_layout = AV_CH_LAYOUT_MONO;
+            case AV_CODEC_ID_AC3:
+            case AV_CODEC_ID_EAC3:
+                avcodec_downmix = w->audio->config.out.normalize_mix_level != 0;
+                break;
+            case AV_CODEC_ID_DTS:
+                avcodec_downmix = w->audio->config.out.normalize_mix_level == 0;
                 break;
-            // request 5.1 before downmixing to dpl1/dpl2
-            case HB_AMIXDOWN_DOLBY:
-            case HB_AMIXDOWN_DOLBYPLII:
-                pv->context->request_channel_layout = AV_CH_LAYOUT_5POINT1;
+            case AV_CODEC_ID_TRUEHD:
+                avcodec_downmix = (w->audio->config.out.normalize_mix_level == 0     ||
+                                   w->audio->config.out.mixdown == HB_AMIXDOWN_MONO  ||
+                                   w->audio->config.out.mixdown == HB_AMIXDOWN_DOLBY ||
+                                   w->audio->config.out.mixdown == HB_AMIXDOWN_DOLBYPLII);
                 break;
-            // request the layout corresponding to the selected mixdown
             default:
-                pv->context->request_channel_layout =
-                    hb_ff_mixdown_xlat(w->audio->config.out.mixdown, NULL);
                 break;
         }
+        if (avcodec_downmix)
+        {
+            switch (w->audio->config.out.mixdown)
+            {
+                case HB_AMIXDOWN_MONO:
+                    if (w->codec_param == AV_CODEC_ID_TRUEHD)
+                    {
+                        // libavcodec can't decode TrueHD Mono (bug #356)
+                        // work around it by requesting Stereo and downmixing
+                        pv->context->request_channel_layout = AV_CH_LAYOUT_STEREO;
+                        break;
+                    }
+                    pv->context->request_channel_layout = AV_CH_LAYOUT_MONO;
+                    break;
+                // request 5.1 before downmixing to dpl1/dpl2
+                case HB_AMIXDOWN_DOLBY:
+                case HB_AMIXDOWN_DOLBYPLII:
+                    pv->context->request_channel_layout = AV_CH_LAYOUT_5POINT1;
+                    break;
+                // request the layout corresponding to the selected mixdown
+                default:
+                    pv->context->request_channel_layout =
+                        hb_ff_mixdown_xlat(w->audio->config.out.mixdown, NULL);
+                    break;
+            }
+        }
     }
 
     // Set decoder opts...