mmfenh/advancedaudiocontroller/tsrc/advancedaudiocontrollertestmodule/AudioRecorderTestModule/src/PlayWindow.cpp
changeset 0 71ca22bcf22a
child 43 9894ed580e4a
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     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 "PlayWindow.h"
       
    20 
       
    21 //////////////////////////////////////////////////////////////////////
       
    22 // Construction/Destruction
       
    23 //////////////////////////////////////////////////////////////////////
       
    24 
       
    25 
       
    26 CPlayWindow::CPlayWindow(CTestModuleIf *aConsole, CStifLogger *aLogger)
       
    27 {
       
    28 	console = aConsole;
       
    29 	logger = aLogger;
       
    30 }
       
    31 
       
    32 CPlayWindow::~CPlayWindow()
       
    33 {
       
    34 
       
    35 	if (recorder) delete recorder;
       
    36 	recorder = NULL;
       
    37 }
       
    38 
       
    39 
       
    40 void CPlayWindow::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 CPlayWindow::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 CPlayWindow"));
       
    65 
       
    66 	TFileName fileName;
       
    67 
       
    68 	//Get file name
       
    69 	TPtrC name;
       
    70 //	TInt volume;
       
    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 	//Get window start position
       
    91 	TTimeIntervalMicroSeconds startPos = TInt64(0);
       
    92 	item = aParser->GetItemLineL(KStartPos, ENoTag);
       
    93 	if (item)
       
    94 	{
       
    95 		CleanupStack::PushL(item);
       
    96 		startPos = ParseTime(item);
       
    97 		CleanupStack::PopAndDestroy();
       
    98 	}
       
    99 	LogTime(_L("Window start:"),startPos.Int64(),aLogger);
       
   100 
       
   101 
       
   102 
       
   103 	//Get window end position
       
   104 	TTimeIntervalMicroSeconds endPos = TInt64(0);
       
   105 	item = aParser->GetItemLineL(KEndPos, ENoTag);
       
   106 	if (item)
       
   107 	{
       
   108 		CleanupStack::PushL(item);
       
   109 		endPos = ParseTime(item);
       
   110 		CleanupStack::PopAndDestroy();
       
   111 	}
       
   112 	LogTime(_L("Window end:"),endPos.Int64(),aLogger);
       
   113 
       
   114 	//Get error range
       
   115 	TTimeIntervalMicroSeconds errorRange = TInt64(KDefaultErrorRange);
       
   116 	item = aParser->GetItemLineL(KErrorRange, ENoTag);
       
   117 	if (item)
       
   118 	{
       
   119 		CleanupStack::PushL(item);
       
   120 		errorRange = ParseTime(item);
       
   121 		CleanupStack::PopAndDestroy();
       
   122 	}
       
   123 	LogTime(_L("Error range:"),errorRange.Int64(),aLogger);
       
   124 
       
   125 
       
   126 //	if (error != KErrNone)
       
   127 //	{
       
   128 //		CleanupStack::PopAndDestroy();
       
   129 //		return error;
       
   130 //	}
       
   131 
       
   132 
       
   133 	// create CPlayWindow
       
   134 	aLogger->Log(_L("Creating CPlayWindow"));
       
   135 
       
   136 	CPlayWindow* selfObj = CPlayWindow::NewL(aConsole, aLogger, &fileName);
       
   137 
       
   138 	selfObj->windowStart = startPos;
       
   139 	selfObj->windowEnd = endPos;
       
   140 
       
   141 	CleanupStack::PushL(selfObj);
       
   142 
       
   143 	CActiveScheduler::Start();
       
   144 
       
   145 	if (selfObj->windowStart != startPos)
       
   146 	{
       
   147 		aLogger->Log(_L("The window start position is not right after SetWindow: %d"),selfObj->windowStart);
       
   148 		error = KErrDiffVolume;
       
   149 	}
       
   150 
       
   151 
       
   152     TTimeIntervalMicroSeconds expectedPlayTime(Abs(endPos.Int64() - startPos.Int64()));
       
   153 
       
   154 	LogTime(_L("expectedPlayTime:"),expectedPlayTime,aLogger);
       
   155 	if (Abs(Abs(selfObj->endTime.Int64() - selfObj->startTime.Int64()) - expectedPlayTime.Int64()) > errorRange.Int64())
       
   156 	{
       
   157 		aLogger->Log(_L("Actual play time differs from expected play time"));
       
   158 		error = KErrPlayWindow;
       
   159 	}
       
   160 
       
   161 	CleanupStack::PopAndDestroy(2); // schedule, selfObj
       
   162 
       
   163 	return error;
       
   164 }
       
   165 
       
   166 
       
   167 CPlayWindow* CPlayWindow::NewL(CTestModuleIf *aConsole, CStifLogger *aLogger, TFileName* fileName)
       
   168 {
       
   169 	CPlayWindow* self = new (ELeave) CPlayWindow(aConsole, aLogger);
       
   170     CleanupStack::PushL(self);
       
   171 
       
   172  //   self->ConstructL(fileName);
       
   173 	TRAPD(err, self->ConstructL(fileName));
       
   174 	if (err != KErrNone)
       
   175 	{
       
   176 		CleanupStack::PopAndDestroy();
       
   177 		return NULL;
       
   178 	}
       
   179 
       
   180 	CleanupStack::Pop(self);
       
   181     return self;
       
   182 }
       
   183 
       
   184 void CPlayWindow::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
       
   185 {
       
   186 #ifdef _DEBUG
       
   187     RDebug::Print (_L ("CPlayWindow::MoscoStateChangeEvent"));
       
   188 #endif
       
   189 
       
   190 	logger->Log(_L("MoscoStateChangeEvent called, error: %d	prev: %d curr : %d"),aErrorCode,aPreviousState,aCurrentState);
       
   191 
       
   192 	if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == 0)
       
   193 	{
       
   194 		// Initialize
       
   195 		recorder->SetAudioDeviceMode(CMdaAudioRecorderUtility::ELocal);
       
   196 		logger->Log(_L("Mode set"));
       
   197 		recorder->SetGain(recorder->MaxGain());
       
   198 		logger->Log(_L("Gain set"));
       
   199 		recorder->SetVolume(recorder->MaxVolume());
       
   200 		logger->Log(_L("Volume set"));
       
   201 		recorder->SetPosition(TTimeIntervalMicroSeconds(TInt64(0)));
       
   202 		logger->Log(_L("Position set"));
       
   203 
       
   204 		//	TInt expectedPlayTime;
       
   205 //		TTimeIntervalMicroSeconds expectedPlayTime = Abs(windowEnd.Int64() - windowStart.Int64());
       
   206 		LogTime(_L("Recorded clip duration:"),recorder->Duration());
       
   207 
       
   208 		recorder->SetPlayWindow(windowStart,windowEnd);
       
   209 
       
   210 
       
   211 		TTime time;
       
   212 		time.UniversalTime();
       
   213 		startTime = time.Int64();
       
   214 
       
   215 		recorder->PlayL();
       
   216 		return;
       
   217 	}
       
   218 
       
   219 	if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == CMdaAudioClipUtility::EPlaying)
       
   220 	{
       
   221 		//get position after play window, which should be start position
       
   222 		windowStart = recorder->Position();
       
   223 
       
   224 		TTime time;
       
   225 		time.UniversalTime();
       
   226 		endTime = time.Int64();
       
   227 
       
   228 		CActiveScheduler::Stop();
       
   229 	}
       
   230 	return;
       
   231 
       
   232 }
       
   233 
       
   234 
       
   235 
       
   236 void CPlayWindow::GetFileName(TPtrC path, TFileName* fileName)
       
   237 {
       
   238 
       
   239 	TParse p;
       
   240 	p.Set(path,NULL,NULL);
       
   241 	fileName->Append(p.DriveAndPath());
       
   242 	fileName->Append(p.Name());
       
   243 
       
   244 	fileName->Append(p.Ext());
       
   245 }