Terminate mixer description dump with a MIXSYNC message. Fix

server-side "desc" temporary buffer size.
This commit is contained in:
Alexandre Ratchov 2015-09-05 16:10:03 +02:00
parent 84e30dd7a9
commit ba4929bdb9
4 changed files with 39 additions and 7 deletions

View File

@ -57,6 +57,7 @@ struct amsg {
#define AMSG_AUTH 12 /* send authentication cookie */
#define AMSG_MIXSUB 13 /* ondesc/onctl subscription */
#define AMSG_MIXSET 14 /* set mixer control value */
#define AMSG_MIXSYNC 15 /* end of mixer description */
uint32_t cmd;
uint32_t __pad;
union {

View File

@ -96,7 +96,6 @@ siomix_aucat_rdata(struct siomix_aucat_hdl *hdl)
}
hdl->buf_wpos = 0;
}
hdl->dump_wait = 0;
return 1;
}
@ -120,6 +119,11 @@ siomix_aucat_runmsg(struct siomix_aucat_hdl *hdl)
ntohs(hdl->aucat.rmsg.u.mixset.addr),
ntohs(hdl->aucat.rmsg.u.mixset.val));
break;
case AMSG_MIXSYNC:
DPRINTF("siomix_aucat_runmsg: got MIXSYNC\n");
hdl->dump_wait = 0;
_siomix_ondesc_cb(&hdl->siomix, NULL, 0);
break;
default:
DPRINTF("sio_aucat_runmsg: unhandled message %u\n",
hdl->aucat.rmsg.cmd);

View File

@ -33,6 +33,8 @@
#include "utils.h"
#include "bsd-compat.h"
#define SOCK_CTLDESC_SIZE 3 /* number of entries in s->ctldesc */
void sock_log(struct sock *);
void sock_close(struct sock *);
void sock_slot_fill(void *);
@ -874,7 +876,7 @@ sock_hello(struct sock *f)
}
return 0;
}
f->ctldesc = xmalloc(dev_nctl(f->ctlslot->dev) *
f->ctldesc = xmalloc(SOCK_CTLDESC_SIZE *
sizeof(struct amsg_mix_desc));
f->ctlops = 0;
return 1;
@ -1272,6 +1274,7 @@ sock_execmsg(struct sock *f)
}
}
f->ctlops |= SOCK_CTLDESC;
f->ctlsyncpending = 1;
} else
f->ctlops &= ~SOCK_CTLDESC;
if (m->u.mixsub.val) {
@ -1543,12 +1546,22 @@ sock_buildmsg(struct sock *f)
return 1;
}
/*
* XXX: add a flag indicating if there are changes
* in controls not seen by this client, rather
* than walking through the full list of control
* searching for the {desc,val}_mask bits
*/
if (f->ctlslot && (f->ctlops & SOCK_CTLDESC)) {
desc = f->ctldesc;
mask = f->ctlslot->mask;
size = 0;
for (c = f->ctlslot->dev->ctl_list; c != NULL; c = c->next) {
if ((c->desc_mask & mask) == 0)
continue;
if (size == SOCK_CTLDESC_SIZE *
sizeof(struct amsg_mix_desc))
break;
c->desc_mask &= ~mask;
c->val_mask &= ~mask;
strlcpy(desc->chan0.str, c->chan0.str,
@ -1561,10 +1574,10 @@ sock_buildmsg(struct sock *f)
strlcpy(desc->func, c->func, AMSG_MIX_NAMEMAX);
desc->addr = htons(c->addr);
desc->curval = htons(c->curval);
size += sizeof(struct amsg_mix_desc);
desc++;
}
if (desc != f->ctldesc) {
size = (char *)desc - (char *)f->ctldesc;
if (size > 0) {
AMSG_INIT(&f->wmsg);
f->wmsg.cmd = htonl(AMSG_DATA);
f->wmsg.u.data.size = htonl(size);
@ -1600,6 +1613,19 @@ sock_buildmsg(struct sock *f)
return 1;
}
}
if (f->ctlslot && f->ctlsyncpending) {
f->ctlsyncpending = 0;
f->wmsg.cmd = htonl(AMSG_MIXSYNC);
f->wtodo = sizeof(struct amsg);
f->wstate = SOCK_WMSG;
#ifdef DEBUG
if (log_level >= 3) {
sock_log(f);
log_puts(": building mixer MIXSYNC message\n");
}
#endif
return 1;
}
#ifdef DEBUG
if (log_level >= 4) {
sock_log(f);

View File

@ -50,7 +50,7 @@ struct sock {
#define SOCK_START 3 /* filling play buffers */
#define SOCK_STOP 4 /* draining rec buffers */
unsigned int pstate; /* one of the above */
int tickpending; /* tick waiting to be transmitted */
int tickpending; /* tick waiting to be transmitted */
int fillpending; /* flowctl waiting to be transmitted */
int stoppending; /* last STOP ack to be sent */
unsigned int walign; /* align written data to this */
@ -61,10 +61,11 @@ struct sock {
struct midi *midi; /* midi endpoint */
struct port *port; /* midi port */
struct ctlslot *ctlslot;
struct amsg_mix_desc *ctldesc;
struct amsg_mix_desc *ctldesc; /* temporary buffer */
#define SOCK_CTLDESC 1 /* dump desc and send changes */
#define SOCK_CTLVAL 2 /* send value changes */
unsigned int ctlops;
unsigned int ctlops; /* bitmap of above */
int ctlsyncpending; /* mixsync waiting to be transmitted */
};
struct sock *sock_new(int fd);