First public contribution.
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 "MMFAudioU8ToPcmS16Codec.h"
22 // __________________________________________________________________________
25 CMMFCodec* CMMFAudioU8PcmS16Codec::NewL(TAny* aInitParams)
27 CMMFAudioU8PcmS16Codec* self=new(ELeave) CMMFAudioU8PcmS16Codec();
28 CleanupStack::PushL(self);
29 self->ConstructL(aInitParams);
30 CleanupStack::Pop(self);
31 return STATIC_CAST( CMMFCodec*, self );
34 CMMFAudioU8PcmS16Codec::~CMMFAudioU8PcmS16Codec()
38 CMMFAudioU8PcmS16Codec::CMMFAudioU8PcmS16Codec()
42 void CMMFAudioU8PcmS16Codec::ConstructL(TAny* /*aInitParams*/)
48 //this codec converts 1 byte to 2 bytes
49 TCodecProcessResult CMMFAudioU8PcmS16Codec::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()) / 2;
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();
80 iAudioU8ToS16Pcm.Convert(pSrc, pDst, srcUse );
82 if ((srcUse * 2) + 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 * 2;
91 iDst->Data().SetLength(iDst->Position() + (srcUse * 2));