Gstreamer Rust memory leak

Guru Govindan gurunathan.govindan at gmail.com
Tue Mar 29 08:18:49 UTC 2022


Hi,
I am developing a pipeline to ingest a video stream from RTSP and create
dynamic ABR ladders that would mux audio and video and mux to hlssink.

I have a create_bin function that creates an Bin element containing
queue->videorate->capsfilter->encoder->hlssink2

the queue sink is set as ghost pad like below
```
let video_ghost_pad = gst::GhostPad::with_target(Some("video"),
&video_sink_pad).unwrap();
video_ghost_pad.set_active(true).unwrap();
enc_bin.add_pad(&video_ghost_pad).unwrap();
```

Then I add the Bin to the pipeline
 `pipe_bin.add(&enc_bin).unwrap();`

I then add a probe to block downstream video from the video tee so that I
can link the video_tee src and ghost sink
```
let tee_video_pad = video_tee.request_pad_simple("src_%u").unwrap();

let video_block =
tee_video_pad.add_probe(gst::PadProbeType::BLOCK_DOWNSTREAM, |_pad, _info| {
    gst::PadProbeReturn::Ok
}).unwrap();
```
I then link the src->sink between video-tee and my Bin
```
let video_sink_pad = enc_bin.static_pad("video").unwrap();
        tee_video_pad.link(&video_sink_pad).unwrap();
```
I then call the call_async method on my Bin to sync state with parent.

```
enc_bin.call_async(move |bin| {
                if bin.sync_state_with_parent().is_err() {
                    log::error!("could not set the enc_bin_{} to playing",
width);
                }
                tee_video_pad.remove_probe(video_block);
            });
```

Everything works fine until now. ( I see that the memory increases by about
100MB depending on the resolution).

When I call to remove this Bin from the pipeline,
I call pipeline.call_async a closure that contains code to block the
video_tee sink pad
```
let video_block =
video_tee_sink_pad.add_probe(gst::PadProbeType::BLOCK_DOWNSTREAM, |_pad,
_info| {
                 gst::PadProbeReturn::Ok
             }).unwrap();
```
I then release the request src pad and remove probe
```
video_tee.release_request_pad(&video_src_pad);
video_tee_sink_pad.remove_probe(video_block);
```
I then call unlink, remove and set the Bin I created to null

```
pipeline.unlink(&enc_bin);
let res = pipeline.remove(&enc_bin);
// I compare the result here

let state_res = enc_bin.set_state(gst::State::Null);
```

Removing seems to work fine as well. However the memory that was allocated
during the creation of the ABR never gets released. I see that it keeps
increasing slowly.

Generating the debug_dump_dot file after removal shows that the bin and the
src pads dont exists anymore.

But everytime I create a new Bin, the memory increases and never releases.

FYI, I am using vaapi encoders for this.

I appreciate any help in this regard. It would be really helpful if you
could even provide any other tools that might help me with this!

Best Regards,
Guru
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20220329/747a757a/attachment.htm>


More information about the gstreamer-devel mailing list