diff options
| author | Takashi Iwai <tiwai@suse.de> | 2024-11-28 08:48:00 +0100 |
|---|---|---|
| committer | Takashi Iwai <tiwai@suse.de> | 2024-12-02 10:25:31 +0100 |
| commit | ec42af4a1fe383af4a4fbbe2bc0e9cc1e8e65620 (patch) | |
| tree | 99f394a6df0a7e062c861f6b238dfcc1d908184b /sound/core | |
| parent | b8e49e24cdba27a0810a0988e810e2c68f2033cb (diff) | |
| download | linux-ec42af4a1fe383af4a4fbbe2bc0e9cc1e8e65620.tar.gz linux-ec42af4a1fe383af4a4fbbe2bc0e9cc1e8e65620.tar.bz2 linux-ec42af4a1fe383af4a4fbbe2bc0e9cc1e8e65620.zip | |
ALSA: seq: Skip notifications unless subscribed to announce port
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>
Diffstat (limited to 'sound/core')
| -rw-r--r-- | sound/core/seq/seq_system.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/sound/core/seq/seq_system.c b/sound/core/seq/seq_system.c index 80267290190d..37edcc3881ed 100644 --- a/sound/core/seq/seq_system.c +++ b/sound/core/seq/seq_system.c @@ -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; |
