diff --git a/darkice/trunk/src/CastSink.cpp b/darkice/trunk/src/CastSink.cpp index aa5c14c..95195e1 100644 --- a/darkice/trunk/src/CastSink.cpp +++ b/darkice/trunk/src/CastSink.cpp @@ -61,7 +61,8 @@ CastSink :: init ( TcpSocket * socket, const char * name, const char * url, const char * genre, - bool isPublic ) + bool isPublic, + unsigned int bufferDuration ) throw ( Exception ) { this->socket = socket; @@ -72,6 +73,13 @@ CastSink :: init ( TcpSocket * socket, this->url = url ? Util::strDup( url) : 0; this->genre = genre ? Util::strDup( genre) : 0; this->isPublic = isPublic; + this->bufferDuration = bufferDuration; + + int bufferSize = bitRate ? (bitRate * 1024 / 8) * bufferDuration + : (128 * 1024 / 8) * bufferDuration; + + bufferedSink = socket ? new BufferedSink( socket, bufferSize) + : 0; } @@ -110,7 +118,7 @@ CastSink :: open ( void ) throw ( Exception ) return false; } - if ( !getSink()->open() ) { + if ( !bufferedSink->open() ) { return false; } diff --git a/darkice/trunk/src/CastSink.h b/darkice/trunk/src/CastSink.h index 366e7bc..f1f5fa0 100644 --- a/darkice/trunk/src/CastSink.h +++ b/darkice/trunk/src/CastSink.h @@ -68,11 +68,21 @@ class CastSink : public Sink, public virtual Reporter */ Ref socket; + /** + * The BufferedSink encapsulating the socket connection to the server. + */ + Ref bufferedSink; + /** * An optional Sink to enable stream dumps. */ Ref streamDump; + /** + * Duration of the BufferedSink buffer in seconds. + */ + unsigned int bufferDuration; + /** * Password to the server. */ @@ -113,6 +123,8 @@ class CastSink : public Sink, public virtual Reporter * @param genre genre of the stream. * @param bitRate bitrate of the stream (e.g. mp3 bitrate). * @param isPublic is the stream public? + * @param bufferDuration duration of the BufferedSink buffer + * in seconds. * @exception Exception */ void @@ -123,7 +135,8 @@ class CastSink : public Sink, public virtual Reporter const char * name, const char * url, const char * genre, - bool isPublic) + bool isPublic, + unsigned int bufferDuration ) throw ( Exception ); /** @@ -165,7 +178,7 @@ class CastSink : public Sink, public virtual Reporter inline Sink * getSink ( void ) const throw () { - return getSocket(); + return bufferedSink.get(); } /** @@ -193,7 +206,8 @@ class CastSink : public Sink, public virtual Reporter * @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 */ inline @@ -204,7 +218,8 @@ class CastSink : public Sink, public virtual Reporter const char * url = 0, const char * genre = 0, bool isPublic = false, - Sink * streamDump = 0) + Sink * streamDump = 0, + unsigned int bufferDuration = 10 ) throw ( Exception ) { init( socket, @@ -214,7 +229,8 @@ class CastSink : public Sink, public virtual Reporter name, url, genre, - isPublic ); + isPublic, + bufferDuration ); } /** @@ -233,7 +249,8 @@ class CastSink : public Sink, public virtual Reporter cs.name, cs.url, cs.genre, - cs.isPublic ); + cs.isPublic, + cs.bufferDuration ); } /** @@ -267,7 +284,8 @@ class CastSink : public Sink, public virtual Reporter cs.name, cs.url, cs.genre, - cs.isPublic ); + cs.isPublic, + cs.bufferDuration ); } return *this; } @@ -290,11 +308,7 @@ class CastSink : public Sink, public virtual Reporter inline virtual bool isOpen ( void ) const throw () { - Sink *s = getSink(); - if (s) - return getSink()->isOpen(); - else - return false; + return bufferedSink != NULL ? bufferedSink->isOpen() : false; } /** @@ -441,6 +455,17 @@ class CastSink : public Sink, public virtual Reporter { return isPublic; } + + /** + * Get the duration of the BufferedSink buffer in seconds. + * + * @return the the duration of the BufferedSink buffer in seconds. + */ + inline unsigned int + getBufferDuration ( void ) const throw () + { + return bufferDuration; + } };