added local dump file possibility
This commit is contained in:
parent
63e7805dd7
commit
2ddb545512
|
@ -5,7 +5,9 @@ DarkIce 0.8
|
|||
o fix: DarkIce now reports public streams correctly
|
||||
thanks to Tom Gray, <tomg@future-i.com>
|
||||
o made up-to-date with Ogg Vorbis rc3 libs
|
||||
thanks to Michael Smith, <msmith@labyrinth.net.au>
|
||||
o made up-to-date with current IceCast2 cvs version
|
||||
o added local stream dump possibility
|
||||
|
||||
19-10-2001: DarkIce 0.7 released
|
||||
|
||||
|
|
|
@ -7,5 +7,4 @@ o libtoolize ?
|
|||
o revisit real-time scheduling and one-thread-per-connection
|
||||
o look into performance
|
||||
o create proper error-reporting module
|
||||
o add local stream dump capability
|
||||
o add Ogg Vorbis resampling
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
.TH darkice.cfg 5 "October 19, 2001" "DarkIce" "DarkIce live audio streamer"
|
||||
.TH darkice.cfg 5 "February 20, 2002" "DarkIce" "DarkIce live audio streamer"
|
||||
.SH NAME
|
||||
darkice.cfg \- configuration file for darkice
|
||||
.SH DESCRIPTION
|
||||
|
@ -134,6 +134,11 @@ The file the
|
|||
server should dump the contents of
|
||||
this stream on its side.
|
||||
.TP
|
||||
.I localDumpFile
|
||||
Dump the same mp3 data sent to the
|
||||
.B IceCast
|
||||
server to this local file.
|
||||
.TP
|
||||
.I lowpass
|
||||
Lowpass filter setting for the lame encoder. If not set or set to 0,
|
||||
the encoder's default behaviour is used. If set to -1, the filter is
|
||||
|
@ -201,6 +206,11 @@ Genre of the stream
|
|||
.TP
|
||||
.I public
|
||||
"yes" or "no", wether the stream is public
|
||||
.TP
|
||||
.I localDumpFile
|
||||
Dump the same Ogg Vorbis data sent to the
|
||||
.B IceCast2
|
||||
server to this local file.
|
||||
|
||||
.PP
|
||||
.B [shoutcast-x]
|
||||
|
@ -271,6 +281,11 @@ disabled.
|
|||
Highpass filter setting for the lame encoder. If not set or set to 0,
|
||||
the encoder's default behaviour is used. If set to -1, the filter is
|
||||
disabled.
|
||||
.TP
|
||||
.I localDumpFile
|
||||
Dump the same mp3 data sent to the
|
||||
.B ShoutCast
|
||||
server to this local file.
|
||||
|
||||
.PP
|
||||
A sample configuration file follows. This file makes
|
||||
|
@ -287,8 +302,12 @@ to mp3 players.
|
|||
The encoding session will be stored by
|
||||
.B IceCast
|
||||
in the file
|
||||
.I /tmp/live96.mp3
|
||||
on the server side.
|
||||
.I /tmp/server-dump.mp3
|
||||
on the server side, and also by
|
||||
.B DarkIce
|
||||
in the file
|
||||
.I /tmp/encoder-dump.mp3
|
||||
on the encoder side.
|
||||
|
||||
.nf
|
||||
[general]
|
||||
|
@ -312,7 +331,8 @@ description = This is only a trial
|
|||
url = http://www.yourserver.com
|
||||
genre = live
|
||||
public = no
|
||||
remoteDumpFile = /tmp/live96.mp3
|
||||
remoteDumpFile = /tmp/server-dump.mp3
|
||||
localDumpFile = /tmp/encoder-dump.mp3
|
||||
.fi
|
||||
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ static const char fileid[] = "$Id$";
|
|||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
CastSink :: init ( TcpSocket * socket,
|
||||
Sink * streamDump,
|
||||
const char * password,
|
||||
unsigned int bitRate,
|
||||
const char * name,
|
||||
|
@ -65,6 +66,7 @@ CastSink :: init ( TcpSocket * socket,
|
|||
throw ( Exception )
|
||||
{
|
||||
this->socket = socket;
|
||||
this->streamDump = streamDump;
|
||||
this->password = Util::strDup( password);
|
||||
this->bitRate = bitRate;
|
||||
this->name = name ? Util::strDup( name) : 0;
|
||||
|
@ -121,6 +123,14 @@ CastSink :: open ( void ) throw ( Exception )
|
|||
return false;
|
||||
}
|
||||
|
||||
if ( streamDump != 0 ) {
|
||||
if ( !streamDump->isOpen() ) {
|
||||
if ( !streamDump->open() ) {
|
||||
reportEvent( 2, "can't open stream dump");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -131,6 +141,9 @@ CastSink :: open ( void ) throw ( Exception )
|
|||
$Source$
|
||||
|
||||
$Log$
|
||||
Revision 1.6 2002/02/20 11:54:11 darkeye
|
||||
added local dump file possibility
|
||||
|
||||
Revision 1.5 2001/09/09 11:27:31 darkeye
|
||||
added support for ShoutCast servers
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
/* ============================================================ include files */
|
||||
|
||||
#include "Ref.h"
|
||||
#include "Reporter.h"
|
||||
#include "Sink.h"
|
||||
#include "TcpSocket.h"
|
||||
#include "BufferedSink.h"
|
||||
|
@ -58,7 +59,7 @@
|
|||
* @author $Author$
|
||||
* @version $Revision$
|
||||
*/
|
||||
class CastSink : public Sink
|
||||
class CastSink : public Sink, public virtual Reporter
|
||||
{
|
||||
private:
|
||||
|
||||
|
@ -72,6 +73,11 @@ class CastSink : public Sink
|
|||
*/
|
||||
Ref<BufferedSink> bufferedSink;
|
||||
|
||||
/**
|
||||
* An optional Sink to enable stream dumps.
|
||||
*/
|
||||
Ref<Sink> streamDump;
|
||||
|
||||
/**
|
||||
* Duration of the BufferedSink buffer in seconds.
|
||||
*/
|
||||
|
@ -123,6 +129,7 @@ class CastSink : public Sink
|
|||
*/
|
||||
void
|
||||
init ( TcpSocket * socket,
|
||||
Sink * streamDump,
|
||||
const char * password,
|
||||
unsigned int bitRate,
|
||||
const char * name,
|
||||
|
@ -198,6 +205,7 @@ class CastSink : public Sink
|
|||
* @param genre genre of the stream.
|
||||
* @param bitRate bitrate of the stream (e.g. mp3 bitrate).
|
||||
* @param isPublic is the stream public?
|
||||
* @param streamDump a Sink to dump the streamed binary data to
|
||||
* @param bufferDuration duration of the BufferedSink buffer
|
||||
* in seconds.
|
||||
* @exception Exception
|
||||
|
@ -210,10 +218,12 @@ class CastSink : public Sink
|
|||
const char * url = 0,
|
||||
const char * genre = 0,
|
||||
bool isPublic = false,
|
||||
Sink * streamDump = 0,
|
||||
unsigned int bufferDuration = 10 )
|
||||
throw ( Exception )
|
||||
{
|
||||
init( socket,
|
||||
streamDump,
|
||||
password,
|
||||
bitRate,
|
||||
name,
|
||||
|
@ -233,6 +243,7 @@ class CastSink : public Sink
|
|||
: Sink( cs )
|
||||
{
|
||||
init( cs.socket.get(),
|
||||
cs.streamDump.get(),
|
||||
cs.password,
|
||||
cs.bitRate,
|
||||
cs.name,
|
||||
|
@ -267,6 +278,7 @@ class CastSink : public Sink
|
|||
strip();
|
||||
Sink::operator=( cs );
|
||||
init( cs.socket.get(),
|
||||
cs.streamDump.get(),
|
||||
cs.password,
|
||||
cs.bitRate,
|
||||
cs.name,
|
||||
|
@ -328,6 +340,10 @@ class CastSink : public Sink
|
|||
write ( const void * buf,
|
||||
unsigned int len ) throw ( Exception )
|
||||
{
|
||||
if ( streamDump != 0 ) {
|
||||
streamDump->write( buf, len);
|
||||
}
|
||||
|
||||
return getSink()->write( buf, len);
|
||||
}
|
||||
|
||||
|
@ -339,6 +355,10 @@ class CastSink : public Sink
|
|||
inline virtual void
|
||||
flush ( void ) throw ( Exception )
|
||||
{
|
||||
if ( streamDump != 0 ) {
|
||||
streamDump->flush();
|
||||
}
|
||||
|
||||
return getSink()->flush();
|
||||
}
|
||||
|
||||
|
@ -350,6 +370,10 @@ class CastSink : public Sink
|
|||
inline virtual void
|
||||
close ( void ) throw ( Exception )
|
||||
{
|
||||
if ( streamDump != 0 ) {
|
||||
streamDump->close();
|
||||
}
|
||||
|
||||
return getSink()->close();
|
||||
}
|
||||
|
||||
|
@ -447,6 +471,9 @@ class CastSink : public Sink
|
|||
$Source$
|
||||
|
||||
$Log$
|
||||
Revision 1.7 2002/02/20 11:54:11 darkeye
|
||||
added local dump file possibility
|
||||
|
||||
Revision 1.6 2001/09/09 11:27:31 darkeye
|
||||
added support for ShoutCast servers
|
||||
|
||||
|
|
|
@ -76,6 +76,7 @@
|
|||
#include "IceCast.h"
|
||||
#include "IceCast2.h"
|
||||
#include "ShoutCast.h"
|
||||
#include "FileSink.h"
|
||||
#include "DarkIce.h"
|
||||
|
||||
#ifdef HAVE_LAME_LIB
|
||||
|
@ -212,6 +213,8 @@ DarkIce :: configIceCast ( const Config & config,
|
|||
bool isPublic = false;
|
||||
int lowpass = 0;
|
||||
int highpass = 0;
|
||||
const char * localDumpName = 0;
|
||||
FileSink * localDumpFile = 0;
|
||||
|
||||
str = cs->get( "sampleRate");
|
||||
sampleRate = str ? Util::strToL( str) : dsp->getSampleRate();
|
||||
|
@ -235,9 +238,22 @@ DarkIce :: configIceCast ( const Config & config,
|
|||
lowpass = str ? Util::strToL( str) : 0;
|
||||
str = cs->get( "highpass");
|
||||
highpass = str ? Util::strToL( str) : 0;
|
||||
localDumpName = cs->get( "localDumpFile");
|
||||
|
||||
// go on and create the things
|
||||
|
||||
// check for and create the local dump file if needed
|
||||
if ( localDumpName != 0 ) {
|
||||
localDumpFile = new FileSink( localDumpName);
|
||||
if ( !localDumpFile->exists() ) {
|
||||
if ( !localDumpFile->create() ) {
|
||||
reportEvent( 1, "can't create local dump file",
|
||||
localDumpName);
|
||||
localDumpFile = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// encoder related stuff
|
||||
unsigned int bs = bufferSecs *
|
||||
(dsp->getBitsPerSample() / 8) *
|
||||
|
@ -256,7 +272,8 @@ DarkIce :: configIceCast ( const Config & config,
|
|||
url,
|
||||
genre,
|
||||
isPublic,
|
||||
remoteDumpFile );
|
||||
remoteDumpFile,
|
||||
localDumpFile );
|
||||
|
||||
audioOuts[u].encoder = new LameLibEncoder( audioOuts[u].server.get(),
|
||||
dsp.get(),
|
||||
|
@ -311,6 +328,8 @@ DarkIce :: configIceCast2 ( const Config & config,
|
|||
const char * url = 0;
|
||||
const char * genre = 0;
|
||||
bool isPublic = false;
|
||||
const char * localDumpName = 0;
|
||||
FileSink * localDumpFile = 0;
|
||||
|
||||
str = cs->getForSure( "format", " missing in section ", stream);
|
||||
if ( Util::strEq( str, "vorbis") ) {
|
||||
|
@ -341,9 +360,22 @@ DarkIce :: configIceCast2 ( const Config & config,
|
|||
genre = cs->get( "genre");
|
||||
str = cs->get( "public");
|
||||
isPublic = str ? (Util::strEq( str, "yes") ? true : false) : false;
|
||||
localDumpName = cs->get( "localDumpFile");
|
||||
|
||||
// go on and create the things
|
||||
|
||||
// check for and create the local dump file if needed
|
||||
if ( localDumpName != 0 ) {
|
||||
localDumpFile = new FileSink( localDumpName);
|
||||
if ( !localDumpFile->exists() ) {
|
||||
if ( !localDumpFile->create() ) {
|
||||
reportEvent( 1, "can't create local dump file",
|
||||
localDumpName);
|
||||
localDumpFile = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// encoder related stuff
|
||||
unsigned int bs = bufferSecs *
|
||||
(dsp->getBitsPerSample() / 8) *
|
||||
|
@ -362,7 +394,8 @@ DarkIce :: configIceCast2 ( const Config & config,
|
|||
description,
|
||||
url,
|
||||
genre,
|
||||
isPublic );
|
||||
isPublic,
|
||||
localDumpFile );
|
||||
|
||||
switch ( format ) {
|
||||
case IceCast2::mp3:
|
||||
|
@ -456,6 +489,8 @@ DarkIce :: configShoutCast ( const Config & config,
|
|||
const char * irc = 0;
|
||||
const char * aim = 0;
|
||||
const char * icq = 0;
|
||||
const char * localDumpName = 0;
|
||||
FileSink * localDumpFile = 0;
|
||||
|
||||
str = cs->get( "sampleRate");
|
||||
sampleRate = str ? Util::strToL( str) : dsp->getSampleRate();
|
||||
|
@ -477,9 +512,22 @@ DarkIce :: configShoutCast ( const Config & config,
|
|||
irc = cs->get( "irc");
|
||||
aim = cs->get( "aim");
|
||||
icq = cs->get( "icq");
|
||||
localDumpName = cs->get( "localDumpFile");
|
||||
|
||||
// go on and create the things
|
||||
|
||||
// check for and create the local dump file if needed
|
||||
if ( localDumpName != 0 ) {
|
||||
localDumpFile = new FileSink( localDumpName);
|
||||
if ( !localDumpFile->exists() ) {
|
||||
if ( !localDumpFile->create() ) {
|
||||
reportEvent( 1, "can't create local dump file",
|
||||
localDumpName);
|
||||
localDumpFile = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// encoder related stuff
|
||||
unsigned int bs = bufferSecs *
|
||||
(dsp->getBitsPerSample() / 8) *
|
||||
|
@ -498,7 +546,8 @@ DarkIce :: configShoutCast ( const Config & config,
|
|||
isPublic,
|
||||
irc,
|
||||
aim,
|
||||
icq );
|
||||
icq,
|
||||
localDumpFile );
|
||||
|
||||
audioOuts[u].encoder = new LameLibEncoder( audioOuts[u].server.get(),
|
||||
dsp.get(),
|
||||
|
@ -648,6 +697,9 @@ DarkIce :: run ( void ) throw ( Exception )
|
|||
$Source$
|
||||
|
||||
$Log$
|
||||
Revision 1.24 2002/02/20 11:54:11 darkeye
|
||||
added local dump file possibility
|
||||
|
||||
Revision 1.23 2002/02/20 10:35:35 darkeye
|
||||
updated to work with Ogg Vorbis libs rc3 and current IceCast2 cvs
|
||||
|
||||
|
|
|
@ -0,0 +1,338 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
|
||||
|
||||
Tyrell DarkIce
|
||||
|
||||
File : FileSink.cpp
|
||||
Version : $Revision$
|
||||
Author : $Author$
|
||||
Location : $Source$
|
||||
|
||||
Copyright notice:
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#error need unistd.h
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDLIB_H
|
||||
#include <stdlib.h>
|
||||
#else
|
||||
#error need stdlib.h
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#else
|
||||
#error need sys/types.h
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_ERRNO_H
|
||||
#include <errno.h>
|
||||
#else
|
||||
#error need errno.h
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
#include <sys/stat.h>
|
||||
#else
|
||||
#error need sys/stat.h
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#else
|
||||
#error need fcntl.h
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#else
|
||||
#error need sys/time.h
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STRING_H
|
||||
#include <string.h>
|
||||
#else
|
||||
#error need string.h
|
||||
#endif
|
||||
|
||||
|
||||
#include "Util.h"
|
||||
#include "Exception.h"
|
||||
#include "FileSink.h"
|
||||
|
||||
|
||||
/* =================================================== local data structures */
|
||||
|
||||
|
||||
/* ================================================ local constants & macros */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* File identity
|
||||
*----------------------------------------------------------------------------*/
|
||||
static const char fileid[] = "$Id$";
|
||||
|
||||
|
||||
/* =============================================== local function prototypes */
|
||||
|
||||
|
||||
/* ============================================================= module code */
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Initialize the object
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
FileSink :: init ( const char * name ) throw ( Exception )
|
||||
{
|
||||
fileName = Util::strDup( name);
|
||||
fileDescriptor = 0;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* De-initialize the object
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
FileSink :: strip ( void) throw ( Exception )
|
||||
{
|
||||
if ( isOpen() ) {
|
||||
close();
|
||||
}
|
||||
|
||||
delete[] fileName;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Copy Constructor
|
||||
*----------------------------------------------------------------------------*/
|
||||
FileSink :: FileSink ( const FileSink & fs ) throw ( Exception )
|
||||
: Sink( fs )
|
||||
{
|
||||
int fd;
|
||||
|
||||
init( fs.fileName);
|
||||
|
||||
if ( (fd = fs.fileDescriptor ? dup( fs.fileDescriptor) : 0) == -1 ) {
|
||||
strip();
|
||||
throw Exception( __FILE__, __LINE__, "dup failure");
|
||||
}
|
||||
|
||||
fileDescriptor = fd;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Assignment operator
|
||||
*----------------------------------------------------------------------------*/
|
||||
FileSink &
|
||||
FileSink :: operator= ( const FileSink & fs ) throw ( Exception )
|
||||
{
|
||||
if ( this != &fs ) {
|
||||
int fd;
|
||||
|
||||
/* first strip */
|
||||
strip();
|
||||
|
||||
|
||||
/* then build up */
|
||||
Sink::operator=( fs );
|
||||
|
||||
init( fs.fileName);
|
||||
|
||||
if ( (fd = fs.fileDescriptor ? dup( fs.fileDescriptor) : 0) == -1 ) {
|
||||
strip();
|
||||
throw Exception( __FILE__, __LINE__, "dup failure");
|
||||
}
|
||||
|
||||
fileDescriptor = fd;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Check wether a file exists and is regular file
|
||||
*----------------------------------------------------------------------------*/
|
||||
bool
|
||||
FileSink :: exists ( void ) const throw ()
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if ( stat( (const char*)fileName, &st) == -1 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return S_ISREG( st.st_mode);
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* 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 ) {
|
||||
reportEvent( 3, "can't create file", fileName, errno);
|
||||
return false;
|
||||
}
|
||||
|
||||
::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.7 2002/02/20 11:54:11 darkeye
|
||||
added local dump file possibility
|
||||
|
||||
Revision 1.5 2001/09/11 15:05:21 darkeye
|
||||
added Solaris support
|
||||
|
||||
Revision 1.4 2001/08/26 20:44:30 darkeye
|
||||
removed external command-line encoder support
|
||||
replaced it with a shared-object support for lame with the possibility
|
||||
of static linkage
|
||||
|
||||
Revision 1.3 2000/11/11 12:33:13 darkeye
|
||||
added kdoc-style documentation
|
||||
|
||||
Revision 1.2 2000/11/05 14:08:27 darkeye
|
||||
changed builting to an automake / autoconf environment
|
||||
|
||||
Revision 1.1.1.1 2000/11/05 10:05:51 darkeye
|
||||
initial version
|
||||
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
|
@ -0,0 +1,269 @@
|
|||
/*------------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2000 Tyrell Corporation. All rights reserved.
|
||||
|
||||
Tyrell DarkIce
|
||||
|
||||
File : FileSink.h
|
||||
Version : $Revision$
|
||||
Author : $Author$
|
||||
Location : $Source$
|
||||
|
||||
Copyright notice:
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
#ifndef FILE_SINK_H
|
||||
#define FILE_SINK_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#error This is a C++ include file
|
||||
#endif
|
||||
|
||||
|
||||
/* ============================================================ include files */
|
||||
|
||||
#include "Reporter.h"
|
||||
#include "Sink.h"
|
||||
|
||||
|
||||
/* ================================================================ constants */
|
||||
|
||||
|
||||
/* =================================================================== macros */
|
||||
|
||||
|
||||
/* =============================================================== data types */
|
||||
|
||||
/**
|
||||
* File data output
|
||||
*
|
||||
* @author $Author$
|
||||
* @version $Revision$
|
||||
*/
|
||||
class FileSink : public Sink, public virtual Reporter
|
||||
{
|
||||
private:
|
||||
|
||||
/**
|
||||
* Name of the file represented by the FileSink.
|
||||
*/
|
||||
char * fileName;
|
||||
|
||||
/**
|
||||
* Initialize the object.
|
||||
*
|
||||
* @param name name of the file to be represented by the object.
|
||||
* @exception Exception
|
||||
*/
|
||||
void
|
||||
init ( const char * name ) throw ( Exception );
|
||||
|
||||
/**
|
||||
* De-initialize the object.
|
||||
*
|
||||
* @exception Exception
|
||||
*/
|
||||
void
|
||||
strip ( void ) throw ( Exception );
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Low-level file descriptor for the file represented by this object.
|
||||
*/
|
||||
int fileDescriptor;
|
||||
|
||||
/**
|
||||
* Default constructor. Always throws an Exception.
|
||||
*
|
||||
* @exception Exception
|
||||
*/
|
||||
inline
|
||||
FileSink ( void ) throw ( Exception )
|
||||
{
|
||||
throw Exception( __FILE__, __LINE__);
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Constructor by a file name.
|
||||
*
|
||||
* @param name name of the file to be represented by the object.
|
||||
* @exception Exception
|
||||
*/
|
||||
inline
|
||||
FileSink( const char * name ) throw ( Exception )
|
||||
{
|
||||
init( name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy constructor.
|
||||
*
|
||||
* @param fsink the FileSink to copy.
|
||||
* @exception Exception
|
||||
*/
|
||||
FileSink( const FileSink & fsink ) throw ( Exception );
|
||||
|
||||
/**
|
||||
* Destructor.
|
||||
*
|
||||
* @exception Exception
|
||||
*/
|
||||
inline virtual
|
||||
~FileSink( void ) throw ( Exception )
|
||||
{
|
||||
strip();
|
||||
}
|
||||
|
||||
/**
|
||||
* Assignment operator.
|
||||
*
|
||||
* @param fs the FileSink to assign to this object.
|
||||
* @return a reference to this object.
|
||||
* @exception Exception
|
||||
*/
|
||||
virtual FileSink &
|
||||
operator= ( const FileSink & fs ) throw ( Exception );
|
||||
|
||||
/**
|
||||
* Get the file name this FileSink represents.
|
||||
*
|
||||
* @return the file name this FileSink represents.
|
||||
*/
|
||||
inline const char *
|
||||
getFileName ( void ) const throw ()
|
||||
{
|
||||
return fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for the existence of the file this FileSink represents.
|
||||
*
|
||||
* @return true if the file exists and is a regular file,
|
||||
* false otherwise.
|
||||
*/
|
||||
virtual bool
|
||||
exists ( void ) const throw ();
|
||||
|
||||
/**
|
||||
* Create the file.
|
||||
*
|
||||
* @return true if creation was successful, false otherwise.
|
||||
* @exception Exception
|
||||
*/
|
||||
virtual bool
|
||||
create ( void ) throw ( Exception );
|
||||
|
||||
/**
|
||||
* Open the file. Truncates the file.
|
||||
*
|
||||
* @return true if opening was successful, false otherwise.
|
||||
* @exception Exception
|
||||
*/
|
||||
virtual bool
|
||||
open ( void ) throw ( Exception );
|
||||
|
||||
/**
|
||||
* Check if the FileSink is open.
|
||||
*
|
||||
* @return true if the FileSink is open, false otherwise.
|
||||
*/
|
||||
inline virtual bool
|
||||
isOpen ( void ) const throw ()
|
||||
{
|
||||
return fileDescriptor != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the FileSink is ready to accept data.
|
||||
* Blocks until the specified time for data to be available.
|
||||
*
|
||||
* @param sec the maximum seconds to block.
|
||||
* @param usec micro seconds to block after the full seconds.
|
||||
* @return true if the Sink is ready to accept data, false otherwise.
|
||||
* @exception Exception
|
||||
*/
|
||||
virtual bool
|
||||
canWrite ( unsigned int sec,
|
||||
unsigned int usec ) throw ( Exception );
|
||||
|
||||
/**
|
||||
* Write data to the FileSink.
|
||||
*
|
||||
* @param buf the data to write.
|
||||
* @param len number of bytes to write from buf.
|
||||
* @return the number of bytes written (may be less than len).
|
||||
* @exception Exception
|
||||
*/
|
||||
virtual unsigned int
|
||||
write ( const void * buf,
|
||||
unsigned int len ) throw ( Exception );
|
||||
|
||||
/**
|
||||
* This is a no-op in this FileSink.
|
||||
*
|
||||
* @exception Exception
|
||||
*/
|
||||
inline virtual void
|
||||
flush ( void ) throw ( Exception )
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the FileSink.
|
||||
*
|
||||
* @exception Exception
|
||||
*/
|
||||
virtual void
|
||||
close ( void ) throw ( Exception );
|
||||
};
|
||||
|
||||
|
||||
/* ================================================= external data structures */
|
||||
|
||||
|
||||
/* ====================================================== function prototypes */
|
||||
|
||||
|
||||
|
||||
#endif /* FILE_SINK_H */
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
|
||||
$Source$
|
||||
|
||||
$Log$
|
||||
Revision 1.5 2002/02/20 11:54:11 darkeye
|
||||
added local dump file possibility
|
||||
|
||||
Revision 1.3 2000/11/11 12:33:13 darkeye
|
||||
added kdoc-style documentation
|
||||
|
||||
Revision 1.2 2000/11/05 17:37:24 darkeye
|
||||
removed clone() functions
|
||||
|
||||
Revision 1.1.1.1 2000/11/05 10:05:51 darkeye
|
||||
initial version
|
||||
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
|
@ -151,6 +151,7 @@ class IceCast : public CastSink
|
|||
const char * genre = 0,
|
||||
bool isPublic = false,
|
||||
const char * remoteDumpFile = 0,
|
||||
Sink * streamDump = 0,
|
||||
unsigned int bufferDuration = 10 )
|
||||
throw ( Exception )
|
||||
: CastSink( socket,
|
||||
|
@ -160,6 +161,7 @@ class IceCast : public CastSink
|
|||
url,
|
||||
genre,
|
||||
isPublic,
|
||||
streamDump,
|
||||
bufferDuration )
|
||||
{
|
||||
init( mountPoint, description, remoteDumpFile);
|
||||
|
@ -261,6 +263,9 @@ class IceCast : public CastSink
|
|||
$Source$
|
||||
|
||||
$Log$
|
||||
Revision 1.7 2002/02/20 11:54:11 darkeye
|
||||
added local dump file possibility
|
||||
|
||||
Revision 1.6 2001/09/09 11:27:31 darkeye
|
||||
added support for ShoutCast servers
|
||||
|
||||
|
|
|
@ -158,6 +158,7 @@ class IceCast2 : public CastSink
|
|||
const char * url = 0,
|
||||
const char * genre = 0,
|
||||
bool isPublic = false,
|
||||
Sink * streamDump = 0,
|
||||
unsigned int bufferDuration = 10 )
|
||||
throw ( Exception )
|
||||
: CastSink( socket,
|
||||
|
@ -167,6 +168,7 @@ class IceCast2 : public CastSink
|
|||
url,
|
||||
genre,
|
||||
isPublic,
|
||||
streamDump,
|
||||
bufferDuration )
|
||||
{
|
||||
init( format, mountPoint, description);
|
||||
|
@ -268,6 +270,9 @@ class IceCast2 : public CastSink
|
|||
$Source$
|
||||
|
||||
$Log$
|
||||
Revision 1.3 2002/02/20 11:54:11 darkeye
|
||||
added local dump file possibility
|
||||
|
||||
Revision 1.2 2002/02/20 10:35:35 darkeye
|
||||
updated to work with Ogg Vorbis libs rc3 and current IceCast2 cvs
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
bin_PROGRAMS = darkice
|
||||
CXXFLAGS = -O2 -Wall
|
||||
CXXFLAGS = -g -O2 -Wall
|
||||
INCLUDES = @LAME_INCFLAGS@ @VORBIS_INCFLAGS@
|
||||
LDADD = @LAME_LDFLAGS@ @VORBIS_LDFLAGS@
|
||||
|
||||
|
@ -9,6 +9,8 @@ darkice_SOURCES = AudioEncoder.h\
|
|||
BufferedSink.h\
|
||||
CastSink.cpp\
|
||||
CastSink.h\
|
||||
FileSink.h\
|
||||
FileSink.cpp\
|
||||
Connector.cpp\
|
||||
Connector.h\
|
||||
DarkIce.cpp\
|
||||
|
|
|
@ -151,6 +151,7 @@ class ShoutCast : public CastSink
|
|||
const char * irc = 0,
|
||||
const char * aim = 0,
|
||||
const char * icq = 0,
|
||||
Sink * streamDump = 0,
|
||||
unsigned int bufferDuration = 10 )
|
||||
throw ( Exception )
|
||||
: CastSink( socket,
|
||||
|
@ -160,6 +161,7 @@ class ShoutCast : public CastSink
|
|||
url,
|
||||
genre,
|
||||
isPublic,
|
||||
streamDump,
|
||||
bufferDuration )
|
||||
{
|
||||
init( irc, aim, icq);
|
||||
|
@ -257,6 +259,9 @@ class ShoutCast : public CastSink
|
|||
$Source$
|
||||
|
||||
$Log$
|
||||
Revision 1.2 2002/02/20 11:54:11 darkeye
|
||||
added local dump file possibility
|
||||
|
||||
Revision 1.1 2001/09/09 11:27:31 darkeye
|
||||
added support for ShoutCast servers
|
||||
|
||||
|
|
Loading…
Reference in New Issue