diff mbox series

[v2,4/4] audio: paaudio: ability to specify stream name

Message ID 43076a2afeb0439b607b0631e0bfff77d55bc0cc.1566847960.git.DirtY.iCE.hu@gmail.com
State New
Headers show
Series Audio: misc fixes for "Audio 20190821 patches" | expand

Commit Message

=?UTF-8?B?Wm9sdMOhbiBLxZF2w6Fnw7M=?= Aug. 26, 2019, 7:59 p.m. UTC
This can be used to identify stream in tools like pavucontrol when one
creates multiple -audiodevs or runs multiple qemu instances.

Signed-off-by: Kővágó, Zoltán <DirtY.iCE.hu@gmail.com>
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
---
 qapi/audio.json | 6 ++++++
 audio/paaudio.c | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

Comments

Gerd Hoffmann Aug. 27, 2019, 5:42 a.m. UTC | #1
On Mon, Aug 26, 2019 at 09:59:04PM +0200, Kővágó, Zoltán wrote:
> This can be used to identify stream in tools like pavucontrol when one
> creates multiple -audiodevs or runs multiple qemu instances.

Hmm, can we create an useful name automatically, without yet another
config option?

Useful choices could be the device name (usb-audio, ...) or the device
id (whatever -device id=xxx was specified on the command line).

cheers,
  Gerd
=?UTF-8?B?Wm9sdMOhbiBLxZF2w6Fnw7M=?= Aug. 27, 2019, 10:43 p.m. UTC | #2
On 2019-08-27 07:42, Gerd Hoffmann wrote:
> On Mon, Aug 26, 2019 at 09:59:04PM +0200, Kővágó, Zoltán wrote:
>> This can be used to identify stream in tools like pavucontrol when one
>> creates multiple -audiodevs or runs multiple qemu instances.
> 
> Hmm, can we create an useful name automatically, without yet another
> config option?
> 
> Useful choices could be the device name (usb-audio, ...) or the device
> id (whatever -device id=xxx was specified on the command line).

I'm afraid this is not going to work with the current architecture: due
to mixeng even if you have multiple devices, they'll be mixed to a
single stream and the audio backend will only see this one mixed stream.
 As a workaround we could do something like concat all device names or
ids, but I don't like that idea.

Alternatively we could use the id of the audiodev instead, and no more
problems with mixeng.  However, with mixeng off (implemented in my next
patch series) suddenly soundcards will have suddenly end up as different
streams.  (This can be worked around by creating multiple audiodevs,
like what you have to use now to get multiple streams from pa, so this
is probably a smaller problem.)

Currently I'm leaning for the audiodev's id option, unless someone
proposes something better.

Regards,
Zoltan
Gerd Hoffmann Aug. 28, 2019, 7:33 a.m. UTC | #3
> > Hmm, can we create an useful name automatically, without yet another
> > config option?
> > 
> > Useful choices could be the device name (usb-audio, ...) or the device
> > id (whatever -device id=xxx was specified on the command line).
> 
> I'm afraid this is not going to work with the current architecture: due
> to mixeng even if you have multiple devices, they'll be mixed to a
> single stream and the audio backend will only see this one mixed stream.
>  As a workaround we could do something like concat all device names or
> ids, but I don't like that idea.
> 
> Alternatively we could use the id of the audiodev instead, and no more
> problems with mixeng.  However, with mixeng off (implemented in my next
> patch series) suddenly soundcards will have suddenly end up as different
> streams.  (This can be worked around by creating multiple audiodevs,
> like what you have to use now to get multiple streams from pa, so this
> is probably a smaller problem.)
> 
> Currently I'm leaning for the audiodev's id option, unless someone
> proposes something better.

Hmm, maybe just wait and see if we really need that?

If we use the vm name for the pa connection I suspect most use cases are
covered ...

cheers,
  Gerd
