mmfenh/advancedaudiocontroller/tsrc/advancedaudiocontrollertestmodule/AudioRecorderTestModule/src/RecordDataFormat.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 "RecordDataFormat.h"
       
    20 #include <mmfFormatImplementationUIDs.hrh>
       
    21 
       
    22 //////////////////////////////////////////////////////////////////////
       
    23 // Construction/Destruction
       
    24 //////////////////////////////////////////////////////////////////////
       
    25 
       
    26 
       
    27 CRecordDataFormat::CRecordDataFormat(CTestModuleIf *aConsole, CStifLogger *aLogger)
       
    28 {
       
    29 	console = aConsole;
       
    30 	logger = aLogger;
       
    31 	callbackErr = KErrNone;
       
    32 }
       
    33 
       
    34 CRecordDataFormat::~CRecordDataFormat()
       
    35 {
       
    36 
       
    37 	if (recorder) delete recorder;
       
    38 	recorder = NULL;
       
    39 }
       
    40 
       
    41 
       
    42 void CRecordDataFormat::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 CRecordDataFormat::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 	aLogger->Log(_L("Creating CRecordDataFormat"));
       
    67 
       
    68 	TFileName fileName;
       
    69 
       
    70 	//Get file name
       
    71 	TPtrC name;
       
    72 	CStifItemParser* item;
       
    73 	item = aParser->GetItemLineL(KFileName, ENoTag);
       
    74 	if (!item)
       
    75 	{
       
    76 		CleanupStack::PopAndDestroy();
       
    77 		return KErrSyntax;
       
    78 	}
       
    79 
       
    80 	CleanupStack::PushL(item);
       
    81 	if (item->GetString(KEmptyString,name) != KErrNone)
       
    82 	{
       
    83 		aLogger->Log(_L("Invalid file name"));
       
    84 		CleanupStack::PopAndDestroy(2);
       
    85 		return KErrSyntax;
       
    86 	}
       
    87 	CleanupStack::PopAndDestroy(); //item
       
    88 
       
    89 	GetFileName(name,&fileName);
       
    90 
       
    91 
       
    92 	TPtrC dataFormat;
       
    93 
       
    94 	item = aParser->GetNextItemLineL(KDataFormat);
       
    95 	if (item)
       
    96 	{
       
    97 		CleanupStack::PushL(item);
       
    98 		error = item->GetString(KDataFormat,dataFormat);
       
    99 		if (error != KErrNone)
       
   100 		{
       
   101 			aLogger->Log(_L("The format syntax in the config file is not right") );
       
   102 			CleanupStack::PopAndDestroy(4);
       
   103 			return KErrSyntax;
       
   104 		}
       
   105 
       
   106 		CleanupStack::PopAndDestroy();   //item
       
   107 	}
       
   108 	else
       
   109 	{
       
   110 		aLogger->Log(_L("Format parameter is missing in the config file"));
       
   111 		error = KErrSyntax;
       
   112 	}
       
   113 
       
   114 
       
   115 	// create CRecordDataFormat
       
   116 
       
   117 	CRecordDataFormat* selfObj = CRecordDataFormat::NewL(aConsole, aLogger, &fileName);
       
   118 
       
   119 	(selfObj->dataFormat).Set(dataFormat);
       
   120 
       
   121 	CleanupStack::PushL(selfObj);
       
   122 
       
   123 	CActiveScheduler::Start();
       
   124 
       
   125 	if (error == KErrNone)
       
   126 	{
       
   127 		error = selfObj->callbackErr;
       
   128 	}
       
   129 
       
   130 	CleanupStack::PopAndDestroy(2); // schedule, selfObj
       
   131 
       
   132 	return error;
       
   133 }
       
   134 
       
   135 
       
   136 CRecordDataFormat* CRecordDataFormat::NewL(CTestModuleIf *aConsole, CStifLogger *aLogger, TFileName* fileName)
       
   137 {
       
   138 	CRecordDataFormat* self = new (ELeave) CRecordDataFormat(aConsole, aLogger);
       
   139     CleanupStack::PushL(self);
       
   140 
       
   141  //   self->ConstructL(fileName);
       
   142 	TRAPD(err, self->ConstructL(fileName));
       
   143 	if (err != KErrNone)
       
   144 	{
       
   145 		CleanupStack::PopAndDestroy();
       
   146 		return NULL;
       
   147 	}
       
   148 
       
   149 	CleanupStack::Pop(self);
       
   150     return self;
       
   151 }
       
   152 
       
   153 void CRecordDataFormat::MoscoStateChangeEvent(CBase* /*aObject*/, TInt aPreviousState, TInt aCurrentState, TInt aErrorCode)
       
   154 {
       
   155 #ifdef _DEBUG
       
   156     RDebug::Print (_L ("CRecordDataFormat::MoscoStateChangeEvent"));
       
   157 #endif
       
   158 	TInt err = KErrNone;
       
   159 	logger->Log(_L("MoscoStateChangeEvent called, error: %d	prev: %d curr : %d"),aErrorCode,aPreviousState,aCurrentState);
       
   160 
       
   161 	if (recorder && aErrorCode == KErrNone && aCurrentState == CMdaAudioClipUtility::EOpen && aPreviousState == 0)
       
   162 	{
       
   163 
       
   164 		if (dataFormat == KFormatWav)
       
   165 		{
       
   166 			logger->Log(_L("SetDestinationFormatL(KMmfUidFormatWAVWrite)"));
       
   167 			TUid id;
       
   168 			id.iUid = KMmfUidFormatWAVWrite;
       
   169 			TRAP(err,recorder->SetDestinationFormatL(id));
       
   170 			if (err != KErrNone)
       
   171 			{
       
   172 				logger->Log(_L("SetDestinationFormatL(%d) failed with error %d"),KMmfUidFormatWAVWrite, err);
       
   173 				callbackErr = err;
       
   174 				CActiveScheduler::Stop();
       
   175 				return;
       
   176 			}
       
   177 
       
   178 			if (recorder->DestinationFormatL() != id)
       
   179 			{
       
   180 				logger->Log(_L("Retrieved format is not same as set format") );
       
   181 				callbackErr = KErrOutOfRange;
       
   182 			}
       
   183 
       
   184 		}
       
   185 		else
       
   186 		{
       
   187 			// Only WAV use format object
       
   188 			logger->Log(_L("Invalid input dataFormat - %S"), &dataFormat);
       
   189 			callbackErr = KErrInvalidId;
       
   190 /*			if (dataFormat == KFormatAmr)
       
   191 			{
       
   192 				logger->Log(_L("SetDestinationFormatL(AMR)"));
       
   193 				TUid id;
       
   194 				id.iUid = KAdvancedUidFormatAMRWrite;
       
   195 				TRAP(err,recorder->SetDestinationFormatL(id));
       
   196 				if (err != KErrNone)
       
   197 				{
       
   198 					logger->Log(_L("SetDestinationFormatL(AMR) failed with error %d"), err);
       
   199 					callbackErr =  err;
       
   200 					CActiveScheduler::Stop();
       
   201 					return;
       
   202 				}
       
   203 
       
   204 				if (recorder->DestinationFormatL() != id)
       
   205 				{
       
   206 					logger->Log(_L("Retrieved format is not same as set format") );
       
   207 					callbackErr = KErrOutOfRange;
       
   208 				}
       
   209 			}*/
       
   210 		}
       
   211 	}
       
   212 
       
   213 	CActiveScheduler::Stop();
       
   214 	return;
       
   215 
       
   216 }
       
   217 
       
   218 
       
   219 
       
   220 void CRecordDataFormat::GetFileName(TPtrC path, TFileName* fileName)
       
   221 {
       
   222 
       
   223 	TParse p;
       
   224 	p.Set(path,NULL,NULL);
       
   225 	fileName->Append(p.DriveAndPath());
       
   226 	fileName->Append(p.Name());
       
   227 
       
   228 	fileName->Append(p.Ext());
       
   229 }
       
   230 
       
   231