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

Make error message more helpful when RTSP stream is used without RTSP support #35

Open
arseni-mourzenko opened this issue Nov 11, 2015 · 2 comments

Comments

@arseni-mourzenko
Copy link

Using motion for RTSP streams results in the error similar to:

[1] [CRT] [NET] netcam_start: Invalid netcam_url (rtsp://192.168.1.64/live.sdp)

When inspecting the code, I see that the error is actually shown when the regular expression which extracts the different parts of an URI doesn't work.

The regular expression is defined like this:

#ifdef have_av_get_media_type_string    
    const char *re = "(http|ftp|mjpg|rtsp)://(((.*):(.*))@)?"
                     "([^/:]|[-.a-z0-9]+)(:([0-9]+))?($|(/[^:]*))";
#else
    const char *re = "(http|ftp|mjpg)://(((.*):(.*))@)?"
                     "([^/:]|[-.a-z0-9]+)(:([0-9]+))?($|(/[^:]*))";
#endif

which means that if I see the error, the motion package has no support for RTSP. But how would a user know that? The documentation inside the /etc/motion/motion.conf file appears, in this case, misleading:

# URL to use if you are using a network camera, size will be autodetected (incl
http:// ftp:// mjpg:// rstp:// or file:///)
# Must be a URL that returns single jpeg pictures or a raw mjpeg stream. Default
: Not defined
netcam_url rtsp://192.168.1.64:554/live.sdp

In order to help users figure out the origin of the issue, consider showing a more helpful error message. For instance, if RTSP support is not enabled, an additional check could verify that the URI starts by rstp://, and if it does, the error could be:

[1] [CRT] [NET] netcam_start: Invalid netcam_url (rtsp://192.168.1.64/live.sdp). RTSP is not supported by the current build; consider compiling the application with have_av_get_media_type_string option.

@tosiara
Copy link

tosiara commented Nov 12, 2015

What if motion is built with rtsp support, but the stream URL is malformed?

@arseni-mourzenko
Copy link
Author

I can see four possible situations:

  1. There is RTSP support and the URI is correct.
  2. There is RTSP support and the URI is malformed.
  3. RTSP support is missing and the URI is correct and doesn't start by rtsp://.
  4. RTSP support is missing and the URI is correct and starts with rtsp://.
  5. RTSP support is missing and the URI is malformed.

Currently, the cases 2, 4 and 5 produce all the same “Invalid netcam_url” error. Especially at the level of regular expressions, as currently implemented, there is no way to differentiate the case 4 and 5.

What I suggest is only to make an additional check for the prefix only in the situation where regular expressions fail and the support for RTSP is missing, thus differentiating the case 4 from the case 5. Regular expressions remain unchanged.

I imagine that instead of:

if (!url.host) {
    MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, "%s: Invalid netcam_url (%s)", 
               cnt->conf.netcam_url);
    netcam_url_free(&url);
    return -1;
}

the changed code will look like this (I haven't written C for the last ten years, so I have no idea about the exact syntax; otherwise I would have forked the project to do the change myself):

if (!url.host) {
    char[] error_pattern = "%s: Invalid netcam_url (%s)";
    #ifndef have_av_get_media_type_string
    // RTSP support is missing.
    if (strncmp("rtsp://", tolower(cnt->conf.netcam_url)) == 0) {
        error_pattern = "%s: Invalid netcam_url (%s). RTSP is not supported by the current build; consider compiling the application with have_av_get_media_type_string option.";
    }
    #ifndef
    MOTION_LOG(CRT, TYPE_NETCAM, NO_ERRNO, error_pattern, 
               cnt->conf.netcam_url);
    netcam_url_free(&url);
    return -1;
}

So:

What if motion is built with rtsp support, but the stream URL is malformed?

This situation is not concerned: only the case where RTSP support is missing is.

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

2 participants