os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcm16ToPcmU8HwDevice.cpp
Update contrib.
1 // Copyright (c) 2003-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.
14 // MmfPcm16ToPcmU8HwDevice.cpp
18 #include "MmfBtPcm16ToPcmU8HwDevice.h"
19 #include "../../MmfBtFileDependencyUtil.h"
23 * Returns the created hw device for signed pcm16 to unsigned pcm8 audio.
25 * @return "CMMFPcm16ToPcmU8HwDevice"
28 CMMFPcm16ToPcmU8HwDevice* CMMFPcm16ToPcmU8HwDevice::NewL()
30 CMMFPcm16ToPcmU8HwDevice* self = new (ELeave) CMMFPcm16ToPcmU8HwDevice();
31 CleanupStack::PushL(self);
33 CleanupStack::Pop(self);
39 * Second phase constructor.
42 void CMMFPcm16ToPcmU8HwDevice::ConstructL()
44 iCodec = new (ELeave) CMMFPcm16ToPcmU8Codec();
49 * ~CMMFPcm16ToPcmU8HwDevice
51 CMMFPcm16ToPcmU8HwDevice::~CMMFPcm16ToPcmU8HwDevice()
53 //The codec is deleted in the base class CMMFSwCodecWrapper
59 * @return 'CMMFSwCodec&'
62 CMMFSwCodec& CMMFPcm16ToPcmU8HwDevice::Codec()
72 * @return 'CMMFSwCodec::TCodecProcessResult'
75 CMMFSwCodec::TCodecProcessResult CMMFPcm16ToPcmU8Codec::ProcessL(const CMMFBuffer& aSource, CMMFBuffer& aDest)
77 TCodecProcessResult result;
78 result.iCodecProcessStatus = result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
80 //convert from generic CMMFBuffer to CMMFDataBuffer
81 const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSource);
82 CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDest);
84 if( !CheckPreconditions( src, dst ))
86 //[ precondition violation ]
87 User::Leave( KErrArgument );
90 //we need to cast away CONST even on the source, as the TClass needs a TUint8*
91 TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
92 TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
94 TInt srcUse = src->Data().Length();
96 TInt noSamples = srcUse /2;
97 iAudioS16ToU8Pcm.Convert(pSrc, pDst, noSamples );
99 result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
100 result.iSrcBytesProcessed = srcUse;
101 result.iDstBytesAdded = srcUse / 2;
103 dst->Data().SetLength(result.iDstBytesAdded);
106 // srcbytes/2 == destbytes added
109 __ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
110 __ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
111 __ASSERT_DEBUG( src->Data().Length()/2 == dst->Data().Length(), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
119 * This methos tests the preconditions of the ProcessL method
120 * @return TBool ETrue for sucess and EFalse for failure of the preconditions
123 TBool CMMFPcm16ToPcmU8Codec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
125 TBool result = EFalse;
137 // Check position of src and dest are 0
138 if( aSrcBuffer->Position() )
143 // Check position of src and dest are 0
144 if( aDestBuffer->Position() )
149 // check there are sufficient bytes in the output to consume the input
150 if( aSrcBuffer->Data().Length()/2 > aDestBuffer->Data().MaxLength() )
155 result = ETrue; // preconditions have been satisfied