First public contribution.
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".
9 // Initial Contributors:
10 // Nokia Corporation - initial contribution.
15 // This program is designed the test of the MMF_ACLNT.
21 @file TestOldCodec.cpp
25 #include "TestOldCodec.h"
32 CTestMmfAclntOldCodecFile::CTestMmfAclntOldCodecFile(const TDesC& aTestName,const TDesC& aSectName,
33 const TDesC& aKeyName,const TBool aPlay,
34 const TInt aExpectedError)
36 ,iExpectedError (aExpectedError)
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;
46 CTestMmfAclntOldCodecFile* CTestMmfAclntOldCodecFile::NewL(const TDesC& aTestName, const TDesC& aSectName,
47 const TDesC& aKeyName,const TBool aPlay,
48 const TInt aExpectedError = KErrNone)
50 CTestMmfAclntOldCodecFile* self = new (ELeave) CTestMmfAclntOldCodecFile(aTestName,aSectName,aKeyName,aPlay,aExpectedError);
54 CTestMmfAclntOldCodecFile* CTestMmfAclntOldCodecFile::NewLC(const TDesC& aTestName, const TDesC& aSectName,
55 const TDesC& aKeyName,
57 const TInt aExpectedError)
59 CTestMmfAclntOldCodecFile* self = CTestMmfAclntOldCodecFile::NewL(aTestName,aSectName,aKeyName,aPlay,aExpectedError);
60 CleanupStack::PushL(self);
64 void CTestMmfAclntOldCodecFile::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
67 if (iError != KErrNone)
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);
74 if (aCurrentState != CMdaAudioClipUtility::EPlaying)
75 {//don't want to stop AS from transition EOpen->EPlaying
76 CActiveScheduler::Stop();
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
85 TVerdict CTestMmfAclntOldCodecFile::DoTestStepL( void )
87 INFO_PRINTF1( _L("TestPlayerUtils : File"));
90 iError = KErrTimedOut;
92 TBuf<KSizeBuf> filename;
94 if(!GetStringFromConfig(iSectName,iKeyName,filename1))
96 GetDriveName(filename);
97 filename.Append(filename1);
98 TUid useCMMFCodecAudioController;
100 useCMMFCodecAudioController.iUid = KMmfUidUseOldCodecAudioController;
102 CMdaAudioRecorderUtility* recUtil = CMdaAudioRecorderUtility::NewL(*this);
104 TRAPD(err, recUtil->OpenFileL(filename,useCMMFCodecAudioController));
108 INFO_PRINTF2( _L("error opening record to file %d "), err);
112 CActiveScheduler::Start();
113 TTimeIntervalMicroSeconds duration = recUtil->Duration();
114 // Wait for initialisation callback
115 INFO_PRINTF1( _L("Initialise CMdaAudioPlayerUtility"));
118 if (iError == KErrNone && recUtil != NULL)
122 iError = KErrTimedOut;
123 TRAPD(err, recUtil->PlayL());
126 INFO_PRINTF2( _L("error opening record to file %d "), err);
130 //lets time how long the file plays for and check
131 //it has played for the full time
134 startTime.HomeTime();
135 // Wait for init callback
136 CActiveScheduler::Start();
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)) )
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());
146 else if(iError == KErrNone)
155 //now try recording file
157 TFourCC recordedDataType;
159 format.iUid = KMmfUidFormatWAVWrite;
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);
173 //rename file to indicate it is recorded
174 if (recordedDataType != KMMFFourCCCodeNULL)
176 TInt matchpos = filename.Find(_L(".wav"));//get position of extension
177 filename.Insert(matchpos,_L("recorded"));//change filename to indicate it is recorded
179 //delete file prior to recording
185 TRAPD(err,recUtil->OpenFileL(filename,useCMMFCodecAudioController,useCMMFCodecAudioController,format,recordedDataType));
190 INFO_PRINTF2( _L("error opening record to file %d "), err);
194 INFO_PRINTF1( _L("Initialise CMdaAudioRecorderUtility"));
195 CActiveScheduler::Start(); // idle -> open
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
202 //INFO_PRINTF1( _L("Record CMdaAudioRecorderUtility"));
203 CActiveScheduler::Start(); // open -> record
204 User::After(KTwoSeconds);
208 TTimeIntervalMicroSeconds expectedDuration(KTwoSeconds);
209 TTimeIntervalMicroSeconds duration = recUtil->Duration();
210 //we'll alow +/- 0.5 variance
211 if (duration > TTimeIntervalMicroSeconds(expectedDuration.Int64() + KDeviation/2))
213 INFO_PRINTF3( _L("Duration too long expected %ld actual %ld "), expectedDuration.Int64(), duration.Int64());
216 else if (duration < TTimeIntervalMicroSeconds(expectedDuration.Int64() - KDeviation/2))
218 INFO_PRINTF3( _L("Duration too short expected %ld actual %ld "), expectedDuration.Int64(), duration.Int64());
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 );