void testKLVDataDefinitions(IAAFDictionary *pDictionary, IAAFMob *pMob) { IAAFDictionary2 *pDic2 = NULL; IAAFClassDef *pKLVDataCD = NULL; IAAFKLVDataDefinition *pKLVDef = NULL; IAAFKLVData *pKLVData = NULL; IAAFTypeDef *typeDef = NULL; IAAFClassDef *pKLVDataDefCD = NULL; const aafCharacter defName[32] = L"Data Definition Omega"; const aafCharacter defDescription[64] = L"This is a test of the data definition!!!"; static const aafUInt8 blobData[]={ 0x01, 0x02, 0x00, 0x00, 0x03 }; //lookup class definition for KLVData checkResult(pDictionary->LookupClassDef(AUID_AAFKLVData, &pKLVDataCD)); //Register the KLVKeys checkResult(pDictionary->LookupTypeDef(kAAFTypeID_UInt8Array, &typeDef)); checkResult(pDictionary->RegisterKLVDataKey(KLVKey_TestData, typeDef)); //Create KLVData and append it to Mob checkResult(pKLVDataCD->CreateInstance(IID_IAAFKLVData, (IUnknown **)&pKLVData)); checkResult(pKLVData->Initialize(KLVKey_TestData, sizeof(blobData), (aafUInt8 *)blobData)); checkResult(pMob->AppendKLVData(pKLVData)); checkResult( pDictionary->QueryInterface( IID_IAAFDictionary2, reinterpret_cast<void**>(&pDic2) ) ); assert(pDic2); //lookup class definition for KLVDataDefinition checkResult(pDictionary->LookupClassDef(AUID_AAFKLVDataDefinition, &pKLVDataDefCD)); //Create KLVDataDef and append it to Dic checkResult(pKLVDataDefCD->CreateInstance(IID_IAAFKLVDataDefinition, (IUnknown **)&pKLVDef)); checkResult(pKLVDef->Initialize(KLVDef_TestData, defName, defDescription)); checkResult(pDic2->RegisterKLVDataDef(pKLVDef)); //cleanup pDic2->Release(); pDic2 = NULL; pKLVDataCD->Release(); pKLVDataCD = NULL; pKLVDef->Release(); pKLVDef = NULL; pKLVData->Release(); pKLVData = NULL; typeDef->Release(); typeDef = NULL; pKLVDataDefCD->Release(); pKLVDataDefCD = NULL; }
void testTaggedDefinitions(IAAFDictionary *pDictionary, IAAFMob *pMob) { IAAFDictionary2 *pDic2 = NULL; IAAFClassDef *pTAGDataCD = NULL; IAAFTaggedValueDefinition *pTAGDef = NULL; const aafCharacter defName[32] = L"Tagged Definition Kappa"; const aafCharacter defDef[64] = L"This is a test of the Tagged definition!!!"; checkResult( pDictionary->QueryInterface( IID_IAAFDictionary2, reinterpret_cast<void**>(&pDic2) ) ); assert(pDic2); //Create a tagged value def & register it checkResult(pDictionary->LookupClassDef(AUID_AAFTaggedValueDefinition, &pTAGDataCD)); checkResult(pTAGDataCD->CreateInstance(IID_IAAFTaggedValueDefinition, (IUnknown **)&pTAGDef)); checkResult(pTAGDef->Initialize(TAGDef_TestData, defName, defDef)); checkResult(pDic2->RegisterTaggedValueDef(pTAGDef)); //cleanup pDic2->Release(); pDic2 = NULL; pTAGDataCD->Release(); pTAGDataCD = NULL; pTAGDef->Release(); pTAGDef = NULL; }
//*********************************************************** // // GetObjRefPropFromObject() // // Get a object reference property on the AAF object specified // by pObj. The value of the property is returned in ppObject. // // Returns: // // On Success: S_OK // On Failure: A failed HRESULT // HRESULT AAFDomainUtils::GetObjRefPropFromObject(IAAFObject* pObj, aafUID_t* pClassID, const aafUID_t* pPropTypeID, aafUID_t* pPropID, IAAFObject** ppObject) { IAAFPropertyValue* pPV = NULL; IAAFClassDef* pCD; HRESULT hr; // Get the property value for the target property hr = _dict->LookupClassDef(*pClassID, &pCD); if (SUCCEEDED(hr)) { IAAFPropertyDef* pPD; hr = pCD->LookupPropertyDef(*pPropID, &pPD); if (SUCCEEDED(hr)) { aafBool present = kAAFFalse; pObj->IsPropertyPresent(pPD, &present); if (present == kAAFTrue) hr = pObj->GetPropertyValue(pPD, &pPV); else hr = AAFRESULT_PROP_NOT_PRESENT; pPD->Release(); } pCD->Release(); } // Get the property type def from the dictionary to interpret this property value // and return the resulting object. if (SUCCEEDED(hr)) { IAAFTypeDef* pTD; hr = _dict->LookupTypeDef(*pPropTypeID, &pTD); if (SUCCEEDED(hr)) { IAAFTypeDefObjectRef* pTDObjectRef; hr = pTD->QueryInterface(IID_IAAFTypeDefObjectRef, (void**)&pTDObjectRef); if (SUCCEEDED(hr)) { IAAFObject* pTempObj; hr = pTDObjectRef->GetObject(pPV, IID_IAAFObject, (IUnknown **)&pTempObj); if (SUCCEEDED(hr)) { *ppObject = pTempObj; } pTDObjectRef->Release(); } pTD->Release(); } } if (pPV) pPV->Release(); return hr; }
HRESULT STDMETHODCALLTYPE CAAFEssenceFileContainer::GetIndexedDefinitionObject (aafUInt32 /* index */, IAAFDictionary *dict, IAAFDefObject **def) { aafUID_t uid; IAAFContainerDef *container = NULL; IAAFClassDef *pcd = 0; if((dict == NULL) || (def == NULL)) return AAFRESULT_NULL_PARAM; XPROTECT() { CHECK(dict->LookupClassDef(AUID_AAFContainerDef, &pcd)); CHECK(pcd->CreateInstance(IID_IAAFContainerDef, (IUnknown **)&container)); pcd->Release(); pcd = 0; uid = ContainerFile; CHECK(container->SetEssenceIsIdentified(kAAFFalse)); CHECK(container->Initialize(uid, L"Raw file Container", L"Essence is in a non-container file.")); CHECK(container->QueryInterface(IID_IAAFDefObject, (void **)def)); container->Release(); container = NULL; } XEXCEPT { if(container != NULL) { container->Release(); container = 0; } if (pcd) { pcd->Release(); pcd = 0; } } XEND return AAFRESULT_SUCCESS; }
//*********************************************************** // // SetObjRefPropOnObject() // // Set an object reference property on the AAF object specified // by pObj. The value of the property is specified in pObject. // // Returns: // // On Success: S_OK // On Failure: A failed HRESULT // HRESULT AAFDomainUtils::SetObjRefPropOnObject(IAAFObject* pObj, aafUID_t* pClassID, const aafUID_t* pPropTypeID, aafUID_t* pPropID, IAAFObject* pValue) { IAAFPropertyValue* pPV = NULL; IAAFTypeDef* pTD; HRESULT hr; // Create a property value from the supplied value (pValue) hr = _dict->LookupTypeDef(*pPropTypeID, &pTD); if (SUCCEEDED(hr)) { IAAFTypeDefObjectRef* pTDObjRef; hr = pTD->QueryInterface(IID_IAAFTypeDefObjectRef, (void**)&pTDObjRef); if (SUCCEEDED(hr)) { hr = pTDObjRef->CreateValue(pValue, &pPV); pTDObjRef->Release(); } pTD->Release(); } // Add the property to the target object. if (SUCCEEDED(hr)) { if (SUCCEEDED(hr)) { IAAFClassDef* pCD; // Get the class def for the object hr = _dict->LookupClassDef(*pClassID, &pCD); if (SUCCEEDED(hr)) { IAAFPropertyDef* pPD; hr = pCD->LookupPropertyDef(*pPropID, &pPD); if (SUCCEEDED(hr)) { // Set the propeter value on the target object hr = pObj->SetPropertyValue(pPD, pPV); pPD->Release(); } pCD->Release(); } } } if (pPV) pPV->Release(); return hr; }
AAFRESULT GetPropertyType( IUnknown* pUnknown, const aafUID_t& propertyId, IAAFTypeDef** ppPropTypeDef ) { AAFRESULT hr = AAFRESULT_SUCCESS; IAAFObject* pObject = 0; hr = pUnknown->QueryInterface( IID_IAAFObject, (void **)&pObject ); if( hr == AAFRESULT_SUCCESS ) { IAAFClassDef* pClassDef = 0; hr = pObject->GetDefinition( &pClassDef ); if( hr == AAFRESULT_SUCCESS ) { IAAFPropertyDef* pPropDef = 0; hr = pClassDef->LookupPropertyDef( propertyId, &pPropDef ); if( hr == AAFRESULT_SUCCESS ) { hr = pPropDef->GetTypeDef( ppPropTypeDef ); pPropDef->Release(); pPropDef = 0; } pClassDef->Release(); pClassDef = 0; } pObject->Release(); pObject = 0; } return hr; }
static HRESULT CreateAAFFile(aafWChar *filename, aafUID_constref fileKind) { TestProductID.companyName = companyName; TestProductID.productName = productName; TestProductID.productVersionString = NULL; TestProductID.productID = UnitTestProductID; TestProductID.platform = NULL; TestProductID.productVersion = &TestVersion; HRESULT hr = S_OK; try { RemoveTestFile(filename); // Open new file IAAFFile *pFile = NULL; TestProductID.productVersionString = const_cast<aafWChar*>(L"CreateAAFFile"); checkResult( AAFFileOpenNewModifyEx( filename, &fileKind, 0, &TestProductID, &pFile) ); // Get the header & dictionary IAAFHeader *pHeader = NULL; IAAFDictionary *pDictionary = NULL; checkResult(pFile->GetHeader(&pHeader)); checkResult(pHeader->GetDictionary(&pDictionary)); // Create a MasterMob IAAFMob *pMob = NULL; IAAFClassDef *classDef = NULL; checkResult(pDictionary->LookupClassDef(AUID_AAFMasterMob, &classDef)); checkResult(classDef->CreateInstance(IID_IAAFMob, (IUnknown **)&pMob)); classDef->Release(); checkResult(pMob->SetMobID(TEST_MobID)); checkResult(pMob->SetName(L"CreateAAFFile - MasterMob")); checkResult(pHeader->AddMob(pMob)); pMob->Release(); // Create a SourceMob IAAFSourceMob *pSourceMob = NULL; checkResult(pDictionary->LookupClassDef(AUID_AAFSourceMob, &classDef)); checkResult(classDef->CreateInstance(IID_IAAFSourceMob, (IUnknown **)&pSourceMob)); classDef->Release(); checkResult(pSourceMob->QueryInterface(IID_IAAFMob, (void **)&pMob)); checkResult(pMob->SetMobID(TEST_SourceMobID)); checkResult(pMob->SetName(L"CreateAAFFile - SourceMob")); IAAFEssenceDescriptor *edesc = NULL; IAAFAIFCDescriptor *pAIFCDesc = NULL; checkResult(pDictionary->LookupClassDef(AUID_AAFAIFCDescriptor, &classDef)); checkResult(classDef->CreateInstance(IID_IAAFEssenceDescriptor, (IUnknown **)&edesc)); classDef->Release(); checkResult(edesc->QueryInterface(IID_IAAFAIFCDescriptor, (void **)&pAIFCDesc)); aafUInt8 buf[] = {0x00}; checkResult(pAIFCDesc->SetSummary(sizeof(buf), buf)); checkResult(pSourceMob->SetEssenceDescriptor(edesc)); checkResult(pHeader->AddMob(pMob)); pAIFCDesc->Release(); edesc->Release(); pSourceMob->Release(); pMob->Release(); pDictionary->Release(); pHeader->Release(); // Save & close the file checkResult(pFile->Save()); checkResult(pFile->Close()); checkResult(pFile->Release()); cout << "CreateAAFFile() - created new file" << endl; } catch (HRESULT& rResult) { hr = rResult; cout << "*** CreateAAFFile: caught error hr=0x" << hex << hr << dec << endl; } return hr; }
static HRESULT ProcessAAFFile(const aafWChar * pFileName, testType_t testType) { IAAFFile * pFile = NULL; IAAFHeader * pHeader = NULL; IAAFDictionary* pDictionary = NULL; IEnumAAFMobs* pMobIter = NULL; aafNumSlots_t numMobs, numSlots; aafSearchCrit_t criteria; aafMobID_t mobID; aafWChar namebuf[1204]; const aafWChar* slotName = L"A slot in Composition Mob"; IAAFComponent* pComponent = NULL; IAAFComponent* aComponent = NULL; IEnumAAFMobSlots* pMobSlotIter = NULL; IAAFMobSlot* pMobSlot = NULL; IAAFTimelineMobSlot* newSlot = NULL; IAAFSegment* seg = NULL; IAAFSegment* pSegment = NULL; IAAFMob* pCompMob = NULL; IAAFMob* pMob = NULL; aafPosition_t zeroPos = 0; IAAFSequence* pAudioSequence = NULL; IAAFSourceClip* pSourceClip = NULL; aafLength_t duration; IAAFTimelineMobSlot* pTimelineMobSlot = NULL; IAAFClassDef *pCompositionMobDef = NULL; IAAFClassDef *pSequenceDef = NULL; IAAFClassDef *pSourceClipDef = NULL; IAAFDataDef *pSoundDef = NULL; IAAFDataDef *pDataDef = NULL; // Set the edit rate information aafRational_t editRate; editRate.numerator = 48000; editRate.denominator = 1; // Set search condition to true bool lookingForAudio = true; // Call the routine (from ExportAudioExample) to make the file for processing check(CreateAAFFile(pwFileName, NULL, testStandardCalls, &pFile)); /* Get the Header and iterate through the Master Mobs in the existing file */ check(pFile->GetHeader(&pHeader)); check(pHeader->GetDictionary(&pDictionary)); /* Lookup class definitions for the objects we want to create. */ check(pDictionary->LookupClassDef(AUID_AAFCompositionMob, &pCompositionMobDef)); check(pDictionary->LookupClassDef(AUID_AAFSequence, &pSequenceDef)); check(pDictionary->LookupClassDef(AUID_AAFSourceClip, &pSourceClipDef)); /* Lookup any necessary data definitions. */ check(pDictionary->LookupDataDef(kAAFDataDef_Sound, &pSoundDef)); // Get the number of master mobs in the existing file (must not be zero) check(pHeader->CountMobs(kAAFMasterMob, &numMobs)); if (numMobs != 0) { printf("Found %d Master Mobs\n", numMobs); criteria.searchTag = kAAFByMobKind; criteria.tags.mobKind = kAAFMasterMob; check(pHeader->GetMobs(&criteria, &pMobIter)); /* Create a Composition Mob */ check(pCompositionMobDef-> CreateInstance(IID_IAAFMob, (IUnknown **)&pCompMob)); /* Append the Mob to the Header */ check(pHeader->AddMob(pCompMob)); /* Create a TimelineMobSlot with an audio sequence */ check(pSequenceDef-> CreateInstance(IID_IAAFSequence, (IUnknown **)&pAudioSequence)); check(pAudioSequence->QueryInterface(IID_IAAFSegment, (void **)&seg)); check(pAudioSequence->QueryInterface(IID_IAAFComponent, (void **)&aComponent)); check(aComponent->SetDataDef(pSoundDef)); check(pCompMob->AppendNewTimelineSlot(editRate, seg, 1, slotName, zeroPos, &newSlot)); seg->Release(); seg = NULL; newSlot->Release(); newSlot = NULL; // This variable is about to be overwritten so we need to release the old interface aComponent->Release(); aComponent = NULL; while((AAFRESULT_SUCCESS == pMobIter->NextOne(&pMob))) { // Print out information about the Mob char mobIDstr[256]; char mobName[256]; check(pMob->GetMobID (&mobID)); check(pMob->GetName (namebuf, sizeof(namebuf))); convert(mobName, sizeof(mobName), namebuf); MobIDtoString(mobID, mobIDstr); printf(" MasterMob Name = '%s'\n", mobName); printf(" (mobID %s)\n", mobIDstr); // Add a Source Clip for each Master Mob to the audio sequence by iterating check(pMob->GetSlots(&pMobSlotIter)); /* Iterating through all Mob Slots */ // Get the number of slots check(pMob->CountSlots(&numSlots)); while (lookingForAudio && (AAFRESULT_SUCCESS == pMobSlotIter->NextOne(&pMobSlot))); { /* Check to see if it is an Audio Timeline Mob Slot */ HRESULT hr; hr=pMobSlot->QueryInterface(IID_IAAFTimelineMobSlot,(void **) &pTimelineMobSlot); if (SUCCEEDED(hr)) { printf("Found a timeline mob slot\n"); check(pMobSlot->GetDataDef(&pDataDef)); // Check that we have a sound file by examining its data definition aafBool bIsSoundKind = kAAFFalse; check(pDataDef->IsSoundKind(&bIsSoundKind)); if (kAAFTrue == bIsSoundKind) { printf("Found a sound file\n"); // We are no longer looking for audio data so set boolean lookingForAudio = false; /* Get the information for the new source clip */ check(pMob->GetMobID(&sourceRef.sourceID)); check(pMobSlot->GetSlotID(&sourceRef.sourceSlotID)); check(pTimelineMobSlot->GetOrigin(&sourceRef.startTime)); check(pMobSlot->GetSegment(&pSegment)); check(pSegment->QueryInterface(IID_IAAFComponent, (void **)&pComponent)); check(pComponent->GetLength(&duration)); pComponent->Release(); pComponent = NULL; pSegment->Release(); pSegment = NULL; // this loop is to be removed upon fixing of the bug // in essenceaccess relating to codec definitions... int j = 0; for (j=0; j<10; j++) { /* Create a new Source Clip */ check(pSourceClipDef-> CreateInstance(IID_IAAFSourceClip, (IUnknown **)&pSourceClip)); // Initialize the Source Clip check(pSourceClip->Initialize( pSoundDef, duration, sourceRef)); check(pSourceClip->QueryInterface(IID_IAAFComponent, (void **) &pComponent)); check(pAudioSequence->AppendComponent(pComponent)); pComponent->Release(); pComponent = NULL; pSourceClip->Release(); pSourceClip = NULL; } } pTimelineMobSlot->Release(); pTimelineMobSlot = NULL; pDataDef->Release(); pDataDef = NULL; } pMobSlot->Release(); pMobSlot = NULL; } pMobSlotIter->Release(); pMobSlotIter = NULL; pMob->Release(); pMob = NULL; } pAudioSequence->Release(); pAudioSequence = NULL; pCompMob->Release(); pCompMob = NULL; pMobIter->Release(); pMobIter = NULL; } else { printf("Error with file: File has no Master mobs.\n"); } cleanup: // Cleanup and return if (pSourceClip) pSourceClip->Release(); if (pComponent) pComponent->Release(); if (pSegment) pSegment->Release(); if (pTimelineMobSlot) pTimelineMobSlot->Release(); if (pMobSlotIter) pMobSlotIter->Release(); if (pMob) pMob->Release(); if (newSlot) newSlot->Release(); if (aComponent) aComponent->Release(); if (seg) seg->Release(); if (pAudioSequence) pAudioSequence->Release(); if (pCompMob) pCompMob->Release(); if (pMobIter) pMobIter->Release(); if (pDataDef) pDataDef->Release(); if (pSoundDef) pSoundDef->Release(); if (pSourceClipDef) pSourceClipDef->Release(); if (pSequenceDef) pSequenceDef->Release(); if (pCompositionMobDef) pCompositionMobDef->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pFile) { /* Save the AAF file */ pFile->Save(); /* Close the AAF file */ pFile->Close(); pFile->Release(); } return moduleErrorTmp; }
static HRESULT ModifyAAFFile(aafWChar *filename, int level) { HRESULT hr = S_OK; try { // Open existing file for modification IAAFFile *pFile = NULL; TestProductID.productVersionString = const_cast<aafWChar*>(L"ModifyAAFFile"); checkResult( AAFFileOpenExistingModify( filename, 0, // modeFlags &TestProductID, &pFile) ); cout << "ModifyAAFFile() - appended Identification" << endl; // Get the header & dictionary IAAFHeader *pHeader = NULL; IAAFDictionary *pDictionary = NULL; checkResult(pFile->GetHeader(&pHeader)); checkResult(pHeader->GetDictionary(&pDictionary)); // Search for Mobs IAAFMob *pFileMob = NULL; IEnumAAFMobs *pFileMobIter = NULL; aafSearchCrit_t criteria; criteria.searchTag = kAAFByMobKind; criteria.tags.mobKind = kAAFFileMob; // Search by File Mob checkResult(pHeader->GetMobs(&criteria, &pFileMobIter)); while (AAFRESULT_SUCCESS == pFileMobIter->NextOne(&pFileMob)) { if (level == 0) break; IAAFEssenceDescriptor *edesc = NULL; IAAFSourceMob *pSourceMob = NULL; CR(pFileMob->QueryInterface(IID_IAAFSourceMob, (void **)&pSourceMob)); CR(pSourceMob->GetEssenceDescriptor(&edesc)); // Change the Name property CR(pFileMob->SetName(L"ModifyAAFFile - modified Name")); cout << "ModifyAAFFile() - changed FileMob's Name property" << endl; if (level == 1) break; // Change descriptor's properties IAAFAIFCDescriptor *pAIFCDesc = NULL; CR(edesc->QueryInterface(IID_IAAFAIFCDescriptor, (void **)&pAIFCDesc)); aafUInt8 AIFCsum[] = {0xa1,0xfc}; CR(pAIFCDesc->SetSummary(sizeof(AIFCsum), AIFCsum)); pAIFCDesc->Release(); edesc->Release(); cout << "ModifyAAFFile() - changed AIFCDescriptor's Summary" << endl; if (level == 2) break; // Change descriptor to new one (overwriting old one) IAAFClassDef *classDef = NULL; IAAFFileDescriptor *pFileDesc = NULL; IAAFWAVEDescriptor *pWAVEDesc = NULL; IAAFEssenceDescriptor *pNewEdesc = NULL; CR(pDictionary->LookupClassDef(AUID_AAFWAVEDescriptor, &classDef)); CR(classDef->CreateInstance(IID_IAAFFileDescriptor, (IUnknown **)&pFileDesc)); CR(pFileDesc->QueryInterface(IID_IAAFWAVEDescriptor, (void **)&pWAVEDesc)); CR(pFileDesc->QueryInterface(IID_IAAFEssenceDescriptor, (void **)&pNewEdesc)); aafUInt8 WAVEsum[] = {0x1a,0x1e,0xee,0xee}; CR(pWAVEDesc->SetSummary(sizeof(WAVEsum), WAVEsum)); CR(pSourceMob->SetEssenceDescriptor(pNewEdesc)); pNewEdesc->Release(); pWAVEDesc->Release(); pFileDesc->Release(); classDef->Release(); cout << "ModifyAAFFile() - replaced AIFCDescriptor with WAVEDescriptor" << endl; if (level == 3) break; // Add EssenceData IAAFEssenceData *pEssenceData = NULL; IAAFEssenceData2 *pEssenceData2 = NULL; IAAFPlainEssenceData *pPlainEssenceData = NULL; aafUInt32 bytesWritten = 0; aafUInt8 essdata[] = "Zaphod Beeblebrox"; CR(pDictionary->LookupClassDef(AUID_AAFEssenceData, &classDef)); CR(classDef->CreateInstance(IID_IAAFEssenceData, (IUnknown **)&pEssenceData)); CR(pEssenceData->SetFileMob(pSourceMob)); CR(pHeader->AddEssenceData(pEssenceData)); CR(pEssenceData->QueryInterface(IID_IAAFEssenceData2, (void**)&pEssenceData2)); CR(pEssenceData2->GetPlainEssenceData(0, &pPlainEssenceData)); CR(pPlainEssenceData->Write(sizeof(essdata), essdata, &bytesWritten)); pEssenceData->Release(); pEssenceData2->Release(); pPlainEssenceData->Release(); classDef->Release(); cout << "ModifyAAFFile() - added EssenceData" << endl; pSourceMob->Release(); } pFileMob->Release(); pFileMobIter->Release(); pDictionary->Release(); pHeader->Release(); // Save & close the file checkResult(pFile->Save()); checkResult(pFile->Close()); checkResult(pFile->Release()); } catch (HRESULT& rResult) { hr = rResult; cout << "*** ModifyAAFFile: caught error hr=0x" << hex << hr << dec << endl; } return hr; }
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; }
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; }
extern int main(int argc, char *argv[]) { const char *filename_cstr = "test.aaf"; #ifndef _MSC_VER setlocale (LC_ALL, "en_US.UTF-8"); #endif if (argc >= 2) { filename_cstr = argv[1]; } // convert C str to wide string aafWChar filename[FILENAME_MAX]; size_t status = mbstowcs(filename, filename_cstr, sizeof(filename)); if (status == (size_t)-1) { fprintf(stderr, "mbstowcs failed for \"%s\"\n", filename_cstr); return 1; } remove(filename_cstr); IAAFFile *pFile = NULL; int mode = 0; aafProductIdentification_t productID; aafProductVersion_t TestVersion = {1, 1, 0, 0, kAAFVersionUnknown}; productID.companyName = (aafCharacter*)L"HSC"; productID.productName = (aafCharacter*)L"String Tester"; productID.productVersion = &TestVersion; productID.productVersionString = NULL; productID.productID = TestProductID; productID.platform = (aafCharacter*)L"Linux"; // Create new AAF file check(AAFFileOpenNewModify(filename, mode, &productID, &pFile)); // Create a simple Mob IAAFClassDef *classDef = NULL; IAAFMob *pMob = NULL; IAAFHeader *pHeader = NULL; IAAFDictionary *pDictionary = NULL; check(pFile->GetHeader(&pHeader)); check(pHeader->GetDictionary(&pDictionary)); check(pDictionary->LookupClassDef(AUID_AAFMasterMob, &classDef)); check(classDef->CreateInstance(IID_IAAFMob, (IUnknown **)&pMob)); classDef->Release(); check(pMob->SetMobID(TEST_MobID)); // UTF-8 for codepoint U+1D11E (musical G Clef): 0xf0,0x9d,0x84,0x9e // UTF-8 for codepoint U+1D122 (musical F Clef): 0xf0,0x9d,0x84,0xa2 // http://unicode.org/charts/PDF/U1D100.pdf // http://en.wikipedia.org/wiki/UTF-8 aafCharacter *mobname; const unsigned char inputStr[] = { 0xf0,0x9d,0x84,0x9e, // U+1D11E 0xf0,0x9d,0x84,0xa2, // U+1D122 0x4d, 0x6f, 0x62, // 'M' 'o' 'b' 0x0 }; // Convert UTF-8 inputStr to native wchar_t representation (UTF-32 Unix, UTF-16 Windows) int wlen = 0, n; #ifndef _MSC_VER int ret; char *p = (char *)inputStr; while ((ret = mblen(p, 4)) > 0) { ++wlen; p+=ret; } mobname = new aafCharacter[wlen+1]; n = mbstowcs(mobname, (const char *)inputStr, wlen+1); if (n == -1) { fprintf (stderr, "mbstowcs returned -1. Invalid multibyte string\n"); exit(1); } #else // Under Windows we must use MultiByteToWideChar() to get correct UTF-8 conversion to UTF-16 // since mbstowcs() is broken for UTF-8. wlen = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, (LPCSTR)inputStr, -1, NULL, 0); if (wlen == 0) { fprintf (stderr, "MultiByteToWideChar returned 0. Invalid multibyte string\n"); exit(1); } mobname = new aafCharacter[wlen]; n = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, (LPCSTR)inputStr, -1, mobname, wlen); if (n == 0) { fprintf (stderr, "MultiByteToWideChar returned 0. Invalid multibyte string\n"); exit(1); } #endif // SetName() calls OMSimpleProperty::set() which does a memcpy of the mobname string // to an OMByte* variable 'bits()' at OMProperty.cpp:399 // Found by setting an rwatch on mobname address. check(pMob->SetName(mobname)); aafUInt32 size_before = 0; check(pMob->GetNameBufLen(&size_before)); check(pHeader->AddMob(pMob)); pMob->Release(); pHeader->Release(); pDictionary->Release(); // All the work of storing to disk happens during Save() // The bits() variable is next read in OMType::contract() at OMType.cpp:137 // which is called by ImplAAFTypeDefCharacter::externalize() at ImplAAFTypeDefCharacter.cpp:307 // which is called by ImplAAFTypeDefString::externalize() at ImplAAFTypeDefString.cpp:584 // which is called by OMSSStoredObject::save() at OMSSStoredObject.cpp:382 check(pFile->Save()); check(pFile->Close()); pFile->Release(); // OMCharacterStringProperty<CharacterType>::stringLength() at OMVariableSizePropertyT.h:80 // calculates string length of AAF string properties // Read AAF file back in check(AAFFileOpenExistingRead(filename, mode, &pFile)); // Get the Mob check(pFile->GetHeader(&pHeader)); check(pHeader->LookupMob(TEST_MobID, &pMob)); aafUInt32 size_after = 0; check(pMob->GetNameBufLen(&size_after)); aafCharacter *mobname_after = new aafCharacter[size_after]; check(pMob->GetName(mobname_after, size_after)); // Compare Mob name before storing to disk with Mob name read back from disk int test_result = 0; if (size_before != size_after) { printf("size_before=%d != size_after=%d\n", size_before, size_after); test_result = 1; } else { if (memcmp(mobname, mobname_after, size_before) != 0) { printf("wchar_t* mobname and wchar_t* mobname_after differ:\n"); printf(" %s\n", hexDump(mobname, size_before)); printf(" %s\n", hexDump(mobname_after, size_after)); test_result = 1; } } // Check if the multibyte (UTF-8) versions of mobname and mobname_after match. char *outputStr; #ifndef _MSC_VER wlen = wcslen(mobname_after)*sizeof(aafCharacter) + 1; outputStr = new char [wlen]; n = wcstombs (outputStr, mobname_after, wlen); if (n == -1) { fprintf(stderr, "Could not convert mobname_after to multibyte str\n"); exit(1); } #else wlen = WideCharToMultiByte(CP_UTF8, 0, mobname_after, -1, NULL, 0, NULL, NULL); if (wlen == 0) { fprintf (stderr, "Failed to convert mobname_after to multibyte string\n"); exit(1); } outputStr = new char[wlen]; wlen = WideCharToMultiByte(CP_UTF8, 0, mobname_after, -1, outputStr, wlen, NULL, NULL); #endif if (strlen((char *)inputStr) != strlen(outputStr)) { fprintf(stderr, "UTF-8 version of string: input length(%d) != output length(%d)\n", (int)strlen((char *)inputStr), (int)strlen(outputStr)); test_result = 1; } if (strcmp((char *)inputStr, outputStr) != 0) { fprintf(stderr, "UTF-8 version of string: input and output strings differ\n"); printf(" %s\n", hexDump(inputStr, strlen((char *)inputStr))); printf(" %s\n", hexDump(outputStr, strlen(outputStr))); test_result = 1; } pMob->Release(); pHeader->Release(); check(pFile->Close()); pFile->Release(); delete [] mobname; delete [] mobname_after; return test_result; }
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; }
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; }
//*********************************************************** // // GetObjRefArrayPropFromObject() // // Get an object reference array property on the AAF object // specified by pObj. The value of the property is returned // in pArray. // // Returns: // // On Success: S_OK // On Failure: A failed HRESULT // HRESULT AAFDomainUtils::GetObjRefArrayPropFromObject(IAAFObject* pObj, aafUID_t* pClassID, const aafUID_t* pPropTypeID, aafUID_t* pPropID, IAAFObject*** pArray, aafUInt32* pNumObjects) { IAAFTypeDefVariableArray* pTDVarArray = NULL; IAAFPropertyValue* pPVVarArray = NULL; IAAFTypeDefObjectRef* pTDArrayElement = NULL; IAAFClassDef* pCD; HRESULT hr; // Get the property value for the target property hr = _dict->LookupClassDef(*pClassID, &pCD); if (SUCCEEDED(hr)) { IAAFPropertyDef* pPD; hr = pCD->LookupPropertyDef(*pPropID, &pPD); if (SUCCEEDED(hr)) { aafBool present = kAAFFalse; pObj->IsPropertyPresent(pPD, &present); if (present == kAAFTrue) hr = pObj->GetPropertyValue(pPD, &pPVVarArray); else hr = AAFRESULT_PROP_NOT_PRESENT; pPD->Release(); } pCD->Release(); } // Get the property type def from the dictionary to interpret this property value. if (SUCCEEDED(hr)) { IAAFTypeDef* pTD; hr = _dict->LookupTypeDef(*pPropTypeID, &pTD); if (SUCCEEDED(hr)) { hr = pTD->QueryInterface(IID_IAAFTypeDefVariableArray, (void**)&pTDVarArray); pTD->Release(); } } // Get the array element type def to interpret the element property value. if (SUCCEEDED(hr)) { IAAFTypeDef* pTDElement; hr = pTDVarArray->GetType(&pTDElement); if (SUCCEEDED(hr)) { pTDElement->QueryInterface(IID_IAAFTypeDefObjectRef, (void **)&pTDArrayElement); pTDElement->Release(); } } // Get each element out of the property, convert them to an IAAFObject pointer and // add them to the array of object which is returned to the user. if (SUCCEEDED(hr)) { IAAFObject** pTempArray; aafUInt32 count = 0, numElements = 0; pTDVarArray->GetCount(pPVVarArray, &count); pTempArray = new IAAFObject* [count]; if (pTempArray) { for (aafUInt32 i = 0; i < count; i++) { IAAFPropertyValue* pPVElement; hr = pTDVarArray->GetElementValue(pPVVarArray, i, &pPVElement); if (SUCCEEDED(hr)) { IAAFObject* pTempObj; hr = pTDArrayElement->GetObject(pPVElement, IID_IAAFObject, (IUnknown **)&pTempObj); if (SUCCEEDED(hr)) { pTempArray[numElements] = pTempObj; numElements++; } pPVElement->Release(); } } if (numElements == 0) { delete [] pTempArray; pTempArray = NULL; } *pArray = pTempArray; *pNumObjects = numElements; } } if (pTDArrayElement) pTDArrayElement->Release(); if (pTDVarArray) pTDVarArray->Release(); if (pPVVarArray) pPVVarArray->Release(); return hr; }
//*********************************************************** // // SetObjRefArrayPropOnObject() // // Set an object reference array property on the AAF object // specified by pObj. The value of the property is specified // in pArray. // // Returns: // // On Success: S_OK // On Failure: A failed HRESULT // HRESULT AAFDomainUtils::SetObjRefArrayPropOnObject(IAAFObject* pObj, aafUID_t* pClassID, const aafUID_t* pPropTypeID, const aafUID_t* pElementTypeID, aafUID_t* pPropID, IAAFObject** pArray, aafUInt32 numObjects) { IAAFPropertyValue* pPVArray = NULL; IAAFTypeDef* pTD; HRESULT hr; // For each object in the source array, create a property value // and append it to the property value for the variable array. hr = _dict->LookupTypeDef(*pPropTypeID, &pTD); if (SUCCEEDED(hr)) { IAAFTypeDefVariableArray* pTDVarArray; hr = pTD->QueryInterface(IID_IAAFTypeDefVariableArray, (void**)&pTDVarArray); if (SUCCEEDED(hr)) { IAAFTypeDef* pTDElement; hr = _dict->LookupTypeDef(*pElementTypeID, &pTDElement); if (SUCCEEDED(hr)) { IAAFTypeDefObjectRef* pTDObjRef; hr = pTDElement->QueryInterface (IID_IAAFTypeDefObjectRef, (void **)&pTDObjRef); if (SUCCEEDED(hr)) { for (aafUInt32 i = 0; i < numObjects; i++) { IAAFPropertyValue* pPVObject; hr = pTDObjRef->CreateValue(pArray[i], &pPVObject); if (SUCCEEDED(hr)) { if (pPVArray == NULL) pTDVarArray->CreateEmptyValue(&pPVArray); hr = pTDVarArray->AppendElement(pPVArray, pPVObject); pPVObject->Release(); } } pTDObjRef->Release(); } pTDElement->Release(); } pTDVarArray->Release(); } pTD->Release(); } // If the object reference array was successfully created, // set the property value on the target object. if (pPVArray) { IAAFClassDef* pCD; // Get the class def for the object hr = _dict->LookupClassDef(*pClassID, &pCD); if (SUCCEEDED(hr)) { IAAFPropertyDef* pPD; hr = pCD->LookupPropertyDef(*pPropID, &pPD); if (SUCCEEDED(hr)) { hr = pObj->SetPropertyValue(pPD, pPVArray); pPD->Release(); } pCD->Release(); } pPVArray->Release(); } return hr; }
static HRESULT CreateAAFFile( aafWChar * pFileName, aafUID_constref fileKind, testRawStorageType_t rawStorageType, aafProductIdentification_constref productID) { IAAFFile* pFile = NULL; IAAFHeader * pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFCodecDef* pCodecDef = NULL; IAAFClassDef* pClass = NULL; bool bFileOpen = false; HRESULT hr = S_OK; aafUID_t uid; /* long test; */ try { // Remove the previous test file if any. RemoveTestFile(pFileName); // Create the AAF 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); checkResult(defs.cdCodecDef()-> CreateInstance(IID_IAAFCodecDef, (IUnknown **)&pCodecDef)); checkResult(pCodecDef->AddEssenceKind (defs.ddkAAFMatte())); uid = kAAFNoCodec; checkResult(pCodecDef->Initialize (uid, sName1, sDescription1)); checkResult(pDictionary->LookupClassDef(kAAFClassID_EssenceDescriptor, &pClass)); checkResult(pCodecDef->SetFileDescriptorClass (pClass)); checkResult(pDictionary->RegisterCodecDef(pCodecDef)); pCodecDef->Release(); pCodecDef = NULL; checkResult(defs.cdCodecDef()-> CreateInstance(IID_IAAFCodecDef, (IUnknown **)&pCodecDef)); checkResult(pCodecDef->AddEssenceKind (defs.ddkAAFMatte())); uid = TESTID_2; checkResult(pCodecDef->Initialize (uid, sName2, sDescription2)); checkResult(pCodecDef->SetFileDescriptorClass (pClass)); checkResult(pDictionary->RegisterCodecDef(pCodecDef)); } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pCodecDef) pCodecDef->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pClass) pClass->Release(); if (pFile) { // Close file if (bFileOpen) { pFile->Save(); pFile->Close(); } pFile->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, 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) { 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; }