sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0: // All rights reserved.
sl@0: // This component and the accompanying materials are made available
sl@0: // under the terms of "Eclipse Public License v1.0"
sl@0: // which accompanies this distribution, and is available
sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: //
sl@0: // Initial Contributors:
sl@0: // Nokia Corporation - initial contribution.
sl@0: //
sl@0: // Contributors:
sl@0: //
sl@0: // Description:
sl@0: //
sl@0: 
sl@0: #include "MmfBtPcm16ToPcmU16BEHwDevice.h"
sl@0: #include "../../MmfBtFileDependencyUtil.h"
sl@0: 
sl@0: /**
sl@0:  *
sl@0:  *	Returns the created hw device for passing audio through audio.
sl@0:  *  for the wins implementation this would always be pcm16 although
sl@0:  *  this is effectively a null hw device that will pass any datatype through
sl@0:  *	@return	"CMMFPcm16ToPcmU16BEHwDevice"
sl@0:  *
sl@0:  */
sl@0: CMMFPcm16ToPcmU16BEHwDevice* CMMFPcm16ToPcmU16BEHwDevice::NewL()
sl@0: 	{
sl@0:     CMMFPcm16ToPcmU16BEHwDevice* self = new (ELeave) CMMFPcm16ToPcmU16BEHwDevice();
sl@0: 	CleanupStack::PushL(self);
sl@0: 	self->ConstructL();
sl@0: 	CleanupStack::Pop(self);
sl@0: 	return self;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: *
sl@0: * ~CMMFPcm16ToPcmU16BEHwDevice
sl@0: */
sl@0: CMMFPcm16ToPcmU16BEHwDevice::~CMMFPcm16ToPcmU16BEHwDevice()
sl@0: 	{
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: *
sl@0: * ConstructL
sl@0: *
sl@0: */
sl@0: void CMMFPcm16ToPcmU16BEHwDevice::ConstructL()
sl@0: 	{
sl@0: 	iCodec = new (ELeave) CMMFPcm16ToPcmU16BECodec();
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: *
sl@0: * Codec
sl@0: * @return 'CMMFSwCodec&'
sl@0: */
sl@0: CMMFSwCodec& CMMFPcm16ToPcmU16BEHwDevice::Codec()
sl@0: 	{
sl@0: 	return *iCodec;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: *
sl@0: * ProcessL
sl@0: * @param aSrc 
sl@0: * @param aDst
sl@0: * @pre position of buffer aSrc is 0
sl@0: * @pre position of buffer aDst is 0
sl@0: * @pre sufficient bytes in output to consume input
sl@0: * @return 'CMMFSwCodec::TCodecProcessResult'
sl@0: * this codec has a does not expand or shrink destination data
sl@0: */
sl@0: CMMFSwCodec::TCodecProcessResult CMMFPcm16ToPcmU16BECodec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
sl@0: 	{
sl@0: 	TCodecProcessResult result;
sl@0: 	result.iCodecProcessStatus = 	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
sl@0: 	
sl@0: 	//convert from generic CMMFBuffer to CMMFDataBuffer
sl@0: 	const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
sl@0: 	CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDst);
sl@0: 	
sl@0: 	//[ Check preconsitions ]
sl@0: 	if( !CheckPreconditions( src, dst ))
sl@0: 		{
sl@0: 		//[ precondition violation ]
sl@0: 		User::Leave( KErrArgument );
sl@0: 		}
sl@0: 	
sl@0: 	//we need to cast away CONST even on the source, as the TClass needs a TUint8*	
sl@0: 	TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
sl@0: 	TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
sl@0:     
sl@0: 	TInt srcUse = src->Data().Length();
sl@0: 	
sl@0: 	TInt noSamples = srcUse/2; // for pcm16 TInt16
sl@0: 	iAudioPcm16ToPcmU16Be.Convert(pSrc, pDst, noSamples );
sl@0: 	
sl@0: 	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
sl@0: 	result.iSrcBytesProcessed  = srcUse;
sl@0: 	result.iDstBytesAdded      = srcUse;
sl@0: 	
sl@0: 	dst->Data().SetLength(srcUse);
sl@0: 	
sl@0: 	//[ Check post conditions ]
sl@0: 	__ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
sl@0: 	__ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
sl@0: 	__ASSERT_DEBUG( src->Data().Length() == dst->Data().Length(), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
sl@0: 	__ASSERT_DEBUG( dst->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // pcm output
sl@0: 	
sl@0: 	return result;
sl@0: 	}
sl@0: 
sl@0: /**
sl@0: *
sl@0: * Preconditions
sl@0: * This methos tests the preconditions of the ProcessL method
sl@0: * @return TBool ETrue for sucess and EFalse for failure of the preconditions
sl@0: *
sl@0: **/
sl@0: TBool CMMFPcm16ToPcmU16BECodec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
sl@0: 	{
sl@0:      TBool result = EFalse;
sl@0: 	 
sl@0: 	 if(! aSrcBuffer )
sl@0: 		 {
sl@0: 		 return result;
sl@0: 		 }
sl@0: 	 
sl@0: 	 if( ! aDestBuffer )
sl@0: 		 {
sl@0: 		 return result;
sl@0: 		 }
sl@0: 	 
sl@0: 	 // Check position of src and dest are 0
sl@0: 	 if( aSrcBuffer->Position() )
sl@0: 		 {
sl@0: 		 return result;
sl@0: 		 }
sl@0: 	 
sl@0: 	 // Check position of src and dest are 0
sl@0: 	 if( aDestBuffer->Position() )
sl@0: 		 {
sl@0: 		 return result;
sl@0: 		 }
sl@0: 	 
sl@0: 	 // check there are sufficient bytes in the output to consume the input
sl@0:      if( ( aSrcBuffer->Data().Length() > aDestBuffer->Data().MaxLength() ) ||
sl@0: 		 ( aSrcBuffer->Data().Length() % 2 != 0 ) ) // must have pcm16 samples on input
sl@0: 		 {
sl@0: 		 return result;
sl@0: 		 }
sl@0: 	 
sl@0: 	 result = ETrue;  // preconditions have been satisfied
sl@0: 	 
sl@0: 	 return result;
sl@0: 	}
sl@0: