|
1 /* |
|
2 * Copyright (c) 2007 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: AudioRecorder Test |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "PlayVolume.h" |
|
20 #include "badesca.h" |
|
21 #include "mmfcontrollerpluginresolver.h" |
|
22 #include "RecPositionClip.h" |
|
23 |
|
24 ////////////////////////////////////////////////////////////////////// |
|
25 // Construction/Destruction |
|
26 ////////////////////////////////////////////////////////////////////// |
|
27 |
|
28 CPlayVolume::CPlayVolume(CTestModuleIf *aConsole, CStifLogger *aLogger) |
|
29 { |
|
30 console = aConsole; |
|
31 logger = aLogger; |
|
32 } |
|
33 |
|
34 CPlayVolume::~CPlayVolume() |
|
35 { |
|
36 if (recorder) delete recorder; |
|
37 recorder = NULL; |
|
38 } |
|
39 |
|
40 |
|
41 |
|
42 CPlayVolume* CPlayVolume::NewL(CTestModuleIf *aConsole, CStifLogger *aLogger, TFileName* fileName) |
|
43 { |
|
44 CPlayVolume* self = new (ELeave) CPlayVolume(aConsole, aLogger); |
|
45 CleanupStack::PushL(self); |
|
46 |
|
47 // self->ConstructL(fileName); |
|
48 TRAPD(err, self->ConstructL(fileName)); |
|
49 if (err != KErrNone) |
|
50 { |
|
51 CleanupStack::PopAndDestroy(); |
|
52 return NULL; |
|
53 } |
|
54 |
|
55 CleanupStack::Pop(self); |
|
56 return self; |
|
57 } |
|
58 |
|
59 void CPlayVolume::ConstructL(TFileName* fileName) |
|
60 { |
|
61 |
|
62 logger->Log(_L("Creating file: %S"),fileName); |
|
63 recorder = CMdaAudioRecorderUtility::NewL(*this); |
|
64 if (recorder) |
|
65 { |
|
66 TRAPD(err,recorder->OpenFileL(*fileName)); |
|
67 if (err != KErrNone) |
|
68 { |
|
69 logger->Log(_L("Error %d opening file: %S"),err,fileName); |
|
70 User::Leave(KErrRecOpenFile); |
|
71 } |
|
72 } |
|
73 } |
|
74 |
|
75 |
|
76 void CPlayVolume::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode) |
|
77 { |
|
78 |
|
79 #ifdef _DEBUG |
|
80 RDebug::Print (_L ("CPlayVolume::MoscoStateChangeEvent")); |
|
81 #endif |
|
82 |
|
83 logger->Log(_L("MoscoStateChangeEvent called, error: %d prev: %d curr : %d"),aErrorCode,aPreviousState,aCurrentState); |
|
84 |
|
85 if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == 0) |
|
86 { |
|
87 // Initialize |
|
88 recorder->SetAudioDeviceMode(CMdaAudioRecorderUtility::ELocal); |
|
89 logger->Log(_L("Mode set")); |
|
90 recorder->SetGain(recorder->MaxGain()); |
|
91 logger->Log(_L("Gain set")); |
|
92 //recorder->SetVolume(recorder->MaxVolume()); |
|
93 //logger->Log(_L("Volume set")); |
|
94 recorder->SetPosition(TTimeIntervalMicroSeconds(TInt64(0))); |
|
95 logger->Log(_L("Position set")); |
|
96 |
|
97 TInt maxVolume = recorder->MaxVolume(); |
|
98 logger->Log(_L("MoscoStateChangeEvent get maxVolume: %d "),maxVolume); |
|
99 recorder->SetVolume(expectedVol); |
|
100 logger->Log(_L("MoscoStateChangeEvent setVolume: %d"),expectedVol); |
|
101 recorder->PlayL(); |
|
102 return; |
|
103 } |
|
104 |
|
105 if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == CMdaAudioClipUtility::EPlaying) |
|
106 { |
|
107 TInt err; |
|
108 |
|
109 err = recorder->GetVolume(volume); |
|
110 if (err != KErrNone) |
|
111 { |
|
112 logger->Log(_L("Error getting volume: %d"),err); |
|
113 } |
|
114 |
|
115 this->volume = volume; |
|
116 logger->Log(_L("MoscoStateChangeEvent getVolume: %d "),volume); |
|
117 CActiveScheduler::Stop(); |
|
118 } |
|
119 return; |
|
120 } |
|
121 |
|
122 |
|
123 |
|
124 TInt CPlayVolume::RunTestL(CTestModuleIf* aConsole, CStifLogger *aLogger, CStifSectionParser* aParser, TInt* /*clipCounter*/) |
|
125 { |
|
126 TInt error = KErrNone; |
|
127 aLogger->Log(_L("Creating scheduler")); |
|
128 |
|
129 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
130 CleanupStack::PushL(scheduler); // push to clean-up stack |
|
131 CActiveScheduler::Install(scheduler); // install as active scheduler |
|
132 |
|
133 aLogger->Log(_L("Creating CPlayVolume")); |
|
134 |
|
135 TFileName fileName; |
|
136 |
|
137 //Get file name |
|
138 TPtrC name; |
|
139 CStifItemParser* item = aParser->GetItemLineL(KFileName, ENoTag); |
|
140 if (!item) |
|
141 { |
|
142 CleanupStack::PopAndDestroy(); |
|
143 return KErrSyntax; |
|
144 } |
|
145 |
|
146 CleanupStack::PushL(item); |
|
147 if (item->GetString(KEmptyString,name) != KErrNone) |
|
148 { |
|
149 aLogger->Log(_L("Invalid file name")); |
|
150 CleanupStack::PopAndDestroy(2); |
|
151 return KErrSyntax; |
|
152 } |
|
153 CleanupStack::PopAndDestroy(); |
|
154 |
|
155 GetFileName(name,&fileName); |
|
156 |
|
157 //Get expected volume |
|
158 TInt expectedVol = 0; |
|
159 item = aParser->GetItemLineL(KMaxVolume); |
|
160 CleanupStack::PushL(item); |
|
161 if (item) |
|
162 if (item->GetInt(KMaxVolume,expectedVol) != KErrNone) |
|
163 { |
|
164 aLogger->Log(_L("Invalid expected volume.")); |
|
165 error = KErrSyntax; |
|
166 } |
|
167 CleanupStack::PopAndDestroy(); // item |
|
168 aLogger->Log(_L("Expected max volume: %d"),expectedVol); |
|
169 |
|
170 //Get max volume error range |
|
171 TInt errRange = 0; |
|
172 item = aParser->GetItemLineL(KErrorRange); |
|
173 CleanupStack::PushL(item); |
|
174 if (item) |
|
175 if (item->GetInt(KErrorRange,errRange) != KErrNone) |
|
176 { |
|
177 aLogger->Log(_L("Invalid max volume error range.")); |
|
178 error = KErrSyntax; |
|
179 } |
|
180 CleanupStack::PopAndDestroy(); // item |
|
181 aLogger->Log(_L("Expected max volume error range: %d"),errRange); |
|
182 |
|
183 |
|
184 // create CPlayVolume |
|
185 aLogger->Log(_L("Creating CPlayVolume")); |
|
186 |
|
187 if (error != KErrNone) |
|
188 { |
|
189 CleanupStack::PopAndDestroy(); |
|
190 return error; |
|
191 } |
|
192 |
|
193 CPlayVolume* selfObj = CPlayVolume::NewL(aConsole, aLogger, &fileName); |
|
194 |
|
195 selfObj->expectedVol = expectedVol; |
|
196 |
|
197 CleanupStack::PushL(selfObj); |
|
198 |
|
199 CActiveScheduler::Start(); |
|
200 |
|
201 |
|
202 if (Abs((selfObj->volume) - expectedVol) > errRange) |
|
203 { |
|
204 aLogger->Log(_L("Max volume differs from expected value by: %d"),Abs(selfObj->volume - expectedVol)); |
|
205 error = KErrDiffVolume; |
|
206 } |
|
207 |
|
208 CleanupStack::PopAndDestroy(2); // schedule, selfObj |
|
209 |
|
210 return error; |
|
211 } |
|
212 |
|
213 |
|
214 void CPlayVolume::GetFileName(TPtrC path, TFileName* fileName) |
|
215 { |
|
216 |
|
217 TParse p; |
|
218 p.Set(path,NULL,NULL); |
|
219 fileName->Append(p.DriveAndPath()); |
|
220 fileName->Append(p.Name()); |
|
221 |
|
222 fileName->Append(p.Ext()); |
|
223 } |