Skip to contentSkip to conversation

Add mixer and control interface media entities

PATCH Superseded Shuah Khan 2 participants 9 messages Oct 20, 2015 – Nov 3, 2015

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Shuah Khan

author
#0 lore raw

v2 cover Add mixer and control interface media entities

This patch v2 series adds the following:

A fix to media_stream_delete() to remove intf devnode.

Add support for creating MEDIA_ENT_F_AUDIO_MIXER entity for each mixer and a MEDIA_INTF_T_ALSA_CONTROL control interface entity that links to mixer entities. MEDIA_INTF_T_ALSA_CONTROL entity corresponds to the control device for the card.

Change au0828_create_media_graph() to create pad link between MEDIA_ENT_F_AUDIO_MIXER entity and decoder's AU8522_PAD_AUDIO_OUT. With mixer entity now linked to decoder, change to link MEDIA_ENT_F_AUDIO_CAPTURE to mixer's source pad

Changes since v1:
1. Included the fix to media_stream_delete() which was by mistake not included in the patch v1.
2. Fixed mixer to decoder link and mider to capture node links based on Mauro Chehapb's review comments on the media graph.

This patch series is dependent on an earlier patch series:

Update ALSA, and au0828 drivers to use Managed Media Controller API:
https://www.mail-archive.com/[email protected]/msg92752.html

Please find the media graphs for ALSA work with mixer and control interface nodes:

https://drive.google.com/folderview?id=0B0NIL0BQg-AlLWE3SzAxazBJWm8&usp=sharing

Shuah Khan (3):
sound/usb: Fix media_stream_delete() to remove intf devnode sound/usb: Create media mixer function and control interface entities
media: au0828 create link between ALSA Mixer and decoder

 drivers/media/usb/au0828/au0828-core.c | 17 +++++--
 drivers/media/usb/au0828/au0828.h      |  1 +
 sound/usb/card.c                       |  5 ++
 sound/usb/media.c                      | 90 ++++++++++++++++++++++++++++++++++
 sound/usb/media.h                      | 20 ++++++++
 sound/usb/mixer.h                      |  1 +
 sound/usb/usbaudio.h                   |  1 +
 7 files changed, 132 insertions(+), 3 deletions(-)
Signature · 1 line
2.1.4
author
#1 lore raw

PATCH v2 1/3 sound/usb: Fix media_stream_delete() to remove intf devnode

media_stream_delete() doesn't remove intf_devnode. Fix it to call media_devnode_remove() to remove the intf_devnode.

---
 sound/usb/media.c | 1 +
 1 file changed, 1 insertion(+)
sound/usb/media.c +1 -0
index 9b455ad..0cbfee6 100644
@@ -173,6 +173,7 @@ void media_stream_delete(struct snd_usb_substream *subs)
 		mdev = media_device_find_devres(&subs->dev->dev);
 		if (mdev) {
 			media_entity_remove_links(&mctl->media_entity);
+			media_devnode_remove(mctl->intf_devnode);
 			media_device_unregister_entity(&mctl->media_entity);
 			media_entity_cleanup(&mctl->media_entity);
 		}
Signature · 1 line
2.1.4
author
#2 lore raw

PATCH v2 2/3 sound/usb: Create media mixer function and control interface entities

In reply to Shuah Khan

Add support for creating MEDIA_ENT_F_AUDIO_MIXER entity for each mixer and a MEDIA_INTF_T_ALSA_CONTROL control interface entity that links to mixer entities. MEDIA_INTF_T_ALSA_CONTROL entity corresponds to the control device for the card.

---
 sound/usb/card.c     |  5 +++
 sound/usb/media.c    | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 sound/usb/media.h    | 20 ++++++++++++
 sound/usb/mixer.h    |  1 +
 sound/usb/usbaudio.h |  1 +
 5 files changed, 116 insertions(+)
