CVS: rdesktop rdpsnd_oss.c,1.34,1.35

Pierre Ossman <[email protected]> Tue, 02 Jan 2007 08:37:56 -0800
Newsgroups gmane.network.rdesktop.cvs
Message-ID <[email protected]>
Update of /cvsroot/rdesktop/rdesktop
In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv17671

Modified Files:
	rdpsnd_oss.c 
Log Message:
Add capture support to the oss backend.


Index: rdpsnd_oss.c
===================================================================
RCS file: /cvsroot/rdesktop/rdesktop/rdpsnd_oss.c,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -d -r1.34 -r1.35
*** rdpsnd_oss.c	2 Jan 2007 11:39:56 -0000	1.34
--- rdpsnd_oss.c	2 Jan 2007 16:37:54 -0000	1.35
***************
*** 4,7 ****
--- 4,8 ----
     Copyright (C) Matthew Chapman 2003
     Copyright (C) GuoJunBo [email protected] 2003
+    Copyright 2006 Pierre Ossman <[email protected]> for Cendio AB
  
     This program is free software; you can redistribute it and/or modify
***************
*** 45,50 ****
  
  static int dsp_fd = -1;
! static BOOL dsp_busy;
  
  static int snd_rate;
  static short samplewidth;
--- 46,59 ----
  
  static int dsp_fd = -1;
! static int dsp_mode;
! static int dsp_refs;
! 
! static BOOL dsp_configured;
  
+ static BOOL dsp_out;
+ static BOOL dsp_in;
+ 
+ static int stereo;
+ static int format;
  static int snd_rate;
  static short samplewidth;
***************
*** 56,59 ****
--- 65,69 ----
  
  void oss_play(void);
+ void oss_record(void);
  
  void
***************
*** 63,70 ****
  		return;
  
! 	if (rdpsnd_queue_empty())
! 		return;
! 
! 	FD_SET(dsp_fd, wfds);
  	if (dsp_fd > *n)
  		*n = dsp_fd;
--- 73,80 ----
  		return;
  
! 	if (dsp_out && !rdpsnd_queue_empty())
! 		FD_SET(dsp_fd, wfds);
! 	if (dsp_in)
! 		FD_SET(dsp_fd, rfds);
  	if (dsp_fd > *n)
  		*n = dsp_fd;
***************
*** 76,79 ****
--- 86,91 ----
  	if (FD_ISSET(dsp_fd, wfds))
  		oss_play();
+ 	if (FD_ISSET(dsp_fd, rfds))
+ 		oss_record();
  }
  
***************
*** 101,112 ****
  
  BOOL
