From 5d9c8058da6c316b009277c385dbe89f3bd6b4fc Mon Sep 17 00:00:00 2001 From: nobody Date: Sun, 5 Nov 2000 10:05:55 +0000 Subject: [PATCH] This commit was manufactured by cvs2svn to create tag 'darkice'. --- darkice/tags/darkice/src/AudioEncoder.h | 252 ++++++++++++++ darkice/tags/darkice/src/AudioSource.h | 171 ++++++++++ darkice/tags/darkice/src/BufferedSink.cpp | 302 ++++++++++++++++ darkice/tags/darkice/src/BufferedSink.h | 213 ++++++++++++ darkice/tags/darkice/src/CastSink.cpp | 144 ++++++++ darkice/tags/darkice/src/CastSink.h | 326 ++++++++++++++++++ darkice/tags/darkice/src/Connector.cpp | 341 +++++++++++++++++++ darkice/tags/darkice/src/Connector.h | 172 ++++++++++ darkice/tags/darkice/src/DarkIce.cpp | 219 ++++++++++++ darkice/tags/darkice/src/DarkIce.h | 165 +++++++++ darkice/tags/darkice/src/Exception.cpp | 128 +++++++ darkice/tags/darkice/src/Exception.h | 199 +++++++++++ darkice/tags/darkice/src/ExternalEncoder.cpp | 190 +++++++++++ darkice/tags/darkice/src/ExternalEncoder.h | 243 +++++++++++++ darkice/tags/darkice/src/FileSink.cpp | 280 +++++++++++++++ darkice/tags/darkice/src/FileSink.h | 182 ++++++++++ darkice/tags/darkice/src/FileSource.cpp | 240 +++++++++++++ darkice/tags/darkice/src/FileSource.h | 163 +++++++++ darkice/tags/darkice/src/IceCast.cpp | 179 ++++++++++ darkice/tags/darkice/src/IceCast.h | 158 +++++++++ darkice/tags/darkice/src/LameEncoder.cpp | 150 ++++++++ darkice/tags/darkice/src/LameEncoder.h | 244 +++++++++++++ darkice/tags/darkice/src/Makefile | 34 ++ darkice/tags/darkice/src/OssDspSource.cpp | 238 +++++++++++++ darkice/tags/darkice/src/OssDspSource.h | 179 ++++++++++ darkice/tags/darkice/src/PipeSink.cpp | 114 +++++++ darkice/tags/darkice/src/PipeSink.h | 141 ++++++++ darkice/tags/darkice/src/PipeSource.cpp | 94 +++++ darkice/tags/darkice/src/PipeSource.h | 137 ++++++++ darkice/tags/darkice/src/Ref.h | 226 ++++++++++++ darkice/tags/darkice/src/Referable.h | 151 ++++++++ darkice/tags/darkice/src/Sink.h | 139 ++++++++ darkice/tags/darkice/src/Source.h | 135 ++++++++ darkice/tags/darkice/src/TcpSocket.cpp | 317 +++++++++++++++++ darkice/tags/darkice/src/TcpSocket.h | 193 +++++++++++ darkice/tags/darkice/src/Util.cpp | 91 +++++ darkice/tags/darkice/src/Util.h | 121 +++++++ darkice/tags/darkice/src/files | 37 ++ darkice/tags/darkice/src/main.cpp | 93 +++++ 39 files changed, 7101 insertions(+) create mode 100644 darkice/tags/darkice/src/AudioEncoder.h create mode 100644 darkice/tags/darkice/src/AudioSource.h create mode 100644 darkice/tags/darkice/src/BufferedSink.cpp create mode 100644 darkice/tags/darkice/src/BufferedSink.h create mode 100644 darkice/tags/darkice/src/CastSink.cpp create mode 100644 darkice/tags/darkice/src/CastSink.h create mode 100644 darkice/tags/darkice/src/Connector.cpp create mode 100644 darkice/tags/darkice/src/Connector.h create mode 100644 darkice/tags/darkice/src/DarkIce.cpp create mode 100644 darkice/tags/darkice/src/DarkIce.h create mode 100644 darkice/tags/darkice/src/Exception.cpp create mode 100644 darkice/tags/darkice/src/Exception.h create mode 100644 darkice/tags/darkice/src/ExternalEncoder.cpp create mode 100644 darkice/tags/darkice/src/ExternalEncoder.h create mode 100644 darkice/tags/darkice/src/FileSink.cpp create mode 100644 darkice/tags/darkice/src/FileSink.h create mode 100644 darkice/tags/darkice/src/FileSource.cpp create mode 100644 darkice/tags/darkice/src/FileSource.h create mode 100644 darkice/tags/darkice/src/IceCast.cpp create mode 100644 darkice/tags/darkice/src/IceCast.h create mode 100644 darkice/tags/darkice/src/LameEncoder.cpp create mode 100644 darkice/tags/darkice/src/LameEncoder.h create mode 100644 darkice/tags/darkice/src/Makefile create mode 100644 darkice/tags/darkice/src/OssDspSource.cpp create mode 100644 darkice/tags/darkice/src/OssDspSource.h create mode 100644 darkice/tags/darkice/src/PipeSink.cpp create mode 100644 darkice/tags/darkice/src/PipeSink.h create mode 100644 darkice/tags/darkice/src/PipeSource.cpp create mode 100644 darkice/tags/darkice/src/PipeSource.h create mode 100644 darkice/tags/darkice/src/Ref.h create mode 100644 darkice/tags/darkice/src/Referable.h create mode 100644 darkice/tags/darkice/src/Sink.h create mode 100644 darkice/tags/darkice/src/Source.h create mode 100644 darkice/tags/darkice/src/TcpSocket.cpp create mode 100644 darkice/tags/darkice/src/TcpSocket.h create mode 100644 darkice/tags/darkice/src/Util.cpp create mode 100644 darkice/tags/darkice/src/Util.h create mode 100644 darkice/tags/darkice/src/files create mode 100644 darkice/tags/darkice/src/main.cpp diff --git a/darkice/tags/darkice/src/AudioEncoder.h b/darkice/tags/darkice/src/AudioEncoder.h new file mode 100644 index 0000000..64443dd --- /dev/null +++ b/darkice/tags/darkice/src/AudioEncoder.h @@ -0,0 +1,252 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : AudioEncoder.h + Version : $Revision$ + Author : $Author$ + Location : $AudioEncoder$ + + Abstract : + + An audio encoder + + 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 AUDIO_ENCODER_H +#define AUDIO_ENCODER_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "Referable.h" +#include "AudioSource.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class AudioEncoder : public virtual Referable +{ + private: + + unsigned int inSampleRate; + unsigned int inBitsPerSample; + unsigned int inChannel; + + unsigned int outBitrate; + unsigned int outSampleRate; + unsigned int outChannel; + + + inline void + init ( unsigned int inSampleRate, + unsigned int inBitsPerSample, + unsigned int inChannel, + unsigned int outBitrate, + unsigned int outSampleRate, + unsigned int outChannel ) throw ( Exception ) + { + this->inSampleRate = inSampleRate; + this->inBitsPerSample = inBitsPerSample; + this->inChannel = inChannel; + this->outBitrate = outBitrate; + this->outSampleRate = outSampleRate; + this->outChannel = outChannel; + } + + + inline void + strip ( void ) throw ( Exception ) + { + } + + + protected: + + inline + AudioEncoder ( void ) throw ( Exception ) + { + throw Exception( __FILE__, __LINE__); + } + + + inline + AudioEncoder ( unsigned int inSampleRate, + unsigned int inBitsPerSample, + unsigned int inChannel, + unsigned int outBitrate, + unsigned int outSampleRate = 0, + unsigned int outChannel = 0 ) + throw ( Exception ) + { + init ( inSampleRate, + inBitsPerSample, + inChannel, + outBitrate, + outSampleRate ? outSampleRate : inSampleRate, + outChannel ? outChannel : inChannel ); + } + + + inline + AudioEncoder ( const AudioSource * as, + unsigned int outBitrate, + unsigned int outSampleRate = 0, + unsigned int outChannel = 0 ) + throw ( Exception) + { + init( as->getSampleRate(), + as->getBitsPerSample(), + as->getChannel(), + outBitrate, + outSampleRate ? outSampleRate : as->getSampleRate(), + outChannel ? outChannel : as->getChannel() ); + } + + + inline + AudioEncoder ( const AudioEncoder & encoder ) throw ( Exception ) + { + init ( encoder.inSampleRate, + encoder.inBitsPerSample, + encoder.inChannel, + encoder.outBitrate, + encoder.outSampleRate, + encoder.outChannel ); + } + + + inline virtual AudioEncoder & + operator= ( const AudioEncoder & encoder ) throw ( Exception ) + { + if ( this != &encoder ) { + strip(); + + init ( encoder.inSampleRate, + encoder.inBitsPerSample, + encoder.inChannel, + encoder.outBitrate, + encoder.outSampleRate, + encoder.outChannel ); + } + + return *this; + } + + + public: + + inline virtual + ~AudioEncoder ( void ) throw ( Exception ) + { + strip(); + } + + + inline int + getInChannel ( void ) const throw () + { + return inChannel; + } + + + inline int + getInSampleRate ( void ) const throw () + { + return inSampleRate; + } + + + inline int + getInBitsPerSample ( void ) const throw () + { + return inBitsPerSample; + } + + + inline int + getOutChannel ( void ) const throw () + { + return outChannel; + } + + + inline int + getOutSampleRate ( void ) const throw () + { + return outSampleRate; + } + + + inline int + getOutBitrate ( void ) const throw () + { + return outBitrate; + } + + + virtual bool + isRunning ( void ) const throw () = 0; + + + virtual bool + start ( void ) throw ( Exception ) = 0; + + + virtual void + stop ( void ) throw ( Exception ) = 0; +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* AUDIO_ENCODER_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:47 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/AudioSource.h b/darkice/tags/darkice/src/AudioSource.h new file mode 100644 index 0000000..ac0e1a1 --- /dev/null +++ b/darkice/tags/darkice/src/AudioSource.h @@ -0,0 +1,171 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : AudioSource.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Audio data input + + 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 AUDIO_SOURCE_H +#define AUDIO_SOURCE_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "Source.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class AudioSource : public Source +{ + private: + + unsigned int channel; + unsigned int sampleRate; + unsigned int bitsPerSample; + + + inline void + init ( unsigned int sampleRate, + unsigned int bitsPerSample, + unsigned int channel ) throw ( Exception ) + { + this->sampleRate = sampleRate; + this->bitsPerSample = bitsPerSample; + this->channel = channel; + } + + + inline void + strip ( void ) throw ( Exception ) + { + } + + + protected: + + inline + AudioSource ( unsigned int sampleRate = 44100, + unsigned int bitsPerSample = 16, + unsigned int channel = 2 ) + throw ( Exception ) + { + init ( sampleRate, bitsPerSample, channel); + } + + + inline + AudioSource ( const AudioSource & as ) throw ( Exception ) + : Source( as ) + { + init ( as.sampleRate, as.bitsPerSample, as.channel); + } + + + virtual inline + ~AudioSource ( void ) throw ( Exception ) + { + } + + + inline virtual AudioSource & + operator= ( const AudioSource & as ) throw ( Exception ) + { + if ( this != &as ) { + strip(); + Source::operator=( as ); + init ( as.sampleRate, as.bitsPerSample, as.channel); + } + + return *this; + } + + + virtual AudioSource * + clone ( void ) const throw ( Exception ) = 0; + + + public: + + inline unsigned int + getChannel ( void ) const throw () + { + return channel; + } + + + inline unsigned int + getSampleRate ( void ) const throw () + { + return sampleRate; + } + + + inline unsigned int + getBitsPerSample ( void ) const throw () + { + return bitsPerSample; + } +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* AUDIO_SOURCE_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:47 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/BufferedSink.cpp b/darkice/tags/darkice/src/BufferedSink.cpp new file mode 100644 index 0000000..5bdc249 --- /dev/null +++ b/darkice/tags/darkice/src/BufferedSink.cpp @@ -0,0 +1,302 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : BufferedSink.cpp + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + A Sink with a First-In First-Out buffer + This buffer can always be written to, it overwrites any + data contained if needed + The class is not thread-safe + + the buffer is filled like this: + + buffer bufferEnd + | | + +----------+--------------------------+--------------+ + |<---- valid data -------->| + outp inp + + buffer bufferEnd + | | + +----------------+--------------+--------------------+ + -- valid data -->| |--- valid data -----> + inp outp + + + + 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 + +#include "Exception.h" +#include "BufferedSink.h" + + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * File identity + *----------------------------------------------------------------------------*/ +static const char fileid[] = "$Id$"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Initialize the object + *----------------------------------------------------------------------------*/ +void +BufferedSink :: init ( Sink * sink, + unsigned int size ) throw ( Exception ) +{ + if ( !sink ) { + throw Exception( __FILE__, __LINE__, "no sink"); + } + + this->sink = sink; // create a reference + this->bufferSize = size; + this->buffer = new unsigned char[bufferSize]; + this->bufferEnd = buffer + bufferSize; + this->inp = buffer; + this->outp = buffer; +} + + +/*------------------------------------------------------------------------------ + * Copy Constructor + *----------------------------------------------------------------------------*/ +BufferedSink :: BufferedSink ( const BufferedSink & buffer ) + throw ( Exception ) +{ + init( buffer.sink.get(), buffer.bufferSize); + + memcpy( this->buffer, buffer.buffer, this->bufferSize); +} + + +/*------------------------------------------------------------------------------ + * De-initalize the object + *----------------------------------------------------------------------------*/ +void +BufferedSink :: strip ( void ) throw ( Exception ) +{ + if ( isOpen() ) { + close(); + } + + sink = 0; // delete the reference + delete buffer; +} + + +/*------------------------------------------------------------------------------ + * Assignment operator + *----------------------------------------------------------------------------*/ +BufferedSink & +BufferedSink :: operator= ( const BufferedSink & buffer ) + throw ( Exception ) +{ + if ( this != &buffer ) { + strip(); + Sink::operator=( buffer ); + init( buffer.sink.get(), buffer.bufferSize); + + memcpy( this->buffer, buffer.buffer, this->bufferSize); + } + + return *this; +} + + +/*------------------------------------------------------------------------------ + * Store bufferSize bytes into the buffer + * All data is consumed. The return value is less then bufferSize only + * if the BufferedSink's internal buffer is smaller than bufferSize, + * thus can't hold that much + *----------------------------------------------------------------------------*/ +unsigned int +BufferedSink :: store ( const void * buffer, + unsigned int bufferSize ) throw ( Exception ) +{ + const unsigned char * buf; + unsigned int size; + unsigned int i; + unsigned char * oldInp; + + if ( !buffer ) { + throw Exception( __FILE__, __LINE__, "buffer is null"); + } + + if ( !bufferSize ) { + return 0; + } + + oldInp = inp; + buf = (const unsigned char *) buffer; + + /* cut the front of the supplied buffer if it wouldn't fit */ + if ( bufferSize > this->bufferSize ) { + size = this->bufferSize - 1; + buf += bufferSize - size; + } else { + size = bufferSize; + } + + /* copy the data into the buffer */ + i = bufferEnd - inp; + if ( size <= i ) { + /* the place between inp and bufferEnd is + * big enough to hold the data */ + + memcpy( inp, buf, size); + inp = slidePointer( inp, size); + + /* adjust outp, lose the data that was overwritten, if any */ + if ( outp > oldInp && outp <= inp ) { + outp = slidePointer( inp, 1); + } + + } else { + /* the place between inp and bufferEnd is not + * big enough to hold the data + * writing will take place in two turns, once from + * inp -> bufferEnd, then from buffer -> */ + + memcpy( inp, buf, i); + i = size - i; + memcpy( this->buffer, buf, i); + inp = slidePointer( this->buffer, i); + + /* adjust outp, lose the data that was overwritten, if any */ + if ( outp <= oldInp ) { + if ( outp < inp ) { + outp = slidePointer( inp, 1); + } + } else { + outp = slidePointer( inp, 1); + } + } + + return size; +} + + +/*------------------------------------------------------------------------------ + * Write some data to the sink + * if len == 0, try to flush the buffer + *----------------------------------------------------------------------------*/ +unsigned int +BufferedSink :: write ( const void * buf, + unsigned int len ) throw ( Exception ) +{ + unsigned int length; + + if ( !buf ) { + throw Exception( __FILE__, __LINE__, "buf is null"); + } + + if ( !isOpen() ) { + return 0; + } + + /* try to write data from the buffer first, if any */ + if ( inp != outp ) { + unsigned int size; + + if ( outp > inp ) { + /* valuable data is between outp -> bufferEnd and buffer -> inp + * try to write the outp -> bufferEnd + * the rest will be written in the next if */ + + size = bufferEnd - outp; + length = sink->write( outp, size); + outp = slidePointer( outp, length); + } + + if ( outp < inp ) { + /* valuable data is between outp and inp + * if the previous if wrote all data from the end + * this part will write the rest */ + + size = inp - outp; + length = sink->write( outp, size); + outp = slidePointer( outp, length); + } + } + + /* the internal buffer is empty, try to write the fresh data */ + length = inp == outp ? sink->write( buf, len) : 0; + + if ( length < len ) { + /* if not all fresh could be written, store the remains */ + + unsigned char * b = (unsigned char *) buf; + + store( b + length, len - length); + } + + /* tell them we ate everything */ + return len; +} + + +/*------------------------------------------------------------------------------ + * Close the sink, lose all pending data + *----------------------------------------------------------------------------*/ +void +BufferedSink :: close ( void ) throw ( Exception ) +{ + if ( !isOpen() ) { + return; + } + + flush(); + sink->close(); + inp = outp = buffer; +} + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:48 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/BufferedSink.h b/darkice/tags/darkice/src/BufferedSink.h new file mode 100644 index 0000000..1b618ae --- /dev/null +++ b/darkice/tags/darkice/src/BufferedSink.h @@ -0,0 +1,213 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : BufferedSink.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + A Sink First-In First-Out buffer + This buffer can always be written to, it overwrites any + data contained if needed + The class is not thread-safe + + 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 BUFFERED_SINK_H +#define BUFFERED_SINK_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "Ref.h" +#include "Sink.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class BufferedSink : public Sink +{ + private: + + unsigned char * buffer; + unsigned char * bufferEnd; + unsigned int bufferSize; + + unsigned char * inp; + unsigned char * outp; + + + Ref sink; + + + void + init ( Sink * sink, + unsigned int size ) throw ( Exception ); + + + void + strip ( void ) throw ( Exception ); + + + inline unsigned char * + slidePointer ( + unsigned char * p, + unsigned int offset ) throw () + { + p += offset; + while ( p >= bufferEnd ) { + p -= bufferSize; + } + + return p; + } + + + protected: + + inline + BufferedSink ( void ) throw ( Exception ) + { + throw Exception( __FILE__, __LINE__); + } + + + inline unsigned int + getSize ( void ) const throw () + { + return bufferSize; + } + + + unsigned int + store ( const void * buffer, + unsigned int bufferSize ) throw ( Exception ); + + + public: + + inline + BufferedSink ( Sink * sink, + unsigned int size ) throw ( Exception ) + { + init( sink, size); + } + + + BufferedSink ( const BufferedSink & buffer ) throw ( Exception ); + + + inline virtual + ~BufferedSink ( void ) throw ( Exception ) + { + strip(); + } + + + virtual BufferedSink & + operator= ( const BufferedSink & bs ) throw ( Exception ); + + + inline virtual BufferedSink * + clone ( void ) const throw ( Exception ) + { + return new BufferedSink(*this); + } + + + inline virtual bool + open ( void ) throw ( Exception ) + { + return sink->open(); + } + + + inline virtual bool + isOpen ( void ) const throw ( Exception ) + { + return sink->isOpen(); + } + + + inline virtual bool + canWrite ( unsigned int sec, + unsigned int usec ) throw ( Exception ) + { + return true; + } + + + virtual unsigned int + write ( const void * buf, + unsigned int len ) throw ( Exception ); + + + inline virtual void + flush ( void ) throw ( Exception ) + { + unsigned char b[0]; + + write( b, 0); + } + + + virtual void + close ( void ) throw ( Exception ); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* BUFFERED_SINK_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:48 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/CastSink.cpp b/darkice/tags/darkice/src/CastSink.cpp new file mode 100644 index 0000000..0d60bfb --- /dev/null +++ b/darkice/tags/darkice/src/CastSink.cpp @@ -0,0 +1,144 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : CastSink.cpp + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Data output to a ShoutCast / IceCast / etc. server + + 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 "Util.h" +#include "Exception.h" +#include "CastSink.h" + + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * File identity + *----------------------------------------------------------------------------*/ +static const char fileid[] = "$Id$"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Initialize the object + *----------------------------------------------------------------------------*/ +void +CastSink :: init ( TcpSocket * socket, + const char * password, + const char * mountPoint, + const char * name, + const char * description, + const char * url, + const char * genre, + unsigned int bitRate, + bool isPublic, + unsigned int bufferDuration ) + throw ( Exception ) +{ + this->socket = socket; + this->password = Util::strDup( password); + this->mountPoint = Util::strDup( mountPoint); + this->name = Util::strDup( name); + this->description = Util::strDup( description); + this->url = Util::strDup( url); + this->genre = Util::strDup( genre); + this->bitRate = bitRate; + this->isPublic = isPublic; + this->bufferDuration = bufferDuration; + + bufferedSink = new BufferedSink( socket, + (bitRate * 1024 / 8) * bufferDuration ); + +} + + +/*------------------------------------------------------------------------------ + * De-initialize the object + *----------------------------------------------------------------------------*/ +void +CastSink :: strip ( void ) throw ( Exception ) +{ + if ( isOpen() ) { + close(); + } + + delete[] password; + delete[] mountPoint; + delete[] name; + delete[] description; + delete[] url; + delete[] genre; +} + + +/*------------------------------------------------------------------------------ + * Open the connection + *----------------------------------------------------------------------------*/ +bool +CastSink :: open ( void ) throw ( Exception ) +{ + if ( isOpen() ) { + return false; + } + + if ( !bufferedSink->open() ) { + return false; + } + + if ( !sendLogin() ) { + close(); + return false; + } + + return true; +} + + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:48 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/CastSink.h b/darkice/tags/darkice/src/CastSink.h new file mode 100644 index 0000000..539bd17 --- /dev/null +++ b/darkice/tags/darkice/src/CastSink.h @@ -0,0 +1,326 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : CastSink.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Data output to a ShoutCast / IceCast / etc. server + + 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 CAST_SINK_H +#define CAST_SINK_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "Ref.h" +#include "Sink.h" +#include "TcpSocket.h" +#include "BufferedSink.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class CastSink : public Sink +{ + private: + + Ref socket; + Ref bufferedSink; + char * password; + char * mountPoint; + + char * name; + char * description; + char * url; + char * genre; + unsigned int bitRate; + bool isPublic; + unsigned int bufferDuration; + + + void + init ( TcpSocket * socket, + const char * password, + const char * mountPoint, + const char * name, + const char * description, + const char * url, + const char * genre, + unsigned int bitRate, + bool isPublic, + unsigned int bufferDuration ) + throw ( Exception ); + + + void + strip ( void ) throw ( Exception ); + + + protected: + + inline + CastSink ( void ) throw ( Exception ) + { + throw Exception( __FILE__, __LINE__); + } + + + virtual bool + sendLogin ( void ) throw ( Exception ) = 0; + + + public: + + inline + CastSink ( TcpSocket * socket, + const char * password, + const char * mountPoint, + const char * name, + const char * description, + const char * url, + const char * genre, + unsigned int bitRate, + bool isPublic, + unsigned int bufferDuration = 10 ) + throw ( Exception ) + { + init( socket, + password, + mountPoint, + name, + description, + url, + genre, + bitRate, + isPublic, + bufferDuration ); + } + + + inline + CastSink( const CastSink & cs ) throw ( Exception ) + : Sink( cs ) + { + init( cs.socket.get(), + cs.password, + cs.mountPoint, + cs.name, + cs.description, + cs.url, + cs.genre, + cs.bitRate, + cs.isPublic, + cs.bufferDuration ); + } + + + inline virtual + ~CastSink( void ) throw ( Exception ) + { + strip(); + } + + + inline virtual CastSink & + operator= ( const CastSink & cs ) throw ( Exception ) + { + if ( this != &cs ) { + strip(); + Sink::operator=( cs ); + init( cs.socket.get(), + cs.password, + cs.mountPoint, + cs.name, + cs.description, + cs.url, + cs.genre, + cs.bitRate, + cs.isPublic, + cs.bufferDuration ); + } + return *this; + } + + + virtual CastSink * + clone ( void ) const throw ( Exception ) = 0; + + + inline Sink * + getSink ( void ) const throw () + { + return bufferedSink.get(); + } + + + inline TcpSocket * + getSocket ( void ) const throw () + { + return socket.get(); + } + + + virtual bool + open ( void ) throw ( Exception ); + + + inline virtual bool + isOpen ( void ) const throw () + { + return bufferedSink->isOpen(); + } + + + inline virtual bool + canWrite ( unsigned int sec, + unsigned int usec ) throw ( Exception ) + { + return bufferedSink->canWrite( sec, usec); + } + + + inline virtual unsigned int + write ( const void * buf, + unsigned int len ) throw ( Exception ) + { + return bufferedSink->write( buf, len); + } + + + inline virtual void + flush ( void ) throw ( Exception ) + { + return bufferedSink->flush(); + } + + + inline virtual void + close ( void ) throw ( Exception ) + { + return bufferedSink->close(); + } + + + inline const char * + getPassword ( void ) const throw () + { + return password; + } + + + inline const char * + getMountPoint ( void ) const throw () + { + return mountPoint; + } + + + inline const char * + getName ( void ) const throw () + { + return name; + } + + + inline const char * + getDescription ( void ) const throw () + { + return description; + } + + + inline const char * + getUrl ( void ) const throw () + { + return url; + } + + + inline const char * + getGenre ( void ) const throw () + { + return genre; + } + + + inline unsigned int + getBitRate ( void ) const throw () + { + return bitRate; + } + + + inline bool + getIsPublic ( void ) const throw () + { + return isPublic; + } + + + inline unsigned int + getBufferDuration ( void ) const throw () + { + return bufferDuration; + } +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* CAST_SINK_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:48 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/Connector.cpp b/darkice/tags/darkice/src/Connector.cpp new file mode 100644 index 0000000..efca964 --- /dev/null +++ b/darkice/tags/darkice/src/Connector.cpp @@ -0,0 +1,341 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : Connector.cpp + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Connects a source to a sink + + 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 "Exception.h" +#include "Connector.h" + + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * File identity + *----------------------------------------------------------------------------*/ +static const char fileid[] = "$Id$"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Initialize the object + *----------------------------------------------------------------------------*/ +void +Connector :: init ( Source * source ) throw ( Exception ) +{ + this->source = source; + this->sinks = 0; + this->numSinks = 0; +} + + +/*------------------------------------------------------------------------------ + * De-initialize the object + *----------------------------------------------------------------------------*/ +void +Connector :: strip ( void ) throw ( Exception ) +{ + source = 0; + + if ( sinks ) { + unsigned int u; + + for ( u = 0; u < numSinks; ++u ) { + sinks[u] = 0; + } + + delete[] sinks; + } +} + + +/*------------------------------------------------------------------------------ + * Constructor + *----------------------------------------------------------------------------*/ +Connector :: Connector ( const Connector & connector ) throw ( Exception ) +{ + unsigned int u; + + init( connector.source.get()); + + for ( u = 0; u < connector.numSinks; ++u ) { + attach( connector.sinks[u].get() ); + } +} + + +/*------------------------------------------------------------------------------ + * Assignment operator + *----------------------------------------------------------------------------*/ +Connector & +Connector :: operator= ( const Connector & connector ) throw ( Exception ) +{ + if ( this != &connector ) { + unsigned int u; + + /* first free everything */ + strip(); + + /* then fill in */ + init( connector.source.get() ); + + for ( u = 0; u < connector.numSinks; ++u ) { + attach( connector.sinks[u].get() ); + } + } + + return *this; +} + + +/*------------------------------------------------------------------------------ + * Attach a sink to the connector + *----------------------------------------------------------------------------*/ +void +Connector :: attach ( Sink * sink ) throw ( Exception ) +{ + if ( !sinks ) { + + numSinks = 1; + sinks = new Ref[1]; + sinks[0] = sink; + + } else { + + unsigned int u; + Ref * s = new Ref[numSinks + 1]; + + for ( u = 0; u < numSinks; ++u ) { + s[u] = sinks[u].get(); + } + + s[numSinks] = sink; + delete[] sinks; + sinks = s; + ++numSinks; + } +} + + +/*------------------------------------------------------------------------------ + * Detach a sink to the connector + *----------------------------------------------------------------------------*/ +bool +Connector :: detach ( Sink * sink ) throw ( Exception ) +{ + if ( numSinks == 0 ) { + + return false; + + } else if ( numSinks == 1 ) { + + sinks[0] = 0; + delete[] sinks; + sinks = 0; + + return true; + + } else { + + unsigned int u; + unsigned int v; + unsigned int ix; + Ref * s; + + ix = numSinks; + for ( u = 0; u < numSinks; ++u ) { + + if ( sinks[u].get() == sink ) { + ix = u; + break; + } + } + + if ( ix == numSinks ) { + return false; + } + + s = new Ref[numSinks - 1]; + for ( u = 0, v = 0; u < numSinks; ++u ) { + + if ( u != ix ) { + s[v++] = sinks[u]; + } + } + + sinks[ix] = 0; + delete[] sinks; + sinks = s; + --numSinks; + + return true; + } +} + + +/*------------------------------------------------------------------------------ + * Open the source and all the sinks if needed + *----------------------------------------------------------------------------*/ +bool +Connector :: open ( void ) throw ( Exception ) +{ + unsigned int u; + + if ( !source->isOpen() ) { + if ( !source->open() ) { + return false; + } + } + + for ( u = 0; u < numSinks; ++u ) { + if ( !sinks[u]->isOpen() ) { + if ( !sinks[u]->open() ) { + break; + } + } + } + + /* if not all could be opened, close those that were */ + if ( u < numSinks ) { + unsigned int v; + + for ( v = 0; v < u; ++v ) { + sinks[v]->close(); + } + + source->close(); + + return false; + } + + return true; +} + + +/*------------------------------------------------------------------------------ + * Transfer some data from the source to the sink + *----------------------------------------------------------------------------*/ +unsigned int +Connector :: transfer ( unsigned int bytes, + unsigned int bufSize, + unsigned int sec, + unsigned int usec ) throw ( Exception ) +{ + unsigned int u; + unsigned int b; + unsigned char buf[bufSize]; + + if ( numSinks == 0 ) { + return 0; + } + + if ( bufSize == 0 ) { + return 0; + } + + for ( b = 0; b < bytes; ) { + unsigned int d = 0; + unsigned int e = 0; + + if ( source->canRead( sec, usec) ) { + d = source->read( buf, bufSize); + + /* check for EOF */ + if ( d == 0 ) { +cout << "Connector :: transfer, EOF" << endl; + break; + } + + for ( u = 0; u < numSinks; ++u ) { + + if ( sinks[u]->canWrite( sec, usec) ) { + e = sinks[u]->write( buf, d); + } else { + sinks[u]->close(); + detach( sinks[u].get() ); + /* with the call to detach, numSinks gets 1 lower, + * and the next sink comes to sinks[u] */ + --u; + + if ( numSinks == 0 ) { +cout << "Connector :: transfer, no more sinks" << endl; + break; + } + } + } + + b += d; + } else { +cout << "Connector :: transfer, can't read" << endl; + break; + } + } + + return b; +} + + +/*------------------------------------------------------------------------------ + * Open the source and all the sinks if needed + *----------------------------------------------------------------------------*/ +void +Connector :: close ( void ) throw ( Exception ) +{ + unsigned int u; + + source->close(); + for ( u = 0; u < numSinks; ++u ) { + sinks[u]->close(); + } +} + + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:49 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/Connector.h b/darkice/tags/darkice/src/Connector.h new file mode 100644 index 0000000..957fa49 --- /dev/null +++ b/darkice/tags/darkice/src/Connector.h @@ -0,0 +1,172 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : Connector.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Connects a source to a sink + + 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 CONNECTOR_H +#define CONNECTOR_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "Referable.h" +#include "Ref.h" +#include "Source.h" +#include "Sink.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class Connector : public virtual Referable +{ + private: + + Ref source; + + + Ref * sinks; + unsigned int numSinks; + + + void + init ( Source * source ) throw ( Exception ); + + + void + strip ( void ) throw ( Exception ); + + + protected: + + inline + Connector ( void ) throw ( Exception ) + { + throw Exception( __FILE__, __LINE__); + } + + + public: + + inline + Connector ( Source * source ) throw ( Exception ) + { + init( source); + } + + + inline + Connector ( Source * source, + Sink * sink ) throw ( Exception ) + { + init( source); + attach( sink); + } + + + Connector ( const Connector & connector ) throw ( Exception ); + + + inline virtual + ~Connector( void ) + { + strip(); + } + + + virtual Connector & + operator= ( const Connector & connector ) throw ( Exception ); + + + inline unsigned int + getNumSinks ( void ) const throw () + { + return numSinks; + } + + + void + attach ( Sink * sink ) throw ( Exception ); + + + bool + detach ( Sink * sink ) throw ( Exception ); + + + bool + open ( void ) throw ( Exception ); + + + unsigned int + transfer ( unsigned int bytes, + unsigned int bufSize, + unsigned int sec, + unsigned int usec ) throw ( Exception ); + + + void + close ( void ) throw ( Exception ); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* CONNECTOR_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:49 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/DarkIce.cpp b/darkice/tags/darkice/src/DarkIce.cpp new file mode 100644 index 0000000..f3119f6 --- /dev/null +++ b/darkice/tags/darkice/src/DarkIce.cpp @@ -0,0 +1,219 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : darkice.cpp + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Program main object + + 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 +#include +#include +#include +#include +#include + +#include "DarkIce.h" + + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * File identity + *----------------------------------------------------------------------------*/ +static const char fileid[] = "$Id$"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Initialize the object + *----------------------------------------------------------------------------*/ +void +DarkIce :: init ( void ) throw ( Exception ) +{ + /* the pipes */ + encOutPipe = new PipeSource( "enc.out"); + encInPipe = new PipeSink( "enc.in"); + + if ( !encOutPipe->exists() ) { + if ( !encOutPipe->create() ) { + throw Exception( __FILE__, __LINE__, "can't create out pipe"); + } + } + + if ( !encInPipe->exists() ) { + if ( !encInPipe->create() ) { + throw Exception( __FILE__, __LINE__, "can't create in pipe"); + } + } + + /* encoder related stuff */ + dsp = new OssDspSource( "/dev/dsp", 22050, 16, 2); + encIn = new BufferedSink( encInPipe.get(), 64 * 1024); + encConnector = new Connector( dsp.get(), encInPipe.get()); + encoder = new LameEncoder( "notlame", + encInPipe->getFileName(), + dsp.get(), + encOutPipe->getFileName(), + 96 ); + + + /* streaming related stuff */ + socket = new TcpSocket( "susi", 8000); + ice = new IceCast( socket.get(), + "hackme", + "sample", + "name", + "description", + "http://ez.az/", + "sajat", + 128, + false ); + shoutConnector = new Connector( encOutPipe.get(), ice.get()); +} + + +/*------------------------------------------------------------------------------ + * Run the encoder + *----------------------------------------------------------------------------*/ +bool +DarkIce :: encode ( void ) throw ( Exception ) +{ + unsigned int len; + + encoder->start(); + + sleep( 1 ); + + if ( !encConnector->open() ) { + throw Exception( __FILE__, __LINE__, "can't open connector"); + } + + len = encConnector->transfer( 22050 * 2 * 2 * 120, 4096, 1, 0 ); + + cout << len << " bytes transfered" << endl; + + encConnector->close(); + + encoder->stop(); + + return true; +} + + +/*------------------------------------------------------------------------------ + * Run the encoder + *----------------------------------------------------------------------------*/ +bool +DarkIce :: shout ( void ) throw ( Exception ) +{ + unsigned int len; + + if ( !shoutConnector->open() ) { + throw Exception( __FILE__, __LINE__, "can't open connector"); + } + + len = shoutConnector->transfer( 128 * 1024 / 8 * 120, 4096, 1, 0 ); + + cout << len << " bytes transfered" << endl; + + shoutConnector->close(); + + return true; +} + + +/*------------------------------------------------------------------------------ + * Run + *----------------------------------------------------------------------------*/ +int +DarkIce :: run ( void ) throw ( Exception ) +{ + pid_t pid; + + cout << "DarkIce" << endl << endl << flush; + + init(); + + cout << "init OK" << endl << flush; + + pid = fork(); + + if ( pid == -1 ) { + throw Exception( __FILE__, __LINE__, "fork error", errno); + + } else if ( pid == 0 ) { + // this is the child + + sleep ( 2 ); + + cout << "shouting" << endl << flush; + shout(); + cout << "shouting ends" << endl << flush; + + exit(0); + } else { + // this is the parent + int status; + + cout << "encoding" << endl << flush; + encode(); + cout << "encoding ends" << endl << flush; + + waitpid( pid, &status, 0); + if ( !WIFEXITED(status) ) { + throw Exception( __FILE__, __LINE__, + "child exited abnormally", WEXITSTATUS(status)); + } + } + + return 0; +} + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:49 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/DarkIce.h b/darkice/tags/darkice/src/DarkIce.h new file mode 100644 index 0000000..9e2bcb4 --- /dev/null +++ b/darkice/tags/darkice/src/DarkIce.h @@ -0,0 +1,165 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : DarkIce.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Program main object + + 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 DARK_ICE_H +#define DARK_ICE_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include + +#include "Referable.h" +#include "Exception.h" +#include "Ref.h" +#include "OssDspSource.h" +#include "PipeSink.h" +#include "BufferedSink.h" +#include "Connector.h" +#include "LameEncoder.h" +#include "PipeSource.h" +#include "TcpSocket.h" +#include "IceCast.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class DarkIce : public virtual Referable +{ + private: + + Ref dsp; + Ref encInPipe; + Ref encIn; + Ref encConnector; + Ref encoder; + + Ref encOutPipe; + Ref socket; + Ref ice; + Ref shoutConnector; + + + void + init ( void ) throw ( Exception ); + + + bool + encode ( void ) throw ( Exception ); + + + bool + shout ( void ) throw ( Exception ); + + + protected: +/* + virtual void + showUsage ( ostream & os ) throw ( Exception ); +*/ + + public: + + inline + DarkIce ( void ) throw ( Exception ) + { + } + + + inline + DarkIce ( int argc, + char * argv[] ) throw () + { + } + + + inline virtual + ~DarkIce ( void ) throw ( Exception ) + { + } + + +/* + + inline + DarkIce ( const DarkIce & di ) throw ( Exception ) + { + } + + + inline DarkIce & + operator= ( const DarkIce * di ) throw ( Exception ) + { + } +*/ + + virtual int + run ( void ) throw ( Exception ); + +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* DARK_ICE_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:50 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/Exception.cpp b/darkice/tags/darkice/src/Exception.cpp new file mode 100644 index 0000000..9776434 --- /dev/null +++ b/darkice/tags/darkice/src/Exception.cpp @@ -0,0 +1,128 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : Exception.cpp + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + An exception class + + This class should not depend on any other class + (note: Cloneable is an interface) and should not throw + any exceptions itself + + 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 + +#include "Exception.h" + + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * File identity + *----------------------------------------------------------------------------*/ +static const char fileid[] = "$Id$"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Initialize the class + *----------------------------------------------------------------------------*/ +void +Exception :: init ( const char * file, + unsigned int line, + const char * description = 0, + int code = 0 ) throw () +{ + if ( !file ) { + this->file = 0; + } else { + size_t len; + + len = strlen( file ) + 1; + this->file = new char[len]; + if ( this->file ) { + memcpy( this->file, file, len); + } + } + + if ( !description ) { + this->description = 0; + } else { + size_t len; + + len = strlen( description ) + 1; + this->description = new char[len]; + if ( this->description ) { + memcpy( this->description, description, len); + } + } + + this->line = line; + this->code = code; +} + + +/*------------------------------------------------------------------------------ + * De-initialize the class + *----------------------------------------------------------------------------*/ +void +Exception :: strip ( void ) throw () +{ + if ( description ) { + delete[] description; + } + + if ( file ) { + delete[] file; + } +} + + + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:50 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/Exception.h b/darkice/tags/darkice/src/Exception.h new file mode 100644 index 0000000..a248582 --- /dev/null +++ b/darkice/tags/darkice/src/Exception.h @@ -0,0 +1,199 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : Exception.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + An exception class + + This class should not depend on any other class + (note: Cloneable is an interface) and should not throw + any exceptions itself + + 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 EXCEPTION_H +#define EXCEPTION_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class Exception +{ + private: + + char * file; + unsigned int line; + char * description; + int code; + + + void + init ( const char * file, + unsigned int line, + const char * description, + int code ) throw (); + + + void + strip () throw (); + + + protected: + + + public: + + inline + Exception ( void ) throw () + { + init( 0, 0, 0, 0); + } + + + inline + Exception ( const Exception & e ) throw () + { + init( e.file, e.line, e.description, e.code); + } + + + inline + Exception ( const char * description, + int code = 0 ) throw () + { + init( 0, 0, description, code); + } + + + inline + Exception ( const char * file, + unsigned int line, + const char * description = 0, + int code = 0 ) throw () + { + init( file, line, description, code); + } + + + inline + ~Exception ( void ) throw () + { + strip(); + } + + + inline Exception & + operator= ( const Exception & e ) throw () + { + if ( this != &e ) { + strip(); + init( e.file, e.line, e.description, e.code); + } + + return *this; + } + + + inline const char * + getDescription( void ) const throw () + { + return description; + } + + inline unsigned int + getLine ( void ) const throw () + { + return line; + } + + + inline const char * + getFile ( void ) const throw () + { + return file; + } + + + inline int + getCode ( void ) const throw () + { + return code; + } + +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + +/*------------------------------------------------------------------------------ + * Print a Exception to an ostream + *----------------------------------------------------------------------------*/ +inline ostream & +operator<< ( ostream & os, + const Exception & e ) +{ + os << e.getDescription() << " [" << e.getCode() << "] (" + << e.getFile() << ":" << e.getLine() << ")"; +} + + + +#endif /* EXCEPTION_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:50 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/ExternalEncoder.cpp b/darkice/tags/darkice/src/ExternalEncoder.cpp new file mode 100644 index 0000000..540b85f --- /dev/null +++ b/darkice/tags/darkice/src/ExternalEncoder.cpp @@ -0,0 +1,190 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : ExternalEncoder.cpp + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + A class representing an external audio encoder which is invoked + with a frok() and an exec() call + + 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 +#include +#include +#include + +#include "Exception.h" +#include "Util.h" +#include "ExternalEncoder.h" + + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * File identity + *----------------------------------------------------------------------------*/ +static const char fileid[] = "$Id$"; + + +/*------------------------------------------------------------------------------ + * File identity + *----------------------------------------------------------------------------*/ +#define ARG_LEN 64 + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Initialize the class + *----------------------------------------------------------------------------*/ +void +ExternalEncoder :: init ( const char * encoderName, + const char * inFileName, + const char * outFileName ) throw ( Exception ) +{ + unsigned int u; + + for ( u = 0; u < numCmdArgs; ++u ) { + cmdArgs[u] = 0; + } + + this->encoderName = Util::strDup( encoderName); + this->inFileName = Util::strDup( inFileName); + this->outFileName = Util::strDup( outFileName); + this->child = 0; +} + + +/*------------------------------------------------------------------------------ + * De-initialize the class + *----------------------------------------------------------------------------*/ +void +ExternalEncoder :: strip ( void ) throw ( Exception ) +{ + unsigned int u; + + if ( isRunning() ) { + stop(); + } + + for ( u = 0; u < numCmdArgs; ++u ) { + if ( cmdArgs[u] ) { + delete[] cmdArgs[u]; + } + } + + delete[] encoderName; + delete[] inFileName; + delete[] outFileName; + child = 0; +} + + +/*------------------------------------------------------------------------------ + * Set the nth command line argument + *----------------------------------------------------------------------------*/ +void +ExternalEncoder :: setArg ( const char * str, + unsigned int index ) throw ( Exception ) +{ + if ( index >= numCmdArgs ) { + throw Exception( __FILE__, __LINE__, "index >= numCmdArgs", index); + } + + cmdArgs[index] = str ? Util::strDup( str) : 0; +} + + +/*------------------------------------------------------------------------------ + * Start the encoding + *----------------------------------------------------------------------------*/ +bool +ExternalEncoder :: start ( void ) throw ( Exception ) +{ + pid_t pid; + + if ( isRunning() ) { + return false; + } + + pid = fork(); + + if ( pid == -1 ) { + throw Exception( __FILE__, __LINE__, "fork error"); + } else if ( pid == 0 ) { + cout << "wow, I'm a voodoo child!" << endl; + + makeArgs(); + execvp( getEncoderName(), cmdArgs); + + throw Exception( __FILE__, __LINE__, "exec returned"); + } else { + child = pid; + cout << "I'm a parent, the child's pid is " << child << endl; + + return true; + } +} + + +/*------------------------------------------------------------------------------ + * End the encoding + *----------------------------------------------------------------------------*/ +void +ExternalEncoder :: stop ( void ) throw ( Exception ) +{ + if ( !isRunning() ) { + return; + } + + if ( kill( child, SIGHUP) == -1 ) { + throw Exception( __FILE__, __LINE__, "kill", errno); + } +} + + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:50 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/ExternalEncoder.h b/darkice/tags/darkice/src/ExternalEncoder.h new file mode 100644 index 0000000..3c7a0b8 --- /dev/null +++ b/darkice/tags/darkice/src/ExternalEncoder.h @@ -0,0 +1,243 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : ExternalEncoder.h + Version : $Revision$ + Author : $Author$ + Location : $ExternalEncoder$ + + Abstract : + + A class representing an external audio encoder which is invoked + with a frok() and an exec() call + + 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 EXTERNAL_ENCODER_H +#define EXTERNAL_ENCODER_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include + +#include "Exception.h" +#include "AudioEncoder.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class ExternalEncoder : public AudioEncoder +{ + private: + + char * encoderName; + char * inFileName; + char * outFileName; + + static const unsigned int numCmdArgs = 32; + + char * cmdArgs[numCmdArgs]; + + pid_t child; + + + void + init ( const char * encoderName, + const char * inFileName, + const char * outFileName ) throw ( Exception ); + + + void + strip ( void ) throw ( Exception ); + + + protected: + + inline + ExternalEncoder ( void ) throw ( Exception ) + { + throw Exception( __FILE__, __LINE__); + } + + + void + setArg ( const char * str, + unsigned int index ) throw ( Exception ); + + + virtual unsigned int + makeArgs ( void ) throw ( Exception ) = 0; + + + public: + + inline + ExternalEncoder ( const char * encoderName, + const char * inFileName, + unsigned int inSampleRate, + unsigned int inBitsPerSample, + unsigned int inChannel, + const char * outFileName, + unsigned int outBitrate, + unsigned int outSampleRate = 0, + unsigned int outChannel = 0 ) + throw ( Exception ) + + : AudioEncoder ( inSampleRate, + inBitsPerSample, + inChannel, + outBitrate, + outSampleRate, + outChannel ) + { + init ( encoderName, inFileName, outFileName ); + } + + + inline + ExternalEncoder ( const char * encoderName, + const char * inFileName, + const AudioSource * as, + const char * outFileName, + unsigned int outBitrate, + unsigned int outSampleRate = 0, + unsigned int outChannel = 0 ) + throw ( Exception ) + + : AudioEncoder ( as, + outBitrate, + outSampleRate, + outChannel ) + { + init ( encoderName, inFileName, outFileName ); + } + + + inline + ExternalEncoder ( const ExternalEncoder & encoder ) + throw ( Exception ) + : AudioEncoder( encoder ) + { + init( encoder.encoderName, + encoder.inFileName, + encoder.outFileName ); + } + + + inline virtual + ~ExternalEncoder ( void ) throw ( Exception ) + { + strip(); + } + + + inline virtual ExternalEncoder & + operator= ( const ExternalEncoder & encoder ) throw ( Exception ) + { + if ( this != &encoder ) { + strip(); + AudioEncoder::operator=( encoder); + init( encoder.encoderName, + encoder.inFileName, + encoder.outFileName ); + } + + return *this; + } + + + inline virtual ExternalEncoder * + clone ( void ) const throw ( Exception ) = 0; + + + const char * + getEncoderName ( void ) const throw () + { + return encoderName; + } + + + const char * + getInFileName ( void ) const throw () + { + return inFileName; + } + + + const char * + getOutFileName ( void ) const throw () + { + return outFileName; + } + + + inline virtual bool + isRunning ( void ) const throw () + { + return child != 0; + } + + + virtual bool + start ( void ) throw ( Exception ); + + + virtual void + stop ( void ) throw ( Exception ); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* EXTERNAL_ENCODER_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:50 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/FileSink.cpp b/darkice/tags/darkice/src/FileSink.cpp new file mode 100644 index 0000000..b2fbd1c --- /dev/null +++ b/darkice/tags/darkice/src/FileSink.cpp @@ -0,0 +1,280 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : FileSink.cpp + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + File data output + + 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 +#include +#include +#include +#include +#include +#include + +#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.1 2000/11/05 10:05:51 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/FileSink.h b/darkice/tags/darkice/src/FileSink.h new file mode 100644 index 0000000..e214dd1 --- /dev/null +++ b/darkice/tags/darkice/src/FileSink.h @@ -0,0 +1,182 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : FileSink.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + File data output + + 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 FILE_SINK_H +#define FILE_SINK_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "Sink.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class FileSink : public Sink +{ + private: + + char * fileName; + + + void + init ( const char * name ) throw ( Exception ); + + + void + strip ( void ) throw ( Exception ); + + + protected: + + int fileDescriptor; + + + inline + FileSink ( void ) throw ( Exception ) + { + throw Exception( __FILE__, __LINE__); + } + + + public: + + inline + FileSink( const char * name ) throw ( Exception ) + { + init( name); + } + + + FileSink( const FileSink & fsink ) throw ( Exception ); + + + inline virtual + ~FileSink( void ) throw ( Exception ) + { + strip(); + } + + + virtual FileSink & + operator= ( const FileSink & fs ) throw ( Exception ); + + + inline virtual FileSink * + clone ( void ) const throw ( Exception ) + { + return new FileSink(*this); + } + + + inline const char * + getFileName ( void ) const throw () + { + return fileName; + } + + + virtual bool + exists ( void ) const throw (); + + + virtual bool + create ( void ) throw ( Exception ); + + + virtual bool + open ( void ) throw ( Exception ); + + + inline virtual bool + isOpen ( void ) const throw () + { + return fileDescriptor != 0; + } + + + virtual bool + canWrite ( unsigned int sec, + unsigned int usec ) throw ( Exception ); + + + virtual unsigned int + write ( const void * buf, + unsigned int len ) throw ( Exception ); + + + inline virtual void + flush ( void ) throw ( Exception ) + { + } + + + virtual void + close ( void ) throw ( Exception ); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* FILE_SINK_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:51 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/FileSource.cpp b/darkice/tags/darkice/src/FileSource.cpp new file mode 100644 index 0000000..15d12b5 --- /dev/null +++ b/darkice/tags/darkice/src/FileSource.cpp @@ -0,0 +1,240 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : FileSource.cpp + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Data input from a file + + 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 +#include +#include +#include +#include + +#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.1 2000/11/05 10:05:51 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/FileSource.h b/darkice/tags/darkice/src/FileSource.h new file mode 100644 index 0000000..97331f1 --- /dev/null +++ b/darkice/tags/darkice/src/FileSource.h @@ -0,0 +1,163 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : FileSource.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Data input from a file + + 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 FILE_SOURCE_H +#define FILE_SOURCE_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "Source.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * A data source based on a file + *----------------------------------------------------------------------------*/ +class FileSource : public Source +{ + private: + + char * fileName; + int fileDescriptor; + + + void + init ( const char * name ) throw ( Exception ); + + + void + strip ( void ) throw ( Exception ); + + + protected: + + inline + FileSource ( void ) throw ( Exception ) + { + throw Exception( __FILE__, __LINE__); + } + + + public: + + inline + FileSource ( const char * name ) throw ( Exception ) + { + init( name); + } + + + FileSource ( const FileSource & fs ) throw ( Exception ); + + + inline + ~FileSource ( void ) throw ( Exception ) + { + strip(); + } + + + inline virtual FileSource & + operator= ( const FileSource & fs ) throw ( Exception ); + + + inline virtual const char * + getFileName ( void ) const throw () + { + return fileName; + } + + + virtual bool + exists ( void ) const throw (); + + + virtual bool + open ( void ) throw ( Exception ); + + + inline virtual bool + isOpen ( void ) const throw () + { + return fileDescriptor != 0; + } + + + virtual bool + canRead ( unsigned int sec, + unsigned int usec ) throw ( Exception ); + + + virtual unsigned int + read ( void * buf, + unsigned int len ) throw ( Exception ); + + + virtual void + close ( void ) throw ( Exception ); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* FILE_SOURCE_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:51 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/IceCast.cpp b/darkice/tags/darkice/src/IceCast.cpp new file mode 100644 index 0000000..8dcdd13 --- /dev/null +++ b/darkice/tags/darkice/src/IceCast.cpp @@ -0,0 +1,179 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : IceCast.cpp + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Class representing output to an IceCast server with + x-audiocast login + + 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 +#include + +#include "Exception.h" +#include "Source.h" +#include "Sink.h" +#include "IceCast.h" + + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * File identity + *----------------------------------------------------------------------------*/ +static const char fileid[] = "$Id$"; + + +/*------------------------------------------------------------------------------ + * Size of string conversion buffer + *----------------------------------------------------------------------------*/ +#define STRBUF_SIZE 32 + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Initialize the object + *----------------------------------------------------------------------------*/ +bool +IceCast :: sendLogin ( void ) throw ( Exception ) +{ + Sink * sink = getSink(); + Source * source = getSocket(); + const char * str; + char resp[STRBUF_SIZE]; + unsigned int len; + + if ( !source->isOpen() ) { + return false; + } + if ( !sink->isOpen() ) { + return false; + } + + /* send the request, a string like: + * "SOURCE /\n\n" */ + str = "SOURCE "; + sink->write( str, strlen( str)); + str = getPassword(); + sink->write( str, strlen( str)); + str = " /"; + sink->write( str, strlen( str)); + str = getMountPoint(); + sink->write( str, strlen( str)); + str = "\n\n"; + sink->write( str, strlen( str)); + sink->flush(); + + /* read the anticipated response: "OK" */ + len = source->read( resp, STRBUF_SIZE); + if ( len < 2 || resp[0] != 'O' || resp[1] != 'K' ) { + return false; + } + + /* suck anything that the other side has to say */ + while ( source->canRead( 0, 0) && + (len = source->read( resp, STRBUF_SIZE)) ) { + ; + } + + /* send the x-audiocast headers */ + str = "x-audiocast-name: "; + sink->write( str, strlen( str)); + str = getName(); + sink->write( str, strlen( str)); + + str = "\nx-audiocast-description: "; + sink->write( str, strlen( str)); + str = getDescription(); + sink->write( str, strlen( str)); + + str = "\nx-audiocast-url: "; + sink->write( str, strlen( str)); + str = getUrl(); + sink->write( str, strlen( str)); + + str = "\nx-audiocast-genre: "; + sink->write( str, strlen( str)); + str = getGenre(); + sink->write( str, strlen( str)); + + str = "\nx-audiocast-bitrate: "; + sink->write( str, strlen( str)); + if ( snprintf( resp, STRBUF_SIZE, "%d", getBitRate()) == -1 ) { + throw Exception( __FILE__, __LINE__, "snprintf overflow"); + } + sink->write( resp, strlen( resp)); + + str = "\nx-audiocast-public: "; + sink->write( str, strlen( str)); + str = getIsPublic() ? "yes" : "no"; + sink->write( str, strlen( str)); + + str = "\n\n"; + sink->write( str, strlen( str)); + sink->flush(); + + /* read the anticipated response: "OK" */ + len = source->read( resp, STRBUF_SIZE); + if ( len < 2 || resp[0] != 'O' || resp[1] != 'K' ) { + return false; + } + + /* suck anything that the other side has to say */ + while ( source->canRead( 0, 0) && + (len = source->read( resp, STRBUF_SIZE)) ) { + ; + } + + + return true; +} + + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:52 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/IceCast.h b/darkice/tags/darkice/src/IceCast.h new file mode 100644 index 0000000..4224391 --- /dev/null +++ b/darkice/tags/darkice/src/IceCast.h @@ -0,0 +1,158 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : IceCast.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Class representing output to an IceCast server with + x-audiocast login + + 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 ICE_CAST_H +#define ICE_CAST_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "Sink.h" +#include "TcpSocket.h" +#include "CastSink.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class IceCast : public CastSink +{ + private: + + + protected: + + inline + IceCast ( void ) throw ( Exception ) + { + throw Exception( __FILE__, __LINE__); + } + + + virtual bool + sendLogin ( void ) throw ( Exception ); + + + public: + + inline + IceCast ( TcpSocket * socket, + const char * password, + const char * mountPoint, + const char * name, + const char * description, + const char * url, + const char * genre, + unsigned int bitRate, + bool isPublic, + unsigned int bufferDuration = 10 ) + throw ( Exception ) + : CastSink( socket, + password, + mountPoint, + name, + description, + url, + genre, + bitRate, + isPublic, + bufferDuration ) + { + } + + + inline + IceCast( const IceCast & cs ) throw ( Exception ) + : CastSink( cs ) + { + } + + + inline virtual + ~IceCast( void ) throw ( Exception ) + { + } + + + inline virtual IceCast & + operator= ( const IceCast & cs ) throw ( Exception ) + { + if ( this != &cs ) { + CastSink::operator=( cs ); + } + return *this; + } + + + virtual IceCast * + clone ( void ) const throw ( Exception ) + { + return new IceCast( *this ); + } +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* ICE_CAST_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:52 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/LameEncoder.cpp b/darkice/tags/darkice/src/LameEncoder.cpp new file mode 100644 index 0000000..dbf399e --- /dev/null +++ b/darkice/tags/darkice/src/LameEncoder.cpp @@ -0,0 +1,150 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : LameEncoder.cpp + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + A class representing the lame mp3 encoder + + 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 + +#include "Exception.h" +#include "LameEncoder.h" + + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * File identity + *----------------------------------------------------------------------------*/ +static const char fileid[] = "$Id$"; + + +/*------------------------------------------------------------------------------ + * File identity + *----------------------------------------------------------------------------*/ +#define ARG_LEN 64 + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Initialize command line parameters + *----------------------------------------------------------------------------*/ +unsigned int +LameEncoder :: makeArgs ( void ) throw ( Exception ) +{ + unsigned int u; + char str[ARG_LEN]; + + u = 0; + + setArg( getEncoderName(), u++); // name of the command + setArg( "-S", u++); // make it silent + setArg( "-r", u++); // input is raw PCM + setArg( "-x", u++); // input is little endian + setArg( "-h", u++); // high quality + + /* set input sample rate */ + if ( snprintf( str, ARG_LEN, "%.3f", + ((double)getInSampleRate()) / 1000.0 ) == -1 ) { + throw Exception( __FILE__, __LINE__, "snprintf overflow"); + } + setArg( "-s", u++); + setArg( str, u++); + + /* set stereo / mono */ + setArg( "-m", u++); + setArg( getOutChannel() == 1 ? "m" : "j", u++); + + /* set output bitrate */ + if ( snprintf( str, ARG_LEN, "%d", getOutBitrate()) == -1 ) { + throw Exception( __FILE__, __LINE__, "snprintf overflow"); + } + setArg( "-b", u++); + setArg( str, u++); + + /* set output sample rate */ + if ( snprintf( str, ARG_LEN, "%.3f", + ((double)getOutSampleRate()) / 1000.0 ) == -1 ) { + throw Exception( __FILE__, __LINE__, "snprintf overflow"); + } + setArg( "--resample", u++); + setArg( str, u++); + + /* set lowpass filter if needed */ + if ( lowpass ) { + if ( snprintf( str, ARG_LEN, "%.3f", + ((double)getLowpass()) / 1000.0 ) == -1 ) { + throw Exception( __FILE__, __LINE__, "snprintf overflow"); + } + setArg( "--lowpass", u++); + setArg( str, u++); + } + + /* set highpass filter if needed */ + if ( highpass ) { + if ( snprintf( str, ARG_LEN, "%.3f", + ((double)getHighpass()) / 1000.0 ) == -1 ) { + throw Exception( __FILE__, __LINE__, "snprintf overflow"); + } + setArg( "--highpass", u++); + setArg( str, u++); + } + + setArg( getInFileName(), u++); // input file + setArg( getOutFileName(), u++); // output file + + setArg( 0, u++); // terminating zero + + + return u; +} + + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:52 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/LameEncoder.h b/darkice/tags/darkice/src/LameEncoder.h new file mode 100644 index 0000000..5d91f55 --- /dev/null +++ b/darkice/tags/darkice/src/LameEncoder.h @@ -0,0 +1,244 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : LameEncoder.h + Version : $Revision$ + Author : $Author$ + Location : $LameEncoder$ + + Abstract : + + A class representing the lame mp3 encoder + + 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 LAME_ENCODER_H +#define LAME_ENCODER_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "Exception.h" +#include "ExternalEncoder.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class LameEncoder : public ExternalEncoder +{ + private: + + unsigned int lowpass; + unsigned int highpass; + + protected: + + virtual unsigned int + makeArgs ( void ) throw ( Exception ); + + + inline + LameEncoder ( void ) throw ( Exception ) + { + throw Exception( __FILE__, __LINE__); + } + + + inline void + init ( unsigned int lowpass, + unsigned int highpass ) throw ( Exception ) + { + this->lowpass = lowpass; + this->highpass = highpass; + } + + + inline void + strip ( void ) throw ( Exception ) + { + } + + + public: + + inline + LameEncoder ( const char * encoderName, + const char * inFileName, + unsigned int inSampleRate, + unsigned int inBitsPerSample, + unsigned int inChannel, + const char * outFileName, + unsigned int outBitrate, + unsigned int outSampleRate = 0, + unsigned int outChannel = 0, + unsigned int lowpass = 0, + unsigned int highpass = 0 ) + throw ( Exception ) + + : ExternalEncoder ( encoderName, + inFileName, + inSampleRate, + inBitsPerSample, + inChannel, + outFileName, + outBitrate, + outSampleRate, + outChannel ) + { + init( lowpass, highpass); + } + + + inline + LameEncoder ( const char * encoderName, + const char * inFileName, + const AudioSource * as, + const char * outFileName, + unsigned int outBitrate, + unsigned int outSampleRate = 0, + unsigned int outChannel = 0, + unsigned int lowpass = 0, + unsigned int highpass = 0 ) + throw ( Exception ) + + : ExternalEncoder ( encoderName, + inFileName, + as, + outFileName, + outBitrate, + outSampleRate, + outChannel ) + { + init( lowpass, highpass); + } + + + inline + LameEncoder ( const LameEncoder & encoder ) throw ( Exception ) + : ExternalEncoder( encoder ) + { + init( encoder.lowpass, encoder.highpass); + } + + + inline virtual + ~LameEncoder ( void ) throw ( Exception ) + { + strip(); + } + + + inline virtual LameEncoder & + operator= ( const LameEncoder & encoder ) throw ( Exception ) + { + if ( this != &encoder ) { + strip(); + ExternalEncoder::operator=( encoder); + init( encoder.lowpass, encoder.highpass); + } + + return *this; + } + + + inline virtual LameEncoder * + clone ( void ) const throw ( Exception ) + { + return new LameEncoder( *this ); + } + + + inline unsigned int + getLowpass ( void ) const throw () + { + return lowpass; + } + + + inline bool + setLowpass ( unsigned int lowpass ) throw () + { + if ( isRunning() ) { + return false; + } else { + this->lowpass = lowpass; + return true; + } + } + + + inline unsigned int + getHighpass ( void ) const throw () + { + return highpass; + } + + + inline bool + setHighpass ( unsigned int highpass ) throw () + { + if ( isRunning() ) { + return false; + } else { + this->highpass = highpass; + return true; + } + } + + +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* LAME_ENCODER_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:52 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/Makefile b/darkice/tags/darkice/src/Makefile new file mode 100644 index 0000000..71710f7 --- /dev/null +++ b/darkice/tags/darkice/src/Makefile @@ -0,0 +1,34 @@ +CPP=g++ + +CPPFLAGS= + +all: darkice + +OBJECTS = main.o\ + Exception.o\ + DarkIce.o\ + Util.o\ + FileSource.o\ + PipeSource.o\ + OssDspSource.o\ + FileSink.o\ + PipeSink.o\ + BufferedSink.o\ + TcpSocket.o\ + CastSink.o\ + IceCast.o\ + Connector.o\ + ExternalEncoder.o\ + LameEncoder.o + +darkice: $(OBJECTS) + $(CPP) $(OBJECTS) -o darkice + +clean: + rm -f $(OBJECTS) darkice + +env: + ls *.h *.cpp > files + rm -f tags + ctags -L files -o tags + diff --git a/darkice/tags/darkice/src/OssDspSource.cpp b/darkice/tags/darkice/src/OssDspSource.cpp new file mode 100644 index 0000000..0be8530 --- /dev/null +++ b/darkice/tags/darkice/src/OssDspSource.cpp @@ -0,0 +1,238 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : OssDspSource.cpp + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Audio data input + + 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 +#include +#include +#include +#include +#include +#include + +#include "Util.h" +#include "Exception.h" +#include "OssDspSource.h" + + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * File identity + *----------------------------------------------------------------------------*/ +static const char fileid[] = "$Id$"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Initialize the object + *----------------------------------------------------------------------------*/ +void +OssDspSource :: init ( const char * name ) throw ( Exception ) +{ + fileName = Util::strDup( name); + fileDescriptor = 0; + running = false; +} + + +/*------------------------------------------------------------------------------ + * De-initialize the object + *----------------------------------------------------------------------------*/ +void +OssDspSource :: strip ( void ) throw ( Exception ) +{ + if ( isOpen() ) { + close(); + } + + delete[] fileName; +} + + +/*------------------------------------------------------------------------------ + * Open the audio source + *----------------------------------------------------------------------------*/ +bool +OssDspSource :: open ( void ) throw ( Exception ) +{ + int format; + int i; + + if ( isOpen() ) { + return false; + } + + switch ( getBitsPerSample() ) { + case 8: + format = AFMT_U8; + break; + + case 16: + format = AFMT_S16_LE; + break; + + default: + return false; + } + + if ( (fileDescriptor = ::open( fileName, O_RDONLY)) == -1 ) { + fileDescriptor = 0; + return false; + } + + i = format; + if ( ioctl( fileDescriptor, SNDCTL_DSP_SETFMT, &i) == -1 || + i != format ) { + + close(); + throw Exception( __FILE__, __LINE__, "can't set format", i); + } + + i = getChannel(); + if ( ioctl( fileDescriptor, SNDCTL_DSP_CHANNELS, &i) == -1 || + i != getChannel() ) { + + close(); + throw Exception( __FILE__, __LINE__, "can't set channels", i); + } + + i = getSampleRate(); + if ( ioctl( fileDescriptor, SNDCTL_DSP_SPEED, &i) == -1 || + i != getSampleRate() ) { + + close(); + throw Exception( __FILE__, __LINE__, "can't set speed", i); + } + + return true; +} + + +/*------------------------------------------------------------------------------ + * Check wether read() would return anything + *----------------------------------------------------------------------------*/ +bool +OssDspSource :: 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[getBitsPerSample()/8]; + + read( b, 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 +OssDspSource :: 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 +OssDspSource :: close ( void ) throw ( Exception ) +{ + if ( !isOpen() ) { + return; + } + + ::close( fileDescriptor); + fileDescriptor = 0; + running = false; +} + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:53 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/OssDspSource.h b/darkice/tags/darkice/src/OssDspSource.h new file mode 100644 index 0000000..0cf21ef --- /dev/null +++ b/darkice/tags/darkice/src/OssDspSource.h @@ -0,0 +1,179 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : OssDspSource.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Audio data input from an OSS /dev/dsp-like device + + 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 OSS_DSP_SOURCE_H +#define OSS_DSP_SOURCE_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "AudioSource.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * An audio input based on /dev/dsp-like raw devices + *----------------------------------------------------------------------------*/ +class OssDspSource : public AudioSource +{ + private: + + char * fileName; + int fileDescriptor; + bool running; + + + protected: + + inline + OssDspSource ( void ) throw ( Exception ) + { + throw Exception( __FILE__, __LINE__); + } + + + void + init ( const char * name ) throw ( Exception ); + + + void + strip ( void ) throw ( Exception ); + + + public: + + inline + OssDspSource ( const char * name, + int sampleRate = 44100, + int bitsPerSample = 16, + int channel = 2 ) + throw ( Exception ) + + : AudioSource( sampleRate, bitsPerSample, channel) + { + init( name); + } + + + inline + OssDspSource ( const OssDspSource & ds ) throw ( Exception ) + : AudioSource( ds ) + { + init( ds.fileName); + } + + + inline virtual + ~OssDspSource ( void ) throw ( Exception ) + { + strip(); + } + + + inline virtual OssDspSource & + operator= ( const OssDspSource & ds ) throw ( Exception ) + { + if ( this != &ds ) { + strip(); + AudioSource::operator=( ds); + init( ds.fileName); + } + return *this; + } + + + inline virtual OssDspSource * + clone ( void ) const throw ( Exception ) + { + return new OssDspSource( *this ); + } + + + virtual bool + open ( void ) throw ( Exception ); + + + inline virtual bool + isOpen ( void ) const throw () + { + return fileDescriptor != 0; + } + + + virtual bool + canRead ( unsigned int sec, + unsigned int usec ) throw ( Exception ); + + + virtual unsigned int + read ( void * buf, + unsigned int len ) throw ( Exception ); + + + virtual void + close ( void ) throw ( Exception ); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* OSS_DSP_SOURCE_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:53 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/PipeSink.cpp b/darkice/tags/darkice/src/PipeSink.cpp new file mode 100644 index 0000000..676144e --- /dev/null +++ b/darkice/tags/darkice/src/PipeSink.cpp @@ -0,0 +1,114 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : PipeSink.cpp + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Audio data input + + 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 +#include +#include +#include + +#include "Exception.h" +#include "PipeSink.h" + + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * File identity + *----------------------------------------------------------------------------*/ +static const char fileid[] = "$Id$"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Create a pipe + *----------------------------------------------------------------------------*/ +bool +PipeSink :: create ( void ) throw ( Exception ) +{ + if ( isOpen() ) { + return false; + } + + if ( mkfifo( getFileName(), S_IRUSR | S_IWUSR) == -1 ) { + if ( errno = EEXIST ) { + return true; + } + throw Exception( __FILE__, __LINE__, "mkfifo error", errno); + } + + return true; +} + + +/*------------------------------------------------------------------------------ + * Open the file + *----------------------------------------------------------------------------*/ +bool +PipeSink :: open ( void ) throw ( Exception ) +{ + if ( isOpen() ) { + return false; + } + + if ( (fileDescriptor = ::open( getFileName(), + O_WRONLY | O_NONBLOCK)) == -1 ) { + fileDescriptor = 0; + return false; + } + + return true; +} + + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:53 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/PipeSink.h b/darkice/tags/darkice/src/PipeSink.h new file mode 100644 index 0000000..2a977a6 --- /dev/null +++ b/darkice/tags/darkice/src/PipeSink.h @@ -0,0 +1,141 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : PipeSink.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + FIFO pipe data output + + 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 PIPE_SINK_H +#define PIPE_SINK_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "FileSink.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class PipeSink : public FileSink +{ + private: + + + protected: + + inline + PipeSink ( void ) throw ( Exception ) + { + throw Exception( __FILE__, __LINE__); + } + + + public: + + inline + PipeSink ( const char * name ) throw ( Exception ) + : FileSink( name ) + { + } + + + inline + PipeSink ( const PipeSink & ps ) throw ( Exception ) + : FileSink( ps ) + { + } + + + inline virtual PipeSink & + operator= ( const PipeSink & fs ) throw ( Exception ) + { + if ( this != &fs ) { + FileSink::operator=( fs ); + } + + return *this; + } + + + inline virtual PipeSink * + clone ( void ) const throw ( Exception ) + { + return new PipeSink(*this); + } + + + virtual inline + ~PipeSink( void ) throw ( Exception ) + { + } + + + virtual bool + create ( void ) throw ( Exception ); + + + virtual bool + open ( void ) throw ( Exception ); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* PIPE_SINK_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:53 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/PipeSource.cpp b/darkice/tags/darkice/src/PipeSource.cpp new file mode 100644 index 0000000..e16bf1f --- /dev/null +++ b/darkice/tags/darkice/src/PipeSource.cpp @@ -0,0 +1,94 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : PipeSource.cpp + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Audio data input + + 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 +#include +#include +#include + +#include "Exception.h" +#include "PipeSource.h" + + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * File identity + *----------------------------------------------------------------------------*/ +static const char fileid[] = "$Id$"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Create a pipe + *----------------------------------------------------------------------------*/ +bool +PipeSource :: create ( void ) throw ( Exception ) +{ + if ( isOpen() ) { + return false; + } + + if ( mkfifo( getFileName(), S_IRUSR | S_IWUSR) == -1 ) { + if ( errno = EEXIST ) { + return true; + } + throw Exception( __FILE__, __LINE__, "mkfifo error", errno); + } + + return true; +} + + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:53 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/PipeSource.h b/darkice/tags/darkice/src/PipeSource.h new file mode 100644 index 0000000..2557607 --- /dev/null +++ b/darkice/tags/darkice/src/PipeSource.h @@ -0,0 +1,137 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : PipeSource.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + FIFO pipe data input + + 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 PIPE_SOURCE_H +#define PIPE_SOURCE_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "FileSource.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class PipeSource : public FileSource +{ + private: + + + protected: + + inline + PipeSource ( void ) throw ( Exception ) + { + throw Exception( __FILE__, __LINE__); + } + + + public: + + inline + PipeSource ( const char * name ) throw ( Exception ) + : FileSource( name ) + { + } + + + inline + PipeSource ( const PipeSource & ps ) throw ( Exception ) + : FileSource( ps ) + { + } + + + inline virtual PipeSource & + operator= ( const PipeSource & fs ) throw ( Exception ) + { + if ( this != &fs ) { + FileSource::operator=( fs ); + } + + return *this; + } + + + inline virtual PipeSource * + clone ( void ) const throw ( Exception ) + { + return new PipeSource(*this); + } + + + virtual inline + ~PipeSource( void ) throw ( Exception ) + { + } + + + virtual bool + create ( void ) throw ( Exception ); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* PIPE_SOURCE_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:53 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/Ref.h b/darkice/tags/darkice/src/Ref.h new file mode 100644 index 0000000..dcf7a93 --- /dev/null +++ b/darkice/tags/darkice/src/Ref.h @@ -0,0 +1,226 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : Ref.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Java-like object reference class + Objects used with this reference class have to be descandents + of class Referable + + sample usage: + + #include "Ref.h" + #include "Referable.h" + + class A : public virtual Referable; + + ... + + A * a = new A(); + Ref ref1 = a; // 1 reference to a + Ref ref2 = ref1; // 2 references to a + + ref1 = 0; // 1 reference to a + ref2 = 0; // at this point object a is destroyed + + + Based on Tima Saarinen's work, + http://gamma.nic.fi/~timosa/comp/refcount.html + + 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 REF_H +#define REF_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "Exception.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +template +class Ref +{ + private: + + T* object; + + + protected: + + + public: + + inline + Ref ( void ) throw () + { + object = NULL; + } + + + inline + Ref ( const Ref & other ) throw ( Exception ) + { + object = NULL; + set( other.object); + } + + + inline + Ref ( T * obj ) throw ( Exception ) + { + object = obj; + obj->increaseReferenceCount(); + } + + + inline virtual + ~Ref ( void ) throw ( Exception ) + { + set( 0 ); + } + + + inline T* + operator->() const throw () + { + if ( !object ) { + throw Exception( __FILE__, __LINE__, + "reference to NULL object"); + } + return object; + } + + + inline Ref & + operator= ( Ref other ) throw ( Exception ) + { + set( other.object); + } + + + inline Ref & + operator= ( T* obj ) throw ( Exception ) + { + set( obj); + return *this; + } + + + inline void + set ( T* newobj ) throw ( Exception ) + { + // If equal do nothing + if ( newobj == object ) { + return; + } + + // Increase reference count + if ( newobj ) { + newobj->increaseReferenceCount(); + } + + // Decrease the reference count of the old referable + if ( object ) { + if ( object->decreaseReferenceCount() == 0 ) { + delete object; + } + } + + // Assign + object = newobj; + } + + + /** + * Return object pointer. This method should be used with + * care because it breaks the encapsulation. + * Typically this method is needed for the method calls + * which require literal object pointer. + * + *

