static HRESULT OpenAAFFile(aafWChar * pFileName) { IAAFFile* pFile = NULL; IAAFHeader* pHeader = NULL; IAAFDictionary* pDictionary = NULL; IAAFMob* pMob = NULL; IAAFEssenceAccess* pEssenceAccess = NULL; IAAFEssenceFormat* pFormat = NULL; IEnumAAFMobs* pMobIter = NULL; aafNumSlots_t numMobs, numSlots; aafSearchCrit_t criteria; aafMobID_t mobID; IAAFDataDef *pSoundDef = NULL; IAAFMobSlot* pMobSlot = NULL; // Open an AAF file check(AAFFileOpenExistingRead (pFileName, 0, &pFile)); check(pFile->GetHeader(&pHeader)); // Open raw audio output file FILE *output; const char *output_file = "raw.pcm"; if ((output = fopen(output_file, "wb")) == NULL) { perror(output_file); exit(1); } // Get the AAF Dictionary from the file check(pHeader->GetDictionary(&pDictionary)); /* Lookup any necessary data definitions. */ check(pDictionary->LookupDataDef(kAAFDataDef_Sound, &pSoundDef)); /* Check number of Mobs in file */ check(pHeader->CountMobs(kAAFMasterMob, &numMobs)); if (numMobs == 0) { printf("No Master Mobs found in AAF file\n"); return 0; } printf("Found %d Master Mobs\n", numMobs); criteria.searchTag = kAAFByMobKind; criteria.tags.mobKind = kAAFMasterMob; check(pHeader->GetMobs(&criteria, &pMobIter)); while (AAFRESULT_SUCCESS == pMobIter->NextOne(&pMob)) { char mobIDstr[256]; aafWChar namebuf[1204]; IAAFTimelineMobSlot* pTimelineMobSlot = NULL; IAAFDataDef *pDataDef = NULL; IAAFEssenceFormat *fmtTemplate = NULL; unsigned char *dataBuff = NULL; IEnumAAFMobSlots* pMobSlotIter = NULL; check(pMob->GetMobID (&mobID)); check(pMob->GetName (namebuf, sizeof(namebuf))); MobIDtoString(mobID, mobIDstr); printf(" MasterMob Name = '%ls'\n", namebuf); printf(" (mobID %s)\n", mobIDstr); // Get the number of slots check(pMob->CountSlots(&numSlots)); // Iterating through all Mob Slots check(pMob->GetSlots(&pMobSlotIter)); while(AAFRESULT_SUCCESS == pMobSlotIter->NextOne(&pMobSlot)) { // Check to see if it is an Audio Timeline Mob Slot HRESULT hr; aafUInt32 MobSlotID; hr=pMobSlot->QueryInterface(IID_IAAFTimelineMobSlot,(void **) &pTimelineMobSlot); if (SUCCEEDED(hr)) { check(pMobSlot->GetDataDef(&pDataDef)); // Check that we have a sound file by examining its data definition aafBool bIsSoundKind = kAAFFalse; check(pDataDef->IsSoundKind(&bIsSoundKind)); if (kAAFTrue == bIsSoundKind) { IAAFMasterMob* pMasterMob = NULL; // Prepare to get audio data: first get MobSlotID check(pMobSlot->GetSlotID(&MobSlotID)); // Then get a Master Mob interface check(pMob->QueryInterface(IID_IAAFMasterMob, (void **)&pMasterMob)); // Open the Essence Data check(pMasterMob->OpenEssence(MobSlotID, NULL, kAAFMediaOpenReadOnly, kAAFCompressionDisable, &pEssenceAccess)); // Get the information about the format of the audio data. // The pFormat object must be setup with each specifier you // wish to access, otherwise you get AAFRESULT_FORMAT_NOT_FOUND. aafUInt32 audioSampleBits; aafRational_t sampleRate; aafUInt32 numChannels; aafUInt32 maxSampleBytes; check(pEssenceAccess->GetEmptyFileFormat(&fmtTemplate)); check(fmtTemplate->AddFormatSpecifier(kAAFAudioSampleBits, 0, NULL)); check(fmtTemplate->AddFormatSpecifier(kAAFSampleRate, 0, NULL)); check(fmtTemplate->AddFormatSpecifier(kAAFNumChannels, 0, NULL)); check(fmtTemplate->AddFormatSpecifier(kAAFMaxSampleBytes, 0, NULL)); check(pEssenceAccess->GetFileFormat(fmtTemplate, &pFormat)); fmtTemplate->Release(); fmtTemplate = NULL; aafInt32 fmtBytesRead; check(pFormat->GetFormatSpecifier(kAAFAudioSampleBits, sizeof(audioSampleBits), (aafDataBuffer_t)&audioSampleBits, &fmtBytesRead)); check(pFormat->GetFormatSpecifier(kAAFSampleRate, sizeof(sampleRate), (aafDataBuffer_t)&sampleRate, &fmtBytesRead)); check(pFormat->GetFormatSpecifier(kAAFNumChannels, sizeof(numChannels), (aafDataBuffer_t)&numChannels, &fmtBytesRead)); check(pFormat->GetFormatSpecifier(kAAFMaxSampleBytes, sizeof(maxSampleBytes), (aafDataBuffer_t)&maxSampleBytes, &fmtBytesRead)); pFormat->Release(); pFormat = NULL; // Get the sample count which is in terms of EditRate aafLength_t sampleCount; check(pEssenceAccess->CountSamples(pSoundDef, &sampleCount)); printf("\tSlotID %u: SampleBits=%d SampleRate=%d/%d NumChannels=%d MaxSampleBytes=%u\n", MobSlotID, audioSampleBits, sampleRate.numerator, sampleRate.denominator, numChannels, maxSampleBytes); printf("\t\tCountSamples=%"AAFFMT64"d\n", sampleCount); // Set a suitable buffer size dataBuff = new unsigned char[maxSampleBytes]; // Read samples until no more are available aafUInt32 samplesRead, actualBytesRead, total_samples = 0; while (true) { hr = (pEssenceAccess->ReadSamples( 1, // number of samples to read maxSampleBytes, // maximum buffer size dataBuff, // output buffer for audio data &samplesRead, // number of samples read &actualBytesRead)); // number of bytes read if (hr == AAFRESULT_EOF) break; else check(hr); if (actualBytesRead!=0) { total_samples += samplesRead; // Write out samples if ( fwrite(dataBuff, maxSampleBytes, 1, output) != 1 ) { perror(output_file); return 1; } } } printf("\tTotal samples = %u (written to %s)\n", total_samples, output_file); delete [] dataBuff; dataBuff = NULL; pEssenceAccess->Release(); pEssenceAccess = NULL; pMasterMob->Release(); pMasterMob = NULL; } pTimelineMobSlot->Release(); pTimelineMobSlot = NULL; pDataDef->Release(); pDataDef = NULL; } pMobSlot->Release(); pMobSlot = NULL; } pMobSlotIter->Release(); pMobSlotIter = NULL; pMob->Release(); pMob = NULL; } pMobIter->Release(); pMobIter = NULL; return moduleErrorTmp; }
static HRESULT 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; }
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; }