[vlc-devel] [PATCH 7/9] pulse: use an intermediate fmt variable

Thomas Guillem thomas at gllm.fr
Thu Oct 3 16:33:57 CEST 2019


This will be needed by the next commit.
---
 modules/audio_output/pulse.c | 76 +++++++++++++++++++-----------------
 1 file changed, 40 insertions(+), 36 deletions(-)

diff --git a/modules/audio_output/pulse.c b/modules/audio_output/pulse.c
index fba8fd6840..158244c425 100644
--- a/modules/audio_output/pulse.c
+++ b/modules/audio_output/pulse.c
@@ -707,7 +707,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 original_fmt)
 {
     aout_sys_t *sys = aout->sys;
 
@@ -715,10 +715,12 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
     struct pa_sample_spec ss = { .format = PA_SAMPLE_INVALID };
     pa_encoding_t encoding = PA_ENCODING_PCM;
 
-    switch (fmt->i_format)
+    audio_sample_format_t fmt = *original_fmt;
+
+    switch (fmt.i_format)
     {
         case VLC_CODEC_FL64:
-            fmt->i_format = VLC_CODEC_FL32;
+            fmt.i_format = VLC_CODEC_FL32;
             /* fall through */
         case VLC_CODEC_FL32:
             ss.format = PA_SAMPLE_FLOAT32NE;
@@ -733,55 +735,55 @@ 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_physical_channels = AOUT_CHANS_2_0;
-            fmt->i_channels = 2;
+            fmt.i_format = VLC_CODEC_SPDIFL;
+            fmt.i_bytes_per_frame = 4;
+            fmt.i_frame_length = 1;
+            fmt.i_physical_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;
-            fmt->i_bytes_per_frame = 4;
-            fmt->i_frame_length = 1;
-            fmt->i_physical_channels = AOUT_CHANS_2_0;
-            fmt->i_channels = 2;
+            fmt.i_format = VLC_CODEC_SPDIFL;
+            fmt.i_bytes_per_frame = 4;
+            fmt.i_frame_length = 1;
+            fmt.i_physical_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;
+            fmt.i_format = VLC_CODEC_SPDIFL FIXME;
             encoding = PA_ENCODING_MPEG_IEC61937;
             break;*/
         case VLC_CODEC_DTS:
-            fmt->i_format = VLC_CODEC_SPDIFL;
-            fmt->i_bytes_per_frame = 4;
-            fmt->i_frame_length = 1;
-            fmt->i_physical_channels = AOUT_CHANS_2_0;
-            fmt->i_channels = 2;
+            fmt.i_format = VLC_CODEC_SPDIFL;
+            fmt.i_bytes_per_frame = 4;
+            fmt.i_frame_length = 1;
+            fmt.i_physical_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)
+            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;
@@ -822,9 +824,9 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
     if (ss.format != PA_SAMPLE_INVALID)
         pa_format_info_set_sample_format(formatv, ss.format);
 
-    if (fmt->channel_type == AUDIO_CHANNEL_TYPE_AMBISONICS)
+    if (fmt.channel_type == AUDIO_CHANNEL_TYPE_AMBISONICS)
     {
-        fmt->channel_type = AUDIO_CHANNEL_TYPE_BITMAP;
+        fmt.channel_type = AUDIO_CHANNEL_TYPE_BITMAP;
 
         /* Setup low latency in order to quickly react to ambisonics
          * filters viewpoint changes. */
@@ -848,28 +850,28 @@ 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;
 
         static_assert(AOUT_CHAN_MAX == 9, "Missing channels");
@@ -960,13 +962,15 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
     if (encoding == PA_ENCODING_PCM)
     {
         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);
 
+    *original_fmt = fmt;
+
     return VLC_SUCCESS;
 
 fail:
-- 
2.20.1



More information about the vlc-devel mailing list