examples/SFExamples/oggvorbiscodec/src/VorbisEncoder/VorbisEncoderPlugIn.cpp

00001 // VorbisEncoderPlugIn.cpp
00002 //
00003 // Copyright (c) Symbian Software Ltd 2005-2008.  All rights reserved.
00004 //
00005 
00006 
00007 #include <e32base.h>
00008 #include <ecom/implementationproxy.h>
00009 #include <mmf/server/mmfswcodecwrapper.h>
00010 #include "VorbisEncoder.h"
00011 #include "VorbisEncoderUIDs.hrh"
00012 #include "VorbisEncoderPlugIn.h"
00013 
00014 /*taken from encoder_example.c in libvorbis\examples\encoder_example.c. These values
00015 taken such a way that we usually get an oggpage generated for the given KSourceBufferSize.*/
00016 const TInt KSourceBufferSize = 0x4000;// = KSamplesToRead/2(channels)*2(16-bit)
00017 const TInt KSinkBufferSize = 0x4000; //enough to accomodate two oggpages which is rare
00018         
00019 CVorbisEncoderPlugInWrapper* CVorbisEncoderPlugInWrapper::NewL()
00020     {
00021     DEBUG("CVorbisHwDeviceWrapper2::NewL");
00022     CVorbisEncoderPlugInWrapper* self = new(ELeave)CVorbisEncoderPlugInWrapper;
00023     CleanupStack::PushL(self);
00024     self->ConstructL();
00025     CleanupStack::Pop(self);
00026     return self;
00027     }
00028 
00029 void CVorbisEncoderPlugInWrapper::ConstructL()
00030         {
00031         iDevice = CVorbisEncoderPlugIn::NewL();
00032         }
00033         
00034 CVorbisEncoderPlugInWrapper::~CVorbisEncoderPlugInWrapper()
00035     {
00036     DEBUG("CVorbisEncoderPlugInWrapper::~CVorbisEncoderPlugInWrapper");
00037     // just in case the codec was never asked for:
00038     if (!iCodecReturned) 
00039         {
00040         delete iDevice;
00041         }
00042     }
00043 
00044 CVorbisEncoderPlugInWrapper::CVorbisEncoderPlugInWrapper()
00045     {
00046     }
00047 
00048 TInt CVorbisEncoderPlugInWrapper::SetConfig(TTaskConfig& aConfig)
00049         {
00050         TInt err = CMMFSwCodecWrapper::SetConfig(aConfig);
00051         if (err != KErrNone)
00052                 {
00053                 return err;
00054                 }
00055         err = static_cast<CVorbisEncoderPlugIn* >(iCodec)->Configure(iSampleRate, iChannels);
00056         return err;
00057         }
00058 
00065 CMMFSwCodec& CVorbisEncoderPlugInWrapper::Codec()
00066     {
00067     DEBUG("CVorbisHwDeviceWrapper2::Codec");
00068     iCodecReturned=ETrue;
00069     return *iDevice; // this is owned by the SwWrapper
00070     }
00071 
00072 
00073 TInt CVorbisEncoderPlugInWrapper::Start(TDeviceFunc aFuncCmd, TDeviceFlow aFlowCmd)
00074         {
00075         TInt err = CMMFSwCodecWrapper::Start(aFuncCmd, aFlowCmd);
00076         if(err == KErrNone)
00077                 {
00078         SetVbrFlag();
00079                 }
00080         return err;
00081         }
00082         
00095 TAny* CVorbisEncoderPlugInWrapper::CustomInterface(TUid aInterfaceId)
00096         {
00097         // if this is the bitrate interface then
00098         // we support this natively
00099         if (aInterfaceId == KUidCustomInterfaceDevSoundBitRate)
00100                 {
00101                 return static_cast<MMMFDevSoundCustomInterfaceBitRate*> (this);
00102                 }
00103         else
00104                 {
00105                 // otherwise pass the interface call onto the base class
00106                 return CMMFSwCodecWrapper::CustomInterface(aInterfaceId);
00107                 }
00108         }
00116 void CVorbisEncoderPlugInWrapper::GetSupportedBitRatesL(RArray<TInt>& aSupportedBitRates)
00117         {
00118         aSupportedBitRates.Reset();
00119         User::LeaveIfError(aSupportedBitRates.Append(KVorbisQualityMinus1));
00120         User::LeaveIfError(aSupportedBitRates.Append(KVorbisQuality0));
00121         User::LeaveIfError(aSupportedBitRates.Append(KVorbisQuality1));
00122         User::LeaveIfError(aSupportedBitRates.Append(KVorbisQuality2));
00123         User::LeaveIfError(aSupportedBitRates.Append(KVorbisQuality3));
00124         User::LeaveIfError(aSupportedBitRates.Append(KVorbisQuality4));
00125         User::LeaveIfError(aSupportedBitRates.Append(KVorbisQuality5));
00126         User::LeaveIfError(aSupportedBitRates.Append(KVorbisQuality6));
00127         User::LeaveIfError(aSupportedBitRates.Append(KVorbisQuality7));
00128         User::LeaveIfError(aSupportedBitRates.Append(KVorbisQuality8));
00129         User::LeaveIfError(aSupportedBitRates.Append(KVorbisQuality9));
00130         User::LeaveIfError(aSupportedBitRates.Append(KVorbisQuality10));
00131         }
00132 
00138 TInt CVorbisEncoderPlugInWrapper::BitRateL()
00139         {
00140         return static_cast<CVorbisEncoderPlugIn* >(iCodec)->BitRateL();
00141         }
00142 
00149 void CVorbisEncoderPlugInWrapper::SetBitRateL(TInt aBitRate)
00150         {
00151         static_cast<CVorbisEncoderPlugIn* >(iCodec)->SetBitRateL(aBitRate);
00152         }
00153 
00154 
00155 CVorbisEncoderPlugIn* CVorbisEncoderPlugIn::NewL()
00156     {
00157     DEBUG("CVorbisEncoderPlugIn::NewL");
00158     CVorbisEncoderPlugIn* self = new(ELeave)CVorbisEncoderPlugIn;
00159     CleanupStack::PushL(self);
00160     self->ConstructL();
00161     CleanupStack::Pop(self);
00162     return self;
00163     }
00164 
00165 CVorbisEncoderPlugIn::CVorbisEncoderPlugIn()
00166     {
00167     }
00168 
00169 CVorbisEncoderPlugIn::~CVorbisEncoderPlugIn()
00170     {
00171     DEBUG("CVorbisEncoderPlugIn::~CVorbisEncoderPlugIn");
00172     delete iProc;
00173     }
00174 
00175 void CVorbisEncoderPlugIn::ConstructL()
00176     {
00177     iProc = CVorbisProcessor::NewL();
00178     }
00195 CMMFSwCodec::TCodecProcessResult CVorbisEncoderPlugIn::ProcessL(const CMMFBuffer& aSource, CMMFBuffer& aDst)
00196     {
00197     //DEBUG("CVorbisEncoderPlugIn::ProcessL");
00198     CMMFSwCodec::TCodecProcessResult res;
00199     CVorbisProcessor::TProcessResult status;
00200     iProc->ProcessL(aSource, aDst, status, res.iSrcBytesProcessed, res.iDstBytesAdded);
00201     switch (status)
00202         {
00203     case CVorbisProcessor::EComplete:
00204         res.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
00205         break;
00206     case CVorbisProcessor::EIncomplete:
00207         res.iCodecProcessStatus = TCodecProcessResult::EProcessIncomplete;
00208         break;
00209     case CVorbisProcessor::EDestNotFilled:
00210         res.iCodecProcessStatus = TCodecProcessResult::EDstNotFilled;
00211         break;
00212         }
00213     return res;
00214     }
00215 
00216 TUint CVorbisEncoderPlugIn::SourceBufferSize()
00217     {
00218     return KSourceBufferSize; 
00219     }
00220 
00221 TUint CVorbisEncoderPlugIn::SinkBufferSize()
00222     {
00223     return KSinkBufferSize; 
00224     }
00225         
00226 TInt CVorbisEncoderPlugIn::BitRateL()
00227         {
00228         return iProc->BitRateL();
00229         }
00230         
00231 void CVorbisEncoderPlugIn::SetBitRateL(TInt aBitRate)
00232         {
00233         iProc->SetBitRateL(aBitRate);
00234         }
00235         
00236 TInt CVorbisEncoderPlugIn::Configure(TInt aSampleRate, TInt aChannels)
00237         {
00238         TRAPD(err, iProc->ConfigureL(aSampleRate, aChannels));
00239         return err;
00240         }
00241 // __________________________________________________________________________
00242 // Exported proxy for instantiation method resolution
00243 // Define the interface UIDs
00244 
00245 const TImplementationProxy ImplementationTable[] =
00246         {
00247         IMPLEMENTATION_PROXY_ENTRY(KVorbisHwEncodeUid,  CVorbisEncoderPlugInWrapper::NewL),
00248         };
00249 
00250 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
00251         {
00252         aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
00253 
00254         return ImplementationTable;
00255         }

Generated by  doxygen 1.6.2