Beispiel #1
0
static HRESULT CreateAAFFile(const aafWChar * pFileName, testDataFile_t *dataFile, testType_t testType)
{
	IAAFFile*					pFile = NULL;
	IAAFHeader*					pHeader = NULL;
	IAAFDictionary*					pDictionary = NULL;
	IAAFMob*					pMob = NULL;
	IAAFMasterMob*				pMasterMob = NULL;
	IAAFEssenceAccess*			pEssenceAccess = NULL;
	IAAFEssenceFormat*			pFormat = NULL;
	IAAFEssenceFormat			*format = NULL;
	IAAFLocator					*pLocator = NULL;
	aafMobID_t					masterMobID;
	aafProductIdentification_t	ProductInfo;
	aafRational_t				editRate = {44100, 1};
	aafRational_t				sampleRate = {44100, 1};
	FILE*						pWavFile = NULL;
	unsigned char				dataBuff[4096], *dataPtr;
	aafUInt32					dataOffset, dataLen;
	aafUInt16					bitsPerSample, numCh;
	aafInt32					n, numSpecifiers;
	aafUID_t					essenceFormatCode, testContainer;
  IAAFClassDef *pMasterMobDef = NULL;
  IAAFClassDef *pNetworkLocatorDef = NULL;
  IAAFDataDef *pSoundDef = NULL;
  aafUInt32 samplesWritten, bytesWritten;


	// Delete any previous test file before continuing...
	char chFileName[1000];
	convert(chFileName, sizeof(chFileName), pFileName);
	remove(chFileName);
	if(dataFile != NULL)
	{
		// Delete any previous test file before continuing...
		char chFileName[1000];
		convert(chFileName, sizeof(chFileName), dataFile->dataFilename);
		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;

	/* Create a new AAF file */

	check(AAFFileOpenNewModifyEx (pFileName, &kAAFFileKind_Aaf4KBinary, 0, &ProductInfo, &pFile));
	check(pFile->GetHeader(&pHeader));
	
	/* Get the AAF Dictionary from the file */
	check(pHeader->GetDictionary(&pDictionary));
	
  /* Lookup class definitions for the objects we want to create. */
  check(pDictionary->LookupClassDef(AUID_AAFMasterMob, &pMasterMobDef));
  check(pDictionary->LookupClassDef(AUID_AAFNetworkLocator, &pNetworkLocatorDef));

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

	/* Create a Mastermob */
	
	// Get a Master MOB Interface
	check(pMasterMobDef->
		  CreateInstance(IID_IAAFMasterMob, 
						 (IUnknown **)&pMasterMob));
	// Get a Mob interface and set its variables.
	check(pMasterMob->QueryInterface(IID_IAAFMob, (void **)&pMob));
	check(pMob->GetMobID(&masterMobID));
	check(pMob->SetName(L"A Master Mob"));
	
	// Add it to the file 
	check(pHeader->AddMob(pMob));

	if(dataFile != NULL)
	{
		// Make a locator, and attach it to the EssenceDescriptor
		check(pNetworkLocatorDef->
			  CreateInstance(IID_IAAFLocator, 
							 (IUnknown **)&pLocator));		
		check(pLocator->SetPath (dataFile->dataFilename));
		testContainer = dataFile->dataFormat;
	}
	else
	{
		pLocator = NULL;
		testContainer = ContainerAAF;
	}


	// Open the Essence file to be included in this AAF file("Laser.wav")
	pWavFile = fopen("Laser.wav", "r");
	if (pWavFile)
	{
		// Read in the essence data
		int rc = fread(dataBuff, sizeof(unsigned char), sizeof(dataBuff), pWavFile);
		(void)rc;
		check(loadWAVEHeader(dataBuff,
										&bitsPerSample,
										&numCh,
										&sampleRate,
										&dataOffset,
										&dataLen));


		assert (numCh == 1, "Input file must be mono audio data");
		//  The testtype is for Internal Standard calls so set dataPtr
		dataPtr = dataBuff + dataOffset;
		
		/* Create the Essence Data specifying the codec, container, edit rate and sample rate */
		check(pMasterMob->CreateEssence(1,				// Slot ID
									pSoundDef,			// MediaKind
									kAAFCodecWAVE,			// codecID
									editRate,			// edit rate
									sampleRate,			// sample rate
									kAAFCompressionDisable,
									pLocator,			// In current file
									testContainer,		// In AAF Format
									&pEssenceAccess));	// Compress disabled

		check(pEssenceAccess->GetFileFormatParameterList (&format));
		check(format->NumFormatSpecifiers (&numSpecifiers));
		for(n = 0; n < numSpecifiers; n++)
		{
			check(format->GetIndexedFormatSpecifier (n, &essenceFormatCode, 0, NULL, NULL));
		}
		format->Release();
		format = NULL;

		// Tell the AAFEssenceAccess what the format is.
		check(pEssenceAccess->GetEmptyFileFormat (&pFormat));
		check(pFormat->NumFormatSpecifiers (&numSpecifiers));

		/* Set the properties that describe the essence data, such as audio sample size */
		
		aafInt32	sampleSize = bitsPerSample;
		check(pFormat->AddFormatSpecifier (kAAFAudioSampleBits, sizeof(sampleSize), (aafUInt8 *)&sampleSize));
		check(pEssenceAccess->PutFileFormat (pFormat));
		pFormat->Release();
		pFormat = NULL;
		
		/* Write the samples */

		aafInt32 samplesLeft = dataLen;
		aafUInt32 bytesPerSample = bitsPerSample/8;
		aafUInt32 samplesToWrite = 0;
		if (dataLen*bytesPerSample < (sizeof(dataBuff) - dataOffset))
			samplesToWrite = dataLen;
		else
			samplesToWrite  = (sizeof(dataBuff) - dataOffset)/bytesPerSample;

		//read input wav file in chunks and write them to Essence stream
		while (true) 
		{
			check(pEssenceAccess->WriteSamples(	samplesToWrite,	// Number of Samples
												sizeof(dataBuff), // buffer size
												dataPtr,	// THE data
												&samplesWritten,
												&bytesWritten));
			samplesLeft = samplesLeft-samplesToWrite;
			if (samplesLeft <= 0)
				break;
			
			aafUInt32 bytesToWrite = fread(dataBuff, sizeof(unsigned char), sizeof(dataBuff), pWavFile);
			samplesToWrite = bytesToWrite/bytesPerSample;
			dataPtr = dataBuff;
		}

		// Close the essence data file
		fclose(pWavFile);

		/* Set the essence to indicate that you have finished writing the samples */
		check(pEssenceAccess->CompleteWrite());

    pEssenceAccess->Release();
    pEssenceAccess = NULL;
	}
	else
	{
		printf("***Failed to open Wave file Laser.wav\n");
	}

	/* Release COM interfaces */

	pMob->Release();
	pMob = NULL;
	pMasterMob->Release();
	pMasterMob = NULL;

  pSoundDef->Release();
  pSoundDef = NULL;
  pNetworkLocatorDef->Release();
  pNetworkLocatorDef = NULL;
  pMasterMobDef->Release();
  pMasterMobDef = NULL;

	pDictionary->Release();
	pDictionary = NULL;
	pHeader->Release();
	pHeader = NULL;
	
	/* Save the AAF file */
	pFile->Save();
	
	/* Close the AAF file */
	pFile->Close();
	pFile->Release();
	pFile = NULL;


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

	if(format)
		format->Release();

	if(pLocator)
		pLocator->Release();

  if (pEssenceAccess)
		pEssenceAccess->Release();
	
	if (pMasterMob)
		pMasterMob->Release();

	if (pMob)
		pMob->Release();

  if (pSoundDef)
    pSoundDef->Release();

  if (pNetworkLocatorDef)
    pNetworkLocatorDef->Release();

  if (pMasterMobDef)
    pMasterMobDef->Release();

	if (pDictionary)
		pDictionary->Release();

	if (pHeader)
		pHeader->Release();

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


	return moduleErrorTmp;
}
Beispiel #2
0
static HRESULT CreateAAFFile(const aafWChar * pFileName, testDataFile_t *dataFile, testType_t /* testType */)
{
  IAAFFile*					pFile = NULL;
  IAAFHeader*					pHeader = NULL;
  IAAFDictionary*				pDictionary = NULL;
  IAAFMob*					pMob = NULL;
  IAAFMasterMob*				pMasterMob = NULL;
  IAAFClassDef*   pKLVDataCD=NULL;
  IAAFClassDef*   pCommentMarkerCD=NULL;
  IAAFTypeDef*    pUnknownBaseType=NULL;
  IAAFTypeDef*	pInt32BaseType=NULL;
  // IAAFTypeDef* pASCIIStringBaseType=NULL;
  IAAFKLVData* pKLVData=NULL;

  IAAFEssenceAccess*			pEssenceAccess = NULL;
  IAAFEssenceMultiAccess*		pMultiEssence = NULL;
  IAAFEssenceFormat*			pFormat = NULL;
  IAAFEssenceFormat*	format = NULL;
  IAAFLocator*	pLocator = NULL;
  IAAFClassDef*	pCDMasterMob = 0;
  IAAFClassDef                *pCDNetworkLocator = 0;
  IAAFDataDef                 *pDdefSound = 0;
  IAAFDataDef*	pDDefSceneDesc=0;
  IAAFEventMobSlot  *pEventSlot=0;
  IAAFMobSlot   *pSlot=0;
  IAAFSequence  *pSeqSceneDesc=0;
  IAAFSegment   *pSegment=0;
  IAAFEvent     *pEventSceneDesc=0;
  IAAFComponent *pComp=0;
  HRESULT	      hr = AAFRESULT_SUCCESS;


  // !!!Previous revisions of this file contained variables here required to handle external essence
  aafMobID_t					masterMobID;
  aafProductIdentification_t	ProductInfo;
  aafRational_t   editRate = {30000, 1001};
  aafRational_t	sampleRate = {44100, 1};
  aafRational_t	eventTimebase = {30000, 1001};
  aafPosition_t	position=0;
  FILE*	pWavFile = NULL;
  unsigned char	dataBuff[4096], *dataPtr;
  //	aafUInt32	bytesWritten;
  aafUInt32	dataOffset, dataLen;
  aafUInt16	bitsPerSample, numCh;
  aafInt32	n, numSpecifiers;
  aafUID_t	essenceFormatCode, testContainer;
  aafUInt32 samplesWritten, bytesWritten;
  // delete any previous test file before continuing...
  char chFileName[1000];
  convert(chFileName, sizeof(chFileName), pFileName);
  remove(chFileName);
  if(dataFile != NULL)
    {
      // delete any previous test file before continuing...
      char chFileName[1000];
      convert(chFileName, sizeof(chFileName), dataFile->dataFilename);
      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;

  check(AAFFileOpenNewModifyEx (pFileName, &kAAFFileKind_Aaf4KBinary, 0, &ProductInfo, &pFile));
  check(pFile->GetHeader(&pHeader));

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

  check(pDictionary->LookupClassDef(AUID_AAFMasterMob,
				    &pCDMasterMob));
  check(pDictionary->LookupClassDef(AUID_AAFNetworkLocator,
				    &pCDNetworkLocator));
  check(pDictionary->LookupDataDef(kAAFDataDef_Sound,
				   &pDdefSound));

  // !!!Previous revisions of this file contained code here required to handle external essence

  // Get a Master MOB Interface
  check(pCDMasterMob->
	CreateInstance(IID_IAAFMasterMob, 
		       (IUnknown **)&pMasterMob));
  // Get a Mob interface and set its variables.
  check(pMasterMob->QueryInterface(IID_IAAFMob, (void **)&pMob));
  check(pMob->GetMobID(&masterMobID));
  check(pMob->SetName(L"A Master Mob"));
	
  // Add it to the file 
  check(pHeader->AddMob(pMob));

  // !!!Previous revisions of this file contained code here required to handle external essence

  if(dataFile != NULL)
    {
      // Make a locator, and attach it to the EssenceDescriptor
      check(pCDNetworkLocator->
	    CreateInstance(IID_IAAFLocator, 
			   (IUnknown **)&pLocator));		
      check(pLocator->SetPath (dataFile->dataFilename));
      testContainer = dataFile->dataFormat;
    }
  else
    {
      pLocator = NULL;
      testContainer = ContainerAAF;
    }


  // open the Essence file to be included in this AAF file("Laser.wav")
  pWavFile = fopen("Laser.wav", "r");
  if (pWavFile)
    {
      // read in the essence data
      fread(dataBuff, sizeof(unsigned char), sizeof(dataBuff), pWavFile);
      check(loadWAVEHeader(dataBuff,
			   &bitsPerSample,
			   &numCh,
			   &sampleRate,
			   &dataOffset,
			   &dataLen));
      dataPtr = dataBuff + dataOffset;
      // now create the Essence data file
     check(pMasterMob->CreateEssence(1,				// Slot ID
				      pDdefSound,		// MediaKind
				      kAAFCodecWAVE,		// codecID
				      editRate,		// edit rate
				      sampleRate,		// sample rate
				      kAAFCompressionDisable,
				      pLocator,	// In current file
				      testContainer,	// In AAF Format
				      &pEssenceAccess));// Compress disabled

      check(pEssenceAccess->GetFileFormatParameterList (&format));
      check(format->NumFormatSpecifiers (&numSpecifiers));
      for(n = 0; n < numSpecifiers; n++)
	{
	  check(format->GetIndexedFormatSpecifier (n, &essenceFormatCode, 0, NULL, NULL));
	}
      format->Release();
      format = NULL;

      // Tell the AAFEssenceAccess what the format is.
      check(pEssenceAccess->GetEmptyFileFormat (&pFormat));
      check(pFormat->NumFormatSpecifiers (&numSpecifiers));

      aafInt32	sampleSize = bitsPerSample;
      check(pFormat->AddFormatSpecifier (kAAFAudioSampleBits, sizeof(sampleSize), (aafUInt8 *)&sampleSize));
      check(pEssenceAccess->PutFileFormat (pFormat));
      pFormat->Release();
      pFormat = NULL;
      // write out the data

      check(pEssenceAccess->WriteSamples( dataLen,//!!! hardcoded bytes/sample ==1// Number of Samples
						sizeof(dataBuff), // buffer size
						dataPtr,	// THE data
						&samplesWritten,
						&bytesWritten));

      // close essence data file
      fclose(pWavFile);
      pWavFile = NULL;
      // Finish writing the destination
      check(pEssenceAccess->CompleteWrite());
      pEssenceAccess->Release();
      pEssenceAccess=NULL;
      // First register DataDef for SceneDescription
      // Is SceneDescription in dictionary already
      // Try using Timecode for MC compat
      hr = pDictionary->LookupDataDef(kAAFDataDef_Timecode,
				      &pDDefSceneDesc);
      // hr = pDictionary->LookupDataDef(kAAFDataDef_SceneDescription,
      //					 &pDDefSceneDesc);
      if (hr != AAFRESULT_SUCCESS) 
	{
	  check(pDictionary->CreateInstance(AUID_AAFDataDef,IID_IAAFDataDef,
					    (IUnknown **)&pDDefSceneDesc));
	  check(pDDefSceneDesc->Initialize(kAAFDataDef_SceneDescription,
					   L"SceneDescEvent",L"DataDefinition for Scene Description Events"));
	  check(pDictionary->RegisterDataDef(pDDefSceneDesc));
	}

      // Add EventSlot to MasterMob

      // Create Slot
      check(pDictionary->CreateInstance(AUID_AAFEventMobSlot, IID_IAAFEventMobSlot,
					(IUnknown **)&pEventSlot));

      check(pEventSlot->SetEditRate(&eventTimebase));

      // Get the mob slot interface so that we can add the event segment.
      check(pEventSlot->QueryInterface(IID_IAAFMobSlot, (void **)&pSlot));
      pEventSlot->Release();
      pEventSlot = NULL;
      aafSlotID_t eventSlotID=5;
      check(pSlot->SetSlotID(eventSlotID));
      check(pSlot->SetName(L"SceneDescriptions"));

      // Set up Sequence for Scene Descriptors
      check(pDictionary->CreateInstance(AUID_AAFSequence,IID_IAAFSequence,
					(IUnknown **)&pSeqSceneDesc));
      check(pSeqSceneDesc->Initialize(pDDefSceneDesc));

      // Create first Comment Marker
      check(pDictionary->LookupClassDef(AUID_AAFCommentMarker,
					&pCommentMarkerCD));
      check(pCommentMarkerCD->CreateInstance(IID_IAAFEvent,
					     (IUnknown **)&pEventSceneDesc));
      position=0;
      check(pEventSceneDesc->SetPosition(position));
      check(pEventSceneDesc->SetComment(L"Racers heading up the hill"));
      check(pEventSceneDesc->QueryInterface(IID_IAAFComponent, (void **)&pComp));
      check(pComp->SetDataDef(pDDefSceneDesc));		
      // Add it to the sequence
      check(pSeqSceneDesc->AppendComponent(pComp));
      pComp->Release();
      pComp = NULL;
      pEventSceneDesc->Release();
      pEventSceneDesc=NULL;

      // Create second Comment Marker
      check(pCommentMarkerCD->CreateInstance(IID_IAAFEvent,
					     (IUnknown **)&pEventSceneDesc));
      position=100;
      check(pEventSceneDesc->SetPosition(position));
      check(pEventSceneDesc->SetComment(L"Racer pulls away from crowd"));
      check(pEventSceneDesc->QueryInterface(IID_IAAFComponent, (void **)&pComp));
      check(pComp->SetDataDef(pDDefSceneDesc));		
      // Add it to the sequence
      check(pSeqSceneDesc->AppendComponent(pComp));
      pComp->Release();
      pComp = NULL;
      pEventSceneDesc->Release();
      pEventSceneDesc=NULL;
      check(pSeqSceneDesc->QueryInterface(IID_IAAFSegment, (void **)&pSegment));

      // Create third Comment Marker
      check(pCommentMarkerCD->CreateInstance(IID_IAAFEvent,
					     (IUnknown **)&pEventSceneDesc));
      position=250;
      check(pEventSceneDesc->SetPosition(position));
      check(pEventSceneDesc->SetComment(L"Racer passes finish line"));
      check(pEventSceneDesc->QueryInterface(IID_IAAFComponent, (void **)&pComp));
      check(pComp->SetDataDef(pDDefSceneDesc));		
      // Add it to the sequence
      check(pSeqSceneDesc->AppendComponent(pComp));
      pComp->Release();
      pComp = NULL;
      pEventSceneDesc->Release();
      pEventSceneDesc=NULL;
      // Add the event sequence to the event mob slot
      // Sequence must have at least one component to ensure event mob slot is valid
      check(pSlot->SetSegment(pSegment));
      pSegment->Release();
      pSegment = NULL;

      // Append the event slot to the Master Mob
      check(pMob->AppendSlot(pSlot));

      // Add the KLV data to the Master Mob

      // Register the two KLVKeys
      check(pDictionary->LookupTypeDef(kAAFTypeID_UInt8Array,
				       &pUnknownBaseType));
      check(pDictionary->RegisterKLVDataKey(KLVKey_BinaryBlob1,
					    pUnknownBaseType));
      check(pDictionary->LookupTypeDef(kAAFTypeID_Int32,
				       &pInt32BaseType));
      check(pDictionary->RegisterKLVDataKey(KLVKey_Int32_1,
					    pInt32BaseType));
      // Next define new ASCII string data def
      // check(pDictionary->RegisterKLVDataKey(KLVKey_ASCIIString1,
      //				      pASCIIStringBaseType));

      // Get the KLVData ClassDefinition
      check(pDictionary->LookupClassDef(AUID_AAFKLVData,
					&pKLVDataCD));


      // Create KLVData and append it to Mob
      check(pKLVDataCD->CreateInstance(IID_IAAFKLVData, 
				       (IUnknown **)&pKLVData));
		
      check(pKLVData->Initialize(KLVKey_BinaryBlob1,
				 sizeof(blobData), (aafUInt8 *)blobData));
      check(pMob->AppendKLVData(pKLVData));
      pKLVData->Release();
      pKLVData=NULL;

      // Create KLVData and append it to Mob
      check(pKLVDataCD->CreateInstance(IID_IAAFKLVData, 
				       (IUnknown **)&pKLVData));
		
      check(pKLVData->Initialize(KLVKey_Int32_1,
				 sizeof(int32Data), (aafUInt8 *)&int32Data));
      check(pMob->AppendKLVData(pKLVData));
      pKLVData->Release();
      pKLVData=NULL;
    }
  else
    {
      printf("***Failed to open Wave file Laser.wav\n");
    }
  // Release all unnecesary interfaces

  if (pInt32BaseType)
    pInt32BaseType->Release();
  pInt32BaseType=NULL;
  if (pUnknownBaseType)
    pUnknownBaseType->Release();
  pUnknownBaseType=NULL;
  if (pKLVDataCD)
    pKLVDataCD->Release();
  pKLVDataCD=NULL;
  if (pCommentMarkerCD)
    pCommentMarkerCD->Release();
  pCommentMarkerCD=NULL;
  if(pComp)
    pComp->Release();
  pComp=NULL;
  if(pEventSceneDesc)
    pEventSceneDesc->Release();
  pEventSceneDesc=0;
  if(pSegment)
    pSegment->Release();
  pSegment=NULL;
  if(pSeqSceneDesc)
    pSeqSceneDesc->Release();
  pSeqSceneDesc=NULL;
  if(pSlot)
    pSlot->Release();
  pSlot=NULL;
  if(pEventSlot)
    pEventSlot->Release();
  pEventSlot=NULL;
  if(pDDefSceneDesc)
    pDDefSceneDesc->Release();
  pDDefSceneDesc=NULL;

  if(pMasterMob)
    pMasterMob->Release();
  pMasterMob = NULL;
  if(pMob)
    pMob->Release();
  pMob = NULL;

  if(pDictionary)
    pDictionary->Release();
  pDictionary = NULL;
  if(pHeader)
    pHeader->Release();
  pHeader = NULL;
  //!!!DebugOnly
  pFile->Save();
  pFile->Close();
  pFile->Release();
  pFile = NULL;
  if (pEssenceAccess)
    {	
      pEssenceAccess->Release();
      pEssenceAccess= NULL;
    }

 cleanup:
  // Cleanup and return
  if(pFormat)
    pFormat->Release();
  if(format)
    format->Release();
  if(pLocator)
    pLocator->Release();

  if (pWavFile)
    fclose(pWavFile);

  if (pEssenceAccess)
    pEssenceAccess->Release();
	
  if (pMultiEssence)
    pMultiEssence->Release();
	
  if (pMasterMob)
    pMasterMob->Release();

  if (pMob)
    pMob->Release();

  if (pDictionary)
    pDictionary->Release();

  if (pHeader)
    pHeader->Release();

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

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

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

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


  return moduleErrorTmp;
}
Beispiel #3
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;
}
Beispiel #4
0
// Create an AAF file to be used by module test.
AAFRESULT CreateTestFile(
    const aafCharacter*                 p_file_name,
    aafUID_constref                     file_kind,
    const testRawStorageType_t          raw_storage_type,
    aafUInt32                           file_mode_flags,
    aafProductIdentification_constref   product_identification,
    IAAFFile**                          pp_new_file )
{
  assert( p_file_name != 0 );
  assert( pp_new_file != 0 );


  //
  // Determine the file encoding to use.
  //
  aafUID_t use_file_kind = EffectiveTestFileEncoding( file_kind );


  //
  // Create a raw storage object if necessary.
  //
  AAFRESULT  hr = AAFRESULT_SUCCESS;
  IAAFRawStorage* p_raw_storage = 0;
  if( raw_storage_type == kAAFNamedFile )
  {
    p_raw_storage = 0;
    hr = AAFRESULT_SUCCESS;
  }
  else if( raw_storage_type == kAAFDiskRawStorage )
  {
    // Attempt to create an IAAFRawStorage object
    // of the specified type.
    hr = AAFCreateRawStorageDisk( p_file_name,
                                  kAAFFileExistence_new,
                                  kAAFFileAccess_modify,
                                  &p_raw_storage );
  }
  else if( raw_storage_type == kAAFCachedDiskRawStorage )
  {
    hr = AAFRESULT_NOT_IMPLEMENTED;
  }
  else if( raw_storage_type == kAAFMappedFileRawStorage )
  {
    hr = AAFRESULT_NOT_IMPLEMENTED;
  }
  else if( raw_storage_type == kAAFMemoryRawStorage )
  {
    hr = AAFRESULT_NOT_IMPLEMENTED;
  }
  else
  {
    // The raw storage type is not supported by the toolkit
    hr = AAFRESULT_INVALID_PARAM;
  }


  //
  // Create a file object.
  //
  if( hr == AAFRESULT_SUCCESS )
  {
    //
    // Create a file object.
    //
    IAAFFile*  p_file = 0;
    if( p_raw_storage != 0 )
    {
      // Use raw storage API to create a file.
      hr = AAFCreateAAFFileOnRawStorage( p_raw_storage,
                                         kAAFFileExistence_new,
                                         kAAFFileAccess_modify,
                                         &use_file_kind,
                                         file_mode_flags,
                                         &product_identification,
                                         &p_file );
      p_raw_storage->Release();
      p_raw_storage = 0;

      // Open the file.
      if( hr == AAFRESULT_SUCCESS )
      {
        hr = p_file->Open();

        if( hr != AAFRESULT_SUCCESS )
        {
          p_file->Release();
          p_file = 0;
        }
      }
    }
    else
    {
      // Use 'traditional' API to create a file.
      hr = AAFFileOpenNewModifyEx(
        p_file_name,
        &use_file_kind,
        file_mode_flags,
        const_cast<aafProductIdentification_t*>( &product_identification ),
        &p_file );
    }


    if( hr == AAFRESULT_SUCCESS )
    {
      assert( p_file != 0 );
      *pp_new_file = p_file;
    }
  }


  return hr;
}
Beispiel #5
0
int main(int argc, char *argv[])
{
    if (argc != 4 ||
            (strcmp(argv[1], "-xml") != 0 && strcmp(argv[1], "-ss") != 0))
    {
        Usage(argc, argv);
        exit(1);
    }


    aafCharacter *inFileName = new aafCharacter[strlen(argv[2]) + 1];
    aafCharacter *outFileName = new aafCharacter[strlen(argv[3]) + 1];

    size_t status = mbstowcs(inFileName, argv[2], strlen(argv[2]));
    if (status == (size_t)-1)
    {
        fprintf(stderr, "\nError: Failed to convert filename '%s' to a wide string.", argv[2]);
        exit(1);
    }
    status = mbstowcs(outFileName, argv[3], strlen(argv[3]));
    if (status == (size_t)-1)
    {
        fprintf(stderr, "\nError: Failed to convert filename '%s' to a wide string.", argv[3]);
        exit(1);
    }
    inFileName[strlen(argv[2])] = 0;
    outFileName[strlen(argv[3])] = 0;

    // remove the output file if it already exists
    remove(argv[3]);

    
    CAAFInitialize aafInit;
    IAAFFile* inFile = 0;
    IAAFFile* outFile = 0;

    check(AAFFileOpenExistingRead(inFileName, 0, &inFile));

    aafProductVersion_t v;
    v.major = 0;
    v.minor = 1;
    v.tertiary = 0;
    v.patchLevel = 0;
    v.type = kAAFVersionUnknown;

    const aafUID_t productUID = 
        {0x97e04c67, 0xdbe6, 0x4d11, {0xbc, 0xd7, 0x3a, 0x90, 0x42, 0x53, 0xa2, 0xef}};
    aafProductIdentification_t  productInfo;
	aafWChar companyName[] = L"AMW Association";
	aafWChar productName[] = L"aaffmtconv";
    productInfo.companyName = companyName;
    productInfo.productName = productName;
    productInfo.productVersion = &v;
    productInfo.productVersionString = 0;
    productInfo.productID = productUID;
    productInfo.platform = 0;

    // create output file based on choice of stored format
    if (strcmp(argv[1], "-xml") == 0)
    {
        check(AAFFileOpenNewModifyEx(outFileName, &kAAFFileKind_AafXmlText, 0, &productInfo, &outFile));
    }
    else
    {
        check(AAFFileOpenNewModify(outFileName, 0, &productInfo, &outFile));
    }

    // save copy using the selected stored format
    check(inFile->SaveCopyAs(outFile));
    
    check(outFile->Close());
    check(inFile->Close());

    outFile->Release();
    outFile = 0;
    inFile->Release();
    inFile = 0;

    delete [] inFileName;
    delete [] outFileName;

    return 0;
}