Exemplo n.º 1
0
static HRESULT CreateAAFFile(aafWChar * pFileName, long int N)
{
  IAAFFile*                   pFile = NULL;
  IAAFHeader*                 pHeader = NULL;
  IAAFDictionary*             pDictionary = NULL;
  IAAFMob*                    pMob = NULL;
  IAAFMob*                    pCompMob = NULL;
  IAAFEssenceDescriptor*      aDesc = NULL;
  IAAFMasterMob*              pMasterMob = NULL;
  IAAFSourceMob*              pFileMob = NULL;
  IAAFSourceMob*              pTapeMob = NULL;
  IAAFSequence*               pSequence = NULL;
  IAAFComponent*              aComponent = NULL;
  IAAFFileDescriptor*         pFileDesc = NULL;
  IAAFAIFCDescriptor*         pAIFCDesc = NULL;
  IAAFTapeDescriptor*         pTapeDesc = NULL;
  IAAFTimelineMobSlot*        newSlot = NULL;
  IAAFSegment*                seg = NULL;
  IAAFSourceClip*             fileSclp = NULL;
  IAAFSourceClip*             masterSclp = NULL;
  IAAFSourceClip*             compSclp = NULL;
  IAAFComponent*              compFill = NULL;
  IAAFLocator*                pLocator = NULL;
  IAAFNetworkLocator*         pNetLocator = NULL;
  IAAFClassDef *              pCDCompositionMob = 0;
  IAAFClassDef *              pCDSequence = 0;
  IAAFClassDef *              pCDSourceMob = 0;
  IAAFClassDef *              pCDTapeDescriptor = 0;
  IAAFClassDef *              pCDAIFCDescriptor = 0;
  IAAFClassDef *              pCDNetworkLocator = 0;
  IAAFClassDef *              pCDMasterMob = 0;
  IAAFClassDef *              pCDSourceClip = 0;
  IAAFClassDef *              pCDFiller = 0;
  IAAFDataDef *               pDdefPicture = 0;
  aafRational_t               videoRate = { 30000, 1001 };
  aafMobID_t                  tapeMobID, fileMobID, masterMobID;
  aafTimecode_t               tapeTC = { 108000, kAAFTcNonDrop, 30};
  aafLength_t                 fileLen = FILE1_LENGTH;
  aafLength_t                 fillLen = FILL_LENGTH;
  aafLength_t                 segLen = SEG_LENGTH;
  aafProductIdentification_t  ProductInfo;
  long int                    i = 0;

  moduleErrorTmp = S_OK;


  // delete any previous test file before continuing...
  char chFileName[1000];
  convert(chFileName, sizeof(chFileName), pFileName);
  remove(chFileName);

  aafProductVersion_t v;
  v.major = 1;
  v.minor = 0;
  v.tertiary = 0;
  v.patchLevel = 0;
  v.type = kAAFVersionUnknown;
  ProductInfo.companyName = companyName;
  ProductInfo.productName = productName;
  ProductInfo.productVersion = &v;
  ProductInfo.productVersionString = NULL;
  ProductInfo.productID = NIL_UID;
  ProductInfo.platform = NULL;

#if defined(USE_MEMORY_FILE)
  check(MemoryFileOpenNewModify (0, &ProductInfo, &pFile));
#else
  check(AAFFileOpenNewModifyEx (pFileName, &kAAFFileKind_Aaf4KBinary, 0, &ProductInfo, &pFile));
#endif

  check(pFile->GetHeader(&pHeader));

  // Get the AAF Dictionary so that we can create valid AAF objects.
  check(pHeader->GetDictionary(&pDictionary));

  check(pDictionary->LookupClassDef(AUID_AAFCompositionMob,
                                    &pCDCompositionMob));
  check(pDictionary->LookupClassDef(AUID_AAFSequence,
                                    &pCDSequence));
  check(pDictionary->LookupClassDef(AUID_AAFSourceMob,
                                    &pCDSourceMob));
  check(pDictionary->LookupClassDef(AUID_AAFTapeDescriptor,
                                    &pCDTapeDescriptor));
  check(pDictionary->LookupClassDef(AUID_AAFAIFCDescriptor,
                                    &pCDAIFCDescriptor));
  check(pDictionary->LookupClassDef(AUID_AAFNetworkLocator,
                                    &pCDNetworkLocator));
  check(pDictionary->LookupClassDef(AUID_AAFMasterMob,
                                    &pCDMasterMob));
  check(pDictionary->LookupClassDef(AUID_AAFSourceClip,
                                    &pCDSourceClip));
  check(pDictionary->LookupClassDef(AUID_AAFFiller,
                                    &pCDFiller));
  check(pDictionary->LookupDataDef(kAAFDataDef_Picture,
                                   &pDdefPicture));

// IMPORTANT: major remodification is from this point onwards...

  // sequence creation code pulled out of the subsequent loop.
  // Create a Composition Mob
  check(pCDCompositionMob->CreateInstance(IID_IAAFMob,
                                          (IUnknown **)&pCompMob));

  check(pCDSequence->CreateInstance(IID_IAAFSequence,
                                    (IUnknown **)&pSequence));
  check(pSequence->QueryInterface (IID_IAAFSegment, (void **)&seg));

  check(pSequence->QueryInterface(IID_IAAFComponent, (void **)&aComponent));

  check(aComponent->SetDataDef(pDdefPicture));
  aComponent->Release();
  aComponent = NULL;

  check(pCompMob->QueryInterface (IID_IAAFMob, (void **)&pMob));
  check(pMob->AppendNewTimelineSlot(videoRate, seg, i, slotName, 0, &newSlot));
  pMob->Release();
  pMob = NULL;
  newSlot->Release();
  newSlot = NULL;
  seg->Release();
  seg = NULL;

  check(pHeader->AddMob(pCompMob));


  // now looping around the remainder N times to make N components
  for (i=0; i < N; i++) {
    //Make the Tape MOB
    check(pCDSourceMob->CreateInstance(IID_IAAFSourceMob,
                                       (IUnknown **)&pTapeMob));
    check(pCDTapeDescriptor->CreateInstance(IID_IAAFTapeDescriptor,
                                            (IUnknown **)&pTapeDesc));
    check(pTapeDesc->QueryInterface (IID_IAAFEssenceDescriptor,
                                     (void **)&aDesc));
    check(pTapeMob->SetEssenceDescriptor(aDesc));
    aDesc->Release();
    aDesc = NULL;
    pTapeDesc->Release();
    pTapeDesc = NULL;

    check(pTapeMob->AppendTimecodeSlot (videoRate, 0, tapeTC, TAPE_LENGTH));
    check(pTapeMob->AddNilReference (1,TAPE_LENGTH, pDdefPicture, videoRate));
    check(pTapeMob->QueryInterface (IID_IAAFMob, (void **)&pMob));
    pTapeMob->Release();
    pTapeMob = NULL;


    // NOTE: TapeMob name is updated to change with number of objects
    // requested at cli.
    // In order to fit with the specification, it is made wide
    char TapeMobNameBuffer[MAX];
    sprintf(TapeMobNameBuffer,"Tape Mob %ld",i);
    aafWChar TapeMobName[MAX];
    mbstowcs(TapeMobName,TapeMobNameBuffer,MAX);

    check(pMob->SetName (TapeMobName));

    check(pHeader->AddMob(pMob));
    check(pMob->GetMobID (&tapeMobID));
    pMob->Release();
    pMob = NULL;

    // Make a FileMob
    check(pCDSourceMob->CreateInstance(IID_IAAFSourceMob,
                                       (IUnknown **)&pFileMob));
    check(pCDAIFCDescriptor->CreateInstance(IID_IAAFFileDescriptor,
                                            (IUnknown **)&pFileDesc));
    check(pFileDesc->QueryInterface (IID_IAAFEssenceDescriptor,
                                     (void **)&aDesc));
    check(pFileDesc->QueryInterface (IID_IAAFAIFCDescriptor,
                                     (void **)&pAIFCDesc));
    check(pAIFCDesc->SetSummary (5, (unsigned char*)"TEST"));
    pAIFCDesc->Release();
    pAIFCDesc = NULL;

    // Make a locator, and attach it to the EssenceDescriptor
    check(pCDNetworkLocator->CreateInstance(IID_IAAFNetworkLocator,
                                            (IUnknown **)&pNetLocator));
    check(pNetLocator->QueryInterface (IID_IAAFLocator, (void **)&pLocator));


    check(pLocator->SetPath (TEST_PATH));
    check(aDesc->AppendLocator(pLocator));
    pLocator->Release();
    pLocator = NULL;
    pNetLocator->Release();
    pNetLocator = NULL;


    check(pFileMob->SetEssenceDescriptor(aDesc));
    aDesc->Release();
    aDesc = NULL;
    pFileDesc->Release();
    pFileDesc = NULL;

    sourceRef.sourceID = tapeMobID;
    sourceRef.sourceSlotID = 1;
    sourceRef.startTime = 0;
    check(pFileMob->NewPhysSourceRef (videoRate, 1, pDdefPicture,
                                      sourceRef, fileLen));

    check(pFileMob->QueryInterface (IID_IAAFMob, (void **)&pMob));
    check(pMob->GetMobID (&fileMobID));
    check(pHeader->AddMob(pMob));
    pMob->Release();
    pMob = NULL;

    //Make the Master MOB
    check(pCDMasterMob->CreateInstance(IID_IAAFMasterMob,
                                       (IUnknown **)&pMasterMob));

    sourceRef.sourceID = fileMobID;
    sourceRef.sourceSlotID = 1;
    sourceRef.startTime = 0;
    check(pMasterMob->NewPhysSourceRef(videoRate, 1, pDdefPicture,
                                       sourceRef, fileLen));
    check(pMasterMob->QueryInterface (IID_IAAFMob, (void **)&pMob));
    check(pMob->GetMobID (&masterMobID));

    // NOTE: MasterMob name is updated to change with number of objects
    // requested at cli.
    // In order to fit with the specification, it is made wide
    char MasterMobNameBuffer[MAX];
    sprintf(MasterMobNameBuffer,"Master Mob %ld",i);
    aafWChar MasterMobName[MAX];
    mbstowcs(MasterMobName,MasterMobNameBuffer,MAX);

    check(pMob->SetName (MasterMobName));

    check(pHeader->AddMob(pMob));
    pMob->Release();
    pMob = NULL;

    // the remaining part of the sequence code, adapted for updating slot names


    // Create a SourceClip
    check(pCDSourceClip->CreateInstance(IID_IAAFSourceClip,
                                        (IUnknown **)&compSclp));

    sourceRef.sourceID = masterMobID;
    sourceRef.sourceSlotID = 1;
    sourceRef.startTime = 0;
    check(compSclp->SetSourceReference (sourceRef));
    check(compSclp->QueryInterface (IID_IAAFComponent, (void **)&aComponent));
    check(aComponent->SetDataDef(pDdefPicture));
    check(aComponent->SetLength (segLen));
    check(pSequence->AppendComponent (aComponent));

    // Create a filler - Get the component interface only (IID_IAAFComponent)
    check(pCDFiller->CreateInstance(IID_IAAFComponent,
                                    (IUnknown **)&compFill));

    check(compFill->SetLength (fillLen));

    check(compFill->SetDataDef(pDdefPicture));
    check(pSequence->AppendComponent (compFill));

    compFill->Release();
    compFill = NULL;

    aComponent->Release();
    aComponent = NULL;

    compSclp->Release();
    compSclp = NULL;

    pMasterMob->Release();
    pMasterMob = NULL;

    pFileMob->Release();
    pFileMob = NULL;

    //  end of loop since only one dictionary and header are needed
    //  the file is then saved, closed and released after all modifications
    //  are complete
  }


cleanup:
  // Cleanup and return
  if (pNetLocator)
    pNetLocator->Release();

  if (pLocator)
    pLocator->Release();

  if (compFill)
    compFill->Release();

  if (compSclp)
    compSclp->Release();

  if (masterSclp)
    masterSclp->Release();

  if (fileSclp)
    fileSclp->Release();

  if (pTapeDesc)
    pTapeDesc->Release();

  if (pFileDesc)
    pFileDesc->Release();

  if (pTapeMob)
    pTapeMob->Release();

  if (pFileMob)
    pFileMob->Release();

  if (pMasterMob)
    pMasterMob->Release();

  if (aDesc)
    aDesc->Release();

  if (newSlot)
    newSlot->Release();

  if (pMob)
    pMob->Release();


  if (pCompMob)
    pCompMob->Release();

  if (seg)
    seg->Release();

  if (aComponent)
    aComponent->Release();

  if (pSequence)
    pSequence->Release();

  if (pDictionary)
    pDictionary->Release();

  if (pHeader)
    pHeader->Release();

  if (pCDCompositionMob) {
    pCDCompositionMob->Release();
    pCDCompositionMob = 0;
  }

  if (pCDSequence) {
    pCDSequence->Release();
    pCDSequence = 0;
  }

  if (pCDSourceMob) {
    pCDSourceMob->Release();
    pCDSourceMob = 0;
  }

  if (pCDTapeDescriptor) {
    pCDTapeDescriptor->Release();
    pCDTapeDescriptor = 0;
  }

  if (pCDAIFCDescriptor) {
    pCDAIFCDescriptor->Release();
    pCDAIFCDescriptor = 0;
  }

  if (pCDNetworkLocator) {
    pCDNetworkLocator->Release();
    pCDNetworkLocator = 0;
  }

  if (pCDMasterMob) {
    pCDMasterMob->Release();
    pCDMasterMob = 0;
  }

  if (pCDSourceClip) {
    pCDSourceClip->Release();
    pCDSourceClip = 0;
  }

  if (pCDFiller) {
    pCDFiller->Release();
    pCDFiller = 0;
  }

  if (pDdefPicture) {
    pDdefPicture->Release();
    pDdefPicture = 0;
  }

  if (pFile) {
    clock_t start = clock();
    clock_t finish;
    double duration;

    pFile->Save();
    pFile->Close();

#if defined(USE_MEMORY_FILE)
    check(MemoryFileSaveToDisk(pFileName, pFile));
#endif
    finish = clock();
    duration = ((double) (finish - start) / CLOCKS_PER_SEC);

    pFile->Release();

    printf("Save time = %f seconds\n", duration);
  }

  return moduleErrorTmp;
}
Exemplo n.º 2
0
static HRESULT CreateAAFFile(
    aafWChar * pFileName,
    aafUID_constref fileKind,
    testRawStorageType_t rawStorageType,
    aafProductIdentification_constref productID)
{
	// IAAFSession 				*pSession = NULL;
	IAAFFile 					*pFile = NULL;
	IAAFHeader 					*pHeader = NULL;
	IAAFDictionary				*pDictionary = NULL;
	IAAFLocator					*pLocator = NULL;
	IAAFLocator					*pLocator2 = NULL;
	IAAFSourceMob 				*pSourceMob = NULL;
	IAAFMob						*pMob = NULL;
	IAAFEssenceDescriptor 		*edesc = NULL;
	IEnumAAFLocators			*pEnumLocators = NULL;
	aafUInt32					numLocators, numLocators2;
	aafUInt32					i;
	HRESULT						hr = AAFRESULT_SUCCESS,
								localhr = AAFRESULT_SUCCESS;
	bool bFileOpen = false;
//	aafUID_t					ddef = kAAFDataDef_Sound;

	try 
	{
	    // Remove the previous test file if any.
	  RemoveTestFile(pFileName);

	  // Create the file.
	  checkResult(CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile ));
	  bFileOpen = true;
 
	  // We can't really do anthing in AAF without the header.
	  checkResult(pFile->GetHeader(&pHeader));

	  // Get the AAF Dictionary so that we can create valid AAF objects.
	  checkResult(pHeader->GetDictionary(&pDictionary));
 		
	  CAAFBuiltinDefs defs (pDictionary);

		//Make the first mob
		// Create a Mob
		checkResult(defs.cdSourceMob()->
					CreateInstance(IID_IAAFSourceMob, 
								   (IUnknown **)&pSourceMob));
		
		// Initialize mob properties:
		checkResult(pSourceMob->QueryInterface (IID_IAAFMob, (void **)&pMob));
		checkResult(pMob->SetMobID(TEST_MobID));
		checkResult(pMob->SetName(L"EssenceDescriptorTest"));
		
		// Create the descriptor:
		// instantiate a concrete subclass of EssenceDescriptor
		checkResult(defs.cdAIFCDescriptor()->
					CreateInstance(IID_IAAFEssenceDescriptor, 
								   (IUnknown **)&edesc));		

		IAAFAIFCDescriptor*			pAIFCDesc = NULL;
		checkResult(edesc->QueryInterface (IID_IAAFAIFCDescriptor, (void **)&pAIFCDesc));
		checkResult(pAIFCDesc->SetSummary (5, (unsigned char*)"TEST"));
		pAIFCDesc->Release();
		pAIFCDesc = NULL;

		checkResult(pSourceMob->SetEssenceDescriptor (edesc));


/* CountLocators()	******************************************/
		localhr = AAFRESULT_SUCCESS;
		// Verify AAFRESULT_NULL_PARAM is returned
		if (edesc->CountLocators(NULL) != AAFRESULT_NULL_PARAM)
			localhr = AAFRESULT_TEST_FAILED;		
		
		// Verify that there are no locators
		if (edesc->CountLocators(&numLocators) != AAFRESULT_SUCCESS)
			localhr = AAFRESULT_TEST_FAILED;
		if (0 != numLocators)
			localhr = AAFRESULT_TEST_FAILED;
			
		if (localhr == AAFRESULT_SUCCESS)
			cout<< "	CountLocators() ...		Passed"<< endl;
		else
		{
			cout<< "	CountLocators() ...		FAILED"<< endl;
			hr = AAFRESULT_TEST_FAILED;
		}
		
/* AppendLocator()	******************************************/
		localhr = AAFRESULT_SUCCESS;
		// Verify AAFRESULT_NULL_PARAM is returned
		if (edesc->AppendLocator(NULL) != AAFRESULT_NULL_PARAM)
			localhr = AAFRESULT_TEST_FAILED;		

		// Append and Count a bunch of Locators
		for (i=1; i<=10; i++)
		{
			// Make a concrete subclass of locator, and attach it to
			// the EssenceDescriptor
			checkResult(defs.cdNetworkLocator()->
					CreateInstance(IID_IAAFLocator, 
								   (IUnknown **)&pLocator));	
								   	
			if (edesc->AppendLocator(pLocator) != AAFRESULT_SUCCESS)
				localhr = AAFRESULT_TEST_FAILED;

			// Verify the number of locators
			numLocators = 0;
			edesc->CountLocators(&numLocators);
			if (i != numLocators)
				localhr = AAFRESULT_TEST_FAILED;

			// Verify that locator was appended
			edesc->GetLocatorAt(i-1, &pLocator2);
			if (pLocator2 != pLocator)
				localhr = AAFRESULT_TEST_FAILED;

			pLocator->Release();
			pLocator = 0;
			pLocator2->Release();
			pLocator2 = 0;
		}

		// Make sure we can't add it again

//		if (edesc->AppendLocator(pLocator) != AAFRESULT_OBJECT_ALREADY_ATTACHED)

//			localhr = AAFRESULT_TEST_FAILED;


		if (localhr == AAFRESULT_SUCCESS)
			cout<< "	AppendLocator() ...		Passed"<< endl;
		else
		{
			cout<< "	AppendLocator() ...		FAILED"<< endl;
			hr = AAFRESULT_TEST_FAILED;
		}
			

/* PrependLocator()	******************************************/
		localhr = AAFRESULT_SUCCESS;
		// Verify AAFRESULT_NULL_PARAM is returned
		if (edesc->PrependLocator(NULL) != AAFRESULT_NULL_PARAM)
			localhr = AAFRESULT_TEST_FAILED;		

		for (; i<=20; i++)
		{
			// Make a concrete subclass of locator, and attach it to
			// the EssenceDescriptor
			checkResult(defs.cdNetworkLocator()->
					CreateInstance(IID_IAAFLocator, 
								   (IUnknown **)&pLocator));	
								   	
			if (edesc->PrependLocator(pLocator) != AAFRESULT_SUCCESS)
				localhr = AAFRESULT_TEST_FAILED;

			// Verify the number of locators
			numLocators = 0;
			edesc->CountLocators(&numLocators);
			if (i != numLocators)
				localhr = AAFRESULT_TEST_FAILED;
				
			// Verify that locator was prepended
			edesc->GetLocatorAt(0, &pLocator2);
			if (pLocator2 != pLocator)
				localhr = AAFRESULT_TEST_FAILED;

			pLocator->Release();
			pLocator = 0;
			pLocator2->Release();
			pLocator2 = 0;
		}

		if (localhr == AAFRESULT_SUCCESS)
			cout<< "	PrependLocator() ...	Passed"<< endl;
		else
		{
			cout<< "	PrependLocator() ...	FAILED"<< endl;
			hr = AAFRESULT_TEST_FAILED;
		}


/* InsertLocatorAt()	**************************************/
		localhr = AAFRESULT_SUCCESS;

		// Make a concrete subclass of locator to attach
		checkResult(defs.cdNetworkLocator()->
						CreateInstance(IID_IAAFLocator, 
				   			(IUnknown **)&pLocator));			

		// Verify that we can't remove an index value that is out of range
		if (edesc->InsertLocatorAt(numLocators+1, pLocator) != AAFRESULT_BADINDEX)
			localhr = AAFRESULT_TEST_FAILED;

		// Verify behavior when NULL is passed in
		if (edesc->InsertLocatorAt(1, NULL) != AAFRESULT_NULL_PARAM)
			localhr = AAFRESULT_TEST_FAILED;

		edesc->CountLocators(&numLocators);

		// Insert it
		if (edesc->InsertLocatorAt(0, pLocator) != AAFRESULT_SUCCESS)
			localhr = AAFRESULT_TEST_FAILED;
		// Check it
		edesc->GetLocatorAt(0, &pLocator2);
		if (pLocator2 != pLocator)
			localhr = AAFRESULT_TEST_FAILED;
		// Count it	
		edesc->CountLocators(&numLocators2);
		if (numLocators2 != numLocators+1)
			localhr = AAFRESULT_TEST_FAILED;

		pLocator->Release();
		pLocator = 0;
		pLocator2->Release();
		pLocator2 = 0;


		edesc->CountLocators(&numLocators);
		// Make a concrete subclass of locator to attach in the middle
		checkResult(defs.cdNetworkLocator()->
						CreateInstance(IID_IAAFLocator, 
				   			(IUnknown **)&pLocator));			
		// Insert it
		if (edesc->InsertLocatorAt(numLocators/2, pLocator) != AAFRESULT_SUCCESS)
			localhr = AAFRESULT_TEST_FAILED;
		// Check it
		edesc->GetLocatorAt(numLocators/2, &pLocator2);
		if (pLocator2 != pLocator)
			localhr = AAFRESULT_TEST_FAILED;
		// Count it	
		edesc->CountLocators(&numLocators2);
		if (numLocators2 != numLocators+1)
			localhr = AAFRESULT_TEST_FAILED;

		pLocator->Release();
		pLocator = 0;
		pLocator2->Release();
		pLocator2 = 0;


		edesc->CountLocators(&numLocators);
		// Make a concrete subclass of locator to attach to the end
		checkResult(defs.cdNetworkLocator()->
						CreateInstance(IID_IAAFLocator, 
				   			(IUnknown **)&pLocator));			
		// Insert it.  note: its 0 based so the end is numLocators - 1
		if (edesc->InsertLocatorAt(numLocators-1, pLocator) != AAFRESULT_SUCCESS)
			localhr = AAFRESULT_TEST_FAILED;
		// Check it
		edesc->GetLocatorAt(numLocators-1, &pLocator2);
		if (pLocator2 != pLocator)
			localhr = AAFRESULT_TEST_FAILED;
		// Count it	
		edesc->CountLocators(&numLocators2);
		if (numLocators2 != numLocators+1)
			localhr = AAFRESULT_TEST_FAILED;
			
		// Make sure we can't add it again
		if (edesc->InsertLocatorAt(numLocators+1, pLocator) != AAFRESULT_OBJECT_ALREADY_ATTACHED)
			localhr = AAFRESULT_TEST_FAILED;
		
		pLocator->Release();
		pLocator = 0;
		pLocator2->Release();
		pLocator2 = 0;


		if (localhr == AAFRESULT_SUCCESS)
			cout<< "	InsertLocatorAt() ...	Passed"<< endl;
		else
		{
			cout<< "	InsertLocatorAt() ...	FAILED"<< endl;
			hr = AAFRESULT_TEST_FAILED;
		}
			
			
/* GetLocatorAt()	******************************************/
		localhr = AAFRESULT_SUCCESS;
		edesc->CountLocators(&numLocators);
		// Verify that we can't remove an index value that is out of range
		// note: Locators index is 0 based so the index numLocators is out of range
		if (edesc->GetLocatorAt(numLocators, &pLocator) != AAFRESULT_BADINDEX)
			localhr = AAFRESULT_TEST_FAILED;

		// Verify behavior when NULL is passed in
		if (edesc->GetLocatorAt(1, NULL) != AAFRESULT_NULL_PARAM)
			localhr = AAFRESULT_TEST_FAILED;
			
		for (i=0; i<numLocators; i++)
		{
			pLocator = NULL;
			if (edesc->GetLocatorAt(i, &pLocator) != AAFRESULT_SUCCESS)
				localhr = AAFRESULT_TEST_FAILED;

			if (pLocator != NULL)
				pLocator->Release();
		}
			
		if (localhr == AAFRESULT_SUCCESS)
			cout<< "	GetLocatorAt() ...		Passed"<< endl;
		else
		{
			cout<< "	GetLocatorAt() ...		FAILED"<< endl;
			hr = AAFRESULT_TEST_FAILED;
		}


/* GetLocators()	******************************************/
		if (edesc->GetLocators(NULL) != AAFRESULT_NULL_PARAM)
			localhr = AAFRESULT_TEST_FAILED;	

		pEnumLocators = NULL;
		if (edesc->GetLocators(&pEnumLocators) == AAFRESULT_SUCCESS)
		{
			if (pEnumLocators != NULL)
			{	
				// Try a simple test to confirm
				if (pEnumLocators->NextOne(&pLocator) != AAFRESULT_SUCCESS)					
					localhr = AAFRESULT_TEST_FAILED;
				edesc->GetLocatorAt(0, &pLocator2);

				if (pLocator != pLocator2)
					localhr = AAFRESULT_TEST_FAILED;
				else
					pLocator2->Release();

				pLocator->Release();
				pLocator = 0;

				pEnumLocators->Release();
			}
			else
				localhr = AAFRESULT_TEST_FAILED;			
		}
		else	
			localhr = AAFRESULT_TEST_FAILED;

		if (localhr == AAFRESULT_SUCCESS)
			cout<< "	GetLocators() ...		Passed"<< endl;
		else
		{
			cout<< "	GetLocators() ...		FAILED"<< endl;
			hr = AAFRESULT_TEST_FAILED;
		}


		

/* RemoveLocatorAt()	******************************************/
		localhr = AAFRESULT_SUCCESS;

		// Verify that we can't remove an index value that is out of range
		// note: Locators index is 0 based so the index numLocators is out of range

		if (edesc->RemoveLocatorAt (numLocators) != AAFRESULT_BADINDEX)
			localhr = AAFRESULT_TEST_FAILED;
				
		// Remove locator at beginning, but Release it first
		edesc->CountLocators(&numLocators);

		edesc->GetLocatorAt(0, &pLocator);
		pLocator->Release();

		edesc->GetLocatorAt(1, &pLocator);
		if (edesc->RemoveLocatorAt (0) != AAFRESULT_SUCCESS)
			localhr = AAFRESULT_TEST_FAILED;

		// Verify the count
		edesc->CountLocators(&numLocators2);
		if (numLocators2 != (numLocators - 1))
			localhr = AAFRESULT_TEST_FAILED;

		edesc->GetLocatorAt(0, &pLocator2);
		// Verify that the locators shifted properly
		if (pLocator != pLocator2)
			localhr = AAFRESULT_TEST_FAILED;
		
		pLocator->Release();
		pLocator = 0;
		pLocator2->Release();
		pLocator2 = 0;

		// Remove locator in middle, but Release it first
		edesc->CountLocators(&numLocators);
		edesc->GetLocatorAt((numLocators/2), &pLocator);
		pLocator->Release();

		edesc->GetLocatorAt((numLocators/2 +1), &pLocator);
		if (edesc->RemoveLocatorAt (numLocators/2) != AAFRESULT_SUCCESS)
			localhr = AAFRESULT_TEST_FAILED;
		
		edesc->CountLocators(&numLocators2);
		if (numLocators2 != (numLocators - 1))
			localhr = AAFRESULT_TEST_FAILED;
		
		edesc->GetLocatorAt(numLocators/2, &pLocator2);
		// Verify that the locators shifted properly
		if (pLocator != pLocator2)
			localhr = AAFRESULT_TEST_FAILED;

		pLocator->Release();
		pLocator = 0;
		pLocator2->Release();
		pLocator2 = 0;


		// Remove locator at end, but Release it first
		edesc->CountLocators(&numLocators);
		edesc->GetLocatorAt(numLocators-1, &pLocator);
		pLocator->Release();

		edesc->GetLocatorAt(numLocators-2, &pLocator);
		if (edesc->RemoveLocatorAt (numLocators-1) != AAFRESULT_SUCCESS)
			localhr = AAFRESULT_TEST_FAILED;
		
		edesc->CountLocators(&numLocators2);
		if (numLocators2 != (numLocators - 1))
			localhr = AAFRESULT_TEST_FAILED;

		edesc->GetLocatorAt(numLocators2-1, &pLocator2);
		// Verify that the locators shifted properly
		if (pLocator != pLocator2)
			localhr = AAFRESULT_TEST_FAILED;

		pLocator->Release();
		pLocator = 0;
		pLocator2->Release();
		pLocator2 = 0;

		if (localhr == AAFRESULT_SUCCESS)
			cout<< "	RemoveLocatorAt() ...	Passed"<< endl;
		else
		{
			cout<< "	RemoveLocatorAt() ...	FAILED"<< endl;
			hr = AAFRESULT_TEST_FAILED;
		}

/*************************************************************/


	// Add the source mob into the tree
	checkResult(pHeader->AddMob(pMob));

	}
	catch (HRESULT& rResult)
	{
    hr = rResult;
	}


	// Cleanup object references
	if (edesc)
		edesc->Release();

	if (pMob)
		pMob->Release();

	if (pSourceMob)
		pSourceMob->Release();
	
	if (pDictionary)
		pDictionary->Release();

	if (pHeader)
		pHeader->Release();
			
	if (pFile)
	{	// Close file, clean-up and return
		if (bFileOpen)
		  {
			pFile->Save();
			pFile->Close();
		  }
 		pFile->Release();
	}

	return hr;
}
Exemplo n.º 3
0
static HRESULT CreateAAFFile(
    aafWChar * pFileName,
    aafUID_constref fileKind,
    testRawStorageType_t rawStorageType,
    aafProductIdentification_constref productID)
{
	IAAFFile *					pFile = NULL;
  bool bFileOpen = false;
	IAAFHeader *				pHeader = NULL;
  IAAFDictionary*  pDictionary = NULL;
	IAAFLocator	*				pLocator = NULL;
	IAAFNetworkLocator *		pNetLocator = NULL;
	IAAFSourceMob	*pSourceMob = NULL;
	IAAFMob			*pMob = NULL;
	IAAFEssenceDescriptor *edesc = NULL;
	aafUInt32					numLocators;
	HRESULT						hr = AAFRESULT_SUCCESS;


	try
	{
	    // Remove the previous test file if any.
	    RemoveTestFile(pFileName);


		// Create the file.
		checkResult(CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile ));
		bFileOpen = true;
 
		// We can't really do anthing in AAF without the header.
		checkResult(pFile->GetHeader(&pHeader));

		// Get the AAF Dictionary so that we can create valid AAF objects.
		checkResult(pHeader->GetDictionary(&pDictionary));
		CAAFBuiltinDefs defs (pDictionary);
 		
		//Make the first mob
		// Create a Mob
		checkResult(defs.cdSourceMob()->
					CreateInstance(IID_IAAFSourceMob, 
								   (IUnknown **)&pSourceMob));

		checkResult(pSourceMob->QueryInterface (IID_IAAFMob, (void **)&pMob));
		checkResult(pMob->SetMobID(TEST_MobID));
		checkResult(pMob->SetName(L"SourceMOBTest"));
		
		// Create a concrete subclass of EssenceDescriptor
		checkResult(defs.cdAIFCDescriptor()->
					CreateInstance(IID_IAAFEssenceDescriptor, 
								   (IUnknown **)&edesc));
										

		IAAFAIFCDescriptor*			pAIFCDesc = NULL;
		checkResult(edesc->QueryInterface (IID_IAAFAIFCDescriptor, (void **)&pAIFCDesc));
		checkResult(pAIFCDesc->SetSummary (5, (unsigned char*)"TEST"));
		pAIFCDesc->Release();
		pAIFCDesc = NULL;

			// Verify that there are no locators
		checkResult(edesc->CountLocators(&numLocators));
		checkExpression(0 == numLocators, AAFRESULT_TEST_FAILED);

  
		// Make a locator, and attach it to the EssenceDescriptor
		checkResult(defs.cdNetworkLocator()->
					CreateInstance(IID_IAAFNetworkLocator, 
								   (IUnknown **)&pNetLocator));		
		checkResult(pNetLocator->QueryInterface (IID_IAAFLocator, (void **)&pLocator));

		checkResult(pLocator->SetPath (TEST_PATH));
		
		checkResult(edesc->AppendLocator(pLocator));
 		checkResult(pSourceMob->SetEssenceDescriptor (edesc));

		// Verify that there is now one locator
		checkResult(edesc->CountLocators(&numLocators));
		checkExpression(1 == numLocators, AAFRESULT_TEST_FAILED);

		// Add the source mob into the tree
		checkResult(pHeader->AddMob(pMob));

	}
  catch (HRESULT& rResult)
  {
    hr = rResult;
  }

	// cleanup
	if (pLocator)
		pLocator->Release();

	if (pNetLocator)
		pNetLocator->Release();

	if (edesc)
		edesc->Release();

	if (pMob)
		pMob->Release();

	if (pSourceMob)
		pSourceMob->Release();

  if (pDictionary)
    pDictionary->Release();

	if (pHeader)
		pHeader->Release();

	if (pFile)
	{
		if (bFileOpen)
		  {
			pFile->Save();
			pFile->Close();
		  }
		pFile->Release();
	}
	// hr = pSession->EndSession();
 	// if (AAFRESULT_SUCCESS != hr)
	//	return hr;

	// if (pSession) pSession->Release();


	return hr;
}