RTSPServer::client_filter hangs or crashes
Hello!
I've found this behaviour in gstreamer_rtsp_server::RTSPServer
that has been happening for some time in my computer, but only now I've found some time to write a proper issue.
Whenever there is at least one client connected, calling RTSPServer::client_filter
like...
rtsp_server.client_filter(Some(&mut |_, _| RTSPFilterResult::Remove));
...will make the program hang or crash.
Many different error messages appear, but the one I've been getting with the example that I'm attaching below is malloc(): unsorted double linked list corrupted
.
The steps to reproduce this error are the following:
- Run the snippet attached below;
- Connect to the RTSP server that the snippet makes available with
gst-launch-1.0 rtspsrc location="rtsp://0.0.0.0:8554/stream" user-id="" user-pw="" ! rtph264depay ! avdec_h264 ! autovideosink
; - Eventually the snippet will raise an error.
Is there something that I should be doing differently?
Obs.: The problem persists even when I remove the factory before removing the clients, inside the loop.
Obs.: This snippet was based on this test.
use gstreamer_rtsp_server::prelude::*;
use {
glib::{MainContext, MainLoop},
gstreamer_rtsp_server::{RTSPFilterResult, RTSPMediaFactory, RTSPServer},
std::{thread, time::Duration},
};
fn main() {
gstreamer::init().unwrap();
let main_context = MainContext::new();
let main_loop = MainLoop::new(Some(&main_context), false);
let rtsp_server = RTSPServer::new();
rtsp_server.set_service("8554");
let source_id = rtsp_server.attach(Some(&main_context));
thread::spawn({
let main_loop = main_loop.clone();
move || {
main_loop.run();
main_context
.find_source_by_id(&source_id)
.unwrap()
.destroy();
}
});
while let false = main_loop.is_running() {
thread::sleep(Duration::from_millis(100));
}
let launch = concat!(
"videotestsrc is-live=true ! ",
"video/x-raw,width=640,height=480 ! ",
"x264enc key-int-max=40 ! ",
"rtph264pay name=pay0",
);
let media_factory = RTSPMediaFactory::new();
media_factory.set_launch(launch);
media_factory.set_shared(true);
rtsp_server
.get_mount_points()
.unwrap()
.add_factory("/stream", &media_factory);
println!(
"RTSP server is running on rtsp://{}:{}/stream",
rtsp_server.get_address().unwrap(),
rtsp_server.get_bound_port()
);
for index in 1.. {
println!("Removing clients for the [{}]th time", index);
rtsp_server.client_filter(Some(&mut |_, _| RTSPFilterResult::Remove));
thread::sleep(Duration::from_secs(10));
}
}