diff mbox series

[FFmpeg-devel] avdevice/pulse_audio_dec: identify channel layout

Message ID 20200126164220.78268-2-federico.simoncelli@gmail.com
State New
Headers show
Series [FFmpeg-devel] avdevice/pulse_audio_dec: identify channel layout | expand

Checks

Context Check Description
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Federico Simoncelli Jan. 26, 2020, 4:42 p.m. UTC
This patch adds the attempt to identify the pulseaudio channel map and
when possible set the relevant channel_layout parameter of the codec.

The result is an improvement over the current behavior of guessing the
layout based on the number of channels (for more information see
guess_layout_max).
---
 libavdevice/pulse_audio_dec.c | 40 +++++++++++++++++++++++++++++++----
 1 file changed, 36 insertions(+), 4 deletions(-)

Comments

Carl Eugen Hoyos Jan. 26, 2020, 7:27 p.m. UTC | #1
Am So., 26. Jan. 2020 um 18:13 Uhr schrieb Federico Simoncelli
<federico.simoncelli@gmail.com>:
>
> This patch adds the attempt to identify the pulseaudio channel map and
> when possible set the relevant channel_layout parameter of the codec.
>
> The result is an improvement over the current behavior of guessing the
> layout based on the number of channels (for more information see
> guess_layout_max).
> ---
>  libavdevice/pulse_audio_dec.c | 40 +++++++++++++++++++++++++++++++----
>  1 file changed, 36 insertions(+), 4 deletions(-)
>
> diff --git a/libavdevice/pulse_audio_dec.c b/libavdevice/pulse_audio_dec.c
> index 50a3c971ae..12f2d15680 100644
> --- a/libavdevice/pulse_audio_dec.c
> +++ b/libavdevice/pulse_audio_dec.c
> @@ -135,6 +135,37 @@ static av_cold int pulse_close(AVFormatContext *s)
>      return 0;
>  }
>
> +static int pulse_map_to_layout(pa_channel_map *cmap)
> +{
> +    const char *map_name = pa_channel_map_to_name(cmap);
> +
> +    if (map_name == NULL)
> +        return 0;
> +
> +    if (strcmp(map_name, "mono") == 0)
> +        return AV_CH_LAYOUT_MONO;
> +
> +    if (strcmp(map_name, "stereo") == 0)
> +        return AV_CH_LAYOUT_STEREO;
> +
> +    if (strcmp(map_name, "surround-40") == 0)
> +        return AV_CH_LAYOUT_4POINT0;
> +
> +    if (strcmp(map_name, "surround-41") == 0)
> +        return AV_CH_LAYOUT_4POINT1;
> +
> +    if (strcmp(map_name, "surround-50") == 0)
> +        return AV_CH_LAYOUT_5POINT0;
> +
> +    if (strcmp(map_name, "surround-51") == 0)
> +        return AV_CH_LAYOUT_5POINT1;
> +
> +    if (strcmp(map_name, "surround-71") == 0)
> +        return AV_CH_LAYOUT_7POINT1;

Let me repeat my question:
Am I correct that without your question, it is possible to set the
channel_layout from the command line?
Is it still possible to overwrite above defaults with your patch?

Carl Eugen
Federico Simoncelli Jan. 26, 2020, 8:37 p.m. UTC | #2
On Sun, Jan 26, 2020 at 8:27 PM Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
>
> Am So., 26. Jan. 2020 um 18:13 Uhr schrieb Federico Simoncelli
> <federico.simoncelli@gmail.com>:
> >
> > This patch adds the attempt to identify the pulseaudio channel map and
> > when possible set the relevant channel_layout parameter of the codec.
> >
> > The result is an improvement over the current behavior of guessing the
> > layout based on the number of channels (for more information see
> > guess_layout_max).
> > ---
> >  libavdevice/pulse_audio_dec.c | 40 +++++++++++++++++++++++++++++++----
> >  1 file changed, 36 insertions(+), 4 deletions(-)
> >
> > diff --git a/libavdevice/pulse_audio_dec.c b/libavdevice/pulse_audio_dec.c
> > index 50a3c971ae..12f2d15680 100644
> > --- a/libavdevice/pulse_audio_dec.c
> > +++ b/libavdevice/pulse_audio_dec.c
> > @@ -135,6 +135,37 @@ static av_cold int pulse_close(AVFormatContext *s)
> >      return 0;
> >  }
> >
> > +static int pulse_map_to_layout(pa_channel_map *cmap)
> > +{
> > +    const char *map_name = pa_channel_map_to_name(cmap);
> > +
> > +    if (map_name == NULL)
> > +        return 0;
> > +
> > +    if (strcmp(map_name, "mono") == 0)
> > +        return AV_CH_LAYOUT_MONO;
> > +
> > +    if (strcmp(map_name, "stereo") == 0)
> > +        return AV_CH_LAYOUT_STEREO;
> > +
> > +    if (strcmp(map_name, "surround-40") == 0)
> > +        return AV_CH_LAYOUT_4POINT0;
> > +
> > +    if (strcmp(map_name, "surround-41") == 0)
> > +        return AV_CH_LAYOUT_4POINT1;
> > +
> > +    if (strcmp(map_name, "surround-50") == 0)
> > +        return AV_CH_LAYOUT_5POINT0;
> > +
> > +    if (strcmp(map_name, "surround-51") == 0)
> > +        return AV_CH_LAYOUT_5POINT1;
> > +
> > +    if (strcmp(map_name, "surround-71") == 0)
> > +        return AV_CH_LAYOUT_7POINT1;
>
> Let me repeat my question:
> Am I correct that without your question, it is possible to set the
> channel_layout from the command line?

AFAIK from the command line you cannot set the layout (before and
after the patch), you can only set the number of channels.
You can then apply filters to modify and set a layout (also here no
effect from my patch).

> Is it still possible to overwrite above defaults with your patch?

Yes, you can still set the number of channels after the patch (also >= 3).
If pulse can provide a recognized layout for the requested number of
channels then with my patch it will be automatically set, otherwise
(as before) it will continue to be guessed.
Carl Eugen Hoyos Jan. 26, 2020, 8:55 p.m. UTC | #3
Am So., 26. Jan. 2020 um 21:44 Uhr schrieb Federico Simoncelli
<federico.simoncelli@gmail.com>:
>
> On Sun, Jan 26, 2020 at 8:27 PM Carl Eugen Hoyos <ceffmpeg@gmail.com> wrote:
> >
> > Am So., 26. Jan. 2020 um 18:13 Uhr schrieb Federico Simoncelli
> > <federico.simoncelli@gmail.com>:
> > >
> > > This patch adds the attempt to identify the pulseaudio channel map and
> > > when possible set the relevant channel_layout parameter of the codec.
> > >
> > > The result is an improvement over the current behavior of guessing the
> > > layout based on the number of channels (for more information see
> > > guess_layout_max).
> > > ---
> > >  libavdevice/pulse_audio_dec.c | 40 +++++++++++++++++++++++++++++++----
> > >  1 file changed, 36 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/libavdevice/pulse_audio_dec.c b/libavdevice/pulse_audio_dec.c
> > > index 50a3c971ae..12f2d15680 100644
> > > --- a/libavdevice/pulse_audio_dec.c
> > > +++ b/libavdevice/pulse_audio_dec.c
> > > @@ -135,6 +135,37 @@ static av_cold int pulse_close(AVFormatContext *s)
> > >      return 0;
> > >  }
> > >
> > > +static int pulse_map_to_layout(pa_channel_map *cmap)
> > > +{
> > > +    const char *map_name = pa_channel_map_to_name(cmap);
> > > +
> > > +    if (map_name == NULL)
> > > +        return 0;
> > > +
> > > +    if (strcmp(map_name, "mono") == 0)
> > > +        return AV_CH_LAYOUT_MONO;
> > > +
> > > +    if (strcmp(map_name, "stereo") == 0)
> > > +        return AV_CH_LAYOUT_STEREO;
> > > +
> > > +    if (strcmp(map_name, "surround-40") == 0)
> > > +        return AV_CH_LAYOUT_4POINT0;
> > > +
> > > +    if (strcmp(map_name, "surround-41") == 0)
> > > +        return AV_CH_LAYOUT_4POINT1;
> > > +
> > > +    if (strcmp(map_name, "surround-50") == 0)
> > > +        return AV_CH_LAYOUT_5POINT0;
> > > +
> > > +    if (strcmp(map_name, "surround-51") == 0)
> > > +        return AV_CH_LAYOUT_5POINT1;
> > > +
> > > +    if (strcmp(map_name, "surround-71") == 0)
> > > +        return AV_CH_LAYOUT_7POINT1;
> >
> > Let me repeat my question:
> > Am I correct that without your question, it is possible to set the
> > channel_layout from the command line?
>
> AFAIK from the command line you cannot set the layout (before and
> after the patch), you can only set the number of channels.
> You can then apply filters to modify and set a layout (also here no
> effect from my patch).

The command line input option channel_layout does not work
with pulse input?

Could you do me a favour and provide a command line
using pulse? I may be able to reproduce but don't
remember how pulse is supposed to work...

Carl Eugen
diff mbox series

Patch

diff --git a/libavdevice/pulse_audio_dec.c b/libavdevice/pulse_audio_dec.c
index 50a3c971ae..12f2d15680 100644
--- a/libavdevice/pulse_audio_dec.c
+++ b/libavdevice/pulse_audio_dec.c
@@ -135,6 +135,37 @@  static av_cold int pulse_close(AVFormatContext *s)
     return 0;
 }
 