Maxim Levitsky Aug. 28, 2019, 9:12 a.m. UTC | #4
On Wed, 2019-08-28 at 09:33 +0200, Gerd Hoffmann wrote:
> > > Hmm, can we create an useful name automatically, without yet another
> > > config option?
> > > 
> > > Useful choices could be the device name (usb-audio, ...) or the device
> > > id (whatever -device id=xxx was specified on the command line).
> > 
> > I'm afraid this is not going to work with the current architecture: due
> > to mixeng even if you have multiple devices, they'll be mixed to a
> > single stream and the audio backend will only see this one mixed stream.
> >  As a workaround we could do something like concat all device names or
> > ids, but I don't like that idea.
> > 
> > Alternatively we could use the id of the audiodev instead, and no more
> > problems with mixeng.  However, with mixeng off (implemented in my next
> > patch series) suddenly soundcards will have suddenly end up as different
> > streams.  (This can be worked around by creating multiple audiodevs,
> > like what you have to use now to get multiple streams from pa, so this
> > is probably a smaller problem.)
> > 
> > Currently I'm leaning for the audiodev's id option, unless someone
> > proposes something better.
> 
> Hmm, maybe just wait and see if we really need that?
> 
> If we use the vm name for the pa connection I suspect most use cases are
> covered ...

My personal opinion would be, to use vm name for the connection (will cover
use case of distinguishing between VMs)
and using audiodev derived name for stream names, which will at least
partially cover the use case of having more that one guestn's soundcard,
and assigning each to different host sound card dynamically,
that is  using pavucontrol, which is what I wanted to do in first place.
This is also should be the easiest to do probably.

Best regards,
	Maxim Levitsky
Daniel P. Berrangé Aug. 28, 2019, 9:53 a.m. UTC | #5
On Wed, Aug 28, 2019 at 12:43:49AM +0200, Zoltán Kővágó wrote:
> On 2019-08-27 07:42, Gerd Hoffmann wrote:
> > On Mon, Aug 26, 2019 at 09:59:04PM +0200, Kővágó, Zoltán wrote:
> >> This can be used to identify stream in tools like pavucontrol when one
> >> creates multiple -audiodevs or runs multiple qemu instances.
> > 
> > Hmm, can we create an useful name automatically, without yet another
> > config option?
> > 
> > Useful choices could be the device name (usb-audio, ...) or the device
> > id (whatever -device id=xxx was specified on the command line).
> 
> I'm afraid this is not going to work with the current architecture: due
> to mixeng even if you have multiple devices, they'll be mixed to a
> single stream and the audio backend will only see this one mixed stream.
>  As a workaround we could do something like concat all device names or
> ids, but I don't like that idea.
> 
> Alternatively we could use the id of the audiodev instead, and no more
> problems with mixeng.  However, with mixeng off (implemented in my next
> patch series) suddenly soundcards will have suddenly end up as different
> streams.  (This can be worked around by creating multiple audiodevs,
> like what you have to use now to get multiple streams from pa, so this
> is probably a smaller problem.)
> 
> Currently I'm leaning for the audiodev's id option, unless someone
> proposes something better.

Using the audiodev id is not a good idea. If you have multiple QEMU's
on your host, it is highly likely that libvirt will have assigned
the same audiodev id to all of them.  Using the vm name would be ok,
but only if you assume that each gust only has a single audio device.

Using a combination of vm name + audidev id is going to be unique
per host, but not especially friendly as a user visible name. It
would be ok as a default, but I'd think we should let the mgmt app
specify stream name explicitly, so that something user friendly
can be set.

Regards,
Daniel
Maxim Levitsky Aug. 28, 2019, 10:14 a.m. UTC | #6
On Wed, 2019-08-28 at 10:53 +0100, Daniel P. Berrangé wrote:
> On Wed, Aug 28, 2019 at 12:43:49AM +0200, Zoltán Kővágó wrote:
> > On 2019-08-27 07:42, Gerd Hoffmann wrote:
> > > On Mon, Aug 26, 2019 at 09:59:04PM +0200, Kővágó, Zoltán wrote:
> > > > This can be used to identify stream in tools like pavucontrol when one
> > > > creates multiple -audiodevs or runs multiple qemu instances.
> > > 
> > > Hmm, can we create an useful name automatically, without yet another
> > > config option?
> > > 
> > > Useful choices could be the device name (usb-audio, ...) or the device
> > > id (whatever -device id=xxx was specified on the command line).
> > 
> > I'm afraid this is not going to work with the current architecture: due
> > to mixeng even if you have multiple devices, they'll be mixed to a
> > single stream and the audio backend will only see this one mixed stream.
> >  As a workaround we could do something like concat all device names or
> > ids, but I don't like that idea.
> > 
> > Alternatively we could use the id of the audiodev instead, and no more
> > problems with mixeng.  However, with mixeng off (implemented in my next
> > patch series) suddenly soundcards will have suddenly end up as different
> > streams.  (This can be worked around by creating multiple audiodevs,
> > like what you have to use now to get multiple streams from pa, so this
> > is probably a smaller problem.)
> > 
> > Currently I'm leaning for the audiodev's id option, unless someone
> > proposes something better.
> 
> Using the audiodev id is not a good idea. If you have multiple QEMU's
> on your host, it is highly likely that libvirt will have assigned
> the same audiodev id to all of them.  Using the vm name would be ok,
> but only if you assume that each gust only has a single audio device.
> 
> Using a combination of vm name + audidev id is going to be unique
> per host, but not especially friendly as a user visible name. It
> would be ok as a default, but I'd think we should let the mgmt app
> specify stream name explicitly, so that something user friendly
> can be set.
No, no!
It seems that pulseaudio has a name for each connection, and a name for each
steam within that connection.

