[vlc-devel] [PATCH 1/6] aout: split aout_PrepareStereoMode

Thomas Guillem thomas at gllm.fr
Thu Jul 16 14:25:30 CEST 2020


 - aout_PrepareStereoMode() prepares the "stereo-mode" var list and return the
default mode.
 - aout_HasStereoMode() returns true if a mode is available (in "stereo-mode"
   var list)
 - aout_UpdateStereo() does the actual changes.
---
 src/audio_output/output.c | 54 +++++++++++++++++++++++++--------------
 1 file changed, 35 insertions(+), 19 deletions(-)

diff --git a/src/audio_output/output.c b/src/audio_output/output.c
index 99fa946f141..ee3e37678a2 100644
--- a/src/audio_output/output.c
+++ b/src/audio_output/output.c
@@ -396,24 +396,16 @@ void aout_Release(audio_output_t *aout)
     vlc_object_delete(VLC_OBJECT(aout));
 }
 
-static void aout_PrepareStereoMode (audio_output_t *aout,
-                                    audio_sample_format_t *restrict fmt,
-                                    aout_filters_cfg_t *filters_cfg,
-                                    audio_channel_type_t input_chan_type,
-                                    unsigned i_nb_input_channels)
+static int aout_PrepareStereoMode(audio_output_t *aout,
+                                  const audio_sample_format_t *restrict fmt,
+                                  audio_channel_type_t input_chan_type,
+                                  unsigned i_nb_input_channels)
 {
-    aout_owner_t *owner = aout_owner (aout);
-
     /* Fill Stereo mode choices */
-    var_Change(aout, "stereo-mode", VLC_VAR_CLEARCHOICES);
     vlc_value_t val;
     const char *txt;
     val.i_int = 0;
 
-    if (!AOUT_FMT_LINEAR(fmt) || i_nb_input_channels == 1)
-        return;
-
-    int i_output_mode = owner->requested_stereo_mode;
     int i_default_mode = AOUT_VAR_CHAN_UNSET;
 
     val.i_int = AOUT_VAR_CHAN_MONO;
@@ -464,6 +456,11 @@ static void aout_PrepareStereoMode (audio_output_t *aout,
             i_default_mode = AOUT_VAR_CHAN_HEADPHONES;
     }
 
+    return i_default_mode;
+}
+
+static bool aout_HasStereoMode(audio_output_t *aout, int mode)
+{
     bool mode_available = false;
     vlc_value_t *vals;
     size_t count;
@@ -473,16 +470,20 @@ static void aout_PrepareStereoMode (audio_output_t *aout,
     {
         for (size_t i = 0; !mode_available && i < count; ++i)
         {
-            if (vals[i].i_int == i_output_mode)
+            if (vals[i].i_int == mode)
                 mode_available = true;
         }
         free(vals);
     }
-    if (!mode_available)
-        i_output_mode = i_default_mode;
+    return mode_available;
+}
 
+static void aout_UpdateStereoMode(audio_output_t *aout, int mode,
+                                  audio_sample_format_t *restrict fmt,
+                                  aout_filters_cfg_t *filters_cfg)
+{
     /* The user may have selected a different channels configuration. */
-    switch (i_output_mode)
+    switch (mode)
     {
         case AOUT_VAR_CHAN_RSTEREO:
             filters_cfg->remap[AOUT_CHANIDX_LEFT] = AOUT_CHANIDX_RIGHT;
@@ -511,8 +512,10 @@ static void aout_PrepareStereoMode (audio_output_t *aout,
             break;
     }
 
+    assert(mode == AOUT_VAR_CHAN_UNSET || aout_HasStereoMode(aout, mode));
+
     var_Change(aout, "stereo-mode", VLC_VAR_SETVALUE,
-               (vlc_value_t) { .i_int = i_output_mode });
+               (vlc_value_t) { .i_int = mode});
 }
 
 /**
@@ -610,8 +613,21 @@ int aout_OutputNew (audio_output_t *aout)
     }
     assert(aout->flush && aout->play && aout->time_get && aout->pause);
 
-    aout_PrepareStereoMode (aout, fmt, filters_cfg, input_chan_type,
-                            i_nb_input_channels);
+    var_Change(aout, "stereo-mode", VLC_VAR_CLEARCHOICES);
+
+    if (AOUT_FMT_LINEAR(fmt) && i_nb_input_channels != 1)
+    {
+        int default_stereo_mode =
+            aout_PrepareStereoMode(aout, fmt, input_chan_type,
+                                   i_nb_input_channels);
+
+        /* Prefer the user requested mode if available, otherwise, use the
+         * default one */
+        int stereo_mode = aout_HasStereoMode(aout, owner->requested_stereo_mode) ?
+                          owner->requested_stereo_mode : default_stereo_mode;
+
+        aout_UpdateStereoMode(aout, stereo_mode, fmt, filters_cfg);
+    }
 
     aout_FormatPrepare (fmt);
     assert (fmt->i_bytes_per_frame > 0 && fmt->i_frame_length > 0);
-- 
2.20.1



More information about the vlc-devel mailing list