This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Runtime IALG_alloc dynamic memory allocation

I have a video codec that can be used on D1 and Megapixel sized video.

We currently have to allocate memory banks via IALG_numAlloc and IALG_alloc for the worst case scenario of a Megapixel size buffer.

Is there anyway to modify the size of the banks returned by IALG_alloc during the IVIDENC_create using the extended parameters?

 

Thanks,

 

Matt

  • Are you the codec producer?

    If so, it's true that your IALG_Fxns->algNumAlloc() must return an Int with the worst case number of memTabs your codec may require.  But the IVIDENC_Params (passed to your IALG_Fxns->algAlloc()) could/should indicate which mode your codec will run in - and the actual memory required, in the memTabs returned by IALG_Fxns->algAlloc(), can be less than the Int returned by IALG_Fxns->algNumAlloc().  Finally, the memory should only be allocated by the framework after IALG_Fxns->algAlloc() reports what the _actual_ needs are (not the worst case needs), and the memory is provided to the codec via IALG_Fxns->algInit().

    So you really should only be requesting the memory you need for the mode indicated in the create params.

    Is that what you're asking?

    Chris

  • Thanks for the response, Chris.

    We produce the codec.

    We have implemented:

    • IALG_Fxns->algNumAlloc();
    • IALG_Fxns->algAlloc();
    • IALG_Fxns->algInit();

    So from dskt2crea.c:

    numRecs = fxns->algNumAlloc();
    sizeofMemTab = numRecs * sizeof(IALG_MemRec);
    memTab = MEM_calloc(_DSKT2_heapID, sizeofMemTab, 0);
    numRecs = fxns->algAlloc((IALG_Params *)params, &fxnsPtr, memTab);
    for (i = 0; i < numRecs; i++) {
        _DSKT2_assignInstanceMemory(scratchId, memTab, numRecs, extHeapId)    
    }
    status = fxns->algInit(alg, memTab, NULL, (IALG_Params *)params) ;

    We have currently introduced a new feature in our application that can take up 5MB of memory.  When running four codecs on the DM6467 this extra 20MB is a major problem.

    So for example:

    • IALG_Fxns->algNumAlloc() has been increase from 20 to 21
    • IALG_Fxns->algAlloc() returns worst case 5MB (for Megapixel) for that new memTab
    • IALG_Fxns->algInit() uses 1MB for D1 leaving 4MB of allocated memory space free.

    As you can see when VIDENC_Create is called DSKT2 allocated 5MB but we only really need 1MB.

    Is there anyway to change the size of the memTab at VIDENC_create:

    Int MY_CODEC_alloc(const IALG_Params *algParams, IALG_Fxns **pf, IALG_MemRec memTab[])
    {
        memTab[ MEM_SEGMENT_NEW_MEM_TAB ].size = MEGA_PIXEL_MEMORY_SIZE_NEEDED;
        memTab[ MEM_SEGMENT_NEW_MEM_TAB ].alignment = 128;
        memTab[ MEM_SEGMENT_NEW_MEM_TAB ].space = IALG_EXTERNAL;
        memTab[ MEM_SEGMENT_NEW_MEM_TAB ].attrs = IALG_PERSIST;
    }

    Can I use the IALG_Params to specify the size, instead of using a #define MEGA_PIXEL_MEMORY_SIZE_NEEDED? (Only just noticed that input variable, will look into it now)

    Are those IALG_Params the input parameters from the VIDENC_create?

  • Toward the end of your reply, I think you're stumbling onto the answer.  Yes, the algParams passed into your MY_CODEC_alloc() are the same ones the app provided in VIDENC_create().  You can/should reflect on them in MY_CODEC_alloc() and set  memTab[MEM_SEGMENT_NEW_MEM_TAB].size appropriately (rather than hardcode it).

    And if the algParams _don't_ provide enough context (I hope they do!), you can always extend them with your own custom field that the app can set.  Extended params are generally discouraged as they bind the app to a particular codec, but it's sometimes needed.

    Chris

  • Thanks, Chris, you're right, I'd pretty much landed the answer.  Just traced back the IALG_Params through the framework to the VIDENC_create.

    I'll have a look over the params and will post again with what i work out.

    Cheers, for all your help, in the last thread as well ;)