r3490 - in trunk/libminisip: . include/libminisip/media/soundcard source/subsystem_media/soundcard source/subsystem_signaling/sip

mikma at minisip.org mikma at minisip.org
Sun Nov 18 21:42:34 CET 2007


Author: mikma
Date: 2007-11-18 21:42:34 +0100 (Sun, 18 Nov 2007)
New Revision: 3490

Added:
   trunk/libminisip/source/subsystem_media/soundcard/OssSoundDriver.cxx
   trunk/libminisip/source/subsystem_media/soundcard/OssSoundDriver.h
Modified:
   trunk/libminisip/Makefile.am
   trunk/libminisip/include/libminisip/media/soundcard/SoundDriver.h
   trunk/libminisip/include/libminisip/media/soundcard/SoundDriverRegistry.h
   trunk/libminisip/source/subsystem_media/soundcard/AlsaSoundDriver.cxx
   trunk/libminisip/source/subsystem_media/soundcard/AlsaSoundDriver.h
   trunk/libminisip/source/subsystem_media/soundcard/DirectSoundDriver.cxx
   trunk/libminisip/source/subsystem_media/soundcard/DirectSoundDriver.h
   trunk/libminisip/source/subsystem_media/soundcard/FileSoundDriver.h
   trunk/libminisip/source/subsystem_media/soundcard/PortAudioDriver.cxx
   trunk/libminisip/source/subsystem_media/soundcard/PortAudioDriver.h
   trunk/libminisip/source/subsystem_media/soundcard/SoundDevice.cxx
   trunk/libminisip/source/subsystem_media/soundcard/SoundDriverRegistry.cxx
   trunk/libminisip/source/subsystem_signaling/sip/SipSoftPhoneConfiguration.cxx
Log:
Add support for auto-detecting default sound driver and input/output
devices during first startup of minisip.


Modified: trunk/libminisip/Makefile.am
===================================================================
--- trunk/libminisip/Makefile.am	2007-11-18 19:08:57 UTC (rev 3489)
+++ trunk/libminisip/Makefile.am	2007-11-18 20:42:34 UTC (rev 3490)
@@ -221,7 +221,10 @@
 
 if !OS_WIN
 if ENABLE_OSS
-        libsoundcard_src += source/subsystem_media/soundcard/OssSoundDevice.cxx source/subsystem_media/soundcard/OssSoundDevice.h
+libsoundcard_src += source/subsystem_media/soundcard/OssSoundDevice.cxx \
+		source/subsystem_media/soundcard/OssSoundDevice.h \
+		source/subsystem_media/soundcard/OssSoundDriver.cxx \
+		source/subsystem_media/soundcard/OssSoundDriver.h
 endif ENABLE_OSS
 endif !OS_WIN
 

Modified: trunk/libminisip/include/libminisip/media/soundcard/SoundDriver.h
===================================================================
--- trunk/libminisip/include/libminisip/media/soundcard/SoundDriver.h	2007-11-18 19:08:57 UTC (rev 3489)
+++ trunk/libminisip/include/libminisip/media/soundcard/SoundDriver.h	2007-11-18 20:42:34 UTC (rev 3490)
@@ -82,6 +82,12 @@
 		/** Returns a list of device names supported by the driver */
 		virtual std::vector<SoundDeviceName> getDeviceNames() const = 0;
 
+		/** @return the name of the driver's default input device */
+		virtual bool getDefaultInputDeviceName( SoundDeviceName &name ) const = 0;
+
+		/** @returns the name of the driver's default output device */
+		virtual bool getDefaultOutputDeviceName( SoundDeviceName &name ) const = 0;
+
 		int operator==( const SoundDriver &driver ) const;
 		
 	private:

Modified: trunk/libminisip/include/libminisip/media/soundcard/SoundDriverRegistry.h
===================================================================
--- trunk/libminisip/include/libminisip/media/soundcard/SoundDriverRegistry.h	2007-11-18 19:08:57 UTC (rev 3489)
+++ trunk/libminisip/include/libminisip/media/soundcard/SoundDriverRegistry.h	2007-11-18 20:42:34 UTC (rev 3490)
@@ -41,6 +41,9 @@
 		const std::vector<MRef<SoundDriver*> > &getDrivers() const;
 		std::vector<SoundDeviceName> getAllDeviceNames() const;
 
