After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 736314 - omxaudiodec: Does not unmap input buffers
omxaudiodec: Does not unmap input buffers
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-omx
1.2.4
Other Linux
: Normal normal
: 1.9.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on:
Blocks:
 
 
Reported: 2014-09-09 09:55 UTC by Jun Ji
Modified: 2016-07-06 09:14 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
filesrc ! aacparse ! omxaacdec ! fakesink (397.20 KB, text/x-log)
2014-09-09 10:00 UTC, Jun Ji
  Details
filesrc ! aacparse ! avdec_aac ! fakesink (585.99 KB, text/x-log)
2014-09-09 10:01 UTC, Jun Ji
  Details
This is what I get from valgrind (3.04 KB, text/x-log)
2014-09-14 10:38 UTC, Jun Ji
  Details
a patch that fixes the memory leak reported in this post. (736 bytes, patch)
2014-09-30 01:58 UTC, Jun Ji
committed Details | Review

Description Jun Ji 2014-09-09 09:55:45 UTC
I suffer from memory leak of omxaacdec and I print log with --*REFCOUNT*:9, there is increasing refcount of allocatorsysmem. It only decreases once per like 3~5 increase. (filesrc ! aacparse ! omxaacdec ! fakesink)

In the normal case of avdec_aac, the refcount of allocatorsysmem is not more than 6~7 as maximum. (filesrc ! aacparse ! avdec_aac ! fakesink)

I believe the files I attached give great hints but it's really hard to decipher, demanding good understanding of the general pipeline process.
Comment 1 Jun Ji 2014-09-09 10:00:52 UTC
Created attachment 285722 [details]
filesrc ! aacparse ! omxaacdec ! fakesink

filesrc ! aacparse ! omxaacdec ! fakesink
Comment 2 Jun Ji 2014-09-09 10:01:56 UTC
Created attachment 285723 [details]
filesrc ! aacparse ! avdec_aac ! fakesink
Comment 3 Sebastian Dröge (slomo) 2014-09-12 12:26:46 UTC
Needs further debugging to find where exactly the buffers (or more exact: the GstMemory) are leaked. They are the ones from the source, that the parser forwards (or should forward!) and then probably are leaked inside the decoder somewhere. Maybe in the code that stores them all in an adapter.
Comment 4 Jun Ji 2014-09-14 10:38:49 UTC
Created attachment 286162 [details]
This is what I get from valgrind
Comment 5 Sebastian Dröge (slomo) 2014-09-16 07:30:02 UTC
This needs further debugging to see where exactly the memories of the source are leaked. Must be the parser or the input side of the decoder though.

Maybe the parser does conversion in the omxaacdec case but not in the other. Can you check the caps in both cases?
Comment 6 Jun Ji 2014-09-17 05:57:23 UTC
OK slomo. I'm still working hard on this issue, but if you give me some points to look first I'll take a look at them. I have full gdb environment.

About the caps, the pipeline is filesrc ! aacparse ! omxaacdec ! fakesink and the option -v shows me the below.

/GstPipeline:pipeline0/GstAacParse:aacparse0.GstPad:src: caps = audio/mpeg, framed=(boolean)true, mpegversion=(int)4, rate=(int)44100, channels=(int)2, stream-format=(string)adts

/GstPipeline:pipeline0/GstOMXAACDec-omxaacdec:omxaacdec-omxaacdec0.GstPad:sink: caps = audio/mpeg, framed=(boolean)true, mpegversion=(int)4, rate=(int)44100, channels=(int)2, stream-format=(string)adts

and the sample aac file's properties are

/ # gst-typefind-1.0 /test.aac 
/test.aac - audio/mpeg, framed=(boolean)false, mpegversion=(int)4, stream-format=(string)adts, level=(string)2, base-profile=(string)lc, profile=(string)lc, channels=(int)2, rate=(int)44100

Thus, it seems like there wouldn't be conversion??
Comment 7 Sebastian Dröge (slomo) 2014-09-17 06:43:32 UTC
Yes, but the debug logs will tell you. I would add some printfs in the various places where the buffers go through to check the refcounts of the memories inside them. That should hint you at where it's leaked.
Comment 8 Jun Ji 2014-09-26 05:59:14 UTC
I found that my pipeline only unrefs the allocatorsysmem0 for the below stack,


