Update contrib.
2 * Copyright (c) 1997-2002 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #include "MMFAudioS16ToPcms16Codec.h"
23 // __________________________________________________________________________
26 CMMFCodec* CMMFAudioS16PcmS16Codec::NewL(TAny* aInitParams)
28 CMMFAudioS16PcmS16Codec* self=new(ELeave) CMMFAudioS16PcmS16Codec();
29 CleanupStack::PushL(self);
30 self->ConstructL(aInitParams);
31 CleanupStack::Pop(self);
32 return STATIC_CAST( CMMFCodec*, self );
35 CMMFAudioS16PcmS16Codec::~CMMFAudioS16PcmS16Codec()
39 CMMFAudioS16PcmS16Codec::CMMFAudioS16PcmS16Codec()
43 void CMMFAudioS16PcmS16Codec::ConstructL(TAny* /*aInitParams*/)
48 //this codec has a does not expand or shrink destination data
49 TCodecProcessResult CMMFAudioS16PcmS16Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
52 TCodecProcessResult result;
53 result.iStatus = TCodecProcessResult::EProcessIncomplete;
55 //convert from generic CMMFBuffer to CMMFDataBuffer
56 iSrc = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
57 iDst = STATIC_CAST(CMMFDataBuffer*, &aDst);
59 const TUint dstMaxLen = iDst->Data().MaxLength();
62 User::Leave(KErrArgument);
64 //don't scribble Destination (pDst) by only consuming enough source to fill pDst
65 TUint srcUse = dstMaxLen - iDst->Position();
66 const TUint srcLen = iSrc->Data().Length();
67 const TUint sourceRemain = srcLen - iSrc->Position();
69 //make sure we don't blow source by checking against remaining
70 //and clipping to minimum remaining if necessary
71 srcUse = (srcUse<sourceRemain ? srcUse : sourceRemain);
73 //we need to cast away CONST even on the source, as the TClass needs a TUint8*
74 TUint8* pSrc = CONST_CAST(TUint8*,iSrc->Data().Ptr());
75 pSrc += iSrc->Position();
76 TUint8* pDst = CONST_CAST(TUint8*,iDst->Data().Ptr());
77 pDst += iDst->Position();
79 //divide by TWO as 2 bytes are equal to 1 sample
80 Mem::Copy( pDst, pSrc, srcUse / 2 );
82 if (srcUse + iDst->Position() < dstMaxLen)
83 result.iStatus = TCodecProcessResult::EDstNotFilled;
85 else if (srcUse + iSrc->Position() >= srcLen)
86 result.iStatus = TCodecProcessResult::EProcessComplete;
88 result.iSrcBytesProcessed = srcUse;
89 result.iDstBytesAdded = srcUse;
91 iDst->Data().SetLength(iDst->Position() + srcUse);