Unexplained latency in RTSP server fed by appsrc
Hey there. I'm tring to build an app which allows multiple clients to utilize my camera (not only gstreamer pipelines).
(For the sake of this discussion and for easier reproducability - I will use videotestsrc). For that, I have the following pipeline:
videotestsrc ! video/x-raw,framerate=30/1 ! timeoverlay ! video/x-raw,width=640,height=480 ! videoconvert ! video/x-raw,format=I420 ! tee name=t1 ! queue ! xvimagesink t1. ! queue ! appsink name=v4l2_lowres_appsink sync=false
I use the clockoverlay
and xvimagesink
to test my latency.
Then, I grab the buffers from the appsink by using the pull-sample
and push it to an appsrc within a GstRTSPMedia element with the push-sample
as such:
appsrc name=lowres_appsrc format=time stream-type=stream leaky-type=2 ! x264enc key-int-max=30 ! h264parse ! video/x-h264,profile=baseline ! rtph264pay name=pay0
(I only start to push buffers when the media-configure
signal is emitted).
I run the client from command line using:
gst-launch-1.0 rtspsrc location=rtsp://127.0.0.1:1234/240p timeout=10000000 latency=0 ! rtph264depay ! h264parse ! avdec_h264 ! videoconvert ! ximagesink sync=false
What I expect is that when a client connects to the RTSP server, he should recieve live footage from the camera (in this case videotestsrc) and the clocks should be synced on the windows opened. Instead, I get this weird behavior:
- If the server was running more than the
timeout
property of myrtspsrc
element - I will get a timeout. By default - 5 seconds. - If the server was running less than the
timeout
property - then the client's window will open showing the time as it was when the connection was made (it takes a few seconds before the window opens). - When I use larger
timeout
values, and wait longer before running the client, it will take longer for the client's window to open. Actually it will take exactly the time it shows on the opened window. So when the client's window opens, it will show exactly half the time the server's window shows.
This might be a dumb timestamping issue beyond my understanding, but I'm struggling and desperate for help.
Thank you!! (Here timeout was 5 seconds) (Here timeout was 20 seconds) (Here it was 5 seconds and I waited longer than 5 seconds before I started the client.