Update contrib.
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
20 #include <mmf/server/mmfswcodecwrapper.h>
22 #include <ecom/implementationproxy.h>
25 #include <ecom/ecom.h>
27 #include <mmf/plugin/mmfhwdeviceimplementationuids.hrh>
32 * @return CMmfGsm610ToPcm16HwDevice*
35 CMmfGsm610ToPcm16HwDevice* CMmfGsm610ToPcm16HwDevice::NewL()
37 CMmfGsm610ToPcm16HwDevice* self=new(ELeave) CMmfGsm610ToPcm16HwDevice();
38 CleanupStack::PushL(self);
40 CleanupStack::Pop(self);
49 CMMFSwCodec& CMmfGsm610ToPcm16HwDevice::Codec()
56 * CMmfGsm610ToPcm16HwDevice
59 CMmfGsm610ToPcm16HwDevice::~CMmfGsm610ToPcm16HwDevice()
69 void CMmfGsm610ToPcm16HwDevice::ConstructL()
71 CMMFGsm610ToPcm16Codec* ptr= new(ELeave)CMMFGsm610ToPcm16Codec();
72 CleanupStack::PushL(ptr);
75 CleanupStack::Pop(ptr);
80 * CMmfPcm16ToGsm610HwDevice
83 CMmfPcm16ToGsm610HwDevice* CMmfPcm16ToGsm610HwDevice::NewL()
85 CMmfPcm16ToGsm610HwDevice* self=new(ELeave) CMmfPcm16ToGsm610HwDevice();
86 CleanupStack::PushL(self);
88 CleanupStack::Pop(self);
95 * @return CMMFSwCodec&
98 CMMFSwCodec& CMmfPcm16ToGsm610HwDevice::Codec()
105 * ~CMmfPcm16ToGsm610HwDevice
108 CMmfPcm16ToGsm610HwDevice::~CMmfPcm16ToGsm610HwDevice()
117 void CMmfPcm16ToGsm610HwDevice::ConstructL()
119 CMMFPcm16ToGsm610Codec* ptr =new(ELeave) CMMFPcm16ToGsm610Codec();
120 CleanupStack::PushL(ptr);
123 CleanupStack::Pop(ptr);
128 * CMMFGsm610ToPcm16Codec
131 CMMFGsm610ToPcm16Codec::CMMFGsm610ToPcm16Codec()
140 void CMMFGsm610ToPcm16Codec::ConstructL()
142 iGsmDecoder = new (ELeave) CGSM610FR_Decoder;
143 iGsmDecoder->ConstructL();
144 iGsmDecoder->StartL();
152 CMMFGsm610ToPcm16Codec* CMMFGsm610ToPcm16Codec::NewL()
154 CMMFGsm610ToPcm16Codec* self=new(ELeave) CMMFGsm610ToPcm16Codec();
155 CleanupStack::PushL(self);
157 CleanupStack::Pop(self);
163 * ~CMMFGsm610ToPcm16Codec
166 CMMFGsm610ToPcm16Codec::~CMMFGsm610ToPcm16Codec()
176 * @precondition input buffer length is mod 65
177 * @precondition output buffer has sufficient space for coded input
180 CMMFSwCodec::TCodecProcessResult CMMFGsm610ToPcm16Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDest)
182 CMMFSwCodec::TCodecProcessResult result;
183 result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
185 //convert from generic CMMFBuffer to CMMFDataBuffer
186 CMMFBuffer* pSrcBuffer =const_cast<CMMFBuffer*>(&aSrc);
189 User::Leave( KErrArgument );
192 CMMFDataBuffer* src = static_cast<CMMFDataBuffer*>( pSrcBuffer );
195 User::Leave( KErrArgument );
198 CMMFDataBuffer* dst = static_cast<CMMFDataBuffer*>(&aDest);
201 User::Leave( KErrArgument );
204 if(!CheckInputBuffers( *src, *dst ))
206 User::Leave( KErrArgument );
209 TInt numBuffersToProcess = NumBuffersToProcess( *src );
210 TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
211 TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
213 for( TInt count = 0; count < numBuffersToProcess; count++ )
215 // Encode two frames of gsm data
216 iGsmDecoder->ExecuteL( pSrc, pDst );
217 pSrc += KGsmFrameSize;;
218 pDst += KPcmDataForGsmFrame;
219 result.iSrcBytesProcessed += KGsmFrameSize;
220 result.iDstBytesAdded += KPcmDataForGsmFrame;
223 dst->Data().SetLength( result.iDstBytesAdded );
224 __ASSERT_DEBUG( ProcessPostCondition( result ), TMmfGsmCodecPanicsNameSpace::Panic( TMmfGsmCodecPanicsNameSpace::EPostConditionViolation ));
234 * This function returns ETrue if the preconditions of processL are met
237 TBool CMMFGsm610ToPcm16Codec::CheckInputBuffers( CMMFDataBuffer& aSrc, CMMFDataBuffer& aDest )
239 TBool result = ETrue;
240 TInt numInputSubFrames = aSrc.Data().Length() / KGsmFrameSize;
241 TInt numOutputSubFrames = aDest.Data().MaxLength() / KPcmDataForGsmFrame;
242 TBool validInputDataLength = (aSrc.Data().Length() % KGsmFrameSize == 0) ? ETrue : aSrc.LastBuffer();
244 if( (numInputSubFrames > numOutputSubFrames) || // sufficient space in the output for the input
245 (aSrc.Position() > 0 ) || // position must be zero since we can eat all the data
246 (aDest.Position() > 0 ) ||
247 (!validInputDataLength)) //position must be zero
257 * NumBuffersToProcess
260 * This method returns the number of buffers to process
263 TInt CMMFGsm610ToPcm16Codec::NumBuffersToProcess( const CMMFDataBuffer& aSrc )
265 TInt numBuffers = (aSrc.Data().Length() / KGsmFrameSize );
271 * ProcessPostCondition
273 * @result TBool Etrue if the post condition is satisfied
276 TBool CMMFGsm610ToPcm16Codec::ProcessPostCondition( const CMMFSwCodec::TCodecProcessResult& aResult )
278 TBool status = ETrue;
279 if( (aResult.iSrcBytesProcessed / KGsmFrameSize ) != (aResult.iDstBytesAdded / KPcmDataForGsmFrame ) )
286 /************************>----------------------------------<*****************************/
290 * CMMFPcm16ToGsm610Codec
293 CMMFPcm16ToGsm610Codec::CMMFPcm16ToGsm610Codec()
302 void CMMFPcm16ToGsm610Codec::ConstructL()
304 iGsmEncoder = new (ELeave) CGSM610FR_Encoder;
305 iGsmEncoder->ConstructL();
306 iGsmEncoder->StartL();
314 CMMFPcm16ToGsm610Codec* CMMFPcm16ToGsm610Codec::NewL()
316 CMMFPcm16ToGsm610Codec* self=new(ELeave) CMMFPcm16ToGsm610Codec();
317 CleanupStack::PushL(self);
319 CleanupStack::Pop(self);
325 * CMMFPcm16ToGsm610Codec
328 CMMFPcm16ToGsm610Codec::~CMMFPcm16ToGsm610Codec()
337 * @param aDest TCodecProcessResult
339 * @precondition input buffer length is mod 320
340 * @precondition output buffer has sufficient space for coded input
342 CMMFSwCodec::TCodecProcessResult CMMFPcm16ToGsm610Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDest)
344 CMMFSwCodec::TCodecProcessResult result;
345 result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
347 //convert from generic CMMFBuffer to CMMFDataBuffer
348 CMMFBuffer* pSrcBuffer =const_cast<CMMFBuffer*>(&aSrc);
351 User::Leave( KErrArgument );
354 CMMFDataBuffer* src = static_cast<CMMFDataBuffer*>( pSrcBuffer );
357 User::Leave( KErrArgument );
360 CMMFDataBuffer* dst = static_cast<CMMFDataBuffer*>(&aDest);
363 User::Leave( KErrArgument );
367 if(!CheckInputBuffers( *src, *dst ))
369 User::Leave( KErrArgument );
372 TInt numBuffersToProcess = NumBuffersToProcess( *src );
373 TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
374 TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
376 for( TInt count = 0; count < numBuffersToProcess; count++ )
378 // Encode two frames of gsm data
379 iGsmEncoder->ExecuteL (pSrc, pDst);
380 pSrc += KPcmDataForGsmFrame;
381 pDst += KGsmFrameSize;
382 result.iSrcBytesProcessed += KPcmDataForGsmFrame;
383 result.iDstBytesAdded += KGsmFrameSize;
386 dst->Data().SetLength( result.iDstBytesAdded );
388 __ASSERT_DEBUG( ProcessPostCondition(result), TMmfGsmCodecPanicsNameSpace::Panic( TMmfGsmCodecPanicsNameSpace::EPostConditionViolation ));
399 * This function returns ETrue if there is sufficient space
400 * in the output buffer for the coded input and
401 * the position of both input buffers is zero
404 TBool CMMFPcm16ToGsm610Codec::CheckInputBuffers( CMMFDataBuffer& aSrc, CMMFDataBuffer& aDest )
406 TBool result = ETrue;
407 TInt numInputSubFrames = aSrc.Data().Length() / KPcmDataForGsmFrame;
408 TInt numOutputSubFrames = aDest.Data().MaxLength() / KGsmFrameSize;
410 TBool validInputDataLength = (aSrc.Data().Length() % KPcmDataForGsmFrame == 0);
412 TBool validInputDataLength = (aSrc.LastBuffer()? ETrue: (aSrc.Data().Length() % KPcmDataForGsmFrame == 0));
414 if( (numInputSubFrames > numOutputSubFrames) || // sufficient space in the output for the input
415 (aSrc.Position() > 0 ) || // position must be zero since we can eat all the data
416 (aDest.Position() > 0 ) ||
417 (!validInputDataLength)) //position must be zero
427 * NumBuffersToProcess
430 * This method returns the number of buffers to process
433 TInt CMMFPcm16ToGsm610Codec::NumBuffersToProcess( const CMMFDataBuffer& aSrc )
435 TInt numBuffers = ( aSrc.Data().Length() / KPcmDataForGsmFrame );