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

AacEncoder.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 
00003    Copyright (c) 2005 Tyrell Corporation. All rights reserved.
00004 
00005    Tyrell DarkIce
00006 
00007    File     : AacEncoder.h
00008    Version  : $Revision$
00009    Author   : $Author$
00010    Location : $Source$
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 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 /* ============================================================ include files */
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 /* ================================================================ constants */
00058 
00059 
00060 /* =================================================================== macros */
00061 
00062 
00063 /* =============================================================== data types */
00064 
00071 class AacEncoder : 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 
00098         Ref<Sink>                   sink;
00099 
00106         inline void
00107         init ( Sink           * sink )                      throw (Exception)
00108         {
00109             this->sink            = sink;
00110 
00111             if ( getInBitsPerSample() != 16 && getInBitsPerSample() != 8 ) {
00112                 throw Exception( __FILE__, __LINE__,
00113                                  "specified bits per sample not supported",
00114                                  getInBitsPerSample() );
00115             }
00116 
00117             if ( getInChannel() != 1 && getInChannel() != 2 ) {
00118                 throw Exception( __FILE__, __LINE__,
00119                          "unsupported number of input channels for the encoder",
00120                                  getInChannel() );
00121             }
00122             if ( getOutChannel() != 1 && getOutChannel() != 2 ) {
00123                 throw Exception( __FILE__, __LINE__,
00124                         "unsupported number of output channels for the encoder",
00125                                  getOutChannel() );
00126             }
00127             if ( getInChannel() != getOutChannel() ) {
00128                 throw Exception( __FILE__, __LINE__,
00129                              "input channels and output channels do not match");
00130             }
00131         }
00132 
00138         inline void
00139         strip ( void )                                  throw ( Exception )
00140         {
00141         }
00142 
00143 
00144     protected:
00145 
00151         inline
00152         AacEncoder ( void )                         throw ( Exception )
00153         {
00154             throw Exception( __FILE__, __LINE__);
00155         }
00156 
00157 
00158     public:
00159 
00177         inline
00178         AacEncoder (    Sink          * sink,
00179                         unsigned int    inSampleRate,
00180                         unsigned int    inBitsPerSample,
00181                         unsigned int    inChannel,
00182                         bool            inBigEndian,
00183                         BitrateMode     outBitrateMode,
00184                         unsigned int    outBitrate,
00185                         double          outQuality,
00186                         unsigned int    outSampleRate = 0,
00187                         unsigned int    outChannel    = 0)
00188                                                         throw ( Exception )
00189             
00190                     : AudioEncoder ( inSampleRate,
00191                                      inBitsPerSample,
00192                                      inChannel,
00193                                      inBigEndian,
00194                                      outBitrateMode,
00195                                      outBitrate,
00196                                      outQuality,
00197                                      outSampleRate,
00198                                      outChannel )
00199         {
00200             init( sink);
00201         }
00202 
00218         inline
00219         AacEncoder (    Sink                  * sink,
00220                         const AudioSource     * as,
00221                         BitrateMode             outBitrateMode,
00222                         unsigned int            outBitrate,
00223                         double                  outQuality,
00224                         unsigned int            outSampleRate = 0,
00225                         unsigned int            outChannel    = 0)
00226                                                             throw ( Exception )
00227             
00228                     : AudioEncoder ( as,
00229                                      outBitrateMode,
00230                                      outBitrate,
00231                                      outQuality,
00232                                      outSampleRate,
00233                                      outChannel )
00234         {
00235             init( sink);
00236         }
00237 
00243         inline
00244         AacEncoder (  const AacEncoder &    encoder )
00245                                                             throw ( Exception )
00246                     : AudioEncoder( encoder )
00247         {
00248             init( encoder.sink.get());
00249         }
00250          
00251 
00257         inline virtual
00258         ~AacEncoder ( void )                            throw ( Exception )
00259         {
00260             if ( isOpen() ) {
00261                 close();
00262             }
00263             strip();
00264         }
00265 
00273         inline virtual AacEncoder &
00274         operator= ( const AacEncoder &      encoder )   throw ( Exception )
00275         {
00276             if ( this != &encoder ) {
00277                 strip();
00278                 AudioEncoder::operator=( encoder);
00279                 init( encoder.sink.get());
00280             }
00281 
00282             return *this;
00283         }
00284 
00290         inline const char *
00291         getFaacVersion( void )
00292         {
00293             char      * id;
00294             char      * copyright;
00295 
00296             faacEncGetVersion(&id, &copyright);
00297             return id;
00298         }
00299 
00305         inline virtual bool
00306         isRunning ( void ) const           throw ()
00307         {
00308             return isOpen();
00309         }
00310 
00318         inline virtual bool
00319         start ( void )                      throw ( Exception )
00320         {
00321             return open();
00322         }
00323 
00329         inline virtual void
00330         stop ( void )                       throw ( Exception )
00331         {
00332             return close();
00333         }
00334 
00341         virtual bool
00342         open ( void )                               throw ( Exception );
00343 
00349         inline virtual bool
00350         isOpen ( void ) const                       throw ()
00351         {
00352             return faacOpen;
00353         }
00354 
00364         inline virtual bool
00365         canWrite (     unsigned int    sec,
00366                        unsigned int    usec )       throw ( Exception )
00367         {
00368             if ( !isOpen() ) {
00369                 return false;
00370             }
00371 
00372             return true;
00373         }
00374 
00386         virtual unsigned int
00387         write (        const void    * buf,
00388                        unsigned int    len )        throw ( Exception );
00389 
00396         virtual void
00397         flush ( void )                              throw ( Exception );
00398 
00404         virtual void
00405         close ( void )                              throw ( Exception );
00406 };
00407 
00408 
00409 /* ================================================= external data structures */
00410 
00411 
00412 /* ====================================================== function prototypes */
00413 
00414 
00415 #endif  /* AAC_ENCODER_H */
00416 
00417 
00418 /*------------------------------------------------------------------------------
00419  
00420   $Source$
00421 
00422   $Log$
00423 
00424   
00425 ------------------------------------------------------------------------------*/
00426 

Generated on Sat Apr 16 22:06:16 2005 for DarkIce by  doxygen 1.4.1