The suggestion is that we use the VM name for the connection,
(which will be unique per VM usually, at least the user can make it be so)
and then use the audiodev id for each stream. Of course for multiple VMs,
the audiodev ids will be the same, but this is all right since you can
always distinguish them that the streams come from different VMs.

Also note that this thing is cosmetic from the correctness point of view,
that is pulse-audio internally has no problem with duplicate IDs.

The thing is useful mostly for tweaking the output streams in the pavucontrol,
where the names will allow you to easily know which steam is which.

Speaking of this, there is another minor feature missing, which is volume level
feedback from pavucontrol to the guest. That means that if you change the volume of the
stream in pavucontrol, the guest will not be aware of this, and still think that the
volume is the same.
But for 'tweaking' I was mostly thinking about assigning the input/output streams to
different sound devices, which pavucontrol can do and does work very well.

Best regards,
	Maxim Levitsky
Daniel P. Berrangé Aug. 28, 2019, 10:26 a.m. UTC | #7
On Wed, Aug 28, 2019 at 01:14:03PM +0300, Maxim Levitsky wrote:
> On Wed, 2019-08-28 at 10:53 +0100, Daniel P. Berrangé wrote:
> > On Wed, Aug 28, 2019 at 12:43:49AM +0200, Zoltán Kővágó wrote:
> > > On 2019-08-27 07:42, Gerd Hoffmann wrote:
> > > > On Mon, Aug 26, 2019 at 09:59:04PM +0200, Kővágó, Zoltán wrote:
> > > > > This can be used to identify stream in tools like pavucontrol when one
> > > > > creates multiple -audiodevs or runs multiple qemu instances.
> > > > 
> > > > Hmm, can we create an useful name automatically, without yet another
> > > > config option?
> > > > 
> > > > Useful choices could be the device name (usb-audio, ...) or the device
> > > > id (whatever -device id=xxx was specified on the command line).
> > > 
> > > I'm afraid this is not going to work with the current architecture: due
> > > to mixeng even if you have multiple devices, they'll be mixed to a
> > > single stream and the audio backend will only see this one mixed stream.
> > >  As a workaround we could do something like concat all device names or
> > > ids, but I don't like that idea.
> > > 
> > > Alternatively we could use the id of the audiodev instead, and no more
> > > problems with mixeng.  However, with mixeng off (implemented in my next
> > > patch series) suddenly soundcards will have suddenly end up as different
> > > streams.  (This can be worked around by creating multiple audiodevs,
> > > like what you have to use now to get multiple streams from pa, so this
> > > is probably a smaller problem.)
> > > 
> > > Currently I'm leaning for the audiodev's id option, unless someone
> > > proposes something better.
> > 
> > Using the audiodev id is not a good idea. If you have multiple QEMU's
> > on your host, it is highly likely that libvirt will have assigned
> > the same audiodev id to all of them.  Using the vm name would be ok,
> > but only if you assume that each gust only has a single audio device.
> > 
> > Using a combination of vm name + audidev id is going to be unique
> > per host, but not especially friendly as a user visible name. It
> > would be ok as a default, but I'd think we should let the mgmt app
> > specify stream name explicitly, so that something user friendly
> > can be set.
> No, no!
> It seems that pulseaudio has a name for each connection, and a name for each
> steam within that connection.
> 
> The suggestion is that we use the VM name for the connection,
> (which will be unique per VM usually, at least the user can make it be so)
> and then use the audiodev id for each stream. Of course for multiple VMs,
> the audiodev ids will be the same, but this is all right since you can
> always distinguish them that the streams come from different VMs.

