Update contrib.
1 // Copyright (c) 1997-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 "MMFPcm16ToMuLawCodec.h"
19 // __________________________________________________________________________
22 CMMFCodec* CMMFPcm16MulawCodec::NewL(TAny* aInitParams)
24 CMMFPcm16MulawCodec* self=new(ELeave) CMMFPcm16MulawCodec();
25 CleanupStack::PushL(self);
26 self->ConstructL(aInitParams);
27 CleanupStack::Pop(self);
28 return STATIC_CAST( CMMFCodec*, self );
31 CMMFPcm16MulawCodec::~CMMFPcm16MulawCodec()
35 CMMFPcm16MulawCodec::CMMFPcm16MulawCodec()
39 void CMMFPcm16MulawCodec::ConstructL(TAny* /*aInitParams*/)
44 //this codec converts 2 bytes into 1
45 TCodecProcessResult CMMFPcm16MulawCodec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
48 TCodecProcessResult result;
49 result.iStatus = TCodecProcessResult::EProcessIncomplete;
51 //convert from generic CMMFBuffer to CMMFDataBuffer
52 iSrc = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
53 iDst = STATIC_CAST(CMMFDataBuffer*, &aDst);
55 const TUint dstMaxLen = iDst->Data().MaxLength();
58 User::Leave(KErrArgument);
60 //don't scribble Destination (pDst) by only consuming enough source to fill pDst
61 TUint srcUse = (dstMaxLen - iDst->Position()) * 2;
62 const TUint srcLen = iSrc->Data().Length();
63 const TUint sourceRemain = srcLen - iSrc->Position();
65 //make sure we don't blow source by checking against remaining
66 //and clipping to minimum remaining if necessary
67 srcUse = (srcUse<sourceRemain ? srcUse : sourceRemain);
69 //we need to cast away CONST even on the source, as the TClass needs a TUint8*
70 TUint8* pSrc = CONST_CAST(TUint8*,iSrc->Data().Ptr());
71 pSrc += iSrc->Position();
72 TUint8* pDst = CONST_CAST(TUint8*,iDst->Data().Ptr());
73 pDst += iDst->Position();
75 //compress TWO bytes (16-bit PCM word) into a to 1 byte sample
76 i16PcmToMulaw.Convert(pSrc, pDst, srcUse / 2);
78 TUint dstBytesAdded = srcUse / 2;
80 if (dstBytesAdded + iDst->Position() < dstMaxLen)
81 result.iStatus = TCodecProcessResult::EDstNotFilled;
83 else if (srcUse + iSrc->Position() >= srcLen)
84 result.iStatus = TCodecProcessResult::EProcessComplete;
86 result.iSrcBytesProcessed = srcUse;
87 result.iDstBytesAdded = dstBytesAdded;
89 iDst->Data().SetLength(iDst->Position() + result.iDstBytesAdded);