Menu

Taking Mobs from existing AAFs and adding to new AAF

Developers
Bill Baker
2015-05-22
2015-05-22
  • Bill Baker

    Bill Baker - 2015-05-22

    I'm looking to take an AAF (or existing AAFs), copy their MOBs and add them to a newly created MOB. The idea is that I can take the contents of several AAFs into one file, and make a sequence from them.

    Currently I'm doing something like, to take the master mob from one file and add to my new one as a test:

    check(AAFFileOpenExistingRead(pMergeFile, kAAFFileAccess_read, &pInputFile));
    check(AAFFileOpenNewModifyEx(pOutputFile, &kAAFFileKind_Aaf4KBinary, 0, &ProductInfo, &pCreatedFile));

    check(pInputFile->GetHeader(&pInputHeader));
    check(pInputFile->GetDictionary(&pInputDictionary));
    
    check(pCreatedFile->GetHeader(&pCreatedHeader));
    check(pCreatedHeader->GetDictionary(&pCreatedDictionary));
    
    check(pInputHeader->GetMobs(&mobCrit, &pEnumAAFMobs));
    check(pEnumAAFMobs->NextOne(&pInputMob));
    check(pCreatedHeader->AddMob(pInputMob));
    

    However this doesn't attach the MOB (throws an error which I catch) the file just includes my product info. If I create a new mob with the below, it adds OK.

    check(AAFFileOpenExistingRead(pMergeFile, kAAFFileAccess_read, &pInputFile));
    check(AAFFileOpenNewModifyEx(pOutputFile, &kAAFFileKind_Aaf4KBinary, 0, &ProductInfo, &pCreatedFile));

    check(pInputFile->GetHeader(&pInputHeader));
    check(pInputFile->GetDictionary(&pInputDictionary));
    
    check(pCreatedFile->GetHeader(&pCreatedHeader));
    check(pCreatedHeader->GetDictionary(&pCreatedDictionary));
    check(pCreatedDictionary->LookupClassDef(AUID_AAFMasterMob, &pCDMasterMob)); //use this to add an empty mob to the AAF
    check(pCDMasterMob->CreateInstance(IID_IAAFMasterMob, (IUnknown **)&pCopiedMob));
    
    check(pInputHeader->GetMobs(&mobCrit, &pEnumAAFMobs));
    check(pEnumAAFMobs->NextOne(&pInputMob));
    check(pCreatedHeader->AddMob(pCopiedMob));
    

    Do I need to be doing anything seperately? Or am I oversimplifying the problem?

    Any thoughts greatly appreciated.

    Bill

     
  • Jim Trainor

    Jim Trainor - 2015-05-22

    I don't see a sequence created in the code sample. Dig through the example code and look from an example that creates a sequence. You need to write code that builds the sequence object then add that to a composition or master mob. Before doing that I suggest you take a step back and review the object model first.

     
  • Bill Baker

    Bill Baker - 2015-05-22

    Hi Jim,

    Thanks for the response - I have some code which creates a sequence, and can attach a mob to that. At the moment this is just a simple test to take a MOB from one file, and then add it to another. I've had a good dig through the examples and inheritance guides.

    In the bottom example, if I create a new instance of a master mob and attach it to the new AAF, it's fine. I have an AAF with one, newly created master mob.

    In the top example, if I read the AAF first, pull out a master mob and then try and attach it, it does not succeed. My question is more, is this valid behaviour in what I am trying to accomplish? Would this accomplish bringing across the whole mob and its inheritance objects? Why would it succeed with just creating a new AAF but not with reading an existing AAF?

     
  • Jim Trainor

    Jim Trainor - 2015-05-22

    My guess is the mob you add to the new file still has underlying connections back to source files where it originated. You probably get some sort of OM violation (the layer of code that manages file persistence). I've never done exactly this but I suspect you'll have to duplicate the mob. That can be done by generically iterating over the properties in the object including recursing into lists and sub objects (i.e. that same way the dumpers traverse objects). There may be some sort of "attach to new file" interface - I'm not sure other than that I don't recall one. I've never done this exactly.

    What exactly is the error you get back?

     
  • Bill Baker

    Bill Baker - 2015-05-22

    Apologies, I was misinterpreting my error handling - it's actually an error thrown by trying to release an inuse interface, unrelated to the problem at hand.

    I don't seem to get an error back, but just no mob attached.

    Saying that:

    HRESULT IAAFMob2::CloneExternal ( [in] aafDepend_t resolveDependencies,
    [in] aafIncMedia_t includeMedia,
    [in] IAAFFile * pDestFile,
    [out] IAAFMob ** ppDestMob
    )

    Looks like it might do what I want... I will give that a go.

     
  • Jim Trainor

    Jim Trainor - 2015-05-22

    Indeed that looks like what you what.

    You'll still need to create the sequence and reference these via source clip objects in the sequence.

     
  • Bill Baker

    Bill Baker - 2015-05-22

    For anyone else struggling out there, this does the trick.

    Jim, thanks for the pointers, helped me discover what I was doing wrong, much appreciated.

     

Log in to post a comment.