mirror of https://github.com/ericonr/sndio.git
convert messages headers to network byte order to allow
client and server with different byte orders to work
This commit is contained in:
parent
52d91a6fa6
commit
134bc5d779
144
aucat/sock.c
144
aucat/sock.c
|
@ -755,7 +755,12 @@ int
|
|||
sock_setpar(struct sock *f)
|
||||
{
|
||||
struct amsg_par *p = &f->rmsg.u.par;
|
||||
unsigned min, max, rate;
|
||||
unsigned min, max, rate, pchan, rchan, appbufsz;
|
||||
|
||||
rchan = ntohs(p->rchan);
|
||||
pchan = ntohs(p->pchan);
|
||||
appbufsz = ntohl(p->appbufsz);
|
||||
rate = ntohl(p->rate);
|
||||
|
||||
if (AMSG_ISSET(p->bits)) {
|
||||
if (p->bits < BITS_MIN || p->bits > BITS_MAX) {
|
||||
|
@ -802,13 +807,13 @@ sock_setpar(struct sock *f)
|
|||
f->rpar.le = f->wpar.le = p->le ? 1 : 0;
|
||||
if (AMSG_ISSET(p->msb))
|
||||
f->rpar.msb = f->wpar.msb = p->msb ? 1 : 0;
|
||||
if (AMSG_ISSET(p->rchan) && (f->mode & MODE_RECMASK)) {
|
||||
if (p->rchan < 1)
|
||||
p->rchan = 1;
|
||||
if (p->rchan > NCHAN_MAX)
|
||||
p->rchan = NCHAN_MAX;
|
||||
if (AMSG_ISSET(rchan) && (f->mode & MODE_RECMASK)) {
|
||||
if (rchan < 1)
|
||||
rchan = 1;
|
||||
if (rchan > NCHAN_MAX)
|
||||
rchan = NCHAN_MAX;
|
||||
f->wpar.cmin = f->opt->wpar.cmin;
|
||||
f->wpar.cmax = f->opt->wpar.cmin + p->rchan - 1;
|
||||
f->wpar.cmax = f->opt->wpar.cmin + rchan - 1;
|
||||
if (f->wpar.cmax > f->opt->wpar.cmax)
|
||||
f->wpar.cmax = f->opt->wpar.cmax;
|
||||
#ifdef DEBUG
|
||||
|
@ -822,13 +827,13 @@ sock_setpar(struct sock *f)
|
|||
}
|
||||
#endif
|
||||
}
|
||||
if (AMSG_ISSET(p->pchan) && (f->mode & MODE_PLAY)) {
|
||||
if (p->pchan < 1)
|
||||
p->pchan = 1;
|
||||
if (p->pchan > NCHAN_MAX)
|
||||
p->pchan = NCHAN_MAX;
|
||||
if (AMSG_ISSET(pchan) && (f->mode & MODE_PLAY)) {
|
||||
if (pchan < 1)
|
||||
pchan = 1;
|
||||
if (pchan > NCHAN_MAX)
|
||||
pchan = NCHAN_MAX;
|
||||
f->rpar.cmin = f->opt->rpar.cmin;
|
||||
f->rpar.cmax = f->opt->rpar.cmin + p->pchan - 1;
|
||||
f->rpar.cmax = f->opt->rpar.cmin + pchan - 1;
|
||||
if (f->rpar.cmax > f->opt->rpar.cmax)
|
||||
f->rpar.cmax = f->opt->rpar.cmax;
|
||||
#ifdef DEBUG
|
||||
|
@ -842,20 +847,20 @@ sock_setpar(struct sock *f)
|
|||
}
|
||||
#endif
|
||||
}
|
||||
if (AMSG_ISSET(p->rate)) {
|
||||
if (p->rate < RATE_MIN)
|
||||
p->rate = RATE_MIN;
|
||||
if (p->rate > RATE_MAX)
|
||||
p->rate = RATE_MAX;
|
||||
f->round = dev_roundof(f->dev, p->rate);
|
||||
f->rpar.rate = f->wpar.rate = p->rate;
|
||||
if (!AMSG_ISSET(p->appbufsz)) {
|
||||
p->appbufsz = f->dev->bufsz / f->dev->round * f->round;
|
||||
if (AMSG_ISSET(rate)) {
|
||||
if (rate < RATE_MIN)
|
||||
rate = RATE_MIN;
|
||||
if (rate > RATE_MAX)
|
||||
rate = RATE_MAX;
|
||||
f->round = dev_roundof(f->dev, rate);
|
||||
f->rpar.rate = f->wpar.rate = rate;
|
||||
if (!AMSG_ISSET(appbufsz)) {
|
||||
appbufsz = f->dev->bufsz / f->dev->round * f->round;
|
||||
#ifdef DEBUG
|
||||
if (debug_level >= 3) {
|
||||
sock_dbg(f);
|
||||
dbg_puts(": using ");
|
||||
dbg_putu(p->appbufsz);
|
||||
dbg_putu(appbufsz);
|
||||
dbg_puts(" fr app buffer size\n");
|
||||
}
|
||||
#endif
|
||||
|
@ -864,7 +869,7 @@ sock_setpar(struct sock *f)
|
|||
if (debug_level >= 3) {
|
||||
sock_dbg(f);
|
||||
dbg_puts(": using ");
|
||||
dbg_putu(p->rate);
|
||||
dbg_putu(rate);
|
||||
dbg_puts("Hz sample rate, ");
|
||||
dbg_putu(f->round);
|
||||
dbg_puts(" fr block size\n");
|
||||
|
@ -897,19 +902,19 @@ sock_setpar(struct sock *f)
|
|||
}
|
||||
#endif
|
||||
}
|
||||
if (AMSG_ISSET(p->appbufsz)) {
|
||||
if (AMSG_ISSET(appbufsz)) {
|
||||
rate = (f->mode & MODE_PLAY) ? f->rpar.rate : f->wpar.rate;
|
||||
min = 1;
|
||||
max = 1 + rate / f->dev->round;
|
||||
min *= f->round;
|
||||
max *= f->round;
|
||||
p->appbufsz += f->round - 1;
|
||||
p->appbufsz -= p->appbufsz % f->round;
|
||||
if (p->appbufsz < min)
|
||||
p->appbufsz = min;
|
||||
if (p->appbufsz > max)
|
||||
p->appbufsz = max;
|
||||
f->bufsz = p->appbufsz;
|
||||
appbufsz += f->round - 1;
|
||||
appbufsz -= appbufsz % f->round;
|
||||
if (appbufsz < min)
|
||||
appbufsz = min;
|
||||
if (appbufsz > max)
|
||||
appbufsz = max;
|
||||
f->bufsz = appbufsz;
|
||||
#ifdef DEBUG
|
||||
if (debug_level >= 3) {
|
||||
sock_dbg(f);
|
||||
|
@ -983,14 +988,16 @@ int
|
|||
sock_hello(struct sock *f)
|
||||
{
|
||||
struct amsg_hello *p = &f->rmsg.u.hello;
|
||||
unsigned mode;
|
||||
|
||||
mode = ntohs(p->mode);
|
||||
#ifdef DEBUG
|
||||
if (debug_level >= 3) {
|
||||
sock_dbg(f);
|
||||
dbg_puts(": hello from <");
|
||||
dbg_puts(p->who);
|
||||
dbg_puts(">, mode = ");
|
||||
dbg_putx(p->mode);
|
||||
dbg_putx(mode);
|
||||
dbg_puts(", ver ");
|
||||
dbg_putu(p->version);
|
||||
dbg_puts("\n");
|
||||
|
@ -1007,7 +1014,7 @@ sock_hello(struct sock *f)
|
|||
#endif
|
||||
return 0;
|
||||
}
|
||||
switch (p->mode) {
|
||||
switch (mode) {
|
||||
case MODE_MIDIIN:
|
||||
case MODE_MIDIOUT:
|
||||
case MODE_MIDIOUT | MODE_MIDIIN:
|
||||
|
@ -1020,7 +1027,7 @@ sock_hello(struct sock *f)
|
|||
if (debug_level >= 1) {
|
||||
sock_dbg(f);
|
||||
dbg_puts(": ");
|
||||
dbg_putx(p->mode);
|
||||
dbg_putx(mode);
|
||||
dbg_puts(": unsupported mode\n");
|
||||
}
|
||||
#endif
|
||||
|
@ -1031,12 +1038,12 @@ sock_hello(struct sock *f)
|
|||
return 0;
|
||||
if (!dev_ref(f->opt->dev))
|
||||
return 0;
|
||||
if ((p->mode & MODE_REC) && (f->opt->mode & MODE_MON)) {
|
||||
p->mode &= ~MODE_REC;
|
||||
p->mode |= MODE_MON;
|
||||
if ((mode & MODE_REC) && (f->opt->mode & MODE_MON)) {
|
||||
mode &= ~MODE_REC;
|
||||
mode |= MODE_MON;
|
||||
}
|
||||
f->dev = f->opt->dev;
|
||||
f->mode = (p->mode & f->opt->mode) & f->dev->mode;
|
||||
f->mode = (mode & f->opt->mode) & f->dev->mode;
|
||||
#ifdef DEBUG
|
||||
if (debug_level >= 3) {
|
||||
sock_dbg(f);
|
||||
|
@ -1045,7 +1052,7 @@ sock_hello(struct sock *f)
|
|||
dbg_puts("\n");
|
||||
}
|
||||
#endif
|
||||
if (f->mode != p->mode) {
|
||||
if (f->mode != mode) {
|
||||
#ifdef DEBUG
|
||||
if (debug_level >= 1) {
|
||||
sock_dbg(f);
|
||||
|
@ -1083,8 +1090,9 @@ sock_execmsg(struct sock *f)
|
|||
{
|
||||
struct amsg *m = &f->rmsg;
|
||||
struct abuf *obuf;
|
||||
unsigned size, ctl;
|
||||
|
||||
switch (m->cmd) {
|
||||
switch (ntohl(m->cmd)) {
|
||||
case AMSG_DATA:
|
||||
#ifdef DEBUG
|
||||
if (debug_level >= 4) {
|
||||
|
@ -1124,7 +1132,8 @@ sock_execmsg(struct sock *f)
|
|||
aproc_del(f->pipe.file.rproc);
|
||||
return 0;
|
||||
}
|
||||
if (m->u.data.size % obuf->bpf != 0) {
|
||||
size = ntohl(m->u.data.size);
|
||||
if (size % obuf->bpf != 0) {
|
||||
#ifdef DEBUG
|
||||
if (debug_level >= 1) {
|
||||
sock_dbg(f);
|
||||
|
@ -1135,7 +1144,7 @@ sock_execmsg(struct sock *f)
|
|||
return 0;
|
||||
}
|
||||
f->rstate = SOCK_RDATA;
|
||||
f->rtodo = m->u.data.size / obuf->bpf;
|
||||
f->rtodo = size / obuf->bpf;
|
||||
#ifdef DEBUG
|
||||
if (debug_level >= 2 &&
|
||||
f->pstate != SOCK_MIDI && f->rtodo > f->rmax) {
|
||||
|
@ -1213,7 +1222,7 @@ sock_execmsg(struct sock *f)
|
|||
else
|
||||
f->pstate = SOCK_STOP;
|
||||
AMSG_INIT(m);
|
||||
m->cmd = AMSG_STOP;
|
||||
m->cmd = htonl(AMSG_STOP);
|
||||
f->rstate = SOCK_RRET;
|
||||
f->rtodo = sizeof(struct amsg);
|
||||
break;
|
||||
|
@ -1259,7 +1268,7 @@ sock_execmsg(struct sock *f)
|
|||
return 0;
|
||||
}
|
||||
AMSG_INIT(m);
|
||||
m->cmd = AMSG_GETPAR;
|
||||
m->cmd = htonl(AMSG_GETPAR);
|
||||
m->u.par.legacy_mode = f->mode;
|
||||
if (f->mode & MODE_PLAY) {
|
||||
m->u.par.bits = f->rpar.bits;
|
||||
|
@ -1267,8 +1276,8 @@ sock_execmsg(struct sock *f)
|
|||
m->u.par.sig = f->rpar.sig;
|
||||
m->u.par.le = f->rpar.le;
|
||||
m->u.par.msb = f->rpar.msb;
|
||||
m->u.par.rate = f->rpar.rate;
|
||||
m->u.par.pchan = f->rpar.cmax - f->rpar.cmin + 1;
|
||||
m->u.par.rate = htonl(f->rpar.rate);
|
||||
m->u.par.pchan = htons(f->rpar.cmax - f->rpar.cmin + 1);
|
||||
}
|
||||
if (f->mode & MODE_RECMASK) {
|
||||
m->u.par.bits = f->wpar.bits;
|
||||
|
@ -1276,13 +1285,13 @@ sock_execmsg(struct sock *f)
|
|||
m->u.par.sig = f->wpar.sig;
|
||||
m->u.par.le = f->wpar.le;
|
||||
m->u.par.msb = f->wpar.msb;
|
||||
m->u.par.rate = f->wpar.rate;
|
||||
m->u.par.rchan = f->wpar.cmax - f->wpar.cmin + 1;
|
||||
m->u.par.rate = htonl(f->wpar.rate);
|
||||
m->u.par.rchan = htons(f->wpar.cmax - f->wpar.cmin + 1);
|
||||
}
|
||||
m->u.par.appbufsz = f->bufsz;
|
||||
m->u.par.bufsz =
|
||||
f->bufsz + (f->dev->bufsz / f->dev->round) * f->round;
|
||||
m->u.par.round = f->round;
|
||||
m->u.par.appbufsz = htonl(f->bufsz);
|
||||
m->u.par.bufsz = htonl(
|
||||
f->bufsz + (f->dev->bufsz / f->dev->round) * f->round);
|
||||
m->u.par.round = htonl(f->round);
|
||||
f->rstate = SOCK_RRET;
|
||||
f->rtodo = sizeof(struct amsg);
|
||||
break;
|
||||
|
@ -1304,7 +1313,8 @@ sock_execmsg(struct sock *f)
|
|||
aproc_del(f->pipe.file.rproc);
|
||||
return 0;
|
||||
}
|
||||
if (m->u.vol.ctl > MIDI_MAXCTL) {
|
||||
ctl = ntohl(m->u.vol.ctl);
|
||||
if (ctl > MIDI_MAXCTL) {
|
||||
#ifdef DEBUG
|
||||
if (debug_level >= 1) {
|
||||
sock_dbg(f);
|
||||
|
@ -1314,9 +1324,9 @@ sock_execmsg(struct sock *f)
|
|||
aproc_del(f->pipe.file.rproc);
|
||||
return 0;
|
||||
}
|
||||
sock_setvol(f, m->u.vol.ctl);
|
||||
sock_setvol(f, ctl);
|
||||
if (f->slot >= 0)
|
||||
ctl_slotvol(f->dev->midi, f->slot, m->u.vol.ctl);
|
||||
ctl_slotvol(f->dev->midi, f->slot, ctl);
|
||||
f->rtodo = sizeof(struct amsg);
|
||||
f->rstate = SOCK_RMSG;
|
||||
break;
|
||||
|
@ -1366,7 +1376,7 @@ sock_execmsg(struct sock *f)
|
|||
return 0;
|
||||
}
|
||||
AMSG_INIT(m);
|
||||
m->cmd = AMSG_ACK;
|
||||
m->cmd = htonl(AMSG_ACK);
|
||||
f->rstate = SOCK_RRET;
|
||||
f->rtodo = sizeof(struct amsg);
|
||||
break;
|
||||
|
@ -1423,8 +1433,8 @@ sock_buildmsg(struct sock *f)
|
|||
}
|
||||
#endif
|
||||
AMSG_INIT(&f->wmsg);
|
||||
f->wmsg.cmd = AMSG_POS;
|
||||
f->wmsg.u.ts.delta = f->startpos;
|
||||
f->wmsg.cmd = htonl(AMSG_POS);
|
||||
f->wmsg.u.ts.delta = htonl(f->startpos);
|
||||
f->rmax += f->startpos;
|
||||
f->wtodo = sizeof(struct amsg);
|
||||
f->wstate = SOCK_WMSG;
|
||||
|
@ -1447,8 +1457,8 @@ sock_buildmsg(struct sock *f)
|
|||
f->wmax += f->delta;
|
||||
f->rmax += f->delta;
|
||||
AMSG_INIT(&f->wmsg);
|
||||
f->wmsg.cmd = AMSG_MOVE;
|
||||
f->wmsg.u.ts.delta = f->delta;
|
||||
f->wmsg.cmd = htonl(AMSG_MOVE);
|
||||
f->wmsg.u.ts.delta = htonl(f->delta);
|
||||
f->wtodo = sizeof(struct amsg);
|
||||
f->wstate = SOCK_WMSG;
|
||||
f->delta = 0;
|
||||
|
@ -1469,8 +1479,8 @@ sock_buildmsg(struct sock *f)
|
|||
}
|
||||
#endif
|
||||
AMSG_INIT(&f->wmsg);
|
||||
f->wmsg.cmd = AMSG_SETVOL;
|
||||
f->wmsg.u.vol.ctl = f->vol;
|
||||
f->wmsg.cmd = htonl(AMSG_SETVOL);
|
||||
f->wmsg.u.vol.ctl = htonl(f->vol);
|
||||
f->wtodo = sizeof(struct amsg);
|
||||
f->wstate = SOCK_WMSG;
|
||||
f->lastvol = f->vol;
|
||||
|
@ -1517,8 +1527,8 @@ sock_buildmsg(struct sock *f)
|
|||
size *= ibuf->bpf;
|
||||
}
|
||||
AMSG_INIT(&f->wmsg);
|
||||
f->wmsg.cmd = AMSG_DATA;
|
||||
f->wmsg.u.data.size = size;
|
||||
f->wmsg.cmd = htonl(AMSG_DATA);
|
||||
f->wmsg.u.data.size = htonl(size);
|
||||
f->wtodo = sizeof(struct amsg);
|
||||
f->wstate = SOCK_WMSG;
|
||||
return 1;
|
||||
|
@ -1651,7 +1661,7 @@ sock_write(struct sock *f)
|
|||
case SOCK_WMSG:
|
||||
if (!sock_wmsg(f, &f->wmsg, &f->wtodo))
|
||||
return 0;
|
||||
if (f->wmsg.cmd != AMSG_DATA) {
|
||||
if (ntohl(f->wmsg.cmd) != AMSG_DATA) {
|
||||
f->wstate = SOCK_WIDLE;
|
||||
f->wtodo = 0xdeadbeef;
|
||||
break;
|
||||
|
@ -1660,7 +1670,7 @@ sock_write(struct sock *f)
|
|||
* XXX: why not set f->wtodo in sock_wmsg() ?
|
||||
*/
|
||||
f->wstate = SOCK_WDATA;
|
||||
f->wtodo = f->wmsg.u.data.size /
|
||||
f->wtodo = ntohl(f->wmsg.u.data.size) /
|
||||
LIST_FIRST(&f->pipe.file.wproc->ins)->bpf;
|
||||
/* PASSTHROUGH */
|
||||
case SOCK_WDATA:
|
||||
|
|
|
@ -77,8 +77,8 @@ aucat_rmsg(struct aucat *hdl, int *eof)
|
|||
}
|
||||
hdl->rtodo -= n;
|
||||
}
|
||||
if (hdl->rmsg.cmd == AMSG_DATA) {
|
||||
hdl->rtodo = hdl->rmsg.u.data.size;
|
||||
if (ntohl(hdl->rmsg.cmd) == AMSG_DATA) {
|
||||
hdl->rtodo = ntohl(hdl->rmsg.u.data.size);
|
||||
hdl->rstate = RSTATE_DATA;
|
||||
} else {
|
||||
hdl->rtodo = sizeof(struct amsg);
|
||||
|
@ -117,8 +117,8 @@ aucat_wmsg(struct aucat *hdl, int *eof)
|
|||
}
|
||||
hdl->wtodo -= n;
|
||||
}
|
||||
if (hdl->wmsg.cmd == AMSG_DATA) {
|
||||
hdl->wtodo = hdl->wmsg.u.data.size;
|
||||
if (ntohl(hdl->wmsg.cmd) == AMSG_DATA) {
|
||||
hdl->wtodo = ntohl(hdl->wmsg.u.data.size);
|
||||
hdl->wstate = WSTATE_DATA;
|
||||
} else {
|
||||
hdl->wtodo = 0xdeadbeef;
|
||||
|
@ -173,8 +173,8 @@ aucat_wdata(struct aucat *hdl, const void *buf, size_t len, unsigned wbpf, int *
|
|||
len -= len % wbpf;
|
||||
if (len == 0)
|
||||
len = wbpf;
|
||||
hdl->wmsg.cmd = AMSG_DATA;
|
||||
hdl->wmsg.u.data.size = len;
|
||||
hdl->wmsg.cmd = htonl(AMSG_DATA);
|
||||
hdl->wmsg.u.data.size = htonl(len);
|
||||
hdl->wtodo = sizeof(struct amsg);
|
||||
hdl->wstate = WSTATE_MSG;
|
||||
/* FALLTHROUGH */
|
||||
|
@ -458,16 +458,16 @@ aucat_open(struct aucat *hdl, const char *str, unsigned mode, int isaudio)
|
|||
* say hello to server
|
||||
*/
|
||||
AMSG_INIT(&hdl->wmsg);
|
||||
hdl->wmsg.cmd = AMSG_AUTH;
|
||||
hdl->wmsg.cmd = htonl(AMSG_AUTH);
|
||||
if (!aucat_mkcookie(hdl->wmsg.u.auth.cookie))
|
||||
goto bad_connect;
|
||||
hdl->wtodo = sizeof(struct amsg);
|
||||
if (!aucat_wmsg(hdl, &eof))
|
||||
goto bad_connect;
|
||||
AMSG_INIT(&hdl->wmsg);
|
||||
hdl->wmsg.cmd = AMSG_HELLO;
|
||||
hdl->wmsg.cmd = htonl(AMSG_HELLO);
|
||||
hdl->wmsg.u.hello.version = AMSG_VERSION;
|
||||
hdl->wmsg.u.hello.mode = mode;
|
||||
hdl->wmsg.u.hello.mode = htons(mode);
|
||||
strlcpy(hdl->wmsg.u.hello.who, __progname,
|
||||
sizeof(hdl->wmsg.u.hello.who));
|
||||
strlcpy(hdl->wmsg.u.hello.opt, opt,
|
||||
|
@ -480,7 +480,7 @@ aucat_open(struct aucat *hdl, const char *str, unsigned mode, int isaudio)
|
|||
DPRINTF("aucat_init: mode refused\n");
|
||||
goto bad_connect;
|
||||
}
|
||||
if (hdl->rmsg.cmd != AMSG_ACK) {
|
||||
if (ntohl(hdl->rmsg.cmd) != AMSG_ACK) {
|
||||
DPRINTF("aucat_init: protocol err\n");
|
||||
goto bad_connect;
|
||||
}
|
||||
|
@ -498,7 +498,7 @@ aucat_close(struct aucat *hdl, int eof)
|
|||
|
||||
if (!eof) {
|
||||
AMSG_INIT(&hdl->wmsg);
|
||||
hdl->wmsg.cmd = AMSG_BYE;
|
||||
hdl->wmsg.cmd = htonl(AMSG_BYE);
|
||||
hdl->wtodo = sizeof(struct amsg);
|
||||
if (!aucat_wmsg(hdl, &eof))
|
||||
goto bad_close;
|
||||
|
|
|
@ -83,36 +83,42 @@ static struct sio_ops sio_aucat_ops = {
|
|||
static int
|
||||
sio_aucat_runmsg(struct sio_aucat_hdl *hdl)
|
||||
{
|
||||
int delta;
|
||||
unsigned size, ctl;
|
||||
|
||||
if (!aucat_rmsg(&hdl->aucat, &hdl->sio.eof))
|
||||
return 0;
|
||||
switch (hdl->aucat.rmsg.cmd) {
|
||||
switch (ntohl(hdl->aucat.rmsg.cmd)) {
|
||||
case AMSG_DATA:
|
||||
if (hdl->aucat.rmsg.u.data.size == 0 ||
|
||||
hdl->aucat.rmsg.u.data.size % hdl->rbpf) {
|
||||
size = ntohl(hdl->aucat.rmsg.u.data.size);
|
||||
if (size == 0 || size % hdl->rbpf) {
|
||||
DPRINTF("sio_aucat_runmsg: bad data message\n");
|
||||
hdl->sio.eof = 1;
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
case AMSG_POS:
|
||||
hdl->maxwrite += hdl->aucat.rmsg.u.ts.delta * (int)hdl->wbpf;
|
||||
delta = ntohl(hdl->aucat.rmsg.u.ts.delta);
|
||||
hdl->maxwrite += delta * (int)hdl->wbpf;
|
||||
DPRINTF("aucat: pos = %d, maxwrite = %d\n",
|
||||
hdl->aucat.rmsg.u.ts.delta, hdl->maxwrite);
|
||||
hdl->delta = hdl->aucat.rmsg.u.ts.delta;
|
||||
delta, hdl->maxwrite);
|
||||
hdl->delta = delta;
|
||||
break;
|
||||
case AMSG_MOVE:
|
||||
hdl->maxwrite += hdl->aucat.rmsg.u.ts.delta * hdl->wbpf;
|
||||
hdl->delta += hdl->aucat.rmsg.u.ts.delta;
|
||||
delta = ntohl(hdl->aucat.rmsg.u.ts.delta);
|
||||
hdl->maxwrite += delta * hdl->wbpf;
|
||||
hdl->delta += delta;
|
||||
DPRINTF("aucat: move = %d, delta = %d, maxwrite = %d\n",
|
||||
hdl->aucat.rmsg.u.ts.delta, hdl->delta, hdl->maxwrite);
|
||||
delta, hdl->delta, hdl->maxwrite);
|
||||
if (hdl->delta >= 0) {
|
||||
sio_onmove_cb(&hdl->sio, hdl->delta);
|
||||
hdl->delta = 0;
|
||||
}
|
||||
break;
|
||||
case AMSG_SETVOL:
|
||||
hdl->curvol = hdl->reqvol = hdl->aucat.rmsg.u.vol.ctl;
|
||||
sio_onvol_cb(&hdl->sio, hdl->curvol);
|
||||
ctl = ntohl(hdl->aucat.rmsg.u.vol.ctl);
|
||||
hdl->curvol = hdl->reqvol = ctl;
|
||||
sio_onvol_cb(&hdl->sio, ctl);
|
||||
break;
|
||||
case AMSG_STOP:
|
||||
hdl->pstate = PSTATE_INIT;
|
||||
|
@ -133,8 +139,8 @@ sio_aucat_buildmsg(struct sio_aucat_hdl *hdl)
|
|||
if (hdl->curvol != hdl->reqvol) {
|
||||
hdl->aucat.wstate = WSTATE_MSG;
|
||||
hdl->aucat.wtodo = sizeof(struct amsg);
|
||||
hdl->aucat.wmsg.cmd = AMSG_SETVOL;
|
||||
hdl->aucat.wmsg.u.vol.ctl = hdl->reqvol;
|
||||
hdl->aucat.wmsg.cmd = htonl(AMSG_SETVOL);
|
||||
hdl->aucat.wmsg.u.vol.ctl = htonl(hdl->reqvol);
|
||||
hdl->curvol = hdl->reqvol;
|
||||
return aucat_wmsg(&hdl->aucat, &hdl->sio.eof);
|
||||
}
|
||||
|
@ -189,7 +195,7 @@ sio_aucat_start(struct sio_hdl *sh)
|
|||
DPRINTF("aucat: start, maxwrite = %d\n", hdl->maxwrite);
|
||||
|
||||
AMSG_INIT(&hdl->aucat.wmsg);
|
||||
hdl->aucat.wmsg.cmd = AMSG_START;
|
||||
hdl->aucat.wmsg.cmd = htonl(AMSG_START);
|
||||
hdl->aucat.wtodo = sizeof(struct amsg);
|
||||
if (!aucat_wmsg(&hdl->aucat, &hdl->sio.eof))
|
||||
return 0;
|
||||
|
@ -234,7 +240,7 @@ sio_aucat_stop(struct sio_hdl *sh)
|
|||
* send stop message
|
||||
*/
|
||||
AMSG_INIT(&hdl->aucat.wmsg);
|
||||
hdl->aucat.wmsg.cmd = AMSG_STOP;
|
||||
hdl->aucat.wmsg.cmd = htonl(AMSG_STOP);
|
||||
hdl->aucat.wtodo = sizeof(struct amsg);
|
||||
if (!aucat_wmsg(&hdl->aucat, &hdl->sio.eof))
|
||||
return 0;
|
||||
|
@ -263,19 +269,19 @@ sio_aucat_setpar(struct sio_hdl *sh, struct sio_par *par)
|
|||
struct sio_aucat_hdl *hdl = (struct sio_aucat_hdl *)sh;
|
||||
|
||||
AMSG_INIT(&hdl->aucat.wmsg);
|
||||
hdl->aucat.wmsg.cmd = AMSG_SETPAR;
|
||||
hdl->aucat.wmsg.cmd = htonl(AMSG_SETPAR);
|
||||
hdl->aucat.wmsg.u.par.bits = par->bits;
|
||||
hdl->aucat.wmsg.u.par.bps = par->bps;
|
||||
hdl->aucat.wmsg.u.par.sig = par->sig;
|
||||
hdl->aucat.wmsg.u.par.le = par->le;
|
||||
hdl->aucat.wmsg.u.par.msb = par->msb;
|
||||
hdl->aucat.wmsg.u.par.rate = par->rate;
|
||||
hdl->aucat.wmsg.u.par.appbufsz = par->appbufsz;
|
||||
hdl->aucat.wmsg.u.par.rate = htonl(par->rate);
|
||||
hdl->aucat.wmsg.u.par.appbufsz = htonl(par->appbufsz);
|
||||
hdl->aucat.wmsg.u.par.xrun = par->xrun;
|
||||
if (hdl->sio.mode & SIO_REC)
|
||||
hdl->aucat.wmsg.u.par.rchan = par->rchan;
|
||||
hdl->aucat.wmsg.u.par.rchan = htons(par->rchan);
|
||||
if (hdl->sio.mode & SIO_PLAY)
|
||||
hdl->aucat.wmsg.u.par.pchan = par->pchan;
|
||||
hdl->aucat.wmsg.u.par.pchan = htons(par->pchan);
|
||||
hdl->aucat.wtodo = sizeof(struct amsg);
|
||||
if (!aucat_wmsg(&hdl->aucat, &hdl->sio.eof))
|
||||
return 0;
|
||||
|
@ -288,14 +294,14 @@ sio_aucat_getpar(struct sio_hdl *sh, struct sio_par *par)
|
|||
struct sio_aucat_hdl *hdl = (struct sio_aucat_hdl *)sh;
|
||||
|
||||
AMSG_INIT(&hdl->aucat.wmsg);
|
||||
hdl->aucat.wmsg.cmd = AMSG_GETPAR;
|
||||
hdl->aucat.wmsg.cmd = htonl(AMSG_GETPAR);
|
||||
hdl->aucat.wtodo = sizeof(struct amsg);
|
||||
if (!aucat_wmsg(&hdl->aucat, &hdl->sio.eof))
|
||||
return 0;
|
||||
hdl->aucat.rtodo = sizeof(struct amsg);
|
||||
if (!aucat_rmsg(&hdl->aucat, &hdl->sio.eof))
|
||||
return 0;
|
||||
if (hdl->aucat.rmsg.cmd != AMSG_GETPAR) {
|
||||
if (ntohl(hdl->aucat.rmsg.cmd) != AMSG_GETPAR) {
|
||||
DPRINTF("sio_aucat_getpar: protocol err\n");
|
||||
hdl->sio.eof = 1;
|
||||
return 0;
|
||||
|
@ -305,15 +311,15 @@ sio_aucat_getpar(struct sio_hdl *sh, struct sio_par *par)
|
|||
par->sig = hdl->aucat.rmsg.u.par.sig;
|
||||
par->le = hdl->aucat.rmsg.u.par.le;
|
||||
par->msb = hdl->aucat.rmsg.u.par.msb;
|
||||
par->rate = hdl->aucat.rmsg.u.par.rate;
|
||||
par->bufsz = hdl->aucat.rmsg.u.par.bufsz;
|
||||
par->appbufsz = hdl->aucat.rmsg.u.par.appbufsz;
|
||||
par->rate = ntohl(hdl->aucat.rmsg.u.par.rate);
|
||||
par->bufsz = ntohl(hdl->aucat.rmsg.u.par.bufsz);
|
||||
par->appbufsz = ntohl(hdl->aucat.rmsg.u.par.appbufsz);
|
||||
par->xrun = hdl->aucat.rmsg.u.par.xrun;
|
||||
par->round = hdl->aucat.rmsg.u.par.round;
|
||||
par->round = ntohl(hdl->aucat.rmsg.u.par.round);
|
||||
if (hdl->sio.mode & SIO_PLAY)
|
||||
par->pchan = hdl->aucat.rmsg.u.par.pchan;
|
||||
par->pchan = ntohs(hdl->aucat.rmsg.u.par.pchan);
|
||||
if (hdl->sio.mode & SIO_REC)
|
||||
par->rchan = hdl->aucat.rmsg.u.par.rchan;
|
||||
par->rchan = ntohs(hdl->aucat.rmsg.u.par.rchan);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue