|
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 "CustomCommand.h" |
|
20 #include <mmfFormatImplementationUIDs.hrh> |
|
21 |
|
22 ////////////////////////////////////////////////////////////////////// |
|
23 // Construction/Destruction |
|
24 ////////////////////////////////////////////////////////////////////// |
|
25 |
|
26 |
|
27 CCustomCommand::CCustomCommand(CTestModuleIf *aConsole, CStifLogger *aLogger) |
|
28 { |
|
29 console = aConsole; |
|
30 logger = aLogger; |
|
31 |
|
32 } |
|
33 |
|
34 CCustomCommand::~CCustomCommand() |
|
35 { |
|
36 |
|
37 if (recorder) delete recorder; |
|
38 recorder = NULL; |
|
39 } |
|
40 |
|
41 |
|
42 void CCustomCommand::ConstructL(TFileName* fileName) |
|
43 { |
|
44 logger->Log(_L("Creating file: %S"),fileName); |
|
45 recorder = CMdaAudioRecorderUtility::NewL(*this); |
|
46 |
|
47 if (recorder) |
|
48 { |
|
49 TRAPD(err,recorder->OpenFileL(*fileName)); |
|
50 if (err != KErrNone) |
|
51 { |
|
52 logger->Log(_L("Error %d opening file: %S"),err,fileName); |
|
53 User::Leave(KErrRecOpenFile); |
|
54 } |
|
55 } |
|
56 } |
|
57 |
|
58 TInt CCustomCommand::RunTestL(CTestModuleIf *aConsole, CStifLogger *aLogger, CStifSectionParser *aParser, TInt* /*clipCounter*/) |
|
59 { |
|
60 TInt error = KErrNone; |
|
61 aLogger->Log(_L("Creating scheduler")); |
|
62 |
|
63 CActiveScheduler* scheduler = new (ELeave) CActiveScheduler; |
|
64 CleanupStack::PushL(scheduler); // push to clean-up stack |
|
65 CActiveScheduler::Install(scheduler); // install as active scheduler |
|
66 |
|
67 TFileName fileName; |
|
68 |
|
69 //Get file name |
|
70 TPtrC name; |
|
71 CStifItemParser* item = aParser->GetItemLineL(KFileName, ENoTag); |
|
72 if (!item) |
|
73 { |
|
74 CleanupStack::PopAndDestroy(); |
|
75 return KErrSyntax; |
|
76 } |
|
77 |
|
78 CleanupStack::PushL(item); |
|
79 if (item->GetString(KEmptyString,name) != KErrNone) |
|
80 { |
|
81 aLogger->Log(_L("Invalid file name")); |
|
82 CleanupStack::PopAndDestroy(2); |
|
83 return KErrSyntax; |
|
84 } |
|
85 CleanupStack::PopAndDestroy(); |
|
86 |
|
87 GetFileName(name,&fileName); |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 if (error != KErrNone) |
|
95 { |
|
96 CleanupStack::PopAndDestroy(); //scheduler |
|
97 return error; |
|
98 } |
|
99 |
|
100 |
|
101 // create CThreadPriority |
|
102 aLogger->Log(_L("Creating CCustomCommand")); |
|
103 |
|
104 CCustomCommand* selfObj = CCustomCommand::NewL(aConsole, aLogger, &fileName); |
|
105 |
|
106 |
|
107 CleanupStack::PushL(selfObj); |
|
108 |
|
109 CActiveScheduler::Start(); |
|
110 |
|
111 |
|
112 CleanupStack::PopAndDestroy(2); // schedule, selfObj |
|
113 |
|
114 return error; |
|
115 } |
|
116 |
|
117 |
|
118 CCustomCommand* CCustomCommand::NewL(CTestModuleIf *aConsole, CStifLogger *aLogger, TFileName* fileName) |
|
119 { |
|
120 CCustomCommand* self = new (ELeave) CCustomCommand(aConsole, aLogger); |
|
121 CleanupStack::PushL(self); |
|
122 |
|
123 // self->ConstructL(fileName); |
|
124 TRAPD(err, self->ConstructL(fileName)); |
|
125 if (err != KErrNone) |
|
126 { |
|
127 CleanupStack::PopAndDestroy(); |
|
128 return NULL; |
|
129 } |
|
130 |
|
131 CleanupStack::Pop(self); |
|
132 return self; |
|
133 } |
|
134 |
|
135 void CCustomCommand::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode) |
|
136 { |
|
137 #ifdef _DEBUG |
|
138 RDebug::Print (_L ("CCustomCommand::MoscoStateChangeEvent")); |
|
139 #endif |
|
140 TInt err = KErrNone; |
|
141 |
|
142 logger->Log(_L("MoscoStateChangeEvent called, error: %d prev: %d curr : %d"),aErrorCode,aPreviousState,aCurrentState); |
|
143 |
|
144 TUint bitRate = recorder->SourceBitRateL(); |
|
145 logger->Log(_L("SourceBitRateL %d "),bitRate); |
|
146 |
|
147 |
|
148 if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == 0) |
|
149 { |
|
150 TBuf8<25> dataFrom; |
|
151 |
|
152 TRequestStatus status; |
|
153 TMMFMessageDestinationPckg dummyPckg; |
|
154 TInt dummyFunc = 100; |
|
155 TBuf8<8> dummyBuff; |
|
156 |
|
157 // Initialize |
|
158 recorder->SetAudioDeviceMode(CMdaAudioRecorderUtility::ELocal); |
|
159 logger->Log(_L("Mode set")); |
|
160 recorder->SetGain(recorder->MaxGain()); |
|
161 logger->Log(_L("Gain set")); |
|
162 recorder->SetVolume(recorder->MaxVolume()); |
|
163 logger->Log(_L("Volume set")); |
|
164 recorder->SetPosition(TTimeIntervalMicroSeconds(TInt64(0))); |
|
165 logger->Log(_L("Position set")); |
|
166 |
|
167 |
|
168 TRAPD(err, recorder->PlayControllerCustomCommandSync(dummyPckg, dummyFunc, |
|
169 dummyBuff, dummyBuff, dataFrom)); |
|
170 if (err != KErrNone) |
|
171 { |
|
172 logger->Log(_L("PlayControllerCustomCommandSync with dataFrom - err=%d"), err); |
|
173 |
|
174 } |
|
175 logger->Log(_L("PlayControllerCustomCommandSync with dataFrom successful")); |
|
176 |
|
177 TRAP(err, recorder->PlayControllerCustomCommandSync(dummyPckg, dummyFunc, |
|
178 dummyBuff, dummyBuff)); |
|
179 if (err != KErrNone) |
|
180 { |
|
181 logger->Log(_L("PlayControllerCustomCommandSync - err=%d"), err); |
|
182 |
|
183 } |
|
184 logger->Log(_L("PlayControllerCustomCommandSync successful")); |
|
185 |
|
186 |
|
187 recorder->RegisterForAudioLoadingNotification(*this); |
|
188 logger->Log(_L("RegisterForAudioLoadingNotification set")); |
|
189 recorder->RegisterAudioResourceNotification(*this,KUidInterfaceMMFController); |
|
190 logger->Log(_L("RegisterAudioResourceNotification set")); |
|
191 recorder->CancelRegisterAudioResourceNotification(KUidInterfaceMMFController); |
|
192 logger->Log(_L("CancelRegisterAudioResourceNotification set")); |
|
193 |
|
194 |
|
195 |
|
196 //PlayController |
|
197 TRAPD(err1, recorder->RecordControllerCustomCommandSync(dummyPckg, dummyFunc, |
|
198 dummyBuff, dummyBuff, dataFrom)); |
|
199 if (err1 != KErrNone) |
|
200 { |
|
201 logger->Log(_L("RecordControllerCustomCommandSync with dataFrom - err=%d"), err1); |
|
202 |
|
203 } |
|
204 logger->Log(_L("RecordControllerCustomCommandSync with dataFrom successful")); |
|
205 |
|
206 TRAP(err, recorder->RecordControllerCustomCommandSync(dummyPckg, dummyFunc, |
|
207 dummyBuff, dummyBuff)); |
|
208 if (err != KErrNone) |
|
209 { |
|
210 logger->Log(_L("RecordControllerCustomCommandSync - err=%d"), err); |
|
211 |
|
212 } |
|
213 logger->Log(_L("RecordControllerCustomCommandSync successful")); |
|
214 |
|
215 logger->Log(_L("Using UseSharedHeap")); |
|
216 recorder->UseSharedHeap(); |
|
217 |
|
218 recorder->PlayL(); |
|
219 |
|
220 |
|
221 return; |
|
222 |
|
223 } |
|
224 |
|
225 if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == CMdaAudioClipUtility::EPlaying) |
|
226 { |
|
227 // Create DRM custom command |
|
228 MMMFDRMCustomCommand* drmCustomCommand; |
|
229 drmCustomCommand = recorder->GetDRMCustomCommand(); |
|
230 if (drmCustomCommand == NULL) |
|
231 { |
|
232 logger->Log(_L("MMMFDRMCustomCommand is NULL.")); |
|
233 |
|
234 } |
|
235 logger->Log(_L("MMMFDRMCustomCommand is successful.")); |
|
236 |
|
237 recorder->WillResumePlay(); |
|
238 CActiveScheduler::Stop(); |
|
239 } |
|
240 |
|
241 return; |
|
242 |
|
243 } |
|
244 |
|
245 void CCustomCommand::MaloLoadingStarted() |
|
246 { |
|
247 logger->Log(_L("MaloLoadingStarted ")); |
|
248 } |
|
249 |
|
250 void CCustomCommand::MaloLoadingComplete() |
|
251 { |
|
252 logger->Log(_L("MaloLoadingComplete ")); |
|
253 } |
|
254 |
|
255 |
|
256 void CCustomCommand::MarncResourceAvailable(TUid aNotificationEventId, const TDesC8 &aNotificationData) |
|
257 { |
|
258 logger->Log(_L("MarncResourceAvailable ")); |
|
259 } |
|
260 |
|
261 void CCustomCommand::GetFileName(TPtrC path, TFileName* fileName) |
|
262 { |
|
263 |
|
264 TParse p; |
|
265 p.Set(path,NULL,NULL); |
|
266 fileName->Append(p.DriveAndPath()); |
|
267 fileName->Append(p.Name()); |
|
268 |
|
269 fileName->Append(p.Ext()); |
|
270 } |