os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/UseOldCodecAudioController/TestUseOldCodecAudioController.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) 2003-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
sl@0
    17
#include <mmf/server/mmfformat.h>
sl@0
    18
#include <mmf/server/mmfclip.h>
sl@0
    19
#include <mdaaudiosampleeditor.h>
sl@0
    20
#include <mmf/plugin/mmfcontrollerimplementationuids.hrh>
sl@0
    21
#include <mmf/common/mmffourcc.h>
sl@0
    22
#include <mmf/common/mmfpaniccodes.h>
sl@0
    23
#include "TestUseOldCodecAudioController.h"
sl@0
    24
sl@0
    25
const TUint KSampleRate8000Hz = 8000;
sl@0
    26
const TUint KSampleRate11025Hz = 11025;
sl@0
    27
const TUint KSampleRate16000Hz = 16000;
sl@0
    28
const TUint KSampleRate22050Hz = 22050;
sl@0
    29
const TUint KSampleRate32000Hz = 32000;
sl@0
    30
const TUint KSampleRate44100Hz = 44100;
sl@0
    31
const TUint KSampleRate48000Hz = 48000;
sl@0
    32
const TUint KSampleRate88200Hz = 88200;
sl@0
    33
const TUint KSampleRate96000Hz = 96000;
sl@0
    34
const TUint KNumChannelsMono = 1;
sl@0
    35
const TUint KNumChannelsStereo = 2;
sl@0
    36
sl@0
    37
/*
sl@0
    38
 TMmfAudioControllerPanics is an enumeration with the following entries:
sl@0
    39
 EBadArgument indicates a bad argument
sl@0
    40
 EBadState indicates a state viaolation
sl@0
    41
 EBadInvariant indicates an invariant violation
sl@0
    42
 EBadReset indicates failed reset
sl@0
    43
 EPostConditionViolation indicates a post condition violation
sl@0
    44
*/
sl@0
    45
enum TMmfAudioControllerPanics
sl@0
    46
	{
sl@0
    47
	EBadArgument,
sl@0
    48
	EBadState,
sl@0
    49
	EBadInvariant,
sl@0
    50
	EBadReset,
sl@0
    51
	EPostConditionViolation
sl@0
    52
	};
sl@0
    53
sl@0
    54
/**
sl@0
    55
* Panic
sl@0
    56
* This method generates a panic
sl@0
    57
* @param "TInt"
sl@0
    58
* @xxxx
sl@0
    59
*/
sl@0
    60
void Panic(TInt aPanicCode)
sl@0
    61
	{
sl@0
    62
	_LIT(KMMFAudioControllerPanicCategory, "MMFAudioController");
sl@0
    63
	User::Panic(KMMFAudioControllerPanicCategory, aPanicCode);
sl@0
    64
	}
sl@0
    65
sl@0
    66
/**
sl@0
    67
 * Static NewL
sl@0
    68
 *
sl@0
    69
 * @return CMMFTestUseOldCodecAudioController*
sl@0
    70
 */
sl@0
    71
CMMFController* CMMFTestUseOldCodecAudioController::NewL()
sl@0
    72
	{
sl@0
    73
	CMMFTestUseOldCodecAudioController* self = new(ELeave) CMMFTestUseOldCodecAudioController;
sl@0
    74
	CleanupStack::PushL(self);
sl@0
    75
	self->ConstructL();
sl@0
    76
	CleanupStack::Pop( self );
sl@0
    77
	return STATIC_CAST( CMMFController*, self );
sl@0
    78
	}
sl@0
    79
sl@0
    80
/**
sl@0
    81
* ConstructL 
sl@0
    82
* 
sl@0
    83
* @xxxx
sl@0
    84
*/
sl@0
    85
void CMMFTestUseOldCodecAudioController::ConstructL()
sl@0
    86
	{
sl@0
    87
	iDataSource         = NULL;
sl@0
    88
	iDataSink           = NULL;
sl@0
    89
	iDataPath           = CMMFDataPath::NewL(iMediaId, *this);
sl@0
    90
	iSourceFormat       = NULL;
sl@0
    91
	iSinkFormat         = NULL;
sl@0
    92
	iSourceAndSinkAdded = EFalse;
sl@0
    93
	iStoppingRecording  = EFalse;
sl@0
    94
sl@0
    95
sl@0
    96
	//iMediaId has already been set up 
sl@0
    97
	SetState( EStopped );
sl@0
    98
	//iPrioritySettings  not initialised because they are held by the controller framework
sl@0
    99
sl@0
   100
	// Construct custom command parsers
sl@0
   101
	CMMFAudioPlayDeviceCustomCommandParser* audPlayDevParser = CMMFAudioPlayDeviceCustomCommandParser::NewL(*this);
sl@0
   102
	CleanupStack::PushL(audPlayDevParser);
sl@0
   103
	AddCustomCommandParserL(*audPlayDevParser);
sl@0
   104
	CleanupStack::Pop( audPlayDevParser );//audPlayDevParser
sl@0
   105
sl@0
   106
	CMMFAudioRecordDeviceCustomCommandParser* audRecDevParser = CMMFAudioRecordDeviceCustomCommandParser::NewL(*this);
sl@0
   107
	CleanupStack::PushL(audRecDevParser);
sl@0
   108
	AddCustomCommandParserL(*audRecDevParser);
sl@0
   109
	CleanupStack::Pop(audRecDevParser);//audRecDevParser
sl@0
   110
sl@0
   111
	CMMFAudioPlayControllerCustomCommandParser* audPlayConParser = CMMFAudioPlayControllerCustomCommandParser::NewL(*this);
sl@0
   112
	CleanupStack::PushL(audPlayConParser);
sl@0
   113
	AddCustomCommandParserL(*audPlayConParser);
sl@0
   114
	CleanupStack::Pop(audPlayConParser);//audPlayConParser
sl@0
   115
sl@0
   116
	CMMFAudioRecordControllerCustomCommandParser* audRecConParser = CMMFAudioRecordControllerCustomCommandParser::NewL(*this);
sl@0
   117
	CleanupStack::PushL(audRecConParser);
sl@0
   118
	AddCustomCommandParserL(*audRecConParser);
sl@0
   119
	CleanupStack::Pop(audRecConParser);//audRecParser
sl@0
   120
sl@0
   121
	CMMFAudioControllerCustomCommandParser* audConParser = CMMFAudioControllerCustomCommandParser::NewL(*this);
sl@0
   122
	CleanupStack::PushL(audConParser);
sl@0
   123
	AddCustomCommandParserL(*audConParser);
sl@0
   124
	CleanupStack::Pop(audConParser);//audConParser
sl@0
   125
	
sl@0
   126
	iWaitForAsyncService = new (ELeave) CActiveSchedulerWait;
sl@0
   127
sl@0
   128
	// [ assert the invariant now that we are constructed ]
sl@0
   129
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
   130
	}
sl@0
   131
sl@0
   132
/**
sl@0
   133
*
sl@0
   134
* CMMFTestUseOldCodecAudioController
sl@0
   135
*
sl@0
   136
*/
sl@0
   137
sl@0
   138
CMMFTestUseOldCodecAudioController::CMMFTestUseOldCodecAudioController() : iMediaId(KUidMediaTypeAudio), iState(EStopped)
sl@0
   139
	{
sl@0
   140
	}
sl@0
   141
sl@0
   142
/**
sl@0
   143
*
sl@0
   144
* ~CMMFTestUseOldCodecAudioController
sl@0
   145
*
sl@0
   146
*/
sl@0
   147
sl@0
   148
CMMFTestUseOldCodecAudioController::~CMMFTestUseOldCodecAudioController()
sl@0
   149
	{
sl@0
   150
	// [ ensure we have logged off the thread ]
sl@0
   151
	if( iDataPath ) 	
sl@0
   152
		{
sl@0
   153
		iDataPath->ResetL();	// this does not leave
sl@0
   154
		}
sl@0
   155
	delete iDataPath;
sl@0
   156
	delete iSourceFormat;
sl@0
   157
	delete iSinkFormat;
sl@0
   158
	delete iStoppingMessage;
sl@0
   159
	delete iWaitForAsyncService;
sl@0
   160
	}
sl@0
   161
sl@0
   162
/**
sl@0
   163
 *  AddDataSourceL
sl@0
   164
 *
sl@0
   165
 *	Adds a data source to the controller
sl@0
   166
 *
sl@0
   167
 *	@param aSource
sl@0
   168
 * Preconditions:
sl@0
   169
 * We are stopped
sl@0
   170
 * Source does not already exist
sl@0
   171
 * Postconditions:
sl@0
   172
 * iDataSource != NULL
sl@0
   173
 * iDataSourceAdded == ETrue
sl@0
   174
 */
sl@0
   175
void CMMFTestUseOldCodecAudioController::AddDataSourceL(MDataSource& aSource)
sl@0
   176
	{
sl@0
   177
	//[ assert the invariant ]
sl@0
   178
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
   179
sl@0
   180
	// [ precondition that the controller is stopped ]
sl@0
   181
    if( State() != EStopped )
sl@0
   182
		User::Leave( KErrNotReady );
sl@0
   183
	
sl@0
   184
	//[ precondition iData source is not already configured ]
sl@0
   185
	if (iDataSource)
sl@0
   186
		User::Leave(KErrAlreadyExists);
sl@0
   187
sl@0
   188
	// Note that this code is not generic for sources
sl@0
   189
	// It it only checks for file, des clips and audio inputs
sl@0
   190
	// If a new source type eg a Url Clip then this needs to be added to the supported source Uids
sl@0
   191
	if ( SourceFormatRequired( aSource) ) 
sl@0
   192
		{
sl@0
   193
		// Get the format from the Source if possible from no specific supplier
sl@0
   194
		TRAPD(err, iSourceFormat = CMMFFormatDecode::NewL(&aSource, KNullDesC));
sl@0
   195
		//[ we want to complete silently for KErrNotSupported
sl@0
   196
		// because there is a possibility that the client
sl@0
   197
		// wants to add the data format later, see audio api for
sl@0
   198
		// a description of this feature]
sl@0
   199
		if ((err != KErrNotSupported) && (err != KErrNone))
sl@0
   200
			{
sl@0
   201
			User::Leave(err);
sl@0
   202
			}
sl@0
   203
		}
sl@0
   204
	else if (aSource.DataSourceType()==KUidMmfAudioInput)
sl@0
   205
		{
sl@0
   206
		//[ ensure that the audio input has a pointer to dev sound ]
sl@0
   207
		CMMFAudioInput* audioInput = STATIC_CAST(CMMFAudioInput*, &aSource);
sl@0
   208
		__ASSERT_ALWAYS( audioInput, Panic(EBadInvariant));
sl@0
   209
		// [ lets load dev sound ]
sl@0
   210
		User::LeaveIfError(audioInput->SourceThreadLogon( *this ));
sl@0
   211
		}
sl@0
   212
	else
sl@0
   213
		{
sl@0
   214
		User::Leave(KErrNotSupported);
sl@0
   215
		}
sl@0
   216
sl@0
   217
	//[ its now safe to set the source ]
sl@0
   218
	iDataSource = &aSource ;
sl@0
   219
	iDataSource->SetSourcePrioritySettings(iPrioritySettings);
sl@0
   220
sl@0
   221
	//[ assert the post condition ]
sl@0
   222
	__ASSERT_ALWAYS(iDataSource, Panic(EMMFAudioControllerPanicDataSourceDoesNotExist));
sl@0
   223
sl@0
   224
	}
sl@0
   225
sl@0
   226
sl@0
   227
/**
sl@0
   228
 *  AddDataSinkL
sl@0
   229
 *
sl@0
   230
 *	Adds a data sink to the controller
sl@0
   231
 *
sl@0
   232
 *	@param aSink
sl@0
   233
 *
sl@0
   234
 */
sl@0
   235
void CMMFTestUseOldCodecAudioController::AddDataSinkL(MDataSink& aSink)
sl@0
   236
	{
sl@0
   237
	//[ assert the invariant ]
sl@0
   238
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
   239
sl@0
   240
	// [ precondition that the controller is stopped ]
sl@0
   241
    if( State() != EStopped )
sl@0
   242
		User::Leave( KErrNotReady );
sl@0
   243
sl@0
   244
	// [ assert precondition that sink does not exist ]
sl@0
   245
	if (iDataSink)
sl@0
   246
		User::Leave(KErrAlreadyExists);
sl@0
   247
sl@0
   248
sl@0
   249
	// Note that this code is not generic for sinks
sl@0
   250
	// It it only checks for file,des clips and audio outputs
sl@0
   251
	// If a new sink type eg a Url Clip then this needs to be added to the supported source Uids
sl@0
   252
	if ( SinkFormatRequired( aSink ) )
sl@0
   253
		{//the sink is a clip
sl@0
   254
sl@0
   255
		// Get the format from the Sink if possible from no specific supplier
sl@0
   256
		TRAPD(err, iSinkFormat = CMMFFormatEncode::NewL(&aSink, KNullDesC));
sl@0
   257
		//[ we want to complete silently for KErrNotSupported
sl@0
   258
		// because there is a possibility that the client
sl@0
   259
		// wants to add the data format later, see audio api for
sl@0
   260
		// a description of this feature]
sl@0
   261
		if ((err != KErrNotSupported) && (err != KErrNone))
sl@0
   262
			{
sl@0
   263
			User::Leave(err);
sl@0
   264
			}
sl@0
   265
		}
sl@0
   266
	else if (aSink.DataSinkType()==KUidMmfAudioOutput)
sl@0
   267
		{
sl@0
   268
sl@0
   269
		//[ ensure that the audio output has a pointer to dev sound ]
sl@0
   270
		CMMFAudioOutput* audioOutput = STATIC_CAST(CMMFAudioOutput*, &aSink);
sl@0
   271
		__ASSERT_ALWAYS( audioOutput, Panic(EBadInvariant));
sl@0
   272
		// [ lets load dev sound ]
sl@0
   273
		User::LeaveIfError(audioOutput->SinkThreadLogon( *this ));
sl@0
   274
		}
sl@0
   275
	else
sl@0
   276
		{
sl@0
   277
		User::Leave(KErrNotSupported);
sl@0
   278
		}
sl@0
   279
sl@0
   280
	//[ now that we are sure we have not left we can update the sink
sl@0
   281
	// transactionally ]
sl@0
   282
	iDataSink = &aSink;
sl@0
   283
	iDataSink->SetSinkPrioritySettings(iPrioritySettings);
sl@0
   284
sl@0
   285
	// [ assert post conditions that a sink has been added ]
sl@0
   286
	__ASSERT_ALWAYS(iDataSink, Panic(EMMFAudioControllerPanicDataSinkDoesNotExist));
sl@0
   287
sl@0
   288
	}
sl@0
   289
sl@0
   290
/**
sl@0
   291
 *  PrimeL
sl@0
   292
 *
sl@0
   293
 *  If Prime fails the client should reset the controller
sl@0
   294
 *  because as noted below this code is not transactional.
sl@0
   295
 *
sl@0
   296
 */
sl@0
   297
void CMMFTestUseOldCodecAudioController::PrimeL()
sl@0
   298
	{
sl@0
   299
	//[ assert the invariant ]
sl@0
   300
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
   301
sl@0
   302
	//[ assert the precondition ( in a friendly way for this api 
sl@0
   303
	// that we are either stopped or primed already ]
sl@0
   304
	if(!(( State() == EStopped ) || (State() == EPrimed )))
sl@0
   305
		User::Leave( KErrNotReady );
sl@0
   306
sl@0
   307
	// [ precondition we have a data source & sink ]
sl@0
   308
	__ASSERT_ALWAYS( iDataSource, Panic( EBadInvariant));
sl@0
   309
	__ASSERT_ALWAYS( iDataSink, Panic( EBadInvariant));
sl@0
   310
sl@0
   311
sl@0
   312
	//[ precondition that we need a source format ]
sl@0
   313
	if ( SourceFormatRequired(*iDataSource) && !(iSourceFormat))
sl@0
   314
		User::Leave( KErrNotSupported );
sl@0
   315
sl@0
   316
	// [ check the precondition if we need a data sink format ]
sl@0
   317
	if ( SinkFormatRequired(*iDataSink) && !( iSinkFormat ))
sl@0
   318
		User::Leave( KErrNotSupported );
sl@0
   319
sl@0
   320
sl@0
   321
	// [ ideally this code should be transaction based and
sl@0
   322
	//   if failure occurs we roll back to the previous state
sl@0
   323
	// in the code below this is not the case and the controller
sl@0
   324
	// can be left in an unstable state should any part of prime fail]
sl@0
   325
	if (iState == EStopped)
sl@0
   326
		{ //datapath propagates prime to sink & source
sl@0
   327
		
sl@0
   328
		TFourCC sinkFormatDataType;
sl@0
   329
		if ((iSinkFormat)&&(iDataSource))
sl@0
   330
			{//audio input so recording
sl@0
   331
			//need to assign the sink format 4CC to pcm16
sl@0
   332
			//even though it isn't pcm16 , this will cause the audio input
sl@0
   333
			//in negotiation to instantiate the null CMMFHwDevice plugin
sl@0
   334
			//after the negotiation set it back to the correct datatype
sl@0
   335
			//forcing the datapath to use a CMMFCodec
sl@0
   336
			sinkFormatDataType = iSinkFormat->SinkDataTypeCode(KUidMediaTypeAudio); //reset this after negotiation
sl@0
   337
			iSinkFormat->SetSinkDataTypeCode(KMMFFourCCCodePCM16, KUidMediaTypeAudio);
sl@0
   338
			}
sl@0
   339
sl@0
   340
		NegotiateL();
sl@0
   341
sl@0
   342
		if (!iSourceAndSinkAdded)
sl@0
   343
			{
sl@0
   344
			//add data source and sinks to datapath - Note cant do this in AddDataSource/Sink
sl@0
   345
			//because the sources and sinks aren't configured at this point
sl@0
   346
			if (iSourceFormat)
sl@0
   347
				iDataPath->AddDataSourceL(iSourceFormat);
sl@0
   348
			else if (iDataSource)
sl@0
   349
				{//record
sl@0
   350
				iDataPath->AddDataSourceL(iDataSource);
sl@0
   351
				if (iSinkFormat) //restore the format data type
sl@0
   352
					{	//this will force datapth to use CMMFCodec
sl@0
   353
					iSinkFormat->SetSinkDataTypeCode(sinkFormatDataType,KUidMediaTypeAudio);
sl@0
   354
					}
sl@0
   355
				}
sl@0
   356
			if (iSinkFormat)
sl@0
   357
				iDataPath->AddDataSinkL(iSinkFormat);
sl@0
   358
			else if (iDataSink)
sl@0
   359
				{//play
sl@0
   360
				//need to set the audio output fourCC code to pcm16
sl@0
   361
				//in order to force the data path to use a CMMFCodec
sl@0
   362
				CMMFAudioOutput* ao = static_cast<CMMFAudioOutput*>(iDataSink);
sl@0
   363
				CMMFDevSound* devSound = &(ao->SoundDevice());
sl@0
   364
sl@0
   365
				//PrimeL() needs to run synchronously but DevSound initialisation is 
sl@0
   366
				//asynchronous.  iWaitForAsyncService halts execution until 
sl@0
   367
				//iDevSoundEventHandler informs us this process has completed.
sl@0
   368
				iDevSoundEventHandler.SetInterceptedDevSoundObserver(ao);
sl@0
   369
				iDevSoundEventHandler.SetEventObserver(this);
sl@0
   370
				//need to reinitialize the devsound to load up a null pcm16->16
sl@0
   371
				//hw device - note this will delete the previous
sl@0
   372
				//non pcm16 hw device
sl@0
   373
				//note can't set this on the audio output as this won't update
sl@0
   374
				//the hw device
sl@0
   375
				devSound->InitializeL(iDevSoundEventHandler,KMMFFourCCCodePCM16,EMMFStatePlaying);
sl@0
   376
				iWaitForAsyncService->Start();
sl@0
   377
sl@0
   378
				//now tell audio output were pcm16
sl@0
   379
				iDataSink->SetSinkDataTypeCode(KMMFFourCCCodePCM16, KUidMediaTypeAudio);
sl@0
   380
				iDataPath->AddDataSinkL(iDataSink);
sl@0
   381
				}
sl@0
   382
			iSourceAndSinkAdded = ETrue ;
sl@0
   383
			}
sl@0
   384
		
sl@0
   385
		iDataPath->PrimeL();
sl@0
   386
		if ((iSinkFormat) && (!iSourceFormat))
sl@0
   387
			{//we are recording to a clip so the data path position is the sink
sl@0
   388
			//need to set datapath position to end of format pos (incase sink clip already exists
sl@0
   389
			TTimeIntervalMicroSeconds duration = iSinkFormat->Duration(iMediaId);
sl@0
   390
			if (duration != TTimeIntervalMicroSeconds(0))
sl@0
   391
				{//the file already exists and has a duration so set data path position to the end of the file
sl@0
   392
				iDataPath->SetPositionL(duration);
sl@0
   393
				}
sl@0
   394
			}
sl@0
   395
		//[ it is now safe to make the transition to primed ]
sl@0
   396
		SetState( EPrimed );		
sl@0
   397
		}
sl@0
   398
	else if (State() == EPrimed)
sl@0
   399
		{ //controller is already primed so just pass prime onto DP
sl@0
   400
		iDataPath->PrimeL();
sl@0
   401
		}
sl@0
   402
	
sl@0
   403
	//[ assert the post condition that we are in the state primed]
sl@0
   404
	__ASSERT_ALWAYS( SetState( EPrimed ), Panic( EPostConditionViolation ));
sl@0
   405
	// [ assert the invariant]
sl@0
   406
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant ) );
sl@0
   407
	}
