os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcmS16ToPcmS8HwDevice.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 "MmfBtPcmS16ToPcmS8HwDevice.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 CMMFPcmS16ToPcmS8HwDevice* CMMFPcmS16ToPcmS8HwDevice::NewL()
29 CMMFPcmS16ToPcmS8HwDevice* self = new (ELeave) CMMFPcmS16ToPcmS8HwDevice();
30 CleanupStack::PushL(self);
32 CleanupStack::Pop(self);
38 * ~CMMFPcmS16ToPcmS8HwDevice
40 CMMFPcmS16ToPcmS8HwDevice::~CMMFPcmS16ToPcmS8HwDevice()
49 void CMMFPcmS16ToPcmS8HwDevice::ConstructL()
51 iCodec = new (ELeave) CMMFPcmS16ToPcmS8Codec();
57 * @return 'CMMFSwCodec&'
60 CMMFSwCodec& CMMFPcmS16ToPcmS8HwDevice::Codec()
73 CMMFSwCodec::TCodecProcessResult CMMFPcmS16ToPcmS8Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
75 TCodecProcessResult result;
76 result.iCodecProcessStatus = result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
78 //convert from generic CMMFBuffer to CMMFDataBuffer
79 const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
80 CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDst);
82 //[Check Preconditions]
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 TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
93 TInt srcUse = src->Data().Length();
94 TInt noSamples = srcUse/2;
96 //compress TWO bytes (16-bit PCM word) into a to 1 byte sample
97 iAudioPcmS16ToPcmS8.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 CMMFPcmS16ToPcmS8Codec::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() ) &&
151 ( aSrcBuffer->Data().Length() % 2 == 0 ) ) // must have pcm16 samples on input
156 result = ETrue; // preconditions have been satisfied