memory leak when reconnection to camera using gstreamer on TX1 platform

Recently, I met a memory leak problem on TX1 platform, when my gstreamer application tried to reconnect to the camera by rtsp.
Moreover, the tegra I’m using is:

R28 (release), REVISION: 2.0, GCID: 10567845, BOARD: t210ref, EABI: aarch64, DATE: Fri Mar 2 04:58:16 UTC 2018

Gstreamer is:
gst-inspect-1.0 version 1.8.1
GStreamer 1.8.3
https://launchpad.net/distros/ubuntu/+source/gstreamer1.0

Problem Details:

  1.  The application will call gst_init() at the very first, then builds pipleline as “rtspsrc location=rtsp://${usrname}:${pwd}@${ip}:${port}/cam/realmonitor?channel=1&subtype=0 protocols=tcp ! rtph264depay ! h264parse ! omxh264dec ! video/x-raw, format=NV12 ! appsink sync=false async=false name=appsink1”. 
    

As expected, it gets data from camera. By top commands, I can see its occupied-memory is ~108M;
(disable ${ip})
2. Of course, the application fails to get data. And the application is trying to reconnect the pipeline periodically. It is still occupied ~108M;
(enable ${ip})
3. The application succeeds to get video again. However, the memory rises to ~180M!
After trying 2,3 for times, I finds that: the memory will increase by ~80M each time when it succeed in reconnection.

The following code segment is the reconnection (first close() then open()). I think I have unref all the resources in close(), in addition, I unref gst-sample, gst-message in time.

int GSTCameraMini::open() {
this->m_camera_state = CAM_INIT;
this → build_pipeline();
gst_element_set_state(this → pipeline, GST_STATE_PLAYING);
return 0;
}

int GSTCameraMini::close() {
this->m_camera_state = CAM_OFFLINE;
gst_element_set_state(this → pipeline, GST_STATE_NULL);
// unref appsink
gst_object_unref(G_OBJECT(this → appsink));
// unref bus
gst_object_unref(G_OBJECT(this → bus));
// unref pipeline
gst_object_unref(G_OBJECT(this → pipeline));
return 0;
}

I have no idea where goes wrong, and this problem makes me headache for a long time. It is a bug from gstreamer or other?
Sincerely looking forward to your reply.

Hi,
We have rtsp usecase in below post:
[url]https://devtalk.nvidia.com/default/topic/1014789/jetson-tx1/-the-cpu-usage-cannot-down-use-cuda-decode-/post/5188538/#5188538[/url]
It is working well without any memory leak being observed. Please compare it to your implementation.

hi DaneLLL,

Thanks for you quick reply!
I have reviewed your recommended post, however, I think it is not helpful to my problem.

As mentioned above, my problem occurs after I recreate a new pipeline after I unref the pipeline, the memory will increase/leak, while if the pipeline works well, I can get the video and the memory is stable.

I hope I have clarify my problem, thanks!

Hi,
We suggest you break down the pipeline to clarify where the leak is from.

rtspsrc location=rtsp://${usrname}:${pwd}@${ip}:${port}/cam/realmonitor?channel=1&subtype=0 protocols=tcp ! rtph264depay ! h264parse ! omxh264dec ! video/x-raw, format=NV12 ! fakesink
rtspsrc location=rtsp://${usrname}:${pwd}@${ip}:${port}/cam/realmonitor?channel=1&subtype=0 protocols=tcp ! rtph264depay ! h264parse ! avdec_h264 ! video/x-raw, format=NV12 ! fakesink
rtspsrc location=rtsp://${usrname}:${pwd}@${ip}:${port}/cam/realmonitor?channel=1&subtype=0 protocols=tcp ! rtph264depay ! fakesink
rtspsrc location=rtsp://${usrname}:${pwd}@${ip}:${port}/cam/realmonitor?channel=1&subtype=0 protocols=tcp ! fakesink

Hi hi DaneLLL,

I have tried the top3 pipeline and record its memory performance:

2. rtspsrc location=rtsp://${usrname}:${pwd}@${ip}:${port}/cam/realmonitor?channel=1&subtype=0 protocols=tcp ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! video/x-raw, format=NV12 ! appsink sync=false async=false name=appsink1

the memory will increase by ~80M every time it successfully reconnects to the camera.

3. rtspsrc location=rtsp://admin:admin@192.168.1.150:554/cam/realmonitor?channel=1&subtype=0 protocols=tcp ! rtph264depay  ! appsink sync=false async=false name=appsink1

my appsink failed to get the YUV video.

Moreover, I find that the memory will only increase when it successfully reconnect to the camera.

I guess the pipeline does not release the resources even if I call unref, and when I rebuild a new pipeline, it applies new resources again…

I sincerely need your help, thanks again!

Hi,
We suggest you go to http://gstreamer-devel.966125.n4.nabble.com/

NVIDIA-developed element is omxh264dec. If you replace it with avdec_264 and the issue is still present, it is more like an issue in your implementation.

rtspsrc location=rtsp://${usrname}:${pwd}@${ip}:${port}/cam/realmonitor?channel=1&subtype=0 protocols=tcp ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! video/x-raw, format=NV12 ! appsink sync=false async=false name=appsink1

Not sure but if you see ~80M leak, it seems you miss to unref certain GstBuffers. This is just guess. Please go to gstreamer forum to get help.

Hi,

Thanks for your suggestion!

Now I have refactor my application, and the memory will not leak for each reconnection by top. But for the first time, it will. Moreover, I use valgrind tool, and its report shows my application still has memory leakage without details, I guess if the leakage comes from the lib?

Do you have any suggestion on how to fix such issue rootly?

Great thanks!

Hi,
The result of valgrind can be for reference. We have tests before each release, so omxh264dec should be pretty stable.

Hi,

Thanks for your helpfully suggestion, yes, omxh264dec does not have problem, the memory leakage seems coming from other part of gstreamer or other, we will look deep into that.

Best!