0
|
1 |
// Copyright (c) 2002-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 |
// This file contains an example Test step implementation
|
|
15 |
// This demonstrates the various functions provided
|
|
16 |
// by the CTestStep base class which are available within
|
|
17 |
// a test step
|
|
18 |
//
|
|
19 |
//
|
|
20 |
|
|
21 |
// EPOC includes
|
|
22 |
#include <e32base.h>
|
|
23 |
#include <e32test.h>
|
|
24 |
#include <e32keys.h>
|
|
25 |
#include <c32comm.h>
|
|
26 |
#include <f32file.h>
|
|
27 |
#include <etel.h>
|
|
28 |
#include <etelmm.h>
|
|
29 |
#include <testframework.h>
|
|
30 |
|
|
31 |
//#include <MdaAudioSamplePlayer.h>
|
|
32 |
#include <mdaaudiosampleeditor.h>
|
|
33 |
//#include <MdaAudioTonePlayer.h>
|
|
34 |
|
|
35 |
// Test system includes
|
|
36 |
#include <testframework.h>
|
|
37 |
|
|
38 |
// Specific includes for this test suite
|
|
39 |
#include "TestStepUnitMMFAudClient.h"
|
|
40 |
#include "TestSuiteUnitMMFAudClient.h"
|
|
41 |
|
|
42 |
// Specific includes for these test steps
|
|
43 |
#include "TestStepRecorder.h"
|
|
44 |
|
|
45 |
|
|
46 |
#include "MmfAudioController.h"
|
|
47 |
#include "mmfclientaudiorecorder.h"
|
|
48 |
//#include "MmfClientAudioPlayer.h"
|
|
49 |
//#include <mmffourcc.h>
|
|
50 |
//#include <mmfpaniccodes.h>
|
|
51 |
//#include <mmfFormatImplementationUIDs.hrh>
|
|
52 |
// --------------------------------------------
|
|
53 |
|
|
54 |
//const TInt KPcm16FrameInterval = 371512; // EABI warning removal
|
|
55 |
|
|
56 |
// frame size is now variable, depeding on the sample rate
|
|
57 |
//const TInt KFrameSize8K16Bit = 4096; // frame size for 8Khz // EABI warning removal
|
|
58 |
|
|
59 |
//if frame size is 4096 bytes, then a sample file of 8KHz, 16bit, mono,
|
|
60 |
// would be 16000 bytes per second, therefore a frame would represent 256 millisecs
|
|
61 |
// we make sure the deviation is not greater than a frame since we can only crop frames.
|
|
62 |
const TInt KExpectedDeviation = (256000); //200000
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
// Orig duration = 1000120 Us, 90% = 900108 Us; @8KHz, 16bits, 1 channel = 14400 bytes (aligned to sample)
|
|
68 |
const TInt KExpectedCropSize1 = 14400 + 44;
|
|
69 |
|
|
70 |
// Second crop - original duration is still taken from source (known error) = 10000120 Us.
|
|
71 |
//Therefore crop point = 40% of 10000120 Us = 400048 Us.
|
|
72 |
//Crop from begining to 400048Us with @8KHz, 16bits, 1 channel = 6400 bytes (aligned to sample).
|
|
73 |
//New file = KExpectedCropSize1 - 6400 = 8046
|
|
74 |
const TInt KExpectedCropSize2 = 8000 + 44;
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
/**
|
|
79 |
*
|
|
80 |
* Static constructor for CTestStepRecorderCrop.
|
|
81 |
*
|
|
82 |
*
|
|
83 |
* @return "CTestStepRecorderCrop*"
|
|
84 |
* The constructed CTestStepRecorderCrop
|
|
85 |
*
|
|
86 |
* @xxxx
|
|
87 |
*
|
|
88 |
*/
|
|
89 |
CTestStepRecorderCrop* CTestStepRecorderCrop::NewL(const TDesC& aTestName, TBool aIsConverterTest)
|
|
90 |
{
|
|
91 |
CTestStepRecorderCrop* self = new(ELeave) CTestStepRecorderCrop(aTestName, aIsConverterTest);
|
|
92 |
return self;
|
|
93 |
}
|
|
94 |
|
|
95 |
/**
|
|
96 |
*
|
|
97 |
* Test step constructor.
|
|
98 |
* Each test step initialises its own name.
|
|
99 |
*
|
|
100 |
* @xxxx
|
|
101 |
*
|
|
102 |
*/
|
|
103 |
CTestStepRecorderCrop::CTestStepRecorderCrop(const TDesC& aTestName, TBool aIsConverterTest)
|
|
104 |
: iError(0), iHasCropped(EFalse), iIsConverterTest(aIsConverterTest)
|
|
105 |
{
|
|
106 |
// store the name of this test case
|
|
107 |
// this is the name that is used by the script file
|
|
108 |
iTestStepName = aTestName;
|
|
109 |
}
|
|
110 |
|
|
111 |
/**
|
|
112 |
*
|
|
113 |
* Test step destructor.
|
|
114 |
*
|
|
115 |
* @xxxx
|
|
116 |
*
|
|
117 |
*/
|
|
118 |
CTestStepRecorderCrop::~CTestStepRecorderCrop()
|
|
119 |
{
|
|
120 |
}
|
|
121 |
|
|
122 |
/**
|
|
123 |
*
|
|
124 |
* Test step Preamble.
|
|
125 |
*
|
|
126 |
* @xxxx
|
|
127 |
*
|
|
128 |
*/
|
|
129 |
enum TVerdict CTestStepRecorderCrop::DoTestStepPreambleL(void)
|
|
130 |
{
|
|
131 |
enum TVerdict verdict = EPass;
|
|
132 |
// this installs the scheduler
|
|
133 |
verdict = CTestStepUnitMMFAudClient::DoTestStepPreambleL();
|
|
134 |
|
|
135 |
// Printing to the console and log file
|
|
136 |
INFO_PRINTF1(iTestStepName);
|
|
137 |
if (!iIsConverterTest)
|
|
138 |
INFO_PRINTF1(_L("this is a test of CMdaAudioRecorderUtility::CropL(beginning/end)"));
|
|
139 |
else
|
|
140 |
INFO_PRINTF1(_L("this is a test of CMdaAudioConvertUtility::CropL(beginning/end)"));
|
|
141 |
|
|
142 |
// open the file to be cropped
|
|
143 |
|
|
144 |
|
|
145 |
User::LeaveIfError(iFs.Connect());
|
|
146 |
iFileMan = CFileMan::NewL(iFs);
|
|
147 |
if (iIsConverterTest)
|
|
148 |
{
|
|
149 |
if(!GetStringFromConfig(_L("SectionOne"), _L("AudioFNameToConvertAndCrop"), iFileName)) //au
|
|
150 |
return EInconclusive;
|
|
151 |
|
|
152 |
iFileNameTmp = iFileName;
|
|
153 |
_LIT(KExtTmp,".tmp.au");
|
|
154 |
iFileNameTmp.Append(KExtTmp);
|
|
155 |
|
|
156 |
//create a copy of the input file to work on
|
|
157 |
User::LeaveIfError(iFileMan->Copy(iFileName, iFileNameTmp));
|
|
158 |
|
|
159 |
//construct an autput filename
|
|
160 |
iOutputFileName = iFileName;
|
|
161 |
_LIT(KExtOutput,".output.wav");
|
|
162 |
iOutputFileName.Append(KExtOutput);
|
|
163 |
|
|
164 |
//delete any existing output file
|
|
165 |
TInt deleteErr = iFileMan->Delete(iOutputFileName); //delete oput file before start test
|
|
166 |
if(deleteErr != KErrNone && deleteErr != KErrNotFound)
|
|
167 |
User::Leave(deleteErr);
|
|
168 |
}
|
|
169 |
else
|
|
170 |
{
|
|
171 |
if(!GetStringFromConfig(_L("SectionOne"), _L("AudioFNameToCrop"), iFileName))
|
|
172 |
return EInconclusive;
|
|
173 |
|
|
174 |
iFileNameTmp = iFileName;
|
|
175 |
_LIT(KExtTmp,".tmp.wav");
|
|
176 |
iFileNameTmp.Append(KExtTmp);
|
|
177 |
|
|
178 |
User::LeaveIfError(iFileMan->Copy(iFileName, iFileNameTmp));
|
|
179 |
}
|
|
180 |
|
|
181 |
|
|
182 |
iFs.Close();
|
|
183 |
delete iFileMan;
|
|
184 |
iFileMan = NULL;
|
|
185 |
User::After(200000); // just in case
|
|
186 |
|
|
187 |
if (!iIsConverterTest)
|
|
188 |
{//0240
|
|
189 |
if ( (iRecorder = CMMFMdaAudioRecorderUtility::NewL(*this)) == NULL )
|
|
190 |
verdict = EInconclusive;
|
|
191 |
|
|
192 |
iRecorder->OpenFileL(iFileNameTmp);
|
|
193 |
CActiveScheduler::Start();
|
|
194 |
if (iError != KErrNone ||
|
|
195 |
iRecorder->State() != CMdaAudioRecorderUtility::EOpen)
|
|
196 |
return EInconclusive;
|
|
197 |
|
|
198 |
iRecorder->SetGain(iRecorder->MaxGain()/2);
|
|
199 |
iOrigDuration = iRecorder->Duration().Int64();
|
|
200 |
|
|
201 |
if ( iError != KErrNone ||
|
|
202 |
iRecorder->State() != CMdaAudioRecorderUtility::EOpen)
|
|
203 |
verdict = EInconclusive;
|
|
204 |
}
|
|
205 |
else
|
|
206 |
{//566
|
|
207 |
if ( (iConvert = CMdaAudioConvertUtility::NewL(*this)) == NULL )
|
|
208 |
verdict = EInconclusive;
|
|
209 |
|
|
210 |
iConvert->OpenL(iFileNameTmp, iOutputFileName);
|
|
211 |
// Another initialisation of the convert utility
|
|
212 |
// should behave the same as the one above
|
|
213 |
//TMdaFileClipLocation* target = new TMdaFileClipLocation(iFileName3);
|
|
214 |
//TMdaAuClipFormat auClipFormat;
|
|
215 |
//TMdaPcm16BitAuCodec au16bitCodec; //KMMFFourCCCodePCM16B
|
|
216 |
//iConvert->OpenL(iFileNameTmp, target,
|
|
217 |
// &auClipFormat,
|
|
218 |
// &au16bitCodec);
|
|
219 |
|
|
220 |
CActiveScheduler::Start();
|
|
221 |
if (iError != KErrNone ||
|
|
222 |
iConvert->State() != CMdaAudioConvertUtility::EOpen)
|
|
223 |
return EInconclusive;
|
|
224 |
|
|
225 |
iOrigDuration = iConvert->Duration().Int64();
|
|
226 |
|
|
227 |
if ( iError != KErrNone ||
|
|
228 |
iConvert->State() != CMdaAudioConvertUtility::EOpen)
|
|
229 |
verdict = EInconclusive;
|
|
230 |
|
|
231 |
// convert because cropping only applies to destination
|
|
232 |
// before conversion destination is empty -> hence no cropping available
|
|
233 |
TRAPD(err, iConvert->ConvertL());
|
|
234 |
// Note: Converting by just openning a wav and an au file will work incorrectly:
|
|
235 |
// the resutling file will contain noise, since the default conversion will be e.g.
|
|
236 |
// wav:PCM16 -> au:PCM16, instead of wav:PCM16 -> au:PCM16BE (Big Endian)
|
|
237 |
// Cropping, duration, position and the flow of the tested code is fine though,
|
|
238 |
// so it serves the purpose of this test, i.e. cropping
|
|
239 |
// This error might be fixed in the future so Big Endian codec is chosen
|
|
240 |
CActiveScheduler::Start(); // open -> record
|
|
241 |
if (err != KErrNone || iError != KErrNone)
|
|
242 |
return EInconclusive;
|
|
243 |
CActiveScheduler::Start(); // record -> open
|
|
244 |
if (err != KErrNone || iError != KErrNone)
|
|
245 |
return EInconclusive;
|
|
246 |
}
|
|
247 |
|
|
248 |
|
|
249 |
return verdict;
|
|
250 |
}
|
|
251 |
|
|
252 |
/**
|
|
253 |
*
|
|
254 |
* Test step Postamble.
|
|
255 |
*
|
|
256 |
* @xxxx
|
|
257 |
*
|
|
258 |
*/
|
|
259 |
enum TVerdict CTestStepRecorderCrop::DoTestStepPostambleL(void)
|
|
260 |
{
|
|
261 |
if (!iIsConverterTest)
|
|
262 |
iRecorder->Close();
|
|
263 |
else
|
|
264 |
iConvert->Close();
|
|
265 |
|
|
266 |
//delete the temp, cropped file
|
|
267 |
User::LeaveIfError(iFs.Connect());
|
|
268 |
iFileMan = CFileMan::NewL(iFs);
|
|
269 |
User::LeaveIfError(iFileMan->Delete(iFileNameTmp));
|
|
270 |
|
|
271 |
if (iIsConverterTest)
|
|
272 |
User::LeaveIfError(iFileMan->Delete(iOutputFileName));
|
|
273 |
|
|
274 |
iFs.Close();
|
|
275 |
delete iFileMan;
|
|
276 |
iFileMan = NULL;
|
|
277 |
|
|
278 |
if (!iIsConverterTest)
|
|
279 |
{//240
|
|
280 |
delete iRecorder;
|
|
281 |
iRecorder = NULL;
|
|
282 |
}
|
|
283 |
else
|
|
284 |
{//566
|
|
285 |
delete iConvert;
|
|
286 |
iConvert = NULL;
|
|
287 |
}
|
|
288 |
|
|
289 |
//[ Destroy the scheduler ]
|
|
290 |
return CTestStepUnitMMFAudClient::DoTestStepPostambleL();
|
|
291 |
}
|
|
292 |
|
|
293 |
/**
|
|
294 |
*
|
|
295 |
* Callback Handle.
|
|
296 |
*
|
|
297 |
* @xxxx
|
|
298 |
*
|
|
299 |
*/
|
|
300 |
void CTestStepRecorderCrop::MoscoStateChangeEvent(CBase* /*aObject*/,
|
|
301 |
TInt /*aPreviousState*/,
|
|
302 |
TInt /*aCurrentState*/,
|
|
303 |
TInt aErrorcCode)
|
|
304 |
{
|
|
305 |
iError = aErrorcCode;
|
|
306 |
CActiveScheduler::Stop();
|
|
307 |
}
|
|
308 |
|
|
309 |
void CTestStepRecorderCrop::CropAndStartSchedulerL(const TTimeIntervalMicroSeconds& aBegin,
|
|
310 |
const TTimeIntervalMicroSeconds& aEnd)
|
|
311 |
{
|
|
312 |
if (!iIsConverterTest)
|
|
313 |
{
|
|
314 |
iRecorder->CropL(aBegin, aEnd);
|
|
315 |
//CActiveScheduler::Start(); // it works synchronously even if we don't start the ActiveScheduler
|
|
316 |
|
|
317 |
|
|
318 |
//Check if the cropped duration is within the deviation from the expected duration
|
|
319 |
TInt64 cropDur = iRecorder->Duration().Int64();
|
|
320 |
TInt64 difDur = aEnd.Int64() - aBegin.Int64();
|
|
321 |
TInt delta = I64INT(cropDur - difDur);
|
|
322 |
if(delta < 0)
|
|
323 |
delta *= (-1);
|
|
324 |
|
|
325 |
if ( delta <= KExpectedDeviation )
|
|
326 |
iHasCropped = ETrue;
|
|
327 |
//iRecorder->Stop();
|
|
328 |
}
|
|
329 |
else // not really used in this test
|
|
330 |
{
|
|
331 |
}
|
|
332 |
}
|
|
333 |
|
|
334 |
void CTestStepRecorderCrop::CropAndStartSchedulerL(TTimeIntervalMicroSeconds aCropPoint, TBool aCropToEnd)
|
|
335 |
{
|
|
336 |
_LIT(_toEnd,"to end from");
|
|
337 |
_LIT(_fromBegining,"from beginning to");
|
|
338 |
|
|
339 |
if (!iIsConverterTest)
|
|
340 |
{//240
|
|
341 |
iRecorder->SetPosition(aCropPoint);
|
|
342 |
const TTimeIntervalMicroSeconds pos = iRecorder->Position();
|
|
343 |
|
|
344 |
iRecorder->CropL(aCropToEnd);
|
|
345 |
//CActiveScheduler::Start(); // it works synchronously even if we don't start the ActiveScheduler
|
|
346 |
|
|
347 |
|
|
348 |
//Check if the cropped duration is within the deviation from the expected duration
|
|
349 |
TInt64 cropDur = iRecorder->Duration().Int64();
|
|
350 |
TInt64 difDur = 0;
|
|
351 |
if (aCropToEnd)
|
|
352 |
difDur = pos.Int64();
|
|
353 |
else
|
|
354 |
difDur = iOrigDuration - pos.Int64();
|
|
355 |
TInt delta = I64INT(cropDur - difDur);
|
|
356 |
if(delta < 0)
|
|
357 |
delta *= (-1);
|
|
358 |
|
|
359 |
if ( delta <= KExpectedDeviation )
|
|
360 |
iHasCropped = ETrue;
|
|
361 |
|
|
362 |
|
|
363 |
INFO_PRINTF2(_L("Cropping from original duration = %d"), iOrigDuration);
|
|
364 |
INFO_PRINTF3(_L("Cropping %S %d "), (aCropToEnd ? &_toEnd : &_fromBegining), aCropPoint.Int64());
|
|
365 |
INFO_PRINTF2(_L("Crop point was set at = %d"), pos.Int64());
|
|
366 |
INFO_PRINTF2(_L("Cropped to = %d"), cropDur);
|
|
367 |
//iRecorder->Stop();
|
|
368 |
}
|
|
369 |
else
|
|
370 |
{
|
|
371 |
iHasCropped = ETrue;
|
|
372 |
|
|
373 |
iConvert->SetPosition(aCropPoint);
|
|
374 |
|
|
375 |
if (aCropToEnd)
|
|
376 |
iConvert->CropL(); // default: crop to end
|
|
377 |
else
|
|
378 |
iConvert->CropFromBeginningL();
|
|
379 |
//CActiveScheduler::Start(); // it works synchronously even if we don't start the ActiveScheduler
|
|
380 |
|
|
381 |
|
|
382 |
//Check if the cropped duration is within the deviation from the expected duration
|
|
383 |
// Note: there is a problem with duration, since Duration() always returns the
|
|
384 |
// duration of the original clip (source clip) before conversion
|
|
385 |
// One can set the position beyond the end of the cropped file, but still below the
|
|
386 |
// original duration before cropping, and start a second cropping. This might lead
|
|
387 |
// to unexpected behaviour.
|
|
388 |
//TInt64 cropDur = iConvert->Duration().Int64();
|
|
389 |
// there is no converter API to check the destination(sink) duration after cropping
|
|
390 |
|
|
391 |
// we are just checking if the cropping took place by checking the size of the
|
|
392 |
// cropped file
|
|
393 |
TInt croppedSize = 0;
|
|
394 |
|
|
395 |
User::LeaveIfError(iFs.Connect());
|
|
396 |
RFile croppedFile;
|
|
397 |
User::LeaveIfError(croppedFile.Open(iFs, iOutputFileName, EFileRead ));
|
|
398 |
CleanupClosePushL(croppedFile);
|
|
399 |
User::LeaveIfError(croppedFile.Size(croppedSize));
|
|
400 |
|
|
401 |
TInt expectedCrop=0;
|
|
402 |
|
|
403 |
if (aCropToEnd)
|
|
404 |
{
|
|
405 |
expectedCrop=KExpectedCropSize1;
|
|
406 |
if (croppedSize != expectedCrop)
|
|
407 |
iHasCropped = EFalse;
|
|
408 |
}
|
|
409 |
else // second crop to beginning
|
|
410 |
{
|
|
411 |
expectedCrop=KExpectedCropSize2;
|
|
412 |
if (croppedSize != expectedCrop)
|
|
413 |
iHasCropped = EFalse;
|
|
414 |
}
|
|
415 |
|
|
416 |
INFO_PRINTF2(_L("Cropping from original duration = %d"), iOrigDuration);
|
|
417 |
INFO_PRINTF3(_L("Cropping %S %d "), (aCropToEnd ? &_toEnd : &_fromBegining), aCropPoint.Int64());
|
|
418 |
INFO_PRINTF3(_L("Cropped to = %d bytes (expected %d bytes)"), croppedSize,expectedCrop);
|
|
419 |
|
|
420 |
CleanupStack::PopAndDestroy(&croppedFile);
|
|
421 |
iFs.Close();
|
|
422 |
}
|
|
423 |
}
|
|
424 |
|
|
425 |
|
|
426 |
|
|
427 |
/**
|
|
428 |
*
|
|
429 |
* Do the test step.
|
|
430 |
* Each test step must supply an implementation for DoTestStepL.
|
|
431 |
*
|
|
432 |
* @return "TVerdict"
|
|
433 |
* The result of the test step
|
|
434 |
*
|
|
435 |
* @xxxx
|
|
436 |
*
|
|
437 |
*/
|
|
438 |
TVerdict CTestStepRecorderCrop::DoTestStepL()
|
|
439 |
{
|
|
440 |
iTestStepResult = EPass;
|
|
441 |
TInt err = KErrNone;
|
|
442 |
|
|
443 |
//NB: crop points are carfully choosen to ensure that at least one block is removed
|
|
444 |
//during each crop operation.
|
|
445 |
|
|
446 |
if (!iIsConverterTest)
|
|
447 |
{//240
|
|
448 |
//crop 40% from beginning of clip
|
|
449 |
TRAP( err, CropAndStartSchedulerL(iOrigDuration / 5 *2, EFalse) );
|
|
450 |
|
|
451 |
if (err != KErrNone ||
|
|
452 |
!iHasCropped ||
|
|
453 |
iRecorder->State() != CMdaAudioRecorderUtility::EOpen )
|
|
454 |
return EFail;
|
|
455 |
|
|
456 |
iHasCropped = EFalse;
|
|
457 |
iOrigDuration = iRecorder->Duration().Int64();
|
|
458 |
//crop frop 80% to end of file
|
|
459 |
TRAP( err, CropAndStartSchedulerL(iOrigDuration - (iOrigDuration/5), ETrue) );
|
|
460 |
|
|
461 |
if (err != KErrNone ||
|
|
462 |
!iHasCropped ||
|
|
463 |
iRecorder->State() != CMdaAudioRecorderUtility::EOpen )
|
|
464 |
{
|
|
465 |
INFO_PRINTF4(_L("Failed err=%d iHasCropped=%d State=%d"),err, iHasCropped, iRecorder->State());
|
|
466 |
return EFail;
|
|
467 |
}
|
|
468 |
}
|
|
469 |
else // iIsConverterTest == ETRue
|
|
470 |
{//566
|
|
471 |
//crop from 90% to end of file
|
|
472 |
TRAP( err, CropAndStartSchedulerL(iOrigDuration - (iOrigDuration/10), ETrue) );
|
|
473 |
|
|
474 |
if (err != KErrNone ||
|
|
475 |
!iHasCropped ||
|
|
476 |
iConvert->State() != CMdaAudioConvertUtility::EOpen )
|
|
477 |
{
|
|
478 |
INFO_PRINTF4(_L("Failed err=%d iHasCropped=%d State=%d"),err, iHasCropped, iConvert->State());
|
|
479 |
return EFail;
|
|
480 |
}
|
|
481 |
|
|
482 |
// crop again
|
|
483 |
iHasCropped = EFalse;
|
|
484 |
iOrigDuration = iConvert->Duration().Int64();
|
|
485 |
|
|
486 |
//crop 40% from beginning of clip
|
|
487 |
TRAP( err, CropAndStartSchedulerL(iOrigDuration / 5 * 2, EFalse) ); // crop from beginning
|
|
488 |
|
|
489 |
if (err != KErrNone ||
|
|
490 |
!iHasCropped ||
|
|
491 |
iConvert->State() != CMdaAudioConvertUtility::EOpen )
|
|
492 |
{
|
|
493 |
INFO_PRINTF4(_L("Failed err=%d iHasCropped=%d State=%d"),err, iHasCropped, iConvert->State());
|
|
494 |
return EFail;
|
|
495 |
}
|
|
496 |
}
|
|
497 |
|
|
498 |
INFO_PRINTF1(_L("finished with this test step"));
|
|
499 |
// test steps return a result
|
|
500 |
return iTestStepResult;
|
|
501 |
}
|
|
502 |
|
|
503 |
//
|
|
504 |
// add new test here for descriptor crop
|
|
505 |
//
|
|
506 |
|
|
507 |
/**
|
|
508 |
*
|
|
509 |
* Static constructor for CTestStepRecCropDescriptor
|
|
510 |
*
|
|
511 |
*
|
|
512 |
* @return "CTestStepRecCropDescriptor*"
|
|
513 |
* The constructed CTestStepRecCropDescriptor
|
|
514 |
*
|
|
515 |
* @xxxx
|
|
516 |
*
|
|
517 |
*/
|
|
518 |
CTestStepRecCropDescriptor* CTestStepRecCropDescriptor::NewL(const TDesC& aTestName, TBool aUseOldApi )
|
|
519 |
{
|
|
520 |
CTestStepRecCropDescriptor* self = new(ELeave) CTestStepRecCropDescriptor(aTestName, aUseOldApi);
|
|
521 |
return self;
|
|
522 |
}
|
|
523 |
|
|
524 |
/**
|
|
525 |
*
|
|
526 |
* Test step constructor.
|
|
527 |
* Each test step initialises its own name.
|
|
528 |
*
|
|
529 |
* @xxxx
|
|
530 |
*
|
|
531 |
*/
|
|
532 |
CTestStepRecCropDescriptor::CTestStepRecCropDescriptor(const TDesC& aTestName, TBool aUseOldApi )
|
|
533 |
: iError(0), iHasCropped(EFalse), iIsOldAPiTest( aUseOldApi )
|
|
534 |
{
|
|
535 |
// store the name of this test case
|
|
536 |
// this is the name that is used by the script file
|
|
537 |
iTestStepName = aTestName;
|
|
538 |
}
|
|
539 |
|
|
540 |
/**
|
|
541 |
*
|
|
542 |
* Test step destructor.
|
|
543 |
*
|
|
544 |
* @xxxx
|
|
545 |
*
|
|
546 |
*/
|
|
547 |
CTestStepRecCropDescriptor::~CTestStepRecCropDescriptor()
|
|
548 |
{
|
|
549 |
}
|
|
550 |
|
|
551 |
/**
|
|
552 |
*
|
|
553 |
* Test step Preamble.
|
|
554 |
*
|
|
555 |
* @xxxx
|
|
556 |
*
|
|
557 |
*/
|
|
558 |
enum TVerdict CTestStepRecCropDescriptor::DoTestStepPreambleL(void)
|
|
559 |
{
|
|
560 |
enum TVerdict verdict = EPass;
|
|
561 |
// this installs the scheduler
|
|
562 |
verdict = CTestStepUnitMMFAudClient::DoTestStepPreambleL();
|
|
563 |
|
|
564 |
// Printing to the console and log file
|
|
565 |
INFO_PRINTF1(iTestStepName);
|
|
566 |
|
|
567 |
INFO_PRINTF1(_L("this is a test of CMdaAudioRecorderUtility::CropL(beginning/end)"));
|
|
568 |
|
|
569 |
// open the file to be cropped
|
|
570 |
|
|
571 |
if(!(GetStringFromConfig(_L("SectionOne"), _L("AudioFNameToCrop"), iFileName)))
|
|
572 |
{
|
|
573 |
return EInconclusive;
|
|
574 |
}
|
|
575 |
|
|
576 |
// copy file to descriptor
|
|
577 |
iFileNameTmp = iFileName;
|
|
578 |
|
|
579 |
//[ append to file name and copy file to tmp file ]
|
|
580 |
_LIT(KExtTmp,".tmp.wav");
|
|
581 |
iFileNameTmp.Append(KExtTmp);
|
|
582 |
|
|
583 |
iFs.Connect();
|
|
584 |
iFileMan = CFileMan::NewL(iFs);
|
|
585 |
iFileMan->Copy(iFileName, iFileNameTmp);
|
|
586 |
iFs.Close();
|
|
587 |
delete iFileMan;
|
|
588 |
iFileMan = NULL;
|
|
589 |
|
|
590 |
|
|
591 |
//[ read the file into a descriptor ]
|
|
592 |
ReadFileToDescriptorL( iFileNameTmp);
|
|
593 |
|
|
594 |
delete iFileMan;
|
|
595 |
iFileMan = NULL;
|
|
596 |
|
|
597 |
User::After(200000); // just in case
|
|
598 |
|
|
599 |
if ( (iRecorder = CMMFMdaAudioRecorderUtility::NewL(*this)) == NULL )
|
|
600 |
verdict = EInconclusive;
|
|
601 |
|
|
602 |
//[ Open the descriptor]
|
|
603 |
//[ set up the tdes8 here and every thing should be kosher]
|
|
604 |
|
|
605 |
if( iIsOldAPiTest )
|
|
606 |
{
|
|
607 |
iRecorder->OpenDesL( *iDes8 );
|
|
608 |
}
|
|
609 |
else
|
|
610 |
{
|
|
611 |
//[ since TDes8 is derived from TDesC8 we can do this cast
|
|
612 |
// to force the correct api to be used ]
|
|
613 |
iRecorder->OpenDesL( (const TDesC8&)(*iDes8) );
|
|
614 |
}
|
|
615 |
|
|
616 |
|
|
617 |
CActiveScheduler::Start();
|
|
618 |
if (iError != KErrNone ||
|
|
619 |
iRecorder->State() != CMdaAudioRecorderUtility::EOpen)
|
|
620 |
return EInconclusive;
|
|
621 |
|
|
622 |
iRecorder->SetGain(iRecorder->MaxGain()/2);
|
|
623 |
iOrigDuration = iRecorder->Duration().Int64();
|
|
624 |
|
|
625 |
if ( iError != KErrNone ||
|
|
626 |
iRecorder->State() != CMdaAudioRecorderUtility::EOpen)
|
|
627 |
verdict = EInconclusive;
|
|
628 |
|
|
629 |
return verdict;
|
|
630 |
}
|
|
631 |
|
|
632 |
/**
|
|
633 |
*
|
|
634 |
* Test step Postamble.
|
|
635 |
*
|
|
636 |
* @xxxx
|
|
637 |
*
|
|
638 |
*/
|
|
639 |
enum TVerdict CTestStepRecCropDescriptor::DoTestStepPostambleL(void)
|
|
640 |
{
|
|
641 |
iRecorder->Close();
|
|
642 |
|
|
643 |
//delete the temp, cropped file
|
|
644 |
iFs.Connect();
|
|
645 |
iFileMan = CFileMan::NewL(iFs);
|
|
646 |
iFileMan->Delete(iFileNameTmp);
|
|
647 |
|
|
648 |
iFs.Close();
|
|
649 |
delete iFileMan;
|
|
650 |
iFileMan = NULL;
|
|
651 |
|
|
652 |
delete iRecorder;
|
|
653 |
iRecorder = NULL;
|
|
654 |
|
|
655 |
delete iDescHBuf;
|
|
656 |
delete iDes8;
|
|
657 |
|
|
658 |
//[ Destroy the scheduler ]
|
|
659 |
return CTestStepUnitMMFAudClient::DoTestStepPostambleL();
|
|
660 |
}
|
|
661 |
|
|
662 |
/**
|
|
663 |
*
|
|
664 |
* Callback Handle.
|
|
665 |
*
|
|
666 |
* @xxxx
|
|
667 |
*
|
|
668 |
*/
|
|
669 |
void CTestStepRecCropDescriptor::MoscoStateChangeEvent(CBase* /*aObject*/,
|
|
670 |
TInt /*aPreviousState*/,
|
|
671 |
TInt /*aCurrentState*/,
|
|
672 |
TInt aErrorcCode)
|
|
673 |
{
|
|
674 |
iError = aErrorcCode;
|
|
675 |
CActiveScheduler::Stop();
|
|
676 |
}
|
|
677 |
|
|
678 |
void CTestStepRecCropDescriptor::CropAndStartSchedulerL(const TTimeIntervalMicroSeconds& aBegin,
|
|
679 |
const TTimeIntervalMicroSeconds& aEnd)
|
|
680 |
{
|
|
681 |
iRecorder->CropL(aBegin, aEnd);
|
|
682 |
|
|
683 |
//Check if the cropped duration is within the deviation from the expected duration
|
|
684 |
TInt64 cropDur = iRecorder->Duration().Int64();
|
|
685 |
TInt64 difDur = aEnd.Int64() - aBegin.Int64();
|
|
686 |
TInt delta = I64INT(cropDur - difDur);
|
|
687 |
if(delta < 0)
|
|
688 |
delta *= (-1);
|
|
689 |
|
|
690 |
if ( delta <= KExpectedDeviation )
|
|
691 |
iHasCropped = ETrue;
|
|
692 |
|
|
693 |
}
|
|
694 |
|
|
695 |
void CTestStepRecCropDescriptor::CropAndStartSchedulerL(TBool aCropToEnd)
|
|
696 |
{
|
|
697 |
const TTimeIntervalMicroSeconds pos = iRecorder->Position();
|
|
698 |
|
|
699 |
iRecorder->CropL(aCropToEnd);
|
|
700 |
|
|
701 |
//Check if the cropped duration is within the deviation from the expected duration
|
|
702 |
TInt64 cropDur = iRecorder->Duration().Int64();
|
|
703 |
TInt64 difDur = 0;
|
|
704 |
if (aCropToEnd)
|
|
705 |
difDur = pos.Int64();
|
|
706 |
else
|
|
707 |
difDur = iOrigDuration - pos.Int64();
|
|
708 |
TInt delta = I64INT(cropDur - difDur);
|
|
709 |
if(delta < 0)
|
|
710 |
delta *= (-1);
|
|
711 |
|
|
712 |
if ( delta <= KExpectedDeviation )
|
|
713 |
iHasCropped = ETrue;
|
|
714 |
|
|
715 |
}
|
|
716 |
|
|
717 |
/**
|
|
718 |
*
|
|
719 |
* Do the test step.
|
|
720 |
* Each test step must supply an implementation for DoTestStepL.
|
|
721 |
*
|
|
722 |
* @return "TVerdict"
|
|
723 |
* The result of the test step
|
|
724 |
*
|
|
725 |
* @xxxx
|
|
726 |
*
|
|
727 |
*/
|
|
728 |
TVerdict CTestStepRecCropDescriptor::DoTestStepL()
|
|
729 |
{
|
|
730 |
iTestStepResult = EPass;
|
|
731 |
TInt err = KErrNone;
|
|
732 |
|
|
733 |
const TTimeIntervalMicroSeconds middle( iOrigDuration / 2 );
|
|
734 |
const TTimeIntervalMicroSeconds threeQuarters( iOrigDuration - (iOrigDuration/4) );
|
|
735 |
|
|
736 |
iRecorder->SetPosition(threeQuarters);
|
|
737 |
TRAP( err, CropAndStartSchedulerL(ETrue) );
|
|
738 |
|
|
739 |
if (err != KErrNone ||
|
|
740 |
!iHasCropped ||
|
|
741 |
iRecorder->State() != CMdaAudioRecorderUtility::EOpen )
|
|
742 |
return EFail;
|
|
743 |
|
|
744 |
iHasCropped = EFalse;
|
|
745 |
iOrigDuration = iRecorder->Duration().Int64();
|
|
746 |
iRecorder->SetPosition(middle);
|
|
747 |
|
|
748 |
CropAndStartSchedulerL(EFalse);
|
|
749 |
|
|
750 |
if (err != KErrNone ||
|
|
751 |
!iHasCropped ||
|
|
752 |
iRecorder->State() != CMdaAudioRecorderUtility::EOpen )
|
|
753 |
return EFail;
|
|
754 |
|
|
755 |
INFO_PRINTF1(_L("finished with this test step"));
|
|
756 |
|
|
757 |
return iTestStepResult;
|
|
758 |
}
|
|
759 |
|
|
760 |
/**
|
|
761 |
* This function reads from a source file into the member variable heap buffer, 'iDescHBuf'.
|
|
762 |
* @param aFilename - The file to read from.
|
|
763 |
*/
|
|
764 |
void CTestStepRecCropDescriptor::ReadFileToDescriptorL(const TDesC& aFilename )
|
|
765 |
{
|
|
766 |
RFs rfs;
|
|
767 |
rfs.Connect();
|
|
768 |
RFile file;
|
|
769 |
|
|
770 |
// Try to open the file.
|
|
771 |
User::LeaveIfError( file.Open(rfs,aFilename,EFileRead|EFileShareAny) );
|
|
772 |
|
|
773 |
// Create the databuffer in which to store the data.
|
|
774 |
TInt fileSize = 0;
|
|
775 |
file.Size(fileSize);
|
|
776 |
iDescHBuf = HBufC8::NewL(fileSize);
|
|
777 |
|
|
778 |
TPtr8 dataBuf = iDescHBuf->Des();
|
|
779 |
|
|
780 |
// Read the data from the file to the data buffer
|
|
781 |
User::LeaveIfError( file.Read(dataBuf) );
|
|
782 |
|
|
783 |
//[ set up the descriptor ]
|
|
784 |
iDes8 = new (ELeave) TPtr8( NULL, 0 );
|
|
785 |
iDes8->Set( iDescHBuf->Des());
|
|
786 |
|
|
787 |
file.Close();
|
|
788 |
rfs.Close();
|
|
789 |
}
|
|
790 |
|
|
791 |
|