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