sl@0
   408
sl@0
   409
/**
sl@0
   410
 *  ResetL
sl@0
   411
 *  This method resets the controller
sl@0
   412
 *
sl@0
   413
 */
sl@0
   414
void CMMFTestUseOldCodecAudioController::ResetL()
sl@0
   415
	{
sl@0
   416
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant ) );
sl@0
   417
sl@0
   418
	// Stop recording if it's not stopped,
sl@0
   419
	if (State() != EStopped)
sl@0
   420
		{
sl@0
   421
		iDataPath->Stop();
sl@0
   422
		SetState(EStopped);
sl@0
   423
		}
sl@0
   424
sl@0
   425
	// Remove references to source and sink
sl@0
   426
	iDataPath->ResetL();
sl@0
   427
sl@0
   428
	delete iSourceFormat; iSourceFormat = NULL  ;
sl@0
   429
	delete iSinkFormat;	iSinkFormat = NULL  ;
sl@0
   430
sl@0
   431
	//[ ensure loggoff of source and sink ]
sl@0
   432
	iDataSource = NULL ;
sl@0
   433
	iDataSink = NULL ;
sl@0
   434
	iSourceAndSinkAdded = EFalse;
sl@0
   435
sl@0
   436
	// [ assert the invariant]
sl@0
   437
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant ) );
sl@0
   438
sl@0
   439
	// [ assert the post condition
sl@0
   440
	//   state == stopped
sl@0
   441
	//   iDataSource is NULL
sl@0
   442
	//   iSourceFormat is NULL
sl@0
   443
	//   iSinkFormat is NULL ]
sl@0
   444
	__ASSERT_ALWAYS( ResetPostCondition(), Panic( EBadReset ));
sl@0
   445
	__ASSERT_ALWAYS( Invariant(), Panic(EBadState));
sl@0
   446
	}
sl@0
   447
sl@0
   448
/**
sl@0
   449
* ResetPostCondition
sl@0
   450
* This function determnines if the reset post condition is valid
sl@0
   451
* @xxxx
sl@0
   452
*/
sl@0
   453
TBool CMMFTestUseOldCodecAudioController::ResetPostCondition() const
sl@0
   454
	{
sl@0
   455
sl@0
   456
     TBool result = EFalse ;
sl@0
   457
	if((iSourceFormat     == NULL)  &&
sl@0
   458
	(iDataSink            == NULL)  &&
sl@0
   459
	(iDataSource          == NULL)  && 
sl@0
   460
	(iSinkFormat          == NULL)  &&
sl@0
   461
	(State() == EStopped))
sl@0
   462
		{
sl@0
   463
         result = ETrue;
sl@0
   464
		}
sl@0
   465
sl@0
   466
    return result;
sl@0
   467
	}
sl@0
   468
sl@0
   469
sl@0
   470
/**
sl@0
   471
 *
sl@0
   472
 * PlayL
sl@0
   473
 *
sl@0
   474
 */
sl@0
   475
void CMMFTestUseOldCodecAudioController::PlayL()
sl@0
   476
	{
sl@0
   477
	// [ assert the precondition that the
sl@0
   478
	//   play command is only activated in the primed state]
sl@0
   479
	if ( State() != EPrimed)
sl@0
   480
		User::Leave(KErrNotReady);
sl@0
   481
sl@0
   482
	// [ assert the Invariant ]
sl@0
   483
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   484
sl@0
   485
	//[datapath propogates play to sink & source]
sl@0
   486
	iDataPath->PlayL();
sl@0
   487
	SetState( EPlaying );
sl@0
   488
	
sl@0
   489
	//[ assert the post condition we are playing ]
sl@0
   490
	//No - this assumption is not always true if an error occurs eg OOM
sl@0
   491
	//the state could be EStopped
sl@0
   492
	//	__ASSERT_ALWAYS( (State() == EPlaying ), Panic( EBadState));
sl@0
   493
	//[ assert the invariant ]
sl@0
   494
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   495
	}
sl@0
   496
sl@0
   497
/**
sl@0
   498
 *  PauseL
sl@0
   499
 *
sl@0
   500
 */
sl@0
   501
void CMMFTestUseOldCodecAudioController::PauseL()
sl@0
   502
	{
sl@0
   503
	// [ assert the invariant ]
sl@0
   504
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   505
	
sl@0
   506
	//[ assert the precondition that we are playing ]
sl@0
   507
	if ( State() != EPlaying)
sl@0
   508
		User::Leave(KErrNotReady);
sl@0
   509
	
sl@0
   510
	//[ datapath propogates pause to sink & source ]
sl@0
   511
	iDataPath->Pause();
sl@0
   512
	SetState(EPrimed);
sl@0
   513
sl@0
   514
	//[ assert the post condition we are primed ]
sl@0
   515
	__ASSERT_ALWAYS( (State() == EPrimed ), Panic( EBadState));
sl@0
   516
	//[ assert the invariant ]
sl@0
   517
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   518
	}
sl@0
   519
sl@0
   520
/**
sl@0
   521
 *  StopL
sl@0
   522
 *
sl@0
   523
 */
sl@0
   524
void CMMFTestUseOldCodecAudioController::StopL(TMMFMessage& aMessage)
sl@0
   525
	{
sl@0
   526
	//[ assert the invariant ]
sl@0
   527
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   528
	// [ precondition that we are not already stopped 
sl@0
   529
	// && if we are stopped do nothing.
sl@0
   530
	//If we are stopping a recording, we need to give the datapath chance to 
sl@0
   531
	//process that data which has already been captured. We therefore stay in the EPlaying
sl@0
   532
	//state, but use iStoppingRecording to indicate that we are stopping.
sl@0
   533
sl@0
   534
	if ((State() != EStopped) && !iStoppingRecording)
sl@0
   535
		{
sl@0
   536
		if((State() == EPlaying) && (iDataSource->DataSourceType()==KUidMmfAudioInput)) //we are recording
sl@0
   537
			{
sl@0
   538
			// datapath is requested to stop recording but process any alreay captured buffers,
sl@0
   539
			// the pause method is used for this purpose and as such, the data path must 
sl@0
   540
			// determine that it is recording to be able to act accordingly.
sl@0
   541
			// aMessgae is not completed until datapath advises that it has completed.
sl@0
   542
			iDataPath->Pause();
sl@0
   543
			iStoppingMessage = CMMFMessageHolder::NewL(aMessage);
sl@0
   544
			iStoppingRecording = ETrue;
sl@0
   545
			}
sl@0
   546
		else
sl@0
   547
			{
sl@0
   548
			//  datapath propogates stop to sink & source
sl@0
   549
			iDataPath->Stop();
sl@0
   550
			SetState(EStopped);
sl@0
   551
			}
sl@0
   552
		}
sl@0
   553
sl@0
   554
	//complete message as request is complete.
sl@0
   555
	if(State() == EStopped && !IsUnderTest())
sl@0
   556
		{
sl@0
   557
		aMessage.Complete(KErrNone);
sl@0
   558
		}
sl@0
   559
sl@0
   560
	//[ assert the invariant ]
sl@0
   561
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   562
	}
sl@0
   563
sl@0
   564
/**
sl@0
   565
 *  PositionL
sl@0
   566
 * Preconditions:
sl@0
   567
 * The Controller is in the state EPrimed
sl@0
   568
 * @return TTimeIntervalMicroSeconds
sl@0
   569
 *
sl@0
   570
 */
sl@0
   571
TTimeIntervalMicroSeconds CMMFTestUseOldCodecAudioController::PositionL() const
sl@0
   572
	{
sl@0
   573
	//[ assert the invariant ]
sl@0
   574
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   575
	// [ precondition that we are playing or primed ]
sl@0
   576
	if( !((State() == EPrimed) || (State() == EPlaying)))
sl@0
   577
			User::Leave(KErrNotReady);
sl@0
   578
sl@0
   579
    TTimeIntervalMicroSeconds position = iDataPath->Position();
sl@0
   580
	
sl@0
   581
	//[ assert the invariant ]
sl@0
   582
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   583
	
sl@0
   584
	return position;
sl@0
   585
	}
sl@0
   586
sl@0
   587
/**
sl@0
   588
* SetPositionL
sl@0
   589
*
sl@0
   590
* @param aPosition
sl@0
   591
*
sl@0
   592
*/
sl@0
   593
void CMMFTestUseOldCodecAudioController::SetPositionL(const TTimeIntervalMicroSeconds& aPosition)
sl@0
   594
	{
sl@0
   595
	//[ assert the invariant ]
sl@0
   596
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   597
	
sl@0
   598
	// [ precondition that we are not already stopped ]
sl@0
   599
	if (iState == EStopped)
sl@0
   600
		User::Leave(KErrNotReady);
sl@0
   601
sl@0
   602
	//[ precondition that the position is >= 0 && <= Duration ]
sl@0
   603
		{
sl@0
   604
		TTimeIntervalMicroSeconds theDuration(0);
sl@0
   605
		if (iSourceFormat)
sl@0
   606
			{ //if the source is a clip then the duration always refers to the source - even if the sink is a clip
sl@0
   607
			theDuration = iSourceFormat->Duration(iMediaId);
sl@0
   608
			}
sl@0
   609
		else if (iSinkFormat)
sl@0
   610
			{ //duration of recorded clip
sl@0
   611
			theDuration = iSinkFormat->Duration(iMediaId);
sl@0
   612
			}
sl@0
   613
		TTimeIntervalMicroSeconds theStart(0);
sl@0
   614
		if( ( aPosition < theStart) || ( aPosition > theDuration) )
sl@0
   615
			//[ invalid position before start and after end]
sl@0
   616
			User::Leave(KErrArgument); 
sl@0
   617
		}
sl@0
   618
sl@0
   619
	//[ set the position on the data path ]
sl@0
   620
	iDataPath->SetPositionL(aPosition);
sl@0
   621
	
sl@0
   622
	//[ assert the invariant ]
sl@0
   623
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   624
sl@0
   625
    // [ post condition not checked ]
sl@0
   626
	//[ we do not compare the set position with get postion
sl@0
   627
    //  because the interface to do so is poor ]
sl@0
   628
	}
sl@0
   629
sl@0
   630
/**
sl@0
   631
*
sl@0
   632
* DurationL
sl@0
   633
*
sl@0
   634
* @returns TTimeIntervalMicroSeconds 
sl@0
   635
*
sl@0
   636
*/
sl@0
   637
TTimeIntervalMicroSeconds CMMFTestUseOldCodecAudioController::DurationL() const
sl@0
   638
	{
sl@0
   639
	//[ assert the invariant ]
sl@0
   640
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   641
sl@0
   642
sl@0
   643
	// [ assert we have a format that supports duration ]
sl@0
   644
	if( !( iSourceFormat || iSinkFormat ) )
sl@0
   645
		User::Leave(KErrNotSupported);
sl@0
   646
	
sl@0
   647
	//[ now do the real work of getting the duration ]
sl@0
   648
	// ------------------------------------------------
sl@0
   649
	TTimeIntervalMicroSeconds theDuration(0);
sl@0
   650
	if (iSourceFormat)
sl@0
   651
		{ //if the source is a clip then the duration always refers to the source - even if the sink is a clip
sl@0
   652
		theDuration = iSourceFormat->Duration(iMediaId);
sl@0
   653
		}
sl@0
   654
	else if (iSinkFormat)
sl@0
   655
		{ //duration of recorded clip
sl@0
   656
		theDuration = iSinkFormat->Duration(iMediaId);
sl@0
   657
		}
sl@0
   658
sl@0
   659
	//[ assert the invariant ]
sl@0
   660
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   661
sl@0
   662
	return theDuration; 
sl@0
   663
	}
sl@0
   664
sl@0
   665
/**
sl@0
   666
*
sl@0
   667
* GetNumberOfMetaDataEntriesL
sl@0
   668
*
sl@0
   669
* @param "TInt"
sl@0
   670
*
sl@0
   671
*/
sl@0
   672
void CMMFTestUseOldCodecAudioController::GetNumberOfMetaDataEntriesL(TInt& aNumberOfEntries )
sl@0
   673
	{
sl@0
   674
sl@0
   675
	//[ assert the invariant ]
sl@0
   676
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   677
sl@0
   678
	//[ precondition that we are in the primed state or stopped ]
sl@0
   679
	if( !((State() == EPrimed) || ( State() == EStopped)))
sl@0
   680
		User::Leave(KErrNotReady);
sl@0
   681
sl@0
   682
    // [ precondition there is a sink format ]
sl@0
   683
	if (!iDataSink)
sl@0
   684
		User::Leave(KErrNotSupported);
sl@0
   685
sl@0
   686
	// [ precondition the sink format is an encode format ]
sl@0
   687
	if ((iDataSink->DataSinkType()!=KUidMmfAudioOutput) &&
sl@0
   688
		(iDataSource->DataSourceType()!= KUidMmfAudioInput) )
sl@0
   689
		User::Leave(KErrNotSupported);
sl@0
   690
sl@0
   691
	if (iDataSink->DataSinkType()==KUidMmfAudioOutput)
sl@0
   692
		{
sl@0
   693
sl@0
   694
		//[ precondition the format exists ]
sl@0
   695
		if( !iSourceFormat )
sl@0
   696
			User::Leave(KErrNotSupported);
sl@0
   697
sl@0
   698
		//[ Get the Number of meta data entries from the sink format ]
sl@0
   699
		iSourceFormat->GetNumberOfMetaDataEntriesL( aNumberOfEntries );
sl@0
   700
		}
sl@0
   701
	else if (iDataSource->DataSourceType()==KUidMmfAudioInput)
sl@0
   702
		{
sl@0
   703
		if( !iSinkFormat )
sl@0
   704
			User::Leave(KErrNotSupported);
sl@0
   705
sl@0
   706
		iSinkFormat->GetNumberOfMetaDataEntriesL( aNumberOfEntries );
sl@0
   707
		}
sl@0
   708
sl@0
   709
	//[ assert the invariant ]
sl@0
   710
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   711
sl@0
   712
	}
sl@0
   713
sl@0
   714
/**
sl@0
   715
* GetMetaDataEntryL
sl@0
   716
* @param aIndex
sl@0
   717
* @returns "CMMFMetaDataEntry*"
sl@0
   718
*/
sl@0
   719
