]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ALSA: seq: Skip notifications unless subscribed to announce port
authorTakashi Iwai <tiwai@suse.de>
Thu, 28 Nov 2024 07:48:00 +0000 (08:48 +0100)
committerTakashi Iwai <tiwai@suse.de>
Mon, 2 Dec 2024 09:25:31 +0000 (10:25 +0100)
The notification via system announce port isn't a lightweight task,
hence it'd be better to skip if there is no subscription is done for
the announce port.  Implement a simple counter for checking that by
hooking the subscribe and unsubscribe callbacks.

Link: https://patch.msgid.link/20241128074801.32253-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/seq/seq_system.c

index 80267290190d0076435b2bc16888fb924d854d59..37edcc3881ed688ffffa535203fc86e6c6ec3f1a 100644 (file)
@@ -49,12 +49,14 @@ static int sysclient = -1;
 /* port id numbers for this client */
 static int announce_port = -1;
 
+/* number of subscriptions to announce port */
+static int announce_subscribed;
 
 
 /* fill standard header data, source port & channel are filled in */
 static int setheader(struct snd_seq_event * ev, int client, int port)
 {
-       if (announce_port < 0)
+       if (announce_port < 0 || !announce_subscribed)
                return -ENODEV;
 
        memset(ev, 0, sizeof(struct snd_seq_event));
@@ -104,6 +106,22 @@ static int event_input_timer(struct snd_seq_event * ev, int direct, void *privat
        return snd_seq_control_queue(ev, atomic, hop);
 }
 
+static int sys_announce_subscribe(void *private_data,
+                                 struct snd_seq_port_subscribe *info)
+{
+       announce_subscribed++;
+       return 0;
+}
+
+static int sys_announce_unsubscribe(void *private_data,
+                                   struct snd_seq_port_subscribe *info)
+{
+       if (snd_BUG_ON(!announce_subscribed))
+               return 0;
+       announce_subscribed--;
+       return 0;
+}
+
 /* register our internal client */
 int __init snd_seq_system_client_init(void)
 {
@@ -143,7 +161,10 @@ int __init snd_seq_system_client_init(void)
        /* register announcement port */
        strcpy(port->name, "Announce");
        port->capability = SNDRV_SEQ_PORT_CAP_READ|SNDRV_SEQ_PORT_CAP_SUBS_READ; /* for broadcast only */
-       port->kernel = NULL;
+       pcallbacks.event_input = NULL;
+       pcallbacks.subscribe = sys_announce_subscribe;
+       pcallbacks.unsubscribe = sys_announce_unsubscribe;
+       port->kernel = &pcallbacks;
        port->type = 0;
        port->flags = SNDRV_SEQ_PORT_FLG_GIVEN_PORT;
        port->addr.client = sysclient;