os/mm/mmplugins/lib3gpunittest/src/parserapi.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2008-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 <mmf/common/mmferrors.h>
    17 #include <caf/caf.h>
    18 #include "tsu3gplibraryapi.h"
    19 
    20 using namespace ContentAccess;
    21 
    22 // --------------------------
    23 // C3GPLibParser_base 
    24 // --------------------------
    25 //
    26 TVerdict C3GPLibParser_base::doTestStepPreambleL()
    27 	{
    28 	SetTestStepResult(EPass);
    29 	SetTestStepError(KErrNone);
    30 	
    31 	TPtrC testSection = ConfigSection();
    32 	
    33 	TInt err = iTestSection.Create(testSection.Length());
    34 	if( err != KErrNone )
    35 		{
    36 		ERR_PRINTF2(_L("Cannot create buffer for inputFilename. err = %d"), err);
    37 		SetTestStepResult(EInconclusive);
    38 		return TestStepResult();
    39 		}
    40 	iTestSection += testSection;
    41 	
    42 	TBuf<20> testFolderName;
    43 	testFolderName.Zero();
    44 	if (ConfigSection().Compare(_L("3GP-H264-MP4-LARGE")) == 0)
    45 		{
    46  		#ifdef __WINSCW__
    47  		testFolderName.Append(_L("inputFileEmu"));
    48  		#else
    49  		testFolderName.Append(_L("inputFileHw"));
    50  		#endif		
    51 		}
    52 	else	
    53 		{
    54  		testFolderName.Append(_L("inputFile"));
    55 		}
    56 	
    57 	TPtrC inputFile;
    58 	if(!GetStringFromConfig(ConfigSection(), testFolderName, inputFile))
    59 		{
    60 		ERR_PRINTF1(_L("Cannot read inputFile from ini file."));
    61 		SetTestStepResult(ETestSuiteError);
    62 		return TestStepResult();
    63 		}
    64 	err = iInputFile.Create(inputFile.Length() + 1);
    65 	if( err != KErrNone )
    66 		{
    67 		ERR_PRINTF2(_L("Cannot create buffer for inputFilename. err = %d"), err);
    68 		SetTestStepResult(EInconclusive);
    69 		return TestStepResult();
    70 		}
    71 	iInputFile += inputFile;
    72 	iInputFile.ZeroTerminate();
    73 	
    74 	return TestStepResult();
    75 	}
    76 
    77 TVerdict C3GPLibParser_base::doTestStepPostambleL()
    78 	{
    79 	iInputFile.Close();
    80 	iTestSection.Close();
    81 	
    82 	// Close file
    83 	iSourceFile.Close();
    84 	iSourceFile64.Close();
    85 
    86     //Close the file server session
    87     iFsSession.Close();
    88     
    89 	return TestStepResult();
    90 	}
    91 
    92 TInt C3GPLibParser_base::CheckError(TInt aError, TInt aExpectError, const TDesC& aFunction)
    93 	{
    94 	if (aError != aExpectError)
    95 		{
    96 		ERR_PRINTF4(_L("%S expected %d, but returns %d; "), &aFunction, aExpectError, aError);
    97 		if (aError != KErrNone)
    98 			{
    99 			return aError;
   100 			}
   101 		// expected an error, but return KErrNone
   102 		return KErrGeneral;
   103 		}
   104 	return KErrNone;
   105 	}
   106 
   107 void C3GPLibParser_base::ParserOpenL(C3GPParse* aParser, TInt aExpectedError)
   108 	{
   109 	ASSERT(aParser);
   110 	
   111 	TInt err = aParser->Open();
   112 	if (aExpectedError == KErrInUse && err == KErrNone)
   113 		{
   114 		err = aParser->Open();
   115 		}
   116 
   117 	if (ShouldRunOOMTest() && err != KErrNone && err != aExpectedError)
   118 		{
   119 		INFO_PRINTF2(_L("Parser open using buffer mode (OOM), returns %d"), err);
   120 		User::Leave(err);
   121 		}
   122 
   123 	if (!ShouldRunOOMTest())
   124 		{
   125 		INFO_PRINTF2(_L("Parser open using buffer mode, returns %d"), err);
   126 		}
   127 
   128 	User::LeaveIfError(CheckError(err, aExpectedError, _L("aParser->Open() buffer mode")));
   129 	}
   130 
   131 void C3GPLibParser_base::ParserOpenFileL(C3GPParse* aParser, TInt aExpectedError)
   132 	{
   133 	ASSERT(aParser);
   134 	
   135 	TInt err = aParser->Open(iInputFile);
   136 	if (aExpectedError == KErrInUse && err == KErrNone)
   137 		{
   138 		err = aParser->Open(iInputFile);
   139 		}
   140 
   141 	if (ShouldRunOOMTest() && err != KErrNone && err != aExpectedError)
   142 		{
   143 		INFO_PRINTF2(_L("Parser open using file path (OOM), returns %d"), err);
   144 		User::Leave(err);
   145 		}
   146 
   147 	if (!ShouldRunOOMTest())
   148 		{
   149 		INFO_PRINTF2(_L("Parser open using file path, returns %d"), err);
   150 		}
   151 	
   152 	User::LeaveIfError(CheckError(err, aExpectedError, _L("aParser->Open() file path")));
   153 	}
   154 
   155 void C3GPLibParser_base::ParserCompleteL(C3GPParse* aParser)
   156 	{
   157 	ASSERT(aParser);
   158 	
   159 	TInt err = aParser->Complete();
   160 	User::LeaveIfError(CheckError(err, KErrNone, _L("aParser->Complete()")));
   161 	}
   162 	
   163 void C3GPLibParser_base::FileOpenL(TUint aFileMode)	
   164 	{
   165 	iSourceFile.Close();
   166 	//Create a connection to the file server    
   167     User::LeaveIfError(iFsSession.Connect());
   168     
   169     //Open the source file passing in the file server session handle, source 
   170     //file path and file access mode 
   171     User::LeaveIfError(iSourceFile.Open(iFsSession, iInputFile, aFileMode ));
   172 	}
   173 
   174 void C3GPLibParser_base::FileClose()	
   175 	{
   176 	// Close file
   177 	iSourceFile.Close();
   178 
   179     //Close the file server session
   180     iFsSession.Close();
   181 	}
   182 
   183 void C3GPLibParser_base::FileOpen64L(TUint aFileMode)	
   184 	{
   185 	iSourceFile64.Close();
   186 	//Create a connection to the file server    
   187     User::LeaveIfError(iFsSession.Connect());
   188     
   189     //Open the source file passing in the file server session handle, source 
   190     //file path and file access mode 
   191     User::LeaveIfError(iSourceFile64.Open(iFsSession, iInputFile, aFileMode ));
   192 	}
   193 
   194 void C3GPLibParser_base::FileClose64()	
   195 	{
   196 	// Close file
   197 	iSourceFile64.Close();
   198 
   199     //Close the file server session
   200     iFsSession.Close();
   201 	}
   202 
   203 void C3GPLibParser_base::ParserOpenFileHandleL(C3GPParse* aParser, TUint aFileMode, TInt aExpectedError)
   204 	{
   205 	ASSERT(aParser);
   206    
   207 	FileOpenL(aFileMode);
   208     TInt err = aParser->Open(iSourceFile);	
   209     if (aExpectedError == KErrInUse && err == KErrNone)
   210 		{
   211 		err = aParser->Open(iSourceFile);
   212 		}
   213 
   214 	if (err != KErrNone && err != aExpectedError)
   215 		{
   216 		FileClose();
   217 
   218 		if (ShouldRunOOMTest())
   219 			{
   220 			INFO_PRINTF2(_L("Parser open using file handle (OOM), returns %d"), err);
   221 			User::Leave(err);
   222 			}
   223 		}
   224 
   225 	if (!ShouldRunOOMTest())
   226 		{
   227 		INFO_PRINTF2(_L("Parser open using file handle, returns %d"), err);		
   228 		}
   229 
   230 	if (err == aExpectedError ) 
   231 		{
   232 		err = KErrNone;
   233 		}
   234 	User::LeaveIfError(err);
   235 	}
   236 
   237 void C3GPLibParser_base::ParserCompleteHandleL(C3GPParse* aParser)
   238 	{
   239 	ASSERT(aParser);
   240 	
   241 	TInt err = aParser->Complete();
   242 	if (err != KErrNone)
   243 		{
   244 		ERR_PRINTF2(_L("aParser->Complete() file handle failed with %d"), err);
   245 		}
   246 	
   247 	FileClose();
   248     User::LeaveIfError(err);
   249 	}
   250 
   251 void C3GPLibParser_base::ParserOpenFileHandle64L(C3GPParse* aParser, TUint aFileMode, TInt aExpectedError)
   252 	{
   253 	ASSERT(aParser);
   254    
   255 	FileOpen64L(aFileMode);
   256     TInt err = aParser->Open(iSourceFile64);	
   257     if (aExpectedError == KErrInUse && err == KErrNone)
   258 		{
   259 		err = aParser->Open(iSourceFile64);
   260 		}
   261 
   262 	if (err != KErrNone && err != aExpectedError)
   263 		{
   264 		FileClose();
   265 
   266 		if (ShouldRunOOMTest())
   267 			{
   268 			INFO_PRINTF2(_L("Parser open using 64bit file handle (OOM), returns %d"), err);
   269 			User::Leave(err);
   270 			}
   271 		}
   272 
   273 	if (!ShouldRunOOMTest())
   274 		{
   275 		INFO_PRINTF2(_L("Parser open using 64bit file handle, returns %d"), err);		
   276 		}
   277 
   278 	if (err == aExpectedError ) 
   279 		{
   280 		err = KErrNone;
   281 		}
   282 	User::LeaveIfError(err);
   283 	}
   284 
   285 void C3GPLibParser_base::ParserCompleteHandle64L(C3GPParse* aParser)
   286 	{
   287 	ASSERT(aParser);
   288 	
   289 	TInt err = aParser->Complete();
   290 	if (err != KErrNone)
   291 		{
   292 		ERR_PRINTF2(_L("aParser->Complete() 64bit file handle failed with %d"), err);
   293 		}
   294 	
   295 	FileClose64();
   296     User::LeaveIfError(err);
   297 	}
   298 
   299 void C3GPLibParser_base::ParserOpenCafLC(C3GPParse* aParser, TInt aExpectedError)
   300 	{
   301 	ASSERT(aParser);
   302 	CContent* content = CContent::NewLC(iInputFile, EContentShareReadWrite);	
   303 	CData* data = content->OpenContentL(EPeek);	
   304 	
   305 	CleanupStack::PushL(data);
   306 
   307 	TInt err = aParser->Open(*data);
   308 	if (aExpectedError == KErrInUse && err == KErrNone)
   309 		{
   310 		err = aParser->Open(*data);
   311 		}
   312 
   313 	if (ShouldRunOOMTest() && err != KErrNone && err != aExpectedError)
   314 		{
   315 		INFO_PRINTF2(_L("Parser open using CAF (OOM), returns %d"), err);
   316 		User::Leave(err);	
   317 		}
   318 
   319 	if (!ShouldRunOOMTest())
   320 		{
   321 		INFO_PRINTF2(_L("Parser open using CAF, returns %d"), err);
   322 		}
   323 
   324 	if (err == aExpectedError)
   325 		{
   326 		err = KErrNone;
   327 		}
   328 	User::LeaveIfError(err);
   329 	}
   330 
   331 void C3GPLibParser_base::ParserCompleteCafL(C3GPParse* aParser)
   332 	{
   333 	ASSERT(aParser);
   334 	TInt err = aParser->Complete();
   335 	if ( err != KErrNone )
   336 		{
   337 		ERR_PRINTF2(_L("parse->Complete() CAF failed with %d."), err);
   338 		}
   339 
   340 	CleanupStack::PopAndDestroy(2); // content, data
   341 	User::LeaveIfError(err);
   342 	}
   343 
   344 // Retrieve both video & audio stream properties
   345 TInt C3GPLibParser_base::GetClipProperties(C3GPParse* aParse, TInt& aVideoError, TUint& aVideoLength, TUint& aAudioLength)
   346 	{
   347 	TInt err = KErrCorrupt;
   348 	T3GPVideoType videoType;
   349 	TReal frameRate;
   350 	TUint avgBitRate;
   351 	TSize videoSize;
   352 	TUint timeScale;
   353 	
   354 	aVideoError = aParse->GetVideoProperties(videoType, aVideoLength, frameRate, avgBitRate, videoSize, timeScale);
   355 	
   356 	if (aVideoError == KErrNone || aVideoError == KErrNotSupported || aVideoError == KErr3gpLibMoreDataRequired)
   357 		{
   358 		T3GPAudioType audioType;
   359 		TInt framesPerSample;
   360 		err = aParse->GetAudioProperties(audioType, aAudioLength, framesPerSample, avgBitRate, timeScale);
   361 		}	
   362 	return err;
   363 	}
   364 
   365 // Get both audio and video decorder information
   366 TInt C3GPLibParser_base::ParserGetDecoderInfo(C3GPParse* aParser)
   367 	{
   368 	TInt dsiSize;
   369 	RBuf8 dsiBuffer;
   370 	
   371 	TInt err = aParser->GetAudioDecoderSpecificInfoSize(dsiSize);
   372 	if ( err == KErrNone )
   373 		{		
   374 		err = dsiBuffer.Create(dsiSize);
   375 		if ( err != KErrNone )
   376 			{
   377 			ERR_PRINTF2(_L("dsiBuffer.Create failed with %d"), err);
   378 			dsiBuffer.Close();
   379 			return err;
   380 			}
   381 		
   382 		err = aParser->GetAudioDecoderSpecificInfo(dsiBuffer);
   383 		}
   384 	if ( err != KErrNone )
   385 		{
   386 		if (!ShouldRunOOMTest())
   387 			{
   388 			ERR_PRINTF3(_L("GetAudioDecoderSpecificInfo/Size() failed with %d, size %d"), err, dsiSize);
   389 			}
   390 		dsiBuffer.Close();
   391 		return err;
   392 		}
   393 	
   394 	err = aParser->GetVideoDecoderSpecificInfoSize(dsiSize);
   395 	if ( err != KErrNone && err != KErrNotSupported)
   396 		{
   397 		dsiBuffer.Close();
   398 		ERR_PRINTF2(_L("parse->GetVideoDecoderSpecificInfoSize() failed with %d"), err);
   399 		return err;
   400 		}
   401 	if (err != KErrNotSupported)
   402 		{
   403 		dsiBuffer.Close();
   404 		err = dsiBuffer.Create(dsiSize);	
   405 		if ( err != KErrNone )
   406 			{
   407 			ERR_PRINTF2(_L("dsiBuffer.Create failed with %d"), err);
   408 			dsiBuffer.Close();
   409 			return err;
   410 			}
   411 		
   412 		err = aParser->GetVideoDecoderSpecificInfo(dsiBuffer);
   413 		if ( err != KErrNone )
   414 			{
   415 			ERR_PRINTF2(_L("VideoDecoderSpecificInfo() failed with %d"), err);
   416 			}
   417 		}
   418 	dsiBuffer.Close();
   419 	return err;
   420 	}
   421 
   422 // Read data from file and insert it to the buffer
   423 void C3GPLibParser_base::InsertDataL(C3GPParse* aParse, RFile aFile, TInt aBufferSize, TInt aPos)
   424 	{
   425 	TInt err = KErrNone;
   426 	RBuf8 buffer;
   427 	CleanupClosePushL(buffer);
   428 	buffer.CreateL(aBufferSize);
   429 	err = aFile.Read(aPos, buffer); 
   430 	if (err == KErrNone)
   431 		{
   432 		err = aParse->InsertData(buffer);
   433 		if ( err != KErrNone )
   434 			{
   435 			ERR_PRINTF2(_L("parse->InsertData() failed with %d"), err);
   436 			}
   437 		}
   438 	else
   439 		{
   440 		ERR_PRINTF2(_L("aFile.Read(aPos, buffer) failed with %d"), err);
   441 		}
   442 	buffer.Close();
   443 	CleanupStack::PopAndDestroy(&buffer);
   444 	User::LeaveIfError(err);
   445 	}
   446 
   447 // Read audio or video frame(s) depending on the input parameter synchronously
   448 TInt C3GPLibParser_base::ReadAudioVideoFrame(C3GPParse* aParse, TBool aRepeat, TBool aReadAudio)
   449 	{
   450 	TInt err = KErrNone;
   451 	// If repeat, read all frames; otherwise, read only one frame
   452 	while (err == KErrNone)
   453 		{
   454 		TUint size;		
   455 		if (aReadAudio)
   456 			{
   457 			err = aParse->GetAudioFramesSize(size);
   458 			}
   459 		else
   460 			{
   461 			err = aParse->GetVideoFrameSize(size);
   462 			}
   463 		
   464 		if (err == KErrNone)
   465 			{
   466 			TUint timeStampInMs;
   467 			TUint timeStampInTimescale;
   468 			RBuf8 buffer;
   469 			err = buffer.Create(size);				
   470 			if (err != KErrNone)
   471 				{
   472 				ERR_PRINTF2(_L("buffer.Create(size) failed with %d"), err);
   473 				buffer.Close();
   474 				return err;
   475 				}
   476 			
   477 			if (aReadAudio)
   478 				{				
   479 				TInt returnedFrames;
   480 				err = aParse->ReadAudioFrames(buffer, returnedFrames, timeStampInMs, timeStampInTimescale);
   481 				}
   482 			else
   483 				{
   484 				TBool keyframe;
   485 				err = aParse->ReadVideoFrame(buffer, keyframe, timeStampInMs, timeStampInTimescale);
   486 				}
   487 			
   488 			if (err != KErrNone && err != KErrNotFound && err != KErr3gpLibMoreDataRequired)
   489 				{
   490 				if (aReadAudio)
   491 					{
   492 					ERR_PRINTF3(_L("parse->GetAudioFrames() failed with %d; frame size: %d"), err, size);
   493 					}
   494 				else
   495 					{
   496 					ERR_PRINTF3(_L("parse->GetVideoFrame() failed with %d; frame size: %d"), err, size);
   497 					}
   498 				buffer.Close();
   499 				return err;
   500 				}
   501 			buffer.Close();
   502 			}
   503 		
   504 		if (!aRepeat)
   505 			{
   506 			break;
   507 			}
   508 		}
   509 	return err;
   510 	}
   511 
   512 // Retrieve user data atom.
   513 TInt C3GPLibParser_base::CallUDTApi(C3GPParse* aParse, TUint32 aUdtType, TUint& aIndex, T3GPUdtaLocation aLocation)
   514 	{
   515 	TInt err = KErrNone;
   516 	TInt udtSize;
   517 	
   518 	// use a copy of the target index requested by the user, so it does not get overwritten
   519 	// when calling the APIs GetUserDataAtomSize & GetUserDataAtom
   520 	TUint tempIndex1 = aIndex;	
   521 	TUint tempIndex2 = aIndex;	
   522 
   523 	err = aParse->GetUserDataAtomSize(aUdtType, aLocation, tempIndex1, udtSize);
   524 	if (err == KErrNone)
   525 		{
   526 		RBuf8 buffer;	
   527 		
   528 		err = buffer.Create(udtSize); // Use size retrieved from GetUserDataAtomSize
   529 		if (err == KErrNone)
   530 			{
   531 			err = aParse->GetUserDataAtom(aUdtType, aLocation, buffer, tempIndex2);
   532 			if (err == KErrNone && tempIndex1 != tempIndex2)
   533 				{
   534 				ERR_PRINTF1(_L("C3GPLibParser_base::CallUDTApi - Highest Index returned is different when calling GetUserDataAtomSize vs GetUserDataAtom"));	
   535 				err = KErrGeneral;
   536 				}
   537 			}
   538 		else
   539 			{
   540 			ERR_PRINTF2(_L("buffer.Create(size) failed with %d"), err);
   541 			}
   542 		buffer.Close();		
   543 		}
   544 	
   545 	if (err == KErrNone)
   546 		{
   547 		// return the highest index found
   548 		aIndex = tempIndex1;
   549 		}
   550 	
   551 	return err;
   552 	}
   553 
   554 void C3GPLibParser_base::DoGetVideoAudioAttributesL(C3GPParse* aParser)
   555 	{
   556 	// Retrieve video & audio stream attributes
   557 	T3GPVideoType videoType;
   558 	TUint length; 
   559 	TReal frameRate;
   560 	TUint avgBitRate;
   561 	TSize videoSize;
   562 	TUint timeScale;
   563 	
   564 	TInt err = aParser->GetVideoProperties(videoType, length, frameRate, avgBitRate, videoSize, timeScale);
   565 	User::LeaveIfError(CheckError(err, KErrNone, _L("aParser->GetVideoProperties()")));
   566 	
   567 	T3GPAudioType audioType;
   568 	TInt framesPerSample;
   569 	err = aParser->GetAudioProperties(audioType, length, framesPerSample, avgBitRate, timeScale);
   570 	User::LeaveIfError(CheckError(err, KErrNone, _L("aParser->GetAudioProperties()")));
   571 	
   572 	err = ParserGetDecoderInfo(aParser);
   573 	User::LeaveIfError(CheckError(err, KErrNone, _L("ParserGetDecoderInfo(aParser)")));
   574 	
   575 	TUint numVideoFrames;
   576 	err = aParser->GetNumberOfVideoFrames(numVideoFrames);
   577 	User::LeaveIfError(CheckError(err, KErrNone, _L("parse->GetNumberOfVideoFrames")));
   578 	
   579 	TUint startIndex = 0;
   580 	RArray<T3GPFrameInfoParameters> array;
   581 	err = aParser->GetVideoFrameProperties(startIndex, numVideoFrames, array);	
   582 	array.Close();
   583 	User::LeaveIfError(CheckError(err, KErrNone, _L("parse->GetVideoFrameProperties")));
   584 	}
   585 
   586 TInt C3GPLibParser_base::DoReadFrame(C3GPParse* aParse)
   587 	{
   588 	TInt numBufferedBytes;
   589 	TInt err = aParse->GetNumBufferedBytes(numBufferedBytes);
   590 	if (err != KErrNone && numBufferedBytes != 0)
   591 		{
   592 		// when GetNumBufferedBytes returns error, numBufferedBytes is set to zero.
   593 		return err;		
   594 		}
   595 	err = CheckError(err, KErrNotSupported, _L("parse->GetNumBufferedBytes()"));	
   596 	if (err == KErrNone)
   597 		{
   598 		// read audio frame
   599 		err = ReadAudioVideoFrame(aParse, ETrue, ETrue);
   600 		// When finishing reading all frames, it returns KErrNotFound
   601 		err = CheckError(err, KErrNotFound, _L("ReadAudioVideoFrame(aParse, ETrue)"));
   602 		
   603 		if (err == KErrNone)
   604 			{
   605 			// read video frame
   606 			err = ReadAudioVideoFrame(aParse, ETrue, EFalse);
   607 			// When finishing reading all frames, it returns KErrNotFound
   608 			err = CheckError(err, KErrNotFound, _L("ReadAudioVideoFrame(aParse, EFalse)"));			
   609 			}
   610 		
   611 		// After finishing reading all frame, the next video time stamp should return with KErrEof
   612 		TUint timeStampInMs;
   613 		TUint timeStampInTimescale;
   614 		err = aParse->GetVideoTimestamp(timeStampInMs, timeStampInTimescale);
   615 		err = CheckError(err, KErrEof, _L("GetVideoTimestamp()"));			
   616 		}
   617 		
   618 	return err;
   619 	}
   620 
   621 void C3GPLibParser_base::DoSeekTestL(C3GPParse* aParser)
   622 	{
   623 	// testclip_h263_qcif_15fps_armnb_8khz_onlyvideo.3GP with some key frame
   624 	TUint num; 
   625 	TUint audioPos;
   626 	TUint videoPos;
   627 	TUint timeStampInMs = 0; // for key frame
   628 	TUint timeStampInTimescale = 0;  // for key frame
   629 	TUint timeStampInMs1 = 0;  // for non key frame immediately after key frame
   630 	TUint timeStampInTimescale1 = 0;  // for non-key frame immediately after key frame
   631 	TUint keyFrameIndex = 0;
   632 	TBool keyFrame;
   633 	TInt err = aParser->GetNumberOfVideoFrames(num);
   634 	if (err == KErrNone)
   635 		{
   636 		for (TInt i = 0; i < num; i++)
   637 			{			
   638 			err = aParser->GetVideoFrameKeyType(i, keyFrame);
   639 			if (err == KErrNone && keyFrame)
   640 				{
   641 				keyFrameIndex = i;
   642 				err = aParser->GetVideoFrameStartTime(keyFrameIndex, timeStampInMs, timeStampInTimescale);
   643 				}
   644 			if (err == KErrNone && !keyFrame && keyFrameIndex > 0)
   645 				{
   646 				keyFrameIndex = i;
   647 				err = aParser->GetVideoFrameStartTime(keyFrameIndex, timeStampInMs1, timeStampInTimescale1);
   648 				break;
   649 				}
   650 			if (err != KErrNone)
   651 				{
   652 				ERR_PRINTF3(_L("aParser->GetVideoFrameKeyType() failed with %d at i %d"), err, i);
   653 				User::Leave(err);
   654 				}
   655 			}
   656 		}
   657 	else
   658 		{
   659 		ERR_PRINTF2(_L("aParser->GetNumberOfVideoFrames() failed with %d"), err);
   660 		User::Leave(err);
   661 		}
   662 	err = aParser->Seek(timeStampInMs, ETrue, audioPos, videoPos);
   663 	if (err != KErrNone || timeStampInMs != videoPos)
   664 		{
   665 		ERR_PRINTF4(_L("aParser->Seek() return %d, timeStampInMs %d, videoPos %d"), err, timeStampInMs, videoPos);
   666 		}
   667 	if (err == KErrNone && timeStampInMs != videoPos)
   668 		{
   669 		User::LeaveIfError(KErrGeneral);
   670 		}
   671 	User::LeaveIfError(err);
   672 	
   673 	err = aParser->Seek(timeStampInMs1, EFalse, audioPos, videoPos);
   674 	if (err != KErrNone || timeStampInMs1 != videoPos)
   675 		{
   676 		ERR_PRINTF4(_L("aParser->Seek() return %d, timeStampInMs1 %d, videoPos %d"), err, timeStampInMs1, videoPos);
   677 		}
   678 	if (err == KErrNone && timeStampInMs1 != videoPos)
   679 		{
   680 		User::LeaveIfError(KErrGeneral);
   681 		}
   682 	User::LeaveIfError(err);
   683 	}
   684 
   685 void C3GPLibParser_base::ReadFrameBufferModeL(C3GPParse* aParser)
   686 	{
   687 	ParserOpenL(aParser);
   688 
   689 	TInt errReadAudio = KErrNone;
   690 	TInt errReadVideo = KErrNone;
   691 	// Insert 1K data into the library
   692 	TInt pos = 0;
   693 	TInt bufferSize = 1000;
   694 	
   695 	InsertDataL(aParser, iSourceFile, bufferSize, pos);
   696 	errReadAudio = ReadAudioVideoFrame(aParser, ETrue, ETrue);
   697 	errReadVideo = ReadAudioVideoFrame(aParser, ETrue, EFalse);
   698 
   699 	while (errReadAudio == KErr3gpLibMoreDataRequired || errReadVideo == KErr3gpLibMoreDataRequired)
   700 		{
   701 		pos = pos + bufferSize;
   702 		InsertDataL(aParser, iSourceFile, bufferSize, pos);
   703 		if (errReadAudio == KErr3gpLibMoreDataRequired)
   704 			{
   705 			errReadAudio = ReadAudioVideoFrame(aParser, ETrue, ETrue);
   706 			}
   707 
   708 		if (errReadVideo == KErr3gpLibMoreDataRequired)
   709 			{
   710 			errReadVideo = ReadAudioVideoFrame(aParser, ETrue, EFalse);
   711 			}
   712 		}
   713 	
   714 	// When last frame has been read, it should return KErrNotFound
   715 	if (errReadAudio != KErrNotFound)
   716 		{
   717 		ERR_PRINTF1(_L("parse->ReadAudioFrames() expects KErrNotFound. "));
   718 		User::Leave(errReadAudio);
   719 		}
   720 	if (errReadVideo != KErrNotFound)
   721 		{
   722 		ERR_PRINTF1(_L("parse->ReadVideoFrame expects KErrNotFound. "));
   723 		User::Leave(errReadVideo);
   724 		}
   725 	
   726 	ParserCompleteL(aParser);
   727 	}
   728 
   729 C3GPLib_AsyncObserver::C3GPLib_AsyncObserver()
   730 	{	
   731 	}
   732 
   733 TVerdict C3GPLib_AsyncObserver::doTestStepPreambleL()
   734 	{
   735 	C3GPLibParser_base::doTestStepPreambleL();
   736 	
   737 	iSchedulerWait = new (ELeave) CActiveSchedulerWait;
   738 	if(!iSchedulerWait)
   739 		{
   740 		SetTestStepResult(EInconclusive);
   741 		}
   742 	return TestStepResult();
   743 	}
   744 
   745 // -----------------------------------------------------------------------------
   746 // C3GPLib_AsyncObserver for asynchronous read
   747 // -----------------------------------------------------------------------------
   748 //
   749 TVerdict C3GPLib_AsyncObserver::doTestStepPostambleL()
   750 	{
   751 	C3GPLibParser_base::doTestStepPostambleL();
   752 	if ( iSchedulerWait)
   753 		{
   754 		if (iSchedulerWait->IsStarted())
   755 			{
   756 			iSchedulerWait->AsyncStop();
   757 			}
   758 		delete iSchedulerWait;
   759 		iSchedulerWait = NULL;
   760 		}	
   761 	return TestStepResult();
   762 	}
   763 
   764 // Read audio or video frame(s) depending on the input parameter asynchronously
   765 TInt C3GPLib_AsyncObserver::ReadAudioVideoFrameAsync(C3GPParse* aParse, TBool aReadAudio, TBool aCancel)
   766 	{
   767 	TInt err = KErrNone;
   768 	TUint size;	
   769 	
   770 	while (err == KErrNone)
   771 		{
   772 		if (aReadAudio)
   773 			{
   774 			err = aParse->GetAudioFramesSize(size);
   775 			}
   776 		else
   777 			{
   778 			err = aParse->GetVideoFrameSize(size);
   779 			}
   780 		
   781 		RBuf8 buffer;
   782 		if (err == KErrNone)
   783 			{
   784 			err = buffer.Create(size);				
   785 			}
   786 		else
   787 			{
   788 			err = buffer.Create(KBufferSize);	
   789 			}
   790 		
   791 		if (err != KErrNone)
   792 			{
   793 			ERR_PRINTF2(_L("buffer.Create(KBufferSize) failed with %d"), err);
   794 			buffer.Close();
   795 			return err;
   796 			}
   797 			
   798 		iWaitForNotification = ETrue;
   799 		if (aReadAudio)
   800 			{				
   801 			aParse->ReadAudioFrames(*this, buffer);
   802 			}
   803 		else 
   804 			{
   805 			aParse->ReadVideoFrame(*this, buffer);
   806 			}
   807 		
   808 		if (aCancel && iAsyncError == KErrNone)
   809 			{
   810 			aParse->CancelReadFrame();
   811 			// Calling cancel again won't have effects
   812 			aParse->CancelReadFrame();
   813 			
   814 			// Do read frame again
   815 			if (aReadAudio)
   816 				{				
   817 				aParse->ReadAudioFrames(*this, buffer);
   818 				}
   819 			else 
   820 				{
   821 				aParse->ReadVideoFrame(*this, buffer);
   822 				}
   823 			}
   824 		
   825 		if (iWaitForNotification)
   826 		    {
   827 			iSchedulerWait->Start();
   828 		    }
   829 		
   830 		err = iAsyncError; 
   831 		buffer.Close(); 
   832 		} 
   833 	
   834 	if ( iSchedulerWait->IsStarted() )
   835         {
   836         iSchedulerWait->AsyncStop();
   837 	    }
   838 			
   839 	if (err != KErrNone && err != KErrNotFound)
   840 		{
   841 		if (!ShouldRunOOMTest())
   842 			{
   843 			ERR_PRINTF2(_L("ReadAudioVideoFrameAsync failed with %d;"), err);
   844 			}
   845 		}
   846 	else
   847 		{
   848 		err = KErrNone;
   849 		}
   850 	
   851 	return err;
   852 	}
   853 
   854 void C3GPLib_AsyncObserver::AudioFramesAvailable(TInt aError, TUint aReturnedFrames, 
   855 			TUint aTimeStampInMs, TUint aTimeStampInTimescale)
   856 	{
   857 	iWaitForNotification = EFalse;
   858 	iAsyncLastNotificationFromAudio = EFalse;
   859 	iAsyncError = aError;
   860 	iAsyncAudioTimeStampInMs = aTimeStampInMs; 
   861 	iAsyncAudioReturnedFrames = aReturnedFrames;
   862 	iAsyncAudioTimestampInTimescale = aTimeStampInTimescale;
   863 	if (iSchedulerWait->IsStarted())
   864 		{
   865 		iSchedulerWait->AsyncStop();
   866 		}
   867 
   868 	}
   869 
   870 void C3GPLib_AsyncObserver::VideoFrameAvailable(TInt aError, TBool aKeyFrame, TUint 
   871 			aTimeStampInMs, TUint aTimeStampInTimescale)
   872 	{
   873 	iWaitForNotification = EFalse;
   874 	iAsyncLastNotificationFromAudio = EFalse;
   875 	iAsyncError = aError;
   876 	iAsyncVideoTimeStampInMs = aTimeStampInMs; 
   877 	iAsyncVideoKeyFrame = aKeyFrame;
   878 	iAsyncVideoTimestampInTimescale = aTimeStampInTimescale;
   879 	
   880 	if (iSchedulerWait->IsStarted())
   881 		{
   882 		iSchedulerWait->AsyncStop();
   883 		}
   884 
   885 	}
   886 
   887 
   888 
   889 // -----------------------------------------------------------------------------
   890 // Setup parser to read file by file path.
   891 // -----------------------------------------------------------------------------
   892 //
   893 C3GPLibParser_0001::C3GPLibParser_0001()
   894 	{
   895 	}
   896 
   897 TVerdict C3GPLibParser_0001::doTestStepL()
   898 	{
   899 	if(TestStepResult() == EPass)
   900 		{
   901 		C3GPParse* parser = C3GPParse::NewL();
   902 		CleanupStack::PushL(parser);
   903 		
   904 		OpenCompleteL(parser);
   905 	
   906 		CleanupStack::PopAndDestroy(parser);
   907 		}
   908 	return TestStepResult();
   909 	}
   910 
   911 void C3GPLibParser_0001::OpenCompleteL(C3GPParse* aParser)
   912 	{
   913 	// Test open and complete with default file access mode
   914 	ParserOpenFileL(aParser);
   915 	ParserCompleteL(aParser);
   916 	
   917 	FileOpenL();
   918     ParserOpenFileL(aParser);
   919 	ParserCompleteL(aParser);
   920 	ParserCompleteL(aParser); // Should not fail when calling complete twice
   921 	FileClose();
   922 	
   923 	//Open the source file passing in the file server session handle, source 
   924     //file path and file access mode (read-write)
   925 	FileOpenL(EFileShareReadersOrWriters | EFileWrite);
   926     ParserOpenFileL(aParser);
   927 	ParserCompleteL(aParser);
   928 	ParserCompleteL(aParser);
   929 	FileClose();
   930 	
   931 	//Open the source file passing in the file server session handle, source 
   932     //file path and file access mode (read-write)
   933 	FileOpenL(EFileShareReadersOrWriters | EFileRead);
   934     ParserOpenFileL(aParser);
   935 	ParserCompleteL(aParser);
   936 	FileClose();
   937 	
   938 	//Open the source file passing in the file server session handle, source 
   939     //file path and file access mode (read-write)
   940 	FileOpenL(EFileShareAny  | EFileWrite);
   941     ParserOpenFileL(aParser);
   942 	ParserCompleteL(aParser);
   943 	FileClose();
   944 	
   945 	//Open the source file passing in the file server session handle, source 
   946     //file path and file access mode (read-write)
   947 	FileOpenL(EFileShareAny | EFileRead);
   948     ParserOpenFileL(aParser);
   949 	ParserCompleteL(aParser);
   950 	FileClose();
   951 	}
   952 
   953 // -----------------------------------------------------------------------------
   954 // Setup parser to read file by buffer mode.
   955 // -----------------------------------------------------------------------------
   956 //
   957 C3GPLibParser_0002::C3GPLibParser_0002()
   958 	{
   959 	}
   960 
   961 TVerdict C3GPLibParser_0002::doTestStepL()
   962 	{	
   963 	if(TestStepResult() == EPass)
   964 		{
   965 		C3GPParse* parser = C3GPParse::NewL();
   966 		CleanupStack::PushL(parser);
   967 		
   968 		OpenCompleteBufferModeL(parser);
   969 		
   970 		CleanupStack::PopAndDestroy(parser);
   971 		}
   972 	return TestStepResult();
   973 	}
   974 
   975 void C3GPLibParser_0002::OpenCompleteBufferModeL(C3GPParse* aParser)
   976 	{
   977 	// buffer mode
   978 	FileOpenL();
   979 	ParserOpenL(aParser);
   980 	
   981 	ParserCompleteL(aParser);
   982 	FileClose();
   983 	}
   984 
   985 // -----------------------------------------------------------------------------
   986 // Setup parser to read file by file handle.
   987 // -----------------------------------------------------------------------------
   988 //
   989 C3GPLibParser_0003::C3GPLibParser_0003()
   990 	{	
   991 	}
   992 
   993 TVerdict C3GPLibParser_0003::doTestStepL()
   994 	{
   995 	if(TestStepResult() == EPass)
   996 		{
   997 		C3GPParse* parser = C3GPParse::NewL();
   998 		CleanupStack::PushL(parser);
   999 		
  1000 		OpenCompleteFileHandleL(parser);
  1001 		
  1002 		CleanupStack::PopAndDestroy(parser);
  1003 		}
  1004 	return TestStepResult();
  1005 	}
  1006 
  1007 void C3GPLibParser_0003::OpenCompleteFileHandleL(C3GPParse* aParser)
  1008 	{
  1009 	ParserOpenFileHandleL(aParser);
  1010 	ParserCompleteHandleL(aParser);
  1011 	
  1012     //Open the source file passing in the file server session handle, source 
  1013     //file path and file access mode (read-only)
  1014 	ParserOpenFileHandleL(aParser, EFileRead | EFileShareReadersOnly);
  1015 	ParserCompleteHandleL(aParser);
  1016 	
  1017 	//Open the source file passing in the file server session handle, source 
  1018     //file path and file access mode (read-only)
  1019 	ParserOpenFileHandleL(aParser, EFileShareReadersOrWriters | EFileWrite);
  1020 	ParserCompleteHandleL(aParser);
  1021 	
  1022 	//Open the source file passing in the file server session handle, source 
  1023     //file path and file access mode (read-only)
  1024 	ParserOpenFileHandleL(aParser, EFileShareReadersOrWriters | EFileRead);
  1025 	ParserCompleteHandleL(aParser);
  1026 	
  1027 	//Open the source file passing in the file server session handle, source 
  1028     //file path and file access mode (read-only)
  1029 	ParserOpenFileHandleL(aParser, EFileShareAny  | EFileWrite);
  1030 	ParserCompleteHandleL(aParser);
  1031     
  1032 	//Open the source file passing in the file server session handle, source 
  1033     //file path and file access mode (read-only)
  1034 	ParserOpenFileHandleL(aParser, EFileShareAny | EFileRead);
  1035 	ParserCompleteHandleL(aParser);
  1036 	}
  1037 
  1038 // -----------------------------------------------------------------------------
  1039 // Setup parser to read file by CAF.
  1040 // -----------------------------------------------------------------------------
  1041 //
  1042 C3GPLibParser_0004::C3GPLibParser_0004()
  1043 	{	
  1044 	}
  1045 
  1046 TVerdict C3GPLibParser_0004::doTestStepL()
  1047 	{
  1048 	if(TestStepResult() == EPass)
  1049 		{
  1050 		CContent* content = CContent::NewLC(iInputFile, EContentShareReadWrite);	
  1051 		
  1052 		CData* data = content->OpenContentL(EPeek);			
  1053 		CleanupStack::PushL(data);
  1054 		
  1055 		C3GPParse* parser = C3GPParse::NewL();
  1056 		CleanupStack::PushL(parser);
  1057 		
  1058 		TInt err = parser->Open(*data);
  1059 
  1060 		if (err != KErrNone)
  1061 			{
  1062 			SetTestStepResult(EFail);
  1063 			CleanupStack::PopAndDestroy(parser);
  1064 			CleanupStack::PopAndDestroy(2); // content, data
  1065 			return TestStepResult();
  1066 			}
  1067 		
  1068 		err = parser->Complete();
  1069 		if (err != KErrNone)
  1070 			{
  1071 			SetTestStepResult(EFail);
  1072 			}
  1073 		
  1074 		CleanupStack::PopAndDestroy(parser);
  1075 		CleanupStack::PopAndDestroy(2); // content, data
  1076 		}
  1077 	return TestStepResult();
  1078 	}
  1079 
  1080 // -----------------------------------------------------------------------------
  1081 // Retrieve video & audio stream attributes from a mp4/3gp/3g2 file with supported 
  1082 // video and audio streams using file mode - file path / file handle and CAF object.
  1083 // -----------------------------------------------------------------------------
  1084 //
  1085 C3GPLibParser_0005::C3GPLibParser_0005()
  1086 	{	
  1087 	}
  1088 
  1089 TVerdict C3GPLibParser_0005::doTestStepL()
  1090 	{
  1091 	if(TestStepResult() == EPass)
  1092 		{
  1093 		C3GPParse* parser = C3GPParse::NewL();
  1094 		CleanupStack::PushL(parser);
  1095 		
  1096 		TRAPD(err, GetVideoAudioAttributesL(parser));
  1097 		if (err != KErrNone)
  1098 			{
  1099 			SetTestStepResult(EFail);
  1100 			}
  1101 		
  1102 		CleanupStack::PopAndDestroy(parser);
  1103 		}
  1104 	return TestStepResult();
  1105 	}
  1106 
  1107 void C3GPLibParser_0005::GetVideoAudioAttributesL(C3GPParse* aParser)
  1108 	{
  1109 	// Open parser in File path
  1110 	ParserOpenFileL(aParser);
  1111 	DoGetVideoAudioAttributesL(aParser);
  1112 	ParserCompleteL(aParser);
  1113 	
  1114 	// open parser in file handle
  1115 	ParserOpenFileHandleL(aParser);
  1116 	DoGetVideoAudioAttributesL(aParser);
  1117 	ParserCompleteHandleL(aParser);
  1118 	
  1119 	// Open parser in CAF
  1120 	ParserOpenCafLC(aParser);
  1121 	DoGetVideoAudioAttributesL(aParser);
  1122 	ParserCompleteCafL(aParser);
  1123 	}
  1124 
  1125 // -----------------------------------------------------------------------------
  1126 // Retrieve video & audio stream attributes from a mp4/3gp/3g2 file 
  1127 // with supported video and audio streams using buffer mode.
  1128 // -----------------------------------------------------------------------------
  1129 //
  1130 C3GPLibParser_0006::C3GPLibParser_0006()
  1131 	{	
  1132 	}
  1133 
  1134 TVerdict C3GPLibParser_0006::doTestStepL()
  1135 	{
  1136 	if(TestStepResult() == EPass)
  1137 		{
  1138 		C3GPParse* parser = C3GPParse::NewL();
  1139 		CleanupStack::PushL(parser);
  1140 		
  1141 		TRAPD(err, VideoAudioAttributesBufferModeL(parser));
  1142 		if (err != KErrNone)
  1143 			{
  1144 			SetTestStepResult(EFail);
  1145 			FileClose();
  1146 			}
  1147 		
  1148 		CleanupStack::PopAndDestroy(parser);
  1149 		}
  1150 	return TestStepResult();
  1151 	}
  1152 
  1153 void C3GPLibParser_0006::VideoAudioAttributesBufferModeL(C3GPParse* aParser)
  1154 	{
  1155 	// buffer mode
  1156 	FileOpenL();
  1157 	ParserOpenL(aParser);
  1158 
  1159 	TInt err = KErrNone;
  1160 	// Retrieve number of buffered bytes before and after data is supplied to the parser.
  1161 	err = GetVideoAudioAttributes(aParser, ENumBufferedBytes);
  1162 	User::LeaveIfError(CheckError(err, KErrNone, _L("GetVideoAudioAttributes(aParser, ENumBufferedBytes)")));
  1163 	
  1164 	ParserCompleteL(aParser);
  1165 	FileClose();
  1166 	
  1167 	// Open the parser again
  1168 	FileOpenL();
  1169 	ParserOpenL(aParser);
  1170 	
  1171 	// Retrieve video and audio descriptions before and after data is supplied to the parser.
  1172 	err = GetVideoAudioAttributes(aParser, EClipProperties);
  1173 	User::LeaveIfError(CheckError(err, KErrNone, _L("GetVideoAudioAttributes(aParser, EClipProperties)")));
  1174 	
  1175 	ParserCompleteL(aParser);
  1176 	FileClose();
  1177 	
  1178 	// Open the parser again
  1179 	FileOpenL();
  1180 	ParserOpenL(aParser);
  1181 	
  1182 	// Retrieve video and audio decoder before and after data is supplied to the parser.
  1183 	err = GetVideoAudioAttributes(aParser, EDecoderInfo);
  1184 	User::LeaveIfError(CheckError(err, KErrNone, _L("GetVideoAudioAttributes(aParser, EDecoderInfo)")));
  1185 	
  1186 	ParserCompleteL(aParser);
  1187 	FileClose();
  1188 	
  1189 	// Open the parser again
  1190 	FileOpenL();
  1191 	ParserOpenL(aParser);
  1192 	
  1193 	
  1194 	// Retrieve video frame properties and number of frames before and after data is supplied to the parser.
  1195 
  1196 	err = GetVideoAudioAttributes(aParser, EVideoFrameProp);
  1197 	User::LeaveIfError(CheckError(err, KErrNone, _L("GetVideoAudioAttributes(aParser, EVideoFrameProp)")));
  1198 	
  1199 	ParserCompleteL(aParser);
  1200 	FileClose();
  1201 	}
  1202 
  1203 TInt C3GPLibParser_0006::CallTest(C3GPParse* aParser, TBufferModeTest aTest, TInt aExpectedNumBuffered)
  1204 	{
  1205 	TInt err = KErrNone;
  1206 	TInt numBufferedBytes;
  1207 
  1208 	// Before insert any data. Retrieving video and audio attributes should fail
  1209 	switch (aTest)
  1210 		{
  1211 		case (ENumBufferedBytes):
  1212 			err = aParser->GetNumBufferedBytes(numBufferedBytes);
  1213 			if (err == KErrNone && numBufferedBytes != aExpectedNumBuffered)
  1214 				{
  1215 				err = KErrGeneral;
  1216 				}
  1217 		break;
  1218 		case (EClipProperties):
  1219 			TInt videoError;
  1220 			TUint videoLength;
  1221 			TUint audioLength;
  1222 			err = GetClipProperties(aParser, videoError, videoLength, audioLength);
  1223 			if ((videoError != KErrNone && videoError != KErr3gpLibMoreDataRequired) || 
  1224 					(err != KErrNone && err != KErr3gpLibMoreDataRequired))
  1225 				{
  1226 				err = KErrGeneral;
  1227 				}
  1228 		break;
  1229 		case (EDecoderInfo):
  1230 			err = ParserGetDecoderInfo(aParser);
  1231 		break;
  1232 		case (EVideoFrameProp):
  1233 			if (aExpectedNumBuffered == 0)
  1234 				{
  1235 				err = GetVideoFramePropAndNumVideoFrame(aParser, EFalse);
  1236 				}
  1237 			else
  1238 				{
  1239 				err = GetVideoFramePropAndNumVideoFrame(aParser, ETrue);
  1240 				}
  1241 		break;
  1242 		default:
  1243 		break;
  1244 		}
  1245 	return err;
  1246 	}
  1247 
  1248 TInt C3GPLibParser_0006::GetVideoAudioAttributes(C3GPParse* aParser, TBufferModeTest aTest)
  1249 	{
  1250 	TInt err = KErrNone;
  1251 	
  1252 	// Before insert any data. Retrieving video and audio attributes should fail
  1253 	err = CallTest(aParser, aTest, 0);
  1254 	if (aTest != ENumBufferedBytes)
  1255 		{
  1256 		err = CheckError(err, KErr3gpLibMoreDataRequired, _L("CallTest(aParser, aTest, 0)"));
  1257 		}
  1258 	else
  1259 		{
  1260 		err = CheckError(err, KErrNone, _L("CallTest()"));
  1261 		}
  1262 	
  1263 	if (err != KErrNone)
  1264 		{
  1265 		ERR_PRINTF2(_L("GetVideoAudioAttributes failed with %d; "), err);
  1266 		return KErrGeneral;
  1267 		}
  1268 	
  1269 	// Insert 1K data to buffer	
  1270 	TInt bufferSize = 0;
  1271 	TInt pos = 0; // from begining of the file
  1272 	err = KErr3gpLibMoreDataRequired;
  1273 	// Insert data until enough data has been inserted
  1274 	while (err == KErr3gpLibMoreDataRequired)
  1275 		{
  1276 		// Insert more data to buffer	
  1277 		pos = bufferSize + pos;
  1278 		bufferSize = KBufferSize;
  1279 		RBuf8 buffer;
  1280 		err = buffer.Create(bufferSize);
  1281 		if (err == KErrNone)
  1282 			{
  1283 			err = iSourceFile.Read(pos, buffer); 
  1284 			if (err == KErrNone)
  1285 				{
  1286 				err = aParser->InsertData(buffer);
  1287 				if ( err == KErrNone )
  1288 					{
  1289 					err = CallTest(aParser, aTest, (bufferSize + pos));
  1290 					}
  1291 				}
  1292 			}
  1293 		buffer.Close();
  1294 		}
  1295 	
  1296 	err = CheckError(err, KErrNone, _L("CallTest()"));
  1297 	return err;
  1298 	}
  1299 
  1300 TInt C3GPLibParser_0006::GetVideoFramePropAndNumVideoFrame(C3GPParse* aParse, TBool aExpectPass)
  1301 	{
  1302 	TInt err = KErrNone;
  1303 	TUint numVideoFrames;
  1304 	err = aParse->GetNumberOfVideoFrames(numVideoFrames);
  1305 	if (aExpectPass)
  1306 		{
  1307 		if ( err == KErrNone )
  1308 			{
  1309 			// Only when GetNumberOfVideoFrames returns KErrNone, the method GetVideoFrameProperties
  1310 			// can be called
  1311 			TUint startIndex = 0;
  1312 			RArray<T3GPFrameInfoParameters> array;
  1313 			err = aParse->GetVideoFrameProperties(startIndex, numVideoFrames, array);
  1314 			array.Close();
  1315 			}		
  1316 		}
  1317 	else
  1318 		{
  1319 		// When there is no data in the handler, GetNumberOfVideoFrames will fail with KErrGeneral, 
  1320 		// not the KErr3gpLibMoreDataRequired
  1321 		if ( err == KErr3gpLibMoreDataRequired || err == KErrGeneral)
  1322 			{
  1323 			if (!ShouldRunOOMTest())
  1324 				{
  1325 				INFO_PRINTF2(_L("Expect parse->GetNumberOfVideoFrames() failed with %d"), err);
  1326 				}
  1327 			err = KErr3gpLibMoreDataRequired;
  1328 			}
  1329 		// expected failure, but get KErrNone.
  1330 		if (err == KErrNone)
  1331 			{
  1332 			INFO_PRINTF1(_L("parse->GetNumberOfVideoFrames() should fail due to buffer too small"));
  1333 			err = KErrGeneral;
  1334 			}
  1335 		}
  1336 	
  1337 	return err;
  1338 	}
  1339 
  1340 // -----------------------------------------------------------------------------
  1341 // Check if the clip is streamable in file mode from a mp4/3gp/3g2 file 
  1342 // -----------------------------------------------------------------------------
  1343 //
  1344 C3GPLibParser_0007::C3GPLibParser_0007()
  1345 	{	
  1346 	}
  1347 
  1348 TVerdict C3GPLibParser_0007::doTestStepL()
  1349 	{
  1350 	if(TestStepResult() == EPass)
  1351 		{
  1352 		C3GPParse* parser = C3GPParse::NewL();
  1353 		CleanupStack::PushL(parser);
  1354 		
  1355 		TRAPD(err, GetstreamableL(parser));
  1356 		if (err != KErrNone)
  1357 			{
  1358 			SetTestStepResult(EFail);
  1359 			}
  1360 		
  1361 		CleanupStack::PopAndDestroy(parser);
  1362 		}
  1363 	return TestStepResult();
  1364 	}
  1365 
  1366 void C3GPLibParser_0007::GetstreamableL(C3GPParse* aParser)
  1367 	{
  1368 	// Open parser in File mode
  1369 	ParserOpenFileL(aParser);
  1370 	
  1371 	// Check if the file is streamable
  1372 	TBool streamable;
  1373 	TInt err = aParser->GetStreamable(streamable);
  1374 	if (err != KErrNone)
  1375 		{
  1376 		SetTestStepError(err);
  1377 		}
  1378 	else if (!streamable)
  1379 		{
  1380 		INFO_PRINTF2(_L("aParser->GetStreamable() returns %d"), streamable);
  1381 		SetTestStepError(KErrNotSupported);
  1382 		}
  1383 	
  1384 	ParserCompleteL(aParser);
  1385 	}
  1386 
  1387 // -----------------------------------------------------------------------------
  1388 // Check if the clip is streamable in buffer mode from a mp4/3gp/3g2 file 
  1389 // -----------------------------------------------------------------------------
  1390 //
  1391 C3GPLibParser_0008::C3GPLibParser_0008()
  1392 	{	
  1393 	}
  1394 
  1395 TVerdict C3GPLibParser_0008::doTestStepL()
  1396 	{
  1397 	if(TestStepResult() == EPass)
  1398 		{
  1399 		C3GPParse* parser = C3GPParse::NewL();
  1400 		CleanupStack::PushL(parser);
  1401 		
  1402 		TRAPD(err, GetstreamableL(parser));
  1403 		if (err != KErrNone)
  1404 			{
  1405 			SetTestStepResult(EFail);
  1406 			}
  1407 		
  1408 		CleanupStack::PopAndDestroy(parser);
  1409 		}
  1410 	return TestStepResult();
  1411 	}
  1412 
  1413 void C3GPLibParser_0008::GetstreamableL(C3GPParse* aParser)
  1414 	{
  1415 	// buffer mode
  1416 	FileOpenL();
  1417 	ParserOpenL(aParser);
  1418 
  1419 	// Check if the file is streamable before the data is inserted
  1420 	TBool streamable;
  1421 	TInt err = aParser->GetStreamable(streamable);
  1422 	
  1423 	// Insert 1K data to buffer	
  1424 	TInt bufferSize = 0;
  1425 	TInt pos = 0; // from begining of the file
  1426 
  1427 	// Insert data until enough data has been inserted
  1428 	while (err == KErr3gpLibMoreDataRequired)
  1429 		{
  1430 		// Insert more data to buffer	
  1431 		pos = bufferSize + pos;
  1432 		bufferSize = KBufferSize;
  1433 		InsertDataL(aParser, iSourceFile, bufferSize, pos);
  1434 		
  1435 		err = aParser->GetStreamable(streamable);
  1436 		}
  1437 	
  1438 	if (err != KErrNone)
  1439 		{
  1440 		if (!ShouldRunOOMTest())
  1441 			{
  1442 			ERR_PRINTF2(_L("aParser->GetStreamable() returns %d"), err);
  1443 			}
  1444 		SetTestStepError(err);
  1445 		}
  1446 	
  1447 	ParserCompleteL(aParser);
  1448 	FileClose();
  1449 	}
  1450 
  1451 // -----------------------------------------------------------------------------
  1452 // Retrieve buffered bytes, and video & audio frames synchronously in file mode
  1453 // -----------------------------------------------------------------------------
  1454 //
  1455 C3GPLibParser_0011::C3GPLibParser_0011()
  1456 	{	
  1457 	}
  1458 
  1459 TVerdict C3GPLibParser_0011::doTestStepL()
  1460 	{
  1461 	if(TestStepResult() == EPass)
  1462 		{
  1463 		C3GPParse* parser = C3GPParse::NewL();
  1464 		CleanupStack::PushL(parser);
  1465 		
  1466 		TRAPD(err, ReadFrameL(parser));
  1467 		if (err != KErrNone)
  1468 			{
  1469 			SetTestStepResult(EFail);
  1470 			}
  1471 		
  1472 		CleanupStack::PopAndDestroy(parser);
  1473 		}
  1474 	return TestStepResult();
  1475 	}
  1476 
  1477 void C3GPLibParser_0011::ReadFrameL(C3GPParse* aParse)
  1478 	{
  1479 	// Parser open using File path 
  1480 	ParserOpenFileL(aParse);
  1481 	User::LeaveIfError(DoReadFrame(aParse));
  1482 	ParserCompleteL(aParse);
  1483 	
  1484 	// Parser open using file handler
  1485 	ParserOpenFileHandleL(aParse);
  1486 	User::LeaveIfError(DoReadFrame(aParse));
  1487 	ParserCompleteHandleL(aParse);
  1488     
  1489 	// Parser open using CAF
  1490 	ParserOpenCafLC(aParse);
  1491 	User::LeaveIfError(DoReadFrame(aParse));
  1492 	ParserCompleteCafL(aParse);
  1493 	}
  1494 
  1495 // -----------------------------------------------------------------------------
  1496 // Parse video & audio frames from a mp4/3gp file asynchronously in file mode
  1497 // -----------------------------------------------------------------------------
  1498 //
  1499 C3GPLibParser_0014::C3GPLibParser_0014()
  1500 	{	
  1501 	}
  1502 
  1503 TVerdict C3GPLibParser_0014::doTestStepPreambleL()
  1504 	{
  1505 	C3GPLib_AsyncObserver::doTestStepPreambleL();	
  1506 	if (TestStepResult() == EPass)
  1507 		{
  1508 		iScheduler = new (ELeave) CActiveScheduler;
  1509 		CActiveScheduler::Install(iScheduler);
  1510 		}
  1511 	return TestStepResult();
  1512 	}
  1513 
  1514 TVerdict C3GPLibParser_0014::doTestStepPostambleL()
  1515 	{
  1516 	C3GPLib_AsyncObserver::doTestStepPostambleL();
  1517 	if( iScheduler )
  1518 		{
  1519 		INFO_PRINTF1(_L("delete iScheduler"));
  1520 		CActiveScheduler::Install(NULL);
  1521 		delete iScheduler;
  1522 		iScheduler = NULL;
  1523 		}
  1524 
  1525 	return TestStepResult();
  1526 	}
  1527 
  1528 TVerdict C3GPLibParser_0014::doTestStepL()
  1529 	{
  1530 	if(TestStepResult() == EPass)
  1531 		{
  1532 		C3GPParse* parser = C3GPParse::NewL();
  1533 		CleanupStack::PushL(parser);
  1534 		
  1535 		TRAPD(err, ReadFrameAsyncL(parser));
  1536 		if (err != KErrNone)
  1537 			{
  1538 			SetTestStepResult(EFail);
  1539 			}
  1540 		
  1541 		CleanupStack::PopAndDestroy(parser);
  1542 		}
  1543 	return TestStepResult();
  1544 	}
  1545 
  1546 void C3GPLibParser_0014::ReadFrameAsyncL(C3GPParse* aParser)
  1547 	{
  1548 	ParserOpenFileL(aParser);
  1549 	User::LeaveIfError(DoReadFrameAsync(aParser));
  1550 	if (!ShouldRunOOMTest())
  1551 		{
  1552 		INFO_PRINTF1(_L("C3GPLibParser_0014::ReadFrameAsyncL()"));
  1553 		}
  1554 	ParserCompleteL(aParser);
  1555 
  1556 	ParserOpenFileL(aParser);
  1557 	User::LeaveIfError(DoReadFrameAsync(aParser, ETrue));
  1558 	if (!ShouldRunOOMTest())
  1559 		{
  1560 		INFO_PRINTF1(_L("C3GPLibParser_0014::ReadFrameAsyncL(), then cancel the read"));
  1561 		}
  1562 	ParserCompleteL(aParser);
  1563 	
  1564 	ParserOpenFileHandleL(aParser);
  1565 	User::LeaveIfError(DoReadFrameAsync(aParser));
  1566 	if (!ShouldRunOOMTest())
  1567 		{
  1568 		INFO_PRINTF1(_L("C3GPLibParser_0014::ReadFrameAsyncL() using file handler"));
  1569 		}
  1570 	ParserCompleteHandleL(aParser);
  1571 
  1572 	ParserOpenCafLC(aParser);
  1573 	User::LeaveIfError(DoReadFrameAsync(aParser));
  1574 	if (!ShouldRunOOMTest())
  1575 		{
  1576 		INFO_PRINTF1(_L("C3GPLibParser_0014::ReadFrameAsyncL() using CAF"));
  1577 		}
  1578 	ParserCompleteCafL(aParser);
  1579 	}
  1580 
  1581 TInt C3GPLibParser_0014::DoReadFrameAsync(C3GPParse* aParser, TBool aCancel)
  1582 	{    
  1583     TInt err = KErrNone;
  1584     
  1585     if (!aCancel)
  1586     	{
  1587     	err = ReadAudioVideoFrameAsync(aParser, ETrue);
  1588     	if (err == KErrNone)
  1589     		{
  1590     		err = ReadAudioVideoFrameAsync(aParser, EFalse);
  1591     		} 
  1592     	}
  1593     else
  1594     	{
  1595     	err = ReadAudioVideoFrameAsync(aParser, EFalse, ETrue);
  1596     	}
  1597  
  1598     return err;
  1599     }
  1600 
  1601 // -----------------------------------------------------------------------------
  1602 // Parse video & audio frames from a mp4/3gp file synchronously
  1603 // -----------------------------------------------------------------------------
  1604 //
  1605 C3GPLibParser_0015::C3GPLibParser_0015()
  1606 	{	
  1607 	}
  1608 
  1609 TVerdict C3GPLibParser_0015::doTestStepL()
  1610 	{
  1611 	if(TestStepResult() == EPass)
  1612 		{
  1613 		C3GPParse* parser = C3GPParse::NewL();
  1614 		CleanupStack::PushL(parser);
  1615 		
  1616 		TRAPD(err, ReadFrameL(parser));
  1617 		if (err != KErrNone)
  1618 			{
  1619 			SetTestStepResult(EFail);
  1620 			}
  1621 		
  1622 		CleanupStack::PopAndDestroy(parser);
  1623 		}
  1624 	return TestStepResult();
  1625 	}
  1626 
  1627 void C3GPLibParser_0015::ReadFrameL(C3GPParse* aParser)
  1628 	{
  1629 	FileOpenL();
  1630 	ReadFrameBufferModeL(aParser);
  1631 	FileClose();
  1632 	}
  1633 
  1634 // -----------------------------------------------------------------------------
  1635 // Get frame type using file path
  1636 // -----------------------------------------------------------------------------
  1637 //
  1638 C3GPLibParser_0016::C3GPLibParser_0016()
  1639 	{	
  1640 	}
  1641 
  1642 
  1643 TVerdict C3GPLibParser_0016::doTestStepL()
  1644 	{
  1645 	if(TestStepResult() == EPass)
  1646 		{
  1647 		C3GPParse* parser = C3GPParse::NewL();
  1648 		CleanupStack::PushL(parser);
  1649 		
  1650 		TRAPD(err, GetFrameTypeL(parser));
  1651 		if (err != KErrNone)
  1652 			{
  1653 			SetTestStepResult(EFail);
  1654 			}
  1655 		
  1656 		CleanupStack::PopAndDestroy(parser);
  1657 		}
  1658 	return TestStepResult();
  1659 	}
  1660 
  1661 void C3GPLibParser_0016::GetFrameTypeL(C3GPParse* aParser)
  1662 	{
  1663 	ParserOpenFileL(aParser);
  1664 	
  1665 	T3GPFrameType type;
  1666 	TInt err = aParser->GetFrameType(type);
  1667 	if (err == KErrNone)
  1668 		{
  1669 		TUint num;
  1670 		err = aParser->GetNumberOfVideoFrames(num);
  1671 		if (err == KErrNone)
  1672 			{
  1673 			// There is number of video in the file. Calling GetFrameType num+1 time won't affect 
  1674 			//the parser’s current position. It should return the same results
  1675 			for (TInt i = 0; i < num; i++)
  1676 				{
  1677 				err = aParser->GetFrameType(type);
  1678 				User::LeaveIfError(err);
  1679 				}
  1680 			err = aParser->GetFrameType(type);
  1681 			User::LeaveIfError(err);
  1682 			}
  1683 
  1684 		if (!ShouldRunOOMTest())
  1685 			{
  1686 			INFO_PRINTF2(_L("GetFrameType return type %d. "), type);
  1687 			}
  1688 		if (type == E3GPAudio)
  1689 			{
  1690 			// read 1 audio frame		
  1691 			err = ReadAudioVideoFrame(aParser, EFalse, ETrue);
  1692 			User::LeaveIfError(CheckError(err, KErrNone, _L("ReadAudioVideoFrame")));
  1693 
  1694 			err = aParser->GetFrameType(type);
  1695 			if (!ShouldRunOOMTest())
  1696 				{
  1697 				INFO_PRINTF3(_L("After read 1 audio frame, GetFrameType return err %d; type %d. "), err, type);
  1698 				}
  1699 			SetTestStepError(err);
  1700 			}
  1701 		if (err == KErrNone && type == E3GPVideo)
  1702 			{
  1703 			// read 1 video frame
  1704 			err = ReadAudioVideoFrame(aParser, EFalse, EFalse);
  1705 			User::LeaveIfError(CheckError(err, KErrNone, _L("ReadAudioVideoFrame")));
  1706 			
  1707 			err = aParser->GetFrameType(type);
  1708 			SetTestStepError(err);
  1709 			}
  1710 		}
  1711 	else
  1712 		{
  1713 		SetTestStepError(err);
  1714 		}
  1715 	ParserCompleteL(aParser);
  1716 	}
  1717 
  1718 // -----------------------------------------------------------------------------
  1719 // Get the QCELP storage mode in file path and buffer mode
  1720 // -----------------------------------------------------------------------------
  1721 //
  1722 C3GPLibParser_0017::C3GPLibParser_0017()
  1723 	{	
  1724 	}
  1725 
  1726 TVerdict C3GPLibParser_0017::doTestStepL()
  1727 	{
  1728 	if(TestStepResult() == EPass)
  1729 		{
  1730 		C3GPParse* parser = C3GPParse::NewL();
  1731 		CleanupStack::PushL(parser);
  1732 		
  1733 		TRAPD(err, GetQcelModeL(parser));
  1734 		if (err != KErrNone)
  1735 			{
  1736 			SetTestStepResult(EFail);
  1737 			}
  1738 		
  1739 		CleanupStack::PopAndDestroy(parser);
  1740 		}
  1741 	return TestStepResult();
  1742 	}
  1743 
  1744 void C3GPLibParser_0017::GetQcelModeL(C3GPParse* aParser)
  1745 	{
  1746 	// file mode
  1747 	ParserOpenFileL(aParser);
  1748 	TInt err = KErrNone;
  1749 	T3GPQcelpStorageMode mode;
  1750 	err = aParser->GetQcelpStorageMode(mode);
  1751 	if (err != KErrNone)
  1752 		{
  1753 		if (!ShouldRunOOMTest())
  1754 			{
  1755 			ERR_PRINTF3(_L("aParser->GetQcelpStorageMode(mode) file mode return %d; mode %d. "), err, mode);
  1756 			}
  1757 		SetTestStepError(err);
  1758 		}
  1759 
  1760 	if ((iTestSection.Compare(KEsds) == 0 && mode != E3GPQcelpSampleEntryBox ) ||
  1761 			(iTestSection.Compare(KSqcp) == 0 && mode != E3GPMP4AudioDescriptionBox ))
  1762 		{
  1763 		User::Leave(KErrGeneral);
  1764 		}
  1765 	
  1766 	ParserCompleteL(aParser);
  1767 	
  1768 	// buffer mode
  1769 	ParserOpenL(aParser);
  1770 	FileOpenL();
  1771 	
  1772 	// Insert 1K data into the library
  1773 	TInt pos = 0;
  1774 	TInt bufferSize = 1000;
  1775 	
  1776 	InsertDataL(aParser, iSourceFile, bufferSize, pos);
  1777 	err = aParser->GetQcelpStorageMode(mode);
  1778 	
  1779 	while (err == KErr3gpLibMoreDataRequired )
  1780 		{
  1781 		pos = pos + bufferSize;
  1782 		InsertDataL(aParser, iSourceFile, bufferSize, pos);
  1783 		err = aParser->GetQcelpStorageMode(mode);
  1784 		}
  1785 	
  1786 	if (err != KErrNone)
  1787 		{
  1788 		if (!ShouldRunOOMTest())
  1789 			{
  1790 			ERR_PRINTF3(_L("aParser->GetQcelpStorageMode(mode) file mode return %d; mode %d. "), err, mode);
  1791 			}
  1792 		SetTestStepError(err);
  1793 		}
  1794 	
  1795 	if ((iTestSection.Compare(KEsds) == 0 && mode != E3GPQcelpSampleEntryBox ) ||
  1796 			(iTestSection.Compare(KSqcp) == 0 && mode != E3GPMP4AudioDescriptionBox ))
  1797 		{
  1798 		User::Leave(KErrGeneral);
  1799 		}
  1800 	
  1801 	ParserCompleteL(aParser);
  1802 	FileClose();
  1803 	}
  1804 
  1805 // -----------------------------------------------------------------------------
  1806 // Get H263 video leve in file path and buffer mode.
  1807 // -----------------------------------------------------------------------------
  1808 //
  1809 C3GPLibParser_0021::C3GPLibParser_0021()
  1810 	{	
  1811 	}
  1812 
  1813 TVerdict C3GPLibParser_0021::doTestStepL()
  1814 	{
  1815 	if(TestStepResult() == EPass)
  1816 		{
  1817 		C3GPParse* parser = C3GPParse::NewL();
  1818 		CleanupStack::PushL(parser);
  1819 		
  1820 		TRAPD(err, GetH263LevelL(parser));
  1821 		if (err != KErrNone)
  1822 			{
  1823 			SetTestStepResult(EFail);
  1824 			}
  1825 		
  1826 		CleanupStack::PopAndDestroy(parser);
  1827 		}
  1828 	return TestStepResult();
  1829 	}
  1830 
  1831 void C3GPLibParser_0021::GetH263LevelL(C3GPParse* aParser)
  1832 	{
  1833 	// file mode
  1834 	ParserOpenFileL(aParser);
  1835 	TInt err = KErrNone;
  1836 	TInt level;
  1837 	err = aParser->GetH263VideoLevel(level);
  1838 	if (err != KErrNone)
  1839 		{
  1840 		if (!ShouldRunOOMTest())
  1841 			{
  1842 			ERR_PRINTF3(_L("aParser->GetH263VideoLevel() file mode return %d; level %d. "), err, level);
  1843 			}
  1844 		SetTestStepError(err);
  1845 		}
  1846 	
  1847 	ParserCompleteL(aParser);
  1848 	
  1849 	// buffer mode
  1850 	ParserOpenL(aParser);
  1851 	FileOpenL();
  1852 	
  1853 	// Insert 1K data into the library
  1854 	TInt pos = 0;
  1855 	TInt bufferSize = KBufferSize;
  1856 	
  1857 	InsertDataL(aParser, iSourceFile, bufferSize, pos);
  1858 	err = aParser->GetH263VideoLevel(level);;
  1859 	
  1860 	while (err == KErr3gpLibMoreDataRequired )
  1861 		{
  1862 		pos = pos + bufferSize;
  1863 		InsertDataL(aParser, iSourceFile, bufferSize, pos);
  1864 		err = aParser->GetH263VideoLevel(level);;
  1865 		}
  1866 	
  1867 	if (err != KErrNone)
  1868 		{
  1869 		if (!ShouldRunOOMTest())
  1870 			{
  1871 			ERR_PRINTF3(_L("aParser->GetH263VideoLevel() file mode return %d; level %d. "), err, level);
  1872 			}
  1873 		SetTestStepError(err);
  1874 		}
  1875 	
  1876 	ParserCompleteL(aParser);
  1877 	FileClose();
  1878 	}
  1879 
  1880 // -----------------------------------------------------------------------------
  1881 // Read Video and audio Decoder Info size and info in file path and buffer mode.
  1882 // -----------------------------------------------------------------------------
  1883 //
  1884 C3GPLibParser_0023::C3GPLibParser_0023()
  1885 	{	
  1886 	}
  1887 
  1888 TVerdict C3GPLibParser_0023::doTestStepL()
  1889 	{
  1890 	if(TestStepResult() == EPass)
  1891 		{
  1892 		C3GPParse* parser = C3GPParse::NewL();
  1893 		CleanupStack::PushL(parser);
  1894 		
  1895 		TRAPD(err, GetDecoderInfoL(parser));
  1896 		if (err != KErrNone)
  1897 			{
  1898 			SetTestStepResult(EFail);
  1899 			}
  1900 		
  1901 		CleanupStack::PopAndDestroy(parser);
  1902 		}
  1903 	return TestStepResult();
  1904 	}
  1905 
  1906 void C3GPLibParser_0023::GetDecoderInfoL(C3GPParse* aParser)
  1907 	{
  1908 	// file mode
  1909 	ParserOpenFileL(aParser);
  1910 
  1911 	TInt errReadAudio = KErrNone;
  1912 	TInt errReadVideo = KErrNone;
  1913 	// Retrieve the info with buffer size = 0. Should fail with KErrOverflow
  1914 	RBuf8 dsiBuffer;
  1915 	CleanupClosePushL(dsiBuffer);
  1916 	dsiBuffer.CreateL(0);
  1917 	errReadAudio = aParser->GetAudioDecoderSpecificInfo(dsiBuffer);
  1918 	errReadVideo = aParser->GetVideoDecoderSpecificInfo(dsiBuffer);
  1919 	
  1920 	if (errReadAudio == KErrOverflow && errReadVideo == KErrOverflow)
  1921 		{
  1922 		errReadAudio = ParserGetDecoderInfo(aParser);
  1923 		
  1924 		if (errReadAudio != KErrNone)
  1925 			{
  1926 			ERR_PRINTF2(_L("ParserGetDecoderInfo file mode return %d; "), errReadAudio);
  1927 			User::Leave(errReadAudio);
  1928 			}
  1929 		}
  1930 	else
  1931 		{
  1932 		ERR_PRINTF2(_L("ParserGetDecoderInfo file mode expected KErrOverflow, but return %d; "), errReadAudio);
  1933 		User::Leave(errReadAudio);
  1934 		}
  1935 	
  1936 	ParserCompleteL(aParser);
  1937 	
  1938 	// buffer mode
  1939 	ParserOpenL(aParser);
  1940 	FileOpenL();
  1941 	
  1942 	// Insert 1K data into the library
  1943 	TInt pos = 0;
  1944 	TInt bufferSize = KBufferSize;
  1945 	
  1946 	InsertDataL(aParser, iSourceFile, bufferSize, pos);
  1947 	
  1948 	// Retrieve the info with buffer size = 0. Should fail with KErrOverflow
  1949 	dsiBuffer.Close();
  1950 	dsiBuffer.CreateL(0);
  1951 	errReadAudio = aParser->GetAudioDecoderSpecificInfo(dsiBuffer);
  1952 	errReadVideo = aParser->GetVideoDecoderSpecificInfo(dsiBuffer);
  1953 	CleanupStack::PopAndDestroy(&dsiBuffer);
  1954 	
  1955 	if (errReadAudio != KErrOverflow || errReadVideo != KErrOverflow)
  1956 		{
  1957 		ERR_PRINTF2(_L("ParserGetDecoderInfo buffer mode expected KErrOverflow, but return %d; "), errReadAudio);
  1958 		User::Leave(errReadAudio);
  1959 		}
  1960 	errReadAudio = ParserGetDecoderInfo(aParser);
  1961 	
  1962 	while (errReadAudio == KErr3gpLibMoreDataRequired )
  1963 		{
  1964 		pos = pos + bufferSize;
  1965 		InsertDataL(aParser, iSourceFile, bufferSize, pos);
  1966 		errReadAudio = ParserGetDecoderInfo(aParser);
  1967 		}
  1968 	if (!ShouldRunOOMTest())
  1969 		{
  1970 		INFO_PRINTF2(_L("ParserGetDecoderInfo(aParser) buffer mode return %d. "), errReadAudio);
  1971 		}
  1972 	ParserCompleteL(aParser);
  1973 	FileClose();
  1974 	}
  1975 
  1976 // -----------------------------------------------------------------------------
  1977 // Seek different position of a video/audio file
  1978 // -----------------------------------------------------------------------------
  1979 //
  1980 C3GPLibParser_0027::C3GPLibParser_0027()
  1981 	{
  1982 	}
  1983 
  1984 TVerdict C3GPLibParser_0027::doTestStepL()
  1985 	{
  1986 	if(TestStepResult() == EPass)
  1987 		{
  1988 		C3GPParse* parser = C3GPParse::NewL();
  1989 		CleanupStack::PushL(parser);
  1990 		
  1991 		TRAPD(err, SeekTestL(parser));
  1992 		if (err != KErrNone)
  1993 			{
  1994 			SetTestStepResult(EFail);
  1995 			}
  1996 		
  1997 		CleanupStack::PopAndDestroy(parser);
  1998 		}
  1999 	return TestStepResult();
  2000 	}
  2001 
  2002 void C3GPLibParser_0027::SeekTestL(C3GPParse* aParse)
  2003 	{	
  2004 	// file mode
  2005 	ParserOpenFileL(aParse);
  2006 	
  2007 	TUint audioPos;
  2008 	TUint videoPos;
  2009 	TUint timeStampInMs = 0;
  2010 	
  2011 	// Seek to position 0.
  2012 	TInt err = KErrNone; 
  2013 	if (iTestSection.Compare(KNoAudioNoVideo) != 0)
  2014 		{
  2015 		// Retrieve video & audio stream length
  2016 		TUint videoLength; 
  2017 		TUint audioLength; 
  2018 		TInt videoError;
  2019 
  2020 		err = GetClipProperties(aParse, videoError, videoLength, audioLength);
  2021 		if (iTestSection.Compare(KAudioOnly) == 0)
  2022 			{
  2023 			// audio only, GetVideoProperties should fail with KErrNotSupported. Set video length to 0
  2024 			User::LeaveIfError(CheckError(videoError, KErrNotSupported, _L("GetClipProperties(aParse, videoError, videoLength, audioLength))")));
  2025 			videoLength = 0;
  2026 			}
  2027 		else if (iTestSection.Compare(KVideoOnly) == 0)
  2028 			{
  2029 			// video only, GetAudioProperties should fail with KErrNotSupported. Set audio length to 0
  2030 			User::LeaveIfError(CheckError(err, KErrNotSupported, _L("GetClipProperties(aParse, videoError, videoLength, audioLength)")));
  2031 			audioLength = 0;
  2032 			}
  2033 		else 
  2034 			{
  2035 			// All other files contains audio and video data
  2036 			User::LeaveIfError(CheckError(videoError, KErrNone, _L("GetClipProperties(aParse, videoError, videoLength, audioLength)")));
  2037 			User::LeaveIfError(CheckError(err, KErrNone, _L("GetClipProperties(aParse, videoError, videoLength, audioLength)")));
  2038 			}
  2039 		
  2040 		if (audioLength >= videoLength)
  2041 			{
  2042 			timeStampInMs = audioLength;
  2043 			}
  2044 		else
  2045 			{
  2046 			timeStampInMs = videoLength;
  2047 			}
  2048 		
  2049 		if (iTestSection.Compare(KSameLenAudioVideo) == 0 || iTestSection.Compare(KAudioOnly) == 0)
  2050 			{
  2051 			err = ParserSeek(aParse, timeStampInMs, audioPos, videoPos);
  2052 			User::LeaveIfError(err);
  2053 			}
  2054 		
  2055 		if (iTestSection.Compare(KAudioMore) == 0 || iTestSection.Compare(KVideoMore) == 0 )
  2056 			{
  2057 			timeStampInMs = (audioLength + videoLength)/2;
  2058 			err = aParse->Seek(timeStampInMs, EFalse, audioPos, videoPos);
  2059 			User::LeaveIfError(err);
  2060 			}
  2061 		}
  2062 	
  2063 	ParserCompleteL(aParse);
  2064 	}
  2065 
  2066 // Seek position 0, half the length and the length of the stream
  2067 TInt C3GPLibParser_0027::ParserSeek(C3GPParse* aParser, TInt aLen, TUint& aAudioPos, TUint& aVideoPos)
  2068 	{
  2069 	TInt err = KErrNone;
  2070 	TUint position = 0;
  2071 	while (err == KErrNone && position <= aLen)
  2072 		{
  2073 		err = aParser->Seek(position, ETrue, aAudioPos, aVideoPos);
  2074 		if (err == KErrNone)
  2075 			{
  2076 			err = aParser->Seek(position, EFalse, aAudioPos, aVideoPos);
  2077 			}
  2078 		position = position + aLen/2;
  2079 		}
  2080 
  2081 	if (err != KErrNone)
  2082 		{
  2083 		ERR_PRINTF3(_L("aParser->Seek() failed with %d when positon is %d"), err, position);
  2084 		}
  2085 	return err;
  2086 	}
  2087 
  2088 // -----------------------------------------------------------------------------
  2089 // Seek positions after any keyframe and immediately after a non-key frame.
  2090 // -----------------------------------------------------------------------------
  2091 //
  2092 C3GPLibParser_0031::C3GPLibParser_0031()
  2093 	{	
  2094 	}
  2095 
  2096 TVerdict C3GPLibParser_0031::doTestStepL()
  2097 	{
  2098 	if(TestStepResult() == EPass)
  2099 		{
  2100 		C3GPParse* parser = C3GPParse::NewL();
  2101 		CleanupStack::PushL(parser);
  2102 		
  2103 		TRAPD(err, SeekTestL(parser));
  2104 		if (err != KErrNone)
  2105 			{
  2106 			SetTestStepResult(EFail);
  2107 			}
  2108 		
  2109 		CleanupStack::PopAndDestroy(parser);
  2110 		}
  2111 	return TestStepResult();
  2112 	}
  2113 
  2114 void C3GPLibParser_0031::SeekTestL(C3GPParse* aParser)
  2115 	{
  2116 	// file mode
  2117 	ParserOpenFileL(aParser);	
  2118 	DoSeekTestL(aParser);			
  2119 	ParserCompleteL(aParser);
  2120 	}
  2121 
  2122 // -----------------------------------------------------------------------------
  2123 // Check frame availability using file path
  2124 // -----------------------------------------------------------------------------
  2125 //
  2126 C3GPLibParser_0032::C3GPLibParser_0032()
  2127 	{	
  2128 	}
  2129 
  2130 TVerdict C3GPLibParser_0032::doTestStepL()
  2131 	{
  2132 	if(TestStepResult() == EPass)
  2133 		{
  2134 		C3GPParse* parser = C3GPParse::NewL();
  2135 		CleanupStack::PushL(parser);
  2136 		
  2137 		TRAPD(err, GetFrameAvailabilityL(parser));
  2138 		if (err != KErrNone)
  2139 			{
  2140 			SetTestStepResult(EFail);
  2141 			}
  2142 		
  2143 		CleanupStack::PopAndDestroy(parser);
  2144 		}
  2145 	return TestStepResult();
  2146 	}
  2147 
  2148 void C3GPLibParser_0032::GetFrameAvailabilityL(C3GPParse* aParser)
  2149 	{
  2150 	// file mode
  2151 	ParserOpenFileL(aParser);
  2152 	DoGetFrameAvailabilityL(aParser);
  2153 	ParserCompleteL(aParser);
  2154 	}
  2155 
  2156 void C3GPLibParser_0032::DoGetFrameAvailabilityL(C3GPParse* aParser)
  2157 	{
  2158 	T3GPFrameType audioType = E3GPAudio;
  2159 	T3GPFrameType videoType = E3GPVideo;
  2160 	TBool audioAvailable;
  2161 	TBool videoAvailable;
  2162 	TUint num;
  2163 	TInt audioErr = aParser->GetFrameAvailability(audioType, audioAvailable);
  2164 	if (audioErr != KErrNone && audioErr != KErrNotFound)
  2165 		{
  2166 		SetTestStepError(audioErr);
  2167 		User::LeaveIfError(audioErr);
  2168 		}
  2169 	
  2170 	TInt videoErr = aParser->GetFrameAvailability(videoType, videoAvailable);
  2171 	if (videoErr != KErrNone && videoErr != KErrNotFound)
  2172 		{
  2173 		SetTestStepError(videoErr);
  2174 		User::LeaveIfError(videoErr);
  2175 		}
  2176 	
  2177 	TInt err = aParser->GetNumberOfVideoFrames(num);
  2178 	if (err != KErrNone && err != KErrNotSupported)
  2179 		{
  2180 		SetTestStepError(err);
  2181 		User::LeaveIfError(err);
  2182 		}
  2183 	
  2184 	if (iTestSection.Compare(KNoAudioNoVideo) == 0)
  2185 		{
  2186 		if (audioErr != KErrNotFound || videoErr != KErrNotFound 
  2187 				|| audioAvailable || videoAvailable)
  2188 			{
  2189 			ERR_PRINTF2(_L("GetFrameAvailability() audio failed with %d, expected KErrNotFound"), audioErr);
  2190 			ERR_PRINTF2(_L("GetFrameAvailability() expected audioAvailable returns false, actual %d "), audioAvailable);
  2191 			ERR_PRINTF2(_L("GetFrameAvailability() video failed with %d, expected KErrNotFound;"), videoErr);
  2192 			ERR_PRINTF2(_L("GetFrameAvailability() expected videoAvailable returns false, actual %d "), videoAvailable);
  2193 			User::Leave(KErrGeneral);  
  2194 			}				
  2195 		User::LeaveIfError(CheckError(err, KErrNotSupported, _L("aParser->GetNumberOfVideoFrames(num)")));
  2196 		}
  2197 	else if (iTestSection.Compare(KAudioOnly) == 0)
  2198 		{
  2199 		if (audioErr != KErrNone || videoErr != KErrNotFound 
  2200 				|| !audioAvailable || videoAvailable)
  2201 			{
  2202 			ERR_PRINTF2(_L("aParser->GetFrameAvailability() audio failed with %d, expected KErrNone"), audioErr);
  2203 			ERR_PRINTF2(_L("aParser->GetFrameAvailability() expected audioAvailable returns True, actual %d "), audioAvailable);
  2204 			ERR_PRINTF2(_L("aParser->GetFrameAvailability() video failed with %d, expected KErrNotFound;"), videoErr);
  2205 			ERR_PRINTF2(_L("aParser->GetFrameAvailability() expected videoAvailable returns false, actual %d"), videoAvailable);
  2206 			User::Leave(KErrGeneral);
  2207 			}
  2208 		User::LeaveIfError(CheckError(err, KErrNotSupported, _L("aParser->GetNumberOfVideoFrames(num)")));
  2209 		}
  2210 	else if (iTestSection.Compare(KVideoOnly) == 0)
  2211 		{
  2212 		if (audioErr != KErrNotFound || videoErr != KErrNone 
  2213 				|| audioAvailable || !videoAvailable)
  2214 			{
  2215 			ERR_PRINTF2(_L("aParser->GetFrameAvailability() audio failed with %d, expected KErrNotFound"), audioErr);
  2216 			ERR_PRINTF2(_L("aParser->GetFrameAvailability() expected audioAvailable returns false, actual %d "), audioAvailable);
  2217 			ERR_PRINTF2(_L("aParser->GetFrameAvailability() video failed with %d, expected KErrNone;"), videoErr);
  2218 			ERR_PRINTF2(_L("aParser->GetFrameAvailability() expected videoAvailable returns true, actual %d"), videoAvailable);
  2219 			User::Leave(KErrGeneral);
  2220 			}
  2221 		User::LeaveIfError(CheckError(err, KErrNone, _L("aParser->GetNumberOfVideoFrames(num)")));
  2222 		if (num != 265)
  2223 			{
  2224 			ERR_PRINTF2(_L("file h263-no-audio.MP4 has 265 video frames. Got %d instread"), num);
  2225 			User::Leave(KErrGeneral);
  2226 			}
  2227 		}
  2228 	else // File contains both valid audio and video data
  2229 		{
  2230 		// If file contains avc profile main or extended, videoErr could be KErrNotFound
  2231 		if (audioErr != KErrNone || !audioAvailable)
  2232 			{
  2233 			ERR_PRINTF2(_L("aParser->GetFrameAvailability() audio failed with %d, expected KErrNone"), audioErr);
  2234 			ERR_PRINTF2(_L("aParser->GetFrameAvailability() expected audioAvailable returns True, actual %d "), audioAvailable);
  2235 			ERR_PRINTF2(_L("aParser->GetFrameAvailability() video failed with %d, expected KErrNone;"), videoErr);
  2236 			ERR_PRINTF2(_L("aParser->GetFrameAvailability() expected videoAvailable returns True, actual %d"), videoAvailable);
  2237 			User::Leave(KErrGeneral);
  2238 			}
  2239 		if (videoErr != KErrNone)
  2240 			{
  2241 			SetTestStepError(videoErr);
  2242 			}
  2243 		else
  2244 			{
  2245 			User::LeaveIfError(CheckError(err, KErrNone, _L("aParser->GetNumberOfVideoFrames(num)")));
  2246 			}
  2247 		}
  2248 	}
  2249 
  2250 // -----------------------------------------------------------------------------
  2251 // Retrieve video frame size & start time without parsing the content file frame 
  2252 // by frame in file mode
  2253 // -----------------------------------------------------------------------------
  2254 //
  2255 C3GPLibParser_0033::C3GPLibParser_0033()
  2256 	{	
  2257 	}
  2258 
  2259 TVerdict C3GPLibParser_0033::doTestStepL()
  2260 	{
  2261 	if(TestStepResult() == EPass)
  2262 		{
  2263 		C3GPParse* parser = C3GPParse::NewL();
  2264 		CleanupStack::PushL(parser);
  2265 		
  2266 		TRAPD(err, VideoInfoL(parser));
  2267 		if (err != KErrNone)
  2268 			{
  2269 			SetTestStepResult(EFail);
  2270 			}
  2271 		
  2272 		CleanupStack::PopAndDestroy(parser);
  2273 		}
  2274 	return TestStepResult();
  2275 	}
  2276 
  2277 void C3GPLibParser_0033::VideoInfoL(C3GPParse* aParser)
  2278 	{
  2279 	// file mode
  2280 	ParserOpenFileL(aParser);
  2281 	
  2282 	TUint num; 
  2283 	TInt num1 = 0;
  2284 	TUint timeStampInMs = 0; 
  2285 	TUint timeStampInTimescale = 0; 
  2286 	TUint timeStampInMs1 = 0; 
  2287 	TUint timeStampInTimescale1 = 0; 
  2288 	TUint frameIndex;
  2289 	TUint frameSize;
  2290 	TBool keyFrame;
  2291 	User::LeaveIfError(aParser->GetNumberOfVideoFrames(num));
  2292 	
  2293 	RBuf8 buffer;
  2294 	CleanupClosePushL(buffer);
  2295 	buffer.CreateL(0);
  2296 	TInt err = aParser->ReadVideoFrame(buffer, keyFrame, timeStampInMs, timeStampInTimescale);
  2297 	if (err != KErrOverflow)
  2298 		{
  2299 		ERR_PRINTF2(_L("aParser->ReadVideoFrame() expected KErrOverflow, actual %d"), err);
  2300 		User::Leave(err);
  2301 		}
  2302 	User::LeaveIfError(aParser->GetVideoSampleEntryIndex(frameIndex));
  2303 	CleanupStack::PopAndDestroy(&buffer);
  2304 	
  2305 	
  2306 	err = KErrNone;
  2307 	while (err == KErrNone)
  2308 		{
  2309 		timeStampInMs = 0; 
  2310 		timeStampInTimescale = 0; 
  2311 		timeStampInMs1 = 0; 
  2312 		timeStampInTimescale1 = 0; 
  2313 
  2314 		if (num1 < num)
  2315 			{
  2316 			User::LeaveIfError(aParser->GetVideoFrameSize(num1, frameSize));
  2317 			User::LeaveIfError(aParser->GetVideoFrameStartTime(num1, timeStampInMs, timeStampInTimescale));
  2318 			}
  2319 		else
  2320 			{
  2321 			err = aParser->GetVideoFrameStartTime(num1, timeStampInMs, timeStampInTimescale);
  2322 			err = aParser->GetVideoFrameSize(num1, frameSize);
  2323 			}
  2324 		RBuf8 buffer1;
  2325 		CleanupClosePushL(buffer1);
  2326 		buffer1.CreateL(frameSize);
  2327 		err = aParser->ReadVideoFrame(buffer1, keyFrame, timeStampInMs1, timeStampInTimescale1);
  2328 		
  2329 		if (timeStampInMs != timeStampInMs1)
  2330 			{
  2331 			ERR_PRINTF3(_L("Two timestamps should be the same. timeStampInMs %d, timeStampInMs1 %d"), timeStampInMs, timeStampInMs1);
  2332 			User::Leave(KErrGeneral);
  2333 			}
  2334 		CleanupStack::PopAndDestroy(&buffer1);
  2335 		num1++;
  2336 		}
  2337 	
  2338 	if (err != KErrNotFound)
  2339 		{
  2340 		ERR_PRINTF2(_L("expected KErrNotFound when finishing reading video frames. Actual err %d"), err);
  2341 		User::Leave(KErrGeneral);
  2342 		}
  2343 	
  2344 	if ((num1 - 1) != num)
  2345 		{
  2346 		ERR_PRINTF3(_L("Two numOfFrame should be the same. num %d, num1 %d"), num, num1);
  2347 		User::Leave(KErrGeneral);
  2348 		}
  2349 	
  2350 	// use an invalid index to attempt retrieving video frame size & start time.  Both should failed with error.
  2351 	err = aParser->GetVideoFrameSize((num + 100), frameSize);
  2352 	User::LeaveIfError(CheckError(err, KErrGeneral, _L("GetVideoFrameSize")));
  2353 	
  2354 	err = aParser->GetVideoFrameStartTime((num + 5), timeStampInMs, timeStampInTimescale);
  2355 	User::LeaveIfError(CheckError(err, KErrGeneral, _L("GetVideoFrameStartTime")));
  2356 	
  2357 	ParserCompleteL(aParser);
  2358 	}
  2359 
  2360 // -----------------------------------------------------------------------------
  2361 // Retrieve video frame size & start time without parsing the content file frame 
  2362 // by frame in buffe mode
  2363 // -----------------------------------------------------------------------------
  2364 //
  2365 C3GPLibParser_0034::C3GPLibParser_0034()
  2366 	{	
  2367 	}
  2368 
  2369 TVerdict C3GPLibParser_0034::doTestStepL()
  2370 	{
  2371 	if(TestStepResult() == EPass)
  2372 		{
  2373 		C3GPParse* parser = C3GPParse::NewL();
  2374 		CleanupStack::PushL(parser);
  2375 		
  2376 		TRAPD(err, VideoInfoBufferModeL(parser));
  2377 		if (err != KErrNone)
  2378 			{
  2379 			SetTestStepResult(EFail);
  2380 			}
  2381 		
  2382 		CleanupStack::PopAndDestroy(parser);
  2383 		}
  2384 	return TestStepResult();
  2385 	}
  2386 
  2387 void C3GPLibParser_0034::VideoInfoBufferModeL(C3GPParse* aParser)
  2388 	{
  2389 	// buffer mode
  2390 	ParserOpenL(aParser);
  2391 	FileOpenL();
  2392 	
  2393 	TUint num; 
  2394 	TUint timeStampInMs = 0; 
  2395 	TUint timeStampInTimescale = 0; 
  2396 	TUint frameSize;
  2397 	
  2398 	// Insert 1K data into the library
  2399 	TInt pos = 0;
  2400 	TInt bufferSize = KBufferSize;
  2401 	InsertDataL(aParser, iSourceFile, bufferSize, pos);
  2402 	TInt err = aParser->GetNumberOfVideoFrames(num);
  2403 	if (err != KErrNone && err != KErrNotSupported && err != KErr3gpLibMoreDataRequired)
  2404 		{
  2405 		SetTestStepError(err);
  2406 		User::LeaveIfError(err);
  2407 		}
  2408 	
  2409 	while (err == KErr3gpLibMoreDataRequired )
  2410 		{
  2411 		pos = pos + bufferSize;
  2412 		InsertDataL(aParser, iSourceFile, bufferSize, pos);
  2413 		err = aParser->GetNumberOfVideoFrames(num);
  2414 		}
  2415 
  2416 	if (err != KErrNone)
  2417 		{
  2418 		SetTestStepError(err);
  2419 		}
  2420 	else 
  2421 		{
  2422 		for (TUint i = 0; i < num; i++)
  2423 			{
  2424 			User::LeaveIfError(aParser->GetVideoFrameSize(i, frameSize));
  2425 			User::LeaveIfError(aParser->GetVideoFrameStartTime(i, timeStampInMs, timeStampInTimescale));	
  2426 			}
  2427 		}
  2428 	
  2429 	ParserCompleteL(aParser);
  2430 	FileClose();
  2431 	}
  2432 
  2433 // -----------------------------------------------------------------------------
  2434 // Retrieve user atoms in all the possible locations 
  2435 // -----------------------------------------------------------------------------
  2436 //
  2437 C3GPLibParser_0035::C3GPLibParser_0035()
  2438 	{	
  2439 	}
  2440 
  2441 TVerdict C3GPLibParser_0035::doTestStepL()
  2442 	{
  2443 	if(TestStepResult() == EPass)
  2444 		{
  2445 		C3GPParse* parser = C3GPParse::NewL();
  2446 		CleanupStack::PushL(parser);
  2447 		
  2448 		TRAPD(err, GetUserDataAtomL(parser));
  2449 		if (err != KErrNone)
  2450 			{
  2451 			SetTestStepResult(EFail);
  2452 			}
  2453 		
  2454 		CleanupStack::PopAndDestroy(parser);
  2455 		}
  2456 	return TestStepResult();
  2457 	}
  2458 
  2459 void C3GPLibParser_0035::GetUserDataAtomL(C3GPParse* aParse)
  2460 	{
  2461 	// file mode
  2462 	ParserOpenFileL(aParse);
  2463 
  2464 	TUint32 udtType = 0x6d657461;  // The udt type of test files is 'meta'
  2465 	T3GPUdtaLocation location = E3GPUdtaAudioTrak;
  2466 	TUint indexMoov = 0;
  2467 	TUint indexAudio = 0;
  2468 	TUint indexVideo = 0;
  2469 	
  2470 	TInt err = CallUDTApi(aParse, udtType, indexAudio, location); 
  2471 	if (err == KErrNone)
  2472 		{
  2473 		location = E3GPUdtaMoov;
  2474 		err = CallUDTApi(aParse, udtType, indexMoov, location); 
  2475 		
  2476 		if (err == KErrNone)
  2477 			{
  2478 			// By default, the location is video track
  2479 			err = CallUDTApi(aParse, udtType, indexVideo); 
  2480 			}
  2481 		if (err == KErrNone)
  2482 			{
  2483 			// Test file KMultiUdta contains 1 udta at E3GPUdtaMoov, 5 udta at E3GPUdtaAudioTrak and 
  2484 			// 3 udta at E3GPUdtaVideoTrak			
  2485 			if (iTestSection.Compare(KMultiUdta) == 0 && (indexMoov != 0 || indexAudio != 4 || indexVideo != 2))
  2486 				{
  2487 				SetTestStepError(KErrNotFound);
  2488 				}
  2489 			}
  2490 		}
  2491 
  2492 	SetTestStepError(err);
  2493 	
  2494 	ParserCompleteL(aParse);
  2495 	}
  2496 
  2497 // -----------------------------------------------------------------------------
  2498 // Retrieve user atoms from a valid mp4/3gp file containing multiple entries of 
  2499 // the same user atom type within a user atom
  2500 // -----------------------------------------------------------------------------
  2501 //
  2502 C3GPLibParser_0036::C3GPLibParser_0036()
  2503 	{	
  2504 	}
  2505 
  2506 TVerdict C3GPLibParser_0036::doTestStepL()
  2507 	{
  2508 	if(TestStepResult() == EPass)
  2509 		{
  2510 		C3GPParse* parser = C3GPParse::NewL();
  2511 		CleanupStack::PushL(parser);
  2512 		
  2513 		TRAPD(err, GetUserDataAtomL(parser));
  2514 		if (err != KErrNone)
  2515 			{
  2516 			SetTestStepResult(EFail);
  2517 			}
  2518 		
  2519 		CleanupStack::PopAndDestroy(parser);
  2520 		}
  2521 	return TestStepResult();
  2522 	}
  2523 
  2524 void C3GPLibParser_0036::GetUserDataAtomL(C3GPParse* aParse)
  2525 	{
  2526 	// file mode
  2527 	ParserOpenFileL(aParse);
  2528 	
  2529 	TUint index;
  2530 	TUint32 udtType = 0x6d657461;  // The udt type of test files could be 'meta'
  2531 	T3GPUdtaLocation location = E3GPUdtaMoov; // The test files should not contain udta in audio trak
  2532 	
  2533 	// First read user data atom with empty buffer. It should return KErrOverflow
  2534 	RBuf8 buffer;	
  2535 	CleanupClosePushL(buffer);
  2536 	buffer.CreateL(0);	
  2537 	TInt err = aParse->GetUserDataAtom(udtType, location, buffer, index);
  2538 	buffer.Close();
  2539 	CleanupStack::PopAndDestroy(&buffer);
  2540 	
  2541 	if (err != KErrOverflow)
  2542 		{
  2543 		ERR_PRINTF2(_L("GetUserDataAtom with empty buffer should return KErrOverflow, failed with err %d"), err);
  2544 		User::Leave(err);
  2545 		}
  2546 	
  2547 	err = CallUDTApi(aParse, udtType, index); 	// By default, the location is videoTrack
  2548 	
  2549 	if (err == KErrNotFound || err == KErrNone)
  2550 		{
  2551 		err = CallUDTApi(aParse, udtType, index, location);
  2552 		
  2553 		if (err == KErrNotFound || err == KErrNone)
  2554 			{
  2555 			location = E3GPUdtaAudioTrak;
  2556 			err = CallUDTApi(aParse, udtType, index, location); 
  2557 			}
  2558 		}
  2559 
  2560 	SetTestStepError(err);
  2561 	
  2562 	ParserCompleteL(aParse);
  2563 	}
  2564 
  2565 // -----------------------------------------------------------------------------
  2566 // Retrieve video frame dependencies  
  2567 // -----------------------------------------------------------------------------
  2568 //
  2569 C3GPLibParser_0037::C3GPLibParser_0037()
  2570 	{	
  2571 	}
  2572 
  2573 TVerdict C3GPLibParser_0037::doTestStepL()
  2574 	{
  2575 	if(TestStepResult() == EPass)
  2576 		{
  2577 		C3GPParse* parser = C3GPParse::NewL();
  2578 		CleanupStack::PushL(parser);
  2579 		
  2580 		TRAPD(err, VideoDependencyL(parser));
  2581 		if (err != KErrNone)
  2582 			{
  2583 			SetTestStepResult(EFail);
  2584 			}
  2585 		
  2586 		CleanupStack::PopAndDestroy(parser);
  2587 		}
  2588 	return TestStepResult();
  2589 	}
  2590 
  2591 void C3GPLibParser_0037::VideoDependencyL(C3GPParse* aParser)
  2592 	{
  2593 	// file mode
  2594 	ParserOpenFileL(aParser);
  2595 	
  2596 	TUint num; 
  2597 	User::LeaveIfError(aParser->GetNumberOfVideoFrames(num));
  2598 	
  2599 	TInt err = KErrNone;
  2600 	T3GPFrameDependencies dependencies;
  2601 	for (TInt i = 0; i < num; i++)
  2602 		{
  2603 		err = aParser->GetVideoFrameDependencies(dependencies);
  2604 		if (err != KErrNone)
  2605 			{
  2606 			ERR_PRINTF2(_L("GetVideoFrameDependencies failed with %d"), err);
  2607 			SetTestStepError(err);
  2608 			break;
  2609 			}
  2610 		}
  2611 	ParserCompleteL(aParser);
  2612 	}
  2613 
  2614 // -----------------------------------------------------------------------------
  2615 // Get Video Frame Properties 
  2616 // -----------------------------------------------------------------------------
  2617 //
  2618 C3GPLibParser_0038::C3GPLibParser_0038()
  2619 	{	
  2620 	}
  2621 
  2622 TVerdict C3GPLibParser_0038::doTestStepL()
  2623 	{
  2624 	if(TestStepResult() == EPass)
  2625 		{
  2626 		C3GPParse* parser = C3GPParse::NewL();
  2627 		CleanupStack::PushL(parser);
  2628 		
  2629 		TRAPD(err, VideoInfoL(parser));
  2630 		if (err != KErrNone)
  2631 			{
  2632 			SetTestStepResult(EFail);
  2633 			}
  2634 		
  2635 		CleanupStack::PopAndDestroy(parser);
  2636 		}
  2637 	return TestStepResult();
  2638 	}
  2639 
  2640 void C3GPLibParser_0038::VideoInfoL(C3GPParse* aParser)
  2641 	{
  2642 	// file mode
  2643 	ParserOpenFileL(aParser);
  2644 	
  2645 	TUint num; 
  2646 	TUint timeStampInMs = 0; 
  2647 	TUint timeStampInTimescale = 0; 
  2648 	TUint frameIndex;
  2649 	TBool keyFrame;
  2650 	User::LeaveIfError(aParser->GetNumberOfVideoFrames(num));
  2651 	User::LeaveIfError(aParser->GetVideoSampleEntryIndex(frameIndex));
  2652 	
  2653 	TInt err = KErrNone;
  2654 	for (TInt i = 0; i < num; i++)
  2655 		{
  2656 		err = aParser->GetVideoFrameKeyType(i, keyFrame);
  2657 		User::LeaveIfError(CheckError(err, KErrNone, _L("GetVideoFrameKeyType()")));
  2658 		
  2659 		err = aParser->GetVideoFrameStartTime(i, timeStampInMs, timeStampInTimescale);
  2660 		User::LeaveIfError(CheckError(err, KErrNone, _L("GetVideoFrameStartTime()")));	
  2661 		}
  2662 	
  2663 	TUint startIndex = 0;
  2664 	RArray<T3GPFrameInfoParameters> array;
  2665 	CleanupClosePushL(array);
  2666 	
  2667 	err = aParser->GetVideoFrameProperties(startIndex, num, array);
  2668 	User::LeaveIfError(CheckError(err, KErrNone, _L("GetVideoFrameProperties")));
  2669 	if (!ShouldRunOOMTest())
  2670 		{
  2671 		INFO_PRINTF1(_L("aParser->GetVideoFrameProperties passed."));
  2672 		}
  2673 	
  2674 	RArray<T3GPFrameInfoParameters> array1;
  2675 	CleanupClosePushL(array1);
  2676 	
  2677 	// Filled in array with some data, say array with size 3
  2678 	TInt arraySize = 3;
  2679 	T3GPFrameInfoParameters fip;
  2680 	for (TInt i = 0; i < arraySize; i++)
  2681 		{
  2682 		fip.iSize = i;
  2683 		fip.iStartTime = 1000;
  2684 		fip.iIsRandomAccessPoint = ETrue;
  2685 		array1.AppendL(fip);
  2686 		}
  2687 	
  2688 	if (!ShouldRunOOMTest())
  2689 		{
  2690 		INFO_PRINTF1(_L("Filled in array with some junk data and call aParser->GetVideoFrameProperties() ago."));
  2691 		}
  2692 	
  2693 	err = aParser->GetVideoFrameProperties(startIndex, num, array1);
  2694 	User::LeaveIfError(CheckError(err, KErrNone, _L("GetVideoFrameProperties")));
  2695 	
  2696 	// Check two arrays are the same
  2697 	if (array.Count() != array1.Count())
  2698 		{
  2699 		ERR_PRINTF3(_L("array1.Count() is %d; expected array.Count() is %d."), array1.Count(), array.Count());
  2700 		User::Leave(KErrGeneral);
  2701 		}
  2702 	for (TInt j = 0; j < array.Count(); j++)
  2703 		{
  2704 		if (array1[j].iSize != array[j].iSize || array1[j].iStartTime != array1[j].iStartTime ||
  2705 				array1[j].iIsRandomAccessPoint != array1[j].iIsRandomAccessPoint)
  2706 			{
  2707 			ERR_PRINTF1(_L("Two array are not the same."));
  2708 			User::Leave(KErrGeneral);
  2709 			}
  2710 		}
  2711 	
  2712 	if (!ShouldRunOOMTest())
  2713 		{
  2714 		INFO_PRINTF1(_L("Two arrays are the same."));	
  2715 		}
  2716 	CleanupStack::PopAndDestroy(&array1);
  2717 	CleanupStack::PopAndDestroy(&array);
  2718 	
  2719 	ParserCompleteL(aParser);
  2720 	}
  2721 
  2722 // -----------------------------------------------------------------------------
  2723 // Read a audio and a video frame into a buffer of filled with junk content and 
  2724 // ensure the buffer gets properly reset when retrieve video / audio frame data.
  2725 // -----------------------------------------------------------------------------
  2726 //
  2727 C3GPLibParser_0039::C3GPLibParser_0039()
  2728 	{	
  2729 	}
  2730 
  2731 TVerdict C3GPLibParser_0039::doTestStepL()
  2732 	{
  2733 	if(TestStepResult() == EPass)
  2734 		{
  2735 		C3GPParse* parser = C3GPParse::NewL();
  2736 		CleanupStack::PushL(parser);
  2737 		
  2738 		TRAPD(err, AudioAndVideoFrameL(parser));
  2739 		if (err != KErrNone)
  2740 			{
  2741 			SetTestStepResult(EFail);
  2742 			}
  2743 		
  2744 		CleanupStack::PopAndDestroy(parser);
  2745 		}
  2746 	return TestStepResult();
  2747 	}
  2748 
  2749 void C3GPLibParser_0039::AudioAndVideoFrameL(C3GPParse* aParser)
  2750 	{
  2751 	// file mode
  2752 	ParserOpenFileL(aParser);
  2753 	
  2754 	TUint size;	
  2755 	TInt err = aParser->GetVideoFrameSize(size);
  2756 	User::LeaveIfError(CheckError(err, KErrNone, _L("GetVideoFrameSize")));
  2757 		
  2758 	RBuf8 buffer;
  2759 	CleanupClosePushL(buffer);
  2760 	buffer.CreateL(size + 15); // Create a buffer bigger than the size returned by GetVideoFrameSize
  2761 	// Filled in junk data into the buffer
  2762 	TChar c = 'a';
  2763 	buffer.AppendFill(c, (size + 15));
  2764 	
  2765 	TBool keyFrame;
  2766 	TUint timeStampInMs; 
  2767 	TUint timeStampInTimescale;
  2768 	err = aParser->ReadVideoFrame(buffer, keyFrame, timeStampInMs, timeStampInTimescale);
  2769 	User::LeaveIfError(CheckError(err, KErrNone, _L("ReadVideoFrame")));
  2770 	// Check the buffer size is the same as size returned by GetVideoFrameSize
  2771 	if (buffer.Length() != size)
  2772 		{
  2773 		ERR_PRINTF3(_L("buffer size is %d; expected size is %d."), buffer.Length(), size);
  2774 		User::Leave(KErrGeneral);
  2775 		}
  2776 	CleanupStack::PopAndDestroy(&buffer);
  2777 	
  2778 	err = aParser->GetAudioFramesSize(size);
  2779 	User::LeaveIfError(CheckError(err, KErrNone, _L("GetAudioFramesSize")));
  2780 			
  2781 	RBuf8 bufferBig;
  2782 	CleanupClosePushL(bufferBig);
  2783 	bufferBig.CreateL(size + 10); // Create a buffer bigger than the size returned by GetVideoFrameSize
  2784 	// Filled in junk data into the buffer
  2785 	bufferBig.AppendFill(c, (size + 10));
  2786 	
  2787 	TInt returnedFrames;
  2788 	err = aParser->ReadAudioFrames(bufferBig, returnedFrames, timeStampInMs, timeStampInTimescale);
  2789 	User::LeaveIfError(CheckError(err, KErrNone, _L("ReadAudioFrames")));
  2790 	// Check the buffer size is the same as size returned by GetVideoFrameSize
  2791 	if (bufferBig.Length() != size)
  2792 		{
  2793 		ERR_PRINTF3(_L("buffer size is %d; expected size is %d."), buffer.Length(), size);
  2794 		User::Leave(KErrGeneral);
  2795 		}
  2796 	
  2797 	CleanupStack::PopAndDestroy(&bufferBig);
  2798 	
  2799 	ParserCompleteL(aParser);
  2800 	}
  2801 
  2802 // -----------------------------------------------------------------------------
  2803 // Multiple parser working simultaneously. 
  2804 // -----------------------------------------------------------------------------
  2805 //
  2806 C3GPLibParser_0041::C3GPLibParser_0041()
  2807 	{
  2808 	}
  2809 
  2810 TVerdict C3GPLibParser_0041::doTestStepPreambleL()
  2811 	{
  2812 	// Add the names of the new files to the following file list array.
  2813 	TInt numOfFiles = 2; // This is the array number. Should be the same as the number of the array.
  2814 	const TText* SelectedFiles[] = 
  2815 		{
  2816 		_S("mpeg4-aac.3gp"), // File with both audio and video
  2817 		_S("arm-nb-acelp-only.3gp")  // File with audio only
  2818 		};
  2819 
  2820 	for (TInt index = 0; index < numOfFiles; index++)
  2821 		{
  2822 		// Create a zero terminated version of the file name
  2823 		TFileName inputFile(K3GPLibTestFilePath);
  2824 		inputFile += TPtrC(SelectedFiles[index]);
  2825 		inputFile.ZeroTerminate();
  2826 		
  2827 		if (index == 0)
  2828 			{
  2829 			User::LeaveIfError(iInputFile1.Create(inputFile.Length() + 1));
  2830 			iInputFile1.Copy(inputFile);	
  2831 			}
  2832 		else
  2833 			{
  2834 			User::LeaveIfError(iInputFile2.Create(inputFile.Length() + 1));
  2835 			iInputFile2.Copy(inputFile);	
  2836 			}
  2837 		}
  2838 	return TestStepResult();
  2839 	}
  2840 
  2841 TVerdict C3GPLibParser_0041::doTestStepPostambleL()
  2842 	{
  2843 	iInputFile1.Close();
  2844 	iInputFile2.Close();
  2845 	return TestStepResult();
  2846 	}
  2847 
  2848 TVerdict C3GPLibParser_0041::doTestStepL()
  2849 	{
  2850 	if(TestStepResult() == EPass)
  2851 		{
  2852 		C3GPParse* parser1 = C3GPParse::NewL();
  2853 		CleanupStack::PushL(parser1);
  2854 		
  2855 		TInt err = parser1->Open(iInputFile1);
  2856 		User::LeaveIfError(CheckError(err, KErrNone, _L("aParser1->Open")));
  2857 		
  2858 		C3GPParse* parser2 = C3GPParse::NewL();
  2859 		CleanupStack::PushL(parser2);
  2860 		
  2861 		err = parser2->Open(iInputFile1);
  2862 		User::LeaveIfError(CheckError(err, KErrNone, _L("aParser2->Open")));
  2863 		
  2864 		C3GPParse* parser3 = C3GPParse::NewL();
  2865 		CleanupStack::PushL(parser3);
  2866 		
  2867 		err = parser3->Open(iInputFile2);
  2868 		User::LeaveIfError(CheckError(err, KErrNone, _L("aParser3->Open")));
  2869 		
  2870 		TRAP(err, MultipleParserL(parser1, parser2, parser3));
  2871 		if (err != KErrNone)
  2872 			{
  2873 			SetTestStepResult(EFail);
  2874 			}
  2875 		
  2876 		ParserCompleteL(parser1);
  2877 		ParserCompleteL(parser2);
  2878 		ParserCompleteL(parser3);
  2879 		
  2880 		CleanupStack::PopAndDestroy(parser3);
  2881 		CleanupStack::PopAndDestroy(parser2);
  2882 		CleanupStack::PopAndDestroy(parser1);
  2883 		}
  2884 	return TestStepResult();
  2885 	}
  2886 
  2887 void C3GPLibParser_0041::MultipleParserL(C3GPParse* aParser1, C3GPParse* aParser2, C3GPParse* aParser3)
  2888 	{
  2889 	TInt err = ReadAudioVideoFrame(aParser1);
  2890 	User::LeaveIfError(CheckError(err, KErrNotFound, _L("ReadAudioVideoFrame(aParser1)")));
  2891 	
  2892 	// Read one video frame with parser2
  2893 	err = ReadAudioVideoFrame(aParser2, EFalse, EFalse);
  2894 	User::LeaveIfError(CheckError(err, KErrNone, _L("ReadAudioVideoFrame(aParser2)")));
  2895 	
  2896 	// Read video properties with parser3. Expected failed with KErrNotSupported
  2897 	T3GPVideoType videoType;
  2898 	TUint length; 
  2899 	TReal frameRate;
  2900 	TUint avgBitRate;
  2901 	TSize videoSize;
  2902 	TUint timeScale;
  2903 	
  2904 	err = aParser3->GetVideoProperties(videoType, length, frameRate, avgBitRate, videoSize, timeScale);
  2905 	User::LeaveIfError(CheckError(err, KErrNotSupported, _L("aParser3->GetVideoProperties")));
  2906 	}
  2907 
  2908 // -----------------------------------------------------------------------------
  2909 // Seek position in buffer mode
  2910 // -----------------------------------------------------------------------------
  2911 //
  2912 C3GPLibParser_0043::C3GPLibParser_0043()
  2913 	{
  2914 	}
  2915 
  2916 TVerdict C3GPLibParser_0043::doTestStepL()
  2917 	{
  2918 	if(TestStepResult() == EPass)
  2919 		{
  2920 		C3GPParse* parser = C3GPParse::NewL();
  2921 		CleanupStack::PushL(parser);
  2922 		
  2923 		TRAPD(err, SeekBufferModeL(parser));
  2924 		if (err != KErrNone)
  2925 			{
  2926 			SetTestStepResult(EFail);
  2927 			}
  2928 		
  2929 		CleanupStack::PopAndDestroy(parser);
  2930 		}
  2931 	return TestStepResult();
  2932 	}
  2933 
  2934 void C3GPLibParser_0043::SeekBufferModeL(C3GPParse* aParser)
  2935 	{
  2936 	// buffer mode
  2937 	ParserOpenL(aParser);
  2938 	FileOpenL();
  2939 	
  2940 	// Insert buffer data into the library
  2941 	TInt pos = 0;
  2942 	TInt bufferSize = KBufferSize;
  2943 	InsertDataL(aParser, iSourceFile, bufferSize, pos);
  2944 	
  2945 	TUint audioPos; 
  2946 	TUint videoPos;
  2947 	TUint timeStampInMs = 0; 
  2948 	
  2949 	// Seek the position
  2950 	TInt err = aParser->Seek(timeStampInMs, EFalse, audioPos, videoPos);
  2951 	while (err == KErr3gpLibMoreDataRequired)
  2952 		{
  2953 		pos = pos + bufferSize;
  2954 		InsertDataL(aParser, iSourceFile, bufferSize, pos);
  2955 		err = aParser->Seek(timeStampInMs, EFalse, audioPos, videoPos);
  2956 		}
  2957 	
  2958 	if (err != KErrNone)
  2959 		{
  2960 		SetTestStepError(err);
  2961 		}
  2962 	ParserCompleteL(aParser);
  2963 	FileClose();
  2964 	}
  2965 
  2966 // -----------------------------------------------------------------------------
  2967 // Test C3GPParse with large file (>2GB)
  2968 // -----------------------------------------------------------------------------
  2969 //
  2970 C3GPLibParser_0045::C3GPLibParser_0045()
  2971 	{
  2972 	}
  2973 
  2974 TVerdict C3GPLibParser_0045::doTestStepPreambleL()
  2975 	{
  2976 	C3GPLib_AsyncObserver::doTestStepPreambleL();	
  2977 	if (TestStepResult() == EPass)
  2978 		{
  2979 		iScheduler = new (ELeave) CActiveScheduler;
  2980 		CActiveScheduler::Install(iScheduler);
  2981 		}
  2982 	return TestStepResult();
  2983 	}
  2984 
  2985 TVerdict C3GPLibParser_0045::doTestStepPostambleL()
  2986 	{
  2987 	C3GPLib_AsyncObserver::doTestStepPostambleL();
  2988 	if( iScheduler )
  2989 		{
  2990 		INFO_PRINTF1(_L("delete iScheduler"));
  2991 		CActiveScheduler::Install(NULL);
  2992 		delete iScheduler;
  2993 		iScheduler = NULL;
  2994 		}
  2995 
  2996 	return TestStepResult();
  2997 	}
  2998 
  2999 TVerdict C3GPLibParser_0045::doTestStepL()
  3000 	{
  3001 	if(TestStepResult() == EPass)
  3002 		{
  3003 		C3GPParse* parser = C3GPParse::NewL();
  3004 		CleanupStack::PushL(parser);
  3005 		
  3006 		TRAPD(err, TestParserWithLargeFileL(parser));
  3007 		if (err != KErrNone)
  3008 			{
  3009 			SetTestStepResult(EFail);
  3010 			}
  3011 		
  3012 		CleanupStack::PopAndDestroy(parser);
  3013 		}
  3014 	return TestStepResult();
  3015 	}
  3016 
  3017 void C3GPLibParser_0045::TestParserWithLargeFileL(C3GPParse* aParser)
  3018 	{
  3019 	INFO_PRINTF1(_L("Test Parser With Large File (>2GB)"));
  3020 	INFO_PRINTF1(_L("Open and complete parser with 64 bit file handle"));
  3021 
  3022 	ParserOpenFileHandle64L(aParser);
  3023 	ParserCompleteHandle64L(aParser);
  3024 	
  3025 	ParserOpenFileHandle64L(aParser, EFileRead | EFileShareReadersOnly);
  3026 	ParserCompleteHandle64L(aParser);
  3027 	
  3028 	ParserOpenFileHandle64L(aParser, EFileShareReadersOrWriters | EFileWrite);
  3029 	ParserCompleteHandle64L(aParser);
  3030 	
  3031 	ParserOpenFileHandle64L(aParser, EFileShareReadersOrWriters | EFileRead);
  3032 	ParserCompleteHandle64L(aParser);
  3033 	
  3034 	ParserOpenFileHandle64L(aParser, EFileShareAny  | EFileWrite);
  3035 	ParserCompleteHandle64L(aParser);
  3036     
  3037 	ParserOpenFileHandle64L(aParser, EFileShareAny | EFileRead);
  3038 	ParserCompleteHandle64L(aParser);
  3039 
  3040 	INFO_PRINTF1(_L("Test parser with 64 bit file handle"));
  3041 
  3042 	// Read audio/video attributes
  3043 	ParserOpenFileHandle64L(aParser);
  3044 	DoGetVideoAudioAttributesL(aParser);
  3045 	ParserCompleteHandle64L(aParser);
  3046 
  3047 	// Read audio/video frames
  3048 	ParserOpenFileHandle64L(aParser);
  3049 	User::LeaveIfError(DoReadFrame(aParser));
  3050 	ParserCompleteHandle64L(aParser);
  3051 
  3052 	// Asynchronous Read of audio/video frames
  3053 	ParserOpenFileHandle64L(aParser);
  3054 	User::LeaveIfError(DoReadFrameAsync(aParser));
  3055 	if (!ShouldRunOOMTest())
  3056 		{
  3057 		INFO_PRINTF1(_L("C3GPLibParser_0045::ReadFrameAsyncL() using 64 bit file handle"));
  3058 		}
  3059 	ParserCompleteHandle64L(aParser);
  3060 	
  3061 	// Seek positions after any keyframe and immediately after a non-key frame
  3062 	ParserOpenFileHandle64L(aParser);
  3063 	DoSeekTestL(aParser);
  3064 	ParserCompleteHandle64L(aParser);	
  3065 
  3066 	INFO_PRINTF1(_L("Test parser in File path"));
  3067 
  3068 	// Read audio/video attributes
  3069 	ParserOpenFileL(aParser);
  3070 	DoGetVideoAudioAttributesL(aParser);
  3071 	ParserCompleteL(aParser);
  3072 	
  3073 	// Read audio/video frames
  3074 	ParserOpenFileL(aParser);
  3075 	User::LeaveIfError(DoReadFrame(aParser));
  3076 	ParserCompleteL(aParser);
  3077 	
  3078 	// Asynchronous Read of audio/video frames
  3079 	ParserOpenFileL(aParser);
  3080 	User::LeaveIfError(DoReadFrameAsync(aParser));
  3081 	if (!ShouldRunOOMTest())
  3082 		{
  3083 		INFO_PRINTF1(_L("C3GPLibParser_0014::ReadFrameAsyncL()"));
  3084 		}
  3085 	ParserCompleteL(aParser);
  3086 
  3087 	ParserOpenFileL(aParser);
  3088 	User::LeaveIfError(DoReadFrameAsync(aParser, ETrue));
  3089 	if (!ShouldRunOOMTest())
  3090 		{
  3091 		INFO_PRINTF1(_L("C3GPLibParser_0014::ReadFrameAsyncL(), then cancel the read"));
  3092 		}
  3093 	ParserCompleteL(aParser);
  3094 
  3095 	INFO_PRINTF1(_L("Test parser in CAF"));
  3096 	
  3097 	// Read audio/video attributes
  3098 	ParserOpenCafLC(aParser);
  3099 	DoGetVideoAudioAttributesL(aParser);
  3100 	ParserCompleteCafL(aParser);
  3101 		    
  3102 	// Read audio/video frames
  3103 	ParserOpenCafLC(aParser);
  3104 	User::LeaveIfError(DoReadFrame(aParser));
  3105 	ParserCompleteCafL(aParser);
  3106 	
  3107 	// Asynchronous Read of audio/video frames
  3108 	ParserOpenCafLC(aParser);
  3109 	User::LeaveIfError(DoReadFrameAsync(aParser));
  3110 	if (!ShouldRunOOMTest())
  3111 		{
  3112 		INFO_PRINTF1(_L("C3GPLibParser_0014::ReadFrameAsyncL() using CAF"));
  3113 		}
  3114 	ParserCompleteCafL(aParser);	
  3115 	}
  3116 
  3117 TInt C3GPLibParser_0045::DoReadFrameAsync(C3GPParse* aParser, TBool aCancel)
  3118 	{    
  3119     TInt err = KErrNone;
  3120     
  3121     if (!aCancel)
  3122     	{
  3123     	err = ReadAudioVideoFrameAsync(aParser, ETrue);
  3124     	if (err == KErrNone)
  3125     		{
  3126     		err = ReadAudioVideoFrameAsync(aParser, EFalse);
  3127     		} 
  3128     	}
  3129     else
  3130     	{
  3131     	err = ReadAudioVideoFrameAsync(aParser, EFalse, ETrue);
  3132     	}
  3133  
  3134     return err;
  3135     }
  3136 
  3137 // -----------------------------------------------------------------------------
  3138 // Parse video & audio frames from >2GB file synchronously in buffer mode
  3139 // -----------------------------------------------------------------------------
  3140 //
  3141 C3GPLibParser_0047::C3GPLibParser_0047()
  3142 	{	
  3143 	}
  3144 
  3145 TVerdict C3GPLibParser_0047::doTestStepL()
  3146 	{
  3147 	if(TestStepResult() == EPass)
  3148 		{
  3149 		C3GPParse* parser = C3GPParse::NewL();
  3150 		CleanupStack::PushL(parser);
  3151 		
  3152 		TRAPD(err, ReadFrameL(parser));
  3153 		if (err != KErrNone)
  3154 			{
  3155 			SetTestStepResult(EFail);
  3156 			}
  3157 		
  3158 		CleanupStack::PopAndDestroy(parser);
  3159 		}
  3160 	return TestStepResult();
  3161 	}
  3162 
  3163 void C3GPLibParser_0047::ReadFrameL(C3GPParse* aParser)
  3164 	{
  3165 	FileOpen64L();
  3166 	ReadFrameBufferModeL(aParser);
  3167 	FileClose64();
  3168 	}
  3169 	
  3170 // -----------------------------------------------------------------------------
  3171 // Retrieve User Data Atoms with Multiple atoms
  3172 // -----------------------------------------------------------------------------
  3173 //
  3174 _LIT(KAtomFileNamePrefix, "AtomFile");
  3175 
  3176 C3GPUserDataAtomRetrieval::C3GPUserDataAtomRetrieval()
  3177 	{		
  3178 	}
  3179 		
  3180 TVerdict C3GPUserDataAtomRetrieval::doTestStepL()
  3181 	{
  3182 	// ensure test step error & result reset before each test
  3183 	if (TestStepResult() != EPass)
  3184 		{
  3185 		return TestStepResult();
  3186 		}
  3187 	SetTestStepError(KErrNone);
  3188 		
  3189 	C3GPParse* parser = C3GPParse::NewL();
  3190 	CleanupStack::PushL(parser);
  3191 
  3192 	if (iLargeFile)
  3193 		{
  3194 		User::LeaveIfError(parser->Open(iInputFile64));		
  3195 		}
  3196 	else
  3197 		{
  3198 		User::LeaveIfError(parser->Open(iInputFile));		
  3199 		}
  3200 	
  3201 	TBool keepLooking = ETrue;
  3202 	TInt atomFound = 0;
  3203 	TInt atomSize = 0;
  3204 	TUint atomIndex = 0;
  3205 	TUint atomHighestIndex1 = 0;
  3206 	TUint atomHighestIndex2 = 0;
  3207 	TInt err = KErrNone;
  3208 	RFile atomFile;
  3209 	RBuf8 atomContent;
  3210 	RBuf8 fileContent;
  3211 	CleanupClosePushL(fileContent);	
  3212 	CleanupClosePushL(atomFile);
  3213 	CleanupClosePushL(atomContent);		
  3214 	
  3215 	while(keepLooking && err == KErrNone)
  3216 		{
  3217 		TInt atomIndexInput = atomIndex;
  3218 		err = parser->GetUserDataAtomSize(iAtomType, iAtomLocation, atomIndex, atomSize);
  3219 		if (err == KErrNone)
  3220 			{
  3221 			atomHighestIndex1 = atomIndex;
  3222 			atomIndex = atomIndexInput;
  3223 			atomContent.CreateL(atomSize);
  3224 			
  3225 			err = parser->GetUserDataAtom(iAtomType, iAtomLocation, atomContent, atomIndex);
  3226 			if (err == KErrNone)
  3227 				{
  3228 				if (atomFound == 0)
  3229 					{
  3230 					// remember the highest atom index found during first run
  3231 					atomHighestIndex2 = atomIndex;
  3232 					if (atomHighestIndex1 != atomHighestIndex2)
  3233 						{
  3234 						if (!ShouldRunOOMTest())
  3235 							{
  3236 							ERR_PRINTF1(_L("Highest Atom Index returned is different when calling GetUserDataAtomSize vs GetUserDataAtom"));							
  3237 							}
  3238 						}
  3239 					}
  3240 				atomFound++;
  3241 				
  3242 				User::LeaveIfError(atomFile.Open(iFs, (*iAtomFileArray)[atomIndexInput], EFileRead | EFileStream));
  3243 				TInt fileSize = 0;
  3244 				User::LeaveIfError(atomFile.Size(fileSize));
  3245 				if (atomContent.Size() != fileSize)
  3246 					{
  3247 					if (!ShouldRunOOMTest())
  3248 						{
  3249 						ERR_PRINTF4(_L("Atom %d retrieved is of different size as expected.  Expected=%d Retrieved=%d"), atomIndexInput, fileSize, atomContent.Size());							
  3250 						}
  3251 					SetTestStepResult(EFail);			
  3252 					keepLooking = EFalse;					
  3253 					}
  3254 				else
  3255 					{
  3256 					fileContent.CreateL(fileSize);
  3257 					User::LeaveIfError(atomFile.Read(fileContent));
  3258 					if (fileContent != atomContent)	
  3259 						{
  3260 						if (!ShouldRunOOMTest())
  3261 							{						
  3262 							ERR_PRINTF4(_L("Atom %d retrieved is of different content.  Expected=%S Retrieved=%S"), atomIndexInput, &fileContent, &atomContent);						
  3263 							}
  3264 						SetTestStepResult(EFail);			
  3265 						keepLooking = EFalse;
  3266 						}
  3267 					else
  3268 						{
  3269 						if (atomIndex != atomHighestIndex2)	
  3270 							{
  3271 							// seems like there's an error occurred, as the highest index for this atom
  3272 							// type should stay the same throughout
  3273 							keepLooking = EFalse;
  3274 							if (!ShouldRunOOMTest())
  3275 								{							
  3276 								ERR_PRINTF3(_L("Previous highest atom index is %d but now it is %d.  Data inconsistency."), atomHighestIndex2, atomIndex);
  3277 								}
  3278 							SetTestStepResult(EFail);
  3279 							}
  3280 						else
  3281 							{
  3282 							// look for the next atom of the same type now	
  3283 							atomIndex = atomIndexInput + 1;
  3284 							}	
  3285 						} 
  3286 					fileContent.Close();	
  3287 					}	
  3288 				atomFile.Close();	
  3289 				}
  3290 			else
  3291 				{
  3292 				if (!ShouldRunOOMTest())
  3293 					{				
  3294 					ERR_PRINTF4(_L("Fail to get user atom: index = %d, location = %d, type = %d"), atomIndex, iAtomLocation, iAtomType);
  3295 					}
  3296 				User::Leave(err);
  3297 				}	
  3298 				
  3299 			atomContent.Close();					
  3300 			}			
  3301 		}
  3302 	if (TestStepResult() == EPass && atomFound != iExpectedNumAtom && atomFound == (atomHighestIndex2 + 1))	
  3303 		{
  3304 		if (!ShouldRunOOMTest())
  3305 			{		
  3306 			ERR_PRINTF3(_L("Number of atoms found (%d) does not match expected # of atoms (%d)."), atomFound, iExpectedNumAtom);
  3307 			}
  3308 		SetTestStepResult(EFail);	
  3309 		}	
  3310 		
  3311 	CleanupStack::PopAndDestroy(&atomContent);
  3312 	CleanupStack::PopAndDestroy(&atomFile);
  3313 	CleanupStack::PopAndDestroy(&fileContent);
  3314 	
  3315 	parser->Complete();
  3316 		
  3317 	CleanupStack::PopAndDestroy(parser);				
  3318 	return TestStepResult();
  3319 	}
  3320 	
  3321 TVerdict C3GPUserDataAtomRetrieval::doTestStepPreambleL()
  3322 	{	
  3323 	SetTestStepResult(ETestSuiteError);					
  3324 
  3325  	#ifdef __WINSCW__
  3326  	_LIT(KFileToParse, "FileToParseEmu");
  3327  	#else
  3328  	_LIT(KFileToParse, "FileToParseHw");
  3329  	#endif		
  3330 	
  3331 	TPtrC inputFilename;
  3332 	if (!GetStringFromConfig(ConfigSection(), KFileToParse, inputFilename))
  3333 		{
  3334 		// file need to be specified
  3335 		ERR_PRINTF1(_L("Specify the file to be parsed."));
  3336 		return TestStepResult();
  3337 		}
  3338 	
  3339 	if (!GetBoolFromConfig(ConfigSection(), _L("largeFile"), iLargeFile))
  3340 		{
  3341 		ERR_PRINTF1(_L("Specify whether the file is larger than 2GB."));
  3342 		return TestStepResult();
  3343 		}
  3344 		
  3345 	User::LeaveIfError(iFs.Connect());			
  3346 	if (iLargeFile)
  3347 		{
  3348 		User::LeaveIfError(iInputFile64.Open(iFs, inputFilename, EFileRead | EFileStream | EFileShareReadersOnly));
  3349 		}
  3350 	else
  3351 		{
  3352 		User::LeaveIfError(iInputFile.Open(iFs, inputFilename, EFileRead | EFileStream | EFileShareReadersOnly));		
  3353 		}
  3354 	
  3355 	if (!GetIntFromConfig(ConfigSection(), _L("ExpectedNumOfAtom"), iExpectedNumAtom))
  3356 		{
  3357 		// Number of expected number of atoms needs to be specified
  3358 		ERR_PRINTF1(_L("Specify the number of atoms to be expected."));
  3359 		return TestStepResult();
  3360 		}
  3361 	
  3362 	iAtomFileArray = new CDesCArrayFlat(4);	
  3363 	TInt temp;
  3364 	if (!GetIntFromConfig(ConfigSection(), _L("AtomType"), temp))
  3365 		{
  3366 		// atom type to retrieve needs to be specified
  3367 		ERR_PRINTF1(_L("Specify the atoms type to be retrieved."));
  3368 		return TestStepResult();
  3369 		}
  3370 	else
  3371 		{
  3372 		iAtomType = (TUint32) temp;	
  3373 		}
  3374 		
  3375 	if (!GetIntFromConfig(ConfigSection(), _L("AtomLocation"), temp))		
  3376 		{
  3377 		// atom location to retrieve needs to be specified
  3378 		ERR_PRINTF1(_L("Specify the atoms location for the atoms to be retrieved."));
  3379 		return TestStepResult();
  3380 		}
  3381 	else
  3382 		{
  3383 		iAtomLocation = (T3GPUdtaLocation) temp;					
  3384 		}
  3385 
  3386 	if (iExpectedNumAtom > 0)
  3387 		{
  3388 		TBuf<50> keyName;	
  3389 		TPtrC fileName;		
  3390 		for (TInt i = 1; i <= iExpectedNumAtom; i++)	
  3391 			{
  3392 			keyName.Zero();
  3393 			keyName.AppendFormat(_L("%S%d"), &KAtomFileNamePrefix, i);			
  3394 
  3395 			if (!GetStringFromConfig(ConfigSection(), keyName, fileName))
  3396 				{
  3397 				// atom content file needs to be specified
  3398 				ERR_PRINTF1(_L("Specify the file name that contents the matching atom content."));
  3399 				return TestStepResult();					
  3400 				}
  3401 			
  3402 			iAtomFileArray->AppendL(fileName);
  3403 			}		
  3404 		}
  3405 		
  3406 	SetTestStepResult(EPass);							
  3407 	return TestStepResult();
  3408 	}
  3409 		
  3410 TVerdict C3GPUserDataAtomRetrieval::doTestStepPostambleL()
  3411 	{
  3412 	if (iAtomFileArray)
  3413 		{
  3414 		iAtomFileArray->Reset();
  3415 		delete iAtomFileArray;			
  3416 		}
  3417 	
  3418 	if (iLargeFile)
  3419 		{	
  3420 		iInputFile64.Close();		
  3421 		}
  3422 	else
  3423 		{
  3424 		iInputFile.Close();		
  3425 		}
  3426 	iFs.Close();
  3427 	
  3428 	return TestStepResult();
  3429 	}