CMMFMetaDataEntry* CMMFTestUseOldCodecAudioController::GetMetaDataEntryL(TInt aIndex )
sl@0
   720
	{
sl@0
   721
		//[ assert the invariant ]
sl@0
   722
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   723
sl@0
   724
	//[ precondition that we are in the primed state or stopped ]
sl@0
   725
	if( !((State() == EPrimed) || ( State() == EStopped)))
sl@0
   726
		User::Leave(KErrNotReady);
sl@0
   727
sl@0
   728
    // [ precondition there is a sink format ]
sl@0
   729
	if (!iDataSink)
sl@0
   730
		User::Leave(KErrNotSupported);
sl@0
   731
sl@0
   732
	iDataSink->DataSinkType();
sl@0
   733
	iDataSource->DataSourceType();
sl@0
   734
sl@0
   735
	// [ precondition the sink or source is either an audio output or input ]
sl@0
   736
	if ((iDataSink->DataSinkType()!= KUidMmfAudioOutput) &&
sl@0
   737
		(iDataSource->DataSourceType()!= KUidMmfAudioInput ))
sl@0
   738
		User::Leave(KErrNotSupported);
sl@0
   739
sl@0
   740
	//[ Get the meta data entry from the sink format ]
sl@0
   741
	CMMFMetaDataEntry*  theEntry = NULL;
sl@0
   742
sl@0
   743
	if (iDataSink->DataSinkType()==KUidMmfAudioOutput)
sl@0
   744
		{ 
sl@0
   745
		//[ precondition the format exists ]
sl@0
   746
		if( !iSourceFormat )
sl@0
   747
			User::Leave(KErrNotSupported);
sl@0
   748
sl@0
   749
		//[ Get the Number of meta data entries from the sink format ]
sl@0
   750
		theEntry = iSourceFormat->MetaDataEntryL(aIndex);
sl@0
   751
		}
sl@0
   752
	else if (iDataSource->DataSourceType()==KUidMmfAudioInput)
sl@0
   753
		{
sl@0
   754
		//[ precondition the format exits ]
sl@0
   755
		if( !iSinkFormat )
sl@0
   756
			User::Leave(KErrNotSupported);
sl@0
   757
		theEntry = iSinkFormat->MetaDataEntryL(aIndex);
sl@0
   758
		}
sl@0
   759
sl@0
   760
	//[ assert the post condition that the entry is not null ]
sl@0
   761
	__ASSERT_ALWAYS( theEntry, Panic(EBadInvariant));
sl@0
   762
sl@0
   763
	//[ assert the invariant ]
sl@0
   764
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   765
sl@0
   766
	return theEntry;
sl@0
   767
	}
sl@0
   768
sl@0
   769
/**
sl@0
   770
* RemoveDataSourceL
sl@0
   771
* @param aDataSource
sl@0
   772
* 
sl@0
   773
*/
sl@0
   774
void CMMFTestUseOldCodecAudioController::RemoveDataSourceL(MDataSource& aDataSource )
sl@0
   775
	{
sl@0
   776
	//[ assert the invariant ]
sl@0
   777
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant) );
sl@0
   778
sl@0
   779
	//[ precondition is that we have a data source ]
sl@0
   780
	if( !iDataSource )
sl@0
   781
		User::Leave(KErrNotReady);
sl@0
   782
sl@0
   783
	//[precondition the data source is the data source we have]
sl@0
   784
	if( iDataSource != &aDataSource )
sl@0
   785
		User::Leave(KErrArgument);
sl@0
   786
sl@0
   787
	//[ the controller is in the stopped state ]
sl@0
   788
	if(State() != EStopped)
sl@0
   789
		User::Leave(KErrNotReady);
sl@0
   790
sl@0
   791
	//[ remove the data sink from the controller and delete the format]
sl@0
   792
     if( iSourceAndSinkAdded )
sl@0
   793
		 {
sl@0
   794
         __ASSERT_ALWAYS( iDataPath, Panic( EBadState )); 
sl@0
   795
	     //[ Remove references to source and sink ]
sl@0
   796
	     iDataPath->ResetL();
sl@0
   797
		 iSourceAndSinkAdded = EFalse ;
sl@0
   798
		 }
sl@0
   799
sl@0
   800
	 // [ delete the data sink and format ]
sl@0
   801
	 iDataSource = NULL ;
sl@0
   802
	 delete iSourceFormat;
sl@0
   803
	 iSourceFormat = NULL;
sl@0
   804
		
sl@0
   805
	// [ assert postcondition we are stopped ]
sl@0
   806
	__ASSERT_ALWAYS( (State() == EStopped), Panic(EPostConditionViolation) );
sl@0
   807
sl@0
   808
	//[ assert postcondition the SourceAndSinkAdded is false ]
sl@0
   809
	__ASSERT_ALWAYS( !iSourceAndSinkAdded, Panic( EPostConditionViolation ));
sl@0
   810
	
sl@0
   811
	//[ assert postcondition the data sinkformat  is null ]
sl@0
   812
	__ASSERT_ALWAYS( (iSourceFormat == NULL ), Panic( EPostConditionViolation ));
sl@0
   813
sl@0
   814
	//[ assert postcondition the data sink  is null ]
sl@0
   815
	__ASSERT_ALWAYS( (iDataSource == NULL ), Panic( EPostConditionViolation ));
sl@0
   816
sl@0
   817
	//[ assert the invariant ]
sl@0
   818
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   819
sl@0
   820
	}
sl@0
   821
sl@0
   822
/**
sl@0
   823
* RemoveDataSinkL
sl@0
   824
* 
sl@0
   825
* @param aDataSink
sl@0
   826
*
sl@0
   827
*/
sl@0
   828
void CMMFTestUseOldCodecAudioController::RemoveDataSinkL(MDataSink& aDataSink )
sl@0
   829
	{
sl@0
   830
	//[ assert the invariant ]
sl@0
   831
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant) );
sl@0
   832
sl@0
   833
	//[ precondition is that we have a data sink ]
sl@0
   834
	if( !iDataSink )
sl@0
   835
		User::Leave(KErrNotSupported);
sl@0
   836
sl@0
   837
	//[precondition the data sink is the data sink we have]
sl@0
   838
	if( iDataSink != &aDataSink )
sl@0
   839
		User::Leave(KErrNotSupported);
sl@0
   840
sl@0
   841
	//[ the controller is in the stopped state ]
sl@0
   842
	if(State() != EStopped)
sl@0
   843
		User::Leave(KErrNotReady);
sl@0
   844
sl@0
   845
	//[ remove the data sink from the controller and delete the format]
sl@0
   846
     if( iSourceAndSinkAdded )
sl@0
   847
		 {
sl@0
   848
         __ASSERT_ALWAYS( iDataPath, Panic( EBadState ));
sl@0
   849
         //[ Remove references to source and sink ]
sl@0
   850
	     iDataPath->ResetL();
sl@0
   851
		 iSourceAndSinkAdded = EFalse ;
sl@0
   852
		 }
sl@0
   853
sl@0
   854
	 // [ reset data sink referenece and remove the format ]
sl@0
   855
	 iDataSink = NULL ;
sl@0
   856
	 delete iSinkFormat;
sl@0
   857
	 iSinkFormat = NULL;
sl@0
   858
		
sl@0
   859
	// [ assert postcondition we are stopped ]
sl@0
   860
	__ASSERT_ALWAYS( (State() == EStopped), Panic(EPostConditionViolation) );
sl@0
   861
sl@0
   862
	//[ assert postcondition the SourceAndSinkAdded is false ]
sl@0
   863
	__ASSERT_ALWAYS( !iSourceAndSinkAdded, Panic( EPostConditionViolation ));
sl@0
   864
	
sl@0
   865
	//[ assert postcondition the data sinkformat  is null ]
sl@0
   866
	__ASSERT_ALWAYS( (iSinkFormat == NULL ), Panic( EPostConditionViolation ));
sl@0
   867
sl@0
   868
	//[ assert postcondition the data sink  is null ]
sl@0
   869
	__ASSERT_ALWAYS( (iDataSink == NULL ), Panic( EPostConditionViolation ));
sl@0
   870
sl@0
   871
	//[ assert the invariant ]
sl@0
   872
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   873
	}
sl@0
   874
sl@0
   875
/**
sl@0
   876
 *  CustomCommand
sl@0
   877
 *  @param aMessage
sl@0
   878
 */
sl@0
   879
void CMMFTestUseOldCodecAudioController::CustomCommand(TMMFMessage& aMessage)
sl@0
   880
	{
sl@0
   881
	//[ assert the invariant ]
sl@0
   882
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   883
	// [ We do not have any custom commands ]
sl@0
   884
	aMessage.Complete(KErrNotSupported);
sl@0
   885
	}
sl@0
   886
sl@0
   887
/**
sl@0
   888
* NegotiateL
sl@0
   889
* 
sl@0
   890
*/
sl@0
   891
void CMMFTestUseOldCodecAudioController::NegotiateL()
sl@0
   892
	{
sl@0
   893
	//[ assert the invariant ]
sl@0
   894
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   895
sl@0
   896
	//utility function used by custom to negotiate source sink settings after a change
sl@0
   897
	if ((iSourceFormat)&&(iSinkFormat)) //convert
sl@0
   898
		{
sl@0
   899
		iSinkFormat->NegotiateL(*iSourceFormat);
sl@0
   900
		iSourceFormat->NegotiateSourceL(*iSinkFormat);
sl@0
   901
		iSinkFormat->NegotiateL(*iSourceFormat);
sl@0
   902
sl@0
   903
		// check for upsampling attempts
sl@0
   904
		if (iSinkFormat->SampleRate() > iSourceFormat->SampleRate())
sl@0
   905
			{
sl@0
   906
			// we don't support upsampling
sl@0
   907
			User::Leave( KErrNotSupported );
sl@0
   908
			}
sl@0
   909
		}
sl@0
   910
	else if ((iDataSource)&&(iSinkFormat)) //record
sl@0
   911
		{
sl@0
   912
		// need two step negotiation for record
sl@0
   913
		// first try to set the audio input settings to match the required settings for recording
sl@0
   914
		iDataSource->NegotiateSourceL(*iSinkFormat);
sl@0
   915
		// now call negotiateL on the sink in order to tell it what the audio input was set to.
sl@0
   916
		iSinkFormat->NegotiateL(*iDataSource);
sl@0
   917
		}
sl@0
   918
	else if ((iSourceFormat)&&(iDataSink)) //play
sl@0
   919
		iDataSink->NegotiateL(*iSourceFormat);
sl@0
   920
sl@0
   921
	//[ assert the invariant ]
sl@0
   922
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   923
	}
sl@0
   924
sl@0
   925
/**
sl@0
   926
 *  SetPrioritySettings
sl@0
   927
 *
sl@0
   928
 *	@param aPrioritySettings
sl@0
   929
 */
sl@0
   930
void CMMFTestUseOldCodecAudioController::SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings)
sl@0
   931
	{
sl@0
   932
	//[ assert the invariant ]
sl@0
   933
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   934
sl@0
   935
	//[ assert the precondition ]
sl@0
   936
	if(State() != EStopped)
sl@0
   937
		{
sl@0
   938
		ASSERT(EFalse);		// used to leave here with KErrNotReady
sl@0
   939
		return;
sl@0
   940
		}
sl@0
   941
sl@0
   942
	//[ update the priority settings of the controller]
sl@0
   943
	iPrioritySettings = aPrioritySettings;
sl@0
   944
sl@0
   945
	//pass settings on to source and sink
sl@0
   946
	if (iDataSource)
sl@0
   947
		{
sl@0
   948
		iDataSource->SetSourcePrioritySettings(iPrioritySettings);
sl@0
   949
		}
sl@0
   950
	if (iDataSink)
sl@0
   951
		{
sl@0
   952
		iDataSink->SetSinkPrioritySettings(iPrioritySettings);
sl@0
   953
		}
sl@0
   954
sl@0
   955
    // assert the post condition
sl@0
   956
	//__ASSERT_ALWAYS( (iPrioritySettings == aPrioritySettings), Panic( ));
sl@0
   957
	//[ assert the invariant ]
sl@0
   958
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   959
	}
sl@0
   960
sl@0
   961
/**
sl@0
   962
 *  SendEventToClient
sl@0
   963
 *
sl@0
   964
 *	@param aEvent
sl@0
   965
 */
sl@0
   966
TInt CMMFTestUseOldCodecAudioController::SendEventToClient(const TMMFEvent& aEvent)
sl@0
   967
	{
sl@0
   968
	//[ assert the invariant ]
sl@0
   969
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
   970
sl@0
   971
	TMMFEvent controllerEvent;
sl@0
   972
	//Were going to stop playing, force event type to be the correct type
sl@0
   973
	controllerEvent.iEventType = KMMFEventCategoryPlaybackComplete;
sl@0
   974
	controllerEvent.iErrorCode = aEvent.iErrorCode;
sl@0
   975
sl@0
   976
sl@0
   977
sl@0
   978
	//If we receive KErrNone from the DataPath, it indicates that it has 
sl@0
   979
	//successfully completed playing/converting/recording.
sl@0
   980
	if ((aEvent.iEventType == KMMFEventCategoryPlaybackComplete) && 
sl@0
   981
		(aEvent.iErrorCode == KErrNone))
sl@0
   982
		{
sl@0
   983
		if(iStoppingRecording)
sl@0
   984
			{
sl@0
   985
			iStoppingRecording = EFalse;
sl@0
   986
			iDataPath->Stop();
sl@0
   987
			SetState( EStopped );
sl@0
   988
			
sl@0
   989
			//complete the clients stop request
sl@0
   990
			iStoppingMessage->Complete(KErrNone);
sl@0
   991
			delete iStoppingMessage; iStoppingMessage=NULL;
sl@0
   992
sl@0
   993
			//we don't want to send an event to the client
sl@0
   994
			return KErrNone;
sl@0
   995
			}
sl@0
   996
		else
sl@0
   997
			{//datapath has reached end of file so set internal state to primed
sl@0
   998
			SetState( EPrimed );
sl@0
   999
			}
sl@0
  1000
		}
sl@0
  1001
	else
sl@0
  1002
		{
sl@0
  1003
		if ( State()!= EStopped)
sl@0
  1004
			{
sl@0
  1005
			//datapath propogates stop to sink & source
sl@0
  1006
			iDataPath->Stop();
sl@0
  1007
			SetState( EStopped );
sl@0
  1008
sl@0
  1009
			if(iStoppingRecording)
sl@0
  1010
				{// an error has occurred while we were waiting for recording to stop, 
sl@0
  1011
				 //must complete clients request
sl@0
  1012
				iStoppingRecording = EFalse;
sl@0
  1013
				iStoppingMessage->Complete(aEvent.iErrorCode);
sl@0
  1014
				delete iStoppingMessage; iStoppingMessage=NULL;
sl@0
  1015
				}
sl@0
  1016
			}
sl@0
  1017
		}
sl@0
  1018
sl@0
  1019
	//now send event to client...
sl@0
  1020
	TInt result = DoSendEventToClient(controllerEvent);
sl@0
  1021
	
sl@0
  1022
	//[ assert the invariant ]
sl@0
  1023
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1024
sl@0
  1025
	return result;
sl@0
  1026
	}
sl@0
  1027
sl@0
  1028
sl@0
  1029
/**
sl@0
  1030
* MapdSetVolumeL
sl@0
  1031
*
sl@0
  1032
*  @param aVolume
sl@0
  1033
*
sl@0
  1034
*/
sl@0
  1035
void CMMFTestUseOldCodecAudioController::MapdSetVolumeL(TInt aVolume)
sl@0
  1036
	{
sl@0
  1037
	//[ assert the invariant ]
sl@0
  1038
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1039
sl@0
  1040
	// [  precondition is true for state 
sl@0
  1041
	//    we can set the volume in any state ]
sl@0
  1042
sl@0
  1043
	//[ precondition we have a data sink ]
sl@0
  1044
	if (!iDataSink)
sl@0
  1045
		User::Leave(KErrNotReady);
sl@0
  1046
sl@0
  1047
    // [ precondition that the data sink is an audio output ]
sl@0
  1048
	// Make sure that iDataSink is an Audio Output
sl@0
  1049
	if (iDataSink->DataSinkType() != KUidMmfAudioOutput)
sl@0
  1050
				User::Leave(KErrNotSupported);
sl@0
  1051
sl@0
  1052
	MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink);
sl@0
  1053
sl@0
  1054
	// [ assert the precondition that aVolume is in range ]
sl@0
  1055
	TInt maxVolume = audioOutput->SoundDevice().MaxVolume();
sl@0
  1056
	if( ( aVolume < 0 ) || ( aVolume > maxVolume ))
sl@0
  1057
			User::Leave(KErrArgument);
sl@0
  1058
	
sl@0
  1059
	//[ set the volume on the device ]
sl@0
  1060
	audioOutput->SoundDevice().SetVolume(aVolume);
sl@0
  1061
sl@0
  1062
	//[ assert the post condition volume is equal to a volume]
sl@0
  1063
	TInt soundVolume = 0;
sl@0
  1064
	soundVolume = audioOutput->SoundDevice().Volume();
sl@0
  1065
sl@0
  1066
    __ASSERT_ALWAYS( ( soundVolume == aVolume), Panic(EPostConditionViolation));
sl@0
  1067
sl@0
  1068
	//[ assert the invariant ]
sl@0
  1069
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1070
	}
sl@0
  1071
sl@0
  1072
/**
sl@0
  1073
*
sl@0
  1074
* MapdGetMaxVolumeL
sl@0
  1075
*
sl@0
  1076
* @param aMaxVolume
sl@0
  1077
*
sl@0
  1078
*/
sl@0
  1079
void CMMFTestUseOldCodecAudioController::MapdGetMaxVolumeL(TInt& aMaxVolume)
sl@0
  1080
	{
sl@0
  1081
	// [ assert the invariant ]
sl@0
  1082
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1083
sl@0
  1084
	//[ we can get max volume in any state ]
sl@0
  1085
sl@0
  1086
	// [ precondition we must have a data sink ]
sl@0
  1087
	if (!iDataSink)
sl@0
  1088
		User::Leave(KErrNotReady);
sl@0
  1089
sl@0
  1090
	//[ precondition the sink must be an audio output]
sl@0
  1091
	// Make sure that iDataSink is an Audio Output
sl@0
  1092
	if (iDataSink->DataSinkType() != KUidMmfAudioOutput)
sl@0
  1093
			User::Leave(KErrNotSupported);
sl@0
  1094
sl@0
  1095
	//[ get the volume from the device ]
sl@0
  1096
	MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink);	
sl@0
  1097
	aMaxVolume = audioOutput->SoundDevice().MaxVolume();
sl@0
  1098
sl@0
  1099
	//[ assert the invariant ]
sl@0
  1100
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1101
sl@0
  1102
	}
sl@0
  1103
sl@0
  1104
sl@0
  1105
/**
sl@0
  1106
*
sl@0
  1107
* MapdGetVolumeL
sl@0
  1108
*
sl@0
  1109
* @param aVolume
sl@0
  1110
*
sl@0
  1111
*/
sl@0
  1112
