static bool testRestore(const wchar_t* fileName) { bool passed = true; IAAFFile* pFile = 0; IAAFHeader* pHeader = 0; IAAFDictionary* pDictionary = 0; IAAFContentStorage* pStorage = 0; IEnumAAFMobs* pMobs = 0; IAAFMob* pMob = 0; try { pFile = openFileForReading(fileName); } catch (...) { return false; } try { // get the Mob containing the test data checkResult(pFile->GetHeader(&pHeader)); checkResult(pHeader->GetDictionary(&pDictionary)); checkResult(pHeader->GetContentStorage(&pStorage)); aafSearchCrit_t searchCrit; searchCrit.searchTag = kAAFByMobKind; searchCrit.tags.mobKind = kAAFAllMob; checkResult(pStorage->GetMobs(&searchCrit, &pMobs)); checkResult(pMobs->NextOne(&pMob)); IAAFObject* pObject = 0; IAAFClassDef* pClassDef = 0; IAAFPropertyDef* pPropertyDef = 0; IAAFPropertyValue* pPropertyValue = 0; IAAFTypeDef* pType = 0; IAAFTypeDefCharacter* pCharacterType = 0; // test simple try { printf(" * Simple: "); const aafUID_t propId = {0x00000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; wchar_t testCharacter = L'A'; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefCharacter, (void **)&pCharacterType)); aafCharacter value; checkResult(pCharacterType->GetCharacter(pPropertyValue, &value)); if (value == testCharacter) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pCharacterType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); // test XML escaped try { printf(" * XML escaped: "); const aafUID_t propId = {0x10000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; wchar_t testCharacter = L'\r'; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefCharacter, (void **)&pCharacterType)); aafCharacter value; checkResult(pCharacterType->GetCharacter(pPropertyValue, &value)); if (value == testCharacter) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pCharacterType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); // test AAF escaped try { printf(" * AAF escaped: "); const aafUID_t propId = {0x20000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; wchar_t testCharacter = 0x0; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefCharacter, (void **)&pCharacterType)); aafCharacter value; checkResult(pCharacterType->GetCharacter(pPropertyValue, &value)); if (value == testCharacter) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pCharacterType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); // test AAF escaped of invalid UNICODE character try { printf(" * AAF escaped invalid Unicode character: "); const aafUID_t propId = {0x30000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; wchar_t testCharacter = 0xFFFF; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefCharacter, (void **)&pCharacterType)); aafCharacter value; checkResult(pCharacterType->GetCharacter(pPropertyValue, &value)); if (value == testCharacter) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pCharacterType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); } catch (...) { passed = false; } // cleanup release(pMob); release(pMobs); release(pStorage); release(pDictionary); release(pHeader); checkResult(pFile->Close()); release(pFile); report(passed); return passed; }
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 bool testRestore(const wchar_t* fileName) { bool passed = true; IAAFFile* pFile = 0; IAAFHeader* pHeader = 0; IAAFDictionary* pDictionary = 0; IAAFContentStorage* pStorage = 0; IEnumAAFMobs* pMobs = 0; IAAFMob* pMob = 0; try { pFile = openFileForReading(fileName); } catch (...) { return false; } try { // get the Mob containing the test data checkResult(pFile->GetHeader(&pHeader)); checkResult(pHeader->GetDictionary(&pDictionary)); checkResult(pHeader->GetContentStorage(&pStorage)); aafSearchCrit_t searchCrit; searchCrit.searchTag = kAAFByMobKind; searchCrit.tags.mobKind = kAAFAllMob; checkResult(pStorage->GetMobs(&searchCrit, &pMobs)); checkResult(pMobs->NextOne(&pMob)); IAAFObject* pObject = 0; IAAFClassDef* pClassDef = 0; IAAFPropertyDef* pPropertyDef = 0; IAAFPropertyValue* pPropertyValue = 0; IAAFTypeDef* pType = 0; IAAFTypeDefEnum* pEnumType = 0; try { printf(" * Baseline: "); const aafUID_t propId = {0x00000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUInt8 testValue = 5; const wchar_t* testName = L"VersionPrivateBuild"; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefEnum, (void **)&pEnumType)); aafInt64 value; aafCharacter name[256]; checkResult(pEnumType->GetIntegerValue(pPropertyValue, &value)); checkResult(pEnumType->GetNameFromValue(pPropertyValue, name, 256)); if (value == testValue && wcscmp(name, testName) == 0) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pEnumType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); try { printf(" * Enum element size 1 : "); const aafUID_t propId = {0x10000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUInt8 testValue = 1; const wchar_t* testName = L"AAA"; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefEnum, (void **)&pEnumType)); aafInt64 value; aafCharacter name[256]; checkResult(pEnumType->GetIntegerValue(pPropertyValue, &value)); checkResult(pEnumType->GetNameFromValue(pPropertyValue, name, 256)); if (value == testValue && wcscmp(name, testName) == 0) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pEnumType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); try { printf(" * Enum element size 2 : "); const aafUID_t propId = {0x20000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUInt8 testValue = 2; const wchar_t* testName = L"BBB"; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefEnum, (void **)&pEnumType)); aafInt64 value; aafCharacter name[256]; checkResult(pEnumType->GetIntegerValue(pPropertyValue, &value)); checkResult(pEnumType->GetNameFromValue(pPropertyValue, name, 256)); if (value == testValue && wcscmp(name, testName) == 0) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pEnumType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); try { printf(" * Enum element size 4 : "); const aafUID_t propId = {0x30000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUInt8 testValue = 1; const wchar_t* testName = L"AAA"; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefEnum, (void **)&pEnumType)); aafInt64 value; aafCharacter name[256]; checkResult(pEnumType->GetIntegerValue(pPropertyValue, &value)); checkResult(pEnumType->GetNameFromValue(pPropertyValue, name, 256)); if (value == testValue && wcscmp(name, testName) == 0) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pEnumType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); try { printf(" * Enum element size 8 : "); const aafUID_t propId = {0x40000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUInt8 testValue = 2; const wchar_t* testName = L"BBB"; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefEnum, (void **)&pEnumType)); aafInt64 value; aafCharacter name[256]; checkResult(pEnumType->GetIntegerValue(pPropertyValue, &value)); checkResult(pEnumType->GetNameFromValue(pPropertyValue, name, 256)); if (value == testValue && wcscmp(name, testName) == 0) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pEnumType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); } catch (...) { passed = false; } // cleanup release(pMob); release(pMobs); release(pStorage); release(pDictionary); release(pHeader); checkResult(pFile->Close()); release(pFile); report(passed); return passed; }
static bool testRestore(const wchar_t* fileName) { bool passed = true; IAAFFile* pFile = 0; IAAFHeader* pHeader = 0; IAAFDictionary* pDictionary = 0; IAAFContentStorage* pStorage = 0; IEnumAAFMobs* pMobs = 0; IAAFMob* pMob = 0; try { pFile = openFileForReading(fileName); } catch (...) { return false; } try { // get the Mob containing the test data checkResult(pFile->GetHeader(&pHeader)); checkResult(pHeader->GetDictionary(&pDictionary)); checkResult(pHeader->GetContentStorage(&pStorage)); aafSearchCrit_t searchCrit; searchCrit.searchTag = kAAFByMobKind; searchCrit.tags.mobKind = kAAFAllMob; checkResult(pStorage->GetMobs(&searchCrit, &pMobs)); checkResult(pMobs->NextOne(&pMob)); IAAFObject* pObject = 0; IAAFClassDef* pClassDef = 0; IAAFPropertyDef* pPropertyDef = 0; IAAFPropertyValue* pPropertyValue = 0; IAAFTypeDef* pType = 0; IAAFTypeDefExtEnum* pExtEnumType = 0; // test baseline ext. enum try { printf(" * Baseline: "); const aafUID_t propId = {0x00000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUID_t testValue = {0x0D010102,0x0101,0x0500,{0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01}}; const wchar_t* testName = L"Usage_SubClip"; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefExtEnum, (void **)&pExtEnumType)); aafUID_t value; aafCharacter name[256]; checkResult(pExtEnumType->GetAUIDValue(pPropertyValue, &value)); checkResult(pExtEnumType->GetNameFromValue(pPropertyValue, name, 256)); if (memcmp(&value, &testValue, sizeof(aafUID_t)) ==0 && wcscmp(name, testName) == 0) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pExtEnumType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); // test Int8 enum try { printf(" * Non-baseline Ext Enum: "); const aafUID_t propId = {0x10000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUID_t testValue = {0x6f9685a4,0x0a0d,0x447b,{0x89,0xf3,0x1b,0x75,0x0b,0xc5,0xc7,0xde}}; const wchar_t* testName = L"AAA"; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefExtEnum, (void **)&pExtEnumType)); aafUID_t value; aafCharacter name[256]; checkResult(pExtEnumType->GetAUIDValue(pPropertyValue, &value)); checkResult(pExtEnumType->GetNameFromValue(pPropertyValue, name, 256)); if (memcmp(&value, &testValue, sizeof(aafUID_t)) ==0 && wcscmp(name, testName) == 0) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pExtEnumType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); // test baseline extension try { printf(" * Baseline extension: "); const aafUID_t propId = {0x20000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUID_t testValue = {0x197e78ac,0xb464,0x4bd1,{0x86,0x11,0xb6,0xf2,0xdf,0x0d,0x03,0xfe}}; const wchar_t* testName = L"MyUsage"; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefExtEnum, (void **)&pExtEnumType)); aafUID_t value; aafCharacter name[256]; checkResult(pExtEnumType->GetAUIDValue(pPropertyValue, &value)); checkResult(pExtEnumType->GetNameFromValue(pPropertyValue, name, 256)); if (memcmp(&value, &testValue, sizeof(aafUID_t)) ==0 && wcscmp(name, testName) == 0) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pExtEnumType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); // test non-baseline extension try { printf(" * Non-baseline extension: "); const aafUID_t propId = {0x30000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUID_t testValue = {0xe54f0efa,0x15c1,0x468f,{0xb7,0x43,0x9b,0xfd,0x12,0x94,0x04,0x49}}; const wchar_t* testName = L"CCC"; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefExtEnum, (void **)&pExtEnumType)); aafUID_t value; aafCharacter name[256]; checkResult(pExtEnumType->GetAUIDValue(pPropertyValue, &value)); checkResult(pExtEnumType->GetNameFromValue(pPropertyValue, name, 256)); if (memcmp(&value, &testValue, sizeof(aafUID_t)) ==0 && wcscmp(name, testName) == 0) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pExtEnumType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); } catch (...) { passed = false; } // cleanup release(pMob); release(pMobs); release(pStorage); release(pDictionary); release(pHeader); checkResult(pFile->Close()); release(pFile); report(passed); return passed; }
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; }
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 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; }
static bool testRestore(const wchar_t* fileName) { bool passed = true; IAAFFile* pFile = 0; IAAFHeader* pHeader = 0; IAAFDictionary* pDictionary = 0; IAAFContentStorage* pStorage = 0; IEnumAAFMobs* pMobs = 0; IAAFMob* pMob = 0; try { pFile = openFileForReading(fileName); } catch (...) { return false; } try { // get the Mob containing the test data checkResult(pFile->GetHeader(&pHeader)); checkResult(pHeader->GetDictionary(&pDictionary)); checkResult(pHeader->GetContentStorage(&pStorage)); aafSearchCrit_t searchCrit; searchCrit.searchTag = kAAFByMobKind; searchCrit.tags.mobKind = kAAFAllMob; checkResult(pStorage->GetMobs(&searchCrit, &pMobs)); checkResult(pMobs->NextOne(&pMob)); IAAFObject* pObject = 0; IAAFClassDef* pClassDef = 0; IAAFPropertyDef* pPropertyDef = 0; IAAFPropertyValue* pPropertyValue = 0; IAAFTypeDef* pType = 0; IAAFTypeDefFixedArray* pFixedArrayType = 0; IAAFTypeDefInt* pIntType = 0; IAAFPropertyValue* pIntValue = 0; try { printf(" * Baseline element type: "); const aafUID_t propId = {0x00000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUInt8 testValue[2] = {0,255}; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefFixedArray, (void **)&pFixedArrayType)); release(pType); checkResult(pFixedArrayType->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefInt, (void **)&pIntType)); aafUInt8 value[2]; checkResult(pFixedArrayType->GetElementValue(pPropertyValue, 0, &pIntValue)); checkResult(pIntType->GetInteger(pIntValue, &value[0], 1)); release(pIntValue); checkResult(pFixedArrayType->GetElementValue(pPropertyValue, 1, &pIntValue)); checkResult(pIntType->GetInteger(pIntValue, &value[1], 1)); if (value[0] == testValue[0] && value[1] == testValue[1]) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pIntValue); release(pIntType); release(pFixedArrayType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); try { printf(" * Non-Baseline element type: "); const aafUID_t propId = {0x10000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUInt8 testValue[2] = {1,2}; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefFixedArray, (void **)&pFixedArrayType)); release(pType); checkResult(pFixedArrayType->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefInt, (void **)&pIntType)); aafUInt8 value[2]; checkResult(pFixedArrayType->GetElementValue(pPropertyValue, 0, &pIntValue)); checkResult(pIntType->GetInteger(pIntValue, &value[0], 1)); release(pIntValue); checkResult(pFixedArrayType->GetElementValue(pPropertyValue, 1, &pIntValue)); checkResult(pIntType->GetInteger(pIntValue, &value[1], 1)); if (value[0] == testValue[0] && value[1] == testValue[1]) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pIntValue); release(pIntType); release(pFixedArrayType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); } catch (...) { passed = false; } // cleanup release(pMob); release(pMobs); release(pStorage); release(pDictionary); release(pHeader); checkResult(pFile->Close()); release(pFile); report(passed); return passed; }
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, 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 ReadAAFFile(aafWChar* pFileName) { IAAFFile* pFile = NULL; IAAFHeader* pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFCodecDef *pCodec = NULL; IAAFClassDef *pWaveClassDef=0,*pReturnedClassDef=0; IAAFDataDef *pDataDef = NULL; IEnumAAFCodecFlavours *pEnum = NULL; bool bFileOpen = false; aafBool testResult; aafUID_t codecID = kAAFCodecWAVE; aafUID_t readFlavour, checkFlavour = kAAFNilCodecFlavour; HRESULT hr = S_OK; try { // Open the AAF file checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); bFileOpen = true; // Get the AAF file header. checkResult(pFile->GetHeader(&pHeader)); checkResult(pHeader->GetDictionary(&pDictionary)); CAAFBuiltinDefs defs (pDictionary); checkResult(pDictionary->LookupCodecDef(codecID, &pCodec)); checkResult(pCodec->IsEssenceKindSupported (defs.ddkAAFMatte(), &testResult)); checkExpression (testResult == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pCodec->IsEssenceKindSupported (defs.ddkAAFPicture(), &testResult)); checkExpression (testResult == kAAFFalse, AAFRESULT_TEST_FAILED); checkResult(pCodec->EnumCodecFlavours (&pEnum)); checkResult(pEnum->NextOne (&readFlavour)); checkExpression (memcmp(&readFlavour, &checkFlavour, sizeof(checkFlavour)) == 0, AAFRESULT_TEST_FAILED); checkResult(pCodec->AreThereFlavours (&testResult)); checkExpression (kAAFFalse == testResult, AAFRESULT_TEST_FAILED); aafUID_t uid = kAAFClassID_WAVEDescriptor; checkResult(pDictionary->LookupClassDef(uid, &pWaveClassDef)); checkResult(pCodec->GetFileDescriptorClass(&pReturnedClassDef)); // COM interface pointers pReturnedClassDef and pWaveClassDef should be // equal checkExpression(AreUnksSame(pReturnedClassDef,pWaveClassDef)==kAAFTrue, AAFRESULT_TEST_FAILED); } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pReturnedClassDef) pReturnedClassDef->Release(); if (pWaveClassDef) pWaveClassDef->Release(); if (pEnum) pEnum->Release(); if (pDataDef) pDataDef->Release(); if (pCodec) pCodec->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pFile) { // Close file if (bFileOpen) pFile->Close(); pFile->Release(); } return hr; }
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; IAAFMob *pMob2 = NULL; IAAFMob2 *pMobInterface2 = NULL; IAAFTimelineMobSlot *newSlot = NULL; IAAFStaticMobSlot *newStaticSlot=NULL; IAAFEventMobSlot *newEventSlot=NULL; IAAFSegment *seg = NULL; IAAFSourceClip *sclp = NULL; IAAFEvent *event=NULL; IAAFComponent* pComponent = NULL; IAAFClassDef *pcdEventMeta=NULL; IAAFClassDef *pcdEvent=NULL; IAAFClassDef *pcdEventConcrete=NULL; HRESULT hr = S_OK; aafNumSlots_t numMobs; aafUInt32 bufLen = 0; aafUInt32 bytesRead = 0; aafUInt32 numComments = 0; aafUInt32 numFound = 0; aafWChar name[500]; aafWChar value[500]; IEnumAAFTaggedValues *enumTaggedVal = NULL; IAAFTaggedValue *taggedVal = NULL; IAAFMobSlot *mSlot = NULL; IAAFFiller *filler = NULL; IAAFKLVData *pKLVData = NULL; IAAFTypeDef* pBaseType = NULL; IAAFSourceReference *pSourceRef = NULL; IAAFTimecode *pTimecode = NULL; aafTimecode_t timecode; int i; 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; // Create a concrete subclass of Mob checkResult(defs.cdMasterMob()-> CreateInstance(IID_IAAFMob, (IUnknown **)&pMob)); checkResult( pMob->QueryInterface(IID_IAAFMob2,(void**)&pMobInterface2)); checkResult(pMob->SetMobID(MOBTestID)); checkExpression(pMob->GetNameBufLen(&bufLen) == AAFRESULT_PROP_NOT_PRESENT, AAFRESULT_TEST_FAILED); checkExpression(pMob->GetName(name, 0) == AAFRESULT_PROP_NOT_PRESENT, AAFRESULT_TEST_FAILED); checkExpression(pMob->SetName(NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkResult(pMob->SetName(mobName)); checkResult(pMob->SetCreateTime(creationTimeStamp)); checkResult(pMob->SetModTime(modificationTimeStamp)); // Add some slots for(test = 1; test < 6; test++) { checkResult(defs.cdSourceClip()-> CreateInstance(IID_IAAFSourceClip, (IUnknown **)&sclp)); checkResult(sclp->QueryInterface(IID_IAAFSourceReference, (void **)&pSourceRef)); checkResult(pSourceRef->SetSourceID(MOBTestID3)); checkResult(sclp->QueryInterface(IID_IAAFComponent, (void **)&pComponent)); checkResult(pComponent->SetDataDef(defs.ddkAAFPicture())); checkResult(sclp->QueryInterface (IID_IAAFSegment, (void **)&seg)); aafRational_t editRate = { 0, 1}; checkResult(pMob->AppendNewTimelineSlot (editRate, seg, test+1, slotNames[test], 0, &newSlot)); if(test == 5) { checkExpression(pMob->AppendNewTimelineSlot (editRate, NULL, test+1, slotNames[test], 0, &newSlot) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkExpression(pMob->AppendNewTimelineSlot (editRate, seg, test+1, NULL, 0, &newSlot) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkExpression(pMob->AppendNewTimelineSlot (editRate, seg, test+1, slotNames[test], 0, NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); pMob->RemoveSlotAt(4); checkExpression(pMob->RemoveSlotAt(test+1) == AAFRESULT_BADINDEX, AAFRESULT_TEST_FAILED); } newSlot->Release(); newSlot = NULL; if(newStaticSlot) newStaticSlot->Release(); newStaticSlot = NULL; seg->Release(); seg = NULL; sclp->Release(); sclp = NULL; pComponent->Release(); pComponent = NULL; pSourceRef->Release(); pSourceRef = NULL; } // PrependSlot checkResult(defs.cdStaticMobSlot()-> CreateInstance(IID_IAAFMobSlot, (IUnknown **)&mSlot)); checkResult(defs.cdFiller()-> CreateInstance(IID_IAAFFiller, (IUnknown **)&filler)); checkResult(filler->Initialize(defs.ddkAAFSound(), 10)); checkResult(filler->QueryInterface (IID_IAAFSegment, (void **)&seg)); checkResult(mSlot->SetName(slotNames[0])); checkResult(mSlot->SetPhysicalNum(1)); checkResult(mSlot->SetSlotID(1)); checkResult(mSlot->SetSegment(seg)); checkResult(pMob->PrependSlot(mSlot)); checkExpression(pMob->PrependSlot(mSlot) == AAFRESULT_OBJECT_ALREADY_ATTACHED, AAFRESULT_TEST_FAILED); checkExpression(pMob->PrependSlot(NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); mSlot->Release(); mSlot = NULL; seg->Release(); seg = NULL; filler->Release(); filler = NULL; // AppendSlot checkResult(defs.cdStaticMobSlot()-> CreateInstance(IID_IAAFMobSlot, (IUnknown **)&mSlot)); checkResult(defs.cdFiller()-> CreateInstance(IID_IAAFFiller, (IUnknown **)&filler)); checkResult(filler->Initialize(defs.ddkAAFSound(), 10)); checkResult(filler->QueryInterface (IID_IAAFSegment, (void **)&seg)); checkResult(mSlot->SetName(slotNames[6])); checkResult(mSlot->SetPhysicalNum(1)); checkResult(mSlot->SetSlotID(7)); checkResult(mSlot->SetSegment(seg)); checkResult(pMob->AppendSlot(mSlot)); checkExpression(pMob->AppendSlot(mSlot) == AAFRESULT_OBJECT_ALREADY_ATTACHED, AAFRESULT_TEST_FAILED); checkExpression(pMob->AppendSlot(NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); mSlot->Release(); mSlot = NULL; seg->Release(); seg = NULL; filler->Release(); filler = NULL; // InsertSlotAt -- insert a timecode object for OffsetToMobTimecode() testing timecode.startFrame = TCstartFrame; // One hour timecode.drop = TCdrop; timecode.fps = TCfps; checkResult(defs.cdTimecode()-> CreateInstance(IID_IAAFTimecode, (IUnknown **)&pTimecode)); checkResult(pTimecode->Initialize(100, &timecode)); checkResult(pTimecode->QueryInterface (IID_IAAFSegment, (void **)&seg)); assert(pComponent == NULL); checkResult(pTimecode->QueryInterface(IID_IAAFComponent,(void **)&pComponent)); checkResult(pComponent->SetDataDef(defs.ddkAAFTimecode())); pComponent->Release(); pComponent = NULL; checkResult(defs.cdStaticMobSlot()-> CreateInstance(IID_IAAFMobSlot, (IUnknown **)&mSlot)); checkResult(mSlot->SetName(slotNames[5])); checkResult(mSlot->SetPhysicalNum(1)); checkResult(mSlot->SetSlotID(6)); checkResult(mSlot->SetSegment(seg)); checkExpression(pMob->InsertSlotAt(8, mSlot) == AAFRESULT_BADINDEX, AAFRESULT_TEST_FAILED); checkResult(pMob->InsertSlotAt(5, mSlot)); checkExpression(pMob->InsertSlotAt(4, mSlot) == AAFRESULT_OBJECT_ALREADY_ATTACHED, AAFRESULT_TEST_FAILED); checkExpression(pMob->InsertSlotAt(1, NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); mSlot->Release(); mSlot = NULL; seg->Release(); seg = NULL; pTimecode->Release(); pTimecode = NULL; //now test AppendNewStaticSlot checkResult(defs.cdSourceClip()-> CreateInstance(IID_IAAFSourceClip, (IUnknown **)&sclp)); checkResult(sclp->QueryInterface(IID_IAAFSourceReference, (void **)&pSourceRef)); checkResult(pSourceRef->SetSourceID(MOBTestID_Static)); checkResult(sclp->QueryInterface(IID_IAAFComponent, (void **)&pComponent)); checkResult(pComponent->SetDataDef(defs.ddkAAFPicture())); checkResult(sclp->QueryInterface (IID_IAAFSegment, (void **)&seg)); checkResult(pMobInterface2->AppendNewStaticSlot ( seg, 8, slotNames[7], &newStaticSlot)); if(newStaticSlot) newStaticSlot->Release(); newStaticSlot = NULL; seg->Release(); seg = NULL; pSourceRef->Release(); pSourceRef = NULL; sclp->Release(); sclp = NULL; pComponent->Release(); pComponent = NULL; //now test AppendNewEventSlot //Create a concrete version of IAAFEvent checkResult (pDictionary->CreateMetaInstance (AUID_AAFClassDef, IID_IAAFClassDef, (IUnknown**) &pcdEventMeta)); checkResult (pDictionary->LookupClassDef (AUID_AAFEvent, &pcdEvent)); checkResult (pcdEventMeta->Initialize (kClassID_ConcreteEvent, pcdEvent, L"COncreteEvent", kAAFTrue)); checkResult (pDictionary->RegisterClassDef (pcdEventMeta)); //Now instantiate it checkResult(pDictionary->LookupClassDef(kClassID_ConcreteEvent, &pcdEventConcrete)); checkResult(pcdEventConcrete->CreateInstance(IID_IAAFEvent, (IUnknown **)&event)); //and initialize reqruied properties checkResult(event->QueryInterface(IID_IAAFComponent, (void **)&pComponent)); checkResult(pComponent->SetDataDef(defs.ddkAAFPicture())); event->SetPosition(1); aafRational_t EventeditRate = { 0, 1}; //get the segment checkResult(event->QueryInterface (IID_IAAFSegment, (void **)&seg)); checkResult(pMobInterface2->AppendNewEventSlot ( EventeditRate, seg, 9, slotNames[8], 0, &newEventSlot)); if(newEventSlot) newEventSlot->Release(); newEventSlot = NULL; seg->Release(); seg = NULL; pComponent->Release(); pComponent = NULL; event->Release(); event = NULL; pcdEventConcrete->Release(); pcdEventConcrete = NULL; pcdEvent->Release(); pcdEvent = NULL; pcdEventMeta->Release(); pcdEventMeta = NULL; // Try CountKLVData before any have been attached numFound = 1; checkResult(pMob->CountKLVData(&numFound)); checkExpression(numFound == 0, AAFRESULT_TEST_FAILED); checkExpression(pMob->CountKLVData(NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); // AppendKLVData - attach some objects checkResult(pDictionary->LookupTypeDef (kAAFTypeID_UInt8Array, &pBaseType)); checkResult(pDictionary->RegisterKLVDataKey(TEST_KLV, pBaseType)); pBaseType->Release(); pBaseType = NULL; checkExpression(pMob->AppendKLVData(NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkResult(defs.cdKLVData()-> CreateInstance(IID_IAAFKLVData, (IUnknown **)&pKLVData)); checkResult(pKLVData->Initialize(TEST_KLV, sizeof(KLVfrowney), (unsigned char *)KLVfrowney)); checkResult(pMob->AppendKLVData(pKLVData)); pKLVData->Release(); pKLVData = NULL; checkResult(defs.cdKLVData()-> CreateInstance(IID_IAAFKLVData, (IUnknown **)&pKLVData)); checkResult(pKLVData->Initialize(TEST_KLV, sizeof(KLVfrowney), (unsigned char *)KLVfrowney)); checkResult(pMob->AppendKLVData(pKLVData)); checkExpression(pMob->AppendKLVData(pKLVData) == AAFRESULT_OBJECT_ALREADY_ATTACHED, AAFRESULT_TEST_FAILED); // RemoveKLVData - remove object #2 checkExpression(pMob->RemoveKLVData(NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkResult(pMob->CountKLVData(&numFound)); checkExpression(numFound == 2, AAFRESULT_TEST_FAILED); checkResult(pMob->RemoveKLVData(pKLVData)); checkResult(pMob->CountKLVData(&numFound)); checkExpression(numFound == 1, AAFRESULT_TEST_FAILED); pKLVData->Release(); pKLVData = NULL; // Try removing an object that is not attached checkResult(defs.cdKLVData()-> CreateInstance(IID_IAAFKLVData, (IUnknown **)&pKLVData)); checkResult(pKLVData->Initialize(TEST_KLV, sizeof(KLVsmiley), (unsigned char *)KLVsmiley)); checkExpression(pMob->RemoveKLVData(pKLVData) == AAFRESULT_OBJECT_NOT_ATTACHED, AAFRESULT_TEST_FAILED); // Attach it to replace the one removed checkResult(pMob->AppendKLVData(pKLVData)); pKLVData->Release(); pKLVData = NULL; // Comments checkExpression(pMob->GetComments(&enumTaggedVal) == AAFRESULT_PROP_NOT_PRESENT, AAFRESULT_TEST_FAILED); // Check CountComments() checkExpression(pMob->CountComments(NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); numComments = 1; checkResult(pMob->CountComments(&numComments)); checkExpression(numComments == 0, AAFRESULT_TEST_FAILED); // Check AppendComments() checkExpression(pMob->AppendComment(NULL, pComment[0]) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkExpression(pMob->AppendComment(const_cast<aafWChar*>(pCategory[0]), NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); for (i = 0; i < 5; ++i) { checkResult(pMob->AppendComment(const_cast<aafWChar*>(pCategory[i]), pComment[i])); } checkResult(pMob->CountComments(&numComments)); checkExpression(numComments == 5, AAFRESULT_TEST_FAILED); // Check GetComments() checkExpression(pMob->GetComments(NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkResult(pMob->GetComments(&enumTaggedVal)); for (i = 0; i < 5; ++i) { checkResult(enumTaggedVal->NextOne(&taggedVal)); checkResult(taggedVal->GetNameBufLen(&bufLen)); checkResult(taggedVal->GetName(name, bufLen)); checkExpression(wcscmp(name, pCategory[i]) == 0, AAFRESULT_TEST_FAILED); checkResult(taggedVal->GetValueBufLen(&bufLen)); checkResult(taggedVal->GetValue(bufLen, (aafDataBuffer_t)value, &bytesRead)); checkExpression(wcscmp(value, pComment[i]) == 0, AAFRESULT_TEST_FAILED); taggedVal->Release(); taggedVal = NULL; } checkResult(defs.cdTaggedValue()-> CreateInstance(IID_IAAFTaggedValue, (IUnknown **)&taggedVal)); checkExpression(pMob->RemoveComment(taggedVal) == AAFRESULT_OBJECT_NOT_ATTACHED, AAFRESULT_TEST_FAILED); taggedVal->Release(); taggedVal = NULL; enumTaggedVal->Reset(); enumTaggedVal->Skip(2); checkResult(enumTaggedVal->NextOne(&taggedVal)); checkExpression(pMob->RemoveComment(NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkResult(pMob->RemoveComment(taggedVal)); taggedVal->Release(); taggedVal = NULL; enumTaggedVal->Reset(); for (i = 0; i < 5; ++i) { if (i==2) continue; checkResult(enumTaggedVal->NextOne(&taggedVal)); checkResult(taggedVal->GetNameBufLen(&bufLen)); checkResult(taggedVal->GetName(name, bufLen)); checkExpression(wcscmp(name, pCategory[i]) == 0, AAFRESULT_TEST_FAILED); checkResult(taggedVal->GetValueBufLen(&bufLen)); checkResult(taggedVal->GetValue(bufLen, (aafDataBuffer_t)value, &bytesRead)); checkExpression(wcscmp(value, pComment[i]) == 0, AAFRESULT_TEST_FAILED); taggedVal->Release(); taggedVal = NULL; } enumTaggedVal->Release(); enumTaggedVal = NULL; // Check the Mob2 attribute and usage code implementations. // Need IAAFMob2 for that; checkResult( pMobInterface2->AppendAttribute( AttributeNames[0], AttributeValues[0] ) ); checkResult( pMobInterface2->AppendAttribute( AttributeNames[1], AttributeValues[1] ) ); checkResult( pMobInterface2->SetUsageCode( kAAFUsage_SubClip ) ); // Add the mob to the file. checkResult(pHeader->AddMob(pMob)); // Test changing the mob id after the mob is attached to the // content store. Change it, then reset to the original id. checkResult(pMob->SetMobID(MOBTestID2)); checkResult(pMob->SetMobID(MOBTestID)); // Create another Mob, check mob count, then delete and recheck count checkResult(defs.cdMasterMob()-> CreateInstance(IID_IAAFMob, (IUnknown **)&pMob2)); checkResult(pMob2->SetMobID(MOBTestID2)); checkResult(pMob2->SetName(mobName)); checkResult(pMob2->SetCreateTime(creationTimeStamp)); checkResult(pMob2->SetModTime(modificationTimeStamp)); // Add the mob to the file. checkResult(pHeader->AddMob(pMob2)); checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); checkExpression(numMobs == 2, AAFRESULT_TEST_FAILED); checkResult(pHeader->RemoveMob(pMob2)); checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); checkExpression(numMobs == 1, AAFRESULT_TEST_FAILED); //try Copy() const aafCharacter *copy_name = L"Name of Copied Mob"; IAAFMobSP spCopiedMob; checkResult(pMob->Copy(copy_name, &spCopiedMob)); checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); checkExpression(numMobs == 2, AAFRESULT_TEST_FAILED); checkResult(pHeader->RemoveMob(spCopiedMob)); checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); checkExpression(numMobs == 1, AAFRESULT_TEST_FAILED); //try CloneExternal IAAFMobSP spClonedMob; IAAFFileSP spDestFile; aafCharacter dest_filename[128]; wcscpy(dest_filename, pFileName); wcscat(dest_filename, L"_clone"); // Remove the previous test file if any. RemoveTestFile(dest_filename); checkResult(CreateTestFile( dest_filename, fileKind, rawStorageType, productID, &spDestFile )); checkResult(pMob->CloneExternal(kAAFNoFollowDepend, kAAFNoIncludeMedia, spDestFile, &spClonedMob)); checkResult(spDestFile->Save()); checkResult(spDestFile->Close()); } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (enumTaggedVal) enumTaggedVal->Release(); if (newSlot) newSlot->Release(); if (newStaticSlot) newStaticSlot->Release(); if (seg) seg->Release(); if (pComponent) pComponent->Release(); if (sclp) sclp->Release(); if (pMob) pMob->Release(); if (pMob2) pMob2->Release(); if (pMobInterface2) pMobInterface2->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if(pcdEventMeta) pcdEventMeta->Release(); if(pcdEvent) pcdEvent->Release(); if(pcdEventConcrete) pcdEventConcrete->Release(); if (pFile) { // Close file if (bFileOpen) { pFile->Save(); pFile->Close(); } pFile->Release(); } return hr; }
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(const aafWChar * pFileName, testDataFile_t *dataFile, testType_t /* testType */) { IAAFFile* pFile = NULL; IAAFHeader* pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFMob* pMob = NULL; IAAFMasterMob* pMasterMob = NULL; IAAFClassDef* pKLVDataCD=NULL; IAAFClassDef* pCommentMarkerCD=NULL; IAAFTypeDef* pUnknownBaseType=NULL; IAAFTypeDef* pInt32BaseType=NULL; // IAAFTypeDef* pASCIIStringBaseType=NULL; IAAFKLVData* pKLVData=NULL; IAAFEssenceAccess* pEssenceAccess = NULL; IAAFEssenceMultiAccess* pMultiEssence = NULL; IAAFEssenceFormat* pFormat = NULL; IAAFEssenceFormat* format = NULL; IAAFLocator* pLocator = NULL; IAAFClassDef* pCDMasterMob = 0; IAAFClassDef *pCDNetworkLocator = 0; IAAFDataDef *pDdefSound = 0; IAAFDataDef* pDDefSceneDesc=0; IAAFEventMobSlot *pEventSlot=0; IAAFMobSlot *pSlot=0; IAAFSequence *pSeqSceneDesc=0; IAAFSegment *pSegment=0; IAAFEvent *pEventSceneDesc=0; IAAFComponent *pComp=0; HRESULT hr = AAFRESULT_SUCCESS; // !!!Previous revisions of this file contained variables here required to handle external essence aafMobID_t masterMobID; aafProductIdentification_t ProductInfo; aafRational_t editRate = {30000, 1001}; aafRational_t sampleRate = {44100, 1}; aafRational_t eventTimebase = {30000, 1001}; aafPosition_t position=0; FILE* pWavFile = NULL; unsigned char dataBuff[4096], *dataPtr; // aafUInt32 bytesWritten; aafUInt32 dataOffset, dataLen; aafUInt16 bitsPerSample, numCh; aafInt32 n, numSpecifiers; aafUID_t essenceFormatCode, testContainer; aafUInt32 samplesWritten, bytesWritten; // delete any previous test file before continuing... char chFileName[1000]; convert(chFileName, sizeof(chFileName), pFileName); remove(chFileName); if(dataFile != NULL) { // delete any previous test file before continuing... char chFileName[1000]; convert(chFileName, sizeof(chFileName), dataFile->dataFilename); remove(chFileName); } aafProductVersion_t v; v.major = 1; v.minor = 0; v.tertiary = 0; v.patchLevel = 0; v.type = kAAFVersionUnknown; ProductInfo.companyName = companyName; ProductInfo.productName = productName; ProductInfo.productVersion = &v; ProductInfo.productVersionString = NULL; ProductInfo.productID = NIL_UID; ProductInfo.platform = NULL; check(AAFFileOpenNewModifyEx (pFileName, &kAAFFileKind_Aaf4KBinary, 0, &ProductInfo, &pFile)); check(pFile->GetHeader(&pHeader)); // test // Get the AAF Dictionary so that we can create valid AAF objects. check(pHeader->GetDictionary(&pDictionary)); check(pDictionary->LookupClassDef(AUID_AAFMasterMob, &pCDMasterMob)); check(pDictionary->LookupClassDef(AUID_AAFNetworkLocator, &pCDNetworkLocator)); check(pDictionary->LookupDataDef(kAAFDataDef_Sound, &pDdefSound)); // !!!Previous revisions of this file contained code here required to handle external essence // Get a Master MOB Interface check(pCDMasterMob-> CreateInstance(IID_IAAFMasterMob, (IUnknown **)&pMasterMob)); // Get a Mob interface and set its variables. check(pMasterMob->QueryInterface(IID_IAAFMob, (void **)&pMob)); check(pMob->GetMobID(&masterMobID)); check(pMob->SetName(L"A Master Mob")); // Add it to the file check(pHeader->AddMob(pMob)); // !!!Previous revisions of this file contained code here required to handle external essence if(dataFile != NULL) { // Make a locator, and attach it to the EssenceDescriptor check(pCDNetworkLocator-> CreateInstance(IID_IAAFLocator, (IUnknown **)&pLocator)); check(pLocator->SetPath (dataFile->dataFilename)); testContainer = dataFile->dataFormat; } else { pLocator = NULL; testContainer = ContainerAAF; } // open the Essence file to be included in this AAF file("Laser.wav") pWavFile = fopen("Laser.wav", "r"); if (pWavFile) { // read in the essence data fread(dataBuff, sizeof(unsigned char), sizeof(dataBuff), pWavFile); check(loadWAVEHeader(dataBuff, &bitsPerSample, &numCh, &sampleRate, &dataOffset, &dataLen)); dataPtr = dataBuff + dataOffset; // now create the Essence data file check(pMasterMob->CreateEssence(1, // Slot ID pDdefSound, // MediaKind kAAFCodecWAVE, // codecID editRate, // edit rate sampleRate, // sample rate kAAFCompressionDisable, pLocator, // In current file testContainer, // In AAF Format &pEssenceAccess));// Compress disabled check(pEssenceAccess->GetFileFormatParameterList (&format)); check(format->NumFormatSpecifiers (&numSpecifiers)); for(n = 0; n < numSpecifiers; n++) { check(format->GetIndexedFormatSpecifier (n, &essenceFormatCode, 0, NULL, NULL)); } format->Release(); format = NULL; // Tell the AAFEssenceAccess what the format is. check(pEssenceAccess->GetEmptyFileFormat (&pFormat)); check(pFormat->NumFormatSpecifiers (&numSpecifiers)); aafInt32 sampleSize = bitsPerSample; check(pFormat->AddFormatSpecifier (kAAFAudioSampleBits, sizeof(sampleSize), (aafUInt8 *)&sampleSize)); check(pEssenceAccess->PutFileFormat (pFormat)); pFormat->Release(); pFormat = NULL; // write out the data check(pEssenceAccess->WriteSamples( dataLen,//!!! hardcoded bytes/sample ==1// Number of Samples sizeof(dataBuff), // buffer size dataPtr, // THE data &samplesWritten, &bytesWritten)); // close essence data file fclose(pWavFile); pWavFile = NULL; // Finish writing the destination check(pEssenceAccess->CompleteWrite()); pEssenceAccess->Release(); pEssenceAccess=NULL; // First register DataDef for SceneDescription // Is SceneDescription in dictionary already // Try using Timecode for MC compat hr = pDictionary->LookupDataDef(kAAFDataDef_Timecode, &pDDefSceneDesc); // hr = pDictionary->LookupDataDef(kAAFDataDef_SceneDescription, // &pDDefSceneDesc); if (hr != AAFRESULT_SUCCESS) { check(pDictionary->CreateInstance(AUID_AAFDataDef,IID_IAAFDataDef, (IUnknown **)&pDDefSceneDesc)); check(pDDefSceneDesc->Initialize(kAAFDataDef_SceneDescription, L"SceneDescEvent",L"DataDefinition for Scene Description Events")); check(pDictionary->RegisterDataDef(pDDefSceneDesc)); } // Add EventSlot to MasterMob // Create Slot check(pDictionary->CreateInstance(AUID_AAFEventMobSlot, IID_IAAFEventMobSlot, (IUnknown **)&pEventSlot)); check(pEventSlot->SetEditRate(&eventTimebase)); // Get the mob slot interface so that we can add the event segment. check(pEventSlot->QueryInterface(IID_IAAFMobSlot, (void **)&pSlot)); pEventSlot->Release(); pEventSlot = NULL; aafSlotID_t eventSlotID=5; check(pSlot->SetSlotID(eventSlotID)); check(pSlot->SetName(L"SceneDescriptions")); // Set up Sequence for Scene Descriptors check(pDictionary->CreateInstance(AUID_AAFSequence,IID_IAAFSequence, (IUnknown **)&pSeqSceneDesc)); check(pSeqSceneDesc->Initialize(pDDefSceneDesc)); // Create first Comment Marker check(pDictionary->LookupClassDef(AUID_AAFCommentMarker, &pCommentMarkerCD)); check(pCommentMarkerCD->CreateInstance(IID_IAAFEvent, (IUnknown **)&pEventSceneDesc)); position=0; check(pEventSceneDesc->SetPosition(position)); check(pEventSceneDesc->SetComment(L"Racers heading up the hill")); check(pEventSceneDesc->QueryInterface(IID_IAAFComponent, (void **)&pComp)); check(pComp->SetDataDef(pDDefSceneDesc)); // Add it to the sequence check(pSeqSceneDesc->AppendComponent(pComp)); pComp->Release(); pComp = NULL; pEventSceneDesc->Release(); pEventSceneDesc=NULL; // Create second Comment Marker check(pCommentMarkerCD->CreateInstance(IID_IAAFEvent, (IUnknown **)&pEventSceneDesc)); position=100; check(pEventSceneDesc->SetPosition(position)); check(pEventSceneDesc->SetComment(L"Racer pulls away from crowd")); check(pEventSceneDesc->QueryInterface(IID_IAAFComponent, (void **)&pComp)); check(pComp->SetDataDef(pDDefSceneDesc)); // Add it to the sequence check(pSeqSceneDesc->AppendComponent(pComp)); pComp->Release(); pComp = NULL; pEventSceneDesc->Release(); pEventSceneDesc=NULL; check(pSeqSceneDesc->QueryInterface(IID_IAAFSegment, (void **)&pSegment)); // Create third Comment Marker check(pCommentMarkerCD->CreateInstance(IID_IAAFEvent, (IUnknown **)&pEventSceneDesc)); position=250; check(pEventSceneDesc->SetPosition(position)); check(pEventSceneDesc->SetComment(L"Racer passes finish line")); check(pEventSceneDesc->QueryInterface(IID_IAAFComponent, (void **)&pComp)); check(pComp->SetDataDef(pDDefSceneDesc)); // Add it to the sequence check(pSeqSceneDesc->AppendComponent(pComp)); pComp->Release(); pComp = NULL; pEventSceneDesc->Release(); pEventSceneDesc=NULL; // Add the event sequence to the event mob slot // Sequence must have at least one component to ensure event mob slot is valid check(pSlot->SetSegment(pSegment)); pSegment->Release(); pSegment = NULL; // Append the event slot to the Master Mob check(pMob->AppendSlot(pSlot)); // Add the KLV data to the Master Mob // Register the two KLVKeys check(pDictionary->LookupTypeDef(kAAFTypeID_UInt8Array, &pUnknownBaseType)); check(pDictionary->RegisterKLVDataKey(KLVKey_BinaryBlob1, pUnknownBaseType)); check(pDictionary->LookupTypeDef(kAAFTypeID_Int32, &pInt32BaseType)); check(pDictionary->RegisterKLVDataKey(KLVKey_Int32_1, pInt32BaseType)); // Next define new ASCII string data def // check(pDictionary->RegisterKLVDataKey(KLVKey_ASCIIString1, // pASCIIStringBaseType)); // Get the KLVData ClassDefinition check(pDictionary->LookupClassDef(AUID_AAFKLVData, &pKLVDataCD)); // Create KLVData and append it to Mob check(pKLVDataCD->CreateInstance(IID_IAAFKLVData, (IUnknown **)&pKLVData)); check(pKLVData->Initialize(KLVKey_BinaryBlob1, sizeof(blobData), (aafUInt8 *)blobData)); check(pMob->AppendKLVData(pKLVData)); pKLVData->Release(); pKLVData=NULL; // Create KLVData and append it to Mob check(pKLVDataCD->CreateInstance(IID_IAAFKLVData, (IUnknown **)&pKLVData)); check(pKLVData->Initialize(KLVKey_Int32_1, sizeof(int32Data), (aafUInt8 *)&int32Data)); check(pMob->AppendKLVData(pKLVData)); pKLVData->Release(); pKLVData=NULL; } else { printf("***Failed to open Wave file Laser.wav\n"); } // Release all unnecesary interfaces if (pInt32BaseType) pInt32BaseType->Release(); pInt32BaseType=NULL; if (pUnknownBaseType) pUnknownBaseType->Release(); pUnknownBaseType=NULL; if (pKLVDataCD) pKLVDataCD->Release(); pKLVDataCD=NULL; if (pCommentMarkerCD) pCommentMarkerCD->Release(); pCommentMarkerCD=NULL; if(pComp) pComp->Release(); pComp=NULL; if(pEventSceneDesc) pEventSceneDesc->Release(); pEventSceneDesc=0; if(pSegment) pSegment->Release(); pSegment=NULL; if(pSeqSceneDesc) pSeqSceneDesc->Release(); pSeqSceneDesc=NULL; if(pSlot) pSlot->Release(); pSlot=NULL; if(pEventSlot) pEventSlot->Release(); pEventSlot=NULL; if(pDDefSceneDesc) pDDefSceneDesc->Release(); pDDefSceneDesc=NULL; if(pMasterMob) pMasterMob->Release(); pMasterMob = NULL; if(pMob) pMob->Release(); pMob = NULL; if(pDictionary) pDictionary->Release(); pDictionary = NULL; if(pHeader) pHeader->Release(); pHeader = NULL; //!!!DebugOnly pFile->Save(); pFile->Close(); pFile->Release(); pFile = NULL; if (pEssenceAccess) { pEssenceAccess->Release(); pEssenceAccess= NULL; } cleanup: // Cleanup and return if(pFormat) pFormat->Release(); if(format) format->Release(); if(pLocator) pLocator->Release(); if (pWavFile) fclose(pWavFile); if (pEssenceAccess) pEssenceAccess->Release(); if (pMultiEssence) pMultiEssence->Release(); if (pMasterMob) pMasterMob->Release(); if (pMob) pMob->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pCDMasterMob) { pCDMasterMob->Release(); pCDMasterMob = 0; } if (pCDNetworkLocator) { pCDNetworkLocator->Release(); pCDNetworkLocator = 0; } if (pDdefSound) { pDdefSound->Release (); pDdefSound = 0; } if (pFile) { pFile->Close(); pFile->Release(); } return moduleErrorTmp; }
static HRESULT CreateAAFFile(aafWChar * pFileName, long int N) { IAAFFile* pFile = NULL; IAAFHeader* pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFMob* pMob = NULL; IAAFMob* pCompMob = NULL; IAAFEssenceDescriptor* aDesc = NULL; IAAFMasterMob* pMasterMob = NULL; IAAFSourceMob* pFileMob = NULL; IAAFSourceMob* pTapeMob = NULL; IAAFSequence* pSequence = NULL; IAAFComponent* aComponent = NULL; IAAFFileDescriptor* pFileDesc = NULL; IAAFAIFCDescriptor* pAIFCDesc = NULL; IAAFTapeDescriptor* pTapeDesc = NULL; IAAFTimelineMobSlot* newSlot = NULL; IAAFSegment* seg = NULL; IAAFSourceClip* fileSclp = NULL; IAAFSourceClip* masterSclp = NULL; IAAFSourceClip* compSclp = NULL; IAAFComponent* compFill = NULL; IAAFLocator* pLocator = NULL; IAAFNetworkLocator* pNetLocator = NULL; IAAFClassDef * pCDCompositionMob = 0; IAAFClassDef * pCDSequence = 0; IAAFClassDef * pCDSourceMob = 0; IAAFClassDef * pCDTapeDescriptor = 0; IAAFClassDef * pCDAIFCDescriptor = 0; IAAFClassDef * pCDNetworkLocator = 0; IAAFClassDef * pCDMasterMob = 0; IAAFClassDef * pCDSourceClip = 0; IAAFClassDef * pCDFiller = 0; IAAFDataDef * pDdefPicture = 0; aafRational_t videoRate = { 30000, 1001 }; aafMobID_t tapeMobID, fileMobID, masterMobID; aafTimecode_t tapeTC = { 108000, kAAFTcNonDrop, 30}; aafLength_t fileLen = FILE1_LENGTH; aafLength_t fillLen = FILL_LENGTH; aafLength_t segLen = SEG_LENGTH; aafProductIdentification_t ProductInfo; long int i = 0; moduleErrorTmp = S_OK; // delete any previous test file before continuing... char chFileName[1000]; convert(chFileName, sizeof(chFileName), pFileName); remove(chFileName); aafProductVersion_t v; v.major = 1; v.minor = 0; v.tertiary = 0; v.patchLevel = 0; v.type = kAAFVersionUnknown; ProductInfo.companyName = companyName; ProductInfo.productName = productName; ProductInfo.productVersion = &v; ProductInfo.productVersionString = NULL; ProductInfo.productID = NIL_UID; ProductInfo.platform = NULL; #if defined(USE_MEMORY_FILE) check(MemoryFileOpenNewModify (0, &ProductInfo, &pFile)); #else check(AAFFileOpenNewModifyEx (pFileName, &kAAFFileKind_Aaf4KBinary, 0, &ProductInfo, &pFile)); #endif check(pFile->GetHeader(&pHeader)); // Get the AAF Dictionary so that we can create valid AAF objects. check(pHeader->GetDictionary(&pDictionary)); check(pDictionary->LookupClassDef(AUID_AAFCompositionMob, &pCDCompositionMob)); check(pDictionary->LookupClassDef(AUID_AAFSequence, &pCDSequence)); check(pDictionary->LookupClassDef(AUID_AAFSourceMob, &pCDSourceMob)); check(pDictionary->LookupClassDef(AUID_AAFTapeDescriptor, &pCDTapeDescriptor)); check(pDictionary->LookupClassDef(AUID_AAFAIFCDescriptor, &pCDAIFCDescriptor)); check(pDictionary->LookupClassDef(AUID_AAFNetworkLocator, &pCDNetworkLocator)); check(pDictionary->LookupClassDef(AUID_AAFMasterMob, &pCDMasterMob)); check(pDictionary->LookupClassDef(AUID_AAFSourceClip, &pCDSourceClip)); check(pDictionary->LookupClassDef(AUID_AAFFiller, &pCDFiller)); check(pDictionary->LookupDataDef(kAAFDataDef_Picture, &pDdefPicture)); // IMPORTANT: major remodification is from this point onwards... // sequence creation code pulled out of the subsequent loop. // Create a Composition Mob check(pCDCompositionMob->CreateInstance(IID_IAAFMob, (IUnknown **)&pCompMob)); check(pCDSequence->CreateInstance(IID_IAAFSequence, (IUnknown **)&pSequence)); check(pSequence->QueryInterface (IID_IAAFSegment, (void **)&seg)); check(pSequence->QueryInterface(IID_IAAFComponent, (void **)&aComponent)); check(aComponent->SetDataDef(pDdefPicture)); aComponent->Release(); aComponent = NULL; check(pCompMob->QueryInterface (IID_IAAFMob, (void **)&pMob)); check(pMob->AppendNewTimelineSlot(videoRate, seg, i, slotName, 0, &newSlot)); pMob->Release(); pMob = NULL; newSlot->Release(); newSlot = NULL; seg->Release(); seg = NULL; check(pHeader->AddMob(pCompMob)); // now looping around the remainder N times to make N components for (i=0; i < N; i++) { //Make the Tape MOB check(pCDSourceMob->CreateInstance(IID_IAAFSourceMob, (IUnknown **)&pTapeMob)); check(pCDTapeDescriptor->CreateInstance(IID_IAAFTapeDescriptor, (IUnknown **)&pTapeDesc)); check(pTapeDesc->QueryInterface (IID_IAAFEssenceDescriptor, (void **)&aDesc)); check(pTapeMob->SetEssenceDescriptor(aDesc)); aDesc->Release(); aDesc = NULL; pTapeDesc->Release(); pTapeDesc = NULL; check(pTapeMob->AppendTimecodeSlot (videoRate, 0, tapeTC, TAPE_LENGTH)); check(pTapeMob->AddNilReference (1,TAPE_LENGTH, pDdefPicture, videoRate)); check(pTapeMob->QueryInterface (IID_IAAFMob, (void **)&pMob)); pTapeMob->Release(); pTapeMob = NULL; // NOTE: TapeMob name is updated to change with number of objects // requested at cli. // In order to fit with the specification, it is made wide char TapeMobNameBuffer[MAX]; sprintf(TapeMobNameBuffer,"Tape Mob %ld",i); aafWChar TapeMobName[MAX]; mbstowcs(TapeMobName,TapeMobNameBuffer,MAX); check(pMob->SetName (TapeMobName)); check(pHeader->AddMob(pMob)); check(pMob->GetMobID (&tapeMobID)); pMob->Release(); pMob = NULL; // Make a FileMob check(pCDSourceMob->CreateInstance(IID_IAAFSourceMob, (IUnknown **)&pFileMob)); check(pCDAIFCDescriptor->CreateInstance(IID_IAAFFileDescriptor, (IUnknown **)&pFileDesc)); check(pFileDesc->QueryInterface (IID_IAAFEssenceDescriptor, (void **)&aDesc)); check(pFileDesc->QueryInterface (IID_IAAFAIFCDescriptor, (void **)&pAIFCDesc)); check(pAIFCDesc->SetSummary (5, (unsigned char*)"TEST")); pAIFCDesc->Release(); pAIFCDesc = NULL; // Make a locator, and attach it to the EssenceDescriptor check(pCDNetworkLocator->CreateInstance(IID_IAAFNetworkLocator, (IUnknown **)&pNetLocator)); check(pNetLocator->QueryInterface (IID_IAAFLocator, (void **)&pLocator)); check(pLocator->SetPath (TEST_PATH)); check(aDesc->AppendLocator(pLocator)); pLocator->Release(); pLocator = NULL; pNetLocator->Release(); pNetLocator = NULL; check(pFileMob->SetEssenceDescriptor(aDesc)); aDesc->Release(); aDesc = NULL; pFileDesc->Release(); pFileDesc = NULL; sourceRef.sourceID = tapeMobID; sourceRef.sourceSlotID = 1; sourceRef.startTime = 0; check(pFileMob->NewPhysSourceRef (videoRate, 1, pDdefPicture, sourceRef, fileLen)); check(pFileMob->QueryInterface (IID_IAAFMob, (void **)&pMob)); check(pMob->GetMobID (&fileMobID)); check(pHeader->AddMob(pMob)); pMob->Release(); pMob = NULL; //Make the Master MOB check(pCDMasterMob->CreateInstance(IID_IAAFMasterMob, (IUnknown **)&pMasterMob)); sourceRef.sourceID = fileMobID; sourceRef.sourceSlotID = 1; sourceRef.startTime = 0; check(pMasterMob->NewPhysSourceRef(videoRate, 1, pDdefPicture, sourceRef, fileLen)); check(pMasterMob->QueryInterface (IID_IAAFMob, (void **)&pMob)); check(pMob->GetMobID (&masterMobID)); // NOTE: MasterMob name is updated to change with number of objects // requested at cli. // In order to fit with the specification, it is made wide char MasterMobNameBuffer[MAX]; sprintf(MasterMobNameBuffer,"Master Mob %ld",i); aafWChar MasterMobName[MAX]; mbstowcs(MasterMobName,MasterMobNameBuffer,MAX); check(pMob->SetName (MasterMobName)); check(pHeader->AddMob(pMob)); pMob->Release(); pMob = NULL; // the remaining part of the sequence code, adapted for updating slot names // Create a SourceClip check(pCDSourceClip->CreateInstance(IID_IAAFSourceClip, (IUnknown **)&compSclp)); sourceRef.sourceID = masterMobID; sourceRef.sourceSlotID = 1; sourceRef.startTime = 0; check(compSclp->SetSourceReference (sourceRef)); check(compSclp->QueryInterface (IID_IAAFComponent, (void **)&aComponent)); check(aComponent->SetDataDef(pDdefPicture)); check(aComponent->SetLength (segLen)); check(pSequence->AppendComponent (aComponent)); // Create a filler - Get the component interface only (IID_IAAFComponent) check(pCDFiller->CreateInstance(IID_IAAFComponent, (IUnknown **)&compFill)); check(compFill->SetLength (fillLen)); check(compFill->SetDataDef(pDdefPicture)); check(pSequence->AppendComponent (compFill)); compFill->Release(); compFill = NULL; aComponent->Release(); aComponent = NULL; compSclp->Release(); compSclp = NULL; pMasterMob->Release(); pMasterMob = NULL; pFileMob->Release(); pFileMob = NULL; // end of loop since only one dictionary and header are needed // the file is then saved, closed and released after all modifications // are complete } cleanup: // Cleanup and return if (pNetLocator) pNetLocator->Release(); if (pLocator) pLocator->Release(); if (compFill) compFill->Release(); if (compSclp) compSclp->Release(); if (masterSclp) masterSclp->Release(); if (fileSclp) fileSclp->Release(); if (pTapeDesc) pTapeDesc->Release(); if (pFileDesc) pFileDesc->Release(); if (pTapeMob) pTapeMob->Release(); if (pFileMob) pFileMob->Release(); if (pMasterMob) pMasterMob->Release(); if (aDesc) aDesc->Release(); if (newSlot) newSlot->Release(); if (pMob) pMob->Release(); if (pCompMob) pCompMob->Release(); if (seg) seg->Release(); if (aComponent) aComponent->Release(); if (pSequence) pSequence->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pCDCompositionMob) { pCDCompositionMob->Release(); pCDCompositionMob = 0; } if (pCDSequence) { pCDSequence->Release(); pCDSequence = 0; } if (pCDSourceMob) { pCDSourceMob->Release(); pCDSourceMob = 0; } if (pCDTapeDescriptor) { pCDTapeDescriptor->Release(); pCDTapeDescriptor = 0; } if (pCDAIFCDescriptor) { pCDAIFCDescriptor->Release(); pCDAIFCDescriptor = 0; } if (pCDNetworkLocator) { pCDNetworkLocator->Release(); pCDNetworkLocator = 0; } if (pCDMasterMob) { pCDMasterMob->Release(); pCDMasterMob = 0; } if (pCDSourceClip) { pCDSourceClip->Release(); pCDSourceClip = 0; } if (pCDFiller) { pCDFiller->Release(); pCDFiller = 0; } if (pDdefPicture) { pDdefPicture->Release(); pDdefPicture = 0; } if (pFile) { clock_t start = clock(); clock_t finish; double duration; pFile->Save(); pFile->Close(); #if defined(USE_MEMORY_FILE) check(MemoryFileSaveToDisk(pFileName, pFile)); #endif finish = clock(); duration = ((double) (finish - start) / CLOCKS_PER_SEC); pFile->Release(); printf("Save time = %f seconds\n", duration); } return moduleErrorTmp; }
static HRESULT CreateAAFFile(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 bool testRestore(const wchar_t* fileName) { bool passed = true; IAAFFile* pFile = 0; IAAFHeader* pHeader = 0; IAAFDictionary* pDictionary = 0; IAAFContentStorage* pStorage = 0; IEnumAAFMobs* pMobs = 0; IAAFMob* pMob = 0; try { pFile = openFileForReading(fileName); } catch (...) { return false; } try { // get the Mob containing the test data checkResult(pFile->GetHeader(&pHeader)); checkResult(pHeader->GetDictionary(&pDictionary)); checkResult(pHeader->GetContentStorage(&pStorage)); aafSearchCrit_t searchCrit; searchCrit.searchTag = kAAFByMobKind; searchCrit.tags.mobKind = kAAFAllMob; checkResult(pStorage->GetMobs(&searchCrit, &pMobs)); checkResult(pMobs->NextOne(&pMob)); IAAFObject* pObject = 0; IAAFClassDef* pClassDef = 0; IAAFPropertyDef* pPropertyDef = 0; IAAFPropertyValue* pPropertyValue = 0; IAAFTypeDef* pType = 0; IAAFTypeDefIndirect* pIndirectType = 0; IAAFPropertyValue* pActualPropertyValue = 0; IAAFTypeDef* pActualType = 0; IAAFTypeDefInt* pIntType = 0; IAAFTypeDefEnum* pEnumType = 0; IAAFTypeDefRecord* pRecordType = 0; try { printf(" * Baseline: "); const aafUID_t propId = {0x00000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafInt8 testValue = -128; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefIndirect, (void **)&pIndirectType)); checkResult(pIndirectType->GetActualValue(pPropertyValue, &pActualPropertyValue)); checkResult(pActualPropertyValue->GetType(&pActualType)); checkResult(pActualType->QueryInterface(IID_IAAFTypeDefInt, (void **)&pIntType)); aafInt8 value; checkResult(pIntType->GetInteger(pActualPropertyValue, (aafUInt8*)&value, 1)); if (value == testValue) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pRecordType); release(pEnumType); release(pIntType); release(pActualType); release(pActualPropertyValue); release(pIndirectType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); try { printf(" * Non-baseline: "); const aafUID_t propId = {0x10000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafUInt8 testValue = 1; const wchar_t* testName = L"AAA"; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefIndirect, (void **)&pIndirectType)); checkResult(pIndirectType->GetActualValue(pPropertyValue, &pActualPropertyValue)); checkResult(pActualPropertyValue->GetType(&pActualType)); checkResult(pActualType->QueryInterface(IID_IAAFTypeDefEnum, (void **)&pEnumType)); aafInt64 value; aafCharacter name[256]; checkResult(pEnumType->GetIntegerValue(pActualPropertyValue, &value)); checkResult(pEnumType->GetNameFromValue(pActualPropertyValue, name, 256)); if (value == testValue && wcscmp(name, testName) == 0) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pRecordType); release(pEnumType); release(pIntType); release(pActualType); release(pActualPropertyValue); release(pIndirectType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); try { printf(" * Baseline record: "); const aafUID_t propId = {0x20000000,0x0000,0x0000,{0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}; aafProductVersion_t testValue = {0,1,0,0,kAAFVersionUnknown}; checkResult(pMob->QueryInterface(IID_IAAFObject, (void **)&pObject)); checkResult(pDictionary->LookupClassDef(kAAFClassID_Mob, &pClassDef)); checkResult(pClassDef->LookupPropertyDef(propId, &pPropertyDef)); checkResult(pObject->GetPropertyValue(pPropertyDef, &pPropertyValue)); checkResult(pPropertyValue->GetType(&pType)); checkResult(pType->QueryInterface(IID_IAAFTypeDefIndirect, (void **)&pIndirectType)); checkResult(pIndirectType->GetActualValue(pPropertyValue, &pActualPropertyValue)); checkResult(pActualPropertyValue->GetType(&pActualType)); checkResult(pActualType->QueryInterface(IID_IAAFTypeDefRecord, (void **)&pRecordType)); aafProductVersion_t value; checkResult(pRecordType->GetStruct(pActualPropertyValue, (aafUInt8*)&value, sizeof(aafProductVersion_t))); if (memcmp(&testValue, &value, sizeof(aafProductVersion_t)) == 0) { printf("passed\n"); } else { printf("FAILED\n"); passed = false; } } catch (...) { printf("FAILED\n"); passed = false; } release(pRecordType); release(pEnumType); release(pIntType); release(pActualType); release(pActualPropertyValue); release(pIndirectType); release(pType); release(pPropertyValue); release(pPropertyDef); release(pClassDef); release(pObject); } catch (...) { passed = false; } // cleanup release(pMob); release(pMobs); release(pStorage); release(pDictionary); release(pHeader); checkResult(pFile->Close()); release(pFile); report(passed); return passed; }