mmfenh/advancedaudiocontroller/tsrc/advancedaudiocontrollertestmodule/AudioRecorderTestModule/src/CropFromBeginning.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 "CropFromBeginning.h"
       
    20 #include <mmfFormatImplementationUIDs.hrh>
       
    21 
       
    22 //////////////////////////////////////////////////////////////////////
       
    23 // Construction/Destruction
       
    24 //////////////////////////////////////////////////////////////////////
       
    25 
       
    26 
       
    27 CCropFromBeginning::CCropFromBeginning(CTestModuleIf *aConsole, CStifLogger *aLogger)
       
    28 {
       
    29 	console = aConsole;
       
    30 	logger = aLogger;
       
    31     callbackErr = KErrNone;
       
    32 }
       
    33 
       
    34 CCropFromBeginning::~CCropFromBeginning()
       
    35 {
       
    36 
       
    37 	if (recorder) delete recorder;
       
    38 	recorder = NULL;
       
    39 }
       
    40 
       
    41 
       
    42 void CCropFromBeginning::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 CCropFromBeginning::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 CCropFromBeginning
       
   101 	aLogger->Log(_L("Creating CCropFromBeginning"));
       
   102 
       
   103 	CCropFromBeginning* selfObj = CCropFromBeginning::NewL(aConsole, aLogger, &fileName);
       
   104 
       
   105 
       
   106 	CleanupStack::PushL(selfObj);
       
   107 
       
   108 	CActiveScheduler::Start();
       
   109 
       
   110 	if (error == KErrNone)
       
   111 	{
       
   112 		error = selfObj->callbackErr;
       
   113 	}
       
   114 
       
   115 	CleanupStack::PopAndDestroy(2); // schedule, selfObj
       
   116 
       
   117 	return error;
       
   118 }
       
   119 
       
   120 
       
   121 CCropFromBeginning* CCropFromBeginning::NewL(CTestModuleIf *aConsole, CStifLogger *aLogger, TFileName* fileName)
       
   122 {
       
   123 	CCropFromBeginning* self = new (ELeave) CCropFromBeginning(aConsole, aLogger);
       
   124     CleanupStack::PushL(self);
       
   125 
       
   126  //   self->ConstructL(fileName);
       
   127 	TRAPD(err, self->ConstructL(fileName));
       
   128 	if (err != KErrNone)
       
   129 	{
       
   130 		CleanupStack::PopAndDestroy();
       
   131 		return NULL;
       
   132 	}
       
   133 
       
   134 	CleanupStack::Pop(self);
       
   135     return self;
       
   136 }
       
   137 
       
   138 void CCropFromBeginning::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
       
   139 {
       
   140 #ifdef _DEBUG
       
   141     RDebug::Print (_L ("CCropFromBeginning::MoscoStateChangeEvent"));
       
   142 #endif
       
   143 	TInt err = KErrNone;
       
   144 //	callbackErr = KErrNone;
       
   145 
       
   146 	logger->Log(_L("MoscoStateChangeEvent called, error: %d	prev: %d curr : %d"),aErrorCode,aPreviousState,aCurrentState);
       
   147 
       
   148     TInt aState = recorder->State();
       
   149     logger->Log(_L("Current State %d"), aState);
       
   150 
       
   151 	if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == 0)
       
   152 	{
       
   153 	    // Initialize
       
   154 		recorder->SetAudioDeviceMode(CMdaAudioRecorderUtility::ELocal);
       
   155 		logger->Log(_L("Mode set"));
       
   156 		recorder->SetGain(recorder->MaxGain());
       
   157 		logger->Log(_L("Gain set"));
       
   158 		recorder->SetVolume(recorder->MaxVolume());
       
   159 		logger->Log(_L("Volume set"));
       
   160 		recorder->SetPosition(TTimeIntervalMicroSeconds(TInt64(0)));
       
   161 		logger->Log(_L("Position set"));
       
   162 
       
   163 
       
   164 
       
   165 		TRAPD(err, recorder->CropFromBeginningL());
       
   166 		if (err != KErrNone)
       
   167 			{
       
   168 				logger->Log(_L("Error %d for CropFromBeginningL."),err);
       
   169 				callbackErr = KErrCropFromBeginning;
       
   170 
       
   171 			}
       
   172 
       
   173 		logger->Log(_L("CropFromBeginningL set"));
       
   174 
       
   175 		recorder->PlayL();
       
   176 
       
   177 
       
   178 		return;
       
   179 
       
   180 
       
   181 	}
       
   182 
       
   183 	if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == CMdaAudioClipUtility::EPlaying)
       
   184 	{
       
   185 
       
   186 		CActiveScheduler::Stop();
       
   187 	}
       
   188 
       
   189 
       
   190 	return;
       
   191 
       
   192 }
       
   193 
       
   194 
       
   195 
       
   196 void CCropFromBeginning::GetFileName(TPtrC path, TFileName* fileName)
       
   197 {
       
   198 
       
   199 	TParse p;
       
   200 	p.Set(path,NULL,NULL);
       
   201 	fileName->Append(p.DriveAndPath());
       
   202 	fileName->Append(p.Name());
       
   203 
       
   204 	fileName->Append(p.Ext());
       
   205 }