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