os/mm/mmlibs/mmfw/src/Plugin/Codec/audio/MMFAudios16ToPcms16Codec.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 "MMFAudioS16ToPcms16Codec.h"
    21 
    22 
    23 // __________________________________________________________________________
    24 // Implementation
    25 
    26 CMMFCodec* CMMFAudioS16PcmS16Codec::NewL(TAny* aInitParams)
    27 	{
    28 	CMMFAudioS16PcmS16Codec* self=new(ELeave) CMMFAudioS16PcmS16Codec();
    29 	CleanupStack::PushL(self);
    30 	self->ConstructL(aInitParams);
    31 	CleanupStack::Pop(self);
    32 	return STATIC_CAST( CMMFCodec*, self );
    33 	}
    34 
    35 CMMFAudioS16PcmS16Codec::~CMMFAudioS16PcmS16Codec()
    36 	{
    37 	}
    38 
    39 CMMFAudioS16PcmS16Codec::CMMFAudioS16PcmS16Codec()
    40 	{
    41 	}
    42 
    43 void CMMFAudioS16PcmS16Codec::ConstructL(TAny* /*aInitParams*/)
    44 	{
    45 	}
    46 
    47 
    48 //this codec has a does not expand or shrink destination data
    49 TCodecProcessResult CMMFAudioS16PcmS16Codec::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();
    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 	//divide by TWO as 2 bytes are equal to 1 sample
    80 	Mem::Copy( pDst, pSrc, srcUse / 2 );
    81 
    82 	if (srcUse + 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;
    90 
    91 	iDst->Data().SetLength(iDst->Position() + srcUse);
    92 
    93 	return result;
    94 
    95 	}