[vlc-devel] [PATCH 09/10] pulse: modify fmt only in case of success

Thomas Guillem thomas at gllm.fr
Wed Jan 18 09:20:08 CET 2017


---
 modules/audio_output/pulse.c | 60 +++++++++++++++++++++++---------------------
 1 file changed, 31 insertions(+), 29 deletions(-)

diff --git a/modules/audio_output/pulse.c b/modules/audio_output/pulse.c
index 38a0d6624e..6986febebc 100644
--- a/modules/audio_output/pulse.c
+++ b/modules/audio_output/pulse.c
@@ -690,7 +690,7 @@ static const char *str_map(const char *key, const char *const table[][2],
 /**
  * Create a PulseAudio playback stream, a.k.a. a sink input.
  */
-static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
+static int Start(audio_output_t *aout, audio_sample_format_t *restrict pfmt)
 {
     aout_sys_t *sys = aout->sys;
 
@@ -698,10 +698,11 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
     struct pa_sample_spec ss;
     pa_encoding_t encoding = PA_ENCODING_INVALID;
 
-    switch (fmt->i_format)
+    audio_sample_format_t fmt = *pfmt;
+    switch (fmt.i_format)
     {
         case VLC_CODEC_FL64:
-            fmt->i_format = VLC_CODEC_FL32;
+            fmt.i_format = VLC_CODEC_FL32;
         case VLC_CODEC_FL32:
             ss.format = PA_SAMPLE_FLOAT32NE;
             break;
@@ -715,50 +716,50 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
             ss.format = PA_SAMPLE_U8;
             break;
         case VLC_CODEC_A52:
-            fmt->i_format = VLC_CODEC_SPDIFL;
-            fmt->i_bytes_per_frame = 4;
-            fmt->i_frame_length = 1;
+            fmt.i_format = VLC_CODEC_SPDIFL;
+            fmt.i_bytes_per_frame = 4;
+            fmt.i_frame_length = 1;
             encoding = PA_ENCODING_AC3_IEC61937;
             ss.format = PA_SAMPLE_S16NE;
             break;
         case VLC_CODEC_EAC3:
-            fmt->i_format = VLC_CODEC_SPDIFL;
-            fmt->i_bytes_per_frame = 4;
-            fmt->i_frame_length = 1;
+            fmt.i_format = VLC_CODEC_SPDIFL;
+            fmt.i_bytes_per_frame = 4;
+            fmt.i_frame_length = 1;
             encoding = PA_ENCODING_EAC3_IEC61937;
             ss.format = PA_SAMPLE_S16NE;
             break;
         /* case VLC_CODEC_MPGA:
-            fmt->i_format = VLC_CODEC_SPDIFL FIXME;
+            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;
-            fmt->i_bytes_per_frame = 4;
-            fmt->i_frame_length = 1;
+            fmt.i_format = VLC_CODEC_SPDIFL;
+            fmt.i_bytes_per_frame = 4;
+            fmt.i_frame_length = 1;
             encoding = PA_ENCODING_DTS_IEC61937;
             ss.format = PA_SAMPLE_S16NE;
             break;
         default:
-            if (!AOUT_FMT_LINEAR(fmt) || aout_FormatNbChannels(fmt) == 0)
+            if (!AOUT_FMT_LINEAR(&fmt) || aout_FormatNbChannels(&fmt) == 0)
                 return VLC_EGENERIC;
 
             if (HAVE_FPU)
             {
-                fmt->i_format = VLC_CODEC_FL32;
+                fmt.i_format = VLC_CODEC_FL32;
                 ss.format = PA_SAMPLE_FLOAT32NE;
             }
             else
             {
-                fmt->i_format = VLC_CODEC_S16N;
+                fmt.i_format = VLC_CODEC_S16N;
                 ss.format = PA_SAMPLE_S16NE;
             }
             break;
     }
 
-    ss.rate = fmt->i_rate;
-    ss.channels = fmt->i_channels;
+    ss.rate = fmt.i_rate;
+    ss.channels = fmt.i_channels;
     if (!pa_sample_spec_valid(&ss)) {
         msg_Err(aout, "unsupported sample specification");
         return VLC_EGENERIC;
@@ -816,30 +817,30 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
         struct pa_channel_map map;
         map.channels = 0;
 
-        if (fmt->i_physical_channels & AOUT_CHAN_LEFT)
+        if (fmt.i_physical_channels & AOUT_CHAN_LEFT)
             map.map[map.channels++] = PA_CHANNEL_POSITION_FRONT_LEFT;
-        if (fmt->i_physical_channels & AOUT_CHAN_RIGHT)
+        if (fmt.i_physical_channels & AOUT_CHAN_RIGHT)
             map.map[map.channels++] = PA_CHANNEL_POSITION_FRONT_RIGHT;
-        if (fmt->i_physical_channels & AOUT_CHAN_MIDDLELEFT)
+        if (fmt.i_physical_channels & AOUT_CHAN_MIDDLELEFT)
             map.map[map.channels++] = PA_CHANNEL_POSITION_SIDE_LEFT;
-        if (fmt->i_physical_channels & AOUT_CHAN_MIDDLERIGHT)
+        if (fmt.i_physical_channels & AOUT_CHAN_MIDDLERIGHT)
             map.map[map.channels++] = PA_CHANNEL_POSITION_SIDE_RIGHT;
-        if (fmt->i_physical_channels & AOUT_CHAN_REARLEFT)
+        if (fmt.i_physical_channels & AOUT_CHAN_REARLEFT)
             map.map[map.channels++] = PA_CHANNEL_POSITION_REAR_LEFT;
-        if (fmt->i_physical_channels & AOUT_CHAN_REARRIGHT)
+        if (fmt.i_physical_channels & AOUT_CHAN_REARRIGHT)
             map.map[map.channels++] = PA_CHANNEL_POSITION_REAR_RIGHT;
-        if (fmt->i_physical_channels & AOUT_CHAN_REARCENTER)
+        if (fmt.i_physical_channels & AOUT_CHAN_REARCENTER)
             map.map[map.channels++] = PA_CHANNEL_POSITION_REAR_CENTER;
-        if (fmt->i_physical_channels & AOUT_CHAN_CENTER)
+        if (fmt.i_physical_channels & AOUT_CHAN_CENTER)
         {
             if (ss.channels == 1)
                 map.map[map.channels++] = PA_CHANNEL_POSITION_MONO;
             else
                 map.map[map.channels++] = PA_CHANNEL_POSITION_FRONT_CENTER;
         }
-        if (fmt->i_physical_channels & AOUT_CHAN_LFE)
+        if (fmt.i_physical_channels & AOUT_CHAN_LFE)
             map.map[map.channels++] = PA_CHANNEL_POSITION_LFE;
-        fmt->i_original_channels = fmt->i_physical_channels;
+        fmt.i_original_channels = fmt.i_physical_channels;
 
         static_assert(AOUT_CHAN_MAX == 9, "Missing channels");
 
@@ -936,13 +937,14 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
     if (encoding == PA_ENCODING_INVALID)
     {
         const struct pa_sample_spec *spec = pa_stream_get_sample_spec(s);
-        fmt->i_rate = spec->rate;
+        fmt.i_rate = spec->rate;
     }
 
     stream_buffer_attr_cb(s, aout);
     stream_moved_cb(s, aout);
     pa_threaded_mainloop_unlock(sys->mainloop);
 
+    *pfmt = fmt;
     return VLC_SUCCESS;
 
 fail:
-- 
2.11.0



More information about the vlc-devel mailing list