Re: sndio: protocol change - diff to test

2012-10-31 Thread Jonathan Gray
On Sun, Oct 28, 2012 at 01:55:34PM +0100, Alexandre Ratchov wrote:
 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@)

There seems to be some compat issue, before I restarted sndiod 44khz
audio was playing at what sounded like the system/hardware 48khz without
conversion.  After restarting sndiod it was fine though.

A quick midi test seems to reveal no problems, sysex messages still come
through, timing sounds right.



Re: sndio: protocol change - diff to test

2012-10-29 Thread Thomas Pfaff
On Sun, 28 Oct 2012 13:55:34 +0100
Alexandre Ratchov a...@caoua.org wrote:

 sorry; the previous diff is wrong, please consider the one
 below (thanks jsg@)
 
 Index: lib/libsndio/amsg.h
 ===
 RCS file: /cvs/src/lib/libsndio/amsg.h,v

Hi.

No noticable difference here after doing some light testing.

Cheers,
Thomas.



Re: sndio: protocol change - diff to test

2012-10-28 Thread Jonathan Gray
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?

This seems to break seeking in mplayer (both audio and video files),
after using the right arrow key to skip ahead it just stops.

attaching from gdb it looks like:

#0  0x197af601039a in poll () at stdin:2
#1  0x197af6ce413d in poll (fds=0x7f7ba060, nfds=1, timeout=-1)
at /usr/src/lib/librthread/rthread_cancel.c:331
#2  0x197af2c1c09f in sio_psleep (hdl=0x197afbd61600, event=4)
at /usr/src/lib/libsndio/sio.c:220
#3  0x197af2c1c264 in sio_write (hdl=0x197afbd61600, buf=0x197af1d86000, 
len=7056) at /usr/src/lib/libsndio/sio.c:308
#4  0x1978eddecec5 in send_udp () from /usr/local/bin/mplayer
#5  0x1978eddc6fae in main () from /usr/local/bin/mplayer



Re: sndio: protocol change - diff to test

2012-10-28 Thread Alexandre Ratchov
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;
+  

Re: sndio: protocol change - diff to test

2012-10-28 Thread Alexandre Ratchov
On Sun, Oct 28, 2012 at 06:45:59PM +1100, Jonathan Gray wrote:
 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?
 
 This seems to break seeking in mplayer (both audio and video files),
 after using the right arrow key to skip ahead it just stops.
 

thanks! ... stupid mistake. I hope the diff in my other mail works
better ;)

On Sat, Oct 27, 2012 at 03:14:07PM +0200, Alexandre Ratchov wrote:

 @@ -551,14 +549,15 @@ sock_attach(struct sock *f, int force)
* get the current position, the origin is when
* the first sample is played/recorded
*/
 - f-startpos = dev_getpos(f-dev) * (int)f-round / (int)f-dev-round;
 - f-startpending = 1;
 + f-delta = dev_getpos(f-dev) *
 + (int)f-round / (int)f-dev-round;
 + f-fillpending = f-delta;
^^
this should be zero

   f-pstate = SOCK_RUN;
  #ifdef DEBUG
   if (debug_level = 3) {
   sock_dbg(f);
   dbg_puts(: attaching at );
 - dbg_puti(f-startpos);
 + dbg_puti(f-delta);
   dbg_puts(\n);
   }
  #endif