alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Provide sequencer sound card number / PID via alsa-lib
@ 2016-02-13 13:42 Martin Koegler
  2016-02-13 13:42 ` [PATCH] Show sequencer sound card numer/PID via aconnect Martin Koegler
                   ` (2 more replies)
  0 siblings, 3 replies; 21+ messages in thread
From: Martin Koegler @ 2016-02-13 13:42 UTC (permalink / raw)
  To: alsa-devel; +Cc: Martin Koegler

From: Martin Koegler <martin.koegler@chello.at>

rawmidi devices expose the card number via IOCTLs, which allows to
find the corresponding device in sysfs.

The sequencer provides no identifing data. Chromium works around this
issue by scanning rawmidi as well as sequencer devices and matching
them by using assumtions, how the kernel register sequencer devices.

This changes adds support for exposing the card number for kernel clients
as well as the PID for user client.

It supports kernels with and without the required support.

Signed-off-by: Martin Koegler <martin.koegler@chello.at>
---
 include/seq.h              |  1 +
 include/sound/asequencer.h |  5 +++--
 src/seq/seq.c              | 11 +++++++++++
 src/seq/seq_hw.c           |  8 +++++++-
 4 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/include/seq.h b/include/seq.h
index 9576822..77996e5 100644
--- a/include/seq.h
+++ b/include/seq.h
@@ -143,6 +143,7 @@ snd_seq_client_type_t snd_seq_client_info_get_type(const snd_seq_client_info_t *
 const char *snd_seq_client_info_get_name(snd_seq_client_info_t *info);
 int snd_seq_client_info_get_broadcast_filter(const snd_seq_client_info_t *info);
 int snd_seq_client_info_get_error_bounce(const snd_seq_client_info_t *info);
+int snd_seq_client_info_get_owner(const snd_seq_client_info_t *info);
 const unsigned char *snd_seq_client_info_get_event_filter(const snd_seq_client_info_t *info);
 int snd_seq_client_info_get_num_ports(const snd_seq_client_info_t *info);
 int snd_seq_client_info_get_event_lost(const snd_seq_client_info_t *info);
diff --git a/include/sound/asequencer.h b/include/sound/asequencer.h
index 09c8a00..7ebf7fd 100644
--- a/include/sound/asequencer.h
+++ b/include/sound/asequencer.h
@@ -24,7 +24,7 @@
 
 
 /** version of the sequencer */
-#define SNDRV_SEQ_VERSION SNDRV_PROTOCOL_VERSION (1, 0, 1)
+#define SNDRV_SEQ_VERSION SNDRV_PROTOCOL_VERSION (1, 0, 2)
 
 /**
  * definition of sequencer event types
@@ -356,7 +356,8 @@ struct snd_seq_client_info {
 	unsigned char event_filter[32];	/* event filter bitmap */
 	int num_ports;			/* RO: number of ports */
 	int event_lost;			/* number of lost events */
-	char reserved[64];		/* for future use */
+	int owner;			/* RO: card number[kernel] / PID[user] */
+	char reserved[64 - sizeof(int)]; /* for future use */
 };
 
 
diff --git a/src/seq/seq.c b/src/seq/seq.c
index 620ca3f..2505293 100644
--- a/src/seq/seq.c
+++ b/src/seq/seq.c
@@ -1522,6 +1522,17 @@ int snd_seq_client_info_get_error_bounce(const snd_seq_client_info_t *info)
 }
 
 /**
+ * \brief Get the sound card number (kernel) or owning PID
+ * \param info client_info container
+ * \return card number/PID/-1 if value is not available.
+ */
+int snd_seq_client_info_get_owner(const snd_seq_client_info_t *info)
+{
+	assert(info);
+	return info->owner;
+}
+
+/**
  * \brief (DEPRECATED) Get the event filter bitmap of a client_info container
  * \param info client_info container
  * \return NULL if no event filter, or pointer to event filter bitmap
diff --git a/src/seq/seq_hw.c b/src/seq/seq_hw.c
index d033367..a4c083a 100644
--- a/src/seq/seq_hw.c
+++ b/src/seq/seq_hw.c
@@ -32,10 +32,11 @@ const char *_snd_module_seq_hw = "";
 #ifndef DOC_HIDDEN
 #define SNDRV_FILE_SEQ		ALSA_DEVICE_DIRECTORY "seq"
 #define SNDRV_FILE_ALOADSEQ	ALOAD_DEVICE_DIRECTORY "aloadSEQ"
-#define SNDRV_SEQ_VERSION_MAX	SNDRV_PROTOCOL_VERSION(1, 0, 1)
+#define SNDRV_SEQ_VERSION_MAX	SNDRV_PROTOCOL_VERSION(1, 0, 2)
 
 typedef struct {
 	int fd;
+	int micro_version;
 } snd_seq_hw_t;
 #endif /* DOC_HIDDEN */
 
