os/mm/devsound/sounddevbt/PlatSec/src/Server/AudioServer/MmfBtDevSoundSessionBody.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) 2001-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 <e32base.h>
sl@0
    17
#include "MmfBtDevSoundSessionBody.h"
sl@0
    18
#include "MmfBtDevSoundSessionXtnd.h"
sl@0
    19
sl@0
    20
#include <mdaaudiotoneplayer.h>
sl@0
    21
#include <mmf/server/mmfdatabuffer.h>
sl@0
    22
#include <mmffourcc.h>
sl@0
    23
#include <mmfbthwdeviceimplementationuids.hrh>
sl@0
    24
#include <mmfbtswcodecwrappercustominterfacesuids.hrh> // KUidBtRefDevSoundTaskConfig
sl@0
    25
sl@0
    26
sl@0
    27
/*
sl@0
    28
 *	AO to handle RSD initialisation
sl@0
    29
 *
sl@0
    30
 */
sl@0
    31
CRoutingSoundDeviceHandler* CRoutingSoundDeviceHandler::NewL(MDevSoundObserver* aObserver)
sl@0
    32
	{
sl@0
    33
	CRoutingSoundDeviceHandler* self = new(ELeave) CRoutingSoundDeviceHandler(aObserver);
sl@0
    34
	CleanupStack::PushL(self);
sl@0
    35
	self->ConstructL();
sl@0
    36
	CleanupStack::Pop(self);
sl@0
    37
	return self;
sl@0
    38
	}
sl@0
    39
	
sl@0
    40
CRoutingSoundDeviceHandler::~CRoutingSoundDeviceHandler()
sl@0
    41
	{
sl@0
    42
	Cancel();
sl@0
    43
	}
sl@0
    44
		
sl@0
    45
void CRoutingSoundDeviceHandler::RunL()
sl@0
    46
	{
sl@0
    47
	TInt err = iStatus.Int();
sl@0
    48
	if (iObserver)
sl@0
    49
		{
sl@0
    50
		iObserver->InitializeComplete(err);
sl@0
    51
		}		
sl@0
    52
	}
sl@0
    53
	
sl@0
    54
void CRoutingSoundDeviceHandler::DoCancel()
sl@0
    55
	{
sl@0
    56
	if (iObserver)
sl@0
    57
		{
sl@0
    58
		iObserver->InitializeComplete(KErrCancel);
sl@0
    59
		}
sl@0
    60
	}
sl@0
    61
	
sl@0
    62
CRoutingSoundDeviceHandler::CRoutingSoundDeviceHandler(MDevSoundObserver* aObserver) :
sl@0
    63
														CActive(EPriorityStandard),
sl@0
    64
													 	iObserver(aObserver)
sl@0
    65
	{
sl@0
    66
	CActiveScheduler::Add(this);	
sl@0
    67
	}
sl@0
    68
	
sl@0
    69
void CRoutingSoundDeviceHandler::ConstructL()
sl@0
    70
	{
sl@0
    71
	}
sl@0
    72
sl@0
    73
void CRoutingSoundDeviceHandler::Start()
sl@0
    74
	{
sl@0
    75
	if (!IsActive())
sl@0
    76
		{
sl@0
    77
		SetActive();
sl@0
    78
		}
sl@0
    79
	}
sl@0
    80
	
sl@0
    81
/*
sl@0
    82
 *
sl@0
    83
 *	Default Constructor.
sl@0
    84
 *
sl@0
    85
 *	No default implementation. CMMFDevSoundProxy implements 2-phase construction.
sl@0
    86
 *
sl@0
    87
 */
sl@0
    88
CMMFDevSoundSvrImp::CMMFDevSoundSvrImp(CMMFDevSoundSessionXtnd* aParent)
sl@0
    89
: iParent(*aParent)
sl@0
    90
	{
sl@0
    91
	iMode= EMMFStateIdle;
sl@0
    92
	//Set reasonable default values for DTMF 
sl@0
    93
	iDTMFGen.SetToneDurations(250000,50000,250000);
sl@0
    94
	}
sl@0
    95
sl@0
    96
/*
sl@0
    97
 *
sl@0
    98
 *	Destructor.
sl@0
    99
 *
sl@0
   100
 *	Deletes all objects and releases all resource owned by this
sl@0
   101
 *	instance.
sl@0
   102
 *
sl@0
   103
 */
sl@0
   104
CMMFDevSoundSvrImp::~CMMFDevSoundSvrImp()
sl@0
   105
	{
sl@0
   106
	delete iRSDHandler;
sl@0
   107
	delete iToneBuffer1;
sl@0
   108
	delete iToneBuffer2;
sl@0
   109
	delete iDevSoundEventHandler; 
sl@0
   110
	if( iAudioPolicyProxy != NULL)
sl@0
   111
		{
sl@0
   112
		iAudioPolicyProxy->Close(); 
sl@0
   113
		delete iAudioPolicyProxy;
sl@0
   114
		}
sl@0
   115
	delete iDevSoundUtil;
sl@0
   116
	delete iFixedSequences;
sl@0
   117
	delete iCMMFHwDevice;
sl@0
   118
	}
sl@0
   119
sl@0
   120
/*
sl@0
   121
 *
sl@0
   122
 *	Constructs, and returns a pointer to, a new CMMFDevSoundSvrImp object.
sl@0
   123
 *
sl@0
   124
 *	Leaves on failure.
sl@0
   125
 *
sl@0
   126
 */
sl@0
   127
CMMFDevSoundSvrImp* CMMFDevSoundSvrImp::NewL(CMMFDevSoundSessionXtnd* aParent)
sl@0
   128
	{
sl@0
   129
	CMMFDevSoundSvrImp* self = new (ELeave) CMMFDevSoundSvrImp(aParent);
sl@0
   130
	return self;
sl@0
   131
	}
sl@0
   132
sl@0
   133
/*
sl@0
   134
 *
sl@0
   135
 *	3rd phase constructor - assumes that iParent has already been set up properly
sl@0
   136
 *                          (During ConstructL() it has yet to be
sl@0
   137
 *
sl@0
   138
 */
sl@0
   139
void CMMFDevSoundSvrImp::Construct3L(RServer2& aPolicyServerHandle)
sl@0
   140
	{
sl@0
   141
	// all these data properties should be NULL, but add ASSERTs to verity
sl@0
   142
	ASSERT(iAudioPolicyProxy==NULL);
sl@0
   143
	iAudioPolicyProxy = new (ELeave) RMMFAudioPolicyProxy();
sl@0
   144
	ASSERT(iDevSoundEventHandler==NULL);
sl@0
   145
	iDevSoundEventHandler = CMMFDevSoundEventHandler::NewL(iAudioPolicyProxy);
sl@0
   146
	User::LeaveIfError(iAudioPolicyProxy->Open(aPolicyServerHandle));
sl@0
   147
	iDevSoundEventHandler->SetDevSoundInfo(&iParent);
sl@0
   148
sl@0
   149
	iDevSoundUtil = CMMFDevSoundUtility::NewL();
sl@0
   150
	// Initialize Fixed sequence related
sl@0
   151
	iDevSoundUtil->InitializeFixedSequenceL(&iFixedSequences);
sl@0
   152
sl@0
   153
	// Add RSD handler construction here.
sl@0
   154
	iRSDHandler = CRoutingSoundDeviceHandler::NewL(&iParent);
sl@0
   155
	
sl@0
   156
	PreInitializeL();
sl@0
   157
	}
sl@0
   158
sl@0
   159
/**
sl@0
   160
 * internal procedure to perform all initialization prior to setting the 
sl@0
   161
 * data type 4CC code
sl@0
   162
 */
sl@0
   163
void CMMFDevSoundSvrImp::PreInitializeL()
sl@0
   164
	{
sl@0
   165
	// Set default values for priority settings: Note: Client must 
sl@0
   166
	// over ride default settings by calling SetPrioirtySettings
sl@0
   167
	iAudioPolicyPrioritySettings.iState = EMMFStateStopped;
sl@0
   168
	iAudioPolicyPrioritySettings.iPref = EMdaPriorityPreferenceNone;
sl@0
   169
	iAudioPolicyPrioritySettings.iPriority = 0;
sl@0
   170
sl@0
   171
	// Get device capabilities and current settings from Audio Policy:
sl@0
   172
	iAudioPolicyProxy->GetPlayFormatsSupported(iPlayFormatsSupported);
sl@0
   173
	iAudioPolicyProxy->GetPlayFormat(iPlayFormat);
sl@0
   174
	iAudioPolicyProxy->GetRecordFormatsSupported(iRecordFormatsSupported);
sl@0
   175
	iAudioPolicyProxy->GetRecordFormat(iRecordFormat);
sl@0
   176
sl@0
   177
	//default to play until we know we are recording
sl@0
   178
	User::LeaveIfError(InitializeFormat(iPlayFormatsSupported, iPlayFormat));
sl@0
   179
	}
sl@0
   180
sl@0
   181
/*
sl@0
   182
 *
sl@0
   183
 *	Initializes CMMFDevSoundProxy object to play and record PCM16 raw audio data
sl@0
   184
 *	with sampling rate of 8 KHz.
sl@0
   185
 *
sl@0
   186
 *	On completion of Initialization, calls InitializeComplete() on
sl@0
   187
 *	aDevSoundObserver.
sl@0
   188
 *
sl@0
   189
 *	Leaves on failure.
sl@0
   190
 *
sl@0
   191
 *	@param	"MDevSoundObserver& aDevSoundObserver"
sl@0
   192
 *			A reference to DevSound Observer instance.
sl@0
   193
 *
sl@0
   194
 *	@param	"TMMFState aMode"
sl@0
   195
 *			Mode for which this object will be used.
sl@0
   196
 *
sl@0
   197
 */
sl@0
   198
void CMMFDevSoundSvrImp::InitializeL(MDevSoundObserver& aDevSoundObserver, TMMFState aMode)
sl@0
   199
sl@0
   200
	{
sl@0
   201
	// if no HwDevice id specified, load default null implementation
sl@0
   202
	TUid rawUid = {KMmfUidBtHwDevicePCM16ToPCM16};
sl@0
   203
	InitializeL(aDevSoundObserver, rawUid, aMode);
sl@0
   204
	}
sl@0
   205
sl@0
   206
/*
sl@0
   207
 *
sl@0
   208
 *	Configure CMMFDevSoundProxy object for the settings in aConfig.
sl@0
   209
 *
sl@0
   210
 *	Use this to set sampling rate, Encoding and Mono/Stereo.
sl@0
   211
 *
sl@0
   212
 *	@param	"TMMFCapabilities& aConfig"
sl@0
   213
 *			Attribute values to which CMMFDevSoundProxy object will be configured to.
sl@0
   214
 *
sl@0
   215
 *  As part of defect 20796, the iRecordFormat has been set under the iPlayFormat, 
sl@0
   216
 *  before it was not set at all.
sl@0
   217
 *
sl@0
   218
 */
sl@0
   219