void CMMFTestUseOldCodecAudioController::MapdGetVolumeL(TInt& aVolume)
sl@0
  1113
	{
sl@0
  1114
	// [ assert the invariant ]
sl@0
  1115
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1116
sl@0
  1117
	//[  precondition that we have a data sink ]
sl@0
  1118
	if (!iDataSink)
sl@0
  1119
		User::Leave(KErrNotReady);
sl@0
  1120
sl@0
  1121
	//[ precondition iDataSink is an Audio Output ]
sl@0
  1122
	if (iDataSink->DataSinkType() != KUidMmfAudioOutput)
sl@0
  1123
		User::Leave(KErrNotSupported);
sl@0
  1124
sl@0
  1125
	// [ get the volume ]
sl@0
  1126
	MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink);
sl@0
  1127
	aVolume = audioOutput->SoundDevice().Volume();
sl@0
  1128
	
sl@0
  1129
	// [ assert precondition that the volume is in range
sl@0
  1130
	//     0.. aMaxVolume ]
sl@0
  1131
	TInt aMaxVolume = audioOutput->SoundDevice().MaxVolume();
sl@0
  1132
	__ASSERT_ALWAYS( (aVolume <= aMaxVolume), Panic(EBadState));
sl@0
  1133
	__ASSERT_ALWAYS( (aVolume >= 0), Panic(EBadState));
sl@0
  1134
sl@0
  1135
	// [ assert the invariant ]
sl@0
  1136
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1137
sl@0
  1138
	}
sl@0
  1139
sl@0
  1140
/**
sl@0
  1141
*
sl@0
  1142
* MapdSetVolumeRampL
sl@0
  1143
*
sl@0
  1144
* @param aRampDuration
sl@0
  1145
*
sl@0
  1146
*/
sl@0
  1147
void CMMFTestUseOldCodecAudioController::MapdSetVolumeRampL(const TTimeIntervalMicroSeconds& aRampDuration)
sl@0
  1148
	{
sl@0
  1149
     // [ assert the invariant ]
sl@0
  1150
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1151
sl@0
  1152
	//[ precondition that we have a data sink ]
sl@0
  1153
	if (!iDataSink)
sl@0
  1154
		User::Leave(KErrNotReady);
sl@0
  1155
sl@0
  1156
	// [ precondition iDataSink is an Audio Output ]
sl@0
  1157
	if (iDataSink->DataSinkType() != KUidMmfAudioOutput)
sl@0
  1158
		User::Leave(KErrNotSupported);
sl@0
  1159
sl@0
  1160
	//[ set the volume ramp ]
sl@0
  1161
	MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink);
sl@0
  1162
	audioOutput->SoundDevice().SetVolumeRamp(aRampDuration);
sl@0
  1163
	
sl@0
  1164
	//[ assert the invariant ]
sl@0
  1165
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1166
		
sl@0
  1167
	}
sl@0
  1168
sl@0
  1169
sl@0
  1170
/**
sl@0
  1171
*
sl@0
  1172
* MapdSetBalanceL
sl@0
  1173
*
sl@0
  1174
* @param aBalance
sl@0
  1175
*
sl@0
  1176
*/
sl@0
  1177
void CMMFTestUseOldCodecAudioController::MapdSetBalanceL(TInt aBalance)
sl@0
  1178
	{
sl@0
  1179
	//[ assert the invariant ]
sl@0
  1180
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  1181
sl@0
  1182
	// [ precondition is that we have a data sink ]
sl@0
  1183
	if (!iDataSink)
sl@0
  1184
		User::Leave(KErrNotReady);
sl@0
  1185
	
sl@0
  1186
	// [ precondition is that the data sink is an audio output]
sl@0
  1187
	if (iDataSink->DataSinkType() != KUidMmfAudioOutput)
sl@0
  1188
		User::Leave(KErrNotSupported);
sl@0
  1189
	
sl@0
  1190
	//[ get the audio output ]
sl@0
  1191
	MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink);
sl@0
  1192
sl@0
  1193
	// [ separate out left and right balance ]
sl@0
  1194
	TInt left  = 0;
sl@0
  1195
	TInt right = 0;
sl@0
  1196
	CalculateLeftRightBalance( left, right, aBalance );
sl@0
  1197
	
sl@0
  1198
	//[ set the balance ]
sl@0
  1199
	audioOutput->SoundDevice().SetPlayBalanceL(left, right); 
sl@0
  1200
sl@0
  1201
	// [assert the post condition that the balance is set correctly]
sl@0
  1202
	TInt rightBalance = 0;
sl@0
  1203
	TInt leftBalance  = 0;
sl@0
  1204
	audioOutput->SoundDevice().GetPlayBalanceL(leftBalance, rightBalance); 
sl@0
  1205
sl@0
  1206
	//[ assert post condition holds]
sl@0
  1207
	TBool postCondition = (( rightBalance == right) && ( leftBalance == left));
sl@0
  1208
	__ASSERT_ALWAYS( postCondition, Panic( EPostConditionViolation ) );
sl@0
  1209
sl@0
  1210
	//[ assert the invariant ]
sl@0
  1211
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  1212
	}
sl@0
  1213
sl@0
  1214
/**
sl@0
  1215
* CalculateLeftRightBalance
sl@0
  1216
* @param aLeft
sl@0
  1217
* @param aRight
sl@0
  1218
* @param aBalance
sl@0
  1219
* Preconditions:
sl@0
  1220
* !(aBalance < KMMFBalanceMaxLeft || aBalance > KMMFBalanceMaxRight)
sl@0
  1221
* y = m x + c
sl@0
  1222
* aLeft = m ( aBalance ) + c
sl@0
  1223
* when aBalance = KMMFBalanceMaxLeft   aLeft = 100
sl@0
  1224
* when aBalance = KMMFBalanceMaxRight  aLeft = 0
sl@0
  1225
* 100 = m( KMMFBalanceMaxLeft ) + c
sl@0
  1226
* 0   = m( KMMFBalanceMaxRight ) + c 
sl@0
  1227
* c = -(KMMFBalanceMaxRight) m
sl@0
  1228
* 100 = m(KMMFBalanceMaxLeft ) - m(KMMFBalanceMaxRight)
sl@0
  1229
* m = 100/(KMMFBalanceMaxLeft - KMMFBalanceMaxRight )
sl@0
  1230
* c = -(KMMFBalanceMaxRight) * 100 /(KMMFBalanceMaxLeft - KMMFBalanceMaxRight )
sl@0
  1231
* aLeft = ( aBalance - KMMFBalanceMaxRight ) * 100 /( KMMFBalanceMaxLeft - KMMFBalanceMaxRight )
sl@0
  1232
* @xxxx
sl@0
  1233
*/
sl@0
  1234
void CMMFTestUseOldCodecAudioController::CalculateLeftRightBalance( TInt& aLeft, TInt& aRight, TInt aBalance ) const
sl@0
  1235
	{
sl@0
  1236
	// Check the balance is within limits & modify to min or max values if necessary
sl@0
  1237
	if (aBalance < KMMFBalanceMaxLeft)
sl@0
  1238
		aBalance = KMMFBalanceMaxLeft;
sl@0
  1239
	if (aBalance > KMMFBalanceMaxRight)
sl@0
  1240
		aBalance = KMMFBalanceMaxRight;
sl@0
  1241
sl@0
  1242
	// [ assert precondition that aBalance is within limits ]
sl@0
  1243
    __ASSERT_ALWAYS( !(aBalance < KMMFBalanceMaxLeft || aBalance > KMMFBalanceMaxRight), Panic(EBadArgument));
sl@0
  1244
	
sl@0
  1245
	//[ Now separate percentage balances out from aBalance ]
sl@0
  1246
	 aLeft = (100 * (aBalance-KMMFBalanceMaxRight)) / (KMMFBalanceMaxLeft-KMMFBalanceMaxRight);
sl@0
  1247
     aRight = 100 - aLeft;
sl@0
  1248
sl@0
  1249
	 //[ assert post condition that left and right are within range ]
sl@0
  1250
	 __ASSERT_ALWAYS( ( (aLeft <= 100) && (aLeft >= 0) ), Panic(EPostConditionViolation));
sl@0
  1251
	 __ASSERT_ALWAYS( ( (aRight <= 100) && (aRight >= 0) ), Panic(EPostConditionViolation));
sl@0
  1252
	}
sl@0
  1253
sl@0
  1254
sl@0
  1255
/**
sl@0
  1256
* MapdGetBalanceL
sl@0
  1257
* @param aBalance
sl@0
  1258
*
sl@0
  1259
*/
sl@0
  1260
void CMMFTestUseOldCodecAudioController::MapdGetBalanceL(TInt& aBalance)
sl@0
  1261
	{
sl@0
  1262
	//[ assert the invariant ]
sl@0
  1263
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1264
sl@0
  1265
	//[ precondition that we have a sink]
sl@0
  1266
	if (!iDataSink)
sl@0
  1267
		User::Leave(KErrNotReady);
sl@0
  1268
	
sl@0
  1269
	// [ iDataSink is an Audio Output ]
sl@0
  1270
	if (iDataSink->DataSinkType() != KUidMmfAudioOutput)
sl@0
  1271
		User::Leave(KErrNotSupported);
sl@0
  1272
	
sl@0
  1273
	// [ get the play balance ]
sl@0
  1274
	MMMFAudioOutput* audioOutput = STATIC_CAST(MMMFAudioOutput*, iDataSink);
sl@0
  1275
	TInt left = 50; // arbitrary values 
sl@0
  1276
	TInt right = 50;
sl@0
  1277
	audioOutput->SoundDevice().GetPlayBalanceL(left, right); 
sl@0
  1278
    CalculateBalance( aBalance, left, right );
sl@0
  1279
sl@0
  1280
	//[ assert the invariant ]
sl@0
  1281
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1282
	}
sl@0
  1283
sl@0
  1284
/**
sl@0
  1285
* CalculateBalance
sl@0
  1286
* @param aBalance
sl@0
  1287
* @param aLeft
sl@0
  1288
* @param aRight
sl@0
  1289
*
sl@0
  1290
* follows a simple straight line transformation
sl@0
  1291
* y = m x + c
sl@0
  1292
* m = (KMMFBalanceMaxLeft-KMMFBalanceMaxRight)/ 100 
sl@0
  1293
* c = KMMFBalanceMaxRight
sl@0
  1294
* by substitution
sl@0
  1295
* when aLeft = 0
sl@0
  1296
*   KMMFBalanceMaxRight = m * 0 + c
sl@0
  1297
*   c = KMMFBalanceMaxRight
sl@0
  1298
* when aLeft = 100
sl@0
  1299
* KMMFBalanceMaxLeft = m * 100 + KMMFBalanceMaxRight
sl@0
  1300
* m = ( KMMFBalanceMaxLeft - KMMFBalanceMaxRight ) /100
sl@0
  1301
*/
sl@0
  1302
void CMMFTestUseOldCodecAudioController::CalculateBalance( TInt& aBalance, TInt aLeft, TInt aRight ) const
sl@0
  1303
	{
sl@0
  1304
	//[ assert pre conditions ]
sl@0
  1305
	__ASSERT_ALWAYS( (( 0 <= aLeft) && ( 100 >= aLeft)), Panic( EBadArgument) );
sl@0
  1306
	__ASSERT_ALWAYS( (( 0 <= aRight) && ( 100 >= aRight)), Panic( EBadArgument) );
sl@0
  1307
	
sl@0
  1308
	if ((aLeft > 0) && (aRight > 0))
sl@0
  1309
		{
sl@0
  1310
		__ASSERT_ALWAYS( (( aLeft + aRight ) == 100 ), Panic( EBadArgument ));
sl@0
  1311
		aBalance = (aLeft * (KMMFBalanceMaxLeft-KMMFBalanceMaxRight))/100 + KMMFBalanceMaxRight;
sl@0
  1312
		}
sl@0
  1313
	else if ((aLeft == 0) && (aRight == 0))
sl@0
  1314
		{
sl@0
  1315
		aBalance = 0;
sl@0
  1316
		}
sl@0
  1317
	else if ((aLeft == 0) && (aRight > 0))
sl@0
  1318
		{
sl@0
  1319
		aBalance = 100;
sl@0
  1320
		}
sl@0
  1321
	else if ((aLeft > 0) && (aRight == 0))
sl@0
  1322
		{
sl@0
  1323
		aBalance = -100;
sl@0
  1324
		}
sl@0
  1325
sl@0
  1326
    //[ assert post condition that aBalance is within limits ]
sl@0
  1327
	__ASSERT_ALWAYS( !(aBalance < KMMFBalanceMaxLeft || aBalance > KMMFBalanceMaxRight), Panic(EBadArgument));
sl@0
  1328
	
sl@0
  1329
	}
sl@0
  1330
sl@0
  1331
/**
sl@0
  1332
* MardSetGainL
sl@0
  1333
* @param aGain
sl@0
  1334
*
sl@0
  1335
*/
sl@0
  1336
void CMMFTestUseOldCodecAudioController::MardSetGainL(TInt aGain)
sl@0
  1337
	{
sl@0
  1338
	// [ assert the invariant ]
sl@0
  1339
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1340
sl@0
  1341
	//[ precondition we are in the state stopped ]
sl@0
  1342
	if(State() != EStopped)
sl@0
  1343
		User::Leave(KErrNotReady);
sl@0
  1344
	
sl@0
  1345
	// [ assert the precondition that we have a data sink ]
sl@0
  1346
	if (!iDataSource)
sl@0
  1347
		User::Leave(KErrNotSupported);
sl@0
  1348
sl@0
  1349
	//[ assert the precondition that the data sink is an audio input ]
sl@0
  1350
	if (iDataSource->DataSourceType() != KUidMmfAudioInput)
sl@0
  1351
		User::Leave(KErrNotReady);
sl@0
  1352
sl@0
  1353
	// Set gain of sound device
sl@0
  1354
	MMMFAudioInput* audioInput = STATIC_CAST(MMMFAudioInput*, iDataSource);
sl@0
  1355
	audioInput->SoundDevice().SetGain(aGain);
sl@0
  1356
	
sl@0
  1357
	//[ assert the invariant ]
sl@0
  1358
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1359
sl@0
  1360
	}
sl@0
  1361
		
sl@0
  1362
/**
sl@0
  1363
* MardGetMaxGainL
sl@0
  1364
* @param aMaxGain
sl@0
  1365
*
sl@0
  1366
*/
sl@0
  1367
void CMMFTestUseOldCodecAudioController::MardGetMaxGainL(TInt& aMaxGain)
sl@0
  1368
	{
sl@0
  1369
	// [ assert the invariant ]
sl@0
  1370
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1371
sl@0
  1372
	// [ assert the precondition that we have a source ]
sl@0
  1373
	if (!iDataSource)
sl@0
  1374
		User::Leave(KErrNotReady);
sl@0
  1375
sl@0
  1376
	//[ assert the precondition that iDataSink is an Audio Input]
sl@0
  1377
	if (iDataSource->DataSourceType() != KUidMmfAudioInput)
sl@0
  1378
		User::Leave(KErrNotSupported);
sl@0
  1379
sl@0
  1380
	MMMFAudioInput* audioInput = STATIC_CAST(MMMFAudioInput*, iDataSource);
sl@0
  1381
	aMaxGain = audioInput->SoundDevice().MaxGain();
sl@0
  1382
sl@0
  1383
	//[ assert the invariant ]
sl@0
  1384
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1385
	
sl@0
  1386
	}
sl@0
  1387
sl@0
  1388
/**
sl@0
  1389
* MardGetGainL
sl@0
  1390
* @param aGain
sl@0
  1391
*
sl@0
  1392
*/
sl@0
  1393
void CMMFTestUseOldCodecAudioController::MardGetGainL(TInt& aGain)
sl@0
  1394
	{
sl@0
  1395
	//[ assert the invariant ]
sl@0
  1396
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1397
sl@0
  1398
	// [ assert the precondition that we have a sink ]
sl@0
  1399
	if (!iDataSource)
sl@0
  1400
		User::Leave(KErrNotReady);
sl@0
  1401
sl@0
  1402
	// [ assert the precondition that we have an audio input sink]
sl@0
  1403
	if (iDataSource->DataSourceType() != KUidMmfAudioInput)
sl@0
  1404
			User::Leave(KErrNotSupported);
sl@0
  1405
sl@0
  1406
	MMMFAudioInput* audioInput = STATIC_CAST(MMMFAudioInput*, iDataSource);
sl@0
  1407
	aGain = audioInput->SoundDevice().Gain();
sl@0
  1408
		
sl@0
  1409
	//[ assert the invariant ]
sl@0
  1410
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1411
	}
sl@0
  1412
sl@0
  1413
sl@0
  1414
/**
sl@0
  1415
 *
sl@0
  1416
 * MardSetBalanceL
sl@0
  1417
 *   @param aBalance
sl@0
  1418
 */
sl@0
  1419
void CMMFTestUseOldCodecAudioController::MardSetBalanceL(TInt aBalance)
sl@0
  1420
	{
sl@0
  1421
	// [ assert the invaraiant ]
sl@0
  1422
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1423
sl@0
  1424
	// [ precondition is that we have a data sink ]
sl@0
  1425
	if (!iDataSink)
sl@0
  1426
		User::Leave(KErrNotReady);
sl@0
  1427
	
sl@0
  1428
	// [ precondition is that the balance is in range ]
sl@0
  1429
	// Make sure aBalance is in the range -100 <-> 100
sl@0
  1430
	if (aBalance < KMMFBalanceMaxLeft || aBalance > KMMFBalanceMaxRight)
sl@0
  1431
		User::Leave(KErrArgument);
sl@0
  1432
	
sl@0
  1433
	// [ precondition is that the data sink is an audio output]
sl@0
  1434
	if (iDataSource->DataSourceType() != KUidMmfAudioInput)
sl@0
  1435
		User::Leave(KErrNotSupported);
sl@0
  1436
	
sl@0
  1437
    
sl@0
  1438
	//[ get the audio output ]
sl@0
  1439
	MMMFAudioInput* audioInput = STATIC_CAST(MMMFAudioInput*, iDataSource);
sl@0
  1440
sl@0
  1441
	// [ separate out left and right balance ]
sl@0
  1442
	TInt left  = 0;
sl@0
  1443
	TInt right = 0;
sl@0
  1444
	CalculateLeftRightBalance( left, right, aBalance );
sl@0
  1445
	
sl@0
  1446
	//[ set the balance ]
sl@0
  1447
	audioInput->SoundDevice().SetRecordBalanceL(left, right); 
sl@0
  1448
sl@0
  1449
	// [assert the post condition that the balance is set correctly]
sl@0
  1450
	TInt rightBalance = 0;
sl@0
  1451
	TInt leftBalance  = 0;
sl@0
  1452
	audioInput->SoundDevice().GetRecordBalanceL(leftBalance, rightBalance); 
sl@0
  1453
sl@0
  1454
	//[ assert post condition holds]
sl@0
  1455
	TBool postCondition = (( rightBalance == right) && ( leftBalance == left));
sl@0
  1456
	__ASSERT_ALWAYS( postCondition, Panic( EPostConditionViolation ) );
sl@0
  1457
sl@0
  1458
	//[ assert the invariant ]
sl@0
  1459
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  1460
	
sl@0
  1461
	}