+		/** @return the default sound driver */
+		virtual MRef<SoundDriver*> getDefaultDriver() const;
+
 		/**
 		 * @param device specifies a sound device and
 		 * should be written in the format "driver:id", where driver

Modified: trunk/libminisip/source/subsystem_media/soundcard/AlsaSoundDriver.cxx
===================================================================
--- trunk/libminisip/source/subsystem_media/soundcard/AlsaSoundDriver.cxx	2007-11-18 19:08:57 UTC (rev 3489)
+++ trunk/libminisip/source/subsystem_media/soundcard/AlsaSoundDriver.cxx	2007-11-18 20:42:34 UTC (rev 3490)
@@ -65,11 +65,23 @@
 std::vector<SoundDeviceName> AlsaSoundDriver::getDeviceNames() const {
 	std::vector<SoundDeviceName> names;
 
-	mdbg << "AlsaSoundDriver::getDeviceNames not implemented" << end;
+	mdbg << "AlsaSoundDriver::getDeviceNames not implemented" << endl;
 
 	return names;
 }
 
+bool AlsaSoundDriver::getDefaultInputDeviceName( SoundDeviceName &name ) const{
+	// TODO set max input/output channels
+	name = SoundDeviceName( "alsa:default", "Default input device" );
+	return true;
+}
+
+bool AlsaSoundDriver::getDefaultOutputDeviceName( SoundDeviceName &name ) const {
+	// TODO set max input/output channels
+	name = SoundDeviceName( "alsa:default", "Default output device" );
+	return true;
+}
+
 uint32_t AlsaSoundDriver::getVersion() const{
 	return 0x00000001;
 }

Modified: trunk/libminisip/source/subsystem_media/soundcard/AlsaSoundDriver.h
===================================================================
--- trunk/libminisip/source/subsystem_media/soundcard/AlsaSoundDriver.h	2007-11-18 19:08:57 UTC (rev 3489)
+++ trunk/libminisip/source/subsystem_media/soundcard/AlsaSoundDriver.h	2007-11-18 20:42:34 UTC (rev 3490)
@@ -41,6 +41,10 @@
 
 		virtual std::vector<SoundDeviceName> getDeviceNames() const;
 
+		virtual bool getDefaultInputDeviceName( SoundDeviceName &name ) const;
+		
+		virtual bool getDefaultOutputDeviceName( SoundDeviceName &name ) const;
+
 		virtual std::string getName() const {
 			return "AlsaSound";
 		}

Modified: trunk/libminisip/source/subsystem_media/soundcard/DirectSoundDriver.cxx
===================================================================
--- trunk/libminisip/source/subsystem_media/soundcard/DirectSoundDriver.cxx	2007-11-18 19:08:57 UTC (rev 3489)
+++ trunk/libminisip/source/subsystem_media/soundcard/DirectSoundDriver.cxx	2007-11-18 20:42:34 UTC (rev 3490)
@@ -114,6 +114,18 @@
 	return names;
 }
 
+bool DirectSoundDriver::getDefaultInputDeviceName( SoundDeviceName &name ) const{
+	mdbg << "DirectSoundDriver::getDefaultInputDeviceName not implemented" << end;
+
+	return false;
+}
+
+bool DirectSoundDriver::getDefaultOutputDeviceName( SoundDeviceName &name ) const {
+	mdbg << "DirectSoundDriver::getDefaultOutputDeviceName not implemented" << end;
+
+	return false;
+}
+
 uint32_t DirectSoundDriver::getVersion() const{
 	return 0x00000001;
 }

Modified: trunk/libminisip/source/subsystem_media/soundcard/DirectSoundDriver.h
===================================================================
--- trunk/libminisip/source/subsystem_media/soundcard/DirectSoundDriver.h	2007-11-18 19:08:57 UTC (rev 3489)
+++ trunk/libminisip/source/subsystem_media/soundcard/DirectSoundDriver.h	2007-11-18 20:42:34 UTC (rev 3490)
@@ -41,6 +41,10 @@
 
 		virtual std::vector<SoundDeviceName> getDeviceNames() const;
 
+		virtual bool getDefaultInputDeviceName( SoundDeviceName &name ) const;
+		
+		virtual bool getDefaultOutputDeviceName( SoundDeviceName &name ) const;
+
 		virtual std::string getName() const {
 			return "DirectSound";
 		}

Modified: trunk/libminisip/source/subsystem_media/soundcard/FileSoundDriver.h
===================================================================
--- trunk/libminisip/source/subsystem_media/soundcard/FileSoundDriver.h	2007-11-18 19:08:57 UTC (rev 3489)
+++ trunk/libminisip/source/subsystem_media/soundcard/FileSoundDriver.h	2007-11-18 20:42:34 UTC (rev 3490)
@@ -41,6 +41,10 @@
 
 		virtual std::vector<SoundDeviceName> getDeviceNames() const;
 
+		virtual bool getDefaultInputDeviceName( SoundDeviceName &name ) const { return false; }
+
+		virtual bool getDefaultOutputDeviceName( SoundDeviceName &name ) const { return false; }
+
 		virtual std::string getName() const {
 			return "FileSound";
 		}

Added: trunk/libminisip/source/subsystem_media/soundcard/OssSoundDriver.cxx
===================================================================
--- trunk/libminisip/source/subsystem_media/soundcard/OssSoundDriver.cxx	                        (rev 0)
+++ trunk/libminisip/source/subsystem_media/soundcard/OssSoundDriver.cxx	2007-11-18 20:42:34 UTC (rev 3490)
@@ -0,0 +1,85 @@
+/*
+ Copyright (C) 2007  Mikael Magnusson
+ 
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+ 
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Lesser General Public License for more details.
+ 
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+*/
+
+/* Copyright (C) 2007
+ *
+ * Authors: Mikael Magnusson <mikma at users.sourceforge.net>
+ */
+
+#include<config.h>
+
+#include<libminisip/media/soundcard/SoundDriver.h>
+#include<libminisip/media/soundcard/SoundDriverRegistry.h>
+#include<libmutil/MPlugin.h>
+
+#include"OssSoundDriver.h"
+#include"OssSoundDevice.h"
+
+using namespace std;
+
+static const char DRIVER_PREFIX[] = "oss";
+static std::list<std::string> pluginList;
+static int initialized;
+
+
+extern "C" LIBMINISIP_API
+std::list<std::string> *moss_LTX_listPlugins( MRef<Library*> lib ){
+	if( !initialized ){
+		pluginList.push_back("getPlugin");
+		initialized = true;
+	}
+
+	return &pluginList;
+}
+
+extern "C" LIBMINISIP_API
+MPlugin * moss_LTX_getPlugin( MRef<Library*> lib ){
+	return new OssSoundDriver( lib );
+}
+
+OssSoundDriver::OssSoundDriver( MRef<Library*> lib ) : SoundDriver( DRIVER_PREFIX, lib ){
+}
+
+OssSoundDriver::~OssSoundDriver( ){
+}
+
+MRef<SoundDevice*> OssSoundDriver::createDevice( string deviceId ){
+	return new OssSoundDevice( deviceId );
+}
+
+std::vector<SoundDeviceName> OssSoundDriver::getDeviceNames() const {
+	std::vector<SoundDeviceName> names;
+
+	mdbg << "OssSoundDriver::getDeviceNames not implemented" << end;
+
+	return names;
+}
+
+bool OssSoundDriver::getDefaultInputDeviceName( SoundDeviceName &name ) const{
+	name = SoundDeviceName( "/dev/dsp", "/dev/dsp" );
+	return true;
+}
+
+bool OssSoundDriver::getDefaultOutputDeviceName( SoundDeviceName &name ) const {
+	name = SoundDeviceName( "/dev/dsp", "/dev/dsp" );
+	return true;
+}
+
+uint32_t OssSoundDriver::getVersion() const{
+	return 0x00000001;
+}


