Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BadRequest answer when sending RTSP SETUP request to camera #110

Open
perkasthor opened this issue May 31, 2021 · 0 comments
Open

BadRequest answer when sending RTSP SETUP request to camera #110

perkasthor opened this issue May 31, 2021 · 0 comments

Comments

@perkasthor
Copy link

Description
When trying to connect a recently updated Vivotek camera, I get a "Bad Request" answer from the camera.
After downloading and debugging the code, I saw that this happened during the RTSP SETUP request.
Using Wireshark, I compared the requests from RtspClientSharp and "ONVIF Device Manager" software, and indeed, the requests are different.
It appears that RtspClientSharp does not support URIs containing queries when appending track name:

  • SETUP URI from RtspClientSharp (wrong): rtsp://<ip>:554/media2/stream.sdp/trackID=2?profile=Profile381b/
  • SETUP URI from ONVIF Device Manager (working): rtsp://<ip>:554/media2/stream.sdp?profile=Profile381b/trackID=2

I've modified the code to support appending track name to either the URI path or query, see my modification below.
File: RtspRequestMessageFactory.cs
Code modification (end of file)

private Uri GetTrackUri(string trackName)
{
    Uri trackUri;

    if (!Uri.IsWellFormedUriString(trackName, UriKind.Absolute))
    {
        var uriBuilder = new UriBuilder(GetContentBasedUri());

        // old
        //bool trackNameStartsWithSlash = trackName.StartsWith("/");
        //if (uriBuilder.Path.EndsWith("/"))
        //    uriBuilder.Path += trackNameStartsWithSlash ? trackName.Substring(1) : trackName;
        //else
        //    uriBuilder.Path += trackNameStartsWithSlash ? trackName : "/" + trackName;

        // new
        if (string.IsNullOrWhiteSpace(uriBuilder.Query))
            uriBuilder.Path = AppendTrackToUri(uriBuilder.Path, trackName);
        else
            uriBuilder.Query = AppendTrackToUri(uriBuilder.Query, trackName);

        trackUri = uriBuilder.Uri;
    }
    else
        trackUri = new Uri(trackName, UriKind.Absolute);

    return trackUri;
}

private static string AppendTrackToUri(string uriPart, string trackName)
{
    bool trackNameStartsWithSlash = trackName.StartsWith("/");

    if (uriPart.EndsWith("/"))
        return uriPart + (trackNameStartsWithSlash ? trackName.Substring(1) : trackName);
    return uriPart + (trackNameStartsWithSlash ? trackName : "/" + trackName);
}

Fell free to integrate this change in the source code. I'm new to GitHub and don't want to mess with this depot ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant