os/mm/devsound/devsoundrefplugin/src/plugin/audio/mmfpcmU16BeToPcmS16HwDevice.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsound/devsoundrefplugin/src/plugin/audio/mmfpcmU16BeToPcmS16HwDevice.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,161 @@
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 "mmfpcmU16BeToPcmS16HwDevice.h"
1.20 +
1.21 +/**
1.22 + *
1.23 + * Returns the created hw device for passing audio through audio.
1.24 + * for the wins implementation this would always be pcm16 although
1.25 + * this is effectively a null hw device that will pass any datatype through
1.26 + * @return "CMMFPcm16ToPcmU16BEHwDevice"
1.27 + *
1.28 + */
1.29 +CMMFPcmU16BeToPcmS16HwDevice* CMMFPcmU16BeToPcmS16HwDevice::NewL()
1.30 + {
1.31 + CMMFPcmU16BeToPcmS16HwDevice* self = new (ELeave) CMMFPcmU16BeToPcmS16HwDevice();
1.32 + CleanupStack::PushL(self);
1.33 + self->ConstructL();
1.34 + CleanupStack::Pop(self);
1.35 + return self;
1.36 + }
1.37 +
1.38 +/**
1.39 +*
1.40 +* ~CMMFPcmU16BeToPcmS16HwDevice
1.41 +*
1.42 +*/
1.43 +CMMFPcmU16BeToPcmS16HwDevice::~CMMFPcmU16BeToPcmS16HwDevice()
1.44 + {
1.45 + }
1.46 +
1.47 +/**
1.48 +*
1.49 +* Codec
1.50 +* @return 'CMMFSwCodec&'
1.51 +*
1.52 +*/
1.53 +CMMFSwCodec& CMMFPcmU16BeToPcmS16HwDevice::Codec()
1.54 + {
1.55 + return *iCodec;
1.56 + }
1.57 +
1.58 +/**
1.59 +*
1.60 +* ConstructL
1.61 +*
1.62 +*/
1.63 +void CMMFPcmU16BeToPcmS16HwDevice::ConstructL()
1.64 + {
1.65 + iCodec = new (ELeave) CMMFPcmU16BeToPcmS16Codec();
1.66 + }
1.67 +
1.68 +/**
1.69 +*
1.70 +* ProcessL
1.71 +* @param aSrc
1.72 +* @param aDst
1.73 +* @return CMMFSwCodec::TCodecProcessResult
1.74 +* this codec has a does not expand or shrink destination data
1.75 +*/
1.76 +CMMFSwCodec::TCodecProcessResult CMMFPcmU16BeToPcmS16Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
1.77 + {
1.78 + TCodecProcessResult result;
1.79 + result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
1.80 +
1.81 + //convert from generic CMMFBuffer to CMMFDataBuffer
1.82 + const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
1.83 + CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDst);
1.84 +
1.85 + //[ check preconditions ]
1.86 + if( !CheckPreconditions( src, dst ))
1.87 + {
1.88 + //[ precondition violation ]
1.89 + User::Leave( KErrArgument );
1.90 + }
1.91 +
1.92 + //we need to cast away CONST even on the source, as the TClass needs a TUint8*
1.93 + TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
1.94 + TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
1.95 +
1.96 + TInt srcUse = src->Data().Length();
1.97 + TInt noSamples = srcUse/2;
1.98 + iAudioPcmU16BeToPcmS16.Convert(pSrc, pDst, noSamples);
1.99 +
1.100 + result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
1.101 + result.iSrcBytesProcessed = srcUse;
1.102 + result.iDstBytesAdded = srcUse;
1.103 +
1.104 + dst->Data().SetLength(srcUse);
1.105 +
1.106 + //[ post conditions
1.107 + // srcbytes/2 == destbytes added
1.108 + // pos src == 0
1.109 + // pos dest == 0
1.110 + // src data length is even
1.111 + // dst data length is even ie pcm16 samples ]
1.112 + __ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
1.113 + __ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
1.114 + __ASSERT_DEBUG( src->Data().Length() == dst->Data().Length(), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
1.115 + __ASSERT_DEBUG( dst->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
1.116 + __ASSERT_DEBUG( src->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
1.117 +
1.118 + return result;
1.119 + }
1.120 +
1.121 +/**
1.122 +*
1.123 +* Preconditions
1.124 +* This methos tests the preconditions of the ProcessL method
1.125 +* @return TBool ETrue for sucess and EFalse for failure of the preconditions
1.126 +*
1.127 +**/
1.128 +TBool CMMFPcmU16BeToPcmS16Codec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
1.129 + {
1.130 + TBool result = EFalse;
1.131 +
1.132 + if(! aSrcBuffer )
1.133 + {
1.134 + return result;
1.135 + }
1.136 +
1.137 + if( ! aDestBuffer )
1.138 + {
1.139 + return result;
1.140 + }
1.141 +
1.142 + // Check position of src and dest are 0
1.143 + if( aSrcBuffer->Position() )
1.144 + {
1.145 + return result;
1.146 + }
1.147 +
1.148 + // Check position of src and dest are 0
1.149 + if( aDestBuffer->Position() )
1.150 + {
1.151 + return result;
1.152 + }
1.153 +
1.154 + // check there are sufficient bytes in the output to consume the input
1.155 + if( ( aSrcBuffer->Data().Length() > aDestBuffer->Data().MaxLength() ) ||
1.156 + ( aSrcBuffer->Data().Length() % 2 != 0 ) ) // must have pcm16 samples on input
1.157 + {
1.158 + return result;
1.159 + }
1.160 +
1.161 + result = ETrue; // preconditions have been satisfied
1.162 +
1.163 + return result;
1.164 + }