Clemens Ladisch | 28 Aug 00:28 2012
Picon

[RFC PATCH 1/11] expose sound device topology information

Hi,

these are some tentative patches to allow sound drivers to provide
routing information to userspace.  (So far, snd-usb-audio has a partial
implementation; I haven't yet had time for snd-hda-intel.  I haven't
even looked at ASoC.)

The media controller API <linux/media.h> allows prividing routing
information, but its implementation does not quite fit the sound
drivers:
* it allows reconfiguration of links, but not in a way that would be
  useful for ALSA selector controls;
* it allows drivers to access the entity graph and pipelines, which is
  not needed;
* it is rather heavyweight.

Therefore, these patches create their own implementation of the media
controller API.  In this implementation, all entity and link information
is completely static, and more space-efficient.

For simplicity, the ioctls hook into the ALSA control device instead
of creating a new /dev/media* device.

The separate implementation does not allow sharing of one media
controller device in the case of combined audio/video devices.  However,
separate drivers would already be a problem for HDMI outputs (GPU and
sound); it appears we might need some mechanism to connect the
topologies of multiple media devices.

TLVs (for jack entities, and for associating controls with entities)
(Continue reading)

Clemens Ladisch | 28 Aug 00:29 2012
Picon

[RFC PATCH 01/11] ALSA: implement MEDIA_IOC_DEVICE_INFO

Add a callback to snd_card to allow card drivers to return driver-
specific information.

Signed-off-by: Clemens Ladisch <clemens <at> ladisch.de>
---
 include/sound/core.h  |    5 +++
 include/sound/media.h |   50 ++++++++++++++++++++++++++++++++
 sound/core/Kconfig    |    7 +++++
 sound/core/Makefile   |    1 +
 sound/core/media.c    |   76 +++++++++++++++++++++++++++++++++++++++++++++++++
 sound/core/sound.c    |    3 ++
 6 files changed, 142 insertions(+), 0 deletions(-)
 create mode 100644 include/sound/media.h
 create mode 100644 sound/core/media.c

diff --git a/include/sound/core.h b/include/sound/core.h
index bc05668..5eca6f5 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
 <at>  <at>  -42,6 +42,7  <at>  <at>  struct pci_dev;
 struct module;
 struct device;
 struct device_attribute;
+struct snd_media_card_ops;

 /* device allocation stuff */

 <at>  <at>  -145,6 +146,10  <at>  <at>  struct snd_card {
 	struct snd_mixer_oss *mixer_oss;
 	int mixer_oss_change_count;
(Continue reading)

Mark Brown | 7 Sep 04:13 2012

Re: [RFC PATCH 01/11] ALSA: implement MEDIA_IOC_DEVICE_INFO

On Tue, Aug 28, 2012 at 12:29:33AM +0200, Clemens Ladisch wrote:

> +config SND_MEDIA
> +	bool "Media Controller API (EXPERIMENTAL)"
> +	depends on EXPERIMENTAL
> +	help
> +	  Say Y here to enable the media controller API, which allows to
> +	  retrieve the internal topology of sound devices.

I think there's a general consensus these days that EXPERIMENTAL is
pretty meaningless so we probably shouldn't bother with it.  The text is
also a bit confusing, it enables use of the media controller API for
ALSA devices really.

I have to say I'm also a bit surprised that there's no core framework
for media controller and we're open coding ioctl() implementations here,
I'd have thought there would at least be a way of enumerating all media
controller devices in the system...
Clemens Ladisch | 7 Sep 09:14 2012
Picon

Re: [RFC PATCH 01/11] ALSA: implement MEDIA_IOC_DEVICE_INFO

Mark Brown wrote:
> On Tue, Aug 28, 2012 at 12:29:33AM +0200, Clemens Ladisch wrote:
>> +config SND_MEDIA
>> +	bool "Media Controller API (EXPERIMENTAL)"
>> +	depends on EXPERIMENTAL
>> +	help
>> +	  Say Y here to enable the media controller API, which allows to
>> +	  retrieve the internal topology of sound devices.
>
> I think there's a general consensus these days that EXPERIMENTAL is
> pretty meaningless so we probably shouldn't bother with it.

Well, I couldn't claim this to be any less experimental than the
implementation in drivers/media/.  :)

> The text is also a bit confusing, it enables use of the media
> controller API for ALSA devices really.

It's in the ALSA menu.  I could put "ALSA" in the title if it helps.

