@@ -49,12 +49,14 @@ static int sysclient = -1;
4949/* port id numbers for this client */
5050static int announce_port = -1 ;
5151
52+ /* number of subscriptions to announce port */
53+ static int announce_subscribed ;
5254
5355
5456/* fill standard header data, source port & channel are filled in */
5557static int setheader (struct snd_seq_event * ev , int client , int port )
5658{
57- if (announce_port < 0 )
59+ if (announce_port < 0 || ! announce_subscribed )
5860 return - ENODEV ;
5961
6062 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
104106 return snd_seq_control_queue (ev , atomic , hop );
105107}
106108
109+ static int sys_announce_subscribe (void * private_data ,
110+ struct snd_seq_port_subscribe * info )
111+ {
112+ announce_subscribed ++ ;
113+ return 0 ;
114+ }
115+
116+ static int sys_announce_unsubscribe (void * private_data ,
117+ struct snd_seq_port_subscribe * info )
118+ {
119+ if (snd_BUG_ON (!announce_subscribed ))
120+ return 0 ;
121+ announce_subscribed -- ;
122+ return 0 ;
123+ }
124+
107125/* register our internal client */
108126int __init snd_seq_system_client_init (void )
109127{
@@ -143,7 +161,10 @@ int __init snd_seq_system_client_init(void)
143161 /* register announcement port */
144162 strcpy (port -> name , "Announce" );
145163 port -> capability = SNDRV_SEQ_PORT_CAP_READ |SNDRV_SEQ_PORT_CAP_SUBS_READ ; /* for broadcast only */
146- port -> kernel = NULL ;
164+ pcallbacks .event_input = NULL ;
165+ pcallbacks .subscribe = sys_announce_subscribe ;
166+ pcallbacks .unsubscribe = sys_announce_unsubscribe ;
167+ port -> kernel = & pcallbacks ;
147168 port -> type = 0 ;
148169 port -> flags = SNDRV_SEQ_PORT_FLG_GIVEN_PORT ;
149170 port -> addr .client = sysclient ;
0 commit comments