added Solaris support

This commit is contained in:
darkeye 2001-09-11 15:05:21 +00:00
parent 08bd0b4272
commit 61b08937c1
11 changed files with 1239 additions and 38 deletions

View File

@ -9,9 +9,10 @@ AC_PROG_INSTALL
dnl AC_STDC_HEADERS dnl AC_STDC_HEADERS
AC_HAVE_HEADERS(errno.h fcntl.h stdio.h stdlib.h string.h unistd.h limits.h) AC_HAVE_HEADERS(errno.h fcntl.h stdio.h stdlib.h string.h unistd.h limits.h)
AC_HAVE_HEADERS(getopt.h signal.h time.h sys/time.h sys/types.h sys/soundcard.h) AC_HAVE_HEADERS(signal.h time.h sys/time.h sys/types.h)
AC_HAVE_HEADERS(netdb.h netinet/in.h sys/ioctl.h sys/socket.h sys/stat.h) AC_HAVE_HEADERS(netdb.h netinet/in.h sys/ioctl.h sys/socket.h sys/stat.h)
AC_HAVE_HEADERS(sched.h) AC_HAVE_HEADERS(sched.h)
AC_HAVE_HEADERS(sys/soundcard.h sys/audio.h)
AC_HEADER_SYS_WAIT() AC_HEADER_SYS_WAIT()
AC_TYPE_PID_T() AC_TYPE_PID_T()
@ -20,7 +21,6 @@ AC_TYPE_SIZE_T()
AC_SUBST(LAME_INCFLAGS) AC_SUBST(LAME_INCFLAGS)
AC_SUBST(LAME_LDFLAGS) AC_SUBST(LAME_LDFLAGS)
AC_SUBST(LINK_STATIC) AC_SUBST(LINK_STATIC)
AC_SUBST(VERSION)
dnl checkin for lame library dnl checkin for lame library
AC_MSG_CHECKING(lame library) AC_MSG_CHECKING(lame library)
@ -36,7 +36,7 @@ AC_ARG_WITH(lame-prefix,
AC_DEFINE(HAVE_LAME_LIB, 1, build with lame library calls) AC_DEFINE(HAVE_LAME_LIB, 1, build with lame library calls)
if test "x${LAME_INC_LOC}" != "x/usr/include" ; then if test "x${LAME_INC_LOC}" != "x/usr/include" ; then
LAME_INCFLAGS="-I${LAME_INC_LOC}" LAME_INCFLAGS="-I${LAME_INC_LOC}"
LAME_LDFLAGS="-Wl,--rpath -Wl,${LAME_LIB_LOC} -lmp3lame" LAME_LDFLAGS="-L${LAME_LIB_LOC} -lmp3lame"
else else
LAME_LDFLAGS="-lmp3lame" LAME_LDFLAGS="-lmp3lame"
fi fi
@ -49,12 +49,12 @@ AC_ARG_WITH(lame-prefix,
AC_ARG_ENABLE( static, AC_ARG_ENABLE( static,
[ --enable-static link everything into the executable statically [no]], [ --enable-static link everything into the executable statically [no]],
CONFIG_LINK_STATIC="${enableval}", CONFIG_LINK_STATIC="") CONFIG_LINK_STATIC="${enableval}", CONFIG_LINK_STATIC="")
if test "${CONFIG_LINK_STATIC}" == "yes" ; then if test "${CONFIG_LINK_STATIC}" != "yes" ; then
LINK_STATIC="--static"
AC_MSG_RESULT( "creating statically linked executable")
else
LINK_STATIC="" LINK_STATIC=""
AC_MSG_RESULT( "creating dinamically linked executable") AC_MSG_RESULT( "creating dinamically linked executable")
else
LINK_STATIC="--static"
AC_MSG_RESULT( "creating statically linked executable")
fi fi

View File

@ -137,16 +137,6 @@ class AudioSource : public Source
init ( as.sampleRate, as.bitsPerSample, as.channel); init ( as.sampleRate, as.bitsPerSample, as.channel);
} }
/**
* Destructor.
*
* @exception Exception
*/
virtual inline
~AudioSource ( void ) throw ( Exception )
{
}
/** /**
* Assignment operator. * Assignment operator.
* *
@ -169,6 +159,16 @@ class AudioSource : public Source
public: public:
/**
* Destructor.
*
* @exception Exception
*/
virtual inline
~AudioSource ( void ) throw ( Exception )
{
}
/** /**
* Get the number of channels for this AudioSource. * Get the number of channels for this AudioSource.
* *
@ -207,6 +207,30 @@ class AudioSource : public Source
/* ================================================= external data structures */ /* ================================================= external data structures */
/*------------------------------------------------------------------------------
* Determine the kind of audio device based on the system
*----------------------------------------------------------------------------*/
#if defined( HAVE_SYS_SOUNDCARD_H )
// we have an OSS DSP sound source device available
#define SUPPORT_OSS_DSP
#include "OssDspSource.h"
typedef class OssDspSource DspSource;
#elif defined( HAVE_SYS_AUDIO_H )
// we have a Solaris DSP sound device available
#define SUPPORT_SOLARIS_DSP
#include "SolarisDspSource.h"
typedef class SolarisDspSource DspSource;
#else
// there was no DSP audio system found
#error No DSP audio input device found on system
#endif
/* ====================================================== function prototypes */ /* ====================================================== function prototypes */
@ -220,6 +244,9 @@ class AudioSource : public Source
$Source$ $Source$
$Log$ $Log$
Revision 1.4 2001/09/11 15:05:21 darkeye
added Solaris support
Revision 1.3 2000/11/12 13:31:40 darkeye Revision 1.3 2000/11/12 13:31:40 darkeye
added kdoc-style documentation comments added kdoc-style documentation comments

