Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

VorbisLibEncoder.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 
00003    Copyright (c) 2000 Tyrell Corporation. All rights reserved.
00004 
00005    Tyrell DarkIce
00006 
00007    File     : VorbisLibEncoder.h
00008    Version  : $Revision: 1.9 $
00009    Author   : $Author: darkeye $
00010    Location : $Source: /cvsroot/darkice/darkice/src/VorbisLibEncoder.h,v $
00011    
00012    Copyright notice:
00013 
00014     This program is free software; you can redistribute it and/or
00015     modify it under the terms of the GNU General Public License  
00016     as published by the Free Software Foundation; either version 2
00017     of the License, or (at your option) any later version.
00018    
00019     This program is distributed in the hope that it will be useful,
00020     but WITHOUT ANY WARRANTY; without even the implied warranty of 
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
00022     GNU General Public License for more details.
00023    
00024     You should have received a copy of the GNU General Public License
00025     along with this program; if not, write to the Free Software
00026     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 
00028 ------------------------------------------------------------------------------*/
00029 #ifndef VORBIS_LIB_ENCODER_H
00030 #define VORBIS_LIB_ENCODER_H
00031 
00032 #ifndef __cplusplus
00033 #error This is a C++ include file
00034 #endif
00035 
00036 
00037 /* ============================================================ include files */
00038 
00039 #ifdef HAVE_CONFIG_H
00040 #include "config.h"
00041 #endif
00042 
00043 #ifdef HAVE_VORBIS_LIB
00044 #include <vorbis/vorbisenc.h>
00045 #else
00046 #error configure for Ogg Vorbis
00047 #endif
00048 
00049 
00050 #include "Ref.h"
00051 #include "Exception.h"
00052 #include "Reporter.h"
00053 #include "AudioEncoder.h"
00054 #include "CastSink.h"
00055 #include "aflibConverter.h"
00056 
00057 
00058 /* ================================================================ constants */
00059 
00060 
00061 /* =================================================================== macros */
00062 
00063 
00064 /* =============================================================== data types */
00065 
00073 class VorbisLibEncoder : public AudioEncoder, public virtual Reporter
00074 {
00075     private:
00076 
00080         bool                            encoderOpen;
00081 
00085         vorbis_info                     vorbisInfo;
00086 
00090         vorbis_dsp_state                vorbisDspState;
00091 
00095         vorbis_block                    vorbisBlock;
00096 
00100         vorbis_comment                  vorbisComment;
00101 
00105         ogg_stream_state                oggStreamState;
00106 
00110         Ref<CastSink>                   sink;
00111 
00115         unsigned int                    outMaxBitrate;
00116 
00120         double                          resampleRatio;
00121 
00125         aflibConverter                * converter;
00126 
00134         void
00135         init ( CastSink       * sink,
00136                unsigned int     outMaxBitrate )         throw ( Exception );
00137 
00143         inline void
00144         strip ( void )                                  throw ( Exception )
00145         {
00146             if ( converter ) {
00147                 delete converter;
00148             }
00149         }
00150 
00154         void
00155         vorbisBlocksOut( void )                         throw ( Exception );
00156 
00157 
00158     protected:
00159 
00165         inline
00166         VorbisLibEncoder ( void )                         throw ( Exception )
00167         {
00168             throw Exception( __FILE__, __LINE__);
00169         }
00170 
00171 
00172     public:
00173 
00193         inline
00194         VorbisLibEncoder (  CastSink      * sink,
00195                             unsigned int    inSampleRate,
00196                             unsigned int    inBitsPerSample,
00197                             unsigned int    inChannel,
00198                             bool            inBigEndian,
00199                             BitrateMode     outBitrateMode,
00200                             unsigned int    outBitrate,
00201                             double          outQuality,
00202                             unsigned int    outSampleRate = 0,
00203                             unsigned int    outChannel    = 0,
00204                             unsigned int    outMaxBitrate = 0 )
00205                                                         throw ( Exception )
00206             
00207                     : AudioEncoder ( inSampleRate,
00208                                      inBitsPerSample,
00209                                      inChannel, 
00210                                      inBigEndian,
00211                                      outBitrateMode,
00212                                      outBitrate,
00213                                      outQuality,
00214                                      outSampleRate,
00215                                      outChannel )
00216         {
00217             init( sink, outMaxBitrate);
00218         }
00219 
00237         inline
00238         VorbisLibEncoder (  CastSink              * sink,
00239                             const AudioSource     * as,
00240                             BitrateMode             outBitrateMode,
00241                             unsigned int            outBitrate,
00242                             double                  outQuality,
00243                             unsigned int            outSampleRate = 0,
00244                             unsigned int            outChannel    = 0,
00245                             unsigned int            outMaxBitrate = 0 )
00246                                                             throw ( Exception )
00247             
00248                     : AudioEncoder ( as,
00249                                      outBitrateMode,
00250                                      outBitrate,
00251                                      outQuality,
00252                                      outSampleRate,
00253                                      outChannel )
00254         {
00255             init( sink, outMaxBitrate);
00256         }
00257 
00263         inline
00264         VorbisLibEncoder (  const VorbisLibEncoder &    encoder )
00265                                                             throw ( Exception )
00266                     : AudioEncoder( encoder )
00267         {
00268             if( encoder.isOpen() ) {
00269                 throw Exception(__FILE__, __LINE__, "don't copy open encoders");
00270             }
00271             init( encoder.sink.get(), encoder.getOutMaxBitrate() );
00272         }
00273 
00279         inline virtual
00280         ~VorbisLibEncoder ( void )                         throw ( Exception )
00281         {
00282             if ( isOpen() ) {
00283                 close();
00284             }
00285             strip();
00286         }
00287 
00295         inline virtual VorbisLibEncoder &
00296         operator= ( const VorbisLibEncoder &   encoder )   throw ( Exception )
00297         {
00298             if( encoder.isOpen() ) {
00299                 throw Exception(__FILE__, __LINE__, "don't copy open encoders");
00300             }
00301 
00302             if ( this != &encoder ) {
00303                 strip();
00304                 AudioEncoder::operator=( encoder);
00305                 init( encoder.sink.get(), encoder.getOutMaxBitrate() );
00306             }
00307 
00308             return *this;
00309         }
00310 
00317         inline unsigned int
00318         getOutMaxBitrate ( void ) const        throw ()
00319         {
00320             return outMaxBitrate;
00321         }
00322 
00328         inline virtual bool
00329         isRunning ( void ) const           throw ()
00330         {
00331             return isOpen();
00332         }
00333 
00341         inline virtual bool
00342         start ( void )                      throw ( Exception )
00343         {
00344             return open();
00345         }
00346 
00352         inline virtual void
00353         stop ( void )                       throw ( Exception )
00354         {
00355             return close();
00356         }
00357 
00364         virtual bool
00365         open ( void )                               throw ( Exception );
00366 
00372         inline virtual bool
00373         isOpen ( void ) const                       throw ()
00374         {
00375             return encoderOpen;
00376         }
00377 
00387         inline virtual bool
00388         canWrite (     unsigned int    sec,
00389                        unsigned int    usec )       throw ( Exception )
00390         {
00391             if ( !isOpen() ) {
00392                 return false;
00393             }
00394 
00395             return true;
00396         }
00397 
00409         virtual unsigned int
00410         write (        const void    * buf,
00411                        unsigned int    len )        throw ( Exception );
00412 
00419         virtual void
00420         flush ( void )                              throw ( Exception );
00421 
00427         virtual void
00428         close ( void )                              throw ( Exception );
00429 };
00430 
00431 
00432 /* ================================================= external data structures */
00433 
00434 
00435 /* ====================================================== function prototypes */
00436 
00437 
00438 
00439 #endif  /* VORBIS_LIB_ENCODER_H */
00440 
00441 
00442 /*------------------------------------------------------------------------------
00443  
00444   $Source: /cvsroot/darkice/darkice/src/VorbisLibEncoder.h,v $
00445 
00446   $Log: VorbisLibEncoder.h,v $
00447   Revision 1.9  2003/02/09 13:15:57  darkeye
00448   added feature for setting the TITLE comment field for vorbis streams
00449 
00450   Revision 1.8  2002/08/20 20:07:36  darkeye
00451   minor fixes
00452 
00453   Revision 1.7  2002/08/20 19:35:37  darkeye
00454   added possibility to specify maximum bitrate for Ogg Vorbis streams
00455 
00456   Revision 1.6  2002/07/20 16:37:06  darkeye
00457   added fault tolerance in case a server connection is dropped
00458 
00459   Revision 1.5  2002/04/13 11:26:00  darkeye
00460   added cbr, abr and vbr setting feature with encoding quality
00461 
00462   Revision 1.4  2002/03/28 16:47:38  darkeye
00463   moved functions conv8() and conv16() to class Util (as conv())
00464   added resampling functionality
00465   added support for variable bitrates
00466 
00467   Revision 1.3  2001/10/19 12:39:42  darkeye
00468   created configure options to compile with or without lame / Ogg Vorbis
00469 
00470   Revision 1.2  2001/09/15 11:36:22  darkeye
00471   added function vorbisBlocksOut(), finalized vorbis support
00472 
00473   Revision 1.1  2001/09/14 19:31:06  darkeye
00474   added IceCast2 / vorbis support
00475 
00476 
00477 
00478 ------------------------------------------------------------------------------*/
00479 

Generated on Thu Apr 14 13:59:13 2005 for DarkIce by  doxygen 1.4.1