Menu

I NEED HELP !! WriteSamples() eat memory!!

Help
jia yining
2008-12-11
2013-04-29
  • jia yining

    jia yining - 2008-12-11

    Hello everybody!
       There is a quite simple demon down here, it just creates an AAF file ,and export DV25 essence. It all work very well until I open the task manager. I found that the memory and virtual memory grow continuous,at the end of the process ,it use 300MB memory in total. but after the pAAFfile->Close() is called ,all the memory is back .so I donn't think it's a memory leak, but it can cause a programme crash because of memory insufficient! The version of my AAF SDK is AAF-src-1.1.3 , anybody who can give me any idea is appreciated .

        HRESULT hr=AAFLoad("./AAFWinSDK/bin/AAFCOAPI.dll" );

        aafProductIdentification_t    m_ProductInfo;
        IAAFFile*                   m_pFile;
        IAAFHeader *                m_pHeader;
        IAAFDictionary *            m_pDictionary;
        IAAFClassDef *                m_pCDMasterMob;
        IAAFClassDef *              m_pCDCDCIDescriptor;
        IAAFDataDef    *                m_pPictureDef;

        m_ProductInfo.companyName = L"Sobey Corporation";
        m_ProductInfo.productName = L"Xpri NS 2.00";
        m_ProductInfo.productVersion = new aafProductVersion_t;
        m_ProductInfo.productVersion->major = PRODUCT_VERSION_MAJOR;
        m_ProductInfo.productVersion->minor = PRODUCT_VERSION_MINOR;
        m_ProductInfo.productVersion->patchLevel = PRODUCT_VERSION_DAILY;
        m_ProductInfo.productVersion->tertiary = PRODUCT_VERSION_BUILD;
    #ifdef _DEBUG
        m_ProductInfo.productVersion->type = kAAFVersionDebug;
    #else
        m_ProductInfo.productVersion->type = kAAFVersionReleased;
    #endif
        m_ProductInfo.productVersionString = NULL;
        m_ProductInfo.productID.Data1 = PRODUCT_UUID.Data1;
        m_ProductInfo.productID.Data2 = PRODUCT_UUID.Data2;
        m_ProductInfo.productID.Data3 = PRODUCT_UUID.Data3;
        memcpy(m_ProductInfo.productID.Data4, PRODUCT_UUID.Data4, 8);
        m_ProductInfo.platform = L"Window XP";

        hr = (AAFFileOpenNewModify (L"./First Compostion.aaf", 0, &m_ProductInfo, &m_pFile));
        delete m_ProductInfo.productVersion;

        hr =(m_pFile->GetHeader(&m_pHeader));
        hr =(m_pHeader->GetDictionary(&m_pDictionary));

        hr = (m_pDictionary->LookupDataDef(kAAFDataDef_Picture, &m_pPictureDef));
        hr = (m_pDictionary->LookupClassDef(AUID_AAFCDCIDescriptor, &m_pCDCDCIDescriptor));
        hr = (m_pDictionary->LookupClassDef(AUID_AAFMasterMob, &m_pCDMasterMob));

        IAAFPluginManager    *mgr = NULL;

        // Load the plugin manager
        hr =(AAFGetPluginManager(&mgr));

        // Attempt load and register all of the plugins
        // in the shared plugin directory.
        hr = (mgr->RegisterSharedPlugins());

        IAAFMasterMob*     pMasterMob =NULL;
        IAAFMob*           pMob         =NULL;
        aafMobID_t                    masterMobID;
        aafRational_t                editRate = {25, 1};
        aafRational_t                stusampleRate = {25, 1};

        hr=m_pCDMasterMob->CreateInstance(IID_IAAFMasterMob,(IUnknown **)&pMasterMob);
        hr=pMasterMob->QueryInterface(IID_IAAFMob, (void **)&pMob);
        hr=pMob->GetMobID(&masterMobID);
        hr=pMob->SetName(L"A Master Mob");
        hr=m_pHeader->AddMob(pMob);

        IAAFEssenceAccess*                                pEssenceAccess;

        hr=pMasterMob->CreateEssence(1,
            m_pPictureDef,
            kAAFCodecCDCI,
            editRate,
            stusampleRate,
            kAAFCompressionDisable,
            NULL,
            ContainerAAF,
            &pEssenceAccess);

        hr = (pEssenceAccess->SetEssenceCodecFlavour(kAAFCodecFlavour_DV_Based_25Mbps_625_50));

        aafUInt32        samplesWritten, bytesWritten;
        LPBYTE pBuffer = new BYTE[144000];
        for(INT l=0;l<40000;l++)
        {
            hr =(pEssenceAccess->WriteSamples(1,   
                static_cast<aafUInt32>(144000), // buffer size
                pBuffer,    // THE data
                &samplesWritten,
                &bytesWritten));

        }

        hr = pEssenceAccess->CompleteWrite();

        if(pBuffer)
            delete[]  pBuffer;

        if(pEssenceAccess)
        {
            pEssenceAccess->Release();
            pEssenceAccess = NULL;
        }

        if(m_pPictureDef)
        {
            m_pPictureDef->Release();
            m_pPictureDef = NULL;
        }
        if(m_pCDMasterMob)
        {
            m_pCDMasterMob->Release();
            m_pCDMasterMob = NULL;
        }
        if(m_pCDCDCIDescriptor)
        {
            m_pCDCDCIDescriptor->Release();
            m_pCDCDCIDescriptor = NULL;
        }

        if(m_pHeader)
        {
            m_pHeader->Release();
            m_pHeader = NULL;
        }

        if(mgr)
        {
            mgr->Release();
            mgr = NULL;
        }
        if(m_pDictionary)
        {
            m_pDictionary->Release();
            m_pDictionary = NULL;
        }

        if(m_pFile)
        {
            m_pFile->Save();
            m_pFile->Close();//Here , all memory came back!!!
            m_pFile->Release();
        }

        AAFUnload();

     
    • Stuart Cunningham

      Hello,

      I can reproduce this problem on the Linux machine I have to hand.  For the 40,000 frames in the test I see memory usage steadily increase from about 14MB to start with to 120MB, increasing at a rate of 1MB per second which corresponds to 1MB for every 500 or so frames written (each frame being 144000 bytes).

      A similar test can be run from test/com/ScaleTest of the AAF SDK.  The following arguments to ScaleTest will reproduce approximately the same steps:
        ScaleTest -c -d -n 40000

      Here I also see a steadily increasing memory usage.

      I will try to narrow down exactly where the memory increase is occurring.  This issue would certainly be a problem when writing AAF files containing big blobs of essence.

      Regards,

      Stuart Cunningham

       
    • jia yining

      jia yining - 2008-12-17

           Thanks, Mr Cunningham. In order to solve this problem ,I have to close my file everytime after one essencedata is finished exporting,just for getting my memory back. but it still a problem when we export large files. So it will be a great news if you
      can solve this problems.
           Here now ,I have another question.
           Does AAF SDK version 1.1.3 which is the latest version I can get form aafassociation support DV50,Dv100,AVC50/100? I cann't find them form the sourcecode , Are they already on the schedule?

       

Log in to post a comment.