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 "MmfBtPcm16ToAlawHwDevice.h"
17 #include "../../MmfBtFileDependencyUtil.h"
24 CMMFPcm16ToAlawHwDevice* CMMFPcm16ToAlawHwDevice::NewL()
26 CMMFPcm16ToAlawHwDevice* self=new(ELeave) CMMFPcm16ToAlawHwDevice();
27 CleanupStack::PushL(self);
29 CleanupStack::Pop(self);
35 * ~CMMFPcm16ToAlawHwDevice
38 CMMFPcm16ToAlawHwDevice::~CMMFPcm16ToAlawHwDevice()
47 void CMMFPcm16ToAlawHwDevice::ConstructL()
49 iCodec = new (ELeave) CMMFPcm16ToALawCodec();
58 CMMFSwCodec &CMMFPcm16ToAlawHwDevice::Codec()
68 * @pre position of buffer aSrc is 0
69 * @pre position of buffer aDst is 0
70 * @pre sufficient bytes in output to consume input
71 * @return TCodecProcessResult
74 CMMFSwCodec::TCodecProcessResult CMMFPcm16ToALawCodec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
76 CMMFSwCodec::TCodecProcessResult result;
77 result.iCodecProcessStatus = result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
79 //convert from generic CMMFBuffer to CMMFDataBuffer
80 const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
81 CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDst);
83 if( !CheckPreconditions( src, dst ))
85 //[ precondition violation ]
86 User::Leave( KErrArgument );
89 //we need to cast away CONST even on the source, as the TClass needs a TUint8*
90 TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
91 pSrc += src->Position();
92 TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
93 pDst += dst->Position();
95 TUint destUse = src->Data().Length()/2;
97 //compress TWO bytes (16-bit PCM word) into a to 1 byte sample
98 iPcm16ToALaw.Convert(pSrc, pDst, destUse );
100 result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
101 result.iSrcBytesProcessed = src->Data().Length();
102 result.iDstBytesAdded = destUse;
104 dst->Data().SetLength(result.iDstBytesAdded);
106 //[ post condition evaluation here ]
107 __ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
108 __ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
109 __ASSERT_DEBUG( src->Data().Length()/2 == dst->Data().Length(), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
117 * This methos tests the preconditions of the ProcessL method
118 * @return TBool ETrue for sucess and EFalse for failure of the preconditions
121 TBool CMMFPcm16ToALawCodec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
123 TBool result = EFalse;
135 // Check position of src and dest are 0
136 if( aSrcBuffer->Position() )
141 // Check position of src and dest are 0
142 if( aDestBuffer->Position() )
147 // check there are sufficient bytes in the output to consume the input
148 if( ( aSrcBuffer->Data().Length()/2 > aDestBuffer->Data().MaxLength()) ||
149 ( aSrcBuffer->Data().Length() % 2 != 0 ))
154 result = ETrue; // preconditions have been satisfied