1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmplugins/lib3gpunittest/src/tsu_3gplibrary_parse_and_check.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,487 @@
1.4 +// Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "tsu_3gplibrary_parse_and_check.h"
1.20 +
1.21 +_LIT( KAvcBaseline, "Baseline" );
1.22 +_LIT( KAvcMain, "Main" );
1.23 +_LIT( KAvcExtended, "Extended" );
1.24 +_LIT( KAvcHigh, "High" );
1.25 +
1.26 +const static TDesC* KAvcProfileNames[] = {
1.27 + &KAvcBaseline,
1.28 + &KAvcMain,
1.29 + &KAvcExtended,
1.30 + &KAvcHigh
1.31 + };
1.32 +
1.33 +const TUint16 KAudioModeSet = 0x81ff;
1.34 +
1.35 +C3GPLibParseAndCheckTypes::C3GPLibParseAndCheckTypes()
1.36 + {
1.37 + }
1.38 +
1.39 +TVerdict C3GPLibParseAndCheckTypes::doTestStepPreambleL()
1.40 + {
1.41 + // ensure test always starts with clean results
1.42 + SetTestStepResult(EPass);
1.43 + SetTestStepError(KErrNone);
1.44 +
1.45 + #ifdef __WINSCW__
1.46 + _LIT(KTestFileName, "filepath");
1.47 + #else
1.48 + _LIT(KTestFileName, "filepathHw");
1.49 + #endif
1.50 +
1.51 + TPtrC inputFilePath;
1.52 + if (!GetStringFromConfig(ConfigSection(), KTestFileName, inputFilePath))
1.53 + {
1.54 + ERR_PRINTF1(_L("Error to read data from ini file."));
1.55 + SetTestStepResult(ETestSuiteError);
1.56 + return TestStepResult();
1.57 + }
1.58 +
1.59 + if (inputFilePath.Length() == 0)
1.60 + {
1.61 + ERR_PRINTF1(_L("Error to read input file path from ini file."));
1.62 + SetTestStepResult(ETestSuiteError);
1.63 + return TestStepResult();
1.64 + }
1.65 +
1.66 + TInt temp;
1.67 + if (!GetIntFromConfig(ConfigSection(), _L("audioType"), temp))
1.68 + {
1.69 + ERR_PRINTF1(_L("expected audio type not specified"));
1.70 + SetTestStepResult(ETestSuiteError);
1.71 + return TestStepResult();
1.72 + }
1.73 + else
1.74 + {
1.75 + iExpectedAudioType = (T3GPAudioType)temp;
1.76 + }
1.77 +
1.78 + if (!GetIntFromConfig(ConfigSection(), _L("videoType"), temp))
1.79 + {
1.80 + ERR_PRINTF1(_L("expected video type not specified"));
1.81 + SetTestStepResult(ETestSuiteError);
1.82 + return TestStepResult();
1.83 + }
1.84 + else
1.85 + {
1.86 + iExpectedVideoType = (T3GPVideoType)temp;
1.87 + }
1.88 +
1.89 +
1.90 + iInputFilePath.CreateL(inputFilePath);
1.91 +
1.92 + iParser = C3GPParse::NewL();
1.93 +
1.94 + return TestStepResult();
1.95 + }
1.96 +
1.97 +TVerdict C3GPLibParseAndCheckTypes::doTestStepL()
1.98 + {
1.99 + // ensure test always starts with clean results
1.100 + SetTestStepResult(EPass);
1.101 + SetTestStepError(KErrNone);
1.102 +
1.103 + INFO_PRINTF2(_L("ParseFileL: file=%S"), &iInputFilePath);
1.104 + TRAPD(err, ParseAndCheckFileL(iInputFilePath));
1.105 + INFO_PRINTF2(_L("ParseFileL returns: err = %d"), err);
1.106 + if( err != KErrNone )
1.107 + {
1.108 + SetTestStepError( err );
1.109 + SetTestStepResult( EFail );
1.110 + iParser->Complete();
1.111 + }
1.112 +
1.113 +
1.114 +
1.115 + return TestStepResult();
1.116 + }
1.117 +
1.118 +TVerdict C3GPLibParseAndCheckTypes::doTestStepPostambleL()
1.119 + {
1.120 + iInputFilePath.Close();
1.121 +
1.122 + delete iParser;
1.123 +
1.124 + return TestStepResult();
1.125 + }
1.126 +
1.127 +void C3GPLibParseAndCheckTypes::ParseAndCheckFileL(const TDesC& aInputFile)
1.128 + {
1.129 + INFO_PRINTF1(_L("C3GPLibParseFileMainHigh::ParseFileL START"));
1.130 + ASSERT(iParser);
1.131 + TInt err = 0;
1.132 +
1.133 + err = iParser->Open(aInputFile);
1.134 +
1.135 + if (err != KErrNone)
1.136 + {
1.137 + ERR_PRINTF2(_L("C3GPParse::Open() returns %d"), err);
1.138 + User::Leave(err);
1.139 + }
1.140 +
1.141 + //
1.142 + // Retrieve Video Properties
1.143 + //
1.144 + T3GPVideoPropertiesBase* videoProperties = NULL;
1.145 + CleanupStack::PushL(videoProperties);
1.146 +
1.147 + RBuf8 videoDecoderSpecificInfo;
1.148 + CleanupClosePushL(videoDecoderSpecificInfo);
1.149 +
1.150 + TUint videoLengthInMs = 0;
1.151 +
1.152 + err = ParseVideoProperties(*iParser, videoDecoderSpecificInfo, videoProperties, videoLengthInMs);
1.153 + if ( err != KErrNone )
1.154 + {
1.155 + ERR_PRINTF2(_L("ParseVideoProperties failed: err = %d"), err);
1.156 + User::Leave(err);
1.157 + }
1.158 +
1.159 + //
1.160 + // Retrieve Audio Properties
1.161 + //
1.162 + T3GPAudioPropertiesBase* audioProperties = NULL;
1.163 + CleanupStack::PushL(audioProperties);
1.164 +
1.165 + RBuf8 audioDecoderSpecificInfo;
1.166 + CleanupClosePushL(audioDecoderSpecificInfo);
1.167 +
1.168 + TUint audioLengthInMs = 0;
1.169 + err = ParseAudioProperties(*iParser, audioDecoderSpecificInfo, audioProperties, audioLengthInMs);
1.170 + if( err != KErrNone )
1.171 + {
1.172 + ERR_PRINTF2(_L("ParseAudioProperties failed: err = %d"), err);
1.173 + User::Leave(err);
1.174 + }
1.175 +
1.176 + if (!videoProperties && !audioProperties)
1.177 + {
1.178 + ERR_PRINTF1(_L("File contains neither video nor audio data"));
1.179 + User::Leave(KErrNotFound);
1.180 + }
1.181 +
1.182 + //
1.183 + // Check that types were as expected
1.184 + //
1.185 + if( audioProperties->iType != iExpectedAudioType )
1.186 + {
1.187 + INFO_PRINTF3(_L("Audio type check failed (expected %d, got %d)"), iExpectedAudioType, audioProperties->iType );
1.188 + SetTestStepResult( EFail );
1.189 + }
1.190 +
1.191 + if( videoProperties->iType != iExpectedVideoType )
1.192 + {
1.193 + INFO_PRINTF3(_L("Video type check failed (expected %d, got %d)"), iExpectedVideoType, videoProperties->iType );
1.194 + SetTestStepResult( EFail );
1.195 + }
1.196 +
1.197 +
1.198 + //
1.199 + // Clean up
1.200 + //
1.201 + CleanupStack::PopAndDestroy(4);
1.202 + // audioDecoderSpecificInfo
1.203 + // audioProperties
1.204 + // videoDecoderSpecificInfo
1.205 + // videoProperties
1.206 +
1.207 + err = iParser->Complete();
1.208 + if (err != KErrNone)
1.209 + {
1.210 + ERR_PRINTF1(_L("aParser->Complete() failed"));
1.211 + User::Leave(err);
1.212 + }
1.213 +
1.214 + INFO_PRINTF1(_L("C3GPLibParseFileMainHigh::ParseFileL END"));
1.215 + }
1.216 +
1.217 +TInt C3GPLibParseAndCheckTypes::ParseVideoProperties(C3GPParse& aParser,
1.218 + RBuf8& aDecoderSpecificInfo,
1.219 + T3GPVideoPropertiesBase*& aProperties,
1.220 + TUint& aLengthInMs)
1.221 + {
1.222 + ASSERT(iParser);
1.223 +
1.224 + T3GPVideoType type;
1.225 + TReal frameRate;
1.226 + TUint avgBitRate;
1.227 + TSize size;
1.228 + TUint timeScale;
1.229 +
1.230 + TInt err = aParser.GetVideoProperties(type, aLengthInMs, frameRate, avgBitRate, size, timeScale);
1.231 + if ( err != KErrNone )
1.232 + {
1.233 + ERR_PRINTF2(_L("aParser->GetVideoProperties failed: %d"), err);
1.234 + return err;
1.235 + }
1.236 +
1.237 + switch(type)
1.238 + {
1.239 + case E3GPMpeg4Video:
1.240 + {
1.241 + INFO_PRINTF1(_L("Video Type: Mpeg4"));
1.242 + err = GetVideoDecoderSpecificInfo(aDecoderSpecificInfo);
1.243 + if (err == KErrNone)
1.244 + {
1.245 + aProperties = new T3GPVideoPropertiesMpeg4Video(timeScale, size,
1.246 + 64000, avgBitRate, aDecoderSpecificInfo);
1.247 + if (!aProperties)
1.248 + {
1.249 + ERR_PRINTF1(_L("T3GPVideoPropertiesMpeg4Video allocation failed"));
1.250 + err = KErrNoMemory;
1.251 + }
1.252 + }
1.253 + break;
1.254 + }
1.255 +
1.256 + case E3GPH263Profile0:
1.257 + case E3GPH263Profile3:
1.258 + {
1.259 + INFO_PRINTF1(_L("Video Type: H263"));
1.260 + T3GPVideoPropertiesH263::TProfile profile = T3GPVideoPropertiesH263::EProfile0;
1.261 + if (type == E3GPH263Profile3)
1.262 + {
1.263 + profile = T3GPVideoPropertiesH263::EProfile3;
1.264 + }
1.265 +
1.266 + TInt videoLevel;
1.267 + err = iParser->GetH263VideoLevel(videoLevel);
1.268 + if( err != KErrNone )
1.269 + {
1.270 + ERR_PRINTF1(_L("aParser->GetH263VideoLevel() failed"));
1.271 + }
1.272 + else
1.273 + {
1.274 + aProperties = new T3GPVideoPropertiesH263(timeScale, size, videoLevel, profile);
1.275 + if( !aProperties )
1.276 + {
1.277 + ERR_PRINTF1(_L("T3GPVideoPropertiesH263 allocation failed"));
1.278 + err = KErrNoMemory;
1.279 + }
1.280 + }
1.281 + break;
1.282 + }
1.283 +
1.284 +
1.285 + case E3GPAvcProfileBaseline:
1.286 + case E3GPAvcProfileMain:
1.287 + case E3GPAvcProfileExtended:
1.288 + case E3GPAvcProfileHigh:
1.289 + {
1.290 + err = GetVideoDecoderSpecificInfo(aDecoderSpecificInfo);
1.291 + if (err == KErrNone)
1.292 + {
1.293 + INFO_PRINTF2(_L("Video Type: Avc Profile %S"), KAvcProfileNames[type-E3GPAvcProfileBaseline] );
1.294 + aProperties = new T3GPVideoPropertiesAvc(timeScale, size, aDecoderSpecificInfo);
1.295 + if (!aProperties)
1.296 + {
1.297 + ERR_PRINTF1(_L("T3GPVideoPropertiesAvc allocation failed"));
1.298 + err = KErrNoMemory;
1.299 + }
1.300 + else
1.301 + {
1.302 + // T3GPVideoPropertiesAvc defaults the video type to AVC baseline profile.
1.303 + // Need to override that here because we want to check for the specific
1.304 + // profile in this test.
1.305 + aProperties->iType = type;
1.306 + }
1.307 + }
1.308 + break;
1.309 + }
1.310 +
1.311 + case E3GPNoVideo:
1.312 + INFO_PRINTF1(_L("Video Type: None"));
1.313 + break;
1.314 +
1.315 + default:
1.316 + err = KErrNotSupported;
1.317 + break;
1.318 + }
1.319 +
1.320 + if( err == KErrNone )
1.321 + {
1.322 + INFO_PRINTF1(_L("**********"));
1.323 + INFO_PRINTF2(_L("Length In Miliseconds = %d"), aLengthInMs);
1.324 + INFO_PRINTF2(_L("Frame Rate = %f"), frameRate);
1.325 + INFO_PRINTF2(_L("Average Bit Rate = %d"), avgBitRate);
1.326 + INFO_PRINTF2(_L("Frame Width = %d"), size.iWidth);
1.327 + INFO_PRINTF2(_L("Frame Height = %d"), size.iHeight);
1.328 + INFO_PRINTF2(_L("Time Scale = %d"), timeScale);
1.329 + INFO_PRINTF1(_L("**********"));
1.330 + }
1.331 + return err;
1.332 + }
1.333 +
1.334 +TInt C3GPLibParseAndCheckTypes::ParseAudioProperties(C3GPParse& aParser,
1.335 + RBuf8& aAudioDecoderSpecificInfo,
1.336 + T3GPAudioPropertiesBase*& aAudioProperties,
1.337 + TUint& aLength)
1.338 + {
1.339 + ASSERT(iParser);
1.340 +
1.341 + T3GPAudioType type;
1.342 + TInt audioFPS;
1.343 + TUint audioAvgBitRate;
1.344 + TUint timeScale;
1.345 +
1.346 + TInt err = aParser.GetAudioProperties(type, aLength, audioFPS, audioAvgBitRate, timeScale);
1.347 + if( err != KErrNone )
1.348 + {
1.349 + ERR_PRINTF2(_L("GetAudioProperties() failed: %d"), err);
1.350 + return err;
1.351 + }
1.352 +
1.353 + switch(type)
1.354 + {
1.355 + case E3GPMpeg4Audio:
1.356 + {
1.357 + INFO_PRINTF1(_L("Audio Type: Mpeg4"));
1.358 + err = GetAudioDecoderSpecificInfo(aAudioDecoderSpecificInfo);
1.359 + if (err == KErrNone)
1.360 + {
1.361 + aAudioProperties = new T3GPAudioPropertiesMpeg4Audio(timeScale, aAudioDecoderSpecificInfo);
1.362 + if( !aAudioProperties )
1.363 + {
1.364 + ERR_PRINTF1(_L("T3GPAudioPropertiesMpeg4Audio allocation failed"));
1.365 + err = KErrNoMemory;
1.366 + }
1.367 + }
1.368 + break;
1.369 + }
1.370 +
1.371 + case E3GPQcelp13K:
1.372 + {
1.373 + INFO_PRINTF1(_L("Audio Type: Qcelp13K"));
1.374 + T3GPQcelpStorageMode mode;
1.375 + err = iParser->GetQcelpStorageMode(mode);
1.376 + if (err != KErrNone)
1.377 + {
1.378 + ERR_PRINTF1(_L("GetQcelpStorageMode failed"));
1.379 + }
1.380 + else
1.381 + {
1.382 + if( mode == E3GPMP4AudioDescriptionBox)
1.383 + {
1.384 + err = GetAudioDecoderSpecificInfo(aAudioDecoderSpecificInfo);
1.385 + aAudioProperties = new T3GPAudioPropertiesQcelp(timeScale, audioFPS, aAudioDecoderSpecificInfo);
1.386 + }
1.387 + else
1.388 + {
1.389 + aAudioProperties = new T3GPAudioPropertiesQcelp(timeScale, audioFPS);
1.390 + }
1.391 +
1.392 + if( !aAudioProperties )
1.393 + {
1.394 + ERR_PRINTF1(_L("T3GPAudioPropertiesQcelp allocation failed"));
1.395 + err = KErrNoMemory;
1.396 + }
1.397 + }
1.398 + break;
1.399 + }
1.400 +
1.401 + case E3GPAmrNB:
1.402 + {
1.403 + INFO_PRINTF1(_L("Audio Type: AMR NB"));
1.404 + aAudioProperties = new T3GPAudioPropertiesAmr(timeScale, audioFPS, KAudioModeSet, T3GPAudioPropertiesAmr::EAmrNB);
1.405 + if( !aAudioProperties )
1.406 + {
1.407 + ERR_PRINTF1(_L("T3GPAudioPropertiesAmr allocation failed"));
1.408 + err = KErrNoMemory;
1.409 + }
1.410 + break;
1.411 + }
1.412 +
1.413 + case E3GPAmrWB:
1.414 + {
1.415 + INFO_PRINTF1(_L("Audio Type: AMR WB"));
1.416 + aAudioProperties = new T3GPAudioPropertiesAmr(timeScale, audioFPS, KAudioModeSet, T3GPAudioPropertiesAmr::EAmrWB);
1.417 + if( !aAudioProperties )
1.418 + {
1.419 + ERR_PRINTF1(_L("T3GPAudioPropertiesAmr allocation failed"));
1.420 + err = KErrNoMemory;
1.421 + }
1.422 + break;
1.423 + }
1.424 +
1.425 + case E3GPNoAudio:
1.426 + INFO_PRINTF1(_L("Audio Type: None"));
1.427 + break;
1.428 +
1.429 + default:
1.430 + INFO_PRINTF1(_L("Audio Type: Unrecognized!"));
1.431 + err = KErrNotSupported;
1.432 + break;
1.433 + }
1.434 +
1.435 + return err;
1.436 + }
1.437 +
1.438 +TInt C3GPLibParseAndCheckTypes::GetAudioDecoderSpecificInfo(RBuf8& aBuffer)
1.439 + {
1.440 + ASSERT(iParser);
1.441 +
1.442 + TInt size;
1.443 + TInt err = iParser->GetAudioDecoderSpecificInfoSize(size);
1.444 + if( err != KErrNone )
1.445 + {
1.446 + ERR_PRINTF2(_L("GetAudioDecoderSpecificInfoSize() failed: %d"), err);
1.447 + return err;
1.448 + }
1.449 +
1.450 + err = aBuffer.Create(size);
1.451 + if( err != KErrNone )
1.452 + {
1.453 + ERR_PRINTF1(_L("Create buffer failed"));
1.454 + return err;
1.455 + }
1.456 +
1.457 + err = iParser->GetAudioDecoderSpecificInfo(aBuffer);
1.458 + if( err != KErrNone )
1.459 + {
1.460 + ERR_PRINTF2(_L("GetAudioDecoderSpecificInfo() failed: %d"), err);
1.461 + }
1.462 +
1.463 + return err;
1.464 + }
1.465 +
1.466 +TInt C3GPLibParseAndCheckTypes::GetVideoDecoderSpecificInfo(RBuf8& aBuffer)
1.467 + {
1.468 + TInt size;
1.469 + TInt err = iParser->GetVideoDecoderSpecificInfoSize(size);
1.470 + if (err != KErrNone)
1.471 + {
1.472 + ERR_PRINTF1(_L("GetVideoDecoderSpecificInfoSize() failed"));
1.473 + return err;
1.474 + }
1.475 +
1.476 + err = aBuffer.Create(size);
1.477 + if (err != KErrNone)
1.478 + {
1.479 + ERR_PRINTF1(_L("Create buffer failed"));
1.480 + return err;
1.481 + }
1.482 +
1.483 + err = iParser->GetVideoDecoderSpecificInfo(aBuffer);
1.484 + if( err != KErrNone )
1.485 + {
1.486 + ERR_PRINTF1(_L("GetVideoDecoderSpecificInfo() failed"));
1.487 + }
1.488 +
1.489 + return err;
1.490 + }