Esempio n. 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;
}
Esempio n. 2
0
static void ReadAAFFile(aafWChar * pFileName)
{
    HRESULT hr = S_OK;
    IAAFFile * pFile = NULL;

    hr = AAFFileOpenExistingRead (pFileName, AAF_FILE_MODE_LAZY_LOADING, &pFile);
    if (SUCCEEDED(hr))
    {
        IAAFHeader * pHeader = NULL;

        hr = pFile->GetHeader(&pHeader);
        check(hr); // display error message
        if (SUCCEEDED(hr))
        {
            IAAFIdentification *    pIdent = NULL;

            hr = pHeader->GetLastIdentification(&pIdent);
            check(hr); // display error message
            if (SUCCEEDED(hr))
            {
                printIdentification(pIdent);

                pIdent->Release();
                pIdent = NULL;

                // count Mobs
                aafNumSlots_t n;
                hr = pHeader->CountMobs(kAAFAllMob, &n);
                check(hr);
                printf("\nNumber of Mobs       = %d\n", n);

                // Header::Version, Header::ObjectModelVersion
                aafVersionType_t version = {0};
                check(pHeader->GetFileRevision (&version) );
                printf("\nHeader::Version      = %d.%d\n", version.major, version.minor);

                aafFileRev_t fileVersion = kAAFRev1;
                check(pFile->GetRevision (&fileVersion) );
                printf("\nHeader::ObjectModelVersion = %d", fileVersion);

                if (fileVersion == kAAFRev1)
                    printf(" (recognized as kAAFRev1)\n");
                else if (fileVersion == kAAFRev2)
                    printf(" (recognized as kAAFRev2)\n");
                else
                    printf("\n");

                // Show datadefs, with version
                IEnumAAFDataDefsSP pEnumDataDef;
                IAAFDictionarySP pDictionary;
                check(pHeader->GetDictionary(&pDictionary));
                check(pDictionary->GetDataDefs(&pEnumDataDef));
                IAAFDataDef* pDataDef;

                printf("\nDatadefs             = ");
                while (SUCCEEDED(pEnumDataDef->NextOne(&pDataDef)))
                {
                    IAAFDefObjectSP pDefObject;
                    check(pDataDef->QueryInterface(IID_IAAFDefObject, (void**)&pDefObject));
                    pDataDef->Release();
                    pDataDef = NULL;

                    aafUID_t id = {0};
                    check(pDefObject->GetAUID(&id));

                    aafWChar wchName[500];
                    char chName[1000];
                    check( pDefObject->GetName(wchName, sizeof (wchName)) );
                    convert(chName, sizeof(chName), wchName);

                    if (memcmp( &id, &kAAFDataDef_LegacyPicture, sizeof(id)) == 0)
                        printf("\"%s\" (recognized as legacy Picture)\n", chName);
                    else if (memcmp( &id, &kAAFDataDef_Picture, sizeof(id)) == 0)
                        printf("\"%s\" (recognized as Picture)\n", chName);
                    else if (memcmp( &id, &kAAFDataDef_LegacySound, sizeof(id)) == 0)
                        printf("\"%s\" (recognized as legacy Sound)\n", chName);
                    else if (memcmp( &id, &kAAFDataDef_Sound, sizeof(id)) == 0)
                        printf("\"%s\" (recognized as Sound)\n", chName);
                    else if (memcmp( &id, &kAAFDataDef_LegacyTimecode, sizeof(id)) == 0)
                        printf("\"%s\" (recognized as legacy Timecode)\n", chName);
                    else if (memcmp( &id, &kAAFDataDef_Timecode, sizeof(id)) == 0)
                        printf("\"%s\" (recognized as Timecode)\n", chName);
                    else if (memcmp( &id, &kAAFDataDef_PictureWithMatte, sizeof(id)) == 0)
                        printf("\"%s\" (recognized as PictureWithMatte)\n", chName);
                    else if (memcmp( &id, &kAAFDataDef_Edgecode, sizeof(id)) == 0)
                        printf("\"%s\" (recognized as Edgecode)\n", chName);
                    else if (memcmp( &id, &kAAFDataDef_Auxiliary, sizeof(id)) == 0)
                        printf("\"%s\" (recognized as Auxiliary)\n", chName);
                    else if (memcmp( &id, &kAAFDataDef_DescriptiveMetadata, sizeof(id)) == 0)
                        printf("\"%s\" (recognized as DescriptiveMetadata)\n", chName);
                    else if (memcmp( &id, &kAAFDataDef_Matte, sizeof(id)) == 0)
                        printf("\"%s\" (recognized as Matte)\n", chName);
                    else
                        printf("\"%s\"\n", chName);
                    printf("                       ");
                }

                // Check if file contains TypeDefs known to cause a v1.0 reader to assert.
                // Known instances of this are UInt32Set and AUIDSet added to the v1.1 SDK.
                // Cannot use Dictionary::LookupTypeDef to check for them, because this
                // has the side effect of registering the typedef we are checking for
                // from the built-in model. Instead, iterate through typedefs (in file)
                // and check for the known instances.
                printf("\nTypes incompatible with SDK v1.0.x =");
                IEnumAAFTypeDefsSP pEnumTypeDef;
                check(pDictionary->GetTypeDefs(&pEnumTypeDef));
                IAAFTypeDef* pTypeDef;
                bool foundToxic = false;
                while (SUCCEEDED(pEnumTypeDef->NextOne(&pTypeDef)))
                {
                    IAAFMetaDefinitionSP pMetaDef;
                    check(pTypeDef->QueryInterface(IID_IAAFMetaDefinition, (void**)&pMetaDef));
                    pTypeDef->Release();
                    pTypeDef = NULL;

                    aafUID_t typeUID;
                    check(pMetaDef->GetAUID(&typeUID));

                    aafWChar wchName[500];
                    char chName[1000];
                    check( pMetaDef->GetName(wchName, sizeof (wchName)) );
                    convert(chName, sizeof(chName), wchName);

                    if ((memcmp( &typeUID, &kAAFTypeID_AUIDSet, sizeof(typeUID)) == 0)
                            || (memcmp( &typeUID, &kAAFTypeID_UInt32Set, sizeof(typeUID)) == 0))
                    {
                        printf(" %s", chName);
                        foundToxic = true;
                    }
                }
                if (!foundToxic)
                    printf(" (none)");
                printf("\n\n");

            }
            pHeader->Release();
            pHeader = NULL;
        }

        hr = pFile->Close();
        check(hr);

        pFile->Release();
        pFile = NULL;

        // Get file kind.
        // Since AAF SDK v1.0.2, the file kind actually identifies the implementation
        // of the file kind, from which the file kind is inferred.
        aafUID_t fileKind = {0};
        aafBool isAAFFile = kAAFFalse;

        check(AAFFileIsAAFFile(pFileName, &fileKind, &isAAFFile));
        if (isAAFFile)
        {
            if (memcmp( &fileKind, &kAAFFileKind_AafM512Binary, sizeof(fileKind)) == 0)
                printf("Filekind             = 512-byte SS (reading with Microsoft)\n");
            else if (memcmp( &fileKind, &kAAFFileKind_AafS512Binary, sizeof(fileKind)) == 0)
                printf("Filekind             = 512-byte SS (reading with Schemasoft)\n");
            else if (memcmp( &fileKind, &kAAFFileKind_AafG512Binary, sizeof(fileKind)) == 0)
                printf("Filekind             = 512-byte SS (reading with GSF)\n");
            else if (memcmp( &fileKind, &kAAFFileKind_Aaf512Binary, sizeof(fileKind)) == 0)
                printf("Filekind             = 512-byte SS (reading with default implementation)\n");
            else if (memcmp( &fileKind, &kAAFFileKind_AafM4KBinary, sizeof(fileKind)) == 0)
                printf("Filekind             = 4096-byte SS (reading with Microsoft)\n");
            else if (memcmp( &fileKind, &kAAFFileKind_AafS4KBinary, sizeof(fileKind)) == 0)
                printf("Filekind             = 4096-byte SS (reading with Schemasoft)\n");
            else if (memcmp( &fileKind, &kAAFFileKind_AafG4KBinary, sizeof(fileKind)) == 0)
                printf("Filekind             = 4096-byte SS (reading with GSF)\n");
            else if (memcmp( &fileKind, &kAAFFileKind_Aaf4KBinary, sizeof(fileKind)) == 0)
                printf("Filekind             = 4096-byte SS (reading with default implementation)\n");
            else
                printf("Filekind             = Recognized by SDK but unknown to AAFInfo\n");
        }
    }
    else
    {
        fprintf(stderr, "Error : Failed to open file (result = %0x).\n", hr);
        exit(1);
    }
}
Esempio n. 3
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;
}
Esempio n. 4
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;
}
Esempio n. 5
0
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;
}
Esempio n. 6
0
static HRESULT OpenAAFFile(aafWChar * pFileName)
{
	IAAFFile*					pFile = NULL;
	IAAFHeader*					pHeader = NULL;
	IAAFDictionary*				pDictionary = NULL;
	IAAFMob*					pMob = NULL;
	IAAFEssenceAccess*			pEssenceAccess = NULL;
	IAAFEssenceFormat*			pFormat = NULL;
	IEnumAAFMobs*				pMobIter = NULL;
	aafNumSlots_t				numMobs, numSlots;
	aafSearchCrit_t				criteria;
	aafMobID_t					mobID;
	IAAFDataDef					*pSoundDef = NULL;
	IAAFMobSlot*				pMobSlot = NULL;


	// Open an AAF file
	check(AAFFileOpenExistingRead (pFileName, 0, &pFile));
	check(pFile->GetHeader(&pHeader));

	// Open raw audio output file
	FILE		*output;
	const char	*output_file = "raw.pcm";

	if ((output = fopen(output_file, "wb")) == NULL)
	{
		perror(output_file);
		exit(1);
	}

	// Get the AAF Dictionary from the file
	check(pHeader->GetDictionary(&pDictionary));

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

	/* Check number of Mobs in file */
	check(pHeader->CountMobs(kAAFMasterMob, &numMobs));
	if (numMobs == 0)
	{
		printf("No Master Mobs found in AAF file\n");
		return 0;
	}

	printf("Found %d Master Mobs\n", numMobs);
	criteria.searchTag = kAAFByMobKind;
	criteria.tags.mobKind = kAAFMasterMob;
	check(pHeader->GetMobs(&criteria, &pMobIter));

	while (AAFRESULT_SUCCESS == pMobIter->NextOne(&pMob))
	{
		char mobIDstr[256];
		aafWChar	namebuf[1204];
		IAAFTimelineMobSlot* pTimelineMobSlot = NULL;
		IAAFDataDef *pDataDef = NULL;
		IAAFEssenceFormat			*fmtTemplate =  NULL;
		unsigned char *dataBuff = NULL;

		IEnumAAFMobSlots* pMobSlotIter = NULL;


		check(pMob->GetMobID (&mobID));
		check(pMob->GetName (namebuf, sizeof(namebuf)));
		MobIDtoString(mobID, mobIDstr);
		printf("    MasterMob Name = '%ls'\n", namebuf);
		printf("        (mobID %s)\n", mobIDstr);
		
		// Get the number of slots
		check(pMob->CountSlots(&numSlots));
		
		// Iterating through all Mob Slots

		check(pMob->GetSlots(&pMobSlotIter));
		while(AAFRESULT_SUCCESS == pMobSlotIter->NextOne(&pMobSlot))
		{
			// Check to see if it is an Audio Timeline Mob Slot
			HRESULT hr;
			aafUInt32 MobSlotID;
	
			hr=pMobSlot->QueryInterface(IID_IAAFTimelineMobSlot,(void **) &pTimelineMobSlot);
			if (SUCCEEDED(hr))
			{
				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)
				{
					IAAFMasterMob*			pMasterMob = NULL;

					// Prepare to get audio data: first get MobSlotID
					check(pMobSlot->GetSlotID(&MobSlotID));
	
					// Then get a Master Mob interface
					check(pMob->QueryInterface(IID_IAAFMasterMob, (void **)&pMasterMob));
					
					// Open the Essence Data
					check(pMasterMob->OpenEssence(MobSlotID,
											 	  NULL,	
												  kAAFMediaOpenReadOnly,
												  kAAFCompressionDisable, 
												  &pEssenceAccess));
					
					// Get the information about the format of the audio data.
					// The pFormat object must be setup with each specifier you
					// wish to access, otherwise you get AAFRESULT_FORMAT_NOT_FOUND.
					aafUInt32			audioSampleBits;
					aafRational_t		sampleRate;
					aafUInt32			numChannels;
					aafUInt32			maxSampleBytes;

					check(pEssenceAccess->GetEmptyFileFormat(&fmtTemplate));
					check(fmtTemplate->AddFormatSpecifier(kAAFAudioSampleBits, 0, NULL));
					check(fmtTemplate->AddFormatSpecifier(kAAFSampleRate, 0, NULL));
					check(fmtTemplate->AddFormatSpecifier(kAAFNumChannels, 0, NULL));
					check(fmtTemplate->AddFormatSpecifier(kAAFMaxSampleBytes, 0, NULL));
					check(pEssenceAccess->GetFileFormat(fmtTemplate, &pFormat));

					fmtTemplate->Release();
					fmtTemplate = NULL;
					
					aafInt32 fmtBytesRead;
					check(pFormat->GetFormatSpecifier(kAAFAudioSampleBits, sizeof(audioSampleBits),
									(aafDataBuffer_t)&audioSampleBits, &fmtBytesRead));
					check(pFormat->GetFormatSpecifier(kAAFSampleRate, sizeof(sampleRate),
									(aafDataBuffer_t)&sampleRate, &fmtBytesRead));
					check(pFormat->GetFormatSpecifier(kAAFNumChannels, sizeof(numChannels),
									(aafDataBuffer_t)&numChannels, &fmtBytesRead));
					check(pFormat->GetFormatSpecifier(kAAFMaxSampleBytes, sizeof(maxSampleBytes),
									(aafDataBuffer_t)&maxSampleBytes, &fmtBytesRead));

					pFormat->Release();
					pFormat = NULL;
			
					// Get the sample count which is in terms of EditRate
					aafLength_t sampleCount;
					check(pEssenceAccess->CountSamples(pSoundDef, &sampleCount));

					printf("\tSlotID %u: SampleBits=%d SampleRate=%d/%d NumChannels=%d MaxSampleBytes=%u\n",
								MobSlotID,
								audioSampleBits, sampleRate.numerator, sampleRate.denominator,
								numChannels, maxSampleBytes);
			
					printf("\t\tCountSamples=%"AAFFMT64"d\n", sampleCount);
	
					// Set a suitable buffer size						
					dataBuff = new unsigned char[maxSampleBytes];
	
					// Read samples until no more are available
					aafUInt32	samplesRead, actualBytesRead, total_samples = 0;
					while (true)
					{
						hr = (pEssenceAccess->ReadSamples(
										1, 					// number of samples to read
										maxSampleBytes,		// maximum buffer size
										dataBuff,			// output buffer for audio data
										&samplesRead,		// number of samples read
										&actualBytesRead));	// number of bytes read
						if (hr == AAFRESULT_EOF)
							break;
						else
							check(hr);
	
						if (actualBytesRead!=0)
						{
							total_samples += samplesRead;

							// Write out samples
							if ( fwrite(dataBuff, maxSampleBytes, 1, output) != 1 )
							{
								perror(output_file);
								return 1;
							}
						} 
					}
					printf("\tTotal samples = %u (written to %s)\n", total_samples, output_file);
					
					delete [] dataBuff;
					dataBuff = NULL;
					
					pEssenceAccess->Release();
					pEssenceAccess = NULL;
					pMasterMob->Release();
					pMasterMob = NULL;
				}
	
				pTimelineMobSlot->Release();
				pTimelineMobSlot = NULL;
	
				pDataDef->Release();
				pDataDef = NULL;
			}	
	
			pMobSlot->Release();
			pMobSlot = NULL;
		}
	
		pMobSlotIter->Release();
		pMobSlotIter = NULL;
	
		pMob->Release();
		pMob = NULL;
	}

	pMobIter->Release();
	pMobIter = NULL;

	return moduleErrorTmp;
}
Esempio n. 7
0
static HRESULT OpenAAFFile(aafWChar * pFileName, bool comp_enable)
{
	IAAFFile*					pFile = NULL;
	IAAFHeader*					pHeader = NULL;
	IAAFDictionary*				pDictionary = NULL;
	IAAFMob*					pMob = NULL;
	IAAFEssenceAccess*			pEssenceAccess = NULL;
	IEnumAAFMobs*				pMobIter = NULL;
	aafNumSlots_t				numMobs, numSlots;
	aafSearchCrit_t				criteria;
	aafMobID_t					mobID;
	IAAFDataDef					*pPictureDef = NULL;
	IAAFMobSlot*				pMobSlot = NULL;


	// Open an AAF file
	check(AAFFileOpenExistingRead (pFileName, 0, &pFile));
	check(pFile->GetHeader(&pHeader));

	// Open raw video output file
	FILE		*output;
	const char	*output_file = comp_enable ? "raw.uyvy" : "raw.mjpeg";

	if ((output = fopen(output_file, "wb")) == NULL)
	{
		perror(output_file);
		exit(1);
	}

	// Get the AAF Dictionary from the file
	check(pHeader->GetDictionary(&pDictionary));

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

	/* Check number of Mobs in file */
	check(pHeader->CountMobs(kAAFMasterMob, &numMobs));
	if (numMobs == 0)
		return 0;

	printf("Found %d Master Mobs\n", numMobs);
	criteria.searchTag = kAAFByMobKind;
	criteria.tags.mobKind = kAAFMasterMob;
	check(pHeader->GetMobs(&criteria, &pMobIter));

	while (AAFRESULT_SUCCESS == pMobIter->NextOne(&pMob))
	{
		char mobIDstr[256];
		char mobName[256];
		aafWChar	namebuf[1204];
		IAAFTimelineMobSlot* pTimelineMobSlot = NULL;
		IAAFDataDef *pDataDef = NULL;

		IEnumAAFMobSlots* pMobSlotIter = NULL;


		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);
		
		// Get the number of slots
		check(pMob->CountSlots(&numSlots));
		
		// Iterating through all Mob Slots

		check(pMob->GetSlots(&pMobSlotIter));
		while(AAFRESULT_SUCCESS == pMobSlotIter->NextOne(&pMobSlot))
		{
			// Check to see if it is a Video Timeline Mob Slot
			HRESULT hr;
	
			hr = pMobSlot->QueryInterface(IID_IAAFTimelineMobSlot,(void **) &pTimelineMobSlot);
			if (FAILED(hr))
			{
				pMobSlot->Release();
				pMobSlot = NULL;
				continue;
			}

			check(pMobSlot->GetDataDef(&pDataDef));

			// Check that we have a picture data def
			aafBool bIsPictureKind = kAAFFalse;
			check(pDataDef->IsPictureKind(&bIsPictureKind));

			if (kAAFTrue != bIsPictureKind)
			{
				pTimelineMobSlot->Release();
				pTimelineMobSlot = NULL;

				pDataDef->Release();
				pDataDef = NULL;
				continue;			// skip non-picture data defs
			}

			aafUInt32 MobSlotID;
			IAAFMasterMob*			pMasterMob = NULL;

			// Prepare to get video data: first get MobSlotID
			check(pMobSlot->GetSlotID(&MobSlotID));

			// Then get a Master Mob interface
			check(pMob->QueryInterface(IID_IAAFMasterMob, (void **)&pMasterMob));
			
			printf("    Opening slot %d with %s\n", MobSlotID, comp_enable ? "CompressionEnable" : "CompressionDisable");

			// Open the Essence Data
			check(pMasterMob->OpenEssence(MobSlotID,
									 	  NULL,	
										  kAAFMediaOpenReadOnly,
										  comp_enable ? kAAFCompressionEnable : kAAFCompressionDisable, 
										  &pEssenceAccess));

			// First put the codec into YUV pixel format
			IAAFEssenceFormat*	pSetFormat = NULL;
			aafInt32			YUV_pixel = kAAFColorSpaceYUV;
			check(pEssenceAccess->GetEmptyFileFormat(&pSetFormat));
			check(pSetFormat->AddFormatSpecifier(kAAFPixelFormat, 4, (unsigned char *) &YUV_pixel));
			check(pEssenceAccess->PutFileFormat(pSetFormat));
			pSetFormat->Release();

			// Get the information about the format of the video data.
			// The pFormat object must be setup with each specifier you
			// wish to access, otherwise you get AAFRESULT_FORMAT_NOT_FOUND.
			aafRational_t		sampleRate;
			aafUInt32			maxSampleSize;
			aafRect_t			storedRect;
			aafFrameLayout_t	frameLayout;

			IAAFEssenceFormat			*fmtTemplate =  NULL;
			IAAFEssenceFormat*			pFormat = NULL;
			check(pEssenceAccess->GetEmptyFileFormat (&fmtTemplate));
			check(fmtTemplate->AddFormatSpecifier(kAAFSampleRate, 0, NULL));
			check(fmtTemplate->AddFormatSpecifier(kAAFMaxSampleBytes, 0, NULL));
			check(fmtTemplate->AddFormatSpecifier(kAAFStoredRect, 0, NULL));
			check(fmtTemplate->AddFormatSpecifier(kAAFFrameLayout, 0, NULL));
			check(pEssenceAccess->GetFileFormat(fmtTemplate, &pFormat));

			fmtTemplate->Release();
			fmtTemplate = NULL;
			
			aafInt32 fmtBytesRead;
			check(pFormat->GetFormatSpecifier(kAAFSampleRate, sizeof(sampleRate),
							(aafDataBuffer_t)&sampleRate, &fmtBytesRead));
			check(pFormat->GetFormatSpecifier(kAAFMaxSampleBytes, sizeof(maxSampleSize),
							(aafDataBuffer_t)&maxSampleSize, &fmtBytesRead));
			check(pFormat->GetFormatSpecifier(kAAFStoredRect, sizeof(storedRect),
							(aafDataBuffer_t)&storedRect, &fmtBytesRead));
			check(pFormat->GetFormatSpecifier(kAAFFrameLayout, sizeof(frameLayout),
							(aafDataBuffer_t)&frameLayout, &fmtBytesRead));

			pFormat->Release();
			pFormat = NULL;
	
			// Get the sample count which is in terms of EditRate
			aafLength_t sampleCount;
			check(pEssenceAccess->CountSamples(pPictureDef, &sampleCount));

			const char *frameLayoutStr = "";
			switch (frameLayout)
			{
				case kAAFFullFrame: frameLayoutStr = "FullFrame"; break;
				case kAAFOneField: frameLayoutStr = "OneField"; break;
				case kAAFSeparateFields: frameLayoutStr = "SeparateFields"; break;
				case kAAFMixedFields: frameLayoutStr = "MixedFields"; break;
				default: break;
			}
			printf("\tSlotID %u: SampleRate=%d/%d MaxSampleBytes=%u StoredRect=%dx%d\n",
						MobSlotID, sampleRate.numerator, sampleRate.denominator,
						maxSampleSize, storedRect.xSize, storedRect.ySize);
	
			printf("\t\tFrameLayout=%s CountSamples=%"AAFFMT64"d\n", frameLayoutStr, sampleCount);

			// Buffer to receive samples from ReadSamples
			aafUInt8 *dataBuf = new aafUInt8[maxSampleSize];

			// Buffer to recombine separated fields into interleaved fields
			aafUInt8 *recombined_buf = new aafUInt8[maxSampleSize];

			// Read samples until no more are available
			aafUInt32	samplesRead, actualBytesRead, total_samples = 0;
			while (true)
			{
				hr = (pEssenceAccess->ReadSamples(
								1, 					// number of samples to read
								maxSampleSize,		// maximum buffer size
								dataBuf,			// output buffer for audio data
								&samplesRead,		// number of samples read
								&actualBytesRead));	// number of bytes read
				if (hr == AAFRESULT_EOF)
					break;
				else
					check(hr);

				aaf_assert(actualBytesRead != 0, "actualBytesRead != 0");

				total_samples += samplesRead;

				aafUInt8* saveBuf = dataBuf;
				if (comp_enable && frameLayout == kAAFSeparateFields) {
					// recombine fields into uncompressed frame when decompressing
					recombine_fields(dataBuf, recombined_buf, storedRect.xSize, storedRect.ySize);
					saveBuf = recombined_buf;
				}

				// Write out video
				if ( fwrite(saveBuf, maxSampleSize, 1, output) != 1 )
				{
					perror(output_file);
					return 1;
				}
			}
			printf("\tTotal samples=%u - written to %s\n", total_samples, output_file);
			
			delete [] dataBuf;
			delete [] recombined_buf;

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

	pMobIter->Release();
	pMobIter = NULL;

	return moduleErrorTmp;
}
Esempio n. 8
0
static HRESULT CreateAAFFile(aafWChar * pFileName, bool comp_enable)
{
	IAAFFile*					pFile = NULL;
	IAAFHeader*					pHeader = NULL;
	IAAFHeader2*				pHeader2 = NULL;
	IAAFDictionary*				pDictionary = NULL;
	IAAFMob*					pMob = NULL;
	IAAFMasterMob*				pMasterMob = NULL;
	IAAFEssenceAccess*			pEssenceAccess = NULL;
	aafMobID_t					masterMobID;
	aafProductIdentification_t	ProductInfo;
	IAAFClassDef				*pCDMasterMob = NULL;
	IAAFDataDef					*pPictureDef = NULL;
	aafUInt32					samplesWritten, bytesWritten;


	// Delete any previous test file before continuing...
	char cFileName[FILENAME_MAX];
	convert(cFileName, sizeof(cFileName), pFileName);
	remove(cFileName);

	cout << "Creating file " << cFileName << " using WriteSamples with " <<
		(comp_enable ? "CompressionEnable" : "CompressionDisable") << endl;

	aafProductVersion_t ver = {1, 0, 0, 0, kAAFVersionBeta};
	ProductInfo.companyName = const_cast<wchar_t *>(L"none");
	ProductInfo.productName = const_cast<wchar_t *>(L"AAF SDK");
	ProductInfo.productVersion = &ver;
	ProductInfo.productVersionString = const_cast<wchar_t *>(L"1.0.0.0 Beta");
	ProductInfo.productID = NIL_UID;
	ProductInfo.platform = NULL;		// Set by SDK when saving

	// select the file kind
	const aafUID_t*			fileKind = &kAAFFileKind_DontCare;
	if( FormatMXF )			fileKind = &kAAFFileKind_AafKlvBinary;
	else if( FormatSS512 )	fileKind = &kAAFFileKind_Aaf512Binary;
	else					fileKind = &kAAFFileKind_Aaf4KBinary;

	// Create a new AAF file
	check(AAFFileOpenNewModifyEx(pFileName, fileKind, 0, &ProductInfo, &pFile));
	check(pFile->GetHeader(&pHeader));

	// Set the operational pattern
	check(pHeader->QueryInterface(IID_IAAFHeader2, (void **)&pHeader2));
	check(pHeader2->SetOperationalPattern(kAAFOpDef_Atom));

	// 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, &pCDMasterMob));

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

	/* Create a Mastermob */

	// 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));
	if (input_video == NULL)
	{
		check(pMob->SetName(L"DNX_color_bars"));
	}
	else
	{
		check(pMob->SetName(pFileName));
	}

	// Add Mobs to the Header
	check(pHeader->AddMob(pMob));

	/* Create the Essence Data specifying the codec, container, edit rate and sample rate */
	check(pMasterMob->CreateEssence(
		1,			// Slot ID within MasterMob
		pPictureDef,			// MediaKind
		UseDNX? kAAFCodecDNxHD : kAAFCodecVC3,			// codecID
		editRate,				// edit rate
		editRate,				// sample rate
		comp_enable ? kAAFCompressionEnable : kAAFCompressionDisable,
		NULL,					// No Locator used
		ContainerAAF,			// Essence embedded in AAF file
		&pEssenceAccess));		//

	// Set the codec flavour for desired video format
	switch(ComprID)
	{
	case 1235:
		pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1235 );
		break;
	case 1238:
		pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1238 );
		break;
	case 1237:
		pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1237 );
		break;
	case 1241:
		pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1241 );
		break;
	case 1243:
		pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1243 );
		break;
	case 1244:
		pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1244 );
		break;
	case 1242:
		pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1242 );
		break;
	case 1250:
		pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1250 );
		break;
	case 1251:
		pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1251 );
		break;
	case 1252:
		pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1252 );
		break;
	case 1253:
		pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1253 );
		break;
	default:
		break;
	}

	switch( input_type )
	{
	case P_UYVY:
	case BarsUYVY:
	default:
		layout = UseDNX?Layout_P_UYVY:Layout_UYVYM;
		break;

	case UYVY:
		layout = UseDNX?Layout_UYVY:Layout_Unknown;
		break;

	case BGRAI:
	case BarsRGB:
		layout = UseDNX?Layout_BGRAI:Layout_Unknown;
		break;

	case BGRA:
		layout = UseDNX?Layout_BGRA:Layout_Unknown;
		break;
	}

	// Set up the information about the format of the data
	IAAFEssenceFormat *  fmtTemplate=NULL;
	check(pEssenceAccess->GetEmptyFileFormat (&fmtTemplate));
	
	if( UseLegacyUIDs )
		check(fmtTemplate->AddFormatSpecifier (kAAFLegacyAUIDs, sizeof(UseLegacyUIDs), (aafDataBuffer_t)&UseLegacyUIDs));

	if( UseDNX )
		check(fmtTemplate->AddFormatSpecifier (kAAFNumThreads, sizeof(nCodecThreads), (aafDataBuffer_t)&nCodecThreads));

	if( UseDNX )
		check(fmtTemplate->AddFormatSpecifier (kAAFBufferLayout, sizeof(layout), (aafDataBuffer_t)&layout));

	// codec will automatically SetEssenceKey() for MXF if !UseLegacyUIDs
	// codec will automatically SetEssenceKey() for Avid legacy if UseLegacyUIDs

	// future: if other kAAFEssenceElementKey, set it here

	// future: if other kAAFPhysicalTrackNum, set it here

	// Put the format specifiers into the codec
	check(pEssenceAccess->PutFileFormat( fmtTemplate ));

	// For fun, print the name of the selected codec flavour
	aafWChar codec_name[128] = L"";
	check(pEssenceAccess->GetCodecName(sizeof(codec_name), codec_name));
	printf("  using codec flavour \"%ls\"\n", codec_name);

	// Write the video samples
	int total_samples = 0;
	if( input_type==Raw )
	{
		// Read one frame of raw VC3 video at a time, repeat last frame until end
		FILE * ip=fopen( input_video,"rb" );
		if(!ip) return false;

		aafUInt32  nwant = GetBytesPerEditUnit(ComprID); 
		unsigned char* raw_buff = new unsigned char [ nwant ];

		size_t nread=0;

		while( Duration-- )
		{
			// keep on trying to read
			if( !feof( ip ) ) nread=fread( raw_buff, 1, nwant, ip );

			// abandon if partial frame (complete frame or zero is ok
			if ( nread!=nwant && nread!= 0 ) { perror(input_video); break; }

			samplesWritten=0;
			check(pEssenceAccess->WriteSamples(1, nwant, raw_buff, &samplesWritten, &bytesWritten));
			total_samples += samplesWritten;
		}
		delete[] raw_buff;
		fclose( ip );
	}
	else if( input_type==P_UYVY || input_type==UYVYI || input_type==UYVYM )
	{
		// Load a single frame of uncompressed
		aafUInt32  nwant = GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1)*(GetPixelsPerLine(ComprID)/2)*(UseDNX?5:8); 
	
		unsigned char* video_buffer = new unsigned char [ nwant ];

		// int LoadXYUV( BufferLayout_t target, byte *video_buffer, int len, int H, int V, const char *input_video, 
		//				 bool isLittleEndian=true, bool isBigEndian=false, bool isP_UYVY=false );

		LoadXYUV( UseDNX?Layout_P_UYVY:Layout_UYVYM, 
			      video_buffer, nwant, 
				  GetPixelsPerLine(ComprID), GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1), 
				  input_video,
				  input_type==UYVYI, input_type==UYVYM, input_type==P_UYVY );

		while( Duration-- )
		{
			samplesWritten=0;
			check(pEssenceAccess->WriteSamples(1, nwant, video_buffer, &samplesWritten, &bytesWritten));
			total_samples += samplesWritten;
		}
		delete[] video_buffer;
	}
	else if( input_type==UYVY )
	{
		// Load a single frame of uncompressed
		aafUInt32  nwant = GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1)*(GetPixelsPerLine(ComprID)/2)*(UseDNX?4:8); 
	
		unsigned char* video_buffer = new unsigned char [ nwant ];

		// int LoadXYUV( BufferLayout_t target, byte *video_buffer, int len, int H, int V, const char *input_video, 
		//				 bool isLittleEndian=true, bool isBigEndian=false, bool isP_UYVY=false );

		LoadXYUV( UseDNX?Layout_UYVY:Layout_UYVYM, 
			      video_buffer, nwant, 
				  GetPixelsPerLine(ComprID), GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1), 
				  input_video,
				  false, false, false );

		while( Duration-- )
		{
			samplesWritten=0;
			check(pEssenceAccess->WriteSamples(1, nwant, video_buffer, &samplesWritten, &bytesWritten));
			total_samples += samplesWritten;
		}
		delete[] video_buffer;
	}
	else if( input_type==BGRAI )
	{
		// never get here with VC3Codec

		// Load a single frame of uncompressed
		aafUInt32  nwant = GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1)*GetPixelsPerLine(ComprID)*8; 
	
		unsigned char* video_buffer = new unsigned char [ nwant ];

		// int LoadXRGB( BufferLayout_t target, byte *video_buffer, int len, int H, int V, const char *input_video, 
		//				 bool isLittleEndian=true, bool isBigEndian=false, bool hasA=false, bool isRGB=false );

		LoadXRGB( Layout_BGRAI, 
			      video_buffer, nwant, 
				  GetPixelsPerLine(ComprID), GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1), 
				  input_video,
				  input_type==BGRAI, false, true, false );

		while( Duration-- )
		{
			samplesWritten=0;
			check(pEssenceAccess->WriteSamples(1, nwant, video_buffer, &samplesWritten, &bytesWritten));
			total_samples += samplesWritten;
		}
		delete[] video_buffer;
	}
	else if( input_type==BGRA )
	{
		// never get here with VC3Codec

		// Load a single frame of uncompressed
		aafUInt32  nwant = GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1)*GetPixelsPerLine(ComprID)*8; 
	
		unsigned char* video_buffer = new unsigned char [ nwant ];

		// int LoadXRGB( BufferLayout_t target, byte *video_buffer, int len, int H, int V, const char *input_video, 
		//				 bool isLittleEndian=true, bool isBigEndian=false, bool hasA=false, bool isRGB=false );

		LoadXRGB( Layout_BGRA, 
			      video_buffer, nwant, 
				  GetPixelsPerLine(ComprID), GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1), 
				  input_video,
				  input_type==BGRAI, false, true, false );

		while( Duration-- )
		{
			samplesWritten=0;
			check(pEssenceAccess->WriteSamples(1, nwant, video_buffer, &samplesWritten, &bytesWritten));
			total_samples += samplesWritten;
		}
		delete[] video_buffer;
	}
	else if( input_type==BarsRGB )		// using generated rgb colo(u)r bars
	{
		// never get here with VC3Codec

		// Create a frame of colour bars
		aafUInt32  nwant = GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1)*GetPixelsPerLine(ComprID)*8; 
		unsigned char* video_buffer = new unsigned char [ nwant ];

		LoadXBars( Layout_BGRAI, video_buffer, nwant, GetPixelsPerLine(ComprID), GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1) );

		while( Duration-- )
		{
			samplesWritten=0;
			check(pEssenceAccess->WriteSamples(1, nwant, video_buffer, &samplesWritten, &bytesWritten));
			total_samples += samplesWritten;
		}
		delete[] video_buffer;
	}
	else // if( input_type==BarsUYVY || input_video == NULL || others... )		// using generated component colo(u)r bars
	{
		// Create a frame of colour bars
		aafUInt32  nwant = GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1)*(GetPixelsPerLine(ComprID)/2)*(UseDNX?5:8); 
		unsigned char* video_buffer = new unsigned char [ nwant ];

		LoadXBars( UseDNX?Layout_P_UYVY:Layout_UYVYM, video_buffer, nwant, GetPixelsPerLine(ComprID), GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1) );

		while( Duration-- )
		{
			samplesWritten=0;
			check(pEssenceAccess->WriteSamples(1, nwant, video_buffer, &samplesWritten, &bytesWritten));
			total_samples += samplesWritten;
		}
		delete[] video_buffer;
	}

	printf("Completed Write\n");

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

	pEssenceAccess->Release();

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

	pPictureDef->Release();
	pCDMasterMob->Release();

	pDictionary->Release();
	pHeader->Release();
	pHeader2->Release();

	/* Save the AAF file */
	pFile->Save();

	/* Close the AAF file */
	pFile->Close();
	pFile->Release();

	return moduleErrorTmp;
}
Esempio n. 9
0
void EventTest::CreateEvent()
{
  assert(_pHeader && _pDictionary);

  HRESULT hr = S_OK;
  IAAFEvent *pEvent = NULL;
  IAAFEventMobSlot *pEventMobSlot = NULL;
  IAAFSegment *pSegment = NULL;
  IAAFMobSlot *pMobSlot = NULL;
  IAAFDataDef *pDataDef = NULL;
  IAAFComponent *pComp = NULL;
  IAAFMob *pMob = NULL;

  CAAFBuiltinDefs defs (_pDictionary);

  try
  {
	  // not already in dictionary
		checkResult(defs.cdDataDef()->
					CreateInstance (IID_IAAFDataDef,
									(IUnknown **)&pDataDef));
	  hr = pDataDef->Initialize (kAAFDataDef_Test, L"Test", L"Test data");
	  hr = _pDictionary->RegisterDataDef (pDataDef);

	// Create a concrete subclass of event
    checkResult(defs.cdCommentMarker()->
				CreateInstance(IID_IAAFEvent, 
							   (IUnknown **)&pEvent));
    checkResult(pEvent->SetPosition(_position));
    checkResult(pEvent->SetComment(const_cast<wchar_t*>(_eventComment)));
	checkResult(pEvent->QueryInterface(IID_IAAFComponent, (void **)&pComp));
	checkResult(pComp->SetDataDef(pDataDef));
	pComp->Release();
	pComp = NULL;

    // Get the segment inteface to the event to install into the mob slot.
    checkResult(pEvent->QueryInterface(IID_IAAFSegment, (void **)&pSegment));

    // Create and initialize an EventMobSlot
    checkResult(defs.cdEventMobSlot()->
				CreateInstance(IID_IAAFEventMobSlot, 
							   (IUnknown **)&pEventMobSlot));
    checkResult(pEventMobSlot->SetEditRate(const_cast<aafRational_t *>(&_editRate)));

    // Get the mob slot interface so that we can add the event segment.
    checkResult(pEventMobSlot->QueryInterface(IID_IAAFMobSlot, (void **)&pMobSlot));

    // Add the event segment to the event mob slot.
    checkResult(pMobSlot->SetSegment(pSegment));

    // Create the mob to hold the new event mob slot.
    checkResult(defs.cdCompositionMob()->
				CreateInstance(IID_IAAFMob, 
							   (IUnknown **)&pMob));
    checkResult(pMob->SetName(L"CompositionMob::Name:Test mob to hold an event mob slot"));

    // Append event slot to the composition mob.
    checkResult(pMob->AppendSlot(pMobSlot));

    // Save the id of the composition mob that contains our test
    // event mob slot.
    checkResult(pMob->SetMobID(gMobID));
    
    // Attach the mob to the header...
    checkResult(_pHeader->AddMob(pMob));

  }
  catch (HRESULT& rHR)
  {
    hr = rHR;
    // fall through and handle cleanup
  }

  // Cleanup local references
  if (pMob)
  {
    pMob->Release();
    pMob = NULL;
  }

  if (pDataDef)
  {
    pDataDef->Release();
    pDataDef = NULL;
  }

  if (pComp)
  {
    pComp->Release();
    pComp = NULL;
  }

  if (pMobSlot)
  {
    pMobSlot->Release();
    pMobSlot = NULL;
  }

  if (pEventMobSlot)
  {
    pEventMobSlot->Release();
    pEventMobSlot = NULL;
  }

  if (pSegment)
  {
    pSegment->Release();
    pSegment = NULL;
  }

  if (pEvent)
  {
    pEvent->Release();
    pEvent = NULL;
  }



  // Propogate the error if necessary.
  checkResult(hr);
}
Esempio n. 10
0
static HRESULT CreateAAFFile(
    aafWChar * pFileName,
    aafUID_constref fileKind,
    testRawStorageType_t rawStorageType,
    aafProductIdentification_constref productID)
{
	IAAFFile*		pFile = NULL;
	IAAFHeader *        pHeader = NULL;
	IAAFDictionary*  pDictionary = NULL;
	IAAFCodecDef*	pPlugDef = NULL;
	IAAFDataDef		*pDataDef = NULL;
	IAAFClassDef	*classDef = NULL;
	IAAFClassDef *pWaveClassDef=0,*pReturnedClassDef=0;
	bool bFileOpen = false;
	HRESULT			hr = S_OK;
	aafUID_t		uid;

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


		// Create the AAF file
		checkResult(CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile ));
		bFileOpen = true;

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

		// Get the AAF Dictionary so that we can create valid AAF objects.
		checkResult(pHeader->GetDictionary(&pDictionary));
		CAAFBuiltinDefs defs (pDictionary);
    
		checkResult(defs.cdCodecDef()->
					CreateInstance(IID_IAAFCodecDef,
								   (IUnknown **)&pPlugDef));
    
		uid = kAAFCodecWAVE;
		checkResult(pPlugDef->Initialize (uid, L"TestCodec", L"TestCodecDescription"));

		checkResult(pPlugDef->AddEssenceKind (defs.ddkAAFMatte()));
		checkResult(pDictionary->RegisterCodecDef(pPlugDef));
		uid = kAAFClassID_WAVEDescriptor;
		checkResult(pDictionary->LookupClassDef(uid, &classDef));
		checkResult(pPlugDef->SetFileDescriptorClass (classDef));

		// Make sure GetFileDescriptorClass() returns correct value
		aafUID_t uid = kAAFClassID_WAVEDescriptor;
		checkResult(pDictionary->LookupClassDef(uid, &pWaveClassDef));
		checkResult(pPlugDef->GetFileDescriptorClass(&pReturnedClassDef));
		// COM interface pointers pReturnedClassDef and pWaveClassDef should be 
		// equal
		checkExpression(AreUnksSame(pReturnedClassDef,pWaveClassDef)==kAAFTrue,
			AAFRESULT_TEST_FAILED);

                /* Not tested
		virtual HRESULT STDMETHODCALLTYPE RemoveEssenceKind();
		virtual HRESULT STDMETHODCALLTYPE CountEssenceKinds();
		virtual HRESULT STDMETHODCALLTYPE GetEssenceKinds();
                */

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


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

  if (pWaveClassDef)
    pWaveClassDef->Release();

  if (classDef)
    classDef->Release();

  if (pDataDef)
    pDataDef->Release();

  if (pPlugDef)
    pPlugDef->Release();

  if (pDictionary)
    pDictionary->Release();

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

  return hr;
}
Esempio n. 11
0
static HRESULT ReadAAFFile(aafWChar* pFileName)
{
	IAAFFile*				pFile = NULL;
	IAAFHeader*				pHeader = NULL;
	IAAFDictionary*			 pDictionary = NULL;
	IAAFCodecDef			*pCodec = NULL;
	IAAFClassDef *pWaveClassDef=0,*pReturnedClassDef=0;
	IAAFDataDef				*pDataDef = NULL;
	IEnumAAFCodecFlavours	*pEnum = NULL;
	bool					bFileOpen = false;
	aafBool					testResult;
	aafUID_t				codecID = kAAFCodecWAVE;
	aafUID_t				readFlavour, checkFlavour = kAAFNilCodecFlavour;
	HRESULT					hr = S_OK;

	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->LookupCodecDef(codecID, &pCodec));

		checkResult(pCodec->IsEssenceKindSupported (defs.ddkAAFMatte(), &testResult));
		checkExpression (testResult == kAAFTrue, AAFRESULT_TEST_FAILED);
		checkResult(pCodec->IsEssenceKindSupported (defs.ddkAAFPicture(), &testResult));
		checkExpression (testResult == kAAFFalse, AAFRESULT_TEST_FAILED);
		checkResult(pCodec->EnumCodecFlavours (&pEnum));
		checkResult(pEnum->NextOne (&readFlavour));
		checkExpression (memcmp(&readFlavour, &checkFlavour, sizeof(checkFlavour)) == 0,
						 AAFRESULT_TEST_FAILED);
		checkResult(pCodec->AreThereFlavours (&testResult));
		checkExpression (kAAFFalse == testResult,
						 AAFRESULT_TEST_FAILED);
		aafUID_t uid = kAAFClassID_WAVEDescriptor;
		checkResult(pDictionary->LookupClassDef(uid, &pWaveClassDef));
		checkResult(pCodec->GetFileDescriptorClass(&pReturnedClassDef));
		// COM interface pointers pReturnedClassDef and pWaveClassDef should be 
		// equal
		checkExpression(AreUnksSame(pReturnedClassDef,pWaveClassDef)==kAAFTrue,
			AAFRESULT_TEST_FAILED);
	}
	catch (HRESULT& rResult)
	{
		hr = rResult;
	}

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

  if (pWaveClassDef)
    pWaveClassDef->Release();

	if (pEnum)
		pEnum->Release();
	if (pDataDef)
		pDataDef->Release();
	if (pCodec)
		pCodec->Release();
	if (pDictionary)
		pDictionary->Release();

	if (pHeader)
		pHeader->Release();

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

	return hr;
}
Esempio n. 12
0
static HRESULT ReadAAFFile(aafWChar * pFileName)
{
	IAAFFile				*pFile = NULL;
	bool					bFileOpen = false;
	IAAFHeader				*pHeader = NULL;
	IEnumAAFMobs			*mobIter = NULL;
	IAAFMob					*aMob = NULL;
	IEnumAAFMobSlots		*slotIter = NULL;
	IAAFMobSlot				*slot = NULL;
	IAAFSegment				*pSeg = NULL;
	IAAFSourceClip			*pSourceClip = NULL;
	IAAFDataDef *            pDataDef = 0;
	IAAFDefObject *          pDefObj = 0;
	aafNumSlots_t			numMobs, n;
	aafSlotID_t				s;
	aafUInt32				length;
	HRESULT					hr = S_OK;
	aafUID_t				readUID, typeUID = kAAFDataDef_Picture;
	
	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));
		
		
		checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs));
		checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED);
		
		
		aafSearchCrit_t		criteria;
		criteria.searchTag = kAAFNoSearch;
		checkResult(pHeader->GetMobs (&criteria, &mobIter));
		
		for(n = 0; n < numMobs; n++)
		{
			aafWChar		name[500], slotName[500];
			aafNumSlots_t	numSlots;
			aafMobID_t		mobID;
			aafSlotID_t		trackID;
			
			checkResult(mobIter->NextOne (&aMob));
			checkResult(aMob->GetName (name, sizeof(name)));
			checkResult(aMob->GetMobID (&mobID));
			
			checkResult(aMob->CountSlots (&numSlots));
			checkExpression(5 == numSlots, AAFRESULT_TEST_FAILED);
			
			checkResult(aMob->GetSlots(&slotIter));
			
			for(s = 0; s < (aafSlotID_t)numSlots; s++)
			{
				checkResult(slotIter->NextOne (&slot));
				checkResult(slot->GetNameBufLen(&length));
				checkResult(slot->GetName (slotName, length));
				checkExpression (wcscmp(slotName, slotNames[s]) == 0, AAFRESULT_TEST_FAILED);
				checkResult(slot->GetSlotID(&trackID));
				checkExpression (trackID == s+1, AAFRESULT_TEST_FAILED);
				checkResult(slot->GetPhysicalNum(&trackID));
				checkExpression (trackID == s+2, AAFRESULT_TEST_FAILED);
				checkResult(slot->GetPhysicalNum(&trackID));
				checkResult(slot->GetDataDef(&pDataDef));
				checkResult(pDataDef->QueryInterface (IID_IAAFDefObject, (void **)&pDefObj));
				checkResult(pDefObj->GetAUID(&readUID));
				checkExpression (memcmp(&typeUID, &readUID, sizeof(typeUID)) == 0, AAFRESULT_TEST_FAILED);
				checkResult(slot->GetSegment(&pSeg));
				checkResult(pSeg->QueryInterface (IID_IAAFSourceClip, (void **)&pSourceClip));
				pDataDef->Release();
				pDataDef = 0;
				pDefObj->Release ();
				pDefObj = 0;
				pSourceClip->Release();
				pSourceClip = NULL;
				pSeg->Release();
				pSeg = NULL;
				slot->Release();
				slot = NULL;
			}
			
			aMob->Release();
			aMob = NULL;
		}
	}
	catch (HRESULT& rResult)
	{
		hr = rResult;
	}
	
	// Cleanup object references
	if (slot)
	  {
		slot->Release();
		slot = 0;
	  }
	
	if (pSeg)
	  {
		pSeg->Release();
		pSeg = 0;
	  }
	
	if (pSourceClip)
	  {
		pSourceClip->Release();
		pSourceClip = 0;
	  }
	
	if (slotIter)
	  {
		slotIter->Release();
		slotIter = 0;
	  }
	
	if (aMob)
	  {
		aMob->Release();
		aMob = 0;
	  }
	
	if (mobIter)
	  {
		mobIter->Release();
		mobIter = 0;
	  }
	
	if (pHeader)
	  {
		pHeader->Release();
		pHeader = 0;
	  }
	
	if (pDataDef)	
	  {
		pDataDef->Release();
		pDataDef = 0;
	  }

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

	if (pFile)
	{  // Close file
		if (bFileOpen)
			pFile->Close();
		pFile->Release();
		pFile = 0;
	}
	
	return hr;
}
Esempio n. 13
0
static HRESULT CreateAAFFile(const aafWChar * pFileName)
{
	IAAFFile*					pFile = NULL;
	IAAFHeader*					pHeader = NULL;
	IAAFDictionary*				pDictionary = NULL;
	IAAFMob*					pMob = NULL;
	IAAFMasterMob*				pMasterMob = NULL;
	IAAFEssenceAccess*			pEssenceAccess = NULL;
	IAAFEssenceFormat*			pFormat = NULL;
	IAAFLocator					*pLocator = NULL;
	aafMobID_t					masterMobID;
	aafProductIdentification_t	ProductInfo;
	aafRational_t				editRate = {11025, 1};
	aafRational_t				sampleRate = {11025, 1};
	IAAFClassDef				*pCDMasterMob = NULL;
	IAAFDataDef					*pSoundDef = NULL;
	aafUInt32					samplesWritten, bytesWritten;

	// Delete any previous test file before continuing...
	char cFileName[FILENAME_MAX];
	convert(cFileName, sizeof(cFileName), pFileName);
	remove(cFileName);

	aafProductVersion_t ver = {1, 0, 0, 0, kAAFVersionBeta};
	ProductInfo.companyName = companyName;
	ProductInfo.productName = productName;
	ProductInfo.productVersion = &ver;
	ProductInfo.productVersionString = NULL;
	ProductInfo.productID = NIL_UID;
	ProductInfo.platform = NULL;		// Set by SDK when saving

	// Create a new AAF file
	check(AAFFileOpenNewModify (pFileName, 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, &pCDMasterMob));

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

	/* Create a Mastermob */

	// 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));
	if (input_video == NULL)
	{
		check(pMob->SetName(L"Laser"));
	}
	else
	{
		check(pMob->SetName(pFileName));
	}

	// Add Mobs to the Header
	check(pHeader->AddMob(pMob));

	// Locator needed for non-embedded essence
	IAAFClassDef *classDef = NULL;
	check(pDictionary->LookupClassDef(AUID_AAFNetworkLocator, &classDef));
	check(classDef->CreateInstance(IID_IAAFLocator, (IUnknown **)&pLocator));
	classDef->Release();
	classDef = NULL;

	if (container == NIL_UID)
	{
		pLocator = NULL;
	}
	else if (container == ContainerAAF)
	{
		check(pLocator->SetPath(L"Laser.aaf"));
		remove("Laser.aaf");
	}
	else if (container == ContainerFile)
	{
		check(pLocator->SetPath(L"Laser.pcm"));
		remove("Laser.pcm");
	}
	else	// RIFFWAVE container
	{
		check(pLocator->SetPath(L"Laser.wav"));
		remove("Laser.wav");
	}

	// Get a pointer to video data for WriteSamples
	unsigned char *dataPtr, buf[4096];
	memcpy(buf, uncompressedWAVE_Laser+44, sizeof(uncompressedWAVE_Laser));
	dataPtr = buf;

	/* Create the Essence Data specifying the codec, container, edit rate and sample rate */
	check(pMasterMob->CreateEssence(1,			// Slot ID within MasterMob
						pSoundDef,				// MediaKind
						kAAFCodecPCM,			// codecID
						editRate,				// edit rate
						sampleRate,				// sample rate
						kAAFCompressionDisable,
						pLocator,				// Locator
						container,			// Container
						&pEssenceAccess));		//

	pEssenceAccess->SetEssenceCodecFlavour( kAAFNilCodecFlavour );

	// Set Format specifiers that describe the essence data
	// Sample rate is already specified in the CreateEssence() call
	aafUInt32 sampleBits = 8;
	aafUInt32 numChannels = 1;

	check(pEssenceAccess->GetEmptyFileFormat(&pFormat));
	check(pFormat->AddFormatSpecifier(kAAFAudioSampleBits, sizeof(sampleBits), (aafUInt8 *)&sampleBits));
	check(pFormat->AddFormatSpecifier(kAAFNumChannels, sizeof(numChannels), (aafUInt8 *)&numChannels));
	check(pEssenceAccess->PutFileFormat(pFormat));

	pFormat->Release();

	/* Write the samples */
	int total_samples = 0;
	if (input_video == NULL)		// using generated uncompressed video?
	{
		for (int i = 0; i < 1793; i++)		// Laser example has 1793 samples
		{
			check(pEssenceAccess->WriteSamples(
						1,					//
						sizeof(buf),		// buffer size
						dataPtr++,			// pointer to video frame
						&samplesWritten,
						&bytesWritten));
			total_samples += samplesWritten;
		}
	}
	printf("Wrote %d samples\n", total_samples);

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

	pEssenceAccess->Release();
	pEssenceAccess = NULL;

	/* Release COM interfaces */

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

	pSoundDef->Release();
	pCDMasterMob->Release();

	pDictionary->Release();
	pHeader->Release();

	/* Save the AAF file */
	pFile->Save();

	/* Close the AAF file */
	pFile->Close();
	pFile->Release();

	return moduleErrorTmp;
}
Esempio n. 14
0
static HRESULT ReadAAFFile(aafWChar* pFileName)
{
	IAAFFile*		pFile = NULL;
	IAAFHeader*		pHeader = NULL;
	IEnumAAFMobs*	pMobIter = NULL;
	IAAFMob*		pMob;
	IEnumAAFMobSlots*	pSlotIter = NULL;
	IAAFMobSlot*		pSlot = NULL;
	IAAFComponent*		pComp = NULL;
	IAAFSegment*		pSegment = NULL;
	IAAFDataDef*		pDataDef = NULL;
	IAAFSequence*		pSequence = NULL;
	IAAFDictionary*		pDictionary = NULL;
	IEnumAAFDataDefs*	pEnumDataDef = NULL;
	IEnumAAFDataDefs*	pCloneEnum = NULL;
	IEnumAAFComponents*	pCompIter = NULL;
	IAAFDataDef*		pArray[2] = { NULL, NULL };
	aafNumSlots_t		numMobs;
	aafInt32			index;
	aafSearchCrit_t		criteria;
	HRESULT				hr = S_OK;
	aafBool				testBool;
	aafUInt32			resultCount;
	
	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));
		
		// The test can't check the types on these because the order of adding data definitions
		// is defined by the toolkit, and not the test.  !!!Change this to determine the order on
		// the first two tests, and then use to test the other functions.

		checkResult(pDictionary->GetDataDefs(&pEnumDataDef));
		/* Read and check the first element */
		checkResult(pEnumDataDef->NextOne(&pDataDef));
		checkResult(pDataDef->IsPictureKind(&testBool));
//		checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED);
		checkResult(pDataDef->IsSoundKind(&testBool));
//		checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED);
		pDataDef->Release();
		pDataDef = NULL;
		
		/**/
		/* Read and check the second element */
		checkResult(pEnumDataDef->NextOne(&pDataDef));
		checkResult(pDataDef->IsSoundKind(&testBool));
//		checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED);
		checkResult(pDataDef->IsPictureKind(&testBool));
//		checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED);
		pDataDef->Release();
		pDataDef = NULL;
		/*****/
		
		/* Reset, and check the first element again*/
		checkResult(pEnumDataDef->Reset());
		checkResult(pEnumDataDef->NextOne(&pDataDef));
		checkResult(pDataDef->IsPictureKind(&testBool));
//		checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED);
		checkResult(pDataDef->IsSoundKind(&testBool));
//		checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED);
		pDataDef->Release();
		pDataDef = NULL;
		
		/* Reset, Skip, and check the second element again*/
		checkResult(pEnumDataDef->Reset());
		checkResult(pEnumDataDef->Skip(1));
		checkResult(pEnumDataDef->NextOne(&pDataDef));
		checkResult(pDataDef->IsSoundKind(&testBool));
//		checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED);
		checkResult(pDataDef->IsPictureKind(&testBool));