Ok, if I'm reading the code correctly, it seems we do take care to
re-use a single connection to PA for all audiodevs we create. So a
VMname is fine for the connection.

> Also note that this thing is cosmetic from the correctness point of view,
> that is pulse-audio internally has no problem with duplicate IDs.
> 
> The thing is useful mostly for tweaking the output streams in the pavucontrol,
> where the names will allow you to easily know which steam is which.

Yep, I wasn't really concerned about internals - from the user POV being
able to accurately distinguish streams in pavucontrol is very important
though, so we should ensure that's possible. If we use 'id'  for the
stream as a default though, we should still allow an override, as 'id'
values are not really intended as end user visible data. If a guest
has multiple devices I'd expect to be able to give them names that are
meaningful to me as a user, not something libvirt auto-generates for
its own machine oriented use.

Regards,
Daniel
Maxim Levitsky Aug. 28, 2019, 10:39 a.m. UTC | #8
On Wed, 2019-08-28 at 11:26 +0100, Daniel P. Berrangé wrote:
> On Wed, Aug 28, 2019 at 01:14:03PM +0300, Maxim Levitsky wrote:
> > On Wed, 2019-08-28 at 10:53 +0100, Daniel P. Berrangé wrote:
> > > On Wed, Aug 28, 2019 at 12:43:49AM +0200, Zoltán Kővágó wrote:
> > > > On 2019-08-27 07:42, Gerd Hoffmann wrote:
> > > > > On Mon, Aug 26, 2019 at 09:59:04PM +0200, Kővágó, Zoltán wrote:
> > > > > > This can be used to identify stream in tools like pavucontrol when one
> > > > > > creates multiple -audiodevs or runs multiple qemu instances.
> > > > > 
> > > > > Hmm, can we create an useful name automatically, without yet another
> > > > > config option?
> > > > > 
> > > > > Useful choices could be the device name (usb-audio, ...) or the device
> > > > > id (whatever -device id=xxx was specified on the command line).
> > > > 
> > > > I'm afraid this is not going to work with the current architecture: due
> > > > to mixeng even if you have multiple devices, they'll be mixed to a
> > > > single stream and the audio backend will only see this one mixed stream.
> > > >  As a workaround we could do something like concat all device names or
> > > > ids, but I don't like that idea.
> > > > 
> > > > Alternatively we could use the id of the audiodev instead, and no more
> > > > problems with mixeng.  However, with mixeng off (implemented in my next
> > > > patch series) suddenly soundcards will have suddenly end up as different
> > > > streams.  (This can be worked around by creating multiple audiodevs,
> > > > like what you have to use now to get multiple streams from pa, so this
> > > > is probably a smaller problem.)
> > > > 
> > > > Currently I'm leaning for the audiodev's id option, unless someone
> > > > proposes something better.
> > > 
> > > Using the audiodev id is not a good idea. If you have multiple QEMU's
> > > on your host, it is highly likely that libvirt will have assigned
> > > the same audiodev id to all of them.  Using the vm name would be ok,
> > > but only if you assume that each gust only has a single audio device.
> > > 
> > > Using a combination of vm name + audidev id is going to be unique
> > > per host, but not especially friendly as a user visible name. It
> > > would be ok as a default, but I'd think we should let the mgmt app
> > > specify stream name explicitly, so that something user friendly
> > > can be set.
> > 
> > No, no!
> > It seems that pulseaudio has a name for each connection, and a name for each
> > steam within that connection.
> > 
> > The suggestion is that we use the VM name for the connection,
> > (which will be unique per VM usually, at least the user can make it be so)
> > and then use the audiodev id for each stream. Of course for multiple VMs,
> > the audiodev ids will be the same, but this is all right since you can
> > always distinguish them that the streams come from different VMs.
> 
> Ok, if I'm reading the code correctly, it seems we do take care to
> re-use a single connection to PA for all audiodevs we create. So a
> VMname is fine for the connection.
> 
> > Also note that this thing is cosmetic from the correctness point of view,
> > that is pulse-audio internally has no problem with duplicate IDs.
> > 
> > The thing is useful mostly for tweaking the output streams in the pavucontrol,
> > where the names will allow you to easily know which steam is which.
> 
> Yep, I wasn't really concerned about internals - from the user POV being
> able to accurately distinguish streams in pavucontrol is very important
> though, so we should ensure that's possible. If we use 'id'  for the
> stream as a default though, we should still allow an override, as 'id'
> values are not really intended as end user visible data. If a guest
> has multiple devices I'd expect to be able to give them names that are
> meaningful to me as a user, not something libvirt auto-generates for
> its own machine oriented use.

