os/mm/mmlibs/mmfw/src/Plugin/Codec/audio/MmfmulawTopcm16codec.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 
    17 #include "MMFMuLawToPcm16Codec.h"
    18 
    19 // __________________________________________________________________________
    20 // Implementation
    21 
    22 CMMFCodec* CMMFMulawPcm16Codec::NewL(TAny* aInitParams)
    23 	{
    24 	CMMFMulawPcm16Codec* self=new(ELeave) CMMFMulawPcm16Codec();
    25 	CleanupStack::PushL(self);
    26 	self->ConstructL(aInitParams);
    27 	CleanupStack::Pop(self);
    28 	return STATIC_CAST( CMMFCodec*, self );
    29 	}
    30 
    31 CMMFMulawPcm16Codec::~CMMFMulawPcm16Codec()
    32 	{
    33 	}
    34 
    35 CMMFMulawPcm16Codec::CMMFMulawPcm16Codec()
    36 	{
    37 	}
    38 
    39 void CMMFMulawPcm16Codec::ConstructL(TAny* /*aInitParams*/)
    40 	{
    41 	}
    42 
    43 
    44 //this codec expands 1 byte to 2 bytes
    45 TCodecProcessResult CMMFMulawPcm16Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
    46 	{
    47 
    48 	TCodecProcessResult result;
    49 	result.iStatus = TCodecProcessResult::EProcessIncomplete;
    50 
    51 	//convert from generic CMMFBuffer to CMMFDataBuffer
    52 	iSrc = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
    53 	iDst = STATIC_CAST(CMMFDataBuffer*, &aDst);
    54 
    55 	const TUint dstMaxLen = iDst->Data().MaxLength();
    56 
    57 	if (!dstMaxLen)
    58 		User::Leave(KErrArgument);
    59 
    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();
    64 
    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);
    68 	
    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();
    74 
    75 
    76 	iMulawTo16Pcm.Convert(pSrc, pDst, srcUse );
    77 
    78 	if ((srcUse * 2) + iDst->Position() < dstMaxLen)
    79 		result.iStatus = TCodecProcessResult::EDstNotFilled;
    80 
    81 	else if (srcUse + iSrc->Position() >= srcLen)
    82 		result.iStatus = TCodecProcessResult::EProcessComplete;
    83 
    84 	result.iSrcBytesProcessed = srcUse;
    85 	result.iDstBytesAdded = srcUse * 2;
    86 
    87 	iDst->Data().SetLength(iDst->Position() + (srcUse * 2));
    88 
    89 	return result;
    90 	}