CVS: rdesktop rdpsnd_sun.c,1.34,1.35

Peter Åstrand <[email protected]> Thu, 24 Apr 2008 08:11:20 -0700
Newsgroups gmane.network.rdesktop.cvs
Message-ID <[email protected]>
Update of /cvsroot/rdesktop/rdesktop
In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv13199

Modified Files:
	rdpsnd_sun.c 
Log Message:
Workaround to support recording on Sun Ray x86 systems. 



Index: rdpsnd_sun.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/rdpsnd_sun.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -d -r1.34 -r1.35
*** rdpsnd_sun.c	8 Feb 2008 10:40:56 -0000	1.34
--- rdpsnd_sun.c	24 Apr 2008 15:11:17 -0000	1.35
***************
*** 29,32 ****
--- 29,33 ----
  #include <sys/ioctl.h>
  #include <sys/audioio.h>
+ #include <string.h>
  
  #if (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
***************
*** 43,46 ****
--- 44,48 ----
  static RD_BOOL dsp_configured;
  static RD_BOOL dsp_broken;
+ static RD_BOOL broken_2_channel_record = False;
  
  static RD_BOOL dsp_out;
***************
*** 241,244 ****
--- 243,253 ----
  		return False;
  
+ 	/* 2 channel recording is known to be broken on Solaris x86
+ 	   Sun Ray systems */
+ #ifdef L_ENDIAN
+ 	if (strstr(dsp_dev, "/utaudio/"))
+ 		broken_2_channel_record = True;
+ #endif
+ 
  	/*
  	 * Unpause the stream now that we have someone using it.
***************
*** 314,327 ****
  	samplewidth = pwfx->wBitsPerSample / 8;
  
  	if (pwfx->nChannels == 1)
  	{
- 		info.play.channels = 1;
  		stereo = 0;
  	}
  	else if (pwfx->nChannels == 2)
  	{
- 		info.play.channels = 2;
  		stereo = 1;
  		samplewidth *= 2;
  	}
  
--- 323,347 ----
  	samplewidth = pwfx->wBitsPerSample / 8;
  
+ 	info.play.channels = pwfx->nChannels;
+ 	info.record.channels = info.play.channels;
+ 
  	if (pwfx->nChannels == 1)
  	{
  		stereo = 0;
  	}
  	else if (pwfx->nChannels == 2)
  	{
  		stereo = 1;
  		samplewidth *= 2;
+ 
+ 		if (broken_2_channel_record)
+ 		{
+ 			info.record.channels = 1;
+ 			if (rdpsnd_dsp_resample_set(pwfx->nSamplesPerSec, pwfx->wBitsPerSample, 2)
+ 			    == False)
+ 			{
+ 				return False;
+ 			}
+ 		}
  	}
  
***************
*** 336,340 ****
  
  	info.record.sample_rate = info.play.sample_rate;
- 	info.record.channels = info.play.channels;
  	info.record.precision = info.play.precision;
  	info.record.encoding = info.play.encoding;
--- 356,359 ----
***************
*** 446,450 ****
  	int len;
  
! 	len = read(dsp_fd, buffer, sizeof(buffer));
  	if (len == -1)
  	{
--- 465,469 ----
  	int len;
  
! 	len = read(dsp_fd, buffer, sizeof(buffer) / 2);
  	if (len == -1)
  	{
***************
*** 454,457 ****
--- 473,498 ----
  	}
  
+ 	if (broken_2_channel_record)
+ 	{
+ 		unsigned int i;
+ 		int rec_samplewidth = samplewidth / 2;
+ 		/* Loop over each byte read backwards and put in place */
+ 		i = len - 1;
+ 		do
+ 		{
+ 			int samples_before = i / rec_samplewidth * 2;
+ 			int sample_byte = i % rec_samplewidth;
+ 			int ch1_offset = samples_before * rec_samplewidth + sample_byte;
+ 			// Channel 1
+ 			buffer[ch1_offset] = buffer[i];
+ 			// Channel 2
+ 			buffer[ch1_offset + rec_samplewidth] = buffer[i];
+ 
+ 			i--;
+ 		}
+ 		while (i);
+ 		len *= 2;
+ 	}
+ 
  	rdpsnd_record(buffer, len);
  }


-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone