sl@0: /* sl@0: * Copyright (c) 1997-2002 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: sl@0: #include "MMFAudioS16ToPcmU8Codec.h" sl@0: sl@0: // __________________________________________________________________________ sl@0: // Implementation sl@0: sl@0: CMMFCodec* CMMFAudioS16PcmU8Codec::NewL(TAny* aInitParams) sl@0: { sl@0: CMMFAudioS16PcmU8Codec* self=new(ELeave) CMMFAudioS16PcmU8Codec(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aInitParams); sl@0: CleanupStack::Pop(self); sl@0: return STATIC_CAST( CMMFCodec*, self ); sl@0: } sl@0: sl@0: CMMFAudioS16PcmU8Codec::~CMMFAudioS16PcmU8Codec() sl@0: { sl@0: } sl@0: sl@0: CMMFAudioS16PcmU8Codec::CMMFAudioS16PcmU8Codec() sl@0: { sl@0: } sl@0: sl@0: void CMMFAudioS16PcmU8Codec::ConstructL(TAny* /*aInitParams*/) sl@0: { sl@0: } sl@0: sl@0: sl@0: //this codec converts 2 bytes into 1 sl@0: TCodecProcessResult CMMFAudioS16PcmU8Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst) sl@0: { sl@0: sl@0: TCodecProcessResult result; sl@0: result.iStatus = TCodecProcessResult::EProcessIncomplete; sl@0: sl@0: //convert from generic CMMFBuffer to CMMFDataBuffer sl@0: iSrc = STATIC_CAST(const CMMFDataBuffer*, &aSrc); sl@0: iDst = STATIC_CAST(CMMFDataBuffer*, &aDst); sl@0: sl@0: const TUint dstMaxLen = iDst->Data().MaxLength(); sl@0: sl@0: if (!dstMaxLen) sl@0: User::Leave(KErrArgument); sl@0: sl@0: //don't scribble Destination (pDst) by only consuming enough source to fill pDst sl@0: TUint srcUse = (dstMaxLen - iDst->Position()) * 2; sl@0: const TUint srcLen = iSrc->Data().Length(); sl@0: const TUint sourceRemain = srcLen - iSrc->Position(); sl@0: sl@0: //make sure we don't blow source by checking against remaining sl@0: //and clipping to minimum remaining if necessary sl@0: srcUse = (srcUseData().Ptr()); sl@0: pSrc += iSrc->Position(); sl@0: TUint8* pDst = CONST_CAST(TUint8*,iDst->Data().Ptr()); sl@0: pDst += iDst->Position(); sl@0: sl@0: //compress TWO bytes (16-bit PCM word) into a to 1 byte sample sl@0: iAudioS16ToU8Pcm.Convert(pSrc, pDst, srcUse / 2); sl@0: sl@0: TUint dstBytesAdded = srcUse / 2; sl@0: sl@0: if (dstBytesAdded + iDst->Position() < dstMaxLen) sl@0: result.iStatus = TCodecProcessResult::EDstNotFilled; sl@0: sl@0: else if (srcUse + iSrc->Position() >= srcLen) sl@0: result.iStatus = TCodecProcessResult::EProcessComplete; sl@0: sl@0: result.iSrcBytesProcessed = srcUse; sl@0: result.iDstBytesAdded = dstBytesAdded; sl@0: sl@0: iDst->Data().SetLength(iDst->Position() + result.iDstBytesAdded); sl@0: sl@0: return result; sl@0: sl@0: }