os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcmU8ToPcm16HwDevice.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 "MmfBtPcmU8ToPcm16HwDevice.h"
17 #include "../../MmfBtFileDependencyUtil.h"
21 * Returns the created hw device for unsigned pcm8 to signed pcm16 audio.
23 * @return "CMMFPcmU8ToPcm16HwDevice"
26 CMMFPcmU8ToPcm16HwDevice* CMMFPcmU8ToPcm16HwDevice::NewL()
28 CMMFPcmU8ToPcm16HwDevice* self = new (ELeave) CMMFPcmU8ToPcm16HwDevice();
29 CleanupStack::PushL(self);
31 CleanupStack::Pop(self);
37 * Second phase constructor.
40 void CMMFPcmU8ToPcm16HwDevice::ConstructL()
42 iCodec = new (ELeave) CMMFPcmU8ToPcm16Codec();
47 * ~CMMFPcmU8ToPcm16HwDevice
50 CMMFPcmU8ToPcm16HwDevice::~CMMFPcmU8ToPcm16HwDevice()
52 //The codec is deleted in the base class CMMFSwCodecWrapper
58 * @return 'CMMFSwCodec&'
61 CMMFSwCodec& CMMFPcmU8ToPcm16HwDevice::Codec()
71 * @return 'CMMFSwCodec::TCodecProcessResult'
74 CMMFSwCodec::TCodecProcessResult CMMFPcmU8ToPcm16Codec::ProcessL(const CMMFBuffer& aSource, CMMFBuffer& aDest)
76 TCodecProcessResult result;
77 result.iCodecProcessStatus = result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
79 //convert from generic CMMFBuffer to CMMFDataBuffer
80 const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSource);
81 CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDest);
83 //[ check preconditions ]
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();
95 TInt noSamples = srcUse;
96 iAudioU8ToS16Pcm.Convert(pSrc, pDst, noSamples );
98 TInt dstBytesAdded = srcUse * 2;
99 result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
100 result.iSrcBytesProcessed = srcUse;
101 result.iDstBytesAdded = dstBytesAdded;
103 dst->Data().SetLength(dstBytesAdded);
105 //[ check post conditions ]
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() == dst->Data().Length()/2, TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // 2 here signifies sizeof TInt16
109 __ASSERT_DEBUG( dst->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // pcm output
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 CMMFPcmU8ToPcm16Codec::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() )
153 result = ETrue; // preconditions have been satisfied