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; }
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; }
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; }
static HRESULT CreateAAFFile( aafWChar * pFileName, aafUID_constref fileKind, testRawStorageType_t rawStorageType, aafProductIdentification_constref productID) { IAAFFile * pFile = NULL; bool bFileOpen = false; IAAFHeader * pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFLocator * pLocator = NULL; IAAFNetworkLocator * pNetLocator = NULL; IAAFSourceMob *pSourceMob = NULL; IAAFMob *pMob = NULL; IAAFEssenceDescriptor *edesc = NULL; aafUInt32 numLocators; HRESULT hr = AAFRESULT_SUCCESS; try { // Remove the previous test file if any. RemoveTestFile(pFileName); // Create the file. checkResult(CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile )); bFileOpen = true; // We can't really do anthing in AAF without the header. checkResult(pFile->GetHeader(&pHeader)); // Get the AAF Dictionary so that we can create valid AAF objects. checkResult(pHeader->GetDictionary(&pDictionary)); CAAFBuiltinDefs defs (pDictionary); //Make the first mob // Create a Mob checkResult(defs.cdSourceMob()-> CreateInstance(IID_IAAFSourceMob, (IUnknown **)&pSourceMob)); checkResult(pSourceMob->QueryInterface (IID_IAAFMob, (void **)&pMob)); checkResult(pMob->SetMobID(TEST_MobID)); checkResult(pMob->SetName(L"SourceMOBTest")); // Create a concrete subclass of EssenceDescriptor checkResult(defs.cdAIFCDescriptor()-> CreateInstance(IID_IAAFEssenceDescriptor, (IUnknown **)&edesc)); IAAFAIFCDescriptor* pAIFCDesc = NULL; checkResult(edesc->QueryInterface (IID_IAAFAIFCDescriptor, (void **)&pAIFCDesc)); checkResult(pAIFCDesc->SetSummary (5, (unsigned char*)"TEST")); pAIFCDesc->Release(); pAIFCDesc = NULL; // Verify that there are no locators checkResult(edesc->CountLocators(&numLocators)); checkExpression(0 == numLocators, AAFRESULT_TEST_FAILED); // Make a locator, and attach it to the EssenceDescriptor checkResult(defs.cdNetworkLocator()-> CreateInstance(IID_IAAFNetworkLocator, (IUnknown **)&pNetLocator)); checkResult(pNetLocator->QueryInterface (IID_IAAFLocator, (void **)&pLocator)); checkResult(pLocator->SetPath (TEST_PATH)); checkResult(edesc->AppendLocator(pLocator)); checkResult(pSourceMob->SetEssenceDescriptor (edesc)); // Verify that there is now one locator checkResult(edesc->CountLocators(&numLocators)); checkExpression(1 == numLocators, AAFRESULT_TEST_FAILED); // Add the source mob into the tree checkResult(pHeader->AddMob(pMob)); } catch (HRESULT& rResult) { hr = rResult; } // cleanup if (pLocator) pLocator->Release(); if (pNetLocator) pNetLocator->Release(); if (edesc) edesc->Release(); if (pMob) pMob->Release(); if (pSourceMob) pSourceMob->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pFile) { if (bFileOpen) { pFile->Save(); pFile->Close(); } pFile->Release(); } // hr = pSession->EndSession(); // if (AAFRESULT_SUCCESS != hr) // return hr; // if (pSession) pSession->Release(); return hr; }
HRESULT STDMETHODCALLTYPE CAAFEssenceFileContainer::CreateDescriptor (IAAFDictionary *dict, IAAFPluginDef **descPtr) { IAAFPluginDef *desc = NULL; IAAFLocator *pLoc = NULL; IAAFNetworkLocator *pNetLoc = NULL; IAAFClassDef *pcd = 0; XPROTECT() { CHECK(dict->LookupClassDef(AUID_AAFPluginDef, &pcd)); CHECK(pcd->CreateInstance(IID_IAAFPluginDef, (IUnknown **)&desc)); pcd->Release(); pcd = 0; *descPtr = desc; desc->AddRef(); CHECK(desc->Initialize(EXAMPLE_FILE_PLUGIN, L"Essence File Container", L"Handles non-container files.")); CHECK(desc->SetCategoryClass(AUID_AAFDefObject)); CHECK(desc->SetPluginVersionString(manufRev)); CHECK(dict->LookupClassDef(AUID_AAFNetworkLocator, &pcd)); CHECK(pcd->CreateInstance(IID_IAAFLocator, (IUnknown **)&pLoc)); CHECK(pLoc->SetPath (manufURL)); CHECK(pLoc->QueryInterface(IID_IAAFNetworkLocator, (void **)&pNetLoc)); CHECK(desc->SetManufacturerInfo(pNetLoc)); pNetLoc->Release(); pNetLoc = NULL; pLoc->Release(); pLoc = NULL; CHECK(desc->SetManufacturerID(MANUF_JEFFS_PLUGINS)); CHECK(desc->SetPluginManufacturerName(manufName)); CHECK(desc->SetIsSoftwareOnly(kAAFTrue)); CHECK(desc->SetIsAccelerated(kAAFFalse)); CHECK(desc->SetSupportsAuthentication(kAAFFalse)); /**/ CHECK(pcd->CreateInstance(IID_IAAFLocator, (IUnknown **)&pLoc)); pcd->Release (); pcd = 0; CHECK(pLoc->SetPath (downloadURL)); CHECK(desc->AppendLocator(pLoc)); desc->Release(); desc = NULL; pLoc->Release(); pLoc = NULL; } XEXCEPT { if(desc != NULL) { desc->Release(); desc = 0; } if(pLoc != NULL) { pLoc->Release(); pLoc = 0; } if(pNetLoc != NULL) { pNetLoc->Release(); pNetLoc = 0; } if (pcd) { pcd->Release (); pcd = 0; } } XEND return AAFRESULT_SUCCESS; }
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; }