2003-03-26 19:57:29 +08:00
|
|
|
//
|
|
|
|
// ZoneMinder Monitor Class Interfaces, $Date$, $Revision$
|
2008-07-25 17:33:23 +08:00
|
|
|
// Copyright (C) 2001-2008 Philip Coombes
|
2003-03-26 19:57:29 +08:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
2016-12-26 23:23:16 +08:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2003-03-26 19:57:29 +08:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ZM_MONITOR_H
|
|
|
|
#define ZM_MONITOR_H
|
|
|
|
|
2013-03-17 07:45:21 +08:00
|
|
|
#include <vector>
|
|
|
|
#include <sstream>
|
2018-03-02 11:22:22 +08:00
|
|
|
#include <thread>
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2009-01-28 23:02:33 +08:00
|
|
|
#include "zm.h"
|
2003-03-26 19:57:29 +08:00
|
|
|
#include "zm_coord.h"
|
|
|
|
#include "zm_image.h"
|
2011-05-01 02:39:34 +08:00
|
|
|
#include "zm_rgb.h"
|
2003-03-26 19:57:29 +08:00
|
|
|
#include "zm_zone.h"
|
2008-10-06 03:07:43 +08:00
|
|
|
#include "zm_event.h"
|
2016-05-14 02:51:26 +08:00
|
|
|
class Monitor;
|
2018-05-03 03:20:07 +08:00
|
|
|
#include "zm_group.h"
|
2003-03-26 19:57:29 +08:00
|
|
|
#include "zm_camera.h"
|
2013-12-14 02:39:39 +08:00
|
|
|
#include "zm_storage.h"
|
2014-05-05 19:29:12 +08:00
|
|
|
#include "zm_utils.h"
|
2003-03-26 19:57:29 +08:00
|
|
|
|
2013-03-17 07:45:21 +08:00
|
|
|
#include "zm_image_analyser.h"
|
|
|
|
|
2009-03-24 05:56:30 +08:00
|
|
|
#include <sys/time.h>
|
2011-05-10 18:50:54 +08:00
|
|
|
#include <stdint.h>
|
2009-03-24 05:56:30 +08:00
|
|
|
|
2008-10-06 03:07:43 +08:00
|
|
|
#define SIGNAL_CAUSE "Signal"
|
|
|
|
#define MOTION_CAUSE "Motion"
|
|
|
|
#define LINKED_CAUSE "Linked"
|
|
|
|
|
2003-03-26 19:57:29 +08:00
|
|
|
//
|
|
|
|
// This is the main class for monitors. Each monitor is associated
|
2008-10-06 03:07:43 +08:00
|
|
|
// with a camera and is effectively a collector for events.
|
2003-03-26 19:57:29 +08:00
|
|
|
//
|
2017-05-17 00:04:56 +08:00
|
|
|
class Monitor {
|
2016-04-29 21:11:14 +08:00
|
|
|
friend class MonitorStream;
|
|
|
|
|
2003-03-26 19:57:29 +08:00
|
|
|
public:
|
2017-05-17 00:04:56 +08:00
|
|
|
typedef enum {
|
2016-04-29 21:11:14 +08:00
|
|
|
QUERY=0,
|
|
|
|
CAPTURE,
|
|
|
|
ANALYSIS
|
|
|
|
} Purpose;
|
|
|
|
|
2017-05-17 00:04:56 +08:00
|
|
|
typedef enum {
|
2016-04-29 21:11:14 +08:00
|
|
|
NONE=1,
|
|
|
|
MONITOR,
|
|
|
|
MODECT,
|
|
|
|
RECORD,
|
|
|
|
MOCORD,
|
|
|
|
NODECT
|
|
|
|
} Function;
|
|
|
|
|
2018-03-09 20:23:40 +08:00
|
|
|
typedef enum {
|
|
|
|
LOCAL,
|
|
|
|
REMOTE,
|
|
|
|
FILE,
|
|
|
|
FFMPEG,
|
|
|
|
LIBVLC,
|
|
|
|
CURL,
|
|
|
|
} CameraType;
|
|
|
|
|
2017-05-17 00:04:56 +08:00
|
|
|
typedef enum {
|
2016-04-29 21:11:14 +08:00
|
|
|
ROTATE_0=1,
|
|
|
|
ROTATE_90,
|
|
|
|
ROTATE_180,
|
|
|
|
ROTATE_270,
|
|
|
|
FLIP_HORI,
|
|
|
|
FLIP_VERT
|
|
|
|
} Orientation;
|
|
|
|
|
2017-05-17 00:04:56 +08:00
|
|
|
typedef enum {
|
2016-04-29 21:11:14 +08:00
|
|
|
IDLE,
|
|
|
|
PREALARM,
|
|
|
|
ALARM,
|
|
|
|
ALERT,
|
|
|
|
TAPE
|
|
|
|
} State;
|
|
|
|
|
2016-09-13 09:35:14 +08:00
|
|
|
typedef enum {
|
|
|
|
DISABLED,
|
|
|
|
X264ENCODE,
|
|
|
|
H264PASSTHROUGH,
|
|
|
|
} VideoWriter;
|
|
|
|
|
2006-01-21 00:10:08 +08:00
|
|
|
protected:
|
2016-04-29 21:11:14 +08:00
|
|
|
typedef std::set<Zone *> ZoneSet;
|
|
|
|
|
|
|
|
typedef enum { GET_SETTINGS=0x1, SET_SETTINGS=0x2, RELOAD=0x4, SUSPEND=0x10, RESUME=0x20 } Action;
|
|
|
|
|
|
|
|
typedef enum { CLOSE_TIME, CLOSE_IDLE, CLOSE_ALARM } EventCloseMode;
|
|
|
|
|
2018-04-24 23:40:38 +08:00
|
|
|
/* sizeof(SharedData) expected to be 340 bytes on 32bit and 64bit */
|
2017-05-17 00:04:56 +08:00
|
|
|
typedef struct {
|
2016-04-29 21:11:14 +08:00
|
|
|
uint32_t size; /* +0 */
|
|
|
|
uint32_t last_write_index; /* +4 */
|
|
|
|
uint32_t last_read_index; /* +8 */
|
|
|
|
uint32_t state; /* +12 */
|
2018-04-24 23:40:38 +08:00
|
|
|
uint64_t last_event; /* +16 */
|
|
|
|
uint32_t action; /* +24 */
|
|
|
|
int32_t brightness; /* +28 */
|
|
|
|
int32_t hue; /* +32 */
|
|
|
|
int32_t colour; /* +36 */
|
|
|
|
int32_t contrast; /* +40 */
|
|
|
|
int32_t alarm_x; /* +44 */
|
|
|
|
int32_t alarm_y; /* +48 */
|
|
|
|
uint8_t valid; /* +52 */
|
|
|
|
uint8_t active; /* +53 */
|
|
|
|
uint8_t signal; /* +54 */
|
|
|
|
uint8_t format; /* +55 */
|
|
|
|
uint32_t imagesize; /* +56 */
|
|
|
|
uint32_t epadding1; /* +60 */
|
2016-04-29 21:11:14 +08:00
|
|
|
/*
|
|
|
|
** This keeps 32bit time_t and 64bit time_t identical and compatible as long as time is before 2038.
|
|
|
|
** Shared memory layout should be identical for both 32bit and 64bit and is multiples of 16.
|
2018-11-14 03:02:44 +08:00
|
|
|
** Because startup_time is 64bit it may be aligned to a 64bit boundary. So it's offset SHOULD be a multiple
|
|
|
|
** of 8. Add or delete epadding's to achieve this.
|
2016-06-22 00:21:18 +08:00
|
|
|
*/
|
2018-11-14 03:02:44 +08:00
|
|
|
union { /* +64 */
|
2016-09-15 23:16:05 +08:00
|
|
|
time_t startup_time; /* When the zmc process started. zmwatch uses this to see how long the process has been running without getting any images */
|
2016-04-29 21:11:14 +08:00
|
|
|
uint64_t extrapad1;
|
|
|
|
};
|
2018-11-14 03:02:44 +08:00
|
|
|
union { /* +72 */
|
2016-09-15 23:16:05 +08:00
|
|
|
time_t last_write_time;
|
2016-04-29 21:11:14 +08:00
|
|
|
uint64_t extrapad2;
|
|
|
|
};
|
2018-11-14 03:02:44 +08:00
|
|
|
union { /* +80 */
|
2016-09-15 23:16:05 +08:00
|
|
|
time_t last_read_time;
|
|
|
|
uint64_t extrapad3;
|
|
|
|
};
|
2018-11-14 03:02:44 +08:00
|
|
|
uint8_t control_state[256]; /* +88 */
|
2016-04-29 21:11:14 +08:00
|
|
|
|
2018-03-13 07:38:12 +08:00
|
|
|
char alarm_cause[256];
|
2016-04-04 22:11:48 +08:00
|
|
|
|
2016-04-29 21:11:14 +08:00
|
|
|
} SharedData;
|
|
|
|
|
|
|
|
typedef enum { TRIGGER_CANCEL, TRIGGER_ON, TRIGGER_OFF } TriggerState;
|
|
|
|
|
|
|
|
/* sizeof(TriggerData) expected to be 560 on 32bit & and 64bit */
|
2017-05-17 00:04:56 +08:00
|
|
|
typedef struct {
|
2016-04-29 21:11:14 +08:00
|
|
|
uint32_t size;
|
|
|
|
uint32_t trigger_state;
|
|
|
|
uint32_t trigger_score;
|
|
|
|
uint32_t padding;
|
|
|
|
char trigger_cause[32];
|
|
|
|
char trigger_text[256];
|
|
|
|
char trigger_showtext[256];
|
|
|
|
} TriggerData;
|
|
|
|
|
|
|
|
/* sizeof(Snapshot) expected to be 16 bytes on 32bit and 32 bytes on 64bit */
|
2017-05-17 00:04:56 +08:00
|
|
|
struct Snapshot {
|
2016-06-22 00:21:18 +08:00
|
|
|
struct timeval *timestamp;
|
|
|
|
Image *image;
|
2016-04-29 21:11:14 +08:00
|
|
|
void* padding;
|
|
|
|
};
|
|
|
|
|
|
|
|
//TODO: Technically we can't exclude this struct when people don't have avformat as the Memory.pm module doesn't know about avformat
|
2013-09-06 10:53:24 +08:00
|
|
|
#if 1
|
2016-04-29 21:11:14 +08:00
|
|
|
//sizeOf(VideoStoreData) expected to be 4104 bytes on 32bit and 64bit
|
2017-05-17 00:04:56 +08:00
|
|
|
typedef struct {
|
2016-04-29 21:11:14 +08:00
|
|
|
uint32_t size;
|
2018-04-24 23:40:38 +08:00
|
|
|
uint64_t current_event;
|
2016-04-29 21:11:14 +08:00
|
|
|
char event_file[4096];
|
2017-05-20 21:03:51 +08:00
|
|
|
timeval recording; // used as both bool and a pointer to the timestamp when recording should begin
|
2016-04-29 21:11:14 +08:00
|
|
|
//uint32_t frameNumber;
|
|
|
|
} VideoStoreData;
|
|
|
|
|
2013-09-06 10:53:24 +08:00
|
|
|
#endif // HAVE_LIBAVFORMAT
|
|
|
|
|
2016-04-29 21:11:14 +08:00
|
|
|
class MonitorLink {
|
2016-04-04 22:11:48 +08:00
|
|
|
protected:
|
|
|
|
unsigned int id;
|
|
|
|
char name[64];
|
2006-01-23 02:31:55 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
bool connected;
|
2017-05-18 05:47:39 +08:00
|
|
|
time_t last_connect_time;
|
2006-01-23 02:31:55 +08:00
|
|
|
|
2008-07-14 23:21:16 +08:00
|
|
|
#if ZM_MEM_MAPPED
|
2017-05-18 05:47:39 +08:00
|
|
|
int map_fd;
|
2016-04-04 22:11:48 +08:00
|
|
|
char mem_file[PATH_MAX];
|
2008-07-14 23:21:16 +08:00
|
|
|
#else // ZM_MEM_MAPPED
|
2016-04-04 22:11:48 +08:00
|
|
|
int shm_id;
|
2008-07-14 23:21:16 +08:00
|
|
|
#endif // ZM_MEM_MAPPED
|
2017-05-18 05:47:39 +08:00
|
|
|
off_t mem_size;
|
2016-04-04 22:11:48 +08:00
|
|
|
unsigned char *mem_ptr;
|
2016-04-29 21:11:14 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
volatile SharedData *shared_data;
|
|
|
|
volatile TriggerData *trigger_data;
|
Feature h264 videostorage (#1882)
* Moved writing of configure options from Controller to Model. Fixes #191.
* Initial commit for saving events as videos :)
* Add zm_video.cpp to autotools
* Add zm_video.h to autotools
* Search for MP4V2 header file 3 times: mp4v2/mp4v2.h, mp4v2.h, mp4.h
* Fix serve memory leak
* Few minor code improvements
* Added the ability to override preset, tune, profile and few other improvements
* Correctly write SPS & PPS from x264 encoder headers
* Remove unnessecary SPS & PPS writing code
* Imported missing files from master to feature-h264-videostorage
* Audio support including fixes for dts/pts, split on keyframe and update to mkv extension to prevent ffmpeg problems writing rtsp audio to mp4 containter (header problem)
* Updates to make gcc happy
* Add html5 video control to timeline and event to support mkv playback
* Add zm_videostore.cpp to CMakeLists.txt
* Remove Modern Branch for now
* Fix minor bug
* Option handled added in master, removing duplicate declaration
* Add CaptureandRecord from zm_camera.h
* Putting placeholder in for CaptureAndRecord function
* Removed duplicate code and brackets
* add digest auth file for cmake
Conflicts:
src/CMakeLists.txt
* Add web dir back into Makefile.am
Revert "Removed web from SUBDIRS in Makefile.am"
This reverts commit d9bbcdf3a94cba4d8955fcd03bd965ed2772f34d.
* Add CaptureAndRecord to vlc, still need to make it record
* Resolve SegFault on videostore
* Swap to mp4 container
* mp4 changes
* spaces to tabs, hide video stuff if video writer is turned off
* Make timeline open event.mp4 instead of mkv
* Missed mkv in timeline.js
* Fix some issues from the merge conflict
* Resolve post merge build issues with braces
* Fix whitespace
* Update Jpeg and Video options for passthrough options
* Whitespace fix zm_camera.h
* Fix array mkssing comma
* Add support for Jpeg save options for h264 branch snapshot. Might remove altogether if snapshots not needed
* Update VideoStoreData memory size comment
* Change from config.use_mkv_storage to per monitor option VideoWriter from video branch
* Fix bracket issues post merge
* Clean up comments and add av_free_packet
* Convert from event_directory to event file as per Video branch
* Testing videojs for video playback
* Fixed a missing bracket post merge and also SQL_values now used for EventID and Monitors
* bring recent improvements in ffmpeg capture function into captureandrecord
* Remove pict from writeAudioFramePacket as not used
* Add translate options for h264 Storage options in Monitor and update en_gb file
* Cherry-Pick from iconnor - make it compile on ubuntu 15.04. Which is libav 56.1.0
Conflicts:
src/zm_ffmpeg.cpp
src/zm_remote_camera_rtsp.cpp
Conflicts:
distros/ubuntu1204/changelog
* Clean up videostore code and remove lots of unused code
* proof of concept for dynamic/automatic video rotation using video-js plugin zoomrotate
Conflicts:
web/skins/classic/views/event.php
* removed redundant field in sql query
Conflicts:
web/skins/classic/views/event.php
* local storage of video js plugin
* Beautify!
Make the code somewhat readable.
* added missing videojs.zoomrotate.js file
added missing videojs.zoomrotate.js file
* Typo
added missing "
* Added missing brackets
* fix to display thumbnails when only storing snapshot.jpg
* added control for video playback rate
Conflicts:
web/skins/classic/views/event.php
* dynamically create jpegs from video file for viewing in browser
* fix timeline view for SaveJPEGs monitors (without enabled VideoWriter)
* only expose monitor info which are being used in client
* fix segmentation fault in zma with ubuntu 14.04 and ffmpeg 2.5.8 (gcc 4.8)
when libx264 is not installed
* better way of detecting showing image or video in timeline and event view
instead of Monitor.VideoWriter, Event.DefaultVideo is used, so even if
VideoWriter/SaveJPEG option is changed, a valid image or video will always be
displayed for historical events in both timeline and event view
this also fixes loading videos in timeline view
* Fixes problem of crashing zmc when bad packet arrives causing av_interleaved_write_frame() to return non-zero (-22). Prefilters common packet issues. Add metadata title to generated video file
* Remove syslog.h
* fixed SaveJPEGs are not working
which is caused in errors introduced when merging with master
* Update README.md
* Fix build warnings specific to h264 branch, unused FrameImg, unused ret and int64_t snprintf issues
* Fix PRId64 issue in travis, builds locally fine, but I can see a gcc version issue here
* Fix PRId64 issue in travis, another try
* Try "STDC_FORMAT_MACROS" to see if that helps Travis on gcc 4.6.3
* Revert space removal around PRId64
* video branch ffmpeg 2.9 fixes
ffmpeg 2.9 patched removed SSE2 CPU
* Add FFMPEGInit back
* use webvvt to overlay timestamp (honoring Monitor.LabelFormat) to videos in timeline and event
also fixed bug which prevented seeking in timeline video preview
* ffmpeg 3.0 API build failure fixes
* Update README.md
* merge all the commits from the messed up iconnor_video branch
* fix whitespace
* revert
* whitespace fixes
* spelling fix
* put back some text
* add these back
* fix spelling mistake
* Steal some packet dumping routines from ffmpeg. Convert them to use our logging routines
* add a test and error message if the codec is not h264
* these have been removed in master
* add a view to check auth and just send the video
* add some comments, and dump filename and AVFormatContext on failure to write header
* add the toggle for RecordAudio so that the checkbox works to turn off Audio
* Must init videoStore in constuctor
* more debug and comments, return checking
* Fix dropped part of sql query.
* fix extra else and some whitespace
* Fix missing } from merge that was preventing building.
* fix tabs
* get rid of use of separator, just use \n
* Restore lost fixes for deprecation
* Why are these failing
* Respect record_audio flag when setting up video file so dont try and initiliase mp4 with unsupported audio
* Forgot that I was trying to solve case of stream is true and record_audio
is false.
* Pass swscale_ctx back in to getCachedContext or it will create new
context every frame and leak memory like a mofo.
* Add libx264-dev and libmp4v2-dev to build requires to save hassle of
ensuring they are installed before build.
* Merge my Rotation/Orientation work and fixes for bad h264 streams
* need arpa/inet for reverse lookups
* pull in the new byte range code for viewing videos
* Move our recording flag deeper into closeevent
* add braces and only call closeEvent if there is an event
* deprecate the z_frame_rate stuff which is deprecated in ffmpeg
* remark out some debugging
* fix for video on stream 1
* fix audio_stream to audio_st
* Ignore bad decodes
* fix problems with content-length causing viewing to not work in chrome/android
* change logic of sending file contents to handle an off by one and be more readable
* Some fixes pointed out by Maxim Romanov. Also simply the loading of events to not join the Monitors table
* fix to sql for timeline
* added RecordAudio to sql in README
* Use sub queries instead of joins to fix errors when using new mysql defaults.
* fix sql queries
* Dockerfile to build feature-h264-videostorage
* Must cast codec
* add php-acpu as a dependency
* require php5-acpu
* fix typo
* remove extra /
* Add a line for out-of-tree builds to do api/lib/Cake/bootstrap.php
* delete merge conflict files
* delete merge conflict files
2017-05-16 10:02:48 +08:00
|
|
|
volatile VideoStoreData *video_store_data;
|
2016-04-29 21:11:14 +08:00
|
|
|
|
2016-04-04 22:11:48 +08:00
|
|
|
int last_state;
|
2018-04-13 04:40:11 +08:00
|
|
|
uint64_t last_event;
|
2016-04-29 21:11:14 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
MonitorLink( int p_id, const char *p_name );
|
|
|
|
~MonitorLink();
|
|
|
|
|
|
|
|
inline int Id() const {
|
2018-04-13 04:40:11 +08:00
|
|
|
return id;
|
2016-04-29 21:11:14 +08:00
|
|
|
}
|
|
|
|
inline const char *Name() const {
|
|
|
|
return( name );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool isConnected() const {
|
|
|
|
return( connected );
|
|
|
|
}
|
|
|
|
inline time_t getLastConnectTime() const {
|
|
|
|
return( last_connect_time );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool connect();
|
|
|
|
bool disconnect();
|
|
|
|
|
|
|
|
bool isAlarmed();
|
|
|
|
bool inAlarm();
|
|
|
|
bool hasAlarmed();
|
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// These are read from the DB and thereafter remain unchanged
|
2017-05-20 21:03:51 +08:00
|
|
|
unsigned int id;
|
|
|
|
char name[64];
|
|
|
|
unsigned int server_id; // Id of the Server object
|
2017-05-24 03:17:46 +08:00
|
|
|
unsigned int storage_id; // Id of the Storage Object, which currently will just provide a path, but in future may do more.
|
2018-03-09 20:23:40 +08:00
|
|
|
CameraType type;
|
2017-05-20 21:03:51 +08:00
|
|
|
Function function; // What the monitor is doing
|
|
|
|
bool enabled; // Whether the monitor is enabled or asleep
|
|
|
|
unsigned int width; // Normally the same as the camera, but not if partly rotated
|
|
|
|
unsigned int height; // Normally the same as the camera, but not if partly rotated
|
|
|
|
bool v4l_multi_buffer;
|
|
|
|
unsigned int v4l_captures_per_frame;
|
|
|
|
Orientation orientation; // Whether the image has to be rotated at all
|
|
|
|
unsigned int deinterlacing;
|
|
|
|
bool videoRecording;
|
2019-06-26 03:34:17 +08:00
|
|
|
std::string decoder_hwaccel_name;
|
|
|
|
std::string decoder_hwaccel_device;
|
2016-04-29 21:11:14 +08:00
|
|
|
|
2018-03-09 20:23:40 +08:00
|
|
|
int savejpegs;
|
2016-09-13 09:35:14 +08:00
|
|
|
VideoWriter videowriter;
|
2016-04-29 21:11:14 +08:00
|
|
|
std::string encoderparams;
|
|
|
|
std::vector<EncoderParameter_t> encoderparamsvec;
|
2018-09-24 04:47:06 +08:00
|
|
|
bool record_audio; // Whether to store the audio that we receive
|
|
|
|
|
|
|
|
int brightness; // The statically saved brightness of the camera
|
|
|
|
int contrast; // The statically saved contrast of the camera
|
|
|
|
int hue; // The statically saved hue of the camera
|
|
|
|
int colour; // The statically saved colour of the camera
|
|
|
|
char event_prefix[64]; // The prefix applied to event names as they are created
|
|
|
|
char label_format[64]; // The format of the timestamp on the images
|
|
|
|
Coord label_coord; // The coordinates of the timestamp on the images
|
|
|
|
int label_size; // Size of the timestamp on the images
|
|
|
|
int image_buffer_count; // Size of circular image buffer, at least twice the size of the pre_event_count
|
|
|
|
int pre_event_buffer_count; // Size of dedicated circular pre event buffer used when analysis is not performed at capturing framerate,
|
2016-04-29 21:11:14 +08:00
|
|
|
// value is pre_event_count + alarm_frame_count - 1
|
2018-09-24 04:47:06 +08:00
|
|
|
int warmup_count; // How many images to process before looking for events
|
|
|
|
int pre_event_count; // How many images to hold and prepend to an alarm event
|
|
|
|
int post_event_count; // How many unalarmed images must occur before the alarm state is reset
|
2019-11-02 05:29:55 +08:00
|
|
|
struct timeval video_buffer_duration; // How long a video segment to keep in buffer (set only if analysis fps != 0 )
|
2018-09-24 04:47:06 +08:00
|
|
|
int stream_replay_buffer; // How many frames to store to support DVR functions, IGNORED from this object, passed directly into zms now
|
|
|
|
int section_length; // How long events should last in continuous modes
|
2019-06-24 23:29:00 +08:00
|
|
|
int min_section_length; // Minimum event length when using event_close_mode == ALARM
|
2018-09-24 04:47:06 +08:00
|
|
|
bool adaptive_skip; // Whether to use the newer adaptive algorithm for this monitor
|
|
|
|
int frame_skip; // How many frames to skip in continuous modes
|
|
|
|
int motion_frame_skip; // How many frames to skip in motion detection
|
2019-07-31 23:23:02 +08:00
|
|
|
double capture_max_fps; // Target Capture FPS
|
2018-09-24 04:47:06 +08:00
|
|
|
double analysis_fps; // Target framerate for video analysis
|
2016-06-22 00:21:18 +08:00
|
|
|
unsigned int analysis_update_delay; // How long we wait before updating analysis parameters
|
2018-09-24 04:47:06 +08:00
|
|
|
int capture_delay; // How long we wait between capture frames
|
|
|
|
int alarm_capture_delay; // How long we wait between capture frames when in alarm state
|
|
|
|
int alarm_frame_count; // How many alarm frames are required before an event is triggered
|
|
|
|
int fps_report_interval; // How many images should be captured/processed between reporting the current FPS
|
|
|
|
int ref_blend_perc; // Percentage of new image going into reference image.
|
|
|
|
int alarm_ref_blend_perc; // Percentage of new image going into reference image during alarm.
|
|
|
|
bool track_motion; // Whether this monitor tries to track detected motion
|
|
|
|
int signal_check_points; // Number of points in the image to check for signal
|
|
|
|
Rgb signal_check_colour; // The colour that the camera will emit when no video signal detected
|
|
|
|
bool embed_exif; // Whether to embed Exif data into each image frame or not
|
|
|
|
|
|
|
|
bool last_signal;
|
2016-06-22 00:21:18 +08:00
|
|
|
|
2019-04-16 01:26:55 +08:00
|
|
|
double fps;
|
|
|
|
unsigned int last_camera_bytes;
|
2018-04-25 02:11:27 +08:00
|
|
|
|
2019-04-16 01:26:55 +08:00
|
|
|
Image delta_image;
|
|
|
|
Image ref_image;
|
|
|
|
Image alarm_image; // Used in creating analysis images, will be initialized in Analysis
|
|
|
|
Image write_image; // Used when creating snapshot images
|
|
|
|
std::string diag_path_r;
|
|
|
|
std::string diag_path_d;
|
2016-06-22 00:21:18 +08:00
|
|
|
|
|
|
|
Purpose purpose; // What this monitor has been created to do
|
2019-04-16 01:26:55 +08:00
|
|
|
int event_count;
|
|
|
|
int image_count;
|
|
|
|
int ready_count;
|
|
|
|
int first_alarm_count;
|
|
|
|
int last_alarm_count;
|
|
|
|
int buffer_count;
|
|
|
|
int prealarm_count;
|
|
|
|
State state;
|
|
|
|
time_t start_time;
|
|
|
|
time_t last_fps_time;
|
|
|
|
time_t auto_resume_time;
|
2016-06-22 00:21:18 +08:00
|
|
|
unsigned int last_motion_score;
|
2016-04-29 21:11:14 +08:00
|
|
|
|
|
|
|
EventCloseMode event_close_mode;
|
2008-09-25 19:18:55 +08:00
|
|
|
|
2008-07-14 23:21:16 +08:00
|
|
|
#if ZM_MEM_MAPPED
|
2019-04-16 01:26:55 +08:00
|
|
|
int map_fd;
|
|
|
|
char mem_file[PATH_MAX];
|
2008-07-14 23:21:16 +08:00
|
|
|
#else // ZM_MEM_MAPPED
|
2019-04-16 01:26:55 +08:00
|
|
|
int shm_id;
|
2008-07-14 23:21:16 +08:00
|
|
|
#endif // ZM_MEM_MAPPED
|
2019-04-16 01:26:55 +08:00
|
|
|
off_t mem_size;
|
|
|
|
unsigned char *mem_ptr;
|
|
|
|
SharedData *shared_data;
|
|
|
|
TriggerData *trigger_data;
|
2016-06-22 00:21:18 +08:00
|
|
|
VideoStoreData *video_store_data;
|
2004-12-29 01:41:55 +08:00
|
|
|
|
2016-06-22 00:21:18 +08:00
|
|
|
Snapshot *image_buffer;
|
|
|
|
Snapshot next_buffer; /* Used by four field deinterlacing */
|
|
|
|
Snapshot *pre_event_buffer;
|
2003-03-26 19:57:29 +08:00
|
|
|
|
2016-06-22 00:21:18 +08:00
|
|
|
Camera *camera;
|
2018-04-24 23:40:38 +08:00
|
|
|
Event *event;
|
|
|
|
Storage *storage;
|
2006-01-23 02:31:55 +08:00
|
|
|
|
2016-06-22 00:21:18 +08:00
|
|
|
int n_zones;
|
|
|
|
Zone **zones;
|
2006-01-23 02:31:55 +08:00
|
|
|
|
2016-06-22 00:21:18 +08:00
|
|
|
struct timeval **timestamps;
|
|
|
|
Image **images;
|
2013-03-17 07:45:21 +08:00
|
|
|
|
2016-06-22 00:21:18 +08:00
|
|
|
const unsigned char *privacy_bitmask;
|
2018-03-02 11:22:22 +08:00
|
|
|
std::thread *event_delete_thread; // Used to close events, but continue processing.
|
2015-10-02 21:49:09 +08:00
|
|
|
|
2016-06-22 00:21:18 +08:00
|
|
|
int n_linked_monitors;
|
|
|
|
MonitorLink **linked_monitors;
|
2006-01-23 02:31:55 +08:00
|
|
|
|
2018-05-13 05:34:26 +08:00
|
|
|
std::vector<Group *> groups;
|
2018-05-03 03:20:07 +08:00
|
|
|
|
2003-03-26 19:57:29 +08:00
|
|
|
public:
|
2017-11-17 10:21:56 +08:00
|
|
|
explicit Monitor( int p_id );
|
2016-05-14 02:51:26 +08:00
|
|
|
|
2013-03-17 07:45:21 +08:00
|
|
|
// OurCheckAlarms seems to be unused. Check it on zm_monitor.cpp for more info.
|
|
|
|
//bool OurCheckAlarms( Zone *zone, const Image *pImage );
|
2016-06-22 00:21:18 +08:00
|
|
|
Monitor(
|
|
|
|
int p_id,
|
|
|
|
const char *p_name,
|
|
|
|
unsigned int p_server_id,
|
|
|
|
unsigned int p_storage_id,
|
|
|
|
int p_function,
|
|
|
|
bool p_enabled,
|
|
|
|
const char *p_linked_monitors,
|
|
|
|
Camera *p_camera,
|
|
|
|
int p_orientation,
|
|
|
|
unsigned int p_deinterlacing,
|
2019-06-26 03:34:17 +08:00
|
|
|
const std::string &p_decoder_hwaccel_name,
|
|
|
|
const std::string &p_decoder_hwaccel_device,
|
2016-06-22 00:21:18 +08:00
|
|
|
int p_savejpegs,
|
2016-09-13 09:35:14 +08:00
|
|
|
VideoWriter p_videowriter,
|
2016-06-22 00:21:18 +08:00
|
|
|
std::string p_encoderparams,
|
|
|
|
bool p_record_audio,
|
|
|
|
const char *p_event_prefix,
|
|
|
|
const char *p_label_format,
|
|
|
|
const Coord &p_label_coord,
|
|
|
|
int label_size,
|
|
|
|
int p_image_buffer_count,
|
|
|
|
int p_warmup_count,
|
|
|
|
int p_pre_event_count,
|
|
|
|
int p_post_event_count,
|
|
|
|
int p_stream_replay_buffer,
|
|
|
|
int p_alarm_frame_count,
|
|
|
|
int p_section_length,
|
2019-06-24 23:29:00 +08:00
|
|
|
int p_min_section_length,
|
2016-06-22 00:21:18 +08:00
|
|
|
int p_frame_skip,
|
|
|
|
int p_motion_frame_skip,
|
2019-07-31 23:23:02 +08:00
|
|
|
double p_capture_max_fps,
|
2016-06-22 00:21:18 +08:00
|
|
|
double p_analysis_fps,
|
|
|
|
unsigned int p_analysis_update_delay,
|
|
|
|
int p_capture_delay,
|
|
|
|
int p_alarm_capture_delay,
|
|
|
|
int p_fps_report_interval,
|
|
|
|
int p_ref_blend_perc,
|
|
|
|
int p_alarm_ref_blend_perc,
|
|
|
|
bool p_track_motion,
|
2018-04-19 22:10:14 +08:00
|
|
|
int p_signal_check_points,
|
2016-06-22 00:21:18 +08:00
|
|
|
Rgb p_signal_check_colour,
|
|
|
|
bool p_embed_exif,
|
|
|
|
Purpose p_purpose,
|
|
|
|
int p_n_zones=0,
|
|
|
|
Zone *p_zones[]=0
|
|
|
|
);
|
|
|
|
~Monitor();
|
|
|
|
|
|
|
|
void AddZones( int p_n_zones, Zone *p_zones[] );
|
|
|
|
void AddPrivacyBitmask( Zone *p_zones[] );
|
|
|
|
|
|
|
|
bool connect();
|
|
|
|
inline int ShmValid() const {
|
|
|
|
return( shared_data->valid );
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int Id() const {
|
2018-04-13 04:40:11 +08:00
|
|
|
return id;
|
2016-06-22 00:21:18 +08:00
|
|
|
}
|
|
|
|
inline const char *Name() const {
|
2018-04-13 04:40:11 +08:00
|
|
|
return name;
|
2016-06-22 00:21:18 +08:00
|
|
|
}
|
|
|
|
inline Storage *getStorage() {
|
|
|
|
if ( ! storage ) {
|
|
|
|
storage = new Storage( storage_id );
|
|
|
|
}
|
2018-04-13 04:40:11 +08:00
|
|
|
return storage;
|
2016-06-22 00:21:18 +08:00
|
|
|
}
|
|
|
|
inline Function GetFunction() const {
|
|
|
|
return( function );
|
|
|
|
}
|
|
|
|
inline bool Enabled() {
|
|
|
|
if ( function <= MONITOR )
|
2018-04-13 04:40:11 +08:00
|
|
|
return false;
|
|
|
|
return enabled;
|
2016-06-22 00:21:18 +08:00
|
|
|
}
|
|
|
|
inline const char *EventPrefix() const {
|
2018-04-13 04:40:11 +08:00
|
|
|
return event_prefix;
|
2016-06-22 00:21:18 +08:00
|
|
|
}
|
|
|
|
inline bool Ready() {
|
|
|
|
if ( function <= MONITOR )
|
2018-04-13 04:40:11 +08:00
|
|
|
return false;
|
2016-06-22 00:21:18 +08:00
|
|
|
return( image_count > ready_count );
|
|
|
|
}
|
|
|
|
inline bool Active() {
|
|
|
|
if ( function <= MONITOR )
|
2018-04-13 04:40:11 +08:00
|
|
|
return false;
|
2016-06-22 00:21:18 +08:00
|
|
|
return( enabled && shared_data->active );
|
|
|
|
}
|
|
|
|
inline bool Exif() {
|
2018-04-13 04:40:11 +08:00
|
|
|
return embed_exif;
|
2016-06-22 00:21:18 +08:00
|
|
|
}
|
2016-08-11 00:22:04 +08:00
|
|
|
Orientation getOrientation() const;
|
2005-12-23 00:46:25 +08:00
|
|
|
|
2016-06-22 00:21:18 +08:00
|
|
|
unsigned int Width() const { return width; }
|
|
|
|
unsigned int Height() const { return height; }
|
|
|
|
unsigned int Colours() const;
|
|
|
|
unsigned int SubpixelOrder() const;
|
2016-04-04 22:11:48 +08:00
|
|
|
|
2018-03-09 20:23:40 +08:00
|
|
|
int GetOptSaveJPEGs() const { return savejpegs; }
|
|
|
|
VideoWriter GetOptVideoWriter() const { return videowriter; }
|
|
|
|
const std::vector<EncoderParameter_t>* GetOptEncoderParams() const { return &encoderparamsvec; }
|
2018-04-13 04:40:11 +08:00
|
|
|
uint64_t GetVideoWriterEventId() const { return video_store_data->current_event; }
|
2018-04-18 01:51:20 +08:00
|
|
|
void SetVideoWriterEventId( unsigned long long p_event_id ) { video_store_data->current_event = p_event_id; }
|
2019-11-02 05:30:57 +08:00
|
|
|
struct timeval GetVideoWriterStartTime() const { return video_store_data->recording; }
|
|
|
|
void SetVideoWriterStartTime(struct timeval &t) { video_store_data->recording = t; }
|
2005-12-23 00:46:25 +08:00
|
|
|
|
2017-04-13 01:39:12 +08:00
|
|
|
unsigned int GetPreEventCount() const { return pre_event_count; };
|
2019-11-02 05:29:55 +08:00
|
|
|
struct timeval GetVideoBufferDuration() const { return video_buffer_duration; };
|
|
|
|
int GetImageBufferCount() const { return image_buffer_count; };
|
2016-06-22 00:21:18 +08:00
|
|
|
State GetState() const;
|
|
|
|
int GetImage( int index=-1, int scale=100 );
|
2018-03-09 20:23:40 +08:00
|
|
|
Snapshot *getSnapshot() const;
|
2016-06-22 00:21:18 +08:00
|
|
|
struct timeval GetTimestamp( int index=-1 ) const;
|
|
|
|
void UpdateAdaptiveSkip();
|
|
|
|
useconds_t GetAnalysisRate();
|
2018-03-09 20:23:40 +08:00
|
|
|
unsigned int GetAnalysisUpdateDelay() const { return analysis_update_delay; }
|
2019-07-31 23:23:02 +08:00
|
|
|
unsigned int GetCaptureMaxFPS() const { return capture_max_fps; }
|
2018-03-09 20:23:40 +08:00
|
|
|
int GetCaptureDelay() const { return capture_delay; }
|
|
|
|
int GetAlarmCaptureDelay() const { return alarm_capture_delay; }
|
2016-06-22 00:21:18 +08:00
|
|
|
unsigned int GetLastReadIndex() const;
|
|
|
|
unsigned int GetLastWriteIndex() const;
|
2018-04-13 04:40:11 +08:00
|
|
|
uint64_t GetLastEventId() const;
|
2016-06-22 00:21:18 +08:00
|
|
|
double GetFPS() const;
|
|
|
|
void ForceAlarmOn( int force_score, const char *force_case, const char *force_text="" );
|
|
|
|
void ForceAlarmOff();
|
|
|
|
void CancelForced();
|
2018-03-09 20:23:40 +08:00
|
|
|
TriggerState GetTriggerState() const { return (TriggerState)(trigger_data?trigger_data->trigger_state:TRIGGER_CANCEL); }
|
|
|
|
inline time_t getStartupTime() const { return shared_data->startup_time; }
|
|
|
|
inline void setStartupTime( time_t p_time ) { shared_data->startup_time = p_time; }
|
2016-06-22 00:21:18 +08:00
|
|
|
|
|
|
|
void actionReload();
|
|
|
|
void actionEnable();
|
|
|
|
void actionDisable();
|
|
|
|
void actionSuspend();
|
|
|
|
void actionResume();
|
|
|
|
|
|
|
|
int actionBrightness( int p_brightness=-1 );
|
|
|
|
int actionHue( int p_hue=-1 );
|
|
|
|
int actionColour( int p_colour=-1 );
|
|
|
|
int actionContrast( int p_contrast=-1 );
|
|
|
|
|
2018-03-09 20:23:40 +08:00
|
|
|
int PrimeCapture() const;
|
|
|
|
int PreCapture() const;
|
2016-06-22 00:21:18 +08:00
|
|
|
int Capture();
|
2018-03-09 20:23:40 +08:00
|
|
|
int PostCapture() const;
|
2018-04-17 22:02:52 +08:00
|
|
|
int Close();
|
2016-06-22 00:21:18 +08:00
|
|
|
|
|
|
|
unsigned int DetectMotion( const Image &comp_image, Event::StringSet &zoneSet );
|
2013-03-17 07:45:21 +08:00
|
|
|
// DetectBlack seems to be unused. Check it on zm_monitor.cpp for more info.
|
|
|
|
//unsigned int DetectBlack( const Image &comp_image, Event::StringSet &zoneSet );
|
2016-06-22 00:21:18 +08:00
|
|
|
bool CheckSignal( const Image *image );
|
|
|
|
bool Analyse();
|
|
|
|
void DumpImage( Image *dump_image ) const;
|
|
|
|
void TimestampImage( Image *ts_image, const struct timeval *ts_time ) const;
|
|
|
|
bool closeEvent();
|
2003-03-26 19:57:29 +08:00
|
|
|
|
2016-06-22 00:21:18 +08:00
|
|
|
void Reload();
|
|
|
|
void ReloadZones();
|
|
|
|
void ReloadLinkedMonitors( const char * );
|
2005-12-23 00:46:25 +08:00
|
|
|
|
2016-06-22 00:21:18 +08:00
|
|
|
bool DumpSettings( char *output, bool verbose );
|
|
|
|
void DumpZoneImage( const char *zone_string=0 );
|
2018-05-13 05:34:26 +08:00
|
|
|
std::vector<Group *> Groups();
|
|
|
|
StringVector GroupNames();
|
2005-12-23 00:46:25 +08:00
|
|
|
|
2018-03-09 20:23:40 +08:00
|
|
|
static int LoadMonitors(std::string sql, Monitor **&monitors, Purpose purpose); // Returns # of Monitors loaded, 0 on failure.
|
2011-02-16 05:59:06 +08:00
|
|
|
#if ZM_HAS_V4L
|
2018-03-09 20:23:40 +08:00
|
|
|
static int LoadLocalMonitors(const char *device, Monitor **&monitors, Purpose purpose);
|
2011-02-16 05:59:06 +08:00
|
|
|
#endif // ZM_HAS_V4L
|
2018-03-09 20:23:40 +08:00
|
|
|
static int LoadRemoteMonitors(const char *protocol, const char *host, const char*port, const char*path, Monitor **&monitors, Purpose purpose);
|
|
|
|
static int LoadFileMonitors(const char *file, Monitor **&monitors, Purpose purpose);
|
2009-01-28 23:02:33 +08:00
|
|
|
#if HAVE_LIBAVFORMAT
|
2018-03-09 20:23:40 +08:00
|
|
|
static int LoadFfmpegMonitors(const char *file, Monitor **&monitors, Purpose purpose);
|
2009-01-28 23:02:33 +08:00
|
|
|
#endif // HAVE_LIBAVFORMAT
|
2018-03-09 20:23:40 +08:00
|
|
|
static Monitor *Load(unsigned int id, bool load_zones, Purpose purpose);
|
|
|
|
static Monitor *Load(MYSQL_ROW dbrow, bool load_zones, Purpose purpose);
|
2016-04-29 21:11:14 +08:00
|
|
|
//void writeStreamImage( Image *image, struct timeval *timestamp, int scale, int mag, int x, int y );
|
|
|
|
//void StreamImages( int scale=100, int maxfps=10, time_t ttl=0, int msq_id=0 );
|
|
|
|
//void StreamImagesRaw( int scale=100, int maxfps=10, time_t ttl=0 );
|
|
|
|
//void StreamImagesZip( int scale=100, int maxfps=10, time_t ttl=0 );
|
2004-03-04 23:05:54 +08:00
|
|
|
#if HAVE_LIBAVCODEC
|
2016-04-29 21:11:14 +08:00
|
|
|
//void StreamMpeg( const char *format, int scale=100, int maxfps=10, int bitrate=100000 );
|
2004-03-04 23:05:54 +08:00
|
|
|
#endif // HAVE_LIBAVCODEC
|
2003-03-26 19:57:29 +08:00
|
|
|
};
|
|
|
|
|
2007-08-30 02:11:09 +08:00
|
|
|
#define MOD_ADD( var, delta, limit ) (((var)+(limit)+(delta))%(limit))
|
|
|
|
|
2003-03-26 19:57:29 +08:00
|
|
|
#endif // ZM_MONITOR_H
|