os/mm/mmlibs/mmfw/src/Plugin/Codec/audio/Mmfaudiou8Topcms16codec.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 /*
     2 * Copyright (c) 1997-2002 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     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".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description:
    15 *
    16 */
    17 
    18 
    19 
    20 #include "MMFAudioU8ToPcmS16Codec.h"
    21 
    22 // __________________________________________________________________________
    23 // Implementation
    24 
    25 CMMFCodec* CMMFAudioU8PcmS16Codec::NewL(TAny* aInitParams)
    26 	{
    27 	CMMFAudioU8PcmS16Codec* self=new(ELeave) CMMFAudioU8PcmS16Codec();
    28 	CleanupStack::PushL(self);
    29 	self->ConstructL(aInitParams);
    30 	CleanupStack::Pop(self);
    31 	return STATIC_CAST( CMMFCodec*, self );
    32 	}
    33 
    34 CMMFAudioU8PcmS16Codec::~CMMFAudioU8PcmS16Codec()
    35 	{
    36 	}
    37 
    38 CMMFAudioU8PcmS16Codec::CMMFAudioU8PcmS16Codec()
    39 	{
    40 	}
    41 
    42 void CMMFAudioU8PcmS16Codec::ConstructL(TAny* /*aInitParams*/)
    43 	{
    44 	}
    45 
    46 
    47 	
    48 //this codec converts 1 byte to 2 bytes
    49 TCodecProcessResult CMMFAudioU8PcmS16Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
    50 	{
    51 
    52 	TCodecProcessResult result;
    53 	result.iStatus = TCodecProcessResult::EProcessIncomplete;
    54 
    55 	//convert from generic CMMFBuffer to CMMFDataBuffer
    56 	iSrc = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
    57 	iDst = STATIC_CAST(CMMFDataBuffer*, &aDst);
    58 
    59 	const TUint dstMaxLen = iDst->Data().MaxLength();
    60 
    61 	if (!dstMaxLen)
    62 		User::Leave(KErrArgument);
    63 
    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();
    68 
    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);
    72 	
    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();
    78 
    79 
    80 	iAudioU8ToS16Pcm.Convert(pSrc, pDst, srcUse );
    81 
    82 	if ((srcUse * 2) + iDst->Position() < dstMaxLen)
    83 		result.iStatus = TCodecProcessResult::EDstNotFilled;
    84 
    85 	else if (srcUse + iSrc->Position() >= srcLen)
    86 		result.iStatus = TCodecProcessResult::EProcessComplete;
    87 
    88 	result.iSrcBytesProcessed = srcUse;
    89 	result.iDstBytesAdded = srcUse * 2;
    90 
    91 	iDst->Data().SetLength(iDst->Position() + (srcUse * 2));
    92 
    93 	return result;
    94 	}
    95