View File

@ -142,10 +142,10 @@ DarkIce :: init ( const Config & config ) throw ( Exception )
channel = Util::strToL( str); channel = Util::strToL( str);
device = cs->getForSure( "device", " missing in section [input]"); device = cs->getForSure( "device", " missing in section [input]");
dsp = new OssDspSource( device, dsp = new DspSource( device,
sampleRate, sampleRate,
bitsPerSample, bitsPerSample,
channel ); channel );
encConnector = new Connector( dsp.get()); encConnector = new Connector( dsp.get());
configIceCast( config, bufferSecs); configIceCast( config, bufferSecs);
@ -477,6 +477,9 @@ DarkIce :: run ( void ) throw ( Exception )
$Source$ $Source$
$Log$ $Log$
Revision 1.18 2001/09/11 15:05:21 darkeye
added Solaris support
Revision 1.17 2001/09/09 11:27:31 darkeye Revision 1.17 2001/09/09 11:27:31 darkeye
added support for ShoutCast servers added support for ShoutCast servers

View File

@ -52,7 +52,7 @@
#include "Reporter.h" #include "Reporter.h"
#include "Exception.h" #include "Exception.h"
#include "Ref.h" #include "Ref.h"
#include "OssDspSource.h" #include "AudioSource.h"
#include "BufferedSink.h" #include "BufferedSink.h"
#include "Connector.h" #include "Connector.h"
#include "LameLibEncoder.h" #include "LameLibEncoder.h"
@ -111,7 +111,7 @@ class DarkIce : public virtual Referable, public virtual Reporter
/** /**
* The dsp to record from. * The dsp to record from.
*/ */
Ref<OssDspSource> dsp; Ref<AudioSource> dsp;
/** /**
* The encoding Connector, connecting the dsp to the encoders. * The encoding Connector, connecting the dsp to the encoders.
@ -281,6 +281,9 @@ class DarkIce : public virtual Referable, public virtual Reporter
$Source$ $Source$
$Log$ $Log$
Revision 1.11 2001/09/11 15:05:21 darkeye
added Solaris support
Revision 1.10 2001/09/09 11:27:31 darkeye Revision 1.10 2001/09/09 11:27:31 darkeye
added support for ShoutCast servers added support for ShoutCast servers

View File

@ -0,0 +1,334 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : FileSink.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#else
#error need unistd.h
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#else
#error need stdlib.h
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#else
#error need sys/types.h
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#else
#error need errno.h
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#else
#error need sys/stat.h
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#else
#error need fcntl.h
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#error need sys/time.h
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#error need string.h
#endif
#include "Util.h"
#include "Exception.h"
#include "FileSink.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Initialize the object
*----------------------------------------------------------------------------*/
void
FileSink :: init ( const char * name ) throw ( Exception )
{
fileName = Util::strDup( name);
fileDescriptor = 0;
}
/*------------------------------------------------------------------------------
* De-initialize the object
*----------------------------------------------------------------------------*/
void
FileSink :: strip ( void) throw ( Exception )
{
if ( isOpen() ) {
close();
}
delete[] fileName;
}
/*------------------------------------------------------------------------------
* Copy Constructor
*----------------------------------------------------------------------------*/
FileSink :: FileSink ( const FileSink & fs ) throw ( Exception )
: Sink( fs )
{
int fd;
init( fs.fileName);
if ( (fd = fs.fileDescriptor ? dup( fs.fileDescriptor) : 0) == -1 ) {
strip();
throw Exception( __FILE__, __LINE__, "dup failure");
}
fileDescriptor = fd;
}
/*------------------------------------------------------------------------------
* Assignment operator
*----------------------------------------------------------------------------*/
FileSink &
FileSink :: operator= ( const FileSink & fs ) throw ( Exception )
{
if ( this != &fs ) {
int fd;
/* first strip */
strip();
/* then build up */
Sink::operator=( fs );
init( fs.fileName);
if ( (fd = fs.fileDescriptor ? dup( fs.fileDescriptor) : 0) == -1 ) {
strip();
throw Exception( __FILE__, __LINE__, "dup failure");
}
fileDescriptor = fd;
}
return *this;
}
/*------------------------------------------------------------------------------
* Check wether a file exists
*----------------------------------------------------------------------------*/
bool
FileSink :: exists ( void ) const throw ()
{
struct stat st;
if ( stat( (const char*)fileName, &st) == -1 ) {
return false;
}
return true;
}
/*------------------------------------------------------------------------------
* Create a file, truncate if already exists
*----------------------------------------------------------------------------*/
bool
FileSink :: create ( void ) throw ( Exception )
{
int fd;
if ( isOpen() ) {
return false;
}
if ( (fd = ::creat( fileName, S_IRUSR | S_IWUSR)) == -1 ) {
throw Exception( __FILE__, __LINE__, "creat error", errno);
}
::close( fd);
return true;
}
/*------------------------------------------------------------------------------
* Open the file
*----------------------------------------------------------------------------*/
bool
FileSink :: open ( void ) throw ( Exception )
{
if ( isOpen() ) {
return false;
}
if ( (fileDescriptor = ::open( fileName, O_WRONLY | O_TRUNC, 0)) == -1 ) {
fileDescriptor = 0;
return false;
}
return true;
}
/*------------------------------------------------------------------------------
* Check wether read() would return anything
*----------------------------------------------------------------------------*/
bool
FileSink :: canWrite ( unsigned int sec,
unsigned int usec ) throw ( Exception )
{
fd_set fdset;
struct timeval tv;
int ret;
if ( !isOpen() ) {
return false;
}
FD_ZERO( &fdset);
FD_SET( fileDescriptor, &fdset);
tv.tv_sec = sec;
tv.tv_usec = usec;
ret = select( fileDescriptor + 1, NULL, &fdset, NULL, &tv);
if ( ret == -1 ) {
throw Exception( __FILE__, __LINE__, "select error");
}
return ret > 0;
}
/*------------------------------------------------------------------------------
* Read from the audio source
*----------------------------------------------------------------------------*/
unsigned int
FileSink :: write ( const void * buf,
unsigned int len ) throw ( Exception )
{
ssize_t ret;
if ( !isOpen() ) {
return 0;
}
ret = ::write( fileDescriptor, buf, len);
if ( ret == -1 ) {
if ( errno == EAGAIN ) {
ret = 0;
} else {
throw Exception( __FILE__, __LINE__, "write error", errno);
}
}
return ret;
}
/*------------------------------------------------------------------------------
* Close the audio source
*----------------------------------------------------------------------------*/
void
FileSink :: close ( void ) throw ( Exception )
{
if ( !isOpen() ) {
return;
}
flush();
::close( fileDescriptor);
fileDescriptor = 0;
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.5 2001/09/11 15:05:21 darkeye
added Solaris support
Revision 1.4 2001/08/26 20:44:30 darkeye
removed external command-line encoder support
replaced it with a shared-object support for lame with the possibility
of static linkage
Revision 1.3 2000/11/11 12:33:13 darkeye
added kdoc-style documentation
Revision 1.2 2000/11/05 14:08:27 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:51 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,284 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : FileSource.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#else
#error need unistd.h
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#else
#error need sys/types.h
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#else
#error need sys/stat.h
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#else
#error need fcntl.h
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#error need sys/time.h
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#error need string.h
#endif
#include "Exception.h"
#include "Util.h"
#include "FileSource.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Initialize the object
*----------------------------------------------------------------------------*/
void
FileSource :: init ( const char * name ) throw ( Exception )
{
fileName = Util::strDup( name);
fileDescriptor = 0;
}
/*------------------------------------------------------------------------------
* De-initialize the object
*----------------------------------------------------------------------------*/
void
FileSource :: strip ( void ) throw ( Exception )
{
if ( isOpen() ) {
close();
}
delete[] fileName;
fileDescriptor = 0;
}
/*------------------------------------------------------------------------------
* Copy Constructor
*----------------------------------------------------------------------------*/
FileSource :: FileSource ( const FileSource & fs ) throw ( Exception )
{
init( fs.fileName);
fileDescriptor = fs.fileDescriptor ? dup( fs.fileDescriptor) : 0;
if ( fileDescriptor == -1 ) {
strip();
throw Exception( __FILE__, __LINE__, "dup failure");
}
}
/*------------------------------------------------------------------------------
* Assignment operator
*----------------------------------------------------------------------------*/
FileSource &
FileSource :: operator= ( const FileSource & fs ) throw ( Exception )
{
if ( this != &fs ) {
init( fs.fileName);
fileDescriptor = fs.fileDescriptor ? dup( fs.fileDescriptor) : 0;
if ( fileDescriptor == -1 ) {
strip();
throw Exception( __FILE__, __LINE__, "dup failure");
}
}
return *this;
}
/*------------------------------------------------------------------------------
* Check wether a file exists
*----------------------------------------------------------------------------*/
bool
FileSource :: exists ( void ) const throw ()
{
struct stat st;
if ( stat( (const char*)fileName, &st) == -1 ) {
return false;
}
return true;
}
/*------------------------------------------------------------------------------
* Open the source
*----------------------------------------------------------------------------*/
bool
FileSource :: open ( void ) throw ( Exception )
{
if ( isOpen() ) {
return false;
}
if ( (fileDescriptor = ::open( fileName, O_RDONLY)) == -1 ) {
fileDescriptor = 0;
return false;
}
return true;
}
/*------------------------------------------------------------------------------
* Check wether read() would return anything
*----------------------------------------------------------------------------*/
bool
FileSource :: canRead ( unsigned int sec,
unsigned int usec ) throw ( Exception )
{
fd_set fdset;
struct timeval tv;
int ret;
if ( !isOpen() ) {
return false;
}
FD_ZERO( &fdset);
FD_SET( fileDescriptor, &fdset);
tv.tv_sec = sec;
tv.tv_usec = usec;
ret = select( fileDescriptor + 1, &fdset, NULL, NULL, &tv);
if ( ret == -1 ) {
throw Exception( __FILE__, __LINE__, "select error");
}
return ret > 0;
}
/*------------------------------------------------------------------------------
* Read from the audio source
*----------------------------------------------------------------------------*/
unsigned int
FileSource :: read ( void * buf,
unsigned int len ) throw ( Exception )
{
ssize_t ret;
if ( !isOpen() ) {
return 0;
}
ret = ::read( fileDescriptor, buf, len);
if ( ret == -1 ) {
throw Exception( __FILE__, __LINE__, "read error");
}
return ret;
}
/*------------------------------------------------------------------------------
* Close the audio source
*----------------------------------------------------------------------------*/
void
FileSource :: close ( void ) throw ( Exception )
{
if ( !isOpen() ) {
return;
}
::close( fileDescriptor);
fileDescriptor = 0;
}
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.5 2001/09/11 15:05:21 darkeye
added Solaris support
Revision 1.4 2001/08/26 20:44:30 darkeye
removed external command-line encoder support
replaced it with a shared-object support for lame with the possibility
of static linkage
Revision 1.3 2000/11/12 13:31:40 darkeye
added kdoc-style documentation comments
Revision 1.2 2000/11/05 14:08:27 darkeye
changed builting to an automake / autoconf environment
Revision 1.1.1.1 2000/11/05 10:05:51 darkeye
initial version
------------------------------------------------------------------------------*/

View File

@ -1,7 +1,7 @@
bin_PROGRAMS = darkice bin_PROGRAMS = darkice
INCLUDES = @LAME_INCFLAGS@ INCLUDES = @LAME_INCFLAGS@
CXXFLAGS = -O2 -Wall -DVERSION="@VERSION@" CXXFLAGS = -O2 -Wall -DVERSION="@VERSION@"
LDADD = @LAME_LDFLAGS@ @LINK_STATIC@ LDADD = -lrt -lsocket -lnsl @LAME_LDFLAGS@ @LINK_STATIC@
darkice_SOURCES = AudioEncoder.h\ darkice_SOURCES = AudioEncoder.h\
AudioSource.h\ AudioSource.h\
@ -23,6 +23,8 @@ darkice_SOURCES = AudioEncoder.h\
LameLibEncoder.h\ LameLibEncoder.h\
OssDspSource.cpp\ OssDspSource.cpp\
OssDspSource.h\ OssDspSource.h\
SolarisDspSource.cpp\
SolarisDspSource.h\
Ref.h\ Ref.h\
Referable.h\ Referable.h\
Sink.h\ Sink.h\

View File

@ -29,6 +29,11 @@
/* ============================================================ include files */ /* ============================================================ include files */
#include "OssDspSource.h"
#ifdef SUPPORT_OSS_DSP
// only compile this code if there is support for it
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -265,12 +270,17 @@ OssDspSource :: close ( void ) throw ( Exception )
running = false; running = false;
} }
#endif // SUPPORT_OSS_DSP
/*------------------------------------------------------------------------------ /*------------------------------------------------------------------------------
$Source$ $Source$
$Log$ $Log$
Revision 1.9 2001/09/11 15:05:21 darkeye
added Solaris support
Revision 1.8 2001/09/02 14:08:40 darkeye Revision 1.8 2001/09/02 14:08:40 darkeye
setting the sound card recording sample rate is now more relaxed setting the sound card recording sample rate is now more relaxed
there is no error reported if the sample rate is not exactly the same there is no error reported if the sample rate is not exactly the same

View File

@ -0,0 +1,282 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : SolarisDspSource.cpp
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#include "SolarisDspSource.h"
#ifdef SUPPORT_SOLARIS_DSP
// only compile this code if there is support for it
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#else
#error need unistd.h
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#error need string.h
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#else
#error need sys/types.h
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#else
#error need sys/stat.h
#endif
#ifdef HAVE_FCNTL_H
#include <fcntl.h>
#else
#error need fcntl.h
#endif
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#error need sys/time.h
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#else
#error need sys/ioctl.h
#endif
#ifdef HAVE_SYS_AUDIO_H
#include <sys/audio.h>
#else
#error need sys/audio.h
#endif
#include "Util.h"
#include "Exception.h"
#include "SolarisDspSource.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* File identity
*----------------------------------------------------------------------------*/
static const char fileid[] = "$Id$";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Initialize the object
*----------------------------------------------------------------------------*/
void
SolarisDspSource :: init ( const char * name ) throw ( Exception )
{
fileName = Util::strDup( name);
fileDescriptor = 0;
running = false;
}
/*------------------------------------------------------------------------------
* De-initialize the object
*----------------------------------------------------------------------------*/
void
SolarisDspSource :: strip ( void ) throw ( Exception )
{
if ( isOpen() ) {
close();
}
delete[] fileName;
}
#include <errno.h>
/*------------------------------------------------------------------------------
* Open the audio source
*----------------------------------------------------------------------------*/
bool
SolarisDspSource :: open ( void ) throw ( Exception )
{
audio_info_t audioInfo;
if ( isOpen() ) {
return false;
}
if ( (fileDescriptor = ::open( fileName, O_RDONLY)) == -1 ) {
fileDescriptor = 0;
return false;
}
AUDIO_INITINFO( &audioInfo);
audioInfo.record.sample_rate = getSampleRate();
audioInfo.record.channels = getChannel();
audioInfo.record.precision = getBitsPerSample();
audioInfo.record.encoding = AUDIO_ENCODING_LINEAR;
if ( ioctl( fileDescriptor, AUDIO_SETINFO, &audioInfo) == -1 ) {
close();
throw Exception( __FILE__, __LINE__, "ioctl error");
}
if ( audioInfo.record.channels != getChannel() ) {
close();
throw Exception( __FILE__, __LINE__,
"can't set channels", audioInfo.record.channels);
}
if ( audioInfo.record.precision != getBitsPerSample() ) {
close();
throw Exception( __FILE__, __LINE__,
"can't set bits per sample",
audioInfo.record.precision);
}
if ( audioInfo.record.sample_rate != getSampleRate() ) {
reportEvent( 2, "sound card recording sample rate set to ",
audioInfo.record.sample_rate,
" while trying to set it to ", getSampleRate());
reportEvent( 2, "this is probably not a problem, but a slight "
"drift in the sound card driver");
}
return true;
}
/*------------------------------------------------------------------------------
* Check wether read() would return anything
*----------------------------------------------------------------------------*/
bool
SolarisDspSource :: canRead ( unsigned int sec,
unsigned int usec ) throw ( Exception )
{
fd_set fdset;
struct timeval tv;
int ret;
if ( !isOpen() ) {
return false;
}
if ( !running ) {
/* ugly workaround to get the dsp into recording state */
unsigned char b[getChannel()*getBitsPerSample()/8];
read( b, getChannel()*getBitsPerSample()/8);
}
FD_ZERO( &fdset);
FD_SET( fileDescriptor, &fdset);
tv.tv_sec = sec;
tv.tv_usec = usec;
ret = select( fileDescriptor + 1, &fdset, NULL, NULL, &tv);
if ( ret == -1 ) {
throw Exception( __FILE__, __LINE__, "select error");
}
return ret > 0;
}
/*------------------------------------------------------------------------------
* Read from the audio source
*----------------------------------------------------------------------------*/
unsigned int
SolarisDspSource :: read ( void * buf,
unsigned int len ) throw ( Exception )
{
ssize_t ret;
if ( !isOpen() ) {
return 0;
}
ret = ::read( fileDescriptor, buf, len);
if ( ret == -1 ) {
throw Exception( __FILE__, __LINE__, "read error");
}
running = true;
return ret;
}
/*------------------------------------------------------------------------------
* Close the audio source
*----------------------------------------------------------------------------*/
void
SolarisDspSource :: close ( void ) throw ( Exception )
{
if ( !isOpen() ) {
return;
}
::close( fileDescriptor);
fileDescriptor = 0;
running = false;
}
#endif // SUPPORT_SOLARIS_DSP
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.1 2001/09/11 15:05:21 darkeye
added Solaris support
------------------------------------------------------------------------------*/

