r2637 - in trunk/libminisip: . include include/libminisip/soundcard
source/soundcard
mikma at minisip.org
mikma at minisip.org
Mon Jun 5 20:37:15 CEST 2006
Author: mikma
Date: 2006-06-05 20:37:13 +0200 (Mon, 05 Jun 2006)
New Revision: 2637
Added:
trunk/libminisip/source/soundcard/FileSoundDevice.h
trunk/libminisip/source/soundcard/FileSoundDriver.cxx
trunk/libminisip/source/soundcard/FileSoundDriver.h
Removed:
trunk/libminisip/include/libminisip/soundcard/FileSoundDevice.h
Modified:
trunk/libminisip/Makefile.am
trunk/libminisip/include/Makefile.am
trunk/libminisip/include/libminisip/soundcard/SoundDriverRegistry.h
trunk/libminisip/source/soundcard/FileSoundDevice.cxx
trunk/libminisip/source/soundcard/SoundDevice.cxx
trunk/libminisip/source/soundcard/SoundDriverRegistry.cxx
Log:
Implement FileSoundDriver and build it as a built-in driver.
Modified: trunk/libminisip/Makefile.am
===================================================================
--- trunk/libminisip/Makefile.am 2006-06-05 18:32:24 UTC (rev 2636)
+++ trunk/libminisip/Makefile.am 2006-06-05 18:37:13 UTC (rev 2637)
@@ -192,7 +192,10 @@
source/soundcard/SoundSource.cxx \
${RESAMPLER_SRC} \
${AUDIOMIXER_SRC} \
+ source/soundcard/FileSoundDevice.h \
source/soundcard/FileSoundDevice.cxx \
+ source/soundcard/FileSoundDriver.h \
+ source/soundcard/FileSoundDriver.cxx \
source/soundcard/FileSoundSource.cxx \
source/soundcard/SoundDevice.cxx \
source/soundcard/SoundDriver.cxx \
Modified: trunk/libminisip/include/Makefile.am
===================================================================
--- trunk/libminisip/include/Makefile.am 2006-06-05 18:32:24 UTC (rev 2636)
+++ trunk/libminisip/include/Makefile.am 2006-06-05 18:37:13 UTC (rev 2637)
@@ -86,7 +86,6 @@
libminisip/soundcard/FileSoundSource.h \
libminisip/soundcard/AudioMixerSpatial.h \
libminisip/soundcard/OssSoundDevice.h \
- libminisip/soundcard/FileSoundDevice.h \
libminisip/soundcard/SoundDevice.h \
libminisip/soundcard/SilenceSensor.h \
libminisip/soundcard/SoundIO.h \
Deleted: trunk/libminisip/include/libminisip/soundcard/FileSoundDevice.h
===================================================================
--- trunk/libminisip/include/libminisip/soundcard/FileSoundDevice.h 2006-06-05 18:32:24 UTC (rev 2636)
+++ trunk/libminisip/include/libminisip/soundcard/FileSoundDevice.h 2006-06-05 18:37:13 UTC (rev 2637)
@@ -1,217 +0,0 @@
-/*
- Copyright (C) 2004-2006 the Minisip Team
-
- 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) 2004
- *
- * Authors: Erik Eliasson <eliasson at it.kth.se>
- * Johan Bilien <jobi at via.ecp.fr>
- * Cesc Santasusana <c e s c DOT s a n t a [AT} g m a i l DOT c o m>
-*/
-
-#ifndef FILESOUNDDEVICE_H
-#define FILESOUNDDEVICE_H
-
-#include<libminisip/libminisip_config.h>
-
-#ifdef _MSC_VER
-# include<io.h>
-# undef open
-# undef close
-# undef read
-# undef write
-#else
-# include<sys/time.h>
-# include<unistd.h>
-#endif
-
-#include<libminisip/soundcard/SoundDevice.h>
-
-#include<stdio.h>
-#include <fcntl.h>
-#include<iostream>
-
-
-#define FILESOUND_TYPE_RAW 0
-#define FILESOUND_TYPE_WAV 1
-#define FILESOUND_TYPE_MP3 2
-
-/**
-SoundDevice which reads from/to files, simulating a synchronous
-access to the soundcard.
-The deviceId needs to be such:
-file:RECORDFILE,PLAYBACKFILE
-where
-- RECORDFILE is a readable file, from where we extract audio samples
- and send them to the callee. If the file was a soundcard,
- this would be the microphone.
- Example: /tmp/minisip.audio.mic
-- PLAYBACKFILE is a writable file, where we dump all the received
- audio.
- Example: /tmp/minisip.audio.dump
-
-When opened from the SoundIO class, it will be opened using the
-same parameters as any other soundcard, this means
- samplingRate = 48000
- numberChannels = 2
- format = 2 bytes per sample, unsigned
-NOTE: i know it needs/generates huge files ... but hey, they are
- in a very good audio quality ;)
-
-TODO: implement other filetypes, not just RAW. Interesting would be
- at least WAV (like RAW but with header) and MP3 (to save space).
-
-NOTE: The output/input of this device for now is RAW. This means that
- to play it or record it you most probably need to first create
- a WAV or MP3 file and then convert it to RAW (use the linux
- tool SOX, for example).
- sox somemp3.mp3 -r 48000 -c 2 -s -w minisip.play.sw
-*/
-class LIBMINISIP_API FileSoundDevice: public SoundDevice{
- public:
- FileSoundDevice(std::string in_file="",
- std::string out_file="",
- int32_t filetype=FILESOUND_TYPE_RAW );
-
- /**
- We need to add a blocking behavior to the reading of the file,
- plus looping.
- Thus, we some specific code, but still call the SoundDevice::read function
- */
- virtual int read( byte_t * buffer, uint32_t nSamples );
-
- /**
- Read from the "record" file, that is, this file is read
- and the audio samples are to be processed (i.e, to send to
- the network).
- */
- virtual int readFromDevice( byte_t * buffer, uint32_t nSamples );
-
- /**
- We need to add a blocking behavior to the writing of the file
- (only if SoundDevice::sleepTime == 0 --> device playback open in blocking mode).
- Thus, we some specific code, but still call the SoundDevice::write function
- */
- virtual int write( byte_t * buffer, uint32_t nSamples );
-
- /**
- Write to the "playback" file, that is, the file where the
- "received" audio is stored for later playback.
- */
- virtual int writeToDevice( byte_t * buffer, uint32_t nSamples );
-
- virtual int readError( int errcode, byte_t * buffer, uint32_t nSamples );
- virtual int writeError( int errcode, byte_t * buffer, uint32_t nSamples );
-
- virtual int openPlayback( int32_t samplingRate, int nChannels, int format=SOUND_S16LE );
- virtual int openRecord( int32_t samplingRate, int nChannels, int format=SOUND_S16LE );
-
- virtual int closePlayback();
- virtual int closeRecord();
-
- /**
- Set/get functions for the looping of the record file (the one played to the
- other peer).
- If set to true, the file is looped for as long as the call is active.
- */
- bool getLoopRecord() { return loopRecord; };
- void setLoopRecord( bool loop ) { loopRecord = loop; };
-
- virtual void sync();
-
- virtual std::string getMemObjectType(){ return "FileSoundDevice";};
-
- protected:
-
- void setAudioParams( int nChannels_, int filetype_ );
-
- /**
- File type of this device. For now, we can only open the same type
- for reading and writing ...
- //FIXME the above ...
- */
- int fileType;
-
- /**
- Filenames
- - inFile is the "record" file, to read from
- - outFile is the "playback" file, to write to
- */
- std::string inFilename;
- std::string outFilename;
-
- /**
- File descriptors
- */
- int in_fd;
- int out_fd;
-
- /**
- During a single execution of minisip, the sound device is started
- and stopped several times.
- If it is the first time we open for playback (dump audio to a file),
- we create the file with filesize = 0. If it is not the first time
- we open the sound device in the current run of minisip, we do not
- create it, we open it in APPEND mode.
- */
- bool isFirstTimeOpenWrite;
-
- /**
- Whether to loop or not the record file, that is, if the other peer
- will receive the same message over and over.
- */
- bool loopRecord;
-
- /**
- Print the "errno" variables ... for debug
- */
- void printError( std::string func );
-
-
- /**
- Do not reuse the sleepTime variable in SoundDevice ... for now
- (as long as the audio playback is still blocking).
- */
- uint32_t fileSoundBlockSleep;
-
- /**
- Implements a sleep function, used to synchronize the writing of
- audio samples. It sleeps for sleepTime miliseconds.
- */
- void writeSleep( );
-
- /**
- State variable, used in writeSleep()
- */
- uint64_t lastTimeWrite;
-
- /**
- Implements a sleep function, used to synchronize the reading of
- audio samples. It sleeps for sleepTime miliseconds.
- */
- void readSleep( );
-
- /**
- State variable, used in readSleep()
- */
- uint64_t lastTimeRead;
-
- int getFileSize( int fd );
-};
-
-
-#endif
Modified: trunk/libminisip/include/libminisip/soundcard/SoundDriverRegistry.h
===================================================================
--- trunk/libminisip/include/libminisip/soundcard/SoundDriverRegistry.h 2006-06-05 18:32:24 UTC (rev 2636)
+++ trunk/libminisip/include/libminisip/soundcard/SoundDriverRegistry.h 2006-06-05 18:37:13 UTC (rev 2637)
@@ -57,10 +57,12 @@
static MRef<SoundDriverRegistry*> getInstance();
protected:
- void registerBuiltinDrivers();
+ SoundDriverRegistry();
private:
std::vector< MRef<SoundDriver*> > drivers;
+
+ friend class MSingleton<SoundDriverRegistry>;
};
#endif // SOUNDDRIVERREGISTRY_H
Modified: trunk/libminisip/source/soundcard/FileSoundDevice.cxx
===================================================================
--- trunk/libminisip/source/soundcard/FileSoundDevice.cxx 2006-06-05 18:32:24 UTC (rev 2636)
+++ trunk/libminisip/source/soundcard/FileSoundDevice.cxx 2006-06-05 18:37:13 UTC (rev 2637)
@@ -25,7 +25,7 @@
#include<config.h>
-#include<libminisip/soundcard/FileSoundDevice.h>
+#include"FileSoundDevice.h"
#include<sys/types.h>
#include<sys/stat.h>
Copied: trunk/libminisip/source/soundcard/FileSoundDevice.h (from rev 2630, trunk/libminisip/include/libminisip/soundcard/FileSoundDevice.h)
Added: trunk/libminisip/source/soundcard/FileSoundDriver.cxx
===================================================================
--- trunk/libminisip/source/soundcard/FileSoundDriver.cxx 2006-06-05 18:32:24 UTC (rev 2636)
+++ trunk/libminisip/source/soundcard/FileSoundDriver.cxx 2006-06-05 18:37:13 UTC (rev 2637)
@@ -0,0 +1,55 @@
+/*
+ Copyright (C) 2006 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) 2006
+ *
+ * Authors: Mikael Magnusson <mikma at users.sourceforge.net>
+ */
+
+#include<config.h>
+
+#include<libminisip/soundcard/SoundDriver.h>
+#include<libminisip/soundcard/SoundDriverRegistry.h>
+#include<libmutil/MPlugin.h>
+
+#include"FileSoundDriver.h"
+#include"FileSoundDevice.h"
+
+using namespace std;
+
+static const char DRIVER_PREFIX[] = "file";
+
+FileSoundDriver::FileSoundDriver( MRef<Library*> lib ) : SoundDriver( DRIVER_PREFIX, lib ){
+}
+
+FileSoundDriver::~FileSoundDriver( ){
+}
+
+MRef<SoundDevice*> FileSoundDriver::createDevice( string deviceId ){
+ return new FileSoundDevice( deviceId, deviceId, FILESOUND_TYPE_RAW );
+}
+
+std::vector<SoundDeviceName> FileSoundDriver::getDeviceNames() const {
+ std::vector<SoundDeviceName> names;
+
+ return names;
+}
+
+uint32_t FileSoundDriver::getVersion() const{
+ return 0x00000001;
+}
Property changes on: trunk/libminisip/source/soundcard/FileSoundDriver.cxx
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Added: trunk/libminisip/source/soundcard/FileSoundDriver.h
===================================================================
--- trunk/libminisip/source/soundcard/FileSoundDriver.h 2006-06-05 18:32:24 UTC (rev 2636)
+++ trunk/libminisip/source/soundcard/FileSoundDriver.h 2006-06-05 18:37:13 UTC (rev 2637)
@@ -0,0 +1,53 @@
+/*
+ Copyright (C) 2006 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) 2006
+ *
+ * Authors: Mikael Magnusson <mikma at users.sourceforge.net>
+ */
+
+#ifndef FILESOUNDDRIVER_H
+#define FILESOUNDDRIVER_H
+
+#include<libminisip/libminisip_config.h>
+
+#include<string>
+#include<libmutil/MemObject.h>
+
+#include<libminisip/soundcard/SoundDriver.h>
+
+
+class FileSoundDriver: public SoundDriver{
+ public:
+ FileSoundDriver( MRef<Library*> lib );
+ virtual ~FileSoundDriver();
+ virtual MRef<SoundDevice*> createDevice( std::string deviceId );
+ virtual std::string getDescription() const { return "FileSound sound driver"; };
+
+ virtual std::vector<SoundDeviceName> getDeviceNames() const;
+
+ virtual std::string getName() const {
+ return "FileSound";
+ }
+
+ virtual std::string getMemObjectType(){ return getName(); }
+
+ virtual uint32_t getVersion() const;
+};
+
+#endif // FILESOUNDDRIVER_H
Property changes on: trunk/libminisip/source/soundcard/FileSoundDriver.h
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: trunk/libminisip/source/soundcard/SoundDevice.cxx
===================================================================
--- trunk/libminisip/source/soundcard/SoundDevice.cxx 2006-06-05 18:32:24 UTC (rev 2636)
+++ trunk/libminisip/source/soundcard/SoundDevice.cxx 2006-06-05 18:37:13 UTC (rev 2637)
@@ -27,7 +27,6 @@
#include<libminisip/soundcard/SoundDevice.h>
#include<libminisip/soundcard/SoundDriverRegistry.h>
-#include<libminisip/soundcard/FileSoundDevice.h>
#ifndef WIN32
# include<libminisip/soundcard/OssSoundDevice.h>
@@ -54,20 +53,6 @@
return device;
}
- if( devideId.substr( 0, 5 ) == "file:" ){
- size_t comaPos = devideId.find( "," );
- if( comaPos == string::npos ){
- merr << "Invalid file sound device specified in"
- "configuration file."
- "Sound will be disabled." << end;
- return NULL;
- }
- return new FileSoundDevice(
- devideId.substr( 5, comaPos-5 ),
- devideId.substr( comaPos + 1, string::npos ),
- FILESOUND_TYPE_RAW );
- }
-
#ifdef WAVE_SOUND
if( devideId.substr( 0, 5 ) == "wave:" ){
return new WaveSoundDevice( devideId.substr( 5, string::npos ) );
Modified: trunk/libminisip/source/soundcard/SoundDriverRegistry.cxx
===================================================================
--- trunk/libminisip/source/soundcard/SoundDriverRegistry.cxx 2006-06-05 18:32:24 UTC (rev 2636)
+++ trunk/libminisip/source/soundcard/SoundDriverRegistry.cxx 2006-06-05 18:37:13 UTC (rev 2637)
@@ -26,6 +26,7 @@
#include<libminisip/soundcard/SoundDriverRegistry.h>
#include<libmutil/dbg.h>
+#include"FileSoundDriver.h"
// #ifdef PORTAUDIO_SUPPORT
// #include<libminisip/soundcard/PortAudioDriver.h>
@@ -47,6 +48,10 @@
}
#endif
+SoundDriverRegistry::SoundDriverRegistry(){
+ registerPlugin( new FileSoundDriver( NULL ) );
+}
+
const std::vector< MRef<SoundDriver*> > &SoundDriverRegistry::getDrivers() const{
return drivers;
}
More information about the Minisip-devel
mailing list