! oss_open(void)
  {
! 	if ((dsp_fd = open(dsp_dev, O_WRONLY)) == -1)
  	{
! 		perror(dsp_dev);
  		return False;
  	}
  
  	in_esddsp = detect_esddsp();
  
--- 113,163 ----
  
  BOOL
! oss_open(int fallback)
  {
! 	int caps;
! 
! 	if (dsp_fd != -1)
  	{
! 		dsp_refs++;
! 
! 		if (dsp_mode == O_RDWR)
! 			return True;
! 
! 		if (dsp_mode == fallback)
! 			return True;
! 
! 		dsp_refs--;
  		return False;
  	}
  
+ 	dsp_configured = False;
+ 
+ 	dsp_mode = O_RDWR;
+ 	dsp_fd = open(dsp_dev, O_RDWR | O_NONBLOCK);
+ 	if (dsp_fd != -1)
+ 	{
+ 		ioctl(dsp_fd, SNDCTL_DSP_SETDUPLEX, 0);
+ 
+ 		if ((ioctl(dsp_fd, SNDCTL_DSP_GETCAPS, &caps) < 0) || !(caps & DSP_CAP_DUPLEX))
+ 		{
+ 			close(dsp_fd);
+ 			dsp_fd = -1;
+ 		}
+ 	}
+ 
+ 	if (dsp_fd == -1)
+ 	{
+ 		dsp_mode = fallback;
+ 
+ 		dsp_fd = open(dsp_dev, dsp_mode | O_NONBLOCK);
+ 		if (dsp_fd == -1)
+ 		{
+ 			perror(dsp_dev);
+ 			return False;
+ 		}
+ 	}
+ 
+ 	dsp_refs++;
+ 
  	in_esddsp = detect_esddsp();
  
***************
*** 117,123 ****
  oss_close(void)
  {
  	close(dsp_fd);
  	dsp_fd = -1;
! 	dsp_busy = False;
  }
  
--- 168,220 ----
  oss_close(void)
  {
+ 	dsp_refs--;
+ 
+ 	if (dsp_refs != 0)
+ 		return;
+ 
  	close(dsp_fd);
  	dsp_fd = -1;
! }
! 
! BOOL
! oss_open_out(void)
! {
! 	if (!oss_open(O_WRONLY))
! 		return False;
! 
! 	dsp_out = True;
! 
! 	return True;
! }
! 
! void
! oss_close_out(void)
! {
! 	oss_close();
! 
! 	/* Ack all remaining packets */
! 	while (!rdpsnd_queue_empty())
! 		rdpsnd_queue_next(0);
! 
! 	dsp_out = False;
! }
! 
! BOOL
! oss_open_in(void)
! {
! 	if (!oss_open(O_RDONLY))
! 		return False;
! 
! 	dsp_in = True;
! 
! 	return True;
! }
! 
! void
! oss_close_in(void)
! {
! 	oss_close();
! 
! 	dsp_in = False;
  }
  
***************
*** 138,144 ****
  oss_set_format(WAVEFORMATEX * pwfx)
  {
! 	int stereo, format, fragments;
  	static BOOL driver_broken = False;
  
  	ioctl(dsp_fd, SNDCTL_DSP_RESET, NULL);
  	ioctl(dsp_fd, SNDCTL_DSP_SYNC, NULL);
--- 235,257 ----
  oss_set_format(WAVEFORMATEX * pwfx)
  {
! 	int fragments;
  	static BOOL driver_broken = False;
  
+ 	if (dsp_configured)
+ 	{
+ 		if ((pwfx->wBitsPerSample == 8) && (format != AFMT_U8))
+ 			return False;
+ 		if ((pwfx->wBitsPerSample == 16) && (format != AFMT_S16_LE))
+ 			return False;
+ 
+ 		if ((pwfx->nChannels == 2) != !!stereo)
+ 			return False;
+ 
+ 		if (pwfx->nSamplesPerSec != snd_rate)
+ 			return False;
+ 
+ 		return True;
+ 	}
+ 
  	ioctl(dsp_fd, SNDCTL_DSP_RESET, NULL);
  	ioctl(dsp_fd, SNDCTL_DSP_SYNC, NULL);
***************
*** 235,238 ****
--- 348,353 ----
  	}
  
+ 	dsp_configured = True;
+ 
  	return True;
  }
***************
*** 317,320 ****
--- 432,452 ----
  }
  
+ void
+ oss_record(void)
+ {
+ 	char buffer[32768];
+ 	int len;
+ 
+ 	len = read(dsp_fd, buffer, sizeof(buffer));
+ 	if (len == -1)
+ 	{
+ 		if (errno != EWOULDBLOCK)
+ 			perror("read audio");
+ 		return;
+ 	}
+ 
+ 	rdpsnd_record(buffer, len);
+ }
+ 
  struct audio_driver *
  oss_register(char *options)
***************
*** 329,338 ****
  	oss_driver.check_fds = oss_check_fds;
  
! 	oss_driver.wave_out_open = oss_open;
! 	oss_driver.wave_out_close = oss_close;
  	oss_driver.wave_out_format_supported = oss_format_supported;
  	oss_driver.wave_out_set_format = oss_set_format;
  	oss_driver.wave_out_volume = oss_volume;
  
  	oss_driver.need_byteswap_on_be = 0;
  	oss_driver.need_resampling = 0;
--- 461,476 ----
  	oss_driver.check_fds = oss_check_fds;
  
! 	oss_driver.wave_out_open = oss_open_out;
! 	oss_driver.wave_out_close = oss_close_out;
  	oss_driver.wave_out_format_supported = oss_format_supported;
  	oss_driver.wave_out_set_format = oss_set_format;
  	oss_driver.wave_out_volume = oss_volume;
  
+ 	oss_driver.wave_in_open = oss_open_in;
+ 	oss_driver.wave_in_close = oss_close_in;
+ 	oss_driver.wave_in_format_supported = oss_format_supported;
+ 	oss_driver.wave_in_set_format = oss_set_format;
+ 	oss_driver.wave_in_volume = NULL;	/* FIXME */
+ 
  	oss_driver.need_byteswap_on_be = 0;
  	oss_driver.need_resampling = 0;


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV