On Sat, Oct 27, 2012 at 03:14:07PM +0200, Alexandre Ratchov wrote:
Hi,
This diff is to use dedicated messages for flow control instead of
abusing clock tick messages and to enable flow control for MIDI.
There should be no change in behaviour, but this change is
necessary for future developpement of sndiod.
any regression? ok?
sorry; the previous diff is wrong, please consider the one
below (thanks jsg@)
-- Alexandre
Index: lib/libsndio/amsg.h
===
RCS file: /cvs/src/lib/libsndio/amsg.h,v
retrieving revision 1.4
diff -u -p -r1.4 amsg.h
--- lib/libsndio/amsg.h 15 Nov 2011 08:05:22 - 1.4
+++ lib/libsndio/amsg.h 28 Oct 2012 12:28:51 -
@@ -42,7 +42,7 @@ struct amsg {
#define AMSG_START 3 /* request the server to start the stream */
#define AMSG_STOP 4 /* request the server to stop the stream */
#define AMSG_DATA 5 /* data block */
-#define AMSG_POS 6 /* initial position */
+#define AMSG_FLOWCTL 6 /* feedback about buffer usage */
#define AMSG_MOVE 7 /* position changed */
#define AMSG_SETVOL9 /* set volume */
#define AMSG_HELLO 10 /* say hello, check versions and so ... */
@@ -80,7 +80,7 @@ struct amsg {
} vol;
struct amsg_hello {
uint16_t mode; /* bitmap of MODE_XXX */
-#define AMSG_VERSION 5
+#define AMSG_VERSION 6
uint8_t version;/* protocol version */
uint8_t devnum; /* device number */
uint32_t _reserved[1]; /* for future use */
Index: lib/libsndio/aucat.c
===
RCS file: /cvs/src/lib/libsndio/aucat.c,v
retrieving revision 1.54
diff -u -p -r1.54 aucat.c
--- lib/libsndio/aucat.c11 Apr 2012 06:05:43 - 1.54
+++ lib/libsndio/aucat.c28 Oct 2012 12:28:51 -
@@ -463,6 +463,7 @@ aucat_open(struct aucat *hdl, const char
hdl-rtodo = sizeof(struct amsg);
hdl-wstate = WSTATE_IDLE;
hdl-wtodo = 0xdeadbeef;
+ hdl-maxwrite = 0;
/*
* say hello to server
Index: lib/libsndio/aucat.h
===
RCS file: /cvs/src/lib/libsndio/aucat.h,v
retrieving revision 1.4
diff -u -p -r1.4 aucat.h
--- lib/libsndio/aucat.h15 Nov 2011 08:05:22 - 1.4
+++ lib/libsndio/aucat.h28 Oct 2012 12:28:51 -
@@ -14,6 +14,7 @@ struct aucat {
#define WSTATE_MSG 3 /* message being transferred */
#define WSTATE_DATA4 /* data being transferred */
unsigned wstate;/* one of above */
+ unsigned maxwrite; /* bytes we're allowed to write */
};
int aucat_rmsg(struct aucat *, int *);
Index: lib/libsndio/mio_aucat.c
===
RCS file: /cvs/src/lib/libsndio/mio_aucat.c,v
retrieving revision 1.8
diff -u -p -r1.8 mio_aucat.c
--- lib/libsndio/mio_aucat.c27 Oct 2012 12:08:25 - 1.8
+++ lib/libsndio/mio_aucat.c28 Oct 2012 12:28:51 -
@@ -54,6 +54,35 @@ static struct mio_ops mio_aucat_ops = {
mio_aucat_revents
};
+/*
+ * execute the next message, return 0 if blocked
+ */
+static int
+mio_aucat_runmsg(struct mio_aucat_hdl *hdl)
+{
+ int delta;
+
+ if (!aucat_rmsg(hdl-aucat, hdl-mio.eof))
+ return 0;
+ switch (ntohl(hdl-aucat.rmsg.cmd)) {
+ case AMSG_DATA:
+ return 1;
+ case AMSG_FLOWCTL:
+ delta = ntohl(hdl-aucat.rmsg.u.ts.delta);
+ hdl-aucat.maxwrite += delta;
+ DPRINTF(aucat: flowctl = %d, maxwrite = %d\n,
+ delta, hdl-aucat.maxwrite);
+ break;
+ default:
+ DPRINTF(mio_aucat_runmsg: unhandled message %u\n,
hdl-aucat.rmsg.cmd);
+ hdl-mio.eof = 1;
+ return 0;
+ }
+ hdl-aucat.rstate = RSTATE_MSG;
+ hdl-aucat.rtodo = sizeof(struct amsg);
+ return 1;
+}
+
struct mio_hdl *
mio_aucat_open(const char *str, unsigned int mode,
int nbio, unsigned int type)
@@ -91,7 +120,7 @@ mio_aucat_read(struct mio_hdl *sh, void
struct mio_aucat_hdl *hdl = (struct mio_aucat_hdl *)sh;
while (hdl-aucat.rstate == RSTATE_MSG) {
- if (!aucat_rmsg(hdl-aucat, hdl-mio.eof))
+ if (!mio_aucat_runmsg(hdl))
return 0;
}
return aucat_rdata(hdl-aucat, buf, len, hdl-mio.eof);
@@ -101,8 +130,15 @@ static size_t
mio_aucat_write(struct mio_hdl *sh, const void *buf, size_t len)
{
struct mio_aucat_hdl *hdl = (struct mio_aucat_hdl *)sh;
+ size_t n;
- return aucat_wdata(hdl-aucat, buf, len, 1, hdl-mio.eof);
+ if (len = 0 || hdl-aucat.maxwrite = 0)
+ return 0;
+