0

I'm implementing an RTSP player in a Xamarin.Forms app. The video plays in the VideoView for 60 seconds before the stream is stopped. According to the Videolan Command Line Help the default rtsp timeout is 60 seconds. I have been unable to override this using the various option formats provided.

I've already tried adding the following options in both the LibVLC constructor and through the media's AddOptions method using the --, - and : prefixes, all to no avail: --rtsp-tcp --rtsp-timeout=300 --rtsp-stream-timeout=300 --sout-keep

Usage Example below:

readonly LibVLC _libvlc;
public VideoPage()
{
    InitializeComponent();
    Core.Initialize();
    _libvlc = new LibVLC(new string[] { "--rtsp-timeout=300" });
    ShowVideo();
}

private void ShowVideo()
{
    var stream = "rtsp://1.2.3.4:1234/MyStream";
    using (var media = new Media(_libvlc, stream, Media.FromType.FromLocation))
    {
        var config = new MediaConfiguration();
        config.EnableHardwareDecoding();
        media.AddOption(":rtsp-timeout=300");
        media.AddOption(config);
        VideoView0.MediaPlayer = new MediaPlayer(_libvlc);
        VideoView0.MediaPlayer.Play(media);
    }
}

I expected the stream to remain open and the video to continue playing for the given timeout duration, but it stops after 60 seconds. Any assistance would be appreciated!

EDIT

It seems the server has a 60 second time out. I don't have control over that, so the solution needs to come from the client side. How would I send a keepalive/RR packet that informs the server to keep the connection open?

feepk
  • 1,756
  • 1
  • 12
  • 14
Michael Jedd
  • 44
  • 2
  • 7
  • Do you mean wanting to continute playing video for 60 seconds after stream is stopped? – Junior Jiang Jan 14 '19 at 08:30
  • No, currently I only get 60 seconds of video playback before the stream is closed. I want to keep the stream open for longer than that. – Michael Jedd Jan 14 '19 at 09:16
  • Okey, do you test this demo about this(https://code.videolan.org/mfkl/libvlcsharp-samples/tree/master/VideoMosaic)?You should check that url and player which has problem first. – Junior Jiang Jan 14 '19 at 09:59
  • The link you posted has a typo. Correct link: https://code.videolan.org/mfkl/libvlcsharp-samples/tree/master/VideoMosaic/VideoMosaic. The sample works just fine. That isn't the problem. – Michael Jedd Jan 14 '19 at 10:13
  • Sorry for typo.If sample works fine,then when your project play stopped, error log is what? – Junior Jiang Jan 15 '19 at 01:47
  • The server has a 60 second timeout. So there isn't an error, the stream just stops playing because I don't know how to send a keep-alive request. – Michael Jedd Jan 15 '19 at 06:20

2 Answers2

0

Generally RTSP is based on TCP and RTP is based on UDP. So ideally both the channels require keep alive functionality.

If Server have setted the value of timeout you receive in SETUP response.

Session = "Session" ":" session-id [ ";" "timeout" "=" delta-seconds ]

And want to keep alive connection with RTSP server,

Client also need to Send any RTSP request periodically (OPTIONS, SET_PARAMETER or GET_PARAMETER) before timeout value received in SETUP response.

Here is the detail discussion about it.

Junior Jiang
  • 12,430
  • 1
  • 10
  • 30
0

I had this question in my bookmarks for a while and never took time to get back to you (and to be honnest, totally forgot this existed). Today, someone asked me this very question. This is actually a bug from libvlc that has just been reported here : https://code.videolan.org/videolan/vlc/-/issues/25662

I'm interested to know the brand of your camera.

The temporary workaround would be to rebuild your own libvlc version with a bigger timeout (the patch is included in the bug report).

cube45
  • 3,429
  • 2
  • 24
  • 35
  • Haha, thanks for answering! I was using a Hikvision camera. But this was long ago, and the project is a distant memory. – Michael Jedd Apr 22 '21 at 06:41