Skip to content

Commit 1180151

Browse files
committed
Merge branch 'master' into 4.2
2 parents 68112cb + c43a560 commit 1180151

16 files changed

+282
-100
lines changed

CHANGELOG

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
Summary of changes for version 4.2.2 are below
2+
* Update version number to 4.2.2/Changelog
3+
* Resolve compile problem for OpenBSD
4+
* Resolve compiler warnings for 18.10
5+
* Guide/Manual updates
6+
* Add the quit/end webcontrol actions to interface 0
7+
* Set the stream index on passthrough
8+
* Revise the webcontrol stream rate
9+
* Answer webcontrol stream only after completing first loop
10+
* Save the preview images when triggering emulate
11+
* Fix startup problem when using track_type 4
12+
* Fix hostname for webcontrol when using IPV6
113
Summary of changes for version 4.2.1 are below
214
* Update version number to 4.2.1 / Changelog
315
* Report to log options included in build

conf.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,7 +2359,9 @@ struct context **conf_load(struct context **cnt)
23592359
exit(-1);
23602360
}
23612361

2362-
snprintf(filename, PATH_MAX, "%s/motion.conf", path);
2362+
snprintf(filename, PATH_MAX, "%.*s/motion.conf"
2363+
, (int)(PATH_MAX-1-strlen("/motion.conf"))
2364+
, path);
23632365
fp = fopen (filename, "r");
23642366
}
23652367

