CVS: rdesktop rdpsnd_libao.c,1.7,1.8

Michael Gernoth <[email protected]>
Newsgroups gmane.network.rdesktop.cvs
Message-ID <[email protected]>
Update of /cvsroot/rdesktop/rdesktop
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28569

Modified Files:
	rdpsnd_libao.c 
Log Message:
much better sound synchronization using the provided timestamps


Index: rdpsnd_libao.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/rdpsnd_libao.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** rdpsnd_libao.c	8 Mar 2005 17:23:26 -0000	1.7
--- rdpsnd_libao.c	22 Apr 2005 21:54:57 -0000	1.8
***************
*** 26,29 ****
--- 26,30 ----
  #include <errno.h>
  #include <ao/ao.h>
+ #include <sys/time.h>
  
  #define MAX_QUEUE	10
***************
*** 36,39 ****
--- 37,41 ----
  int g_channels;
  BOOL g_dsp_busy = False;
+ static BOOL g_reopened;
  static short g_samplewidth;
  
***************
*** 70,73 ****
--- 72,77 ----
  	queue_lo = queue_hi = 0;
  
+ 	g_reopened = True;
+ 
  	return True;
  }
***************
*** 130,133 ****
--- 134,138 ----
  	}
  
+ 	g_reopened = True;
  
  	return True;
***************
*** 173,176 ****
--- 178,193 ----
  	unsigned char outbuf[WAVEOUTBUF];
  	int offset, len, i;
+ 	static long prev_s, prev_us;
+ 	unsigned int duration;
+ 	struct timeval tv;
+ 	int next_tick;
+ 
+ 	if (g_reopened)
+ 	{
+ 		g_reopened = False;
+ 		gettimeofday(&tv, NULL);
+ 		prev_s = tv.tv_sec;
+ 		prev_us = tv.tv_usec;
+ 	}
  
  	if (queue_lo == queue_hi)
***************
*** 183,186 ****
--- 200,212 ----
  	out = &packet->s;
  
+ 	if (((queue_lo + 1) % MAX_QUEUE) != queue_hi)
+ 	{
+ 		next_tick = packet_queue[(queue_lo + 1) % MAX_QUEUE].tick;
+ 	}
+ 	else
+ 	{
+ 		next_tick = (packet->tick + 65535) % 65536;
+ 	}
+ 
  	len = 0;
  
***************
*** 217,223 ****
  	ao_play(o_device, outbuf, len);
  
! 	if (out->p == out->end)
  	{
! 		rdpsnd_send_completion(packet->tick, packet->index);
  		free(out->data);
  		queue_lo = (queue_lo + 1) % MAX_QUEUE;
--- 243,268 ----
  	ao_play(o_device, outbuf, len);
  
! 	gettimeofday(&tv, NULL);
! 
! 	duration = ((tv.tv_sec - prev_s) * 1000000 + (tv.tv_usec - prev_us)) / 1000;
! 
! 	if (packet->tick > next_tick)
! 		next_tick += 65536;
! 
! 	if ((out->p == out->end) || duration > next_tick - packet->tick + 500)
  	{
! 		prev_s = tv.tv_sec;
! 		prev_us = tv.tv_usec;
! 
! 		if (abs((next_tick - packet->tick) - duration) > 20)
! 		{
! 			DEBUG(("duration: %d, calc: %d, ", duration, next_tick - packet->tick));
! 			DEBUG(("last: %d, is: %d, should: %d\n", packet->tick,
! 			       (packet->tick + duration) % 65536, next_tick % 65536));
! 		}
! 
! 		/* Until all drivers are using the windows sound-ticks, we need to
! 		   substract the 50 ticks added later by rdpsnd.c */
! 		rdpsnd_send_completion(((packet->tick + duration) % 65536) - 50, packet->index);
  		free(out->data);
  		queue_lo = (queue_lo + 1) % MAX_QUEUE;



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.