os/mm/mmlibs/mmfw/tsrc/mmfintegrationtest/SDevSound/SDSCapTestServer/src/CapTestStep0008.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 //
    15 
    16 #include "CapTestStep0008.h"
    17 
    18 CSecDevSndTS0008* CSecDevSndTS0008::NewL()
    19 	{
    20 	CSecDevSndTS0008* self = new (ELeave) CSecDevSndTS0008;
    21 	CleanupStack::PushL(self);
    22 	self->ConstructL();
    23 	CleanupStack::Pop();
    24 	return self;
    25 	}
    26 	
    27 void CSecDevSndTS0008::ConstructL()
    28 	{
    29 	iIsFirst = ETrue;
    30 	}
    31 	
    32 
    33 void CSecDevSndTS0008::StartProcessing(TRequestStatus& aStatus)
    34 	{
    35 	iStatus = &aStatus;
    36 	if ( (iVerdict = DoTestStepPreambleL() ) == EPass)
    37 		{
    38 		// only do this when DoTestStepPreambleL() pass, if it fails, it means 
    39 		// devsound is not ready for play data yet.
    40 		iVerdict = DoPlayData();
    41 		}
    42 	}
    43 		
    44 CSecDevSndTS0008::~CSecDevSndTS0008()
    45 	{
    46 	}
    47 
    48 /******************************************************************************
    49  *
    50  * DevSound methods
    51  *
    52  *****************************************************************************/
    53  
    54 /**
    55  *
    56  * DoTestStepL
    57  * @result TVerdict
    58  *
    59  */
    60 
    61 TVerdict CSecDevSndTS0008::DoPlayData()
    62 	{
    63 	//Initialize
    64 	TVerdict initOK = TestInitialize(EMMFStatePlaying);
    65 	if (initOK != EPass)
    66 		{
    67 		return EInconclusive;
    68 		}
    69 
    70 	TestSetPriority(KDevSoundPriorityHigh);
    71 
    72 	initOK = TestPlayInit();
    73 	if (initOK != EPass)
    74 		{
    75 		return EInconclusive;
    76 		}
    77 
    78 	User::RequestComplete(iStatus, KErrNone);
    79 
    80 	TestSetVolume(iMMFDevSound->MaxVolume() / 2);
    81 
    82 	_LIT(KTestFileName, "C:\\sdevsoundinttestdata\\mainTst.wav");
    83 	TFileName aFilename(KTestFileName);
    84 
    85 	return PlayDataFile(aFilename);
    86 	}
    87 
    88 /**
    89  *
    90  * TestDigitalPlayback
    91  * @param aNumSamples
    92  * @param aFilename
    93  * @param aDataType
    94  * @result TVerdict
    95  *
    96  */
    97 TVerdict CSecDevSndTS0008::PlayDataFile(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 		return EInconclusive;
   109 		}
   110 
   111 	err = file.Open(fs, aFilename, EFileRead);
   112 	if (err != KErrNone)
   113 		{
   114 		fs.Close();
   115 		return EInconclusive;
   116 		}
   117 
   118 	TInt bufferCount = 0;
   119 	if (aNumSamples < 0)
   120 		{// Play to EOF
   121 		while (initOK == KErrNone && iCallbackError == KErrNone)
   122 			{
   123 			//read sizeof buffer from file
   124 			CMMFDataBuffer*  buffer = STATIC_CAST (CMMFDataBuffer*, iBuffer);
   125 			file.Read(buffer->Data());
   126 			if (buffer->Data().Length()!= buffer->RequestSize())
   127 				{
   128 				iBuffer->SetLastBuffer(ETrue);
   129 				}
   130 
   131 			//DevSound Play
   132 			initOK = TestPlayData();
   133 			bufferCount ++;
   134 			}
   135 		}
   136 	else
   137 		{
   138 		while (bufferCount < aNumSamples && initOK == KErrNone && iCallbackError == KErrNone)
   139 			{
   140 			//read sizeof buffer from file
   141 			CMMFDataBuffer* buffer = STATIC_CAST (CMMFDataBuffer*, iBuffer);
   142 			file.Read(buffer->Data());
   143 			if (buffer->Data().Length()!= buffer->RequestSize())
   144 				{
   145 				iBuffer->SetLastBuffer(ETrue);
   146 				}
   147 
   148 			//DevSound Play
   149 			initOK = TestPlayData();
   150 			bufferCount ++;
   151 			}
   152 		}
   153 
   154 	file.Close();
   155 	fs.Close();
   156 
   157 	if (initOK != KErrNone)
   158 		{
   159 		return EFail;
   160 		}
   161 
   162 	if (aNumSamples >= 0 && bufferCount != aNumSamples)
   163 		{
   164 		return EFail;
   165 		}
   166 
   167 	return EPass;
   168 	}
   169 
   170 /**
   171  *
   172  * TestInitialize
   173  * @param aDataType
   174  * @param aMode
   175  * @result TVerdict
   176  *
   177  */
   178 TVerdict CSecDevSndTS0008::TestInitialize(TMMFState aMode)
   179 	{
   180 	TFourCC pcm16(KMMFFourCCCodePCM16); //default to pcm16 data type
   181 
   182 	iCallbackError = KErrNone;
   183 	iExpectedValue = KErrNone;
   184 
   185 	// Initialize
   186 	TRAPD(err, iMMFDevSound->InitializeL(*this, pcm16, aMode));
   187 	if (err)
   188 		{
   189 		return EInconclusive;
   190 		}
   191 	else
   192 		{
   193 		CActiveScheduler::Start();
   194 
   195 		if (iCallbackError != iExpectedValue)
   196 			{
   197 			return EFail;
   198 			}
   199 		if (iCallbackArray[EInitComplete] != 1)
   200 			{
   201 			return EFail;
   202 			}
   203 		}
   204 	return EPass;
   205 	}
   206 
   207 /**
   208  *
   209  * TestPlayInit
   210  * @result TVerdict
   211  *
   212  */
   213 TVerdict CSecDevSndTS0008::TestPlayInit()
   214 	{
   215 	ResetCallbacks();
   216 
   217 	//get buffer from devsound
   218 	TRAPD(err, iMMFDevSound->PlayInitL());
   219 	// Start the active scheduler and catch the callback
   220  	CActiveScheduler::Start();
   221 	if (err)
   222 		{
   223 		return EFail;
   224 		}
   225 	else
   226 		{
   227 		if (iCallbackArray[EBuffToFill] != 1)
   228 			{
   229 			return EFail;
   230 			}
   231 		TInt tot = GetCallbackTotal();
   232 		if (tot > 1)
   233 			{
   234 			return EFail;
   235 			}
   236 		}
   237 	return EPass;
   238 	}
   239 
   240 /**
   241  *
   242  * TestPlayData
   243  * @result TVerdict
   244  *
   245  */
   246 TVerdict CSecDevSndTS0008::TestPlayData()
   247 	{
   248 	ResetCallbacks();
   249 
   250 	iMMFDevSound->PlayData();
   251 	// Start the active scheduler and catch the callback
   252  	CActiveScheduler::Start();
   253 
   254 	if (iCallbackArray[EBuffToFill] != 1)
   255 		{
   256 		if (iCallbackArray[EBuffToFill] == 0 && iCallbackArray[EPlayError] == 1)
   257 			{
   258 			// DevSound PlayError was called 1 time. Must be EOF.
   259 			}
   260 		else
   261 			{
   262 			return EFail;
   263 			}
   264 		}
   265 
   266 	TInt tot = GetCallbackTotal();
   267 	if (tot > 2)
   268 		{
   269 		return EFail;
   270 		}
   271 	return EPass;
   272 	}
   273 
   274 /******************************************************************************
   275  *
   276  * DevSound mixin methods
   277  *
   278  *****************************************************************************/
   279  
   280 /**
   281  *
   282  * BufferToBeFilled
   283  * @param aBuffer
   284  *
   285  */
   286 void CSecDevSndTS0008::BufferToBeFilled (CMMFBuffer* aBuffer)
   287 	{
   288 	iBuffer = aBuffer;
   289 	if (aBuffer != NULL) 
   290 		{
   291 		if( iIsFirst )
   292 			{
   293 			iIsFirst = EFalse;
   294 			}
   295 		iCallbackError = KErrNone;
   296 		}
   297 	else 
   298 		{
   299 		iCallbackError = KErrNotFound;
   300 		}
   301 	iCallbackArray[EBuffToFill] ++;
   302 	CActiveScheduler::Stop();
   303 	}
   304 
   305 /**
   306  *
   307  * PlayError
   308  * @param aError
   309  *
   310  */
   311 void CSecDevSndTS0008::PlayError (TInt aError)
   312 	{
   313 	if( aError != KErrInUse )
   314 		{
   315 		// should get interrupted by client
   316 		iVerdict = EFail;
   317 		}
   318 
   319 	iCallbackError = aError;
   320 	iCallbackArray[EPlayError] ++;
   321 	CActiveScheduler::Stop();
   322 	}