void EnumEssenceDataTest::createEssenceData(IAAFSourceMob *pSourceMob) { assert(_pFile && _pHeader && _pDictionary); assert(pSourceMob); assert(NULL == _pEssenceData); CAAFBuiltinDefs defs (_pDictionary); // Attempt to create an AAFEssenceData. check(defs.cdEssenceData()-> CreateInstance(IID_IAAFEssenceData, (IUnknown **)&_pEssenceData)); check(_pEssenceData->SetFileMob(pSourceMob)); check(_pHeader->AddEssenceData(_pEssenceData)); _pEssenceData->Release(); _pEssenceData = NULL; }
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; }
void EssenceDataTest::createEssenceData(IAAFSourceMob *pSourceMob) { assert(_pFile && _pHeader && _pDictionary); assert(pSourceMob); assert(NULL == _pEssenceData); CAAFBuiltinDefs defs (_pDictionary); // Attempt to create an AAFEssenceData. IAAFEssenceData* pRawEssenceData = NULL; check(defs.cdEssenceData()-> CreateInstance(IID_IAAFEssenceData, (IUnknown **)&pRawEssenceData)); check(pRawEssenceData->SetFileMob(pSourceMob)); check(_pHeader->AddEssenceData(pRawEssenceData)); IAAFEssenceData2* pEssenceData2 = NULL; check(pRawEssenceData->QueryInterface(IID_IAAFEssenceData2, (void**)&pEssenceData2)); check(pEssenceData2->GetPlainEssenceData(0, &_pEssenceData)); // Set essence element key IAAFKLVEssenceDataParameters* pParameters = NULL; check(_pEssenceData->QueryInterface(IID_IAAFKLVEssenceDataParameters, (void **)&pParameters)); AAFRESULT hr = pParameters->SetEssenceElementKey(_essenceElementKey); checkExpression(AAFRESULT_SUCCEEDED(hr) || hr == AAFRESULT_OPERATION_NOT_PERMITTED, AAFRESULT_TEST_FAILED); aafUID_t key; hr = pParameters->GetEssenceElementKey(&key); checkExpression(AAFRESULT_SUCCEEDED(hr) || hr == AAFRESULT_OPERATION_NOT_PERMITTED, AAFRESULT_TEST_FAILED); checkExpression(AAFRESULT_FAILED(hr) || key == _essenceElementKey, AAFRESULT_TEST_FAILED); writeEssenceData(_pEssenceData, (aafDataBuffer_t)_smiley, sizeof(_smiley)); writeEssenceData(_pEssenceData, (aafDataBuffer_t)_frowney, sizeof(_frowney)); // Read back the data before saving and/or closing the file check(_pEssenceData->SetPosition(0)); aafPosition_t dataPosition = 0; check(_pEssenceData->GetPosition(&dataPosition)); checkExpression(dataPosition == 0, AAFRESULT_TEST_FAILED); // Validate the current essence size. aafLength_t essenceSize = 0; aafLength_t expectedEssenceSize = sizeof(_smiley) + sizeof(_frowney); check(_pEssenceData->GetSize(&essenceSize)); checkExpression(essenceSize == expectedEssenceSize, AAFRESULT_TEST_FAILED); readEssenceData(_pEssenceData, (aafDataBuffer_t)_smiley, sizeof(_smiley)); readEssenceData(_pEssenceData, (aafDataBuffer_t)_frowney, sizeof(_frowney)); pParameters->Release(); pParameters = NULL; pRawEssenceData->Release(); pRawEssenceData = NULL; pEssenceData2->Release(); pEssenceData2 = NULL; _pEssenceData->Release(); _pEssenceData = NULL; }