Skip to content

Commit

Permalink
Merge branch 'master' into 4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Dave committed Feb 3, 2019
2 parents 68112cb + c43a560 commit 1180151
Show file tree
Hide file tree
Showing 16 changed files with 282 additions and 100 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Summary of changes for version 4.2.2 are below
* Update version number to 4.2.2/Changelog
* Resolve compile problem for OpenBSD
* Resolve compiler warnings for 18.10
* Guide/Manual updates
* Add the quit/end webcontrol actions to interface 0
* Set the stream index on passthrough
* Revise the webcontrol stream rate
* Answer webcontrol stream only after completing first loop
* Save the preview images when triggering emulate
* Fix startup problem when using track_type 4
* Fix hostname for webcontrol when using IPV6
Summary of changes for version 4.2.1 are below
* Update version number to 4.2.1 / Changelog
* Report to log options included in build
Expand Down
6 changes: 4 additions & 2 deletions conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -2359,7 +2359,9 @@ struct context **conf_load(struct context **cnt)
exit(-1);
}

snprintf(filename, PATH_MAX, "%s/motion.conf", path);
snprintf(filename, PATH_MAX, "%.*s/motion.conf"
, (int)(PATH_MAX-1-strlen("/motion.conf"))
, path);
fp = fopen (filename, "r");
}