//		checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED);
		pDataDef->Release();
		pDataDef = NULL;
		
		/* Reset, and read both elements */
		checkResult(pEnumDataDef->Reset());
		checkResult(pEnumDataDef->Next (2, (IAAFDataDef **)&pArray, &resultCount));
		checkExpression (resultCount == 2, AAFRESULT_TEST_FAILED);
		checkResult(pArray[0]->IsPictureKind(&testBool));
//		checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED);
		checkResult(pArray[0]->IsSoundKind(&testBool));
//		checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED);
		pArray[0]->Release();
		pArray[0] = NULL;
		
		checkResult(pArray[1]->IsSoundKind(&testBool));
//		checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED);
		checkResult(pArray[1]->IsPictureKind(&testBool));
//		checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED);
		pArray[1]->Release();
		pArray[1] = NULL;
		
//		/* Read one past to make sure that it fails */
//		checkExpression(pEnumDataDef->NextOne(&pDataDef) != AAFRESULT_SUCCESS, AAFRESULT_TEST_FAILED);
		/* Clone the enumerator, and read one element */
		checkResult(pEnumDataDef->Clone(&pCloneEnum));
		checkResult(pCloneEnum->Reset());
		checkResult(pCloneEnum->NextOne(&pDataDef));
		checkResult(pDataDef->IsPictureKind(&testBool));