void CMMFDevSoundSvrImp::SetConfigL(const TMMFCapabilities& aConfig)
sl@0
   220
	{
sl@0
   221
	TUint attributeValue = aConfig.iRate;
sl@0
   222
	// WINS supports from 8000 Hz to 96000 Hz
sl@0
   223
	if (attributeValue & EMMFSampleRate96000Hz) 
sl@0
   224
		{ 
sl@0
   225
		iPlayFormat().iRate = 96000; 
sl@0
   226
		iRecordFormat().iRate = 96000;
sl@0
   227
		iDeviceConfig.iRate = EMMFSampleRate96000Hz;
sl@0
   228
		}
sl@0
   229
	else if (attributeValue & EMMFSampleRate88200Hz) 
sl@0
   230
		{ 
sl@0
   231
		iPlayFormat().iRate = 88200; 
sl@0
   232
		iRecordFormat().iRate = 88200;
sl@0
   233
		iDeviceConfig.iRate = EMMFSampleRate88200Hz;
sl@0
   234
		}
sl@0
   235
	else if (attributeValue & EMMFSampleRate64000Hz) 
sl@0
   236
		{ 
sl@0
   237
		iPlayFormat().iRate = 64000; 
sl@0
   238
		iRecordFormat().iRate = 64000;
sl@0
   239
		iDeviceConfig.iRate = EMMFSampleRate64000Hz;
sl@0
   240
		}
sl@0
   241
	else if (attributeValue & EMMFSampleRate48000Hz) 
sl@0
   242
		{ 
sl@0
   243
		iPlayFormat().iRate = 48000; 
sl@0
   244
		iRecordFormat().iRate = 48000;
sl@0
   245
		iDeviceConfig.iRate = EMMFSampleRate48000Hz;
sl@0
   246
		}
sl@0
   247
	else if (attributeValue & EMMFSampleRate44100Hz) 
sl@0
   248
		{ 
sl@0
   249
		iPlayFormat().iRate = 44100; 
sl@0
   250
		iRecordFormat().iRate = 44100;
sl@0
   251
		iDeviceConfig.iRate = EMMFSampleRate44100Hz;
sl@0
   252
		}
sl@0
   253
	else if (attributeValue & EMMFSampleRate32000Hz) 
sl@0
   254
		{ 
sl@0
   255
		iPlayFormat().iRate = 32000; 
sl@0
   256
		iRecordFormat().iRate = 32000; 
sl@0
   257
		iDeviceConfig.iRate = EMMFSampleRate32000Hz;
sl@0
   258
		}
sl@0
   259
	else if (attributeValue & EMMFSampleRate24000Hz)
sl@0
   260
		{
sl@0
   261
		iPlayFormat().iRate = 
sl@0
   262
		iRecordFormat().iRate = 24000;
sl@0
   263
		iDeviceConfig.iRate = EMMFSampleRate24000Hz;
sl@0
   264
		}
sl@0
   265
	else if (attributeValue & EMMFSampleRate22050Hz)
sl@0
   266
		{ 
sl@0
   267
		iPlayFormat().iRate = 22050; 
sl@0
   268
		iRecordFormat().iRate = 22050; 
sl@0
   269
		iDeviceConfig.iRate = EMMFSampleRate22050Hz;
sl@0
   270
		}
sl@0
   271
	else if (attributeValue & EMMFSampleRate16000Hz)
sl@0
   272
		{
sl@0
   273
		iPlayFormat().iRate = 16000;
sl@0
   274
		iRecordFormat().iRate = 16000; 
sl@0
   275
		iDeviceConfig.iRate = EMMFSampleRate16000Hz;
sl@0
   276
		}
sl@0
   277
	else if (attributeValue & EMMFSampleRate12000Hz)
sl@0
   278
		{
sl@0
   279
		iPlayFormat().iRate = 
sl@0
   280
		iRecordFormat().iRate = 12000;
sl@0
   281
		iDeviceConfig.iRate = EMMFSampleRate12000Hz;
sl@0
   282
		}
sl@0
   283
	else if (attributeValue & EMMFSampleRate11025Hz)
sl@0
   284
		{
sl@0
   285
		iPlayFormat().iRate = 11025;
sl@0
   286
		iRecordFormat().iRate = 11025;
sl@0
   287
		iDeviceConfig.iRate = EMMFSampleRate11025Hz;
sl@0
   288
		}
sl@0
   289
	else if (attributeValue & EMMFSampleRate8000Hz)
sl@0
   290
		{
sl@0
   291
		iPlayFormat().iRate = 8000;
sl@0
   292
		iRecordFormat().iRate = 8000;
sl@0
   293
		iDeviceConfig.iRate = EMMFSampleRate8000Hz;
sl@0
   294
		}
sl@0
   295
	else if (attributeValue) 
sl@0
   296
		{ //if no attribute value assume its not set
sl@0
   297
		User::Leave(KErrNotSupported);
sl@0
   298
		}
sl@0
   299
sl@0
   300
	attributeValue = aConfig.iEncoding;
sl@0
   301
	// Map from MMF Encoding enums to RMdaDevSound enum
sl@0
   302
	if(attributeValue & EMMFSoundEncoding8BitPCM) 
sl@0
   303
		{
sl@0
   304
		iPlayFormat().iEncoding = RMdaDevSound::EMdaSoundEncoding8BitPCM;
sl@0
   305
		iRecordFormat().iEncoding = RMdaDevSound::EMdaSoundEncoding8BitPCM;
sl@0
   306
		iDeviceConfig.iEncoding = EMMFSoundEncoding8BitPCM;
sl@0
   307
		}
sl@0
   308
	else if(attributeValue & EMMFSoundEncoding8BitALaw)
sl@0
   309
		{
sl@0
   310
		iPlayFormat().iEncoding = RMdaDevSound::EMdaSoundEncoding8BitALaw;
sl@0
   311
		iRecordFormat().iEncoding = RMdaDevSound::EMdaSoundEncoding8BitALaw;
sl@0
   312
		iDeviceConfig.iEncoding = EMMFSoundEncoding8BitALaw;
sl@0
   313
		}
sl@0
   314
	else if(attributeValue & EMMFSoundEncoding8BitMuLaw) 
sl@0
   315
		{
sl@0
   316
		iPlayFormat().iEncoding = RMdaDevSound::EMdaSoundEncoding8BitMuLaw;
sl@0
   317
		iRecordFormat().iEncoding = RMdaDevSound::EMdaSoundEncoding8BitMuLaw;
sl@0
   318
		iDeviceConfig.iEncoding = EMMFSoundEncoding8BitMuLaw;
sl@0
   319
		}
sl@0
   320
	else if(attributeValue & EMMFSoundEncoding16BitPCM)
sl@0
   321
		{
sl@0
   322
		iPlayFormat().iEncoding = RMdaDevSound::EMdaSoundEncoding16BitPCM;
sl@0
   323
		iRecordFormat().iEncoding = RMdaDevSound::EMdaSoundEncoding16BitPCM;
sl@0
   324
		iDeviceConfig.iEncoding = EMMFSoundEncoding16BitPCM;
sl@0
   325
		}
sl@0
   326
	else if (attributeValue) 
sl@0
   327
		{ //if no attribute value assume its not set
sl@0
   328
		User::Leave(KErrNotSupported);
sl@0
   329
		}
sl@0
   330
sl@0
   331
	// Mono/Stereo settings
sl@0
   332
	attributeValue = aConfig.iChannels;
sl@0
   333
	if(attributeValue & EMMFStereo) 
sl@0
   334
		{
sl@0
   335
		iPlayFormat().iChannels = 2;
sl@0
   336
		iRecordFormat().iChannels = 2;
sl@0
   337
		iDeviceConfig.iChannels = EMMFStereo;
sl@0
   338
		}
sl@0
   339
	else if(attributeValue & EMMFMono)
sl@0
   340
		{
sl@0
   341
		iPlayFormat().iChannels = 1;
sl@0
   342
		iRecordFormat().iChannels = 1;
sl@0
   343
		iDeviceConfig.iChannels = EMMFMono;
sl@0
   344
		}
sl@0
   345
	else if (attributeValue) 
sl@0
   346
		{ //if no attribute value assume its not set
sl@0
   347
		User::Leave(KErrNotSupported);
sl@0
   348
		}
sl@0
   349
	}
sl@0
   350
sl@0
   351
/*
sl@0
   352
 *
sl@0
   353
 *	Changes the current playback volume to a specified value.
sl@0
   354
 *
sl@0
   355
 *	The volume can be changed before or during playback and is effective
sl@0
   356
 *	immediately.
sl@0
   357
 *
sl@0
   358
 *	@param	"TInt aVolume"
sl@0
   359
 *			The volume setting. This can be any value from zero to the value
sl@0
   360
 *			returned by a call to CMdaAudioPlayerUtility::MaxVolume(). If the
sl@0
   361
 *			volume is not within this range, the volume is automatically set to
sl@0
   362
 *			minimum or maximum value based on the value that is being passed.
sl@0
   363
 *			Setting a zero value mutes the sound. Setting the maximum value
sl@0
   364
 *			results in the loudest possible sound.
sl@0
   365
 *
sl@0
   366
 */
sl@0
   367
void CMMFDevSoundSvrImp::SetVolume(TInt aVolume)
sl@0
   368
	{
sl@0
   369
sl@0
   370
	// Check and make sure that the volume is in valid range
sl@0
   371
	if (aVolume < 0)
sl@0
   372
		aVolume = 0;
sl@0
   373
sl@0
   374
	if (aVolume > MaxVolume())
sl@0
   375
		aVolume = MaxVolume();
sl@0
   376
sl@0
   377
	iVolume = aVolume;
sl@0
   378
sl@0
   379
	SetDeviceVolume(iVolume);
sl@0
   380
	}
sl@0
   381
sl@0
   382
/*
sl@0
   383
 *
sl@0
   384
 *	Changes the current recording gain to a specified value.
sl@0
   385
 *
sl@0
   386
 *	The gain can be changed before or during recording and is effective
sl@0
   387
 *	immediately.
sl@0
   388
 *
sl@0
   389
 *	@param	"TInt aGain"
sl@0
   390
 *			The volume setting. This can be any value from zero to the value
sl@0
   391
 *			returned by a call to CMdaAudioPlayerUtility::MaxVolume(). If the
sl@0
   392
 *			volume is not within this range, the gain is automatically set to
sl@0
   393
 *			minimum or maximum value based on the value that is being passed.
sl@0
   394
 *			Setting a zero value mutes the sound. Setting the maximum value
sl@0
   395
 *			results in the loudest possible sound.
sl@0
   396
 *
sl@0
   397
 */
sl@0
   398
void CMMFDevSoundSvrImp::SetGain(TInt aGain)
sl@0
   399
	{
sl@0
   400
	// make sure it falls with the correct range
sl@0
   401
	TInt maxGain = iRecordFormatsSupported().iMaxVolume;
sl@0
   402
	if (aGain > maxGain)
sl@0
   403
		aGain = maxGain;
sl@0
   404
	else if (aGain < 0)
sl@0
   405
		aGain = 0;
sl@0
   406
	iGain = aGain;
sl@0
   407
	SetDeviceRecordLevel(iGain);
sl@0
   408
	}
sl@0
   409
sl@0
   410
/*
sl@0
   411
 *
sl@0
   412
 *	Sets the speaker balance for playing.
sl@0
   413
 *
sl@0
   414
 *	The speaker balance can be changed before or during playback and is
sl@0
   415
 *	effective immediately.
sl@0
   416
 *
sl@0
   417
 *	@param	"TInt& aLeftPercentage"
sl@0
   418
 *			On return contains left speaker volume perecentage. This can be any
sl@0
   419
 *			value from zero to 100. Setting a zero value mutes the sound on left
sl@0
   420
 *			speaker.
sl@0
   421
 *
sl@0
   422
 *	@param	"TInt& aRightPercentage"
sl@0
   423
 *			On return contains right speaker volume perecentage. This can be any
sl@0
   424
 *			value from zero to 100. Setting a zero value mutes the sound on
sl@0
   425
 *			right speaker.
sl@0
   426
 *
sl@0
   427
 */
sl@0
   428
void CMMFDevSoundSvrImp::SetPlayBalanceL(TInt aLeftPercentage, TInt aRightPercentage)
sl@0
   429
	{
sl@0
   430
	if (aLeftPercentage < 0)
sl@0
   431
		aLeftPercentage = 0;
sl@0
   432
	else if (aLeftPercentage > 100)
sl@0
   433
		aLeftPercentage = 100;
sl@0
   434
	if (aRightPercentage < 0)
sl@0
   435
		aRightPercentage = 0;
sl@0
   436
	else if (aRightPercentage > 100)
sl@0
   437
		aRightPercentage = 100;
sl@0
   438
	iLeftPlayBalance = aLeftPercentage;
sl@0
   439
	iRightPlayBalance = aRightPercentage;
sl@0
   440
	}
sl@0
   441
sl@0
   442
/*
sl@0
   443
 *
sl@0
   444
 *	Sets the microphone gain balance for recording.
sl@0
   445
 *
sl@0
   446
 *	The microphone gain balance can be changed before or during recording and
sl@0
   447
 *	is effective immediately.
sl@0
   448
 *
sl@0
   449
 *	@param	"TInt aLeftPercentage"
sl@0
   450
 *			Left microphone gain precentage. This can be any value from zero to
sl@0
   451
 *			100. Setting a zero value mutes the gain on left microphone.
sl@0
   452
 *
sl@0
   453
 *	@param	"TInt aRightPercentage"
sl@0
   454
 *			Right microphone gain precentage. This can be any value from zero to
sl@0
   455
 *			100. Setting a zero value mutes the gain on right microphone.
sl@0
   456
 *
sl@0
   457
 */
sl@0
   458
void CMMFDevSoundSvrImp::SetRecordBalanceL(TInt aLeftPercentage, TInt aRightPercentage)
sl@0
   459
	{
sl@0
   460
	if (aLeftPercentage < 0)
sl@0
   461
		aLeftPercentage = 0;
sl@0
   462
	else if (aLeftPercentage > 100)
sl@0
   463
		aLeftPercentage = 100;
sl@0
   464
	if (aRightPercentage < 0)
sl@0
   465
		aRightPercentage = 0;
sl@0
   466
	else if (aRightPercentage > 100)
sl@0
   467
		aRightPercentage = 100;
sl@0
   468
	iLeftRecordBalance = aLeftPercentage;
sl@0
   469
	iRightRecordBalance = aRightPercentage;
sl@0
   470
	}
sl@0
   471
sl@0
   472
/*
sl@0
   473
 *
sl@0
   474
 *	Initializes audio device and start play process. This method queries and
sl@0
   475
 *	acquires the audio policy before initializing audio device. If there was an
sl@0
   476
 *	error during policy initialization, PlayError() method will be called on
sl@0
   477
 *	the observer with error code KErrAccessDenied, otherwise BufferToBeFilled()
sl@0
   478
 *	method will be called with a buffer reference. After reading data into the
sl@0
   479
 *	buffer reference passed, the client should call PlayData() to play data.
sl@0
   480
 *
sl@0
   481
 *	The amount of data that can be played is specified in
sl@0
   482
 *	CMMFBuffer::RequestSize(). Any data that is read into buffer beyond this
sl@0
   483
 *	size will be ignored.
sl@0
   484
 *
sl@0
   485
 *	Leaves on failure.
sl@0
   486
 *
sl@0
   487
 */
sl@0
   488