> I have to say I'm also a bit surprised that there's no core framework
> for media controller and we're open coding ioctl() implementations here,

drivers/media/media-*.c exists, but I did not use that implementation
because someone expressed concern about it being too heavyweight ...

> I'd have thought there would at least be a way of enumerating all media
> controller devices in the system...

It appears userspace is supposed to check all /dev/media* devices.
(Continue reading)

Takashi Iwai | 7 Sep 12:40 2012
Picon

Re: [RFC PATCH 01/11] ALSA: implement MEDIA_IOC_DEVICE_INFO

At Fri, 07 Sep 2012 09:14:30 +0200,
Clemens Ladisch wrote:
> 
> Mark Brown wrote:
> > On Tue, Aug 28, 2012 at 12:29:33AM +0200, Clemens Ladisch wrote:
> >> +config SND_MEDIA
> >> +	bool "Media Controller API (EXPERIMENTAL)"
> >> +	depends on EXPERIMENTAL
> >> +	help
> >> +	  Say Y here to enable the media controller API, which allows to
> >> +	  retrieve the internal topology of sound devices.
> >
> > I think there's a general consensus these days that EXPERIMENTAL is
> > pretty meaningless so we probably shouldn't bother with it.
> 
> Well, I couldn't claim this to be any less experimental than the
> implementation in drivers/media/.  :)

In the previous kernel summit, we agreed to drop CONFIG_EXPERIMENTAL
since it's just useless.  So, no need to add yet another new entry
with that flag.

> > The text is also a bit confusing, it enables use of the media
> > controller API for ALSA devices really.
> 
> It's in the ALSA menu.  I could put "ALSA" in the title if it helps.

Yeah, I also prefer with that.

Takashi
(Continue reading)

Clemens Ladisch | 28 Aug 00:30 2012
Picon

[RFC PATCH 02/11] ALSA: implement MEDIA_IOC_ENUM_ENTITIES

Allow drivers to create entities.  To avoid bloat, the snd_media_entity
structure stores only basic information and retrieves the full entitiy
information on demand with a callback.

Signed-off-by: Clemens Ladisch <clemens <at> ladisch.de>
---
 include/sound/core.h  |    5 ++
 include/sound/media.h |   23 ++++++++++
 sound/core/init.c     |    4 ++
 sound/core/media.c    |  114 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 145 insertions(+), 1 deletions(-)

diff --git a/include/sound/core.h b/include/sound/core.h
index 5eca6f5..072b642 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
 <at>  <at>  -51,7 +51,8  <at>  <at>  struct snd_media_card_ops;
 typedef int __bitwise snd_device_type_t;
 #define	SNDRV_DEV_TOPLEVEL	((__force snd_device_type_t) 0)
 #define	SNDRV_DEV_CONTROL	((__force snd_device_type_t) 1)
-#define	SNDRV_DEV_LOWLEVEL_PRE	((__force snd_device_type_t) 2)
+#define	SNDRV_DEV_MEDIA		((__force snd_device_type_t) 2)
+#define	SNDRV_DEV_LOWLEVEL_PRE	((__force snd_device_type_t) 3)
 #define	SNDRV_DEV_LOWLEVEL_NORMAL ((__force snd_device_type_t) 0x1000)
 #define	SNDRV_DEV_PCM		((__force snd_device_type_t) 0x1001)
 #define	SNDRV_DEV_RAWMIDI	((__force snd_device_type_t) 0x1002)
 <at>  <at>  -149,6 +150,8  <at>  <at>  struct snd_card {

 #ifdef CONFIG_SND_MEDIA
 	const struct snd_media_card_ops *media_ops;
(Continue reading)

Clemens Ladisch | 28 Aug 00:30 2012
Picon

[RFC PATCH 03/11] ALSA: pcm: add ALSA PCM device entities

Add a helper function for creating entities representing ALSA PCM
devices.

Signed-off-by: Clemens Ladisch <clemens <at> ladisch.de>
---
 include/sound/pcm.h |    6 ++++++
 sound/core/pcm.c    |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 0 deletions(-)

diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 39e26a3..f0a80b7 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
 <at>  <at>  -480,6 +480,12  <at>  <at>  int snd_pcm_new_internal(struct snd_card *card, const char *id, int device,
 		int playback_count, int capture_count,
 		struct snd_pcm **rpcm);
 int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count);
