|
1 // Copyright (c) 2004-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 <mmf/plugin/mmfcontrollerimplementationuids.hrh> |
|
17 #include <caf/caf.h> |
|
18 #include <mmf/plugin/mmfcontrollerimplementationuids.hrh> |
|
19 #include "TestPlayerUtils.h" |
|
20 #include "OpenFileByHandle7904.h" |
|
21 |
|
22 /** |
|
23 * Constructor |
|
24 */ |
|
25 CTestMmfAclntOpenFile7904::CTestMmfAclntOpenFile7904(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile) |
|
26 |
|
27 { |
|
28 // store the name of this test case |
|
29 // this is the name that is used by the script file |
|
30 // Each test step initialises it's own name |
|
31 iTestStepName = aTestName; |
|
32 iHeapSize = 200000; // playback part of test loads whole sound file into buffer, so need large heap |
|
33 iSectName = aSectName; |
|
34 iKeyName = aKeyName; |
|
35 iTestFormat = aFormat; |
|
36 iCreateFile = aCreateFile; |
|
37 } |
|
38 |
|
39 CTestMmfAclntOpenFile7904* CTestMmfAclntOpenFile7904::NewL(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile) |
|
40 { |
|
41 CTestMmfAclntOpenFile7904* self = new (ELeave) CTestMmfAclntOpenFile7904(aTestName,aSectName,aKeyName,aFormat,aCreateFile); |
|
42 return self; |
|
43 } |
|
44 |
|
45 CTestMmfAclntOpenFile7904* CTestMmfAclntOpenFile7904::NewLC(const TDesC& aTestName, const TDesC& aSectName,const TDesC& aKeyName, const TTestFormat aFormat, const TBool aCreateFile) |
|
46 { |
|
47 CTestMmfAclntOpenFile7904* self = CTestMmfAclntOpenFile7904::NewLC(aTestName,aSectName,aKeyName,aFormat,aCreateFile); |
|
48 CleanupStack::PushL(self); |
|
49 return self; |
|
50 } |
|
51 |
|
52 void CTestMmfAclntOpenFile7904::MoscoStateChangeEvent(CBase* /*aObject*/, TInt /*aPreviousState*/, TInt /*aCurrentState*/, TInt aErrorCode) |
|
53 { |
|
54 iError = aErrorCode; |
|
55 INFO_PRINTF1( _L("CTestMmfAclntOpenFile7904 : MMdaObjectStateChangeObserver Callback for CMdaAudioRecorderUtility complete")); |
|
56 INFO_PRINTF2( _L("iError %d "), iError); |
|
57 |
|
58 CActiveScheduler::Stop(); |
|
59 } |
|
60 |
|
61 // Audio utility callbacks |
|
62 void CTestMmfAclntOpenFile7904::MapcInitComplete(TInt aError, const TTimeIntervalMicroSeconds& /*aDuration*/) |
|
63 { |
|
64 iError = aError; |
|
65 CActiveScheduler::Stop(); |
|
66 } |
|
67 |
|
68 void CTestMmfAclntOpenFile7904::MapcPlayComplete(TInt aError) |
|
69 { |
|
70 iError = aError; |
|
71 CActiveScheduler::Stop(); |
|
72 } |
|
73 |
|
74 // Audio output stream callbacks |
|
75 void CTestMmfAclntOpenFile7904::MaoscOpenComplete(TInt aError) |
|
76 { |
|
77 iError = aError; |
|
78 CActiveScheduler::Stop(); |
|
79 } |
|
80 |
|
81 void CTestMmfAclntOpenFile7904::MaoscBufferCopied(TInt aError, const TDesC8& /*aBuffer*/) |
|
82 { |
|
83 iError = aError; |
|
84 CActiveScheduler::Stop(); |
|
85 } |
|
86 |
|
87 void CTestMmfAclntOpenFile7904::MaoscPlayComplete(TInt aError) |
|
88 { |
|
89 iError = aError; |
|
90 CActiveScheduler::Stop(); |
|
91 } |
|
92 |
|
93 |
|
94 TVerdict CTestMmfAclntOpenFile7904::DoTestStepPreambleL() |
|
95 { |
|
96 TVerdict ret = EPass; |
|
97 |
|
98 SetupFormatL(iTestFormat); |
|
99 |
|
100 if((ret == EInconclusive) || (ret == EFail)) |
|
101 return ret; |
|
102 |
|
103 return CTestMmfAclntStep::DoTestStepPreambleL(); |
|
104 } |
|
105 |
|
106 /** |
|
107 * Open a file based clip and record |
|
108 */ |
|
109 TVerdict CTestMmfAclntOpenFile7904::DoTestStepL() |
|
110 { |
|
111 INFO_PRINTF1( _L("TestRecorder : Record File")); |
|
112 TVerdict ret = EFail; |
|
113 iError = KErrTimedOut; |
|
114 |
|
115 RFs fs; |
|
116 RFile file; |
|
117 |
|
118 User::LeaveIfError(fs.Connect()); |
|
119 CleanupClosePushL(fs); |
|
120 User::LeaveIfError(fs.ShareProtected()); |
|
121 |
|
122 TPtrC filename; |
|
123 if(!GetStringFromConfig(iSectName, iKeyName, filename)) |
|
124 { |
|
125 return EInconclusive; |
|
126 } |
|
127 |
|
128 CMdaAudioRecorderUtility* recUtil = CMdaAudioRecorderUtility::NewL(*this); |
|
129 CleanupStack::PushL(recUtil); |
|
130 |
|
131 TUid audioController = TUid::Uid(KMmfUidControllerAudio); |
|
132 |
|
133 User::LeaveIfError(file.Replace(fs,filename,EFileWrite)); |
|
134 CleanupClosePushL(file); |
|
135 |
|
136 recUtil->OpenFileL(file, audioController, KNullUid, KNullUid, KFourCCNULL); |
|
137 |
|
138 INFO_PRINTF1( _L("Initialise CMdaAudioRecorderUtility")); |
|
139 CActiveScheduler::Start(); |
|
140 |
|
141 if(iError == KErrNone) |
|
142 { |
|
143 iError = KErrTimedOut; |
|
144 recUtil->RecordL(); |
|
145 INFO_PRINTF1( _L("Record CMdaAudioRecorderUtility")); |
|
146 CActiveScheduler::Start(); // open -> record |
|
147 |
|
148 User::After(500000); |
|
149 recUtil->Stop(); |
|
150 } |
|
151 |
|
152 CleanupStack::PopAndDestroy(2, recUtil); // file, recUtil |
|
153 recUtil = NULL; |
|
154 |
|
155 // Playback the file |
|
156 if (iError == KErrNone) |
|
157 { |
|
158 if (filename.Right(4).Compare(_L(".wav"))==0) |
|
159 { |
|
160 // Wav file playback |
|
161 CMdaAudioPlayerUtility* playUtil = CMdaAudioPlayerUtility::NewL(*this); |
|
162 CleanupStack::PushL(playUtil); |
|
163 TRAPD(err, playUtil->OpenFileL(filename)); |
|
164 if (err != KErrNone) |
|
165 { |
|
166 INFO_PRINTF2(_L("Error opening file for playback err = %d"), err); |
|
167 ret = EFail; |
|
168 } |
|
169 CActiveScheduler::Start(); |
|
170 if (iError != KErrNone) |
|
171 { |
|
172 INFO_PRINTF2(_L("Error opening file for playback iError = %d"), iError); |
|
173 ret = EFail; |
|
174 } |
|
175 playUtil->Play(); |
|
176 CActiveScheduler::Start(); |
|
177 CleanupStack::PopAndDestroy(playUtil); |
|
178 if (iError != KErrNone) |
|
179 { |
|
180 INFO_PRINTF2(_L("Error during playback of recorded file iError=%d"), iError); |
|
181 ret = EFail; |
|
182 } |
|
183 } |
|
184 } |
|
185 |
|
186 if( iError == KErrNone ) |
|
187 { |
|
188 RFile file; |
|
189 TInt size = 0; |
|
190 User::LeaveIfError(file.Open(fs,filename,EFileRead)); |
|
191 CleanupClosePushL(file); |
|
192 User::LeaveIfError(file.Size(size)); |
|
193 |
|
194 if(size > 0) |
|
195 { |
|
196 ret = EPass; |
|
197 } |
|
198 CleanupStack::PopAndDestroy(); //file |
|
199 } |
|
200 |
|
201 CleanupStack::PopAndDestroy(&fs); // fs |
|
202 |
|
203 ERR_PRINTF2( _L("CMdaAudioRecorderUtility completed with error %d"),iError ); |
|
204 User::After(KOneSecond); |
|
205 |
|
206 return ret; |
|
207 } |