mmfenh/advancedaudiocontroller/tsrc/advancedaudiocontrollertestmodule/AudioRecorderTestModule/src/AudioLoadingProgress.cpp
changeset 0 71ca22bcf22a
child 7 709f89d8c047
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 "AudioLoadingProgress.h"
       
    20 #include <mmfFormatImplementationUIDs.hrh>
       
    21 
       
    22 //////////////////////////////////////////////////////////////////////
       
    23 // Construction/Destruction
       
    24 //////////////////////////////////////////////////////////////////////
       
    25 
       
    26 
       
    27 CAudioLoadingProgress::CAudioLoadingProgress(CTestModuleIf *aConsole, CStifLogger *aLogger)
       
    28 {
       
    29 	console = aConsole;
       
    30 	logger = aLogger;
       
    31     callbackErr = KErrNone;
       
    32 }
       
    33 
       
    34 CAudioLoadingProgress::~CAudioLoadingProgress()
       
    35 {
       
    36 
       
    37 	if (recorder) delete recorder;
       
    38 	recorder = NULL;
       
    39 }
       
    40 
       
    41 
       
    42 void CAudioLoadingProgress::ConstructL(TFileName* fileName)
       
    43 {
       
    44 	logger->Log(_L("Creating file: %S"),fileName);
       
    45 	CMdaServer* aServer = NULL;
       
    46 	recorder = CMdaAudioRecorderUtility::NewL(*this, aServer, EMdaPriorityNormal,
       
    47 	    EMdaPriorityPreferenceTimeAndQuality );
       
    48 	if (recorder)
       
    49 	{
       
    50 		TRAPD(err,recorder->OpenFileL(*fileName));
       
    51 		if (err != KErrNone)
       
    52 		{
       
    53 			logger->Log(_L("Error %d opening file: %S"),err,fileName);
       
    54 			User::Leave(KErrRecOpenFile);
       
    55 		}
       
    56 	}
       
    57 }
       
    58 
       
    59 TInt CAudioLoadingProgress::RunTestL(CTestModuleIf *aConsole, CStifLogger *aLogger, CStifSectionParser *aParser, TInt* /*clipCounter*/)
       
    60 {
       
    61 	TInt error = KErrNone;
       
    62 	aLogger->Log(_L("Creating scheduler"));
       
    63 
       
    64 	CActiveScheduler*  scheduler = new (ELeave) CActiveScheduler;
       
    65 	CleanupStack::PushL(scheduler); // push to clean-up stack
       
    66 	CActiveScheduler::Install(scheduler); // install as active scheduler
       
    67 
       
    68 	TFileName fileName;
       
    69 
       
    70 	//Get file name
       
    71 	TPtrC name;
       
    72 	CStifItemParser* item = aParser->GetItemLineL(KFileName, ENoTag);
       
    73 	if (!item)
       
    74 	{
       
    75 		CleanupStack::PopAndDestroy();
       
    76 		return KErrSyntax;
       
    77 	}
       
    78 
       
    79 	CleanupStack::PushL(item);
       
    80 	if (item->GetString(KEmptyString,name) != KErrNone)
       
    81 	{
       
    82 		aLogger->Log(_L("Invalid file name"));
       
    83 		CleanupStack::PopAndDestroy(2);
       
    84 		return KErrSyntax;
       
    85 	}
       
    86 	CleanupStack::PopAndDestroy();
       
    87 
       
    88 	GetFileName(name,&fileName);
       
    89 
       
    90 
       
    91 
       
    92 
       
    93 
       
    94 
       
    95 	if (error != KErrNone)
       
    96 	{
       
    97 		CleanupStack::PopAndDestroy();  //scheduler
       
    98 		return error;
       
    99 	}
       
   100 
       
   101 
       
   102 	// create CAudioLoadingProgress
       
   103 	aLogger->Log(_L("Creating CAudioLoadingProgress"));
       
   104 
       
   105 	CAudioLoadingProgress* selfObj = CAudioLoadingProgress::NewL(aConsole, aLogger, &fileName);
       
   106 
       
   107 
       
   108 	CleanupStack::PushL(selfObj);
       
   109 
       
   110 	CActiveScheduler::Start();
       
   111 
       
   112 	if (error == KErrNone)
       
   113 	{
       
   114 		error = selfObj->callbackErr;
       
   115 	}
       
   116 
       
   117 	CleanupStack::PopAndDestroy(2); // schedule, selfObj
       
   118 
       
   119 	return error;
       
   120 }
       
   121 
       
   122 
       
   123 CAudioLoadingProgress* CAudioLoadingProgress::NewL(CTestModuleIf *aConsole, CStifLogger *aLogger, TFileName* fileName)
       
   124 {
       
   125 	CAudioLoadingProgress* self = new (ELeave) CAudioLoadingProgress(aConsole, aLogger);
       
   126     CleanupStack::PushL(self);
       
   127 
       
   128  //   self->ConstructL(fileName);
       
   129 	TRAPD(err, self->ConstructL(fileName));
       
   130 	if (err != KErrNone)
       
   131 	{
       
   132 		CleanupStack::PopAndDestroy();
       
   133 		return NULL;
       
   134 	}
       
   135 
       
   136 	CleanupStack::Pop(self);
       
   137     return self;
       
   138 }
       
   139 
       
   140 void CAudioLoadingProgress::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
       
   141 {
       
   142 #ifdef _DEBUG
       
   143     RDebug::Print (_L ("CAudioLoadingProgress::MoscoStateChangeEvent"));
       
   144 #endif
       
   145 	TInt err = KErrNone;
       
   146 	callbackErr = KErrNone;
       
   147 
       
   148 	logger->Log(_L("MoscoStateChangeEvent called, error: %d	prev: %d curr : %d"),aErrorCode,aPreviousState,aCurrentState);
       
   149 
       
   150     TInt aState = recorder->State();
       
   151     logger->Log(_L("Current State %d"), aState);
       
   152 
       
   153 	if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == 0)
       
   154 	{
       
   155 	    // Initialize
       
   156 		recorder->SetAudioDeviceMode(CMdaAudioRecorderUtility::ELocal);
       
   157 		logger->Log(_L("Mode set"));
       
   158 		recorder->SetGain(recorder->MaxGain());
       
   159 		logger->Log(_L("Gain set"));
       
   160 		recorder->SetVolume(recorder->MaxVolume());
       
   161 		logger->Log(_L("Volume set"));
       
   162 		recorder->SetPosition(TTimeIntervalMicroSeconds(TInt64(0)));
       
   163 		logger->Log(_L("Position set"));
       
   164 
       
   165 
       
   166 		recorder->PlayL();
       
   167 
       
   168 
       
   169 		return;
       
   170 
       
   171 
       
   172 	}
       
   173 
       
   174 	if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == CMdaAudioClipUtility::EPlaying)
       
   175 	{
       
   176 
       
   177 		TInt percentage;
       
   178 		TRAPD(err, recorder->GetAudioLoadingProgressL(percentage));
       
   179 		if (err != KErrNone)
       
   180 			{
       
   181 				logger->Log(_L("Error %d for GetAudioLoadingProgressL %d "),KErrProgressPect, percentage  );
       
   182 				callbackErr = KErrProgressPect;
       
   183 
       
   184 			}
       
   185 		logger->Log(_L("GetAudioLoadingProgressL finish %d"),percentage );
       
   186 
       
   187 
       
   188 		CActiveScheduler::Stop();
       
   189 	}
       
   190 
       
   191 
       
   192 	return;
       
   193 
       
   194 }
       
   195 
       
   196 
       
   197 
       
   198 void CAudioLoadingProgress::GetFileName(TPtrC path, TFileName* fileName)
       
   199 {
       
   200 
       
   201 	TParse p;
       
   202 	p.Set(path,NULL,NULL);
       
   203 	fileName->Append(p.DriveAndPath());
       
   204 	fileName->Append(p.Name());
       
   205 
       
   206 	fileName->Append(p.Ext());
       
   207 }