Breakpoint 10, gst_object_unref (object=0x20418) at gstobject.c:267
267     {
(gdb) bt
  • #0 gst_object_unref
    at gstobject.c line 267
  • #1 gst_mini_object_unref
    at gstminiobject.c line 467
  • #2 gst_memory_unref
    at ../gst/gstmemory.h line 325
  • #3 _gst_buffer_free
    at gstbuffer.c line 578
  • #4 gst_mini_object_unref
    at gstminiobject.c line 467
  • #5 gst_buffer_unref
    at ../../../gst/gstbuffer.h line 354
  • #6 gst_base_sink_set_last_buffer_unlocked
    at gstbasesink.c line 954
  • #7 gst_base_sink_set_last_buffer
    at gstbasesink.c line 966
  • #8 gst_base_sink_set_last_buffer
    at gstbasesink.c line 960
  • #9 gst_base_sink_chain_unlocked
    at gstbasesink.c line 3372
  • #10 gst_base_sink_chain_main
    at gstbasesink.c line 3486
  • #11 gst_pad_chain_data_unchecked
    at gstpad.c line 3768
  • #12 gst_pad_push_data
    at gstpad.c line 3998
  • #13 gst_audio_decoder_push_forward
    from /home/jsea/workspace/breadnut/wd-host-script/rootfs/usr/lib/libgstaudio-1.0.so.0
  • #14 gst_audio_decoder_output
    from /home/jsea/workspace/breadnut/wd-host-script/rootfs/usr/lib/libgstaudio-1.0.so.0
  • #15 gst_audio_decoder_finish_frame
    from /home/jsea/workspace/breadnut/wd-host-script/rootfs/usr/lib/libgstaudio-1.0.so.0
  • #16 gst_omx_audio_dec_loop
    at gstomxaudiodec.c line 562
  • #17 gst_task_func
    at gsttask.c line 316
  • #18 default_func
    at gsttaskpool.c line 70
  • #19 g_thread_pool_thread_proxy
    at gthreadpool.c line 309
  • #20 g_thread_proxy
    at gthread.c line 797
  • #21 start_thread
    at pthread_create.c line 313
  • #22 ??
    at ../ports/sysdeps/unix/sysv/linux/arm/clone.S line 96
  • #23 ??
    at ../ports/sysdeps/unix/sysv/linux/arm/clone.S line 96

Comment 9 Jun Ji 2014-09-26 06:06:03 UTC
while it refs the allocator for the below three cases.

#1

Breakpoint 11, gst_object_ref (object=object@entry=0x20418) at gstobject.c:242
242     {
(gdb) bt
  • #0 gst_object_ref
    at gstobject.c line 242
  • #1 gst_memory_init
    at gstmemory.c line 125
  • #2 _sysmem_init
    at gstallocator.c line 372
  • #3 _sysmem_new_block
    at gstallocator.c line 435
  • #4 default_alloc
    at gstallocator.c line 514
  • #5 gst_allocator_alloc
    at gstallocator.c line 312
  • #6 gst_buffer_new_allocate
    at gstbuffer.c line 668
  • #7 gst_audio_decoder_allocate_output_buffer
    from /home/jsea/workspace/breadnut/wd-host-script/rootfs/usr/lib/libgstaudio-1.0.so.0
  • #8 gst_omx_audio_dec_loop
    at gstomxaudiodec.c line 518
  • #9 gst_task_func
    at gsttask.c line 316
  • #10 default_func
    at gsttaskpool.c line 70
  • #11 g_thread_pool_thread_proxy
    at gthreadpool.c line 309
  • #12 g_thread_proxy
    at gthread.c line 797
  • #13 start_thread
    at pthread_create.c line 313
  • #14 ??
    at ../ports/sysdeps/unix/sysv/linux/arm/clone.S line 96
  • #15 ??
    at ../ports/sysdeps/unix/sysv/linux/arm/clone.S line 96
  • #0 gst_object_ref
    at gstobject.c line 242
  • #1 gst_memory_init
    at gstmemory.c line 125
  • #2 _sysmem_init
    at gstallocator.c line 372
  • #3 _sysmem_new_block
    at gstallocator.c line 435
  • #4 default_alloc
    at gstallocator.c line 514
  • #5 gst_allocator_alloc
    at gstallocator.c line 312
  • #6 gst_buffer_new_allocate
    at gstbuffer.c line 668
  • #7 gst_base_src_default_alloc
    at gstbasesrc.c line 1438
  • #8 gst_base_src_default_create
    at gstbasesrc.c line 1476
  • #9 gst_base_src_get_range
    at gstbasesrc.c line 2466
  • #10 gst_base_src_getrange
    at gstbasesrc.c line 2633
  • #11 gst_pad_get_range_unchecked
    at gstpad.c line 4184
  • #12 gst_pad_pull_range
    at gstpad.c line 4414
  • #13 gst_base_parse_pull_range
    at gstbaseparse.c line 2957
  • #14 gst_base_parse_scan_frame
    at gstbaseparse.c line 3096
  • #15 gst_base_parse_loop
    at gstbaseparse.c line 3204
  • #16 gst_task_func
    at gsttask.c line 316
  • #17 default_func
    at gsttaskpool.c line 70
  • #18 g_thread_pool_thread_proxy
    at gthreadpool.c line 309
  • #19 g_thread_proxy
    at gthread.c line 797
  • #20 start_thread
    at pthread_create.c line 313
  • #21 ??
    at ../ports/sysdeps/unix/sysv/linux/arm/clone.S line 96
  • #22 ??
    at ../ports/sysdeps/unix/sysv/linux/arm/clone.S line 96
  • #0 gst_object_ref
    at gstobject.c line 242
  • #1 gst_memory_init
    at gstmemory.c line 125
  • #2 _sysmem_init
    at gstallocator.c line 372
  • #3 _sysmem_new
    at gstallocator.c line 393
  • #4 _sysmem_share
    at gstallocator.c line 483
  • #5 gst_memory_share
    at gstmemory.c line 388
  • #6 gst_buffer_copy_into
    at gstbuffer.c line 451
  • #7 gst_buffer_copy_region
    at gstbuffer.c line 1795
  • #8 gst_adapter_take_buffer
    at gstadapter.c line 856
  • #9 gst_base_parse_finish_frame
    at gstbaseparse.c line 2445
  • #10 gst_aac_parse_handle_frame
    at gstaacparse.c line 1302
  • #11 gst_base_parse_handle_buffer
    at gstbaseparse.c line 1979
  • #12 gst_base_parse_scan_frame
    at gstbaseparse.c line 3131
  • #13 gst_base_parse_loop
    at gstbaseparse.c line 3204
  • #14 gst_task_func
    at gsttask.c line 316
  • #15 default_func
    at gsttaskpool.c line 70
  • #16 g_thread_pool_thread_proxy
    at gthreadpool.c line 309
  • #17 g_thread_proxy
    at gthread.c line 797
  • #18 start_thread
    at pthread_create.c line 313
  • #19 ??
    at ../ports/sysdeps/unix/sysv/linux/arm/clone.S line 96
  • #20 ??
    at ../ports/sysdeps/unix/sysv/linux/arm/clone.S line 96

Comment 10 Jun Ji 2014-09-26 06:09:28 UTC
so if the alloctor in/decreases its refcount by only gst_object_ref/unref, this information would be hopefully a great hint..
Comment 11 Jun Ji 2014-09-26 06:35:42 UTC
I'm relieved to know that the allocatorsysmem0 really changes it refcount by only gst_object_ref/unref, meaning that the above stack cases are the all happening to this object for refcount.
Comment 12 Jun Ji 2014-09-26 06:43:04 UTC
it refcount => its refcount
Comment 13 Sebastian Dröge (slomo) 2014-09-26 07:34:02 UTC
However what is leaked here is the memory, not the allocator. The allocator is a singleton.
Comment 14 Jun Ji 2014-09-30 01:58:33 UTC
Created attachment 287412 [details] [review]
a patch that fixes the memory leak reported in this post.

tracked the place where the refcount of parse->priv->cache->mem unnecessarily changes and found that one of functions in gstomxaudiodec.c doesn't gst_buffer_unmap() but only increases the mem's refcount by gst_buffer_map(), making it unable to be freed, later.
Comment 15 Sebastian Dröge (slomo) 2014-09-30 07:48:22 UTC
Added some further fixes on top (moved the unmap outside the loop and added it to all error cases)

commit eba9e3f29d01f8eab2bf32e12c944ad6c5ea1fea
Author: junji <jun.ji@lge.com>
Date:   Tue Sep 30 10:50:07 2014 +0900

    omxaudiodec: Unmap input buffers after usage
    
    https://bugzilla.gnome.org/show_bug.cgi?id=736314