os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcm16ToMulawHwDevice.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 "MmfBtPcm16ToMulawHwDevice.h"
17 #include "../../MmfBtFileDependencyUtil.h"
24 CMMFPcm16ToMulawHwDevice* CMMFPcm16ToMulawHwDevice::NewL()
26 CMMFPcm16ToMulawHwDevice* self=new(ELeave) CMMFPcm16ToMulawHwDevice();
27 CleanupStack::PushL(self);
29 CleanupStack::Pop(self);
35 * ~CMMFPcm16ToMulawHwDevice
38 CMMFPcm16ToMulawHwDevice::~CMMFPcm16ToMulawHwDevice()
47 void CMMFPcm16ToMulawHwDevice::ConstructL()
49 iCodec = new (ELeave) CMMFPcm16ToMuLawCodec();
57 CMMFSwCodec &CMMFPcm16ToMulawHwDevice::Codec()
67 * @pre position of buffer aSrc is 0
68 * @pre position of buffer aDst is 0
69 * @pre sufficient bytes in output to consume input
70 * @return TCodecProcessResult
73 CMMFSwCodec::TCodecProcessResult CMMFPcm16ToMuLawCodec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
75 CMMFSwCodec::TCodecProcessResult result;
76 result.iCodecProcessStatus = result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
78 //convert from generic CMMFBuffer to CMMFDataBuffer
79 const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
80 CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDst);
82 if( !CheckPreconditions( src, dst ) )
84 //[ precondition(s) violation ]
85 User::Leave(KErrArgument);
88 TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
89 TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
91 TUint destUse = src->Data().Length()/2;
93 //compress TWO bytes (16-bit PCM word) into a to 1 byte sample
94 iPcm16ToMuLaw.Convert(pSrc, pDst, destUse );
96 result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
97 result.iSrcBytesProcessed = src->Data().Length();
98 result.iDstBytesAdded = destUse;
100 dst->Data().SetLength(result.iDstBytesAdded);
103 // srcbytes/2 == destbytes added
106 __ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
107 __ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
108 __ASSERT_DEBUG( src->Data().Length()/2 == dst->Data().Length(), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
116 * This method tests the preconditions of the ProcessL method
117 * @return TBool ETrue for sucess and EFalse for failure of the preconditions
120 TBool CMMFPcm16ToMuLawCodec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
122 TBool result = EFalse;
134 // Check position of src and dest are 0
135 if( aSrcBuffer->Position() )
140 // Check position of src and dest are 0
141 if( aDestBuffer->Position() )
146 // check there are sufficient bytes in the output to consume the input
147 if( ( aSrcBuffer->Data().Length()/2 > aDestBuffer->Data().MaxLength()) ||
148 ( aSrcBuffer->Data().Length() % 2 != 0 ))
153 result = ETrue; // preconditions have been satisfied