examples/SFExamples/oggvorbiscodec94/src/VorbisEncoder/VorbisEncoder.h

00001 // VorbisEncoder.h
00002 //
00003 // Copyright (c) Symbian Software Ltd 2005-2006.  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     };
00081 
00082 /*
00083  This class is responsible for encoding the raw data obtained from the CVorbisEncoderPlugInWrapper into
00084  vorbis data. It also returns the result of the operation
00085  */
00086 class CVorbisProcessor : public CBase
00087     {
00088 public:
00089     enum TProcessResult
00090         {
00091         EComplete,
00092         EIncomplete,
00093         EDestNotFilled
00094         };
00095 
00096     static CVorbisProcessor* NewL();
00097     virtual ~CVorbisProcessor();
00098 
00099     void ProcessL(const CMMFBuffer& aSource,
00100                            CMMFBuffer& aDest,
00101                            TProcessResult& aRes,
00102                            TUint& aSourceUsed,
00103                            TUint& aDestWritten);
00104     TInt BitRateL();
00105     void SetBitRateL(TInt aBitRate);
00106     void ConfigureL(TInt aSampleRate, TInt aChannels);
00107 private:
00108     CVorbisProcessor();
00109     void ConstructL();
00110 private:
00111     CVorbisEncoder* iEncoder;
00112 #ifdef SYMBIAN_SEP_HEAP    
00113     RHeap* iDefaultHeap;
00114     RHeap* iVorbisHeap;
00115     RChunk iVorbisChunk;
00116 #endif
00117     };
00118 
00119 #endif //VORBISENCODER_H

Generated by  doxygen 1.6.2