os/mm/mmplugins/lib3gpunittest/src/tsu_3gplibrary_parse_compose.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 "tsu_3gplibrary_parse_compose.h"
    17 
    18 const TUint16 KAudioModeSet = 0x81ff;
    19 const TReal KMillisecondsInSecond = 1000;
    20 const TReal KOneHalf = 0.5;
    21 const TInt KLargeFileWriteBufferSize = 16384;  // 16K
    22 const TInt KLargeFileWriteBufferMaxCount = 15;
    23 
    24 _LIT( KAvcBaseline, "Baseline" );
    25 _LIT( KAvcMain, "Main" );
    26 _LIT( KAvcExtended, "Extended" );
    27 _LIT( KAvcHigh, "High" );
    28 
    29 const static TDesC* KAvcProfileNames[] = {
    30         &KAvcBaseline,
    31         &KAvcMain,
    32         &KAvcExtended,
    33         &KAvcHigh
    34     };
    35 
    36 
    37 C3GPLibParseComposeFile::C3GPLibParseComposeFile() :
    38 	iCompareOriginal(EFalse),
    39 	iLargeFile(EFalse)	
    40 	{
    41 	}
    42 
    43 TVerdict C3GPLibParseComposeFile::doTestStepPreambleL()
    44 	{
    45 	#ifdef __WINSCW__
    46 	_LIT(KInputDir, "inputDirEmul");
    47 	_LIT(KOutputDir, "outputDirEmul");
    48 	#else
    49 	_LIT(KInputDir, "inputDirHw");
    50 	_LIT(KOutputDir, "outputDirHw");
    51 	#endif
    52 	// ensure test always starts with clean results
    53 	SetTestStepResult(EPass);
    54 	SetTestStepError(KErrNone);
    55 	
    56 	// ensure there's always a Active Scheduler for the Composer
    57 	if (!CActiveScheduler::Current())
    58 		{
    59 		iScheduler = new (ELeave) CActiveScheduler;
    60 		CActiveScheduler::Install(iScheduler);	
    61 		}
    62 	
    63 	User::LeaveIfError(iFs.Connect());
    64 	// retrieve the input files' directory 
    65 	TPtrC inputFileDir;
    66 	TBool composeFile = EFalse;
    67 	TPtrC outputFileDir;					
    68 	if (GetStringFromConfig(ConfigSection(), KInputDir, inputFileDir))
    69 		{
    70 		if (inputFileDir.Length() == 0)
    71 			{
    72 			ERR_PRINTF1(_L("Ensure input directory is specified."));
    73 			SetTestStepResult(EInconclusive);			
    74 			return TestStepResult();
    75 			}
    76 		else 
    77 			{
    78 			iInputDir.CreateL(inputFileDir);
    79 			}
    80 		
    81 		GetIntFromConfig(ConfigSection(), _L("expectedFailure"), iExpectedNumberOfFailure);
    82 		
    83 		if (GetBoolFromConfig(ConfigSection(), _L("composeFile"), composeFile))
    84 			{
    85 			if (composeFile)
    86 				{
    87 				if (GetStringFromConfig(ConfigSection(), KOutputDir, outputFileDir))
    88 					{
    89 					if (outputFileDir.Length() == 0)
    90 						{
    91 						ERR_PRINTF1(_L("Ensure output directory is specified."));
    92 						SetTestStepResult(EInconclusive);			
    93 						return TestStepResult();
    94 						}
    95 					else if (outputFileDir == inputFileDir)
    96 						{
    97 						ERR_PRINTF1(_L("Ensure output directory is not the same as input directory."));
    98 						SetTestStepResult(EInconclusive);			
    99 						return TestStepResult();						
   100 						}
   101 					else if (!GetIntFromConfig(ConfigSection(), _L("fileFormat"), iFileFormat))
   102 						{
   103 						ERR_PRINTF1(_L("Ensure a output file format is specified."));
   104 						SetTestStepResult(EInconclusive);			
   105 						return TestStepResult();												
   106 						}
   107 					
   108 					GetIntFromConfig(ConfigSection(), _L("composeFlag"), iComposeFlag);
   109 					GetBoolFromConfig(ConfigSection(), _L("compareOriginal"), iCompareOriginal);
   110 					GetBoolFromConfig(ConfigSection(), _L("largeFile"), iLargeFile);					
   111 					}
   112 				else
   113 					{
   114 					ERR_PRINTF1(_L("Ensure output directory is specified."));
   115 					SetTestStepResult(EInconclusive);
   116 					}
   117 				}
   118 			}
   119 		}
   120 	else
   121 		{
   122 		ERR_PRINTF1(_L("Ensure input directory is specified."));
   123 		SetTestStepResult(EInconclusive);
   124 		}
   125 	
   126 	if (TestStepResult() == EPass)
   127 		{
   128 		// Create a list of all files contained in the input directory
   129 		User::LeaveIfError(iFs.GetDir(inputFileDir, KEntryAttNormal, ESortNone, iDirList));			
   130 		
   131 		if (!iDirList || iDirList->Count() == 0)
   132 			{
   133 			ERR_PRINTF1(_L("Input directory is empty."));
   134 			SetTestStepResult(EInconclusive);		
   135 			}
   136 		}
   137 	
   138 	if (TestStepResult() == EPass)
   139 		{
   140 		iParser = C3GPParse::NewL();
   141 		if (composeFile)
   142 			{
   143 			if (iLargeFile)
   144 				{
   145 				iComposer = C3GPCompose::NewL(KLargeFileWriteBufferSize, KLargeFileWriteBufferMaxCount);				
   146 				}
   147 			else
   148 				{
   149 				iComposer = C3GPCompose::NewL();				
   150 				}
   151 
   152 			iOutputDir.CreateL(outputFileDir);
   153 			TInt err = iFs.MkDirAll(iOutputDir);
   154 			if (err != KErrNone && err != KErrAlreadyExists)
   155 				{
   156 				User::Leave(err);
   157 				}
   158 			}
   159 		}
   160 	
   161 	return TestStepResult();
   162 	}		
   163 
   164 TVerdict C3GPLibParseComposeFile::doTestStepL()
   165 	{
   166 	if( TestStepResult() == EPass)
   167 		{
   168 		TInt failCount = 0;
   169 		TInt fileCount = 0;
   170 		RBuf filePath;
   171 		CleanupClosePushL(filePath);
   172 		filePath.CreateL(KMaxFileName);
   173 		
   174 		for (TInt i = 0; i < iDirList->Count(); i++)
   175 			{
   176 			const TEntry& entry = (*iDirList)[i];
   177 			if (!entry.IsDir())
   178 				{
   179 				fileCount++;
   180 				
   181 				filePath.Copy(iInputDir);
   182 				filePath.Append(entry.iName);
   183 				
   184 				INFO_PRINTF2(_L("ParseAndComposeL: file=%S"), &filePath);				
   185 				TRAPD(err, ParseFileL(filePath));
   186 				INFO_PRINTF2(_L("ParseAndComposeL returns: err = %d"), err);
   187 				if( err != KErrNone )
   188 					{
   189 					iParser->Complete();
   190 					if (iComposer)
   191 						{
   192 						iComposer->Complete();
   193 						}
   194 					failCount++;
   195 					}
   196 				else
   197 					{
   198 					if (iCompareOriginal && iComposer)
   199 						{
   200 						if (!CompareInputOuputFileL(filePath))
   201 							{
   202 							ERR_PRINTF1(_L("Input & output file is not the same"));
   203 							failCount ++;
   204 							}
   205 						else
   206 							{
   207 							INFO_PRINTF1(_L("Input & output file is the same."));
   208 							}
   209 						}
   210 					}				
   211 				}
   212 			}
   213 		
   214 		// clean up
   215 		CleanupStack::PopAndDestroy(&filePath);
   216 		
   217 		INFO_PRINTF3(_L("%d of %d files failed"), failCount, fileCount);
   218 		if (failCount != iExpectedNumberOfFailure)
   219 			{
   220 			ERR_PRINTF2(_L("Expected failure: %d - Test Failed"), iExpectedNumberOfFailure);
   221 			SetTestStepResult(EFail);
   222 			}		
   223 		}
   224 	
   225 	return TestStepResult();
   226 	}
   227 
   228 TVerdict C3GPLibParseComposeFile::doTestStepPostambleL()
   229 	{
   230 	if( iScheduler )
   231 		{
   232 		CActiveScheduler::Install(NULL);
   233 		delete iScheduler;
   234 		}
   235 	
   236 	iOutputDir.Close();
   237 	iInputDir.Close();
   238 	iComposedFile.Close();
   239 	
   240 	delete iDirList;
   241 	
   242 	iParsedFileHandle64.Close();
   243 	iComposedFileHandle64.Close();
   244 	iFs.Close();
   245 			
   246 	delete iParser;	
   247 	if (iComposer)
   248 		{
   249 		delete iComposer;
   250 		}	
   251 	
   252 	return TestStepResult();
   253 	}
   254 
   255 void C3GPLibParseComposeFile::ParseFileL(const TDesC& aInputFile)
   256 	{
   257 	ASSERT(iParser);
   258 	TInt err = 0;
   259 	
   260 	if (iLargeFile)
   261 		{
   262 		iParsedFileHandle64.Close();
   263 		err = iParsedFileHandle64.Open(iFs, aInputFile, EFileShareReadersOrWriters);
   264 		if (err == KErrNone)
   265 			{
   266 			err = iParser->Open(iParsedFileHandle64);		
   267 			}
   268 		}
   269 	else
   270 		{
   271 		err = iParser->Open(aInputFile);		
   272 		}
   273 	
   274 	if (err != KErrNone)
   275 		{
   276 		ERR_PRINTF2(_L("C3GPParse::Open() returns %d"), err);
   277 		User::Leave(err);
   278 		}
   279 	
   280 	//
   281 	// Retrieve Video Properties
   282 	//	
   283 	T3GPVideoPropertiesBase* videoProperties = NULL;
   284 	CleanupStack::PushL(videoProperties);
   285 	
   286 	RBuf8 videoDecoderSpecificInfo;
   287 	CleanupClosePushL(videoDecoderSpecificInfo);
   288 	
   289 	TUint videoLengthInMs = 0;
   290 		
   291 	err = ParseVideoProperties(*iParser, videoDecoderSpecificInfo, videoProperties, videoLengthInMs);
   292 	if (err != KErrNone && err != KErrNotSupported)
   293 		{
   294 		ERR_PRINTF2(_L("ParseVideoProperties failed: err = %d"), err);
   295 		User::Leave(err);
   296 		}
   297 	
   298 	//
   299 	// Retrieve Audio Properties
   300 	//
   301 	T3GPAudioPropertiesBase* audioProperties = NULL;
   302 	CleanupStack::PushL(audioProperties);	
   303 
   304 	RBuf8 audioDecoderSpecificInfo;
   305 	CleanupClosePushL(audioDecoderSpecificInfo);
   306 	
   307 	TUint audioLengthInMs = 0;
   308 	err = ParseAudioProperties(*iParser, audioDecoderSpecificInfo, audioProperties, audioLengthInMs);
   309 	if( err != KErrNone && err != KErrNotSupported)
   310 		{
   311 		ERR_PRINTF2(_L("ParseAudioProperties failed: err = %d"), err);		
   312 		User::Leave(err);
   313 		}
   314 
   315 	if (!videoProperties && !audioProperties)
   316 		{
   317 		ERR_PRINTF1(_L("File contains neither video nor audio data"));
   318 		User::Leave(KErrNotFound);		
   319 		}
   320 	
   321 	//
   322 	// Prepare for the Composer if file output is expected 
   323 	//	
   324 	if (iComposer)
   325 		{
   326 		RBuf outputFile;
   327 		CleanupClosePushL(outputFile);
   328 		
   329 		outputFile.CreateL(KMaxFileName);
   330 		outputFile.Copy(iOutputDir);
   331 		
   332 		TParsePtrC parsePtr(aInputFile);
   333 		TPtrC name = parsePtr.NameAndExt();
   334 				
   335 		outputFile.Append(parsePtr.NameAndExt());
   336 
   337 		if (iLargeFile)
   338 			{
   339 			iComposedFileHandle64.Close();
   340 			err = iComposedFileHandle64.Create(iFs, outputFile, EFileShareAny|EFileStream|EFileWrite);
   341 			if (err == KErrAlreadyExists)
   342 				{
   343 				err = iComposedFileHandle64.Replace(iFs, outputFile, EFileShareAny|EFileStream|EFileWrite);
   344 				}
   345 			
   346 			if (err == KErrNone)
   347 				{
   348 				err = iComposer->Open((T3GPFileFormatType)iFileFormat, videoProperties, audioProperties, iComposedFileHandle64, iComposeFlag);
   349 				}
   350 			}
   351 		else
   352 			{			
   353 			err = iComposer->Open((T3GPFileFormatType)iFileFormat, videoProperties, audioProperties, outputFile, iComposeFlag);
   354 			}
   355 				
   356 		if (err != KErrNone)
   357 			{
   358 			ERR_PRINTF2(_L("C3GPCompose::Open failed: err = %d"), err);		
   359 			User::Leave(err);			
   360 			}
   361 		
   362 		CleanupStack::PopAndDestroy(&outputFile);
   363 		}
   364 	
   365 	//
   366 	// Parse and compose (if specified) video / audio frame data 
   367 	//
   368 	ReadWriteAudioVideoFramesL(videoProperties, audioProperties, videoLengthInMs, audioLengthInMs);
   369 	
   370 	//
   371 	// Clean up
   372 	//
   373 	CleanupStack::PopAndDestroy(4);	 
   374 									// audioDecoderSpecificInfo
   375 									// audioProperties 
   376 									// videoDecoderSpecificInfo 
   377 									// videoProperties
   378 	
   379 	if (iComposer)
   380 		{
   381 		err = iComposer->Complete();
   382 		if (err != KErrNone)
   383 			{
   384 			ERR_PRINTF1(_L("aComposer->Complete() failed"));
   385 			User::Leave(err);
   386 			}
   387 			
   388 		if (iLargeFile)
   389 			{
   390 			iComposedFileHandle64.Close();
   391 			}
   392 		}
   393 	
   394 	err = iParser->Complete();
   395 	if (err != KErrNone)
   396 		{
   397 		ERR_PRINTF1(_L("aParser->Complete() failed"));
   398 		User::Leave(err);
   399 		}
   400 
   401 	if (iLargeFile)
   402 		{
   403 		iParsedFileHandle64.Close();
   404 		}
   405 	
   406 	INFO_PRINTF1(_L("C3GPLibParseComposeFile::ParseAndComposeL OUT"));		
   407 	}
   408 
   409 void C3GPLibParseComposeFile::ReadWriteAudioVideoFramesL(const T3GPVideoPropertiesBase* aVideoProperties, 
   410 														 const T3GPAudioPropertiesBase* aAudioProperties,
   411 														 TUint aVideoLengthInMs,
   412 														 TUint aAudioLengthInMs)
   413 	{
   414 	ASSERT(iParser);
   415 
   416 	TUint videoLengthInTS = 0;
   417 	TUint audioLengthInTS = 0;
   418 	if (aVideoProperties)
   419 		{
   420         // The "+KOneHalf" in the following calculation has the effect of rounding
   421         // to the nearest integer instead of just flooring it when converting from
   422         // TReal to TUint.
   423         // This is to avoid videoLengthInTS being off by one and leading to false
   424         // positives when the video properties are compared later on.
   425 		videoLengthInTS = (TUint) ((TReal)(aVideoLengthInMs * aVideoProperties->iTimescale) / KMillisecondsInSecond + KOneHalf );
   426 		}
   427 	if (aAudioProperties)
   428 		{
   429 		// The "+KOneHalf" in the following calculation has the effect of rounding
   430 		// to the nearest integer instead of just flooring it when converting from
   431 		// TReal to TUint.
   432 		// This is to avoid audioLengthInTS being off by one and leading to false
   433 		// positives when the audio properties are compared later on.
   434 		audioLengthInTS = (TUint) ((TReal)(aAudioLengthInMs * aAudioProperties->iTimescale) / KMillisecondsInSecond + KOneHalf );
   435 		}
   436 	
   437 	TInt framePerSample1 = 0;
   438 	TInt framePerSample2 = 0;
   439 	TUint audioTS1 = 0;
   440 	TUint audioTS2 = 0;
   441 	RBuf8 audioBuf1;	
   442 	RBuf8 audioBuf2;
   443 	CleanupClosePushL(audioBuf1);
   444 	CleanupClosePushL(audioBuf2);
   445 
   446 	TUint videoTS1;
   447 	TUint videoTS2;
   448 	TBool keyFrame1;
   449 	TBool keyFrame2;
   450 	T3GPFrameDependencies dep1;
   451 	T3GPFrameDependencies dep2;
   452 	RBuf8 videoBuf1;
   453 	RBuf8 videoBuf2;
   454 	CleanupClosePushL(videoBuf1);		
   455 	CleanupClosePushL(videoBuf2);	
   456 
   457 	TInt err = KErrNone;
   458 	T3GPFrameType frameType;
   459 	
   460 	RArray<T3GPFrameType> frameTypeArray(10);
   461 	CleanupClosePushL(frameTypeArray);
   462 	
   463 	TInt videoFrameCount = 0;
   464 	TInt audioFrameCount = 0;
   465 	
   466 	while (err == KErrNone)
   467 		{
   468 		err = iParser->GetFrameType(frameType);
   469 		if (err == KErrNone)
   470 			{		
   471 			switch(frameType)
   472 				{
   473 				case E3GPAudio:
   474 					audioFrameCount++;
   475 					frameTypeArray.AppendL(frameType);		
   476 					err = ReadAudioFrames(*iParser, audioBuf1, framePerSample1, audioTS1);
   477 					audioBuf1.Close();				
   478 					break;
   479 					
   480 				case E3GPVideo:
   481 					videoFrameCount++;
   482 					frameTypeArray.AppendL(frameType);
   483 					err = ReadVideoFrame(*iParser, videoBuf1, keyFrame1, videoTS1, dep1);
   484 					videoBuf1.Close();				
   485 					break;
   486 					
   487 				default:
   488 					ERR_PRINTF1(_L("GetFrameType retrieves an unsupported frame type"));
   489 					User::Leave(KErrUnknown);
   490 					break;
   491 				}
   492 			
   493 			// if there's anything wrong w/ retrieving the frame, exit the function now
   494 			User::LeaveIfError(err);
   495 			}
   496 		}
   497 	
   498 	INFO_PRINTF2(_L("ReadWriteAudioVideoFramesL read %d video frames."), videoFrameCount);
   499 	INFO_PRINTF2(_L("ReadWriteAudioVideoFramesL read %d audio frames."), audioFrameCount);
   500 		
   501 	// reset the video and audio cursor at the beginning of the clip 
   502 	TUint videoPos = 0;
   503 	TUint audioPos = 0;
   504 	iParser->Seek(0, EFalse, videoPos, audioPos);
   505 	
   506 	videoFrameCount = 0;
   507 	audioFrameCount = 0;
   508 	
   509 	if (iComposer)
   510 		{	
   511 		// if the data should be supplied into a composer to construct an output file
   512 		TInt index = 0;	
   513 		while (index < frameTypeArray.Count())
   514 			{
   515 			frameType = frameTypeArray[index++]; 
   516 			switch (frameType)
   517 				{
   518 				case E3GPAudio:
   519 					if (audioBuf1.Length() == 0)
   520 						{					
   521 						User::LeaveIfError(ReadAudioFrames(*iParser, audioBuf1, framePerSample1, audioTS1));
   522 						}
   523 					err = ReadAudioFrames(*iParser, audioBuf2, framePerSample2, audioTS2);
   524 					
   525 					if (audioBuf1.Length() > 0 && audioBuf2.Length() > 0 || 
   526 						audioBuf1.Length() > 0 && err == KErrNotFound)
   527 						{
   528 						TUint duration = 0;
   529 						if (audioBuf2.Length() == 0)
   530 							{
   531 							// duration for the last batch of audio frames = total audio length - the 2nd last audio frame
   532 							duration = audioLengthInTS - audioTS1;
   533 							}
   534 						else
   535 							{
   536 							duration = audioTS2 - audioTS1;			
   537 							}	
   538 							
   539 						User::LeaveIfError(iComposer->WriteAudioFrames(audioBuf1, duration));
   540 						audioFrameCount++;
   541 						
   542 						audioBuf1.Close();
   543 						audioBuf1.Swap(audioBuf2);
   544 						framePerSample1 = framePerSample2;
   545 						audioTS1 = audioTS2;
   546 						}
   547 					break;
   548 					
   549 				case E3GPVideo:
   550 					if (videoBuf1.Length() == 0)
   551 						{
   552 						User::LeaveIfError(ReadVideoFrame(*iParser, videoBuf1, keyFrame1, videoTS1, dep1));
   553 						}					
   554 					err = ReadVideoFrame(*iParser, videoBuf2, keyFrame2, videoTS2, dep2);
   555 					
   556 					if (videoBuf1.Length() > 0 && videoBuf2.Length() > 0 || 
   557 						videoBuf1.Length() > 0 && err == KErrNotFound)
   558 						{
   559 						TUint duration = 0;
   560 						if (videoBuf2.Length() == 0)
   561 							{
   562 							// duration for the last batch of audio frames = total audio length - the 2nd last audio frame
   563 							duration = videoLengthInTS - videoTS1;
   564 							}
   565 						else
   566 							{
   567 							duration = videoTS2 - videoTS1;			
   568 							}	
   569 							
   570 						User::LeaveIfError(iComposer->WriteVideoFrame(videoBuf1, duration, keyFrame1, dep1));
   571 						videoFrameCount++;
   572 						
   573 						videoBuf1.Close();
   574 						videoBuf1.Swap(videoBuf2);
   575 						keyFrame1 = keyFrame2;
   576 						videoTS1 = videoTS2;
   577 						dep1.iDependsOn = dep2.iDependsOn;
   578 						dep1.iIsDependedOn = dep2.iIsDependedOn;
   579 						dep1.iHasRedundancy = dep2.iHasRedundancy;		
   580 						}
   581 					break;
   582 					
   583 				default:
   584 					ERR_PRINTF1(_L("Unknown frame type detected."));
   585 					User::Leave(KErrUnknown);
   586 					break;
   587 				}
   588 			}	// end of while loop
   589 		}	// if (iComposer)
   590 	
   591 	CleanupStack::PopAndDestroy(5);
   592 	
   593 	INFO_PRINTF2(_L("ReadWriteAudioVideoFramesL wrote %d video frames."), videoFrameCount);
   594 	INFO_PRINTF2(_L("ReadWriteAudioVideoFramesL wrote %d audio frames."), audioFrameCount);	
   595 	}
   596 
   597 TInt C3GPLibParseComposeFile::GetAudioDecoderSpecificInfo(RBuf8& aBuffer)
   598 	{
   599 	ASSERT(iParser);
   600 	
   601 	TInt size;
   602 	TInt err = iParser->GetAudioDecoderSpecificInfoSize(size);
   603 	if( err != KErrNone )
   604 		{
   605 		ERR_PRINTF2(_L("GetAudioDecoderSpecificInfoSize() failed: %d"), err);
   606 		return err;
   607 		}
   608 
   609 	err = aBuffer.Create(size);
   610 	if( err != KErrNone )
   611 		{
   612 		ERR_PRINTF1(_L("Create buffer failed"));
   613 		return err;
   614 		}
   615 
   616 	err = iParser->GetAudioDecoderSpecificInfo(aBuffer);
   617 	if( err != KErrNone )
   618 		{
   619 		ERR_PRINTF2(_L("GetAudioDecoderSpecificInfo() failed: %d"), err);
   620 		}
   621 	
   622 	return err;
   623 	}
   624 
   625 TInt C3GPLibParseComposeFile::ParseVideoProperties(C3GPParse& aParser,
   626 												   RBuf8& aDecoderSpecificInfo,
   627 												   T3GPVideoPropertiesBase*& aProperties,
   628 												   TUint& aLengthInMs) 
   629 	{
   630 	ASSERT(iParser);
   631 	
   632 	T3GPVideoType type; 
   633 	TReal frameRate;
   634 	TUint avgBitRate;
   635 	TSize size;
   636 	TUint timeScale;	
   637 	
   638 	TInt err = aParser.GetVideoProperties(type, aLengthInMs, frameRate, avgBitRate, size, timeScale);
   639 	if ((err != KErrNone) && (err != KErrNotSupported))
   640 		{
   641 		ERR_PRINTF2(_L("aParser->GetVideoProperties failed: %d"), err);
   642 		return err;
   643 		}
   644 
   645 	switch(type)
   646 		{
   647 		case E3GPMpeg4Video:
   648 			{
   649 			INFO_PRINTF1(_L("Video Type: Mpeg4"));			
   650 			err = GetVideoDecoderSpecificInfo(aDecoderSpecificInfo);		
   651 			if (err == KErrNone)
   652 				{
   653 				aProperties = new T3GPVideoPropertiesMpeg4Video(timeScale, size,
   654 						64000, avgBitRate, aDecoderSpecificInfo);
   655 				if (!aProperties)
   656 					{
   657 					ERR_PRINTF1(_L("T3GPVideoPropertiesMpeg4Video allocation failed"));
   658 					err = KErrNoMemory;
   659 					}
   660 				}
   661 			break;			
   662 			}
   663 		
   664 		case E3GPAvcProfileBaseline:
   665 		case E3GPAvcProfileMain:
   666 		case E3GPAvcProfileExtended:
   667 		case E3GPAvcProfileHigh:
   668 			{
   669 			err = GetVideoDecoderSpecificInfo(aDecoderSpecificInfo);
   670 			if (err == KErrNone)
   671 				{
   672 				INFO_PRINTF2(_L("Video Type: Avc Profile %S"), KAvcProfileNames[type-E3GPAvcProfileBaseline] );
   673 				aProperties = new T3GPVideoPropertiesAvc(timeScale, size, aDecoderSpecificInfo);
   674 				if (!aProperties)
   675 					{
   676 					ERR_PRINTF1(_L("T3GPVideoPropertiesAvc allocation failed"));
   677 					err = KErrNoMemory;
   678 					}
   679                 else
   680                     {
   681                     // T3GPVideoPropertiesAvc defaults the video type to AVC baseline profile.
   682                     // Need to override that here because we want to check for the specific
   683                     // profile in this test.
   684                     aProperties->iType = type;
   685                     }
   686 				}
   687 			break;
   688 			}
   689 			
   690 		case E3GPH263Profile0:
   691 		case E3GPH263Profile3:
   692 			{
   693 			INFO_PRINTF1(_L("Video Type: H263"));			
   694 			T3GPVideoPropertiesH263::TProfile profile = T3GPVideoPropertiesH263::EProfile0;
   695 			if (type == E3GPH263Profile3)
   696 				{
   697 				profile = T3GPVideoPropertiesH263::EProfile3;
   698 				}
   699 			
   700 			TInt videoLevel;
   701 			err = iParser->GetH263VideoLevel(videoLevel);
   702 			if( err != KErrNone )
   703 				{
   704 				ERR_PRINTF1(_L("aParser->GetH263VideoLevel() failed"));
   705 				}
   706 			else
   707 				{			
   708 				aProperties = new T3GPVideoPropertiesH263(timeScale, size, videoLevel, profile);
   709 				if( !aProperties )
   710 					{
   711 					ERR_PRINTF1(_L("T3GPVideoPropertiesH263 allocation failed"));
   712 					err = KErrNoMemory;
   713 					}
   714 				}
   715 			break;			
   716 			}
   717 		
   718 		case E3GPNoVideo:
   719 			INFO_PRINTF1(_L("Video Type: None"));
   720 			break;
   721 			
   722 		default:
   723 			err = KErrNotSupported;
   724 			break;
   725 		}
   726 	
   727 	return err;
   728 	}
   729 
   730 TInt C3GPLibParseComposeFile::GetVideoDecoderSpecificInfo(RBuf8& aBuffer)
   731 	{	
   732 	TInt size;
   733 	TInt err = iParser->GetVideoDecoderSpecificInfoSize(size);
   734 	if (err != KErrNone)
   735 		{
   736 		ERR_PRINTF1(_L("GetVideoDecoderSpecificInfoSize() failed"));
   737 		return err;
   738 		}
   739 	
   740 	err = aBuffer.Create(size);
   741 	if (err != KErrNone)
   742 		{
   743 		ERR_PRINTF1(_L("Create buffer failed"));
   744 		return err;
   745 		}
   746 
   747 	err = iParser->GetVideoDecoderSpecificInfo(aBuffer);
   748 	if( err != KErrNone )
   749 		{
   750 		ERR_PRINTF1(_L("GetVideoDecoderSpecificInfo() failed"));
   751 		}
   752 	
   753 	return err;
   754 	}
   755 
   756 TInt C3GPLibParseComposeFile::ParseAudioProperties(C3GPParse& aParser, 
   757 												   RBuf8& aAudioDecoderSpecificInfo,
   758 												   T3GPAudioPropertiesBase*& aAudioProperties,
   759 												   TUint& aLength)
   760 	{
   761 	
   762 	ASSERT(iParser);
   763 	
   764 	T3GPAudioType type; 
   765 	TInt audioFPS; 
   766 	TUint audioAvgBitRate; 
   767 	TUint timeScale;	
   768 	
   769 	TInt err = aParser.GetAudioProperties(type, aLength, audioFPS, audioAvgBitRate, timeScale);
   770 	if(( err != KErrNone ) && ( err != KErrNotSupported ))
   771 		{
   772 		ERR_PRINTF2(_L("GetAudioProperties() failed: %d"), err);
   773 		return err;
   774 		}
   775 
   776 	switch(type)
   777 		{
   778 		case E3GPMpeg4Audio:
   779 			{
   780 			INFO_PRINTF1(_L("Audio Type: Mpeg4"));
   781 			err = GetAudioDecoderSpecificInfo(aAudioDecoderSpecificInfo);
   782 			if (err == KErrNone)
   783 				{
   784 				aAudioProperties = new T3GPAudioPropertiesMpeg4Audio(timeScale, aAudioDecoderSpecificInfo);
   785 				if( !aAudioProperties )
   786 					{
   787 					ERR_PRINTF1(_L("T3GPAudioPropertiesMpeg4Audio allocation failed"));
   788 					err = KErrNoMemory;
   789 					}
   790 				}
   791 			break;
   792 			}
   793 			
   794 		case E3GPQcelp13K:
   795 			{
   796 			INFO_PRINTF1(_L("Audio Type: Qcelp13K"));
   797 			T3GPQcelpStorageMode mode;
   798 			err = iParser->GetQcelpStorageMode(mode);
   799 			if (err != KErrNone)
   800 				{
   801 				ERR_PRINTF1(_L("GetQcelpStorageMode failed"));
   802 				}
   803 			else 
   804 				{
   805 				if( mode == E3GPMP4AudioDescriptionBox)
   806 					{
   807 					err = GetAudioDecoderSpecificInfo(aAudioDecoderSpecificInfo);
   808 					aAudioProperties = new T3GPAudioPropertiesQcelp(timeScale, audioFPS, aAudioDecoderSpecificInfo);
   809 					}
   810 				else
   811 					{
   812 					aAudioProperties = new T3GPAudioPropertiesQcelp(timeScale, audioFPS);
   813 					}
   814 				
   815 				if( !aAudioProperties )
   816 					{
   817 					ERR_PRINTF1(_L("T3GPAudioPropertiesQcelp allocation failed"));
   818 					err = KErrNoMemory;
   819 					}
   820 				}
   821 			break;
   822 			}
   823 			
   824 		case E3GPAmrNB:
   825 			{
   826 			INFO_PRINTF1(_L("Audio Type: AMR NB"));
   827 			aAudioProperties = new T3GPAudioPropertiesAmr(timeScale, audioFPS, KAudioModeSet, T3GPAudioPropertiesAmr::EAmrNB);
   828 			if( !aAudioProperties )
   829 				{
   830 				ERR_PRINTF1(_L("T3GPAudioPropertiesAmr allocation failed"));
   831 				err = KErrNoMemory;
   832 				}
   833 			break;
   834 			}
   835 			
   836 		case E3GPAmrWB:
   837 			{
   838 			INFO_PRINTF1(_L("Audio Type: AMR WB"));
   839 			aAudioProperties = new T3GPAudioPropertiesAmr(timeScale, audioFPS, KAudioModeSet, T3GPAudioPropertiesAmr::EAmrWB);
   840 			if( !aAudioProperties )
   841 				{
   842 				ERR_PRINTF1(_L("T3GPAudioPropertiesAmr allocation failed"));
   843 				err = KErrNoMemory;
   844 				}
   845 			break;
   846 			}
   847 			
   848 		case E3GPNoAudio:
   849 			INFO_PRINTF1(_L("Audio Type: None"));			
   850 			break;
   851 			
   852 		default:
   853 			INFO_PRINTF1(_L("Audio Type: Unrecognized!"));
   854 			err = KErrNotSupported;
   855 			break;
   856 		}
   857 	
   858 	return err;
   859 	}
   860 
   861 TInt C3GPLibParseComposeFile::ReadVideoFrame(C3GPParse& aParser,
   862 											 RBuf8& aVideoBuffer, 
   863 											 TBool& aVideoKeyFrame, 
   864 											 TUint& aVideoTimestampInTS, 
   865 											 T3GPFrameDependencies& aDependencies)
   866 	{
   867 	ASSERT(iParser);
   868 	
   869 	// flush all data in the buffer
   870 	aVideoBuffer.Close();
   871 	
   872 	TInt err = aParser.GetVideoFrameDependencies(aDependencies);
   873 	if (err != KErrNone)
   874 		{
   875 		aDependencies.iDependsOn = E3GPDependencyUnknown;
   876 		aDependencies.iIsDependedOn = E3GPDependencyUnknown;
   877 		aDependencies.iHasRedundancy = E3GPRedundancyUnknown;
   878 		}
   879 	
   880 	TUint frameSize = 0;
   881 	err = aParser.GetVideoFrameSize(frameSize);
   882 	if (err == KErrNone)
   883 		{
   884 		if (frameSize > KMaxTInt / 2)
   885 			{
   886 			ERR_PRINTF1(_L("Video Frame too large!"));
   887 			err = KErrOverflow;
   888 			}
   889 		else
   890 			{
   891 			err = aVideoBuffer.Create((TInt)frameSize);
   892 			if (err == KErrNone)
   893 				{
   894 				TUint videoTimestampMS = 0;
   895 				err = aParser.ReadVideoFrame(aVideoBuffer, aVideoKeyFrame, videoTimestampMS, aVideoTimestampInTS);				
   896 				if (err == KErrNone)
   897 					{
   898 					if (err == KErrNotSupported)
   899 						{
   900 						// Not supported error is OK
   901 						err = KErrNone;
   902 						}
   903 					else if (err != KErrNone)
   904 						{
   905 						ERR_PRINTF2(_L("GetVideoFrameDependencies failed with err = %d"), err);					
   906 						}
   907 					}
   908 				else
   909 					{
   910 					ERR_PRINTF2(_L("ReadVideoFrame failed with err = %d"), err);					
   911 					}
   912 				}
   913 			}
   914 		}
   915 	else
   916 		{
   917 		ERR_PRINTF2(_L("GetVideoFrameSize fails with %d"), err);		
   918 		}
   919 	
   920 	return err;	
   921 	}
   922 
   923 TInt C3GPLibParseComposeFile::ReadAudioFrames(C3GPParse& aParser, 
   924 											  RBuf8& aBuffer, 
   925 											  TInt& aFramesInSample, 
   926 											  TUint& aTimestampInTS)
   927 	{
   928 	// flush all existing data
   929 	aBuffer.Close();
   930 	
   931 	TUint size = 0;
   932 	TInt err = aParser.GetAudioFramesSize(size);
   933 	if (err == KErrNone)
   934 		{
   935 		if (size > KMaxTInt / 2)	
   936 			{
   937 			// cannot create RBuf of size > KMaxTInt / 2 
   938 			ERR_PRINTF1(_L("Audio Frames too large!"));
   939 			err = KErrOverflow;
   940 			}
   941 		else
   942 			{
   943 			err = aBuffer.Create((TInt)size);
   944 			if (err == KErrNone)
   945 				{
   946 				TUint audioTimestampMS = 0;
   947 				err = aParser.ReadAudioFrames(aBuffer, aFramesInSample, audioTimestampMS, aTimestampInTS);
   948 				if (err != KErrNone)
   949 					{
   950 					ERR_PRINTF2(_L("ReadAudioFrames failed with err = %d"), err);							
   951 					}
   952 				}
   953 			}
   954 		}
   955 	else
   956 		{
   957 		ERR_PRINTF2(_L("GetAudioFramesSize failed with err = %d"), err);		
   958 		}
   959 	
   960 	return err;
   961 	}
   962 
   963 TBool C3GPLibParseComposeFile::CompareInputOuputFileL(const TDesC& aInputFile)
   964 	{
   965 	ASSERT(iParser);
   966 	TInt err = 0;
   967 
   968 	if (iLargeFile)
   969 		{
   970 		iParsedFileHandle64.Close();
   971 		err = iParsedFileHandle64.Open(iFs, aInputFile, EFileShareReadersOrWriters);
   972 		if (err == KErrNone)
   973 			{
   974 			err = iParser->Open(iParsedFileHandle64);		
   975 			}
   976 		}
   977 	else
   978 		{
   979 		err = iParser->Open(aInputFile);		
   980 		}
   981 
   982 	if (err != KErrNone)
   983 		{
   984 		ERR_PRINTF2(_L("C3GPParse 1 Open() returns %d"), err);
   985 		User::Leave(err);
   986 		}
   987 	
   988 	RBuf outputFile;
   989 	CleanupClosePushL(outputFile);
   990 	
   991 	outputFile.CreateL(KMaxFileName);
   992 	outputFile.Copy(iOutputDir);
   993 	
   994 	TParsePtrC parsePtr(aInputFile);
   995 	TPtrC name = parsePtr.NameAndExt();	
   996 	outputFile.Append(parsePtr.NameAndExt());
   997 
   998 	C3GPParse* parser2 = C3GPParse::NewL();
   999 	CleanupStack::PushL(parser2);
  1000 
  1001 	RFile64 file2;
  1002 	if (iLargeFile)
  1003 		{
  1004 		err = file2.Open(iFs, outputFile, EFileShareReadersOrWriters);
  1005 		if (err == KErrNone)
  1006 			{
  1007 			err = parser2->Open(file2);		
  1008 			}
  1009 		}
  1010 	else
  1011 		{
  1012 		err = parser2->Open(outputFile);		
  1013 		}
  1014 		
  1015 	if (err != KErrNone)
  1016 		{
  1017 		ERR_PRINTF2(_L("C3GPParse 2 Open() returns %d"), err);
  1018 		User::Leave(err);
  1019 		}
  1020 	
  1021 	TBool result = EFalse;	
  1022 	if (CompareVideoPropertiesL(*iParser, *parser2))
  1023 		{
  1024 		if (CompareAudioPropertiesL(*iParser, *parser2))
  1025 			{
  1026 			if (CompareAudioVideoData(*iParser, *parser2))
  1027 				{
  1028 				result = ETrue;
  1029 				}			
  1030 			else
  1031 				{
  1032 				ERR_PRINTF1(_L("Audio/Video Data not matching"));
  1033 				}					
  1034 			}
  1035 		else
  1036 			{
  1037 			ERR_PRINTF1(_L("Audio Properites not matching"));
  1038 			}		
  1039 		}
  1040 	else
  1041 		{
  1042 		ERR_PRINTF1(_L("Video Properites not matching"));
  1043 		}
  1044 	
  1045 	parser2->Complete();
  1046 	iParser->Complete();
  1047 	
  1048 	if (iLargeFile)
  1049 		{
  1050 		file2.Close();
  1051 		iParsedFileHandle64.Close();
  1052 		}
  1053 	
  1054 	CleanupStack::PopAndDestroy(2);		// outputFile, parser2
  1055 	
  1056 	return result;
  1057 	}
  1058 
  1059 TBool C3GPLibParseComposeFile::CompareVideoPropertiesL(C3GPParse& aParser1, 
  1060 													   C3GPParse& aParser2)
  1061 	{
  1062 	//
  1063 	// Retrieve Video Properties from Parser 1
  1064 	//	
  1065 	T3GPVideoPropertiesBase* videoProperties1 = NULL;
  1066 	CleanupStack::PushL(videoProperties1);
  1067 	
  1068 	RBuf8 videoDecoderSpecificInfo1;
  1069 	CleanupClosePushL(videoDecoderSpecificInfo1);
  1070 	
  1071 	TUint videoLengthInMs1 = 0;
  1072 		
  1073 	TInt err1 = ParseVideoProperties(aParser1, videoDecoderSpecificInfo1, videoProperties1, videoLengthInMs1);
  1074 	if (err1 != KErrNone && err1 != KErrNotSupported)
  1075 		{
  1076 		ERR_PRINTF2(_L("ParseVideoProperties 1 failed: err = %d"), err1);
  1077 		User::Leave(err1);
  1078 		}
  1079 	
  1080 	//
  1081 	// Retrieve Video Properties from Parser 2
  1082 	//	
  1083 	T3GPVideoPropertiesBase* videoProperties2 = NULL;
  1084 	CleanupStack::PushL(videoProperties2);
  1085 	
  1086 	RBuf8 videoDecoderSpecificInfo2;
  1087 	CleanupClosePushL(videoDecoderSpecificInfo2);
  1088 	
  1089 	TUint videoLengthInMs2 = 0;
  1090 		
  1091 	TInt err2 = ParseVideoProperties(aParser2, videoDecoderSpecificInfo2, videoProperties2, videoLengthInMs2);
  1092 	if (err2 != KErrNone && err2 != KErrNotSupported)
  1093 		{
  1094 		ERR_PRINTF2(_L("ParseVideoProperties 2 failed: err = %d"), err2);
  1095 		User::Leave(err2);
  1096 		}
  1097 
  1098 	TBool result = EFalse;
  1099 	if (err1 == err2 && err1 != KErrNotSupported)
  1100 		{
  1101 		if (videoLengthInMs1 == videoLengthInMs2)
  1102 			{
  1103 			if (videoProperties1 && videoProperties2)
  1104 				{
  1105 				result = (videoProperties1->iType == videoProperties2->iType) &&
  1106 						 (videoProperties1->iSize == videoProperties2->iSize) &&
  1107 						 (videoProperties1->iTimescale == videoProperties2->iTimescale);
  1108 					
  1109 				if (result)
  1110 					{
  1111 					switch(videoProperties1->iType)
  1112 						{
  1113 						case E3GPMpeg4Video:
  1114 							{
  1115 							T3GPVideoPropertiesMpeg4Video* video1 = (T3GPVideoPropertiesMpeg4Video*)videoProperties1;
  1116 							T3GPVideoPropertiesMpeg4Video* video2 = (T3GPVideoPropertiesMpeg4Video*)videoProperties2;
  1117 							
  1118 							// NOTE: Comparison of the avg bit rate is omitted.  The reason is that the avg. bit 
  1119 							//       rate is calculated by: 
  1120 							//       video avg bit rate = stream avg bit rate - audio avg bit rate
  1121 							//       However, stream avg. bit rate is not be properly set by the 3GP composer
  1122 							//       as it is not very important.  Thus leading to the video avg. bit rate  
  1123 							//       retrieved from the output file to NOT match the original.
  1124 							result = ((video1->iMaxBitRate == video2->iMaxBitRate) && 
  1125 									 //(video1->iAvgBitRate == video2->iAvgBitRate) &&
  1126 									 (video1->iDecoderSpecificInfo == video2->iDecoderSpecificInfo)); 
  1127 							break;			
  1128 							}
  1129 								
  1130 						case E3GPAvcProfileBaseline:
  1131 						case E3GPAvcProfileMain:
  1132 						case E3GPAvcProfileExtended:
  1133 						case E3GPAvcProfileHigh:
  1134 							{
  1135 							T3GPVideoPropertiesAvc* video1 = (T3GPVideoPropertiesAvc*)videoProperties1;
  1136 							T3GPVideoPropertiesAvc* video2 = (T3GPVideoPropertiesAvc*)videoProperties2;
  1137 							
  1138 							result = (video1->iDecoderSpecificInfo == video2->iDecoderSpecificInfo); 
  1139 							break;
  1140 							}
  1141 									
  1142 						case E3GPH263Profile0:
  1143 						case E3GPH263Profile3:
  1144 							{
  1145 							T3GPVideoPropertiesH263* video1 = (T3GPVideoPropertiesH263*)videoProperties1;
  1146 							T3GPVideoPropertiesH263* video2 = (T3GPVideoPropertiesH263*)videoProperties2;
  1147 
  1148 							result = (video1->iVideoLevel == video2->iVideoLevel);
  1149 							break;			
  1150 							}
  1151 						}
  1152 					}
  1153 				}			
  1154 			}		
  1155 		}	
  1156 	else if (err1 == KErrNotSupported && err2 == err1)
  1157 		{
  1158 		result = ETrue;
  1159 		}
  1160 
  1161 	CleanupStack::PopAndDestroy(4);		// videoProperties1, 
  1162 										// videoProperties2, 
  1163 										// videoDecoderSpecificInfo1, 
  1164 										// videoDecoderSpecificInfo2
  1165 	
  1166 	return result;
  1167 	}
  1168 
  1169 TBool C3GPLibParseComposeFile::CompareAudioPropertiesL(C3GPParse& aParser1, 
  1170 													   C3GPParse& aParser2)
  1171 	{
  1172 	//
  1173 	// Retrieve Audio Properties 1
  1174 	//
  1175 	T3GPAudioPropertiesBase* audioProperties1 = NULL;
  1176 	CleanupStack::PushL(audioProperties1);	
  1177 
  1178 	RBuf8 audioDecoderSpecificInfo1;
  1179 	CleanupClosePushL(audioDecoderSpecificInfo1);
  1180 	
  1181 	TUint audioLengthInMs1 = 0;
  1182 	TInt err1 = ParseAudioProperties(aParser1, audioDecoderSpecificInfo1, audioProperties1, audioLengthInMs1);
  1183 	if( err1 != KErrNone && err1 != KErrNotSupported)
  1184 		{
  1185 		ERR_PRINTF2(_L("ParseAudioProperties failed: err = %d"), err1);		
  1186 		User::Leave(err1);
  1187 		}
  1188 
  1189 	//
  1190 	// Retrieve Audio Properties 2
  1191 	//
  1192 	T3GPAudioPropertiesBase* audioProperties2 = NULL;
  1193 	CleanupStack::PushL(audioProperties2);	
  1194 
  1195 	RBuf8 audioDecoderSpecificInfo2;
  1196 	CleanupClosePushL(audioDecoderSpecificInfo2);
  1197 	
  1198 	TUint audioLengthInMs2 = 0;
  1199 	TInt err2 = ParseAudioProperties(aParser2, audioDecoderSpecificInfo2, audioProperties2, audioLengthInMs2);
  1200 	if( err2 != KErrNone && err2 != KErrNotSupported)
  1201 		{
  1202 		ERR_PRINTF2(_L("ParseAudioProperties failed: err = %d"), err2);		
  1203 		User::Leave(err2);
  1204 		}
  1205 	
  1206 	TBool result = EFalse;
  1207 	if (err1 == err2 && err1 != KErrNotSupported)
  1208 		{
  1209 		if (audioLengthInMs2 == audioLengthInMs1)
  1210 			{
  1211 			if (audioProperties1 && audioProperties2)
  1212 				{
  1213 				result = (audioProperties1->iType == audioProperties2->iType) &&
  1214 						 (audioProperties1->iFramesPerSample == audioProperties2->iFramesPerSample) &&
  1215 						 (audioProperties1->iTimescale == audioProperties2->iTimescale);
  1216 				
  1217 				if (result)
  1218 					{
  1219 					switch(audioProperties1->iType)
  1220 						{
  1221 						case E3GPMpeg4Audio:
  1222 							{
  1223 							T3GPAudioPropertiesMpeg4Audio* audio1 = (T3GPAudioPropertiesMpeg4Audio*) audioProperties1;
  1224 							T3GPAudioPropertiesMpeg4Audio* audio2 = (T3GPAudioPropertiesMpeg4Audio*) audioProperties2;
  1225 							result = (audio1->iDecoderSpecificInfo == audio2->iDecoderSpecificInfo);
  1226 							}
  1227 							break;							
  1228 							
  1229 						case E3GPAmrNB:
  1230 						case E3GPAmrWB:
  1231 							{
  1232 							T3GPAudioPropertiesAmr* audio1 = (T3GPAudioPropertiesAmr*) audioProperties1;
  1233 							T3GPAudioPropertiesAmr* audio2 = (T3GPAudioPropertiesAmr*) audioProperties2;
  1234 							result = (audio1->iModeSet == audio2->iModeSet);
  1235 							}
  1236 							break;														
  1237 							
  1238 						case E3GPQcelp13K:
  1239 							{
  1240 							T3GPAudioPropertiesQcelp* audio1 = (T3GPAudioPropertiesQcelp*) audioProperties1;
  1241 							T3GPAudioPropertiesQcelp* audio2 = (T3GPAudioPropertiesQcelp*) audioProperties2;
  1242 							result = ((audio1->iDecoderSpecificInfo == audio2->iDecoderSpecificInfo) &&
  1243 									 (audio1->iMode == audio2->iMode));
  1244 							}
  1245 							break;														
  1246 						}
  1247 					}
  1248 				}
  1249 			}
  1250 		}	
  1251 	else if (err1 == KErrNotSupported && err2 == err1)
  1252 		{
  1253 		result = ETrue;
  1254 		}
  1255 
  1256 	CleanupStack::PopAndDestroy(4);		// audioProperties1, audioProperties2, audioDecoderSpecificInfo1, audioDecoderSpecificInfo2
  1257 	
  1258 	return result;
  1259 	}
  1260 
  1261 TBool C3GPLibParseComposeFile::CompareAudioVideoData(C3GPParse& aParser1, C3GPParse& aParser2)
  1262 	{
  1263 	T3GPFrameType frameType1;
  1264 	T3GPFrameType frameType2;
  1265 	TInt err1 = KErrNone;
  1266 	TInt err2 = KErrNone;
  1267 	TBool keepLooping = ETrue;
  1268 	TBool result = EFalse;
  1269 	
  1270 	while (keepLooping)
  1271 		{
  1272 		err1 = aParser1.GetFrameType(frameType1);
  1273 		err2 = aParser2.GetFrameType(frameType2);
  1274 		
  1275 		if (err1 != err2)
  1276 			{
  1277 			break;
  1278 			}		
  1279 		else
  1280 			{
  1281 			if (err1 == KErrNotFound)
  1282 				{
  1283 				// completed looping thru all the frames
  1284 				break;
  1285 				}
  1286 			
  1287 			if (err1 != KErrNone)
  1288 				{
  1289 				// if the error is not KErrNotFound, something's wrong!
  1290 				result = EFalse;
  1291 				}			
  1292 			else if (frameType1 != frameType2)
  1293 				{			
  1294 				result = EFalse;
  1295 				}		
  1296 			else if (frameType1 == E3GPVideo)
  1297 				{
  1298 				result = CompareVideoFrame(aParser1, aParser2);
  1299 				}				
  1300 			else if (frameType1 == E3GPAudio)			
  1301 				{
  1302 				result = CompareAudioFrames(aParser1, aParser2);
  1303 				}
  1304 			
  1305 			if (!result)
  1306 				{
  1307 				break;
  1308 				}
  1309 			}
  1310 		} 
  1311 	
  1312 	return result;
  1313 	}
  1314 
  1315 TBool C3GPLibParseComposeFile::CompareVideoFrame(C3GPParse& aParser1, C3GPParse& aParser2)
  1316 	{
  1317 	TUint timestamp1 = 0;
  1318 	TUint timestamp2 = 0;
  1319 	RBuf8 buf1;
  1320 	RBuf8 buf2;
  1321 	TBool keyFrame1 = EFalse;
  1322 	TBool keyFrame2 = EFalse;
  1323 	T3GPFrameDependencies dep1;
  1324 	T3GPFrameDependencies dep2;
  1325 	
  1326 	TInt err1 = ReadVideoFrame(aParser1, buf1, keyFrame1, timestamp1, dep1);
  1327 	TInt err2 = ReadVideoFrame(aParser2, buf2, keyFrame2, timestamp2, dep2);
  1328 
  1329 	TBool result = EFalse;
  1330 	if (err1 == err2)
  1331 		{
  1332 		if (keyFrame1 == keyFrame2 && timestamp1 == timestamp2)
  1333 			{
  1334 			if (dep1.iDependsOn == dep2.iDependsOn && 
  1335 				dep1.iHasRedundancy == dep2.iHasRedundancy && 
  1336 				dep1.iIsDependedOn == dep2.iIsDependedOn)
  1337 				{
  1338 				if (buf1 == buf2)
  1339 					{
  1340 					result = ETrue;
  1341 					}
  1342 				else 
  1343 					{
  1344 					result = EFalse;
  1345 					}
  1346 				}
  1347 			else 
  1348 				{
  1349 				result = EFalse;
  1350 				}			
  1351 			}
  1352 		else 
  1353 			{
  1354 			result = EFalse;
  1355 			}		
  1356 		}
  1357 	else 
  1358 		{
  1359 		result = EFalse;
  1360 		}	
  1361 
  1362 	// cleanup
  1363 	buf1.Close();
  1364 	buf2.Close();
  1365 	
  1366 	return result;
  1367 	}
  1368 
  1369 TBool C3GPLibParseComposeFile::CompareAudioFrames(C3GPParse& aParser1, C3GPParse& aParser2)
  1370 	{
  1371 	TInt fps1 = 0;
  1372 	TInt fps2 = 0;
  1373 	TUint timestamp1 = 0;
  1374 	TUint timestamp2 = 0;
  1375 	RBuf8 buf1;
  1376 	RBuf8 buf2;
  1377 	
  1378 	TInt err1 = ReadAudioFrames(aParser1, buf1, fps1, timestamp1);
  1379 	TInt err2 = ReadAudioFrames(aParser2, buf2, fps2, timestamp2);
  1380 
  1381 	TBool result = EFalse;
  1382 	if (err1 == err2)
  1383 		{
  1384 		if (fps1 == fps2 && timestamp1 == timestamp2)
  1385 			{
  1386 			if (buf1 == buf2)
  1387 				{
  1388 				result = ETrue;
  1389 				}
  1390 			else 
  1391 				{
  1392 				result = EFalse;
  1393 				}			
  1394 			}
  1395 		else 
  1396 			{
  1397 			result = EFalse;
  1398 			}		
  1399 		}
  1400 	else 
  1401 		{
  1402 		result = EFalse;
  1403 		}
  1404 	
  1405 	// cleanup	
  1406 	buf1.Close();
  1407 	buf2.Close();
  1408 	
  1409 	return result;
  1410 	}