Property changes on: trunk/libminisip/source/subsystem_media/soundcard/OssSoundDriver.cxx
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Added: trunk/libminisip/source/subsystem_media/soundcard/OssSoundDriver.h
===================================================================
--- trunk/libminisip/source/subsystem_media/soundcard/OssSoundDriver.h	                        (rev 0)
+++ trunk/libminisip/source/subsystem_media/soundcard/OssSoundDriver.h	2007-11-18 20:42:34 UTC (rev 3490)
@@ -0,0 +1,57 @@
+/*
+ Copyright (C) 2007  Mikael Magnusson
+ 
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+ 
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Lesser General Public License for more details.
+ 
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+*/
+
+/* Copyright (C) 2007
+ *
+ * Authors: Mikael Magnusson <mikma at users.sourceforge.net>
+ */
+
+#ifndef OSSSOUNDDRIVER_H
+#define OSSSOUNDDRIVER_H
+
+#include<libminisip/libminisip_config.h>
+
+#include<string>
+#include<libmutil/MemObject.h>
+
+#include<libminisip/media/soundcard/SoundDriver.h>
+
+
+class OssSoundDriver: public SoundDriver{
+	public:
+		OssSoundDriver( MRef<Library*> lib );
+		virtual ~OssSoundDriver();
+		virtual MRef<SoundDevice*> createDevice( std::string deviceId );
+		virtual std::string getDescription() const { return "OssSound sound driver"; };
+
+		virtual std::vector<SoundDeviceName> getDeviceNames() const;
+
+		virtual bool getDefaultInputDeviceName( SoundDeviceName &name ) const;
+		
+		virtual bool getDefaultOutputDeviceName( SoundDeviceName &name ) const;
+
+		virtual std::string getName() const {
+			return "OssSound";
+		}
+
+		virtual std::string getMemObjectType() const { return getName(); }
+
+		virtual uint32_t getVersion() const;
+};
+
+#endif	// OSSSOUNDDRIVER_H


