Esempio n. 1
0
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;
}
Esempio n. 2
0
static HRESULT CreateAAFFile(const aafWChar * pFileName, testDataFile_t *dataFile, testType_t /* testType */)
{
  IAAFFile*					pFile = NULL;
  IAAFHeader*					pHeader = NULL;
  IAAFDictionary*				pDictionary = NULL;
  IAAFMob*					pMob = NULL;
  IAAFMasterMob*				pMasterMob = NULL;
  IAAFClassDef*   pKLVDataCD=NULL;
  IAAFClassDef*   pCommentMarkerCD=NULL;
  IAAFTypeDef*    pUnknownBaseType=NULL;
  IAAFTypeDef*	pInt32BaseType=NULL;
  // IAAFTypeDef* pASCIIStringBaseType=NULL;
  IAAFKLVData* pKLVData=NULL;

  IAAFEssenceAccess*			pEssenceAccess = NULL;
  IAAFEssenceMultiAccess*		pMultiEssence = NULL;
  IAAFEssenceFormat*			pFormat = NULL;
  IAAFEssenceFormat*	format = NULL;
  IAAFLocator*	pLocator = NULL;
  IAAFClassDef*	pCDMasterMob = 0;
  IAAFClassDef                *pCDNetworkLocator = 0;
  IAAFDataDef                 *pDdefSound = 0;
  IAAFDataDef*	pDDefSceneDesc=0;
  IAAFEventMobSlot  *pEventSlot=0;
  IAAFMobSlot   *pSlot=0;
  IAAFSequence  *pSeqSceneDesc=0;
  IAAFSegment   *pSegment=0;
  IAAFEvent     *pEventSceneDesc=0;
  IAAFComponent *pComp=0;
  HRESULT	      hr = AAFRESULT_SUCCESS;


  // !!!Previous revisions of this file contained variables here required to handle external essence
  aafMobID_t					masterMobID;
  aafProductIdentification_t	ProductInfo;
  aafRational_t   editRate = {30000, 1001};
  aafRational_t	sampleRate = {44100, 1};
  aafRational_t	eventTimebase = {30000, 1001};
  aafPosition_t	position=0;
  FILE*	pWavFile = NULL;
  unsigned char	dataBuff[4096], *dataPtr;
  //	aafUInt32	bytesWritten;
  aafUInt32	dataOffset, dataLen;
  aafUInt16	bitsPerSample, numCh;
  aafInt32	n, numSpecifiers;
  aafUID_t	essenceFormatCode, testContainer;
  aafUInt32 samplesWritten, bytesWritten;
  // delete any previous test file before continuing...
  char chFileName[1000];
  convert(chFileName, sizeof(chFileName), pFileName);
  remove(chFileName);
  if(dataFile != NULL)
    {
      // delete any previous test file before continuing...
      char chFileName[1000];
      convert(chFileName, sizeof(chFileName), dataFile->dataFilename);
      remove(chFileName);
    }


  aafProductVersion_t v;
  v.major = 1;
  v.minor = 0;
  v.tertiary = 0;
  v.patchLevel = 0;
  v.type = kAAFVersionUnknown;

  ProductInfo.companyName = companyName;
  ProductInfo.productName = productName;
  ProductInfo.productVersion = &v;
  ProductInfo.productVersionString = NULL;
  ProductInfo.productID = NIL_UID;
  ProductInfo.platform = NULL;

  check(AAFFileOpenNewModifyEx (pFileName, &kAAFFileKind_Aaf4KBinary, 0, &ProductInfo, &pFile));
  check(pFile->GetHeader(&pHeader));

  // test
  // Get the AAF Dictionary so that we can create valid AAF objects.
  check(pHeader->GetDictionary(&pDictionary));

  check(pDictionary->LookupClassDef(AUID_AAFMasterMob,
				    &pCDMasterMob));
  check(pDictionary->LookupClassDef(AUID_AAFNetworkLocator,
				    &pCDNetworkLocator));
  check(pDictionary->LookupDataDef(kAAFDataDef_Sound,
				   &pDdefSound));

  // !!!Previous revisions of this file contained code here required to handle external essence

  // Get a Master MOB Interface
  check(pCDMasterMob->
	CreateInstance(IID_IAAFMasterMob, 
		       (IUnknown **)&pMasterMob));
  // Get a Mob interface and set its variables.
  check(pMasterMob->QueryInterface(IID_IAAFMob, (void **)&pMob));
  check(pMob->GetMobID(&masterMobID));
  check(pMob->SetName(L"A Master Mob"));
	
  // Add it to the file 
  check(pHeader->AddMob(pMob));

  // !!!Previous revisions of this file contained code here required to handle external essence

  if(dataFile != NULL)
    {
      // Make a locator, and attach it to the EssenceDescriptor
      check(pCDNetworkLocator->
	    CreateInstance(IID_IAAFLocator, 
			   (IUnknown **)&pLocator));		
      check(pLocator->SetPath (dataFile->dataFilename));
      testContainer = dataFile->dataFormat;
    }
  else
    {
      pLocator = NULL;
      testContainer = ContainerAAF;
    }


  // open the Essence file to be included in this AAF file("Laser.wav")
  pWavFile = fopen("Laser.wav", "r");
  if (pWavFile)
    {
      // read in the essence data
      fread(dataBuff, sizeof(unsigned char), sizeof(dataBuff), pWavFile);
      check(loadWAVEHeader(dataBuff,
			   &bitsPerSample,
			   &numCh,
			   &sampleRate,
			   &dataOffset,
			   &dataLen));
      dataPtr = dataBuff + dataOffset;
      // now create the Essence data file
     check(pMasterMob->CreateEssence(1,				// Slot ID
				      pDdefSound,		// MediaKind
				      kAAFCodecWAVE,		// codecID
				      editRate,		// edit rate
				      sampleRate,		// sample rate
				      kAAFCompressionDisable,
				      pLocator,	// In current file
				      testContainer,	// In AAF Format
				      &pEssenceAccess));// Compress disabled

      check(pEssenceAccess->GetFileFormatParameterList (&format));
      check(format->NumFormatSpecifiers (&numSpecifiers));
      for(n = 0; n < numSpecifiers; n++)
	{
	  check(format->GetIndexedFormatSpecifier (n, &essenceFormatCode, 0, NULL, NULL));
	}
      format->Release();
      format = NULL;

      // Tell the AAFEssenceAccess what the format is.
      check(pEssenceAccess->GetEmptyFileFormat (&pFormat));
      check(pFormat->NumFormatSpecifiers (&numSpecifiers));

      aafInt32	sampleSize = bitsPerSample;
      check(pFormat->AddFormatSpecifier (kAAFAudioSampleBits, sizeof(sampleSize), (aafUInt8 *)&sampleSize));
      check(pEssenceAccess->PutFileFormat (pFormat));
      pFormat->Release();
      pFormat = NULL;
      // write out the data

      check(pEssenceAccess->WriteSamples( dataLen,//!!! hardcoded bytes/sample ==1// Number of Samples
						sizeof(dataBuff), // buffer size
						dataPtr,	// THE data
						&samplesWritten,
						&bytesWritten));

      // close essence data file
      fclose(pWavFile);
      pWavFile = NULL;
      // Finish writing the destination
      check(pEssenceAccess->CompleteWrite());
      pEssenceAccess->Release();
      pEssenceAccess=NULL;
      // First register DataDef for SceneDescription
      // Is SceneDescription in dictionary already
      // Try using Timecode for MC compat
      hr = pDictionary->LookupDataDef(kAAFDataDef_Timecode,
				      &pDDefSceneDesc);
      // hr = pDictionary->LookupDataDef(kAAFDataDef_SceneDescription,
      //					 &pDDefSceneDesc);
      if (hr != AAFRESULT_SUCCESS) 
	{
	  check(pDictionary->CreateInstance(AUID_AAFDataDef,IID_IAAFDataDef,
					    (IUnknown **)&pDDefSceneDesc));
	  check(pDDefSceneDesc->Initialize(kAAFDataDef_SceneDescription,
					   L"SceneDescEvent",L"DataDefinition for Scene Description Events"));
	  check(pDictionary->RegisterDataDef(pDDefSceneDesc));
	}

      // Add EventSlot to MasterMob

      // Create Slot
      check(pDictionary->CreateInstance(AUID_AAFEventMobSlot, IID_IAAFEventMobSlot,
					(IUnknown **)&pEventSlot));

      check(pEventSlot->SetEditRate(&eventTimebase));

      // Get the mob slot interface so that we can add the event segment.
      check(pEventSlot->QueryInterface(IID_IAAFMobSlot, (void **)&pSlot));
      pEventSlot->Release();
      pEventSlot = NULL;
      aafSlotID_t eventSlotID=5;
      check(pSlot->SetSlotID(eventSlotID));
      check(pSlot->SetName(L"SceneDescriptions"));

      // Set up Sequence for Scene Descriptors
      check(pDictionary->CreateInstance(AUID_AAFSequence,IID_IAAFSequence,
					(IUnknown **)&pSeqSceneDesc));
      check(pSeqSceneDesc->Initialize(pDDefSceneDesc));

      // Create first Comment Marker
      check(pDictionary->LookupClassDef(AUID_AAFCommentMarker,
					&pCommentMarkerCD));
      check(pCommentMarkerCD->CreateInstance(IID_IAAFEvent,
					     (IUnknown **)&pEventSceneDesc));
      position=0;
      check(pEventSceneDesc->SetPosition(position));
      check(pEventSceneDesc->SetComment(L"Racers heading up the hill"));
      check(pEventSceneDesc->QueryInterface(IID_IAAFComponent, (void **)&pComp));
      check(pComp->SetDataDef(pDDefSceneDesc));		
      // Add it to the sequence
      check(pSeqSceneDesc->AppendComponent(pComp));
      pComp->Release();
      pComp = NULL;
      pEventSceneDesc->Release();
      pEventSceneDesc=NULL;

      // Create second Comment Marker
      check(pCommentMarkerCD->CreateInstance(IID_IAAFEvent,
					     (IUnknown **)&pEventSceneDesc));
      position=100;
      check(pEventSceneDesc->SetPosition(position));
      check(pEventSceneDesc->SetComment(L"Racer pulls away from crowd"));
      check(pEventSceneDesc->QueryInterface(IID_IAAFComponent, (void **)&pComp));
      check(pComp->SetDataDef(pDDefSceneDesc));		
      // Add it to the sequence
      check(pSeqSceneDesc->AppendComponent(pComp));
      pComp->Release();
      pComp = NULL;
      pEventSceneDesc->Release();
      pEventSceneDesc=NULL;
      check(pSeqSceneDesc->QueryInterface(IID_IAAFSegment, (void **)&pSegment));

      // Create third Comment Marker
      check(pCommentMarkerCD->CreateInstance(IID_IAAFEvent,
					     (IUnknown **)&pEventSceneDesc));
      position=250;
      check(pEventSceneDesc->SetPosition(position));
      check(pEventSceneDesc->SetComment(L"Racer passes finish line"));
      check(pEventSceneDesc->QueryInterface(IID_IAAFComponent, (void **)&pComp));
      check(pComp->SetDataDef(pDDefSceneDesc));		
      // Add it to the sequence
      check(pSeqSceneDesc->AppendComponent(pComp));
      pComp->Release();
      pComp = NULL;
      pEventSceneDesc->Release();
      pEventSceneDesc=NULL;
      // Add the event sequence to the event mob slot
      // Sequence must have at least one component to ensure event mob slot is valid
      check(pSlot->SetSegment(pSegment));
      pSegment->Release();
      pSegment = NULL;

      // Append the event slot to the Master Mob
      check(pMob->AppendSlot(pSlot));

      // Add the KLV data to the Master Mob

      // Register the two KLVKeys
      check(pDictionary->LookupTypeDef(kAAFTypeID_UInt8Array,
				       &pUnknownBaseType));
      check(pDictionary->RegisterKLVDataKey(KLVKey_BinaryBlob1,
					    pUnknownBaseType));
      check(pDictionary->LookupTypeDef(kAAFTypeID_Int32,
				       &pInt32BaseType));
      check(pDictionary->RegisterKLVDataKey(KLVKey_Int32_1,
					    pInt32BaseType));
      // Next define new ASCII string data def
      // check(pDictionary->RegisterKLVDataKey(KLVKey_ASCIIString1,
      //				      pASCIIStringBaseType));

      // Get the KLVData ClassDefinition
      check(pDictionary->LookupClassDef(AUID_AAFKLVData,
					&pKLVDataCD));


      // Create KLVData and append it to Mob
      check(pKLVDataCD->CreateInstance(IID_IAAFKLVData, 
				       (IUnknown **)&pKLVData));
		
      check(pKLVData->Initialize(KLVKey_BinaryBlob1,
				 sizeof(blobData), (aafUInt8 *)blobData));
      check(pMob->AppendKLVData(pKLVData));
      pKLVData->Release();
      pKLVData=NULL;

      // Create KLVData and append it to Mob
      check(pKLVDataCD->CreateInstance(IID_IAAFKLVData, 
				       (IUnknown **)&pKLVData));
		
      check(pKLVData->Initialize(KLVKey_Int32_1,
				 sizeof(int32Data), (aafUInt8 *)&int32Data));
      check(pMob->AppendKLVData(pKLVData));
      pKLVData->Release();
      pKLVData=NULL;
    }
  else
    {
      printf("***Failed to open Wave file Laser.wav\n");
    }
  // Release all unnecesary interfaces

  if (pInt32BaseType)
    pInt32BaseType->Release();
  pInt32BaseType=NULL;
  if (pUnknownBaseType)
    pUnknownBaseType->Release();
  pUnknownBaseType=NULL;
  if (pKLVDataCD)
    pKLVDataCD->Release();
  pKLVDataCD=NULL;
  if (pCommentMarkerCD)
    pCommentMarkerCD->Release();
  pCommentMarkerCD=NULL;
  if(pComp)
    pComp->Release();
  pComp=NULL;
  if(pEventSceneDesc)
    pEventSceneDesc->Release();
  pEventSceneDesc=0;
  if(pSegment)
    pSegment->Release();
  pSegment=NULL;
  if(pSeqSceneDesc)
    pSeqSceneDesc->Release();
  pSeqSceneDesc=NULL;
  if(pSlot)
    pSlot->Release();
  pSlot=NULL;
  if(pEventSlot)
    pEventSlot->Release();
  pEventSlot=NULL;
  if(pDDefSceneDesc)
    pDDefSceneDesc->Release();
  pDDefSceneDesc=NULL;

  if(pMasterMob)
    pMasterMob->Release();
  pMasterMob = NULL;
  if(pMob)
    pMob->Release();
  pMob = NULL;

  if(pDictionary)
    pDictionary->Release();
  pDictionary = NULL;
  if(pHeader)
    pHeader->Release();
  pHeader = NULL;
  //!!!DebugOnly
  pFile->Save();
  pFile->Close();
  pFile->Release();
  pFile = NULL;
  if (pEssenceAccess)
    {	
      pEssenceAccess->Release();
      pEssenceAccess= NULL;
    }

 cleanup:
  // Cleanup and return
  if(pFormat)
    pFormat->Release();
  if(format)
    format->Release();
  if(pLocator)
    pLocator->Release();

  if (pWavFile)
    fclose(pWavFile);

  if (pEssenceAccess)
    pEssenceAccess->Release();
	
  if (pMultiEssence)
    pMultiEssence->Release();
	
  if (pMasterMob)
    pMasterMob->Release();

  if (pMob)
    pMob->Release();

  if (pDictionary)
    pDictionary->Release();

  if (pHeader)
    pHeader->Release();

  if (pCDMasterMob)
    {
      pCDMasterMob->Release();
      pCDMasterMob = 0;
    }

  if (pCDNetworkLocator)
    {
      pCDNetworkLocator->Release();
      pCDNetworkLocator = 0;
    }

  if (pDdefSound)
    {
      pDdefSound->Release ();
      pDdefSound = 0;
    }

  if (pFile)
    {
      pFile->Close();
      pFile->Release();
    }


  return moduleErrorTmp;
}
Esempio n. 3
0
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;
}