extern int main(int argc, char *argv[]) { const char *filename_cstr = "test.aaf"; #ifndef _MSC_VER setlocale (LC_ALL, "en_US.UTF-8"); #endif if (argc >= 2) { filename_cstr = argv[1]; } // convert C str to wide string aafWChar filename[FILENAME_MAX]; size_t status = mbstowcs(filename, filename_cstr, sizeof(filename)); if (status == (size_t)-1) { fprintf(stderr, "mbstowcs failed for \"%s\"\n", filename_cstr); return 1; } remove(filename_cstr); IAAFFile *pFile = NULL; int mode = 0; aafProductIdentification_t productID; aafProductVersion_t TestVersion = {1, 1, 0, 0, kAAFVersionUnknown}; productID.companyName = (aafCharacter*)L"HSC"; productID.productName = (aafCharacter*)L"String Tester"; productID.productVersion = &TestVersion; productID.productVersionString = NULL; productID.productID = TestProductID; productID.platform = (aafCharacter*)L"Linux"; // Create new AAF file check(AAFFileOpenNewModify(filename, mode, &productID, &pFile)); // Create a simple Mob IAAFClassDef *classDef = NULL; IAAFMob *pMob = NULL; IAAFHeader *pHeader = NULL; IAAFDictionary *pDictionary = NULL; check(pFile->GetHeader(&pHeader)); check(pHeader->GetDictionary(&pDictionary)); check(pDictionary->LookupClassDef(AUID_AAFMasterMob, &classDef)); check(classDef->CreateInstance(IID_IAAFMob, (IUnknown **)&pMob)); classDef->Release(); check(pMob->SetMobID(TEST_MobID)); // UTF-8 for codepoint U+1D11E (musical G Clef): 0xf0,0x9d,0x84,0x9e // UTF-8 for codepoint U+1D122 (musical F Clef): 0xf0,0x9d,0x84,0xa2 // http://unicode.org/charts/PDF/U1D100.pdf // http://en.wikipedia.org/wiki/UTF-8 aafCharacter *mobname; const unsigned char inputStr[] = { 0xf0,0x9d,0x84,0x9e, // U+1D11E 0xf0,0x9d,0x84,0xa2, // U+1D122 0x4d, 0x6f, 0x62, // 'M' 'o' 'b' 0x0 }; // Convert UTF-8 inputStr to native wchar_t representation (UTF-32 Unix, UTF-16 Windows) int wlen = 0, n; #ifndef _MSC_VER int ret; char *p = (char *)inputStr; while ((ret = mblen(p, 4)) > 0) { ++wlen; p+=ret; } mobname = new aafCharacter[wlen+1]; n = mbstowcs(mobname, (const char *)inputStr, wlen+1); if (n == -1) { fprintf (stderr, "mbstowcs returned -1. Invalid multibyte string\n"); exit(1); } #else // Under Windows we must use MultiByteToWideChar() to get correct UTF-8 conversion to UTF-16 // since mbstowcs() is broken for UTF-8. wlen = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, (LPCSTR)inputStr, -1, NULL, 0); if (wlen == 0) { fprintf (stderr, "MultiByteToWideChar returned 0. Invalid multibyte string\n"); exit(1); } mobname = new aafCharacter[wlen]; n = MultiByteToWideChar (CP_UTF8, MB_ERR_INVALID_CHARS, (LPCSTR)inputStr, -1, mobname, wlen); if (n == 0) { fprintf (stderr, "MultiByteToWideChar returned 0. Invalid multibyte string\n"); exit(1); } #endif // SetName() calls OMSimpleProperty::set() which does a memcpy of the mobname string // to an OMByte* variable 'bits()' at OMProperty.cpp:399 // Found by setting an rwatch on mobname address. check(pMob->SetName(mobname)); aafUInt32 size_before = 0; check(pMob->GetNameBufLen(&size_before)); check(pHeader->AddMob(pMob)); pMob->Release(); pHeader->Release(); pDictionary->Release(); // All the work of storing to disk happens during Save() // The bits() variable is next read in OMType::contract() at OMType.cpp:137 // which is called by ImplAAFTypeDefCharacter::externalize() at ImplAAFTypeDefCharacter.cpp:307 // which is called by ImplAAFTypeDefString::externalize() at ImplAAFTypeDefString.cpp:584 // which is called by OMSSStoredObject::save() at OMSSStoredObject.cpp:382 check(pFile->Save()); check(pFile->Close()); pFile->Release(); // OMCharacterStringProperty<CharacterType>::stringLength() at OMVariableSizePropertyT.h:80 // calculates string length of AAF string properties // Read AAF file back in check(AAFFileOpenExistingRead(filename, mode, &pFile)); // Get the Mob check(pFile->GetHeader(&pHeader)); check(pHeader->LookupMob(TEST_MobID, &pMob)); aafUInt32 size_after = 0; check(pMob->GetNameBufLen(&size_after)); aafCharacter *mobname_after = new aafCharacter[size_after]; check(pMob->GetName(mobname_after, size_after)); // Compare Mob name before storing to disk with Mob name read back from disk int test_result = 0; if (size_before != size_after) { printf("size_before=%d != size_after=%d\n", size_before, size_after); test_result = 1; } else { if (memcmp(mobname, mobname_after, size_before) != 0) { printf("wchar_t* mobname and wchar_t* mobname_after differ:\n"); printf(" %s\n", hexDump(mobname, size_before)); printf(" %s\n", hexDump(mobname_after, size_after)); test_result = 1; } } // Check if the multibyte (UTF-8) versions of mobname and mobname_after match. char *outputStr; #ifndef _MSC_VER wlen = wcslen(mobname_after)*sizeof(aafCharacter) + 1; outputStr = new char [wlen]; n = wcstombs (outputStr, mobname_after, wlen); if (n == -1) { fprintf(stderr, "Could not convert mobname_after to multibyte str\n"); exit(1); } #else wlen = WideCharToMultiByte(CP_UTF8, 0, mobname_after, -1, NULL, 0, NULL, NULL); if (wlen == 0) { fprintf (stderr, "Failed to convert mobname_after to multibyte string\n"); exit(1); } outputStr = new char[wlen]; wlen = WideCharToMultiByte(CP_UTF8, 0, mobname_after, -1, outputStr, wlen, NULL, NULL); #endif if (strlen((char *)inputStr) != strlen(outputStr)) { fprintf(stderr, "UTF-8 version of string: input length(%d) != output length(%d)\n", (int)strlen((char *)inputStr), (int)strlen(outputStr)); test_result = 1; } if (strcmp((char *)inputStr, outputStr) != 0) { fprintf(stderr, "UTF-8 version of string: input and output strings differ\n"); printf(" %s\n", hexDump(inputStr, strlen((char *)inputStr))); printf(" %s\n", hexDump(outputStr, strlen(outputStr))); test_result = 1; } pMob->Release(); pHeader->Release(); check(pFile->Close()); pFile->Release(); delete [] mobname; delete [] mobname_after; return test_result; }
static HRESULT CreateAAFFile( aafWChar * pFileName, aafUID_constref fileKind, testRawStorageType_t rawStorageType, aafProductIdentification_constref productID) { IAAFFile * pFile = NULL; bool bFileOpen = false; IAAFHeader * pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFLocator * pLocator = NULL; IAAFNetworkLocator * pNetLocator = NULL; IAAFSourceMob *pSourceMob = NULL; IAAFMob *pMob = NULL; IAAFEssenceDescriptor *edesc = NULL; aafUInt32 numLocators; HRESULT hr = AAFRESULT_SUCCESS; try { // Remove the previous test file if any. RemoveTestFile(pFileName); // Create the file. checkResult(CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile )); bFileOpen = true; // We can't really do anthing in AAF without the header. checkResult(pFile->GetHeader(&pHeader)); // Get the AAF Dictionary so that we can create valid AAF objects. checkResult(pHeader->GetDictionary(&pDictionary)); CAAFBuiltinDefs defs (pDictionary); //Make the first mob // Create a Mob checkResult(defs.cdSourceMob()-> CreateInstance(IID_IAAFSourceMob, (IUnknown **)&pSourceMob)); checkResult(pSourceMob->QueryInterface (IID_IAAFMob, (void **)&pMob)); checkResult(pMob->SetMobID(TEST_MobID)); checkResult(pMob->SetName(L"SourceMOBTest")); // Create a concrete subclass of EssenceDescriptor checkResult(defs.cdAIFCDescriptor()-> CreateInstance(IID_IAAFEssenceDescriptor, (IUnknown **)&edesc)); IAAFAIFCDescriptor* pAIFCDesc = NULL; checkResult(edesc->QueryInterface (IID_IAAFAIFCDescriptor, (void **)&pAIFCDesc)); checkResult(pAIFCDesc->SetSummary (5, (unsigned char*)"TEST")); pAIFCDesc->Release(); pAIFCDesc = NULL; // Verify that there are no locators checkResult(edesc->CountLocators(&numLocators)); checkExpression(0 == numLocators, AAFRESULT_TEST_FAILED); // Make a locator, and attach it to the EssenceDescriptor checkResult(defs.cdNetworkLocator()-> CreateInstance(IID_IAAFNetworkLocator, (IUnknown **)&pNetLocator)); checkResult(pNetLocator->QueryInterface (IID_IAAFLocator, (void **)&pLocator)); checkResult(pLocator->SetPath (TEST_PATH)); checkResult(edesc->AppendLocator(pLocator)); checkResult(pSourceMob->SetEssenceDescriptor (edesc)); // Verify that there is now one locator checkResult(edesc->CountLocators(&numLocators)); checkExpression(1 == numLocators, AAFRESULT_TEST_FAILED); // Add the source mob into the tree checkResult(pHeader->AddMob(pMob)); } catch (HRESULT& rResult) { hr = rResult; } // cleanup if (pLocator) pLocator->Release(); if (pNetLocator) pNetLocator->Release(); if (edesc) edesc->Release(); if (pMob) pMob->Release(); if (pSourceMob) pSourceMob->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pFile) { if (bFileOpen) { pFile->Save(); pFile->Close(); } pFile->Release(); } // hr = pSession->EndSession(); // if (AAFRESULT_SUCCESS != hr) // return hr; // if (pSession) pSession->Release(); return hr; }
static HRESULT CreateAAFFile(aafWChar * pFileName, long int N) { IAAFFile* pFile = NULL; IAAFHeader* pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFMob* pMob = NULL; IAAFMob* pCompMob = NULL; IAAFEssenceDescriptor* aDesc = NULL; IAAFMasterMob* pMasterMob = NULL; IAAFSourceMob* pFileMob = NULL; IAAFSourceMob* pTapeMob = NULL; IAAFSequence* pSequence = NULL; IAAFComponent* aComponent = NULL; IAAFFileDescriptor* pFileDesc = NULL; IAAFAIFCDescriptor* pAIFCDesc = NULL; IAAFTapeDescriptor* pTapeDesc = NULL; IAAFTimelineMobSlot* newSlot = NULL; IAAFSegment* seg = NULL; IAAFSourceClip* fileSclp = NULL; IAAFSourceClip* masterSclp = NULL; IAAFSourceClip* compSclp = NULL; IAAFComponent* compFill = NULL; IAAFLocator* pLocator = NULL; IAAFNetworkLocator* pNetLocator = NULL; IAAFClassDef * pCDCompositionMob = 0; IAAFClassDef * pCDSequence = 0; IAAFClassDef * pCDSourceMob = 0; IAAFClassDef * pCDTapeDescriptor = 0; IAAFClassDef * pCDAIFCDescriptor = 0; IAAFClassDef * pCDNetworkLocator = 0; IAAFClassDef * pCDMasterMob = 0; IAAFClassDef * pCDSourceClip = 0; IAAFClassDef * pCDFiller = 0; IAAFDataDef * pDdefPicture = 0; aafRational_t videoRate = { 30000, 1001 }; aafMobID_t tapeMobID, fileMobID, masterMobID; aafTimecode_t tapeTC = { 108000, kAAFTcNonDrop, 30}; aafLength_t fileLen = FILE1_LENGTH; aafLength_t fillLen = FILL_LENGTH; aafLength_t segLen = SEG_LENGTH; aafProductIdentification_t ProductInfo; long int i = 0; moduleErrorTmp = S_OK; // delete any previous test file before continuing... char chFileName[1000]; convert(chFileName, sizeof(chFileName), pFileName); remove(chFileName); aafProductVersion_t v; v.major = 1; v.minor = 0; v.tertiary = 0; v.patchLevel = 0; v.type = kAAFVersionUnknown; ProductInfo.companyName = companyName; ProductInfo.productName = productName; ProductInfo.productVersion = &v; ProductInfo.productVersionString = NULL; ProductInfo.productID = NIL_UID; ProductInfo.platform = NULL; #if defined(USE_MEMORY_FILE) check(MemoryFileOpenNewModify (0, &ProductInfo, &pFile)); #else check(AAFFileOpenNewModifyEx (pFileName, &kAAFFileKind_Aaf4KBinary, 0, &ProductInfo, &pFile)); #endif check(pFile->GetHeader(&pHeader)); // Get the AAF Dictionary so that we can create valid AAF objects. check(pHeader->GetDictionary(&pDictionary)); check(pDictionary->LookupClassDef(AUID_AAFCompositionMob, &pCDCompositionMob)); check(pDictionary->LookupClassDef(AUID_AAFSequence, &pCDSequence)); check(pDictionary->LookupClassDef(AUID_AAFSourceMob, &pCDSourceMob)); check(pDictionary->LookupClassDef(AUID_AAFTapeDescriptor, &pCDTapeDescriptor)); check(pDictionary->LookupClassDef(AUID_AAFAIFCDescriptor, &pCDAIFCDescriptor)); check(pDictionary->LookupClassDef(AUID_AAFNetworkLocator, &pCDNetworkLocator)); check(pDictionary->LookupClassDef(AUID_AAFMasterMob, &pCDMasterMob)); check(pDictionary->LookupClassDef(AUID_AAFSourceClip, &pCDSourceClip)); check(pDictionary->LookupClassDef(AUID_AAFFiller, &pCDFiller)); check(pDictionary->LookupDataDef(kAAFDataDef_Picture, &pDdefPicture)); // IMPORTANT: major remodification is from this point onwards... // sequence creation code pulled out of the subsequent loop. // Create a Composition Mob check(pCDCompositionMob->CreateInstance(IID_IAAFMob, (IUnknown **)&pCompMob)); check(pCDSequence->CreateInstance(IID_IAAFSequence, (IUnknown **)&pSequence)); check(pSequence->QueryInterface (IID_IAAFSegment, (void **)&seg)); check(pSequence->QueryInterface(IID_IAAFComponent, (void **)&aComponent)); check(aComponent->SetDataDef(pDdefPicture)); aComponent->Release(); aComponent = NULL; check(pCompMob->QueryInterface (IID_IAAFMob, (void **)&pMob)); check(pMob->AppendNewTimelineSlot(videoRate, seg, i, slotName, 0, &newSlot)); pMob->Release(); pMob = NULL; newSlot->Release(); newSlot = NULL; seg->Release(); seg = NULL; check(pHeader->AddMob(pCompMob)); // now looping around the remainder N times to make N components for (i=0; i < N; i++) { //Make the Tape MOB check(pCDSourceMob->CreateInstance(IID_IAAFSourceMob, (IUnknown **)&pTapeMob)); check(pCDTapeDescriptor->CreateInstance(IID_IAAFTapeDescriptor, (IUnknown **)&pTapeDesc)); check(pTapeDesc->QueryInterface (IID_IAAFEssenceDescriptor, (void **)&aDesc)); check(pTapeMob->SetEssenceDescriptor(aDesc)); aDesc->Release(); aDesc = NULL; pTapeDesc->Release(); pTapeDesc = NULL; check(pTapeMob->AppendTimecodeSlot (videoRate, 0, tapeTC, TAPE_LENGTH)); check(pTapeMob->AddNilReference (1,TAPE_LENGTH, pDdefPicture, videoRate)); check(pTapeMob->QueryInterface (IID_IAAFMob, (void **)&pMob)); pTapeMob->Release(); pTapeMob = NULL; // NOTE: TapeMob name is updated to change with number of objects // requested at cli. // In order to fit with the specification, it is made wide char TapeMobNameBuffer[MAX]; sprintf(TapeMobNameBuffer,"Tape Mob %ld",i); aafWChar TapeMobName[MAX]; mbstowcs(TapeMobName,TapeMobNameBuffer,MAX); check(pMob->SetName (TapeMobName)); check(pHeader->AddMob(pMob)); check(pMob->GetMobID (&tapeMobID)); pMob->Release(); pMob = NULL; // Make a FileMob check(pCDSourceMob->CreateInstance(IID_IAAFSourceMob, (IUnknown **)&pFileMob)); check(pCDAIFCDescriptor->CreateInstance(IID_IAAFFileDescriptor, (IUnknown **)&pFileDesc)); check(pFileDesc->QueryInterface (IID_IAAFEssenceDescriptor, (void **)&aDesc)); check(pFileDesc->QueryInterface (IID_IAAFAIFCDescriptor, (void **)&pAIFCDesc)); check(pAIFCDesc->SetSummary (5, (unsigned char*)"TEST")); pAIFCDesc->Release(); pAIFCDesc = NULL; // Make a locator, and attach it to the EssenceDescriptor check(pCDNetworkLocator->CreateInstance(IID_IAAFNetworkLocator, (IUnknown **)&pNetLocator)); check(pNetLocator->QueryInterface (IID_IAAFLocator, (void **)&pLocator)); check(pLocator->SetPath (TEST_PATH)); check(aDesc->AppendLocator(pLocator)); pLocator->Release(); pLocator = NULL; pNetLocator->Release(); pNetLocator = NULL; check(pFileMob->SetEssenceDescriptor(aDesc)); aDesc->Release(); aDesc = NULL; pFileDesc->Release(); pFileDesc = NULL; sourceRef.sourceID = tapeMobID; sourceRef.sourceSlotID = 1; sourceRef.startTime = 0; check(pFileMob->NewPhysSourceRef (videoRate, 1, pDdefPicture, sourceRef, fileLen)); check(pFileMob->QueryInterface (IID_IAAFMob, (void **)&pMob)); check(pMob->GetMobID (&fileMobID)); check(pHeader->AddMob(pMob)); pMob->Release(); pMob = NULL; //Make the Master MOB check(pCDMasterMob->CreateInstance(IID_IAAFMasterMob, (IUnknown **)&pMasterMob)); sourceRef.sourceID = fileMobID; sourceRef.sourceSlotID = 1; sourceRef.startTime = 0; check(pMasterMob->NewPhysSourceRef(videoRate, 1, pDdefPicture, sourceRef, fileLen)); check(pMasterMob->QueryInterface (IID_IAAFMob, (void **)&pMob)); check(pMob->GetMobID (&masterMobID)); // NOTE: MasterMob name is updated to change with number of objects // requested at cli. // In order to fit with the specification, it is made wide char MasterMobNameBuffer[MAX]; sprintf(MasterMobNameBuffer,"Master Mob %ld",i); aafWChar MasterMobName[MAX]; mbstowcs(MasterMobName,MasterMobNameBuffer,MAX); check(pMob->SetName (MasterMobName)); check(pHeader->AddMob(pMob)); pMob->Release(); pMob = NULL; // the remaining part of the sequence code, adapted for updating slot names // Create a SourceClip check(pCDSourceClip->CreateInstance(IID_IAAFSourceClip, (IUnknown **)&compSclp)); sourceRef.sourceID = masterMobID; sourceRef.sourceSlotID = 1; sourceRef.startTime = 0; check(compSclp->SetSourceReference (sourceRef)); check(compSclp->QueryInterface (IID_IAAFComponent, (void **)&aComponent)); check(aComponent->SetDataDef(pDdefPicture)); check(aComponent->SetLength (segLen)); check(pSequence->AppendComponent (aComponent)); // Create a filler - Get the component interface only (IID_IAAFComponent) check(pCDFiller->CreateInstance(IID_IAAFComponent, (IUnknown **)&compFill)); check(compFill->SetLength (fillLen)); check(compFill->SetDataDef(pDdefPicture)); check(pSequence->AppendComponent (compFill)); compFill->Release(); compFill = NULL; aComponent->Release(); aComponent = NULL; compSclp->Release(); compSclp = NULL; pMasterMob->Release(); pMasterMob = NULL; pFileMob->Release(); pFileMob = NULL; // end of loop since only one dictionary and header are needed // the file is then saved, closed and released after all modifications // are complete } cleanup: // Cleanup and return if (pNetLocator) pNetLocator->Release(); if (pLocator) pLocator->Release(); if (compFill) compFill->Release(); if (compSclp) compSclp->Release(); if (masterSclp) masterSclp->Release(); if (fileSclp) fileSclp->Release(); if (pTapeDesc) pTapeDesc->Release(); if (pFileDesc) pFileDesc->Release(); if (pTapeMob) pTapeMob->Release(); if (pFileMob) pFileMob->Release(); if (pMasterMob) pMasterMob->Release(); if (aDesc) aDesc->Release(); if (newSlot) newSlot->Release(); if (pMob) pMob->Release(); if (pCompMob) pCompMob->Release(); if (seg) seg->Release(); if (aComponent) aComponent->Release(); if (pSequence) pSequence->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pCDCompositionMob) { pCDCompositionMob->Release(); pCDCompositionMob = 0; } if (pCDSequence) { pCDSequence->Release(); pCDSequence = 0; } if (pCDSourceMob) { pCDSourceMob->Release(); pCDSourceMob = 0; } if (pCDTapeDescriptor) { pCDTapeDescriptor->Release(); pCDTapeDescriptor = 0; } if (pCDAIFCDescriptor) { pCDAIFCDescriptor->Release(); pCDAIFCDescriptor = 0; } if (pCDNetworkLocator) { pCDNetworkLocator->Release(); pCDNetworkLocator = 0; } if (pCDMasterMob) { pCDMasterMob->Release(); pCDMasterMob = 0; } if (pCDSourceClip) { pCDSourceClip->Release(); pCDSourceClip = 0; } if (pCDFiller) { pCDFiller->Release(); pCDFiller = 0; } if (pDdefPicture) { pDdefPicture->Release(); pDdefPicture = 0; } if (pFile) { clock_t start = clock(); clock_t finish; double duration; pFile->Save(); pFile->Close(); #if defined(USE_MEMORY_FILE) check(MemoryFileSaveToDisk(pFileName, pFile)); #endif finish = clock(); duration = ((double) (finish - start) / CLOCKS_PER_SEC); pFile->Release(); printf("Save time = %f seconds\n", duration); } return moduleErrorTmp; }
static HRESULT CreateAAFFile( aafWChar * pFileName, aafUID_constref fileKind, testRawStorageType_t rawStorageType, aafProductIdentification_constref productID) { IAAFFile * pFile = NULL; bool bFileOpen = false; IAAFHeader * pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFContainerDef* pContainer = NULL; IAAFSourceMob *pSourceMob = NULL; IAAFMob *pMob = NULL; IAAFEssenceDescriptor *edesc = NULL; IAAFFileDescriptor *pFileDesc = NULL; IAAFFileDescriptor2 *pFileDesc2 = NULL; HRESULT hr = S_OK; try { // Remove the previous test file if any. RemoveTestFile(pFileName); // Create the file checkResult(CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile )); bFileOpen = true; // We can't really do anthing in AAF without the header. checkResult(pFile->GetHeader(&pHeader)); // Get the AAF Dictionary so that we can create valid AAF objects. checkResult(pHeader->GetDictionary(&pDictionary)); CAAFBuiltinDefs defs (pDictionary); //Make the first mob long test; aafRational_t audioRate = { 44100, 1 }; // Create a Mob checkResult(defs.cdSourceMob()-> CreateInstance(IID_IAAFSourceMob, (IUnknown **)&pSourceMob)); checkResult(pSourceMob->QueryInterface (IID_IAAFMob, (void **)&pMob)); checkResult(pMob->SetMobID(TEST_MobID)); checkResult(pMob->SetName(L"FileDescriptorTest")); // Add some slots for(test = 0; test < 2; test++) { checkResult(pSourceMob->AddNilReference (test+1, 0, defs.ddkAAFSound(), audioRate)); } // Create a concrete subclass of FileDescriptor checkResult(defs.cdAIFCDescriptor()-> CreateInstance(IID_IAAFEssenceDescriptor, (IUnknown **)&edesc)); IAAFAIFCDescriptor* pAIFCDesc = NULL; checkResult(edesc->QueryInterface (IID_IAAFAIFCDescriptor, (void **)&pAIFCDesc)); checkResult(pAIFCDesc->SetSummary (5, (unsigned char*)"TEST")); pAIFCDesc->Release(); pAIFCDesc = NULL; checkResult(edesc->QueryInterface(IID_IAAFFileDescriptor, (void **) &pFileDesc)); checkResult(pFileDesc->SetSampleRate (checkSampleRate)); checkResult(pDictionary->LookupContainerDef(checkContainer, &pContainer)); checkResult(pFileDesc->SetContainerFormat (pContainer)); pContainer->Release(); pContainer = NULL; checkResult(pFileDesc->SetLength (checkLength)); checkResult(pFileDesc->QueryInterface(IID_IAAFFileDescriptor2, (void **)&pFileDesc2)); checkResult(pFileDesc2->SetLinkedSlotID (checkLinkedSlotID)); // checkResult(pFileDesc->SetIsInContainer (kAAFTrue)); checkResult(pSourceMob->SetEssenceDescriptor (edesc)); checkResult(pHeader->AddMob(pMob)); } catch (HRESULT& rResult) { hr = rResult; } if (pFileDesc) pFileDesc->Release(); if (pFileDesc2) pFileDesc2->Release(); if (edesc) edesc->Release(); if (pMob) pMob->Release(); if (pSourceMob) pSourceMob->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pFile) { if (bFileOpen) { pFile->Save(); pFile->Close(); } pFile->Release(); } return hr; }
static HRESULT ReadAAFFile(aafWChar * pFileName) { IAAFFile* pFile = NULL; IAAFHeader* pHeader = NULL; IEnumAAFMobs* pMobIter = NULL; IAAFMob* pMob = NULL; IAAFSourceMob* pSourceMob = NULL; IAAFEssenceDescriptor* pEssDesc = NULL; IAAFTIFFDescriptor* pTIFFDesc = NULL; aafNumSlots_t numMobs = 0; HRESULT hr = AAFRESULT_SUCCESS; aafBool isContiguous, isUniform; aafInt32 leadingLines, trailingLines; aafUInt32 size; aafUInt8 summary[512]; try { // Open the AAF file checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); // Get the AAF file header. checkResult(pFile->GetHeader(&pHeader)); checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED); checkResult(pHeader->GetMobs(NULL, &pMobIter)); checkResult(pMobIter->NextOne(&pMob)); checkResult(pMob->QueryInterface(IID_IAAFSourceMob, (void **)&pSourceMob)); // Back into testing mode checkResult(pSourceMob->GetEssenceDescriptor(&pEssDesc)); checkResult(pEssDesc->QueryInterface(IID_IAAFTIFFDescriptor, (void **)&pTIFFDesc)); checkResult(pTIFFDesc->GetIsContiguous(&isContiguous)); checkResult(pTIFFDesc->GetIsUniform(&isUniform)); checkResult(pTIFFDesc->GetLeadingLines(&leadingLines)); checkResult(pTIFFDesc->GetTrailingLines(&trailingLines)); checkResult(pTIFFDesc->GetSummaryBufferSize(&size)); checkExpression(size == 34, AAFRESULT_TEST_FAILED); checkResult(pTIFFDesc->GetSummary(size, summary)); checkExpression(isContiguous == kAAFTrue, AAFRESULT_TEST_FAILED); checkExpression(isUniform == kAAFFalse, AAFRESULT_TEST_FAILED); checkExpression(leadingLines == 10, AAFRESULT_TEST_FAILED); checkExpression(trailingLines == 20, AAFRESULT_TEST_FAILED); // The next statement is not true when doing cross-platform tests //#if defined( OS_WINDOWS ) // checkExpression(memcmp(summary, "II", 2) == 0, AAFRESULT_TEST_FAILED); //#else // checkExpression(memcmp(summary, "MM", 2) == 0, AAFRESULT_TEST_FAILED); //#endif // NOTE: The elements in the summary structure need to be byte swapped // on Big Endian system (i.e. the MAC). } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pEssDesc) pEssDesc->Release(); if (pTIFFDesc) pTIFFDesc->Release(); if (pMob) pMob->Release(); if (pSourceMob) pSourceMob->Release(); if (pHeader) pHeader->Release(); if (pMobIter) pMobIter->Release(); if (pFile) { pFile->Close(); pFile->Release(); } return hr; }
static HRESULT OpenAAFFile(aafWChar * pFileName, bool comp_enable) { IAAFFile* pFile = NULL; IAAFHeader* pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFMob* pMob = NULL; IAAFEssenceAccess* pEssenceAccess = NULL; IEnumAAFMobs* pMobIter = NULL; aafNumSlots_t numMobs, numSlots; aafSearchCrit_t criteria; aafMobID_t mobID; IAAFDataDef *pPictureDef = NULL; IAAFMobSlot* pMobSlot = NULL; // Open an AAF file check(AAFFileOpenExistingRead (pFileName, 0, &pFile)); check(pFile->GetHeader(&pHeader)); // Open raw video output file FILE *output; const char *output_file = comp_enable ? "raw.uyvy" : "raw.mjpeg"; if ((output = fopen(output_file, "wb")) == NULL) { perror(output_file); exit(1); } // Get the AAF Dictionary from the file check(pHeader->GetDictionary(&pDictionary)); /* Lookup any necessary data definitions. */ check(pDictionary->LookupDataDef(kAAFDataDef_Picture, &pPictureDef)); /* Check number of Mobs in file */ check(pHeader->CountMobs(kAAFMasterMob, &numMobs)); if (numMobs == 0) return 0; printf("Found %d Master Mobs\n", numMobs); criteria.searchTag = kAAFByMobKind; criteria.tags.mobKind = kAAFMasterMob; check(pHeader->GetMobs(&criteria, &pMobIter)); while (AAFRESULT_SUCCESS == pMobIter->NextOne(&pMob)) { char mobIDstr[256]; char mobName[256]; aafWChar namebuf[1204]; IAAFTimelineMobSlot* pTimelineMobSlot = NULL; IAAFDataDef *pDataDef = NULL; IEnumAAFMobSlots* pMobSlotIter = NULL; 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); // Get the number of slots check(pMob->CountSlots(&numSlots)); // Iterating through all Mob Slots check(pMob->GetSlots(&pMobSlotIter)); while(AAFRESULT_SUCCESS == pMobSlotIter->NextOne(&pMobSlot)) { // Check to see if it is a Video Timeline Mob Slot HRESULT hr; hr = pMobSlot->QueryInterface(IID_IAAFTimelineMobSlot,(void **) &pTimelineMobSlot); if (FAILED(hr)) { pMobSlot->Release(); pMobSlot = NULL; continue; } check(pMobSlot->GetDataDef(&pDataDef)); // Check that we have a picture data def aafBool bIsPictureKind = kAAFFalse; check(pDataDef->IsPictureKind(&bIsPictureKind)); if (kAAFTrue != bIsPictureKind) { pTimelineMobSlot->Release(); pTimelineMobSlot = NULL; pDataDef->Release(); pDataDef = NULL; continue; // skip non-picture data defs } aafUInt32 MobSlotID; IAAFMasterMob* pMasterMob = NULL; // Prepare to get video data: first get MobSlotID check(pMobSlot->GetSlotID(&MobSlotID)); // Then get a Master Mob interface check(pMob->QueryInterface(IID_IAAFMasterMob, (void **)&pMasterMob)); printf(" Opening slot %d with %s\n", MobSlotID, comp_enable ? "CompressionEnable" : "CompressionDisable"); // Open the Essence Data check(pMasterMob->OpenEssence(MobSlotID, NULL, kAAFMediaOpenReadOnly, comp_enable ? kAAFCompressionEnable : kAAFCompressionDisable, &pEssenceAccess)); // First put the codec into YUV pixel format IAAFEssenceFormat* pSetFormat = NULL; aafInt32 YUV_pixel = kAAFColorSpaceYUV; check(pEssenceAccess->GetEmptyFileFormat(&pSetFormat)); check(pSetFormat->AddFormatSpecifier(kAAFPixelFormat, 4, (unsigned char *) &YUV_pixel)); check(pEssenceAccess->PutFileFormat(pSetFormat)); pSetFormat->Release(); // Get the information about the format of the video data. // The pFormat object must be setup with each specifier you // wish to access, otherwise you get AAFRESULT_FORMAT_NOT_FOUND. aafRational_t sampleRate; aafUInt32 maxSampleSize; aafRect_t storedRect; aafFrameLayout_t frameLayout; IAAFEssenceFormat *fmtTemplate = NULL; IAAFEssenceFormat* pFormat = NULL; check(pEssenceAccess->GetEmptyFileFormat (&fmtTemplate)); check(fmtTemplate->AddFormatSpecifier(kAAFSampleRate, 0, NULL)); check(fmtTemplate->AddFormatSpecifier(kAAFMaxSampleBytes, 0, NULL)); check(fmtTemplate->AddFormatSpecifier(kAAFStoredRect, 0, NULL)); check(fmtTemplate->AddFormatSpecifier(kAAFFrameLayout, 0, NULL)); check(pEssenceAccess->GetFileFormat(fmtTemplate, &pFormat)); fmtTemplate->Release(); fmtTemplate = NULL; aafInt32 fmtBytesRead; check(pFormat->GetFormatSpecifier(kAAFSampleRate, sizeof(sampleRate), (aafDataBuffer_t)&sampleRate, &fmtBytesRead)); check(pFormat->GetFormatSpecifier(kAAFMaxSampleBytes, sizeof(maxSampleSize), (aafDataBuffer_t)&maxSampleSize, &fmtBytesRead)); check(pFormat->GetFormatSpecifier(kAAFStoredRect, sizeof(storedRect), (aafDataBuffer_t)&storedRect, &fmtBytesRead)); check(pFormat->GetFormatSpecifier(kAAFFrameLayout, sizeof(frameLayout), (aafDataBuffer_t)&frameLayout, &fmtBytesRead)); pFormat->Release(); pFormat = NULL; // Get the sample count which is in terms of EditRate aafLength_t sampleCount; check(pEssenceAccess->CountSamples(pPictureDef, &sampleCount)); const char *frameLayoutStr = ""; switch (frameLayout) { case kAAFFullFrame: frameLayoutStr = "FullFrame"; break; case kAAFOneField: frameLayoutStr = "OneField"; break; case kAAFSeparateFields: frameLayoutStr = "SeparateFields"; break; case kAAFMixedFields: frameLayoutStr = "MixedFields"; break; default: break; } printf("\tSlotID %u: SampleRate=%d/%d MaxSampleBytes=%u StoredRect=%dx%d\n", MobSlotID, sampleRate.numerator, sampleRate.denominator, maxSampleSize, storedRect.xSize, storedRect.ySize); printf("\t\tFrameLayout=%s CountSamples=%"AAFFMT64"d\n", frameLayoutStr, sampleCount); // Buffer to receive samples from ReadSamples aafUInt8 *dataBuf = new aafUInt8[maxSampleSize]; // Buffer to recombine separated fields into interleaved fields aafUInt8 *recombined_buf = new aafUInt8[maxSampleSize]; // Read samples until no more are available aafUInt32 samplesRead, actualBytesRead, total_samples = 0; while (true) { hr = (pEssenceAccess->ReadSamples( 1, // number of samples to read maxSampleSize, // maximum buffer size dataBuf, // output buffer for audio data &samplesRead, // number of samples read &actualBytesRead)); // number of bytes read if (hr == AAFRESULT_EOF) break; else check(hr); aaf_assert(actualBytesRead != 0, "actualBytesRead != 0"); total_samples += samplesRead; aafUInt8* saveBuf = dataBuf; if (comp_enable && frameLayout == kAAFSeparateFields) { // recombine fields into uncompressed frame when decompressing recombine_fields(dataBuf, recombined_buf, storedRect.xSize, storedRect.ySize); saveBuf = recombined_buf; } // Write out video if ( fwrite(saveBuf, maxSampleSize, 1, output) != 1 ) { perror(output_file); return 1; } } printf("\tTotal samples=%u - written to %s\n", total_samples, output_file); delete [] dataBuf; delete [] recombined_buf; pEssenceAccess->Release(); pEssenceAccess = NULL; pMasterMob->Release(); pMasterMob = NULL; } pMobSlotIter->Release(); pMobSlotIter = NULL; pMob->Release(); pMob = NULL; } pMobIter->Release(); pMobIter = NULL; return moduleErrorTmp; }
static HRESULT ReadAAFFile(aafWChar* pFileName) { IAAFFile* pFile = NULL; bool bFileOpen = false; IAAFHeader* pHeader = NULL; IEnumAAFMobs* pMobIter = NULL; IAAFMob* pMob = NULL; IAAFMasterMob* pMasterMob = NULL; IEnumAAFMobSlots* pSlotIter = NULL; IAAFMobSlot* pSlot; aafNumSlots_t numMobs; aafSearchCrit_t criteria; IAAFSearchSource* pSearchSource = NULL; IAAFFindSourceInfo* pSourceInfo = NULL; IAAFMob* si_mob = NULL; //mob used by SourceInfo intf. 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)); // Validate that there is on one master mob in the test file. checkResult(pHeader->CountMobs(kAAFMasterMob, &numMobs)); checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED); // Enumerate over Master MOBs criteria.searchTag = kAAFByMobKind; criteria.tags.mobKind = kAAFMasterMob; checkResult(pHeader->GetMobs(&criteria, &pMobIter)); while (pMobIter && pMobIter->NextOne(&pMob) == AAFRESULT_SUCCESS) { aafWChar name[500]; aafNumSlots_t numSlots = 0; aafMobID_t mobID; // TODO: Test Master MOB specific methods here checkResult(pMob->QueryInterface(IID_IAAFMasterMob, (void **) &pMasterMob)); checkResult(pMob->GetName(name, sizeof(name))); checkExpression(wcscmp(name, MobName) == 0, AAFRESULT_TEST_FAILED); checkResult(pMob->GetMobID(&mobID)); checkExpression(0 == memcmp(&mobID, &TEST_Master_MobID, sizeof(mobID)), AAFRESULT_TEST_FAILED); checkResult(pMob->CountSlots(&numSlots)); checkExpression(NumMobSlots == numSlots, AAFRESULT_TEST_FAILED); //AAFRESULT STDMETHODCALLTYPE // ImplAAFMasterMob::GetTapeNameBufLen (0, // aafInt32* pLen) unsigned long s = 0; // Enumerate over all MOB slots for this MOB checkResult(pMob->GetSlots(&pSlotIter)); while (pSlotIter && pSlotIter->NextOne(&pSlot) == AAFRESULT_SUCCESS) { aafWChar slotName[500]; aafSlotID_t slotID; //aafUInt32 bufSize = 0; // Validate the slot name checkResult(pSlot->GetName(slotName, sizeof(slotName))); checkExpression(wcscmp(slotName, slotNames[s]) == 0, AAFRESULT_TEST_FAILED); // Validate the slot id. checkResult(pSlot->GetSlotID(&slotID)); checkExpression(slotID == s+1, AAFRESULT_TEST_FAILED); //Now, do a search source ............... //Get a search source intf. checkResult( pMasterMob->QueryInterface(IID_IAAFSearchSource, (void**)&pSearchSource) ); //From the searchsource inft, get a FindSourceINfo intf. checkResult ( pSearchSource->SearchSource( slotID, 0, kAAFTapeMob, NULL, //don't care about Media Criteria NULL, //don't care about operation choice &pSourceInfo)); //This is an important milestone! At this point, we were successful - about getting a pSourceInfo intf. // so, release the search source intf. if (pSearchSource) { pSearchSource->Release(); pSearchSource=NULL; } //NOw, simply test the methods on the (final) SourceInfo intf. aafRational_t si_editRate = {-1}; aafLength_t si_length = {-1}; aafSourceRef_t si_sourceRef = {{{0,0,0,0,0,0,0,0,0,0,0,0},0,0,0,0,{0,0,0,{0,0,0,0,0,0,0,0}}},0,0}; aafMobID_t si_MobID = {{0,0,0,0,0,0,0,0,0,0,0,0},0,0,0,0, {0,0,0,{0,0,0,0,0,0,0,0}}}; //Call the methods pSourceInfo->GetEditRate( &si_editRate); pSourceInfo->GetLength(&si_length); pSourceInfo->GetMob(&si_mob); pSourceInfo->GetSourceReference(&si_sourceRef); //Check the values returned by the methods //edit rate checkExpression(si_editRate.numerator == slotRates[s].numerator, AAFRESULT_TEST_FAILED); checkExpression(si_editRate.denominator == slotRates[s].denominator, AAFRESULT_TEST_FAILED); //Length checkExpression(si_length == TAPE_MOB_LENGTH_ARR[s], AAFRESULT_TEST_FAILED); //Mob checkExpression(si_mob!=NULL, AAFRESULT_TEST_FAILED); si_mob->GetMobID(&si_MobID); checkExpression(memcmp(&si_MobID, &tapeMobID, sizeof(aafMobID_t))==0, AAFRESULT_TEST_FAILED); //Source Reference checkExpression(si_sourceRef.sourceSlotID == s, AAFRESULT_TEST_FAILED); checkExpression(si_sourceRef.startTime == TAPE_MOB_OFFSET_ARR[s], AAFRESULT_TEST_FAILED); //Done with tests .. release the FindSourceInfo intf .. if (pSourceInfo) { pSourceInfo->Release(); pSourceInfo=NULL; } //Also don't forget to release the si_mob intf. if (si_mob) { si_mob->Release(); si_mob=NULL; } pSlot->Release(); pSlot = NULL; s++; } pSlotIter->Release(); pSlotIter = NULL; pMob->Release(); pMob = NULL; pMasterMob->Release(); pMasterMob = NULL; } } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pSearchSource) pSearchSource->Release(); if (pSourceInfo) pSourceInfo->Release(); if (si_mob) si_mob->Release(); if (pSlot) pSlot->Release(); if (pMasterMob) pMasterMob->Release(); if (pMob) pMob->Release(); if (pMobIter) pMobIter->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; IAAFMobSlot *newSlot = NULL; IAAFSegment *seg = NULL; IAAFSourceClip *sclp = NULL; IAAFComponent *pComp = NULL; HRESULT hr = S_OK; try { // Remove the previous test file if any. RemoveTestFile(pFileName); // Create the file. checkResult(CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile )); bFileOpen = true; // We can't really do anthing in AAF without the header. checkResult(pFile->GetHeader(&pHeader)); // Get the AAF Dictionary so that we can create valid AAF objects. checkResult(pHeader->GetDictionary(&pDictionary)); CAAFBuiltinDefs defs (pDictionary); //Make the first mob long test; // Create a concrete subclass of Mob checkResult(defs.cdMasterMob()-> CreateInstance(IID_IAAFMob, (IUnknown **)&pMob)); checkResult(pMob->SetMobID(TEST_MobID)); checkResult(pMob->SetName(L"MOBTest")); // Add some slots for(test = 0; test < 5; test++) { checkResult(defs.cdSourceClip()-> CreateInstance(IID_IAAFSourceClip, (IUnknown **)&sclp)); checkResult(sclp->QueryInterface (IID_IAAFComponent, (void **)&pComp)); checkResult(pComp->SetDataDef (defs.ddkAAFPicture())); pComp->Release(); pComp = NULL; checkResult(sclp->QueryInterface (IID_IAAFSegment, (void **)&seg)); // Create a concrete subclass of MobSlot checkResult(defs.cdStaticMobSlot()-> CreateInstance(IID_IAAFMobSlot, (IUnknown **)&newSlot)); checkResult(newSlot->SetSegment(seg)); checkResult(newSlot->SetSlotID(test+1)); checkResult(newSlot->SetPhysicalNum(test+2)); checkResult(newSlot->SetName(slotNames[test])); checkResult(pMob->AppendSlot (newSlot)); newSlot->Release(); newSlot = NULL; seg->Release(); seg = NULL; sclp->Release(); sclp = NULL; } // Add the mob to the file. checkResult(pHeader->AddMob(pMob)); } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (newSlot) newSlot->Release(); if (seg) seg->Release(); if (sclp) sclp->Release(); if (pComp) pComp->Release(); if (pMob) pMob->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pFile) { // Close file if (bFileOpen) { pFile->Save(); pFile->Close(); } pFile->Release(); } return hr; }
static HRESULT ReadAAFFile(aafWChar * pFileName) { // IAAFSession * pSession = NULL; IAAFFile * pFile = NULL; IAAFHeader * pHeader = NULL; IEnumAAFMobs *mobIter = NULL; IAAFMob *aMob = NULL; IAAFEssenceDescriptor *pEdesc = NULL; IAAFSourceMob *pSourceMob = NULL; IEnumAAFLocators * pEnum = NULL; IAAFLocator * pLocator = NULL; aafUInt32 numLocators; aafNumSlots_t numMobs, n; HRESULT hr = AAFRESULT_SUCCESS; bool bFileOpen = false; try { // Open the file checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); bFileOpen = true; // We can't really do anthing in AAF without the header. checkResult(pFile->GetHeader(&pHeader)); checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); checkExpression (1 == numMobs, AAFRESULT_TEST_FAILED); checkResult(pHeader->GetMobs (NULL, &mobIter)); for(n = 0; n < numMobs; n++) { aafWChar name[500]; aafMobID_t mobID; checkResult(mobIter->NextOne (&aMob)); checkResult(aMob->GetName (name, sizeof(name))); checkResult(aMob->GetMobID (&mobID)); checkResult(aMob->QueryInterface (IID_IAAFSourceMob, (void **)&pSourceMob)); checkResult(pSourceMob->GetEssenceDescriptor (&pEdesc)); // Verify that there is now one locator checkResult(pEdesc->CountLocators(&numLocators)); checkExpression(20 == numLocators, AAFRESULT_TEST_FAILED); checkResult(pEdesc->GetLocators(&pEnum)); // This should read the one real locator for ( n=0; n<numLocators; n++) { checkResult(pEnum->NextOne(&pLocator)); pLocator->Release(); pLocator = NULL; } // We had better not succeed or get an unknown failure. checkExpression(AAFRESULT_NO_MORE_OBJECTS == pEnum->NextOne(&pLocator), AAFRESULT_TEST_FAILED); pEnum->Release(); pEnum = NULL; pEdesc->Release(); pEdesc = NULL; pSourceMob->Release(); pSourceMob = NULL; aMob->Release(); aMob = NULL; } } catch (HRESULT& rResult) { hr = rResult; } // Cleanup object references if (pLocator) pLocator->Release(); if (pEnum) pEnum->Release(); if (pEdesc) pEdesc->Release(); if (pSourceMob) pSourceMob->Release(); if (aMob) aMob->Release(); if (mobIter) mobIter->Release(); if (pHeader) pHeader->Release(); if (pFile) { // Close file, clean-up and return if (bFileOpen) pFile->Close(); pFile->Release(); } /* hr = pSession->EndSession(); if (AAFRESULT_SUCCESS != hr) return hr; */ return hr; }
static HRESULT CreateAAFFile( aafWChar * pFileName, aafUID_constref fileKind, testRawStorageType_t rawStorageType, aafProductIdentification_constref productID) { IAAFFile* pFile = NULL; IAAFHeader * pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFDefObject* pDef = NULL; IAAFInterpolationDef* pInterpolationDef = NULL; bool bFileOpen = false; HRESULT hr = S_OK; /* 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.cdInterpolationDefinition()-> CreateInstance(IID_IAAFInterpolationDef, (IUnknown **)&pInterpolationDef)); checkResult(pInterpolationDef->QueryInterface (IID_IAAFDefObject, (void **)&pDef)); checkResult(pInterpolationDef->Initialize(InterpDef1, sName1, sDescription1)); checkResult(pDictionary->RegisterInterpolationDef(pInterpolationDef)); pDef->Release(); pDef = NULL; pInterpolationDef->Release(); pInterpolationDef = NULL; checkResult(defs.cdInterpolationDefinition()-> CreateInstance(IID_IAAFInterpolationDef, (IUnknown **)&pInterpolationDef)); checkResult(pInterpolationDef->QueryInterface (IID_IAAFDefObject, (void **)&pDef)); checkResult(pInterpolationDef->Initialize(InterpDef2, sName2, sDescription2)); checkResult(pDictionary->RegisterInterpolationDef(pInterpolationDef)); } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pDef) pDef->Release(); if (pInterpolationDef) pInterpolationDef->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pFile) { // Close file if (bFileOpen) { pFile->Save(); pFile->Close(); } pFile->Release(); } return hr; }
static HRESULT ReadAAFFile(aafWChar * pFileName) { IAAFFile *pFile = NULL; bool bFileOpen = false; IAAFHeader *pHeader = NULL; IEnumAAFMobs *mobIter = NULL; IAAFMob *aMob = NULL; IEnumAAFMobSlots *slotIter = NULL; IAAFMobSlot *slot = NULL; IAAFSegment *pSeg = NULL; IAAFSourceClip *pSourceClip = NULL; IAAFDataDef * pDataDef = 0; IAAFDefObject * pDefObj = 0; aafNumSlots_t numMobs, n; aafSlotID_t s; aafUInt32 length; HRESULT hr = S_OK; aafUID_t readUID, typeUID = kAAFDataDef_Picture; try { // Open the file checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); bFileOpen = true; // We can't really do anthing in AAF without the header. checkResult(pFile->GetHeader(&pHeader)); checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED); aafSearchCrit_t criteria; criteria.searchTag = kAAFNoSearch; checkResult(pHeader->GetMobs (&criteria, &mobIter)); for(n = 0; n < numMobs; n++) { aafWChar name[500], slotName[500]; aafNumSlots_t numSlots; aafMobID_t mobID; aafSlotID_t trackID; checkResult(mobIter->NextOne (&aMob)); checkResult(aMob->GetName (name, sizeof(name))); checkResult(aMob->GetMobID (&mobID)); checkResult(aMob->CountSlots (&numSlots)); checkExpression(5 == numSlots, AAFRESULT_TEST_FAILED); checkResult(aMob->GetSlots(&slotIter)); for(s = 0; s < (aafSlotID_t)numSlots; s++) { checkResult(slotIter->NextOne (&slot)); checkResult(slot->GetNameBufLen(&length)); checkResult(slot->GetName (slotName, length)); checkExpression (wcscmp(slotName, slotNames[s]) == 0, AAFRESULT_TEST_FAILED); checkResult(slot->GetSlotID(&trackID)); checkExpression (trackID == s+1, AAFRESULT_TEST_FAILED); checkResult(slot->GetPhysicalNum(&trackID)); checkExpression (trackID == s+2, AAFRESULT_TEST_FAILED); checkResult(slot->GetPhysicalNum(&trackID)); checkResult(slot->GetDataDef(&pDataDef)); checkResult(pDataDef->QueryInterface (IID_IAAFDefObject, (void **)&pDefObj)); checkResult(pDefObj->GetAUID(&readUID)); checkExpression (memcmp(&typeUID, &readUID, sizeof(typeUID)) == 0, AAFRESULT_TEST_FAILED); checkResult(slot->GetSegment(&pSeg)); checkResult(pSeg->QueryInterface (IID_IAAFSourceClip, (void **)&pSourceClip)); pDataDef->Release(); pDataDef = 0; pDefObj->Release (); pDefObj = 0; pSourceClip->Release(); pSourceClip = NULL; pSeg->Release(); pSeg = NULL; slot->Release(); slot = NULL; } aMob->Release(); aMob = NULL; } } catch (HRESULT& rResult) { hr = rResult; } // Cleanup object references if (slot) { slot->Release(); slot = 0; } if (pSeg) { pSeg->Release(); pSeg = 0; } if (pSourceClip) { pSourceClip->Release(); pSourceClip = 0; } if (slotIter) { slotIter->Release(); slotIter = 0; } if (aMob) { aMob->Release(); aMob = 0; } if (mobIter) { mobIter->Release(); mobIter = 0; } if (pHeader) { pHeader->Release(); pHeader = 0; } if (pDataDef) { pDataDef->Release(); pDataDef = 0; } if (pDefObj) { pDefObj->Release (); pDefObj = 0; } if (pFile) { // Close file if (bFileOpen) pFile->Close(); pFile->Release(); pFile = 0; } return hr; }
static HRESULT CreateAAFFile( aafWChar * pFileName, aafUID_constref fileKind, testRawStorageType_t rawStorageType, aafProductIdentification_constref productID) { HRESULT hr = AAFRESULT_SUCCESS; IAAFFile* pFile = NULL; IAAFHeader * pHeader = NULL; IAAFDictionary * pDict = NULL; try { //Do the usual ... RemoveTestFile (pFileName); checkResult (CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile )); assert (pFile); checkResult (pFile->GetHeader (&pHeader)); assert (pHeader); checkResult (pHeader->GetDictionary (&pDict)); assert (pDict); CAAFBuiltinDefs defs (pDict); /////////////////////// //checkResult(createCHARType (pDict)); checkResult(addCHARTypeToComponent (pDict)); /////////// //Create a concrete subclass of mob IAAFMobSP spMob; checkResult(defs.cdMasterMob()-> CreateInstance(IID_IAAFMob, (IUnknown **)&spMob)); checkResult(spMob->SetMobID(TEST_MobID)); checkResult(spMob->SetName(L"Some Mob")); //Add a slot - make it our Filler /// first, create Filler IAAFFillerSP spFill; checkResult(defs.cdFiller()->CreateInstance(IID_IAAFFiller, (IUnknown**)&spFill)); checkResult(spFill->Initialize(defs.ddkAAFSound(), 10)); checkResult(createCHARFiller(pDict, spFill)); //seg //QI the filler for its segment IAAFSegmentSP spSeg; checkResult(spFill->QueryInterface (IID_IAAFSegment, (void **)&spSeg)); //Create a concrete subclass of mob slot IAAFMobSlotSP spMobSlot; checkResult(defs.cdStaticMobSlot()-> CreateInstance(IID_IAAFMobSlot, (IUnknown **)&spMobSlot)); //Add the segment to the mobslot checkResult(spMobSlot->SetSegment(spSeg)); checkResult(spMobSlot->SetSlotID(TEST_SLOT_ID)); checkResult(spMobSlot->SetName(TEST_SLOT_NAME)); //Append the slot to the Mob .... checkResult(spMob->AppendSlot (spMobSlot)); //FINALLY .... Add mob to header checkResult (pHeader->AddMob (spMob)); //////////////////// done /!!!!!!!!!!!!!!!!!!!!!! //Verify results right away (during this creation process) .... checkResult(verifyContents (pHeader, pDict, kAAFTrue)); //True => minimal testing } catch (HRESULT & rResult) { hr = rResult; } if (pDict) pDict->Release(); if (pHeader) pHeader->Release(); if (pFile) { stopGap(pFile->Save()); stopGap(pFile->Close()); pFile->Release(); } return hr; }//CreateAAFFile()
static HRESULT ReadAAFFile(aafWChar * pFileName) { IAAFDictionary *pDictionary = NULL; IAAFFile *pFile = NULL; bool bFileOpen = false; IAAFHeader *pHeader = NULL; IEnumAAFMobs *mobIter = NULL; IAAFMob *aMob = NULL; IEnumAAFMobSlots *slotIter = NULL; IAAFMobSlot *slot = NULL; aafNumSlots_t numMobs, n, s; HRESULT hr = S_OK; aafUInt32 bufLen = 0; aafUInt32 bytesRead = 0; aafUInt32 numFound = 0; aafWChar value[500]; IEnumAAFTaggedValues *enumTaggedVal = NULL; IAAFTaggedValue *taggedVal = NULL; aafUID_t testKey; IEnumAAFKLVData *klvEnum = NULL; IAAFKLVData *pKLVData = NULL; IAAFTypeDef* pBaseType = NULL; IAAFSourceClip *pSourceClip = NULL; IAAFSourceReference *pSourceRef = NULL; IAAFSegment *pSegment = NULL; aafMobID_t sourceID; int i; try { // Open the file checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); bFileOpen = true; // We can't really do anthing in AAF without the header. checkResult(pFile->GetHeader(&pHeader)); checkResult(pHeader->GetDictionary(&pDictionary)); CAAFBuiltinDefs defs (pDictionary); checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED); aafSearchCrit_t criteria; criteria.searchTag = kAAFNoSearch; checkResult(pHeader->GetMobs (&criteria, &mobIter)); for(n = 0; n < numMobs; n++) { aafWChar name[500], slotName[500]; aafNumSlots_t numSlots; aafMobID_t mobID; aafSlotID_t trackID; aafUInt32 nameBufLen = 0; checkResult(mobIter->NextOne (&aMob)); // Check GetNameBufLen and GetName checkExpression(aMob->GetNameBufLen(NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkResult(aMob->GetNameBufLen(&nameBufLen)); checkExpression(((wcslen(mobName) + 1) * sizeof(aafCharacter)) == nameBufLen, AAFRESULT_TEST_FAILED); checkExpression(aMob->GetName (NULL, nameBufLen) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkExpression(aMob->GetName (name, 4) == AAFRESULT_SMALLBUF, AAFRESULT_TEST_FAILED); checkResult(aMob->GetName (name, nameBufLen)); checkExpression (wcscmp(mobName, name) == 0, AAFRESULT_TEST_FAILED); // Check GetMobID checkExpression(aMob->GetMobID (NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkResult(aMob->GetMobID (&mobID)); checkExpression(memcmp(&MOBTestID, &mobID, sizeof(mobID)) == 0, AAFRESULT_TEST_FAILED); // Check the time stamps aafTimeStamp_t created = { {0,0,0}, {0,0,0,0} }; checkExpression(aMob->GetCreateTime(NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkResult(aMob->GetCreateTime(&created)); checkTimeStampsAreEqual(creationTimeStamp, created); aafTimeStamp_t modified = { {0,0,0}, {0,0,0,0} }; checkExpression(aMob->GetModTime(NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkResult(aMob->GetModTime(&modified)); checkTimeStampsAreEqual(modificationTimeStamp, modified); // Check the GetMobInfo data. memset(&created, 0, sizeof(created)); memset(&modified, 0, sizeof(modified)); checkExpression(aMob->GetMobInfo(NULL, &created, name, sizeof(name)) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkExpression(aMob->GetMobInfo(&modified, NULL, name, sizeof(name)) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkExpression(aMob->GetMobInfo(&modified, &created, NULL, sizeof(name)) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkExpression(aMob->GetMobInfo(&modified, &created, name, 1) == AAFRESULT_SMALLBUF, AAFRESULT_TEST_FAILED); checkResult(aMob->GetMobInfo(&modified, &created, name, sizeof(name))); checkTimeStampsAreEqual(creationTimeStamp, created); checkTimeStampsAreEqual(modificationTimeStamp, modified); checkExpression (wcscmp(mobName, name) == 0, AAFRESULT_TEST_FAILED); checkExpression(aMob->CountSlots (NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkResult(aMob->CountSlots (&numSlots)); //seven slots made by IAAFMob and one static slot and event slot made throught IAAFMOb2 checkExpression((7+1+1) == numSlots, AAFRESULT_TEST_FAILED); checkExpression(aMob->GetSlots(NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkResult(aMob->GetSlots(&slotIter)); for(s = 0; s < numSlots; s++) { checkResult(slotIter->NextOne (&slot)); checkResult(slot->GetNameBufLen(&bufLen)); checkResult(slot->GetName (slotName, bufLen)); checkResult(slot->GetSlotID(&trackID)); checkExpression (wcscmp(slotName, slotNames[s]) == 0, AAFRESULT_TEST_FAILED); checkExpression(trackID == (s+1), AAFRESULT_TEST_FAILED); slot->Release(); slot = NULL; bufLen = 0; trackID = 0; } slotIter->Release(); slotIter = NULL; // GetSlotAt checkExpression(aMob->GetSlotAt(1, NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkExpression(aMob->GetSlotAt(9, &slot) == AAFRESULT_BADINDEX, AAFRESULT_TEST_FAILED); for (s = 0; s < numSlots; ++s) { checkResult(aMob->GetSlotAt(s, &slot)); checkResult(slot->GetNameBufLen(&bufLen)); checkResult(slot->GetName(slotName, bufLen)); checkResult(slot->GetSlotID(&trackID)); checkExpression(wcscmp(slotName, slotNames[s]) == 0, AAFRESULT_TEST_FAILED); checkExpression(trackID == (s+1), AAFRESULT_TEST_FAILED); if ( 0 < s && s < 5 ) // These are the SourceClips { checkResult(slot->GetSegment(&pSegment)); checkResult(pSegment->QueryInterface (IID_IAAFSourceClip, (void **)&pSourceClip)); checkResult(pSourceClip->QueryInterface (IID_IAAFSourceReference, (void **)&pSourceRef)); checkResult(pSourceRef->GetSourceID(&sourceID)); checkExpression(memcmp(&sourceID, &MOBTestID3, sizeof(aafMobID_t)) == 0, AAFRESULT_TEST_FAILED); pSourceRef->Release(); pSourceRef = NULL; pSourceClip->Release(); pSourceClip = NULL; pSegment->Release(); pSegment = NULL; } slot->Release(); slot = NULL; bufLen = 0; trackID = 0; } // ChangeRef checkResult(aMob->ChangeRef(MOBTestID3, MOBTestID4)); for (s = 1; s < 5; ++s) // These are the SourceClips { checkResult(aMob->GetSlotAt(s, &slot)); checkResult(slot->GetSegment(&pSegment)); checkResult(pSegment->QueryInterface (IID_IAAFSourceClip, (void **)&pSourceClip)); checkResult(pSourceClip->QueryInterface (IID_IAAFSourceReference, (void **)&pSourceRef)); checkResult(pSourceRef->GetSourceID(&sourceID)); checkExpression(memcmp(&sourceID, &MOBTestID4, sizeof(aafMobID_t)) == 0, AAFRESULT_TEST_FAILED); pSourceRef->Release(); pSourceRef = NULL; pSourceClip->Release(); pSourceClip = NULL; pSegment->Release(); pSegment = NULL; slot->Release(); slot = NULL; } // try it again with a MobID it won't find. Make sure nothing changes checkResult(aMob->ChangeRef(MOBTestID3, MOBTestID2)); for (s = 1; s < 5; ++s) // These are the SourceClips { checkResult(aMob->GetSlotAt(s, &slot)); checkResult(slot->GetSegment(&pSegment)); checkResult(pSegment->QueryInterface (IID_IAAFSourceClip, (void **)&pSourceClip)); checkResult(pSourceClip->QueryInterface (IID_IAAFSourceReference, (void **)&pSourceRef)); checkResult(pSourceRef->GetSourceID(&sourceID)); checkExpression(memcmp(&sourceID, &MOBTestID4, sizeof(aafMobID_t)) == 0, AAFRESULT_TEST_FAILED); pSourceRef->Release(); pSourceRef = NULL; pSourceClip->Release(); pSourceClip = NULL; pSegment->Release(); pSegment = NULL; slot->Release(); slot = NULL; } // LookUpSlot checkResult(aMob->LookupSlot(4, &slot)); checkResult(slot->GetSegment(&pSegment)); checkResult(pSegment->QueryInterface (IID_IAAFSourceClip, (void **)&pSourceClip)); checkResult(pSourceClip->QueryInterface (IID_IAAFSourceReference, (void **)&pSourceRef)); checkResult(pSourceRef->GetSourceID(&sourceID)); checkResult(slot->GetNameBufLen(&bufLen)); checkResult(slot->GetName(slotName, bufLen)); checkResult(slot->GetSlotID(&trackID)); checkExpression(wcscmp(slotName, slotNames[3]) == 0, AAFRESULT_TEST_FAILED); checkExpression(trackID == (4), AAFRESULT_TEST_FAILED); pSourceRef->Release(); pSourceRef = NULL; pSourceClip->Release(); pSourceClip = NULL; pSegment->Release(); pSegment = NULL; slot->Release(); slot = NULL; checkExpression(aMob->LookupSlot(10, &slot) == AAFRESULT_SLOT_NOT_FOUND, AAFRESULT_TEST_FAILED); checkExpression(aMob->LookupSlot(0, NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); // OffsetToMobTimecode // 7/5/00 - this method is broken so the tests that will // make it fail have been commented out. This module test // will still report Partial Success until implementation has been fixed aafPosition_t offset = 1; aafTimecode_t timecode; // initialize timecode values timecode.startFrame = 0; timecode.drop = kAAFTcDrop; timecode.fps = 24; checkResult(aMob->LookupSlot(6, &slot)); checkResult(slot->GetSegment(&pSegment)); checkResult(aMob->OffsetToMobTimecode(pSegment, &offset, &timecode)); checkExpression(timecode.startFrame == (TCstartFrame + offset), AAFRESULT_TEST_FAILED); checkExpression(timecode.drop == TCdrop, AAFRESULT_TEST_FAILED); checkExpression(timecode.fps == TCfps, AAFRESULT_TEST_FAILED); checkExpression(aMob->OffsetToMobTimecode(pSegment, NULL, &timecode) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); checkExpression(aMob->OffsetToMobTimecode(pSegment, &offset, NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); // reinitialize values timecode.startFrame = 0; timecode.drop = kAAFTcDrop; timecode.fps = 24; // According to IDL this should search for the slot containing the timecode segment checkResult(aMob->OffsetToMobTimecode(NULL, &offset, &timecode)); checkExpression(timecode.startFrame == (TCstartFrame + offset), AAFRESULT_TEST_FAILED); checkExpression(timecode.drop == TCdrop, AAFRESULT_TEST_FAILED); checkExpression(timecode.fps == TCfps, AAFRESULT_TEST_FAILED); pSegment->Release(); pSegment = NULL; slot->Release(); slot = NULL; // Pass in a segment that is not a timecode and make sure it returns correct hr checkResult(aMob->LookupSlot(1, &slot)); checkResult(slot->GetSegment(&pSegment)); checkExpression(aMob->OffsetToMobTimecode(pSegment, &offset, &timecode) == AAFRESULT_TIMECODE_NOT_FOUND, AAFRESULT_TEST_FAILED); pSegment->Release(); pSegment = NULL; slot->Release(); slot = NULL; // GetKLVData checkResult(pDictionary->LookupTypeDef (kAAFTypeID_UInt8Array, &pBaseType)); checkResult(pDictionary->RegisterKLVDataKey(TEST_KLV, pBaseType)); pBaseType->Release(); pBaseType = NULL; checkResult(aMob->CountKLVData(&numFound)); checkExpression(numFound == 2, AAFRESULT_TEST_FAILED); checkResult(aMob->GetKLVData(&klvEnum)); checkResult(klvEnum->NextOne(&pKLVData)); checkResult(pKLVData->GetValueBufLen(&bufLen)); checkExpression(sizeof(KLVfrowney) == bufLen, AAFRESULT_TEST_FAILED); checkResult(pKLVData->GetValue( sizeof(value), (unsigned char *)value, &bytesRead)); checkExpression(memcmp(value, KLVfrowney, sizeof(KLVfrowney)) == 0, AAFRESULT_TEST_FAILED); checkResult(pKLVData->GetKey(&testKey)); checkExpression(memcmp(&testKey, &TEST_KLV, sizeof(aafUID_t)) == 0, AAFRESULT_TEST_FAILED); pKLVData->Release(); pKLVData = NULL; checkResult(klvEnum->NextOne(&pKLVData)); checkResult(pKLVData->GetValueBufLen(&bufLen)); checkExpression(sizeof(KLVsmiley) == bufLen, AAFRESULT_TEST_FAILED); checkResult(pKLVData->GetValue( sizeof(value), (unsigned char *)value, &bytesRead)); checkExpression(memcmp(value, KLVsmiley, sizeof(KLVsmiley)) == 0, AAFRESULT_TEST_FAILED); checkResult(pKLVData->GetKey(&testKey)); checkExpression(memcmp(&testKey, &TEST_KLV, sizeof(aafUID_t)) == 0, AAFRESULT_TEST_FAILED); pKLVData->Release(); pKLVData = NULL; klvEnum->Release(); klvEnum = NULL; checkExpression(aMob->GetKLVData(NULL) == AAFRESULT_NULL_PARAM, AAFRESULT_TEST_FAILED); // Check the comments checkResult(aMob->GetComments(&enumTaggedVal)); 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; } // Check attributes and usage code. // Need IAAFMob2 for that; IAAFMob2* aMobInterface2 = 0; checkResult( aMob->QueryInterface( IID_IAAFMob2, reinterpret_cast<void**>(&aMobInterface2) ) ); IEnumAAFTaggedValues* pAttributesEnum = 0; checkResult( aMobInterface2->GetAttributes( &pAttributesEnum ) ); int attributeCount = 0; HRESULT atthr = AAFRESULT_SUCCESS; IAAFTaggedValue* pAttribute = 0; for( atthr = pAttributesEnum->NextOne( &pAttribute ); atthr == AAFRESULT_SUCCESS; atthr = pAttributesEnum->NextOne( &pAttribute ) ) { aafUInt32 bufLen = 0; checkResult( pAttribute->GetNameBufLen(&bufLen) ); // "name" is 500 chars long... sized more than // large enough for a simple test. checkExpression( attributeCount < 2, AAFRESULT_TEST_FAILED ); checkResult( pAttribute->GetName( name, bufLen ) ); checkExpression( wcscmp(name, AttributeNames[attributeCount] ) == 0, AAFRESULT_TEST_FAILED ); // check the value IAAFTypeDef* pAttributeTypeDef = NULL; checkResult( pAttribute->GetTypeDefinition( &pAttributeTypeDef ) ); // It should be a string. IAAFTypeDefString* pTDString = NULL; checkResult( pAttributeTypeDef->QueryInterface( IID_IAAFTypeDefString, reinterpret_cast<void**>(&pTDString) ) ); checkResult( pAttribute->GetValue( sizeof(name), reinterpret_cast<aafDataBuffer_t>(name), &bufLen ) ); checkExpression( wcscmp( AttributeValues[attributeCount], name ) == 0, AAFRESULT_TEST_FAILED ); pAttributeTypeDef->Release(); pAttributeTypeDef = NULL; pTDString->Release(); pTDString = NULL; pAttribute->Release(); pAttribute = NULL; attributeCount++; } checkExpression( 2 == attributeCount && atthr == AAFRESULT_NO_MORE_OBJECTS, AAFRESULT_TEST_FAILED ); aafUID_t code; checkResult( aMobInterface2->GetUsageCode( &code ) ); checkExpression( memcmp( &code, &kAAFUsage_SubClip, sizeof(code) ) == 0, AAFRESULT_TEST_FAILED ); pAttributesEnum->Release(); pAttributesEnum = NULL; enumTaggedVal->Release(); enumTaggedVal = NULL; aMobInterface2->Release(); aMobInterface2 = NULL; aMob->Release(); aMob = NULL; } } catch (HRESULT& rResult) { hr = rResult; } // Cleanup object references if (slot) slot->Release(); if (slotIter) slotIter->Release(); if (aMob) aMob->Release(); if (mobIter) mobIter->Release(); if (pHeader) pHeader->Release(); if (pDictionary) pDictionary->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; }
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 HRESULT CreateAAFFile( aafWChar * pFileName, aafUID_constref fileKind, testRawStorageType_t rawStorageType, aafProductIdentification_constref productID) { // IAAFSession *pSession = NULL; IAAFFile *pFile = NULL; IAAFHeader *pHeader = NULL; IAAFDictionary *pDictionary = NULL; IAAFLocator *pLocator = NULL; IAAFLocator *pLocator2 = NULL; IAAFSourceMob *pSourceMob = NULL; IAAFMob *pMob = NULL; IAAFEssenceDescriptor *edesc = NULL; IEnumAAFLocators *pEnumLocators = NULL; aafUInt32 numLocators, numLocators2; aafUInt32 i; HRESULT hr = AAFRESULT_SUCCESS, localhr = AAFRESULT_SUCCESS; bool bFileOpen = false; // aafUID_t ddef = kAAFDataDef_Sound; try { // Remove the previous test file if any. RemoveTestFile(pFileName); // Create the file. checkResult(CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile )); bFileOpen = true; // We can't really do anthing in AAF without the header. checkResult(pFile->GetHeader(&pHeader)); // Get the AAF Dictionary so that we can create valid AAF objects. checkResult(pHeader->GetDictionary(&pDictionary)); CAAFBuiltinDefs defs (pDictionary); //Make the first mob // Create a Mob checkResult(defs.cdSourceMob()-> CreateInstance(IID_IAAFSourceMob, (IUnknown **)&pSourceMob)); // Initialize mob properties: checkResult(pSourceMob->QueryInterface (IID_IAAFMob, (void **)&pMob)); checkResult(pMob->SetMobID(TEST_MobID)); checkResult(pMob->SetName(L"EssenceDescriptorTest")); // Create the descriptor: // instantiate a concrete subclass of EssenceDescriptor checkResult(defs.cdAIFCDescriptor()-> CreateInstance(IID_IAAFEssenceDescriptor, (IUnknown **)&edesc)); IAAFAIFCDescriptor* pAIFCDesc = NULL; checkResult(edesc->QueryInterface (IID_IAAFAIFCDescriptor, (void **)&pAIFCDesc)); checkResult(pAIFCDesc->SetSummary (5, (unsigned char*)"TEST")); pAIFCDesc->Release(); pAIFCDesc = NULL; checkResult(pSourceMob->SetEssenceDescriptor (edesc)); /* CountLocators() ******************************************/ localhr = AAFRESULT_SUCCESS; // Verify AAFRESULT_NULL_PARAM is returned if (edesc->CountLocators(NULL) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; // Verify that there are no locators if (edesc->CountLocators(&numLocators) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; if (0 != numLocators) localhr = AAFRESULT_TEST_FAILED; if (localhr == AAFRESULT_SUCCESS) cout<< " CountLocators() ... Passed"<< endl; else { cout<< " CountLocators() ... FAILED"<< endl; hr = AAFRESULT_TEST_FAILED; } /* AppendLocator() ******************************************/ localhr = AAFRESULT_SUCCESS; // Verify AAFRESULT_NULL_PARAM is returned if (edesc->AppendLocator(NULL) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; // Append and Count a bunch of Locators for (i=1; i<=10; i++) { // Make a concrete subclass of locator, and attach it to // the EssenceDescriptor checkResult(defs.cdNetworkLocator()-> CreateInstance(IID_IAAFLocator, (IUnknown **)&pLocator)); if (edesc->AppendLocator(pLocator) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; // Verify the number of locators numLocators = 0; edesc->CountLocators(&numLocators); if (i != numLocators) localhr = AAFRESULT_TEST_FAILED; // Verify that locator was appended edesc->GetLocatorAt(i-1, &pLocator2); if (pLocator2 != pLocator) localhr = AAFRESULT_TEST_FAILED; pLocator->Release(); pLocator = 0; pLocator2->Release(); pLocator2 = 0; } // Make sure we can't add it again // if (edesc->AppendLocator(pLocator) != AAFRESULT_OBJECT_ALREADY_ATTACHED) // localhr = AAFRESULT_TEST_FAILED; if (localhr == AAFRESULT_SUCCESS) cout<< " AppendLocator() ... Passed"<< endl; else { cout<< " AppendLocator() ... FAILED"<< endl; hr = AAFRESULT_TEST_FAILED; } /* PrependLocator() ******************************************/ localhr = AAFRESULT_SUCCESS; // Verify AAFRESULT_NULL_PARAM is returned if (edesc->PrependLocator(NULL) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; for (; i<=20; i++) { // Make a concrete subclass of locator, and attach it to // the EssenceDescriptor checkResult(defs.cdNetworkLocator()-> CreateInstance(IID_IAAFLocator, (IUnknown **)&pLocator)); if (edesc->PrependLocator(pLocator) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; // Verify the number of locators numLocators = 0; edesc->CountLocators(&numLocators); if (i != numLocators) localhr = AAFRESULT_TEST_FAILED; // Verify that locator was prepended edesc->GetLocatorAt(0, &pLocator2); if (pLocator2 != pLocator) localhr = AAFRESULT_TEST_FAILED; pLocator->Release(); pLocator = 0; pLocator2->Release(); pLocator2 = 0; } if (localhr == AAFRESULT_SUCCESS) cout<< " PrependLocator() ... Passed"<< endl; else { cout<< " PrependLocator() ... FAILED"<< endl; hr = AAFRESULT_TEST_FAILED; } /* InsertLocatorAt() **************************************/ localhr = AAFRESULT_SUCCESS; // Make a concrete subclass of locator to attach checkResult(defs.cdNetworkLocator()-> CreateInstance(IID_IAAFLocator, (IUnknown **)&pLocator)); // Verify that we can't remove an index value that is out of range if (edesc->InsertLocatorAt(numLocators+1, pLocator) != AAFRESULT_BADINDEX) localhr = AAFRESULT_TEST_FAILED; // Verify behavior when NULL is passed in if (edesc->InsertLocatorAt(1, NULL) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; edesc->CountLocators(&numLocators); // Insert it if (edesc->InsertLocatorAt(0, pLocator) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; // Check it edesc->GetLocatorAt(0, &pLocator2); if (pLocator2 != pLocator) localhr = AAFRESULT_TEST_FAILED; // Count it edesc->CountLocators(&numLocators2); if (numLocators2 != numLocators+1) localhr = AAFRESULT_TEST_FAILED; pLocator->Release(); pLocator = 0; pLocator2->Release(); pLocator2 = 0; edesc->CountLocators(&numLocators); // Make a concrete subclass of locator to attach in the middle checkResult(defs.cdNetworkLocator()-> CreateInstance(IID_IAAFLocator, (IUnknown **)&pLocator)); // Insert it if (edesc->InsertLocatorAt(numLocators/2, pLocator) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; // Check it edesc->GetLocatorAt(numLocators/2, &pLocator2); if (pLocator2 != pLocator) localhr = AAFRESULT_TEST_FAILED; // Count it edesc->CountLocators(&numLocators2); if (numLocators2 != numLocators+1) localhr = AAFRESULT_TEST_FAILED; pLocator->Release(); pLocator = 0; pLocator2->Release(); pLocator2 = 0; edesc->CountLocators(&numLocators); // Make a concrete subclass of locator to attach to the end checkResult(defs.cdNetworkLocator()-> CreateInstance(IID_IAAFLocator, (IUnknown **)&pLocator)); // Insert it. note: its 0 based so the end is numLocators - 1 if (edesc->InsertLocatorAt(numLocators-1, pLocator) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; // Check it edesc->GetLocatorAt(numLocators-1, &pLocator2); if (pLocator2 != pLocator) localhr = AAFRESULT_TEST_FAILED; // Count it edesc->CountLocators(&numLocators2); if (numLocators2 != numLocators+1) localhr = AAFRESULT_TEST_FAILED; // Make sure we can't add it again if (edesc->InsertLocatorAt(numLocators+1, pLocator) != AAFRESULT_OBJECT_ALREADY_ATTACHED) localhr = AAFRESULT_TEST_FAILED; pLocator->Release(); pLocator = 0; pLocator2->Release(); pLocator2 = 0; if (localhr == AAFRESULT_SUCCESS) cout<< " InsertLocatorAt() ... Passed"<< endl; else { cout<< " InsertLocatorAt() ... FAILED"<< endl; hr = AAFRESULT_TEST_FAILED; } /* GetLocatorAt() ******************************************/ localhr = AAFRESULT_SUCCESS; edesc->CountLocators(&numLocators); // Verify that we can't remove an index value that is out of range // note: Locators index is 0 based so the index numLocators is out of range if (edesc->GetLocatorAt(numLocators, &pLocator) != AAFRESULT_BADINDEX) localhr = AAFRESULT_TEST_FAILED; // Verify behavior when NULL is passed in if (edesc->GetLocatorAt(1, NULL) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; for (i=0; i<numLocators; i++) { pLocator = NULL; if (edesc->GetLocatorAt(i, &pLocator) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; if (pLocator != NULL) pLocator->Release(); } if (localhr == AAFRESULT_SUCCESS) cout<< " GetLocatorAt() ... Passed"<< endl; else { cout<< " GetLocatorAt() ... FAILED"<< endl; hr = AAFRESULT_TEST_FAILED; } /* GetLocators() ******************************************/ if (edesc->GetLocators(NULL) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; pEnumLocators = NULL; if (edesc->GetLocators(&pEnumLocators) == AAFRESULT_SUCCESS) { if (pEnumLocators != NULL) { // Try a simple test to confirm if (pEnumLocators->NextOne(&pLocator) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; edesc->GetLocatorAt(0, &pLocator2); if (pLocator != pLocator2) localhr = AAFRESULT_TEST_FAILED; else pLocator2->Release(); pLocator->Release(); pLocator = 0; pEnumLocators->Release(); } else localhr = AAFRESULT_TEST_FAILED; } else localhr = AAFRESULT_TEST_FAILED; if (localhr == AAFRESULT_SUCCESS) cout<< " GetLocators() ... Passed"<< endl; else { cout<< " GetLocators() ... FAILED"<< endl; hr = AAFRESULT_TEST_FAILED; } /* RemoveLocatorAt() ******************************************/ localhr = AAFRESULT_SUCCESS; // Verify that we can't remove an index value that is out of range // note: Locators index is 0 based so the index numLocators is out of range if (edesc->RemoveLocatorAt (numLocators) != AAFRESULT_BADINDEX) localhr = AAFRESULT_TEST_FAILED; // Remove locator at beginning, but Release it first edesc->CountLocators(&numLocators); edesc->GetLocatorAt(0, &pLocator); pLocator->Release(); edesc->GetLocatorAt(1, &pLocator); if (edesc->RemoveLocatorAt (0) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; // Verify the count edesc->CountLocators(&numLocators2); if (numLocators2 != (numLocators - 1)) localhr = AAFRESULT_TEST_FAILED; edesc->GetLocatorAt(0, &pLocator2); // Verify that the locators shifted properly if (pLocator != pLocator2) localhr = AAFRESULT_TEST_FAILED; pLocator->Release(); pLocator = 0; pLocator2->Release(); pLocator2 = 0; // Remove locator in middle, but Release it first edesc->CountLocators(&numLocators); edesc->GetLocatorAt((numLocators/2), &pLocator); pLocator->Release(); edesc->GetLocatorAt((numLocators/2 +1), &pLocator); if (edesc->RemoveLocatorAt (numLocators/2) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; edesc->CountLocators(&numLocators2); if (numLocators2 != (numLocators - 1)) localhr = AAFRESULT_TEST_FAILED; edesc->GetLocatorAt(numLocators/2, &pLocator2); // Verify that the locators shifted properly if (pLocator != pLocator2) localhr = AAFRESULT_TEST_FAILED; pLocator->Release(); pLocator = 0; pLocator2->Release(); pLocator2 = 0; // Remove locator at end, but Release it first edesc->CountLocators(&numLocators); edesc->GetLocatorAt(numLocators-1, &pLocator); pLocator->Release(); edesc->GetLocatorAt(numLocators-2, &pLocator); if (edesc->RemoveLocatorAt (numLocators-1) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; edesc->CountLocators(&numLocators2); if (numLocators2 != (numLocators - 1)) localhr = AAFRESULT_TEST_FAILED; edesc->GetLocatorAt(numLocators2-1, &pLocator2); // Verify that the locators shifted properly if (pLocator != pLocator2) localhr = AAFRESULT_TEST_FAILED; pLocator->Release(); pLocator = 0; pLocator2->Release(); pLocator2 = 0; if (localhr == AAFRESULT_SUCCESS) cout<< " RemoveLocatorAt() ... Passed"<< endl; else { cout<< " RemoveLocatorAt() ... FAILED"<< endl; hr = AAFRESULT_TEST_FAILED; } /*************************************************************/ // Add the source mob into the tree checkResult(pHeader->AddMob(pMob)); } catch (HRESULT& rResult) { hr = rResult; } // Cleanup object references if (edesc) edesc->Release(); if (pMob) pMob->Release(); if (pSourceMob) pSourceMob->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pFile) { // Close file, clean-up and return if (bFileOpen) { pFile->Save(); pFile->Close(); } pFile->Release(); } return hr; }
static HRESULT OpenAAFFile(aafWChar * pFileName) { IAAFFile* pFile = NULL; IAAFHeader* pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFMob* pMob = NULL; IAAFEssenceAccess* pEssenceAccess = NULL; IAAFEssenceFormat* pFormat = NULL; IEnumAAFMobs* pMobIter = NULL; aafNumSlots_t numMobs, numSlots; aafSearchCrit_t criteria; aafMobID_t mobID; IAAFDataDef *pSoundDef = NULL; IAAFMobSlot* pMobSlot = NULL; // Open an AAF file check(AAFFileOpenExistingRead (pFileName, 0, &pFile)); check(pFile->GetHeader(&pHeader)); // Open raw audio output file FILE *output; const char *output_file = "raw.pcm"; if ((output = fopen(output_file, "wb")) == NULL) { perror(output_file); exit(1); } // Get the AAF Dictionary from the file check(pHeader->GetDictionary(&pDictionary)); /* Lookup any necessary data definitions. */ check(pDictionary->LookupDataDef(kAAFDataDef_Sound, &pSoundDef)); /* Check number of Mobs in file */ check(pHeader->CountMobs(kAAFMasterMob, &numMobs)); if (numMobs == 0) { printf("No Master Mobs found in AAF file\n"); return 0; } printf("Found %d Master Mobs\n", numMobs); criteria.searchTag = kAAFByMobKind; criteria.tags.mobKind = kAAFMasterMob; check(pHeader->GetMobs(&criteria, &pMobIter)); while (AAFRESULT_SUCCESS == pMobIter->NextOne(&pMob)) { char mobIDstr[256]; aafWChar namebuf[1204]; IAAFTimelineMobSlot* pTimelineMobSlot = NULL; IAAFDataDef *pDataDef = NULL; IAAFEssenceFormat *fmtTemplate = NULL; unsigned char *dataBuff = NULL; IEnumAAFMobSlots* pMobSlotIter = NULL; check(pMob->GetMobID (&mobID)); check(pMob->GetName (namebuf, sizeof(namebuf))); MobIDtoString(mobID, mobIDstr); printf(" MasterMob Name = '%ls'\n", namebuf); printf(" (mobID %s)\n", mobIDstr); // Get the number of slots check(pMob->CountSlots(&numSlots)); // Iterating through all Mob Slots check(pMob->GetSlots(&pMobSlotIter)); while(AAFRESULT_SUCCESS == pMobSlotIter->NextOne(&pMobSlot)) { // Check to see if it is an Audio Timeline Mob Slot HRESULT hr; aafUInt32 MobSlotID; hr=pMobSlot->QueryInterface(IID_IAAFTimelineMobSlot,(void **) &pTimelineMobSlot); if (SUCCEEDED(hr)) { 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) { IAAFMasterMob* pMasterMob = NULL; // Prepare to get audio data: first get MobSlotID check(pMobSlot->GetSlotID(&MobSlotID)); // Then get a Master Mob interface check(pMob->QueryInterface(IID_IAAFMasterMob, (void **)&pMasterMob)); // Open the Essence Data check(pMasterMob->OpenEssence(MobSlotID, NULL, kAAFMediaOpenReadOnly, kAAFCompressionDisable, &pEssenceAccess)); // Get the information about the format of the audio data. // The pFormat object must be setup with each specifier you // wish to access, otherwise you get AAFRESULT_FORMAT_NOT_FOUND. aafUInt32 audioSampleBits; aafRational_t sampleRate; aafUInt32 numChannels; aafUInt32 maxSampleBytes; check(pEssenceAccess->GetEmptyFileFormat(&fmtTemplate)); check(fmtTemplate->AddFormatSpecifier(kAAFAudioSampleBits, 0, NULL)); check(fmtTemplate->AddFormatSpecifier(kAAFSampleRate, 0, NULL)); check(fmtTemplate->AddFormatSpecifier(kAAFNumChannels, 0, NULL)); check(fmtTemplate->AddFormatSpecifier(kAAFMaxSampleBytes, 0, NULL)); check(pEssenceAccess->GetFileFormat(fmtTemplate, &pFormat)); fmtTemplate->Release(); fmtTemplate = NULL; aafInt32 fmtBytesRead; check(pFormat->GetFormatSpecifier(kAAFAudioSampleBits, sizeof(audioSampleBits), (aafDataBuffer_t)&audioSampleBits, &fmtBytesRead)); check(pFormat->GetFormatSpecifier(kAAFSampleRate, sizeof(sampleRate), (aafDataBuffer_t)&sampleRate, &fmtBytesRead)); check(pFormat->GetFormatSpecifier(kAAFNumChannels, sizeof(numChannels), (aafDataBuffer_t)&numChannels, &fmtBytesRead)); check(pFormat->GetFormatSpecifier(kAAFMaxSampleBytes, sizeof(maxSampleBytes), (aafDataBuffer_t)&maxSampleBytes, &fmtBytesRead)); pFormat->Release(); pFormat = NULL; // Get the sample count which is in terms of EditRate aafLength_t sampleCount; check(pEssenceAccess->CountSamples(pSoundDef, &sampleCount)); printf("\tSlotID %u: SampleBits=%d SampleRate=%d/%d NumChannels=%d MaxSampleBytes=%u\n", MobSlotID, audioSampleBits, sampleRate.numerator, sampleRate.denominator, numChannels, maxSampleBytes); printf("\t\tCountSamples=%"AAFFMT64"d\n", sampleCount); // Set a suitable buffer size dataBuff = new unsigned char[maxSampleBytes]; // Read samples until no more are available aafUInt32 samplesRead, actualBytesRead, total_samples = 0; while (true) { hr = (pEssenceAccess->ReadSamples( 1, // number of samples to read maxSampleBytes, // maximum buffer size dataBuff, // output buffer for audio data &samplesRead, // number of samples read &actualBytesRead)); // number of bytes read if (hr == AAFRESULT_EOF) break; else check(hr); if (actualBytesRead!=0) { total_samples += samplesRead; // Write out samples if ( fwrite(dataBuff, maxSampleBytes, 1, output) != 1 ) { perror(output_file); return 1; } } } printf("\tTotal samples = %u (written to %s)\n", total_samples, output_file); delete [] dataBuff; dataBuff = NULL; pEssenceAccess->Release(); pEssenceAccess = NULL; pMasterMob->Release(); pMasterMob = NULL; } pTimelineMobSlot->Release(); pTimelineMobSlot = NULL; pDataDef->Release(); pDataDef = NULL; } pMobSlot->Release(); pMobSlot = NULL; } pMobSlotIter->Release(); pMobSlotIter = NULL; pMob->Release(); pMob = NULL; } pMobIter->Release(); pMobIter = NULL; 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; IAAFMasterMob* pMasterMob = NULL; IAAFSourceMob* pSrcMob = NULL; IAAFSourceMob* pTapeMob = NULL; IAAFEssenceDescriptor* pDesc = NULL; IAAFMob* pTempMob = NULL; HRESULT hr = S_OK; long test; aafSourceRef_t ref; IAAFEssenceDescriptor* pEssDesc = NULL; IAAFTapeDescriptor* pTapeDesc = NULL; try { // Remove the previous test file if any. RemoveTestFile(pFileName); // Create the AAF file checkResult(CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile )); bFileOpen = true; // Get the AAF file header. checkResult(pFile->GetHeader(&pHeader)); // Get the AAF Dictionary so that we can create valid AAF objects. checkResult(pHeader->GetDictionary(&pDictionary)); CAAFBuiltinDefs defs (pDictionary); // Create a Master Mob checkResult(defs.cdMasterMob()-> CreateInstance(IID_IAAFMob, (IUnknown **)&pMob)); // Set the IAAFMob properties checkResult(pMob->SetMobID(TEST_Master_MobID)); checkResult(pMob->SetName(MobName)); checkResult(pMob->QueryInterface(IID_IAAFMasterMob, (void **) &pMasterMob)); // Create source mob to associate with our MasterMob. checkResult(defs.cdSourceMob()-> CreateInstance(IID_IAAFSourceMob, (IUnknown **)&pTapeMob)); hr = defs.cdTapeDescriptor()-> CreateInstance(IID_IAAFTapeDescriptor, (IUnknown **)&pTapeDesc); if (AAFRESULT_SUCCESS == hr) { hr = pTapeDesc->QueryInterface(IID_IAAFEssenceDescriptor, (void **)&pEssDesc); if (AAFRESULT_SUCCESS == hr) { hr = pTapeMob->SetEssenceDescriptor(pEssDesc); if (AAFRESULT_SUCCESS == hr) { hr = pTapeDesc->SetTapeManufacturer( Manufacturer ); if (AAFRESULT_SUCCESS == hr ) { hr = pTapeDesc->SetTapeModel( Model ); if (AAFRESULT_SUCCESS == hr ) { hr = pTapeDesc->SetTapeFormFactor( FormFactor ); if (AAFRESULT_SUCCESS == hr ) { hr = pTapeDesc->SetSignalType( VideoSignalType ); if (AAFRESULT_SUCCESS == hr ) { hr = pTapeDesc->SetTapeFormat( TapeFormat ); if (AAFRESULT_SUCCESS == hr ) hr = pTapeDesc->SetTapeLength( TapeLength ); } } } } } pEssDesc->Release(); pEssDesc = NULL; } pTapeDesc->Release(); pTapeDesc = NULL; } for (test = 0; test < NumMobSlots; test++) { IAAFDataDefSP pDataDef; checkResult (pDictionary->LookupDataDef (*slotDDefs[test], &pDataDef)); checkResult(pTapeMob->AddNilReference (test, TAPE_MOB_LENGTH_ARR[test], pDataDef, slotRates[test])); } checkResult(pTapeMob->QueryInterface(IID_IAAFMob, (void **) &pTempMob)); checkResult(pTempMob->SetName(TAPE_MOB_NAME)); checkResult(pTempMob->SetMobID(tapeMobID)); //save the id for future (test) reference // TAPE_MOB_ID = tapeMobID; checkResult(pHeader->AddMob(pTempMob)); pTempMob->Release(); pTempMob = NULL; // Add some slots for (test = 0; test < NumMobSlots; test++) { // Create source mob to associate with our MasterMob. checkResult(defs.cdSourceMob()-> CreateInstance(IID_IAAFSourceMob, (IUnknown **)&pSrcMob)); ref.sourceID = tapeMobID; ref.sourceSlotID = test; ref.startTime = TAPE_MOB_OFFSET_ARR[test]; IAAFDataDefSP pDDef; checkResult(pDictionary->LookupDataDef(*slotDDefs[test], &pDDef)); checkResult(pSrcMob->AppendPhysSourceRef (slotRates[test], test, pDDef, ref, TAPE_MOB_LENGTH_ARR[test])); // Create a concrete subclass of EssenceDescriptor checkResult(defs.cdAIFCDescriptor()-> CreateInstance(IID_IAAFEssenceDescriptor, (IUnknown **)&pDesc)); IAAFAIFCDescriptor* pAIFCDesc = NULL; checkResult(pDesc->QueryInterface (IID_IAAFAIFCDescriptor, (void **)&pAIFCDesc)); checkResult(pAIFCDesc->SetSummary (5, (unsigned char*)"TEST")); pAIFCDesc->Release(); pAIFCDesc = NULL; checkResult(pSrcMob->SetEssenceDescriptor(pDesc)); pDesc->Release(); pDesc = NULL; // Append source MOB to header checkResult(pSrcMob->QueryInterface(IID_IAAFMob, (void **) &pTempMob)); checkResult(pTempMob->SetMobID(TEST_Source_MobIDs[test])); checkResult(pTempMob->SetName(L"source mob")); checkResult(pHeader->AddMob(pTempMob)); pTempMob->Release(); pTempMob = NULL; IAAFDataDefSP pDataDef; checkResult (pDictionary->LookupDataDef (*slotDDefs[test], &pDataDef)); checkResult(pMasterMob->AddMasterSlot(pDataDef, test, pSrcMob, test+1, slotNames[test])); pSrcMob->Release(); pSrcMob = NULL; } // Add the master mob to the file and cleanup checkResult(pHeader->AddMob(pMob)); } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pTempMob) pTempMob->Release(); if (pEssDesc) pEssDesc->Release(); if (pTapeDesc) pTapeDesc->Release(); if (pDesc) pDesc->Release(); if (pSrcMob) pSrcMob->Release(); if (pTapeMob) pTapeMob->Release(); if (pMasterMob) pMasterMob->Release(); if (pMob) pMob->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pFile) { // Close file if (bFileOpen) { pFile->Save(); pFile->Close(); } pFile->Release(); } return hr; }
static HRESULT 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 ReadAAFFile(aafWChar * pFileName) { // IAAFSession * pSession = NULL; IAAFFile * pFile = NULL; bool bFileOpen = false; IAAFHeader * pHeader = NULL; IEnumAAFMobs *mobIter = NULL; IAAFContainerDef* pContainer = NULL; IAAFDefObject * pDef = NULL; IAAFEssenceDescriptor *pEdesc = NULL; IAAFSourceMob *pSourceMob = NULL; IAAFMob *aMob = NULL; IEnumAAFMobSlots *slotIter = NULL; IAAFMobSlot *slot = NULL; IAAFFileDescriptor *pFileDesc = NULL; IAAFFileDescriptor2 *pFileDesc2 = NULL; aafNumSlots_t numMobs, n, s; HRESULT hr = S_OK; aafRational_t testSampleRate; aafUID_t testContainer; aafLength_t testLength; aafUInt32 testLinkedSlotID; // aafBool testBool; try { // Open the file checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); bFileOpen = true; // We can't really do anthing in AAF without the header. checkResult(pFile->GetHeader(&pHeader)); // Get the number of mobs in the file (should be one) checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED); checkResult(pHeader->GetMobs (NULL, &mobIter)); for(n = 0; n < numMobs; n++) { aafWChar name[500]; aafNumSlots_t numSlots; aafMobID_t mobID; aafSlotID_t trackID; checkResult(mobIter->NextOne (&aMob)); checkResult(aMob->GetName (name, sizeof(name))); checkResult(aMob->GetMobID (&mobID)); checkResult(aMob->CountSlots (&numSlots)); if (2 != numSlots) return AAFRESULT_TEST_FAILED; if(numSlots != 0) { checkResult(aMob->GetSlots(&slotIter)); for(s = 0; s < numSlots; s++) { checkResult(slotIter->NextOne (&slot)); checkResult(slot->GetSlotID(&trackID)); slot->Release(); slot = NULL; } } checkResult(aMob->QueryInterface (IID_IAAFSourceMob, (void **)&pSourceMob)); checkResult(pSourceMob->GetEssenceDescriptor (&pEdesc)); checkResult(pEdesc->QueryInterface(IID_IAAFFileDescriptor, (void **) &pFileDesc)); checkResult(pFileDesc->GetSampleRate (&testSampleRate)); checkExpression(testSampleRate.numerator == checkSampleRate.numerator, AAFRESULT_TEST_FAILED); checkExpression(testSampleRate.denominator == checkSampleRate.denominator, AAFRESULT_TEST_FAILED); checkResult(pFileDesc->GetContainerFormat (&pContainer)); checkResult(pContainer->QueryInterface(IID_IAAFDefObject, (void **) &pDef)); checkResult(pDef->GetAUID(&testContainer)); pContainer->Release(); pContainer = NULL; pDef->Release(); pDef = NULL; checkExpression(memcmp(&testContainer, &checkContainer, sizeof(testContainer)) == 0, AAFRESULT_TEST_FAILED); checkResult(pFileDesc->GetLength (&testLength)); checkExpression(checkLength == testLength, AAFRESULT_TEST_FAILED); checkResult(pFileDesc->QueryInterface(IID_IAAFFileDescriptor2, (void **)&pFileDesc2)); checkResult(pFileDesc2->GetLinkedSlotID (&testLinkedSlotID)); checkExpression(checkLinkedSlotID == testLinkedSlotID, AAFRESULT_TEST_FAILED); // checkResult(pFileDesc->GetIsInContainer (&testBool)); // checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); pEdesc->Release(); pEdesc = NULL; pFileDesc->Release(); pFileDesc = NULL; pFileDesc2->Release(); pFileDesc2 = NULL; pSourceMob->Release(); pSourceMob = NULL; aMob->Release(); aMob = NULL; } } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (slot) slot->Release(); if (pFileDesc) pFileDesc->Release(); if (pFileDesc2) pFileDesc2->Release(); if (slotIter) slotIter->Release(); if (pEdesc) pEdesc->Release(); if (pSourceMob) pSourceMob->Release(); if (aMob) aMob->Release(); if(mobIter) mobIter->Release(); if (pHeader) pHeader->Release(); if (pFile) { if (bFileOpen) pFile->Close(); pFile->Release(); } return hr; }
static HRESULT CreateAAFFile(aafWChar * pFileName, bool comp_enable) { IAAFFile* pFile = NULL; IAAFHeader* pHeader = NULL; IAAFHeader2* pHeader2 = NULL; IAAFDictionary* pDictionary = NULL; IAAFMob* pMob = NULL; IAAFMasterMob* pMasterMob = NULL; IAAFEssenceAccess* pEssenceAccess = NULL; aafMobID_t masterMobID; aafProductIdentification_t ProductInfo; IAAFClassDef *pCDMasterMob = NULL; IAAFDataDef *pPictureDef = NULL; aafUInt32 samplesWritten, bytesWritten; // Delete any previous test file before continuing... char cFileName[FILENAME_MAX]; convert(cFileName, sizeof(cFileName), pFileName); remove(cFileName); cout << "Creating file " << cFileName << " using WriteSamples with " << (comp_enable ? "CompressionEnable" : "CompressionDisable") << endl; aafProductVersion_t ver = {1, 0, 0, 0, kAAFVersionBeta}; ProductInfo.companyName = const_cast<wchar_t *>(L"none"); ProductInfo.productName = const_cast<wchar_t *>(L"AAF SDK"); ProductInfo.productVersion = &ver; ProductInfo.productVersionString = const_cast<wchar_t *>(L"1.0.0.0 Beta"); ProductInfo.productID = NIL_UID; ProductInfo.platform = NULL; // Set by SDK when saving // select the file kind const aafUID_t* fileKind = &kAAFFileKind_DontCare; if( FormatMXF ) fileKind = &kAAFFileKind_AafKlvBinary; else if( FormatSS512 ) fileKind = &kAAFFileKind_Aaf512Binary; else fileKind = &kAAFFileKind_Aaf4KBinary; // Create a new AAF file check(AAFFileOpenNewModifyEx(pFileName, fileKind, 0, &ProductInfo, &pFile)); check(pFile->GetHeader(&pHeader)); // Set the operational pattern check(pHeader->QueryInterface(IID_IAAFHeader2, (void **)&pHeader2)); check(pHeader2->SetOperationalPattern(kAAFOpDef_Atom)); // Get the AAF Dictionary from the file check(pHeader->GetDictionary(&pDictionary)); /* Lookup class definitions for the objects we want to create. */ check(pDictionary->LookupClassDef(AUID_AAFMasterMob, &pCDMasterMob)); /* Lookup any necessary data definitions. */ check(pDictionary->LookupDataDef(kAAFDataDef_Picture, &pPictureDef)); /* Create a Mastermob */ // Get a Master MOB Interface check(pCDMasterMob->CreateInstance(IID_IAAFMasterMob, (IUnknown **)&pMasterMob)); // Get a Mob interface and set its variables. check(pMasterMob->QueryInterface(IID_IAAFMob, (void **)&pMob)); check(pMob->GetMobID(&masterMobID)); if (input_video == NULL) { check(pMob->SetName(L"DNX_color_bars")); } else { check(pMob->SetName(pFileName)); } // Add Mobs to the Header check(pHeader->AddMob(pMob)); /* Create the Essence Data specifying the codec, container, edit rate and sample rate */ check(pMasterMob->CreateEssence( 1, // Slot ID within MasterMob pPictureDef, // MediaKind UseDNX? kAAFCodecDNxHD : kAAFCodecVC3, // codecID editRate, // edit rate editRate, // sample rate comp_enable ? kAAFCompressionEnable : kAAFCompressionDisable, NULL, // No Locator used ContainerAAF, // Essence embedded in AAF file &pEssenceAccess)); // // Set the codec flavour for desired video format switch(ComprID) { case 1235: pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1235 ); break; case 1238: pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1238 ); break; case 1237: pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1237 ); break; case 1241: pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1241 ); break; case 1243: pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1243 ); break; case 1244: pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1244 ); break; case 1242: pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1242 ); break; case 1250: pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1250 ); break; case 1251: pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1251 ); break; case 1252: pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1252 ); break; case 1253: pEssenceAccess->SetEssenceCodecFlavour( kAAFCodecFlavour_VC3_1253 ); break; default: break; } switch( input_type ) { case P_UYVY: case BarsUYVY: default: layout = UseDNX?Layout_P_UYVY:Layout_UYVYM; break; case UYVY: layout = UseDNX?Layout_UYVY:Layout_Unknown; break; case BGRAI: case BarsRGB: layout = UseDNX?Layout_BGRAI:Layout_Unknown; break; case BGRA: layout = UseDNX?Layout_BGRA:Layout_Unknown; break; } // Set up the information about the format of the data IAAFEssenceFormat * fmtTemplate=NULL; check(pEssenceAccess->GetEmptyFileFormat (&fmtTemplate)); if( UseLegacyUIDs ) check(fmtTemplate->AddFormatSpecifier (kAAFLegacyAUIDs, sizeof(UseLegacyUIDs), (aafDataBuffer_t)&UseLegacyUIDs)); if( UseDNX ) check(fmtTemplate->AddFormatSpecifier (kAAFNumThreads, sizeof(nCodecThreads), (aafDataBuffer_t)&nCodecThreads)); if( UseDNX ) check(fmtTemplate->AddFormatSpecifier (kAAFBufferLayout, sizeof(layout), (aafDataBuffer_t)&layout)); // codec will automatically SetEssenceKey() for MXF if !UseLegacyUIDs // codec will automatically SetEssenceKey() for Avid legacy if UseLegacyUIDs // future: if other kAAFEssenceElementKey, set it here // future: if other kAAFPhysicalTrackNum, set it here // Put the format specifiers into the codec check(pEssenceAccess->PutFileFormat( fmtTemplate )); // For fun, print the name of the selected codec flavour aafWChar codec_name[128] = L""; check(pEssenceAccess->GetCodecName(sizeof(codec_name), codec_name)); printf(" using codec flavour \"%ls\"\n", codec_name); // Write the video samples int total_samples = 0; if( input_type==Raw ) { // Read one frame of raw VC3 video at a time, repeat last frame until end FILE * ip=fopen( input_video,"rb" ); if(!ip) return false; aafUInt32 nwant = GetBytesPerEditUnit(ComprID); unsigned char* raw_buff = new unsigned char [ nwant ]; size_t nread=0; while( Duration-- ) { // keep on trying to read if( !feof( ip ) ) nread=fread( raw_buff, 1, nwant, ip ); // abandon if partial frame (complete frame or zero is ok if ( nread!=nwant && nread!= 0 ) { perror(input_video); break; } samplesWritten=0; check(pEssenceAccess->WriteSamples(1, nwant, raw_buff, &samplesWritten, &bytesWritten)); total_samples += samplesWritten; } delete[] raw_buff; fclose( ip ); } else if( input_type==P_UYVY || input_type==UYVYI || input_type==UYVYM ) { // Load a single frame of uncompressed aafUInt32 nwant = GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1)*(GetPixelsPerLine(ComprID)/2)*(UseDNX?5:8); unsigned char* video_buffer = new unsigned char [ nwant ]; // int LoadXYUV( BufferLayout_t target, byte *video_buffer, int len, int H, int V, const char *input_video, // bool isLittleEndian=true, bool isBigEndian=false, bool isP_UYVY=false ); LoadXYUV( UseDNX?Layout_P_UYVY:Layout_UYVYM, video_buffer, nwant, GetPixelsPerLine(ComprID), GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1), input_video, input_type==UYVYI, input_type==UYVYM, input_type==P_UYVY ); while( Duration-- ) { samplesWritten=0; check(pEssenceAccess->WriteSamples(1, nwant, video_buffer, &samplesWritten, &bytesWritten)); total_samples += samplesWritten; } delete[] video_buffer; } else if( input_type==UYVY ) { // Load a single frame of uncompressed aafUInt32 nwant = GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1)*(GetPixelsPerLine(ComprID)/2)*(UseDNX?4:8); unsigned char* video_buffer = new unsigned char [ nwant ]; // int LoadXYUV( BufferLayout_t target, byte *video_buffer, int len, int H, int V, const char *input_video, // bool isLittleEndian=true, bool isBigEndian=false, bool isP_UYVY=false ); LoadXYUV( UseDNX?Layout_UYVY:Layout_UYVYM, video_buffer, nwant, GetPixelsPerLine(ComprID), GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1), input_video, false, false, false ); while( Duration-- ) { samplesWritten=0; check(pEssenceAccess->WriteSamples(1, nwant, video_buffer, &samplesWritten, &bytesWritten)); total_samples += samplesWritten; } delete[] video_buffer; } else if( input_type==BGRAI ) { // never get here with VC3Codec // Load a single frame of uncompressed aafUInt32 nwant = GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1)*GetPixelsPerLine(ComprID)*8; unsigned char* video_buffer = new unsigned char [ nwant ]; // int LoadXRGB( BufferLayout_t target, byte *video_buffer, int len, int H, int V, const char *input_video, // bool isLittleEndian=true, bool isBigEndian=false, bool hasA=false, bool isRGB=false ); LoadXRGB( Layout_BGRAI, video_buffer, nwant, GetPixelsPerLine(ComprID), GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1), input_video, input_type==BGRAI, false, true, false ); while( Duration-- ) { samplesWritten=0; check(pEssenceAccess->WriteSamples(1, nwant, video_buffer, &samplesWritten, &bytesWritten)); total_samples += samplesWritten; } delete[] video_buffer; } else if( input_type==BGRA ) { // never get here with VC3Codec // Load a single frame of uncompressed aafUInt32 nwant = GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1)*GetPixelsPerLine(ComprID)*8; unsigned char* video_buffer = new unsigned char [ nwant ]; // int LoadXRGB( BufferLayout_t target, byte *video_buffer, int len, int H, int V, const char *input_video, // bool isLittleEndian=true, bool isBigEndian=false, bool hasA=false, bool isRGB=false ); LoadXRGB( Layout_BGRA, video_buffer, nwant, GetPixelsPerLine(ComprID), GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1), input_video, input_type==BGRAI, false, true, false ); while( Duration-- ) { samplesWritten=0; check(pEssenceAccess->WriteSamples(1, nwant, video_buffer, &samplesWritten, &bytesWritten)); total_samples += samplesWritten; } delete[] video_buffer; } else if( input_type==BarsRGB ) // using generated rgb colo(u)r bars { // never get here with VC3Codec // Create a frame of colour bars aafUInt32 nwant = GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1)*GetPixelsPerLine(ComprID)*8; unsigned char* video_buffer = new unsigned char [ nwant ]; LoadXBars( Layout_BGRAI, video_buffer, nwant, GetPixelsPerLine(ComprID), GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1) ); while( Duration-- ) { samplesWritten=0; check(pEssenceAccess->WriteSamples(1, nwant, video_buffer, &samplesWritten, &bytesWritten)); total_samples += samplesWritten; } delete[] video_buffer; } else // if( input_type==BarsUYVY || input_video == NULL || others... ) // using generated component colo(u)r bars { // Create a frame of colour bars aafUInt32 nwant = GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1)*(GetPixelsPerLine(ComprID)/2)*(UseDNX?5:8); unsigned char* video_buffer = new unsigned char [ nwant ]; LoadXBars( UseDNX?Layout_P_UYVY:Layout_UYVYM, video_buffer, nwant, GetPixelsPerLine(ComprID), GetLinesPerField(ComprID)*(IsInterlaced(ComprID)?2:1) ); while( Duration-- ) { samplesWritten=0; check(pEssenceAccess->WriteSamples(1, nwant, video_buffer, &samplesWritten, &bytesWritten)); total_samples += samplesWritten; } delete[] video_buffer; } printf("Completed Write\n"); /* Set the essence to indicate that you have finished writing the samples */ check(pEssenceAccess->CompleteWrite()); check(pHeader2->UpdateEssenceContainers()); pEssenceAccess->Release(); pMob->Release(); pMasterMob->Release(); pPictureDef->Release(); pCDMasterMob->Release(); pDictionary->Release(); pHeader->Release(); pHeader2->Release(); /* Save the AAF file */ pFile->Save(); /* Close the AAF file */ pFile->Close(); pFile->Release(); return moduleErrorTmp; }
static HRESULT CreateAAFFile( aafWChar * pFileName, aafUID_constref fileKind, testRawStorageType_t rawStorageType, aafProductIdentification_constref productID) { IAAFFile* pFile = NULL; IAAFHeader* pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFSourceMob* pSourceMob = NULL; IAAFMob* pMob = NULL; IAAFTIFFDescriptor* pTIFFDesc = NULL; IAAFEssenceDescriptor* pEssDesc = NULL; HRESULT hr = AAFRESULT_SUCCESS; aafUInt8 summary[512]; aafUInt16 numEntries = 2; unsigned long nOffset; #if defined( OS_WINDOWS ) tiffHeader.tiff_byteOrder = TIFF_LITTLEENDIAN; #else tiffHeader.tiff_byteOrder = TIFF_BIGENDIAN; #endif tiffHeader.tiff_identNumber = TIFF_VERSION; tiffHeader.tiff_firstIFD = 0; memcpy(summary, (void *)&tiffHeader, sizeof(tiffHeader)); nOffset = sizeof(tiffHeader); tagImageWidth.tdir_tag = TIFFTAG_IMAGEWIDTH; tagImageWidth.tdir_type = TIFF_LONG; tagImageWidth.tdir_count = 1; tagImageWidth.tdir_offset = 320; tagImageLength.tdir_tag = TIFFTAG_IMAGELENGTH; tagImageLength.tdir_type = TIFF_LONG; tagImageLength.tdir_count = 1; tagImageLength.tdir_offset = 640; // Write IFD data memcpy(summary+nOffset, &numEntries, sizeof(numEntries)); nOffset += sizeof(numEntries); memcpy((void *)(summary+nOffset), (void *)&tagImageWidth, sizeof(tagImageWidth)); nOffset += sizeof(tagImageWidth); memcpy((void *)(summary+nOffset), (void *)&tagImageLength, sizeof(tagImageLength)); nOffset += sizeof(tagImageLength); try { // Remove the previous test file if any. RemoveTestFile(pFileName); // Create the AAF file checkResult(CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile )); // 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); // Create a source mob checkResult(defs.cdSourceMob()-> CreateInstance(IID_IAAFSourceMob, (IUnknown **)&pSourceMob)); checkResult(pSourceMob->QueryInterface(IID_IAAFMob, (void **)&pMob)); checkResult(pMob->SetMobID(TEST_MobID)); checkResult(pMob->SetName(L"TIFFDescriptorTest")); checkResult(defs.cdTIFFDescriptor()-> CreateInstance(IID_IAAFTIFFDescriptor, (IUnknown **)&pTIFFDesc)); checkResult(pTIFFDesc->QueryInterface(IID_IAAFEssenceDescriptor, (void **)&pEssDesc)); checkResult(pTIFFDesc->SetIsUniform(kAAFFalse)); checkResult(pTIFFDesc->SetIsContiguous(kAAFTrue)); checkResult(pTIFFDesc->SetLeadingLines((aafInt32)10)); checkResult(pTIFFDesc->SetTrailingLines((aafInt32)20)); checkResult(pTIFFDesc->SetJPEGTableID((aafJPEGTableID_t)0)); checkResult(pTIFFDesc->SetSummary((aafUInt32)nOffset, (aafDataValue_t) summary)); checkResult(pSourceMob->SetEssenceDescriptor(pEssDesc)); // Add the MOB to the file checkResult(pHeader->AddMob(pMob)); } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pTIFFDesc) pTIFFDesc->Release(); if (pDictionary) pDictionary->Release(); if (pEssDesc) pEssDesc->Release(); if (pMob) pMob->Release(); if (pSourceMob) pSourceMob->Release(); if (pHeader) pHeader->Release(); if (pFile) { pFile->Save(); pFile->Close(); pFile->Release(); } return hr; }
static HRESULT ReadAAFFile(aafWChar* pFileName) { IAAFFile* pFile = NULL; IAAFHeader* pHeader = NULL; IAAFDictionary* pDictionary = NULL; IEnumAAFOperationDefs *pOperationGroupEnum = NULL; IEnumAAFParameterDefs *pParmDefEnum = NULL; IAAFOperationDef *pOperationDef = NULL; IAAFParameterDef *pParmDef = NULL; IAAFParameter *pParameter = NULL; IAAFMetaDefinition* pMetaDefinition = NULL; IAAFSegment* pSeg = NULL; IAAFOperationGroup* pOperationGroup = NULL; IEnumAAFMobs *mobIter = NULL; IAAFMob* pMob = NULL; IEnumAAFMobSlots *slotIter = NULL; IAAFMobSlot* pSlot = NULL; IAAFFiller* pFill = NULL; IAAFSourceReference *pSourceRef = NULL; IEnumAAFControlPoints *pEnumCP = NULL; IAAFControlPoint *pControlPoint = NULL; IAAFVaryingValue *pVaryingValue = NULL; IAAFInterpolationDef *pInterpDef = NULL; IAAFTypeDef *pTypeDef = NULL; bool bFileOpen = false; aafBool readIsTimeWarp; aafUInt32 testNumSources, testNumParam; HRESULT hr = S_OK; aafNumSlots_t s; aafNumSlots_t numSlots; aafUInt32 readOverride; aafBool readValidTransition; aafRational_t testTime; aafRational_t sampleValue1 = kTestLevel1, sampleValue2 = kTestLevel2, testValue; aafRational_t checkTime1 = kTestTime1; aafRational_t checkTime2 = kTestTime2; aafEditHint_t checkEditHint; aafUID_t testInterpDef, checkInterpDef = kAAFTypeID_Rational; try { // Open the AAF file checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); bFileOpen = true; // Get the AAF file header. checkResult(pFile->GetHeader(&pHeader)); aafSearchCrit_t criteria; criteria.searchTag = kAAFNoSearch; checkResult(pHeader->GetMobs (&criteria, &mobIter)); checkResult(mobIter->NextOne (&pMob)); checkResult(pMob->GetSlots(&slotIter)); checkResult(pMob->CountSlots (&numSlots)); for(s = 0; s < numSlots; s++) { checkResult(slotIter->NextOne (&pSlot)); checkResult(pSlot->GetSegment (&pSeg)); checkResult(pSeg->QueryInterface (IID_IAAFOperationGroup, (void **)&pOperationGroup)); pSeg->Release(); pSeg = NULL; checkResult(pOperationGroup->CountSourceSegments(&testNumSources)); checkExpression(testNumSources == TEST_NUM_INPUTS, AAFRESULT_TEST_FAILED); checkResult(pOperationGroup->CountParameters(&testNumParam)); checkExpression(testNumSources == 1, AAFRESULT_TEST_FAILED); checkResult(pOperationGroup->IsATimeWarp (&readIsTimeWarp)); checkExpression(readIsTimeWarp == kAAFFalse, AAFRESULT_TEST_FAILED); checkResult(pOperationGroup->GetBypassOverride (&readOverride)); checkExpression(readOverride == 1, AAFRESULT_TEST_FAILED); checkResult(pOperationGroup->IsValidTranOperation (&readValidTransition)); checkExpression(readValidTransition == kAAFFalse, AAFRESULT_TEST_FAILED); /**/ checkResult(pOperationGroup->GetInputSegmentAt (0, &pSeg)); checkResult(pSeg->QueryInterface(IID_IAAFFiller, (void **) &pFill)); pFill->Release(); pFill = NULL; /**/ checkResult(pOperationGroup->LookupParameter (kTestParmID, &pParameter)); checkResult(pParameter->QueryInterface(IID_IAAFVaryingValue, (void **) &pVaryingValue)); /*** Check the VaryingValue methods **/ aafUInt32 testLen, bytesRead; checkResult(pVaryingValue->GetControlPoints(&pEnumCP)); checkResult(pEnumCP->NextOne(&pControlPoint)); checkResult(pControlPoint->GetValueBufLen (&testLen)); checkExpression(testLen == sizeof(sampleValue1), AAFRESULT_TEST_FAILED); checkResult(pControlPoint->GetValue (sizeof(sampleValue1), (aafDataBuffer_t)&testValue, &bytesRead)); checkExpression(testValue.numerator == sampleValue1.numerator, AAFRESULT_TEST_FAILED); checkExpression(testValue.denominator == sampleValue1.denominator, AAFRESULT_TEST_FAILED); checkExpression(bytesRead == sizeof(sampleValue1), AAFRESULT_TEST_FAILED); checkResult(pControlPoint->GetTime(&testTime)); checkExpression(testTime.numerator == checkTime1.numerator, AAFRESULT_TEST_FAILED); checkExpression(testTime.denominator == checkTime1.denominator, AAFRESULT_TEST_FAILED); checkResult(pControlPoint->GetEditHint(&checkEditHint)); checkExpression(checkEditHint == kAAFRelativeLeft, AAFRESULT_TEST_FAILED); checkResult(pControlPoint->GetTypeDefinition (&pTypeDef)); checkResult(pTypeDef->QueryInterface(IID_IAAFMetaDefinition, (void **) &pMetaDefinition)); checkResult(pMetaDefinition->GetAUID(&testInterpDef)); checkExpression(memcmp(&testInterpDef, &checkInterpDef, sizeof(aafUID_t)) == 0, AAFRESULT_TEST_FAILED); pControlPoint->Release(); pControlPoint = NULL; pTypeDef->Release(); pTypeDef = NULL; pMetaDefinition->Release(); pMetaDefinition = NULL; /**/ checkResult(pEnumCP->NextOne(&pControlPoint)); checkResult(pControlPoint->GetValueBufLen (&testLen)); checkExpression(testLen == sizeof(sampleValue2), AAFRESULT_TEST_FAILED); checkResult(pControlPoint->GetValue (sizeof(sampleValue2), (aafDataBuffer_t)&testValue, &bytesRead)); checkExpression(testValue.numerator == sampleValue2.numerator, AAFRESULT_TEST_FAILED); checkExpression(testValue.denominator == sampleValue2.denominator, AAFRESULT_TEST_FAILED); checkExpression(bytesRead == sizeof(sampleValue2), AAFRESULT_TEST_FAILED); checkResult(pControlPoint->GetTime(&testTime)); checkExpression(testTime.numerator == checkTime2.numerator, AAFRESULT_TEST_FAILED); checkExpression(testTime.denominator == checkTime2.denominator, AAFRESULT_TEST_FAILED); checkResult(pControlPoint->GetEditHint(&checkEditHint)); checkExpression(checkEditHint == kAAFProportional, AAFRESULT_TEST_FAILED); checkResult(pControlPoint->GetTypeDefinition (&pTypeDef)); checkResult(pTypeDef->QueryInterface(IID_IAAFMetaDefinition, (void **) &pMetaDefinition)); checkResult(pMetaDefinition->GetAUID(&testInterpDef)); checkExpression(memcmp(&testInterpDef, &checkInterpDef, sizeof(aafUID_t)) == 0, AAFRESULT_TEST_FAILED); pControlPoint->Release(); pControlPoint = NULL; pEnumCP->Release(); pEnumCP = NULL; pTypeDef->Release(); pTypeDef = NULL; pMetaDefinition->Release(); pMetaDefinition = NULL; /*****/ pVaryingValue->Release(); pVaryingValue = NULL; pParameter->Release(); pParameter = NULL; pSeg->Release(); pSeg = NULL; pOperationGroup->Release(); pOperationGroup = NULL; pSlot->Release(); pSlot = NULL; } slotIter->Release(); slotIter = NULL; pMob->Release(); pMob = NULL; } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pFill) pFill->Release(); if(pInterpDef) pInterpDef->Release(); if(pVaryingValue) pVaryingValue->Release(); if (pSourceRef) pSourceRef->Release(); if (mobIter) mobIter->Release(); if (pSlot) pSlot->Release(); if (slotIter) slotIter->Release(); if (pMob) pMob->Release(); if (pHeader) pHeader->Release(); if (pSeg) pSeg->Release(); if (pControlPoint) pControlPoint->Release(); if(pEnumCP) pEnumCP->Release(); if (pOperationGroup) pOperationGroup->Release(); if (pDictionary) pDictionary->Release(); if (pOperationGroupEnum) pOperationGroupEnum->Release(); if (pParameter) pParameter->Release(); if (pParmDefEnum) pParmDefEnum->Release(); if (pOperationDef) pOperationDef->Release(); if (pMetaDefinition) pMetaDefinition->Release(); if (pParmDef) pParmDef->Release(); if (pTypeDef) pTypeDef->Release(); if (pFile) { // Close file if (bFileOpen) pFile->Close(); pFile->Release(); } return hr; }
static HRESULT ReadAAFFile(aafWChar * pFileName) { // IAAFSession * pSession = NULL; IAAFFile * pFile = NULL; IAAFHeader * pHeader = NULL; IAAFEssenceDescriptor *pEdesc = NULL; IAAFSourceMob *pSourceMob = NULL; IEnumAAFLocators * pEnum = NULL; IAAFLocator * pLocator = NULL; IEnumAAFMobs *mobIter = NULL; IAAFMob *aMob = NULL; aafUInt32 numLocators; aafUInt32 readLen; aafNumSlots_t numMobs, n; HRESULT hr = AAFRESULT_SUCCESS; aafWChar readBuf[1024]; bool bFileOpen = false; try { // Open the file. checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); bFileOpen = true; checkResult(pFile->GetHeader(&pHeader)); checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); if (1 != numMobs ) checkResult(AAFRESULT_TEST_FAILED); //!!! aafSearchCrit_t criteria; //!!! criteria.searchTag = kAAFNoSearch; checkResult(pHeader->GetMobs (NULL, &mobIter)); for(n = 0; n < numMobs; n++) { aafWChar name[500]; aafMobID_t mobID; checkResult(mobIter->NextOne (&aMob)); checkResult(aMob->GetName (name, sizeof(name))); checkResult(aMob->GetMobID (&mobID)); checkResult(aMob->QueryInterface (IID_IAAFSourceMob, (void **)&pSourceMob)); checkResult(pSourceMob->GetEssenceDescriptor (&pEdesc)); // Verify that there is now one locator checkResult(pEdesc->CountLocators(&numLocators)); if (1 != numLocators) checkResult(AAFRESULT_TEST_FAILED); checkResult(pEdesc->GetLocators(&pEnum)); // This should read the one real locator checkResult(pEnum->NextOne(&pLocator)); checkResult(pLocator->GetPathBufLen (&readLen)); // if(readLen != strlen(TEST_PATH)) checkResult(pLocator->GetPath (readBuf, readLen)); // This should run off the end pLocator->Release(); pLocator = NULL; hr = pEnum->NextOne(&pLocator); if (AAFRESULT_NO_MORE_OBJECTS != hr) checkResult(hr); else hr = AAFRESULT_SUCCESS; // reset result } } catch (HRESULT& rResult) { hr = rResult; } // Cleanup... if (pLocator) pLocator->Release(); if (pEnum) pEnum->Release(); if (pEdesc) pEdesc->Release(); if (pSourceMob) pSourceMob->Release(); if (aMob) aMob->Release(); if (mobIter) mobIter->Release(); if (pHeader) pHeader->Release(); if (pFile) { if (bFileOpen) pFile->Close(); pFile->Release(); } // hr = pSession->EndSession(); // if (AAFRESULT_SUCCESS != hr) // return hr; // if (pSession) pSession->Release(); return hr; }
static HRESULT CreateAAFFile( aafWChar * pFileName, aafUID_constref fileKind, testRawStorageType_t rawStorageType, aafProductIdentification_constref productID) { IAAFFile* pFile = NULL; IAAFHeader * pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFOperationDef* pOperationDef = NULL; IAAFParameterDef* pParamDef = NULL; IAAFDefObject* pDefObject = NULL; IAAFOperationGroup *pOperationGroup = NULL; IAAFMob *pMob = NULL; IAAFSegment *pSeg = NULL; IAAFTimelineMobSlot *pSlot = NULL; IAAFParameter *pParm = NULL; IAAFVaryingValue *pVaryingValue = NULL; IAAFSegment *pFiller = NULL; IAAFComponent *pComponent = NULL; IAAFSourceClip *pSourceClip = NULL; IAAFControlPoint *pControlPoint = NULL; IAAFSourceReference *pSourceRef = NULL; IAAFInterpolationDef *pInterpDef = NULL; IAAFPluginManager *pMgr = NULL; IAAFTypeDef *pTypeDef = NULL; bool bFileOpen = false; HRESULT hr = S_OK; // aafUID_t testInterpDef = kAAFTypeID_Rational; aafLength_t effectLen = TEST_EFFECT_LEN; aafUID_t effectID = kTestEffectID; aafUID_t parmID = kTestParmID; aafRational_t testLevel1 = kTestLevel1; aafRational_t testLevel2 = kTestLevel2; aafRational_t testTime1 = kTestTime1; aafRational_t testTime2 = kTestTime2; /* 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; // 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.cdOperationDef()-> CreateInstance(IID_IAAFOperationDef, (IUnknown **)&pOperationDef)); checkResult(defs.cdParameterDef()-> CreateInstance(IID_IAAFParameterDef, (IUnknown **)&pParamDef)); checkResult(pDictionary->LookupTypeDef (kAAFTypeID_Rational, &pTypeDef)); checkResult(pParamDef->Initialize (parmID, TEST_PARAM_NAME, TEST_PARAM_DESC, pTypeDef)); checkResult(AAFGetPluginManager(&pMgr)); checkResult(pMgr->CreatePluginDefinition(LinearInterpolator, pDictionary, &pDefObject)); checkResult(pDefObject->QueryInterface(IID_IAAFInterpolationDef, (void **) &pInterpDef)); pDefObject->Release(); pDefObject = NULL; checkResult(pOperationDef->Initialize (effectID, TEST_EFFECT_NAME, TEST_EFFECT_DESC)); checkResult(pDictionary->RegisterOperationDef (pOperationDef)); checkResult(pDictionary->RegisterParameterDef (pParamDef)); checkResult(pDictionary->RegisterInterpolationDef (pInterpDef)); checkResult(pOperationDef->SetDataDef (defs.ddkAAFPicture())); checkResult(pOperationDef->SetIsTimeWarp (kAAFFalse)); checkResult(pOperationDef->SetNumberInputs (TEST_NUM_INPUTS)); checkResult(pOperationDef->SetCategory (TEST_CATEGORY)); checkResult(pOperationDef->AddParameterDef (pParamDef)); checkResult(pOperationDef->SetBypass (TEST_BYPASS)); checkResult(pParamDef->SetDisplayUnits(TEST_PARAM_UNITS)); //Make the first mob long test; aafRational_t videoRate = { 2997, 100 }; // Create a Mob checkResult(defs.cdCompositionMob()-> CreateInstance(IID_IAAFMob, (IUnknown **)&pMob)); checkResult(pMob->SetName(L"AAFOperationGroupTest")); // Add some slots for(test = 0; test < 2; test++) { checkResult(defs.cdOperationGroup()-> CreateInstance(IID_IAAFOperationGroup, (IUnknown **)&pOperationGroup)); checkResult(defs.cdFiller()-> CreateInstance(IID_IAAFSegment, (IUnknown **)&pFiller)); checkResult(pFiller->QueryInterface (IID_IAAFComponent, (void **)&pComponent)); checkResult(pComponent->SetLength(effectLen)); CAAFBuiltinDefs defs(pDictionary); checkResult(pComponent->SetDataDef(defs.ddkAAFPicture())); checkResult(pOperationGroup->Initialize(defs.ddkAAFPicture(), TEST_EFFECT_LEN, pOperationDef)); checkResult(defs.cdVaryingValue()-> CreateInstance(IID_IAAFVaryingValue, (IUnknown **)&pVaryingValue)); checkResult(pVaryingValue->Initialize (pParamDef, pInterpDef)); checkResult(defs.cdControlPoint()-> CreateInstance(IID_IAAFControlPoint, (IUnknown **)&pControlPoint)); checkResult(pControlPoint->Initialize (pVaryingValue, testTime1, sizeof(testLevel1), (aafDataBuffer_t)&testLevel1)); checkResult(pControlPoint->SetEditHint(kAAFRelativeLeft)); checkResult(pVaryingValue->AddControlPoint(pControlPoint)); pControlPoint->Release(); pControlPoint = NULL; checkResult(defs.cdControlPoint()-> CreateInstance(IID_IAAFControlPoint, (IUnknown **)&pControlPoint)); checkResult(pControlPoint->Initialize (pVaryingValue, testTime2, sizeof(testLevel2), (aafDataBuffer_t)&testLevel2)); checkResult(pControlPoint->SetEditHint(kAAFProportional)); checkResult(pVaryingValue->AddControlPoint(pControlPoint)); pControlPoint->Release(); pControlPoint = NULL; checkResult(pVaryingValue->QueryInterface (IID_IAAFParameter, (void **)&pParm)); checkResult(pOperationGroup->AddParameter (pParm)); checkResult(pOperationGroup->AppendInputSegment (pFiller)); pFiller->Release(); pFiller = NULL; checkResult(pOperationGroup->SetBypassOverride (1)); checkResult(defs.cdSourceClip()-> CreateInstance(IID_IAAFSourceClip, (IUnknown **)&pSourceClip)); aafSourceRef_t sourceRef; sourceRef.sourceID = zeroMobID; sourceRef.sourceSlotID = 0; sourceRef.startTime = 0; checkResult(pSourceClip->Initialize (defs.ddkAAFPicture(), effectLen, sourceRef)); checkResult(pSourceClip->QueryInterface (IID_IAAFSourceReference, (void **)&pSourceRef)); checkResult(pOperationGroup->SetRender (pSourceRef)); checkResult(pOperationGroup->QueryInterface (IID_IAAFSegment, (void **)&pSeg)); checkResult(pMob->AppendNewTimelineSlot (videoRate, pSeg, test+1, slotNames[test], 0, &pSlot)); pSlot->Release(); pSlot = NULL; pSeg->Release(); pSeg = NULL; pOperationGroup->Release(); pOperationGroup = NULL; pParm->Release(); pParm = NULL; pVaryingValue->Release(); pVaryingValue = NULL; pComponent->Release(); pComponent = NULL; pSourceRef->Release(); pSourceRef = NULL; pSourceClip->Release(); pSourceClip = NULL; } // Add the mob to the file. checkResult(pHeader->AddMob(pMob)); } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if(pSourceRef) pSourceRef->Release(); if(pControlPoint) pControlPoint->Release(); if(pSourceClip) pSourceClip->Release(); if (pDefObject) pDefObject->Release(); if (pOperationGroup) pOperationGroup->Release(); if (pMob) pMob->Release(); if (pSeg) pSeg->Release(); if (pSlot) pSlot->Release(); if (pComponent) pComponent->Release(); if (pParm) pParm->Release(); // if (pIntDef) // pIntDef->Release(); if (pInterpDef) pInterpDef->Release(); if (pVaryingValue) pVaryingValue->Release(); if (pFiller) pFiller->Release(); if (pOperationDef) pOperationDef->Release(); if (pParamDef) pParamDef->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if(pMgr) pMgr->Release(); if(pTypeDef) pTypeDef->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 ReadAAFFile(aafWChar* pFileName) { IAAFFile* pFile = NULL; IAAFHeader* pHeader = NULL; IAAFDictionary* pDictionary = NULL; IEnumAAFCodecDefs *pPlug = NULL; IEnumAAFCodecDefs *pClonePlug = NULL; IAAFDefObject* pDef = NULL; IAAFCodecDef* pCodecDef = NULL; IAAFCodecDef* pArray[2] = { NULL, NULL }; IAAFCodecDef** pArrayDef = pArray; bool bFileOpen = false; HRESULT hr = S_OK; wchar_t testString[256]; aafUInt32 resultCount; 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)); checkResult(pDictionary->GetCodecDefs(&pPlug)); /* Read and check the first element */ checkResult(pPlug->NextOne(&pCodecDef)); checkResult(pCodecDef->QueryInterface (IID_IAAFDefObject, (void **)&pDef)); checkResult(pDef->GetName (testString, sizeof(testString))); checkExpression (wcscmp(testString, sName1) == 0, AAFRESULT_TEST_FAILED); pCodecDef->Release(); pCodecDef = NULL; pDef->Release(); pDef = NULL; /* Read and check the second element */ checkResult(pPlug->NextOne(&pCodecDef)); checkResult(pCodecDef->QueryInterface (IID_IAAFDefObject, (void **)&pDef)); checkResult(pDef->GetName (testString, sizeof(testString))); checkExpression (wcscmp(testString, sName2) == 0, AAFRESULT_TEST_FAILED); pCodecDef->Release(); pCodecDef = NULL; pDef->Release(); pDef = NULL; /* Reset, and check the first element again*/ checkResult(pPlug->Reset()); checkResult(pPlug->NextOne(&pCodecDef)); checkResult(pCodecDef->QueryInterface (IID_IAAFDefObject, (void **)&pDef)); checkResult(pDef->GetName (testString, sizeof(testString))); checkExpression (wcscmp(testString, sName1) == 0, AAFRESULT_TEST_FAILED); pCodecDef->Release(); pCodecDef = NULL; pDef->Release(); pDef = NULL; /* Reset, Skip, and check the second element again*/ checkResult(pPlug->Reset()); checkResult(pPlug->Skip(1)); checkResult(pPlug->NextOne(&pCodecDef)); checkResult(pCodecDef->QueryInterface (IID_IAAFDefObject, (void **)&pDef)); checkResult(pDef->GetName (testString, sizeof(testString))); checkExpression (wcscmp(testString, sName2) == 0, AAFRESULT_TEST_FAILED); pCodecDef->Release(); pCodecDef = NULL; pDef->Release(); pDef = NULL; /* Reset, and read both elements */ checkResult(pPlug->Reset()); checkResult(pPlug->Next (2, (IAAFCodecDef **)&pArray, &resultCount)); checkExpression (resultCount == 2, AAFRESULT_TEST_FAILED); checkResult(pArrayDef[0]->QueryInterface (IID_IAAFDefObject, (void **)&pDef)); checkResult(pDef->GetName (testString, sizeof(testString))); checkExpression (wcscmp(testString, sName1) == 0, AAFRESULT_TEST_FAILED); pDef->Release(); pDef = NULL; checkResult(pArrayDef[1]->QueryInterface (IID_IAAFDefObject, (void **)&pDef)); checkResult(pDef->GetName (testString, sizeof(testString))); checkExpression (wcscmp(testString, sName2) == 0, AAFRESULT_TEST_FAILED); pDef->Release(); pDef = NULL; pArrayDef[0]->Release(); pArrayDef[0] = NULL; pArrayDef[1]->Release(); pArrayDef[1] = NULL; /* Read one past to make sure that it fails */ checkExpression(pPlug->NextOne(&pCodecDef) != AAFRESULT_SUCCESS, AAFRESULT_TEST_FAILED); /* Clone the enumerator, and read one element */ checkResult(pPlug->Clone(&pClonePlug)); checkResult(pClonePlug->Reset()); checkResult(pClonePlug->NextOne(&pCodecDef)); checkResult(pCodecDef->QueryInterface (IID_IAAFDefObject, (void **)&pDef)); checkResult(pDef->GetName (testString, sizeof(testString))); checkExpression (wcscmp(testString, sName1) == 0, AAFRESULT_TEST_FAILED); pCodecDef->Release(); pCodecDef = NULL; pDef->Release(); pDef = NULL; } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pHeader) pHeader->Release(); if (pDictionary) pDictionary->Release(); if (pPlug) pPlug->Release(); if (pClonePlug) pClonePlug->Release(); if (pDef) pDef->Release(); if (pCodecDef) pCodecDef->Release(); if (pArray[0]) pArray[0]->Release(); if (pArray[1]) pArray[1]->Release(); if (pFile) { // Close file if (bFileOpen) pFile->Close(); pFile->Release(); } return hr; }
static HRESULT CreateAAFFile(const aafWChar * pFileName, testDataFile_t *dataFile, testType_t testType, IAAFFile ** ppFile) { 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; int i; 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 IN MEMORY */ check(AAFFileOpenNewModifyEx (pFileName, &kAAFFileKind_Aaf4KBinary, 0, &ProductInfo, ppFile)); pFile=*ppFile; 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 */ // note that there is only one iteration at present because of // a bug in essenceaccess which prevents this functioning... for (i = 0; i<1; i++) { // 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)); // 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 totalNumberSamples = dataLen * 5; // arbitrarily set to write 5 copies of audio sequentially aafInt32 samplesLeft = totalNumberSamples; while (samplesLeft >0) { check(pEssenceAccess->WriteSamples( dataLen, //!!! hardcoded bytes/sample ==1// Number of Samples sizeof(dataBuff), // buffer size dataPtr, // THE data &samplesWritten, &bytesWritten)); samplesLeft=samplesLeft-dataLen; } // 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; if(pDictionary) pDictionary->Release(); pDictionary = NULL; if(pHeader) pHeader->Release(); pHeader = 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(); return moduleErrorTmp; }
static HRESULT ReadAAFFile(aafWChar * pFileName) { IAAFFile *pFile = NULL; bool bFileOpen = false; IAAFHeader *pHeader = NULL; IEnumAAFMobs *mobIter = NULL; IAAFMob *aMob = NULL; IEnumAAFMobSlots *slotIter = NULL; IAAFMobSlot *slot = NULL; aafNumSlots_t numMobs, n, s; HRESULT hr = S_OK; IAAFMobSlot* pArray[2] = { NULL, NULL }; IAAFMobSlot** pArrayDef = pArray; aafUInt32 resultCount; IEnumAAFMobSlots *slotClone = NULL; try { // Open the file checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); bFileOpen = true; // We can't really do anthing in AAF without the header. checkResult(pFile->GetHeader(&pHeader)); checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED); aafSearchCrit_t criteria; criteria.searchTag = kAAFNoSearch; checkResult(pHeader->GetMobs (&criteria, &mobIter)); for(n = 0; n < numMobs; n++) { aafWChar name[500], slotName[500]; aafNumSlots_t numSlots; aafMobID_t mobID; aafSlotID_t trackID; checkResult(mobIter->NextOne (&aMob)); checkResult(aMob->GetName (name, sizeof(name))); checkResult(aMob->GetMobID (&mobID)); checkResult(aMob->CountSlots (&numSlots)); checkExpression(5 == numSlots, AAFRESULT_TEST_FAILED); checkResult(aMob->GetSlots(&slotIter)); /* Read and check all elements using NextOne */ for(s = 0; s < numSlots; s++) { checkResult(slotIter->NextOne (&slot)); checkResult(slot->GetName (slotName, sizeof(slotName))); checkResult(slot->GetSlotID(&trackID)); checkExpression (wcscmp(slotName, slotNames[s]) == 0, AAFRESULT_TEST_FAILED); slot->Release(); slot = NULL; } /* Read one past to make sure that it fails */ checkExpression(slotIter->NextOne(&slot) != AAFRESULT_SUCCESS, AAFRESULT_TEST_FAILED); /* Reset, and check the first element again*/ checkResult(slotIter->Reset()); checkResult(slotIter->NextOne (&slot)); checkResult(slot->GetName (slotName, sizeof(slotName))); checkResult(slot->GetSlotID(&trackID)); checkExpression (wcscmp(slotName, slotNames[0]) == 0, AAFRESULT_TEST_FAILED); slot->Release(); slot = NULL; /* Reset, Skip, and check the second element again*/ checkResult(slotIter->Reset()); checkResult(slotIter->Skip(1)); checkResult(slotIter->NextOne (&slot)); checkResult(slot->GetName (slotName, sizeof(slotName))); checkResult(slot->GetSlotID(&trackID)); checkExpression (wcscmp(slotName, slotNames[1]) == 0, AAFRESULT_TEST_FAILED); slot->Release(); slot = NULL; /* Reset, and read both elements */ checkResult(slotIter->Reset()); checkResult(slotIter->Next (2, (IAAFMobSlot **)&pArray, &resultCount)); checkExpression (resultCount == 2, AAFRESULT_TEST_FAILED); checkResult(pArrayDef[0]->GetName (slotName, sizeof(slotName))); checkResult(pArrayDef[0]->GetSlotID(&trackID)); checkExpression (wcscmp(slotName, slotNames[0]) == 0, AAFRESULT_TEST_FAILED); checkResult(pArrayDef[1]->GetName (slotName, sizeof(slotName))); checkResult(pArrayDef[1]->GetSlotID(&trackID)); checkExpression (wcscmp(slotName, slotNames[1]) == 0, AAFRESULT_TEST_FAILED); pArrayDef[0]->Release(); pArrayDef[0] = NULL; pArrayDef[1]->Release(); pArrayDef[1] = NULL; /* Clone the enumerator, and read one element */ checkResult(slotIter->Clone(&slotClone)); checkResult(slotClone->Reset()); checkResult(slotClone->NextOne (&slot)); checkResult(slot->GetName (slotName, sizeof(slotName))); checkResult(slot->GetSlotID(&trackID)); checkExpression (wcscmp(slotName, slotNames[0]) == 0, AAFRESULT_TEST_FAILED); slot->Release(); slot = NULL; slotIter->Release(); slotIter = NULL; slotClone->Release(); slotClone = NULL; aMob->Release(); aMob = NULL; } } catch (HRESULT& rResult) { hr = rResult; } // Cleanup object references if (slot) slot->Release(); if (slotIter) slotIter->Release(); if (aMob) aMob->Release(); if (mobIter) mobIter->Release(); if (pHeader) pHeader->Release(); if (pFile) { // Close file if (bFileOpen) pFile->Close(); pFile->Release(); } return hr; }