Search code examples
c#authenticationurirtsp

Send RTSP Authentication C#


I am simply trying write a program in C# (windows forms) to play a video from an acquired URI that is password protected. The point of the program was to locate a URI using SOAPs and other means in order to stream a specific video feed. I didn't know the most difficult part of the project would be simply playing the video. I assumed there had to be libraries out there that could handle this. While there is plenty that can play a video, I am struggling to figure out how to handle RTSP streaming with authentication.

Tried formatting the URI object with UserName and Password. This throws a bad formatting error. Even though the final results follows good formatting according Wiki "IsWellFormedUriString" still throws an error.

        local_uri.Host = deviceUri.Host;
        local_uri.Port = 554;
        local_uri.Scheme = "rtsp";
        local_uri.Password = "admin";
        local_uri.UserName = "admin";
        //List full URI info. 
        infoBox.Text = local_uri.ToString();

        //Past it to VideoView and start playing video. 
        bool check = Uri.IsWellFormedUriString(local_uri.Uri.ToString(), UriKind.RelativeOrAbsolute);
        bool check = true;

        if (check)
        {
            //_mp is of type LibVlcSharp.Shared.MediaPlayer
            _mp.Play(new Media(_libVLC, local_uri.Uri));
            check = false;
        }
        else
            check = false; 

I've tired to get a depreciated version of the VLC library working but seem to be running into the same issues. Looked through c# VLC lib and didn't find any function that would obviously handle authorization. I then started just trying to write code to handle, buffer, and play the data. I think this will be out of the question for how time consuming it is and given the time constrains on this assignment.

I know the URI i get back is valid. I can open VLC and entire the URI. A moment later the following pops up... enter image description here

Once its entered I see a RTSP package sent to the URL...

 DESCRIBE rtsp://192.168.1.64:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1 RTSP/1.0
    CSeq: 7
    Authorization: Digest username="admin", realm="IP Camera(C6990)", nonce="61218496a6adcf4869f748505626d63a", uri="rtsp://192.168.1.64:554/Streaming/Channels/101?transportmode=unicast&profile=Profile_1", response="3cce04175b5b1a3d0a6a8dcfea9d377a"
    User-Agent: LibVLC/3.0.11 (LIVE555 Streaming Media v2016.11.28)
    Accept: application/sdp

Then of course the URL responds with an 200 Ok and starts streaming. It would be great if I could figure out how to recreate this event in C#. I had a recommendations of doing a Dialog API but cannot figure out how to work that out with the VLC Object. Any direction would be greatly appreciated. Hindsight I should not have chosen a different project as this is attached to my grade.


Solution

  • As it turns out (and I'm not entirely sure why) but the code above does work as long as your password does not contain anything that would cause string formatting error. For example, the password cannot contain an "@" symbol with the code above. I'm sure there is a workaround for this but have not figured out what it is.