examples/sfexamples/oggvorbiscodec/src/VorbisEncoder/VorbisEncoder.h

00001 // VorbisEncoder.h
00002 //
00003 // Copyright (c) Symbian Software Ltd 2005-2008.  All rights reserved.
00004 //
00005 
00006 #ifndef VORBISENCODER_H
00007 #define VORBISENCODER_H
00008 
00009 #include <mmf/server/mmfdatabuffer.h>
00010 #include <oggutil.h>
00011 #include <vorbisinfo.h>
00012 #include "vorbis/vorbisenc.h"
00013 #include "vorbis/codec.h"
00014 
00015 #ifdef SYMBIAN_VORBIS_DEBUG
00016 #define DEBUG(x) RDebug::Print(_L(x))
00017 #define DEBUG1(x,x1) RDebug::Print(_L(x),x1)
00018 #else
00019 #define DEBUG(x)
00020 #define DEBUG1(x,x1)
00021 #endif
00022 
00023 const TInt KOggVorbisMinBitrate = 45000; //see http://en.wikipedia.org/wiki/Vorbis
00024 // see for the derivation of these constants http://en.wikipedia.org/wiki/Vorbis
00025 const TInt KVorbisQualityMinus1 = 45000;
00026 const TInt KVorbisQuality0 = 64000;
00027 const TInt KVorbisQuality1 = 80000;
00028 const TInt KVorbisQuality2 = 96000;
00029 const TInt KVorbisQuality3 = 112000;
00030 const TInt KVorbisQuality4 = 128000;
00031 const TInt KVorbisQuality5 = 160000;
00032 const TInt KVorbisQuality6 = 192000;
00033 const TInt KVorbisQuality7 = 224000;
00034 const TInt KVorbisQuality8 = 256000;
00035 const TInt KVorbisQuality9 = 320000;
00036 const TInt KVorbisQuality10 = 500000;
00037 //note that the Vorbis libraries can crash below this limit                                             
00038 
00039 //Central encoding class - talks to the Xiph vorbis libraries
00040 class CVorbisEncoder : public CBase
00041     {
00042 public:
00043     static CVorbisEncoder* NewL();
00044     ~CVorbisEncoder();
00045     TInt PageOutL(CMMFDataBuffer& aBuf);
00046     void PcmInL(const CMMFDataBuffer& aBuf);
00047     void Reset();
00048         TInt BitRateL();
00049     void SetBitRateL(TInt aBitRate);
00050     void InitializeVorbisStreamL();
00051     void ConfigureL(TInt aSampleRate, TInt aChannels);
00052     void ConvertBitRateToQuality(TInt aBitRate, TReal32& aQuality);
00053 private:
00054         CVorbisEncoder();
00055         void ConstructL();
00056         void PrepareHeadersL();
00057         TInt TranslateOggVorbisError(TInt aError);
00058     enum TCodecState
00059         {
00060         ENotReady,
00061         EInitialized,
00062         EReady
00063         };
00064     TCodecState iState;
00065     // struct that stores all the static vorbis bitstream settings
00066     vorbis_info iInfo; 
00067     // struct that stores all the user comments
00068     vorbis_comment iComment;
00069      // central working state for the packet->PCM decoder
00070     vorbis_dsp_state iDspState;
00071     //local working space for packet->PCM decode 
00072     vorbis_block iBlock;
00073     ogg_stream_state iStream;
00074     TInt iBitRate;
00075     //Encode quality to be used.
00076     TReal32 iQuality;
00077     TInt iSampleRate;
00078     TInt iChannels;
00079     TInt iPageCount;
00080     TBool iLastBuffer;
00081     };
00082 
00083 /*
00084  This class is responsible for encoding the raw data obtained from the CVorbisEncoderPlugInWrapper into
00085  vorbis data. It also returns the result of the operation
00086  */
00087 class CVorbisProcessor : public CBase
00088     {
00089 public:
00090     enum TProcessResult
00091         {
00092         EComplete,
00093         EIncomplete,
00094         EDestNotFilled
00095         };
00096 
00097     static CVorbisProcessor* NewL();
00098     virtual ~CVorbisProcessor();
00099 
00100     void ProcessL(const CMMFBuffer& aSource,
00101                            CMMFBuffer& aDest,
00102                            TProcessResult& aRes,
00103                            TUint& aSourceUsed,
00104                            TUint& aDestWritten);
00105     TInt BitRateL();
00106     void SetBitRateL(TInt aBitRate);
00107     void ConfigureL(TInt aSampleRate, TInt aChannels);
00108 private:
00109     CVorbisProcessor();
00110     void ConstructL();
00111 private:
00112     CVorbisEncoder* iEncoder;
00113 #ifdef SYMBIAN_SEP_HEAP    
00114     RHeap* iDefaultHeap;
00115     RHeap* iVorbisHeap;
00116     RChunk iVorbisChunk;
00117 #endif
00118     };
00119 
00120 #endif //VORBISENCODER_H

Generated by  doxygen 1.6.2