From ab8efd2d31fda04f3f04baed3eb8d22bb7ec9867 Mon Sep 17 00:00:00 2001 From: darkeye Date: Wed, 20 Feb 2002 10:40:02 +0000 Subject: [PATCH] updated to work with Ogg Vorbis libs rc3 and current IceCast2 cvs --- darkice/trunk/ChangeLog | 2 + darkice/trunk/darkice.cfg | 3 +- darkice/trunk/man/darkice.cfg.5 | 5 ++ darkice/trunk/src/DarkIce.cpp | 89 +++++++++++++++++++------- darkice/trunk/src/IceCast2.cpp | 24 ++++++- darkice/trunk/src/IceCast2.h | 39 +++++++++-- darkice/trunk/src/VorbisLibEncoder.cpp | 34 ++++++---- 7 files changed, 154 insertions(+), 42 deletions(-) diff --git a/darkice/trunk/ChangeLog b/darkice/trunk/ChangeLog index 6228a36..e65d090 100644 --- a/darkice/trunk/ChangeLog +++ b/darkice/trunk/ChangeLog @@ -4,6 +4,8 @@ DarkIce 0.8 o fixed incorrect vorbis bitrate setting o fix: DarkIce now reports public streams correctly thanks to Tom Gray, + o made up-to-date with Ogg Vorbis rc3 libs + o made up-to-date with current IceCast2 cvs version 19-10-2001: DarkIce 0.7 released diff --git a/darkice/trunk/darkice.cfg b/darkice/trunk/darkice.cfg index c589443..14c3f43 100644 --- a/darkice/trunk/darkice.cfg +++ b/darkice/trunk/darkice.cfg @@ -36,7 +36,8 @@ public = yes # advertise this stream? # there may be up to 8 of these sections, named [icecast2-0] ... [icecast2-7] # these can be mixed with [icecast-x] and [shoutcast-x] sections [icecast2-0] -bitrate = 96 # bitrate of the mp3 stream sent to the server +format = vorbis # format of the stream: ogg vorbis +bitrate = 96 # bitrate of the stream sent to the server server = yp.yourserver.com # host name of the server port = 8000 # port of the IceCast2 server, usually 8000 diff --git a/darkice/trunk/man/darkice.cfg.5 b/darkice/trunk/man/darkice.cfg.5 index 46e86a6..8330677 100644 --- a/darkice/trunk/man/darkice.cfg.5 +++ b/darkice/trunk/man/darkice.cfg.5 @@ -158,6 +158,11 @@ The stream will be reachable at Required values: +.TP +.I format +Format of the stream sent to the +.B IceCast2 +server. Currently the only supported value here is 'vorbis'. .TP .I bitrate Bit rate to encode to in kBits / sec (e.g. 96) diff --git a/darkice/trunk/src/DarkIce.cpp b/darkice/trunk/src/DarkIce.cpp index 2efa11e..b881e6c 100644 --- a/darkice/trunk/src/DarkIce.cpp +++ b/darkice/trunk/src/DarkIce.cpp @@ -298,26 +298,34 @@ DarkIce :: configIceCast2 ( const Config & config, break; } -#ifndef HAVE_VORBIS_LIB - throw Exception( __FILE__, __LINE__, - "DarkIce not compiled with Ogg Vorbis support, " - "thus can't connect to IceCast 2, stream: ", - stream); -#else - const char * str; - unsigned int bitrate = 0; - const char * server = 0; - unsigned int port = 0; - const char * password = 0; - const char * mountPoint = 0; - const char * name = 0; - const char * description = 0; - const char * url = 0; - const char * genre = 0; - bool isPublic = false; + IceCast2::StreamFormat format; + unsigned int bitrate = 0; + const char * server = 0; + unsigned int port = 0; + const char * password = 0; + const char * mountPoint = 0; + const char * name = 0; + const char * description = 0; + const char * url = 0; + const char * genre = 0; + bool isPublic = false; + str = cs->getForSure( "format", " missing in section ", stream); + if ( Util::strEq( str, "vorbis") ) { + format = IceCast2::oggVorbis; + } else if ( Util::strEq( str, "mp3") ) { + format = IceCast2::mp3; + // TODO: enable this format in the future, when icecast2 + // supports it as well + throw Exception( __FILE__, __LINE__, + "unsupported stream format: ", str); + } else { + throw Exception( __FILE__, __LINE__, + "unsupported stream format: ", str); + } + str = cs->getForSure("bitrate", " missing in section ", stream); bitrate = Util::strToL( str); server = cs->getForSure( "server", " missing in section ", stream); @@ -348,6 +356,7 @@ DarkIce :: configIceCast2 ( const Config & config, audioOuts[u].server = new IceCast2( audioOuts[u].socket.get(), password, mountPoint, + format, bitrate, name, description, @@ -355,14 +364,45 @@ DarkIce :: configIceCast2 ( const Config & config, genre, isPublic ); - audioOuts[u].encoder = new VorbisLibEncoder( audioOuts[u].server.get(), - dsp.get(), - bitrate, - dsp->getSampleRate(), - dsp->getChannel() ); + switch ( format ) { + case IceCast2::mp3: +#ifndef HAVE_LAME_LIB + throw Exception( __FILE__, __LINE__, + "DarkIce not compiled with lame support, " + "thus can't create mp3 stream: ", + stream); +#else + audioOuts[u].encoder = new LameLibEncoder( + audioOuts[u].server.get(), + dsp.get(), + bitrate, + dsp->getSampleRate(), + dsp->getChannel() ); +#endif // HAVE_LAME_LIB + break; + + case IceCast2::oggVorbis: +#ifndef HAVE_VORBIS_LIB + throw Exception( __FILE__, __LINE__, + "DarkIce not compiled with Ogg Vorbis support, " + "thus can't Ogg Vorbis stream: ", + stream); +#else + audioOuts[u].encoder = new VorbisLibEncoder( + audioOuts[u].server.get(), + dsp.get(), + bitrate, + dsp->getSampleRate(), + dsp->getChannel() ); +#endif // HAVE_VORBIS_LIB + break; + + default: + throw Exception( __FILE__, __LINE__, + "Illegal stream format: ", format); + } encConnector->attach( audioOuts[u].encoder.get()); -#endif // HAVE_VORBIS_LIB } noAudioOuts += u; @@ -608,6 +648,9 @@ DarkIce :: run ( void ) throw ( Exception ) $Source$ $Log$ + Revision 1.23 2002/02/20 10:35:35 darkeye + updated to work with Ogg Vorbis libs rc3 and current IceCast2 cvs + Revision 1.22 2001/10/20 10:56:45 darkeye added possibility to disable highpass and lowpass filters for lame diff --git a/darkice/trunk/src/IceCast2.cpp b/darkice/trunk/src/IceCast2.cpp index 40c9d38..dfd898f 100644 --- a/darkice/trunk/src/IceCast2.cpp +++ b/darkice/trunk/src/IceCast2.cpp @@ -79,10 +79,12 @@ static const char fileid[] = "$Id$"; * Initialize the object *----------------------------------------------------------------------------*/ void -IceCast2 :: init ( const char * mountPoint, +IceCast2 :: init ( StreamFormat format, + const char * mountPoint, const char * description ) throw ( Exception ) { + this->format = format; this->mountPoint = Util::strDup( mountPoint); this->description = description ? Util::strDup( description) : 0; } @@ -129,7 +131,22 @@ IceCast2 :: sendLogin ( void ) throw ( Exception ) sink->write( str, strlen( str)); /* send the content type, Ogg Vorbis */ - str = "\nContent-type: application/x-ogg"; + str = "\nContent-type: "; + sink->write( str, strlen( str)); + switch ( format ) { + case mp3: + str = "audio/mpeg"; + break; + + case oggVorbis: + str = "application/x-ogg"; + break; + + default: + throw Exception( __FILE__, __LINE__, + "unsupported stream format", format); + break; + } sink->write( str, strlen( str)); /* send the ice- headers */ @@ -192,6 +209,9 @@ IceCast2 :: sendLogin ( void ) throw ( Exception ) $Source$ $Log$ + Revision 1.4 2002/02/20 10:35:35 darkeye + updated to work with Ogg Vorbis libs rc3 and current IceCast2 cvs + Revision 1.3 2002/02/19 15:24:26 darkeye send Content-type header when logging in to icecast2 servers diff --git a/darkice/trunk/src/IceCast2.h b/darkice/trunk/src/IceCast2.h index cc9095d..6aa4d74 100644 --- a/darkice/trunk/src/IceCast2.h +++ b/darkice/trunk/src/IceCast2.h @@ -58,8 +58,21 @@ */ class IceCast2 : public CastSink { + public: + + /** + * Type for specifying the format of the stream. + */ + enum StreamFormat { mp3, oggVorbis }; + + private: + /** + * The format of the stream. + */ + StreamFormat format; + /** * Mount point of the stream on the server. */ @@ -79,7 +92,8 @@ class IceCast2 : public CastSink * @exception Exception */ void - init ( const char * mountPoint, + init ( StreamFormat format, + const char * mountPoint, const char * description ) throw ( Exception ); @@ -137,6 +151,7 @@ class IceCast2 : public CastSink IceCast2 ( TcpSocket * socket, const char * password, const char * mountPoint, + StreamFormat format, unsigned int bitRate, const char * name = 0, const char * description = 0, @@ -154,7 +169,7 @@ class IceCast2 : public CastSink isPublic, bufferDuration ) { - init( mountPoint, description); + init( format, mountPoint, description); } /** @@ -166,7 +181,8 @@ class IceCast2 : public CastSink IceCast2( const IceCast2 & cs ) throw ( Exception ) : CastSink( cs ) { - init( cs.getMountPoint(), + init( cs.getFormat(), + cs.getMountPoint(), cs.getDescription() ); } @@ -194,12 +210,24 @@ class IceCast2 : public CastSink if ( this != &cs ) { strip(); CastSink::operator=( cs ); - init( cs.getMountPoint(), + init( cs.getFormat(), + cs.getMountPoint(), cs.getDescription() ); } return *this; } + /** + * Get the format of the stream. + * + * @return the format of the stream. + */ + inline StreamFormat + getFormat ( void ) const throw () + { + return format; + } + /** * Get the mount point of the stream on the server. * @@ -240,6 +268,9 @@ class IceCast2 : public CastSink $Source$ $Log$ + Revision 1.2 2002/02/20 10:35:35 darkeye + updated to work with Ogg Vorbis libs rc3 and current IceCast2 cvs + Revision 1.1 2001/09/14 19:31:06 darkeye added IceCast2 / vorbis support diff --git a/darkice/trunk/src/VorbisLibEncoder.cpp b/darkice/trunk/src/VorbisLibEncoder.cpp index 33943d4..eca8ab6 100644 --- a/darkice/trunk/src/VorbisLibEncoder.cpp +++ b/darkice/trunk/src/VorbisLibEncoder.cpp @@ -75,7 +75,7 @@ VorbisLibEncoder :: open ( void ) if ( (ret = vorbis_encode_init( &vorbisInfo, getInChannel(), getInSampleRate(), - -1, + getOutBitrate() * 1000, getOutBitrate() * 1000, -1 )) ) { throw Exception( __FILE__, __LINE__, "vorbis encode init error", ret); @@ -117,7 +117,7 @@ VorbisLibEncoder :: open ( void ) throw Exception( __FILE__, __LINE__, "vorbis header init error", ret); } - vorbis_comment_clear( &vorbisComment ); + vorbis_comment_init( &vorbisComment); ogg_stream_packetin( &oggStreamState, &header); ogg_stream_packetin( &oggStreamState, &commentHeader); @@ -129,6 +129,8 @@ VorbisLibEncoder :: open ( void ) sink->write( oggPage.body, oggPage.body_len); } + vorbis_comment_clear( &vorbisComment ); + encoderOpen = true; return true; @@ -313,19 +315,24 @@ VorbisLibEncoder :: vorbisBlocksOut ( void ) throw () ogg_page oggPage; vorbis_analysis( &vorbisBlock, &oggPacket); - ogg_stream_packetin( &oggStreamState, &oggPacket); + vorbis_bitrate_addblock( &vorbisBlock); - while ( ogg_stream_pageout( &oggStreamState, &oggPage) ) { - int written; - - written = sink->write( oggPage.header, oggPage.header_len); - written += sink->write( oggPage.body, oggPage.body_len); + while ( vorbis_bitrate_flushpacket( &vorbisDspState, &oggPacket) ) { - if ( written < oggPage.header_len + oggPage.body_len ) { - // just let go data that could not be written - reportEvent( 2, + ogg_stream_packetin( &oggStreamState, &oggPacket); + + while ( ogg_stream_pageout( &oggStreamState, &oggPage) ) { + int written; + + written = sink->write( oggPage.header, oggPage.header_len); + written += sink->write( oggPage.body, oggPage.body_len); + + if ( written < oggPage.header_len + oggPage.body_len ) { + // just let go data that could not be written + reportEvent( 2, "couldn't write full vorbis data to underlying sink", - oggPage.header_len + oggPage.body_len - written); + oggPage.header_len + oggPage.body_len - written); + } } } } @@ -359,6 +366,9 @@ VorbisLibEncoder :: close ( void ) throw ( Exception ) $Source$ $Log$ + Revision 1.6 2002/02/20 10:35:35 darkeye + updated to work with Ogg Vorbis libs rc3 and current IceCast2 cvs + Revision 1.5 2001/10/21 13:08:18 darkeye fixed incorrect vorbis bitrate setting