sound/usb/card.c +5 -0
index 469d2bf..d004cb4 100644
@@ -560,6 +560,9 @@ static int usb_audio_probe(struct usb_interface *intf,
 	if (err < 0)
 		goto __error;
 
+	/* Create media entities for mixer and control dev */
+	media_mixer_init(chip);
+
 	usb_chip[chip->index] = chip;
 	chip->num_interfaces++;
 	chip->probing = 0;
@@ -616,6 +619,8 @@ static void usb_audio_disconnect(struct usb_interface *intf)
 		list_for_each(p, &chip->midi_list) {
 			snd_usbmidi_disconnect(p);
 		}
+		/* delete mixer media resources */
+		media_mixer_delete(chip);
 		/* release mixer resources */
 		list_for_each_entry(mixer, &chip->mixer_list, list) {
 			snd_usb_mixer_disconnect(mixer);
sound/usb/media.c +89 -0

93 lines not on this page · raw message

sound/usb/media.h +20 -0
index cdcfb80..8268e52 100644
@@ -20,6 +20,7 @@
 #ifdef USE_MEDIA_CONTROLLER
 #include <media/media-device.h>
 #include <media/media-entity.h>
+#include <sound/asound.h>
 
 struct media_ctl {
 	struct media_device *media_dev;
@@ -30,6 +31,21 @@ struct media_ctl {
 	struct media_pipeline media_pipe;
 };
 
+/* One source pad each for SNDRV_PCM_STREAM_CAPTURE and
+ * SNDRV_PCM_STREAM_PLAYBACK. One for sink pad to link
+ * to AUDIO Source
+*/
+#define MEDIA_MIXER_PAD_MAX	(SNDRV_PCM_STREAM_LAST + 2)
+
+struct media_mixer_ctl {
+	struct media_device *media_dev;
+	struct media_entity media_entity;
+	struct media_intf_devnode *intf_devnode;
+	struct media_link *intf_link;
+	struct media_pad media_pad[MEDIA_MIXER_PAD_MAX];
+	struct media_pipeline media_pipe;
+};
+
 int media_device_init(struct snd_usb_audio *chip, struct usb_interface *iface);
 void media_device_delete(struct usb_interface *iface);
 int media_stream_init(struct snd_usb_substream *subs, struct snd_pcm *pcm,
@@ -37,6 +53,8 @@ int media_stream_init(struct snd_usb_substream *subs, struct snd_pcm *pcm,
 void media_stream_delete(struct snd_usb_substream *subs);
 int media_start_pipeline(struct snd_usb_substream *subs);
 void media_stop_pipeline(struct snd_usb_substream *subs);
+int media_mixer_init(struct snd_usb_audio *chip);
+void media_mixer_delete(struct snd_usb_audio *chip);
 #else
 static inline int media_device_init(struct snd_usb_audio *chip,
 					struct usb_interface *iface)
@@ -49,5 +67,7 @@ static inline void media_stream_delete(struct snd_usb_substream *subs) { }
 static inline int media_start_pipeline(struct snd_usb_substream *subs)
 					{ return 0; }
 static inline void media_stop_pipeline(struct snd_usb_substream *subs) { }
+static int media_mixer_init(struct snd_usb_audio *chip) { return 0; }
+static void media_mixer_delete(struct snd_usb_audio *chip) { }
 #endif
 #endif /* __MEDIA_H */
sound/usb/mixer.h +1 -0
index d3268f0..9d62a9e 100644
@@ -22,6 +22,7 @@ struct usb_mixer_interface {
 	struct urb *rc_urb;
 	struct usb_ctrlrequest *rc_setup_packet;
 	u8 rc_buffer[6];
+	void *media_mixer_ctl;
 };
 
 #define MAX_CHANNELS	16	/* max logical channels */
sound/usb/usbaudio.h +1 -0
index c2dbf1d..b2be7c3 100644
@@ -59,6 +59,7 @@ struct snd_usb_audio {
 	bool autoclock;			/* from the 'autoclock' module param */
 
 	struct usb_host_interface *ctrl_intf;	/* the audio control interface */
+	void *ctl_intf_media_devnode;
 };
 
 #define usb_audio_err(chip, fmt, args...) \
Signature · 1 line
2.1.4
#3 lore raw

Re: [PATCH MC Next Gen v2 2/3] sound/usb: Create media mixer function and control interface entities

Quoted 52 lines · Shuah Khan

Add support for creating MEDIA_ENT_F_AUDIO_MIXER entity for each mixer and a MEDIA_INTF_T_ALSA_CONTROL control interface entity that links to mixer entities. MEDIA_INTF_T_ALSA_CONTROL entity corresponds to the control device for the card.

---
 sound/usb/card.c     |  5 +++
 sound/usb/media.c    | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 sound/usb/media.h    | 20 ++++++++++++
 sound/usb/mixer.h    |  1 +
 sound/usb/usbaudio.h |  1 +
 5 files changed, 116 insertions(+)
sound/usb/card.c +5 -0
index 469d2bf..d004cb4 100644
@@ -560,6 +560,9 @@ static int usb_audio_probe(struct usb_interface *intf,
 	if (err < 0)
 		goto __error;
 
+	/* Create media entities for mixer and control dev */
+	media_mixer_init(chip);
+
 	usb_chip[chip->index] = chip;
 	chip->num_interfaces++;
 	chip->probing = 0;
@@ -616,6 +619,8 @@ static void usb_audio_disconnect(struct usb_interface *intf)
 		list_for_each(p, &chip->midi_list) {
 			snd_usbmidi_disconnect(p);
 		}
+		/* delete mixer media resources */
+		media_mixer_delete(chip);
 		/* release mixer resources */
 		list_for_each_entry(mixer, &chip->mixer_list, list) {
 			snd_usb_mixer_disconnect(mixer);
sound/usb/media.c +6 -0
index 0cbfee6..a26ea8b 100644
@@ -199,4 +199,93 @@ void media_stop_pipeline(struct snd_usb_substream *subs)
 	if (mctl)
 		media_disable_source(mctl);
 }
+
+int media_mixer_init(struct snd_usb_audio *chip)
+{
+	struct device *ctl_dev = &chip->card->ctl_dev;
+	struct media_intf_devnode *ctl_intf;
+	struct usb_mixer_interface *mixer;

sound/usb/media.c void media_stop_pipeline(struct snd_usb_substream *subs) · line 217

Quoted 10 lines
sound/usb/media.c +10 -0
+	struct media_device *mdev;
+	struct media_mixer_ctl *mctl;
+	u32 intf_type = MEDIA_INTF_T_ALSA_CONTROL;
+	int ret;
+
+	mdev = media_device_find_devres(&chip->dev->dev);
+	if (!mdev)
+		return -ENODEV;
+
+	ctl_intf = (struct media_intf_devnode *) chip->ctl_intf_media_devnode;

Why do we need cast? Can't chip->ctl_intf_media_devnode itself be struct media_intf_devndoe pointer?

sound/usb/media.c void media_stop_pipeline(struct snd_usb_substream *subs) · line 225

Quoted 8 lines
sound/usb/media.c +8 -0
+	if (!ctl_intf) {
+		ctl_intf = (void *) media_devnode_create(mdev,
+							 intf_type, 0,
+							 MAJOR(ctl_dev->devt),
+							 MINOR(ctl_dev->devt));
+		if (!ctl_intf)
+			return -ENOMEM;
+	}

Is chip->ctl_intf_media_devnode assigned anywhere at all?

Not directly related with this patchset: the above uses media_devnode_create(), which I assume it's a device-file (major:minor) specific. What if sound hardware with multiple codecs and so on in general?

Quoted 15 lines
sound/usb/media.c +15 -0
+
+	list_for_each_entry(mixer, &chip->mixer_list, list) {
+
+		if (mixer->media_mixer_ctl)
+			continue;
+
+		/* allocate media_ctl */
+		mctl = kzalloc(sizeof(struct media_ctl), GFP_KERNEL);
+		if (!mctl)
+			return -ENOMEM;
+
+		mixer->media_mixer_ctl = (void *) mctl;
+		mctl->media_dev = mdev;
+
+		mctl->media_entity.function = MEDIA_ENT_F_AUDIO_MIXER;

sound/usb/media.c void media_stop_pipeline(struct snd_usb_substream *subs) · line 250

Quoted 10 lines
sound/usb/media.c +10 -0
+		mctl->media_entity.name = chip->card->mixername;
+		mctl->media_pad[0].flags = MEDIA_PAD_FL_SINK;
+		mctl->media_pad[1].flags = MEDIA_PAD_FL_SOURCE;
+		mctl->media_pad[2].flags = MEDIA_PAD_FL_SOURCE;
+		media_entity_init(&mctl->media_entity, MEDIA_MIXER_PAD_MAX,
+				  mctl->media_pad);
+		ret =  media_device_register_entity(mctl->media_dev,
+						    &mctl->media_entity);
+		if (ret)
+			return ret;

Will the last (unfinished) mctl be freed properly in the error path?

sound/usb/media.c void media_stop_pipeline(struct snd_usb_substream *subs) · line 257

Quoted 6 lines
sound/usb/media.c +6 -0
+		mctl->intf_link = media_create_intf_link(&mctl->media_entity,
+							 &ctl_intf->intf,
+							 MEDIA_LNK_FL_ENABLED);
+		if (!mctl->intf_link) {
+			media_device_unregister_entity(&mctl->media_entity);
+			return -ENOMEM;

Ditto.

Quoted 18 lines
sound/usb/media.c +18 -0
+		}
+		mctl->intf_devnode = ctl_intf;
+	}
+	return 0;
+}
+
+void media_mixer_delete(struct snd_usb_audio *chip)
+{
+	struct usb_mixer_interface *mixer;
+	struct media_device *mdev;
+
+	mdev = media_device_find_devres(&chip->dev->dev);
+	if (!mdev)
+		return;
+
+	list_for_each_entry(mixer, &chip->mixer_list, list) {
+		struct media_mixer_ctl *mctl;
+

sound/usb/media.c void media_stop_pipeline(struct snd_usb_substream *subs) · line 285

Quoted 10 lines
sound/usb/media.c +10 -0
+		mctl = (struct media_mixer_ctl *) mixer->media_mixer_ctl;
+		if (!mixer->media_mixer_ctl)
+			continue;
+
+		media_entity_remove_links(&mctl->media_entity);
+		media_device_unregister_entity(&mctl->media_entity);
+		media_entity_cleanup(&mctl->media_entity);
+		mctl->media_dev = NULL;
+		mctl->intf_devnode = NULL;
+		kfree(mctl);

The previous two NULL are superfluous as we'll free them immediately.

thanks,

Takashi

Quoted 84 lines
sound/usb/media.c +5 -0
+		mixer->media_mixer_ctl = NULL;
+	}
+	media_devnode_remove(chip->ctl_intf_media_devnode);
+}
+
 #endif
sound/usb/media.h +20 -0
index cdcfb80..8268e52 100644
@@ -20,6 +20,7 @@
 #ifdef USE_MEDIA_CONTROLLER
 #include <media/media-device.h>
 #include <media/media-entity.h>
+#include <sound/asound.h>
 
 struct media_ctl {
 	struct media_device *media_dev;
@@ -30,6 +31,21 @@ struct media_ctl {
 	struct media_pipeline media_pipe;
 };
 
+/* One source pad each for SNDRV_PCM_STREAM_CAPTURE and
+ * SNDRV_PCM_STREAM_PLAYBACK. One for sink pad to link
+ * to AUDIO Source
+*/
+#define MEDIA_MIXER_PAD_MAX	(SNDRV_PCM_STREAM_LAST + 2)
+
+struct media_mixer_ctl {
+	struct media_device *media_dev;
+	struct media_entity media_entity;
+	struct media_intf_devnode *intf_devnode;
+	struct media_link *intf_link;
+	struct media_pad media_pad[MEDIA_MIXER_PAD_MAX];
+	struct media_pipeline media_pipe;
+};
+
 int media_device_init(struct snd_usb_audio *chip, struct usb_interface *iface);
 void media_device_delete(struct usb_interface *iface);
 int media_stream_init(struct snd_usb_substream *subs, struct snd_pcm *pcm,
@@ -37,6 +53,8 @@ int media_stream_init(struct snd_usb_substream *subs, struct snd_pcm *pcm,
 void media_stream_delete(struct snd_usb_substream *subs);
 int media_start_pipeline(struct snd_usb_substream *subs);
 void media_stop_pipeline(struct snd_usb_substream *subs);
+int media_mixer_init(struct snd_usb_audio *chip);
+void media_mixer_delete(struct snd_usb_audio *chip);
 #else
 static inline int media_device_init(struct snd_usb_audio *chip,
 					struct usb_interface *iface)
@@ -49,5 +67,7 @@ static inline void media_stream_delete(struct snd_usb_substream *subs) { }
 static inline int media_start_pipeline(struct snd_usb_substream *subs)
 					{ return 0; }
 static inline void media_stop_pipeline(struct snd_usb_substream *subs) { }
+static int media_mixer_init(struct snd_usb_audio *chip) { return 0; }
+static void media_mixer_delete(struct snd_usb_audio *chip) { }
 #endif
 #endif /* __MEDIA_H */
sound/usb/mixer.h +1 -0
index d3268f0..9d62a9e 100644
@@ -22,6 +22,7 @@ struct usb_mixer_interface {
 	struct urb *rc_urb;
 	struct usb_ctrlrequest *rc_setup_packet;
 	u8 rc_buffer[6];
+	void *media_mixer_ctl;
 };
 
 #define MAX_CHANNELS	16	/* max logical channels */
sound/usb/usbaudio.h +1 -0
index c2dbf1d..b2be7c3 100644
@@ -59,6 +59,7 @@ struct snd_usb_audio {
 	bool autoclock;			/* from the 'autoclock' module param */
 
 	struct usb_host_interface *ctrl_intf;	/* the audio control interface */
+	void *ctl_intf_media_devnode;
 };
 
 #define usb_audio_err(chip, fmt, args...) \
Signature · 1 line
2.1.4
author
#4 lore raw

Re: [PATCH MC Next Gen v2 2/3] sound/usb: Create media mixer function and control interface entities

Quoted 59 lines · Takashi Iwai
Quoted 57 lines · Shuah Khan

Add support for creating MEDIA_ENT_F_AUDIO_MIXER entity for each mixer and a MEDIA_INTF_T_ALSA_CONTROL control interface entity that links to mixer entities. MEDIA_INTF_T_ALSA_CONTROL entity corresponds to the control device for the card.

---
  sound/usb/card.c     |  5 +++
  sound/usb/media.c    | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  sound/usb/media.h    | 20 ++++++++++++
  sound/usb/mixer.h    |  1 +
  sound/usb/usbaudio.h |  1 +
  5 files changed, 116 insertions(+)
sound/usb/card.c +5 -0
index 469d2bf..d004cb4 100644
@@ -560,6 +560,9 @@ static int usb_audio_probe(struct usb_interface *intf,
  	if (err < 0)
  		goto __error;
 
+	/* Create media entities for mixer and control dev */
+	media_mixer_init(chip);
+
  	usb_chip[chip->index] = chip;
  	chip->num_interfaces++;
  	chip->probing = 0;
@@ -616,6 +619,8 @@ static void usb_audio_disconnect(struct usb_interface *intf)
  		list_for_each(p, &chip->midi_list) {
  			snd_usbmidi_disconnect(p);
  		}
+		/* delete mixer media resources */
+		media_mixer_delete(chip);
  		/* release mixer resources */
  		list_for_each_entry(mixer, &chip->mixer_list, list) {
  			snd_usb_mixer_disconnect(mixer);
sound/usb/media.c +11 -0
index 0cbfee6..a26ea8b 100644
@@ -199,4 +199,93 @@ void media_stop_pipeline(struct snd_usb_substream *subs)
  	if (mctl)
  		media_disable_source(mctl);
  }
+
+int media_mixer_init(struct snd_usb_audio *chip)
+{
+	struct device *ctl_dev = &chip->card->ctl_dev;
+	struct media_intf_devnode *ctl_intf;
+	struct usb_mixer_interface *mixer;
+	struct media_device *mdev;
+	struct media_mixer_ctl *mctl;
+	u32 intf_type = MEDIA_INTF_T_ALSA_CONTROL;
+	int ret;
+
Quoted 8 lines

sound/usb/media.c void media_stop_pipeline(struct snd_usb_substream *subs) · line 217

Quoted 5 lines
sound/usb/media.c +5 -0
+	mdev = media_device_find_devres(&chip->dev->dev);
+	if (!mdev)
+		return -ENODEV;
+
+	ctl_intf = (struct media_intf_devnode *) chip->ctl_intf_media_devnode;

Why do we need cast? Can't chip->ctl_intf_media_devnode itself be struct media_intf_devndoe pointer?

Yeah. There is no need to cast here. I will fix it.

Quoted 9 lines

sound/usb/media.c void media_stop_pipeline(struct snd_usb_substream *subs) · line 224

Quoted 9 lines
sound/usb/media.c +7 -0
+	if (!ctl_intf) {
+		ctl_intf = (void *) media_devnode_create(mdev,
+							 intf_type, 0,
+							 MAJOR(ctl_dev->devt),
+							 MINOR(ctl_dev->devt));
+		if (!ctl_intf)
+			return -ENOMEM;

chip->ctl_intf_media_devnode = ctl_intf;

Quoted 3 lines

sound/usb/media.c void media_stop_pipeline(struct snd_usb_substream *subs) · line 225

Quoted 1 line
sound/usb/media.c +1 -0
+	}

Is chip->ctl_intf_media_devnode assigned anywhere at all?

Thanks. Great find. I missed that one. It should be assigned as above in media_devnode_create() success path.

Quoted 5 lines

Not directly related with this patchset: the above uses media_devnode_create(), which I assume it's a device-file (major:minor) specific. What if sound hardware with multiple codecs and so on in general?

Yes. It is for the control device. I looked at the multiple codecs case briefly, but it requires more thought. Maybe something I could bring up at the Media Workshop today if time permits.

Quoted 21 lines
Quoted 21 lines
sound/usb/media.c +19 -0
+
+	list_for_each_entry(mixer, &chip->mixer_list, list) {
+
+		if (mixer->media_mixer_ctl)
+			continue;
+
+		/* allocate media_ctl */
+		mctl = kzalloc(sizeof(struct media_ctl), GFP_KERNEL);
+		if (!mctl)
+			return -ENOMEM;
+
+		mixer->media_mixer_ctl = (void *) mctl;
+		mctl->media_dev = mdev;
+
+		mctl->media_entity.function = MEDIA_ENT_F_AUDIO_MIXER;
+		mctl->media_entity.name = chip->card->mixername;
+		mctl->media_pad[0].flags = MEDIA_PAD_FL_SINK;
+		mctl->media_pad[1].flags = MEDIA_PAD_FL_SOURCE;
+		mctl->media_pad[2].flags = MEDIA_PAD_FL_SOURCE;
Quoted 8 lines

sound/usb/media.c void media_stop_pipeline(struct snd_usb_substream *subs) · line 250

Quoted 6 lines
sound/usb/media.c +6 -0
+		media_entity_init(&mctl->media_entity, MEDIA_MIXER_PAD_MAX,
+				  mctl->media_pad);
+		ret =  media_device_register_entity(mctl->media_dev,
+						    &mctl->media_entity);
+		if (ret)
+			return ret;

Will the last (unfinished) mctl be freed properly in the error path?

Should be I will make sure.

Quoted 32 lines

sound/usb/media.c void media_stop_pipeline(struct snd_usb_substream *subs) · line 257

Quoted 7 lines
sound/usb/media.c +6 -0
+		mctl->intf_link = media_create_intf_link(&mctl->media_entity,
+							 &ctl_intf->intf,
+							 MEDIA_LNK_FL_ENABLED);
+		if (!mctl->intf_link) {
+			media_device_unregister_entity(&mctl->media_entity);
+			return -ENOMEM;

Ditto.

Quoted 22 lines
sound/usb/media.c +22 -0
+		}
+		mctl->intf_devnode = ctl_intf;
+	}
+	return 0;
+}
+
+void media_mixer_delete(struct snd_usb_audio *chip)
+{
+	struct usb_mixer_interface *mixer;
+	struct media_device *mdev;
+
+	mdev = media_device_find_devres(&chip->dev->dev);
+	if (!mdev)
+		return;
+
+	list_for_each_entry(mixer, &chip->mixer_list, list) {
+		struct media_mixer_ctl *mctl;
+
+		mctl = (struct media_mixer_ctl *) mixer->media_mixer_ctl;
+		if (!mixer->media_mixer_ctl)
+			continue;
+
Quoted 8 lines

sound/usb/media.c void media_stop_pipeline(struct snd_usb_substream *subs) · line 285

Quoted 6 lines
sound/usb/media.c +6 -0
+		media_entity_remove_links(&mctl->media_entity);
+		media_device_unregister_entity(&mctl->media_entity);
+		media_entity_cleanup(&mctl->media_entity);
+		mctl->media_dev = NULL;
+		mctl->intf_devnode = NULL;
+		kfree(mctl);

The previous two NULL are superfluous as we'll free them immediately.

Yes. I will fix that.

Thanks for the review

-- Shuah

Quoted 91 lines

thanks,

Takashi

Quoted 84 lines
sound/usb/media.c +5 -0
+		mixer->media_mixer_ctl = NULL;
+	}
+	media_devnode_remove(chip->ctl_intf_media_devnode);
+}
+
  #endif
sound/usb/media.h +20 -0
index cdcfb80..8268e52 100644
@@ -20,6 +20,7 @@
  #ifdef USE_MEDIA_CONTROLLER
  #include <media/media-device.h>
  #include <media/media-entity.h>
+#include <sound/asound.h>
 
  struct media_ctl {
  	struct media_device *media_dev;
@@ -30,6 +31,21 @@ struct media_ctl {
  	struct media_pipeline media_pipe;
  };
 
+/* One source pad each for SNDRV_PCM_STREAM_CAPTURE and
+ * SNDRV_PCM_STREAM_PLAYBACK. One for sink pad to link
+ * to AUDIO Source
+*/
+#define MEDIA_MIXER_PAD_MAX	(SNDRV_PCM_STREAM_LAST + 2)
+
+struct media_mixer_ctl {
+	struct media_device *media_dev;
+	struct media_entity media_entity;
+	struct media_intf_devnode *intf_devnode;
+	struct media_link *intf_link;
+	struct media_pad media_pad[MEDIA_MIXER_PAD_MAX];
+	struct media_pipeline media_pipe;
+};
+
  int media_device_init(struct snd_usb_audio *chip, struct usb_interface *iface);
  void media_device_delete(struct usb_interface *iface);
  int media_stream_init(struct snd_usb_substream *subs, struct snd_pcm *pcm,
@@ -37,6 +53,8 @@ int media_stream_init(struct snd_usb_substream *subs, struct snd_pcm *pcm,
  void media_stream_delete(struct snd_usb_substream *subs);
  int media_start_pipeline(struct snd_usb_substream *subs);
  void media_stop_pipeline(struct snd_usb_substream *subs);
+int media_mixer_init(struct snd_usb_audio *chip);
+void media_mixer_delete(struct snd_usb_audio *chip);
  #else
  static inline int media_device_init(struct snd_usb_audio *chip,
  					struct usb_interface *iface)
@@ -49,5 +67,7 @@ static inline void media_stream_delete(struct snd_usb_substream *subs) { }
  static inline int media_start_pipeline(struct snd_usb_substream *subs)
  					{ return 0; }
  static inline void media_stop_pipeline(struct snd_usb_substream *subs) { }
+static int media_mixer_init(struct snd_usb_audio *chip) { return 0; }
+static void media_mixer_delete(struct snd_usb_audio *chip) { }
  #endif
  #endif /* __MEDIA_H */
sound/usb/mixer.h +1 -0
index d3268f0..9d62a9e 100644
@@ -22,6 +22,7 @@ struct usb_mixer_interface {
  	struct urb *rc_urb;
  	struct usb_ctrlrequest *rc_setup_packet;
  	u8 rc_buffer[6];
+	void *media_mixer_ctl;
  };
 
  #define MAX_CHANNELS	16	/* max logical channels */
sound/usb/usbaudio.h +1 -1
index c2dbf1d..b2be7c3 100644
@@ -59,6 +59,7 @@ struct snd_usb_audio {
  	bool autoclock;			/* from the 'autoclock' module param */
 
  	struct usb_host_interface *ctrl_intf;	/* the audio control interface */
+	void *ctl_intf_media_devnode;
  };
 
  #define usb_audio_err(chip, fmt, args...) \
--

2.1.4

Signature · 4 lines
Shuah Khan
Sr. Linux Kernel Developer
Samsung Research America (Silicon Valley)
[email protected] | (970) 217-8978
author
#5 lore raw

Re: [PATCH MC Next Gen v2 2/3] sound/usb: Create media mixer function and control interface entities

Quoted 74 lines · Shuah Khan
Quoted 64 lines · Takashi Iwai
Quoted 62 lines · Shuah Khan

Add support for creating MEDIA_ENT_F_AUDIO_MIXER entity for each mixer and a MEDIA_INTF_T_ALSA_CONTROL control interface entity that links to mixer entities. MEDIA_INTF_T_ALSA_CONTROL entity corresponds to the control device for the card.

---
  sound/usb/card.c     |  5 +++
  sound/usb/media.c    | 89
++++++++++++++++++++++++++++++++++++++++++++++++++++
  sound/usb/media.h    | 20 ++++++++++++
  sound/usb/mixer.h    |  1 +
  sound/usb/usbaudio.h |  1 +
  5 files changed, 116 insertions(+)
sound/usb/card.c +3 -0
index 469d2bf..d004cb4 100644
@@ -560,6 +560,9 @@ static int usb_audio_probe(struct usb_interface
 *intf,
      if (err < 0)
          goto __error;
 
+    /* Create media entities for mixer and control dev */
+    media_mixer_init(chip);
+
      usb_chip[chip->index] = chip;
      chip->num_interfaces++;
      chip->probing = 0;
sound/usb/card.c +2 -0
@@ -616,6 +619,8 @@ static void usb_audio_disconnect(struct
 usb_interface *intf)
          list_for_each(p, &chip->midi_list) {
              snd_usbmidi_disconnect(p);
          }
+        /* delete mixer media resources */
+        media_mixer_delete(chip);
          /* release mixer resources */
          list_for_each_entry(mixer, &chip->mixer_list, list) {
              snd_usb_mixer_disconnect(mixer);
sound/usb/media.c +12 -0
index 0cbfee6..a26ea8b 100644
@@ -199,4 +199,93 @@ void media_stop_pipeline(struct
 snd_usb_substream *subs)
      if (mctl)
          media_disable_source(mctl);
  }
+
+int media_mixer_init(struct snd_usb_audio *chip)
+{
+    struct device *ctl_dev = &chip->card->ctl_dev;
+    struct media_intf_devnode *ctl_intf;
+    struct usb_mixer_interface *mixer;
+    struct media_device *mdev;
+    struct media_mixer_ctl *mctl;
+    u32 intf_type = MEDIA_INTF_T_ALSA_CONTROL;
+    int ret;
+
+    mdev = media_device_find_devres(&chip->dev->dev);
Quoted 8 lines
Quoted 5 lines
sound/usb/media.c +4 -0
+    if (!mdev)
+        return -ENODEV;
+
+    ctl_intf = (struct media_intf_devnode *)

chip->ctl_intf_media_devnode;

Why do we need cast? Can't chip->ctl_intf_media_devnode itself be struct media_intf_devndoe pointer?

Quoted 1 line

Yeah. There is no need to cast here. I will fix it.

Sorry I misspoke. The reason for this cast is ctl_intf_media_devnode is void to avoid including media.h and other media files in usbaudio.h

The same approach I took for card.h when adding media_ctl to struct snd_usb_substream

Does this sound reasonable or would you rather see these to be their respective struct pointers which would require including media.h in these headers?

thanks,
-- Shuah

Signature · 5 lines
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
[email protected] | (970) 217-8978
#6 lore raw

Re: [PATCH MC Next Gen v2 2/3] sound/usb: Create media mixer function and control interface entities

Quoted 76 lines · Shuah Khan
Quoted 74 lines · Shuah Khan
Quoted 72 lines · Takashi Iwai
Quoted 66 lines · Shuah Khan

Add support for creating MEDIA_ENT_F_AUDIO_MIXER entity for each mixer and a MEDIA_INTF_T_ALSA_CONTROL control interface entity that links to mixer entities. MEDIA_INTF_T_ALSA_CONTROL entity corresponds to the control device for the card.

---
  sound/usb/card.c     |  5 +++
  sound/usb/media.c    | 89
++++++++++++++++++++++++++++++++++++++++++++++++++++
  sound/usb/media.h    | 20 ++++++++++++
  sound/usb/mixer.h    |  1 +
  sound/usb/usbaudio.h |  1 +
  5 files changed, 116 insertions(+)
sound/usb/card.c +3 -0
index 469d2bf..d004cb4 100644
@@ -560,6 +560,9 @@ static int usb_audio_probe(struct usb_interface
 *intf,
      if (err < 0)
          goto __error;
 
+    /* Create media entities for mixer and control dev */
+    media_mixer_init(chip);
+
      usb_chip[chip->index] = chip;
      chip->num_interfaces++;
      chip->probing = 0;
sound/usb/card.c +2 -0
@@ -616,6 +619,8 @@ static void usb_audio_disconnect(struct
 usb_interface *intf)
          list_for_each(p, &chip->midi_list) {
              snd_usbmidi_disconnect(p);
          }
+        /* delete mixer media resources */
+        media_mixer_delete(chip);
          /* release mixer resources */
          list_for_each_entry(mixer, &chip->mixer_list, list) {
              snd_usb_mixer_disconnect(mixer);
sound/usb/media.c +16 -0
index 0cbfee6..a26ea8b 100644
@@ -199,4 +199,93 @@ void media_stop_pipeline(struct
 snd_usb_substream *subs)
      if (mctl)
          media_disable_source(mctl);
  }
+
+int media_mixer_init(struct snd_usb_audio *chip)
+{
+    struct device *ctl_dev = &chip->card->ctl_dev;
+    struct media_intf_devnode *ctl_intf;
+    struct usb_mixer_interface *mixer;
+    struct media_device *mdev;
+    struct media_mixer_ctl *mctl;
+    u32 intf_type = MEDIA_INTF_T_ALSA_CONTROL;
+    int ret;
+
+    mdev = media_device_find_devres(&chip->dev->dev);
+    if (!mdev)
+        return -ENODEV;
+
+    ctl_intf = (struct media_intf_devnode *)
Quoted 1 line

chip->ctl_intf_media_devnode;

Why do we need cast? Can't chip->ctl_intf_media_devnode itself be struct media_intf_devndoe pointer?

Quoted 4 lines
Quoted 1 line

Yeah. There is no need to cast here. I will fix it.

Sorry I misspoke. The reason for this cast is ctl_intf_media_devnode is void to avoid including media.h and other media files in usbaudio.h

You can declare the struct without definition in each header file. So just declare it and use it in usbaudio.h like:

struct media_intf_devnode;

struct snd_usb_audio {
	....
	struct media_intf_devnode *ctl_intf_media_devnode;
	....

And even if you're using a void pointer there instead of the explicit struct pointer, the cast is superfluous. The implicit cast between a void pointer and any other pointer is valid in plain C.

Takashi

author
#7 lore raw

Re: [PATCH MC Next Gen v2 2/3] sound/usb: Create media mixer function and control interface entities

Quoted 88 lines · Takashi Iwai
Quoted 76 lines · Shuah Khan
Quoted 74 lines · Shuah Khan
Quoted 72 lines · Takashi Iwai
Quoted 66 lines · Shuah Khan

Add support for creating MEDIA_ENT_F_AUDIO_MIXER entity for each mixer and a MEDIA_INTF_T_ALSA_CONTROL control interface entity that links to mixer entities. MEDIA_INTF_T_ALSA_CONTROL entity corresponds to the control device for the card.

---
  sound/usb/card.c     |  5 +++
  sound/usb/media.c    | 89
++++++++++++++++++++++++++++++++++++++++++++++++++++
  sound/usb/media.h    | 20 ++++++++++++
  sound/usb/mixer.h    |  1 +
  sound/usb/usbaudio.h |  1 +
  5 files changed, 116 insertions(+)
sound/usb/card.c +3 -0
index 469d2bf..d004cb4 100644
@@ -560,6 +560,9 @@ static int usb_audio_probe(struct usb_interface
 *intf,
      if (err < 0)
          goto __error;
 
+    /* Create media entities for mixer and control dev */
+    media_mixer_init(chip);
+
      usb_chip[chip->index] = chip;
      chip->num_interfaces++;
      chip->probing = 0;
sound/usb/card.c +2 -0
@@ -616,6 +619,8 @@ static void usb_audio_disconnect(struct
 usb_interface *intf)
          list_for_each(p, &chip->midi_list) {
              snd_usbmidi_disconnect(p);
          }
+        /* delete mixer media resources */
+        media_mixer_delete(chip);
          /* release mixer resources */
          list_for_each_entry(mixer, &chip->mixer_list, list) {
              snd_usb_mixer_disconnect(mixer);
sound/usb/media.c +16 -0
index 0cbfee6..a26ea8b 100644
@@ -199,4 +199,93 @@ void media_stop_pipeline(struct
 snd_usb_substream *subs)
      if (mctl)
          media_disable_source(mctl);
  }
+
+int media_mixer_init(struct snd_usb_audio *chip)
+{
+    struct device *ctl_dev = &chip->card->ctl_dev;
+    struct media_intf_devnode *ctl_intf;
+    struct usb_mixer_interface *mixer;
+    struct media_device *mdev;
+    struct media_mixer_ctl *mctl;
+    u32 intf_type = MEDIA_INTF_T_ALSA_CONTROL;
+    int ret;
+
+    mdev = media_device_find_devres(&chip->dev->dev);
+    if (!mdev)
+        return -ENODEV;
+
+    ctl_intf = (struct media_intf_devnode *)
Quoted 1 line

chip->ctl_intf_media_devnode;

Why do we need cast? Can't chip->ctl_intf_media_devnode itself be struct media_intf_devndoe pointer?

Quoted 4 lines
Quoted 1 line

Yeah. There is no need to cast here. I will fix it.

Sorry I misspoke. The reason for this cast is ctl_intf_media_devnode is void to avoid including media.h and other media files in usbaudio.h

You can declare the struct without definition in each header file. So just declare it and use it in usbaudio.h like:

struct media_intf_devnode;

Quoted 9 lines
struct snd_usb_audio {
	....
	struct media_intf_devnode *ctl_intf_media_devnode;
	....

And even if you're using a void pointer there instead of the explicit struct pointer, the cast is superfluous. The implicit cast between a void pointer and any other pointer is valid in plain C.

Yes. cast is definitely not necessary. I will drop the cast and leave the rest alone.

thanks,
-- Shuah

Signature · 5 lines
Shuah Khan
Sr. Linux Kernel Developer
Open Source Innovation Group
Samsung Research America (Silicon Valley)
[email protected] | (970) 217-8978
author
#8 lore raw

PATCH v2 3/3 media: au0828 create link between ALSA Mixer and decoder

In reply to Shuah Khan

Change au0828_create_media_graph() to create pad link between MEDIA_ENT_F_AUDIO_MIXER entity and decoder's AU8522_PAD_AUDIO_OUT. With mixer entity now linked to decoder, change to link MEDIA_ENT_F_AUDIO_CAPTURE to mixer's source pad.

---
 drivers/media/usb/au0828/au0828-core.c | 17 ++++++++++++++---
 drivers/media/usb/au0828/au0828.h      |  1 +
 2 files changed, 15 insertions(+), 3 deletions(-)
drivers/media/usb/au0828/au0828-core.c +14 -3
index 7af5d0d..3ef6fee 100644
@@ -225,6 +225,7 @@ void au0828_create_media_graph(struct media_entity *new, void *notify_data)
 	struct media_entity *entity;
 	struct media_entity *tuner = NULL, *decoder = NULL;
 	struct media_entity *audio_capture = NULL;
+	struct media_entity *mixer = NULL;
 	int i, ret;
 
 	if (!mdev)
@@ -245,6 +246,9 @@ void au0828_create_media_graph(struct media_entity *new, void *notify_data)
 		case MEDIA_ENT_F_AUDIO_CAPTURE:
 			audio_capture = entity;
 			break;
+		case MEDIA_ENT_F_AUDIO_MIXER:
+			mixer = entity;
+			break;
 		}
 	}
 
@@ -309,13 +313,20 @@ void au0828_create_media_graph(struct media_entity *new, void *notify_data)
 		}
 	}
 
-	if (audio_capture && !dev->audio_capture_linked) {
-		ret = media_create_pad_link(decoder, AU8522_PAD_AUDIO_OUT,
-					    audio_capture, 0,
+	if (mixer && audio_capture && !dev->audio_capture_linked) {
+		ret = media_create_pad_link(mixer, 1, audio_capture, 0,
 					    MEDIA_LNK_FL_ENABLED);
 		if (ret == 0)
 			dev->audio_capture_linked = 1;
 	}
+
+	if (mixer && !dev->mixer_linked) {
+		ret = media_create_pad_link(decoder, AU8522_PAD_AUDIO_OUT,
+					    mixer, 0,
+					    MEDIA_LNK_FL_ENABLED);
+		if (ret == 0)
+			dev->mixer_linked = 1;
+	}
 #endif
 }
 
drivers/media/usb/au0828/au0828.h +1 -0
index 2f4d597..6dd81b2 100644
@@ -288,6 +288,7 @@ struct au0828_dev {
 	bool vdev_linked;
 	bool vbi_linked;
 	bool audio_capture_linked;
+	bool mixer_linked;
 	struct media_link *active_link;
 	struct media_entity *active_link_owner;
 #endif
Signature · 1 line
2.1.4