Beispiel #1
0
static HRESULT ReadAAFFile(aafWChar * pFileName)
{
    // IAAFSession *				pSession = NULL;
	IAAFFile *					pFile = NULL;
	bool						bFileOpen = false;
	IAAFHeader *				pHeader = NULL;
	IAAFDictionary*				pDictionary = NULL;
	IEnumAAFMobs*				pMobIter = NULL;
	IEnumAAFMobSlots*			pEnum = NULL;
	IAAFMob*					pMob = NULL;
	IAAFMobSlot*				pMobSlot = NULL;
	IAAFSegment*				pSegment = NULL;
	IAAFSequence*				pSequence = NULL;
	IAAFTransition*				pTransition = NULL;
	IAAFComponent*				pComponent = NULL;
	IAAFFiller*					pFiller = NULL;
	IAAFOperationGroup*					pOperationGroup = NULL;
	IEnumAAFComponents*			pCompIter = NULL;
	aafLength_t					transitionLength;
	aafPosition_t				cutPoint;

	aafNumSlots_t				numMobs;
	aafUInt32					numComponents = 0;
	HRESULT						hr = S_OK;

	try
	{
		// Open the file
		checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile));
		bFileOpen = true;
 
		// We can't really do anthing in AAF without the header.
		checkResult(pFile->GetHeader(&pHeader));

		// Get the number of mobs in the file (should be one)
		checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs));
		checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED);

		checkResult(pHeader->GetMobs( NULL, &pMobIter));
		while (AAFRESULT_SUCCESS == pMobIter->NextOne(&pMob))
		{
			checkResult(pMob->GetSlots (&pEnum));

			while (AAFRESULT_SUCCESS == pEnum->NextOne (&pMobSlot))
			{
				checkResult(pMobSlot->GetSegment (&pSegment));
				// Check to see if Segment is a Sequence
				checkResult(pSegment->QueryInterface(IID_IAAFSequence, (void **) &pSequence));
				// It is, so get a Component Iterator
				checkResult(pSequence->CountComponents(&numComponents));
				// Verify that all 3 components(Filler, Transition, Filler) are present
				checkExpression(numComponents == 3,  AAFRESULT_TEST_FAILED);
				checkResult(pSequence->GetComponents(&pCompIter));
				// Now visit each and every one of the components.
				while(AAFRESULT_SUCCESS == pCompIter->NextOne(&pComponent))
				{
					// Find out what kind of segment we have
					if ((pComponent->QueryInterface(IID_IAAFTransition, (void **)&pTransition)) == AAFRESULT_SUCCESS)
					{
						// This is the transition 
						checkResult(pTransition->GetCutPoint (&cutPoint));
						checkResult(pComponent->GetLength(&transitionLength));
						checkResult(pTransition->GetOperationGroup(&pOperationGroup));
						// Check results !!
						checkExpression(cutPoint == 0, AAFRESULT_TEST_FAILED);
						checkExpression(transitionLength == 100, AAFRESULT_TEST_FAILED);
						pTransition->Release();
						pTransition = NULL;
					}
					else
					{
						// validate that the other segments are Fillers
						checkResult(pComponent->QueryInterface(IID_IAAFFiller, (void **)&pFiller));
						pFiller->Release();
						pFiller = NULL;
					}
					pComponent->Release();
					pComponent = NULL;
				}
				pSegment->Release();
				pSegment = NULL;
				pSequence->Release();
				pSequence = NULL;
				pCompIter->Release();
				pCompIter = NULL;
			}

			pMob->Release();
			pMob = NULL;
		}
	}
	catch (HRESULT& rResult)
	{
		hr = rResult;
	}
	

	// Cleanup and return
	if (pTransition)
		pTransition->Release();

	if (pOperationGroup)
		pOperationGroup->Release();

	if (pComponent)
		pComponent->Release();

	if (pSegment)
		pSegment->Release();

	if (pMobSlot)
		pMobSlot->Release();

	if (pSequence)
		pSequence->Release();

	if (pCompIter)
		pCompIter->Release();

	if (pEnum)
		pEnum->Release();

	if (pFiller)
		pFiller->Release();

	if (pMob)
		pMob->Release();

	if (pMobIter)
		pMobIter->Release();

	if (pDictionary)
		pDictionary->Release();

	if (pHeader)
		pHeader->Release();

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

	return hr;
}
static HRESULT ProcessAAFFile(const aafWChar * pFileName, testType_t testType)
{
	IAAFFile *					pFile = NULL;
	IAAFHeader *				pHeader = NULL;
	IAAFDictionary*				pDictionary = NULL;
	IEnumAAFMobs*				pMobIter = NULL;
	aafNumSlots_t				numMobs, numSlots;
	aafSearchCrit_t				criteria;
	aafMobID_t					mobID;
	aafWChar					namebuf[1204];
	const aafWChar*				slotName = L"A slot in Composition Mob";
	IAAFComponent*				pComponent = NULL;
	IAAFComponent*				aComponent = NULL;
	IEnumAAFMobSlots*			pMobSlotIter = NULL;
	IAAFMobSlot*				pMobSlot = NULL;
	IAAFTimelineMobSlot*		newSlot = NULL;
	IAAFSegment*				seg = NULL;
	IAAFSegment*				pSegment = NULL;
	IAAFMob*					pCompMob = NULL;
	IAAFMob*					pMob = NULL;
	aafPosition_t				zeroPos = 0;
	IAAFSequence*				pAudioSequence = NULL;
	IAAFSourceClip*				pSourceClip = NULL;
	aafLength_t					duration;
	IAAFTimelineMobSlot* pTimelineMobSlot = NULL;
  IAAFClassDef *pCompositionMobDef = NULL;
  IAAFClassDef *pSequenceDef = NULL;
  IAAFClassDef *pSourceClipDef = NULL;
  IAAFDataDef *pSoundDef = NULL;
  IAAFDataDef *pDataDef = NULL;
	

	// Set the edit rate information
	aafRational_t				editRate;
	editRate.numerator = 48000;
	editRate.denominator = 1;

	// Set search condition to true
	bool lookingForAudio = true;

	// Call the routine (from ExportAudioExample) to make the file for processing
	check(CreateAAFFile(pwFileName, NULL, testStandardCalls, &pFile));

	/* Get the Header and iterate through the Master Mobs in the existing file */
	check(pFile->GetHeader(&pHeader));
	check(pHeader->GetDictionary(&pDictionary));

	
  /* Lookup class definitions for the objects we want to create. */
  check(pDictionary->LookupClassDef(AUID_AAFCompositionMob, &pCompositionMobDef));
  check(pDictionary->LookupClassDef(AUID_AAFSequence, &pSequenceDef));
  check(pDictionary->LookupClassDef(AUID_AAFSourceClip, &pSourceClipDef));

  /* Lookup any necessary data definitions. */
  check(pDictionary->LookupDataDef(kAAFDataDef_Sound, &pSoundDef));
  

	// Get the number of master mobs in the existing file (must not be zero)
	check(pHeader->CountMobs(kAAFMasterMob, &numMobs));
	if (numMobs != 0)
	{
		printf("Found %d Master Mobs\n", numMobs);
		criteria.searchTag = kAAFByMobKind;
		criteria.tags.mobKind = kAAFMasterMob;
		check(pHeader->GetMobs(&criteria, &pMobIter));

		/* Create a Composition Mob */
		check(pCompositionMobDef->
			  CreateInstance(IID_IAAFMob,
							 (IUnknown **)&pCompMob));
		/* Append the Mob to the Header */
		check(pHeader->AddMob(pCompMob));
 
		/* Create a TimelineMobSlot with an audio sequence */
		check(pSequenceDef->
			  CreateInstance(IID_IAAFSequence,
							 (IUnknown **)&pAudioSequence));
		check(pAudioSequence->QueryInterface(IID_IAAFSegment, (void **)&seg));

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

		check(aComponent->SetDataDef(pSoundDef));
		check(pCompMob->AppendNewTimelineSlot(editRate, seg, 1, slotName, zeroPos, &newSlot));
    seg->Release();
    seg = NULL;
    newSlot->Release();
    newSlot = NULL;

		// This variable is about to be overwritten so we need to release the old interface
		aComponent->Release();
		aComponent = NULL;

		while((AAFRESULT_SUCCESS == pMobIter->NextOne(&pMob)))
		{
			//  Print out information about the Mob
			char mobIDstr[256];
			char mobName[256];

			check(pMob->GetMobID (&mobID));
			check(pMob->GetName (namebuf, sizeof(namebuf)));
			convert(mobName, sizeof(mobName), namebuf);
			MobIDtoString(mobID, mobIDstr);
			printf("    MasterMob Name = '%s'\n", mobName);
			printf("        (mobID %s)\n", mobIDstr);
			
			// Add a Source Clip for each Master Mob to the audio sequence by iterating
			check(pMob->GetSlots(&pMobSlotIter));
			
			/* Iterating through all Mob Slots */
			// Get the number of slots
			check(pMob->CountSlots(&numSlots));
			
			while (lookingForAudio && (AAFRESULT_SUCCESS == pMobSlotIter->NextOne(&pMobSlot)));
			{
				/* Check to see if it is an Audio Timeline Mob Slot */
				HRESULT hr;
				
				hr=pMobSlot->QueryInterface(IID_IAAFTimelineMobSlot,(void **) &pTimelineMobSlot);
				if (SUCCEEDED(hr))
				{
					printf("Found a timeline mob slot\n");
					check(pMobSlot->GetDataDef(&pDataDef));
					
					// Check that we have a sound file by examining its data definition
          aafBool bIsSoundKind = kAAFFalse;
          check(pDataDef->IsSoundKind(&bIsSoundKind));

          if (kAAFTrue == bIsSoundKind)
					{
						printf("Found a sound file\n");

						// We are no longer looking for audio data so set boolean	
						lookingForAudio = false;

						/* Get the information for the new source clip */
						check(pMob->GetMobID(&sourceRef.sourceID));
						check(pMobSlot->GetSlotID(&sourceRef.sourceSlotID));
						check(pTimelineMobSlot->GetOrigin(&sourceRef.startTime));
						check(pMobSlot->GetSegment(&pSegment));
						check(pSegment->QueryInterface(IID_IAAFComponent, (void **)&pComponent));
						check(pComponent->GetLength(&duration));
            pComponent->Release();
            pComponent = NULL;
            pSegment->Release();
            pSegment = NULL;
						
						// this loop is to be removed upon fixing of the bug
						// in essenceaccess relating to codec definitions...
						int j = 0;
						for (j=0; j<10; j++)
						{
							/* Create a new Source Clip */
							check(pSourceClipDef->
								  CreateInstance(IID_IAAFSourceClip,
												 (IUnknown **)&pSourceClip));
							// Initialize the Source Clip
							check(pSourceClip->Initialize( pSoundDef, duration, sourceRef));
							check(pSourceClip->QueryInterface(IID_IAAFComponent, (void **) &pComponent));
							check(pAudioSequence->AppendComponent(pComponent));
              pComponent->Release();
              pComponent = NULL;
							pSourceClip->Release();
							pSourceClip = NULL;
						}
					}
					pTimelineMobSlot->Release();
					pTimelineMobSlot = NULL;

          pDataDef->Release();
          pDataDef = NULL;
				}	
        
        pMobSlot->Release();
        pMobSlot = NULL;
			}

      pMobSlotIter->Release();
      pMobSlotIter = NULL;
		  pMob->Release();
		  pMob = NULL;
		}
		

    pAudioSequence->Release();
    pAudioSequence = NULL;

    pCompMob->Release();
    pCompMob = NULL;

		pMobIter->Release();
		pMobIter = NULL;
	}
	else
	{
		printf("Error with file: File has no Master mobs.\n");
	}

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

  if (pComponent)
    pComponent->Release();

  if (pSegment)
    pSegment->Release();

  if (pTimelineMobSlot)
    pTimelineMobSlot->Release();

  if (pMobSlotIter)
    pMobSlotIter->Release();

  if (pMob)
    pMob->Release();

  if (newSlot)
    newSlot->Release();

  if (aComponent)
    aComponent->Release();

  if (seg)
    seg->Release();

  if (pAudioSequence)
    pAudioSequence->Release();

  if (pCompMob)
    pCompMob->Release();

  if (pMobIter)
		pMobIter->Release();

  if (pDataDef)
    pDataDef->Release();

  if (pSoundDef)
    pSoundDef->Release();

  if (pSourceClipDef)
    pSourceClipDef->Release();

  if (pSequenceDef)
    pSequenceDef->Release();

  if (pCompositionMobDef)
    pCompositionMobDef->Release();

	if (pDictionary)
		pDictionary->Release();

	if (pHeader)
		pHeader->Release();

	if (pFile) 
	{
	  /* Save the AAF file */
    pFile->Save();
	  /* Close the AAF file */
		pFile->Close();
		pFile->Release();
	}

	return moduleErrorTmp;
}