From 8fd167a179ea768a9968cef33abbc2c1c835f0ac Mon Sep 17 00:00:00 2001 From: darkeye Date: Sat, 19 Oct 2002 12:24:55 +0000 Subject: [PATCH] anged internals so that now each encoding/server connection is a separate thread --- darkice/trunk/ChangeLog | 2 + darkice/trunk/TODO | 2 +- darkice/trunk/configure.in | 3 +- darkice/trunk/src/Connector.cpp | 9 +++++ darkice/trunk/src/Connector.h | 66 +++++++++++++++++---------------- darkice/trunk/src/DarkIce.cpp | 7 +++- darkice/trunk/src/Makefile.am | 2 + 7 files changed, 57 insertions(+), 34 deletions(-) diff --git a/darkice/trunk/ChangeLog b/darkice/trunk/ChangeLog index db56a59..b5fce78 100644 --- a/darkice/trunk/ChangeLog +++ b/darkice/trunk/ChangeLog @@ -2,6 +2,8 @@ DarkIce next release o ported to FreeBSD (removed reference to MSG_NOSIGNAL in TcpSocket.cpp) o bug fix: maximum bitrate setting fixed for Ogg Vorbis streams + o changed internals so that now each encoding/server connection is + a separate thread 20-08-2002: DarkIce 0.11 released diff --git a/darkice/trunk/TODO b/darkice/trunk/TODO index 8544fa9..e32875b 100644 --- a/darkice/trunk/TODO +++ b/darkice/trunk/TODO @@ -3,7 +3,7 @@ o make a master config file, and a small one ? o reconnect to server if connection is dropped o add support for multiple servers for one stream ? o libtoolize ? -o revisit real-time scheduling and one-thread-per-connection +o revisit real-time scheduling o look into performance o create proper error-reporting module o set comment fields for Ogg Vorbis streams as in diff --git a/darkice/trunk/configure.in b/darkice/trunk/configure.in index e6c7d24..70f1dff 100644 --- a/darkice/trunk/configure.in +++ b/darkice/trunk/configure.in @@ -11,7 +11,7 @@ dnl AC_STDC_HEADERS AC_HAVE_HEADERS(errno.h fcntl.h stdio.h stdlib.h string.h unistd.h limits.h) AC_HAVE_HEADERS(signal.h time.h sys/time.h sys/types.h sys/wait.h math.h) AC_HAVE_HEADERS(netdb.h netinet/in.h sys/ioctl.h sys/socket.h sys/stat.h) -AC_HAVE_HEADERS(sched.h) +AC_HAVE_HEADERS(sched.h pthread.h) AC_HAVE_HEADERS(sys/soundcard.h sys/audio.h) AC_HEADER_SYS_WAIT() @@ -21,6 +21,7 @@ AC_TYPE_SIZE_T() AC_CHECK_LIB( socket, socket) AC_CHECK_LIB( nsl, gethostbyname) AC_CHECK_LIB( rt, sched_getscheduler) +AC_CHECK_LIB( pthread, pthread_create) SYSTEM_INCLUDE=/usr/include diff --git a/darkice/trunk/src/Connector.cpp b/darkice/trunk/src/Connector.cpp index 65d33a1..67f79ef 100644 --- a/darkice/trunk/src/Connector.cpp +++ b/darkice/trunk/src/Connector.cpp @@ -161,6 +161,10 @@ Connector :: detach ( Sink * sink ) throw ( Exception ) } else if ( numSinks == 1 ) { + if ( sinks[0].get() != sink ) { + return false; + } + sinks[0] = 0; delete[] sinks; sinks = 0; @@ -286,6 +290,7 @@ Connector :: transfer ( unsigned long bytes, if ( sinks[u]->canWrite( sec, usec) ) { try { + /* we expect the sink to accept all data written */ e = sinks[u]->write( buf, d); } catch ( Exception & e ) { sinks[u]->close(); @@ -341,6 +346,10 @@ Connector :: close ( void ) throw ( Exception ) $Source$ $Log$ + Revision 1.10 2002/10/19 12:24:55 darkeye + anged internals so that now each encoding/server connection is + a separate thread + Revision 1.9 2002/08/02 17:59:17 darkeye bug fix: when the last server dropped connection, darkice crashed diff --git a/darkice/trunk/src/Connector.h b/darkice/trunk/src/Connector.h index 903e999..d4af39c 100644 --- a/darkice/trunk/src/Connector.h +++ b/darkice/trunk/src/Connector.h @@ -61,21 +61,6 @@ class Connector : public virtual Referable, public virtual Reporter { private: - /** - * The source to read from. - */ - Ref source; - - /** - * The sinks to connect the source to. - */ - Ref * sinks; - - /** - * Total number of sinks. - */ - unsigned int numSinks; - /** * Initialize the object. * @@ -96,6 +81,21 @@ class Connector : public virtual Referable, public virtual Reporter protected: + /** + * The source to read from. + */ + Ref source; + + /** + * The sinks to connect the source to. + */ + Ref * sinks; + + /** + * Total number of sinks. + */ + unsigned int numSinks; + /** * Default constructor. Always throws an Exception. * @@ -107,6 +107,16 @@ class Connector : public virtual Referable, public virtual Reporter throw Exception( __FILE__, __LINE__); } + /** + * Detach an already attached Sink from the Source of this Connector. + * + * @param sink the Sink to detach. + * @return true if the detachment was successful, false otherwise. + * @exception Exception + */ + virtual bool + detach ( Sink * sink ) throw ( Exception ); + public: @@ -172,7 +182,7 @@ class Connector : public virtual Referable, public virtual Reporter * @return the number of Sinks in the Connector. * @exception Exception */ - inline unsigned int + inline virtual unsigned int getNumSinks ( void ) const throw () { return numSinks; @@ -184,26 +194,16 @@ class Connector : public virtual Referable, public virtual Reporter * @param sink the Sink to attach. * @exception Exception */ - void + virtual void attach ( Sink * sink ) throw ( Exception ); - /** - * Detach an already attached Sink from the Source of this Connector. - * - * @param sink the Sink to detach. - * @return true if the detachment was successful, false otherwise. - * @exception Exception - */ - bool - detach ( Sink * sink ) throw ( Exception ); - /** * Open the connector. Opens the Source and the Sinks if necessary. * * @return true if opening was successful, false otherwise. * @exception Exception */ - bool + virtual bool open ( void ) throw ( Exception ); /** @@ -222,13 +222,13 @@ class Connector : public virtual Referable, public virtual Reporter * @param sec the number of seconds to wait for the Source to have * data available in each turn, and the number of seconds * to wait for the Sinks to accept data. - * @param usec the number of micros seconds to wait for the Source to + * @param usec the number of micro seconds to wait for the Source to * have data available in each turn, and the number of * micro seconds to wait for the Sinks to accept data. * @return the number of bytes read from the Source. * @exception Exception */ - unsigned int + virtual unsigned int transfer ( unsigned long bytes, unsigned int bufSize, unsigned int sec, @@ -239,7 +239,7 @@ class Connector : public virtual Referable, public virtual Reporter * * @exception Exception */ - void + virtual void close ( void ) throw ( Exception ); }; @@ -259,6 +259,10 @@ class Connector : public virtual Referable, public virtual Reporter $Source$ $Log$ + Revision 1.6 2002/10/19 12:24:55 darkeye + anged internals so that now each encoding/server connection is + a separate thread + Revision 1.5 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 diff --git a/darkice/trunk/src/DarkIce.cpp b/darkice/trunk/src/DarkIce.cpp index 0b0f4a8..b3aab70 100644 --- a/darkice/trunk/src/DarkIce.cpp +++ b/darkice/trunk/src/DarkIce.cpp @@ -77,6 +77,7 @@ #include "IceCast2.h" #include "ShoutCast.h" #include "FileCast.h" +#include "MultiThreadedConnector.h" #include "DarkIce.h" #ifdef HAVE_LAME_LIB @@ -157,7 +158,7 @@ DarkIce :: init ( const Config & config ) throw ( Exception ) sampleRate, bitsPerSample, channel ); - encConnector = new Connector( dsp.get()); + encConnector = new MultiThreadedConnector( dsp.get()); noAudioOuts = 0; configIceCast( config, bufferSecs); @@ -964,6 +965,10 @@ DarkIce :: run ( void ) throw ( Exception ) $Source$ $Log$ + Revision 1.32 2002/10/19 12:24:55 darkeye + anged internals so that now each encoding/server connection is + a separate thread + Revision 1.31 2002/08/20 19:35:37 darkeye added possibility to specify maximum bitrate for Ogg Vorbis streams diff --git a/darkice/trunk/src/Makefile.am b/darkice/trunk/src/Makefile.am index 35660da..d49aaae 100644 --- a/darkice/trunk/src/Makefile.am +++ b/darkice/trunk/src/Makefile.am @@ -13,6 +13,8 @@ darkice_SOURCES = AudioEncoder.h\ FileSink.cpp\ Connector.cpp\ Connector.h\ + MultiThreadedConnector.cpp\ + MultiThreadedConnector.h\ DarkIce.cpp\ DarkIce.h\ Exception.cpp\