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 <mmfbtswcodecwrapper.h>
22 #include <ecom/implementationproxy.h>
25 #include <ecom/ecom.h>
27 #include <mmfbthwdeviceimplementationuids.hrh>
28 #include "../../../MmfBtFileDependencyUtil.h"
33 * @return CMmfGsm610ToPcm16HwDevice*
36 CMmfGsm610ToPcm16HwDevice* CMmfGsm610ToPcm16HwDevice::NewL()
38 CMmfGsm610ToPcm16HwDevice* self=new(ELeave) CMmfGsm610ToPcm16HwDevice();
39 CleanupStack::PushL(self);
41 CleanupStack::Pop(self);
50 CMMFSwCodec& CMmfGsm610ToPcm16HwDevice::Codec()
57 * CMmfGsm610ToPcm16HwDevice
60 CMmfGsm610ToPcm16HwDevice::~CMmfGsm610ToPcm16HwDevice()
70 void CMmfGsm610ToPcm16HwDevice::ConstructL()
72 CMMFGsm610ToPcm16Codec* ptr= new(ELeave)CMMFGsm610ToPcm16Codec();
73 CleanupStack::PushL(ptr);
76 CleanupStack::Pop(ptr);
81 * CMmfPcm16ToGsm610HwDevice
84 CMmfPcm16ToGsm610HwDevice* CMmfPcm16ToGsm610HwDevice::NewL()
86 CMmfPcm16ToGsm610HwDevice* self=new(ELeave) CMmfPcm16ToGsm610HwDevice();
87 CleanupStack::PushL(self);
89 CleanupStack::Pop(self);
96 * @return CMMFSwCodec&
99 CMMFSwCodec& CMmfPcm16ToGsm610HwDevice::Codec()
106 * ~CMmfPcm16ToGsm610HwDevice
109 CMmfPcm16ToGsm610HwDevice::~CMmfPcm16ToGsm610HwDevice()
118 void CMmfPcm16ToGsm610HwDevice::ConstructL()
120 CMMFPcm16ToGsm610Codec* ptr =new(ELeave) CMMFPcm16ToGsm610Codec();
121 CleanupStack::PushL(ptr);
124 CleanupStack::Pop(ptr);
129 * CMMFGsm610ToPcm16Codec
132 CMMFGsm610ToPcm16Codec::CMMFGsm610ToPcm16Codec()
141 void CMMFGsm610ToPcm16Codec::ConstructL()
143 iGsmDecoder = new (ELeave) CGSM610FR_Decoder;
144 iGsmDecoder->ConstructL();
145 iGsmDecoder->StartL();
153 CMMFGsm610ToPcm16Codec* CMMFGsm610ToPcm16Codec::NewL()
155 CMMFGsm610ToPcm16Codec* self=new(ELeave) CMMFGsm610ToPcm16Codec();
156 CleanupStack::PushL(self);
158 CleanupStack::Pop(self);
164 * ~CMMFGsm610ToPcm16Codec
167 CMMFGsm610ToPcm16Codec::~CMMFGsm610ToPcm16Codec()
177 * @pre input buffer length is mod 65
178 * @pre output buffer has sufficient space for coded input
181 CMMFSwCodec::TCodecProcessResult CMMFGsm610ToPcm16Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDest)
183 CMMFSwCodec::TCodecProcessResult result;
184 result.iCodecProcessStatus = result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
186 //convert from generic CMMFBuffer to CMMFDataBuffer
187 CMMFBuffer* pSrcBuffer =const_cast<CMMFBuffer*>(&aSrc);
190 User::Leave( KErrArgument );
193 CMMFDataBuffer* src = static_cast<CMMFDataBuffer*>( pSrcBuffer );
196 User::Leave( KErrArgument );
199 CMMFDataBuffer* dst = static_cast<CMMFDataBuffer*>(&aDest);
202 User::Leave( KErrArgument );
205 if(!CheckInputBuffers( *src, *dst ))
207 User::Leave( KErrArgument );
210 TInt numBuffersToProcess = NumBuffersToProcess( *src );
211 TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
212 TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
214 for( TInt count = 0; count < numBuffersToProcess; count++ )
216 // Encode two frames of gsm data
217 iGsmDecoder->ExecuteL( pSrc, pDst );
218 pSrc += KGsmFrameSize;;
219 pDst += KPcmDataForGsmFrame;
220 result.iSrcBytesProcessed += KGsmFrameSize;
221 result.iDstBytesAdded += KPcmDataForGsmFrame;
224 dst->Data().SetLength( result.iDstBytesAdded );
225 __ASSERT_DEBUG( ProcessPostCondition( result ), TMmfGsmCodecPanicsNameSpace::Panic( TMmfGsmCodecPanicsNameSpace::EPostConditionViolation ));
235 * This function returns ETrue if the preconditions of processL are met
238 TBool CMMFGsm610ToPcm16Codec::CheckInputBuffers( CMMFDataBuffer& aSrc, CMMFDataBuffer& aDest )
240 TBool result = ETrue;
241 TInt numInputSubFrames = aSrc.Data().Length() / KGsmFrameSize;
242 TInt numOutputSubFrames = aDest.Data().MaxLength() / KPcmDataForGsmFrame;
243 TBool validInputDataLength = (aSrc.Data().Length() % KGsmFrameSize == 0);
245 if( (numInputSubFrames > numOutputSubFrames) || // sufficient space in the output for the input
246 (aSrc.Position() > 0 ) || // position must be zero since we can eat all the data
247 (aDest.Position() > 0 ) ||
248 (!validInputDataLength)) //position must be zero
258 * NumBuffersToProcess
261 * This method returns the number of buffers to process
264 TInt CMMFGsm610ToPcm16Codec::NumBuffersToProcess( const CMMFDataBuffer& aSrc )
266 TInt numBuffers = (aSrc.Data().Length() / KGsmFrameSize );
272 * ProcessPostCondition
274 * @return TBool Etrue if the post condition is satisfied
277 TBool CMMFGsm610ToPcm16Codec::ProcessPostCondition( const CMMFSwCodec::TCodecProcessResult& aResult )
279 TBool status = ETrue;
280 if( (aResult.iSrcBytesProcessed / KGsmFrameSize ) != (aResult.iDstBytesAdded / KPcmDataForGsmFrame ) )
287 /************************>----------------------------------<*****************************/
291 * CMMFPcm16ToGsm610Codec
294 CMMFPcm16ToGsm610Codec::CMMFPcm16ToGsm610Codec()
303 void CMMFPcm16ToGsm610Codec::ConstructL()
305 iGsmEncoder = new (ELeave) CGSM610FR_Encoder;
306 iGsmEncoder->ConstructL();
307 iGsmEncoder->StartL();
315 CMMFPcm16ToGsm610Codec* CMMFPcm16ToGsm610Codec::NewL()
317 CMMFPcm16ToGsm610Codec* self=new(ELeave) CMMFPcm16ToGsm610Codec();
318 CleanupStack::PushL(self);
320 CleanupStack::Pop(self);
326 * CMMFPcm16ToGsm610Codec
329 CMMFPcm16ToGsm610Codec::~CMMFPcm16ToGsm610Codec()
338 * @param aDest TCodecProcessResult
340 * @pre input buffer length is mod 320
341 * @pre output buffer has sufficient space for coded input
343 CMMFSwCodec::TCodecProcessResult CMMFPcm16ToGsm610Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDest)
345 CMMFSwCodec::TCodecProcessResult result;
346 result.iCodecProcessStatus = result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
348 //convert from generic CMMFBuffer to CMMFDataBuffer
349 CMMFBuffer* pSrcBuffer =const_cast<CMMFBuffer*>(&aSrc);
352 User::Leave( KErrArgument );
355 CMMFDataBuffer* src = static_cast<CMMFDataBuffer*>( pSrcBuffer );
358 User::Leave( KErrArgument );
361 CMMFDataBuffer* dst = static_cast<CMMFDataBuffer*>(&aDest);
364 User::Leave( KErrArgument );
368 if(!CheckInputBuffers( *src, *dst ))
370 User::Leave( KErrArgument );
373 TInt numBuffersToProcess = NumBuffersToProcess( *src );
374 TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
375 TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
377 for( TInt count = 0; count < numBuffersToProcess; count++ )
379 // Encode two frames of gsm data
380 iGsmEncoder->ExecuteL (pSrc, pDst);
381 pSrc += KPcmDataForGsmFrame;
382 pDst += KGsmFrameSize;
383 result.iSrcBytesProcessed += KPcmDataForGsmFrame;
384 result.iDstBytesAdded += KGsmFrameSize;
387 dst->Data().SetLength( result.iDstBytesAdded );
389 __ASSERT_DEBUG( ProcessPostCondition(result), TMmfGsmCodecPanicsNameSpace::Panic( TMmfGsmCodecPanicsNameSpace::EPostConditionViolation ));
400 * This function returns ETrue if there is sufficient space
401 * in the output buffer for the coded input and
402 * the position of both input buffers is zero
405 TBool CMMFPcm16ToGsm610Codec::CheckInputBuffers( CMMFDataBuffer& aSrc, CMMFDataBuffer& aDest )
407 TBool result = ETrue;
408 TInt numInputSubFrames = aSrc.Data().Length() / KPcmDataForGsmFrame;
409 TInt numOutputSubFrames = aDest.Data().MaxLength() / KGsmFrameSize;
410 TBool validInputDataLength = (aSrc.Data().Length() % KPcmDataForGsmFrame == 0);
412 if( (numInputSubFrames > numOutputSubFrames) || // sufficient space in the output for the input
413 (aSrc.Position() > 0 ) || // position must be zero since we can eat all the data
414 (aDest.Position() > 0 ) ||
415 (!validInputDataLength)) //position must be zero
425 * NumBuffersToProcess
428 * This method returns the number of buffers to process
431 TInt CMMFPcm16ToGsm610Codec::NumBuffersToProcess( const CMMFDataBuffer& aSrc )
433 TInt numBuffers = ( aSrc.Data().Length() / KPcmDataForGsmFrame );