Expand Down Expand Up @@ -3120,7 +3122,7 @@ static struct context **config_camera(struct context **cnt, const char *str,
*/
static void usage()
{
printf("motion Version "VERSION", Copyright 2000-2018 Jeroen Vreeken/Folkert van Heusden/Kenneth Lavrsen/Motion-Project maintainers\n");
printf("motion Version "VERSION", Copyright 2000-2019 Jeroen Vreeken/Folkert van Heusden/Kenneth Lavrsen/Motion-Project maintainers\n");
printf("\nHome page :\t https://motion-project.github.io/ \n");
printf("\nusage:\tmotion [options]\n");
printf("\n\n");
Expand Down
84 changes: 68 additions & 16 deletions event.c
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,11 @@ static void event_image_detect(struct context *cnt,
imagepath = DEF_IMAGEPATH;

mystrftime(cnt, filename, sizeof(filename), imagepath, currenttime_tv, NULL, 0);
snprintf(fullfilename, PATH_MAX, "%s/%s.%s", cnt->conf.target_dir, filename, imageext(cnt));
snprintf(fullfilename, PATH_MAX, "%.*s/%.*s.%s"
, (int)(PATH_MAX-2-strlen(filename)-strlen(imageext(cnt)))
, cnt->conf.target_dir
, (int)(PATH_MAX-2-strlen(cnt->conf.target_dir)-strlen(imageext(cnt)))
, filename, imageext(cnt));

passthrough = util_check_passthrough(cnt);
if ((cnt->imgs.size_high > 0) && (!passthrough)) {
Expand Down Expand Up @@ -558,9 +562,14 @@ static void event_imagem_detect(struct context *cnt,
mystrftime(cnt, filename, sizeof(filename), imagepath, currenttime_tv, NULL, 0);

/* motion images gets same name as normal images plus an appended 'm' */
snprintf(filenamem, PATH_MAX, "%sm", filename);
snprintf(fullfilenamem, PATH_MAX, "%s/%s.%s", cnt->conf.target_dir, filenamem, imageext(cnt));

snprintf(filenamem, PATH_MAX, "%.*sm"
, (int)(PATH_MAX-1-strlen(filename))
, filename);
snprintf(fullfilenamem, PATH_MAX, "%.*s/%.*s.%s"
, (int)(PATH_MAX-2-strlen(filenamem)-strlen(imageext(cnt)))
, cnt->conf.target_dir
, (int)(PATH_MAX-2-strlen(cnt->conf.target_dir)-strlen(imageext(cnt)))
, filenamem, imageext(cnt));
put_picture(cnt, fullfilenamem, cnt->imgs.img_motion.image_norm, FTYPE_IMAGE_MOTION);
event(cnt, EVENT_FILECREATE, NULL, fullfilenamem, (void *)FTYPE_IMAGE, currenttime_tv);
}
Expand Down Expand Up @@ -593,16 +602,25 @@ static void event_image_snapshot(struct context *cnt,
snappath = DEF_SNAPPATH;

mystrftime(cnt, filepath, sizeof(filepath), snappath, currenttime_tv, NULL, 0);
snprintf(filename, PATH_MAX, "%s.%s", filepath, imageext(cnt));
snprintf(fullfilename, PATH_MAX, "%s/%s", cnt->conf.target_dir, filename);
snprintf(filename, PATH_MAX, "%.*s.%s"
, (int)(PATH_MAX-1-strlen(filepath)-strlen(imageext(cnt)))
, filepath, imageext(cnt));
snprintf(fullfilename, PATH_MAX, "%.*s/%.*s"
, (int)(PATH_MAX-1-strlen(filename))
, cnt->conf.target_dir
, (int)(PATH_MAX-1-strlen(cnt->conf.target_dir))
, filename);
put_picture(cnt, fullfilename, img_data->image_norm, FTYPE_IMAGE_SNAPSHOT);
event(cnt, EVENT_FILECREATE, NULL, fullfilename, (void *)FTYPE_IMAGE, currenttime_tv);

/*
* Update symbolic link *after* image has been written so that
* the link always points to a valid file.
*/
snprintf(linkpath, PATH_MAX, "%s/lastsnap.%s", cnt->conf.target_dir, imageext(cnt));
snprintf(linkpath, PATH_MAX, "%.*s/lastsnap.%s"
, (int)(PATH_MAX-strlen("/lastsnap.")-strlen(imageext(cnt)))
, cnt->conf.target_dir, imageext(cnt));

remove(linkpath);

if (symlink(filename, linkpath)) {
Expand All @@ -612,8 +630,14 @@ static void event_image_snapshot(struct context *cnt,
}
} else {
mystrftime(cnt, filepath, sizeof(filepath), cnt->conf.snapshot_filename, currenttime_tv, NULL, 0);
snprintf(filename, PATH_MAX, "%s.%s", filepath, imageext(cnt));
snprintf(fullfilename, PATH_MAX, "%s/%s", cnt->conf.target_dir, filename);
snprintf(filename, PATH_MAX, "%.*s.%s"
, (int)(PATH_MAX-1-strlen(imageext(cnt)))
, filepath, imageext(cnt));
snprintf(fullfilename, PATH_MAX, "%.*s/%.*s"
, (int)(PATH_MAX-1-strlen(filename))
, cnt->conf.target_dir
, (int)(PATH_MAX-1-strlen(cnt->conf.target_dir))
, filename);
remove(fullfilename);
put_picture(cnt, fullfilename, img_data->image_norm, FTYPE_IMAGE_SNAPSHOT);
event(cnt, EVENT_FILECREATE, NULL, fullfilename, (void *)FTYPE_IMAGE, currenttime_tv);
Expand Down Expand Up @@ -687,7 +711,11 @@ static void event_image_preview(struct context *cnt,
imagepath = (char *)DEF_IMAGEPATH;

mystrftime(cnt, filename, sizeof(filename), imagepath, &cnt->imgs.preview_image.timestamp_tv, NULL, 0);
snprintf(previewname, PATH_MAX, "%s/%s.%s", cnt->conf.target_dir, filename, imageext(cnt));
snprintf(previewname, PATH_MAX, "%.*s/%.*s.%s"
, (int)(PATH_MAX-2-strlen(filename)-strlen(imageext(cnt)))
, cnt->conf.target_dir
, (int)(PATH_MAX-2-strlen(cnt->conf.target_dir)-strlen(imageext(cnt)))
, filename, imageext(cnt));

passthrough = util_check_passthrough(cnt);
if ((cnt->imgs.size_high > 0) && (!passthrough)) {
Expand Down Expand Up @@ -771,7 +799,11 @@ static void event_create_extpipe(struct context *cnt,
}

mystrftime(cnt, stamp, sizeof(stamp), moviepath, currenttime_tv, NULL, 0);
snprintf(cnt->extpipefilename, PATH_MAX - 4, "%s/%s", cnt->conf.target_dir, stamp);
snprintf(cnt->extpipefilename, PATH_MAX - 4, "%.*s/%.*s"
, (int)(PATH_MAX-5-strlen(stamp))
, cnt->conf.target_dir
, (int)(PATH_MAX-5-strlen(cnt->conf.target_dir))
, stamp);

if (access(cnt->conf.target_dir, W_OK)!= 0) {
/* Permission denied */
Expand Down Expand Up @@ -943,11 +975,27 @@ static void event_ffmpeg_newfile(struct context *cnt,
codec = "msmpeg4";
break;
}
snprintf(cnt->motionfilename, PATH_MAX - 4, "%s/%s_%sm", cnt->conf.target_dir, codec, stamp);
snprintf(cnt->newfilename, PATH_MAX - 4, "%s/%s_%s", cnt->conf.target_dir, codec, stamp);
snprintf(cnt->motionfilename, PATH_MAX - 4, "%.*s/%s_%.*sm"
, (int)(PATH_MAX-7-strlen(stamp)-strlen(codec))
, cnt->conf.target_dir, codec
, (int)(PATH_MAX-7-strlen(cnt->conf.target_dir)-strlen(codec))
, stamp);
snprintf(cnt->newfilename, PATH_MAX - 4, "%.*s/%s_%.*s"
, (int)(PATH_MAX-6-strlen(stamp)-strlen(codec))
, cnt->conf.target_dir, codec
, (int)(PATH_MAX-6-strlen(cnt->conf.target_dir)-strlen(codec))
, stamp);
} else {
snprintf(cnt->motionfilename, PATH_MAX - 4, "%s/%sm", cnt->conf.target_dir, stamp);
snprintf(cnt->newfilename, PATH_MAX - 4, "%s/%s", cnt->conf.target_dir, stamp);
snprintf(cnt->motionfilename, PATH_MAX - 4, "%.*s/%.*sm"
, (int)(PATH_MAX-6-strlen(stamp))
, cnt->conf.target_dir
, (int)(PATH_MAX-6-strlen(cnt->conf.target_dir))
, stamp);
snprintf(cnt->newfilename, PATH_MAX - 4, "%.*s/%.*s"
, (int)(PATH_MAX-5-strlen(stamp))
, cnt->conf.target_dir
, (int)(PATH_MAX-5-strlen(cnt->conf.target_dir))
, stamp);
}
if (cnt->conf.movie_output) {
cnt->ffmpeg_output = mymalloc(sizeof(struct ffmpeg));
Expand Down Expand Up @@ -1056,7 +1104,11 @@ static void event_ffmpeg_timelapse(struct context *cnt,
mystrftime(cnt, tmp, sizeof(tmp), timepath, currenttime_tv, NULL, 0);

/* PATH_MAX - 4 to allow for .mpg to be appended without overflow */
snprintf(cnt->timelapsefilename, PATH_MAX - 4, "%s/%s", cnt->conf.target_dir, tmp);
snprintf(cnt->timelapsefilename, PATH_MAX - 4, "%.*s/%.*s"
, (int)(PATH_MAX-5-strlen(tmp))
, cnt->conf.target_dir
, (int)(PATH_MAX-5-strlen(cnt->conf.target_dir))
, tmp);
passthrough = util_check_passthrough(cnt);
cnt->ffmpeg_timelapse = mymalloc(sizeof(struct ffmpeg));
if ((cnt->imgs.size_high > 0) && (!passthrough)){
Expand Down
2 changes: 2 additions & 0 deletions ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,8 @@ static void ffmpeg_passthru_write(struct ffmpeg *ffmpeg, int indx){
return;
}

ffmpeg->pkt.stream_index = 0;

retcd = av_write_frame(ffmpeg->oc, &ffmpeg->pkt);
my_packet_unref(ffmpeg->pkt);
if (retcd < 0) {
Expand Down
15 changes: 14 additions & 1 deletion motion.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH MOTION 1 2018-10-20 "Motion" "Motion Options and Config Files"
.TH MOTION 1 2019-02-02 "Motion" "Motion Options and Config Files"
.SH NAME
motion \- Detect motion using a video4linux device or network camera
.SH SYNOPSIS
Expand Down Expand Up @@ -1803,6 +1803,19 @@ Maximum frame rate to send to stream
.RE
.RE

.TP
.B stream_motion
.RS
.nf
Values: on,off
Default: off
Description:
.fi
.RS
Limit stream to 1 fps when no motion is being detected.
.RE
.RE

.TP
.B database_type
.RS
Expand Down
28 changes: 27 additions & 1 deletion motion.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ static void sig_handler(int signo)
if (cnt_list) {
i = -1;
while (cnt_list[++i]) {
cnt_list[i]->webcontrol_finish = 1;
cnt_list[i]->webcontrol_finish = TRUE;
cnt_list[i]->event_stop = TRUE;
cnt_list[i]->finish = 1;
/*
Expand Down Expand Up @@ -1389,6 +1389,7 @@ static int motion_init(struct context *cnt)
MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, _("Error capturing first image"));
}
}
cnt->current_image = &cnt->imgs.image_ring[cnt->imgs.image_ring_in];

/* create a reference frame */
alg_update_reference_frame(cnt, RESET_REF_FRAME);
Expand Down Expand Up @@ -2466,6 +2467,11 @@ static void mlp_actions(struct context *cnt){
}

cnt->current_image->flags |= (IMAGE_TRIGGER | IMAGE_SAVE);
/* Mark all images in image_ring to be saved */
for (indx = 0; indx < cnt->imgs.image_ring_size; indx++){
cnt->imgs.image_ring[indx].flags |= IMAGE_SAVE;
}

motion_detected(cnt, cnt->video_dev, cnt->current_image);
} else if ((cnt->current_image->flags & IMAGE_MOTION) && (cnt->startup_frames == 0)) {
/*
Expand Down Expand Up @@ -3429,6 +3435,8 @@ static void motion_watchdog(int indx){
* Best to just not get into a watchdog situation...
*/

if (!cnt_list[indx]->running) return;

cnt_list[indx]->watchdog--;
if (cnt_list[indx]->watchdog == 0) {
MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO
Expand Down Expand Up @@ -3532,6 +3540,24 @@ static int motion_check_threadcount(void){
motion_threads_running++;
}

/* If the web control/streams are in finish/shutdown, we
* do not want to count them. They will be completely closed
* by the process outside of loop that is checking the counts
* of threads. If the webcontrol is not in a finish / shutdown
* then we want to keep them in the tread count to allow user
* to restart the cameras and keep Motion running.
*/
indx = 0;
while (cnt_list[indx] != NULL){
if ((cnt_list[indx]->webcontrol_finish == FALSE) &&
((cnt_list[indx]->webcontrol_daemon != NULL) ||
(cnt_list[indx]->webstream_daemon != NULL))) {
motion_threads_running++;
}
indx++;
}


if (((motion_threads_running == 0) && finish) ||
((motion_threads_running == 0) && (threads_running == 0))) {
MOTION_LOG(ALL, TYPE_ALL, NO_ERRNO
Expand Down
2 changes: 1 addition & 1 deletion motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct image_data;
#include <pthread.h>
#include <microhttpd.h>

#ifdef __FreeBSD__
#if defined(__FreeBSD__) || defined(__OpenBSD__)
#include <pthread_np.h>
#endif

Expand Down
55 changes: 45 additions & 10 deletions motion_config.html
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,12 @@ <h2><a name="Configuration_OptionsAlpha"></a> Configuration Options-Listed Alph
<td align="left">stream_maxrate</td>
<td align="left"><a href="#stream_maxrate" >stream_maxrate</a></td>
</tr>
<tr>
<td align="left">webcam_motion</td>
<td align="left">stream_motion</td>
<td align="left">stream_motion</td>
<td align="left"><a href="#stream_motion" >stream_motion</a></td>
</tr>
<tr>
<td align="left">webcam_port</td>
<td align="left">stream_port</td>
Expand Down Expand Up @@ -1527,12 +1533,6 @@ <h2><a name="Configuration_OptionsAlpha"></a> Configuration Options-Listed Alph
<td align="left">stream_limit</td>
<td align="left">-Depreciated</td>
</tr>
<tr>
<td align="left">webcam_motion</td>
<td align="left">stream_motion</td>
<td align="left">stream_motion</td>
<td align="left">-Depreciated</td>
</tr>
<tr>
<td align="left"></td>
<td align="left"></td>
Expand Down Expand Up @@ -1958,7 +1958,10 @@ <h2><a name="Configuration_OptionsTopic"></a> Configuration Options-Listed by T
<td bgcolor="#edf4f9" ><a href="#stream_grey" >stream_grey</a> </td>
<td bgcolor="#edf4f9" ><a href="#stream_maxrate" >stream_maxrate</a> </td>
</tr>
</tbody>
<tr>
<td bgcolor="#edf4f9" ><a href="#stream_motion" >stream_motion</a> </td>
</tr>
</tbody>
</table>

<p></p>
Expand Down Expand Up @@ -4750,13 +4753,33 @@ <h3><a name="OptDetail_Webcontrol"></a>Web Control</a> </h3>
<li><code>{IP}:{port}/{camid}/action/eventend</code> Trigger the end of a event.</li>
<li><code>{IP}:{port}/{camid}/action/snapshot</code> Create a snapshot</li>
<li><code>{IP}:{port}/{camid}/action/restart</code> Shutdown and restart Motion</li>
<li><code>{IP}:{port}/{camid}/action/quit</code> Shutdown Motion</li>
<li><code>{IP}:{port}/{camid}/action/quit</code> Close all connections to the camera</li>
<li><code>{IP}:{port}/{camid}/action/end</code> Entirely shutdown the Motion application</li>
<li><code>{IP}:{port}/{camid}/track/center</code> Send command to center PTZ camera</li>
<li><code>{IP}:{port}/{camid}/track/set?x={value1}&y={value2}</code> Send command to PTZ camera to move
to location specified by x and y</li>
<li><code>{IP}:{port}/{camid}/track/set?pan={value1}&tilt={value2}</code> Send command to PTZ camera to
pan to value1 and tilt to value2</li>
</ul>
<p></p>
As a general rule, when the {camid} references the camera_id in the main motion.conf file, the webcontrol
actions referenced above are going to be applied to every camera that is connected to Motion. This camera_id
is usually specified as 0 (zero). So issuing a command of <code>{IP}:{port}/0/detection/pause</code> is
going to pause all the cameras.
<p></p>
A point of clarification with respect to the differences between <code>pause</code>, <code>quit</code>,
and <code>end</code>. When the action of <code>pause</code> is executed, Motion will stop the motion detection
processing and of course all events but will continue to process and decode images from the camera. This allows
for a faster transition when the user executes a <code>start</code> The <code>quit</code> action conversely not
only stops the motion detection but also disconnects from the camera and decoding of images. To start motion
detection after a <code>quit</code>, the user must execute a <code>restart</code> which will reinitialize the
connection to the camera. And since the camera was completely disconnect, it can take more than a few seconds
for Motion to fully start and have the camera available for processing or viewing. Finally, there is an
option for <code>end</code>. This option completely terminates the Motion application. It closes all connections
to all the cameras and terminates the application. This may be required when running Motion in daemon mode.
Note that there is no way to restart the Motion application from the webcontrol interface after processing
a <code>end</code> request.

<p></p>
If the item above is available via the HTML/CSS interface, it is also possible to see the exact URL sent
to Motion in the log. Change the log level to 8 (debug), then open up the Motion webcontrol interface and
Expand Down Expand Up @@ -5196,6 +5219,18 @@ <h3><a name="stream_maxrate"></a> stream_maxrate </h3>
Don't set this parameter too high unless you only use it on the localhost or on an internal LAN.
<p></p>

<h3><a name="stream_motion"></a> stream_motion </h3>
<p></p>
<ul>
<li> Type: boolean</li>
<li> Range / Valid values: on, off</li>
<li> Default: off</li>
</ul>
<p></p>
Limit the framerate to 1 frame per second when there is no motion being detected and increase
it to the stream_maxrate when there is motion.
<p></p>

</ul>


Expand Down Expand Up @@ -5388,8 +5423,8 @@ <h3><a name="sql_query_stop"></a> sql_query_stop </h3>
<li> Default: Not defined</li>
</ul>
<p></p>
SQL query that executes on a event where a file is closed after a event of motion.
This can be used to for example update the events table with an end timestamp for the recordings.
SQL query that executes after a movie has finished.
This can be used to for example update the events table with an end timestamp for the recording.
<p></p>
<p></p>
You can use <a href="#conversion_specifiers">Conversion Specifiers</a> within the query.
Expand Down
Loading

0 comments on commit 1180151

Please sign in to comment.