+static int pulse_map_to_layout(pa_channel_map *cmap)
+{
+    const char *map_name = pa_channel_map_to_name(cmap);
+
+    if (map_name == NULL)
+        return 0;
+
+    if (strcmp(map_name, "mono") == 0)
+        return AV_CH_LAYOUT_MONO;
+
+    if (strcmp(map_name, "stereo") == 0)
+        return AV_CH_LAYOUT_STEREO;
+
+    if (strcmp(map_name, "surround-40") == 0)
+        return AV_CH_LAYOUT_4POINT0;
+
+    if (strcmp(map_name, "surround-41") == 0)
+        return AV_CH_LAYOUT_4POINT1;
+
+    if (strcmp(map_name, "surround-50") == 0)
+        return AV_CH_LAYOUT_5POINT0;
+
+    if (strcmp(map_name, "surround-51") == 0)
+        return AV_CH_LAYOUT_5POINT1;
+
+    if (strcmp(map_name, "surround-71") == 0)
+        return AV_CH_LAYOUT_7POINT1;
+
+    return 0;
+}
+
 static av_cold int pulse_read_header(AVFormatContext *s)
 {
     PulseData *pd = s->priv_data;
@@ -245,10 +276,11 @@  static av_cold int pulse_read_header(AVFormatContext *s)
     pa_threaded_mainloop_unlock(pd->mainloop);
 
     /* take real parameters */
-    st->codecpar->codec_type  = AVMEDIA_TYPE_AUDIO;
-    st->codecpar->codec_id    = codec_id;
-    st->codecpar->sample_rate = pd->sample_rate;
-    st->codecpar->channels    = pd->channels;
+    st->codecpar->codec_type     = AVMEDIA_TYPE_AUDIO;
+    st->codecpar->codec_id       = codec_id;
+    st->codecpar->sample_rate    = pd->sample_rate;
+    st->codecpar->channels       = pd->channels;
+    st->codecpar->channel_layout = pulse_map_to_layout(&cmap);
     avpriv_set_pts_info(st, 64, 1, 1000000);  /* 64 bits pts in us */
 
     pd->timefilter = ff_timefilter_new(1000000.0 / pd->sample_rate,