@@ -100,6 +101,8 @@ static int snd_seq_hw_get_client_info(snd_seq_t *seq, snd_seq_client_info_t * in
 		/*SYSERR("SNDRV_SEQ_IOCTL_GET_CLIENT_INFO failed");*/
 		return -errno;
 	}
+	if (hw->micro_version < SNDRV_PROTOCOL_MICRO(SNDRV_SEQ_VERSION_MAX))
+		info->owner = -1;
 	return 0;
 }
 
@@ -368,6 +371,8 @@ static int snd_seq_hw_query_next_client(snd_seq_t *seq, snd_seq_client_info_t *i
 		/*SYSERR("SNDRV_SEQ_IOCTL_QUERY_NEXT_CLIENT failed");*/
 		return -errno;
 	}
+	if (hw->micro_version < SNDRV_PROTOCOL_MICRO(SNDRV_SEQ_VERSION_MAX))
+		info->owner = -1;
 	return 0;
 }
 
@@ -480,6 +485,7 @@ int snd_seq_hw_open(snd_seq_t **handle, const char *name, int streams, int mode)
 		return -ENOMEM;
 	}
 	hw->fd = fd;
+	hw->micro_version = SNDRV_PROTOCOL_MICRO(ver);
 	if (streams & SND_SEQ_OPEN_OUTPUT) {
 		seq->obuf = (char *) malloc(seq->obufsize = SND_SEQ_OBUF_SIZE);
 		if (!seq->obuf) {
-- 
2.6.2

^ permalink raw reply related	[flat|nested] 21+ messages in thread
* [PATCH] Show sequencer sound card numer/PID via aconnect
@ 2016-03-08 22:06 Martin Koegler
  2016-03-09  8:16 ` Takashi Iwai
  0 siblings, 1 reply; 21+ messages in thread
From: Martin Koegler @ 2016-03-08 22:06 UTC (permalink / raw)
  To: alsa-devel; +Cc: Martin Koegler

From: Martin Koegler <martin.koegler@chello.at>

rawmidi devices expose the card number via IOCTLs, which allows to
find the corresponding device in sysfs.

The sequencer provides no identifing data. Chromium works around this
issue by scanning rawmidi as well as sequencer devices and matching
them by using assumtions, how the kernel register sequencer devices.

This patch adds support for displaying the sound card number/PID to
aconnect.

Signed-off-by: Martin Koegler <martin.koegler@chello.at>
---
 configure.ac            |  9 +++++++++
 seq/aconnect/aconnect.c | 17 ++++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index bdb133c..9e48190 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,15 @@ AC_CHECK_HEADERS([alsa/topology.h], [have_topology="yes"], [have_topology="no"],
 AC_CHECK_HEADERS([samplerate.h], [have_samplerate="yes"], [have_samplerate="no"],
   [#include <samplerate.h>])
 
+AC_CHECK_LIB([asound], [snd_seq_client_info_get_card], [HAVE_SEQ_CLIENT_INFO_GET_CARD="yes"])
+if test "$HAVE_SEQ_CLIENT_INFO_GET_CARD" = "yes" ; then
+    AC_DEFINE([HAVE_SEQ_CLIENT_INFO_GET_CARD], 1, [alsa-lib supports snd_seq_client_info_get_card])
+fi
+AC_CHECK_LIB([asound], [snd_seq_client_info_get_pid], [HAVE_SEQ_CLIENT_INFO_GET_PID="yes"])
+if test "$HAVE_SEQ_CLIENT_INFO_GET_PID" = "yes" ; then
+    AC_DEFINE([HAVE_SEQ_CLIENT_INFO_GET_PID], 1, [alsa-lib supports snd_seq_client_info_get_pid])
+fi
+
 AM_CONDITIONAL(HAVE_PCM, test "$have_pcm" = "yes")
 AM_CONDITIONAL(HAVE_MIXER, test "$have_mixer" = "yes")
 AM_CONDITIONAL(HAVE_RAWMIDI, test "$have_rawmidi" = "yes")
diff --git a/seq/aconnect/aconnect.c b/seq/aconnect/aconnect.c
index 8d6cebb..85a7770 100644
--- a/seq/aconnect/aconnect.c
+++ b/seq/aconnect/aconnect.c
@@ -166,11 +166,26 @@ static void print_port(snd_seq_t *seq, snd_seq_client_info_t *cinfo,
 		       snd_seq_port_info_t *pinfo, int count)
 {
 	if (! count) {
-		printf(_("client %d: '%s' [type=%s]\n"),
+		int card = -1, pid = -1;
+
+		printf(_("client %d: '%s' [type=%s"),
 		       snd_seq_client_info_get_client(cinfo),
 		       snd_seq_client_info_get_name(cinfo),
 		       (snd_seq_client_info_get_type(cinfo) == SND_SEQ_USER_CLIENT ?
 			_("user") : _("kernel")));
+
+#ifdef HAVE_SEQ_CLIENT_INFO_GET_CARD
+		card = snd_seq_client_info_get_card(cinfo);
+#endif
+		if (card != -1)
+			printf(",card=%d", card);
+
+#ifdef HAVE_SEQ_CLIENT_INFO_GET_PID
+		pid = snd_seq_client_info_get_pid(cinfo);
+#endif
+		if (pid != -1)
+			printf(",pid=%d", pid);
+		printf("]\n");
 	}
 	printf("  %3d '%-16s'\n",
 	       snd_seq_port_info_get_port(pinfo),
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 21+ messages in thread
* [PATCH] Show sequencer sound card numer/PID via aconnect
@ 2016-02-12 18:56 Martin Koegler
  2016-02-13 12:30 ` Takashi Sakamoto
  0 siblings, 1 reply; 21+ messages in thread
From: Martin Koegler @ 2016-02-12 18:56 UTC (permalink / raw)
  To: alsa-devel; +Cc: Martin Koegler

From: Martin Koegler <martin.koegler@chello.at>

Signed-off-by: Martin Koegler <martin.koegler@chello.at>
---
 seq/aconnect/aconnect.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/seq/aconnect/aconnect.c b/seq/aconnect/aconnect.c
index 8d6cebb..3508e1b 100644
--- a/seq/aconnect/aconnect.c
+++ b/seq/aconnect/aconnect.c
@@ -166,11 +166,19 @@ static void print_port(snd_seq_t *seq, snd_seq_client_info_t *cinfo,
 		       snd_seq_port_info_t *pinfo, int count)
 {
 	if (! count) {
-		printf(_("client %d: '%s' [type=%s]\n"),
+		printf(_("client %d: '%s' [type=%s"),
 		       snd_seq_client_info_get_client(cinfo),
 		       snd_seq_client_info_get_name(cinfo),
 		       (snd_seq_client_info_get_type(cinfo) == SND_SEQ_USER_CLIENT ?
 			_("user") : _("kernel")));
+		int owner = snd_seq_client_info_get_owner(cinfo);
+		if (owner != -1) {
+			if (snd_seq_client_info_get_type(cinfo) == SND_SEQ_USER_CLIENT)
+				printf(",pid=%d", owner);
+			else
+				printf(",card=%d", owner);
+		}
+		printf("]\n");
 	}
 	printf("  %3d '%-16s'\n",
 	       snd_seq_port_info_get_port(pinfo),
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2016-03-09  8:16 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-13 13:42 [PATCH] Provide sequencer sound card number / PID via alsa-lib Martin Koegler
2016-02-13 13:42 ` [PATCH] Show sequencer sound card numer/PID via aconnect Martin Koegler
2016-02-13 13:42 ` [PATCH] Provide card number / PID via sequencer client info Martin Koegler
2016-02-15 10:30   ` Takashi Iwai
2016-02-15 10:37     ` Clemens Ladisch
2016-02-15 18:32     ` Martin Koegler
2016-02-15 19:08       ` Takashi Iwai
2016-02-15 21:44         ` Martin Koegler
2016-02-15 22:34           ` Takashi Iwai
2016-02-16  8:03             ` Martin Koegler
2016-02-16  8:41               ` Takashi Iwai
2016-02-16  8:59                 ` Clemens Ladisch
2016-02-16  9:27                   ` Takashi Iwai
2016-02-16 18:21                     ` Martin Koegler
2016-02-17 14:07                       ` Takashi Iwai
2016-02-17 21:30                         ` Martin Koegler
2016-02-15 10:39 ` [PATCH] Provide sequencer sound card number / PID via alsa-lib Clemens Ladisch
  -- strict thread matches above, loose matches on Subject: below --
2016-03-08 22:06 [PATCH] Show sequencer sound card numer/PID via aconnect Martin Koegler
2016-03-09  8:16 ` Takashi Iwai
2016-02-12 18:56 Martin Koegler
2016-02-13 12:30 ` Takashi Sakamoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).