00001
00002
00003
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;
00024
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
00038
00039
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
00066 vorbis_info iInfo;
00067
00068 vorbis_comment iComment;
00069
00070 vorbis_dsp_state iDspState;
00071
00072 vorbis_block iBlock;
00073 ogg_stream_state iStream;
00074 TInt iBitRate;
00075
00076 TReal32 iQuality;
00077 TInt iSampleRate;
00078 TInt iChannels;
00079 TInt iPageCount;
00080 };
00081
00082
00083
00084
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