void CMMFDevSoundSvrImp::PlayInitL()
sl@0
   489
	{
sl@0
   490
	if (!iDevSoundObserver)
sl@0
   491
		User::Leave(KErrNotReady);
sl@0
   492
sl@0
   493
	// Get audio policy
sl@0
   494
	iAudioPolicyPrioritySettings.iState = EMMFStatePlayData;
sl@0
   495
	RequestPolicy();
sl@0
   496
	}
sl@0
   497
sl@0
   498
/*
sl@0
   499
 *
sl@0
   500
 *	Initializes audio device and start record process. 
sl@0
   501
 *  This method:
sl@0
   502
 *  1. Queries and acquires the audio policy before initializing audio device. 
sl@0
   503
 *     If there was an error during policy initialization, RecordError() method will 
sl@0
   504
 *     be called on the observer with error code KErrAccessDenied, otherwise BufferToBeEmptied()
sl@0
   505
 *	   method will be called with a buffer reference. This buffer contains recorded
sl@0
   506
 *	   or encoded data. After processing data in the buffer reference passed, the
sl@0
   507
 *	   client should call RecordData() to continue recording process.
sl@0
   508
 *
sl@0
   509
 *  2. Checks if the requesting client process has a UserEnvironment capability.
sl@0
   510
 *     If it does not, the audio device will not be initialized and an error 
sl@0
   511
 *     code KErrAccessDenied will be sent to the client.
sl@0
   512
 *
sl@0
   513
 *	The amount of data that is available is specified in
sl@0
   514
 *	CMMFBuffer::RequestSize().
sl@0
   515
 *
sl@0
   516
 *	Leaves on failure.
sl@0
   517
 *
sl@0
   518
 */
sl@0
   519
void CMMFDevSoundSvrImp::RecordInitL(const RMmfIpcMessage& aMessage)
sl@0
   520
	{
sl@0
   521
	if (!iDevSoundObserver)
sl@0
   522
		User::Leave(KErrNotReady);
sl@0
   523
	
sl@0
   524
	// Checkes if the client has the UserEnvironment capability
sl@0
   525
	if (!aMessage.HasCapability(ECapabilityUserEnvironment))
sl@0
   526
		{
sl@0
   527
		User::Leave(KErrPermissionDenied);
sl@0
   528
		}
sl@0
   529
	
sl@0
   530
	// Get audio policy
sl@0
   531
	iAudioPolicyPrioritySettings.iState = EMMFStateRecordData;
sl@0
   532
	RequestPolicy();
sl@0
   533
	}
sl@0
   534
sl@0
   535
/*
sl@0
   536
 *
sl@0
   537
 *	Plays data in the buffer at the current volume. The client should fill
sl@0
   538
 *	the buffer with audio data before calling this method. The Observer gets
sl@0
   539
 *	reference to buffer along with callback BufferToBeFilled(). When playing of
sl@0
   540
 *	the audio sample is complete, successfully or otherwise, the method
sl@0
   541
 *	PlayError() on observer is called.
sl@0
   542
 *
sl@0
   543
 */
sl@0
   544
void CMMFDevSoundSvrImp::PlayData()
sl@0
   545
	{
sl@0
   546
	ASSERT(iDevSoundObserver);
sl@0
   547
sl@0
   548
	if (iMode== EMMFStateIdle)
sl@0
   549
		return;
sl@0
   550
sl@0
   551
	TInt error = KErrNone;
sl@0
   552
sl@0
   553
    if(iCMMFHwDevice)
sl@0
   554
	    {
sl@0
   555
		if (iPaused)
sl@0
   556
			{
sl@0
   557
			iPaused = EFalse;
sl@0
   558
			//note PlayData does not leave or return an error code so the Start() fails we cannot
sl@0
   559
			//report the error back at this point
sl@0
   560
			error = iCMMFHwDevice->Start(EDevDecode, EDevOutFlow);//restart hw device after pause
sl@0
   561
			}
sl@0
   562
	   else if(iMode== EMMFStatePlaying)
sl@0
   563
		    {
sl@0
   564
		    TInt len = iHwDeviceBuffer->Data().Length();
sl@0
   565
		    iPlayedBytesCount += len;
sl@0
   566
		    if (iHwDeviceBuffer->LastBuffer())
sl@0
   567
			    iLastBufferReceived = ETrue;
sl@0
   568
sl@0
   569
sl@0
   570
            if (iMode== EMMFStatePlaying)
sl@0
   571
                // Pass the data buffer to HwDevice
sl@0
   572
                error = iCMMFHwDevice->ThisHwBufferFilled(*iHwDeviceBuffer);
sl@0
   573
            }
sl@0
   574
		}
sl@0
   575
	if (error != KErrNone)
sl@0
   576
		iDevSoundObserver->PlayError(error);
sl@0
   577
	}
sl@0
   578
sl@0
   579
/*
sl@0
   580
 *
sl@0
   581
 *	Stops the ongoing operation (Play, Record, TonePlay, Convert)
sl@0
   582
 *
sl@0
   583
 */
sl@0
   584
void CMMFDevSoundSvrImp::Stop()
sl@0
   585
	{
sl@0
   586
	iPaused = EFalse;
sl@0
   587
sl@0
   588
	if (iMode== EMMFStateIdle)
sl@0
   589
		return;
sl@0
   590
sl@0
   591
	 // Stop the hw device first - this unloads sound drivers
sl@0
   592
    if(iCMMFHwDevice)
sl@0
   593
		iCMMFHwDevice->Stop();
sl@0
   594
sl@0
   595
	iDevSoundEventHandler->CancelReceiveEvents();
sl@0
   596
sl@0
   597
	iAudioPolicyPrioritySettings.iState = EMMFStateStopped;
sl@0
   598
	UpdatePolicyState();
sl@0
   599
	}
sl@0
   600
sl@0
   601
/*
sl@0
   602
 *
sl@0
   603
 *	Temporarily Stops the ongoing operation (Play, Record, TonePlay, Convert)
sl@0
   604
 *
sl@0
   605
 */
sl@0
   606
void CMMFDevSoundSvrImp::Pause()
sl@0
   607
	{
sl@0
   608
	iPaused = ETrue;
sl@0
   609
sl@0
   610
	if (iMode== EMMFStateIdle)
sl@0
   611
		return;
sl@0
   612
sl@0
   613
	// Pause the HW device first
sl@0
   614
	if(iCMMFHwDevice)
sl@0
   615
		iCMMFHwDevice->Pause();
sl@0
   616
	
sl@0
   617
	// defer policy update until buffers have been flushed
sl@0
   618
	if ((iMode == EMMFStatePlaying) || (iMode == EMMFStateTonePlaying))
sl@0
   619
		{
sl@0
   620
		iDevSoundEventHandler->CancelReceiveEvents();
sl@0
   621
		
sl@0
   622
		iAudioPolicyPrioritySettings.iState = EMMFStatePaused;
sl@0
   623
		UpdatePolicyState();
sl@0
   624
		}
sl@0
   625
	}
sl@0
   626
sl@0
   627
/*
sl@0
   628
 *
sl@0
   629
 *	Returns the sample recorded so far.
sl@0
   630
 *
sl@0
   631
 *	@return "TInt"
sl@0
   632
 *			Returns the samples recorded.
sl@0
   633
 *
sl@0
   634
 */
sl@0
   635
TInt CMMFDevSoundSvrImp::SamplesRecorded()
sl@0
   636
	{
sl@0
   637
	TInt samples = 0;
sl@0
   638
	
sl@0
   639
	if(iRecordCustomInterface)
sl@0
   640
		{
sl@0
   641
		samples = iRecordCustomInterface->BytesRecorded();
sl@0
   642
		if(NumberOfChannels() > 1)
sl@0
   643
			{
sl@0
   644
			samples /= NumberOfChannels();
sl@0
   645
			}
sl@0
   646
		if(BytesPerAudioSample() > 1)
sl@0
   647
			{
sl@0
   648
			samples /= BytesPerAudioSample();
sl@0
   649
			}
sl@0
   650
		}
sl@0
   651
sl@0
   652
	return samples;
sl@0
   653
	}
sl@0
   654
sl@0
   655
/*
sl@0
   656
 *
sl@0
   657
 *	Returns the sample played so far.
sl@0
   658
 *
sl@0
   659
 *	@return "TInt"
sl@0
   660
 *			Returns the samples recorded.
sl@0
   661
 *
sl@0
   662
 */
sl@0
   663
TInt CMMFDevSoundSvrImp::SamplesPlayed()
sl@0
   664
	{
sl@0
   665
	TInt samples = 0;
sl@0
   666
	if(iPlayCustomInterface)
sl@0
   667
		{
sl@0
   668
		TUint bytesPlayed = iPlayCustomInterface->BytesPlayed();
sl@0
   669
		if (bytesPlayed)
sl@0
   670
			iPlayedBytesCount = bytesPlayed;
sl@0
   671
sl@0
   672
		samples = iPlayedBytesCount;
sl@0
   673
		if(NumberOfChannels() > 1)
sl@0
   674
			samples /= NumberOfChannels();
sl@0
   675
sl@0
   676
		if(BytesPerAudioSample() > 1)
sl@0
   677
			samples /= BytesPerAudioSample();
sl@0
   678
		}
sl@0
   679
	//note always pcm16 becuase the iPlayedBytesCount originates from 
sl@0
   680
	//RMdaDevSound which is always pcm16
sl@0
   681
	return samples; //each sample is 2 bytes
sl@0
   682
	}
sl@0
   683
sl@0
   684
sl@0
   685
/*
sl@0
   686
 *
sl@0
   687
 *	Initializes audio device and start playing tone. Tone is played with
sl@0
   688
 *	frequency and for duration specified.
sl@0
   689
 *
sl@0
   690
 *	Leaves on failure.
sl@0
   691
 *
sl@0
   692
 *	@param	"TInt aFrequency"
sl@0
   693
 *			Frequency at with the tone will be played.
sl@0
   694
 *
sl@0
   695
 *	@param	"TTimeIntervalMicroSeconds& aDuration"
sl@0
   696
 *			The period over which the tone will be played. A zero value causes
sl@0
   697
 *			the no tone to be played (Verify this with test app).
sl@0
   698
 *
sl@0
   699
 */
sl@0
   700
void CMMFDevSoundSvrImp::PlayToneL(TInt aFrequency, const TTimeIntervalMicroSeconds& aDuration)
sl@0
   701
	{
sl@0
   702
	if (iMode!= EMMFStateTonePlaying)
sl@0
   703
		User::Leave(KErrNotSupported); //tone playing only supported in tone play state
sl@0
   704
sl@0
   705
	// Check whether frequency and duration is valid or not
sl@0
   706
	TInt64 zeroInt64(0);
sl@0
   707
	if ((aFrequency<0) || (aDuration.Int64() < zeroInt64))
sl@0
   708
		User::Leave(KErrArgument);
sl@0
   709
sl@0
   710
	if (!iDevSoundObserver)
sl@0
   711
		User::Leave(KErrNotReady);
sl@0
   712
sl@0
   713
	iToneGen.SetFrequencyAndDuration(aFrequency,aDuration);
sl@0
   714
sl@0
   715
	// Get audio policy
sl@0
   716
	iAudioPolicyPrioritySettings.iState = EMMFStatePlayTone;
sl@0
   717
	RequestPolicy();
sl@0
   718
	}
sl@0
   719
sl@0
   720
/*
sl@0
   721
 *	Initializes audio device and start playing a dual tone. 
sl@0
   722
 *  The tone consists of two sine waves of different frequencies summed together
sl@0
   723
 *  Dual Tone is played with specified frequencies and for specified duration.
sl@0
   724
 *
sl@0
   725
 *	@param	"aFrequencyOne"
sl@0
   726
 *			First frequency of dual tone
sl@0
   727
 *
sl@0
   728
 *	@param	"aFrequencyTwo"
sl@0
   729
 *			Second frequency of dual tone
sl@0
   730
 *
sl@0
   731
 *	@param	"aDuration"
sl@0
   732
 *			The period over which the tone will be played. A zero value causes
sl@0
   733
 *			the no tone to be played (Verify this with test app).
sl@0
   734
 */
sl@0
   735
void CMMFDevSoundSvrImp::PlayDualToneL(TInt aFrequencyOne, TInt aFrequencyTwo, const TTimeIntervalMicroSeconds& aDuration)
sl@0
   736
	{
sl@0
   737
sl@0
   738
	// Check whether frequencies and duration are valid or not
sl@0
   739
	TInt64 zeroInt64(0);
sl@0
   740
	if ((aFrequencyOne<0) || (aFrequencyTwo<0) || (aDuration.Int64() < zeroInt64))
sl@0
   741
		User::Leave(KErrArgument);
sl@0
   742
sl@0
   743
	if (!iDevSoundObserver)
sl@0
   744
		User::Leave(KErrNotReady);
sl@0
   745
sl@0
   746
	iDualToneGen.SetFrequencyAndDuration(aFrequencyOne, aFrequencyTwo, aDuration);
sl@0
   747
sl@0
   748
	// Get audio policy
sl@0
   749
	iAudioPolicyPrioritySettings.iState = EMMFStatePlayDualTone;
sl@0
   750
	RequestPolicy();
sl@0
   751
	}
sl@0
   752
sl@0
   753
