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

Alex Beregszaszi alex at mplayerhq.hu
Fri May 30 20:16:02 CEST 2003


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

Modified Files:
	ao_esd.c 
Log Message:
esd:server and esd latency support by Andrew Williams <andrew.s.williams at adelaide.edu.au>

Index: ao_esd.c
===================================================================
RCS file: /cvsroot/mplayer/main/libao2/ao_esd.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ao_esd.c	21 Mar 2003 16:42:50 -0000	1.3
+++ ao_esd.c	30 May 2003 18:15:59 -0000	1.4
@@ -51,7 +51,6 @@
 #define	ESD_CLIENT_NAME	"MPlayer"
 #define	ESD_MAX_DELAY	(1.0f)	/* max amount of data buffered in esd (#sec) */
 
-
 static ao_info_t info =
 {
     "EsounD audio output",
@@ -69,7 +68,7 @@
 static int esd_bytes_per_sample;
 static unsigned long esd_samples_written;
 static struct timeval esd_play_start;
-
+extern float audio_delay;
 
 /*
  * to set/get/query special features/parameters
@@ -146,25 +145,36 @@
     esd_format_t esd_fmt;
     int bytes_per_sample;
     int fl;
+    char *server = ao_subdevice;  /* NULL for localhost */
+    float lag_seconds, lag_net, lag_serv;
+    struct timeval proto_start, proto_end;
 
     if (esd_fd < 0) {
-	esd_fd = esd_open_sound(NULL);
+	esd_fd = esd_open_sound(server);
 	if (esd_fd < 0) {
-	    mp_msg(MSGT_AO, MSGL_ERR, "AO: [esd] esd_open_sound failed: %s\n",
+	    mp_msg(MSGT_AO, MSGL_ERR, 
+		   "AO: [esd] esd_open_sound failed: %s\n",
 		   strerror(errno));
 	    return 0;
 	}
 
+	/* get server info, and measure network latency */
+	gettimeofday(&proto_start, NULL);
 	esd_svinfo = esd_get_server_info(esd_fd);
-     /*
+	if(server) {
+	    gettimeofday(&proto_end, NULL);
+	    lag_net  = (proto_end.tv_sec  - proto_start.tv_sec) +
+		(proto_end.tv_usec - proto_start.tv_usec) / 1000000.0;
+	    lag_net /= 2.0; /* round trip -> one way */
+	} else
+	    lag_net = 0.0;  /* no network lag */
+
+	/*
 	if (esd_svinfo) {
 	    mp_msg(MSGT_AO, MSGL_INFO, "AO: [esd] server info:\n");
 	    esd_print_server_info(esd_svinfo);
 	}
-      */
-
-	esd_latency = esd_get_latency(esd_fd);
-	/* mp_msg(MSGT_AO, MSGL_INFO, "AO: [esd] latency: %d\n", esd_latency); */
+	*/
     }
 
     esd_fmt = ESD_STREAM | ESD_PLAY;
@@ -178,7 +188,6 @@
 #endif
     ao_data.samplerate = rate_hz;
 
-    
     /* EsounD can play mono or stereo */
     switch (channels) {
     case 1:
@@ -205,8 +214,29 @@
 	break;
     }
 
+    /* modify audio_delay depending on esd_latency
+     * latency is number of samples @ 44.1khz stereo 16 bit
+     * adjust according to rate_hz & bytes_per_sample
+     */
+#ifdef HAVE_ESD_LATENCY
+    esd_latency = esd_get_latency(esd_fd);
+#else
+    esd_latency = ((channels == 1 ? 2 : 1) * ESD_DEFAULT_RATE * 
+		   (ESD_BUF_SIZE + 64 * (4.0f / bytes_per_sample))
+		   ) / rate_hz;  
+    esd_latency += ESD_BUF_SIZE * 2; 
+#endif
+    if(esd_latency > 0) {
+	lag_serv = (esd_latency * 4.0f) / (bytes_per_sample * rate_hz);
+	lag_seconds = lag_net + lag_serv;
+	audio_delay += lag_seconds;
+	mp_msg(MSGT_AO, MSGL_INFO,
+	       "AO: [esd] latency: [server: %0.2fs, net: %0.2fs] "
+	       "(adjust %0.2fs)\n", lag_serv, lag_net, lag_seconds);
+    }
+    
     esd_play_fd = esd_play_stream_fallback(esd_fmt, rate_hz,
-					   NULL, ESD_CLIENT_NAME);
+					   server, ESD_CLIENT_NAME);
     if (esd_play_fd < 0) {
 	mp_msg(MSGT_AO, MSGL_ERR,
 	       "AO: [esd] failed to open esd playback stream: %s\n",



More information about the MPlayer-cvslog mailing list