[Mplayer-cvslog] CVS: main/libao2 ao_esd.c,1.4,1.5

Attila Kinali CVS attila at mplayerhq.hu
Wed Dec 10 13:19:36 CET 2003


Update of /cvsroot/mplayer/main/libao2
In directory mail:/var/tmp.root/cvs-serv3293

Modified Files:
	ao_esd.c 
Log Message:
This patch contains bugfixes for the esd audio output driver that I
uncovered while trying to send sound to a remote esd server over a
wireless (11 mbs, just enough to handle to sound) link.

First, the sound was full "ticking" sounds.  I found a bug that
prevented the "send the remainder of this block" code from ever being
called - so large chunks of audio were simply being ignored.  Fixing
this bug removed the "ticking" from audio streams. 

Fixing this bug, however, uncovered another problem - when the socket
buffer was full, doing a blocking write to finish the buffer would take
far too long and would turn video into a chunky mess.  I'd imagine this
blocking write would be fine for an audio-only stream, but it turns out
to hold up the video far too much.

The solution in this patch is to write as much data as possible to the
socket, and then return as soon as possible, reporting the number of
bytes actually written accurately back to mplayer.  I've tested it on
both local and remote esd servers, and it works well. 

Patch by Benjamin Osheroff <ben at gimbo.net>


Index: ao_esd.c
===================================================================
RCS file: /cvsroot/mplayer/main/libao2/ao_esd.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ao_esd.c	30 May 2003 18:15:59 -0000	1.4
+++ ao_esd.c	10 Dec 2003 12:19:13 -0000	1.5
@@ -315,58 +315,24 @@
 #if	SINGLE_WRITE
     nwritten = write(esd_play_fd, data, len);
 #else
-    for (offs = 0; offs + ESD_BUF_SIZE <= len; offs += ESD_BUF_SIZE) {
+    for (offs = 0, nwritten=0; offs + ESD_BUF_SIZE <= len; offs += ESD_BUF_SIZE) {
 	/*
 	 * note: we're writing to a non-blocking socket here.
 	 * A partial write means, that the socket buffer is full.
 	 */
-	nwritten = write(esd_play_fd, (char*)data + offs, ESD_BUF_SIZE);
-	if (nwritten != ESD_BUF_SIZE) {
-	    if (nwritten < 0 && errno != EAGAIN) {
+	n = write(esd_play_fd, (char*)data + offs, ESD_BUF_SIZE);
+	if ( n < 0 ) {
+	    if ( errno != EAGAIN ) 
 		dprintf("esd play: write failed: %s\n", strerror(errno));
-	    }
 	    break;
-	}
-    }
-    nwritten = offs;
-#endif
-
-    if (nwritten > 0 && nwritten % ESD_BUF_SIZE != 0) {
-
-	/*
-	 * partial write of an audio block of ESD_BUF_SIZE bytes.
-	 *
-	 * Send the remainder of that block as well; this avoids a busy
-	 * polling loop in the esd daemon, which waits for the rest of
-	 * the incomplete block using reads from a non-blocking
-	 * socket. This busy polling loop wastes CPU cycles on the
-	 * esd server machine, and we're trying to avoid that.
-	 * (esd 0.2.28+ has the busy polling read loop, 0.2.22 inserts
-	 * 0 samples which is bad as well)
-	 *
-	 * Let's hope the blocking write does not consume too much time.
-	 *
-	 * (fortunatelly, this piece of code is not used when playing
-	 * sound on the local machine - on solaris at least)
-	 */
-	remainder = ESD_BUF_SIZE - nwritten % ESD_BUF_SIZE;
-	dprintf("esd play: partial audio block written, remainder %d \n",
-		remainder);
-
-	/* blocking write of remaining bytes for the partial audio block */
-	saved_fl = fcntl(esd_play_fd, F_GETFL);
-	fcntl(esd_play_fd, F_SETFL, saved_fl & ~O_NDELAY);
-	n = write(esd_play_fd, (char *)data + nwritten, remainder);
-	fcntl(esd_play_fd, F_SETFL, saved_fl);
-
-	if (n != remainder) {
-	    mp_msg(MSGT_AO, MSGL_ERR,
-		   "AO: [esd] send remainer of audio block failed, %d/%d\n",
-		   n, remainder);
+	} else if ( n != ESD_BUF_SIZE ) {
+	    nwritten += n;
+	    break;
 	} else
 	    nwritten += n;
     }
-
+#endif
+	
     if (nwritten > 0) {
 	if (!esd_play_start.tv_sec)
 	    gettimeofday(&esd_play_start, NULL);



More information about the MPlayer-cvslog mailing list