/*
sl@0
   754
 *
sl@0
   755
 *	Initializes audio device and start playing DTMF string aDTMFString.
sl@0
   756
 *
sl@0
   757
 *	Leaves on failure.
sl@0
   758
 *
sl@0
   759
 *	@param	"TDesC& aDTMFString"
sl@0
   760
 *			DTMF sequence in a descriptor.
sl@0
   761
 *
sl@0
   762
 */
sl@0
   763
void CMMFDevSoundSvrImp::PlayDTMFStringL(const TDesC& aDTMFString)
sl@0
   764
	{
sl@0
   765
	if (!iDevSoundObserver)
sl@0
   766
		User::Leave(KErrNotReady);
sl@0
   767
sl@0
   768
	if (iMode!= EMMFStateTonePlaying)
sl@0
   769
		User::Leave(KErrNotSupported); //tone playing only supported in tone play state
sl@0
   770
sl@0
   771
	iDTMFGen.SetString(aDTMFString);
sl@0
   772
sl@0
   773
	// Get audio policy
sl@0
   774
	iAudioPolicyPrioritySettings.iState = EMMFStatePlayDTMFString;
sl@0
   775
	RequestPolicy();
sl@0
   776
	}
sl@0
   777
sl@0
   778
/*
sl@0
   779
 *
sl@0
   780
 *	Initializes audio device and start playing tone sequence.
sl@0
   781
 *
sl@0
   782
 *	Leaves on failure.
sl@0
   783
 *
sl@0
   784
 *	@param	"TDesC8& aData"
sl@0
   785
 *			Tone sequence in a descriptor.
sl@0
   786
 *
sl@0
   787
 */
sl@0
   788
void CMMFDevSoundSvrImp::PlayToneSequenceL(const TDesC8& aData)
sl@0
   789
	{
sl@0
   790
	if (!iDevSoundObserver)
sl@0
   791
		User::Leave(KErrNotReady);
sl@0
   792
sl@0
   793
	if (iMode!= EMMFStateTonePlaying)
sl@0
   794
		User::Leave(KErrNotSupported); //tone playing only supported in tone play state
sl@0
   795
sl@0
   796
	// Check whether the sequence is valid or not
sl@0
   797
	if (!iDevSoundUtil->RecognizeSequence(aData))
sl@0
   798
		User::Leave(KErrCorrupt);
sl@0
   799
sl@0
   800
	iSequenceGen.SetSequenceData(aData);
sl@0
   801
sl@0
   802
	// Get audio policy
sl@0
   803
	iAudioPolicyPrioritySettings.iState = EMMFStatePlayToneSequence;
sl@0
   804
	RequestPolicy();
sl@0
   805
	}
sl@0
   806
sl@0
   807
/*
sl@0
   808
 *
sl@0
   809
 *	Initializes audio device and start playing the specified pre-defined tone
sl@0
   810
 *	sequence.
sl@0
   811
 *
sl@0
   812
 *	Leaves on failure.
sl@0
   813
 *
sl@0
   814
 *	@param	"TInt aSequenceNumber"
sl@0
   815
 *			The index identifying the specific pre-defined tone sequence. Index
sl@0
   816
 *			values are relative to zero.
sl@0
   817
 *			This can be any value from zero to the value returned by a call to
sl@0
   818
 *			CMdaAudioPlayerUtility::FixedSequenceCount() - 1.
sl@0
   819
 *			The function raises a panic if sequence number is not within this
sl@0
   820
 *			range.
sl@0
   821
 *
sl@0
   822
 */
sl@0
   823
void CMMFDevSoundSvrImp::PlayFixedSequenceL(TInt aSequenceNumber)
sl@0
   824
	{
sl@0
   825
	if (!iDevSoundObserver)
sl@0
   826
		User::Leave(KErrNotReady);
sl@0
   827
sl@0
   828
	if (iMode!= EMMFStateTonePlaying)
sl@0
   829
		User::Leave(KErrNotSupported); //tone playing only supported in tone play state
sl@0
   830
sl@0
   831
	ASSERT((aSequenceNumber >= 0)&&(aSequenceNumber < iFixedSequences->Count()));
sl@0
   832
sl@0
   833
	iFixedSequence.Set(iFixedSequences->MdcaPoint(aSequenceNumber));
sl@0
   834
	iSequenceGen.SetSequenceData(iFixedSequence);
sl@0
   835
sl@0
   836
	// Get audio policy
sl@0
   837
	iAudioPolicyPrioritySettings.iState = EMMFStatePlayToneSequence;
sl@0
   838
	RequestPolicy();
sl@0
   839
	}
sl@0
   840
sl@0
   841
/*
sl@0
   842
 *
sl@0
   843
 *	Defines the duration of tone on, tone off and tone pause to be used during the
sl@0
   844
 *	DTMF tone playback operation.
sl@0
   845
 *
sl@0
   846
 *	Supported only during tone playing.
sl@0
   847
 *
sl@0
   848
 *	@param	"TTimeIntervalMicroSeconds32& aToneOnLength"
sl@0
   849
 *			The period over which the tone will be played. If this is set to
sl@0
   850
 *			zero, then the tone is not played.
sl@0
   851
 *
sl@0
   852
 *	@param	"TTimeIntervalMicroSeconds32& aToneOffLength"
sl@0
   853
 *			The period over which the no tone will be played.
sl@0
   854
 *
sl@0
   855
 *	@param	"TTimeIntervalMicroSeconds32& aPauseLength"
sl@0
   856
 *			The period over which the tone playing will be paused.
sl@0
   857
 *
sl@0
   858
 */
sl@0
   859
void CMMFDevSoundSvrImp::SetDTMFLengths(TTimeIntervalMicroSeconds32& aToneOnLength,
sl@0
   860
								TTimeIntervalMicroSeconds32& aToneOffLength,
sl@0
   861
								TTimeIntervalMicroSeconds32& aPauseLength) 
sl@0
   862
	{
sl@0
   863
sl@0
   864
	if(aToneOnLength.Int() < KMdaInfiniteDurationDTMFToneOnLength)
sl@0
   865
		aToneOnLength = TTimeIntervalMicroSeconds32(0);
sl@0
   866
	if(aToneOffLength.Int() < 0)
sl@0
   867
		aToneOffLength = TTimeIntervalMicroSeconds32(0);
sl@0
   868
	if(aPauseLength.Int() < 0)
sl@0
   869
		aPauseLength = TTimeIntervalMicroSeconds32(0);
sl@0
   870
sl@0
   871
	iDTMFGen.SetToneDurations(aToneOnLength,aToneOffLength,aPauseLength);
sl@0
   872
	}
sl@0
   873
sl@0
   874
/*
sl@0
   875
 *
sl@0
   876
 *	Defines the period over which the volume level is to rise smoothly from
sl@0
   877
 *	nothing to the normal volume level.
sl@0
   878
 *
sl@0
   879
 *	@param	"TTimeIntervalMicroSeconds& aRampDuration"
sl@0
   880
 *			The period over which the volume is to rise. A zero value causes 
sl@0
   881
 *			the tone sample to be played at the normal level for the full
sl@0
   882
 *			duration of the playback. A value, which is longer than the duration
sl@0
   883
 *			of the tone sample, that the sample never reaches its normal
sl@0
   884
 *			volume level.
sl@0
   885
 *
sl@0
   886
 *
sl@0
   887
 */
sl@0
   888
void CMMFDevSoundSvrImp::SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration)
sl@0
   889
	{
sl@0
   890
	// save ramp duration for tone generator
sl@0
   891
	iRampDuration = aRampDuration;
sl@0
   892
sl@0
   893
	SetDeviceVolumeRamp(iRampDuration);
sl@0
   894
	}
sl@0
   895
sl@0
   896
/**
sl@0
   897
 *	Sets volume ramp on HwDevice.
sl@0
   898
 */
sl@0
   899
TInt CMMFDevSoundSvrImp::SetDeviceVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration)
sl@0
   900
	{
sl@0
   901
	TInt error = KErrNone;
sl@0
   902
	if (iPlayCustomInterface) 
sl@0
   903
		iPlayCustomInterface->SetVolumeRamp(aRampDuration);
sl@0
   904
	else
sl@0
   905
		error = KErrNotReady;
sl@0
   906
	return error;
sl@0
   907
    }
sl@0
   908
sl@0
   909
/**
sl@0
   910
 *	@see sounddevice.h
sl@0
   911
 */
sl@0
   912
void CMMFDevSoundSvrImp::GetSupportedInputDataTypesL(RArray<TFourCC>& aSupportedDataTypes, const TMMFPrioritySettings& /*aPrioritySettings*/) const
sl@0
   913
	{
sl@0
   914
	//aPrioritySettings not used on ref DevSound
sl@0
   915
	//search for playing datatypes
sl@0
   916
	iDevSoundUtil->SeekHwDevicePluginsL(aSupportedDataTypes, EMMFStatePlaying);
sl@0
   917
	}
sl@0
   918
sl@0
   919
/**
sl@0
   920
 *	@see sounddevice.h
sl@0
   921
 */
sl@0
   922
void CMMFDevSoundSvrImp::GetSupportedOutputDataTypesL(RArray<TFourCC>& aSupportedDataTypes, const TMMFPrioritySettings& /*aPrioritySettings*/) const
sl@0
   923
	{
sl@0
   924
	//aPrioritySettings not used on ref DevSound
sl@0
   925
	// search for recording datatypes
sl@0
   926
	iDevSoundUtil->SeekHwDevicePluginsL(aSupportedDataTypes, EMMFStateRecording);
sl@0
   927
	}
sl@0
   928
	
sl@0
   929
TInt CMMFDevSoundSvrImp::RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData)
sl@0
   930
	{	
sl@0
   931
	return iAudioPolicyProxy->RequestResourceNotification(aEventType,aNotificationRegistrationData);
sl@0
   932
	}
sl@0
   933
	
sl@0
   934
TInt CMMFDevSoundSvrImp::CancelRegisterAsClient(TUid aEventType)
sl@0
   935
	{	
sl@0
   936
	return iAudioPolicyProxy->CancelRequestResourceNotification(aEventType);
sl@0
   937
	}
sl@0
   938
sl@0
   939
TInt CMMFDevSoundSvrImp::GetResourceNotificationData(TUid aEventType, TDes8& aNotificationData)
sl@0
   940
	{	
sl@0
   941
	TInt err = KErrNone;
sl@0
   942
	err = iAudioPolicyProxy->IsRegisteredResourceNotification(aEventType);
sl@0
   943
	if(err == KErrNone)
sl@0
   944
		{
sl@0
   945
		aNotificationData.Num(SamplesPlayed());
sl@0
   946
		}
sl@0
   947
	return err;
sl@0
   948
	}
sl@0
   949
	
sl@0
   950
TInt CMMFDevSoundSvrImp::WillResumePlay()
sl@0
   951
	{
sl@0
   952
	return iAudioPolicyProxy->StopNotification();
sl@0
   953
	}	
sl@0
   954
sl@0
   955
/********************************************************************************
sl@0
   956
 *				Implementations of Non Exported public functions begins here	*
sl@0
   957
 ********************************************************************************/
sl@0
   958
sl@0
   959
//
sl@0
   960
//				Audio Policy specific implementation begins here				//
sl@0
   961
//
sl@0
   962
sl@0
   963
/*
sl@0
   964
 *
sl@0
   965
 *	Called by Audio Policy Server when a request to play is approved by the 
sl@0
   966
 *	Audio Policy Server.
sl@0
   967
 *
sl@0
   968
 *	Leaves on failure??.
sl@0
   969
 *
sl@0
   970
 */
sl@0
   971
void CMMFDevSoundSvrImp::StartPlayDataL()
sl@0
   972
	{
sl@0
   973
	ASSERT(iMode== EMMFStatePlaying);
sl@0
   974
sl@0
   975
	TInt error = KErrNone;
sl@0
   976
sl@0
   977
	if(iCMMFHwDevice)
sl@0
   978
		{
sl@0
   979
        // Set volume and play format values
sl@0
   980
        error = SetPlayFormat(iPlayFormat);
sl@0
   981
        if (error == KErrNone)
sl@0
   982
			error = SetDeviceVolume(iVolume);
sl@0
   983
        if (error == KErrNone)
sl@0
   984
			error = SetDeviceVolumeRamp(iRampDuration);
sl@0
   985
sl@0
   986
		// Initialize attribute values
sl@0
   987
		iPlayedBytesCount = 0;
sl@0
   988
		iLastBufferReceived = EFalse;
sl@0
   989
sl@0
   990
        // Start HwDevice
sl@0
   991
        if (error == KErrNone)
sl@0
   992
	        error = iCMMFHwDevice->Start(EDevDecode, EDevOutFlow);
sl@0
   993
		}
sl@0
   994
	else
sl@0
   995
		error = KErrNotReady;
sl@0
   996
sl@0
   997
	if (error != KErrNone)
sl@0
   998
		iDevSoundObserver->PlayError(error);
sl@0
   999
	}
sl@0
  1000
sl@0
  1001
/*
sl@0
  1002
 *
sl@0
  1003
 *	Called by Audio Policy Server when a request to record is approved by the 
sl@0
  1004
 *	Audio Policy Server.
sl@0
  1005
 *
sl@0
  1006
 *	Leaves on failure.
sl@0
  1007
 *
sl@0
  1008
 */
sl@0
  1009