I have absolutely nothing against user specified override!
Just that if the idea is shot down, lets at least have device id instead.


For the reference this is how currently the sound streams are shown,
without any patches applied
https://imgur.com/a/I8HZhgx

Gnome sound panel only shows application names,
but pavucontrol shows both the application name and stream name.

Best regards,
	Maxim Levitsky
=?UTF-8?B?Wm9sdMOhbiBLxZF2w6Fnw7M=?= Sept. 9, 2019, 11:42 p.m. UTC | #9
On 2019-08-28 12:39, Maxim Levitsky wrote:
> On Wed, 2019-08-28 at 11:26 +0100, Daniel P. Berrangé wrote:
>> On Wed, Aug 28, 2019 at 01:14:03PM +0300, Maxim Levitsky wrote:
>>> On Wed, 2019-08-28 at 10:53 +0100, Daniel P. Berrangé wrote:
>>>> On Wed, Aug 28, 2019 at 12:43:49AM +0200, Zoltán Kővágó wrote:
>>>>> On 2019-08-27 07:42, Gerd Hoffmann wrote:
>>>>>> On Mon, Aug 26, 2019 at 09:59:04PM +0200, Kővágó, Zoltán wrote:
>>>>>>> This can be used to identify stream in tools like pavucontrol when one
>>>>>>> creates multiple -audiodevs or runs multiple qemu instances.
>>>>>>
>>>>>> Hmm, can we create an useful name automatically, without yet another
>>>>>> config option?
>>>>>>
>>>>>> Useful choices could be the device name (usb-audio, ...) or the device
>>>>>> id (whatever -device id=xxx was specified on the command line).
>>>>>
>>>>> I'm afraid this is not going to work with the current architecture: due
>>>>> to mixeng even if you have multiple devices, they'll be mixed to a
>>>>> single stream and the audio backend will only see this one mixed stream.
>>>>>   As a workaround we could do something like concat all device names or
>>>>> ids, but I don't like that idea.
>>>>>
>>>>> Alternatively we could use the id of the audiodev instead, and no more
>>>>> problems with mixeng.  However, with mixeng off (implemented in my next
>>>>> patch series) suddenly soundcards will have suddenly end up as different
>>>>> streams.  (This can be worked around by creating multiple audiodevs,
>>>>> like what you have to use now to get multiple streams from pa, so this
>>>>> is probably a smaller problem.)
>>>>>
>>>>> Currently I'm leaning for the audiodev's id option, unless someone
>>>>> proposes something better.
>>>>
>>>> Using the audiodev id is not a good idea. If you have multiple QEMU's
>>>> on your host, it is highly likely that libvirt will have assigned
>>>> the same audiodev id to all of them.  Using the vm name would be ok,
>>>> but only if you assume that each gust only has a single audio device.
>>>>
>>>> Using a combination of vm name + audidev id is going to be unique
>>>> per host, but not especially friendly as a user visible name. It
>>>> would be ok as a default, but I'd think we should let the mgmt app
>>>> specify stream name explicitly, so that something user friendly
>>>> can be set.
>>>
>>> No, no!
>>> It seems that pulseaudio has a name for each connection, and a name for each
>>> steam within that connection.
>>>
>>> The suggestion is that we use the VM name for the connection,
>>> (which will be unique per VM usually, at least the user can make it be so)
>>> and then use the audiodev id for each stream. Of course for multiple VMs,
>>> the audiodev ids will be the same, but this is all right since you can
>>> always distinguish them that the streams come from different VMs.
>>
>> Ok, if I'm reading the code correctly, it seems we do take care to
>> re-use a single connection to PA for all audiodevs we create. So a
>> VMname is fine for the connection.
>>
>>> Also note that this thing is cosmetic from the correctness point of view,
>>> that is pulse-audio internally has no problem with duplicate IDs.
>>>
>>> The thing is useful mostly for tweaking the output streams in the pavucontrol,
>>> where the names will allow you to easily know which steam is which.
>>
>> Yep, I wasn't really concerned about internals - from the user POV being
>> able to accurately distinguish streams in pavucontrol is very important
>> though, so we should ensure that's possible. If we use 'id'  for the
>> stream as a default though, we should still allow an override, as 'id'
>> values are not really intended as end user visible data. If a guest
>> has multiple devices I'd expect to be able to give them names that are
>> meaningful to me as a user, not something libvirt auto-generates for
>> its own machine oriented use.
> 
> I have absolutely nothing against user specified override!
> Just that if the idea is shot down, lets at least have device id instead.
> 
> 
> For the reference this is how currently the sound streams are shown,
> without any patches applied
> https://imgur.com/a/I8HZhgx
> 
> Gnome sound panel only shows application names,
> but pavucontrol shows both the application name and stream name.
> 
> Best regards,
> 	Maxim Levitsky
> 

