diff -r 000000000000 -r 40261b775718 mmlibs/mmfw/src/Plugin/Codec/audio/Mmfaudiou16Topcms16codec.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mmlibs/mmfw/src/Plugin/Codec/audio/Mmfaudiou16Topcms16codec.cpp Tue Feb 02 01:56:55 2010 +0200 @@ -0,0 +1,94 @@ +/* +* Copyright (c) 1997-2002 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + +#include "MMFAudioU16ToPcmS16Codec.h" + +// __________________________________________________________________________ +// Implementation + +CMMFCodec* CMMFAudioU16PcmS16Codec::NewL(TAny* aInitParams) + { + CMMFAudioU16PcmS16Codec* self=new(ELeave) CMMFAudioU16PcmS16Codec(); + CleanupStack::PushL(self); + self->ConstructL(aInitParams); + CleanupStack::Pop(self); + return STATIC_CAST( CMMFCodec*, self ); + } + +CMMFAudioU16PcmS16Codec::~CMMFAudioU16PcmS16Codec() + { + } + +CMMFAudioU16PcmS16Codec::CMMFAudioU16PcmS16Codec() + { + } + +void CMMFAudioU16PcmS16Codec::ConstructL(TAny* /*aInitParams*/) + { + } + + +//this codec has a does not expand or shrink destination data +TCodecProcessResult CMMFAudioU16PcmS16Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst) + { + + TCodecProcessResult result; + result.iStatus = TCodecProcessResult::EProcessIncomplete; + + //convert from generic CMMFBuffer to CMMFDataBuffer + iSrc = STATIC_CAST(const CMMFDataBuffer*, &aSrc); + iDst = STATIC_CAST(CMMFDataBuffer*, &aDst); + + const TUint dstMaxLen = iDst->Data().MaxLength(); + + if (!dstMaxLen) + User::Leave(KErrArgument); + + //don't scribble Destination (pDst) by only consuming enough source to fill pDst + TUint srcUse = dstMaxLen - iDst->Position(); + const TUint srcLen = iSrc->Data().Length(); + const TUint sourceRemain = srcLen - iSrc->Position(); + + //make sure we don't blow source by checking against remaining + //and clipping to minimum remaining if necessary + srcUse = (srcUseData().Ptr()); + pSrc += iSrc->Position(); + TUint8* pDst = CONST_CAST(TUint8*,iDst->Data().Ptr()); + pDst += iDst->Position(); + + //divide by TWO as 2 bytes are equal to 1 sample + iAudioU16ToS16Pcm.Convert(pSrc, pDst, srcUse / 2); + + if (srcUse + iDst->Position() < dstMaxLen) + result.iStatus = TCodecProcessResult::EDstNotFilled; + + else if (srcUse + iSrc->Position() >= srcLen) + result.iStatus = TCodecProcessResult::EProcessComplete; + + result.iSrcBytesProcessed = srcUse; + result.iDstBytesAdded = srcUse; + + iDst->Data().SetLength(iDst->Position() + srcUse); + + return result; + + }