os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcm16ToPcmU8HwDevice.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcm16ToPcmU8HwDevice.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,158 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// MmfPcm16ToPcmU8HwDevice.cpp
1.18 +//
1.19 +//
1.20 +
1.21 +#include "MmfBtPcm16ToPcmU8HwDevice.h"
1.22 +#include "../../MmfBtFileDependencyUtil.h"
1.23 +
1.24 +/**
1.25 + *
1.26 + * Returns the created hw device for signed pcm16 to unsigned pcm8 audio.
1.27 + *
1.28 + * @return "CMMFPcm16ToPcmU8HwDevice"
1.29 + *
1.30 + */
1.31 +CMMFPcm16ToPcmU8HwDevice* CMMFPcm16ToPcmU8HwDevice::NewL()
1.32 + {
1.33 + CMMFPcm16ToPcmU8HwDevice* self = new (ELeave) CMMFPcm16ToPcmU8HwDevice();
1.34 + CleanupStack::PushL(self);
1.35 + self->ConstructL();
1.36 + CleanupStack::Pop(self);
1.37 + return self;
1.38 + }
1.39 +
1.40 +/**
1.41 + *
1.42 + * Second phase constructor.
1.43 + *
1.44 + */
1.45 +void CMMFPcm16ToPcmU8HwDevice::ConstructL()
1.46 + {
1.47 + iCodec = new (ELeave) CMMFPcm16ToPcmU8Codec();
1.48 + }
1.49 +
1.50 +/**
1.51 +*
1.52 +* ~CMMFPcm16ToPcmU8HwDevice
1.53 +*/
1.54 +CMMFPcm16ToPcmU8HwDevice::~CMMFPcm16ToPcmU8HwDevice()
1.55 + {
1.56 + //The codec is deleted in the base class CMMFSwCodecWrapper
1.57 + }
1.58 +
1.59 +/**
1.60 +*
1.61 +* Codec
1.62 +* @return 'CMMFSwCodec&'
1.63 +*
1.64 +*/
1.65 +CMMFSwCodec& CMMFPcm16ToPcmU8HwDevice::Codec()
1.66 + {
1.67 + return *iCodec;
1.68 + }
1.69 +
1.70 +/**
1.71 +*
1.72 +* ProcessL
1.73 +* @param aSrc
1.74 +* @param aDst
1.75 +* @return 'CMMFSwCodec::TCodecProcessResult'
1.76 +*
1.77 +*/
1.78 +CMMFSwCodec::TCodecProcessResult CMMFPcm16ToPcmU8Codec::ProcessL(const CMMFBuffer& aSource, CMMFBuffer& aDest)
1.79 + {
1.80 + TCodecProcessResult result;
1.81 + result.iCodecProcessStatus = result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
1.82 +
1.83 + //convert from generic CMMFBuffer to CMMFDataBuffer
1.84 + const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSource);
1.85 + CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDest);
1.86 +
1.87 + if( !CheckPreconditions( src, dst ))
1.88 + {
1.89 + //[ precondition violation ]
1.90 + User::Leave( KErrArgument );
1.91 + }
1.92 +
1.93 + //we need to cast away CONST even on the source, as the TClass needs a TUint8*
1.94 + TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
1.95 + TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
1.96 +
1.97 + TInt srcUse = src->Data().Length();
1.98 +
1.99 + TInt noSamples = srcUse /2;
1.100 + iAudioS16ToU8Pcm.Convert(pSrc, pDst, noSamples );
1.101 +
1.102 + result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
1.103 + result.iSrcBytesProcessed = srcUse;
1.104 + result.iDstBytesAdded = srcUse / 2;
1.105 +
1.106 + dst->Data().SetLength(result.iDstBytesAdded);
1.107 +
1.108 + //[ post conditions
1.109 + // srcbytes/2 == destbytes added
1.110 + // pos src == 0
1.111 + // pos dest == 0 ]
1.112 + __ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
1.113 + __ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
1.114 + __ASSERT_DEBUG( src->Data().Length()/2 == dst->Data().Length(), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
1.115 +
1.116 + return result;
1.117 + }
1.118 +
1.119 +/**
1.120 +*
1.121 +* Preconditions
1.122 +* This methos tests the preconditions of the ProcessL method
1.123 +* @return TBool ETrue for sucess and EFalse for failure of the preconditions
1.124 +*
1.125 +**/
1.126 +TBool CMMFPcm16ToPcmU8Codec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
1.127 + {
1.128 + TBool result = EFalse;
1.129 +
1.130 + if(! aSrcBuffer )
1.131 + {
1.132 + return result;
1.133 + }
1.134 +
1.135 + if( ! aDestBuffer )
1.136 + {
1.137 + return result;
1.138 + }
1.139 +
1.140 + // Check position of src and dest are 0
1.141 + if( aSrcBuffer->Position() )
1.142 + {
1.143 + return result;
1.144 + }
1.145 +
1.146 + // Check position of src and dest are 0
1.147 + if( aDestBuffer->Position() )
1.148 + {
1.149 + return result;
1.150 + }
1.151 +
1.152 + // check there are sufficient bytes in the output to consume the input
1.153 + if( aSrcBuffer->Data().Length()/2 > aDestBuffer->Data().MaxLength() )
1.154 + {
1.155 + return result;
1.156 + }
1.157 +
1.158 + result = ETrue; // preconditions have been satisfied
1.159 +
1.160 + return result;
1.161 + }