Property changes on: trunk/libminisip/source/subsystem_media/soundcard/OssSoundDriver.h
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Modified: trunk/libminisip/source/subsystem_media/soundcard/PortAudioDriver.cxx
===================================================================
--- trunk/libminisip/source/subsystem_media/soundcard/PortAudioDriver.cxx	2007-11-18 19:08:57 UTC (rev 3489)
+++ trunk/libminisip/source/subsystem_media/soundcard/PortAudioDriver.cxx	2007-11-18 20:42:34 UTC (rev 3490)
@@ -84,25 +84,49 @@
 	return new PortAudioDevice( device );
 }
 
+
+static bool getPaDeviceName(PaDeviceIndex i, SoundDeviceName &name) {
+	char device[10] = "";
+
+	const PaDeviceInfo *info = Pa_GetDeviceInfo( i );
+
+	if( !info ){
+		return false;
+	}
+
+	snprintf( device, sizeof( device ), "%s:%d", PA_PREFIX, i );
+	name = SoundDeviceName( device, info->name, info->maxInputChannels, info->maxOutputChannels );
+	return true;
+}
+
 std::vector<SoundDeviceName> PortAudioDriver::getDeviceNames() const {
 	std::vector<SoundDeviceName> names;
 
 	for( int i = 0; i < Pa_GetDeviceCount(); i++ ){
-		char device[10] = "";
+		SoundDeviceName name;
 
-		const PaDeviceInfo *info = Pa_GetDeviceInfo( i );
-
-		if( !info ){
+		if( !getPaDeviceName( i, name ) ){
 			continue;
 		}
 
-		snprintf( device, sizeof( device ), "%s:%d", PA_PREFIX, i );
-		names.push_back( SoundDeviceName( device, info->name, info->maxInputChannels, info->maxOutputChannels ) );
+		names.push_back( name );
 	}
 
 	return names;
 }
 
+bool PortAudioDriver::getDefaultInputDeviceName( SoundDeviceName &name ) const {
+	PaDeviceIndex input = Pa_GetDefaultInputDevice();
+
+	return getPaDeviceName( input, name );
+}
+
+bool PortAudioDriver::getDefaultOutputDeviceName( SoundDeviceName &name ) const {
+	PaDeviceIndex output = Pa_GetDefaultOutputDevice();
+
+	return getPaDeviceName( output, name );
+}
+
 uint32_t PortAudioDriver::getVersion() const{
 	return 0x00000001;
 }

Modified: trunk/libminisip/source/subsystem_media/soundcard/PortAudioDriver.h
===================================================================
--- trunk/libminisip/source/subsystem_media/soundcard/PortAudioDriver.h	2007-11-18 19:08:57 UTC (rev 3489)
+++ trunk/libminisip/source/subsystem_media/soundcard/PortAudioDriver.h	2007-11-18 20:42:34 UTC (rev 3490)
@@ -40,6 +40,10 @@
 
 		virtual std::vector<SoundDeviceName> getDeviceNames() const;
 
+		virtual bool getDefaultInputDeviceName( SoundDeviceName &name ) const;
+
+		virtual bool getDefaultOutputDeviceName( SoundDeviceName &name ) const;
+
 		virtual std::string getName() const {
 			return "PortAudio";
 		}

Modified: trunk/libminisip/source/subsystem_media/soundcard/SoundDevice.cxx
===================================================================
--- trunk/libminisip/source/subsystem_media/soundcard/SoundDevice.cxx	2007-11-18 19:08:57 UTC (rev 3489)
+++ trunk/libminisip/source/subsystem_media/soundcard/SoundDevice.cxx	2007-11-18 20:42:34 UTC (rev 3490)
@@ -28,12 +28,6 @@
 #include<libminisip/media/soundcard/SoundDevice.h>
 #include<libminisip/media/soundcard/SoundDriverRegistry.h>
 
-#ifndef WIN32
-#ifdef ENABLE_OSS
-#	include"OssSoundDevice.h"
-#endif
-#endif
-
 #ifdef WAVE_SOUND
 #	include"WaveSoundDevice.h"
 #endif
@@ -61,17 +55,6 @@
 		return new WaveSoundDevice( devideId.substr( 5, string::npos ) );
 	}
 #endif