+#ifdef CONFIG_SND_MEDIA
+int snd_pcm_media_entities_create(struct snd_pcm *pcm, int stream,
+				  unsigned int id);
+#else
+#define snd_pcm_media_entities_create(pcm, stream, id)
+#endif

 int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree);

diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 1a3070b..a138c57 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
(Continue reading)

Clemens Ladisch | 28 Aug 00:31 2012
Picon

[RFC PATCH 04/11] ALSA: implement MEDIA_IOC_ENUM_LINKS (1)

Allow to retrieve pad information.

Signed-off-by: Clemens Ladisch <clemens <at> ladisch.de>
---
 sound/core/media.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/sound/core/media.c b/sound/core/media.c
index aa94175..96b09a3 100644
--- a/sound/core/media.c
+++ b/sound/core/media.c
 <at>  <at>  -161,6 +161,48  <at>  <at>  static int snd_media_enum_entities(struct snd_card *card,
 	return copy_to_user(descp, &desc, sizeof(desc));
 }

+static int snd_media_enum_links(struct snd_card *card,
+				struct media_links_enum __user *linksp)
+{
+	struct media_links_enum links;
+	struct snd_media_entity *entity;
+
+	if (copy_from_user(&links, linksp, sizeof(links)))
+		return -EFAULT;
+
+	mutex_lock(&card->media_mutex);
+	entity = search_entity(card, links.entity);
+	mutex_unlock(&card->media_mutex);
+	if (!entity)
+		return -EINVAL;
+
(Continue reading)

Clemens Ladisch | 28 Aug 00:31 2012
Picon

[RFC PATCH 05/11] ALSA: implement MEDIA_IOC_ENUM_LINKS (2)

Allow drivers to create links between entities.

Signed-off-by: Clemens Ladisch <clemens <at> ladisch.de>
---
 include/sound/core.h  |    3 ++
 include/sound/media.h |   11 ++++++
 sound/core/media.c    |   86 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 100 insertions(+), 0 deletions(-)

diff --git a/include/sound/core.h b/include/sound/core.h
index 072b642..f6577ec 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
 <at>  <at>  -43,6 +43,7  <at>  <at>  struct module;
 struct device;
 struct device_attribute;
 struct snd_media_card_ops;
+struct snd_media_link;

 /* device allocation stuff */

 <at>  <at>  -152,6 +153,8  <at>  <at>  struct snd_card {
 	const struct snd_media_card_ops *media_ops;
 	struct mutex media_mutex;
 	struct list_head media_entities;
+	unsigned int media_links_count;
+	struct snd_media_link *media_links;
 #endif
 };

(Continue reading)

Clemens Ladisch | 28 Aug 00:32 2012
Picon

[RFC PATCH 06/11] ALSA: implement MEDIA_IOC_SETUP_LINK

Just for compatibility with the media controller API, implement the
setup link ioctl, which does not actually do anything.

Signed-off-by: Clemens Ladisch <clemens <at> ladisch.de>
---
 sound/core/media.c |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/sound/core/media.c b/sound/core/media.c
index aa90848..cbc51d9 100644
--- a/sound/core/media.c
+++ b/sound/core/media.c
 <at>  <at>  -289,6 +289,45  <at>  <at>  static int snd_media_enum_links(struct snd_card *card,
 	return 0;
 }

+static int snd_media_setup_link(struct snd_card *card,
+				struct media_link_desc __user *descp)
+{
+	struct media_link_desc desc;
+	struct snd_media_entity *source, *sink;
+	struct snd_media_link *link;
+	unsigned int i;
+	int err;
+
+	if (copy_from_user(&desc, descp, sizeof(desc)))
+		return -EFAULT;
+
+	if (desc.flags != (MEDIA_LNK_FL_ENABLED | MEDIA_LNK_FL_IMMUTABLE))
+		return -EINVAL;
(Continue reading)

Clemens Ladisch | 28 Aug 00:33 2012
Picon

[RFC PATCH 07/11] [media] media: add entity types for ALSA

Add entity types for describing the topology of sound devices.

JACK entities represent connections to the outside world.  Properties of
the jack will be described by a TLV on the jack entity.

MIXER entities add their inputs together, while SELECTOR entities route
on of their inputs to the output.  PROCESSING entities represent volume/
mute controls or other effects processing units.  These entities may
have ALSA controls associated with them, which is indicated by those
controls having a TLV containing the entity ID and the control type.

SPLIT and MERGE entities are needed for HDA codecs, whose topology is
constructed of stereo channel pairs.

Signed-off-by: Clemens Ladisch <clemens <at> ladisch.de>
---
 include/linux/media.h |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/include/linux/media.h b/include/linux/media.h
index 0ef8833..9d2ad75 100644
--- a/include/linux/media.h
+++ b/include/linux/media.h
 <at>  <at>  -57,6 +57,15  <at>  <at>  struct media_device_info {
 #define MEDIA_ENT_T_V4L2_SUBDEV_FLASH	(MEDIA_ENT_T_V4L2_SUBDEV + 2)
 #define MEDIA_ENT_T_V4L2_SUBDEV_LENS	(MEDIA_ENT_T_V4L2_SUBDEV + 3)

+#define MEDIA_ENT_T_JACK		(3 << MEDIA_ENT_TYPE_SHIFT)
+
+#define MEDIA_ENT_T_ALSA		(4 << MEDIA_ENT_TYPE_SHIFT)
(Continue reading)

Clemens Ladisch | 28 Aug 00:33 2012
Picon

[RFC PATCH 08/11] ALSA: usb-audio: implement card get_info callback

Add a helper for retrieving information about USB devices.

Signed-off-by: Clemens Ladisch <clemens <at> ladisch.de>
---
 include/sound/media.h |   16 ++++++++++++++++
 sound/core/media.c    |   28 ++++++++++++++++++++++++++++
 sound/usb/card.c      |    2 ++
 3 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/include/sound/media.h b/include/sound/media.h
index ebb7c7d..5339acb 100644
--- a/include/sound/media.h
+++ b/include/sound/media.h
 <at>  <at>  -39,6 +39,15  <at>  <at>  typedef int (*snd_media_entity_get_desc_t)(struct snd_card *card,

 #define snd_card_set_media_ops(card, ops) ((card)->media_ops = (ops))

+#if defined(CONFIG_USB) || defined(CONFIG_USB_MODULE)
+int snd_media_get_usb_card_info(struct snd_card *card,
+				struct media_device_info *info);
+
+extern const struct snd_media_card_ops snd_media_default_usb_ops;
+#define snd_card_set_media_ops_default_usb(card) \
+		snd_card_set_media_ops((card), &snd_media_default_usb_ops)
+#endif
+
 int snd_media_entity_create(struct snd_card *card,
 			    snd_media_entity_get_desc_t get_desc,
 			    unsigned int id,
 <at>  <at>  -58,6 +67,13  <at>  <at>  void __exit snd_media_exit(void);
(Continue reading)

Clemens Ladisch | 28 Aug 00:34 2012
Picon

[RFC PATCH 09/11] ALSA: usb-audio: create PCM device entities

Signed-off-by: Clemens Ladisch <clemens <at> ladisch.de>
---
 sound/usb/quirks.c |    4 ++--
 sound/usb/stream.c |   16 +++++++++++-----
 sound/usb/stream.h |    1 +
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 2781726..293b4ba 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
 <at>  <at>  -152,7 +152,7  <at>  <at>  static int create_fixed_stream_quirk(struct snd_usb_audio *chip,

 	stream = (fp->endpoint & USB_DIR_IN)
 		? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
-	err = snd_usb_add_audio_stream(chip, stream, fp);
+	err = snd_usb_add_audio_stream(chip, stream, 0, fp);
 	if (err < 0) {
 		kfree(fp);
 		kfree(rate_table);
 <at>  <at>  -258,7 +258,7  <at>  <at>  static int create_uaxx_quirk(struct snd_usb_audio *chip,

 	stream = (fp->endpoint & USB_DIR_IN)
 		? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
-	err = snd_usb_add_audio_stream(chip, stream, fp);
+	err = snd_usb_add_audio_stream(chip, stream, 0, fp);
 	if (err < 0) {
 		kfree(fp);
 		return err;
diff --git a/sound/usb/stream.c b/sound/usb/stream.c
(Continue reading)

Clemens Ladisch | 28 Aug 00:35 2012
Picon

[RFC PATCH 10/11] ALSA: usb-audio: add terminal/unit entities and links

Use the terminal/unit descriptors to create entities and links.

(This should be integrated with parse_audio_unit(), but that function
does not yet support all unit types.)

Signed-off-by: Clemens Ladisch <clemens <at> ladisch.de>
---
 sound/usb/mixer.c |  278 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 278 insertions(+), 0 deletions(-)

diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 4f40ba8..a5fa807 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
 <at>  <at>  -45,6 +45,7  <at>  <at> 
 #include <linux/bitops.h>
 #include <linux/init.h>
 #include <linux/list.h>
+#include <linux/media.h>
 #include <linux/slab.h>
 #include <linux/string.h>
 #include <linux/usb.h>
 <at>  <at>  -55,6 +56,7  <at>  <at> 
 #include <sound/control.h>
 #include <sound/hwdep.h>
 #include <sound/info.h>
+#include <sound/media.h>
 #include <sound/tlv.h>

 #include "usbaudio.h"
(Continue reading)

Clemens Ladisch | 28 Aug 00:36 2012
Picon

[RFC PATCH 11/11] ALSA: hda-intel: implement card get_info callback

Add a helper for retrieving information about PCI devices.

(Codec topology information is not yet implemented.)

Signed-off-by: Clemens Ladisch <clemens <at> ladisch.de>
---
 include/sound/media.h     |   16 ++++++++++++++++
 sound/core/media.c        |   36 ++++++++++++++++++++++++++++++++++++
 sound/pci/hda/hda_intel.c |    2 ++
 3 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/include/sound/media.h b/include/sound/media.h
index 5339acb..e030e4c 100644
--- a/include/sound/media.h
+++ b/include/sound/media.h
 <at>  <at>  -39,6 +39,15  <at>  <at>  typedef int (*snd_media_entity_get_desc_t)(struct snd_card *card,

 #define snd_card_set_media_ops(card, ops) ((card)->media_ops = (ops))

+#ifdef CONFIG_PCI
+int snd_media_get_pci_card_info(struct snd_card *card,
+				struct media_device_info *info);
+
+extern const struct snd_media_card_ops snd_media_default_pci_ops;
+#define snd_card_set_media_ops_default_pci(card) \
+		snd_card_set_media_ops((card), &snd_media_default_pci_ops)
+#endif
+
 #if defined(CONFIG_USB) || defined(CONFIG_USB_MODULE)
 int snd_media_get_usb_card_info(struct snd_card *card,
(Continue reading)

Takashi Iwai | 4 Sep 17:56 2012
Picon

Re: [RFC PATCH 1/11] expose sound device topology information

Hi Clemens,

At Tue, 28 Aug 2012 00:28:30 +0200,
Clemens Ladisch wrote:
> 
> Hi,
> 
> these are some tentative patches to allow sound drivers to provide
> routing information to userspace.  (So far, snd-usb-audio has a partial
> implementation; I haven't yet had time for snd-hda-intel.  I haven't
> even looked at ASoC.)

Thanks for patches.  This brought up interesting discussions at
Plumbers.  We (kind of) agree that the media controller API can be
pretty suitable, and even Mark didn't grumble so much against it :)
It's a good sign.

> The media controller API <linux/media.h> allows prividing routing
> information, but its implementation does not quite fit the sound
> drivers:
> * it allows reconfiguration of links, but not in a way that would be
>   useful for ALSA selector controls;
> * it allows drivers to access the entity graph and pipelines, which is
>   not needed;
> * it is rather heavyweight.
> 
> Therefore, these patches create their own implementation of the media
> controller API.  In this implementation, all entity and link information
> is completely static, and more space-efficient.

(Continue reading)

Clemens Ladisch | 4 Sep 20:02 2012
Picon

Re: [RFC PATCH 1/11] expose sound device topology information

Takashi Iwai wrote:
> Clemens Ladisch wrote:
>> The media controller API <linux/media.h> allows prividing routing
>> information, but its implementation does not quite fit the sound
>> drivers:
>> * it allows reconfiguration of links, but not in a way that would be
>>   useful for ALSA selector controls

I didn't mention why:  it is not possible to enable two links to a sink
pad, and neither can one change the state of two links atomically;
therefore, an enum control with exactly one active input cannot be
modelled.  (It might be possible to change the media controller API to
allow this.)

Mute controls _could_ be modelled by disabling links, but with all other
mixer control types not represented in the media controller API, this
doesn't appear to be very useful.

> But what about multiple codecs on a single control device?  Can they
> be represented well?

The driver has to choose the entity IDs so that they don't conflict;
something like busnumber<<20 | codecaddress<<10 | nodeid.
The USB audio driver will have this problem if there are multiple audio
control interfaces, so I guess it will have to include the interface
number.

Regards,
Clemens
(Continue reading)


Gmane