os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcm16ToPcmU16BEHwDevice.cpp
First public contribution.
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 "MmfBtPcm16ToPcmU16BEHwDevice.h"
17 #include "../../MmfBtFileDependencyUtil.h"
21 * Returns the created hw device for passing audio through audio.
22 * for the wins implementation this would always be pcm16 although
23 * this is effectively a null hw device that will pass any datatype through
24 * @return "CMMFPcm16ToPcmU16BEHwDevice"
27 CMMFPcm16ToPcmU16BEHwDevice* CMMFPcm16ToPcmU16BEHwDevice::NewL()
29 CMMFPcm16ToPcmU16BEHwDevice* self = new (ELeave) CMMFPcm16ToPcmU16BEHwDevice();
30 CleanupStack::PushL(self);
32 CleanupStack::Pop(self);
38 * ~CMMFPcm16ToPcmU16BEHwDevice
40 CMMFPcm16ToPcmU16BEHwDevice::~CMMFPcm16ToPcmU16BEHwDevice()
49 void CMMFPcm16ToPcmU16BEHwDevice::ConstructL()
51 iCodec = new (ELeave) CMMFPcm16ToPcmU16BECodec();
57 * @return 'CMMFSwCodec&'
59 CMMFSwCodec& CMMFPcm16ToPcmU16BEHwDevice::Codec()
69 * @pre position of buffer aSrc is 0
70 * @pre position of buffer aDst is 0
71 * @pre sufficient bytes in output to consume input
72 * @return 'CMMFSwCodec::TCodecProcessResult'
73 * this codec has a does not expand or shrink destination data
75 CMMFSwCodec::TCodecProcessResult CMMFPcm16ToPcmU16BECodec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
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*, &aSrc);
82 CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDst);
84 //[ Check preconsitions ]
85 if( !CheckPreconditions( src, dst ))
87 //[ precondition violation ]
88 User::Leave( KErrArgument );
91 //we need to cast away CONST even on the source, as the TClass needs a TUint8*
92 TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
93 TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
95 TInt srcUse = src->Data().Length();
97 TInt noSamples = srcUse/2; // for pcm16 TInt16
98 iAudioPcm16ToPcmU16Be.Convert(pSrc, pDst, noSamples );
100 result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
101 result.iSrcBytesProcessed = srcUse;
102 result.iDstBytesAdded = srcUse;
104 dst->Data().SetLength(srcUse);
106 //[ Check post conditions ]
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() == dst->Data().Length(), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
110 __ASSERT_DEBUG( dst->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // pcm output
118 * This methos tests the preconditions of the ProcessL method
119 * @return TBool ETrue for sucess and EFalse for failure of the preconditions
122 TBool CMMFPcm16ToPcmU16BECodec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
124 TBool result = EFalse;
136 // Check position of src and dest are 0
137 if( aSrcBuffer->Position() )
142 // Check position of src and dest are 0
143 if( aDestBuffer->Position() )
148 // check there are sufficient bytes in the output to consume the input
149 if( ( aSrcBuffer->Data().Length() > aDestBuffer->Data().MaxLength() ) ||
150 ( aSrcBuffer->Data().Length() % 2 != 0 ) ) // must have pcm16 samples on input
155 result = ETrue; // preconditions have been satisfied