Ping.

If I understand the situation correctly, the current consensus is:

* use VM name for PA server connection
* audiodev id is a good default for PA stream name

What is not clear whether we need a separate qapi option for stream 
name, or just always use the audiodev id.  I don't use pulseaudio or 
libvirt, so I can't really comment about this issue.

Ideally I'd like to create a new patch with this change and a fix for 
the coverity issue reported in [1].

Regards,
Zoltan

[1]: https://lists.gnu.org/archive/html/qemu-devel/2019-09/msg01543.html
Gerd Hoffmann Sept. 10, 2019, 7 a.m. UTC | #10
> Ping.
> 
> If I understand the situation correctly, the current consensus is:
> 
> * use VM name for PA server connection

Yes (most important one IMHO).

> * audiodev id is a good default for PA stream name

Yes.

> What is not clear whether we need a separate qapi option for stream name, or
> just always use the audiodev id.  I don't use pulseaudio or libvirt, so I
> can't really comment about this issue.

No clear consensus.  I'd suggest to just ignore that for now,
or make it a separate patch.

cheers,
  Gerd
diff mbox series

Patch

diff --git a/qapi/audio.json b/qapi/audio.json
index 9fefdf5186..a433b3c9d7 100644
--- a/qapi/audio.json
+++ b/qapi/audio.json
@@ -206,6 +206,11 @@ 
 #
 # @name: name of the sink/source to use
 #
+# @stream-name: name of the PulseAudio stream created by qemu.  Can be
+#               used to identify the stream in PulseAudio when you
+#               create multiple PulseAudio devices or run multiple qemu
+#               instances (default "qemu", since 4.2)
+#
 # @latency: latency you want PulseAudio to achieve in microseconds
 #           (default 15000)
 #
@@ -215,6 +220,7 @@ 
   'base': 'AudiodevPerDirectionOptions',
   'data': {
     '*name': 'str',
+    '*stream-name': 'str',
     '*latency': 'uint32' } }
 
 ##
diff --git a/audio/paaudio.c b/audio/paaudio.c
index 777b8e4718..827f442b6e 100644
--- a/audio/paaudio.c
+++ b/audio/paaudio.c
@@ -562,7 +562,7 @@  static int qpa_init_out(HWVoiceOut *hw, struct audsettings *as,
 
     pa->stream = qpa_simple_new (
         c,
-        "qemu",
+        ppdo->has_stream_name ? ppdo->stream_name : "qemu",
         PA_STREAM_PLAYBACK,
         ppdo->has_name ? ppdo->name : NULL,
         &ss,
@@ -630,7 +630,7 @@  static int qpa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 
     pa->stream = qpa_simple_new (
         c,
-        "qemu",
+        ppdo->has_stream_name ? ppdo->stream_name : "qemu",
         PA_STREAM_RECORD,
         ppdo->has_name ? ppdo->name : NULL,
         &ss,