os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcm16ToPcm16HwDevice.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "MmfBtPcm16ToPcm16HwDevice.h"
sl@0
    17
#include "../../MmfBtFileDependencyUtil.h"
sl@0
    18
sl@0
    19
/**
sl@0
    20
 *
sl@0
    21
 *	Returns the created hw device for passing audio through audio.
sl@0
    22
 *  for the wins implementation this would always be pcm16 although
sl@0
    23
 *  this is effectively a null hw device that will pass any datatype through
sl@0
    24
 *	@return	"CMMFPcm16ToPcm16HwDevice"
sl@0
    25
 *
sl@0
    26
 */
sl@0
    27
CMMFPcm16ToPcm16HwDevice* CMMFPcm16ToPcm16HwDevice::NewL()
sl@0
    28
	{
sl@0
    29
    CMMFPcm16ToPcm16HwDevice* self = new (ELeave) CMMFPcm16ToPcm16HwDevice();
sl@0
    30
	CleanupStack::PushL(self);
sl@0
    31
	self->ConstructL();
sl@0
    32
	CleanupStack::Pop(self);
sl@0
    33
	return self;
sl@0
    34
	}
sl@0
    35
sl@0
    36
/**
sl@0
    37
 *
sl@0
    38
 *	Second phase constructor.
sl@0
    39
 *
sl@0
    40
 */
sl@0
    41
void CMMFPcm16ToPcm16HwDevice::ConstructL()
sl@0
    42
	{
sl@0
    43
    iCodec = new (ELeave) CMMFPcm16ToPcm16Codec();
sl@0
    44
	static_cast<CMMFPcm16ToPcm16Codec*>(iCodec)->SetHwDevice(this);
sl@0
    45
	}
sl@0
    46
sl@0
    47
/**
sl@0
    48
*
sl@0
    49
* ~CMMFPcm16ToPcm16HwDevice
sl@0
    50
*
sl@0
    51
**/
sl@0
    52
CMMFPcm16ToPcm16HwDevice::~CMMFPcm16ToPcm16HwDevice()
sl@0
    53
	{
sl@0
    54
	}
sl@0
    55
sl@0
    56
/**
sl@0
    57
*
sl@0
    58
* Codec
sl@0
    59
* @return CMMFSwCodec&
sl@0
    60
**/
sl@0
    61
CMMFSwCodec& CMMFPcm16ToPcm16HwDevice::Codec()
sl@0
    62
	{
sl@0
    63
	return *iCodec;
sl@0
    64
	}
sl@0
    65
sl@0
    66
sl@0
    67
sl@0
    68
sl@0
    69
sl@0
    70
/**
sl@0
    71
*
sl@0
    72
* ProcessL
sl@0
    73
* @param aSrc Source Buffer
sl@0
    74
* @param aDest Destintion Buffer
sl@0
    75
* @return CMMFSwCodec::TCodecProcessResult
sl@0
    76
*
sl@0
    77
**/
sl@0
    78
CMMFSwCodec::TCodecProcessResult CMMFPcm16ToPcm16Codec::ProcessL(const CMMFBuffer& /*aSource*/, CMMFBuffer& /*aDest*/)
sl@0
    79
	{//no processing required for null codec
sl@0
    80
	User::Leave(KErrNotSupported); 
sl@0
    81
	//to keep compiler happy
sl@0
    82
	TCodecProcessResult result;
sl@0
    83
	result.iCodecProcessStatus = TCodecProcessResult::EEndOfData;
sl@0
    84
	result.iSrcBytesProcessed = 0;
sl@0
    85
	result.iDstBytesAdded = 0;
sl@0
    86
	return result;
sl@0
    87
	};
sl@0
    88
sl@0
    89
sl@0
    90
TUint CMMFPcm16ToPcm16Codec::SourceBufferSize()
sl@0
    91
	{
sl@0
    92
	if (!iBufferSize) 
sl@0
    93
		iBufferSize = iHwDevice->CalculateBufferSize();
sl@0
    94
	return iBufferSize;
sl@0
    95
	}
sl@0
    96
sl@0
    97
sl@0
    98
TUint CMMFPcm16ToPcm16Codec::SinkBufferSize()
sl@0
    99
	{
sl@0
   100
	if (!iBufferSize) 
sl@0
   101
		iBufferSize = iHwDevice->CalculateBufferSize();
sl@0
   102
	return iBufferSize;
sl@0
   103
	}
sl@0
   104
sl@0
   105
void CMMFPcm16ToPcm16Codec::SetHwDevice(CMMFPcm16ToPcm16HwDevice* aHwDevice)
sl@0
   106
	{
sl@0
   107
	iHwDevice = aHwDevice;
sl@0
   108
	}
sl@0
   109
sl@0
   110
