os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/ACLNT/TestOldCodec.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
sl@0
     2
// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
// All rights reserved.
sl@0
     4
// This component and the accompanying materials are made available
sl@0
     5
// under the terms of "Eclipse Public License v1.0"
sl@0
     6
// which accompanies this distribution, and is available
sl@0
     7
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
//
sl@0
     9
// Initial Contributors:
sl@0
    10
// Nokia Corporation - initial contribution.
sl@0
    11
//
sl@0
    12
// Contributors:
sl@0
    13
//
sl@0
    14
// Description:
sl@0
    15
// This program is designed the test of the MMF_ACLNT.
sl@0
    16
// Test DEF039267
sl@0
    17
// 
sl@0
    18
//
sl@0
    19
sl@0
    20
/**
sl@0
    21
 @file TestOldCodec.cpp
sl@0
    22
*/
sl@0
    23
sl@0
    24
sl@0
    25
#include "TestOldCodec.h"
sl@0
    26
sl@0
    27
sl@0
    28
/**
sl@0
    29
 * Constructor
sl@0
    30
 */
sl@0
    31
sl@0
    32
CTestMmfAclntOldCodecFile::CTestMmfAclntOldCodecFile(const TDesC& aTestName,const TDesC& aSectName,
sl@0
    33
									 const TDesC& aKeyName,const TBool aPlay, 
sl@0
    34
									 const TInt aExpectedError)
sl@0
    35
	:iPlay (aPlay)
sl@0
    36
	,iExpectedError (aExpectedError)
sl@0
    37
	{
sl@0
    38
	// store the name of this test case
sl@0
    39
	// this is the name that is used by the script file
sl@0
    40
	// Each test step initialises it's own name
sl@0
    41
	iTestStepName = aTestName;
sl@0
    42
	iSectName = aSectName;
sl@0
    43
	iKeyName = aKeyName;
sl@0
    44
	}
sl@0
    45
sl@0
    46
CTestMmfAclntOldCodecFile* CTestMmfAclntOldCodecFile::NewL(const TDesC& aTestName, const TDesC& aSectName,
sl@0
    47
										   const TDesC& aKeyName,const TBool aPlay, 
sl@0
    48
										   const TInt aExpectedError = KErrNone)
sl@0
    49
	{
sl@0
    50
	CTestMmfAclntOldCodecFile* self = new (ELeave) CTestMmfAclntOldCodecFile(aTestName,aSectName,aKeyName,aPlay,aExpectedError);
sl@0
    51
	return self;
sl@0
    52
	}
sl@0
    53
sl@0
    54
CTestMmfAclntOldCodecFile* CTestMmfAclntOldCodecFile::NewLC(const TDesC& aTestName, const TDesC& aSectName,
sl@0
    55
											const TDesC& aKeyName,
sl@0
    56
											const TBool aPlay,  
sl@0
    57
											const TInt aExpectedError)
sl@0
    58
	{
sl@0
    59
	CTestMmfAclntOldCodecFile* self = CTestMmfAclntOldCodecFile::NewL(aTestName,aSectName,aKeyName,aPlay,aExpectedError);
sl@0
    60
	CleanupStack::PushL(self);
sl@0
    61
	return self;
sl@0
    62
	}
sl@0
    63
sl@0
    64
void CTestMmfAclntOldCodecFile::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
sl@0
    65
	{
sl@0
    66
	iError = aErrorCode;
sl@0
    67
	if (iError != KErrNone)
sl@0
    68
		{
sl@0
    69
		INFO_PRINTF1( _L("CTestMmfAclntRecFile : MMdaObjectStateChangeObserver Callback for CMdaAudioRecorderUtility complete"));
sl@0
    70
		INFO_PRINTF2( _L("Previous State %d "), aPreviousState);
sl@0
    71
		INFO_PRINTF2( _L("State %d "), aCurrentState);
sl@0
    72
		INFO_PRINTF2( _L("iError %d "), iError);
sl@0
    73
		}
sl@0
    74
	if (aCurrentState != CMdaAudioClipUtility::EPlaying)
sl@0
    75
		{//don't want to stop AS from transition EOpen->EPlaying
sl@0
    76
		CActiveScheduler::Stop();
sl@0
    77
		}
sl@0
    78
	}
sl@0
    79
sl@0
    80
sl@0
    81