sl@0
  1462
sl@0
  1463
/**
sl@0
  1464
*
sl@0
  1465
* MardGetBalanceL
sl@0
  1466
* @param aBalance
sl@0
  1467
*
sl@0
  1468
*/
sl@0
  1469
void CMMFTestUseOldCodecAudioController::MardGetBalanceL(TInt& aBalance)
sl@0
  1470
	{
sl@0
  1471
	//[ assert the invariant ]
sl@0
  1472
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1473
sl@0
  1474
	//[ precondition that we have a sink]
sl@0
  1475
	if (!iDataSink)
sl@0
  1476
		User::Leave(KErrNotReady);
sl@0
  1477
	
sl@0
  1478
	// [ iDataSink is an Audio Output ]
sl@0
  1479
	if (iDataSource->DataSourceType() != KUidMmfAudioInput)
sl@0
  1480
		User::Leave(KErrNotSupported);
sl@0
  1481
	
sl@0
  1482
	// [ get the play balance ]
sl@0
  1483
	MMMFAudioInput* audioInput = STATIC_CAST(MMMFAudioInput*, iDataSource);
sl@0
  1484
	TInt left = 50; // arbitrary values 
sl@0
  1485
	TInt right = 50;
sl@0
  1486
	audioInput->SoundDevice().GetRecordBalanceL(left, right); 
sl@0
  1487
    CalculateBalance( aBalance, left, right );
sl@0
  1488
sl@0
  1489
	//[ assert the invariant ]
sl@0
  1490
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1491
sl@0
  1492
	}
sl@0
  1493
sl@0
  1494
/**
sl@0
  1495
* MapcSetPlaybackWindowL
sl@0
  1496
* @param aStart
sl@0
  1497
* @param aEnd
sl@0
  1498
*
sl@0
  1499
*/
sl@0
  1500
void CMMFTestUseOldCodecAudioController::MapcSetPlaybackWindowL(const TTimeIntervalMicroSeconds& aStart, const TTimeIntervalMicroSeconds& aEnd)
sl@0
  1501
	{
sl@0
  1502
	iDataPath->SetPlayWindowL(aStart, aEnd);
sl@0
  1503
	}
sl@0
  1504
sl@0
  1505
/**
sl@0
  1506
* MapcDeletePlaybackWindowL
sl@0
  1507
*/
sl@0
  1508
void CMMFTestUseOldCodecAudioController::MapcDeletePlaybackWindowL()
sl@0
  1509
	{
sl@0
  1510
	iDataPath->ClearPlayWindowL();
sl@0
  1511
	}
sl@0
  1512
sl@0
  1513
/**
sl@0
  1514
* MapcGetLoadingProgressL
sl@0
  1515
*/
sl@0
  1516
void CMMFTestUseOldCodecAudioController::MapcGetLoadingProgressL(TInt& /*aPercentageComplete*/)
sl@0
  1517
	{
sl@0
  1518
	User::Leave(KErrNotSupported);
sl@0
  1519
	}
sl@0
  1520
sl@0
  1521
sl@0
  1522
/**
sl@0
  1523
* MarcGetRecordTimeAvailableL
sl@0
  1524
* @param aTime
sl@0
  1525
*
sl@0
  1526
*/
sl@0
  1527
void CMMFTestUseOldCodecAudioController::MarcGetRecordTimeAvailableL(TTimeIntervalMicroSeconds& aTime)
sl@0
  1528
	{
sl@0
  1529
	//[ assert the invariant ]
sl@0
  1530
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1531
	
sl@0
  1532
	//[ assert the precondition ( in a friendly way for this api 
sl@0
  1533
	// that we minimally have a data sink ]
sl@0
  1534
	if( !iDataSink )
sl@0
  1535
		User::Leave( KErrNotReady );
sl@0
  1536
	
sl@0
  1537
	// Use the FormatEncode to get the bytes per second and the sink (clip) to get the bytes available
sl@0
  1538
	// return the calculated value.
sl@0
  1539
	if	((iDataSink->DataSinkType() != KUidMmfFileSink) && (iDataSink->DataSinkType() != KUidMmfDescriptorSink))
sl@0
  1540
		User::Leave(KErrNotSupported) ;
sl@0
  1541
	
sl@0
  1542
	// [ max file size ]
sl@0
  1543
	//[ pre condition is that we have a sink ]
sl@0
  1544
   	
sl@0
  1545
	// In order to get the record time available we need to take into consideration
sl@0
  1546
	// that there may be a max file size ]
sl@0
  1547
	TInt64 bytesFree       = STATIC_CAST(CMMFClip*, iDataSink)->BytesFree() ;
sl@0
  1548
	TInt64 bytesPerSecond  = TInt64(0);
sl@0
  1549
	//[ set default time available ]
sl@0
  1550
	       aTime           = TTimeIntervalMicroSeconds( 0 ) ; // just return zero
sl@0
  1551
sl@0
  1552
	if( iSinkFormat )
sl@0
  1553
		{
sl@0
  1554
		TInt maxFileSize = STATIC_CAST(CMMFFormatEncode*, iSinkFormat)->MaximumClipSize();
sl@0
  1555
		//[ if maxFileSize > 0 we need to limit the bytes free to this value - size ]
sl@0
  1556
		if( maxFileSize > 0 )
sl@0
  1557
			{
sl@0
  1558
			// [ strangely the size of data written is a TInt ]
sl@0
  1559
			TInt fileSize = STATIC_CAST(CMMFClip*, iDataSink)->Size();
sl@0
  1560
			bytesFree = maxFileSize - fileSize;
sl@0
  1561
			// [ note it can occur that the fileSize id greater than the MaxFileSize
sl@0
  1562
			//  due to someone setting the max file size on an existing file ]
sl@0
  1563
			if( bytesFree < 0 ) bytesFree = 0;
sl@0
  1564
			__ASSERT_DEBUG( ( bytesFree <= maxFileSize), Panic(	EBadInvariant) );
sl@0
  1565
			}		
sl@0
  1566
		bytesPerSecond = STATIC_CAST(CMMFFormatEncode*, iSinkFormat)->BytesPerSecond() ;
sl@0
  1567
		}
sl@0
  1568
sl@0
  1569
	//[ now lets perform the calculation of time available ]
sl@0
  1570
	if ( bytesPerSecond != TInt64(0) )
sl@0
  1571
		{
sl@0
  1572
		aTime = TTimeIntervalMicroSeconds( bytesFree * KOneSecondInMicroSeconds / bytesPerSecond ) ;
sl@0
  1573
		}
sl@0
  1574
	
sl@0
  1575
	//[ assert the invariant ]
sl@0
  1576
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1577
	}
sl@0
  1578
sl@0
  1579
/**
sl@0
  1580
* MarcSetMaxDurationL
sl@0
  1581
* @param aMaxDuration
sl@0
  1582
*/
sl@0
  1583
void CMMFTestUseOldCodecAudioController::MarcSetMaxDurationL(const TTimeIntervalMicroSeconds& )
sl@0
  1584
	{
sl@0
  1585
	//[ this method is deprecated and no longer supported ]
sl@0
  1586
	User::Leave(KErrNotSupported);
sl@0
  1587
	}
sl@0
  1588
sl@0
  1589
/**
sl@0
  1590
* MarcSetMaxFileSizeL
sl@0
  1591
* @param aFileSize
sl@0
  1592
* @precondition 
sl@0
  1593
* The argument aFileSize must be greater than -1
sl@0
  1594
* zero is used as a sentinel value which means that the file
sl@0
  1595
* can grow without limit
sl@0
  1596
*/
sl@0
  1597
void CMMFTestUseOldCodecAudioController::MarcSetMaxFileSizeL(TInt aFileSize )
sl@0
  1598
	{
sl@0
  1599
	//[ assert the invariant ]
sl@0
  1600
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1601
sl@0
  1602
	//[ assert the state is not playing since this opens open 
sl@0
  1603
	// nefarious posibilities
sl@0
  1604
	if(State() == EPlaying )
sl@0
  1605
		User::Leave( KErrNotReady );
sl@0
  1606
	
sl@0
  1607
	//[ assert we have a sink format ]
sl@0
  1608
	if( !iSinkFormat )
sl@0
  1609
		User::Leave( KErrNotReady );
sl@0
  1610
sl@0
  1611
	//[ assert file size > -1, as a basic sanity filter
sl@0
  1612
	// 0 is the sentinel value which allows a file to grow
sl@0
  1613
	// as needed ]
sl@0
  1614
	if( aFileSize < 0 )
sl@0
  1615
		User::Leave( KErrArgument );
sl@0
  1616
sl@0
  1617
    //[ pre condition is that we have a sink ]
sl@0
  1618
    STATIC_CAST(CMMFFormatEncode*, iSinkFormat)->SetMaximumClipSizeL( aFileSize );
sl@0
  1619
sl@0
  1620
	// [ assert the post condition ]
sl@0
  1621
	// [since we have no means of querying the value
sl@0
  1622
	// we have to assume all went well for now or we left]
sl@0
  1623
sl@0
  1624
	//[ assert the invariant ]
sl@0
  1625
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1626
	}
sl@0
  1627
sl@0
  1628
/**
sl@0
  1629
* MarcCropL
sl@0
  1630
* @param aToEnd
sl@0
  1631
*/
sl@0
  1632
void CMMFTestUseOldCodecAudioController::MarcCropL(TBool aToEnd)
sl@0
  1633
	{
sl@0
  1634
	//[ assert the invariant ]
sl@0
  1635
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1636
sl@0
  1637
	//[ precondition there is a sink format]
sl@0
  1638
	if (!iSinkFormat)
sl@0
  1639
		User::Leave(KErrNotSupported);
sl@0
  1640
sl@0
  1641
	iSinkFormat->CropL( PositionL(), aToEnd );
sl@0
  1642
sl@0
  1643
	//[ assert the invariant ]
sl@0
  1644
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1645
	}
sl@0
  1646
sl@0
  1647
/**
sl@0
  1648
* MarcAddMetaDataEntryL
sl@0
  1649
* @param aNewEntry
sl@0
  1650
*/
sl@0
  1651
void CMMFTestUseOldCodecAudioController::MarcAddMetaDataEntryL(const CMMFMetaDataEntry& aNewEntry )
sl@0
  1652
	{
sl@0
  1653
	//[ assert the invariant ]
sl@0
  1654
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1655
sl@0
  1656
	//[ precondition the format exists ]
sl@0
  1657
	if( !iSinkFormat )
sl@0
  1658
		User::Leave(KErrNotSupported);
sl@0
  1659
sl@0
  1660
	//[ Add the meta data entry ]
sl@0
  1661
	iSinkFormat->AddMetaDataEntryL( aNewEntry );
sl@0
  1662
sl@0
  1663
	//[ assert the invariant ]
sl@0
  1664
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1665
sl@0
  1666
	}
sl@0
  1667
sl@0
  1668
/**
sl@0
  1669
* MarcRemoveMetaDataEntryL
sl@0
  1670
* @param aIndex
sl@0
  1671
*/
sl@0
  1672
void CMMFTestUseOldCodecAudioController::MarcRemoveMetaDataEntryL(TInt aIndex)
sl@0
  1673
	{
sl@0
  1674
	//[ assert the invariant ]
sl@0
  1675
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1676
sl@0
  1677
	//[ precondition that we are in the primed state ]
sl@0
  1678
	if( State() != EPrimed)
sl@0
  1679
		User::Leave(KErrNotReady);
sl@0
  1680
sl@0
  1681
    //[ precondition the format exists ]
sl@0
  1682
	if( !iSinkFormat )
sl@0
  1683
		User::Leave(KErrNotSupported);
sl@0
  1684
sl@0
  1685
	//[ remove the meta data entry ]
sl@0
  1686
	iSinkFormat->RemoveMetaDataEntry( aIndex );
sl@0
  1687
sl@0
  1688
	//[ assert the invariant ]
sl@0
  1689
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1690
sl@0
  1691
	}
sl@0
  1692
sl@0
  1693
/**
sl@0
  1694
* MarcReplaceMetaDataEntryL
sl@0
  1695
* @param aIndex
sl@0
  1696
* @param aNewEntry
sl@0
  1697
*/
sl@0
  1698
void CMMFTestUseOldCodecAudioController::MarcReplaceMetaDataEntryL(TInt aIndex, const CMMFMetaDataEntry& aNewEntry)
sl@0
  1699
	{
sl@0
  1700
	//[ assert the invariant ]
sl@0
  1701
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1702
sl@0
  1703
	//[ precondition that we are in the primed state ]
sl@0
  1704
	if( State() != EPrimed)
sl@0
  1705
		User::Leave(KErrNotReady);
sl@0
  1706
sl@0
  1707
   	//[ precondition the format exists ]
sl@0
  1708
	if( !iSinkFormat )
sl@0
  1709
		User::Leave(KErrNotSupported);
sl@0
  1710
sl@0
  1711
	//[ replace meta data entry ]
sl@0
  1712
	iSinkFormat->ReplaceMetaDataEntryL( aIndex, aNewEntry );
sl@0
  1713
sl@0
  1714
	//[ assert the invariant ]
sl@0
  1715
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1716
sl@0
  1717
	}
sl@0
  1718
sl@0
  1719
/**
sl@0
  1720
* MacSetSourceSampleRateL
sl@0
  1721
* @param aSampleRate
sl@0
  1722
*/
sl@0
  1723
void CMMFTestUseOldCodecAudioController::MacSetSourceSampleRateL(TUint aSampleRate)
sl@0
  1724
	{
sl@0
  1725
	// [ assert the invariant ]
sl@0
  1726
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  1727
	
sl@0
  1728
	// [ assert the precondition we are stopped ]
sl@0
  1729
	if( State() != EStopped )
sl@0
  1730
		User::Leave(KErrNotReady);
sl@0
  1731
sl@0
  1732
sl@0
  1733
	if (iSourceFormat)
sl@0
  1734
		{//only applicable to formats
sl@0
  1735
		// don't throw an error if the clip already exists with a different sample rate
sl@0
  1736
		TInt error = iSourceFormat->SetSampleRate(aSampleRate);
sl@0
  1737
		if (error != KErrNone && error != KErrAlreadyExists)
sl@0
  1738
			User::Leave(error);
sl@0
  1739
		}
sl@0
  1740
	else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput))
sl@0
  1741
		{
sl@0
  1742
		// cast iDataSource to audio input and set sample rate
sl@0
  1743
		MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource);
sl@0
  1744
		
sl@0
  1745
		//note that it is safe to call SoundDevice()
sl@0
  1746
		//as the controller logs onto the iDataSource when it is added
sl@0
  1747
		TMMFCapabilities devSoundConfig = ai->SoundDevice().Config();
sl@0
  1748
sl@0
  1749
		ConvertFromSampleRateToDevSoundCapsL(aSampleRate, devSoundConfig);
sl@0
  1750
		ai->SoundDevice().SetConfigL(devSoundConfig);
sl@0
  1751
		//ReNegotiateL();
sl@0
  1752
		}
sl@0
  1753
	else 
sl@0
  1754
		User::Leave(KErrNotSupported);
sl@0
  1755
sl@0
  1756
	// [assert the post condition ]
sl@0
  1757
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  1758
sl@0
  1759
	}
sl@0
  1760
sl@0
  1761
/**
sl@0
  1762
* MacSetSourceNumChannelsL
sl@0
  1763
* @param aNumChannels
sl@0
  1764
*/
sl@0
  1765
void CMMFTestUseOldCodecAudioController::MacSetSourceNumChannelsL(TUint aNumChannels)
sl@0
  1766
	{
sl@0
  1767
	// [ assert the invariant ]
sl@0
  1768
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  1769
  
sl@0
  1770
	// [assert the precondition that we are stopped ]
sl@0
  1771
	if( State() != EStopped )
sl@0
  1772
		User::Leave(KErrNotReady);
sl@0
  1773
sl@0
  1774
	if (iSourceFormat)
sl@0
  1775
		{//only applicable to formats
sl@0
  1776
		// don't throw an error if the clip already exists with a different number of channels
sl@0
  1777
		TInt error = iSourceFormat->SetNumChannels(aNumChannels);
sl@0
  1778
		if (error != KErrNone && error != KErrAlreadyExists)
sl@0
  1779
			User::Leave(error);
sl@0
  1780
		}
sl@0
  1781
	else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput))
sl@0
  1782
		{
sl@0
  1783
		// cast iDataSource to audio input and set num channels
sl@0
  1784
		MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource);
sl@0
  1785
sl@0
  1786
		//note that it is safe to call SoundDevice()
sl@0
  1787
		//as the controller logs onto the iDataSource when it is added
sl@0
  1788
		TMMFCapabilities devSoundConfig = ai->SoundDevice().Config();
sl@0
  1789
sl@0
  1790
		ConvertFromNumChannelsToDevSoundCapsL(aNumChannels, devSoundConfig);
sl@0
  1791
		ai->SoundDevice().SetConfigL(devSoundConfig);
sl@0
  1792
		//ReNegotiateL();
sl@0
  1793
		}
sl@0
  1794
	else 
sl@0
  1795
		User::Leave(KErrNotSupported);
sl@0
  1796
	
sl@0
  1797
	// [ assert the invariant ]
sl@0
  1798
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); 
sl@0
  1799
sl@0
  1800
	}
sl@0
  1801
sl@0
  1802
/**
sl@0
  1803
* MacSetSourceFormatL
sl@0
  1804
* @param aFormatUid
sl@0
  1805
*
sl@0
  1806
*/
sl@0
  1807
void CMMFTestUseOldCodecAudioController::MacSetSourceFormatL(TUid aFormatUid)
sl@0
  1808
	{
sl@0
  1809
     //[ assert the invaraint ]
sl@0
  1810
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); 
sl@0
  1811
	
sl@0
  1812
	// [ precondition that the controller is stopped ]
sl@0
  1813
    if( State() != EStopped )
sl@0
  1814
		User::Leave( KErrNotReady );
sl@0
  1815
sl@0
  1816
	//[ precondition that the data source exists]
