static HRESULT CreateAAFFile( aafWChar * pFileName, aafUID_constref fileKind, testRawStorageType_t rawStorageType, aafProductIdentification_constref productID) { HRESULT hr = AAFRESULT_SUCCESS; IAAFFile* pFile = NULL; IAAFHeader * pHeader = NULL; IAAFDictionary * pDict = NULL; IAAFCompositionMob * pCMob = NULL; IAAFMob * pMob = NULL; IAAFObject * pObj = NULL; try { //Do the usual ... RemoveTestFile (pFileName); checkResult (CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile )); assert (pFile); checkResult (pFile->GetHeader (&pHeader)); assert (pHeader); checkResult (pHeader->GetDictionary (&pDict)); assert (pDict); CAAFBuiltinDefs defs (pDict); //Create a composition ... checkResult (defs.cdCompositionMob()-> CreateInstance (IID_IAAFCompositionMob, (IUnknown **) &pCMob)); assert (pCMob); checkResult (pCMob->Initialize (TEST_NAME)); //... Get its mob, and add it to the header info checkResult (pCMob->QueryInterface (IID_IAAFMob, (void **) &pMob)); assert (pMob); checkResult (pHeader->AddMob (pMob)); } catch (HRESULT & rResult) { hr = rResult; } if (pCMob) pCMob->Release(); if (pMob) pCMob->Release(); if (pObj) pObj->Release(); if (pDict) pDict->Release(); if (pHeader) pHeader->Release(); if (pFile) { AAFRESULT temphr = pFile->Save(); if (! SUCCEEDED (temphr)) return temphr; temphr = pFile->Close(); if (! SUCCEEDED (temphr)) return temphr; 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; }
void HTMLClipTest::CreateHTMLClip() { assert(_pHeader && _pDictionary); HRESULT hr = S_OK; IAAFMasterMob *pMasterMob = NULL; IAAFMob *pReferencedMob = NULL; IAAFHTMLClip *pHTMLClip = NULL; IAAFSourceReference *pSourceReference = NULL; IAAFCompositionMob *pCompositionMob = NULL; IAAFMob *pReferencingMob = NULL; IAAFSegment *pSegment = NULL; IAAFTimelineMobSlot *pMobSlot = NULL; IAAFComponent *pComponent = NULL; CAAFBuiltinDefs defs (_pDictionary); try { //Make the MOB to be referenced checkResult(defs.cdMasterMob()-> CreateInstance(IID_IAAFMasterMob, (IUnknown **)&pMasterMob)); checkResult(pMasterMob->QueryInterface(IID_IAAFMob, (void **)&pReferencedMob)); checkResult(pReferencedMob->GetMobID(&_referencedMobID)); checkResult(pReferencedMob->SetName(L"HTMLClipTest::ReferencedMob")); // Save the master mob. checkResult(_pHeader->AddMob(pReferencedMob)); // Use EssenceAccess to write some html essence // Create a file mob for the html essence. // Create the corresponding html essence. // Write some html essence. // Create a HTMLClip checkResult(defs.cdHTMLClip()-> CreateInstance(IID_IAAFHTMLClip, (IUnknown **)&pHTMLClip)); checkResult(pHTMLClip->SetBeginAnchor(const_cast<wchar_t *>(_beginAnchor))); checkResult(pHTMLClip->SetEndAnchor(const_cast<wchar_t *>(_endAnchor))); checkResult(pHTMLClip->QueryInterface(IID_IAAFComponent, (void **)&pComponent)); checkResult(pComponent->SetDataDef(defs.ddkAAFPicture())); pComponent->Release(); pComponent = NULL; // Initialize the source reference data. checkResult(pHTMLClip->QueryInterface(IID_IAAFSourceReference, (void **)&pSourceReference)); checkResult(pSourceReference->SetSourceID(_referencedMobID)); checkResult(pSourceReference->SetSourceMobSlotID(0)); // Create a composition mob to hold the html clip. checkResult(defs.cdCompositionMob()-> CreateInstance(IID_IAAFCompositionMob, (IUnknown **)&pCompositionMob)); checkResult(pCompositionMob->QueryInterface(IID_IAAFMob, (void **)&pReferencingMob)); checkResult(pReferencingMob->SetName(L"CompositionMob_HTMLClipTest")); checkResult(pHTMLClip->QueryInterface(IID_IAAFSegment, (void **)&pSegment)); IAAFMobSlot *pSlot = NULL; aafRational_t editRate = { 0, 1}; checkResult(pReferencingMob->AppendNewTimelineSlot(editRate, pSegment, 1, L"HTMLClipTest", 0, &pMobSlot)); // Save the referencing mob. checkResult(_pHeader->AddMob(pReferencingMob)); } catch (HRESULT& rHR) { hr = rHR; // fall through and handle cleanup } // Cleanup local references if (pMobSlot) { pMobSlot->Release(); pMobSlot = NULL; } if (pComponent) { pComponent->Release(); pComponent = NULL; } if (pSegment) { pSegment->Release(); pSegment = NULL; } if (pReferencingMob) { pReferencingMob->Release(); pReferencingMob = NULL; } if (pCompositionMob) { pCompositionMob->Release(); pCompositionMob = NULL; } if (pSourceReference) { pSourceReference->Release(); pSourceReference = NULL; } if (pHTMLClip) { pHTMLClip->Release(); pHTMLClip = NULL; } if (pReferencedMob) { pReferencedMob->Release(); pReferencedMob = NULL; } if (pMasterMob) { pMasterMob->Release(); pMasterMob = NULL; } // Propogate the error if necessary. checkResult(hr); }
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 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* pRMob = NULL; IAAFMasterMob* pReferencedMob = NULL; IAAFCompositionMob* pCompMob = NULL; IAAFTimelineMobSlot *newSlot = NULL; IAAFSegment *seg = NULL; IAAFSourceClip *sclp = NULL; HRESULT hr = S_OK; try { // Remove the previous test file if any. RemoveTestFile(pFileName); // Create the file. checkResult(CreateTestFile( pFileName, fileKind, rawStorageType, productID, &pFile )); bFileOpen = true; // We can't really do anthing in AAF without the header. checkResult(pFile->GetHeader(&pHeader)); // Get the AAF Dictionary so that we can create valid AAF objects. checkResult(pHeader->GetDictionary(&pDictionary)); CAAFBuiltinDefs defs (pDictionary); //Make the first mob long test; // Create a Composition Mob checkResult(defs.cdCompositionMob()-> CreateInstance(IID_IAAFCompositionMob, (IUnknown **)&pCompMob)); checkResult(pCompMob->QueryInterface(IID_IAAFMob, (void **)&pMob)); checkResult(pMob->SetMobID(TEST_MobID)); checkResult(pMob->SetName(L"AAFTaggedValuesTest")); // append a comment to this mob !! checkResult(pMob->AppendComment(const_cast<aafWChar*>(TagNames), Comments)); checkResult(pMob->AppendComment(const_cast<aafWChar*>(TagNames), AltComment)); // Create a master mob to be referenced checkResult(defs.cdMasterMob()-> CreateInstance(IID_IAAFMasterMob, (IUnknown **)&pReferencedMob)); checkResult(pReferencedMob->QueryInterface(IID_IAAFMob, (void **)&pRMob)); checkResult(pRMob->SetMobID(TEST_referencedMobID)); checkResult(pRMob->SetName(L"AAFTaggedValueTest::ReferencedMob")); // Add some slots for(test = 0; test < 5; test++) { checkResult(defs.cdSourceClip()-> CreateInstance(IID_IAAFSourceClip, (IUnknown **)&sclp)); // Set the properties for the SourceClip sourceRef.sourceID = TEST_referencedMobID; sourceRef.sourceSlotID = 0; sourceRef.startTime = 0; IAAFDataDefSP pDataDef; checkResult(pDictionary->LookupDataDef(*slotDDefs[test], &pDataDef)); checkResult(sclp->Initialize(pDataDef, slotsLength[test], sourceRef)); checkResult(sclp->QueryInterface (IID_IAAFSegment, (void **)&seg)); aafRational_t editRate = { 0, 1}; checkResult(pMob->AppendNewTimelineSlot (editRate, seg, test+1, slotNames[test], 0, &newSlot)); newSlot->Release(); newSlot = NULL; seg->Release(); seg = NULL; sclp->Release(); sclp = NULL; } // Add the mob to the file. checkResult(pHeader->AddMob(pMob)); checkResult(pHeader->AddMob(pRMob)); } catch (HRESULT& rResult) { hr = rResult; } // Cleanup and return if (newSlot) newSlot->Release(); if (seg) seg->Release(); if (sclp) sclp->Release(); if (pCompMob) pCompMob->Release(); if (pMob) pMob->Release(); if (pReferencedMob) pReferencedMob->Release(); if (pRMob) pRMob->Release(); if (pDictionary) pDictionary->Release(); if (pHeader) pHeader->Release(); if (pFile) { // Close file if (bFileOpen) { pFile->Save(); pFile->Close(); } pFile->Release(); } return hr; }