1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsound/devsoundrefplugin/src/plugin/audio/MmfMuLawToPcm16hwDevice.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,153 @@
1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "MMFAudioCodec.h"
1.20 +#include <mmf/common/mmfpaniccodes.h>
1.21 +#include "MmfMuLawToPcm16hwDevice.h"
1.22 +
1.23 +/**
1.24 +*
1.25 +* NewL
1.26 +*
1.27 +*/
1.28 +CMMFMulawToPcm16CodecHwDevice* CMMFMulawToPcm16CodecHwDevice::NewL()
1.29 + {
1.30 + CMMFMulawToPcm16CodecHwDevice* self=new(ELeave) CMMFMulawToPcm16CodecHwDevice();
1.31 + CleanupStack::PushL(self);
1.32 + self->ConstructL();
1.33 + CleanupStack::Pop(self);
1.34 + return self;
1.35 + }
1.36 +
1.37 +/**
1.38 +*
1.39 +* ~CMMFMulawPcm16HwDevice
1.40 +*
1.41 +*/
1.42 +CMMFMulawToPcm16CodecHwDevice::~CMMFMulawToPcm16CodecHwDevice()
1.43 + {
1.44 + }
1.45 +
1.46 +/**
1.47 +*
1.48 +* ConstructL
1.49 +*
1.50 +*/
1.51 +void CMMFMulawToPcm16CodecHwDevice::ConstructL()
1.52 + {
1.53 + iCodec = new (ELeave) CMMFMulawToPcm16Codec();
1.54 + }
1.55 +
1.56 +/**
1.57 +*
1.58 +* Codec
1.59 +*
1.60 +*/
1.61 +CMMFSwCodec &CMMFMulawToPcm16CodecHwDevice::Codec()
1.62 + {
1.63 + return *iCodec;
1.64 + }
1.65 +
1.66 +/**
1.67 +*
1.68 +* ProcessL
1.69 +* @param aSrc
1.70 +* @param aDst
1.71 +* @return TCodecProcessResult
1.72 +*
1.73 +*/
1.74 +CMMFSwCodec::TCodecProcessResult CMMFMulawToPcm16Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
1.75 + {
1.76 + CMMFSwCodec::TCodecProcessResult result;
1.77 + result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
1.78 +
1.79 + //convert from generic CMMFBuffer to CMMFDataBuffer
1.80 + const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
1.81 + CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDst);
1.82 +
1.83 + //[check preconditions hold ]
1.84 + if( !CheckPreconditions( src, dst ))
1.85 + {
1.86 + //[ precondition violation ]
1.87 + User::Leave( KErrArgument );
1.88 + }
1.89 +
1.90 + //we need to cast away CONST even on the source, as the TClass needs a TUint8*
1.91 + TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
1.92 + TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
1.93 + TInt noSamples = src->Data().Length();
1.94 +
1.95 + iMulawTo16Pcm.Convert(pSrc, pDst, noSamples );
1.96 +
1.97 + TUint dstBytesAdded = noSamples*sizeof(TInt16);
1.98 +
1.99 + result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
1.100 + result.iSrcBytesProcessed = src->Data().Length();
1.101 + result.iDstBytesAdded = dstBytesAdded;
1.102 +
1.103 + dst->Data().SetLength( dstBytesAdded );
1.104 +
1.105 + //[ check post conditions ]
1.106 + __ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
1.107 + __ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
1.108 + __ASSERT_DEBUG( src->Data().Length() == dst->Data().Length()/2, TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // 2 here signifies sizeof TInt16
1.109 + __ASSERT_DEBUG( dst->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // pcm output
1.110 +
1.111 + return result;
1.112 + }
1.113 +
1.114 +/**
1.115 +*
1.116 +* Preconditions
1.117 +* This methos tests the preconditions of the ProcessL method
1.118 +* @return TBool ETrue for sucess and EFalse for failure of the preconditions
1.119 +*
1.120 +**/
1.121 +TBool CMMFMulawToPcm16Codec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
1.122 + {
1.123 + TBool result = EFalse;
1.124 +
1.125 + if(! aSrcBuffer )
1.126 + {
1.127 + return result;
1.128 + }
1.129 +
1.130 + if( ! aDestBuffer )
1.131 + {
1.132 + return result;
1.133 + }
1.134 +
1.135 + // Check position of src and dest are 0
1.136 + if( aSrcBuffer->Position() )
1.137 + {
1.138 + return result;
1.139 + }
1.140 +
1.141 + // Check position of src and dest are 0
1.142 + if( aDestBuffer->Position() )
1.143 + {
1.144 + return result;
1.145 + }
1.146 +
1.147 + // check there are sufficient bytes in the output to consume the input
1.148 + if( aSrcBuffer->Data().Length() > aDestBuffer->Data().MaxLength()/2 )
1.149 + {
1.150 + return result;
1.151 + }
1.152 +
1.153 + result = ETrue; // preconditions have been satisfied
1.154 +
1.155 + return result;
1.156 + }