-
-#ifndef WIN32
-#ifdef ENABLE_OSS
-#define SOUND_DEVICE_IMPLEMENTED
-	return new OssSoundDevice( devideId );
-#endif
-#else
-	cerr << "WARNING: No sound device is created! (BUG?)"<<endl;
-	return NULL;
-#endif
-
 }
 
 SoundDevice::SoundDevice( string device ):openedRecord(false),openedPlayback(false){

Modified: trunk/libminisip/source/subsystem_media/soundcard/SoundDriverRegistry.cxx
===================================================================
--- trunk/libminisip/source/subsystem_media/soundcard/SoundDriverRegistry.cxx	2007-11-18 19:08:57 UTC (rev 3489)
+++ trunk/libminisip/source/subsystem_media/soundcard/SoundDriverRegistry.cxx	2007-11-18 20:42:34 UTC (rev 3490)
@@ -32,6 +32,10 @@
 #include"DirectSoundDriver.h"
 #endif
 
+#ifdef ENABLE_OSS
+#include"OssSoundDriver.h"
+#endif
+
 #include<algorithm>
 
 using namespace std;
@@ -55,6 +59,9 @@
 #ifdef _MSC_VER
 	registerPlugin( new DirectSoundDriver(NULL) );
 #endif
+#ifdef ENABLE_OSS
+	registerPlugin( new OssSoundDriver( NULL ) );
+#endif
 }
 
 const std::vector< MRef<SoundDriver*> > &SoundDriverRegistry::getDrivers() const{
@@ -78,7 +85,29 @@
 	return allNames;
 }
 