//		checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED);
		checkResult(pDataDef->IsSoundKind(&testBool));
//		checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED);
		pDataDef->Release();
		pDataDef = NULL;
		pCloneEnum->Release();
		pCloneEnum = NULL;
		
		// Enumerate over Composition MOBs
		criteria.searchTag = kAAFByMobKind;
		criteria.tags.mobKind = kAAFCompMob;
		checkResult(pHeader->GetMobs(&criteria, &pMobIter));
		CAAFBuiltinDefs defs (pDictionary);
		while (pMobIter && pMobIter->NextOne(&pMob) == AAFRESULT_SUCCESS)
		{
			aafNumSlots_t		numSlots = 0;
			
			checkResult(pMob->CountSlots(&numSlots));
			checkExpression(1 == numSlots, AAFRESULT_TEST_FAILED);
			
			// Enumerate over all MOB slots for this MOB
			checkResult(pMob->GetSlots(&pSlotIter));
			while (pSlotIter && pSlotIter->NextOne(&pSlot) == AAFRESULT_SUCCESS)
			{
				aafUInt32			numCpnts;
				
				checkResult(pSlot->GetSegment(&pSegment));
				checkResult(pSegment->QueryInterface(IID_IAAFSequence, (void **) &pSequence));
				
				checkResult(pSequence->CountComponents(&numCpnts));
				checkExpression(numCpnts == kNumComponents, AAFRESULT_TEST_FAILED);
				
				checkResult(pSequence->GetComponents(&pCompIter));
				numCpnts = 0;
				index = 0;
				while (pCompIter && pCompIter->NextOne(&pComp) == AAFRESULT_SUCCESS)
				{
					aafBool		testBool;
					
					numCpnts++;
					
					checkResult(pComp->GetDataDef(&pDataDef));
					checkResult(pDataDef->IsSoundKind(&testBool));
					checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED);
					checkResult(pDataDef->IsMatteKind(&testBool));
					checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED);
					
					if(index == 0)	// First segment is Picture with Matte, converts to picture
					{
						checkResult(pDataDef->IsDataDefOf(defs.ddkAAFPictureWithMatte(),
														  &testBool));
						checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED);
						checkResult(pDataDef->IsPictureKind(&testBool));
						checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED);
						checkResult(pDataDef->IsPictureWithMatteKind(&testBool));
						checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED);
						checkResult(pDataDef->DoesDataDefConvertTo (defs.ddkAAFPicture(), &testBool));
						checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED);
					}
					else		// First segment is Picture, converts from picture with Matte
					{
						checkResult(pDataDef->IsDataDefOf(defs.ddkAAFPicture(), &testBool));
						checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED);
						checkResult(pDataDef->IsPictureKind(&testBool));
						checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED);
						checkResult(pDataDef->IsPictureWithMatteKind(&testBool));
						checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED);
						checkResult(pDataDef->DoesDataDefConvertFrom (defs.ddkAAFPictureWithMatte(),
																	  &testBool));
						checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED);
					}
					checkResult(pDataDef->DoesDataDefConvertTo (defs.ddkAAFSound(),
																&testBool));
					checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED);
					checkResult(pDataDef->DoesDataDefConvertFrom (defs.ddkAAFSound(), &testBool));
					checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED);
					
					pComp->Release();
					pComp = NULL;
					pDataDef->Release();
					pDataDef = NULL;
					index++;
				}
				
				pCompIter->Release();
				pCompIter = NULL;
				
				pSequence->Release();
				pSequence = NULL;
				
				pSegment->Release();
				pSegment = NULL;
				
				pSlot->Release();
				pSlot = NULL;
			}
			
			pSlotIter->Release();
			pSlotIter = NULL;
			
			pMob->Release();
			pMob = NULL;
		}
		
		
	}
	catch (HRESULT& rResult)
	{
		hr = rResult;
	}
	
	// Cleanup object references
	if (pComp)
		pComp->Release();
	

	if (pEnumDataDef)
		pEnumDataDef->Release();
	if (pCloneEnum)
		pCloneEnum->Release();
	if (pCompIter)
		pCompIter->Release();
	if (pArray[0])
		pArray[0]->Release();
	if (pArray[1])
		pArray[1]->Release();
	
	if (pDataDef)
		pDataDef->Release();
	
	if (pSequence)
		pSequence->Release();
	
	if (pSegment)
		pSegment->Release();
	
	if (pSlot)
		pSlot->Release();
	
	if (pDictionary)
		pDictionary->Release();
	
	if (pSlotIter)
		pSlotIter->Release();
	
	if (pMob)
		pMob->Release();
	
	if (pMobIter)
		pMobIter->Release();
	
	if (pHeader) pHeader->Release();
	
	if (pFile)
	{
		pFile->Close();
		pFile->Release();
	}
	
	
	return 	hr;
}