void CMMFDevSoundSvrImp::StartRecordDataL()
sl@0
  1010
	{
sl@0
  1011
	ASSERT(iMode== EMMFStateRecording);
sl@0
  1012
sl@0
  1013
	 if(iCMMFHwDevice)
sl@0
  1014
		{
sl@0
  1015
        TInt error = KErrNone;
sl@0
  1016
        error = SetRecordFormat(iRecordFormat);
sl@0
  1017
		if (error != KErrNone)
sl@0
  1018
			{
sl@0
  1019
			iDevSoundObserver->RecordError(error);
sl@0
  1020
			return;
sl@0
  1021
			}
sl@0
  1022
        error = SetDeviceRecordLevel(iGain);
sl@0
  1023
		if (error != KErrNone)
sl@0
  1024
			{
sl@0
  1025
			iDevSoundObserver->RecordError(error);
sl@0
  1026
			return;
sl@0
  1027
			}
sl@0
  1028
sl@0
  1029
        // Initialize attribute values
sl@0
  1030
		iRecordedBytesCount = 0;
sl@0
  1031
sl@0
  1032
        error = iCMMFHwDevice->Start(EDevEncode, EDevInFlow);
sl@0
  1033
		if (iHwDeviceBuffer)
sl@0
  1034
			iHwDeviceBuffer->SetLastBuffer(EFalse);
sl@0
  1035
sl@0
  1036
		if (error != KErrNone)
sl@0
  1037
			{
sl@0
  1038
			iDevSoundObserver->RecordError(error);
sl@0
  1039
			return;
sl@0
  1040
			}
sl@0
  1041
        }
sl@0
  1042
	else
sl@0
  1043
		iDevSoundObserver->RecordError(KErrNotReady);
sl@0
  1044
	}
sl@0
  1045
sl@0
  1046
/*
sl@0
  1047
 *
sl@0
  1048
 *	Called by Audio Policy Server when a request to play tone is approved by
sl@0
  1049
 *	the Audio Policy Server.
sl@0
  1050
 *
sl@0
  1051
 *	Leaves on failure.
sl@0
  1052
 *
sl@0
  1053
 */
sl@0
  1054
void CMMFDevSoundSvrImp::StartPlayToneL()
sl@0
  1055
	{
sl@0
  1056
	ASSERT(iMode== EMMFStateTonePlaying);
sl@0
  1057
sl@0
  1058
	 if(iCMMFHwDevice)
sl@0
  1059
		{
sl@0
  1060
        TInt error = KErrNone;
sl@0
  1061
        // Set volume and play format values
sl@0
  1062
        error = SetPlayFormat(iPlayFormat);
sl@0
  1063
		if (error != KErrNone)
sl@0
  1064
			{
sl@0
  1065
			iDevSoundObserver->ToneFinished(error);
sl@0
  1066
			return;
sl@0
  1067
			}
sl@0
  1068
        if (iHwDeviceID.iUid == KMmfUidBtHwDevicePCM16ToPCM16)
sl@0
  1069
            error = SetDeviceVolume(iVolume);
sl@0
  1070
		else
sl@0
  1071
			error = KErrGeneral;//hw device should always be pcm16 for tone
sl@0
  1072
sl@0
  1073
		// turn off volume ramping - this is done in software below
sl@0
  1074
        if (error == KErrNone)
sl@0
  1075
			error = SetDeviceVolumeRamp(TTimeIntervalMicroSeconds(0));
sl@0
  1076
sl@0
  1077
        if (error != KErrNone)
sl@0
  1078
            {
sl@0
  1079
            iDevSoundObserver->ToneFinished(error);
sl@0
  1080
            return;
sl@0
  1081
            }
sl@0
  1082
sl@0
  1083
        // Initialize attribute values
sl@0
  1084
		iPlayedBytesCount = 0;
sl@0
  1085
sl@0
  1086
        // Configure tone generator
sl@0
  1087
        iToneGen.Configure(
sl@0
  1088
			iPlayFormat().iRate,
sl@0
  1089
			iPlayFormat().iChannels,
sl@0
  1090
		    iRepeatCount,
sl@0
  1091
			I64LOW((iRepeatTrailingSilence.Int64()*iPlayFormat().iRate)/1000000),
sl@0
  1092
			I64LOW((iRampDuration.Int64()*iPlayFormat().iRate)/1000000)
sl@0
  1093
			);
sl@0
  1094
sl@0
  1095
		iCurrentGenerator = &iToneGen;
sl@0
  1096
sl@0
  1097
        // Start playback
sl@0
  1098
        DoPlayL();
sl@0
  1099
               
sl@0
  1100
		}
sl@0
  1101
	else
sl@0
  1102
		iDevSoundObserver->ToneFinished(KErrNotReady);
sl@0
  1103
	}
sl@0
  1104
sl@0
  1105
/*
sl@0
  1106
 *
sl@0
  1107
 *	Called by Audio Policy Server when a request to play a dual tone is approved by
sl@0
  1108
 *	the Audio Policy Server.
sl@0
  1109
 *
sl@0
  1110
 */
sl@0
  1111
void CMMFDevSoundSvrImp::StartPlayDualToneL()
sl@0
  1112
	{
sl@0
  1113
	ASSERT(iMode== EMMFStateTonePlaying);
sl@0
  1114
sl@0
  1115
	 if(iCMMFHwDevice)
sl@0
  1116
		{
sl@0
  1117
        TInt error = KErrNone;
sl@0
  1118
        // Set volume and play format values
sl@0
  1119
        error = SetPlayFormat(iPlayFormat);
sl@0
  1120
		if (error != KErrNone)
sl@0
  1121
			{
sl@0
  1122
			iDevSoundObserver->ToneFinished(error);
sl@0
  1123
			return;
sl@0
  1124
			}
sl@0
  1125
        if (iHwDeviceID.iUid == KMmfUidBtHwDevicePCM16ToPCM16)
sl@0
  1126
            error = SetDeviceVolume(iVolume);
sl@0
  1127
		else 
sl@0
  1128
			error = KErrGeneral;//hw device should always be pcm16 for tone
sl@0
  1129
sl@0
  1130
		// turn off volume ramping - this is done in software below
sl@0
  1131
        if (error == KErrNone)
sl@0
  1132
			error = SetDeviceVolumeRamp(TTimeIntervalMicroSeconds(0));
sl@0
  1133
sl@0
  1134
        if (error != KErrNone)
sl@0
  1135
            {
sl@0
  1136
            iDevSoundObserver->ToneFinished(error);
sl@0
  1137
            return;
sl@0
  1138
            }
sl@0
  1139
sl@0
  1140
        // Initialize attribute values
sl@0
  1141
		iPlayedBytesCount = 0;
sl@0
  1142
sl@0
  1143
        // Configure dual tone generator
sl@0
  1144
		iDualToneGen.Configure(
sl@0
  1145
			iPlayFormat().iRate,
sl@0
  1146
			iPlayFormat().iChannels,
sl@0
  1147
			iRepeatCount,
sl@0
  1148
			I64LOW((iRepeatTrailingSilence.Int64()*iPlayFormat().iRate)/KOneMillionMicroSeconds),
sl@0
  1149
			I64LOW((iRampDuration.Int64()*iPlayFormat().iRate)/KOneMillionMicroSeconds)
sl@0
  1150
			);
sl@0
  1151
sl@0
  1152
		iCurrentGenerator = &iDualToneGen;
sl@0
  1153
sl@0
  1154
        // Start playback
sl@0
  1155
        DoPlayL();
sl@0
  1156
		}
sl@0
  1157
	else
sl@0
  1158
		iDevSoundObserver->ToneFinished(KErrNotReady);
sl@0
  1159
	}
sl@0
  1160
sl@0
  1161
/*
sl@0
  1162
 *
sl@0
  1163
 *	Called by Audio Policy Server when a request to play DTMF String is approved
sl@0
  1164
 *	by the Audio Policy Server.
sl@0
  1165
 *
sl@0
  1166
 *	Leaves on failure.
sl@0
  1167
 *
sl@0
  1168
 */
sl@0
  1169
void CMMFDevSoundSvrImp::StartPlayDTMFStringL()
sl@0
  1170
	{
sl@0
  1171
sl@0
  1172
	ASSERT(iMode== EMMFStateTonePlaying);
sl@0
  1173
sl@0
  1174
	if(iCMMFHwDevice)
sl@0
  1175
		{
sl@0
  1176
        TInt error = KErrNone;
sl@0
  1177
        // Set volume and play format values
sl@0
  1178
        error = SetPlayFormat(iPlayFormat);
sl@0
  1179
		if (error != KErrNone)
sl@0
  1180
            {
sl@0
  1181
            iDevSoundObserver->ToneFinished(error);
sl@0
  1182
            return;
sl@0
  1183
            }
sl@0
  1184
        error = SetDeviceVolume(iVolume);
sl@0
  1185
sl@0
  1186
		// turn off volume ramping - this is done in software below
sl@0
  1187
        if (error == KErrNone)
sl@0
  1188
			error = SetDeviceVolumeRamp(TTimeIntervalMicroSeconds(0));
sl@0
  1189
sl@0
  1190
        if (error != KErrNone)
sl@0
  1191
            {
sl@0
  1192
            iDevSoundObserver->ToneFinished(error);
sl@0
  1193
            return;
sl@0
  1194
            }
sl@0
  1195
sl@0
  1196
        // Initialize attribute values
sl@0
  1197
		iPlayedBytesCount = 0;
sl@0
  1198
sl@0
  1199
	    iDTMFGen.Configure(
sl@0
  1200
			iPlayFormat().iRate,
sl@0
  1201
			iPlayFormat().iChannels,
sl@0
  1202
		    iRepeatCount,
sl@0
  1203
			I64LOW((iRepeatTrailingSilence.Int64()*iPlayFormat().iRate)/1000000),
sl@0
  1204
		    I64LOW((iRampDuration.Int64()*iPlayFormat().iRate)/1000000)
sl@0
  1205
			);
sl@0
  1206
sl@0
  1207
		iCurrentGenerator = &iDTMFGen;
sl@0
  1208
sl@0
  1209
        // Start playback
sl@0
  1210
		//need to trap this as we can leave with KErrUnderflow
sl@0
  1211
		//if there was no data to play - the error has already
sl@0
  1212
		//been sent to the observer and we don't want to call RunError
sl@0
  1213
        TRAP(error,DoPlayL());
sl@0
  1214
		if ((error != KErrUnderflow)&&(error != KErrNone))
sl@0
  1215
			{
sl@0
  1216
			User::Leave(error);
sl@0
  1217
			}
sl@0
  1218
		}
sl@0
  1219
	else
sl@0
  1220
		iDevSoundObserver->ToneFinished(KErrNotReady);
sl@0
  1221
	}
sl@0
  1222
sl@0
  1223
/*
sl@0
  1224
 *
sl@0
  1225
 *	Called by Audio Policy Server when a request to play tone sequence is
sl@0
  1226
 *	approved by the Audio Policy Server.
sl@0
  1227
 *
sl@0
  1228
 *	Leaves on failure.
sl@0
  1229
 *
sl@0
  1230
 */
sl@0
  1231
void CMMFDevSoundSvrImp::StartPlayToneSequenceL()
sl@0
  1232
	{
sl@0
  1233
	ASSERT(iMode== EMMFStateTonePlaying);
sl@0
  1234
sl@0
  1235
	if(iCMMFHwDevice)
sl@0
  1236
		{
sl@0
  1237
        TInt error = KErrNone;
sl@0
  1238
        // Set volume and play format values
sl@0
  1239
        if (iHwDeviceID.iUid == KMmfUidBtHwDevicePCM16ToPCM16)
sl@0
  1240
            error = SetPlayFormat(iPlayFormat);
sl@0
  1241
			else error = KErrGeneral;//hw device should always be pcm16 for tone
sl@0
  1242
		if (error != KErrNone)
sl@0
  1243
            {
sl@0
  1244
            iDevSoundObserver->ToneFinished(error);
sl@0
  1245
            return;
sl@0
  1246
            }
sl@0
  1247
sl@0
  1248
        if (iHwDeviceID.iUid == KMmfUidBtHwDevicePCM16ToPCM16)
sl@0
  1249
            error = SetDeviceVolume(iVolume);
sl@0
  1250
		else 
sl@0
  1251
			error = KErrGeneral;//hw device should always be pcm16 for tone
sl@0
  1252
sl@0
  1253
		// turn off volume ramping - this is done in software below
sl@0
  1254
        if (error == KErrNone)
sl@0
  1255
			error = SetDeviceVolumeRamp(TTimeIntervalMicroSeconds(0));
sl@0
  1256
sl@0
  1257
        if (error != KErrNone)
sl@0
  1258
            {
sl@0
  1259
            iDevSoundObserver->ToneFinished(error);
sl@0
  1260
            return;
sl@0
  1261
            }
sl@0
  1262
sl@0
  1263
        // Initialize attribute values
sl@0
  1264
		iPlayedBytesCount = 0;
sl@0
  1265
sl@0
  1266
		iSequenceGen.Configure(
sl@0
  1267
			iPlayFormat().iRate,
sl@0
  1268
			iPlayFormat().iChannels,
sl@0
  1269
			iRepeatCount,
sl@0
  1270
			I64LOW((iRepeatTrailingSilence.Int64()*iPlayFormat().iRate)/1000000),
sl@0
  1271
			I64LOW((iRampDuration.Int64()*iPlayFormat().iRate)/1000000)
sl@0
  1272
			);
sl@0
  1273
sl@0
  1274
		iCurrentGenerator = &iSequenceGen;
sl@0
  1275
sl@0
  1276
        // Start playback
sl@0
  1277
        DoPlayL();
sl@0
  1278
		}
sl@0
  1279
	else
sl@0
  1280
		iDevSoundObserver->ToneFinished(KErrNotReady);
sl@0
  1281
	}
