os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/SDevSound/SDSCapTestServer/src/CapTestStep0010.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // CapTestStep0010.h
    15 // 
    16 //
    17 
    18 #include "CapTestStep0010.h"
    19 
    20 CSecDevSndTS0010* CSecDevSndTS0010::NewL()
    21 	{
    22 	CSecDevSndTS0010* self = new (ELeave) CSecDevSndTS0010;
    23 	CleanupStack::PushL(self);
    24 	self->ConstructL();
    25 	CleanupStack::Pop();
    26 	return self;
    27 	}
    28 	
    29 void CSecDevSndTS0010::ConstructL()
    30 	{
    31 	}
    32 	
    33 
    34 void CSecDevSndTS0010::StartProcessing(TRequestStatus& aStatus)
    35 	{
    36 	iStatus = &aStatus;
    37 	if ( (iVerdict = DoTestStepPreambleL() ) == EPass)
    38 		{
    39 		// only do this when DoTestStepPreambleL() pass, if it fails, it means 
    40 		// devsound is not ready for play data yet.
    41 		iVerdict = DoRecordData();
    42 		}
    43 	}
    44 		
    45 CSecDevSndTS0010::~CSecDevSndTS0010()
    46 	{
    47 	}
    48 
    49 /******************************************************************************
    50  *
    51  * DevSound methods
    52  *
    53  *****************************************************************************/
    54  
    55 /**
    56  *
    57  * DoTestStepL
    58  * @result TVerdict
    59  *
    60  */
    61 
    62 TVerdict CSecDevSndTS0010::DoRecordData()
    63 	{
    64 	//Initialize
    65 	TVerdict initOK = TestInitialize(EMMFStateRecording);
    66 	if (initOK != EPass)
    67 		{
    68 		return EInconclusive;
    69 		}
    70 
    71 	TestSetPriority(KDevSoundPriorityHigh);
    72 
    73 	initOK = TestRecordInit();
    74 	if (initOK != EPass)
    75 		{
    76 		return EInconclusive;
    77 		}
    78 
    79 	User::RequestComplete(iStatus, KErrNone);
    80 
    81 	TestSetVolume(iMMFDevSound->MaxVolume() / 2);
    82 
    83 	TFileName	aFilename = _L("C:\\rectest1.wav");
    84 
    85 	return RecordDataFile(aFilename);
    86 	}
    87 
    88 /**
    89  *
    90  * TestDigitalPlayback
    91  * @param aNumSamples
    92  * @param aFilename
    93  * @param aDataType
    94  * @result TVerdict
    95  *
    96  */
    97 TVerdict CSecDevSndTS0010::RecordDataFile(TDesC& aFilename)
    98 	{
    99 	TInt		initOK = KErrNone;
   100 	TInt		aNumSamples = 1;
   101 
   102 	//open file
   103 	RFs fs;
   104 	RFile file;
   105 	TInt err = fs.Connect();
   106 	if (err != KErrNone)
   107 		{
   108 		// Could not connect to Filesystem.
   109 		return EInconclusive;
   110 		}
   111 
   112 	//Create output directory if it doesn't already exist
   113 //	fs.MkDir(_L("C:\\TSU_MMF_DEVSOUND_SUITE\\Output\\"));
   114 
   115 	err = file.Replace(fs, aFilename, EFileWrite);
   116 	if (err != KErrNone)
   117 		{
   118 		file.Close();
   119 		fs.Close();
   120 		return EInconclusive;
   121 		}
   122 
   123 	//SetGain
   124 	TInt vol = iMMFDevSound->MaxVolume();	// Hacked... Fix this...
   125 	TestSetGain(vol);
   126 
   127 	TInt bufferCount = 0;
   128 	while (bufferCount < aNumSamples && initOK == KErrNone && iCallbackError == KErrNone)
   129 		{
   130 		//DevSound Record
   131 		initOK = TestRecordData();
   132 
   133 		//Write buffer to file
   134 		CMMFDataBuffer* buffer = STATIC_CAST (CMMFDataBuffer*, iBuffer);
   135 		file.Write(buffer->Data());
   136 
   137 		bufferCount ++;
   138 		}
   139 
   140 	file.Close();
   141 	fs.Close();
   142 
   143 	if (initOK != KErrNone)
   144 		{
   145 		return EFail;
   146 		}
   147 
   148 	if (aNumSamples >= 0 && bufferCount != aNumSamples)
   149 		{
   150 		return EFail;
   151 		}
   152 
   153 	return EPass;
   154 	}
   155 
   156 /**
   157  *
   158  * TestInitialize
   159  * @param aDataType
   160  * @param aMode
   161  * @result TVerdict
   162  *
   163  */
   164 TVerdict CSecDevSndTS0010::TestInitialize(TMMFState aMode)
   165 	{
   166 	TFourCC pcm16(KMMFFourCCCodePCM16); //default to pcm16 data type
   167 
   168 	iCallbackError = KErrNone;
   169 	iExpectedValue = KErrNone;
   170 
   171 	// Initialize
   172 	TRAPD(err, iMMFDevSound->InitializeL(*this, pcm16, aMode));
   173 	if (err)
   174 		{
   175 		return EInconclusive;
   176 		}
   177 	else
   178 		{
   179 		CActiveScheduler::Start();
   180 		
   181 		if (iCallbackError != iExpectedValue)
   182 			{
   183 			return EFail;
   184 			}
   185 		if (iCallbackArray[EInitComplete] != 1)
   186 			{
   187 			return EFail;
   188 			}
   189 		}
   190 	return EPass;
   191 	}
   192 
   193 /**
   194  *
   195  * TestRecordInit
   196  * @result TVerdict
   197  *
   198  */
   199 TVerdict CSecDevSndTS0010::TestRecordInit()
   200 	{
   201 	ResetCallbacks();
   202 
   203 	//get buffer from devsound
   204 	TRAPD(err, iMMFDevSound->RecordInitL());
   205 	// Start the active scheduler and catch the callback
   206  	CActiveScheduler::Start();
   207 	if (err)
   208 		{
   209 		return EFail;
   210 		}
   211 	else
   212 		{
   213 		if (iCallbackArray[EBuffToEmpty] != 1)
   214 			{
   215 			return EFail;
   216 			}
   217 		TInt tot = GetCallbackTotal();
   218 		if (tot > 1)
   219 			{
   220 			return EFail;
   221 			}
   222 		}
   223 	return EPass;
   224 	}
   225 
   226 /**
   227  *
   228  * TestRecordData
   229  * @result TVerdict
   230  *
   231  */
   232 TVerdict CSecDevSndTS0010::TestRecordData()
   233 	{
   234 	ResetCallbacks();
   235 
   236 	iMMFDevSound->RecordData();
   237 	// Start the active scheduler and catch the callback
   238  	CActiveScheduler::Start();
   239 
   240 	if (iCallbackArray[EBuffToEmpty] != 1)
   241 		{
   242 		if (iCallbackArray[EBuffToEmpty] == 0 && iCallbackArray[ERecError] == 1)
   243 			{
   244 			// DevSound RecordError was called 1 time.
   245 			}
   246 		else
   247 			{
   248 			return EFail;
   249 			}
   250 		}
   251 
   252 	TInt tot = GetCallbackTotal();
   253 	if (tot > 1)
   254 		{
   255 		return EFail;
   256 		}
   257 	return EPass;
   258 	}
   259 
   260 /******************************************************************************
   261  *
   262  * DevSound mixin methods
   263  *
   264  *****************************************************************************/
   265  
   266 /**
   267  * 
   268  * BufferToBeEmptied
   269  * @param aBuffer
   270  *
   271  */
   272 void CSecDevSndTS0010::BufferToBeEmptied (CMMFBuffer* aBuffer)
   273 	{
   274 	iBuffer = aBuffer;
   275 	if (aBuffer != NULL)
   276 		{
   277 		iCallbackError = KErrNone;
   278 		}
   279 	else
   280 		{
   281 		iCallbackError = KErrNotFound;
   282 		}
   283 	iCallbackArray[EBuffToEmpty] ++;
   284 	CActiveScheduler::Stop();
   285 	}
   286 
   287 /**
   288  *
   289  * RecordError
   290  * @param aError
   291  *
   292  */
   293 void CSecDevSndTS0010::RecordError (TInt aError)
   294 	{
   295 	if( aError != KErrInUse )
   296 		{
   297 		// should get interrupted by client
   298 		iVerdict = EFail;
   299 		}
   300 	iCallbackError = aError;
   301 	iCallbackArray[ERecError] ++;
   302 	CActiveScheduler::Stop();
   303 	}