+MRef<SoundDriver*> SoundDriverRegistry::getDefaultDriver() const{
+	const char *driverPriority[] =
+		{ "PortAudio", "DirectSound", "AlsaSound", "OssSound", NULL };
+	int i;
 
+	for( i = 0;; i++ ){
+		const char *name = driverPriority[i];
+
+		if( !name )
+			return NULL;
+
+		MRef<MPlugin*> plugin = findPlugin( name );
+		if( plugin ){
+			MRef<SoundDriver*> driver;
+			driver = dynamic_cast<SoundDriver*>(*plugin);
+			if( driver )
+				return driver;
+		}
+	}
+
+	return NULL;
+}
+
 MRef<SoundDevice*> SoundDriverRegistry::createDevice( std::string deviceName ){
 	string driverId;
 	string deviceId;

Modified: trunk/libminisip/source/subsystem_signaling/sip/SipSoftPhoneConfiguration.cxx
===================================================================
--- trunk/libminisip/source/subsystem_signaling/sip/SipSoftPhoneConfiguration.cxx	2007-11-18 19:08:57 UTC (rev 3489)
+++ trunk/libminisip/source/subsystem_signaling/sip/SipSoftPhoneConfiguration.cxx	2007-11-18 20:42:34 UTC (rev 3490)
@@ -40,6 +40,7 @@
 #include<libminisip/signaling/sip/SipSoftPhoneConfiguration.h>
 
 #include<libminisip/media/soundcard/SoundIO.h>
+#include<libminisip/media/soundcard/SoundDriverRegistry.h>
 #include<libminisip/media/SubsystemMedia.h>
 #include<libminisip/media/codecs/Codec.h>
 #include<libminisip/contacts/PhoneBook.h>
@@ -897,6 +898,43 @@
 
 }
 
+static void getDefaultSoundDevices( string &soundDeviceIn,
+				    string &soundDeviceOut ){
+	MRef<SoundDriver*> defaultDriver =
+		SoundDriverRegistry::getInstance()->getDefaultDriver();
+
+	if( defaultDriver ){
+		SoundDeviceName inputName;
+		SoundDeviceName outputName;
+
+		if( defaultDriver->getDefaultInputDeviceName( inputName ) ){
+			soundDeviceIn = inputName.getName();
+		}
+
+		if( defaultDriver->getDefaultOutputDeviceName( outputName ) ){
+			soundDeviceOut = outputName.getName();
+		}
+	}
+
+	if( soundDeviceIn.empty() ){
+		mdbg("signaling/sip") << "SipSoftPhoneConfiguration: Using fallback sound input driver" << endl;
+#ifdef WIN32
+		soundDeviceIn = "dsound:0";
+#else
+		soundDeviceIn = "/dev/dsp";
+#endif
+	}
+
+	if( soundDeviceOut.empty() ){
+		mdbg("signaling/sip") << "SipSoftPhoneConfiguration: Using fallback sound output driver" << endl;
+#ifdef WIN32
+		soundDeviceOut = "dsound:0";
+#else
+		soundDeviceOut = "/dev/dsp";
+#endif
+	}
+}
+
 void SipSoftPhoneConfiguration::saveDefault( MRef<ConfBackend *> be ){
 	//be->save( "version", CONFIG_FILE_VERSION_REQUIRED_STR );
 	be->save( "version", CONFIG_FILE_VERSION_REQUIRED );
@@ -933,12 +971,15 @@
 	be->save( "local_tcp_port", 5060 );
 	be->save( "local_tls_port", 5061 );
 
-#ifdef WIN32
-	be->save( "sound_device", "dsound:0" );
-#else
-	be->save( "sound_device", "/dev/dsp" );
-#endif
+	string soundDeviceIn;
+	string soundDeviceOut;
 
+	getDefaultSoundDevices( soundDeviceIn, soundDeviceOut );
+
+	be->save( "sound_device", soundDeviceIn );
+	be->save( "sound_device_in", soundDeviceIn );
+	be->save( "sound_device_out", soundDeviceOut );
+
 	be->save( "mixer_type", "spatial" );
 
 #if defined HAS_SPEEX && defined HAS_GSM



More information about the Minisip-devel mailing list