00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef TWOLAME_LIB_ENCODER_H
00030 #define TWOLAME_LIB_ENCODER_H
00031
00032 #ifndef __cplusplus
00033 #error This is a C++ include file
00034 #endif
00035
00036
00037
00038
00039 #ifdef HAVE_CONFIG_H
00040 #include "config.h"
00041 #endif
00042
00043 #ifdef HAVE_TWOLAME_LIB
00044 #include <twolame.h>
00045 #else
00046 #error configure with twolame
00047 #endif
00048
00049
00050 #include "Ref.h"
00051 #include "Exception.h"
00052 #include "Reporter.h"
00053 #include "AudioEncoder.h"
00054 #include "Sink.h"
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00072 class TwoLameLibEncoder : public AudioEncoder, public virtual Reporter
00073 {
00074 private:
00075
00079 twolame_options * twolame_opts;
00080
00084 Ref<Sink> sink;
00085
00092 void
00093 init ( Sink * sink ) throw ( Exception );
00094
00100 inline void
00101 strip ( void ) throw ( Exception )
00102 {
00103 }
00104
00105
00106 protected:
00107
00113 inline
00114 TwoLameLibEncoder ( void ) throw ( Exception )
00115 {
00116 throw Exception( __FILE__, __LINE__);
00117 }
00118
00119
00120 public:
00121
00138 inline
00139 TwoLameLibEncoder ( Sink * sink,
00140 unsigned int inSampleRate,
00141 unsigned int inBitsPerSample,
00142 unsigned int inChannel,
00143 bool inBigEndian,
00144 BitrateMode outBitrateMode,
00145 unsigned int outBitrate,
00146 unsigned int outSampleRate = 0,
00147 unsigned int outChannel = 0 )
00148 throw ( Exception )
00149
00150 : AudioEncoder ( inSampleRate,
00151 inBitsPerSample,
00152 inChannel,
00153 inBigEndian,
00154 outBitrateMode,
00155 outBitrate,
00156 0.0f,
00157 outSampleRate,
00158 outChannel )
00159 {
00160 init( sink );
00161 }
00162
00177 inline
00178 TwoLameLibEncoder ( Sink * sink,
00179 const AudioSource * as,
00180 BitrateMode outBitrateMode,
00181 unsigned int outBitrate,
00182 unsigned int outSampleRate = 0,
00183 unsigned int outChannel = 0 )
00184 throw ( Exception )
00185
00186 : AudioEncoder ( as,
00187 outBitrateMode,
00188 outBitrate,
00189 0.0f,
00190 outSampleRate,
00191 outChannel )
00192 {
00193 init( sink );
00194 }
00195
00201 inline
00202 TwoLameLibEncoder ( const TwoLameLibEncoder & encoder )
00203 throw ( Exception )
00204 : AudioEncoder( encoder )
00205 {
00206 init( encoder.sink.get() );
00207 }
00208
00209
00215 inline virtual
00216 ~TwoLameLibEncoder ( void ) throw ( Exception )
00217 {
00218 if ( isOpen() ) {
00219 close();
00220 }
00221 strip();
00222 }
00223
00231 inline virtual TwoLameLibEncoder &
00232 operator= ( const TwoLameLibEncoder & encoder ) throw ( Exception )
00233 {
00234 if ( this != &encoder ) {
00235 strip();
00236 AudioEncoder::operator=( encoder);
00237 init( encoder.sink.get() );
00238 }
00239
00240 return *this;
00241 }
00242
00248 inline const char *
00249 getLameVersion( void )
00250 {
00251 return get_twolame_version();
00252 }
00253
00259 inline virtual bool
00260 isRunning ( void ) const throw ()
00261 {
00262 return isOpen();
00263 }
00264
00272 inline virtual bool
00273 start ( void ) throw ( Exception )
00274 {
00275 return open();
00276 }
00277
00283 inline virtual void
00284 stop ( void ) throw ( Exception )
00285 {
00286 return close();
00287 }
00288
00295 virtual bool
00296 open ( void ) throw ( Exception );
00297
00303 inline virtual bool
00304 isOpen ( void ) const throw ()
00305 {
00306 return twolame_opts != 0;
00307 }
00308
00318 inline virtual bool
00319 canWrite ( unsigned int sec,
00320 unsigned int usec ) throw ( Exception )
00321 {
00322 if ( !isOpen() ) {
00323 return false;
00324 }
00325
00326 return true;
00327 }
00328
00340 virtual unsigned int
00341 write ( const void * buf,
00342 unsigned int len ) throw ( Exception );
00343
00350 virtual void
00351 flush ( void ) throw ( Exception );
00352
00358 virtual void
00359 close ( void ) throw ( Exception );
00360 };
00361
00362
00363
00364
00365
00366
00367
00368
00369 #endif
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385