View File

@ -0,0 +1,260 @@
/*------------------------------------------------------------------------------
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
Tyrell DarkIce
File : SolarisDspSource.h
Version : $Revision$
Author : $Author$
Location : $Source$
Copyright notice:
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
------------------------------------------------------------------------------*/
#ifndef SOLARIS_DSP_SOURCE_H
#define SOLARIS_DSP_SOURCE_H
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#include "Reporter.h"
#include "AudioSource.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An audio input based on Solaris /dev/audio devices
*
* @author $Author$
* @version $Revision$
*/
class SolarisDspSource : public AudioSource, public virtual Reporter
{
private:
/**
* The file name of the OSS DSP device (e.g. /dev/audio)
*/
char * fileName;
/**
* The low-level file descriptor of the Solaris DSP device.
*/
int fileDescriptor;
/**
* Indicates wether the low-level Solaris DSP device is in a recording
* state.
*/
bool running;
protected:
/**
* Default constructor. Always throws an Exception.
*
* @exception Exception
*/
inline
SolarisDspSource ( void ) throw ( Exception )
{
throw Exception( __FILE__, __LINE__);
}
/**
* Initialize the object
*
* @param name the file name of the Solaris DSP device.
* @exception Exception
*/
void
init ( const char * name ) throw ( Exception );
/**
* De-iitialize the object
*
* @exception Exception
*/
void
strip ( void ) throw ( Exception );
public:
/**
* Constructor.
*
* @param name the file name of the Solaris DSP device
* (e.g. /dev/audio or /dev/sound/0)
* @param sampleRate samples per second (e.g. 44100 for 44.1kHz).
* @param bitsPerSample bits per sample (e.g. 16 bits).
* @param channel number of channels of the audio source
* (e.g. 1 for mono, 2 for stereo, etc.).
* @exception Exception
*/
inline
SolarisDspSource ( const char * name,
int sampleRate = 44100,
int bitsPerSample = 16,
int channel = 2 )
throw ( Exception )
: AudioSource( sampleRate, bitsPerSample, channel)
{
init( name);
}
/**
* Copy Constructor.
*
* @param source the object to copy.
* @exception Exception
*/
inline
SolarisDspSource ( const SolarisDspSource & ds )
throw ( Exception )
: AudioSource( ds )
{
init( ds.fileName);
}
/**
* Destructor.
*
* @exception Exception
*/
inline virtual
~SolarisDspSource ( void ) throw ( Exception )
{
strip();
}
/**
* Assignment operator.
*
* @param ds the object to assign to this one.
* @return a reference to this object.
* @exception Exception
*/
inline virtual SolarisDspSource &
operator= ( const SolarisDspSource & ds ) throw ( Exception )
{
if ( this != &ds ) {
strip();
AudioSource::operator=( ds);
init( ds.fileName);
}
return *this;
}
/**
* Open the SolarisDspSource.
* This does not put the Solaris DSP device into recording mode.
* To start getting samples, call either canRead() or read().
*
* @return true if opening was successful, false otherwise
* @exception Exception
*
* @see #canRead
* @see #read
*/
virtual bool
open ( void ) throw ( Exception );
/**
* Check if the SolarisDspSource is open.
*
* @return true if the SolarisDspSource is open, false otherwise.
*/
inline virtual bool
isOpen ( void ) const throw ()
{
return fileDescriptor != 0;
}
/**
* Check if the SolarisDspSource can be read from.
* Blocks until the specified time for data to be available.
* Puts the Solaris DSP device into recording mode.
*
* @param sec the maximum seconds to block.
* @param usec micro seconds to block after the full seconds.
* @return true if the SolarisDspSource is ready to be read from,
* false otherwise.
* @exception Exception
*/
virtual bool
canRead ( unsigned int sec,
unsigned int usec ) throw ( Exception );
/**
* Read from the SolarisDspSource.
* Puts the Solaris DSP device into recording mode.
*
* @param buf the buffer to read into.
* @param len the number of bytes to read into buf
* @return the number of bytes read (may be less than len).
* @exception Exception
*/
virtual unsigned int
read ( void * buf,
unsigned int len ) throw ( Exception );
/**
* Close the SolarisDspSource.
*
* @exception Exception
*/
virtual void
close ( void ) throw ( Exception );
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
#endif /* SOLARIS_DSP_SOURCE_H */
/*------------------------------------------------------------------------------
$Source$
$Log$
Revision 1.1 2001/09/11 15:05:21 darkeye
added Solaris support
------------------------------------------------------------------------------*/

View File

@ -37,10 +37,10 @@
#include "config.h" #include "config.h"
#endif #endif
#ifdef HAVE_GETOPT_H #ifdef HAVE_STDLIB_H
#include <getopt.h> #include <stdlib.h>
#else #else
#error need getopt.h #error needs stdlib.h
#endif #endif
#include <iostream.h> #include <iostream.h>
@ -94,15 +94,8 @@ main (
unsigned int verbosity = 1; unsigned int verbosity = 1;
int i; int i;
const char opts[] = "hc:v:"; const char opts[] = "hc:v:";
static struct option long_options[] = {
{ "config", 1, 0, 'c'},
{ "help", 0, 0, 'h'},
{ "verbosity", 1, 0, 'v'},
{ 0, 0, 0, 0}
};
while ( (i = getopt_long( argc, argv, opts, long_options, 0)) != -1 ) { while ( (i = getopt( argc, argv, opts)) != -1 ) {
switch ( i ) { switch ( i ) {
case 'c': case 'c':
configFileName = optarg; configFileName = optarg;
@ -157,11 +150,11 @@ showUsage ( ostream & os )
<< endl << endl
<< "options:" << "options:"
<< endl << endl
<< " -c, --config=config.file use configuration file config.file" << " -c config.file use configuration file config.file"
<< endl << endl
<< " -v, --verbosity=number verbosity level (0 = silent, 10 = loud)" << " -v n verbosity level (0 = silent, 10 = loud)"
<< endl << endl
<< " -h, --help print this message and exit" << " -h print this message and exit"
<< endl << endl
<< endl; << endl;
} }
@ -172,6 +165,9 @@ showUsage ( ostream & os )
$Source$ $Source$
$Log$ $Log$
Revision 1.9 2001/09/11 15:05:21 darkeye
added Solaris support
Revision 1.8 2001/09/02 12:24:29 darkeye Revision 1.8 2001/09/02 12:24:29 darkeye
now displays usage info when no command line parameters given now displays usage info when no command line parameters given