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; IEnumAAFLocators * pCloneEnum = NULL; IAAFLocator * pLocator = NULL; aafUInt32 numLocators; aafNumSlots_t numMobs, n; HRESULT hr = AAFRESULT_SUCCESS; bool bFileOpen = false; wchar_t testname[256]; IAAFLocator * pArray[2] = { NULL, NULL }; IAAFLocator ** pArrayPoint = pArray; aafUInt32 resultCount; 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 two locators checkResult(pEdesc->CountLocators(&numLocators)); checkExpression(2 == numLocators, AAFRESULT_TEST_FAILED); checkResult(pEdesc->GetLocators(&pEnum)); /* Read and check the first element */ checkResult(pEnum->NextOne(&pLocator)); checkResult(pLocator->GetPath (testname, sizeof(testname))); checkExpression(wcscmp(testname, locator1) == 0, AAFRESULT_TEST_FAILED); pLocator->Release(); pLocator = NULL; /**/ /* Read and check the second element */ checkResult(pEnum->NextOne(&pLocator)); checkResult(pLocator->GetPath (testname, sizeof(testname))); checkExpression(wcscmp(testname, locator2) == 0, AAFRESULT_TEST_FAILED); pLocator->Release(); pLocator = NULL; /*****/ /* Reset, and check the first element again*/ checkResult(pEnum->Reset()); checkResult(pEnum->NextOne(&pLocator)); checkResult(pLocator->GetPath (testname, sizeof(testname))); checkExpression(wcscmp(testname, locator1) == 0, AAFRESULT_TEST_FAILED); pLocator->Release(); pLocator = NULL; /* Reset, Skip, and check the second element again*/ checkResult(pEnum->Reset()); checkResult(pEnum->Skip(1)); checkResult(pEnum->NextOne(&pLocator)); checkResult(pLocator->GetPath (testname, sizeof(testname))); checkExpression(wcscmp(testname, locator2) == 0, AAFRESULT_TEST_FAILED); pLocator->Release(); pLocator = NULL; /* Reset, and read both elements */ checkResult(pEnum->Reset()); checkResult(pEnum->Next (2, (IAAFLocator **)&pArray, &resultCount)); checkExpression (resultCount == 2, AAFRESULT_TEST_FAILED); checkResult(pArrayPoint[0]->GetPath (testname, sizeof(testname))); checkExpression(wcscmp(testname, locator1) == 0, AAFRESULT_TEST_FAILED); pArrayPoint[0]->Release(); pArrayPoint[0] = NULL; checkResult(pArrayPoint[1]->GetPath (testname, sizeof(testname))); checkExpression(wcscmp(testname, locator2) == 0, AAFRESULT_TEST_FAILED); pArrayPoint[1]->Release(); pArrayPoint[1] = NULL; /* Read one past to make sure that it fails */ checkExpression(pEnum->NextOne(&pLocator) != AAFRESULT_SUCCESS, AAFRESULT_TEST_FAILED); /* Clone the enumerator, and read one element */ checkResult(pEnum->Clone(&pCloneEnum)); checkResult(pCloneEnum->Reset()); checkResult(pCloneEnum->NextOne(&pLocator)); checkResult(pLocator->GetPath (testname, sizeof(testname))); checkExpression(wcscmp(testname, locator1) == 0, AAFRESULT_TEST_FAILED); pLocator->Release(); pLocator = NULL; pEnum->Release(); pEnum = NULL; pEdesc->Release(); pEdesc = NULL; pSourceMob->Release(); pSourceMob = NULL; aMob->Release(); aMob = NULL; pCloneEnum->Release(); pCloneEnum = 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 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 ReadAAFFile(aafWChar * pFileName) { IAAFFile * pFile = NULL; IAAFHeader * pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFSourceMob* pSourceMob = NULL; IAAFMob* pMob = NULL; IAAFEssenceDescriptor* pEssDesc = NULL; IAAFBWFImportDescriptor* pBWFImportDesc = NULL; IEnumAAFRIFFChunks* pEnum = NULL; IAAFRIFFChunk* pRIFFChunk = NULL; IAAFRIFFChunk* pRIFFChunkTest = NULL; IEnumAAFMobs* pMobIter = NULL; aafUInt32 numData, bytesRead, com, testNum; aafLength_t testRIFFLen; aafNumSlots_t numMobs; char Value[sizeof(RIFFChunksmiley)]; char Value2[sizeof(RIFFChunkfrowney)]; HRESULT hr = AAFRESULT_SUCCESS; wchar_t testString[256]; checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); checkResult( pFile->GetHeader(&pHeader)); // Get the AAF Dictionary so that we can create a fake RIFFChunk to test RemoveUnknownBWFChunks. checkResult(pHeader->GetDictionary(&pDictionary)); CAAFBuiltinDefs defs (pDictionary); checkResult(defs.cdRIFFChunk()->CreateInstance(IID_IAAFRIFFChunk, (IUnknown **)&pRIFFChunkTest)); checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); if (1 == numMobs ) { checkResult(pHeader->GetMobs(NULL, &pMobIter)); checkResult(pMobIter->NextOne(&pMob)); checkResult(pMob->QueryInterface(IID_IAAFSourceMob, (void **)&pSourceMob)); // Back into testing mode checkResult(pSourceMob->GetEssenceDescriptor(&pEssDesc)); checkResult( pEssDesc->QueryInterface( IID_IAAFBWFImportDescriptor, (void**)&pBWFImportDesc )); checkResult(pBWFImportDesc->GetFileSecurityReport(&testNum)); checkExpression(testNum==TEST_FileSecurityReport, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetFileSecurityWave(&testNum)); checkExpression(testNum==TEST_FileSecurityWave, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetCodingHistory(testString, sizeof(testString))); checkExpression(wcscmp(testString, TEST_CodingHistory) == 0, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetBasicData(testString, sizeof(testString))); checkExpression(wcscmp(testString, TEST_BasicData) == 0, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetStartOfModulation(testString, sizeof(testString))); checkExpression(wcscmp(testString, TEST_StartOfModulation) == 0, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetQualityEvent(testString, sizeof(testString))); checkExpression(wcscmp(testString, TEST_QualityEvent) == 0, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetEndOfModulation(testString, sizeof(testString))); checkExpression(wcscmp(testString, TEST_EndOfModulation) == 0, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetQualityParameter(testString, sizeof(testString))); checkExpression(wcscmp(testString, TEST_QualityParameter) == 0, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetOperatorComment(testString, sizeof(testString))); checkExpression(wcscmp(testString, TEST_OperatorComment) == 0, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetCueSheet(testString, sizeof(testString))); checkExpression(wcscmp(testString, TEST_CueSheet) == 0, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->CountUnknownBWFChunks(&numData)); checkExpression(2 == numData, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetUnknownBWFChunks(&pEnum)); for(com = 0; com < numData; com++) { checkResult(pEnum->NextOne(&pRIFFChunk)); pRIFFChunk->GetLength(&testRIFFLen); checkExpression(testRIFFLen!=chunkLength /*huh?*/, AAFRESULT_TEST_FAILED); checkResult(pRIFFChunk->GetLength(&testRIFFLen)); pRIFFChunk->GetChunkID(&testNum); if (testNum==1){ checkExpression(sizeof(RIFFChunksmiley) == testRIFFLen, AAFRESULT_TEST_FAILED); checkResult(pRIFFChunk->Read( sizeof(Value), (unsigned char *)Value, &bytesRead)); checkExpression(memcmp(Value, RIFFChunksmiley, sizeof(RIFFChunksmiley)) == 0, AAFRESULT_TEST_FAILED); } else if (testNum==2){ checkExpression(sizeof(RIFFChunkfrowney) == testRIFFLen, AAFRESULT_TEST_FAILED); checkResult(pRIFFChunk->Read( sizeof(Value2), (unsigned char *)Value2, &bytesRead)); checkExpression(memcmp(Value2, RIFFChunkfrowney, sizeof(RIFFChunkfrowney)) == 0, AAFRESULT_TEST_FAILED); } pRIFFChunk->Release(); pRIFFChunk = NULL; } checkResult(pEnum->Reset()); checkResult(pEnum->NextOne(&pRIFFChunk)); checkExpression((pBWFImportDesc->RemoveUnknownBWFChunkAt(2))==AAFRESULT_BADINDEX, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->RemoveUnknownBWFChunkAt(0)); checkResult(pBWFImportDesc->CountUnknownBWFChunks(&numData)); checkExpression(1 == numData, AAFRESULT_TEST_FAILED); pRIFFChunk->Release(); pRIFFChunk = NULL; pEnum->Release(); pEnum = NULL; pBWFImportDesc->Release(); pBWFImportDesc = NULL; pEssDesc->Release(); pEssDesc = NULL; pSourceMob->Release(); pSourceMob = NULL; pMobIter->Release(); pMobIter = NULL; } pRIFFChunkTest->Release(); pRIFFChunkTest = NULL; pMob->Release(); pMob = NULL; pHeader->Release(); pHeader = NULL; pDictionary->Release(); pDictionary = NULL; pFile->Close(); pFile->Release(); pFile = NULL; return hr; }
static HRESULT ReadAAFFile(const aafWChar * pFileName, testType_t testType) { IAAFFile * pFile = NULL; IAAFHeader * pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFEssenceAccess* pEssenceAccess = NULL; IAAFEssenceMultiAccess* pMultiEssence = NULL; IAAFEssenceFormat *fmtTemplate = NULL; IEnumAAFMobs* pMobIter = NULL; IAAFMob* pMob = NULL; IAAFMasterMob* pMasterMob = NULL; IAAFEssenceFormat* pFormat = NULL; aafNumSlots_t numMobs, numSlots; aafSearchCrit_t criteria; aafRational_t readSampleRate; aafMobID_t mobID; aafWChar namebuf[1204]; unsigned char AAFDataBuf[4096]; aafUInt32 AAFBytesRead, samplesRead; FILE* pWavFile = NULL; unsigned char WAVDataBuf[4096], *dataPtr; size_t WAVBytesRead; aafUInt32 dataOffset, dataLen; aafUInt16 bitsPerSample, numCh; check(AAFFileOpenExistingRead ( pFileName, 0, &pFile)); check(pFile->GetHeader(&pHeader)); // Get the AAF Dictionary so that we can create valid AAF objects. check(pHeader->GetDictionary(&pDictionary)); // Here we check on the number of mobs in the file. // Get the number of master mobs in the file (should be one) check(pHeader->CountMobs(kAAFMasterMob, &numMobs)); // ** causes leak if (1 == numMobs ) { 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]; 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); // Make sure we have two slots check(pMob->CountSlots(&numSlots)); if (2 == numSlots) { // The essence data is in SlotID 1 // Get a Master Mob interface check(pMob->QueryInterface(IID_IAAFMasterMob, (void **)&pMasterMob)); // Open the Essence Data check(pMasterMob->OpenEssence( 1, // SlotID 1 NULL, // mediaCriteria (Don't care) kAAFMediaOpenReadOnly, // Open mode kAAFCompressionDisable,// Compress disabled &pEssenceAccess)); // Open and read the Wave file (for comparison) pWavFile = fopen("Laser.wav", "r"); if (pWavFile) { // read in the essence data WAVBytesRead = fread(WAVDataBuf, sizeof(unsigned char), sizeof(WAVDataBuf), pWavFile); fclose(pWavFile); pWavFile = NULL; check(loadWAVEHeader(WAVDataBuf, &bitsPerSample, &numCh, &readSampleRate, &dataOffset, &dataLen)); dataPtr = WAVDataBuf + dataOffset; aafUInt32 sampleBits; aafInt32 bytesRead; check(pEssenceAccess->GetEmptyFileFormat (&fmtTemplate)); check(fmtTemplate->AddFormatSpecifier (kAAFAudioSampleBits, 0, NULL)); check(pEssenceAccess->GetFileFormat (fmtTemplate, &pFormat)); fmtTemplate->Release(); fmtTemplate = NULL; check(pFormat->GetFormatSpecifier (kAAFAudioSampleBits, sizeof(sampleBits), (aafDataBuffer_t)&sampleBits, &bytesRead)); pFormat->Release(); pFormat = NULL; if(sampleBits != bitsPerSample) { printf("***Wrong sample size read ( was %d , should be %d)\n", sampleBits, bitsPerSample); } // Read the Data from the AAF file if(testType == testStandardCalls) { check(pEssenceAccess->ReadSamples( dataLen, //!!! Hardcoded // Number of Samples sizeof(AAFDataBuf), // Maximum buffer size AAFDataBuf, // Buffer for the data &samplesRead, // Actual number of samples read &AAFBytesRead)); // Actual number of bytes read } else if(testType == testMultiCalls) { aafmMultiXfer_t xfer; aafmMultiResult_t result; check(pEssenceAccess->QueryInterface(IID_IAAFEssenceMultiAccess, (void **)&pMultiEssence)); xfer.numSamples = dataLen; //!!! Hardcoded // Number of Samples xfer.buflen = sizeof(AAFDataBuf); xfer.buffer = AAFDataBuf; result.bytesXfered = 0; check(pMultiEssence->ReadMultiSamples(1, &xfer, &result)); samplesRead = result.samplesXfered; AAFBytesRead = result.bytesXfered; pMultiEssence->Release(); pMultiEssence = NULL; } // Now compare the data read from the AAF file to the actual WAV file if (dataLen != AAFBytesRead) { printf("***Wrong number of bytes read (was %u , should be %zu)\n", AAFBytesRead, WAVBytesRead); } if (memcmp( dataPtr, AAFDataBuf, dataLen) != 0) { printf("*** Data Read is different than the data in the WAV file ***\n"); } } else { printf("***Failed to open Wave file Laser.wav for comparison\n"); } } else { printf("***Wrong number of slots in the Master Mob (was %d should be %d)\n", numSlots, 2); } if (pMasterMob) { pMasterMob->Release(); pMasterMob = NULL; } pMob->Release(); pMob = NULL; if (pEssenceAccess) { pEssenceAccess->Release(); pEssenceAccess = NULL; } } // while pMobIter->NextOne pMobIter->Release(); pMobIter = NULL; } else { printf("***Wrong number of Master mobs in the file (was %d should be %d)\n", numMobs, 1); } printf("--------\n"); cleanup: // Cleanup and return if (pWavFile) fclose(pWavFile); if (pMultiEssence) pMultiEssence->Release(); pMultiEssence=NULL; if(fmtTemplate) { fmtTemplate->Release(); fmtTemplate = NULL; } if (pEssenceAccess) { pEssenceAccess->Release(); pEssenceAccess = NULL; } if (pDictionary) pDictionary->Release(); pDictionary=NULL; if (pHeader) pHeader->Release(); pHeader=NULL; if (pMobIter) pMobIter->Release(); pMobIter=NULL; if (pFormat) pFormat->Release(); pFormat=NULL; if (pFile) { pFile->Close(); pFile->Release(); pFile=NULL; } return moduleErrorTmp; }
static HRESULT ReadAAFFile(aafWChar * pFileName) { IAAFFile* pFile = NULL; IAAFHeader* pHeader = NULL; IEnumAAFMobs* pMobIter = NULL; IAAFMob* pMob = NULL; IAAFSourceMob* pSourceMob = NULL; IAAFEssenceDescriptor* pEssDesc = NULL; IAAFDataEssenceDescriptor* pDataEssenceDesc = NULL; aafNumSlots_t numMobs = 0; aafUID_t dataEssenceCoding, dataEssTestVal; HRESULT hr = AAFRESULT_SUCCESS; try { memset(&dataEssTestVal, 0, sizeof(aafUID_t)); // Open the AAF file checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); // Get the AAF file header. checkResult(pFile->GetHeader(&pHeader)); checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED); checkResult(pHeader->GetMobs(NULL, &pMobIter)); checkResult(pMobIter->NextOne(&pMob)); checkResult(pMob->QueryInterface(IID_IAAFSourceMob, (void **)&pSourceMob)); // Back into testing mode checkResult(pSourceMob->GetEssenceDescriptor(&pEssDesc)); // if there is an Essence Descriptor then it MUST be an (essence) DataEssence Descriptor checkResult(pEssDesc->QueryInterface(IID_IAAFDataEssenceDescriptor, (void **) &pDataEssenceDesc)); checkResult(pDataEssenceDesc->GetDataEssenceCoding(&dataEssenceCoding)); checkExpression(memcmp(&dataEssenceCoding, &dataEssTestVal, sizeof(aafUID_t)) == 0, AAFRESULT_TEST_FAILED); } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pDataEssenceDesc) pDataEssenceDesc->Release(); if (pEssDesc) pEssDesc->Release(); if (pSourceMob) pSourceMob->Release(); if (pMob) pMob->Release(); if (pMobIter) pMobIter->Release(); if (pHeader) pHeader->Release(); if (pFile) { pFile->Close(); pFile->Release(); } return hr; }
static HRESULT ReadAAFFile(aafWChar * pFileName ) { HRESULT hr = AAFRESULT_SUCCESS; IAAFFile * pFile = NULL; IAAFHeader * pHeader = NULL; IEnumAAFMobs* pMobIter = NULL; IAAFCompositionMob * pCMob = NULL; IAAFMob* pMob = NULL; bool bFileOpen = false; aafNumSlots_t numMobs; IAAFObject* pObj = NULL; IEnumAAFProperties * pEnum = NULL; IAAFProperty *pProp = NULL; IAAFPropertyDef* pPropDef = NULL; IAAFPropertyValue* pPropVal = NULL; IAAFTypeDef* pTypeDef = 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)); // Validate that there is only one composition mob. checkResult(pHeader->CountMobs(kAAFCompMob, &numMobs)); checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED); // Enumerate over all Composition Mobs aafSearchCrit_t criteria; criteria.searchTag = kAAFByMobKind; criteria.tags.mobKind = kAAFCompMob; checkResult(pHeader->GetMobs(&criteria, &pMobIter)); while (AAFRESULT_SUCCESS == pMobIter->NextOne(&pMob)) { //Get the Composition mob checkResult (pMob->QueryInterface (IID_IAAFCompositionMob, (void **) &pCMob)); //Get the Object checkResult (pCMob->QueryInterface (IID_IAAFObject, (void **) &pObj)); //From the Object, we can get the properties .... aafUInt32 propCount = 0; checkResult (pObj->CountProperties (&propCount)); //A composition should have at least 5 properties ... checkExpression(propCount>=5, AAFRESULT_TEST_FAILED); //Get Enumeration over properties checkResult (pObj->GetProperties (&pEnum)); checkExpression (pEnum != 0, AAFRESULT_TEST_FAILED); while (propCount--) { //Check for property validity checkResult (pEnum->NextOne (&pProp)); checkExpression (pProp != NULL, AAFRESULT_TEST_FAILED); //Now call prop methods //1. Get Definition checkResult( pProp->GetDefinition(&pPropDef) ); //2. Get Value checkResult( pProp->GetValue(&pPropVal) ); //deal with prop value checkResult( pPropVal->GetType(&pTypeDef) ); //From propval, get the typedef!!!!!!!!!!!!!!!!!!!!! IAAFTypeDefSP spTypeDef; checkResult( pPropVal->GetType(&spTypeDef) ); //get category eAAFTypeCategory_t typeCat = kAAFTypeCatUnknown; checkResult (spTypeDef->GetTypeCategory(&typeCat)); //make sure it is not unknown checkExpression(kAAFTypeCatUnknown != typeCat, AAFRESULT_TEST_FAILED); //Deal with our Name String .... if (typeCat == kAAFTypeCatString) { IAAFTypeDefStringSP spTypeDefString; checkResult( spTypeDef->QueryInterface(IID_IAAFTypeDefString, (void**)&spTypeDefString) ); aafUInt32 bufSize = //don't forget the NULL char, and factoring in the size of a wchar (wcslen(TEST_NAME)+1) * sizeof(aafCharacter); aafCharacter *nameBuf = new aafCharacter[bufSize]; checkResult( spTypeDefString->GetElements(pPropVal, (aafMemPtr_t)nameBuf, bufSize) ); checkExpression( wcscmp(TEST_NAME, nameBuf) == 0, AAFRESULT_TEST_FAILED ); delete [] nameBuf; } //Done ........... //release typedef pTypeDef->Release(); //release defintion + value pPropDef->Release(); pPropVal->Release(); //release this prop pProp->Release(); pProp = NULL; }//while prop count }//while mob iter }//try catch (HRESULT & rResult) { hr = rResult; } //Release the rest ... if (pEnum) pEnum->Release(); if (pObj) pObj->Release(); if (pCMob) pCMob->Release(); if (pMob) pMob->Release(); if (pMobIter) pMobIter->Release(); if (pHeader) pHeader->Release(); if (pFile) { if (bFileOpen) pFile->Close(); pFile->Release(); } return hr; }
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; IAAFSequence *pSequence = 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 number of mobs to force creation of the content storage. // This is temporary as the content storage should be created by // the call to OpenNewModify above. aafNumSlots_t n; checkResult(pHeader->CountMobs(kAAFAllMob, &n)); // Get the AAF Dictionary so that we can create valid AAF objects. checkResult(pHeader->GetDictionary(&pDictionary)); // Create a sequence withou attaching it to the file. checkResult(CreateAAFSequence(pDictionary, &pSequence)); // Test the enumeration methods. checkResult(TestEnumerator(pSequence)); } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pSequence) pSequence->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; 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; }
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 ReadAAFFile(aafWChar * pFileName) { IAAFFile * pFile = NULL; bool bFileOpen = false; IAAFHeader * pHeader = NULL; IEnumAAFMobs *mobIter = NULL; IAAFMob *aMob = NULL; IEnumAAFMobSlots *slotIter = NULL; IEnumAAFTaggedValues* pCommentIterator = NULL; IAAFTaggedValue* pComment = NULL; IAAFMobSlot *slot = NULL; aafNumSlots_t numMobs, n, slt; aafUInt32 numComments, bytesRead, com; HRESULT hr = S_OK; aafWChar tag[64]; aafWChar Value[64]; aafSearchCrit_t criteria; 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)); criteria.searchTag = kAAFByMobKind; criteria.tags.mobKind = kAAFCompMob; checkResult(pHeader->CountMobs(kAAFCompMob, &numMobs)); checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED); 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)); // Check for comments checkResult(aMob->CountComments(&numComments)); checkExpression(1 == numComments, AAFRESULT_TEST_FAILED); checkResult(aMob->GetComments(&pCommentIterator)); for(com = 0; com < numComments; com++) { checkResult(pCommentIterator->NextOne(&pComment)); checkResult(pComment->GetName(tag, sizeof(tag))); checkResult(pComment->GetValue( sizeof(Value), (unsigned char *)Value, &bytesRead)); checkExpression(wcscmp(tag, TagNames)== 0, AAFRESULT_TEST_FAILED); checkExpression(wcscmp(Value, AltComment)== 0, AAFRESULT_TEST_FAILED); pComment->Release(); } pCommentIterator->Release(); checkResult(aMob->CountSlots (&numSlots)); checkExpression(5 == numSlots, AAFRESULT_TEST_FAILED); checkResult(aMob->GetSlots(&slotIter)); for(slt = 0; slt < numSlots; slt++) { checkResult(slotIter->NextOne (&slot)); checkResult(slot->GetName (slotName, sizeof(slotName))); checkResult(slot->GetSlotID(&trackID)); checkExpression (wcscmp(slotName, slotNames[slt]) == 0, AAFRESULT_TEST_FAILED); slot->Release(); slot = 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; }
static HRESULT ReadAAFFile(aafWChar * pFileName) { IAAFFile * pFile = NULL; IAAFHeader * pHeader = NULL; IAAFSourceMob* pSourceMob = NULL; IAAFMob* pMob = NULL; IAAFEssenceDescriptor* pEssDesc = NULL; IAAFBWFImportDescriptor* pBWFImportDesc = NULL; IEnumAAFRIFFChunks* pEnum = NULL; IAAFRIFFChunk* pRIFFChunk = NULL; IEnumAAFMobs* pMobIter = NULL; aafUInt32 numData, bytesRead, com, testID; aafLength_t testLength, testRIFFLen; aafPosition_t dataPos; aafNumSlots_t numMobs; char Value[sizeof(RIFFChunksmiley)]; char Value2[sizeof(RIFFChunkfrowney)]; HRESULT hr = AAFRESULT_SUCCESS; checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); checkResult( pFile->GetHeader(&pHeader)); checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); if (1 == numMobs ) { checkResult(pHeader->GetMobs(NULL, &pMobIter)); checkResult(pMobIter->NextOne(&pMob)); checkResult(pMob->QueryInterface(IID_IAAFSourceMob, (void **)&pSourceMob)); // Back into testing mode checkResult(pSourceMob->GetEssenceDescriptor(&pEssDesc)); checkResult( pEssDesc->QueryInterface( IID_IAAFBWFImportDescriptor, (void**)&pBWFImportDesc )); checkResult(pBWFImportDesc->CountUnknownBWFChunks(&numData)); checkExpression(1 == numData, AAFRESULT_TEST_FAILED); checkResult(pBWFImportDesc->GetUnknownBWFChunks(&pEnum)); for(com = 0; com < numData; com++) { checkResult(pEnum->NextOne(&pRIFFChunk)); checkResult(pRIFFChunk->GetLength(&testRIFFLen)); checkExpression((sizeof(RIFFChunksmiley)+sizeof(RIFFChunkfrowney)) == testRIFFLen, AAFRESULT_TEST_FAILED); checkResult(pRIFFChunk->Read( sizeof(Value), (unsigned char *)Value, &bytesRead)); checkExpression(memcmp(Value, RIFFChunksmiley, sizeof(RIFFChunksmiley)) == 0, AAFRESULT_TEST_FAILED); checkResult(pRIFFChunk->Read( sizeof(Value2), (unsigned char *)Value2, &bytesRead)); checkExpression(memcmp(Value2, RIFFChunkfrowney, sizeof(RIFFChunkfrowney)) == 0, AAFRESULT_TEST_FAILED); checkResult(pRIFFChunk->GetPosition(&dataPos)); checkExpression(dataPos==(sizeof(RIFFChunksmiley)+sizeof(RIFFChunkfrowney)), AAFRESULT_TEST_FAILED); checkResult(pRIFFChunk->SetPosition(0)); checkResult(pRIFFChunk->Read( sizeof(Value), (unsigned char *)Value, &bytesRead)); checkExpression(memcmp(Value, RIFFChunksmiley, sizeof(RIFFChunksmiley)) == 0, AAFRESULT_TEST_FAILED); pRIFFChunk->GetChunkID(&testID); checkExpression(testID==chunkID, AAFRESULT_TEST_FAILED); pRIFFChunk->GetLength(&testLength); checkExpression(testLength == sizeof(RIFFChunksmiley) + sizeof(RIFFChunkfrowney), AAFRESULT_TEST_FAILED); pRIFFChunk->Release(); pRIFFChunk = NULL; } pEnum->Release(); pEnum = NULL; pEssDesc->Release(); pEssDesc = NULL; pBWFImportDesc->Release(); pBWFImportDesc = NULL; pSourceMob->Release(); pSourceMob = NULL; pMobIter->Release(); pMobIter = NULL; } pMob->Release(); pMob = NULL; pHeader->Release(); pHeader = NULL; pFile->Close(); pFile->Release(); pFile = NULL; return hr; }
static HRESULT ReadAAFFile(aafWChar * pFileName) { // IAAFSession * pSession = NULL; IAAFFile * pFile = NULL; IAAFHeader * pHeader = NULL; IEnumAAFMobs* pMobIter = NULL; IAAFMob* pMob = NULL; IAAFMob* pReferencedMob = NULL; IEnumAAFMobSlots* pSlotIter = NULL; IAAFMobSlot* pSlot = NULL; IAAFSegment* pSegment = NULL; IAAFDescriptiveClip* pDescClip = NULL; bool bFileOpen = false; aafSearchCrit_t criteria; aafNumSlots_t numMobs, numSlots; HRESULT hr = AAFRESULT_SUCCESS; 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(2 == numMobs, AAFRESULT_TEST_FAILED); // Enumerate over all Composition Mobs criteria.searchTag = kAAFByMobKind; criteria.tags.mobKind = kAAFCompMob; checkResult(pHeader->GetMobs(&criteria, &pMobIter)); while (AAFRESULT_SUCCESS == pMobIter->NextOne(&pMob)) { checkResult(pMob->CountSlots(&numSlots)); checkExpression(1 == numSlots, AAFRESULT_TEST_FAILED); checkResult(pMob->GetSlots(&pSlotIter)); while (AAFRESULT_SUCCESS == pSlotIter->NextOne(&pSlot)) { // The segment should be a source clip... checkResult(pSlot->GetSegment(&pSegment)); checkResult(pSegment->QueryInterface(IID_IAAFDescriptiveClip, (void **) &pDescClip)); // Get, and test, the described slots from the marker. aafUInt32 getDescribedSlotIDsVector[TestDescribedSlotIDsVectorSize]; aafUInt32 getDescribedSlotIDsVectorSize = 0; checkResult( pDescClip->CountDescribedSlotIDs( &getDescribedSlotIDsVectorSize ) ); checkExpression( TestDescribedSlotIDsVectorSize == getDescribedSlotIDsVectorSize, AAFRESULT_TEST_FAILED ); checkExpression( AAFRESULT_SMALLBUF == pDescClip->GetDescribedSlotIDs( getDescribedSlotIDsVectorSize-1, getDescribedSlotIDsVector ), AAFRESULT_TEST_FAILED ); checkResult( pDescClip->GetDescribedSlotIDs( getDescribedSlotIDsVectorSize, getDescribedSlotIDsVector ) ); checkExpression( 0 == memcmp( getDescribedSlotIDsVector, TestDescribedSlotIDsVector, sizeof(TestDescribedSlotIDsVector) ), AAFRESULT_TEST_FAILED ); pSlot->Release(); pSlot = NULL; } pMob->Release(); pMob = NULL; } } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pReferencedMob) pReferencedMob->Release(); if (pDescClip) pDescClip->Release(); if (pSegment) pSegment->Release(); if (pSlot) pSlot->Release(); if (pSlotIter) pSlotIter->Release(); if (pMob) pMob->Release(); if (pMobIter) pMobIter->Release(); if (pHeader) pHeader->Release(); if (pFile) { 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 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 ProcessAAFFile(const aafWChar * pFileName, testType_t testType) { IAAFFile * pFile = NULL; IAAFHeader * pHeader = NULL; IAAFDictionary* pDictionary = NULL; IEnumAAFMobs* pMobIter = NULL; aafNumSlots_t numMobs, numSlots; aafSearchCrit_t criteria; aafMobID_t mobID; aafWChar namebuf[1204]; const aafWChar* slotName = L"A slot in Composition Mob"; IAAFComponent* pComponent = NULL; IAAFComponent* aComponent = NULL; IEnumAAFMobSlots* pMobSlotIter = NULL; IAAFMobSlot* pMobSlot = NULL; IAAFTimelineMobSlot* newSlot = NULL; IAAFSegment* seg = NULL; IAAFSegment* pSegment = NULL; IAAFMob* pCompMob = NULL; IAAFMob* pMob = NULL; aafPosition_t zeroPos = 0; IAAFSequence* pAudioSequence = NULL; IAAFSourceClip* pSourceClip = NULL; aafLength_t duration; IAAFTimelineMobSlot* pTimelineMobSlot = NULL; IAAFClassDef *pCompositionMobDef = NULL; IAAFClassDef *pSequenceDef = NULL; IAAFClassDef *pSourceClipDef = NULL; IAAFDataDef *pSoundDef = NULL; IAAFDataDef *pDataDef = NULL; // Set the edit rate information aafRational_t editRate; editRate.numerator = 48000; editRate.denominator = 1; // Set search condition to true bool lookingForAudio = true; // Call the routine (from ExportAudioExample) to make the file for processing check(CreateAAFFile(pwFileName, NULL, testStandardCalls, &pFile)); /* Get the Header and iterate through the Master Mobs in the existing file */ check(pFile->GetHeader(&pHeader)); check(pHeader->GetDictionary(&pDictionary)); /* Lookup class definitions for the objects we want to create. */ check(pDictionary->LookupClassDef(AUID_AAFCompositionMob, &pCompositionMobDef)); check(pDictionary->LookupClassDef(AUID_AAFSequence, &pSequenceDef)); check(pDictionary->LookupClassDef(AUID_AAFSourceClip, &pSourceClipDef)); /* Lookup any necessary data definitions. */ check(pDictionary->LookupDataDef(kAAFDataDef_Sound, &pSoundDef)); // Get the number of master mobs in the existing file (must not be zero) check(pHeader->CountMobs(kAAFMasterMob, &numMobs)); if (numMobs != 0) { printf("Found %d Master Mobs\n", numMobs); criteria.searchTag = kAAFByMobKind; criteria.tags.mobKind = kAAFMasterMob; check(pHeader->GetMobs(&criteria, &pMobIter)); /* Create a Composition Mob */ check(pCompositionMobDef-> CreateInstance(IID_IAAFMob, (IUnknown **)&pCompMob)); /* Append the Mob to the Header */ check(pHeader->AddMob(pCompMob)); /* Create a TimelineMobSlot with an audio sequence */ check(pSequenceDef-> CreateInstance(IID_IAAFSequence, (IUnknown **)&pAudioSequence)); check(pAudioSequence->QueryInterface(IID_IAAFSegment, (void **)&seg)); check(pAudioSequence->QueryInterface(IID_IAAFComponent, (void **)&aComponent)); check(aComponent->SetDataDef(pSoundDef)); check(pCompMob->AppendNewTimelineSlot(editRate, seg, 1, slotName, zeroPos, &newSlot)); seg->Release(); seg = NULL; newSlot->Release(); newSlot = NULL; // This variable is about to be overwritten so we need to release the old interface aComponent->Release(); aComponent = NULL; while((AAFRESULT_SUCCESS == pMobIter->NextOne(&pMob))) { // Print out information about the Mob char mobIDstr[256]; char mobName[256]; check(pMob->GetMobID (&mobID)); check(pMob->GetName (namebuf, sizeof(namebuf))); convert(mobName, sizeof(mobName), namebuf); MobIDtoString(mobID, mobIDstr); printf(" MasterMob Name = '%s'\n", mobName); printf(" (mobID %s)\n", mobIDstr); // Add a Source Clip for each Master Mob to the audio sequence by iterating check(pMob->GetSlots(&pMobSlotIter)); /* Iterating through all Mob Slots */ // Get the number of slots check(pMob->CountSlots(&numSlots)); while (lookingForAudio && (AAFRESULT_SUCCESS == pMobSlotIter->NextOne(&pMobSlot))); { /* Check to see if it is an Audio Timeline Mob Slot */ HRESULT hr; hr=pMobSlot->QueryInterface(IID_IAAFTimelineMobSlot,(void **) &pTimelineMobSlot); if (SUCCEEDED(hr)) { printf("Found a timeline mob slot\n"); check(pMobSlot->GetDataDef(&pDataDef)); // Check that we have a sound file by examining its data definition aafBool bIsSoundKind = kAAFFalse; check(pDataDef->IsSoundKind(&bIsSoundKind)); if (kAAFTrue == bIsSoundKind) { printf("Found a sound file\n"); // We are no longer looking for audio data so set boolean lookingForAudio = false; /* Get the information for the new source clip */ check(pMob->GetMobID(&sourceRef.sourceID)); check(pMobSlot->GetSlotID(&sourceRef.sourceSlotID)); check(pTimelineMobSlot->GetOrigin(&sourceRef.startTime)); check(pMobSlot->GetSegment(&pSegment)); check(pSegment->QueryInterface(IID_IAAFComponent, (void **)&pComponent)); check(pComponent->GetLength(&duration)); pComponent->Release(); pComponent = NULL; pSegment->Release(); pSegment = NULL; // this loop is to be removed upon fixing of the bug // in essenceaccess relating to codec definitions... int j = 0; for (j=0; j<10; j++) { /* Create a new Source Clip */ check(pSourceClipDef-> CreateInstance(IID_IAAFSourceClip, (IUnknown **)&pSourceClip)); // Initialize the Source Clip check(pSourceClip->Initialize( pSoundDef, duration, sourceRef)); check(pSourceClip->QueryInterface(IID_IAAFComponent, (void **) &pComponent)); check(pAudioSequence->AppendComponent(pComponent)); pComponent->Release(); pComponent = NULL; pSourceClip->Release(); pSourceClip = NULL; } } pTimelineMobSlot->Release(); pTimelineMobSlot = NULL; pDataDef->Release(); pDataDef = NULL; } pMobSlot->Release(); pMobSlot = NULL; } pMobSlotIter->Release(); pMobSlotIter = NULL; pMob->Release(); pMob = NULL; } pAudioSequence->Release(); pAudioSequence = NULL; pCompMob->Release(); pCompMob = NULL; pMobIter->Release(); pMobIter = NULL; } else { printf("Error with file: File has no Master mobs.\n"); } cleanup: // Cleanup and return if (pSourceClip) pSourceClip->Release(); if (pComponent) pComponent->Release(); if (pSegment) pSegment->Release(); if (pTimelineMobSlot) pTimelineMobSlot->Release(); if (pMobSlotIter) pMobSlotIter->Release(); if (pMob) pMob->Release(); if (newSlot) newSlot->Release(); if (aComponent) aComponent->Release(); if (seg) seg->Release(); if (pAudioSequence) pAudioSequence->Release(); if (pCompMob) pCompMob->Release(); if (pMobIter) pMobIter->Release(); if (pDataDef) pDataDef->Release(); if (pSoundDef) pSoundDef->Release(); if (pSourceClipDef) pSourceClipDef->Release(); if (pSequenceDef) pSequenceDef->Release(); if (pCompositionMobDef) pCompositionMobDef->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pFile) { /* Save the AAF file */ pFile->Save(); /* Close the AAF file */ pFile->Close(); pFile->Release(); } return moduleErrorTmp; }
void HTMLClipTest::OpenHTMLClip() { assert(_pHeader); HRESULT hr = S_OK; aafNumSlots_t compositionMobs = 0; IEnumAAFMobs *pEnumMobs = NULL; IAAFMob *pReferencingMob = NULL; IAAFCompositionMob *pCompositionMob = NULL; aafNumSlots_t mobSlots = 0; IEnumAAFMobSlots *pEnumSlots = NULL; IAAFMobSlot *pMobSlot = NULL; IAAFSegment *pSegment = NULL; IAAFHTMLClip *pHTMLClip = NULL; aafUInt32 bufSize = 0; aafUInt32 actualBufSize = 0; aafUInt32 actualLength = 0; wchar_t *pBeginAnchor = NULL; wchar_t *pEndAnchor = NULL; IAAFSourceReference *pSourceReference = NULL; aafMobID_t masterMobID = {0}; IAAFMasterMob *pMasterMob = NULL; IAAFMob *pReferencedMob = NULL; try { // Get the number of composition mobs in the file (should be one) checkResult(_pHeader->CountMobs(kAAFCompMob, &compositionMobs)); checkExpression(1 == compositionMobs, AAFRESULT_TEST_FAILED); // Get the composition mob. There should only be one. aafSearchCrit_t criteria; criteria.searchTag = kAAFByMobKind; criteria.tags.mobKind = kAAFCompMob; checkResult(_pHeader->GetMobs(&criteria, &pEnumMobs)); checkResult(pEnumMobs->NextOne(&pReferencingMob)); checkResult(pReferencingMob->QueryInterface(IID_IAAFCompositionMob, (void **)&pCompositionMob)); // Get the html clip in the slot. There should be only one. checkResult(pReferencingMob->CountSlots(&mobSlots)); checkExpression(1 == mobSlots, AAFRESULT_TEST_FAILED); checkResult(pReferencingMob->GetSlots(&pEnumSlots)); checkResult(pEnumSlots->NextOne(&pMobSlot)); checkResult(pMobSlot->GetSegment(&pSegment)); checkResult(pSegment->QueryInterface(IID_IAAFHTMLClip, (void **)&pHTMLClip)); // Validate the properties... checkResult(pHTMLClip->GetBeginAnchorBufLen(&bufSize)); actualLength = wcslen(_beginAnchor) + 1; actualBufSize = actualLength * 2; checkExpression(bufSize == actualBufSize, AAFRESULT_TEST_FAILED); pBeginAnchor = new wchar_t[actualLength]; checkExpression(NULL != pBeginAnchor, AAFRESULT_NOMEMORY); checkResult(pHTMLClip->GetBeginAnchor(pBeginAnchor, actualBufSize)); checkExpression(0 == wcscmp(pBeginAnchor, _beginAnchor), AAFRESULT_TEST_FAILED); checkResult(pHTMLClip->GetEndAnchorBufLen(&bufSize)); actualLength = wcslen(_endAnchor) + 1; actualBufSize = actualLength * 2; checkExpression(bufSize == actualBufSize, AAFRESULT_TEST_FAILED); pEndAnchor = new wchar_t[actualLength]; checkExpression(NULL != pEndAnchor, AAFRESULT_NOMEMORY); checkResult(pHTMLClip->GetEndAnchor(pEndAnchor, actualBufSize)); checkExpression(0 == wcscmp(pEndAnchor, _endAnchor), AAFRESULT_TEST_FAILED); // Attempt to "resolve" the reference and find the master mob. checkResult(pHTMLClip->QueryInterface(IID_IAAFSourceReference, (void **)&pSourceReference)); checkResult(pSourceReference->GetSourceID(&masterMobID)); checkExpression(0 == memcmp(&masterMobID, &_referencedMobID, sizeof(masterMobID)), AAFRESULT_TEST_FAILED); checkResult(_pHeader->LookupMob(masterMobID, &pReferencedMob)); checkResult(pReferencedMob->QueryInterface(IID_IAAFMasterMob, (void **)&pMasterMob)); // Use EssenceAccess to read some html essence // Find the file mob for the html essence. // Find the corresponding html essence. // Read some html essence. } catch (HRESULT& rHR) { hr = rHR; // fall through and handle cleanup } // Cleanup local references if (pMasterMob) { pMasterMob->Release(); pMasterMob = NULL; } if (pReferencedMob) { pReferencedMob->Release(); pReferencedMob = NULL; } if (pSourceReference) { pSourceReference->Release(); pSourceReference = NULL; } if (pEndAnchor) { delete [] pEndAnchor; pEndAnchor = NULL; } if (pBeginAnchor) { delete [] pBeginAnchor; pBeginAnchor = NULL; } if (pHTMLClip) { pHTMLClip->Release(); pHTMLClip = NULL; } if (pSegment) { pSegment->Release(); pSegment = NULL; } if (pMobSlot) { pMobSlot->Release(); pMobSlot = NULL; } if (pEnumSlots) { pEnumSlots->Release(); pEnumSlots = NULL; } if (pCompositionMob) { pCompositionMob->Release(); pCompositionMob = NULL; } if (pReferencingMob) { pReferencingMob->Release(); pReferencingMob = NULL; } if (pEnumMobs) { pEnumMobs->Release(); pEnumMobs = NULL; } // Propogate the error if necessary. checkResult(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 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 void ReadAAFFile(aafWChar * pFileName) { HRESULT hr = S_OK; IAAFFile * pFile = NULL; hr = AAFFileOpenExistingRead (pFileName, AAF_FILE_MODE_LAZY_LOADING, &pFile); if (SUCCEEDED(hr)) { IAAFHeader * pHeader = NULL; hr = pFile->GetHeader(&pHeader); check(hr); // display error message if (SUCCEEDED(hr)) { IAAFIdentification * pIdent = NULL; hr = pHeader->GetLastIdentification(&pIdent); check(hr); // display error message if (SUCCEEDED(hr)) { printIdentification(pIdent); pIdent->Release(); pIdent = NULL; // count Mobs aafNumSlots_t n; hr = pHeader->CountMobs(kAAFAllMob, &n); check(hr); printf("\nNumber of Mobs = %d\n", n); // Header::Version, Header::ObjectModelVersion aafVersionType_t version = {0}; check(pHeader->GetFileRevision (&version) ); printf("\nHeader::Version = %d.%d\n", version.major, version.minor); aafFileRev_t fileVersion = kAAFRev1; check(pFile->GetRevision (&fileVersion) ); printf("\nHeader::ObjectModelVersion = %d", fileVersion); if (fileVersion == kAAFRev1) printf(" (recognized as kAAFRev1)\n"); else if (fileVersion == kAAFRev2) printf(" (recognized as kAAFRev2)\n"); else printf("\n"); // Show datadefs, with version IEnumAAFDataDefsSP pEnumDataDef; IAAFDictionarySP pDictionary; check(pHeader->GetDictionary(&pDictionary)); check(pDictionary->GetDataDefs(&pEnumDataDef)); IAAFDataDef* pDataDef; printf("\nDatadefs = "); while (SUCCEEDED(pEnumDataDef->NextOne(&pDataDef))) { IAAFDefObjectSP pDefObject; check(pDataDef->QueryInterface(IID_IAAFDefObject, (void**)&pDefObject)); pDataDef->Release(); pDataDef = NULL; aafUID_t id = {0}; check(pDefObject->GetAUID(&id)); aafWChar wchName[500]; char chName[1000]; check( pDefObject->GetName(wchName, sizeof (wchName)) ); convert(chName, sizeof(chName), wchName); if (memcmp( &id, &kAAFDataDef_LegacyPicture, sizeof(id)) == 0) printf("\"%s\" (recognized as legacy Picture)\n", chName); else if (memcmp( &id, &kAAFDataDef_Picture, sizeof(id)) == 0) printf("\"%s\" (recognized as Picture)\n", chName); else if (memcmp( &id, &kAAFDataDef_LegacySound, sizeof(id)) == 0) printf("\"%s\" (recognized as legacy Sound)\n", chName); else if (memcmp( &id, &kAAFDataDef_Sound, sizeof(id)) == 0) printf("\"%s\" (recognized as Sound)\n", chName); else if (memcmp( &id, &kAAFDataDef_LegacyTimecode, sizeof(id)) == 0) printf("\"%s\" (recognized as legacy Timecode)\n", chName); else if (memcmp( &id, &kAAFDataDef_Timecode, sizeof(id)) == 0) printf("\"%s\" (recognized as Timecode)\n", chName); else if (memcmp( &id, &kAAFDataDef_PictureWithMatte, sizeof(id)) == 0) printf("\"%s\" (recognized as PictureWithMatte)\n", chName); else if (memcmp( &id, &kAAFDataDef_Edgecode, sizeof(id)) == 0) printf("\"%s\" (recognized as Edgecode)\n", chName); else if (memcmp( &id, &kAAFDataDef_Auxiliary, sizeof(id)) == 0) printf("\"%s\" (recognized as Auxiliary)\n", chName); else if (memcmp( &id, &kAAFDataDef_DescriptiveMetadata, sizeof(id)) == 0) printf("\"%s\" (recognized as DescriptiveMetadata)\n", chName); else if (memcmp( &id, &kAAFDataDef_Matte, sizeof(id)) == 0) printf("\"%s\" (recognized as Matte)\n", chName); else printf("\"%s\"\n", chName); printf(" "); } // Check if file contains TypeDefs known to cause a v1.0 reader to assert. // Known instances of this are UInt32Set and AUIDSet added to the v1.1 SDK. // Cannot use Dictionary::LookupTypeDef to check for them, because this // has the side effect of registering the typedef we are checking for // from the built-in model. Instead, iterate through typedefs (in file) // and check for the known instances. printf("\nTypes incompatible with SDK v1.0.x ="); IEnumAAFTypeDefsSP pEnumTypeDef; check(pDictionary->GetTypeDefs(&pEnumTypeDef)); IAAFTypeDef* pTypeDef; bool foundToxic = false; while (SUCCEEDED(pEnumTypeDef->NextOne(&pTypeDef))) { IAAFMetaDefinitionSP pMetaDef; check(pTypeDef->QueryInterface(IID_IAAFMetaDefinition, (void**)&pMetaDef)); pTypeDef->Release(); pTypeDef = NULL; aafUID_t typeUID; check(pMetaDef->GetAUID(&typeUID)); aafWChar wchName[500]; char chName[1000]; check( pMetaDef->GetName(wchName, sizeof (wchName)) ); convert(chName, sizeof(chName), wchName); if ((memcmp( &typeUID, &kAAFTypeID_AUIDSet, sizeof(typeUID)) == 0) || (memcmp( &typeUID, &kAAFTypeID_UInt32Set, sizeof(typeUID)) == 0)) { printf(" %s", chName); foundToxic = true; } } if (!foundToxic) printf(" (none)"); printf("\n\n"); } pHeader->Release(); pHeader = NULL; } hr = pFile->Close(); check(hr); pFile->Release(); pFile = NULL; // Get file kind. // Since AAF SDK v1.0.2, the file kind actually identifies the implementation // of the file kind, from which the file kind is inferred. aafUID_t fileKind = {0}; aafBool isAAFFile = kAAFFalse; check(AAFFileIsAAFFile(pFileName, &fileKind, &isAAFFile)); if (isAAFFile) { if (memcmp( &fileKind, &kAAFFileKind_AafM512Binary, sizeof(fileKind)) == 0) printf("Filekind = 512-byte SS (reading with Microsoft)\n"); else if (memcmp( &fileKind, &kAAFFileKind_AafS512Binary, sizeof(fileKind)) == 0) printf("Filekind = 512-byte SS (reading with Schemasoft)\n"); else if (memcmp( &fileKind, &kAAFFileKind_AafG512Binary, sizeof(fileKind)) == 0) printf("Filekind = 512-byte SS (reading with GSF)\n"); else if (memcmp( &fileKind, &kAAFFileKind_Aaf512Binary, sizeof(fileKind)) == 0) printf("Filekind = 512-byte SS (reading with default implementation)\n"); else if (memcmp( &fileKind, &kAAFFileKind_AafM4KBinary, sizeof(fileKind)) == 0) printf("Filekind = 4096-byte SS (reading with Microsoft)\n"); else if (memcmp( &fileKind, &kAAFFileKind_AafS4KBinary, sizeof(fileKind)) == 0) printf("Filekind = 4096-byte SS (reading with Schemasoft)\n"); else if (memcmp( &fileKind, &kAAFFileKind_AafG4KBinary, sizeof(fileKind)) == 0) printf("Filekind = 4096-byte SS (reading with GSF)\n"); else if (memcmp( &fileKind, &kAAFFileKind_Aaf4KBinary, sizeof(fileKind)) == 0) printf("Filekind = 4096-byte SS (reading with default implementation)\n"); else printf("Filekind = Recognized by SDK but unknown to AAFInfo\n"); } } else { fprintf(stderr, "Error : Failed to open file (result = %0x).\n", hr); exit(1); } }
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; aafNumSlots_t numMobs, i; HRESULT hr = S_OK; HRESULT localhr = S_OK; IEnumAAFMobs *mobIter = NULL; IEnumAAFMobs *cloneMobIter = NULL; IAAFMob *aMob = NULL; IAAFMob **mobArray = NULL; aafSearchCrit_t criteria; aafUInt32 numFetched = 0; 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)); // Make sure that we have one master, one file, and one composition (three total) checkResult(pHeader->CountMobs(kAAFAllMob, &numMobs)); checkExpression (3 == numMobs, AAFRESULT_TEST_FAILED); criteria.searchTag = kAAFNoSearch; checkResult(pHeader->GetMobs (&criteria, &mobIter)); /* Test the Reset method *******************************/ if (mobIter->Reset() == AAFRESULT_SUCCESS) cout<< " Reset() ... Passed" << endl; else { cout<< " Reset() ... Failed!!!" << endl; hr = AAFRESULT_TEST_FAILED; } /* Test the NextOne method ******************************/ // Call NextOne once for each mob for a total of numMobs times for (i=0; i<numMobs; i++) { if (mobIter->NextOne(&aMob) == AAFRESULT_SUCCESS) { aMob->Release(); aMob = NULL; } else localhr = AAFRESULT_TEST_FAILED; } // Make sure we are at the end if (mobIter->NextOne(&aMob) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; mobIter->Reset(); // this should return AAFRESULT_NULL_PARAM if (mobIter->NextOne(NULL) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; if (SUCCEEDED(localhr)) cout<< " NextOne() ... Passed" << endl; else { cout<< " NextOne() ... Failed!!!" << endl; hr = AAFRESULT_TEST_FAILED; } /* Test the Skip method ******************************/ localhr = S_OK; mobIter->Reset(); // skip over each Mob one at a time. for (i=0; i<numMobs; i++) if (mobIter->Skip(1) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; // Make sure we are at the end. if (mobIter->Skip(1) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; mobIter->Reset(); // Skip over multiple Mobs at a time. for (i=2; i<=numMobs; i++) { if (mobIter->Skip(i) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; mobIter->Reset(); } // Make sure we are at the end. if (mobIter->Skip(numMobs+1) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; if (SUCCEEDED(localhr)) cout<< " Skip() ... Passed" << endl; else { cout<< " Skip() ... Failed!!!" << endl; hr = AAFRESULT_TEST_FAILED; } /* Next() ******************************************/ mobArray = new IAAFMob *[numMobs]; localhr = S_OK; numFetched = 1; // Iterate thru the Mobs using Next doing 1 at a time mobIter->Reset(); for ( i=0; i<numMobs ;i++) { if (mobIter->Next(1, &aMob, &numFetched) == AAFRESULT_SUCCESS) { aMob->Release(); aMob = NULL; if (1 != numFetched) localhr = AAFRESULT_TEST_FAILED; } else localhr = AAFRESULT_TEST_FAILED; } // Make sure we are at the end if (mobIter->Next(1, &aMob, &numFetched) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; if(numFetched != 0) localhr = AAFRESULT_TEST_FAILED; // Test the Next method filling out an array of Mobs numFetched = 0; mobIter->Reset(); for ( i=2; i<=numMobs ;i++) { if (mobIter->Next(i, mobArray, &numFetched) == AAFRESULT_SUCCESS) { if (i != numFetched) localhr = AAFRESULT_TEST_FAILED; for (i = 0; i < numFetched; i++) if (mobArray[i] != NULL) // should have been set { mobArray[i]->Release(); mobArray[i] = NULL; } else localhr = AAFRESULT_TEST_FAILED; } else localhr = AAFRESULT_TEST_FAILED; mobIter->Reset(); } // Make sure we can't get more Mobs than numMobs if (mobIter->Next(i+1, mobArray, &numFetched) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; if (numMobs != numFetched) localhr = AAFRESULT_TEST_FAILED; for (i = 0; i < numMobs; i++) if (mobArray[i] != NULL) { mobArray[i]->Release(); mobArray[i] = NULL; } else localhr = AAFRESULT_TEST_FAILED; mobIter->Reset(); mobIter->Skip(2); // Make sure we can't go past the end to fill the array if (mobIter->Next(numMobs, mobArray, &numFetched) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; if ((numMobs-2) != numFetched) localhr = AAFRESULT_TEST_FAILED; for (i = 0; i < numMobs-2; i++) if (mobArray[i] != NULL) { mobArray[i]->Release(); mobArray[i] = NULL; } else localhr = AAFRESULT_TEST_FAILED; mobIter->Reset(); // Make sure it returns AAFRESULT_NULL_PARAM if (mobIter->Next(1, NULL, &numFetched) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; // Make sure it returns E_INVALIDARG if (mobIter->Next(1, mobArray, &numFetched) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; else { for (i = 0; i < numFetched; i++) if (mobArray[i] != NULL) { mobArray[i]->Release(); mobArray[i] = NULL; } else localhr = AAFRESULT_TEST_FAILED; } if (SUCCEEDED(localhr)) cout<< " Next() ... Passed" << endl; else { cout<< " Next() ... Failed!!!" << endl; hr = AAFRESULT_TEST_FAILED; } /* Clone() ************************************/ // Test the Clone method with with enumerator at begining localhr = S_OK; mobIter->Reset(); if (mobIter->Clone(&cloneMobIter) == AAFRESULT_SUCCESS) { for (i=0; i < numMobs; i++) { if (cloneMobIter->NextOne(&aMob) == AAFRESULT_SUCCESS) { aMob->Release(); aMob = NULL; } else localhr = AAFRESULT_TEST_FAILED; } if (cloneMobIter->NextOne(&aMob) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; cloneMobIter->Reset(); if (cloneMobIter->Next(numMobs, mobArray, &numFetched) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; if (numMobs != numFetched) localhr = AAFRESULT_TEST_FAILED; for (i = 0; i < numMobs; i++) { if (mobArray[i] != NULL) { mobArray[i]->Release(); mobArray[i] = NULL; } else localhr = AAFRESULT_TEST_FAILED; } cloneMobIter->Reset(); if (cloneMobIter->Next(numMobs+1, mobArray, &numFetched) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; if (numMobs != numFetched) localhr = AAFRESULT_TEST_FAILED; for (i = 0; i < numMobs; i++) { if (mobArray[i] != NULL) { mobArray[i]->Release(); mobArray[i] = NULL; } else localhr = AAFRESULT_TEST_FAILED; } cloneMobIter->Reset(); cloneMobIter->Skip(1); if (cloneMobIter->Next(numMobs, mobArray, &numFetched) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; if ((numMobs-1) != numFetched) localhr = AAFRESULT_TEST_FAILED; for (i = 0; i < numMobs-1; i++) { if (mobArray[i] != NULL) { mobArray[i]->Release(); mobArray[i] = NULL; } else localhr = AAFRESULT_TEST_FAILED; } cloneMobIter->Release(); cloneMobIter = NULL; } else localhr = AAFRESULT_TEST_FAILED; // Test the Clone method with with enumerator at end. // Indirectly tests the Skip and Reset methods. mobIter->Reset(); mobIter->Skip(numMobs-1); if (mobIter->Clone(&cloneMobIter) == AAFRESULT_SUCCESS) { if (cloneMobIter->NextOne(&aMob) == AAFRESULT_SUCCESS) { aMob->Release(); aMob = NULL; } if (cloneMobIter->NextOne(&aMob) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; cloneMobIter->Release(); cloneMobIter = NULL; } else localhr = AAFRESULT_TEST_FAILED; // Test the Clone method with with enumerator in the middle. // Indirectly tests the Skip and Reset methods. mobIter->Reset(); mobIter->Skip(numMobs-2); if (mobIter->Clone(&cloneMobIter) == AAFRESULT_SUCCESS) { cloneMobIter->Skip(1); if (cloneMobIter->NextOne(&aMob) == AAFRESULT_SUCCESS) { aMob->Release(); aMob = NULL; } else localhr = AAFRESULT_TEST_FAILED; if (cloneMobIter->NextOne(&aMob) != AAFRESULT_NO_MORE_OBJECTS) localhr = AAFRESULT_TEST_FAILED; cloneMobIter->Release(); cloneMobIter = NULL; } else localhr = AAFRESULT_TEST_FAILED; mobIter->Reset(); if (mobIter->Clone(&cloneMobIter) == AAFRESULT_SUCCESS) { if (cloneMobIter->Next(1, NULL, &numFetched) != AAFRESULT_NULL_PARAM) localhr = AAFRESULT_TEST_FAILED; if (cloneMobIter->Next(1, mobArray, &numFetched) != AAFRESULT_SUCCESS) localhr = AAFRESULT_TEST_FAILED; else { for (i = 0; i < numFetched; i++) { if (mobArray[i] != NULL) { mobArray[i]->Release(); mobArray[i] = NULL; } else localhr = AAFRESULT_TEST_FAILED; } } cloneMobIter->Release(); cloneMobIter = NULL; } else localhr = AAFRESULT_TEST_FAILED; if (SUCCEEDED(localhr)) cout<< " Clone() ... Passed" << endl; else { cout<< " Clone() ... Failed!!!" << endl; hr = AAFRESULT_TEST_FAILED; } checkResult(pHeader->CountMobs(kAAFMasterMob, &numMobs)); checkExpression (1 == numMobs, AAFRESULT_TEST_FAILED); checkResult(pHeader->CountMobs(kAAFFileMob, &numMobs)); checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED); checkResult(pHeader->CountMobs(kAAFCompMob, &numMobs)); checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED); // Test usageCode search criteria. { // Should find one TopLevel mob, and two Template mobs. // There should be one mob with usage code TopLevel, and it should be // a composition mob. aafSearchCrit_t usageCrit; usageCrit.searchTag = kAAFByUsageCode; usageCrit.tags.usageCode = kAAFUsage_TopLevel; CheckMobsByUsageCode( pHeader, usageCrit, 1, true, IID_IAAFCompositionMob ); // There should be one composition mob with usage code TopLevel. usageCrit.searchTag = kAAFByCompositionMobUsageCode; usageCrit.tags.usageCode = kAAFUsage_TopLevel; CheckMobsByUsageCode( pHeader, usageCrit, 1, true, IID_IAAFCompositionMob ); // There should be two mobs with usage code Template. They are of difference // types, hence, don't check the type. usageCrit.searchTag = kAAFByUsageCode; usageCrit.tags.usageCode = kAAFUsage_Template; CheckMobsByUsageCode( pHeader, usageCrit, 2, false, IID_IUnknown ); // One of the Template mobs should be a SourceMob, the other should be MasterMob. usageCrit.searchTag = kAAFBySourceMobUsageCode; usageCrit.tags.usageCode = kAAFUsage_Template; CheckMobsByUsageCode( pHeader, usageCrit, 1, true, IID_IAAFSourceMob ); usageCrit.searchTag = kAAFByMasterMobUsageCode; usageCrit.tags.usageCode = kAAFUsage_Template; CheckMobsByUsageCode( pHeader, usageCrit, 1, true, IID_IAAFMasterMob ); } } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return delete [] mobArray; if (mobIter) mobIter->Release(); if (pHeader) pHeader->Release(); if (pFile) { if (bFileOpen) pFile->Close(); pFile->Release(); } return hr; }
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 ReadAAFFile(aafWChar * pFileName) { // IAAFSession * pSession = NULL; IAAFFile * pFile = NULL; IAAFHeader * pHeader = NULL; IEnumAAFMobs* pMobIter = NULL; IAAFMob* pMob = NULL; IAAFMob* pReferencedMob = NULL; IEnumAAFMobSlots* pSlotIter = NULL; IAAFMobSlot* pSlot = NULL; IAAFSegment* pSegment = NULL; IAAFSourceClip* pSourceClip = NULL; bool bFileOpen = false; aafSearchCrit_t criteria; aafNumSlots_t numMobs, numSlots; HRESULT hr = AAFRESULT_SUCCESS; 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(2 == numMobs, AAFRESULT_TEST_FAILED); // Enumerate over all Composition Mobs criteria.searchTag = kAAFByMobKind; criteria.tags.mobKind = kAAFCompMob; checkResult(pHeader->GetMobs(&criteria, &pMobIter)); while (AAFRESULT_SUCCESS == pMobIter->NextOne(&pMob)) { checkResult(pMob->CountSlots(&numSlots)); checkExpression(1 == numSlots, AAFRESULT_TEST_FAILED); checkResult(pMob->GetSlots(&pSlotIter)); while (AAFRESULT_SUCCESS == pSlotIter->NextOne(&pSlot)) { // The segment should be a source clip... checkResult(pSlot->GetSegment(&pSegment)); pSegment->Release(); pSegment = NULL; pSlot->Release(); pSlot = NULL; } pMob->Release(); pMob = NULL; } } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pReferencedMob) pReferencedMob->Release(); if (pSourceClip) pSourceClip->Release(); if (pSegment) pSegment->Release(); if (pSlot) pSlot->Release(); if (pSlotIter) pSlotIter->Release(); if (pMob) pMob->Release(); if (pMobIter) pMobIter->Release(); if (pHeader) pHeader->Release(); if (pFile) { if (bFileOpen) 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 ReadAAFFile(aafWChar * pFileName) { // IAAFSession * pSession = NULL; IAAFFile * pFile = NULL; bool bFileOpen = false; IAAFHeader * pHeader = NULL; IAAFDictionary* pDictionary = NULL; IEnumAAFMobs* pMobIter = NULL; IEnumAAFMobSlots* pEnum = NULL; IAAFMob* pMob = NULL; IAAFMobSlot* pMobSlot = NULL; IAAFSegment* pSegment = NULL; IAAFSequence* pSequence = NULL; IAAFTransition* pTransition = NULL; IAAFComponent* pComponent = NULL; IAAFFiller* pFiller = NULL; IAAFOperationGroup* pOperationGroup = NULL; IEnumAAFComponents* pCompIter = NULL; aafLength_t transitionLength; aafPosition_t cutPoint; aafNumSlots_t numMobs; aafUInt32 numComponents = 0; HRESULT hr = S_OK; 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, &pMobIter)); while (AAFRESULT_SUCCESS == pMobIter->NextOne(&pMob)) { checkResult(pMob->GetSlots (&pEnum)); while (AAFRESULT_SUCCESS == pEnum->NextOne (&pMobSlot)) { checkResult(pMobSlot->GetSegment (&pSegment)); // Check to see if Segment is a Sequence checkResult(pSegment->QueryInterface(IID_IAAFSequence, (void **) &pSequence)); // It is, so get a Component Iterator checkResult(pSequence->CountComponents(&numComponents)); // Verify that all 3 components(Filler, Transition, Filler) are present checkExpression(numComponents == 3, AAFRESULT_TEST_FAILED); checkResult(pSequence->GetComponents(&pCompIter)); // Now visit each and every one of the components. while(AAFRESULT_SUCCESS == pCompIter->NextOne(&pComponent)) { // Find out what kind of segment we have if ((pComponent->QueryInterface(IID_IAAFTransition, (void **)&pTransition)) == AAFRESULT_SUCCESS) { // This is the transition checkResult(pTransition->GetCutPoint (&cutPoint)); checkResult(pComponent->GetLength(&transitionLength)); checkResult(pTransition->GetOperationGroup(&pOperationGroup)); // Check results !! checkExpression(cutPoint == 0, AAFRESULT_TEST_FAILED); checkExpression(transitionLength == 100, AAFRESULT_TEST_FAILED); pTransition->Release(); pTransition = NULL; } else { // validate that the other segments are Fillers checkResult(pComponent->QueryInterface(IID_IAAFFiller, (void **)&pFiller)); pFiller->Release(); pFiller = NULL; } pComponent->Release(); pComponent = NULL; } pSegment->Release(); pSegment = NULL; pSequence->Release(); pSequence = NULL; pCompIter->Release(); pCompIter = NULL; } pMob->Release(); pMob = NULL; } } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (pTransition) pTransition->Release(); if (pOperationGroup) pOperationGroup->Release(); if (pComponent) pComponent->Release(); if (pSegment) pSegment->Release(); if (pMobSlot) pMobSlot->Release(); if (pSequence) pSequence->Release(); if (pCompIter) pCompIter->Release(); if (pEnum) pEnum->Release(); if (pFiller) pFiller->Release(); if (pMob) pMob->Release(); if (pMobIter) pMobIter->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pFile) { if (bFileOpen) pFile->Close(); pFile->Release(); } return hr; }
static HRESULT ReadAAFFile(aafWChar* pFileName) { IAAFFile* pFile = NULL; IAAFHeader* pHeader = NULL; IEnumAAFMobs* pMobIter = NULL; IAAFMob* pMob; IEnumAAFMobSlots* pSlotIter = NULL; IAAFMobSlot* pSlot = NULL; IAAFComponent* pComp = NULL; IAAFSegment* pSegment = NULL; IAAFDataDef* pDataDef = NULL; IAAFSequence* pSequence = NULL; IAAFDictionary* pDictionary = NULL; IEnumAAFDataDefs* pEnumDataDef = NULL; IEnumAAFDataDefs* pCloneEnum = NULL; IEnumAAFComponents* pCompIter = NULL; IAAFDataDef* pArray[2] = { NULL, NULL }; aafNumSlots_t numMobs; aafInt32 index; aafSearchCrit_t criteria; HRESULT hr = S_OK; aafBool testBool; aafUInt32 resultCount; try { // Open the AAF file checkResult(AAFFileOpenExistingRead(pFileName, 0, &pFile)); // Get the AAF file header. checkResult(pFile->GetHeader(&pHeader)); // Validate that there is only one composition mob. checkResult(pHeader->CountMobs(kAAFCompMob, &numMobs)); checkExpression(1 == numMobs, AAFRESULT_TEST_FAILED); // Get the AAF Dictionary so that we can create valid AAF objects. checkResult(pHeader->GetDictionary(&pDictionary)); // The test can't check the types on these because the order of adding data definitions // is defined by the toolkit, and not the test. !!!Change this to determine the order on // the first two tests, and then use to test the other functions. checkResult(pDictionary->GetDataDefs(&pEnumDataDef)); /* Read and check the first element */ checkResult(pEnumDataDef->NextOne(&pDataDef)); checkResult(pDataDef->IsPictureKind(&testBool)); // checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsSoundKind(&testBool)); // checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); pDataDef->Release(); pDataDef = NULL; /**/ /* Read and check the second element */ checkResult(pEnumDataDef->NextOne(&pDataDef)); checkResult(pDataDef->IsSoundKind(&testBool)); // checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsPictureKind(&testBool)); // checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); pDataDef->Release(); pDataDef = NULL; /*****/ /* Reset, and check the first element again*/ checkResult(pEnumDataDef->Reset()); checkResult(pEnumDataDef->NextOne(&pDataDef)); checkResult(pDataDef->IsPictureKind(&testBool)); // checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsSoundKind(&testBool)); // checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); pDataDef->Release(); pDataDef = NULL; /* Reset, Skip, and check the second element again*/ checkResult(pEnumDataDef->Reset()); checkResult(pEnumDataDef->Skip(1)); checkResult(pEnumDataDef->NextOne(&pDataDef)); checkResult(pDataDef->IsSoundKind(&testBool)); // checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsPictureKind(&testBool)); // checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); pDataDef->Release(); pDataDef = NULL; /* Reset, and read both elements */ checkResult(pEnumDataDef->Reset()); checkResult(pEnumDataDef->Next (2, (IAAFDataDef **)&pArray, &resultCount)); checkExpression (resultCount == 2, AAFRESULT_TEST_FAILED); checkResult(pArray[0]->IsPictureKind(&testBool)); // checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pArray[0]->IsSoundKind(&testBool)); // checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); pArray[0]->Release(); pArray[0] = NULL; checkResult(pArray[1]->IsSoundKind(&testBool)); // checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pArray[1]->IsPictureKind(&testBool)); // checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); pArray[1]->Release(); pArray[1] = NULL; // /* Read one past to make sure that it fails */ // checkExpression(pEnumDataDef->NextOne(&pDataDef) != AAFRESULT_SUCCESS, AAFRESULT_TEST_FAILED); /* Clone the enumerator, and read one element */ checkResult(pEnumDataDef->Clone(&pCloneEnum)); checkResult(pCloneEnum->Reset()); checkResult(pCloneEnum->NextOne(&pDataDef)); checkResult(pDataDef->IsPictureKind(&testBool)); // checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsSoundKind(&testBool)); // checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); pDataDef->Release(); pDataDef = NULL; pCloneEnum->Release(); pCloneEnum = NULL; // Enumerate over Composition MOBs criteria.searchTag = kAAFByMobKind; criteria.tags.mobKind = kAAFCompMob; checkResult(pHeader->GetMobs(&criteria, &pMobIter)); CAAFBuiltinDefs defs (pDictionary); while (pMobIter && pMobIter->NextOne(&pMob) == AAFRESULT_SUCCESS) { aafNumSlots_t numSlots = 0; checkResult(pMob->CountSlots(&numSlots)); checkExpression(1 == numSlots, AAFRESULT_TEST_FAILED); // Enumerate over all MOB slots for this MOB checkResult(pMob->GetSlots(&pSlotIter)); while (pSlotIter && pSlotIter->NextOne(&pSlot) == AAFRESULT_SUCCESS) { aafUInt32 numCpnts; checkResult(pSlot->GetSegment(&pSegment)); checkResult(pSegment->QueryInterface(IID_IAAFSequence, (void **) &pSequence)); checkResult(pSequence->CountComponents(&numCpnts)); checkExpression(numCpnts == kNumComponents, AAFRESULT_TEST_FAILED); checkResult(pSequence->GetComponents(&pCompIter)); numCpnts = 0; index = 0; while (pCompIter && pCompIter->NextOne(&pComp) == AAFRESULT_SUCCESS) { aafBool testBool; numCpnts++; checkResult(pComp->GetDataDef(&pDataDef)); checkResult(pDataDef->IsSoundKind(&testBool)); checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsMatteKind(&testBool)); checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); if(index == 0) // First segment is Picture with Matte, converts to picture { checkResult(pDataDef->IsDataDefOf(defs.ddkAAFPictureWithMatte(), &testBool)); checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsPictureKind(&testBool)); checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsPictureWithMatteKind(&testBool)); checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->DoesDataDefConvertTo (defs.ddkAAFPicture(), &testBool)); checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); } else // First segment is Picture, converts from picture with Matte { checkResult(pDataDef->IsDataDefOf(defs.ddkAAFPicture(), &testBool)); checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsPictureKind(&testBool)); checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); checkResult(pDataDef->IsPictureWithMatteKind(&testBool)); checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); checkResult(pDataDef->DoesDataDefConvertFrom (defs.ddkAAFPictureWithMatte(), &testBool)); checkExpression(testBool == kAAFTrue, AAFRESULT_TEST_FAILED); } checkResult(pDataDef->DoesDataDefConvertTo (defs.ddkAAFSound(), &testBool)); checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); checkResult(pDataDef->DoesDataDefConvertFrom (defs.ddkAAFSound(), &testBool)); checkExpression(testBool == kAAFFalse, AAFRESULT_TEST_FAILED); pComp->Release(); pComp = NULL; pDataDef->Release(); pDataDef = NULL; index++; } pCompIter->Release(); pCompIter = NULL; pSequence->Release(); pSequence = NULL; pSegment->Release(); pSegment = NULL; pSlot->Release(); pSlot = NULL; } pSlotIter->Release(); pSlotIter = NULL; pMob->Release(); pMob = NULL; } } catch (HRESULT& rResult) { hr = rResult; } // Cleanup object references if (pComp) pComp->Release(); if (pEnumDataDef) pEnumDataDef->Release(); if (pCloneEnum) pCloneEnum->Release(); if (pCompIter) pCompIter->Release(); if (pArray[0]) pArray[0]->Release(); if (pArray[1]) pArray[1]->Release(); if (pDataDef) pDataDef->Release(); if (pSequence) pSequence->Release(); if (pSegment) pSegment->Release(); if (pSlot) pSlot->Release(); if (pDictionary) pDictionary->Release(); if (pSlotIter) pSlotIter->Release(); if (pMob) pMob->Release(); if (pMobIter) pMobIter->Release(); if (pHeader) pHeader->Release(); if (pFile) { pFile->Close(); pFile->Release(); } return hr; }