1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmlibs/mmfw/src/Plugin/Codec/audio/MmfmulawTopcm16codec.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,90 @@
1.4 +// Copyright (c) 1997-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 +//
1.18 +
1.19 +
1.20 +#include "MMFMuLawToPcm16Codec.h"
1.21 +
1.22 +// __________________________________________________________________________
1.23 +// Implementation
1.24 +
1.25 +CMMFCodec* CMMFMulawPcm16Codec::NewL(TAny* aInitParams)
1.26 + {
1.27 + CMMFMulawPcm16Codec* self=new(ELeave) CMMFMulawPcm16Codec();
1.28 + CleanupStack::PushL(self);
1.29 + self->ConstructL(aInitParams);
1.30 + CleanupStack::Pop(self);
1.31 + return STATIC_CAST( CMMFCodec*, self );
1.32 + }
1.33 +
1.34 +CMMFMulawPcm16Codec::~CMMFMulawPcm16Codec()
1.35 + {
1.36 + }
1.37 +
1.38 +CMMFMulawPcm16Codec::CMMFMulawPcm16Codec()
1.39 + {
1.40 + }
1.41 +
1.42 +void CMMFMulawPcm16Codec::ConstructL(TAny* /*aInitParams*/)
1.43 + {
1.44 + }
1.45 +
1.46 +
1.47 +//this codec expands 1 byte to 2 bytes
1.48 +TCodecProcessResult CMMFMulawPcm16Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
1.49 + {
1.50 +
1.51 + TCodecProcessResult result;
1.52 + result.iStatus = TCodecProcessResult::EProcessIncomplete;
1.53 +
1.54 + //convert from generic CMMFBuffer to CMMFDataBuffer
1.55 + iSrc = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
1.56 + iDst = STATIC_CAST(CMMFDataBuffer*, &aDst);
1.57 +
1.58 + const TUint dstMaxLen = iDst->Data().MaxLength();
1.59 +
1.60 + if (!dstMaxLen)
1.61 + User::Leave(KErrArgument);
1.62 +
1.63 + //don't scribble Destination (pDst) by only consuming enough source to fill pDst
1.64 + TUint srcUse = (dstMaxLen - iDst->Position()) / 2;
1.65 + const TUint srcLen = iSrc->Data().Length();
1.66 + const TUint sourceRemain = srcLen - iSrc->Position();
1.67 +
1.68 + //make sure we don't blow source by checking against remaining
1.69 + //and clipping to minimum remaining if necessary
1.70 + srcUse = (srcUse<sourceRemain ? srcUse : sourceRemain);
1.71 +
1.72 + //we need to cast away CONST even on the source, as the TClass needs a TUint8*
1.73 + TUint8* pSrc = CONST_CAST(TUint8*,iSrc->Data().Ptr());
1.74 + pSrc += iSrc->Position();
1.75 + TUint8* pDst = CONST_CAST(TUint8*,iDst->Data().Ptr());
1.76 + pDst += iDst->Position();
1.77 +
1.78 +
1.79 + iMulawTo16Pcm.Convert(pSrc, pDst, srcUse );
1.80 +
1.81 + if ((srcUse * 2) + iDst->Position() < dstMaxLen)
1.82 + result.iStatus = TCodecProcessResult::EDstNotFilled;
1.83 +
1.84 + else if (srcUse + iSrc->Position() >= srcLen)
1.85 + result.iStatus = TCodecProcessResult::EProcessComplete;
1.86 +
1.87 + result.iSrcBytesProcessed = srcUse;
1.88 + result.iDstBytesAdded = srcUse * 2;
1.89 +
1.90 + iDst->Data().SetLength(iDst->Position() + (srcUse * 2));
1.91 +
1.92 + return result;
1.93 + }