motion
motion copied to clipboard
Make error message more helpful when RTSP stream is used without RTSP support
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.
What if motion is built with rtsp support, but the stream URL is malformed?
I can see four possible situations:
- There is RTSP support and the URI is correct.
- There is RTSP support and the URI is malformed.
- RTSP support is missing and the URI is correct and doesn't start by
rtsp://
. - RTSP support is missing and the URI is correct and starts with
rtsp://
. - 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.