/** Play and record an audio file using the UseOldCodecAudioController
sl@0
    82
 *  which uses CMMFCodecs and the 'null' pcm16->pcm16 hw device plugin
sl@0
    83
 *  This is for DEF039267
sl@0
    84
 */
sl@0
    85
TVerdict CTestMmfAclntOldCodecFile::DoTestStepL( void )
sl@0
    86
	{
sl@0
    87
	INFO_PRINTF1( _L("TestPlayerUtils : File"));
sl@0
    88
	TVerdict ret = EFail;
sl@0
    89
sl@0
    90
	iError = KErrTimedOut;
sl@0
    91
sl@0
    92
	TBuf<KSizeBuf>	filename;
sl@0
    93
	TPtrC			filename1; 
sl@0
    94
	if(!GetStringFromConfig(iSectName,iKeyName,filename1))
sl@0
    95
		return EInconclusive;
sl@0
    96
	GetDriveName(filename);
sl@0
    97
	filename.Append(filename1);
sl@0
    98
	TUid useCMMFCodecAudioController;
sl@0
    99
sl@0
   100
	useCMMFCodecAudioController.iUid = KMmfUidUseOldCodecAudioController;
sl@0
   101
sl@0
   102
	CMdaAudioRecorderUtility* recUtil = CMdaAudioRecorderUtility::NewL(*this);
sl@0
   103
sl@0
   104
	TRAPD(err, recUtil->OpenFileL(filename,useCMMFCodecAudioController));
sl@0
   105
sl@0
   106
	if (err)
sl@0
   107
		{
sl@0
   108
		INFO_PRINTF2( _L("error opening record to file %d "), err);
sl@0
   109
		}
sl@0
   110
	else
sl@0
   111
		{
sl@0
   112
		CActiveScheduler::Start();
sl@0
   113
		TTimeIntervalMicroSeconds duration = recUtil->Duration();
sl@0
   114
		// Wait for initialisation callback
sl@0
   115
		INFO_PRINTF1( _L("Initialise CMdaAudioPlayerUtility"));
sl@0
   116
sl@0
   117
		// Check for errors.
sl@0
   118
		if (iError == KErrNone && recUtil != NULL)
sl@0
   119
			{
sl@0
   120
			if(iPlay)
sl@0
   121
				{
sl@0
   122
				iError = KErrTimedOut;
sl@0
   123
				TRAPD(err, recUtil->PlayL());
sl@0
   124
				if (err)
sl@0
   125
					{
sl@0
   126
					INFO_PRINTF2( _L("error opening record to file %d "), err);
sl@0
   127
					}
sl@0
   128
				else
sl@0
   129
					{
sl@0
   130
					//lets time how long the file plays for and check 
sl@0
   131
					//it has played for the full time
sl@0
   132
					TTime startTime(0);
sl@0
   133
					TTime endTime(0);
sl@0
   134
					startTime.HomeTime();
sl@0
   135
					// Wait for init callback
sl@0
   136
					CActiveScheduler::Start();
sl@0
   137
					endTime.HomeTime();
sl@0
   138
					//check file played for the expected time - allow margin of error + 1S -0.5S
sl@0
   139
					TTimeIntervalMicroSeconds playduration = endTime.MicroSecondsFrom(startTime);
sl@0
   140
					if ( (playduration.Int64() < (duration.Int64()-KOneSecond/2)) ||
sl@0
   141
						(playduration.Int64() > (duration.Int64()+KOneSecond)) )
sl@0
   142
						{
sl@0
   143
						INFO_PRINTF2(_L("file didn't play for the expected duration expected %ld"), duration.Int64());
sl@0
   144
						INFO_PRINTF2(_L("but actual duration was %ld"), playduration.Int64());
sl@0
   145
						}
sl@0
   146
					else if(iError == KErrNone)
sl@0
   147
						ret = EPass;
sl@0
   148
					}
sl@0
   149
				}		
sl@0
   150
			}
sl@0
   151
sl@0
   152
		recUtil->Close();
sl@0
   153
		}
sl@0
   154
sl@0
   155
	//now try recording file
sl@0
   156
sl@0
   157
	TFourCC recordedDataType;
sl@0
   158
	TUid format;
sl@0
   159
	format.iUid = KMmfUidFormatWAVWrite;
sl@0
   160
sl@0
   161
	//check that the datatype is a valid datatype to record
sl@0
   162
	if (!iKeyName.Compare(_L("ALAW ")))
sl@0
   163
		recordedDataType.Set(KMMFFourCCCodeALAW);
sl@0
   164
	else if (!iKeyName.Compare(_L("PCMU8")))
sl@0
   165
		recordedDataType.Set(KMMFFourCCCodePCMU8);
sl@0
   166
	else if (!iKeyName.Compare(_L("MULAW")))
sl@0
   167
		recordedDataType.Set(KMMFFourCCCodeMuLAW);
sl@0
   168
	else if (!iKeyName.Compare(_L("IMAD")))
sl@0
   169
		recordedDataType.Set(KMMFFourCCCodeIMAD);
sl@0
   170
	else if (!iKeyName.Compare(_L("GSM610")))
sl@0
   171
		recordedDataType.Set(KMMFFourCCCodeGSM610);
sl@0
   172
sl@0
   173
	//rename file to indicate it is recorded
sl@0
   174
	if (recordedDataType != KMMFFourCCCodeNULL)
sl@0
   175
		{
sl@0
   176
		TInt matchpos = filename.Find(_L(".wav"));//get position of extension
sl@0
   177
		filename.Insert(matchpos,_L("recorded"));//change filename to indicate it is recorded
sl@0
   178
sl@0
   179
		//delete file prior to recording
sl@0
   180
		RFs fs;
sl@0
   181
		fs.Connect();
sl@0
   182
		fs.Delete(filename);
sl@0
   183
		fs.Close();
sl@0
   184
	
sl@0
   185
		TRAPD(err,recUtil->OpenFileL(filename,useCMMFCodecAudioController,useCMMFCodecAudioController,format,recordedDataType));
sl@0
   186
sl@0
   187
		if (err)
sl@0
   188
			{
sl@0
   189
			ret = EFail;
sl@0
   190
			INFO_PRINTF2( _L("error opening record to file %d "), err);
sl@0
   191
			}
sl@0
   192
		else
sl@0
   193
			{
sl@0
   194
			INFO_PRINTF1( _L("Initialise CMdaAudioRecorderUtility"));
sl@0
   195
			CActiveScheduler::Start();	// idle -> open
sl@0
   196
sl@0
   197
			recUtil->RecordL();
sl@0
   198
sl@0
   199
			// Commented this line of code as a fix for DEF 40709 as it looks like sending a trace message
sl@0
   200
			// to the TestFramework server(for some reason)and taking a very long time on beech/lubbock 
sl@0
   201
sl@0
   202
			//INFO_PRINTF1( _L("Record CMdaAudioRecorderUtility"));
sl@0
   203
			CActiveScheduler::Start(); // open -> record
sl@0
   204
			User::After(KTwoSeconds);
sl@0
   205
			
sl@0
   206
			recUtil->Stop();
sl@0
   207
	
sl@0
   208
			TTimeIntervalMicroSeconds expectedDuration(KTwoSeconds);
sl@0
   209
			TTimeIntervalMicroSeconds duration = recUtil->Duration();
sl@0
   210
			//we'll alow +/- 0.5 variance 
sl@0
   211
			if (duration > TTimeIntervalMicroSeconds(expectedDuration.Int64() + KDeviation/2))
sl@0
   212
				{
sl@0
   213
				INFO_PRINTF3( _L("Duration too long expected %ld actual %ld "), expectedDuration.Int64(), duration.Int64());
sl@0
   214
				ret = EFail;
sl@0
   215
				}
sl@0
   216
			else if (duration < TTimeIntervalMicroSeconds(expectedDuration.Int64() - KDeviation/2))
sl@0
   217
				{
sl@0
   218
				INFO_PRINTF3( _L("Duration too short expected %ld actual %ld "), expectedDuration.Int64(), duration.Int64());
sl@0
   219
				ret = EFail;
sl@0
   220
				}
sl@0
   221
sl@0
   222
			recUtil->Close();
sl@0
   223
			}
sl@0
   224
		}
sl@0
   225
sl@0
   226
	delete recUtil;
sl@0
   227
	User::After(KOneSecond); // wait for deletion to shut down devsound
sl@0
   228
	if(iError != KErrNone)
sl@0
   229
		ERR_PRINTF2( _L("CMdaAudioPlayerUtility failed with error %d"),iError );
sl@0
   230
	return	ret;
sl@0
   231
	}
sl@0
   232
sl@0
   233
sl@0
   234
sl@0
   235
sl@0
   236