TUint CMMFPcm16ToPcm16HwDevice::CalculateBufferSize()
sl@0
   111
	{
sl@0
   112
	TUint sampleRate = 0;
sl@0
   113
	TUint channels = 0;
sl@0
   114
	TInt useBufferOfSize = 0;
sl@0
   115
	TInt minBufferSize = 0;
sl@0
   116
	TInt maxBufferSize = 0;
sl@0
   117
sl@0
   118
	if (iPlayCustomInterface)
sl@0
   119
		{
sl@0
   120
		sampleRate = iSampleRate;
sl@0
   121
		channels = iChannels;	
sl@0
   122
/*		if ((sampleRate) && (channels))
sl@0
   123
			{
sl@0
   124
			RMdaDevSound::TSoundFormatsSupportedBuf playFormatsSupported;
sl@0
   125
			if (iDataPath->Device().Handle())
sl@0
   126
				{
sl@0
   127
				iDataPath->Device().PlayFormatsSupported(playFormatsSupported);
sl@0
   128
				minBufferSize = playFormatsSupported().iMinBufferSize;
sl@0
   129
				maxBufferSize = playFormatsSupported().iMaxBufferSize;
sl@0
   130
				}
sl@0
   131
			else
sl@0
   132
				{//try to get handle
sl@0
   133
				TInt err = iDataPath->Device().Open();
sl@0
   134
				if (err == KErrNone)
sl@0
   135
					{
sl@0
   136
					iDataPath->Device().PlayFormatsSupported(playFormatsSupported);
sl@0
   137
					minBufferSize = playFormatsSupported().iMinBufferSize;
sl@0
   138
					maxBufferSize = playFormatsSupported().iMaxBufferSize;
sl@0
   139
					iDataPath->Device().Close();
sl@0
   140
					}
sl@0
   141
				}
sl@0
   142
			}
sl@0
   143
*/		}
sl@0
   144
	if ((iRecordCustomInterface) && (!sampleRate) && (!channels))
sl@0
   145
		{ //must be record
sl@0
   146
		sampleRate = iSampleRate;
sl@0
   147
		channels = iChannels;
sl@0
   148
/*		if ((sampleRate) && (channels))
sl@0
   149
			{//get max and min supported buffer sizes supported by hw
sl@0
   150
			RMdaDevSound::TSoundFormatsSupportedBuf recordFormatsSupported;
sl@0
   151
			if (iDataPath->Device().Handle())
sl@0
   152
				{
sl@0
   153
				iDataPath->Device().RecordFormatsSupported(recordFormatsSupported);
sl@0
   154
				minBufferSize = recordFormatsSupported().iMinBufferSize;
sl@0
   155
				maxBufferSize = recordFormatsSupported().iMaxBufferSize;
sl@0
   156
				}
sl@0
   157
			else
sl@0
   158
				{//try to get handle
sl@0
   159
				TInt err = iDataPath->Device().Open();
sl@0
   160
				if (err == KErrNone)
sl@0
   161
					{
sl@0
   162
					iDataPath->Device().RecordFormatsSupported(recordFormatsSupported);
sl@0
   163
					minBufferSize = recordFormatsSupported().iMinBufferSize;
sl@0
   164
					maxBufferSize = recordFormatsSupported().iMaxBufferSize;
sl@0
   165
					iDataPath->Device().Close();
sl@0
   166
					}
sl@0
   167
				}
sl@0
   168
			}
sl@0
   169
*/		}
sl@0
   170
//	else convert so not applicable
sl@0
   171
sl@0
   172
	if ((sampleRate) && (channels))
sl@0
   173
		{
sl@0
   174
		// Buffer size = (SampleRate * BytesPerSample * Channels) / 4
sl@0
   175
		useBufferOfSize = ((sampleRate * 2 * channels)/KDevSoundFramesPerSecond + (KDevSoundDeltaFrameSize-1)) &~ (KDevSoundDeltaFrameSize-1);
sl@0
   176
		//clamp buffer to desired limits
sl@0
   177
		if(useBufferOfSize < KDevSoundMinFrameSize) 
sl@0
   178
			useBufferOfSize = KDevSoundMinFrameSize;
sl@0
   179
		else if(useBufferOfSize > KDevSoundMaxFrameSize) 
sl@0
   180
			useBufferOfSize = KDevSoundMaxFrameSize;
sl@0
   181
sl@0
   182
		//clamp buffer to limits of hardware
sl@0
   183
		if (maxBufferSize)
sl@0
   184
			{//buffer size limits have been set by sound driver
sl@0
   185
			 //check we are within the limits
sl@0
   186
			if(useBufferOfSize < minBufferSize)
sl@0
   187
				useBufferOfSize = minBufferSize;
sl@0
   188
			else if(useBufferOfSize > maxBufferSize)
sl@0
   189
				useBufferOfSize = maxBufferSize;
sl@0
   190
			}
sl@0
   191
		}
sl@0
   192
	else
sl@0
   193
		{
sl@0
   194
		useBufferOfSize = KPCM16ToPCM16BufferSize;
sl@0
   195
		}
sl@0
   196
sl@0
   197
	return useBufferOfSize;
sl@0
   198
	}