sl@0
  1282
sl@0
  1283
/*
sl@0
  1284
 *
sl@0
  1285
 *	Called by Audio Policy Server when the current DevSound instance looses the
sl@0
  1286
 *	policy because of another instance with a higher priority wants the device.
sl@0
  1287
 *
sl@0
  1288
 */
sl@0
  1289
void CMMFDevSoundSvrImp::SendEventToClient(const TMMFEvent& aEvent)
sl@0
  1290
	{
sl@0
  1291
	switch (iMode)
sl@0
  1292
		{
sl@0
  1293
		case EMMFStatePlaying:
sl@0
  1294
		case EMMFStateTonePlaying:
sl@0
  1295
		case EMMFStatePlayToneSequence:
sl@0
  1296
		case EMMFStateRecording:
sl@0
  1297
			{
sl@0
  1298
			Error(aEvent.iErrorCode);//Updates Bytes played informs client
sl@0
  1299
			iCMMFHwDevice->Stop();//unloads sound device
sl@0
  1300
			Stopped();//Updates policy		
sl@0
  1301
			iMode = EMMFStateIdle;
sl@0
  1302
			iAudioPolicyProxy->LaunchRequests();
sl@0
  1303
			break;
sl@0
  1304
			}
sl@0
  1305
		case EMMFStateIdle:
sl@0
  1306
			{	
sl@0
  1307
			iMode = EMMFStatePlaying;
sl@0
  1308
			iDevSoundObserver->SendEventToClient(aEvent);
sl@0
  1309
			break;
sl@0
  1310
			}
sl@0
  1311
		default:
sl@0
  1312
			break;
sl@0
  1313
		}
sl@0
  1314
	// Have audio Policy launch higher priority request:
sl@0
  1315
	}
sl@0
  1316
sl@0
  1317
sl@0
  1318
/**
sl@0
  1319
 *
sl@0
  1320
 *	Sets volume on HwDevice.
sl@0
  1321
 *	
sl@0
  1322
 *	@return	"TInt"
sl@0
  1323
 *			Error value returned by HwDevice.
sl@0
  1324
 *
sl@0
  1325
 */
sl@0
  1326
TInt CMMFDevSoundSvrImp::SetDeviceVolume(TInt aVolume)
sl@0
  1327
	{
sl@0
  1328
	TInt error = KErrNone;
sl@0
  1329
	if (iPlayCustomInterface) 
sl@0
  1330
		iPlayCustomInterface->SetVolume(aVolume);
sl@0
  1331
	else error = KErrNotReady;
sl@0
  1332
	return error;
sl@0
  1333
    }
sl@0
  1334
sl@0
  1335
/**
sl@0
  1336
 *
sl@0
  1337
 *	Sets PlayFormat on HwDevice.
sl@0
  1338
 *	
sl@0
  1339
 *
sl@0
  1340
 *	@return	"TInt"
sl@0
  1341
 *			Error value returned by HwDevice.
sl@0
  1342
 *
sl@0
  1343
 */
sl@0
  1344
TInt CMMFDevSoundSvrImp::SetPlayFormat(RMdaDevSound::TCurrentSoundFormatBuf& aPlayFormat)
sl@0
  1345
	{
sl@0
  1346
	TInt error = KErrNone;
sl@0
  1347
	if (iCMMFHwDevice)
sl@0
  1348
		{
sl@0
  1349
		TTaskConfig taskConfig;
sl@0
  1350
		taskConfig.iUid = KUidBtRefDevSoundTaskConfig;
sl@0
  1351
		taskConfig.iRate = aPlayFormat().iRate;
sl@0
  1352
		
sl@0
  1353
		if (aPlayFormat().iChannels == 1)
sl@0
  1354
			{
sl@0
  1355
			taskConfig.iStereoMode = ETaskMono;
sl@0
  1356
			}
sl@0
  1357
		else if (aPlayFormat().iChannels == 2)
sl@0
  1358
			{
sl@0
  1359
			taskConfig.iStereoMode = ETaskInterleaved;
sl@0
  1360
			}
sl@0
  1361
		else
sl@0
  1362
			{
sl@0
  1363
			return KErrArgument;
sl@0
  1364
			}
sl@0
  1365
sl@0
  1366
		error = iCMMFHwDevice->SetConfig(taskConfig);
sl@0
  1367
		//note the iEncoding and iBufferSize are already determined by the 
sl@0
  1368
		//CMMFHwDevice plugin and so are not set.
sl@0
  1369
		}
sl@0
  1370
	else
sl@0
  1371
		{
sl@0
  1372
		error = KErrNotReady;
sl@0
  1373
		}
sl@0
  1374
	return error;
sl@0
  1375
    }
sl@0
  1376
sl@0
  1377
sl@0
  1378
/**
sl@0
  1379
 *
sl@0
  1380
 *	Sets RecordFormat on HwDevice.
sl@0
  1381
 *	
sl@0
  1382
 *
sl@0
  1383
 *	@return	"TInt"
sl@0
  1384
 *			Error value returned by HwDevice.
sl@0
  1385
 *
sl@0
  1386
 */
sl@0
  1387
TInt CMMFDevSoundSvrImp::SetRecordFormat(RMdaDevSound::TCurrentSoundFormatBuf& aRecordFormat)
sl@0
  1388
	{
sl@0
  1389
	TInt error = KErrNone;
sl@0
  1390
	if (iCMMFHwDevice)
sl@0
  1391
		{
sl@0
  1392
		TTaskConfig taskConfig;
sl@0
  1393
		taskConfig.iUid = KUidBtRefDevSoundTaskConfig;
sl@0
  1394
		taskConfig.iRate = aRecordFormat().iRate;
sl@0
  1395
sl@0
  1396
		if (aRecordFormat().iChannels == 1)
sl@0
  1397
			{
sl@0
  1398
			taskConfig.iStereoMode = ETaskMono;
sl@0
  1399
			}
sl@0
  1400
		else if (aRecordFormat().iChannels == 2)
sl@0
  1401
			{
sl@0
  1402
			taskConfig.iStereoMode = ETaskInterleaved;
sl@0
  1403
			}
sl@0
  1404
		else
sl@0
  1405
			{
sl@0
  1406
			return KErrArgument;
sl@0
  1407
			}
sl@0
  1408
sl@0
  1409
		error = iCMMFHwDevice->SetConfig(taskConfig);
sl@0
  1410
		//note the iEncoding and iBufferSize are already determined by the 
sl@0
  1411
		//CMMFHwDevice plugin and so are not set.
sl@0
  1412
		}
sl@0
  1413
	else
sl@0
  1414
		{
sl@0
  1415
		error = KErrNotReady;
sl@0
  1416
		}
sl@0
  1417
	return error;
sl@0
  1418
    }
sl@0
  1419
sl@0
  1420
sl@0
  1421
/**
sl@0
  1422
 *
sl@0
  1423
 *	Sets record level on HwDevice.
sl@0
  1424
 *	
sl@0
  1425
 *
sl@0
  1426
 *	@return	"TInt"
sl@0
  1427
 *			Error value returned by HwDevice.
sl@0
  1428
 *
sl@0
  1429
 */
sl@0
  1430
TInt CMMFDevSoundSvrImp::SetDeviceRecordLevel(TInt aGain)
sl@0
  1431
	{
sl@0
  1432
	TInt error = KErrNone;
sl@0
  1433
	if (iRecordCustomInterface) 
sl@0
  1434
		iRecordCustomInterface->SetGain(aGain);
sl@0
  1435
	else error = KErrNotReady;
sl@0
  1436
	return error;
sl@0
  1437
sl@0
  1438
    }
sl@0
  1439
sl@0
  1440
sl@0
  1441
/**
sl@0
  1442
 *
sl@0
  1443
 *	MMMFHwDeviceObserver mixin implementation.
sl@0
  1444
 *
sl@0
  1445
 *	The CMMFHwDevice implementation object calls this method during decoding
sl@0
  1446
 *	(playing), when it needs the encoded data in the buffer
sl@0
  1447
 *	aHwDataBuffer.
sl@0
  1448
 *
sl@0
  1449
 *	@return	"TInt"
sl@0
  1450
 *			Error code. KErrNone if success.
sl@0
  1451
 *
sl@0
  1452
 */
sl@0
  1453
TInt CMMFDevSoundSvrImp::FillThisHwBuffer(CMMFBuffer& aHwDataBuffer)
sl@0
  1454
	{
sl@0
  1455
	TInt err = KErrNone;
sl@0
  1456
    // Keep a reference to this Hw data Buffer. We need to send the 
sl@0
  1457
	// reference back to HwDevice implementation
sl@0
  1458
	iHwDeviceBuffer = static_cast<CMMFDataBuffer*> (&aHwDataBuffer);
sl@0
  1459
	// Set the request length, From HwDevice this comes with buffer
sl@0
  1460
	// length.
sl@0
  1461
	TInt len = iHwDeviceBuffer->Data().MaxLength();
sl@0
  1462
	// Ignore error. since buffer size = Buffer Length 
sl@0
  1463
	TRAP(err, iHwDeviceBuffer->SetRequestSizeL(len));
sl@0
  1464
sl@0
  1465
	if (iMode== EMMFStatePlaying) // Get Data from Observer
sl@0
  1466
		{
sl@0
  1467
		if (iLastBufferReceived)
sl@0
  1468
			{
sl@0
  1469
			iHwDeviceBuffer->Data().SetLength(0);
sl@0
  1470
			// Pass the buffer to the he device
sl@0
  1471
            err = iCMMFHwDevice->ThisHwBufferFilled(*iHwDeviceBuffer);
sl@0
  1472
			}
sl@0
  1473
		else
sl@0
  1474
			// Pass the buffer to the observer
sl@0
  1475
			iDevSoundObserver->BufferToBeFilled(&aHwDataBuffer);
sl@0
  1476
		}
sl@0
  1477
	else if (iMode== EMMFStateTonePlaying)
sl@0
  1478
		{
sl@0
  1479
        // Hw device will call this method right after its Start was called.
sl@0
  1480
        // When it calls this for the first time it hasn't played one single
sl@0
  1481
        // buffer yet so check that.
sl@0
  1482
        // In this case there's no need to set the active buffer as it's already
sl@0
  1483
        // waiting to be played.
sl@0
  1484
        if (!iFirstCallFromHwDevice)
sl@0
  1485
            SetActiveToneBuffer();
sl@0
  1486
sl@0
  1487
		// If there is no data in the active buffer, tone play is finished.
sl@0
  1488
		// DevSound just have to wait for completion event from audio device.
sl@0
  1489
		if (iActiveToneBuffer->Data().Length() > 0)
sl@0
  1490
            { 
sl@0
  1491
			TInt tonelen = iActiveToneBuffer->Data().Length();
sl@0
  1492
sl@0
  1493
			// don't enter more data than can be handled by the receiving buffer
sl@0
  1494
			if (len >= tonelen) len = tonelen;
sl@0
  1495
sl@0
  1496
            // Copy data from tone buffer to hw device buffer
sl@0
  1497
            Mem::Copy((TAny*)(iHwDeviceBuffer->Data().Ptr()), (TAny*)(iActiveToneBuffer->Data().Ptr()), len);
sl@0
  1498
            
sl@0
  1499
            iHwDeviceBuffer->Data().SetLength(len);
sl@0
  1500
            // Play data and try to generate next data block
sl@0
  1501
			err = iCMMFHwDevice->ThisHwBufferFilled(*iHwDeviceBuffer);
sl@0
  1502
            if (err != KErrNone)
sl@0
  1503
            	return err;
sl@0
  1504
            // Check again whether this is the first call from Hw device.
sl@0
  1505
            // FillFreeToneBuffer assumes the iActiveToneBuffer has already
sl@0
  1506
            // been played.
sl@0
  1507
            if (!iFirstCallFromHwDevice)
sl@0
  1508
                err = FillFreeToneBuffer();
sl@0
  1509
            else
sl@0
  1510
                iFirstCallFromHwDevice = EFalse;  // Reset flag
sl@0
  1511
sl@0
  1512
 			}
sl@0
  1513
		else if (iFirstCallFromHwDevice)
sl@0
  1514
			{//we have no data in the tone buffer and thus have no 
sl@0
  1515
			//outstanding requests to play
sl@0
  1516
			err = KErrUnderflow; //simulate underrun
sl@0
  1517
			}
sl@0
  1518
sl@0
  1519
	
sl@0
  1520
		// If there was an error filling the buffer could be corrupt data
sl@0
  1521
		// notify the client and stop playing.Set err to KErrNone. 
sl@0
  1522
		if (err != KErrNone)
sl@0
  1523
			{
sl@0
  1524
			Error(err);//Updates Bytes played informs client
sl@0
  1525
			err = KErrNone;
sl@0
  1526
			iCMMFHwDevice->Stop();//unloads sound device
sl@0
  1527
			Stopped();//Updates policy
sl@0
  1528
            }
sl@0
  1529
		}
sl@0
  1530
	else
sl@0
  1531
		{
sl@0
  1532
		err = KErrGeneral;
sl@0
  1533
		iDevSoundObserver->PlayError(KErrGeneral);
sl@0
  1534
		}
sl@0
  1535
	return err;
sl@0
  1536
	}