sl@0
  1817
	if (!iDataSource)
sl@0
  1818
		User::Leave(KErrNotReady);
sl@0
  1819
	
sl@0
  1820
	//[ precondition that we need a format ]
sl@0
  1821
	if( !SourceFormatRequired( *iDataSource ) )
sl@0
  1822
		User::Leave(KErrNotSupported); //cant set source format if source isn't a clip
sl@0
  1823
sl@0
  1824
	//[ if the format exists and the uid of the requested
sl@0
  1825
	//	format is the same as the existing format then simply 
sl@0
  1826
	// return otherwise create a new format ]
sl@0
  1827
	if( !((iSourceFormat) && ( iSourceFormat->ImplementationUid() == aFormatUid)))
sl@0
  1828
		{
sl@0
  1829
		// [ delete the old format regardless ]
sl@0
  1830
		delete iSourceFormat;
sl@0
  1831
		iSourceFormat = NULL;
sl@0
  1832
		iSourceFormat = CMMFFormatDecode::NewL(aFormatUid, iDataSource);
sl@0
  1833
		}
sl@0
  1834
sl@0
  1835
	//[ assert the invariant ]
sl@0
  1836
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant)); 
sl@0
  1837
sl@0
  1838
	//[ assert the post condition that a source format has been constructed ]
sl@0
  1839
	__ASSERT_ALWAYS( (iSourceFormat != NULL), Panic( EPostConditionViolation ));
sl@0
  1840
	}
sl@0
  1841
sl@0
  1842
/**
sl@0
  1843
* MacSetSinkSampleRateL
sl@0
  1844
* @param aSampleRate
sl@0
  1845
*/
sl@0
  1846
void CMMFTestUseOldCodecAudioController::MacSetSinkSampleRateL(TUint aSampleRate)
sl@0
  1847
	{
sl@0
  1848
	//[ assert the invariant ]
sl@0
  1849
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  1850
sl@0
  1851
	// [ assert the precondition that we are stopped ]
sl@0
  1852
	if (State() != EStopped )
sl@0
  1853
		User::Leave(KErrNotReady);
sl@0
  1854
sl@0
  1855
	if (iSinkFormat)
sl@0
  1856
		{//only applicable to formats
sl@0
  1857
		// don't throw an error if the clip already exists with a different sample rate
sl@0
  1858
		TInt error = iSinkFormat->SetSampleRate(aSampleRate);
sl@0
  1859
		if (error != KErrNone && error != KErrAlreadyExists)
sl@0
  1860
			User::Leave(error);
sl@0
  1861
		}
sl@0
  1862
	else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
sl@0
  1863
		{
sl@0
  1864
		// cast iDataSink to audio output and set sample rate
sl@0
  1865
		MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink);
sl@0
  1866
sl@0
  1867
sl@0
  1868
sl@0
  1869
		TMMFCapabilities devSoundConfig = ao->SoundDevice().Config();
sl@0
  1870
		ConvertFromSampleRateToDevSoundCapsL(aSampleRate, devSoundConfig);
sl@0
  1871
		ao->SoundDevice().SetConfigL(devSoundConfig);
sl@0
  1872
		}
sl@0
  1873
	else 
sl@0
  1874
		User::Leave(KErrNotSupported);
sl@0
  1875
sl@0
  1876
	//[ assert the invariant ]
sl@0
  1877
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  1878
	}
sl@0
  1879
sl@0
  1880
/**
sl@0
  1881
* MacSetSinkNumChannelsL
sl@0
  1882
* @param aNumChannels
sl@0
  1883
*
sl@0
  1884
*/
sl@0
  1885
void CMMFTestUseOldCodecAudioController::MacSetSinkNumChannelsL(TUint aNumChannels)
sl@0
  1886
	{
sl@0
  1887
	//[ assert the invariant ]
sl@0
  1888
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  1889
sl@0
  1890
	// [ assert the precondition that we are stopped ]
sl@0
  1891
	if (State() != EStopped )
sl@0
  1892
		User::Leave(KErrNotReady);
sl@0
  1893
sl@0
  1894
	if (iSinkFormat)
sl@0
  1895
		{//only applicable to formats
sl@0
  1896
		// don't throw an error if the clip already exists with a different number of channels
sl@0
  1897
		TInt error = iSinkFormat->SetNumChannels(aNumChannels);
sl@0
  1898
		if (error != KErrNone && error != KErrAlreadyExists)
sl@0
  1899
			User::Leave(error);
sl@0
  1900
		}
sl@0
  1901
	else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
sl@0
  1902
		{
sl@0
  1903
		// cast iDataSink to audio output and set num channels
sl@0
  1904
		MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink);
sl@0
  1905
sl@0
  1906
		//note that it is safe to call SoundDevice()
sl@0
  1907
		//as the controller logs onto the iDataSource when it is added
sl@0
  1908
		TMMFCapabilities devSoundConfig = ao->SoundDevice().Config();
sl@0
  1909
		ConvertFromNumChannelsToDevSoundCapsL(aNumChannels, devSoundConfig);
sl@0
  1910
		ao->SoundDevice().SetConfigL(devSoundConfig);
sl@0
  1911
		}
sl@0
  1912
	else 
sl@0
  1913
		User::Leave(KErrNotSupported);
sl@0
  1914
sl@0
  1915
	// [assert the invariant ]
sl@0
  1916
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  1917
sl@0
  1918
	}
sl@0
  1919
sl@0
  1920
/**
sl@0
  1921
* MacSetSinkFormatL 
sl@0
  1922
* @param aFormatUid
sl@0
  1923
*
sl@0
  1924
*/
sl@0
  1925
void CMMFTestUseOldCodecAudioController::MacSetSinkFormatL(TUid aFormatUid)
sl@0
  1926
	{
sl@0
  1927
    //[ assert the invariant ]
sl@0
  1928
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  1929
sl@0
  1930
	// [ precondition that the controller is stopped ]
sl@0
  1931
    if( State() != EStopped )
sl@0
  1932
		User::Leave( KErrNotReady );
sl@0
  1933
sl@0
  1934
	//[ precondition that the data sink exists]
sl@0
  1935
	if (!iDataSink)
sl@0
  1936
		User::Leave(KErrNotReady);
sl@0
  1937
sl@0
  1938
	//[ precondition that we need a format ]
sl@0
  1939
	if (!SinkFormatRequired( *iDataSink))
sl@0
  1940
		User::Leave(KErrNotSupported);
sl@0
  1941
sl@0
  1942
	//[ if the format exists and the uid of the requested
sl@0
  1943
	//	format is the same as the existing format then simply 
sl@0
  1944
	// return ]
sl@0
  1945
	if( !((iSinkFormat) && ( iSinkFormat->ImplementationUid() == aFormatUid)))
sl@0
  1946
		{
sl@0
  1947
		// [ delete the old format regardless ]
sl@0
  1948
		delete iSinkFormat;
sl@0
  1949
		iSinkFormat = NULL;
sl@0
  1950
		iSinkFormat = CMMFFormatEncode::NewL(aFormatUid, iDataSink);
sl@0
  1951
		}
sl@0
  1952
sl@0
  1953
	//[ assert the invariant ]
sl@0
  1954
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  1955
sl@0
  1956
	//[ assert the post condition that a sink format has been constructed ]
sl@0
  1957
	__ASSERT_ALWAYS( (iSinkFormat != NULL), Panic( EPostConditionViolation ));
sl@0
  1958
	}
sl@0
  1959
sl@0
  1960
sl@0
  1961
/**
sl@0
  1962
* MacSetCodecL
sl@0
  1963
* @param aSourceDataType
sl@0
  1964
* @param aSinkDataType
sl@0
  1965
*
sl@0
  1966
*/
sl@0
  1967
void CMMFTestUseOldCodecAudioController::MacSetCodecL(TFourCC aSourceDataType, TFourCC aSinkDataType)
sl@0
  1968
	{
sl@0
  1969
	//[ assert the invariant ]
sl@0
  1970
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  1971
sl@0
  1972
	//[ assert the precondition ]
sl@0
  1973
	if(State() != EStopped)
sl@0
  1974
		User::Leave(KErrNotReady);
sl@0
  1975
sl@0
  1976
	//don't set codec directly  -just set source & sink fourCC codes
sl@0
  1977
	//[  ]
sl@0
  1978
	TInt error(KErrNone);
sl@0
  1979
	if ((iSinkFormat)&&(aSinkDataType != KMMFFourCCCodeNULL))
sl@0
  1980
		{
sl@0
  1981
		error = iSinkFormat->SetSinkDataTypeCode(aSinkDataType,iMediaId);
sl@0
  1982
		}
sl@0
  1983
	else if((iDataSink) && (aSinkDataType != KMMFFourCCCodeNULL))
sl@0
  1984
		{
sl@0
  1985
		error = iDataSink->SetSinkDataTypeCode(aSinkDataType,iMediaId);
sl@0
  1986
		}
sl@0
  1987
	if ((iSourceFormat)&&(!error)&&(aSourceDataType != KMMFFourCCCodeNULL))
sl@0
  1988
		{
sl@0
  1989
		error = iSourceFormat->SetSourceDataTypeCode(aSourceDataType,iMediaId);
sl@0
  1990
		}
sl@0
  1991
	else if ((iDataSource) && (aSourceDataType != KMMFFourCCCodeNULL))
sl@0
  1992
		{
sl@0
  1993
		error = iDataSource->SetSourceDataTypeCode(aSourceDataType,iMediaId);
sl@0
  1994
		}
sl@0
  1995
sl@0
  1996
	//[ leave if we are not ready or there was an error ]
sl@0
  1997
	User::LeaveIfError(error);
sl@0
  1998
sl@0
  1999
	//[ assert the invariant ]
sl@0
  2000
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  2001
	}
sl@0
  2002
sl@0
  2003
/**
sl@0
  2004
* MacSetSourceBitRateL
sl@0
  2005
* @param "TUint"
sl@0
  2006
* Sets the source bit rate
sl@0
  2007
*
sl@0
  2008
*/
sl@0
  2009
void CMMFTestUseOldCodecAudioController::MacSetSourceBitRateL(TUint aBitRate)
sl@0
  2010
	{
sl@0
  2011
	//[ assert the invariant ]
sl@0
  2012
	__ASSERT_ALWAYS( Invariant(), Panic(EBadInvariant));
sl@0
  2013
sl@0
  2014
	//[ assert the precondition ]
sl@0
  2015
	if(State() != EStopped)
sl@0
  2016
		User::Leave(KErrNotReady);
sl@0
  2017
sl@0
  2018
	//[ pre condition  that we have a source format]
sl@0
  2019
	if (!iSourceFormat)
sl@0
  2020
		User::Leave(KErrNotSupported);
sl@0
  2021
sl@0
  2022
	//only applicable to formats
sl@0
  2023
	User::LeaveIfError(iSourceFormat->SetBitRate(aBitRate));
sl@0
  2024
sl@0
  2025
	//[ assert the set bit rate is the bit rate ]
sl@0
  2026
	__ASSERT_ALWAYS( (aBitRate == iSourceFormat->BitRate()), Panic( EPostConditionViolation ));
sl@0
  2027
		
sl@0
  2028
	//[ assert the invariant ]
sl@0
  2029
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  2030
	}
sl@0
  2031
sl@0
  2032
sl@0
  2033
/**
sl@0
  2034
*
sl@0
  2035
* MacSetSourceDataTypeL
sl@0
  2036
* @param "TFourCC"
sl@0
  2037
*
sl@0
  2038
*/
sl@0
  2039
void CMMFTestUseOldCodecAudioController::MacSetSourceDataTypeL(TFourCC aDataType)
sl@0
  2040
	{
sl@0
  2041
	MacSetCodecL(aDataType, KMMFFourCCCodeNULL);
sl@0
  2042
	}
sl@0
  2043
sl@0
  2044
/**
sl@0
  2045
*
sl@0
  2046
* MacSetSinkBitRateL
sl@0
  2047
* @param "TUint"
sl@0
  2048
*
sl@0
  2049
*/
sl@0
  2050
void CMMFTestUseOldCodecAudioController::MacSetSinkBitRateL(TUint aRate)
sl@0
  2051
	{
sl@0
  2052
	//[ assert the invariant ]
sl@0
  2053
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  2054
sl@0
  2055
    // [ assert we are stopped ]
sl@0
  2056
	if( State() != EStopped)
sl@0
  2057
		User::Leave( KErrNotReady );
sl@0
  2058
sl@0
  2059
	//[ pre condition we have a sink format ]
sl@0
  2060
	if (!iSinkFormat)
sl@0
  2061
		User::Leave(KErrNotSupported);
sl@0
  2062
sl@0
  2063
	//only applicable to formats
sl@0
  2064
	User::LeaveIfError(iSinkFormat->SetBitRate(aRate));
sl@0
  2065
sl@0
  2066
	//[ assert the set bit rate is the bit rate ]
sl@0
  2067
	__ASSERT_ALWAYS( (aRate == iSinkFormat->BitRate()), Panic( EBadInvariant));
sl@0
  2068
sl@0
  2069
	//[ assert the invariant ]
sl@0
  2070
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  2071
	}
sl@0
  2072
sl@0
  2073
/**
sl@0
  2074
*
sl@0
  2075
* MacSetSinkDataTypeL
sl@0
  2076
* @param "TFourCC"
sl@0
  2077
*
sl@0
  2078
*/
sl@0
  2079
void CMMFTestUseOldCodecAudioController::MacSetSinkDataTypeL(TFourCC aDataType)
sl@0
  2080
	{
sl@0
  2081
	MacSetCodecL(KMMFFourCCCodeNULL, aDataType);
sl@0
  2082
sl@0
  2083
	if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
sl@0
  2084
		{
sl@0
  2085
		MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink);
sl@0
  2086
		TMMFCapabilities devSoundConfig = ao->SoundDevice().Config();
sl@0
  2087
		RArray<TFourCC> dataTypes;
sl@0
  2088
		CleanupClosePushL(dataTypes);		
sl@0
  2089
		
sl@0
  2090
		//[ set dev sound data type here ]
sl@0
  2091
		ConvertFromDataTypeToDevSoundCapsL(aDataType, devSoundConfig);
sl@0
  2092
		ao->SoundDevice().SetConfigL(devSoundConfig);
sl@0
  2093
		CleanupStack::PopAndDestroy();//dataTypes
sl@0
  2094
		}
sl@0
  2095
	}
sl@0
  2096
sl@0
  2097
/**
sl@0
  2098
*
sl@0
  2099
* MacGetSourceSampleRateL
sl@0
  2100
* @param "TUint"
sl@0
  2101
* 
sl@0
  2102
*/
sl@0
  2103
void CMMFTestUseOldCodecAudioController::MacGetSourceSampleRateL(TUint& aRate)
sl@0
  2104
	{
sl@0
  2105
	//[ assert the invariant ]
sl@0
  2106
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  2107
sl@0
  2108
	//[ precondition is that we have a source format ||
sl@0
  2109
	// we have a data source and its an audio input ]
sl@0
  2110
	if( !((iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput)) ||
sl@0
  2111
		( iSourceFormat )))
sl@0
  2112
		User::Leave(KErrNotSupported);
sl@0
  2113
	
sl@0
  2114
	if (iSourceFormat)
sl@0
  2115
		{
sl@0
  2116
		aRate = iSourceFormat->SampleRate();
sl@0
  2117
		}
sl@0
  2118
	else
sl@0
  2119
		{
sl@0
  2120
		// cast iDataSource to audio input and query sample rate
sl@0
  2121
		MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource);
sl@0
  2122
		TMMFCapabilities devSoundConfig = ai->SoundDevice().Config();
sl@0
  2123
		RArray<TUint> rates;
sl@0
  2124
		CleanupClosePushL(rates);
sl@0
  2125
		ConvertFromDevSoundCapsToSampleRatesL(devSoundConfig, rates);
sl@0
  2126
		ASSERT(rates.Count()==1);//make sure we've been given the correct config by devsound
sl@0
  2127
		aRate = rates[0];
sl@0
  2128
		CleanupStack::PopAndDestroy();//rates
sl@0
  2129
		}
sl@0
  2130
sl@0
  2131
	//[ assert the invariant ]
sl@0
  2132
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  2133
	}
sl@0
  2134
sl@0
  2135
/**
sl@0
  2136
*
sl@0
  2137
* MacGetSourceBitRateL
sl@0
  2138
* @param "TUint"
sl@0
  2139
*
sl@0
  2140
*/
sl@0
  2141
void CMMFTestUseOldCodecAudioController::MacGetSourceBitRateL(TUint& aRate)
sl@0
  2142
	{
sl@0
  2143
	//[ assert the invariant ]
sl@0
  2144
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  2145
sl@0
  2146
	// Can only query formats for bit rate - devsound doesn't do bit rates.
sl@0
  2147
	if (!iSourceFormat)
sl@0
  2148
		User::Leave(KErrNotSupported);
sl@0
  2149
sl@0
  2150
	aRate = iSourceFormat->BitRate();
sl@0
  2151
	
sl@0
  2152
	//[ assert the invariant ]
sl@0
  2153
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  2154
	
sl@0
  2155
	}
sl@0
  2156
sl@0
  2157
/**
sl@0
  2158
*
sl@0
  2159
* MacGetSourceNumChannelsL
sl@0
  2160
* @param "TUint&"
sl@0
  2161
*
sl@0
  2162
*/
sl@0
  2163
void CMMFTestUseOldCodecAudioController::MacGetSourceNumChannelsL(TUint& aNumChannels)
sl@0
  2164
	{
sl@0
  2165
	//[ assert the invariant ]
sl@0
  2166
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  2167
sl@0
  2168
	//[ assert the precondition ]
sl@0
  2169
	if( !((iSourceFormat) ||
sl@0
  2170
		(iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput))))
sl@0
  2171
		User::Leave(KErrNotSupported);
sl@0
  2172
sl@0
  2173
	if (iSourceFormat)
sl@0
  2174
		{
sl@0
  2175
		aNumChannels = iSourceFormat->NumChannels();
sl@0
  2176
		}
sl@0
  2177
	else
sl@0
  2178
		{
sl@0
  2179
		// cast iDataSource to audio input and query num channels
sl@0
  2180
		MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource);
sl@0
  2181
		TMMFCapabilities devSoundConfig = ai->SoundDevice().Config();
sl@0
  2182
		RArray<TUint> numChannels;
sl@0
  2183
		CleanupClosePushL(numChannels);
sl@0
  2184
		ConvertFromDevSoundCapsToNumChannelsL(devSoundConfig, numChannels);
