Subject: Re: Bugs in audio.c
To: None <tech-kern@netbsd.org>
From: Cliff Wright <cliff@snipe444.org>
List: tech-kern
Date: 02/02/2006 15:23:58
This is a multi-part message in MIME format.

--Multipart=_Thu__2_Feb_2006_15_23_58_-0800_qjw36n.7MS842QBy
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit

On Thu, 2 Feb 2006 23:35:26 +0100
Pavel Cahyna <pavel.cahyna@st.mff.cuni.cz> wrote:

> Does linphone work now for you?
Yes, I tested with asterisk in gsm, ulaw, alaw, speex, and also between
phones. asterisk did require at least gsm to be specificaly allowed.
Note their is a bug with the gui version with unlocking an already
unlocked mutex. I have not tracked this down yet, so currently ignore
with the PTHREAD_DIAGASSERT environment variable. Attached are my notes
(which really should be posted to a different group).


--Multipart=_Thu__2_Feb_2006_15_23_58_-0800_qjw36n.7MS842QBy
Content-Type: text/plain;
 name="cliffnotes.txt"
Content-Disposition: attachment;
 filename="cliffnotes.txt"
Content-Transfer-Encoding: 7bit

installed packages:
  audio/speex (I used version 1.0.5)
  devel/libosip (I used version 2.2.2)(package is called libosip2)
setenv LDFLAGS -lossaudio
./configure --disable-manual --enable-ipv6 --with-osip=/usr/pkg --with-speex=/usr/pkg
run with
  setenv PTHREAD_DIAGASSERT A	(command line linphonec works without this)
binary tared up with tar czf linphone-bin.tgz -T tarlist
NetBSD patch follows:

--- mediastreamer/osscard.c.distrib	2005-03-02 04:46:07.000000000 -0800
+++ mediastreamer/osscard.c	2006-02-01 13:56:31.000000000 -0800
@@ -25,6 +25,10 @@
 
 #ifdef HAVE_SYS_SOUNDCARD_H
 #include <sys/soundcard.h>
+#ifdef __NetBSD__
+#include <sys/ioctl.h>
+#include <sys/audioio.h>
+#endif
 
 #include <errno.h>
 #include <fcntl.h>
@@ -122,6 +126,29 @@
      	else p=p/2;
      }
 	}
+#ifdef __NetBSD__
+	{
+	int duplex = 1;
+	audio_info_t ainfo;
+
+		/* set device to full duplex */
+		if(ioctl(fd, AUDIO_SETFD, &duplex) < 0) {
+			g_warning("oss_open: can't set to full duplex:%s.",strerror(errno));
+		}
+		/*
+		 * set mode to play all data even if late
+		 * set blocksize for 32ms of audio
+		 * start recording
+		 */
+		AUDIO_INITINFO(&ainfo);
+		ainfo.mode = AUMODE_PLAY_ALL | AUMODE_RECORD;
+		ainfo.blocksize = rate * bits / 250;
+		ainfo.record.pause = 0;
+		if (ioctl(fd, AUDIO_SETINFO, &ainfo) == -1) {
+			perror( "ioctl, audio setting mode" );
+		}
+	}
+#endif
 	ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &min_size);
 	if (min_size>blocksize)
 	{
@@ -161,7 +188,11 @@
 	int min_size=0,blocksize=512;
 	
 	if (obj->fd>0) return SND_CARD(obj)->bsize;
+#ifdef __NetBSD__
+	fd=open("/dev/audioctl", O_RDWR);
+#else
 	fd=open(obj->dev_name,O_RDWR|O_NONBLOCK);
+#endif
 	if (fd<0) {
 		g_warning("oss_card_probe: can't open %s: %s.",obj->dev_name,strerror(errno));
 		return -1;
@@ -192,6 +223,25 @@
      	else p=p/2;
      }
 	}
+#ifdef __NetBSD__
+	{
+	int duplex = 1;
+	audio_info_t ainfo;
+
+		/* set device to full duplex */
+		if(ioctl(fd, AUDIO_SETFD, &duplex) < 0) {
+			g_warning("oss_open: can't set to full duplex:%s.",strerror(errno));
+		}
+		/* set mode to play all data even if late */
+		/* set blocksize for 32ms of audio */
+		AUDIO_INITINFO(&ainfo);
+		ainfo.mode = AUMODE_PLAY_ALL | AUMODE_RECORD;
+		ainfo.blocksize = rate * bits / 250;
+		if (ioctl(fd, AUDIO_SETINFO, &ainfo) == -1) {
+			perror( "ioctl, audio setting mode" );
+		}
+	}
+#endif
 	ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &min_size);
 	if (min_size>blocksize)
 	{
@@ -201,7 +251,8 @@
 		min_size=blocksize;
 	}
 	close(fd);
-	return min_size;
+	/*return min_size; is this a bug? should be ms not bytes. cliff */
+	return 0;/* cliff */
 }
 
 
@@ -430,7 +481,11 @@
 	return base;
 }
 
+#ifdef __NetBSD__
+#define DSP_NAME "/dev/sound"
+#else
 #define DSP_NAME "/dev/dsp"
+#endif
 #define MIXER_NAME "/dev/mixer"
 
 gint oss_card_manager_init(SndCardManager *manager, gint tabindex)
@@ -448,7 +503,11 @@
 		manager->cards[0]=oss_card_new(DSP_NAME,MIXER_NAME);
 		manager->cards[0]->index=0;
 		found++;
+#ifdef __NetBSD__
+		g_message("Found /dev/sound.");
+#else
 		g_message("Found /dev/dsp.");
+#endif
 	}
 	for (;tabindex<MAX_SND_CARDS && devindex<MAX_SND_CARDS ;devindex++){
 		devname=g_strdup_printf("%s%i",DSP_NAME,devindex);

--Multipart=_Thu__2_Feb_2006_15_23_58_-0800_qjw36n.7MS842QBy--