os/mm/mmlibs/mmfw/src/Plugin/Codec/audio/Mmfaudios16Topcmu8codec.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/mmlibs/mmfw/src/Plugin/Codec/audio/Mmfaudios16Topcmu8codec.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,96 @@
     1.4 +/*
     1.5 +* Copyright (c) 1997-2002 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description:
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +
    1.23 +#include "MMFAudioS16ToPcmU8Codec.h"
    1.24 +
    1.25 +// __________________________________________________________________________
    1.26 +// Implementation
    1.27 +
    1.28 +CMMFCodec* CMMFAudioS16PcmU8Codec::NewL(TAny* aInitParams)
    1.29 +	{
    1.30 +	CMMFAudioS16PcmU8Codec* self=new(ELeave) CMMFAudioS16PcmU8Codec();
    1.31 +	CleanupStack::PushL(self);
    1.32 +	self->ConstructL(aInitParams);
    1.33 +	CleanupStack::Pop(self);
    1.34 +	return STATIC_CAST( CMMFCodec*, self );
    1.35 +	}
    1.36 +
    1.37 +CMMFAudioS16PcmU8Codec::~CMMFAudioS16PcmU8Codec()
    1.38 +	{
    1.39 +	}
    1.40 +
    1.41 +CMMFAudioS16PcmU8Codec::CMMFAudioS16PcmU8Codec()
    1.42 +	{
    1.43 +	}
    1.44 +
    1.45 +void CMMFAudioS16PcmU8Codec::ConstructL(TAny* /*aInitParams*/)
    1.46 +	{
    1.47 +	}
    1.48 +
    1.49 +
    1.50 +//this codec converts 2 bytes into 1
    1.51 +TCodecProcessResult CMMFAudioS16PcmU8Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
    1.52 +	{
    1.53 +
    1.54 +	TCodecProcessResult result;
    1.55 +	result.iStatus = TCodecProcessResult::EProcessIncomplete;
    1.56 +
    1.57 +	//convert from generic CMMFBuffer to CMMFDataBuffer
    1.58 +	iSrc = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
    1.59 +	iDst = STATIC_CAST(CMMFDataBuffer*, &aDst);
    1.60 +
    1.61 +	const TUint dstMaxLen = iDst->Data().MaxLength();
    1.62 +
    1.63 +	if (!dstMaxLen)
    1.64 +		User::Leave(KErrArgument);
    1.65 +
    1.66 +	//don't scribble Destination (pDst) by only consuming enough source to fill pDst
    1.67 +	TUint srcUse = (dstMaxLen - iDst->Position()) * 2;
    1.68 +	const TUint srcLen = iSrc->Data().Length();
    1.69 +	const TUint sourceRemain = srcLen - iSrc->Position();
    1.70 +
    1.71 +	//make sure we don't blow source by checking against remaining
    1.72 +	//and clipping to minimum remaining if necessary
    1.73 +	srcUse = (srcUse<sourceRemain ? srcUse : sourceRemain);
    1.74 +
    1.75 +	//we need to cast away CONST even on the source, as the TClass needs a TUint8*
    1.76 +	TUint8* pSrc = CONST_CAST(TUint8*,iSrc->Data().Ptr());
    1.77 +	pSrc += iSrc->Position();
    1.78 +	TUint8* pDst = CONST_CAST(TUint8*,iDst->Data().Ptr());
    1.79 +	pDst += iDst->Position();
    1.80 +
    1.81 +	//compress TWO bytes (16-bit PCM word) into a to 1 byte sample
    1.82 +	iAudioS16ToU8Pcm.Convert(pSrc, pDst, srcUse / 2);
    1.83 +
    1.84 +	TUint dstBytesAdded = srcUse / 2;
    1.85 +
    1.86 +	if (dstBytesAdded + iDst->Position() < dstMaxLen)
    1.87 +		result.iStatus = TCodecProcessResult::EDstNotFilled;
    1.88 +
    1.89 +	else if (srcUse + iSrc->Position() >= srcLen)
    1.90 +		result.iStatus = TCodecProcessResult::EProcessComplete;
    1.91 +
    1.92 +	result.iSrcBytesProcessed = srcUse;
    1.93 +	result.iDstBytesAdded = dstBytesAdded;
    1.94 +
    1.95 +	iDst->Data().SetLength(iDst->Position() + result.iDstBytesAdded);
    1.96 +
    1.97 +	return result;
    1.98 +
    1.99 +	}