sl@0
  2185
		ASSERT(numChannels.Count()==1);
sl@0
  2186
		aNumChannels = numChannels[0];
sl@0
  2187
		CleanupStack::PopAndDestroy();//numChannels
sl@0
  2188
		}
sl@0
  2189
	
sl@0
  2190
	//[ assert the invariant ]
sl@0
  2191
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  2192
sl@0
  2193
	}
sl@0
  2194
sl@0
  2195
/**
sl@0
  2196
*
sl@0
  2197
* MacGetSourceFormatL
sl@0
  2198
* @param "TUid"
sl@0
  2199
*/
sl@0
  2200
void CMMFTestUseOldCodecAudioController::MacGetSourceFormatL(TUid& aFormat)
sl@0
  2201
	{
sl@0
  2202
	//[ assert the invariant ]
sl@0
  2203
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  2204
sl@0
  2205
	//[ precondition we have a format ]
sl@0
  2206
	if (!iSourceFormat)
sl@0
  2207
		User::Leave(KErrNotSupported);
sl@0
  2208
sl@0
  2209
	// [ get the source format uid ]
sl@0
  2210
	aFormat = iSourceFormat->ImplementationUid();
sl@0
  2211
sl@0
  2212
	//[ assert the invariant ]
sl@0
  2213
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant));
sl@0
  2214
	
sl@0
  2215
	}
sl@0
  2216
sl@0
  2217
/**
sl@0
  2218
*
sl@0
  2219
* MacGetSourceDataTypeL
sl@0
  2220
* @param "TFourCC&"
sl@0
  2221
*
sl@0
  2222
*/
sl@0
  2223
void CMMFTestUseOldCodecAudioController::MacGetSourceDataTypeL(TFourCC& aDataType)
sl@0
  2224
	{
sl@0
  2225
	if (iSourceFormat)
sl@0
  2226
		aDataType = iSourceFormat->SourceDataTypeCode(TMediaId(KUidMediaTypeAudio));
sl@0
  2227
	else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput))
sl@0
  2228
		{
sl@0
  2229
		// cast iDataSource to audio input and query num channels
sl@0
  2230
		MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource);
sl@0
  2231
		TMMFCapabilities devSoundConfig = ai->SoundDevice().Config();
sl@0
  2232
		RArray<TFourCC> dataTypes;
sl@0
  2233
		CleanupClosePushL(dataTypes);
sl@0
  2234
		ConvertFromDevSoundCapsToDataTypesL(devSoundConfig, dataTypes);
sl@0
  2235
		ASSERT(dataTypes.Count()==1);
sl@0
  2236
		aDataType = dataTypes[0];
sl@0
  2237
		CleanupStack::PopAndDestroy();//dataTypes
sl@0
  2238
		}
sl@0
  2239
	else
sl@0
  2240
		User::Leave(KErrNotSupported);
sl@0
  2241
	}
sl@0
  2242
sl@0
  2243
/**
sl@0
  2244
*
sl@0
  2245
* MacGetSinkSampleRateL
sl@0
  2246
* @param "TUint&"
sl@0
  2247
*
sl@0
  2248
*/
sl@0
  2249
sl@0
  2250
void CMMFTestUseOldCodecAudioController::MacGetSinkSampleRateL(TUint& aRate)
sl@0
  2251
	{
sl@0
  2252
	if (iSinkFormat)
sl@0
  2253
		aRate = iSinkFormat->SampleRate();
sl@0
  2254
	else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
sl@0
  2255
		{
sl@0
  2256
		// cast iDataSink to audio output and query sample rate
sl@0
  2257
		MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink);
sl@0
  2258
		TMMFCapabilities devSoundConfig = ao->SoundDevice().Config();
sl@0
  2259
		RArray<TUint> rates;
sl@0
  2260
		CleanupClosePushL(rates);
sl@0
  2261
		ConvertFromDevSoundCapsToSampleRatesL(devSoundConfig, rates);
sl@0
  2262
		ASSERT(rates.Count()==1);//make sure we've been given the correct config by devsound
sl@0
  2263
		aRate = rates[0];
sl@0
  2264
		CleanupStack::PopAndDestroy();//rates
sl@0
  2265
		}
sl@0
  2266
	else
sl@0
  2267
		User::Leave(KErrNotSupported);
sl@0
  2268
	}
sl@0
  2269
sl@0
  2270
/**
sl@0
  2271
*
sl@0
  2272
* MacGetSinkBitRateL
sl@0
  2273
* @param "TUint&"
sl@0
  2274
*
sl@0
  2275
*/
sl@0
  2276
void CMMFTestUseOldCodecAudioController::MacGetSinkBitRateL(TUint& aRate)
sl@0
  2277
	{
sl@0
  2278
	if (iSinkFormat)
sl@0
  2279
		aRate = iSinkFormat->BitRate();
sl@0
  2280
	else
sl@0
  2281
		User::Leave(KErrNotSupported);
sl@0
  2282
	}
sl@0
  2283
sl@0
  2284
/**
sl@0
  2285
*
sl@0
  2286
* MacGetSinkNumChannelsL
sl@0
  2287
* @param "TUint&"
sl@0
  2288
*
sl@0
  2289
*/
sl@0
  2290
void CMMFTestUseOldCodecAudioController::MacGetSinkNumChannelsL(TUint& aNumChannels)
sl@0
  2291
	{
sl@0
  2292
	if (iSinkFormat)
sl@0
  2293
		aNumChannels = iSinkFormat->NumChannels();
sl@0
  2294
	else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
sl@0
  2295
		{
sl@0
  2296
		// cast iDataSink to audio output and query num channels
sl@0
  2297
		MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink);
sl@0
  2298
		TMMFCapabilities devSoundConfig = ao->SoundDevice().Config();
sl@0
  2299
		RArray<TUint> numChannels;
sl@0
  2300
		CleanupClosePushL(numChannels);
sl@0
  2301
		ConvertFromDevSoundCapsToNumChannelsL(devSoundConfig, numChannels);
sl@0
  2302
		ASSERT(numChannels.Count()==1);
sl@0
  2303
		aNumChannels = numChannels[0];
sl@0
  2304
		CleanupStack::PopAndDestroy();//numChannels
sl@0
  2305
		}
sl@0
  2306
	else
sl@0
  2307
		User::Leave(KErrNotSupported);
sl@0
  2308
	}
sl@0
  2309
sl@0
  2310
/**
sl@0
  2311
*
sl@0
  2312
* MacGetSinkFormatL
sl@0
  2313
* @param "TUid&"
sl@0
  2314
*
sl@0
  2315
*/
sl@0
  2316
void CMMFTestUseOldCodecAudioController::MacGetSinkFormatL(TUid& aFormat)
sl@0
  2317
	{
sl@0
  2318
	if (iSinkFormat)
sl@0
  2319
		aFormat = iSinkFormat->ImplementationUid();
sl@0
  2320
	else 
sl@0
  2321
		User::Leave(KErrNotSupported);
sl@0
  2322
	}
sl@0
  2323
sl@0
  2324
/**
sl@0
  2325
*
sl@0
  2326
* MacGetSinkDataTypeL
sl@0
  2327
* @param "TFourCC&"
sl@0
  2328
*
sl@0
  2329
*/
sl@0
  2330
void CMMFTestUseOldCodecAudioController::MacGetSinkDataTypeL(TFourCC& aDataType)
sl@0
  2331
	{
sl@0
  2332
	if (iSinkFormat)
sl@0
  2333
		aDataType = iSinkFormat->SinkDataTypeCode(TMediaId(KUidMediaTypeAudio));
sl@0
  2334
	else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
sl@0
  2335
		{
sl@0
  2336
		// cast iDataSink to audio output and query data type
sl@0
  2337
		MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink);
sl@0
  2338
		TMMFCapabilities devSoundConfig = ao->SoundDevice().Config();
sl@0
  2339
		RArray<TFourCC> dataTypes;
sl@0
  2340
		CleanupClosePushL(dataTypes);
sl@0
  2341
		ConvertFromDevSoundCapsToDataTypesL(devSoundConfig, dataTypes);
sl@0
  2342
		ASSERT(dataTypes.Count()==1);
sl@0
  2343
		aDataType = dataTypes[0];
sl@0
  2344
		CleanupStack::PopAndDestroy();//dataTypes
sl@0
  2345
		}
sl@0
  2346
	else
sl@0
  2347
		User::Leave(KErrNotSupported);
sl@0
  2348
	}
sl@0
  2349
sl@0
  2350
/**
sl@0
  2351
* 
sl@0
  2352
* MacGetSupportedSourceSampleRatesL
sl@0
  2353
* @param "RArray<TUint>&"
sl@0
  2354
* 
sl@0
  2355
*/
sl@0
  2356
void CMMFTestUseOldCodecAudioController::MacGetSupportedSourceSampleRatesL(RArray<TUint>& aSupportedRates)
sl@0
  2357
	{
sl@0
  2358
	aSupportedRates.Reset();
sl@0
  2359
	if (iSourceFormat)
sl@0
  2360
		iSourceFormat->GetSupportedSampleRatesL(aSupportedRates);
sl@0
  2361
	else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput))
sl@0
  2362
		{
sl@0
  2363
		// cast iDataSource to audio input and query supported sample rates
sl@0
  2364
		MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource);
sl@0
  2365
		TMMFCapabilities devSoundConfig = ai->SoundDevice().Capabilities();
sl@0
  2366
		ConvertFromDevSoundCapsToSampleRatesL(devSoundConfig, aSupportedRates);
sl@0
  2367
		}
sl@0
  2368
	else
sl@0
  2369
		User::Leave(KErrNotSupported);
sl@0
  2370
	}
sl@0
  2371
sl@0
  2372
/**
sl@0
  2373
*
sl@0
  2374
* MacGetSupportedSourceBitRatesL
sl@0
  2375
* @param "RArray<TUint>&"
sl@0
  2376
*
sl@0
  2377
*/
sl@0
  2378
void CMMFTestUseOldCodecAudioController::MacGetSupportedSourceBitRatesL(RArray<TUint>& aSupportedRates)
sl@0
  2379
	{
sl@0
  2380
	aSupportedRates.Reset();
sl@0
  2381
	if (iSourceFormat)
sl@0
  2382
		iSourceFormat->GetSupportedBitRatesL(aSupportedRates);
sl@0
  2383
	else
sl@0
  2384
		User::Leave(KErrNotSupported);
sl@0
  2385
	}
sl@0
  2386
sl@0
  2387
/***
sl@0
  2388
*
sl@0
  2389
* MacGetSupportedSourceNumChannelsL
sl@0
  2390
* @param "RArray<TUint>&"
sl@0
  2391
*
sl@0
  2392
*/
sl@0
  2393
void CMMFTestUseOldCodecAudioController::MacGetSupportedSourceNumChannelsL(RArray<TUint>& aSupportedChannels)
sl@0
  2394
	{
sl@0
  2395
	aSupportedChannels.Reset();
sl@0
  2396
	if (iSourceFormat)
sl@0
  2397
		iSourceFormat->GetSupportedNumChannelsL(aSupportedChannels);
sl@0
  2398
	else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput))
sl@0
  2399
		{
sl@0
  2400
		// cast iDataSource to audio input and query supported num channels
sl@0
  2401
		MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource);
sl@0
  2402
		TMMFCapabilities devSoundConfig = ai->SoundDevice().Capabilities();
sl@0
  2403
		ConvertFromDevSoundCapsToNumChannelsL(devSoundConfig, aSupportedChannels);
sl@0
  2404
		}
sl@0
  2405
	else
sl@0
  2406
		User::Leave(KErrNotSupported);
sl@0
  2407
	}
sl@0
  2408
sl@0
  2409
/***
sl@0
  2410
*
sl@0
  2411
* MacGetSupportedSourceDataTypesL
sl@0
  2412
* @param "RArray<TFourCC>&"
sl@0
  2413
*
sl@0
  2414
*/
sl@0
  2415
void CMMFTestUseOldCodecAudioController::MacGetSupportedSourceDataTypesL(RArray<TFourCC>& aSupportedDataTypes)
sl@0
  2416
	{
sl@0
  2417
	aSupportedDataTypes.Reset();
sl@0
  2418
	if (iSourceFormat)
sl@0
  2419
		iSourceFormat->GetSupportedDataTypesL(TMediaId(KUidMediaTypeAudio), aSupportedDataTypes);
sl@0
  2420
	else if (iDataSource && (iDataSource->DataSourceType()==KUidMmfAudioInput))
sl@0
  2421
		{
sl@0
  2422
		// cast iDataSource to audio input and query supported data types
sl@0
  2423
		MMMFAudioInput* ai = STATIC_CAST(MMMFAudioInput*, iDataSource);
sl@0
  2424
		TMMFCapabilities devSoundConfig = ai->SoundDevice().Capabilities();
sl@0
  2425
		ConvertFromDevSoundCapsToDataTypesL(devSoundConfig, aSupportedDataTypes);
sl@0
  2426
		}
sl@0
  2427
	else
sl@0
  2428
		User::Leave(KErrNotSupported);
sl@0
  2429
	}
sl@0
  2430
sl@0
  2431
/***
sl@0
  2432
*
sl@0
  2433
* MacGetSupportedSinkSampleRatesL
sl@0
  2434
* @param "RArray<TUint>& "
sl@0
  2435
*
sl@0
  2436
*/
sl@0
  2437
void CMMFTestUseOldCodecAudioController::MacGetSupportedSinkSampleRatesL(RArray<TUint>& aSupportedRates)
sl@0
  2438
	{
sl@0
  2439
	aSupportedRates.Reset();
sl@0
  2440
	if (iSinkFormat)
sl@0
  2441
		iSinkFormat->GetSupportedSampleRatesL(aSupportedRates);
sl@0
  2442
	else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
sl@0
  2443
		{
sl@0
  2444
		// cast iDataSink to audio output and query supported sample rates
sl@0
  2445
		MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink);
sl@0
  2446
		TMMFCapabilities devSoundConfig = ao->SoundDevice().Capabilities();
sl@0
  2447
		ConvertFromDevSoundCapsToSampleRatesL(devSoundConfig, aSupportedRates);
sl@0
  2448
		}
sl@0
  2449
	else
sl@0
  2450
		User::Leave(KErrNotSupported);
sl@0
  2451
	}
sl@0
  2452
sl@0
  2453
/***
sl@0
  2454
*
sl@0
  2455
* MacGetSupportedSinkBitRatesL
sl@0
  2456
* @param RArray<TUint>& 
sl@0
  2457
*
sl@0
  2458
*/
sl@0
  2459
void CMMFTestUseOldCodecAudioController::MacGetSupportedSinkBitRatesL(RArray<TUint>& aSupportedRates)
sl@0
  2460
	{
sl@0
  2461
	if (iSinkFormat)
sl@0
  2462
		iSinkFormat->GetSupportedBitRatesL(aSupportedRates);
sl@0
  2463
	else
sl@0
  2464
		User::Leave(KErrNotSupported);
sl@0
  2465
	}
sl@0
  2466
sl@0
  2467
/***
sl@0
  2468
*
sl@0
  2469
* MacGetSupportedSinkNumChannelsL
sl@0
  2470
* @param RArray<TUint>&
sl@0
  2471
*
sl@0
  2472
*/
sl@0
  2473
void CMMFTestUseOldCodecAudioController::MacGetSupportedSinkNumChannelsL(RArray<TUint>& aSupportedChannels)
sl@0
  2474
	{
sl@0
  2475
	aSupportedChannels.Reset();
sl@0
  2476
	if (iSinkFormat)
sl@0
  2477
		iSinkFormat->GetSupportedNumChannelsL(aSupportedChannels);
sl@0
  2478
	else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
sl@0
  2479
		{
sl@0
  2480
		// cast iDataSink to audio output and query supported channels
sl@0
  2481
		MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink);
sl@0
  2482
		TMMFCapabilities devSoundConfig = ao->SoundDevice().Capabilities();
sl@0
  2483
		ConvertFromDevSoundCapsToNumChannelsL(devSoundConfig, aSupportedChannels);
sl@0
  2484
		}
sl@0
  2485
	else
sl@0
  2486
		User::Leave(KErrNotSupported);
sl@0
  2487
	}
sl@0
  2488
sl@0
  2489
/***
sl@0
  2490
*
sl@0
  2491
* MacGetSupportedSinkDataTypesL
sl@0
  2492
* @param "RArray<TFourCC>&"
sl@0
  2493
*/
sl@0
  2494
void CMMFTestUseOldCodecAudioController::MacGetSupportedSinkDataTypesL(RArray<TFourCC>& aSupportedDataTypes)
sl@0
  2495
	{
sl@0
  2496
	aSupportedDataTypes.Reset();
sl@0
  2497
	if (iSinkFormat)
sl@0
  2498
		iSinkFormat->GetSupportedDataTypesL(TMediaId(KUidMediaTypeAudio), aSupportedDataTypes);
sl@0
  2499
	else if (iDataSink && (iDataSink->DataSinkType()==KUidMmfAudioOutput))
sl@0
  2500
		{
sl@0
  2501
		// cast iDataSink to audio output and query supported data types
sl@0
  2502
		MMMFAudioOutput* ao = STATIC_CAST(MMMFAudioOutput*, iDataSink);
sl@0
  2503
		TMMFCapabilities devSoundConfig = ao->SoundDevice().Capabilities();
sl@0
  2504
		ConvertFromDevSoundCapsToDataTypesL(devSoundConfig, aSupportedDataTypes);
sl@0
  2505
		}
sl@0
  2506
	else
sl@0
  2507
		User::Leave(KErrNotSupported);
sl@0
  2508
	}
sl@0
  2509
sl@0
  2510
/**
sl@0
  2511
*
sl@0
  2512
* ConvertFromDevSoundCapsToSampleRatesL
sl@0
  2513
* @param "const TMMFCapabilities& "
sl@0
  2514
* @param "RArray<TUint>&"
sl@0
  2515
*
sl@0
  2516
*/
sl@0
  2517
