os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcmU16BeToPcmS16HwDevice.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 "MmfBtPcmU16BeToPcmS16HwDevice.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 CMMFPcmU16BeToPcmS16HwDevice* CMMFPcmU16BeToPcmS16HwDevice::NewL()
29 CMMFPcmU16BeToPcmS16HwDevice* self = new (ELeave) CMMFPcmU16BeToPcmS16HwDevice();
30 CleanupStack::PushL(self);
32 CleanupStack::Pop(self);
38 * ~CMMFPcmU16BeToPcmS16HwDevice
41 CMMFPcmU16BeToPcmS16HwDevice::~CMMFPcmU16BeToPcmS16HwDevice()
48 * @return 'CMMFSwCodec&'
51 CMMFSwCodec& CMMFPcmU16BeToPcmS16HwDevice::Codec()
61 void CMMFPcmU16BeToPcmS16HwDevice::ConstructL()
63 iCodec = new (ELeave) CMMFPcmU16BeToPcmS16Codec();
71 * @return CMMFSwCodec::TCodecProcessResult
72 * this codec has a does not expand or shrink destination data
74 CMMFSwCodec::TCodecProcessResult CMMFPcmU16BeToPcmS16Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
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*, &aSrc);
81 CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDst);
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/2;
96 iAudioPcmU16BeToPcmS16.Convert(pSrc, pDst, noSamples);
98 result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
99 result.iSrcBytesProcessed = srcUse;
100 result.iDstBytesAdded = srcUse;
102 dst->Data().SetLength(srcUse);
105 // srcbytes/2 == destbytes added
108 // src data length is even
109 // dst data length is even ie pcm16 samples ]
110 __ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
111 __ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
112 __ASSERT_DEBUG( src->Data().Length() == dst->Data().Length(), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
113 __ASSERT_DEBUG( dst->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
114 __ASSERT_DEBUG( src->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
122 * This methos tests the preconditions of the ProcessL method
123 * @return TBool ETrue for sucess and EFalse for failure of the preconditions
126 TBool CMMFPcmU16BeToPcmS16Codec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
128 TBool result = EFalse;
140 // Check position of src and dest are 0
141 if( aSrcBuffer->Position() )
146 // Check position of src and dest are 0
147 if( aDestBuffer->Position() )
152 // check there are sufficient bytes in the output to consume the input
153 if( ( aSrcBuffer->Data().Length() > aDestBuffer->Data().MaxLength() ) ||
154 ( aSrcBuffer->Data().Length() % 2 != 0 ) ) // must have pcm16 samples on input
159 result = ETrue; // preconditions have been satisfied