[vlc-devel] [PATCH 14/16] pulse: factor pa_format_info initialisation

Thomas Guillem thomas at gllm.fr
Fri Jul 7 16:03:00 CEST 2017


---
 modules/audio_output/pulse.c | 30 +++++++++++-------------------
 1 file changed, 11 insertions(+), 19 deletions(-)

diff --git a/modules/audio_output/pulse.c b/modules/audio_output/pulse.c
index b23d110388..ac1254c8b9 100644
--- a/modules/audio_output/pulse.c
+++ b/modules/audio_output/pulse.c
@@ -695,8 +695,8 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
     aout_sys_t *sys = aout->sys;
 
     /* Sample format specification */
-    struct pa_sample_spec ss;
-    pa_encoding_t encoding = PA_ENCODING_INVALID;
+    struct pa_sample_spec ss = { .format = PA_SAMPLE_INVALID };
+    pa_encoding_t encoding = PA_ENCODING_PCM;
 
     switch (fmt->i_format)
     {
@@ -722,7 +722,6 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
             fmt->i_physical_channels = fmt->i_original_channels = AOUT_CHANS_2_0;
             fmt->i_channels = 2;
             encoding = PA_ENCODING_AC3_IEC61937;
-            ss.format = PA_SAMPLE_S16NE;
             break;
         case VLC_CODEC_EAC3:
             fmt->i_format = VLC_CODEC_SPDIFL;
@@ -731,12 +730,10 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
             fmt->i_physical_channels = fmt->i_original_channels = AOUT_CHANS_2_0;
             fmt->i_channels = 2;
             encoding = PA_ENCODING_EAC3_IEC61937;
-            ss.format = PA_SAMPLE_S16NE;
             break;
         /* case VLC_CODEC_MPGA:
             fmt->i_format = VLC_CODEC_SPDIFL FIXME;
             encoding = PA_ENCODING_MPEG_IEC61937;
-            ss.format = PA_SAMPLE_S16NE;
             break;*/
         case VLC_CODEC_DTS:
             fmt->i_format = VLC_CODEC_SPDIFL;
@@ -745,7 +742,6 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
             fmt->i_physical_channels = fmt->i_original_channels = AOUT_CHANS_2_0;
             fmt->i_channels = 2;
             encoding = PA_ENCODING_DTS_IEC61937;
-            ss.format = PA_SAMPLE_S16NE;
             break;
         default:
             if (!AOUT_FMT_LINEAR(fmt) || aout_FormatNbChannels(fmt) == 0)
@@ -800,13 +796,14 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
     pa_cvolume_init(&sys->cvolume);
     sys->first_pts = VLC_TS_INVALID;
 
-    pa_format_info *formatv;
+    pa_format_info *formatv = pa_format_info_new();
+    formatv->encoding = encoding;
+    pa_format_info_set_rate(formatv, ss.rate);
+    if (ss.format != PA_SAMPLE_INVALID)
+        pa_format_info_set_sample_format(formatv, ss.format);
 
-    /* Favor digital pass-through if available*/
-    if (encoding != PA_ENCODING_INVALID) {
-        formatv = pa_format_info_new();
-        formatv->encoding = encoding;
-        pa_format_info_set_rate(formatv, ss.rate);
+    if (encoding != PA_ENCODING_PCM)
+    {
         pa_format_info_set_channels(formatv, ss.channels);
 
         /* FIX flags are only permitted for PCM, and there is no way to pass
@@ -861,11 +858,6 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
             msg_Dbg(aout, "using %s channel map", (name != NULL) ? name : "?");
         }
 
-        /* PCM */
-        formatv = pa_format_info_new();
-        formatv->encoding = PA_ENCODING_PCM;
-        pa_format_info_set_sample_format(formatv, ss.format);
-        pa_format_info_set_rate(formatv, ss.rate);
         pa_format_info_set_channels(formatv, ss.channels);
         pa_format_info_set_channel_map(formatv, &map);
     }
@@ -924,7 +916,7 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
     if (pa_stream_connect_playback(s, sys->sink_force, &attr, flags,
                                    cvolume, NULL) < 0
      || stream_wait(s, sys->mainloop)) {
-        if (encoding != PA_ENCODING_INVALID)
+        if (encoding != PA_ENCODING_PCM)
             vlc_pa_error(aout, "digital pass-through stream connection failure",
                          sys->context);
         else
@@ -936,7 +928,7 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
     free(sys->sink_force);
     sys->sink_force = NULL;
 
-    if (encoding == PA_ENCODING_INVALID)
+    if (encoding == PA_ENCODING_PCM)
     {
         const struct pa_sample_spec *spec = pa_stream_get_sample_spec(s);
         fmt->i_rate = spec->rate;
-- 
2.11.0



More information about the vlc-devel mailing list