removed legacy branch

This commit is contained in:
darkeye 2006-11-20 17:05:08 +00:00
parent bb0fdb10b9
commit 11992d9cdd
39 changed files with 0 additions and 7101 deletions

View File

@ -1,252 +0,0 @@
/*------------------------------------------------------------------------------
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
------------------------------------------------------------------------------*/

View File

@ -1,171 +0,0 @@
/*------------------------------------------------------------------------------
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
------------------------------------------------------------------------------*/

View File

@ -1,302 +0,0 @@
/*------------------------------------------------------------------------------
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 <string.h>
#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
------------------------------------------------------------------------------*/

View File

@ -1,213 +0,0 @@
/*------------------------------------------------------------------------------
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> 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
------------------------------------------------------------------------------*/

View File

@ -1,144 +0,0 @@
/*------------------------------------------------------------------------------
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
------------------------------------------------------------------------------*/

View File

@ -1,326 +0,0 @@
/*------------------------------------------------------------------------------
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<TcpSocket> socket;
Ref<BufferedSink> 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
------------------------------------------------------------------------------*/

View File

@ -1,341 +0,0 @@
/*------------------------------------------------------------------------------
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<Sink>[1];
sinks[0] = sink;
} else {
unsigned int u;
Ref<Sink> * s = new Ref<Sink>[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<Sink> * 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<Sink>[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
------------------------------------------------------------------------------*/

View File

@ -1,172 +0,0 @@
/*------------------------------------------------------------------------------
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> source;
Ref<Sink> * 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
------------------------------------------------------------------------------*/

View File

@ -1,219 +0,0 @@
/*------------------------------------------------------------------------------
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 <unistd.h>
#include <stdlib.h>
#include <iostream.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <errno.h>
#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
------------------------------------------------------------------------------*/

View File

@ -1,165 +0,0 @@
/*------------------------------------------------------------------------------
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 <iostream.h>
#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<OssDspSource> dsp;
Ref<PipeSink> encInPipe;
Ref<BufferedSink> encIn;
Ref<Connector> encConnector;
Ref<LameEncoder> encoder;
Ref<PipeSource> encOutPipe;
Ref<TcpSocket> socket;
Ref<IceCast> ice;
Ref<Connector> 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
------------------------------------------------------------------------------*/

View File

@ -1,128 +0,0 @@
/*------------------------------------------------------------------------------
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 <string.h>
#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
------------------------------------------------------------------------------*/

View File

@ -1,199 +0,0 @@
/*------------------------------------------------------------------------------
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 <iostream.h>
/* ================================================================ 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
------------------------------------------------------------------------------*/

View File

@ -1,190 +0,0 @@
/*------------------------------------------------------------------------------
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 <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#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
------------------------------------------------------------------------------*/

View File

@ -1,243 +0,0 @@
/*------------------------------------------------------------------------------
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 <sys/types.h>
#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
------------------------------------------------------------------------------*/

View File

@ -1,280 +0,0 @@
/*------------------------------------------------------------------------------
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 <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/time.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#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
------------------------------------------------------------------------------*/

View File

@ -1,182 +0,0 @@
/*------------------------------------------------------------------------------
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
------------------------------------------------------------------------------*/

View File

@ -1,240 +0,0 @@
/*------------------------------------------------------------------------------
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 <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <unistd.h>
#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
------------------------------------------------------------------------------*/

View File

@ -1,163 +0,0 @@
/*------------------------------------------------------------------------------
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
------------------------------------------------------------------------------*/

View File

@ -1,179 +0,0 @@
/*------------------------------------------------------------------------------
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 <string.h>
#include <stdio.h>
#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 <password> /<mountpoint>\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
------------------------------------------------------------------------------*/

View File

@ -1,158 +0,0 @@
/*------------------------------------------------------------------------------
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
------------------------------------------------------------------------------*/

View File

@ -1,150 +0,0 @@
/*------------------------------------------------------------------------------
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 <stdio.h>
#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
------------------------------------------------------------------------------*/

View File

@ -1,244 +0,0 @@
/*------------------------------------------------------------------------------
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
------------------------------------------------------------------------------*/

View File

@ -1,34 +0,0 @@
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

View File

@ -1,238 +0,0 @@
/*------------------------------------------------------------------------------
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 <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <sys/soundcard.h>
#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
------------------------------------------------------------------------------*/

View File

@ -1,179 +0,0 @@
/*------------------------------------------------------------------------------
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
------------------------------------------------------------------------------*/

View File

@ -1,114 +0,0 @@
/*------------------------------------------------------------------------------
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 <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#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
------------------------------------------------------------------------------*/

View File

@ -1,141 +0,0 @@
/*------------------------------------------------------------------------------
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
------------------------------------------------------------------------------*/

View File

@ -1,94 +0,0 @@
/*------------------------------------------------------------------------------
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 <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#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
------------------------------------------------------------------------------*/

View File

@ -1,137 +0,0 @@
/*------------------------------------------------------------------------------
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
------------------------------------------------------------------------------*/

View File

@ -1,226 +0,0 @@
/*------------------------------------------------------------------------------
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<A> ref1 = a; // 1 reference to a
Ref<A> 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 T>
class Ref
{
private:
T* object;
protected:
public:
inline
Ref ( void ) throw ()
{
object = NULL;
}
inline
Ref ( const Ref<T> & 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<T> &
operator= ( Ref<T> other ) throw ( Exception )
{
set( other.object);
}
inline Ref<T> &
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.
*
* <P>It may not be bad idea to pass the <CODE>Ref</CODE>
* objects as method arguments.</P>
*
* @return Object pointer or <CODE>NULL</CODE>.
*/
inline T*
get ( void ) const throw ()
{
return object;
}
inline bool
operator== ( const Ref<T> & other ) const throw ()
{
return object == other.object;
}
inline bool
operator!= ( const Ref<T> & 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
------------------------------------------------------------------------------*/

View File

@ -1,151 +0,0 @@
/*------------------------------------------------------------------------------
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
------------------------------------------------------------------------------*/

View File

@ -1,139 +0,0 @@
/*------------------------------------------------------------------------------
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
------------------------------------------------------------------------------*/

View File

@ -1,135 +0,0 @@
/*------------------------------------------------------------------------------
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
------------------------------------------------------------------------------*/

View File

@ -1,317 +0,0 @@
/*------------------------------------------------------------------------------
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 <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <errno.h>
#include <sys/time.h>
#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
------------------------------------------------------------------------------*/

View File

@ -1,193 +0,0 @@
/*------------------------------------------------------------------------------
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
------------------------------------------------------------------------------*/

View File

@ -1,91 +0,0 @@
/*------------------------------------------------------------------------------
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 <string.h>
#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
------------------------------------------------------------------------------*/

View File

@ -1,121 +0,0 @@
/*------------------------------------------------------------------------------
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
------------------------------------------------------------------------------*/

View File

@ -1,37 +0,0 @@
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

View File

@ -1,93 +0,0 @@
/*------------------------------------------------------------------------------
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 <iostream.h>
#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<DarkIce> 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
------------------------------------------------------------------------------*/