mmfenh/advancedaudiocontroller/tsrc/advancedaudiocontrollertestmodule/AudioRecorderTestModule/src/ThreadPriority.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 "ThreadPriority.h"
       
    20 #include <mmfFormatImplementationUIDs.hrh>
       
    21 
       
    22 //////////////////////////////////////////////////////////////////////
       
    23 // Construction/Destruction
       
    24 //////////////////////////////////////////////////////////////////////
       
    25 
       
    26 
       
    27 CThreadPriority::CThreadPriority(CTestModuleIf *aConsole, CStifLogger *aLogger)
       
    28 {
       
    29 	console = aConsole;
       
    30 	logger = aLogger;
       
    31 
       
    32 }
       
    33 
       
    34 CThreadPriority::~CThreadPriority()
       
    35 {
       
    36 
       
    37 	if (recorder) delete recorder;
       
    38 	recorder = NULL;
       
    39 }
       
    40 
       
    41 
       
    42 void CThreadPriority::ConstructL(TFileName* fileName)
       
    43 {
       
    44 	logger->Log(_L("Creating file: %S"),fileName);
       
    45 	recorder = CMdaAudioRecorderUtility::NewL(*this);
       
    46 	if (recorder)
       
    47 	{
       
    48 		TRAPD(err,recorder->OpenFileL(*fileName));
       
    49 		if (err != KErrNone)
       
    50 		{
       
    51 			logger->Log(_L("Error %d opening file: %S"),err,fileName);
       
    52 			User::Leave(KErrRecOpenFile);
       
    53 		}
       
    54 	}
       
    55 }
       
    56 
       
    57 TInt CThreadPriority::RunTestL(CTestModuleIf *aConsole, CStifLogger *aLogger, CStifSectionParser *aParser, TInt* /*clipCounter*/)
       
    58 {
       
    59 	TInt error = KErrNone;
       
    60 	aLogger->Log(_L("Creating scheduler"));
       
    61 
       
    62 	CActiveScheduler*  scheduler = new (ELeave) CActiveScheduler;
       
    63 	CleanupStack::PushL(scheduler); // push to clean-up stack
       
    64 	CActiveScheduler::Install(scheduler); // install as active scheduler
       
    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 
       
    89 
       
    90 
       
    91 
       
    92 
       
    93 	if (error != KErrNone)
       
    94 	{
       
    95 		CleanupStack::PopAndDestroy();  //scheduler
       
    96 		return error;
       
    97 	}
       
    98 
       
    99 
       
   100 	// create CThreadPriority
       
   101 	aLogger->Log(_L("Creating CThreadPriority"));
       
   102 
       
   103 	CThreadPriority* selfObj = CThreadPriority::NewL(aConsole, aLogger, &fileName);
       
   104 
       
   105 
       
   106 	CleanupStack::PushL(selfObj);
       
   107 
       
   108 	CActiveScheduler::Start();
       
   109 
       
   110 
       
   111 	CleanupStack::PopAndDestroy(2); // schedule, selfObj
       
   112 
       
   113 	return error;
       
   114 }
       
   115 
       
   116 
       
   117 CThreadPriority* CThreadPriority::NewL(CTestModuleIf *aConsole, CStifLogger *aLogger, TFileName* fileName)
       
   118 {
       
   119 	CThreadPriority* self = new (ELeave) CThreadPriority(aConsole, aLogger);
       
   120     CleanupStack::PushL(self);
       
   121 
       
   122  //   self->ConstructL(fileName);
       
   123 	TRAPD(err, self->ConstructL(fileName));
       
   124 	if (err != KErrNone)
       
   125 	{
       
   126 		CleanupStack::PopAndDestroy();
       
   127 		return NULL;
       
   128 	}
       
   129 
       
   130 	CleanupStack::Pop(self);
       
   131     return self;
       
   132 }
       
   133 
       
   134 void CThreadPriority::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
       
   135 {
       
   136 #ifdef _DEBUG
       
   137     RDebug::Print (_L ("CThreadPriority::MoscoStateChangeEvent"));
       
   138 #endif
       
   139 	TInt err = KErrNone;
       
   140 
       
   141 	logger->Log(_L("MoscoStateChangeEvent called, error: %d	prev: %d curr : %d"),aErrorCode,aPreviousState,aCurrentState);
       
   142 logger->Log(_L("Before Checking Duaration."));
       
   143 		TTimeIntervalMicroSeconds aDuration, aRecordTime;
       
   144   	    TMMFDurationInfo clipDuration = recorder->Duration(aDuration);
       
   145 		logger->Log(_L("Duaration is %d"), aDuration.Int64());
       
   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         recorder->SetThreadPriorityPlayback(EPriorityNormal);
       
   161 		logger->Log(_L("ThreadPriorityPlayback set"));
       
   162 		recorder->SetThreadPriorityRecord(EPriorityNormal);
       
   163 		logger->Log(_L("ThreadPriorityPlayRecord set"));
       
   164 
       
   165         recorder->ClearPlayWindow();
       
   166 		logger->Log(_L("ClearPlayWindow set"));
       
   167 
       
   168 		recorder->PlayL();
       
   169 
       
   170 
       
   171 		return;
       
   172 
       
   173 
       
   174 	}
       
   175 
       
   176 	if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == CMdaAudioClipUtility::EPlaying)
       
   177 	{
       
   178 	    logger->Log(_L("Checking Duaration."));
       
   179 		TTimeIntervalMicroSeconds aDuration, aRecordTime;
       
   180   	    TMMFDurationInfo clipDuration = recorder->Duration(aDuration);
       
   181 		logger->Log(_L("Duaration is %d"), aDuration.Int64());
       
   182 
       
   183 		const CMMFControllerImplementationInformation& info = recorder->AudioPlayControllerImplementationInformationL();
       
   184 
       
   185 		const CMMFControllerImplementationInformation& info_1 = recorder->AudioRecorderControllerImplementationInformationL();
       
   186 
       
   187 
       
   188 
       
   189 		//aRecordTime= recorder->RecordTimeAvailable();
       
   190  	    //logger->Log(_L("RecordTimeAvailable %d"), aRecordTime);
       
   191 
       
   192 
       
   193 		CActiveScheduler::Stop();
       
   194 	}
       
   195 
       
   196 
       
   197 	return;
       
   198 
       
   199 }
       
   200 
       
   201 
       
   202 
       
   203 void CThreadPriority::GetFileName(TPtrC path, TFileName* fileName)
       
   204 {
       
   205 
       
   206 	TParse p;
       
   207 	p.Set(path,NULL,NULL);
       
   208 	fileName->Append(p.DriveAndPath());
       
   209 	fileName->Append(p.Name());
       
   210 
       
   211 	fileName->Append(p.Ext());
       
   212 }