sl@0
  1537
sl@0
  1538
sl@0
  1539
/**
sl@0
  1540
 *
sl@0
  1541
 *	MMMFHwDeviceObserver mixin implementation.
sl@0
  1542
 *
sl@0
  1543
 *	The CMMFHwDevice implementation object calls this method during encoding
sl@0
  1544
 *	(recording), when it fills the buffer aHwDataBuffer with
sl@0
  1545
 *	encoded data.
sl@0
  1546
 *
sl@0
  1547
 *	@return	"TInt"
sl@0
  1548
 *			Error code. KErrNone if success.
sl@0
  1549
 *
sl@0
  1550
 */
sl@0
  1551
TInt CMMFDevSoundSvrImp::EmptyThisHwBuffer(CMMFBuffer& aHwDataBuffer)
sl@0
  1552
	{
sl@0
  1553
	TInt err = KErrNone;
sl@0
  1554
	if(iMode== EMMFStateRecording)
sl@0
  1555
		{
sl@0
  1556
		// Keep a reference to this Hw data Buffer. We need to send the 
sl@0
  1557
		// reference back to HwDevice implementation
sl@0
  1558
		iHwDeviceBuffer = static_cast<CMMFDataBuffer*>(&aHwDataBuffer);
sl@0
  1559
sl@0
  1560
		// Set the request length, From HwDevice this comes with buffer
sl@0
  1561
		// length. MMF will use RequestSize attribute of the buffer.
sl@0
  1562
		// We can avoid this by setting in HwDevice implemenation
sl@0
  1563
		TInt len = iHwDeviceBuffer->Data().Length();
sl@0
  1564
		iRecordedBytesCount += len;
sl@0
  1565
		TRAP(err, iHwDeviceBuffer->SetRequestSizeL(len));
sl@0
  1566
	
sl@0
  1567
		// if we're pausing (i.e. flushing) set the last buffer flag
sl@0
  1568
		// when we get an empty buffer from the logical driver
sl@0
  1569
		if(iPaused  && iHwDeviceBuffer->Data().Length() == 0)
sl@0
  1570
		{
sl@0
  1571
		iPaused = EFalse;
sl@0
  1572
sl@0
  1573
		iHwDeviceBuffer->SetLastBuffer(ETrue);
sl@0
  1574
sl@0
  1575
		iDevSoundEventHandler->CancelReceiveEvents();
sl@0
  1576
sl@0
  1577
		iAudioPolicyPrioritySettings.iState = EMMFStateStopped;
sl@0
  1578
		UpdatePolicyState();
sl@0
  1579
		}
sl@0
  1580
sl@0
  1581
		// Send Data from Observer
sl@0
  1582
		iDevSoundObserver->BufferToBeEmptied(iHwDeviceBuffer);
sl@0
  1583
		}
sl@0
  1584
	else
sl@0
  1585
		{
sl@0
  1586
		err = KErrGeneral;
sl@0
  1587
		iDevSoundObserver->RecordError(KErrGeneral);
sl@0
  1588
		}
sl@0
  1589
sl@0
  1590
	return err;
sl@0
  1591
	}
sl@0
  1592
sl@0
  1593
sl@0
  1594
/**
sl@0
  1595
 *
sl@0
  1596
 *	MMMFHwDeviceObserver mixin implementation.
sl@0
  1597
 *
sl@0
  1598
 *	The CMMFHwDevice implementation object calls this method when a message from
sl@0
  1599
 *	the hardware device implementation is received.
sl@0
  1600
 *
sl@0
  1601
 *	@return	"TInt"
sl@0
  1602
 *			Error code. KErrNone if success.
sl@0
  1603
 *
sl@0
  1604
 */
sl@0
  1605
TInt CMMFDevSoundSvrImp::MsgFromHwDevice(TUid aMessageType, const TDesC8& /*aMsg*/)
sl@0
  1606
	{
sl@0
  1607
	TInt result = KErrNotSupported;
sl@0
  1608
	if (aMessageType.iUid == KMmfHwDeviceObserverUpdateBytesPlayed)
sl@0
  1609
		{//this is used by sw codec wrapper to request a bytes played update
sl@0
  1610
		//bytes played won't be updated in Stopped() or Error() on sw cdoec wrapper
sl@0
  1611
		//as the sound device is closed. Non swCodec wrapper Hw device plugins
sl@0
  1612
		//can get there bytes updated on Stopped() and/or Error()
sl@0
  1613
		UpdateBytesPlayed();
sl@0
  1614
		result = KErrNone;
sl@0
  1615
		}
sl@0
  1616
	return result;
sl@0
  1617
	}
sl@0
  1618
sl@0
  1619
/**
sl@0
  1620
 *
sl@0
  1621
 *	MMMFHwDeviceObserver mixin implementation.
sl@0
  1622
 *
sl@0
  1623
 *	The CMMFHwDevice implementation object calls this method when the current
sl@0
  1624
 *	encode or decode task is finished or stopped.  The policy state is updated
sl@0
  1625
 *
sl@0
  1626
 */
sl@0
  1627
void CMMFDevSoundSvrImp::Stopped()
sl@0
  1628
	{
sl@0
  1629
	//for swcodec wrap hw devices bytes played updated in MsgFromHwDevice
sl@0
  1630
	//but non Swcodec wrappers hw devices may do it differently
sl@0
  1631
	//also don't know if non Swcodec wrap hw device will call Stopped or Error first
sl@0
  1632
	UpdateBytesPlayed();
sl@0
  1633
sl@0
  1634
	iLastBufferReceived = EFalse;
sl@0
  1635
	iAudioPolicyPrioritySettings.iState = EMMFStateCompleted;
sl@0
  1636
	UpdatePolicyState();
sl@0
  1637
	}
sl@0
  1638
sl@0
  1639
/**
sl@0
  1640
 *  MMMFHwDeviceObserver mixin implementation
sl@0
  1641
 *  Processes error from hw device
sl@0
  1642
 */
sl@0
  1643
void CMMFDevSoundSvrImp::Error(TInt aError)
sl@0
  1644
	{
sl@0
  1645
	if (iMode== EMMFStatePlaying)
sl@0
  1646
		{
sl@0
  1647
		//for swcodec wrap hw devices bytes played updated in MsgFromHwDevice
sl@0
  1648
		//but non Swcodec wrappers hw devices may do it differently
sl@0
  1649
		//also don't know if non Swcodec wrap hw device will call Stopped or Error first
sl@0
  1650
		UpdateBytesPlayed();
sl@0
  1651
sl@0
  1652
        	iDevSoundObserver->PlayError(aError);		
sl@0
  1653
        	iAudioPolicyPrioritySettings.iState = EMMFStateStopped;
sl@0
  1654
        	UpdatePolicyState();
sl@0
  1655
		}
sl@0
  1656
	else if (iMode== EMMFStateRecording)
sl@0
  1657
		{
sl@0
  1658
        iDevSoundObserver->RecordError(aError);
sl@0
  1659
		}
sl@0
  1660
	else if (iMode== EMMFStateTonePlaying)
sl@0
  1661
		{
sl@0
  1662
        iDevSoundObserver->ToneFinished(aError);
sl@0
  1663
		}
sl@0
  1664
	//else can't handle error
sl@0
  1665
	}
sl@0
  1666
sl@0
  1667
sl@0
  1668
/********************************************************************************
sl@0
  1669
 *				Non Exported public functions ends here							*
sl@0
  1670
 ********************************************************************************/
sl@0
  1671
sl@0
  1672
sl@0
  1673
/********************************************************************************
sl@0
  1674
 *				Private functions begins here									*
sl@0
  1675
 ********************************************************************************/
sl@0
  1676
sl@0
  1677
TInt CMMFDevSoundSvrImp::InitializeFormat(RMdaDevSound::TSoundFormatsSupportedBuf& aSupportedFormat,
sl@0
  1678
		RMdaDevSound::TCurrentSoundFormatBuf& aFormat)
sl@0
  1679
	{
sl@0
  1680
	// Choose an encoding
sl@0
  1681
	TUint32 enc = aSupportedFormat().iEncodings;
sl@0
  1682
	// Always defaults to this
sl@0
  1683
	if (enc & RMdaDevSound::EMdaSoundEncoding16BitPCM)
sl@0
  1684
		aFormat().iEncoding = RMdaDevSound::EMdaSoundEncoding16BitPCM;
sl@0
  1685
	else if (enc & RMdaDevSound::EMdaSoundEncoding8BitALaw)
sl@0
  1686
		aFormat().iEncoding = RMdaDevSound::EMdaSoundEncoding8BitALaw;
sl@0
  1687
	else if (enc & RMdaDevSound::EMdaSoundEncoding8BitMuLaw)
sl@0
  1688
		aFormat().iEncoding = RMdaDevSound::EMdaSoundEncoding8BitMuLaw;
sl@0
  1689
	else if (enc & RMdaDevSound::EMdaSoundEncoding8BitPCM)
sl@0
  1690
		aFormat().iEncoding = RMdaDevSound::EMdaSoundEncoding8BitPCM;
sl@0
  1691
sl@0
  1692
	// default to Monophonic playback:
sl@0
  1693
	aFormat().iChannels=1;
sl@0
  1694
sl@0
  1695
	// Store the device capabilities (WINS supports from 8000 Hz to 44100 Hz)
sl@0
  1696
	if ((aSupportedFormat().iMinRate <= 8000) && (8000 <= aSupportedFormat().iMaxRate))
sl@0
  1697
		iDeviceCapabilities.iRate = EMMFSampleRate8000Hz;
sl@0
  1698
	if ((aSupportedFormat().iMinRate <= 11025) && (11025 <= aSupportedFormat().iMaxRate))
sl@0
  1699
		iDeviceCapabilities.iRate |= EMMFSampleRate11025Hz;
sl@0
  1700
	if ((aSupportedFormat().iMinRate <= 12000) && (12000 <= aSupportedFormat().iMaxRate))
sl@0
  1701
		iDeviceCapabilities.iRate |= EMMFSampleRate12000Hz;
sl@0
  1702
	if ((aSupportedFormat().iMinRate <= 16000) && (16000 <= aSupportedFormat().iMaxRate))
sl@0
  1703
		iDeviceCapabilities.iRate |= EMMFSampleRate16000Hz;
sl@0
  1704
	if ((aSupportedFormat().iMinRate <= 22050) && (22050 <= aSupportedFormat().iMaxRate))
sl@0
  1705
		iDeviceCapabilities.iRate |= EMMFSampleRate22050Hz;
sl@0
  1706
	if ((aSupportedFormat().iMinRate <= 24000) && (24000 <= aSupportedFormat().iMaxRate))
sl@0
  1707
		iDeviceCapabilities.iRate |= EMMFSampleRate24000Hz;
sl@0
  1708
	if ((aSupportedFormat().iMinRate <= 32000) && (32000 <= aSupportedFormat().iMaxRate))
sl@0
  1709
		iDeviceCapabilities.iRate |= EMMFSampleRate32000Hz;
sl@0
  1710
	if ((aSupportedFormat().iMinRate <= 44100) && (44100 <= aSupportedFormat().iMaxRate))
sl@0
  1711
		iDeviceCapabilities.iRate |= EMMFSampleRate44100Hz;
sl@0
  1712
	if ((aSupportedFormat().iMinRate <= 48000) && (48000 <= aSupportedFormat().iMaxRate))
sl@0
  1713
		iDeviceCapabilities.iRate |= EMMFSampleRate48000Hz;
sl@0
  1714
	if ((aSupportedFormat().iMinRate <= 64000) && (64000 <= aSupportedFormat().iMaxRate))
sl@0
  1715
		iDeviceCapabilities.iRate |= EMMFSampleRate64000Hz;
sl@0
  1716
	if ((aSupportedFormat().iMinRate <= 88200) && (88200 <= aSupportedFormat().iMaxRate))
sl@0
  1717
		iDeviceCapabilities.iRate |= EMMFSampleRate88200Hz;
sl@0
  1718
	if ((aSupportedFormat().iMinRate <= 96000) && (96000 <= aSupportedFormat().iMaxRate))
sl@0
  1719
		iDeviceCapabilities.iRate |= EMMFSampleRate96000Hz;
sl@0
  1720
sl@0
  1721
	// Store the encodings supported
sl@0
  1722
	iDeviceCapabilities.iEncoding = 0;
sl@0
  1723
	if (enc & RMdaDevSound::EMdaSoundEncoding16BitPCM)
sl@0
  1724
		iDeviceCapabilities.iEncoding |= EMMFSoundEncoding16BitPCM;
sl@0
  1725
	if (enc & RMdaDevSound::EMdaSoundEncoding8BitALaw)
sl@0
  1726
		iDeviceCapabilities.iEncoding |= EMMFSoundEncoding8BitALaw;
sl@0
  1727
	if (enc & RMdaDevSound::EMdaSoundEncoding8BitMuLaw)
sl@0
  1728
		iDeviceCapabilities.iEncoding |= EMMFSoundEncoding8BitMuLaw;
sl@0
  1729
	if (enc & RMdaDevSound::EMdaSoundEncoding8BitPCM)
sl@0
  1730
		iDeviceCapabilities.iEncoding |= EMMFSoundEncoding8BitPCM;
sl@0
  1731
sl@0
  1732
	// Mono and Stereo support
sl@0
  1733
	if (aSupportedFormat().iChannels == 2)
sl@0
  1734
		iDeviceCapabilities.iChannels = EMMFStereo;
sl@0
  1735
	iDeviceCapabilities.iChannels |= EMMFMono;
sl@0
  1736
sl@0
  1737
	iDeviceCapabilities.iBufferSize = aSupportedFormat().iMaxBufferSize;
sl@0
  1738
	// Default
sl@0
  1739
	iDeviceConfig.iRate = EMMFSampleRate8000Hz;
sl@0
  1740
	iDeviceConfig.iEncoding = EMMFSoundEncoding16BitPCM;
sl@0
  1741
	iDeviceConfig.iChannels = EMMFMono;
sl@0
  1742
sl@0
  1743
	return KErrNone;
sl@0
  1744
	}
