|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include "char_a3f_devsound_testbase.h" |
|
17 #include "char_a3f_devsound_playrecordclients.h" |
|
18 #include "char_a3f_devsound_toneclient.h" |
|
19 |
|
20 const TUint KRateLookup[] = |
|
21 { |
|
22 EMMFSampleRate8000Hz, |
|
23 EMMFSampleRate11025Hz, |
|
24 EMMFSampleRate16000Hz, |
|
25 EMMFSampleRate22050Hz, |
|
26 EMMFSampleRate32000Hz, |
|
27 EMMFSampleRate44100Hz, |
|
28 EMMFSampleRate48000Hz, |
|
29 EMMFSampleRate88200Hz, |
|
30 EMMFSampleRate96000Hz, |
|
31 EMMFSampleRate12000Hz, |
|
32 EMMFSampleRate24000Hz, |
|
33 EMMFSampleRate64000Hz |
|
34 }; |
|
35 |
|
36 const TUint KChannelsLookup[] = |
|
37 { |
|
38 EMMFMono, |
|
39 EMMFStereo |
|
40 }; |
|
41 |
|
42 RA3FDevSoundTestBase::RA3FDevSoundTestBase(const TDesC& aTestName) |
|
43 : iFourCCString(KNullDesC), |
|
44 iFourCCCode(KMMFFourCCCodeNULL), |
|
45 iDevSoundState(EStateInitial), |
|
46 iDevsoundToneClient(NULL), |
|
47 iDevsoundPlayClient(NULL), |
|
48 iDevsoundRecordClient(NULL), |
|
49 iMMFDevSound(NULL), |
|
50 iTimer(NULL), iBuffer(NULL) |
|
51 { |
|
52 iTestStepName = aTestName; |
|
53 } |
|
54 |
|
55 void RA3FDevSoundTestBase::KickoffTestL() |
|
56 { |
|
57 INFO_PRINTF1(_L("__________ Creating DevSound object ___________")); |
|
58 |
|
59 // Create devsound object |
|
60 TRAPD(err, iMMFDevSound = CMMFDevSound::NewL()); |
|
61 if (err != KErrNone) |
|
62 { |
|
63 ERR_PRINTF2(_L("Could not create DevSound object. Error = %d"), err); |
|
64 StopTest(err); |
|
65 return; |
|
66 } |
|
67 INFO_PRINTF1(_L("DevSound State: EStateCreated")); |
|
68 iDevSoundState = EStateCreated; |
|
69 // Connect RFs |
|
70 err = iFs.Connect(); |
|
71 if (err != KErrNone) |
|
72 { |
|
73 ERR_PRINTF2(_L("Could not connect to Filesystem. Error = %d"), err); |
|
74 StopTest(err); |
|
75 return; |
|
76 } |
|
77 DoKickoffTestL(); |
|
78 INFO_PRINTF1(_L("DevSound Event: EEventInitialize")); |
|
79 Fsm(EEventInitialize, KErrNone); |
|
80 } |
|
81 |
|
82 void RA3FDevSoundTestBase::CloseTest() |
|
83 { |
|
84 if (iMMFDevSound) |
|
85 { |
|
86 INFO_PRINTF1(KMsgDeleteDevsound); |
|
87 delete iMMFDevSound; |
|
88 } |
|
89 if(iTimer) |
|
90 { |
|
91 delete iTimer; |
|
92 } |
|
93 if(iDevsoundToneClient) |
|
94 { |
|
95 delete iDevsoundToneClient; |
|
96 } |
|
97 if(iDevsoundPlayClient) |
|
98 { |
|
99 delete iDevsoundPlayClient; |
|
100 } |
|
101 if(iDevsoundRecordClient) |
|
102 { |
|
103 delete iDevsoundRecordClient; |
|
104 } |
|
105 if (iAsyncWriteBTFAO) |
|
106 { |
|
107 delete iAsyncWriteBTFAO; |
|
108 iAsyncWriteBTFAO = NULL; |
|
109 } |
|
110 |
|
111 iFile.Close(); |
|
112 iFs.Close(); |
|
113 } |
|
114 |
|
115 /* |
|
116 * |
|
117 * CallStopTest |
|
118 * |
|
119 */ |
|
120 void RA3FDevSoundTestBase::CallStopTest(TInt aError) |
|
121 { |
|
122 StopTest(aError); |
|
123 } |
|
124 |
|
125 |
|
126 void RA3FDevSoundTestBase::StartTimer(TTimeIntervalMicroSeconds32 aWaitTime) |
|
127 { |
|
128 TTimeIntervalMicroSeconds32 timeInterval; |
|
129 |
|
130 if(aWaitTime <= TTimeIntervalMicroSeconds32(0)) |
|
131 { |
|
132 timeInterval = KMicroSecsInOneSec; |
|
133 } |
|
134 else |
|
135 { |
|
136 timeInterval = aWaitTime; |
|
137 } |
|
138 TCallBack callback (TimerCallback, this); |
|
139 iTimer->Start(timeInterval, timeInterval, callback); |
|
140 INFO_PRINTF1(_L("Timer has been started")); |
|
141 } |
|
142 |
|
143 TInt RA3FDevSoundTestBase::TimerCallback(TAny* aPtr) |
|
144 { |
|
145 static_cast<RA3FDevSoundTestBase*>(aPtr)->DoTimerCallback(); |
|
146 return KErrNone; |
|
147 } |
|
148 |
|
149 void RA3FDevSoundTestBase::DoTimerCallback() |
|
150 { |
|
151 __ASSERT_ALWAYS(0, Panic(_L("RA3FDevSoundTestBase"), EInvalidCallbackCall)); |
|
152 } |
|
153 |
|
154 void RA3FDevSoundTestBase::EncodingFromStringToTFourCC(const TDesC& aFourCCString) |
|
155 { |
|
156 iFourCCString.Copy(aFourCCString); |
|
157 if(aFourCCString.Length() <= KTFourCC) |
|
158 { |
|
159 while( iFourCCString.Length() < KTFourCC ) |
|
160 { |
|
161 iFourCCString.Insert(0, _L(" ")); |
|
162 } |
|
163 iFourCCCode = TFourCC(iFourCCString[3] << 24 | iFourCCString[2] << 16 | iFourCCString[1] << 8 | iFourCCString[0]); |
|
164 } |
|
165 else |
|
166 { |
|
167 ERR_PRINTF2(KMsgErrorFourccLength,iFourCCString.Length()); |
|
168 StopTest(KErrUnknown); |
|
169 } |
|
170 } |
|
171 |
|
172 void RA3FDevSoundTestBase::InitializeComplete(TInt aError) |
|
173 { |
|
174 INFO_PRINTF1(_L("========== DevSound InitializeComplete() callback ==========")); |
|
175 INFO_PRINTF3(KMsgErrorDevSoundCallback, &KInitializeCompleteText, aError); |
|
176 if(iDevSoundState == EStateInitializing) |
|
177 { |
|
178 INFO_PRINTF1(_L("DevSound Event: EEventInitComplete")); |
|
179 Fsm(EEventInitComplete, aError); |
|
180 } |
|
181 } |
|
182 |
|
183 void RA3FDevSoundTestBase::ToneFinished(TInt aError) |
|
184 { |
|
185 INFO_PRINTF1(_L("========== DevSound ToneFinished() callback ==========")); |
|
186 if (aError == KErrUnderflow) |
|
187 { |
|
188 INFO_PRINTF2(_L("DevSound called CMMFDevSound::ToneFinished with error = %d as expected"), aError); |
|
189 StopTest(aError,EPass); |
|
190 } |
|
191 else |
|
192 { |
|
193 ERR_PRINTF2(_L("DevSound called CMMFDevSound::ToneFinished with error = %d"), aError); |
|
194 ERR_PRINTF2(_L("Expected error = %d"), KErrUnderflow); |
|
195 StopTest(aError); |
|
196 } |
|
197 } |
|
198 |
|
199 void RA3FDevSoundTestBase::BufferToBeFilled(CMMFBuffer* aBuffer) |
|
200 { |
|
201 INFO_PRINTF1(_L("========== DevSound BufferToBeFilled() callback ==========")); |
|
202 if (!aBuffer) |
|
203 { |
|
204 ERR_PRINTF1(_L("BufferToBeFilled callback received a NULL CMMFBuffer!")); |
|
205 StopTest(KErrGeneral); |
|
206 } |
|
207 else |
|
208 { |
|
209 iBuffer = aBuffer; |
|
210 INFO_PRINTF1(_L("DevSound Event: EEventBTBF")); |
|
211 Fsm(EEventBTBF, KErrNone); |
|
212 } |
|
213 } |
|
214 |
|
215 void RA3FDevSoundTestBase::PlayError(TInt aError) |
|
216 { |
|
217 INFO_PRINTF1(_L("========== DevSound PlayError() callback ==========")); |
|
218 INFO_PRINTF3(KMsgErrorDevSoundCallback, &KPlayErrorText, aError); |
|
219 if(iBuffer->LastBuffer() && (aError == KErrUnderflow)) |
|
220 { |
|
221 INFO_PRINTF1(_L("Playback completed normally")); |
|
222 StopTest(); |
|
223 } |
|
224 else |
|
225 { |
|
226 INFO_PRINTF1(_L("Playback completed with error")); |
|
227 StopTest(aError, EFail); |
|
228 } |
|
229 } |
|
230 |
|
231 void RA3FDevSoundTestBase::BufferToBeEmptied(CMMFBuffer* aBuffer) |
|
232 { |
|
233 INFO_PRINTF1(_L("DevSound called BufferToBeEmptied.")); |
|
234 if (!aBuffer) |
|
235 { |
|
236 INFO_PRINTF1(_L("BufferToBeEmptied callback received a NULL CMMFBuffer")); |
|
237 StopTest(KErrGeneral); |
|
238 return; |
|
239 } |
|
240 iBuffer = aBuffer; |
|
241 if(aBuffer->LastBuffer()) |
|
242 { |
|
243 if(iDevSoundState == EStatePause) |
|
244 { |
|
245 // We need to call CMMFDevSound->Stop() here if last buffer flag set |
|
246 INFO_PRINTF1(_L("Devsound is in Paused state and CMMFBuffer::LastBuffer is set")); |
|
247 INFO_PRINTF1(_L("iMMFDevSound->Stop()")); |
|
248 iMMFDevSound->Stop(); |
|
249 StopTest(); |
|
250 } |
|
251 else |
|
252 { |
|
253 INFO_PRINTF1(_L("***** Unknown behaviour: Last buffer flag set before calling CMMFDevSound->Pause()")); |
|
254 StopTest(KErrUnknown); |
|
255 } |
|
256 } |
|
257 else |
|
258 { |
|
259 INFO_PRINTF1(_L("DevSound Event: EEventBTBE")); |
|
260 Fsm(EEventBTBE, KErrNone); |
|
261 } |
|
262 } |
|
263 |
|
264 void RA3FDevSoundTestBase::RecordError(TInt aError) |
|
265 { |
|
266 INFO_PRINTF2(_L("DevSound called RecordError with error = %d"), aError); |
|
267 if (aError == KErrUnderflow) |
|
268 { |
|
269 StopTest(aError); |
|
270 } |
|
271 } |
|
272 |
|
273 void RA3FDevSoundTestBase::ConvertError(TInt /*aError*/) |
|
274 { |
|
275 __ASSERT_ALWAYS(0, Panic(_L("RA3FDevSoundTestBase"), EInvalidCallbackCall)); |
|
276 } |
|
277 |
|
278 void RA3FDevSoundTestBase::DeviceMessage(TUid /*aMessageType*/, const TDesC8& /*aMsg*/) |
|
279 { |
|
280 __ASSERT_ALWAYS(0, Panic(_L("RA3FDevSoundTestBase"), EInvalidCallbackCall)); |
|
281 } |
|
282 |
|
283 void RA3FDevSoundTestBase::SendEventToClient(const TMMFEvent& aEvent) |
|
284 { |
|
285 INFO_PRINTF3(_L("RA3FDevSoundTestBase::SendEventToClient type=0x%08x errorCode=%d"),aEvent.iEventType, aEvent.iErrorCode); |
|
286 if(aEvent.iEventType == KMMFEventCategoryAudioResourceAvailable) |
|
287 { |
|
288 INFO_PRINTF1(_L("Received KMMFEventCategoryAudioResourceAvailable")); |
|
289 Fsm(EResourceAvailable, aEvent.iErrorCode); |
|
290 } |
|
291 } |
|
292 |
|
293 void RA3FDevSoundTestBase::SampleRateFromTIntToTMMFSampleRate(TInt aSampleRate, TMMFSampleRate &aESampleRate) |
|
294 { |
|
295 const TSampleRateToTMMFSampleRate SampleRateLookUp [] = |
|
296 { |
|
297 {8000, EMMFSampleRate8000Hz}, |
|
298 {11025, EMMFSampleRate11025Hz}, |
|
299 {16000, EMMFSampleRate16000Hz}, |
|
300 {22050, EMMFSampleRate22050Hz}, |
|
301 {32000, EMMFSampleRate32000Hz}, |
|
302 {44100, EMMFSampleRate44100Hz}, |
|
303 {48000, EMMFSampleRate48000Hz}, |
|
304 {88200, EMMFSampleRate88200Hz}, |
|
305 {96000, EMMFSampleRate96000Hz}, |
|
306 {12000, EMMFSampleRate12000Hz}, |
|
307 {24000, EMMFSampleRate24000Hz}, |
|
308 {64000, EMMFSampleRate64000Hz} |
|
309 }; |
|
310 |
|
311 const TInt length = sizeof SampleRateLookUp / sizeof *SampleRateLookUp; |
|
312 |
|
313 for(TInt i = 0; i < length; i++) |
|
314 { |
|
315 if(aSampleRate == SampleRateLookUp[i].iTIntSampleRate) |
|
316 { |
|
317 aESampleRate = SampleRateLookUp[i].iTMMFSampleRate; |
|
318 return; |
|
319 } |
|
320 } |
|
321 ERR_PRINTF1(_L("User SampleRate doesn't match any of the specified sample rates")); |
|
322 StopTest(KErrGeneral); |
|
323 } |
|
324 |
|
325 |
|
326 void RA3FDevSoundTestBase::SampleRateFromTUintToString(TUint aSampleRate, TDes& aStringSampleRate) |
|
327 { |
|
328 const TSampleRateToString SampleRateLookUp [] = |
|
329 { |
|
330 {0x00000001, KEMMFSampleRate8000Hz() }, |
|
331 {0x00000002, KEMMFSampleRate11025Hz()}, |
|
332 {0x00000004, KEMMFSampleRate16000Hz()}, |
|
333 {0x00000008, KEMMFSampleRate22050Hz()}, |
|
334 {0x00000010, KEMMFSampleRate32000Hz()}, |
|
335 {0x00000020, KEMMFSampleRate44100Hz()}, |
|
336 {0x00000040, KEMMFSampleRate48000Hz()}, |
|
337 {0x00000080, KEMMFSampleRate88200Hz()}, |
|
338 {0x00000100, KEMMFSampleRate96000Hz()}, |
|
339 {0x00000200, KEMMFSampleRate12000Hz()}, |
|
340 {0x00000400, KEMMFSampleRate24000Hz()}, |
|
341 {0x00000800, KEMMFSampleRate64000Hz()} |
|
342 }; |
|
343 |
|
344 const TInt length = sizeof SampleRateLookUp / sizeof *SampleRateLookUp; |
|
345 |
|
346 for (TInt i =0; i < length; i++) |
|
347 { |
|
348 if(aSampleRate == SampleRateLookUp[i].iTUIntSampleRate) |
|
349 { |
|
350 aStringSampleRate.Copy(SampleRateLookUp[i].iTPtrSampleRate); |
|
351 return; |
|
352 } |
|
353 } |
|
354 ERR_PRINTF1(_L("SampleRate doesn't match any of the specified sample rates")); |
|
355 StopTest(KErrGeneral); |
|
356 } |
|
357 |
|
358 void RA3FDevSoundTestBase::ChannelsFromTUintToString(TUint aChannels,TDes& aStringChannels) |
|
359 { |
|
360 const TChannelsToString ChannelsLookUp [] = |
|
361 { |
|
362 {0x00000001, KEMMFMono() }, |
|
363 {0x00000002, KEMMFStereo()}, |
|
364 }; |
|
365 const TInt length = sizeof ChannelsLookUp / sizeof *ChannelsLookUp; |
|
366 |
|
367 for (TInt i =0; i < length; i++) |
|
368 { |
|
369 if(aChannels == ChannelsLookUp[i].iTUIntChannels) |
|
370 { |
|
371 aStringChannels.Copy(ChannelsLookUp[i].iTPtrChannels); |
|
372 return; |
|
373 } |
|
374 } |
|
375 ERR_PRINTF1(_L("Channels doesn't match any of the specified channels")); |
|
376 StopTest(KErrGeneral); |
|
377 } |
|
378 |
|
379 |
|
380 void RA3FDevSoundTestBase::PrintSupportedCapabilities(TUint aSampleRate,TUint aChannel) |
|
381 { |
|
382 TInt length = sizeof KRateLookup / sizeof *KRateLookup; |
|
383 TBuf<KMaxSampleRateStringLength> stringSampleRate; |
|
384 TBuf<KMaxChannelsStringLength> channels; |
|
385 |
|
386 for(TInt i = 0; i < length ; i++) |
|
387 { |
|
388 if(aSampleRate & KRateLookup[i]) |
|
389 { |
|
390 SampleRateFromTUintToString(KRateLookup[i],stringSampleRate); |
|
391 INFO_PRINTF3(_L("Supported Sample rate 0x%08x %S"),KRateLookup[i],&stringSampleRate); |
|
392 } |
|
393 } |
|
394 length = sizeof KChannelsLookup / sizeof *KChannelsLookup; |
|
395 |
|
396 for(TInt i = 0; i < length ; i++) |
|
397 { |
|
398 if(aChannel & KChannelsLookup[i]) |
|
399 { |
|
400 ChannelsFromTUintToString(KChannelsLookup[i],channels); |
|
401 INFO_PRINTF3(_L("Supported channels 0x%08x %S"),KChannelsLookup[i],&channels); |
|
402 } |
|
403 } |
|
404 } |
|
405 |
|
406 // |
|
407 // CAsyncWriteBufferToFile |
|
408 // |
|
409 |
|
410 CAsyncWriteBufferToFile::CAsyncWriteBufferToFile(RFile& aFile, CMMFDevSound* aDevSound, RA3FDevSoundTestBase& aTestStep) |
|
411 :CActive(EPriorityStandard), |
|
412 iFile(aFile), |
|
413 iDevSound(aDevSound), |
|
414 iTestStep(aTestStep) |
|
415 { |
|
416 CActiveScheduler::Add(this); |
|
417 } |
|
418 |
|
419 CAsyncWriteBufferToFile::~CAsyncWriteBufferToFile() |
|
420 { |
|
421 Cancel(); |
|
422 } |
|
423 |
|
424 CAsyncWriteBufferToFile* CAsyncWriteBufferToFile::NewL(RFile& aFile, CMMFDevSound* aDevSound, RA3FDevSoundTestBase& aTestStep) |
|
425 { |
|
426 CAsyncWriteBufferToFile* self = new(ELeave) CAsyncWriteBufferToFile(aFile, aDevSound, aTestStep); |
|
427 CleanupStack::PushL(self); |
|
428 self->ConstructL(); |
|
429 CleanupStack::Pop(self); |
|
430 return self; |
|
431 } |
|
432 |
|
433 void CAsyncWriteBufferToFile::ConstructL() |
|
434 { |
|
435 // Nothing to do here |
|
436 } |
|
437 |
|
438 void CAsyncWriteBufferToFile::RunL() |
|
439 { |
|
440 //If error occurs then deal with problem in RunError() |
|
441 User::LeaveIfError(iStatus.Int()); |
|
442 // Continue recording data to a buffer |
|
443 iDevSound->RecordData(); |
|
444 |
|
445 } |
|
446 |
|
447 void CAsyncWriteBufferToFile::Start(CMMFDataBuffer* aBuffer) |
|
448 { |
|
449 iFile.Write(aBuffer->Data(), iStatus); |
|
450 SetActive(); |
|
451 } |
|
452 |
|
453 void CAsyncWriteBufferToFile::DoCancel() |
|
454 { |
|
455 // Can't cancel an async write request |
|
456 } |
|
457 |
|
458 TInt CAsyncWriteBufferToFile::RunError(TInt aError) |
|
459 { |
|
460 iTestStep.CallStopTest(aError); |
|
461 return KErrNone; |
|
462 } |