void CMMFTestUseOldCodecAudioController::ConvertFromDevSoundCapsToSampleRatesL(const TMMFCapabilities& aDevSoundCaps, RArray<TUint>& aSampleRates)
sl@0
  2518
	{
sl@0
  2519
	if (aDevSoundCaps.iRate & EMMFSampleRate8000Hz)
sl@0
  2520
		User::LeaveIfError(aSampleRates.Append(KSampleRate8000Hz));
sl@0
  2521
	if (aDevSoundCaps.iRate & EMMFSampleRate11025Hz)
sl@0
  2522
		User::LeaveIfError(aSampleRates.Append(KSampleRate11025Hz));
sl@0
  2523
	if (aDevSoundCaps.iRate & EMMFSampleRate16000Hz)
sl@0
  2524
		User::LeaveIfError(aSampleRates.Append(KSampleRate16000Hz));
sl@0
  2525
	if (aDevSoundCaps.iRate & EMMFSampleRate22050Hz)
sl@0
  2526
		User::LeaveIfError(aSampleRates.Append(KSampleRate22050Hz));
sl@0
  2527
	if (aDevSoundCaps.iRate & EMMFSampleRate32000Hz)
sl@0
  2528
		User::LeaveIfError(aSampleRates.Append(KSampleRate32000Hz));
sl@0
  2529
	if (aDevSoundCaps.iRate & EMMFSampleRate44100Hz)
sl@0
  2530
		User::LeaveIfError(aSampleRates.Append(KSampleRate44100Hz));
sl@0
  2531
	if (aDevSoundCaps.iRate & EMMFSampleRate48000Hz)
sl@0
  2532
		User::LeaveIfError(aSampleRates.Append(KSampleRate48000Hz));
sl@0
  2533
	if (aDevSoundCaps.iRate & EMMFSampleRate88200Hz)
sl@0
  2534
		User::LeaveIfError(aSampleRates.Append(KSampleRate88200Hz));
sl@0
  2535
	if (aDevSoundCaps.iRate & EMMFSampleRate96000Hz)
sl@0
  2536
		User::LeaveIfError(aSampleRates.Append(KSampleRate96000Hz));
sl@0
  2537
	}
sl@0
  2538
sl@0
  2539
/**
sl@0
  2540
*
sl@0
  2541
* ConvertFromDevSoundCapsToNumChannelsL
sl@0
  2542
* @param "const TMMFCapabilities&"
sl@0
  2543
* @param "RArray<TUint>&"
sl@0
  2544
*
sl@0
  2545
*/
sl@0
  2546
void CMMFTestUseOldCodecAudioController::ConvertFromDevSoundCapsToNumChannelsL(const TMMFCapabilities& aDevSoundCaps, RArray<TUint>& aNumChannels)
sl@0
  2547
	{
sl@0
  2548
	if (aDevSoundCaps.iChannels & EMMFMono)
sl@0
  2549
		User::LeaveIfError(aNumChannels.Append(KNumChannelsMono));
sl@0
  2550
	if (aDevSoundCaps.iChannels & EMMFStereo)
sl@0
  2551
		User::LeaveIfError(aNumChannels.Append(KNumChannelsStereo));
sl@0
  2552
	}
sl@0
  2553
sl@0
  2554
/**
sl@0
  2555
*
sl@0
  2556
* ConvertFromDevSoundCapsToDataTypesL
sl@0
  2557
* @param "const TMMFCapabilities&"
sl@0
  2558
* @param "TMMFCapabilities& aDevSoundCaps, RArray<TFourCC>&"
sl@0
  2559
*
sl@0
  2560
*/
sl@0
  2561
void CMMFTestUseOldCodecAudioController::ConvertFromDevSoundCapsToDataTypesL(const TMMFCapabilities& aDevSoundCaps, RArray<TFourCC>& aDataTypes)
sl@0
  2562
	{
sl@0
  2563
	if (aDevSoundCaps.iEncoding & EMMFSoundEncoding8BitPCM)
sl@0
  2564
		User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodePCM8));
sl@0
  2565
	if (aDevSoundCaps.iEncoding & EMMFSoundEncoding16BitPCM)
sl@0
  2566
		User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodePCM16));
sl@0
  2567
	if (aDevSoundCaps.iEncoding & EMMFSoundEncoding8BitALaw)
sl@0
  2568
		User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodeALAW));
sl@0
  2569
	if (aDevSoundCaps.iEncoding & EMMFSoundEncoding8BitMuLaw)
sl@0
  2570
		User::LeaveIfError(aDataTypes.Append(KMMFFourCCCodeMuLAW));
sl@0
  2571
	}
sl@0
  2572
sl@0
  2573
/**
sl@0
  2574
*
sl@0
  2575
* ConvertFromSampleRateToDevSoundCapsL
sl@0
  2576
* @param "TUint"
sl@0
  2577
* @param "TMMFCapabilities&"
sl@0
  2578
*
sl@0
  2579
*/
sl@0
  2580
void CMMFTestUseOldCodecAudioController::ConvertFromSampleRateToDevSoundCapsL(TUint aSampleRate, TMMFCapabilities& aDevSoundCaps)
sl@0
  2581
	{
sl@0
  2582
	if (aSampleRate == KSampleRate8000Hz)
sl@0
  2583
		aDevSoundCaps.iRate = EMMFSampleRate8000Hz;
sl@0
  2584
	else if (aSampleRate == KSampleRate11025Hz)
sl@0
  2585
		aDevSoundCaps.iRate = EMMFSampleRate11025Hz;
sl@0
  2586
	else if (aSampleRate == KSampleRate16000Hz)
sl@0
  2587
		aDevSoundCaps.iRate = EMMFSampleRate16000Hz;
sl@0
  2588
	else if (aSampleRate == KSampleRate22050Hz)
sl@0
  2589
		aDevSoundCaps.iRate = EMMFSampleRate22050Hz;
sl@0
  2590
	else if (aSampleRate == KSampleRate32000Hz)
sl@0
  2591
		aDevSoundCaps.iRate = EMMFSampleRate32000Hz;
sl@0
  2592
	else if (aSampleRate == KSampleRate44100Hz)
sl@0
  2593
		aDevSoundCaps.iRate = EMMFSampleRate44100Hz;
sl@0
  2594
	else if (aSampleRate == KSampleRate48000Hz)
sl@0
  2595
		aDevSoundCaps.iRate = EMMFSampleRate48000Hz;
sl@0
  2596
	else if (aSampleRate == KSampleRate88200Hz)
sl@0
  2597
		aDevSoundCaps.iRate = EMMFSampleRate88200Hz;
sl@0
  2598
	else if (aSampleRate == KSampleRate96000Hz)
sl@0
  2599
		aDevSoundCaps.iRate = EMMFSampleRate96000Hz;
sl@0
  2600
	else
sl@0
  2601
		User::Leave(KErrNotSupported);
sl@0
  2602
	}
sl@0
  2603
sl@0
  2604
/**
sl@0
  2605
*
sl@0
  2606
* ConvertFromNumChannelsToDevSoundCapsL
sl@0
  2607
* @param "TUint"
sl@0
  2608
* @param  "TMMFCapabilities&"
sl@0
  2609
*
sl@0
  2610
*/
sl@0
  2611
void CMMFTestUseOldCodecAudioController::ConvertFromNumChannelsToDevSoundCapsL(TUint aNumChannels, TMMFCapabilities& aDevSoundCaps)
sl@0
  2612
	{
sl@0
  2613
	if (aNumChannels == KNumChannelsMono)
sl@0
  2614
		aDevSoundCaps.iChannels = EMMFMono;
sl@0
  2615
	else if (aNumChannels == KNumChannelsStereo)
sl@0
  2616
		aDevSoundCaps.iChannels = EMMFStereo;
sl@0
  2617
	else
sl@0
  2618
		User::Leave(KErrNotSupported);
sl@0
  2619
	}
sl@0
  2620
sl@0
  2621
/**
sl@0
  2622
*
sl@0
  2623
* ConvertFromDataTypeToDevSoundCapsL
sl@0
  2624
* @param "TFourCC"
sl@0
  2625
* @param "TMMFCapabilities&"
sl@0
  2626
*
sl@0
  2627
*/
sl@0
  2628
void CMMFTestUseOldCodecAudioController::ConvertFromDataTypeToDevSoundCapsL(TFourCC aDataType, TMMFCapabilities& aDevSoundCaps)
sl@0
  2629
	{
sl@0
  2630
	if (aDataType == KMMFFourCCCodePCM8)
sl@0
  2631
		aDevSoundCaps.iEncoding = EMMFSoundEncoding8BitPCM;
sl@0
  2632
	else if (aDataType == KMMFFourCCCodePCM16)
sl@0
  2633
		aDevSoundCaps.iEncoding = EMMFSoundEncoding16BitPCM;
sl@0
  2634
	else if (aDataType == KMMFFourCCCodeALAW)
sl@0
  2635
		aDevSoundCaps.iEncoding = EMMFSoundEncoding8BitALaw;
sl@0
  2636
	else if (aDataType == KMMFFourCCCodeMuLAW)
sl@0
  2637
		aDevSoundCaps.iEncoding = EMMFSoundEncoding8BitMuLaw;
sl@0
  2638
	else
sl@0
  2639
		User::Leave(KErrNotSupported);
sl@0
  2640
	}
sl@0
  2641
sl@0
  2642
/**
sl@0
  2643
* IsValidStateTransition
sl@0
  2644
* The function validates a state transition from iState to aState
sl@0
  2645
* and returns ETrue if the transition is allowed.
sl@0
  2646
* @param TControllerState
sl@0
  2647
* @returns "TBool"
sl@0
  2648
* @xxxx
sl@0
  2649
*/
sl@0
  2650
TBool CMMFTestUseOldCodecAudioController::IsValidStateTransition( TControllerState aState ) const
sl@0
  2651
	{
sl@0
  2652
	 TBool result = ETrue ;
sl@0
  2653
	//[ assert the precondition that aState is a valid State ]
sl@0
  2654
	__ASSERT_ALWAYS( IsValidState(aState), Panic( EBadArgument ) );
sl@0
  2655
	//[ assert the invariant that iState is a valid State ]
sl@0
  2656
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant ));
sl@0
  2657
sl@0
  2658
	// [ check the valid state transitions ]
sl@0
  2659
	  // the only invalid transition is
sl@0
  2660
	  // stopped to playing
sl@0
  2661
	if( ( iState == EStopped ) && ( aState == EPlaying ))
sl@0
  2662
		{
sl@0
  2663
         result = EFalse ;
sl@0
  2664
		}
sl@0
  2665
  
sl@0
  2666
	//[ assert the invariant that iState is a valid State ]
sl@0
  2667
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant ));
sl@0
  2668
sl@0
  2669
	return result ;
sl@0
  2670
	}
sl@0
  2671
sl@0
  2672
/*
sl@0
  2673
* Invariant
sl@0
  2674
* @returns "TBool"
sl@0
  2675
* This function returns whether the invariant is valid
sl@0
  2676
* @xxxx
sl@0
  2677
*/
sl@0
  2678
TBool  CMMFTestUseOldCodecAudioController::Invariant() const
sl@0
  2679
	{
sl@0
  2680
	//[ The invariant is for now defined 
sl@0
  2681
	// as simply being in the correct state and
sl@0
  2682
	// having iDataPath defined ]
sl@0
  2683
	return ( iDataPath )&& IsValidState( iState);
sl@0
  2684
	}
sl@0
  2685
sl@0
  2686
/*
sl@0
  2687
* SetState
sl@0
  2688
*  This function sets the state of the controller.
sl@0
  2689
* @returns "TBool"
sl@0
  2690
* @xxxx
sl@0
  2691
*/
sl@0
  2692
TBool CMMFTestUseOldCodecAudioController::SetState(TControllerState aState)
sl@0
  2693
	{
sl@0
  2694
	TBool result = ETrue;
sl@0
  2695
	//[ assert the precondition that the state is a valid state ]
sl@0
  2696
   	__ASSERT_ALWAYS( IsValidState( aState),  Panic( EBadArgument ) );
sl@0
  2697
	//[ assert the invariant the current state is valid ]
sl@0
  2698
	__ASSERT_ALWAYS( Invariant(),  Panic( EBadInvariant ) );
sl@0
  2699
    //[ only allow valid state transitions ]
sl@0
  2700
	if( IsValidStateTransition( aState ) )	
sl@0
  2701
		{
sl@0
  2702
		//[ valid state transition set the state]
sl@0
  2703
		iState = aState ;
sl@0
  2704
		}
sl@0
  2705
	else
sl@0
  2706
		{
sl@0
  2707
		//[ invalid state transition return EFalse ]
sl@0
  2708
		result = EFalse;         
sl@0
  2709
		}
sl@0
  2710
	// [ assert the invariant on the state ]
sl@0
  2711
	__ASSERT_ALWAYS( Invariant(), Panic( EBadState ));
sl@0
  2712
	
sl@0
  2713
	return result ;
sl@0
  2714
	}
sl@0
  2715
sl@0
  2716
/*
sl@0
  2717
* IsValidState 
sl@0
  2718
* checks whether a state is a valid 
sl@0
  2719
* @returns "TBool"
sl@0
  2720
* @param TControllerState
sl@0
  2721
* @xxxx
sl@0
  2722
*/
sl@0
  2723
TBool  CMMFTestUseOldCodecAudioController::IsValidState( TControllerState aState ) const 
sl@0
  2724
	{
sl@0
  2725
	TBool result = EFalse;
sl@0
  2726
     if(( aState >= EStopped ) && ( aState <= EPlaying ))
sl@0
  2727
		 {
sl@0
  2728
          result = ETrue;
sl@0
  2729
		 }
sl@0
  2730
	 return result;
sl@0
  2731
	}
sl@0
  2732
sl@0
  2733
/**
sl@0
  2734
* State
sl@0
  2735
* The function State returns the current state of the audio controller
sl@0
  2736
* @returns "TControllerState"
sl@0
  2737
* @xxxx
sl@0
  2738
*/
sl@0
  2739
CMMFTestUseOldCodecAudioController::TControllerState CMMFTestUseOldCodecAudioController::State() const
sl@0
  2740
	{
sl@0
  2741
	__ASSERT_ALWAYS( Invariant(), Panic( EBadInvariant ) );
sl@0
  2742
	return iState;
sl@0
  2743
	}
sl@0
  2744
sl@0
  2745
/**
sl@0
  2746
*
sl@0
  2747
* SinkFormatRequired
sl@0
  2748
*
sl@0
  2749
*/
sl@0
  2750
TBool CMMFTestUseOldCodecAudioController::SinkFormatRequired( MDataSink& aDataSink ) const
sl@0
  2751
	{
sl@0
  2752
     return (aDataSink.DataSinkType()==KUidMmfFileSink || 
sl@0
  2753
		     aDataSink.DataSinkType()==KUidMmfDescriptorSink);
sl@0
  2754
	}
sl@0
  2755
sl@0
  2756
/**
sl@0
  2757
*
sl@0
  2758
* SourceFormatRequired
sl@0
  2759
*
sl@0
  2760
*/
sl@0
  2761
sl@0
  2762
TBool CMMFTestUseOldCodecAudioController::SourceFormatRequired(MDataSource& aDataSource) const
sl@0
  2763
	{
sl@0
  2764
	return (aDataSource.DataSourceType()==KUidMmfFileSource || 
sl@0
  2765
		    aDataSource.DataSourceType()==KUidMmfDescriptorSource);
sl@0
  2766
	}
sl@0
  2767
/**
sl@0
  2768
*
sl@0
  2769
* DevSoundInitialised
sl@0
  2770
* Used in certain configurations to resume completion of PrimeL() when it is pending DevSound initialisation.
sl@0
  2771
*
sl@0
  2772
*/
sl@0
  2773
void CMMFTestUseOldCodecAudioController::DevSoundInitialised(TInt /*aError*/)
sl@0
  2774
	{
sl@0
  2775
	iWaitForAsyncService->AsyncStop();
sl@0
  2776
	}
sl@0
  2777
sl@0
  2778
CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::TDevSoundEventHandler()
sl@0
  2779
: iInterceptedDevSoundObserver(NULL), iEventObserver(NULL)
sl@0
  2780
	{
sl@0
  2781
	}	
sl@0
  2782
sl@0
  2783
void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::SetInterceptedDevSoundObserver(MDevSoundObserver* aObserver)
sl@0
  2784
	{
sl@0
  2785
	iInterceptedDevSoundObserver = aObserver;
sl@0
  2786
	}
sl@0
  2787
	
sl@0
  2788
void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::SetEventObserver(CMMFTestUseOldCodecAudioController* aObserver)
sl@0
  2789
	{
sl@0
  2790
	iEventObserver = aObserver;
sl@0
  2791
	}
sl@0
  2792
		
sl@0
  2793
void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::InitializeComplete(TInt aError)
sl@0
  2794
	{
sl@0
  2795
	iInterceptedDevSoundObserver->InitializeComplete(aError);
sl@0
  2796
	iEventObserver->DevSoundInitialised(aError);
sl@0
  2797
	}
sl@0
  2798
sl@0
  2799
void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::ToneFinished(TInt aError)
sl@0
  2800
	{
sl@0
  2801
	iInterceptedDevSoundObserver->ToneFinished(aError);
sl@0
  2802
	}
sl@0
  2803
sl@0
  2804
void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::BufferToBeFilled(CMMFBuffer* aBuffer)
sl@0
  2805
	{
sl@0
  2806
	iInterceptedDevSoundObserver->BufferToBeFilled(aBuffer);
sl@0
  2807
	}
sl@0
  2808
sl@0
  2809
void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::PlayError(TInt aError)
sl@0
  2810
	{
sl@0
  2811
	iInterceptedDevSoundObserver->PlayError(aError);
sl@0
  2812
	}
sl@0
  2813
sl@0
  2814
void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::BufferToBeEmptied(CMMFBuffer* aBuffer)
sl@0
  2815
	{
sl@0
  2816
	iInterceptedDevSoundObserver->BufferToBeEmptied(aBuffer);
sl@0
  2817
	}
sl@0
  2818
sl@0
  2819
void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::RecordError(TInt aError)
sl@0
  2820
	{
sl@0
  2821
	iInterceptedDevSoundObserver->RecordError(aError);
sl@0
  2822
	}
sl@0
  2823
sl@0
  2824
void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::ConvertError(TInt aError)
sl@0
  2825
	{
sl@0
  2826
	iInterceptedDevSoundObserver->ConvertError(aError);
sl@0
  2827
	}
sl@0
  2828
sl@0
  2829
void CMMFTestUseOldCodecAudioController::TDevSoundEventHandler::DeviceMessage(TUid aMessageType, const TDesC8& aMsg)
sl@0
  2830
	{
sl@0
  2831
	iInterceptedDevSoundObserver->DeviceMessage(aMessageType, aMsg);
sl@0
  2832
	}
sl@0
  2833
sl@0
  2834