os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtMuLawToPcm16HwDevice.cpp
Update contrib.
1 // Copyright (c) 2005-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.
16 #include "MmfBtAudioCodec.h"
17 #include <mmfpaniccodes.h>
18 #include "MmfBtMuLawToPcm16HwDevice.h"
19 #include "../../MmfBtFileDependencyUtil.h"
26 CMMFMulawToPcm16CodecHwDevice* CMMFMulawToPcm16CodecHwDevice::NewL()
28 CMMFMulawToPcm16CodecHwDevice* self=new(ELeave) CMMFMulawToPcm16CodecHwDevice();
29 CleanupStack::PushL(self);
31 CleanupStack::Pop(self);
37 * ~CMMFMulawPcm16HwDevice
40 CMMFMulawToPcm16CodecHwDevice::~CMMFMulawToPcm16CodecHwDevice()
49 void CMMFMulawToPcm16CodecHwDevice::ConstructL()
51 iCodec = new (ELeave) CMMFMulawToPcm16Codec();
59 CMMFSwCodec &CMMFMulawToPcm16CodecHwDevice::Codec()
69 * @return TCodecProcessResult
72 CMMFSwCodec::TCodecProcessResult CMMFMulawToPcm16Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
74 CMMFSwCodec::TCodecProcessResult result;
75 result.iCodecProcessStatus = result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
77 //convert from generic CMMFBuffer to CMMFDataBuffer
78 const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
79 CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDst);
81 //[check preconditions hold ]
82 if( !CheckPreconditions( src, dst ))
84 //[ precondition violation ]
85 User::Leave( KErrArgument );
88 //we need to cast away CONST even on the source, as the TClass needs a TUint8*
89 TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
90 TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
91 TInt noSamples = src->Data().Length();
93 iMulawTo16Pcm.Convert(pSrc, pDst, noSamples );
95 TUint dstBytesAdded = noSamples*sizeof(TInt16);
97 result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
98 result.iSrcBytesProcessed = src->Data().Length();
99 result.iDstBytesAdded = dstBytesAdded;
101 dst->Data().SetLength( dstBytesAdded );
103 //[ check post conditions ]
104 __ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
105 __ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
106 __ASSERT_DEBUG( src->Data().Length() == dst->Data().Length()/2, TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // 2 here signifies sizeof TInt16
107 __ASSERT_DEBUG( dst->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // pcm output
115 * This methos tests the preconditions of the ProcessL method
116 * @return TBool ETrue for sucess and EFalse for failure of the preconditions
119 TBool CMMFMulawToPcm16Codec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
121 TBool result = EFalse;
133 // Check position of src and dest are 0
134 if( aSrcBuffer->Position() )
139 // Check position of src and dest are 0
140 if( aDestBuffer->Position() )
145 // check there are sufficient bytes in the output to consume the input
146 if( aSrcBuffer->Data().Length() > aDestBuffer->Data().MaxLength()/2 )
151 result = ETrue; // preconditions have been satisfied