From 5cd067e6a0a8e1f399b4ecb54748438ad0dedbe7 Mon Sep 17 00:00:00 2001 From: attila Date: Wed, 10 Dec 2003 12:19:13 +0000 Subject: 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 git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@11620 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libao2/ao_esd.c | 52 +++++++++------------------------------------------- 1 file changed, 9 insertions(+), 43 deletions(-) (limited to 'libao2/ao_esd.c') diff --git a/libao2/ao_esd.c b/libao2/ao_esd.c index ea5394bb53..9318174c4c 100644 --- a/libao2/ao_esd.c +++ b/libao2/ao_esd.c @@ -315,58 +315,24 @@ static int play(void* data, int len, int flags) #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); -- cgit v1.2.3