sl@0
  1745
sl@0
  1746
/*
sl@0
  1747
 *
sl@0
  1748
 *	Makes request to Policy Server (asynchronous call)
sl@0
  1749
 *
sl@0
  1750
 */
sl@0
  1751
void CMMFDevSoundSvrImp::RequestPolicy()
sl@0
  1752
	{
sl@0
  1753
	iDevSoundEventHandler->CancelReceiveEvents();
sl@0
  1754
	iDevSoundEventHandler->ReceiveEvents();
sl@0
  1755
	iAudioPolicyPrioritySettings.iCapabilities = iParent.CheckClientCapabilities();
sl@0
  1756
	iAudioPolicyProxy->MakeRequest(iAudioPolicyPrioritySettings);
sl@0
  1757
	}
sl@0
  1758
sl@0
  1759
/*
sl@0
  1760
 *
sl@0
  1761
 *	Creates buffer and begin playback using the specified tone generator.
sl@0
  1762
 *
sl@0
  1763
 */
sl@0
  1764
void CMMFDevSoundSvrImp::DoPlayL()
sl@0
  1765
	{
sl@0
  1766
	// Delete any buffer from previous call and try to create maximum buffer 
sl@0
  1767
	// size. Double Buffer the Tone data.
sl@0
  1768
	if (iToneBuffer1)
sl@0
  1769
		{
sl@0
  1770
		delete iToneBuffer1; 
sl@0
  1771
		iToneBuffer1 = NULL; 
sl@0
  1772
		}
sl@0
  1773
	//note the tone buffer needs to be the same as the pcm16->pcm16 'null'
sl@0
  1774
	//hw device plugin
sl@0
  1775
	// Buffer size = (SampleRate * BytesPerSample * Channels) / 4
sl@0
  1776
	TInt useBufferOfSize = ((SamplingFrequency() * 2 * NumberOfChannels())/KDevSoundFramesPerSecond + (KDevSoundDeltaFrameSize-1)) &~ (KDevSoundDeltaFrameSize-1);
sl@0
  1777
	//clamp buffer to desired limits
sl@0
  1778
	if(useBufferOfSize < KDevSoundMinFrameSize) 
sl@0
  1779
		useBufferOfSize = KDevSoundMinFrameSize;
sl@0
  1780
	else if(useBufferOfSize > KDevSoundMaxFrameSize) 
sl@0
  1781
		useBufferOfSize = KDevSoundMaxFrameSize;
sl@0
  1782
sl@0
  1783
	//clamp buffer to limits of hardware
sl@0
  1784
	if(useBufferOfSize < Max(iPlayFormatsSupported().iMinBufferSize, iRecordFormatsSupported().iMinBufferSize))
sl@0
  1785
		useBufferOfSize = Max(iPlayFormatsSupported().iMinBufferSize, iRecordFormatsSupported().iMinBufferSize);
sl@0
  1786
	else if(useBufferOfSize > Min(iPlayFormatsSupported().iMaxBufferSize, iRecordFormatsSupported().iMaxBufferSize))
sl@0
  1787
		useBufferOfSize = Min(iPlayFormatsSupported().iMaxBufferSize, iRecordFormatsSupported().iMaxBufferSize);
sl@0
  1788
sl@0
  1789
	iToneBuffer1 = CMMFDataBuffer::NewL(useBufferOfSize);
sl@0
  1790
	User::LeaveIfError(iCurrentGenerator->FillBuffer(iToneBuffer1->Data()));
sl@0
  1791
sl@0
  1792
	if (iToneBuffer2)
sl@0
  1793
		{
sl@0
  1794
		delete iToneBuffer2; 
sl@0
  1795
		iToneBuffer2 = NULL;
sl@0
  1796
		}
sl@0
  1797
	iToneBuffer2 = CMMFDataBuffer::NewL(useBufferOfSize);
sl@0
  1798
	User::LeaveIfError(iCurrentGenerator->FillBuffer(iToneBuffer2->Data()));
sl@0
  1799
sl@0
  1800
	// Assign active buffer
sl@0
  1801
	iActiveToneBuffer = iToneBuffer1;
sl@0
  1802
sl@0
  1803
	// Hw device hasn't played anything yet so don't change
sl@0
  1804
    // active buffer. This is checked in FillThisHwBuffer.
sl@0
  1805
    iFirstCallFromHwDevice = ETrue;
sl@0
  1806
sl@0
  1807
    // Start HwDevice to play data
sl@0
  1808
    User::LeaveIfError(iCMMFHwDevice->Start(EDevDecode, EDevOutFlow));
sl@0
  1809
	
sl@0
  1810
	}
sl@0
  1811
sl@0
  1812
/*
sl@0
  1813
 *
sl@0
  1814
 *	This method assigns the other buffer as active buffer. The tone audio 
sl@0
  1815
 *	generator should fill data in the other buffer by now.
sl@0
  1816
 *
sl@0
  1817
 */
sl@0
  1818
void CMMFDevSoundSvrImp::SetActiveToneBuffer()
sl@0
  1819
	{
sl@0
  1820
	if (iActiveToneBuffer == iToneBuffer1)
sl@0
  1821
		iActiveToneBuffer = iToneBuffer2;
sl@0
  1822
	else if (iActiveToneBuffer == iToneBuffer2)
sl@0
  1823
		iActiveToneBuffer = iToneBuffer1;
sl@0
  1824
	}
sl@0
  1825
sl@0
  1826
/*
sl@0
  1827
 *
sl@0
  1828
 *	This method fills data into the free buffer.
sl@0
  1829
 *
sl@0
  1830
 *	@return	"TInt"
sl@0
  1831
 *			Error code. KErrNone if success.
sl@0
  1832
 *
sl@0
  1833
 */
sl@0
  1834
TInt CMMFDevSoundSvrImp::FillFreeToneBuffer()
sl@0
  1835
	{
sl@0
  1836
	TInt err(KErrNone);
sl@0
  1837
	if (iActiveToneBuffer == iToneBuffer1)
sl@0
  1838
		err = iCurrentGenerator->FillBuffer(iToneBuffer2->Data());
sl@0
  1839
	else if (iActiveToneBuffer == iToneBuffer2)
sl@0
  1840
		err = iCurrentGenerator->FillBuffer(iToneBuffer1->Data());
sl@0
  1841
	return err;
sl@0
  1842
	}
sl@0
  1843
sl@0
  1844
/*
sl@0
  1845
 *
sl@0
  1846
 *	Updates the policy state based on Audio policy settings of this devsound instance
sl@0
  1847
 *
sl@0
  1848
 */
sl@0
  1849
TInt CMMFDevSoundSvrImp::UpdatePolicyState()
sl@0
  1850
	{
sl@0
  1851
	TInt error = iAudioPolicyProxy->UpdateState(iAudioPolicyPrioritySettings);
sl@0
  1852
	return error;
sl@0
  1853
	}
sl@0
  1854
sl@0
  1855
/*
sl@0
  1856
 *
sl@0
  1857
 *	Initializes audio device node by setting volume, and sampling rate.
sl@0
  1858
 *
sl@0
  1859
 *	@return	"TInt"
sl@0
  1860
 *			Error Code. KErrNone if success.
sl@0
  1861
 *
sl@0
  1862
 */
sl@0
  1863
TInt CMMFDevSoundSvrImp::InitTask()
sl@0
  1864
	{
sl@0
  1865
	// No Implementation
sl@0
  1866
	return KErrNone;
sl@0
  1867
	}
sl@0
  1868
sl@0
  1869
sl@0
  1870
sl@0
  1871
/*
sl@0
  1872
 *
sl@0
  1873
 *	Returns an integer representing Sampling Frequency the device is currently
sl@0
  1874
 *	configured to.
sl@0
  1875
 *
sl@0
  1876
 *	@return	"TInt"
sl@0
  1877
 *			Sampling Frequency.
sl@0
  1878
 *
sl@0
  1879
 */
sl@0
  1880
TInt CMMFDevSoundSvrImp::SamplingFrequency()
sl@0
  1881
	{
sl@0
  1882
	if(iDeviceConfig.iRate == EMMFSampleRate8000Hz)
sl@0
  1883
		return 8000;
sl@0
  1884
	else if(iDeviceConfig.iRate == EMMFSampleRate11025Hz)
sl@0
  1885
		return 11025;
sl@0
  1886
	else if(iDeviceConfig.iRate == EMMFSampleRate12000Hz)
sl@0
  1887
		return 12000;
sl@0
  1888
	else if(iDeviceConfig.iRate == EMMFSampleRate16000Hz)
sl@0
  1889
		return 16000;
sl@0
  1890
	else if(iDeviceConfig.iRate == EMMFSampleRate22050Hz)
sl@0
  1891
		return 22050;
sl@0
  1892
	else if(iDeviceConfig.iRate == EMMFSampleRate24000Hz)
sl@0
  1893
		return 24000;
sl@0
  1894
	else if(iDeviceConfig.iRate == EMMFSampleRate32000Hz)
sl@0
  1895
		return 32000;
sl@0
  1896
	else if(iDeviceConfig.iRate == EMMFSampleRate44100Hz)
sl@0
  1897
		return 44100;
sl@0
  1898
	else if(iDeviceConfig.iRate == EMMFSampleRate48000Hz)
sl@0
  1899
		return 48000;
sl@0
  1900
	else if(iDeviceConfig.iRate == EMMFSampleRate88200Hz)
sl@0
  1901
		return 88200;
sl@0
  1902
	else if(iDeviceConfig.iRate == EMMFSampleRate96000Hz)
sl@0
  1903
		return 96000;
sl@0
  1904
	else
sl@0
  1905
		return 8000; //default
sl@0
  1906
	}
sl@0
  1907
 
sl@0
  1908
/*
sl@0
  1909
 *
sl@0
  1910
 *	Returns an integer representing number of channels the device is currently
sl@0
  1911
 *	configured to.
sl@0
  1912
 *
sl@0
  1913
 *	@return	"TInt"
sl@0
  1914
 *			Number of audio channels 1 if mono, 2 if stereo.
sl@0
  1915
 *
sl@0
  1916
 */
sl@0
  1917
TInt CMMFDevSoundSvrImp::NumberOfChannels()
sl@0
  1918
	{
sl@0
  1919
	if(iDeviceConfig.iChannels == EMMFMono)
sl@0
  1920
		return 1;
sl@0
  1921
	else
sl@0
  1922
		return 2;
sl@0
  1923
	}
sl@0
  1924
sl@0
  1925
/*
sl@0
  1926
 *
sl@0
  1927
 *	Returns an integer representing number of bytes in each audio sample
sl@0
  1928
 *	
sl@0
  1929
 *
sl@0
  1930
 *	@return	"TInt"
sl@0
  1931
 *			Number of of bytes in each audio sample.
sl@0
  1932
 *
sl@0
  1933
 */
sl@0
  1934
TInt CMMFDevSoundSvrImp::BytesPerAudioSample()
sl@0
  1935
	{
sl@0
  1936
	TInt bytes=1;
sl@0
  1937
	switch (iDeviceConfig.iEncoding)
sl@0
  1938
		{
sl@0
  1939
		case EMMFSoundEncoding8BitPCM:
sl@0
  1940
		case EMMFSoundEncoding8BitALaw:
sl@0
  1941
		case EMMFSoundEncoding8BitMuLaw:
sl@0
  1942
			{
sl@0
  1943
			bytes=1;
sl@0
  1944
			}
sl@0
  1945
		break;
sl@0
  1946
		case EMMFSoundEncoding16BitPCM:
sl@0
  1947
			{
sl@0
  1948
			bytes=2;
sl@0
  1949
			}
sl@0
  1950
		break;
sl@0
  1951
		}
sl@0
  1952
	return bytes;
sl@0
  1953
	}
sl@0
  1954
sl@0
  1955
sl@0
  1956
/********************************************************************************
sl@0
  1957
 *				Private functions ends here										*
sl@0
  1958
 ********************************************************************************/