mmfenh/advancedaudiocontroller/tsrc/advancedaudiocontrollertestmodule/AudioRecorderTestModule/src/AudioResourceNotification.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 "AudioResourceNotification.h"
       
    20 #include <mmfFormatImplementationUIDs.hrh>
       
    21 
       
    22 //////////////////////////////////////////////////////////////////////
       
    23 // Construction/Destruction
       
    24 //////////////////////////////////////////////////////////////////////
       
    25 
       
    26 
       
    27 CAudioResourceNotification::CAudioResourceNotification(CTestModuleIf *aConsole, CStifLogger *aLogger)
       
    28 {
       
    29 	console = aConsole;
       
    30 	logger = aLogger;
       
    31 
       
    32 }
       
    33 
       
    34 CAudioResourceNotification::~CAudioResourceNotification()
       
    35 {
       
    36 
       
    37 	if (recorder) delete recorder;
       
    38 	recorder = NULL;
       
    39 }
       
    40 
       
    41 
       
    42 void CAudioResourceNotification::ConstructL(TFileName* fileName)
       
    43 {
       
    44 	logger->Log(_L("Creating file: %S"),fileName);
       
    45 	recorder = CMdaAudioRecorderUtility::NewL(*this);
       
    46 
       
    47 	if (recorder)
       
    48 	{
       
    49 		TRAPD(err,recorder->OpenFileL(*fileName));
       
    50 		if (err != KErrNone)
       
    51 		{
       
    52 			logger->Log(_L("Error %d opening file: %S"),err,fileName);
       
    53 			User::Leave(KErrRecOpenFile);
       
    54 		}
       
    55 	}
       
    56 }
       
    57 
       
    58 TInt CAudioResourceNotification::RunTestL(CTestModuleIf *aConsole, CStifLogger *aLogger, CStifSectionParser *aParser, TInt* /*clipCounter*/)
       
    59 {
       
    60 	TInt error = KErrNone;
       
    61 	aLogger->Log(_L("Creating scheduler"));
       
    62 
       
    63 	CActiveScheduler*  scheduler = new (ELeave) CActiveScheduler;
       
    64 	CleanupStack::PushL(scheduler); // push to clean-up stack
       
    65 	CActiveScheduler::Install(scheduler); // install as active scheduler
       
    66 
       
    67 	TFileName fileName;
       
    68 
       
    69 	//Get file name
       
    70 	TPtrC name;
       
    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 
       
    91 
       
    92 
       
    93 
       
    94 	if (error != KErrNone)
       
    95 	{
       
    96 		CleanupStack::PopAndDestroy();  //scheduler
       
    97 		return error;
       
    98 	}
       
    99 
       
   100 
       
   101 	// create CThreadPriority
       
   102 	aLogger->Log(_L("Creating CAudioResourceNotification"));
       
   103 
       
   104 	CAudioResourceNotification* selfObj = CAudioResourceNotification::NewL(aConsole, aLogger, &fileName);
       
   105 
       
   106 
       
   107 	CleanupStack::PushL(selfObj);
       
   108 
       
   109 	CActiveScheduler::Start();
       
   110 
       
   111 
       
   112 	CleanupStack::PopAndDestroy(2); // schedule, selfObj
       
   113 
       
   114 	return error;
       
   115 }
       
   116 
       
   117 
       
   118 CAudioResourceNotification* CAudioResourceNotification::NewL(CTestModuleIf *aConsole, CStifLogger *aLogger, TFileName* fileName)
       
   119 {
       
   120 	CAudioResourceNotification* self = new (ELeave) CAudioResourceNotification(aConsole, aLogger);
       
   121     CleanupStack::PushL(self);
       
   122 
       
   123  //   self->ConstructL(fileName);
       
   124 	TRAPD(err, self->ConstructL(fileName));
       
   125 	if (err != KErrNone)
       
   126 	{
       
   127 		CleanupStack::PopAndDestroy();
       
   128 		return NULL;
       
   129 	}
       
   130 
       
   131 	CleanupStack::Pop(self);
       
   132     return self;
       
   133 }
       
   134 
       
   135 void CAudioResourceNotification::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
       
   136 {
       
   137 #ifdef _DEBUG
       
   138     RDebug::Print (_L ("CAudioResourceNotification::MoscoStateChangeEvent"));
       
   139 #endif
       
   140 	TInt err = KErrNone;
       
   141 
       
   142 	logger->Log(_L("MoscoStateChangeEvent called, error: %d	prev: %d curr : %d"),aErrorCode,aPreviousState,aCurrentState);
       
   143 
       
   144 
       
   145 
       
   146 	if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == 0)
       
   147 	{
       
   148 	    TBuf8<25> dataFrom;
       
   149 
       
   150  	   	TRequestStatus status;
       
   151 		TMMFMessageDestinationPckg dummyPckg;
       
   152 		TInt dummyFunc = 100;
       
   153 		TBuf8<8> dummyBuff;
       
   154 
       
   155 
       
   156 	    // Initialize
       
   157 		recorder->SetAudioDeviceMode(CMdaAudioRecorderUtility::ELocal);
       
   158 		logger->Log(_L("Mode set"));
       
   159 		recorder->SetGain(recorder->MaxGain());
       
   160 		logger->Log(_L("Gain set"));
       
   161 		recorder->SetVolume(recorder->MaxVolume());
       
   162 		logger->Log(_L("Volume set"));
       
   163 		recorder->SetPosition(TTimeIntervalMicroSeconds(TInt64(0)));
       
   164 		logger->Log(_L("Position set"));
       
   165 
       
   166 
       
   167     	recorder->RegisterForAudioLoadingNotification(*this);
       
   168 		logger->Log(_L("RegisterForAudioLoadingNotification set"));
       
   169 		recorder->RegisterAudioResourceNotification(*this,KUidInterfaceMMFController);
       
   170 		logger->Log(_L("RegisterAudioResourceNotification set"));
       
   171         recorder->CancelRegisterAudioResourceNotification(KUidInterfaceMMFController);
       
   172 		logger->Log(_L("CancelRegisterAudioResourceNotification set"));
       
   173 
       
   174 
       
   175 		TRAPD(err1, recorder->RecordControllerCustomCommandSync(dummyPckg, dummyFunc,
       
   176   								    	dummyBuff, dummyBuff, dataFrom));
       
   177 	    if (err1 != KErrNone)
       
   178         {
       
   179             logger->Log(_L("RecordControllerCustomCommandSync with dataFrom - err=%d"), err1);
       
   180 
       
   181         }
       
   182     	logger->Log(_L("RecordControllerCustomCommandSync with dataFrom successful"));
       
   183 
       
   184     	TRAP(err, recorder->RecordControllerCustomCommandSync(dummyPckg, dummyFunc,
       
   185         								dummyBuff, dummyBuff));
       
   186     	if (err != KErrNone)
       
   187         {
       
   188             logger->Log(_L("RecordControllerCustomCommandSync - err=%d"), err);
       
   189 
       
   190         }
       
   191     	logger->Log(_L("RecordControllerCustomCommandSync successful"));
       
   192 
       
   193     	logger->Log(_L("Using UseSharedHeap"));
       
   194     	recorder->UseSharedHeap();
       
   195 
       
   196 		recorder->PlayL();
       
   197 
       
   198 
       
   199 		return;
       
   200 
       
   201 	}
       
   202 
       
   203 	if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == CMdaAudioClipUtility::EPlaying)
       
   204 	{
       
   205 
       
   206 		recorder->WillResumePlay();
       
   207 		CActiveScheduler::Stop();
       
   208 	}
       
   209 
       
   210 	return;
       
   211 
       
   212 }
       
   213 
       
   214 void CAudioResourceNotification::MaloLoadingStarted()
       
   215 {
       
   216 		logger->Log(_L("MaloLoadingStarted "));
       
   217 }
       
   218 
       
   219 void CAudioResourceNotification::MaloLoadingComplete()
       
   220 {
       
   221 	  	logger->Log(_L("MaloLoadingComplete "));
       
   222 }
       
   223 
       
   224 
       
   225 void CAudioResourceNotification::MarncResourceAvailable(TUid aNotificationEventId, const TDesC8 &aNotificationData)
       
   226 {
       
   227 		logger->Log(_L("MarncResourceAvailable "));
       
   228 }
       
   229 
       
   230 void CAudioResourceNotification::GetFileName(TPtrC path, TFileName* fileName)
       
   231 {
       
   232 
       
   233 	TParse p;
       
   234 	p.Set(path,NULL,NULL);
       
   235 	fileName->Append(p.DriveAndPath());
       
   236 	fileName->Append(p.Name());
       
   237 
       
   238 	fileName->Append(p.Ext());
       
   239 }