It may not be bad idea to pass the Ref + * objects as method arguments.

+ * + * @return Object pointer or NULL. + */ + inline T* + get ( void ) const throw () + { + return object; + } + + + inline bool + operator== ( const Ref & other ) const throw () + { + return object == other.object; + } + + + inline bool + operator!= ( const Ref & other ) const throw () + { + return object != other.object; + } +}; + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* REF_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:54 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/Referable.h b/darkice/tags/darkice/src/Referable.h new file mode 100644 index 0000000..4b25687 --- /dev/null +++ b/darkice/tags/darkice/src/Referable.h @@ -0,0 +1,151 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : Referable.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Base class for an object for which references can be made + with the reference class Ref (see Ref.h) + + usage: + + class A : public virtual Referable + { + ... + }; + + 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 REFERABLE_H +#define REFERABLE_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "Exception.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class Referable +{ + private: + + unsigned int referenceCount; + + static const + unsigned int maxCount = ~((unsigned int)0); + + + protected: + + inline + Referable ( void ) throw () + { + referenceCount = 0; + } + + + inline virtual + ~Referable ( void ) throw ( Exception ) + { + if ( referenceCount > 0 ) { + throw Exception( __FILE__, __LINE__, + "reference count positive in destructor", + referenceCount); + } + } + + + public: + + inline unsigned int + increaseReferenceCount ( void ) throw ( Exception ) + { + if ( referenceCount >= maxCount ) { + throw Exception( __FILE__, + __LINE__, + "reference count overflow", + referenceCount ); + } + return ++referenceCount; + } + + + inline unsigned int + decreaseReferenceCount ( void ) throw ( Exception ) + { + if ( referenceCount == 0 ) { + throw Exception( __FILE__, __LINE__, + "reference count underflow", + referenceCount ); + } + return --referenceCount; + } + + + inline unsigned int + getReferenceCount ( void ) const throw () + { + return referenceCount; + } +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* REFERABLE_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:54 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/Sink.h b/darkice/tags/darkice/src/Sink.h new file mode 100644 index 0000000..d4b0c6f --- /dev/null +++ b/darkice/tags/darkice/src/Sink.h @@ -0,0 +1,139 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : Sink.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + A general data sink + + 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 SINK_H +#define SINK_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "Referable.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class Sink : public virtual Referable +{ + private: + + + protected: + + inline + Sink ( void ) + { + } + + + inline + Sink ( const Sink & sink ) + { + } + + + inline virtual Sink & + operator= ( const Sink & sink ) + { + return *this; + } + + + public: + + inline virtual + ~Sink ( void ) + { + } + + + virtual bool + open ( void ) = 0; + + + virtual bool + isOpen ( void ) const = 0; + + + virtual bool + canWrite ( unsigned int sec, + unsigned int usec ) = 0; + + + virtual unsigned int + write ( const void * buf, + unsigned int len ) = 0; + + + virtual void + flush ( void ) = 0; + + + virtual void + close ( void ) = 0; +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* SINK_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:54 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/Source.h b/darkice/tags/darkice/src/Source.h new file mode 100644 index 0000000..5f95fb6 --- /dev/null +++ b/darkice/tags/darkice/src/Source.h @@ -0,0 +1,135 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : Source.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + A general data 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 SOURCE_H +#define SOURCE_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "Referable.h" +#include "Exception.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class Source : public virtual Referable +{ + private: + + protected: + + inline + Source ( void ) throw ( Exception ) + { + } + + + inline + Source ( const Source & source ) throw ( Exception ) + { + } + + + inline virtual Source & + operator= ( const Source & source ) throw ( Exception ) + { + return *this; + } + + + public: + + inline virtual + ~Source ( void ) throw ( Exception ) + { + } + + + virtual bool + open ( void ) throw ( Exception ) = 0; + + + virtual bool + isOpen ( void ) const throw () = 0; + + + virtual bool + canRead ( unsigned int sec, + unsigned int usec ) throw ( Exception ) = 0; + + + virtual unsigned int + read ( void * buf, + unsigned int len ) throw ( Exception ) = 0; + + + virtual void + close ( void ) throw ( Exception ) = 0; +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* SOURCE_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:54 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/TcpSocket.cpp b/darkice/tags/darkice/src/TcpSocket.cpp new file mode 100644 index 0000000..38bb40e --- /dev/null +++ b/darkice/tags/darkice/src/TcpSocket.cpp @@ -0,0 +1,317 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : TcpSocket.cpp + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + A TCP network socket + + 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 +#include +#include +#include +#include +#include +#include +#include + +#include "Util.h" +#include "Exception.h" +#include "TcpSocket.h" + + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * File identity + *----------------------------------------------------------------------------*/ +static const char fileid[] = "$Id$"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Initialize the object + *----------------------------------------------------------------------------*/ +void +TcpSocket :: init ( const char * host, + unsigned short port ) throw ( Exception ) +{ + this->host = Util::strDup( host); + this->port = port; + this->sockfd = 0; +} + + +/*------------------------------------------------------------------------------ + * De-initialize the object + *----------------------------------------------------------------------------*/ +void +TcpSocket :: strip ( void) throw ( Exception ) +{ + if ( isOpen() ) { + close(); + } + + delete[] host; +} + + +/*------------------------------------------------------------------------------ + * Copy Constructor + *----------------------------------------------------------------------------*/ +TcpSocket :: TcpSocket ( const TcpSocket & ss ) throw ( Exception ) + : Sink( ss ), Source( ss ) +{ + int fd; + + init( ss.host, ss.port); + + if ( (fd = ss.sockfd ? dup( ss.sockfd) : 0) == -1 ) { + strip(); + throw Exception( __FILE__, __LINE__, "dup failure"); + } + + sockfd = fd; +} + + +/*------------------------------------------------------------------------------ + * Assignment operator + *----------------------------------------------------------------------------*/ +TcpSocket & +TcpSocket :: operator= ( const TcpSocket & ss ) throw ( Exception ) +{ + if ( this != &ss ) { + int fd; + + /* first strip */ + strip(); + + + /* then build up */ + Sink::operator=( ss ); + Source::operator=( ss ); + + init( ss.host, ss.port); + + if ( (fd = ss.sockfd ? dup( ss.sockfd) : 0) == -1 ) { + strip(); + throw Exception( __FILE__, __LINE__, "dup failure"); + } + + sockfd = fd; + } + + return *this; +} + + +/*------------------------------------------------------------------------------ + * Open the file + *----------------------------------------------------------------------------*/ +bool +TcpSocket :: open ( void ) throw ( Exception ) +{ + struct sockaddr_in addr; + struct hostent * pHostEntry; + + if ( isOpen() ) { + return false; + } + + if ( !(pHostEntry = gethostbyname( host)) ) { + throw Exception( __FILE__, __LINE__, "gethostbyname error", errno); + } + + if ( (sockfd = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1 ) { + throw Exception( __FILE__, __LINE__, "socket error", errno); + } + + memset( &addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_port = htons(port); + addr.sin_addr.s_addr = *((long*) pHostEntry->h_addr_list[0]); + + if ( connect( sockfd, (struct sockaddr*)&addr, sizeof(addr)) == -1 ) { + ::close( sockfd); + throw Exception( __FILE__, __LINE__, "connect error", errno); + } + + return true; +} + + +/*------------------------------------------------------------------------------ + * Check wether read() would return anything + *----------------------------------------------------------------------------*/ +bool +TcpSocket :: 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( sockfd, &fdset); + tv.tv_sec = sec; + tv.tv_usec = usec; + + ret = select( sockfd + 1, &fdset, NULL, NULL, &tv); + + if ( ret == -1 ) { + throw Exception( __FILE__, __LINE__, "select error"); + } + + return ret > 0; +} + + +/*------------------------------------------------------------------------------ + * Read from the socket + *----------------------------------------------------------------------------*/ +unsigned int +TcpSocket :: read ( void * buf, + unsigned int len ) throw ( Exception ) +{ + int ret; + + if ( !isOpen() ) { + return 0; + } + + ret = recv( sockfd, buf, len, 0); + + if ( ret == -1 ) { + throw Exception( __FILE__, __LINE__, "recv error", errno); + } + + return ret; +} + + +/*------------------------------------------------------------------------------ + * Check wether read() would return anything + *----------------------------------------------------------------------------*/ +bool +TcpSocket :: 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( sockfd, &fdset); + tv.tv_sec = sec; + tv.tv_usec = usec; + + ret = select( sockfd + 1, NULL, &fdset, NULL, &tv); + + if ( ret == -1 ) { + throw Exception( __FILE__, __LINE__, "select error"); + } + + return ret > 0; +} + + +/*------------------------------------------------------------------------------ + * Write to the socket + *----------------------------------------------------------------------------*/ +unsigned int +TcpSocket :: write ( const void * buf, + unsigned int len ) throw ( Exception ) +{ + int ret; + + if ( !isOpen() ) { + return 0; + } + +// ret = send( sockfd, buf, len, MSG_DONTWAIT); + ret = send( sockfd, buf, len, 0); + + if ( ret == -1 ) { + if ( errno == EAGAIN ) { + ret = 0; + } else { + throw Exception( __FILE__, __LINE__, "send error", errno); + } + } + + return ret; +} + + +/*------------------------------------------------------------------------------ + * Close the socket + *----------------------------------------------------------------------------*/ +void +TcpSocket :: close ( void ) throw ( Exception ) +{ + if ( !isOpen() ) { + return; + } + + flush(); + ::close( sockfd); + sockfd = 0; +} + + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:55 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/TcpSocket.h b/darkice/tags/darkice/src/TcpSocket.h new file mode 100644 index 0000000..725ce9c --- /dev/null +++ b/darkice/tags/darkice/src/TcpSocket.h @@ -0,0 +1,193 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : TcpSocket.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + A TCP network socket + + 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 TCP_SOCKET_H +#define TCP_SOCKET_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "Source.h" +#include "Sink.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class TcpSocket : public Source, public Sink +{ + private: + + char * host; + unsigned short port; + + int sockfd; + + void + init ( const char * host, + unsigned short port ) throw ( Exception ); + + + void + strip ( void ) throw ( Exception ); + + + protected: + + inline + TcpSocket ( void ) throw ( Exception ) + { + throw Exception( __FILE__, __LINE__); + } + + + public: + + inline + TcpSocket( const char * host, + unsigned short port ) throw ( Exception ) + { + init( host, port); + } + + + TcpSocket( const TcpSocket & ss ) throw ( Exception ); + + + inline virtual + ~TcpSocket( void ) throw ( Exception ) + { + strip(); + } + + + inline virtual TcpSocket & + operator= ( const TcpSocket & ss ) throw ( Exception ); + + + inline virtual TcpSocket * + clone ( void ) const throw ( Exception ) + { + TcpSocket * s = new TcpSocket(*this); + } + + + inline const char * + getHost ( void ) const throw () + { + return host; + } + + + inline unsigned int + getPort ( void ) const throw () + { + return port; + } + + + virtual bool + open ( void ) throw ( Exception ); + + + inline virtual bool + isOpen ( void ) const throw () + { + return sockfd != 0; + } + + + virtual bool + canRead ( unsigned int sec, + unsigned int usec ) throw ( Exception ); + + + virtual unsigned int + read ( void * buf, + unsigned int len ) throw ( Exception ); + + + virtual bool + canWrite ( unsigned int sec, + unsigned int usec ) throw ( Exception ); + + + virtual unsigned int + write ( const void * buf, + unsigned int len ) throw ( Exception ); + + + inline virtual void + flush ( void ) throw ( Exception ) + { + } + + + virtual void + close ( void ) throw ( Exception ); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* TCP_SOCKET_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:55 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/Util.cpp b/darkice/tags/darkice/src/Util.cpp new file mode 100644 index 0000000..fc33632 --- /dev/null +++ b/darkice/tags/darkice/src/Util.cpp @@ -0,0 +1,91 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : Util.cpp + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Widely used utilities + + 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 + +#include "Util.h" + + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * File identity + *----------------------------------------------------------------------------*/ +static const char fileid[] = "$Id$"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Duplicate a string by allocating space with new[] + * The returned string must be freed with delete[] + *----------------------------------------------------------------------------*/ +char * +Util :: strDup( const char * str ) throw ( Exception ) +{ + size_t len; + char * s; + + if ( !str ) { + throw Exception( __FILE__, __LINE__, "no str"); + } + + len = strlen( str) + 1; + s = new char[len]; + memcpy( s, str, len); + + return s; +} + + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:55 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/Util.h b/darkice/tags/darkice/src/Util.h new file mode 100644 index 0000000..11229bb --- /dev/null +++ b/darkice/tags/darkice/src/Util.h @@ -0,0 +1,121 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : Util.h + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Widely used utilities + + 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 UTIL_H +#define UTIL_H + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#include "Exception.h" + + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/*------------------------------------------------------------------------------ + * + *----------------------------------------------------------------------------*/ +class Util +{ + private: + + + protected: + + inline + Util ( void ) throw ( Exception ) + { + throw Exception( __FILE__, __LINE__); + } + + + inline + Util ( const Util & e ) throw ( Exception ) + { + throw Exception( __FILE__, __LINE__); + } + + + inline + ~Util ( void ) throw ( Exception ) + { + throw Exception( __FILE__, __LINE__); + } + + + inline Util & + operator= ( const Util & e ) throw ( Exception ) + { + throw Exception( __FILE__, __LINE__); + } + + + + public: + + static char * + strDup( const char * str ) throw ( Exception ); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + + +#endif /* UTIL_H */ + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:55 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ + diff --git a/darkice/tags/darkice/src/files b/darkice/tags/darkice/src/files new file mode 100644 index 0000000..9f849ec --- /dev/null +++ b/darkice/tags/darkice/src/files @@ -0,0 +1,37 @@ +AudioEncoder.h +AudioSource.h +BufferedSink.cpp +BufferedSink.h +CastSink.cpp +CastSink.h +Connector.cpp +Connector.h +DarkIce.cpp +DarkIce.h +Exception.cpp +Exception.h +ExternalEncoder.cpp +ExternalEncoder.h +FileSink.cpp +FileSink.h +FileSource.cpp +FileSource.h +IceCast.cpp +IceCast.h +LameEncoder.cpp +LameEncoder.h +OssDspSource.cpp +OssDspSource.h +PipeSink.cpp +PipeSink.h +PipeSource.cpp +PipeSource.h +Ref.h +Referable.h +Sink.h +Source.h +TcpSocket.cpp +TcpSocket.h +Util.cpp +Util.h +main.cpp diff --git a/darkice/tags/darkice/src/main.cpp b/darkice/tags/darkice/src/main.cpp new file mode 100644 index 0000000..8a816ae --- /dev/null +++ b/darkice/tags/darkice/src/main.cpp @@ -0,0 +1,93 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2000 Tyrell Corporation. All rights reserved. + + Tyrell DarkIce + + File : main.cpp + Version : $Revision$ + Author : $Author$ + Location : $Source$ + + Abstract : + + Program entry point + + 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 + +#include "Ref.h" +#include "Exception.h" +#include "DarkIce.h" + + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +/*------------------------------------------------------------------------------ + * File identity + *----------------------------------------------------------------------------*/ +static const char fileid[] = "$Id$"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Program entry point + *----------------------------------------------------------------------------*/ +int +main ( + int argc, + char * argv[] ) +{ + int res = -1; + + try { + + Ref di = new DarkIce( argc, argv); + di->run(); + + } catch ( Exception & e ) { + cout << "Exception: " << e << endl << flush; + } + + return res; +} + + +/*------------------------------------------------------------------------------ + + $Source$ + + $Log$ + Revision 1.1 2000/11/05 10:05:52 darkeye + Initial revision + + +------------------------------------------------------------------------------*/ +