static HRESULT ReadAAFFile(aafWChar * pFileName) { IAAFFile * pFile = NULL; IAAFHeader * pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFSourceMob* pSourceMob = NULL; IAAFMob* pMob = NULL; IAAFEssenceDescriptor* pEssDesc = NULL; IAAFBWFImportDescriptor* pBWFImportDesc = NULL; IEnumAAFRIFFChunks* pEnum = NULL; IAAFRIFFChunk* pRIFFChunk = NULL; IAAFRIFFChunk* pRIFFChunkTest = NULL; IEnumAAFMobs* pMobIter = NULL; aafUInt32 numData, bytesRead, com, testNum; aafLength_t testRIFFLen; aafNumSlots_t numMobs; char Value[sizeof(RIFFChunksmiley)]; char Value2[sizeof(RIFFChunkfrowney)]; HRESULT hr = AAFRESULT_SUCCESS; wchar_t testString[256]; checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); checkResult( pFile->GetHeader(&pHeader)); // Get the AAF Dictionary so that we can create a fake RIFFChunk to test RemoveUnknownBWFChunks. checkResult(pHeader->GetDictionary(&pDictionary)); CAAFBuiltinDefs defs (pDictionary); checkResult(defs.cdRIFFChunk()->CreateInstance(IID_IAAFRIFFChunk, (IUnknown **)&pRIFFChunkTest)); checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); if (1 == numMobs ) { checkResult(pHeader->GetMobs(NULL, &pMobIter)); checkResult(pMobIter->NextOne(&pMob)); checkResult(pMob->QueryInterface(IID_IAAFSourceMob, (void **)&pSourceMob)); // Back into testing mode checkResult(pSourceMob->GetEssenceDescriptor(&pEssDesc)); checkResult( pEssDesc->QueryInterface( IID_IAAFBWFImportDescriptor, (void**)&pBWFImportDesc )); checkResult(pBWFImportDesc->GetFileSecurityReport(&testNum)); checkExpression(testNum==TEST_FileSecurityReport, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetFileSecurityWave(&testNum)); checkExpression(testNum==TEST_FileSecurityWave, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetCodingHistory(testString, sizeof(testString))); checkExpression(wcscmp(testString, TEST_CodingHistory) == 0, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetBasicData(testString, sizeof(testString))); checkExpression(wcscmp(testString, TEST_BasicData) == 0, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetStartOfModulation(testString, sizeof(testString))); checkExpression(wcscmp(testString, TEST_StartOfModulation) == 0, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetQualityEvent(testString, sizeof(testString))); checkExpression(wcscmp(testString, TEST_QualityEvent) == 0, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetEndOfModulation(testString, sizeof(testString))); checkExpression(wcscmp(testString, TEST_EndOfModulation) == 0, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetQualityParameter(testString, sizeof(testString))); checkExpression(wcscmp(testString, TEST_QualityParameter) == 0, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetOperatorComment(testString, sizeof(testString))); checkExpression(wcscmp(testString, TEST_OperatorComment) == 0, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetCueSheet(testString, sizeof(testString))); checkExpression(wcscmp(testString, TEST_CueSheet) == 0, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->CountUnknownBWFChunks(&numData)); checkExpression(2 == numData, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetUnknownBWFChunks(&pEnum)); for(com = 0; com < numData; com++) { checkResult(pEnum->NextOne(&pRIFFChunk)); pRIFFChunk->GetLength(&testRIFFLen); checkExpression(testRIFFLen!=chunkLength /*huh?*/, AAFRESULT_TEST_FAILED); checkResult(pRIFFChunk->GetLength(&testRIFFLen)); pRIFFChunk->GetChunkID(&testNum); if (testNum==1){ checkExpression(sizeof(RIFFChunksmiley) == testRIFFLen, AAFRESULT_TEST_FAILED); checkResult(pRIFFChunk->Read( sizeof(Value), (unsigned char *)Value, &bytesRead)); checkExpression(memcmp(Value, RIFFChunksmiley, sizeof(RIFFChunksmiley)) == 0, AAFRESULT_TEST_FAILED); } else if (testNum==2){ checkExpression(sizeof(RIFFChunkfrowney) == testRIFFLen, AAFRESULT_TEST_FAILED); checkResult(pRIFFChunk->Read( sizeof(Value2), (unsigned char *)Value2, &bytesRead)); checkExpression(memcmp(Value2, RIFFChunkfrowney, sizeof(RIFFChunkfrowney)) == 0, AAFRESULT_TEST_FAILED); } pRIFFChunk->Release(); pRIFFChunk = NULL; } checkResult(pEnum->Reset()); checkResult(pEnum->NextOne(&pRIFFChunk)); checkExpression((pBWFImportDesc->RemoveUnknownBWFChunkAt(2))==AAFRESULT_BADINDEX, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->RemoveUnknownBWFChunkAt(0)); checkResult(pBWFImportDesc->CountUnknownBWFChunks(&numData)); checkExpression(1 == numData, AAFRESULT_TEST_FAILED); pRIFFChunk->Release(); pRIFFChunk = NULL; pEnum->Release(); pEnum = NULL; pBWFImportDesc->Release(); pBWFImportDesc = NULL; pEssDesc->Release(); pEssDesc = NULL; pSourceMob->Release(); pSourceMob = NULL; pMobIter->Release(); pMobIter = NULL; } pRIFFChunkTest->Release(); pRIFFChunkTest = NULL; pMob->Release(); pMob = NULL; pHeader->Release(); pHeader = NULL; pDictionary->Release(); pDictionary = NULL; pFile->Close(); pFile->Release(); pFile = NULL; return hr; }
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 *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 ReadAAFFile(aafWChar * pFileName) { IAAFFile* pFile = NULL; IAAFHeader* pHeader = NULL; IEnumAAFMobs* pMobIter = NULL; IAAFMob* pMob = NULL; IAAFSourceMob* pSourceMob = NULL; IAAFEssenceDescriptor* pEssDesc = NULL; IAAFDataEssenceDescriptor* pDataEssenceDesc = NULL; aafNumSlots_t numMobs = 0; aafUID_t dataEssenceCoding, dataEssTestVal; HRESULT hr = AAFRESULT_SUCCESS; try { memset(&dataEssTestVal, 0, sizeof(aafUID_t)); // Open the AAF file checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); // Get the AAF file header. checkResult(pFile->GetHeader(&pHeader)); checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED); checkResult(pHeader->GetMobs(NULL, &pMobIter)); checkResult(pMobIter->NextOne(&pMob)); checkResult(pMob->QueryInterface(IID_IAAFSourceMob, (void **)&pSourceMob)); // Back into testing mode checkResult(pSourceMob->GetEssenceDescriptor(&pEssDesc)); // if there is an Essence Descriptor then it MUST be an (essence) DataEssence Descriptor checkResult(pEssDesc->QueryInterface(IID_IAAFDataEssenceDescriptor, (void **) &pDataEssenceDesc)); checkResult(pDataEssenceDesc->GetDataEssenceCoding(&dataEssenceCoding)); checkExpression(memcmp(&dataEssenceCoding, &dataEssTestVal, sizeof(aafUID_t)) == 0, AAFRESULT_TEST_FAILED); } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pDataEssenceDesc) pDataEssenceDesc->Release(); if (pEssDesc) pEssDesc->Release(); if (pSourceMob) pSourceMob->Release(); if (pMob) pMob->Release(); if (pMobIter) pMobIter->Release(); if (pHeader) pHeader->Release(); if (pFile) { pFile->Close(); pFile->Release(); } return hr; }
static HRESULT CreateAAFFile( aafWChar * pFileName, aafUID_constref fileKind, testRawStorageType_t rawStorageType, aafProductIdentification_constref productID) { // IAAFSession * pSession = NULL; IAAFFile * pFile = NULL; bool bFileOpen = false; IAAFHeader * pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFSourceMob *pSourceMob = NULL; IAAFMob *pMob = NULL; IAAFEssenceDescriptor *edesc = NULL; HRESULT hr = S_OK; 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 FileMob checkResult(defs.cdSourceMob()-> CreateInstance(IID_IAAFSourceMob, (IUnknown **)&pSourceMob)); checkResult(pSourceMob->QueryInterface (IID_IAAFMob, (void **)&pMob)); checkResult(pMob->SetMobID(TEST_File_MobID)); checkResult(pMob->SetName(L"File Mob")); // Check the Mob2 usage code implementations. // Need IAAFMob2 for to do that. { IAAFSmartPointer<IAAFMob2> pMobInterface2; checkResult( pMob->QueryInterface( IID_IAAFMob2, reinterpret_cast<void**>(&pMobInterface2) ) ); checkResult( pMobInterface2->SetUsageCode( kAAFUsage_Template ) ); } // Create a concrete subclass of FileDescriptor 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; checkResult(pSourceMob->SetEssenceDescriptor (edesc)); checkResult(pHeader->AddMob(pMob)); // Reusing local variable so we need to release the inteface. pMob->Release(); pMob = NULL; // Create a MasterMob checkResult(defs.cdMasterMob()-> CreateInstance(IID_IAAFMob, (IUnknown **)&pMob)); checkResult(pMob->SetMobID(TEST_Master_MobID)); checkResult(pMob->SetName(L"Master Mob")); // Check the Mob2 usage code implementations. // Need IAAFMob2 for to do that. { IAAFSmartPointer<IAAFMob2> pMobInterface2; checkResult( pMob->QueryInterface( IID_IAAFMob2, reinterpret_cast<void**>(&pMobInterface2) ) ); checkResult( pMobInterface2->SetUsageCode( kAAFUsage_Template ) ); } checkResult(pHeader->AddMob(pMob)); // Reusing local variable so we need to release the inteface. pMob->Release(); pMob = NULL; // Create a CompositionMob checkResult(defs.cdCompositionMob()-> CreateInstance(IID_IAAFMob, (IUnknown **)&pMob)); checkResult(pMob->SetMobID(TEST_Composition_MobID)); checkResult(pMob->SetName(L"Composition Mob")); // Check the Mob2 usage code implementations. // Need IAAFMob2 for to do that. IAAFSmartPointer<IAAFMob2> pMobInterface2; checkResult( pMob->QueryInterface( IID_IAAFMob2, reinterpret_cast<void**>(&pMobInterface2) ) ); checkResult( pMobInterface2->SetUsageCode( kAAFUsage_TopLevel ) ); checkResult(pHeader->AddMob(pMob)); } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return 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(); } return hr; }
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; }
static HRESULT CreateAAFFile( aafWChar * pFileName, aafUID_constref fileKind, testRawStorageType_t rawStorageType, aafProductIdentification_constref productID) { // IAAFSession *pSession = NULL; IAAFFile *pFile = NULL; IAAFHeader *pHeader = NULL; IAAFDictionary *pDictionary = NULL; IAAFLocator *pLocator = NULL; IAAFLocator *pLocator2 = NULL; IAAFSourceMob *pSourceMob = NULL; IAAFMob *pMob = NULL; IAAFEssenceDescriptor *edesc = NULL; IEnumAAFLocators *pEnumLocators = NULL; aafUInt32 numLocators, numLocators2; aafUInt32 i; HRESULT hr = AAFRESULT_SUCCESS, localhr = AAFRESULT_SUCCESS; bool bFileOpen = false; // aafUID_t ddef = kAAFDataDef_Sound; 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)); // Initialize mob properties: checkResult(pSourceMob->QueryInterface (IID_IAAFMob, (void **)&pMob)); checkResult(pMob->SetMobID(TEST_MobID)); checkResult(pMob->SetName(L"EssenceDescriptorTest")); // Create the descriptor: // instantiate 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; checkResult(pSourceMob->SetEssenceDescriptor (edesc)); /* CountLocators() ******************************************/ localhr = AAFRESULT_SUCCESS; // Verify AAFRESULT_NULL_PARAM is returned if (edesc->CountLocators(NULL) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; // Verify that there are no locators if (edesc->CountLocators(&numLocators) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; if (0 != numLocators) localhr = AAFRESULT_TEST_FAILED; if (localhr == AAFRESULT_SUCCESS) cout<< " CountLocators() ... Passed"<< endl; else { cout<< " CountLocators() ... FAILED"<< endl; hr = AAFRESULT_TEST_FAILED; } /* AppendLocator() ******************************************/ localhr = AAFRESULT_SUCCESS; // Verify AAFRESULT_NULL_PARAM is returned if (edesc->AppendLocator(NULL) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; // Append and Count a bunch of Locators for (i=1; i<=10; i++) { // Make a concrete subclass of locator, and attach it to // the EssenceDescriptor checkResult(defs.cdNetworkLocator()-> CreateInstance(IID_IAAFLocator, (IUnknown **)&pLocator)); if (edesc->AppendLocator(pLocator) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; // Verify the number of locators numLocators = 0; edesc->CountLocators(&numLocators); if (i != numLocators) localhr = AAFRESULT_TEST_FAILED; // Verify that locator was appended edesc->GetLocatorAt(i-1, &pLocator2); if (pLocator2 != pLocator) localhr = AAFRESULT_TEST_FAILED; pLocator->Release(); pLocator = 0; pLocator2->Release(); pLocator2 = 0; } // Make sure we can't add it again // if (edesc->AppendLocator(pLocator) != AAFRESULT_OBJECT_ALREADY_ATTACHED) // localhr = AAFRESULT_TEST_FAILED; if (localhr == AAFRESULT_SUCCESS) cout<< " AppendLocator() ... Passed"<< endl; else { cout<< " AppendLocator() ... FAILED"<< endl; hr = AAFRESULT_TEST_FAILED; } /* PrependLocator() ******************************************/ localhr = AAFRESULT_SUCCESS; // Verify AAFRESULT_NULL_PARAM is returned if (edesc->PrependLocator(NULL) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; for (; i<=20; i++) { // Make a concrete subclass of locator, and attach it to // the EssenceDescriptor checkResult(defs.cdNetworkLocator()-> CreateInstance(IID_IAAFLocator, (IUnknown **)&pLocator)); if (edesc->PrependLocator(pLocator) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; // Verify the number of locators numLocators = 0; edesc->CountLocators(&numLocators); if (i != numLocators) localhr = AAFRESULT_TEST_FAILED; // Verify that locator was prepended edesc->GetLocatorAt(0, &pLocator2); if (pLocator2 != pLocator) localhr = AAFRESULT_TEST_FAILED; pLocator->Release(); pLocator = 0; pLocator2->Release(); pLocator2 = 0; } if (localhr == AAFRESULT_SUCCESS) cout<< " PrependLocator() ... Passed"<< endl; else { cout<< " PrependLocator() ... FAILED"<< endl; hr = AAFRESULT_TEST_FAILED; } /* InsertLocatorAt() **************************************/ localhr = AAFRESULT_SUCCESS; // Make a concrete subclass of locator to attach checkResult(defs.cdNetworkLocator()-> CreateInstance(IID_IAAFLocator, (IUnknown **)&pLocator)); // Verify that we can't remove an index value that is out of range if (edesc->InsertLocatorAt(numLocators+1, pLocator) != AAFRESULT_BADINDEX) localhr = AAFRESULT_TEST_FAILED; // Verify behavior when NULL is passed in if (edesc->InsertLocatorAt(1, NULL) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; edesc->CountLocators(&numLocators); // Insert it if (edesc->InsertLocatorAt(0, pLocator) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; // Check it edesc->GetLocatorAt(0, &pLocator2); if (pLocator2 != pLocator) localhr = AAFRESULT_TEST_FAILED; // Count it edesc->CountLocators(&numLocators2); if (numLocators2 != numLocators+1) localhr = AAFRESULT_TEST_FAILED; pLocator->Release(); pLocator = 0; pLocator2->Release(); pLocator2 = 0; edesc->CountLocators(&numLocators); // Make a concrete subclass of locator to attach in the middle checkResult(defs.cdNetworkLocator()-> CreateInstance(IID_IAAFLocator, (IUnknown **)&pLocator)); // Insert it if (edesc->InsertLocatorAt(numLocators/2, pLocator) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; // Check it edesc->GetLocatorAt(numLocators/2, &pLocator2); if (pLocator2 != pLocator) localhr = AAFRESULT_TEST_FAILED; // Count it edesc->CountLocators(&numLocators2); if (numLocators2 != numLocators+1) localhr = AAFRESULT_TEST_FAILED; pLocator->Release(); pLocator = 0; pLocator2->Release(); pLocator2 = 0; edesc->CountLocators(&numLocators); // Make a concrete subclass of locator to attach to the end checkResult(defs.cdNetworkLocator()-> CreateInstance(IID_IAAFLocator, (IUnknown **)&pLocator)); // Insert it. note: its 0 based so the end is numLocators - 1 if (edesc->InsertLocatorAt(numLocators-1, pLocator) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; // Check it edesc->GetLocatorAt(numLocators-1, &pLocator2); if (pLocator2 != pLocator) localhr = AAFRESULT_TEST_FAILED; // Count it edesc->CountLocators(&numLocators2); if (numLocators2 != numLocators+1) localhr = AAFRESULT_TEST_FAILED; // Make sure we can't add it again if (edesc->InsertLocatorAt(numLocators+1, pLocator) != AAFRESULT_OBJECT_ALREADY_ATTACHED) localhr = AAFRESULT_TEST_FAILED; pLocator->Release(); pLocator = 0; pLocator2->Release(); pLocator2 = 0; if (localhr == AAFRESULT_SUCCESS) cout<< " InsertLocatorAt() ... Passed"<< endl; else { cout<< " InsertLocatorAt() ... FAILED"<< endl; hr = AAFRESULT_TEST_FAILED; } /* GetLocatorAt() ******************************************/ localhr = AAFRESULT_SUCCESS; edesc->CountLocators(&numLocators); // Verify that we can't remove an index value that is out of range // note: Locators index is 0 based so the index numLocators is out of range if (edesc->GetLocatorAt(numLocators, &pLocator) != AAFRESULT_BADINDEX) localhr = AAFRESULT_TEST_FAILED; // Verify behavior when NULL is passed in if (edesc->GetLocatorAt(1, NULL) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; for (i=0; i<numLocators; i++) { pLocator = NULL; if (edesc->GetLocatorAt(i, &pLocator) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; if (pLocator != NULL) pLocator->Release(); } if (localhr == AAFRESULT_SUCCESS) cout<< " GetLocatorAt() ... Passed"<< endl; else { cout<< " GetLocatorAt() ... FAILED"<< endl; hr = AAFRESULT_TEST_FAILED; } /* GetLocators() ******************************************/ if (edesc->GetLocators(NULL) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; pEnumLocators = NULL; if (edesc->GetLocators(&pEnumLocators) == AAFRESULT_SUCCESS) { if (pEnumLocators != NULL) { // Try a simple test to confirm if (pEnumLocators->NextOne(&pLocator) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; edesc->GetLocatorAt(0, &pLocator2); if (pLocator != pLocator2) localhr = AAFRESULT_TEST_FAILED; else pLocator2->Release(); pLocator->Release(); pLocator = 0; pEnumLocators->Release(); } else localhr = AAFRESULT_TEST_FAILED; } else localhr = AAFRESULT_TEST_FAILED; if (localhr == AAFRESULT_SUCCESS) cout<< " GetLocators() ... Passed"<< endl; else { cout<< " GetLocators() ... FAILED"<< endl; hr = AAFRESULT_TEST_FAILED; } /* RemoveLocatorAt() ******************************************/ localhr = AAFRESULT_SUCCESS; // Verify that we can't remove an index value that is out of range // note: Locators index is 0 based so the index numLocators is out of range if (edesc->RemoveLocatorAt (numLocators) != AAFRESULT_BADINDEX) localhr = AAFRESULT_TEST_FAILED; // Remove locator at beginning, but Release it first edesc->CountLocators(&numLocators); edesc->GetLocatorAt(0, &pLocator); pLocator->Release(); edesc->GetLocatorAt(1, &pLocator); if (edesc->RemoveLocatorAt (0) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; // Verify the count edesc->CountLocators(&numLocators2); if (numLocators2 != (numLocators - 1)) localhr = AAFRESULT_TEST_FAILED; edesc->GetLocatorAt(0, &pLocator2); // Verify that the locators shifted properly if (pLocator != pLocator2) localhr = AAFRESULT_TEST_FAILED; pLocator->Release(); pLocator = 0; pLocator2->Release(); pLocator2 = 0; // Remove locator in middle, but Release it first edesc->CountLocators(&numLocators); edesc->GetLocatorAt((numLocators/2), &pLocator); pLocator->Release(); edesc->GetLocatorAt((numLocators/2 +1), &pLocator); if (edesc->RemoveLocatorAt (numLocators/2) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; edesc->CountLocators(&numLocators2); if (numLocators2 != (numLocators - 1)) localhr = AAFRESULT_TEST_FAILED; edesc->GetLocatorAt(numLocators/2, &pLocator2); // Verify that the locators shifted properly if (pLocator != pLocator2) localhr = AAFRESULT_TEST_FAILED; pLocator->Release(); pLocator = 0; pLocator2->Release(); pLocator2 = 0; // Remove locator at end, but Release it first edesc->CountLocators(&numLocators); edesc->GetLocatorAt(numLocators-1, &pLocator); pLocator->Release(); edesc->GetLocatorAt(numLocators-2, &pLocator); if (edesc->RemoveLocatorAt (numLocators-1) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; edesc->CountLocators(&numLocators2); if (numLocators2 != (numLocators - 1)) localhr = AAFRESULT_TEST_FAILED; edesc->GetLocatorAt(numLocators2-1, &pLocator2); // Verify that the locators shifted properly if (pLocator != pLocator2) localhr = AAFRESULT_TEST_FAILED; pLocator->Release(); pLocator = 0; pLocator2->Release(); pLocator2 = 0; if (localhr == AAFRESULT_SUCCESS) cout<< " RemoveLocatorAt() ... Passed"<< endl; else { cout<< " RemoveLocatorAt() ... FAILED"<< endl; hr = AAFRESULT_TEST_FAILED; } /*************************************************************/ // Add the source mob into the tree checkResult(pHeader->AddMob(pMob)); } catch (HRESULT& rResult) { hr = rResult; } // Cleanup object references if (edesc) edesc->Release(); if (pMob) pMob->Release(); if (pSourceMob) pSourceMob->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pFile) { // Close file, clean-up and return if (bFileOpen) { pFile->Save(); pFile->Close(); } pFile->Release(); } return hr; }
static HRESULT ReadAAFFile(aafWChar * pFileName) { IAAFFile* pFile = NULL; IAAFHeader* pHeader = NULL; IEnumAAFMobs* pMobIter = NULL; IAAFMob* pMob = NULL; IAAFSourceMob* pSourceMob = NULL; IAAFEssenceDescriptor* pEssDesc = NULL; IAAFTIFFDescriptor* pTIFFDesc = NULL; aafNumSlots_t numMobs = 0; HRESULT hr = AAFRESULT_SUCCESS; aafBool isContiguous, isUniform; aafInt32 leadingLines, trailingLines; aafUInt32 size; aafUInt8 summary[512]; try { // Open the AAF file checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); // Get the AAF file header. checkResult(pFile->GetHeader(&pHeader)); checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED); checkResult(pHeader->GetMobs(NULL, &pMobIter)); checkResult(pMobIter->NextOne(&pMob)); checkResult(pMob->QueryInterface(IID_IAAFSourceMob, (void **)&pSourceMob)); // Back into testing mode checkResult(pSourceMob->GetEssenceDescriptor(&pEssDesc)); checkResult(pEssDesc->QueryInterface(IID_IAAFTIFFDescriptor, (void **)&pTIFFDesc)); checkResult(pTIFFDesc->GetIsContiguous(&isContiguous)); checkResult(pTIFFDesc->GetIsUniform(&isUniform)); checkResult(pTIFFDesc->GetLeadingLines(&leadingLines)); checkResult(pTIFFDesc->GetTrailingLines(&trailingLines)); checkResult(pTIFFDesc->GetSummaryBufferSize(&size)); checkExpression(size == 34, AAFRESULT_TEST_FAILED); checkResult(pTIFFDesc->GetSummary(size, summary)); checkExpression(isContiguous == kAAFTrue, AAFRESULT_TEST_FAILED); checkExpression(isUniform == kAAFFalse, AAFRESULT_TEST_FAILED); checkExpression(leadingLines == 10, AAFRESULT_TEST_FAILED); checkExpression(trailingLines == 20, AAFRESULT_TEST_FAILED); // The next statement is not true when doing cross-platform tests //#if defined( OS_WINDOWS ) // checkExpression(memcmp(summary, "II", 2) == 0, AAFRESULT_TEST_FAILED); //#else // checkExpression(memcmp(summary, "MM", 2) == 0, AAFRESULT_TEST_FAILED); //#endif // NOTE: The elements in the summary structure need to be byte swapped // on Big Endian system (i.e. the MAC). } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pEssDesc) pEssDesc->Release(); if (pTIFFDesc) pTIFFDesc->Release(); if (pMob) pMob->Release(); if (pSourceMob) pSourceMob->Release(); if (pHeader) pHeader->Release(); if (pMobIter) pMobIter->Release(); if (pFile) { pFile->Close(); pFile->Release(); } return hr; }
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; IAAFContainerDef* pContainer = NULL; IAAFSourceMob *pSourceMob = NULL; IAAFMob *pMob = NULL; IAAFEssenceDescriptor *edesc = NULL; IAAFFileDescriptor *pFileDesc = NULL; IAAFFileDescriptor2 *pFileDesc2 = NULL; HRESULT hr = S_OK; 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 long test; aafRational_t audioRate = { 44100, 1 }; // 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"FileDescriptorTest")); // Add some slots for(test = 0; test < 2; test++) { checkResult(pSourceMob->AddNilReference (test+1, 0, defs.ddkAAFSound(), audioRate)); } // Create a concrete subclass of FileDescriptor 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; checkResult(edesc->QueryInterface(IID_IAAFFileDescriptor, (void **) &pFileDesc)); checkResult(pFileDesc->SetSampleRate (checkSampleRate)); checkResult(pDictionary->LookupContainerDef(checkContainer, &pContainer)); checkResult(pFileDesc->SetContainerFormat (pContainer)); pContainer->Release(); pContainer = NULL; checkResult(pFileDesc->SetLength (checkLength)); checkResult(pFileDesc->QueryInterface(IID_IAAFFileDescriptor2, (void **)&pFileDesc2)); checkResult(pFileDesc2->SetLinkedSlotID (checkLinkedSlotID)); // checkResult(pFileDesc->SetIsInContainer (kAAFTrue)); checkResult(pSourceMob->SetEssenceDescriptor (edesc)); checkResult(pHeader->AddMob(pMob)); } catch (HRESULT& rResult) { hr = rResult; } if (pFileDesc) pFileDesc->Release(); if (pFileDesc2) pFileDesc2->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(); } return hr; }
static HRESULT ReadAAFFile(aafWChar * pFileName) { // IAAFSession * pSession = NULL; IAAFFile * pFile = NULL; bool bFileOpen = false; IAAFHeader * pHeader = NULL; IEnumAAFMobs *mobIter = NULL; IAAFContainerDef* pContainer = NULL; IAAFDefObject * pDef = NULL; IAAFEssenceDescriptor *pEdesc = NULL; IAAFSourceMob *pSourceMob = NULL; IAAFMob *aMob = NULL; IEnumAAFMobSlots *slotIter = NULL; IAAFMobSlot *slot = NULL; IAAFFileDescriptor *pFileDesc = NULL; IAAFFileDescriptor2 *pFileDesc2 = NULL; aafNumSlots_t numMobs, n, s; HRESULT hr = S_OK; aafRational_t testSampleRate; aafUID_t testContainer; aafLength_t testLength; aafUInt32 testLinkedSlotID; // aafBool testBool; try { // Open the file checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); bFileOpen = true; // We can't really do anthing in AAF without the header. checkResult(pFile->GetHeader(&pHeader)); // Get the number of mobs in the file (should be one) checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED); checkResult(pHeader->GetMobs (NULL, &mobIter)); for(n = 0; n < numMobs; n++) { aafWChar name[500]; aafNumSlots_t numSlots; aafMobID_t mobID; aafSlotID_t trackID; checkResult(mobIter->NextOne (&aMob)); checkResult(aMob->GetName (name, sizeof(name))); checkResult(aMob->GetMobID (&mobID)); checkResult(aMob->CountSlots (&numSlots)); if (2 != numSlots) return AAFRESULT_TEST_FAILED; if(numSlots != 0) { checkResult(aMob->GetSlots(&slotIter)); for(s = 0; s < numSlots; s++) { checkResult(slotIter->NextOne (&slot)); checkResult(slot->GetSlotID(&trackID)); slot->Release(); slot = NULL; } } checkResult(aMob->QueryInterface (IID_IAAFSourceMob, (void **)&pSourceMob)); checkResult(pSourceMob->GetEssenceDescriptor (&pEdesc)); checkResult(pEdesc->QueryInterface(IID_IAAFFileDescriptor, (void **) &pFileDesc)); checkResult(pFileDesc->GetSampleRate (&testSampleRate)); checkExpression(testSampleRate.numerator == checkSampleRate.numerator, AAFRESULT_TEST_FAILED); checkExpression(testSampleRate.denominator == checkSampleRate.denominator, AAFRESULT_TEST_FAILED); checkResult(pFileDesc->GetContainerFormat (&pContainer)); checkResult(pContainer->QueryInterface(IID_IAAFDefObject, (void **) &pDef)); checkResult(pDef->GetAUID(&testContainer)); pContainer->Release(); pContainer = NULL; pDef->Release(); pDef = NULL; checkExpression(memcmp(&testContainer, &checkContainer, sizeof(testContainer)) == 0, AAFRESULT_TEST_FAILED); checkResult(pFileDesc->GetLength (&testLength)); checkExpression(checkLength == testLength, AAFRESULT_TEST_FAILED); checkResult(pFileDesc->QueryInterface(IID_IAAFFileDescriptor2, (void **)&pFileDesc2)); checkResult(pFileDesc2->GetLinkedSlotID (&testLinkedSlotID)); checkExpression(checkLinkedSlotID == testLinkedSlotID, AAFRESULT_TEST_FAILED); // checkResult(pFileDesc->GetIsInContainer (&testBool)); // checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); pEdesc->Release(); pEdesc = NULL; pFileDesc->Release(); pFileDesc = NULL; pFileDesc2->Release(); pFileDesc2 = NULL; pSourceMob->Release(); pSourceMob = NULL; aMob->Release(); aMob = NULL; } } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (slot) slot->Release(); if (pFileDesc) pFileDesc->Release(); if (pFileDesc2) pFileDesc2->Release(); if (slotIter) slotIter->Release(); if (pEdesc) pEdesc->Release(); if (pSourceMob) pSourceMob->Release(); if (aMob) aMob->Release(); if(mobIter) mobIter->Release(); if (pHeader) pHeader->Release(); if (pFile) { if (bFileOpen) pFile->Close(); pFile->Release(); } return hr; }
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; IAAFMob* pMob = NULL; IAAFMasterMob* pMasterMob = NULL; IAAFSourceMob* pSrcMob = NULL; IAAFSourceMob* pTapeMob = NULL; IAAFEssenceDescriptor* pDesc = NULL; IAAFMob* pTempMob = NULL; HRESULT hr = S_OK; long test; aafSourceRef_t ref; IAAFEssenceDescriptor* pEssDesc = NULL; IAAFTapeDescriptor* pTapeDesc = NULL; 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); // Create a Master Mob checkResult(defs.cdMasterMob()-> CreateInstance(IID_IAAFMob, (IUnknown **)&pMob)); // Set the IAAFMob properties checkResult(pMob->SetMobID(TEST_Master_MobID)); checkResult(pMob->SetName(MobName)); checkResult(pMob->QueryInterface(IID_IAAFMasterMob, (void **) &pMasterMob)); // Create source mob to associate with our MasterMob. checkResult(defs.cdSourceMob()-> CreateInstance(IID_IAAFSourceMob, (IUnknown **)&pTapeMob)); hr = defs.cdTapeDescriptor()-> CreateInstance(IID_IAAFTapeDescriptor, (IUnknown **)&pTapeDesc); if (AAFRESULT_SUCCESS == hr) { hr = pTapeDesc->QueryInterface(IID_IAAFEssenceDescriptor, (void **)&pEssDesc); if (AAFRESULT_SUCCESS == hr) { hr = pTapeMob->SetEssenceDescriptor(pEssDesc); if (AAFRESULT_SUCCESS == hr) { hr = pTapeDesc->SetTapeManufacturer( Manufacturer ); if (AAFRESULT_SUCCESS == hr ) { hr = pTapeDesc->SetTapeModel( Model ); if (AAFRESULT_SUCCESS == hr ) { hr = pTapeDesc->SetTapeFormFactor( FormFactor ); if (AAFRESULT_SUCCESS == hr ) { hr = pTapeDesc->SetSignalType( VideoSignalType ); if (AAFRESULT_SUCCESS == hr ) { hr = pTapeDesc->SetTapeFormat( TapeFormat ); if (AAFRESULT_SUCCESS == hr ) hr = pTapeDesc->SetTapeLength( TapeLength ); } } } } } pEssDesc->Release(); pEssDesc = NULL; } pTapeDesc->Release(); pTapeDesc = NULL; } for (test = 0; test < NumMobSlots; test++) { IAAFDataDefSP pDataDef; checkResult (pDictionary->LookupDataDef (*slotDDefs[test], &pDataDef)); checkResult(pTapeMob->AddNilReference (test, TAPE_MOB_LENGTH_ARR[test], pDataDef, slotRates[test])); } checkResult(pTapeMob->QueryInterface(IID_IAAFMob, (void **) &pTempMob)); checkResult(pTempMob->SetName(TAPE_MOB_NAME)); checkResult(pTempMob->SetMobID(tapeMobID)); //save the id for future (test) reference // TAPE_MOB_ID = tapeMobID; checkResult(pHeader->AddMob(pTempMob)); pTempMob->Release(); pTempMob = NULL; // Add some slots for (test = 0; test < NumMobSlots; test++) { // Create source mob to associate with our MasterMob. checkResult(defs.cdSourceMob()-> CreateInstance(IID_IAAFSourceMob, (IUnknown **)&pSrcMob)); ref.sourceID = tapeMobID; ref.sourceSlotID = test; ref.startTime = TAPE_MOB_OFFSET_ARR[test]; IAAFDataDefSP pDDef; checkResult(pDictionary->LookupDataDef(*slotDDefs[test], &pDDef)); checkResult(pSrcMob->AppendPhysSourceRef (slotRates[test], test, pDDef, ref, TAPE_MOB_LENGTH_ARR[test])); // Create a concrete subclass of EssenceDescriptor checkResult(defs.cdAIFCDescriptor()-> CreateInstance(IID_IAAFEssenceDescriptor, (IUnknown **)&pDesc)); IAAFAIFCDescriptor* pAIFCDesc = NULL; checkResult(pDesc->QueryInterface (IID_IAAFAIFCDescriptor, (void **)&pAIFCDesc)); checkResult(pAIFCDesc->SetSummary (5, (unsigned char*)"TEST")); pAIFCDesc->Release(); pAIFCDesc = NULL; checkResult(pSrcMob->SetEssenceDescriptor(pDesc)); pDesc->Release(); pDesc = NULL; // Append source MOB to header checkResult(pSrcMob->QueryInterface(IID_IAAFMob, (void **) &pTempMob)); checkResult(pTempMob->SetMobID(TEST_Source_MobIDs[test])); checkResult(pTempMob->SetName(L"source mob")); checkResult(pHeader->AddMob(pTempMob)); pTempMob->Release(); pTempMob = NULL; IAAFDataDefSP pDataDef; checkResult (pDictionary->LookupDataDef (*slotDDefs[test], &pDataDef)); checkResult(pMasterMob->AddMasterSlot(pDataDef, test, pSrcMob, test+1, slotNames[test])); pSrcMob->Release(); pSrcMob = NULL; } // Add the master mob to the file and cleanup checkResult(pHeader->AddMob(pMob)); } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pTempMob) pTempMob->Release(); if (pEssDesc) pEssDesc->Release(); if (pTapeDesc) pTapeDesc->Release(); if (pDesc) pDesc->Release(); if (pSrcMob) pSrcMob->Release(); if (pTapeMob) pTapeMob->Release(); if (pMasterMob) pMasterMob->Release(); if (pMob) pMob->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 ReadAAFFile(aafWChar * pFileName) { IAAFFile * pFile = NULL; IAAFHeader * pHeader = NULL; IAAFSourceMob* pSourceMob = NULL; IAAFMob* pMob = NULL; IAAFEssenceDescriptor* pEssDesc = NULL; IAAFBWFImportDescriptor* pBWFImportDesc = NULL; IEnumAAFRIFFChunks* pEnum = NULL; IAAFRIFFChunk* pRIFFChunk = NULL; IEnumAAFMobs* pMobIter = NULL; aafUInt32 numData, bytesRead, com, testID; aafLength_t testLength, testRIFFLen; aafPosition_t dataPos; aafNumSlots_t numMobs; char Value[sizeof(RIFFChunksmiley)]; char Value2[sizeof(RIFFChunkfrowney)]; HRESULT hr = AAFRESULT_SUCCESS; checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); checkResult( pFile->GetHeader(&pHeader)); checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); if (1 == numMobs ) { checkResult(pHeader->GetMobs(NULL, &pMobIter)); checkResult(pMobIter->NextOne(&pMob)); checkResult(pMob->QueryInterface(IID_IAAFSourceMob, (void **)&pSourceMob)); // Back into testing mode checkResult(pSourceMob->GetEssenceDescriptor(&pEssDesc)); checkResult( pEssDesc->QueryInterface( IID_IAAFBWFImportDescriptor, (void**)&pBWFImportDesc )); checkResult(pBWFImportDesc->CountUnknownBWFChunks(&numData)); checkExpression(1 == numData, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetUnknownBWFChunks(&pEnum)); for(com = 0; com < numData; com++) { checkResult(pEnum->NextOne(&pRIFFChunk)); checkResult(pRIFFChunk->GetLength(&testRIFFLen)); checkExpression((sizeof(RIFFChunksmiley)+sizeof(RIFFChunkfrowney)) == testRIFFLen, AAFRESULT_TEST_FAILED); checkResult(pRIFFChunk->Read( sizeof(Value), (unsigned char *)Value, &bytesRead)); checkExpression(memcmp(Value, RIFFChunksmiley, sizeof(RIFFChunksmiley)) == 0, AAFRESULT_TEST_FAILED); checkResult(pRIFFChunk->Read( sizeof(Value2), (unsigned char *)Value2, &bytesRead)); checkExpression(memcmp(Value2, RIFFChunkfrowney, sizeof(RIFFChunkfrowney)) == 0, AAFRESULT_TEST_FAILED); checkResult(pRIFFChunk->GetPosition(&dataPos)); checkExpression(dataPos==(sizeof(RIFFChunksmiley)+sizeof(RIFFChunkfrowney)), AAFRESULT_TEST_FAILED); checkResult(pRIFFChunk->SetPosition(0)); checkResult(pRIFFChunk->Read( sizeof(Value), (unsigned char *)Value, &bytesRead)); checkExpression(memcmp(Value, RIFFChunksmiley, sizeof(RIFFChunksmiley)) == 0, AAFRESULT_TEST_FAILED); pRIFFChunk->GetChunkID(&testID); checkExpression(testID==chunkID, AAFRESULT_TEST_FAILED); pRIFFChunk->GetLength(&testLength); checkExpression(testLength == sizeof(RIFFChunksmiley) + sizeof(RIFFChunkfrowney), AAFRESULT_TEST_FAILED); pRIFFChunk->Release(); pRIFFChunk = NULL; } pEnum->Release(); pEnum = NULL; pEssDesc->Release(); pEssDesc = NULL; pBWFImportDesc->Release(); pBWFImportDesc = NULL; pSourceMob->Release(); pSourceMob = NULL; pMobIter->Release(); pMobIter = NULL; } pMob->Release(); pMob = NULL; pHeader->Release(); pHeader = NULL; pFile->Close(); pFile->Release(); pFile = NULL; return hr; }