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.

H.264 HP encoder for C66x memory problem with 176x144 resolution

Hi,

I am using H.264 HP encoder for c66x platform (100.V.H264HP.E.C6678.01.00). When I configure resolution 176x144 free memory "dissapears" while algInit call.

As you know algInit calls shmmem* callbacks. I added logging of free memory to the callbacks and got the following result:

[C66xx_0] main() on CORE=0
Initialize RMAN
Start SYS/BIOS
test_task
Create encoder
WARNING: Not supported parent functions
space=17 pointer=80000180 size=d900
space=0 pointer=00800000 size=32000
space=17 pointer=8000da80 size=300000
space=17 pointer=8030da80 size=d580
space=17 pointer=8031b000 size=d580
space=17 pointer=80328580 size=32000
space=17 pointer=8035a580 size=518c
space=0 pointer=00832000 size=1800
space=17 pointer=8035f780 size=380
space=17 pointer=8035fb00 size=10000
space=17 pointer=8036fb00 size=800
space=0 pointer=00833800 size=800
space=0 pointer=00834000 size=300
space=17 pointer=80370300 size=200
space=17 pointer=80370500 size=900
space=0 pointer=00834300 size=2000
space=17 pointer=80370e00 size=80
space=17 pointer=80370e80 size=80
space=17 pointer=80370f00 size=80
space=17 pointer=80370f80 size=2a80
space=17 pointer=80373a00 size=200
algInit BEGIN
shmmap 0 15048 2 0
external memory size total=268435456 free=264815728
external memory size total=268435456 free=264815728
shmmap 1 176 2 0
external memory size total=268435456 free=264815728
external memory size total=268435456 free=264815728
shmmap 2 11104 2 0
external memory size total=268435456 free=264815728
external memory size total=268435456 free=264815728
shmmap 3 760 2 0
external memory size total=268435456 free=264815728
external memory size total=268435456 free=264815728
shmmap 4 431424 0 0
external memory size total=268435456 free=264815728
external memory size total=268435456 free=264384304
shmmap 5 5576 2 0
external memory size total=268435456 free=264384304
external memory size total=268435456 free=264384304
shmmap 6 264 0 0
external memory size total=268435456 free=264384304
external memory size total=268435456 free=264384040
shmmap_sync 6 0
external memory size total=268435456 free=176
shmmap 7 3145728 0 0
external memory size total=268435456 free=176
[t=0x001e35fc] ti.sysbios.heaps.HeapMem: ERROR: line 294: out of memory: handle=0x901bcdb8, size=3145728
ti.sysbios.heaps.HeapMem: line 294: out of memory: handle=0x901bcdb8, size=3145728
external memory size total=268435456 free=176
algInit END
algInit failed: -1
space=17 pointer=80000180 size=d900
space=0 pointer=00800000 size=32000
space=17 pointer=8000da80 size=300000
space=17 pointer=8030da80 size=d580
space=17 pointer=8031b000 size=d580
space=17 pointer=80328580 size=32000
space=17 pointer=8035a580 size=518c
space=0 pointer=00832000 size=1800
space=17 pointer=8035f780 size=380
space=17 pointer=8035fb00 size=10000
space=17 pointer=8036fb00 size=800
space=0 pointer=00833800 size=800
space=0 pointer=00834000 size=300
space=17 pointer=80370300 size=200
space=17 pointer=80370500 size=900
space=0 pointer=00834300 size=2000
space=17 pointer=80370e00 size=80
space=17 pointer=80370e80 size=80
space=17 pointer=80370f00 size=80
space=17 pointer=80370f80 size=2a80
space=17 pointer=80373a00 size=200
Failed to create encoder

As you see huge amount of memory disappears inside algInit and it fails with -1 error because of memory allocation problems. There is no problems with other bigger resolutions. I see the same problem in totally different programs that use HP encoder: in simple test that is attached to the post and in production transcoder.

The attached test project reproduces the bug. It is little modified test from another thread: http://e2e.ti.com/support/embedded/multimedia_software_codecs/f/356/p/234891/832080.aspx

You can read description how to use the test there.

Can you please help to understand why memory disappears inside algInit?

Andrey Lisnevich

h264hp_test.zip
  • Forgot to mention interesting facts:

    1) in both programs (test project and production transcoder project) always only 176 free bytes left.

    2) 176 is width resolution

    So it looks like memory corruption.

  • Hi Andrey,

    It looks like there is some issue in memory allocation. we are further working on issue. For now we identified below issue...

    There is a check in the code shared by him as shown below : 
    Memory_alloc((attr == IVIDMC_SHMEM_ATTRS_DDR_CACHED) ? NULL : sharedMemoryHeap, shmem_size, alignment, &eb);in shmmap_test( ).

    In initobj( ), shared memory keys 4,6 and 7 are having attribute as "IVIDMC_SHMEM_ATTRS_DDR_CACHED" and the above statement check is not allocating memory as desired. 
    Regards
    Rama
  • Hi Rama,

    In other production project I allocate memory perfectly correct (as I understand it):

    allocatedMemory = Memory_alloc((attr == IVIDMC_SHMEM_ATTRS_SL2) ? sharedMemoryHeap : externalMemoryHeap, shmem_size, alignment, &eb);

    sharedMemoryHeap is in MSMCSRAM, externalMemoryHeap is in cache-enabled DDR3. And the problem still exists.

    And after algInit only 176 bytes left in externalMemoryHeap (i.e. not in default NULL heap)

    You can very easily allocate memory correctly by slightly changing test project and adding caching to DDR3 region. But as I see it does not fix the issue.

    Regards,

    Andriy Lysnevych

  • Hi Andrey,

    We have root caused the issue. With the specified configuration (176x144) one of the memtab request is non multiple of 16. Allocated memory is reset to zero by codec for this memtab. Reset function in codec is not checking for 16 byte alignment and overwriting other memtab area.

    We will take care of this issue in coming releases for H264 HP encoder. As a workaround you can allocate multiple of 16 byte memory chunks even though memory request is non multiple of 16.

    Regards,

    Rama

  • Hi Rama,

    This workaround fixed the issue.

    Thanks