Beispiel #1
0
static HRESULT ReadAAFFile(aafWChar* pFileName)
{
	IAAFFile*			pFile = NULL;
	IAAFHeader*			pHeader = NULL;
	IAAFDictionary*		pDictionary = NULL;
	IEnumAAFOperationDefs *pEffectEnum = NULL;
	IEnumAAFOperationDefs *pDegradeEnum = NULL;
	IEnumAAFParameterDefs *pParmDefEnum = NULL;
	IAAFOperationDef		*pOperationDef = NULL;
	IAAFParameterDef	*pParmDef = NULL;
	IAAFDefObject*		pDefObject = NULL;
	bool				bFileOpen = false;
	IAAFDataDefSP		pReadDataDef;
	aafBool				readIsTimeWarp;
	aafInt32			checkNumInputs;
	aafUInt32			checkBypass;
	HRESULT				hr = S_OK;
	wchar_t				checkName[256];
	aafUID_t			checkCat;
	aafBool				bResult = kAAFFalse;

	try
	{
		// Open the AAF file
		checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile));
		bFileOpen = true;

		// Get the AAF file header.
		checkResult(pFile->GetHeader(&pHeader));

		checkResult(pHeader->GetDictionary(&pDictionary));
		CAAFBuiltinDefs defs (pDictionary);
	
		checkResult(pDictionary->GetOperationDefs(&pEffectEnum));
		checkResult(pEffectEnum->NextOne (&pOperationDef));
		checkResult(pOperationDef->GetDataDef(&pReadDataDef));

		checkResult(pOperationDef->QueryInterface(IID_IAAFDefObject, (void **) &pDefObject));
		checkResult(pDefObject->GetName (checkName, sizeof(checkName)));
		checkExpression(wcscmp(checkName, effectNames[0]) == 0, AAFRESULT_TEST_FAILED);
		checkResult(pDefObject->GetDescription (checkName, sizeof(checkName)));
		checkExpression(wcscmp(checkName, effectDesc[0]) == 0, AAFRESULT_TEST_FAILED);
		pDefObject->Release();
		pDefObject = NULL;
		
		checkResult(pReadDataDef->IsDataDefOf(defs.ddkAAFPicture(), &bResult));
		checkExpression(bResult == kAAFTrue, AAFRESULT_TEST_FAILED);
						
		checkResult(pOperationDef->IsTimeWarp (&readIsTimeWarp));
		checkExpression(readIsTimeWarp == kAAFFalse, AAFRESULT_TEST_FAILED);
		checkResult(pOperationDef->GetCategory (&checkCat));
		checkExpression(memcmp(&checkCat, &TEST_CATEGORY, sizeof(aafUID_t)) == 0, AAFRESULT_TEST_FAILED);
		checkResult(pOperationDef->GetBypass (&checkBypass));
		checkExpression(checkBypass == TEST_BYPASS, AAFRESULT_TEST_FAILED);
		checkResult(pOperationDef->GetNumberInputs (&checkNumInputs));
		checkExpression(checkNumInputs == TEST_NUM_INPUTS, AAFRESULT_TEST_FAILED);
		checkResult(pOperationDef->GetParameterDefs (&pParmDefEnum));
		checkResult(pParmDefEnum->NextOne (&pParmDef));

		checkResult(pParmDef->QueryInterface(IID_IAAFDefObject, (void **) &pDefObject));
		checkResult(pDefObject->GetName (checkName, sizeof(checkName)));
		checkExpression(wcscmp(checkName, TEST_PARAM_NAME) == 0, AAFRESULT_TEST_FAILED);
		checkResult(pDefObject->GetDescription (checkName, sizeof(checkName)));
		checkExpression(wcscmp(checkName, TEST_PARAM_DESC) == 0, AAFRESULT_TEST_FAILED);
		pDefObject->Release();
		pDefObject = NULL;

		checkResult(pOperationDef->GetDegradeToOperations (&pDegradeEnum));
		pOperationDef->Release();
		pOperationDef = NULL;

		// Check for prepended one first
		checkResult(pDegradeEnum->NextOne (&pOperationDef));
		checkResult(pOperationDef->QueryInterface(IID_IAAFDefObject, (void **) &pDefObject));
		checkResult(pDefObject->GetName (checkName, sizeof(checkName)));
		checkExpression(wcscmp(checkName, effectNames[2]) == 0, AAFRESULT_TEST_FAILED);
		checkResult(pDefObject->GetDescription (checkName, sizeof(checkName)));
		checkExpression(wcscmp(checkName, effectDesc[2]) == 0, AAFRESULT_TEST_FAILED);
		pDefObject->Release();
		pDefObject = NULL;
		pOperationDef->Release();
		pOperationDef = NULL;

		// Check for appended one second
		checkResult(pDegradeEnum->NextOne (&pOperationDef));
		checkResult(pOperationDef->QueryInterface(IID_IAAFDefObject, (void **) &pDefObject));
		checkResult(pDefObject->GetName (checkName, sizeof(checkName)));
		checkExpression(wcscmp(checkName, effectNames[1]) == 0, AAFRESULT_TEST_FAILED);
		checkResult(pDefObject->GetDescription (checkName, sizeof(checkName)));
		checkExpression(wcscmp(checkName, effectDesc[1]) == 0, AAFRESULT_TEST_FAILED);
		pDefObject->Release();
		pDefObject = NULL;
		pOperationDef->Release();
		pOperationDef = NULL;
	}
	catch (HRESULT& rResult)
	{
		hr = rResult;
	}

	// Cleanup and return
	if (pHeader)
		pHeader->Release();
      
	if (pDictionary)
		pDictionary->Release();
      
	if (pEffectEnum)
		pEffectEnum->Release();

	if (pDegradeEnum)
		pDegradeEnum->Release();

	if (pParmDefEnum)
		pParmDefEnum->Release();
      
	if (pOperationDef)
		pOperationDef->Release();
      
	if (pDefObject)
		pDefObject->Release();

	if (pParmDef)
		pParmDef->Release();

	if (pFile)
	{  // Close file
		if (bFileOpen)
			pFile->Close();
		pFile->Release();
	}

	return hr;
}
Beispiel #2
0
static HRESULT ReadAAFFile(aafWChar* pFileName)
{
  IAAFFileSP           pFile;
  IAAFHeaderSP         pHeader;
  IEnumAAFMobsSP       pMobIter;
  IAAFMobSP            pMob;
  IEnumAAFMobSlotsSP   pSlotIter;
  IAAFMobSlotSP        pSlot;
  IAAFComponentSP      pComp;
  IAAFSegmentSP        pSegment;
  IAAFDataDefSP        pDataDef;
  IAAFSequenceSP       pSequence;
  IAAFDictionarySP     pDictionary;
  IEnumAAFComponentsSP pCompIter;
  aafNumSlots_t        numMobs;
  aafSearchCrit_t      criteria;
  HRESULT              hr = S_OK;
	
  try
	{
	  // Open the AAF file
	  checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile));

	  // Get the AAF file header.
	  checkResult(pFile->GetHeader(&pHeader));
		
	  // Validate that there is only one composition mob.
	  checkResult(pHeader->CountMobs(kAAFCompMob, &numMobs));
	  checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED);
		
	  // Get the AAF Dictionary so that we can create valid AAF objects.
	  checkResult(pHeader->GetDictionary(&pDictionary));
	  CAAFBuiltinDefs defs (pDictionary);

	  // Check a data definition from a composition MOB in order to test weak references
	  criteria.searchTag = kAAFByMobKind;
	  criteria.tags.mobKind = kAAFCompMob;
	  checkResult(pHeader->GetMobs(&criteria, &pMobIter));
	  while (pMobIter && pMobIter->NextOne(&pMob) == AAFRESULT_SUCCESS)
		{					
		  // Enumerate the first MOB slot for this MOB
		  checkResult(pMob->GetSlots(&pSlotIter));
		  checkResult(pSlotIter->NextOne(&pSlot));

		  checkResult(pSlot->GetSegment(&pSegment));
		  checkResult(pSegment->QueryInterface(IID_IAAFSequence, (void **) &pSequence));
		  checkResult(pSequence->GetComponents(&pCompIter));
		  checkResult(pCompIter->NextOne(&pComp));

		  aafBool  testBool;

		  checkResult(pComp->GetDataDef(&pDataDef));
		  checkResult(pDataDef->IsSoundKind(&testBool));
		  checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED);

		  checkResult(pDataDef->IsDataDefOf(defs.ddkAAFPictureWithMatte(), &testBool));
		  checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED);
		
		  // Make sure first component is a filler, and is our extended
		  // class.  To do that, we'll compare the class def we looked
		  // up in the dict, with the one we got from the new object.
		  //
		  // First get the class from the object.
		  IAAFFillerSP pFill;
		  checkResult(pComp->QueryInterface(IID_IAAFFiller,
											(void **) &pFill));
		  assert (pFill);

		  IAAFObjectSP pObj;
		  checkResult(pFill->QueryInterface(IID_IAAFObject,
											(void **) &pObj));
		  assert (pObj);
		  IAAFClassDefSP pClassFromObj;
		  checkResult (pObj->GetDefinition (&pClassFromObj));
		  assert (pClassFromObj);
		  IUnknownSP pUnkFromObj;
		  checkResult(pClassFromObj->QueryInterface(IID_IUnknown,
													(void **) &pUnkFromObj));

		  // Now get the class from the dict
		  IAAFClassDefSP pClassFromDict;
		  checkResult (pDictionary->LookupClassDef (kClassAUID_NewFill,
													&pClassFromDict));
		  assert (pClassFromDict);
		  IUnknownSP pUnkFromDict;
		  checkResult(pClassFromDict->QueryInterface(IID_IUnknown,
													 (void **) &pUnkFromDict));

		  // Compare class from object with class from dict.  Compare
		  // using IUnknown pointers.
		  assert (((IUnknown*)pUnkFromObj) ==
				  ((IUnknown*)pUnkFromDict));

		  // To test GetClassDefinitions(), try explicit lookup.
		  IEnumAAFClassDefsSP pClassDefEnum;
		  checkResult (pDictionary->GetClassDefs (&pClassDefEnum));
		  bool found = false;
		  IAAFClassDefSP cd;
		  while (SUCCEEDED (pClassDefEnum->NextOne (&cd)))
			{
			  IAAFMetaDefinitionSP def;
			  checkResult(cd->QueryInterface(IID_IAAFMetaDefinition,
											 (void **) &def));
			  aafUID_t classid;
			  checkResult (def->GetAUID (&classid));
			  if (EqualGUID (&classid, &kClassAUID_NewFill))
				{
				  // Found it the hard way.
				  found = true;
				  break;
				}
			}
		  // make sure we found it the hard way.
		  checkExpression(found == kAAFTrue, AAFRESULT_TEST_FAILED);

		  // Get the 'odor' property from our new fill clip.  Make
		  // sure it is set to the value we think it should be
		  // ('42').
		  //
		  // First get the property def from the class.
		  IAAFPropertyDefSP pPropDef;
		  checkResult (pClassFromObj->LookupPropertyDef
					   (kPropAUID_NewFill_Odor,
						&pPropDef));
		  //
		  // Get the property value from the object
		  IAAFPropertyValueSP pPropVal;
		  checkResult (pObj->GetPropertyValue (pPropDef, &pPropVal));
		  // 
		  // We know the property is int32; get the int32 type def
		  IAAFTypeDefSP ptd;
		  checkResult (pDictionary->LookupTypeDef
					   (kAAFTypeID_UInt32,
						&ptd));
		  IAAFTypeDefIntSP pTDUint32;
		  checkResult(ptd->QueryInterface(IID_IAAFTypeDefInt,
										  (void **) &pTDUint32));
		  assert (pTDUint32);
		  //
		  // Ask the typedef to interpret this property value for us.
		  aafUInt32 odorValue = 0;
		  checkResult (pTDUint32->GetInteger
					   (pPropVal,
						(aafMemPtr_t) &odorValue,
						sizeof (odorValue)));
		  //
		  // make sure it's what we expect.
		  assert (42 == odorValue);
		}

	  checkResult (LookupDefs (pDictionary));


	//Test the Lookup KLV and Tagged methods
	IAAFKLVDataDefinition *pKLVLook = NULL;
	IAAFTaggedValueDefinition *pTAGDefLook = NULL;
	IAAFDictionary2 *pDic2 = NULL;	
	IAAFDefObject *pKLVDataDefObj = NULL;
	IAAFDefObject *pTaggedValueDefObj = NULL;
	aafUID_t auid;

	checkResult( pDictionary->QueryInterface( IID_IAAFDictionary2, reinterpret_cast<void**>(&pDic2) ) );
	assert(pDic2);
	
	//test LookUpKLV()
	if(pDic2->LookupKLVDataDef(KLVDef_TestData, &pKLVLook) != AAFRESULT_SUCCESS)
		checkResult(AAFRESULT_TEST_FAILED);

	checkResult( pKLVLook->QueryInterface( IID_IAAFDefObject, reinterpret_cast<void**>(&pKLVDataDefObj) ) );
	assert(pKLVDataDefObj);
	
	//ensure the KLVLook auid is equal to KLVDef_TestData auid
	checkResult(pKLVDataDefObj->GetAUID(&auid));

	if(auid != KLVDef_TestData)
		checkResult(AAFRESULT_TEST_FAILED);

	//test LookUpTagged()
	if(pDic2->LookupTaggedValueDef(TAGDef_TestData, &pTAGDefLook) != AAFRESULT_SUCCESS)
		checkResult(AAFRESULT_TEST_FAILED);

	checkResult( pTAGDefLook->QueryInterface( IID_IAAFDefObject, reinterpret_cast<void**>(&pTaggedValueDefObj) ) );
	assert(pTaggedValueDefObj);
	
	//ensure the TAGDefLook auid is equal to TAGDef_TestData auid
	checkResult(pTaggedValueDefObj->GetAUID(&auid));

	if(auid != TAGDef_TestData)
		checkResult(AAFRESULT_TEST_FAILED);


	//cleanup	
	pDic2->Release();
	pDic2 = NULL;
	pKLVLook->Release();
	pKLVLook = NULL;
	pTAGDefLook->Release();
	pTAGDefLook = NULL;
	pKLVDataDefObj->Release();
	pKLVDataDefObj = NULL;
	pTaggedValueDefObj->Release();
	pTaggedValueDefObj = NULL;

	}

  catch (HRESULT& rResult)
	{
	  hr = rResult;
	}
	
  // Cleanup and return.
  if (pFile)
	{
	  pFile->Close();
	}
  return 	hr;
}