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 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
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
00059
00060
00061
00062
00063
00064
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
00433
00434
00435
00436
00437
00438
00439 #endif
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479