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 AAC_ENCODER_H
00030 #define AAC_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_FAAC_LIB
00044 #include <faac.h>
00045 #else
00046 #error configure with faac
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
00071 class FaacEncoder : public AudioEncoder, public virtual Reporter
00072 {
00073 private:
00074
00078 bool faacOpen;
00079
00083 faacEncHandle encoderHandle;
00084
00088 unsigned long inputSamples;
00089
00093 unsigned long maxOutputBytes;
00094
00099 int lowpass;
00100
00104 Ref<Sink> sink;
00105
00116 inline void
00117 init ( Sink * sink,
00118 int lowpass) throw (Exception)
00119 {
00120 this->faacOpen = false;
00121 this->sink = sink;
00122 this->lowpass = lowpass;
00123
00124 if ( getInBitsPerSample() != 16 && getInBitsPerSample() != 8 ) {
00125 throw Exception( __FILE__, __LINE__,
00126 "specified bits per sample not supported",
00127 getInBitsPerSample() );
00128 }
00129
00130 if ( getInChannel() != 1 && getInChannel() != 2 ) {
00131 throw Exception( __FILE__, __LINE__,
00132 "unsupported number of input channels for the encoder",
00133 getInChannel() );
00134 }
00135 if ( getOutChannel() != 1 && getOutChannel() != 2 ) {
00136 throw Exception( __FILE__, __LINE__,
00137 "unsupported number of output channels for the encoder",
00138 getOutChannel() );
00139 }
00140 if ( getInChannel() != getOutChannel() ) {
00141 throw Exception( __FILE__, __LINE__,
00142 "input channels and output channels do not match");
00143 }
00144 }
00145
00151 inline void
00152 strip ( void ) throw ( Exception )
00153 {
00154 }
00155
00156
00157 protected:
00158
00164 inline
00165 FaacEncoder ( void ) throw ( Exception )
00166 {
00167 throw Exception( __FILE__, __LINE__);
00168 }
00169
00170
00171 public:
00172
00194 inline
00195 FaacEncoder ( Sink * sink,
00196 unsigned int inSampleRate,
00197 unsigned int inBitsPerSample,
00198 unsigned int inChannel,
00199 bool inBigEndian,
00200 BitrateMode outBitrateMode,
00201 unsigned int outBitrate,
00202 double outQuality,
00203 unsigned int outSampleRate = 0,
00204 unsigned int outChannel = 0,
00205 int lowpass = 0)
00206 throw ( Exception )
00207
00208 : AudioEncoder ( inSampleRate,
00209 inBitsPerSample,
00210 inChannel,
00211 inBigEndian,
00212 outBitrateMode,
00213 outBitrate,
00214 outQuality,
00215 outSampleRate,
00216 outChannel )
00217 {
00218 init( sink, lowpass);
00219 }
00220
00240 inline
00241 FaacEncoder ( Sink * sink,
00242 const AudioSource * as,
00243 BitrateMode outBitrateMode,
00244 unsigned int outBitrate,
00245 double outQuality,
00246 unsigned int outSampleRate = 0,
00247 unsigned int outChannel = 0,
00248 int lowpass = 0)
00249 throw ( Exception )
00250
00251 : AudioEncoder ( as,
00252 outBitrateMode,
00253 outBitrate,
00254 outQuality,
00255 outSampleRate,
00256 outChannel )
00257 {
00258 init( sink, lowpass);
00259 }
00260
00266 inline
00267 FaacEncoder ( const FaacEncoder & encoder )
00268 throw ( Exception )
00269 : AudioEncoder( encoder )
00270 {
00271 init( encoder.sink.get(), encoder.lowpass);
00272 }
00273
00274
00280 inline virtual
00281 ~FaacEncoder ( void ) throw ( Exception )
00282 {
00283 if ( isOpen() ) {
00284 close();
00285 }
00286 strip();
00287 }
00288
00296 inline virtual FaacEncoder &
00297 operator= ( const FaacEncoder & encoder ) throw ( Exception )
00298 {
00299 if ( this != &encoder ) {
00300 strip();
00301 AudioEncoder::operator=( encoder);
00302 init( encoder.sink.get(), encoder.lowpass);
00303 }
00304
00305 return *this;
00306 }
00307
00313 inline const char *
00314 getFaacVersion( void )
00315 {
00316 char * id;
00317 char * copyright;
00318
00319 faacEncGetVersion(&id, ©right);
00320 return id;
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 faacOpen;
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
00433
00434
00435
00436
00437
00438 #endif
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458