]> granicus.if.org Git - handbrake/commitdiff
Move mixdown-> channel_layout/matrix_encoding translation to hb_audio_resample_init().
authorRodeo <tdskywalker@gmail.com>
Mon, 27 Aug 2012 22:00:28 +0000 (22:00 +0000)
committerRodeo <tdskywalker@gmail.com>
Mon, 27 Aug 2012 22:00:28 +0000 (22:00 +0000)
Unlike hb_audio_remap, hb_audio_resample will never be used in situations where we don't have a mixdown.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4923 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/audio_resample.c
libhb/audio_resample.h
libhb/deca52.c
libhb/decavcodec.c
libhb/declpcm.c
libhb/encavcodecaudio.c

index 1e5e10556c5f9e3abc16b521672afea3fddb27b8..44f2a0144d89cbc52dc7121db883253ed3ae2702 100644 (file)
@@ -11,9 +11,8 @@
 #include "hbffmpeg.h"
 #include "audio_resample.h"
 
-hb_audio_resample_t* hb_audio_resample_init(enum AVSampleFormat output_sample_fmt,
-                                            uint64_t output_channel_layout,
-                                            enum AVMatrixEncoding matrix_encoding,
+hb_audio_resample_t* hb_audio_resample_init(enum AVSampleFormat sample_fmt,
+                                            int hb_amixdown, int do_remix,
                                             int normalize_mix_level)
 {
     hb_audio_resample_t *resample = malloc(sizeof(hb_audio_resample_t));
@@ -23,22 +22,31 @@ hb_audio_resample_t* hb_audio_resample_init(enum AVSampleFormat output_sample_fm
         return NULL;
     }
 
-    resample->out.sample_fmt          = output_sample_fmt;
-    resample->out.sample_size         =
-        av_get_bytes_per_sample(output_sample_fmt);
-    resample->out.channel_layout      = output_channel_layout;
-    resample->out.channels            =
-        av_get_channel_layout_nb_channels(output_channel_layout);
+    // convert mixdown to channel_layout/matrix_encoding combo
+    int channels, matrix_encoding;
+    uint64_t channel_layout = hb_ff_mixdown_xlat(hb_amixdown, &matrix_encoding);
+    channels = av_get_channel_layout_nb_channels(channel_layout);
+
+    // requested channel_layout
+    resample->out.channels            = channels;
+    resample->out.channel_layout      = channel_layout;
     resample->out.matrix_encoding     = matrix_encoding;
     resample->out.normalize_mix_level = normalize_mix_level;
-    resample->resample_needed         = 0;
-    resample->avresample              = NULL;
+
+    // requested sample_fmt
+    resample->out.sample_fmt          = sample_fmt;
+    resample->out.sample_size         = av_get_bytes_per_sample(sample_fmt);
 
     // set default input characteristics
-    resample->in.sample_fmt         = resample->out.sample_fmt;
-    resample->in.channel_layout     = resample->out.channel_layout;
-    resample->in.center_mix_level   = HB_MIXLEV_DEFAULT;
-    resample->in.surround_mix_level = HB_MIXLEV_DEFAULT;
+    resample->in.sample_fmt           = resample->out.sample_fmt;
+    resample->in.channel_layout       = resample->out.channel_layout;
+    resample->in.center_mix_level     = HB_MIXLEV_DEFAULT;
+    resample->in.surround_mix_level   = HB_MIXLEV_DEFAULT;
+
+    // by default, no conversion needed
+    resample->resample_needed         = 0;
+    resample->avresample              = NULL;
+    resample->do_remix                = !!do_remix;
 
     return resample;
 }
@@ -47,7 +55,7 @@ void hb_audio_resample_set_channel_layout(hb_audio_resample_t *resample,
                                           uint64_t channel_layout,
                                           int channels)
 {
-    if (resample != NULL)
+    if (resample != NULL && resample->do_remix)
     {
         channel_layout = hb_ff_layout_xlat(channel_layout, channels);
         if (channel_layout == AV_CH_LAYOUT_STEREO_DOWNMIX)
@@ -63,7 +71,7 @@ void hb_audio_resample_set_mix_levels(hb_audio_resample_t *resample,
                                       double surround_mix_level,
                                       double center_mix_level)
 {
-    if (resample != NULL)
+    if (resample != NULL && resample->do_remix)
     {
         resample->in.center_mix_level   = center_mix_level;
         resample->in.surround_mix_level = surround_mix_level;
index c853fc2e26bfd2b179bddbbb772ee2979ac16f4f..3a01d8696dc23eaf09127db953bd3d0b99549a41 100644 (file)
@@ -27,6 +27,7 @@
 
 typedef struct
 {
+    int do_remix;
     int resample_needed;
     AVAudioResampleContext *avresample;
 
@@ -59,14 +60,15 @@ typedef struct
 } hb_audio_resample_t;
 
 /* Initialize an hb_audio_resample_t for converting audio to the requested
- * sample_fmt and channel_layout, using the specified matrix_encoding.
+ * sample_fmt and mixdown.
  *
  * Also sets the default audio input characteristics, so that they are the same
  * as the output characteristics (no conversion needed).
+ *
+ * If do_remix is 0, it will be assumed that any remixing was *already* done.
  */
-hb_audio_resample_t* hb_audio_resample_init(enum AVSampleFormat output_sample_fmt,
-                                            uint64_t output_channel_layout,
-                                            enum AVMatrixEncoding matrix_encoding,
+hb_audio_resample_t* hb_audio_resample_init(enum AVSampleFormat sample_fmt,
+                                            int hb_amixdown, int do_remix,
                                             int normalize_mix_level);
 
 /* The following functions set the audio input characteristics.
index 9ad6038616542ebe1ba085d7113b91616f234443..66e936dd2b5ecd6b8e4a8835dead737953437c83 100644 (file)
@@ -139,10 +139,10 @@ static int deca52Init(hb_work_object_t *w, hb_job_t *job)
         pv->dynamic_range_compression =
             audio->config.out.dynamic_range_compression;
 
-        int mode;
-        uint64_t layout = hb_ff_mixdown_xlat(audio->config.out.mixdown, &mode);
-        pv->resample = hb_audio_resample_init(AV_SAMPLE_FMT_FLT, layout, mode,
-                                              audio->config.out.normalize_mix_level);
+        pv->resample =
+            hb_audio_resample_init(AV_SAMPLE_FMT_FLT,
+                                   audio->config.out.mixdown, 1,
+                                   audio->config.out.normalize_mix_level);
         if (pv->resample == NULL)
         {
             hb_error("deca52Init: hb_audio_resample_init() failed");
index 4dc1e7388b7fac327a039a61d7403fc423ba71e1..a5312273d7940043e2e05826b583f712a478194e 100644 (file)
@@ -189,11 +189,10 @@ static int decavcodecaInit( hb_work_object_t * w, hb_job_t * job )
     /* Downmixing & sample_fmt conversion */
     if (!(w->audio->config.out.codec & HB_ACODEC_PASS_FLAG))
     {
-        int mode;
-        uint64_t layout = hb_ff_mixdown_xlat(w->audio->config.out.mixdown,
-                                             &mode);
-        pv->resample = hb_audio_resample_init(AV_SAMPLE_FMT_FLT, layout, mode,
-                                              w->audio->config.out.normalize_mix_level);
+        pv->resample =
+            hb_audio_resample_init(AV_SAMPLE_FMT_FLT,
+                                   w->audio->config.out.mixdown, 1,
+                                   w->audio->config.out.normalize_mix_level);
         if (pv->resample == NULL)
         {
             hb_error("decavcodecaInit: hb_audio_resample_init() failed");
index 85a47c313952c4ba8334b499960e5b2f3180e9e6..0cb5726a5264b60d859063364938e9aec19bbd80 100644 (file)
@@ -162,10 +162,10 @@ static int declpcmInit( hb_work_object_t * w, hb_job_t * job )
     w->private_data = pv;
     pv->job = job;
 
-    int mode;
-    uint64_t layout = hb_ff_mixdown_xlat(w->audio->config.out.mixdown, &mode);
-    pv->resample = hb_audio_resample_init(AV_SAMPLE_FMT_FLT, layout, mode,
-                                          w->audio->config.out.normalize_mix_level);
+    pv->resample =
+        hb_audio_resample_init(AV_SAMPLE_FMT_FLT,
+                               w->audio->config.out.mixdown, 1,
+                               w->audio->config.out.normalize_mix_level);
     if (pv->resample == NULL)
     {
         hb_error("declpcmInit: hb_audio_resample_init() failed");
index 3a0af64d212eeeb861144d2669117fcf748ef35d..67f4d23d57ff8c8ff202289406288475621ed80a 100644 (file)
@@ -118,8 +118,7 @@ static int encavcodecaInit(hb_work_object_t *w, hb_job_t *job)
 
     // sample_fmt conversion
     pv->resample = hb_audio_resample_init(context->sample_fmt,
-                                          context->channel_layout,
-                                          AV_MATRIX_ENCODING_NONE, 0);
+                                          audio->config.out.mixdown, 0, 0);
     hb_audio_resample_set_sample_fmt(pv->resample, AV_SAMPLE_FMT_FLT);
     if (hb_audio_resample_update(pv->resample))
     {