os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcm16ToPcm16HwDevice.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcm16ToPcm16HwDevice.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,198 @@
     1.4 +// Copyright (c) 2005-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 "MmfBtPcm16ToPcm16HwDevice.h"
    1.20 +#include "../../MmfBtFileDependencyUtil.h"
    1.21 +
    1.22 +/**
    1.23 + *
    1.24 + *	Returns the created hw device for passing audio through audio.
    1.25 + *  for the wins implementation this would always be pcm16 although
    1.26 + *  this is effectively a null hw device that will pass any datatype through
    1.27 + *	@return	"CMMFPcm16ToPcm16HwDevice"
    1.28 + *
    1.29 + */
    1.30 +CMMFPcm16ToPcm16HwDevice* CMMFPcm16ToPcm16HwDevice::NewL()
    1.31 +	{
    1.32 +    CMMFPcm16ToPcm16HwDevice* self = new (ELeave) CMMFPcm16ToPcm16HwDevice();
    1.33 +	CleanupStack::PushL(self);
    1.34 +	self->ConstructL();
    1.35 +	CleanupStack::Pop(self);
    1.36 +	return self;
    1.37 +	}
    1.38 +
    1.39 +/**
    1.40 + *
    1.41 + *	Second phase constructor.
    1.42 + *
    1.43 + */
    1.44 +void CMMFPcm16ToPcm16HwDevice::ConstructL()
    1.45 +	{
    1.46 +    iCodec = new (ELeave) CMMFPcm16ToPcm16Codec();
    1.47 +	static_cast<CMMFPcm16ToPcm16Codec*>(iCodec)->SetHwDevice(this);
    1.48 +	}
    1.49 +
    1.50 +/**
    1.51 +*
    1.52 +* ~CMMFPcm16ToPcm16HwDevice
    1.53 +*
    1.54 +**/
    1.55 +CMMFPcm16ToPcm16HwDevice::~CMMFPcm16ToPcm16HwDevice()
    1.56 +	{
    1.57 +	}
    1.58 +
    1.59 +/**
    1.60 +*
    1.61 +* Codec
    1.62 +* @return CMMFSwCodec&
    1.63 +**/
    1.64 +CMMFSwCodec& CMMFPcm16ToPcm16HwDevice::Codec()
    1.65 +	{
    1.66 +	return *iCodec;
    1.67 +	}
    1.68 +
    1.69 +
    1.70 +
    1.71 +
    1.72 +
    1.73 +/**
    1.74 +*
    1.75 +* ProcessL
    1.76 +* @param aSrc Source Buffer
    1.77 +* @param aDest Destintion Buffer
    1.78 +* @return CMMFSwCodec::TCodecProcessResult
    1.79 +*
    1.80 +**/
    1.81 +CMMFSwCodec::TCodecProcessResult CMMFPcm16ToPcm16Codec::ProcessL(const CMMFBuffer& /*aSource*/, CMMFBuffer& /*aDest*/)
    1.82 +	{//no processing required for null codec
    1.83 +	User::Leave(KErrNotSupported); 
    1.84 +	//to keep compiler happy
    1.85 +	TCodecProcessResult result;
    1.86 +	result.iCodecProcessStatus = TCodecProcessResult::EEndOfData;
    1.87 +	result.iSrcBytesProcessed = 0;
    1.88 +	result.iDstBytesAdded = 0;
    1.89 +	return result;
    1.90 +	};
    1.91 +
    1.92 +
    1.93 +TUint CMMFPcm16ToPcm16Codec::SourceBufferSize()
    1.94 +	{
    1.95 +	if (!iBufferSize) 
    1.96 +		iBufferSize = iHwDevice->CalculateBufferSize();
    1.97 +	return iBufferSize;
    1.98 +	}
    1.99 +
   1.100 +
   1.101 +TUint CMMFPcm16ToPcm16Codec::SinkBufferSize()
   1.102 +	{
   1.103 +	if (!iBufferSize) 
   1.104 +		iBufferSize = iHwDevice->CalculateBufferSize();
   1.105 +	return iBufferSize;
   1.106 +	}
   1.107 +
   1.108 +void CMMFPcm16ToPcm16Codec::SetHwDevice(CMMFPcm16ToPcm16HwDevice* aHwDevice)
   1.109 +	{
   1.110 +	iHwDevice = aHwDevice;
   1.111 +	}
   1.112 +
   1.113 +TUint CMMFPcm16ToPcm16HwDevice::CalculateBufferSize()
   1.114 +	{
   1.115 +	TUint sampleRate = 0;
   1.116 +	TUint channels = 0;
   1.117 +	TInt useBufferOfSize = 0;
   1.118 +	TInt minBufferSize = 0;
   1.119 +	TInt maxBufferSize = 0;
   1.120 +
   1.121 +	if (iPlayCustomInterface)
   1.122 +		{
   1.123 +		sampleRate = iSampleRate;
   1.124 +		channels = iChannels;	
   1.125 +/*		if ((sampleRate) && (channels))
   1.126 +			{
   1.127 +			RMdaDevSound::TSoundFormatsSupportedBuf playFormatsSupported;
   1.128 +			if (iDataPath->Device().Handle())
   1.129 +				{
   1.130 +				iDataPath->Device().PlayFormatsSupported(playFormatsSupported);
   1.131 +				minBufferSize = playFormatsSupported().iMinBufferSize;
   1.132 +				maxBufferSize = playFormatsSupported().iMaxBufferSize;
   1.133 +				}
   1.134 +			else
   1.135 +				{//try to get handle
   1.136 +				TInt err = iDataPath->Device().Open();
   1.137 +				if (err == KErrNone)
   1.138 +					{
   1.139 +					iDataPath->Device().PlayFormatsSupported(playFormatsSupported);
   1.140 +					minBufferSize = playFormatsSupported().iMinBufferSize;
   1.141 +					maxBufferSize = playFormatsSupported().iMaxBufferSize;
   1.142 +					iDataPath->Device().Close();
   1.143 +					}
   1.144 +				}
   1.145 +			}
   1.146 +*/		}
   1.147 +	if ((iRecordCustomInterface) && (!sampleRate) && (!channels))
   1.148 +		{ //must be record
   1.149 +		sampleRate = iSampleRate;
   1.150 +		channels = iChannels;
   1.151 +/*		if ((sampleRate) && (channels))
   1.152 +			{//get max and min supported buffer sizes supported by hw
   1.153 +			RMdaDevSound::TSoundFormatsSupportedBuf recordFormatsSupported;
   1.154 +			if (iDataPath->Device().Handle())
   1.155 +				{
   1.156 +				iDataPath->Device().RecordFormatsSupported(recordFormatsSupported);
   1.157 +				minBufferSize = recordFormatsSupported().iMinBufferSize;
   1.158 +				maxBufferSize = recordFormatsSupported().iMaxBufferSize;
   1.159 +				}
   1.160 +			else
   1.161 +				{//try to get handle
   1.162 +				TInt err = iDataPath->Device().Open();
   1.163 +				if (err == KErrNone)
   1.164 +					{
   1.165 +					iDataPath->Device().RecordFormatsSupported(recordFormatsSupported);
   1.166 +					minBufferSize = recordFormatsSupported().iMinBufferSize;
   1.167 +					maxBufferSize = recordFormatsSupported().iMaxBufferSize;
   1.168 +					iDataPath->Device().Close();
   1.169 +					}
   1.170 +				}
   1.171 +			}
   1.172 +*/		}
   1.173 +//	else convert so not applicable
   1.174 +
   1.175 +	if ((sampleRate) && (channels))
   1.176 +		{
   1.177 +		// Buffer size = (SampleRate * BytesPerSample * Channels) / 4
   1.178 +		useBufferOfSize = ((sampleRate * 2 * channels)/KDevSoundFramesPerSecond + (KDevSoundDeltaFrameSize-1)) &~ (KDevSoundDeltaFrameSize-1);
   1.179 +		//clamp buffer to desired limits
   1.180 +		if(useBufferOfSize < KDevSoundMinFrameSize) 
   1.181 +			useBufferOfSize = KDevSoundMinFrameSize;
   1.182 +		else if(useBufferOfSize > KDevSoundMaxFrameSize) 
   1.183 +			useBufferOfSize = KDevSoundMaxFrameSize;
   1.184 +
   1.185 +		//clamp buffer to limits of hardware
   1.186 +		if (maxBufferSize)
   1.187 +			{//buffer size limits have been set by sound driver
   1.188 +			 //check we are within the limits
   1.189 +			if(useBufferOfSize < minBufferSize)
   1.190 +				useBufferOfSize = minBufferSize;
   1.191 +			else if(useBufferOfSize > maxBufferSize)
   1.192 +				useBufferOfSize = maxBufferSize;
   1.193 +			}
   1.194 +		}
   1.195 +	else
   1.196 +		{
   1.197 +		useBufferOfSize = KPCM16ToPCM16BufferSize;
   1.198 +		}
   1.199 +
   1.200 +	return useBufferOfSize;
   1.201 +	}