|
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 "RecordDataType.h" |
|
20 #include <mmfFormatImplementationUIDs.hrh> |
|
21 //#include "MdaAudioSampleEditor.h" |
|
22 |
|
23 ////////////////////////////////////////////////////////////////////// |
|
24 // Construction/Destruction |
|
25 ////////////////////////////////////////////////////////////////////// |
|
26 |
|
27 |
|
28 CRecordDataType::CRecordDataType(CTestModuleIf *aConsole, CStifLogger *aLogger) |
|
29 { |
|
30 console = aConsole; |
|
31 logger = aLogger; |
|
32 callbackErr = KErrNone; |
|
33 } |
|
34 |
|
35 CRecordDataType::~CRecordDataType() |
|
36 { |
|
37 |
|
38 if (recorder) delete recorder; |
|
39 recorder = NULL; |
|
40 } |
|
41 |
|
42 |
|
43 void CRecordDataType::ConstructL(TFileName* fileName) |
|
44 { |
|
45 logger->Log(_L("Creating file: %S"),fileName); |
|
46 recorder = CMdaAudioRecorderUtility::NewL(*this); |
|
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 CRecordDataType::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 CRecordDataType |
|
102 aLogger->Log(_L("Creating CRecordDataType")); |
|
103 |
|
104 CRecordDataType* selfObj = CRecordDataType::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 CRecordDataType* CRecordDataType::NewL(CTestModuleIf *aConsole, CStifLogger *aLogger, TFileName* fileName) |
|
119 { |
|
120 CRecordDataType* self = new (ELeave) CRecordDataType(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 CRecordDataType::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode) |
|
136 { |
|
137 #ifdef _DEBUG |
|
138 RDebug::Print (_L ("CRecordDataType::MoscoStateChangeEvent")); |
|
139 #endif |
|
140 TInt err = KErrNone; |
|
141 callbackErr = KErrNone; |
|
142 RArray<TFourCC> dataTypes; |
|
143 |
|
144 logger->Log(_L("MoscoStateChangeEvent called, error: %d prev: %d curr : %d"),aErrorCode,aPreviousState,aCurrentState); |
|
145 |
|
146 |
|
147 |
|
148 if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == 0) |
|
149 { |
|
150 // Initialize |
|
151 recorder->SetAudioDeviceMode(CMdaAudioRecorderUtility::ELocal); |
|
152 logger->Log(_L("Mode set")); |
|
153 recorder->SetGain(recorder->MaxGain()); |
|
154 logger->Log(_L("Gain set")); |
|
155 recorder->SetVolume(recorder->MaxVolume()); |
|
156 logger->Log(_L("Volume set")); |
|
157 recorder->SetPosition(TTimeIntervalMicroSeconds(TInt64(0))); |
|
158 logger->Log(_L("Position set")); |
|
159 |
|
160 |
|
161 logger->Log(_L("SetDestinationDataTypeL set")); |
|
162 |
|
163 |
|
164 TRAPD(err, recorder->SetDestinationDataTypeL(KMMFFourCCCodeNULL)); |
|
165 if (err != KErrNone) |
|
166 { |
|
167 logger->Log(_L("Error %d for SetDestinationDataTypeL(0x%x)"),err, KMMFFourCCCodeNULL ); |
|
168 callbackErr = err; |
|
169 |
|
170 } |
|
171 |
|
172 |
|
173 TFourCC new_fourCC = recorder->DestinationDataTypeL(); |
|
174 if (new_fourCC != KMMFFourCCCodeNULL) |
|
175 { |
|
176 logger->Log(_L("Expected dataType is: 0x%x"), KMMFFourCCCodeNULL); |
|
177 logger->Log(_L("New dataType is: 0x%x"), new_fourCC.FourCC()); |
|
178 logger->Log(_L("Expected dataType is not right") ); |
|
179 callbackErr = KErrOutOfRange; |
|
180 |
|
181 } |
|
182 logger->Log(_L("DestinationDataTypeL Get")); |
|
183 |
|
184 recorder->GetSupportedDestinationDataTypesL(dataTypes); |
|
185 logger->Log(_L("GetSupportedDestinationDataTypesL Get")); |
|
186 |
|
187 |
|
188 recorder->PlayL(); |
|
189 |
|
190 |
|
191 return; |
|
192 } |
|
193 |
|
194 if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == CMdaAudioClipUtility::EPlaying) |
|
195 { |
|
196 TFourCC new_fourCC = recorder->DestinationDataTypeL(); |
|
197 if (new_fourCC != KMMFFourCCCodeNULL) |
|
198 { |
|
199 logger->Log(_L("Expected dataType is: 0x%x"), KMMFFourCCCodeNULL); |
|
200 logger->Log(_L("New dataType is: 0x%x"), new_fourCC.FourCC()); |
|
201 logger->Log(_L("Expected dataType is not right") ); |
|
202 callbackErr = KErrOutOfRange; |
|
203 |
|
204 } |
|
205 logger->Log(_L("DestinationDataTypeL after play.")); |
|
206 |
|
207 |
|
208 CActiveScheduler::Stop(); |
|
209 } |
|
210 |
|
211 |
|
212 |
|
213 return; |
|
214 |
|
215 } |
|
216 |
|
217 |
|
218 |
|
219 void CRecordDataType::GetFileName(TPtrC path, TFileName* fileName) |
|
220 { |
|
221 |
|
222 TParse p; |
|
223 p.Set(path,NULL,NULL); |
|
224 fileName->Append(p.DriveAndPath()); |
|
225 fileName->Append(p.Name()); |
|
226 |
|
227 fileName->Append(p.Ext()); |
|
228 } |