@@ -3120,7 +3122,7 @@ static struct context **config_camera(struct context **cnt, const char *str,
31203122
*/
31213123
static void usage()
31223124
{
3123-
printf("motion Version "VERSION", Copyright 2000-2018 Jeroen Vreeken/Folkert van Heusden/Kenneth Lavrsen/Motion-Project maintainers\n");
3125+
printf("motion Version "VERSION", Copyright 2000-2019 Jeroen Vreeken/Folkert van Heusden/Kenneth Lavrsen/Motion-Project maintainers\n");
31243126
printf("\nHome page :\t https://motion-project.github.io/ \n");
31253127
printf("\nusage:\tmotion [options]\n");
31263128
printf("\n\n");

event.c

Lines changed: 68 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,11 @@ static void event_image_detect(struct context *cnt,
521521
imagepath = DEF_IMAGEPATH;
522522

523523
mystrftime(cnt, filename, sizeof(filename), imagepath, currenttime_tv, NULL, 0);
524-
snprintf(fullfilename, PATH_MAX, "%s/%s.%s", cnt->conf.target_dir, filename, imageext(cnt));
524+
snprintf(fullfilename, PATH_MAX, "%.*s/%.*s.%s"
525+
, (int)(PATH_MAX-2-strlen(filename)-strlen(imageext(cnt)))
526+
, cnt->conf.target_dir
527+
, (int)(PATH_MAX-2-strlen(cnt->conf.target_dir)-strlen(imageext(cnt)))
528+
, filename, imageext(cnt));
525529

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

560564
/* motion images gets same name as normal images plus an appended 'm' */
561-
snprintf(filenamem, PATH_MAX, "%sm", filename);
562-
snprintf(fullfilenamem, PATH_MAX, "%s/%s.%s", cnt->conf.target_dir, filenamem, imageext(cnt));
563-
565+
snprintf(filenamem, PATH_MAX, "%.*sm"
566+
, (int)(PATH_MAX-1-strlen(filename))
567+
, filename);
568+
snprintf(fullfilenamem, PATH_MAX, "%.*s/%.*s.%s"
569+
, (int)(PATH_MAX-2-strlen(filenamem)-strlen(imageext(cnt)))
570+
, cnt->conf.target_dir
571+
, (int)(PATH_MAX-2-strlen(cnt->conf.target_dir)-strlen(imageext(cnt)))
572+
, filenamem, imageext(cnt));
564573
put_picture(cnt, fullfilenamem, cnt->imgs.img_motion.image_norm, FTYPE_IMAGE_MOTION);
565574
event(cnt, EVENT_FILECREATE, NULL, fullfilenamem, (void *)FTYPE_IMAGE, currenttime_tv);
566575
}
@@ -593,16 +602,25 @@ static void event_image_snapshot(struct context *cnt,
593602
snappath = DEF_SNAPPATH;
594603

595604
mystrftime(cnt, filepath, sizeof(filepath), snappath, currenttime_tv, NULL, 0);
596-
snprintf(filename, PATH_MAX, "%s.%s", filepath, imageext(cnt));
597-
snprintf(fullfilename, PATH_MAX, "%s/%s", cnt->conf.target_dir, filename);
605+
snprintf(filename, PATH_MAX, "%.*s.%s"
606+
, (int)(PATH_MAX-1-strlen(filepath)-strlen(imageext(cnt)))
607+
, filepath, imageext(cnt));
608+
snprintf(fullfilename, PATH_MAX, "%.*s/%.*s"
609+
, (int)(PATH_MAX-1-strlen(filename))
610+
, cnt->conf.target_dir
611+
, (int)(PATH_MAX-1-strlen(cnt->conf.target_dir))
612+
, filename);
598613
put_picture(cnt, fullfilename, img_data->image_norm, FTYPE_IMAGE_SNAPSHOT);
599614
event(cnt, EVENT_FILECREATE, NULL, fullfilename, (void *)FTYPE_IMAGE, currenttime_tv);
600615

601616
/*
602617
* Update symbolic link *after* image has been written so that
603618
* the link always points to a valid file.
604619
*/
605-
snprintf(linkpath, PATH_MAX, "%s/lastsnap.%s", cnt->conf.target_dir, imageext(cnt));
620+
snprintf(linkpath, PATH_MAX, "%.*s/lastsnap.%s"
621+
, (int)(PATH_MAX-strlen("/lastsnap.")-strlen(imageext(cnt)))
622+
, cnt->conf.target_dir, imageext(cnt));
623+
606624
remove(linkpath);
607625

608626
if (symlink(filename, linkpath)) {
@@ -612,8 +630,14 @@ static void event_image_snapshot(struct context *cnt,
612630
}
613631
} else {
614632
mystrftime(cnt, filepath, sizeof(filepath), cnt->conf.snapshot_filename, currenttime_tv, NULL, 0);
615-
snprintf(filename, PATH_MAX, "%s.%s", filepath, imageext(cnt));
616-
snprintf(fullfilename, PATH_MAX, "%s/%s", cnt->conf.target_dir, filename);
633+
snprintf(filename, PATH_MAX, "%.*s.%s"
634+
, (int)(PATH_MAX-1-strlen(imageext(cnt)))
635+
, filepath, imageext(cnt));
636+
snprintf(fullfilename, PATH_MAX, "%.*s/%.*s"
637+
, (int)(PATH_MAX-1-strlen(filename))
638+
, cnt->conf.target_dir
639+
, (int)(PATH_MAX-1-strlen(cnt->conf.target_dir))
640+
, filename);
617641
remove(fullfilename);
618642
put_picture(cnt, fullfilename, img_data->image_norm, FTYPE_IMAGE_SNAPSHOT);
619643
event(cnt, EVENT_FILECREATE, NULL, fullfilename, (void *)FTYPE_IMAGE, currenttime_tv);
@@ -687,7 +711,11 @@ static void event_image_preview(struct context *cnt,
687711
imagepath = (char *)DEF_IMAGEPATH;
688712

689713
mystrftime(cnt, filename, sizeof(filename), imagepath, &cnt->imgs.preview_image.timestamp_tv, NULL, 0);
690-
snprintf(previewname, PATH_MAX, "%s/%s.%s", cnt->conf.target_dir, filename, imageext(cnt));
714+
snprintf(previewname, PATH_MAX, "%.*s/%.*s.%s"
715+
, (int)(PATH_MAX-2-strlen(filename)-strlen(imageext(cnt)))
716+
, cnt->conf.target_dir
717+
, (int)(PATH_MAX-2-strlen(cnt->conf.target_dir)-strlen(imageext(cnt)))
718+
, filename, imageext(cnt));
691719

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

773801
mystrftime(cnt, stamp, sizeof(stamp), moviepath, currenttime_tv, NULL, 0);
774-
snprintf(cnt->extpipefilename, PATH_MAX - 4, "%s/%s", cnt->conf.target_dir, stamp);
802+
snprintf(cnt->extpipefilename, PATH_MAX - 4, "%.*s/%.*s"
803+
, (int)(PATH_MAX-5-strlen(stamp))
804+
, cnt->conf.target_dir
805+
, (int)(PATH_MAX-5-strlen(cnt->conf.target_dir))
806+
, stamp);
775807

776808
if (access(cnt->conf.target_dir, W_OK)!= 0) {
777809
/* Permission denied */
@@ -943,11 +975,27 @@ static void event_ffmpeg_newfile(struct context *cnt,
943975
codec = "msmpeg4";
944976
break;
945977
}
946-
snprintf(cnt->motionfilename, PATH_MAX - 4, "%s/%s_%sm", cnt->conf.target_dir, codec, stamp);
947-
snprintf(cnt->newfilename, PATH_MAX - 4, "%s/%s_%s", cnt->conf.target_dir, codec, stamp);
978+
snprintf(cnt->motionfilename, PATH_MAX - 4, "%.*s/%s_%.*sm"
979+
, (int)(PATH_MAX-7-strlen(stamp)-strlen(codec))
980+
, cnt->conf.target_dir, codec
981+
, (int)(PATH_MAX-7-strlen(cnt->conf.target_dir)-strlen(codec))
982+
, stamp);
983+
snprintf(cnt->newfilename, PATH_MAX - 4, "%.*s/%s_%.*s"
984+
, (int)(PATH_MAX-6-strlen(stamp)-strlen(codec))
985+
, cnt->conf.target_dir, codec
986+
, (int)(PATH_MAX-6-strlen(cnt->conf.target_dir)-strlen(codec))
987+
, stamp);
948988
} else {
949-
snprintf(cnt->motionfilename, PATH_MAX - 4, "%s/%sm", cnt->conf.target_dir, stamp);
950-
snprintf(cnt->newfilename, PATH_MAX - 4, "%s/%s", cnt->conf.target_dir, stamp);
989+
snprintf(cnt->motionfilename, PATH_MAX - 4, "%.*s/%.*sm"
990+
, (int)(PATH_MAX-6-strlen(stamp))
991+
, cnt->conf.target_dir
992+
, (int)(PATH_MAX-6-strlen(cnt->conf.target_dir))
993+
, stamp);
994+
snprintf(cnt->newfilename, PATH_MAX - 4, "%.*s/%.*s"
995+
, (int)(PATH_MAX-5-strlen(stamp))
996+
, cnt->conf.target_dir
997+
, (int)(PATH_MAX-5-strlen(cnt->conf.target_dir))
998+
, stamp);
951999
}
9521000
if (cnt->conf.movie_output) {
9531001
cnt->ffmpeg_output = mymalloc(sizeof(struct ffmpeg));
@@ -1056,7 +1104,11 @@ static void event_ffmpeg_timelapse(struct context *cnt,
10561104
mystrftime(cnt, tmp, sizeof(tmp), timepath, currenttime_tv, NULL, 0);
10571105

10581106
/* PATH_MAX - 4 to allow for .mpg to be appended without overflow */
1059-
snprintf(cnt->timelapsefilename, PATH_MAX - 4, "%s/%s", cnt->conf.target_dir, tmp);
1107+
snprintf(cnt->timelapsefilename, PATH_MAX - 4, "%.*s/%.*s"
1108+
, (int)(PATH_MAX-5-strlen(tmp))
1109+
, cnt->conf.target_dir
1110+
, (int)(PATH_MAX-5-strlen(cnt->conf.target_dir))
1111+
, tmp);
10601112
passthrough = util_check_passthrough(cnt);
10611113
cnt->ffmpeg_timelapse = mymalloc(sizeof(struct ffmpeg));
10621114
if ((cnt->imgs.size_high > 0) && (!passthrough)){

ffmpeg.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,8 @@ static void ffmpeg_passthru_write(struct ffmpeg *ffmpeg, int indx){
989989
return;
990990
}
991991

992+
ffmpeg->pkt.stream_index = 0;
993+
992994
retcd = av_write_frame(ffmpeg->oc, &ffmpeg->pkt);
993995
my_packet_unref(ffmpeg->pkt);
994996
if (retcd < 0) {

motion.1

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.TH MOTION 1 2018-10-20 "Motion" "Motion Options and Config Files"
1+
.TH MOTION 1 2019-02-02 "Motion" "Motion Options and Config Files"
22
.SH NAME
33
motion \- Detect motion using a video4linux device or network camera
44
.SH SYNOPSIS
@@ -1803,6 +1803,19 @@ Maximum frame rate to send to stream
18031803
.RE
18041804
.RE
18051805

1806+
.TP
1807+
.B stream_motion
1808+
.RS
1809+
.nf
1810+
Values: on,off
1811+
Default: off
1812+
Description:
1813+
.fi
1814+
.RS
1815+
Limit stream to 1 fps when no motion is being detected.
1816+
.RE
1817+
.RE
1818+
18061819
.TP
18071820
.B database_type
18081821
.RS

motion.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ static void sig_handler(int signo)
364364
if (cnt_list) {
365365
i = -1;
366366
while (cnt_list[++i]) {
367-
cnt_list[i]->webcontrol_finish = 1;
367+
cnt_list[i]->webcontrol_finish = TRUE;
368368
cnt_list[i]->event_stop = TRUE;
369369
cnt_list[i]->finish = 1;
370370
/*
@@ -1389,6 +1389,7 @@ static int motion_init(struct context *cnt)
13891389
MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO, _("Error capturing first image"));
13901390
}
13911391
}
1392+
cnt->current_image = &cnt->imgs.image_ring[cnt->imgs.image_ring_in];
13921393

13931394
/* create a reference frame */
13941395
alg_update_reference_frame(cnt, RESET_REF_FRAME);
@@ -2466,6 +2467,11 @@ static void mlp_actions(struct context *cnt){
24662467
}
24672468

24682469
cnt->current_image->flags |= (IMAGE_TRIGGER | IMAGE_SAVE);
2470+
/* Mark all images in image_ring to be saved */
2471+
for (indx = 0; indx < cnt->imgs.image_ring_size; indx++){
2472+
cnt->imgs.image_ring[indx].flags |= IMAGE_SAVE;
2473+
}
2474+
24692475
motion_detected(cnt, cnt->video_dev, cnt->current_image);
24702476
} else if ((cnt->current_image->flags & IMAGE_MOTION) && (cnt->startup_frames == 0)) {
24712477
/*
@@ -3429,6 +3435,8 @@ static void motion_watchdog(int indx){
34293435
* Best to just not get into a watchdog situation...
34303436
*/
34313437

3438+
if (!cnt_list[indx]->running) return;
3439+
34323440
cnt_list[indx]->watchdog--;
34333441
if (cnt_list[indx]->watchdog == 0) {
34343442
MOTION_LOG(ERR, TYPE_ALL, NO_ERRNO
@@ -3532,6 +3540,24 @@ static int motion_check_threadcount(void){
35323540
motion_threads_running++;
35333541
}
35343542

3543+
/* If the web control/streams are in finish/shutdown, we
3544+
* do not want to count them. They will be completely closed
3545+
* by the process outside of loop that is checking the counts
3546+
* of threads. If the webcontrol is not in a finish / shutdown
3547+
* then we want to keep them in the tread count to allow user
3548+
* to restart the cameras and keep Motion running.
3549+
*/
3550+
indx = 0;
3551+
while (cnt_list[indx] != NULL){
3552+
if ((cnt_list[indx]->webcontrol_finish == FALSE) &&
3553+
((cnt_list[indx]->webcontrol_daemon != NULL) ||
3554+
(cnt_list[indx]->webstream_daemon != NULL))) {
3555+
motion_threads_running++;
3556+
}
3557+
indx++;
3558+
}
3559+
3560+
35353561
if (((motion_threads_running == 0) && finish) ||
35363562
((motion_threads_running == 0) && (threads_running == 0))) {
35373563
MOTION_LOG(ALL, TYPE_ALL, NO_ERRNO

motion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct image_data;
5353
#include <pthread.h>
5454
#include <microhttpd.h>
5555

56-
#ifdef __FreeBSD__
56+
#if defined(__FreeBSD__) || defined(__OpenBSD__)
5757
#include <pthread_np.h>
5858
#endif
5959

motion_config.html

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,12 @@ <h2><a name="Configuration_OptionsAlpha"></a> Configuration Options-Listed Alph
11731173
<td align="left">stream_maxrate</td>
11741174
<td align="left"><a href="#stream_maxrate" >stream_maxrate</a></td>
11751175
</tr>
1176+
<tr>
1177+
<td align="left">webcam_motion</td>
1178+
<td align="left">stream_motion</td>
1179+
<td align="left">stream_motion</td>
1180+
<td align="left"><a href="#stream_motion" >stream_motion</a></td>
1181+
</tr>
11761182
<tr>
11771183
<td align="left">webcam_port</td>
11781184
<td align="left">stream_port</td>
@@ -1527,12 +1533,6 @@ <h2><a name="Configuration_OptionsAlpha"></a> Configuration Options-Listed Alph
15271533
<td align="left">stream_limit</td>
15281534
<td align="left">-Depreciated</td>
15291535
</tr>
1530-
<tr>
1531-
<td align="left">webcam_motion</td>
1532-
<td align="left">stream_motion</td>
1533-
<td align="left">stream_motion</td>
1534-
<td align="left">-Depreciated</td>
1535-
</tr>
15361536
<tr>
15371537
<td align="left"></td>
15381538
<td align="left"></td>
@@ -1958,7 +1958,10 @@ <h2><a name="Configuration_OptionsTopic"></a> Configuration Options-Listed by T
19581958
<td bgcolor="#edf4f9" ><a href="#stream_grey" >stream_grey</a> </td>
19591959
<td bgcolor="#edf4f9" ><a href="#stream_maxrate" >stream_maxrate</a> </td>
19601960
</tr>
1961-
</tbody>
1961+
<tr>
1962+
<td bgcolor="#edf4f9" ><a href="#stream_motion" >stream_motion</a> </td>
1963+
</tr>
1964+
</tbody>
19621965
</table>
19631966

19641967
<p></p>
@@ -4750,13 +4753,33 @@ <h3><a name="OptDetail_Webcontrol"></a>Web Control</a> </h3>
47504753
<li><code>{IP}:{port}/{camid}/action/eventend</code> Trigger the end of a event.</li>
47514754
<li><code>{IP}:{port}/{camid}/action/snapshot</code> Create a snapshot</li>
47524755
<li><code>{IP}:{port}/{camid}/action/restart</code> Shutdown and restart Motion</li>
4753-
<li><code>{IP}:{port}/{camid}/action/quit</code> Shutdown Motion</li>
4756+
<li><code>{IP}:{port}/{camid}/action/quit</code> Close all connections to the camera</li>
4757+
<li><code>{IP}:{port}/{camid}/action/end</code> Entirely shutdown the Motion application</li>
47544758
<li><code>{IP}:{port}/{camid}/track/center</code> Send command to center PTZ camera</li>
47554759
<li><code>{IP}:{port}/{camid}/track/set?x={value1}&y={value2}</code> Send command to PTZ camera to move
47564760
to location specified by x and y</li>
47574761
<li><code>{IP}:{port}/{camid}/track/set?pan={value1}&tilt={value2}</code> Send command to PTZ camera to
47584762
pan to value1 and tilt to value2</li>
47594763
</ul>
4764+
<p></p>
4765+
As a general rule, when the {camid} references the camera_id in the main motion.conf file, the webcontrol
4766+
actions referenced above are going to be applied to every camera that is connected to Motion. This camera_id
4767+
is usually specified as 0 (zero). So issuing a command of <code>{IP}:{port}/0/detection/pause</code> is
4768+
going to pause all the cameras.
4769+
<p></p>
4770+
A point of clarification with respect to the differences between <code>pause</code>, <code>quit</code>,
4771+
and <code>end</code>. When the action of <code>pause</code> is executed, Motion will stop the motion detection
4772+
processing and of course all events but will continue to process and decode images from the camera. This allows
4773+
for a faster transition when the user executes a <code>start</code> The <code>quit</code> action conversely not
4774+
only stops the motion detection but also disconnects from the camera and decoding of images. To start motion
4775+
detection after a <code>quit</code>, the user must execute a <code>restart</code> which will reinitialize the
4776+
connection to the camera. And since the camera was completely disconnect, it can take more than a few seconds
4777+
for Motion to fully start and have the camera available for processing or viewing. Finally, there is an
4778+
option for <code>end</code>. This option completely terminates the Motion application. It closes all connections
4779+
to all the cameras and terminates the application. This may be required when running Motion in daemon mode.
4780+
Note that there is no way to restart the Motion application from the webcontrol interface after processing
4781+
a <code>end</code> request.
4782+
47604783
<p></p>
47614784
If the item above is available via the HTML/CSS interface, it is also possible to see the exact URL sent
47624785
to Motion in the log. Change the log level to 8 (debug), then open up the Motion webcontrol interface and
@@ -5196,6 +5219,18 @@ <h3><a name="stream_maxrate"></a> stream_maxrate </h3>
51965219
Don't set this parameter too high unless you only use it on the localhost or on an internal LAN.
51975220
<p></p>
51985221

5222+
<h3><a name="stream_motion"></a> stream_motion </h3>
5223+
<p></p>
5224+
<ul>
5225+
<li> Type: boolean</li>
5226+
<li> Range / Valid values: on, off</li>
5227+
<li> Default: off</li>
5228+
</ul>
5229+
<p></p>
5230+
Limit the framerate to 1 frame per second when there is no motion being detected and increase
5231+
it to the stream_maxrate when there is motion.
5232+
<p></p>
5233+
51995234
</ul>
52005235

52015236

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

0 commit comments

Comments
 (0)