Add record_audio member, also correct whitespace

This commit is contained in:
Isaac Connor 2016-03-31 12:17:17 -04:00
parent 4e8255c80a
commit 2a3ed0c32c
1 changed files with 179 additions and 170 deletions

View File

@ -45,20 +45,17 @@
// This is the main class for monitors. Each monitor is associated // This is the main class for monitors. Each monitor is associated
// with a camera and is effectively a collector for events. // with a camera and is effectively a collector for events.
// //
class Monitor class Monitor {
{
friend class MonitorStream; friend class MonitorStream;
public: public:
typedef enum typedef enum {
{
QUERY=0, QUERY=0,
CAPTURE, CAPTURE,
ANALYSIS ANALYSIS
} Purpose; } Purpose;
typedef enum typedef enum {
{
NONE=1, NONE=1,
MONITOR, MONITOR,
MODECT, MODECT,
@ -67,8 +64,7 @@ public:
NODECT NODECT
} Function; } Function;
typedef enum typedef enum {
{
ROTATE_0=1, ROTATE_0=1,
ROTATE_90, ROTATE_90,
ROTATE_180, ROTATE_180,
@ -77,8 +73,7 @@ public:
FLIP_VERT FLIP_VERT
} Orientation; } Orientation;
typedef enum typedef enum {
{
IDLE, IDLE,
PREALARM, PREALARM,
ALARM, ALARM,
@ -87,45 +82,44 @@ public:
} State; } State;
protected: protected:
typedef std::set<Zone *> ZoneSet; typedef std::set<Zone *> ZoneSet;
typedef enum { GET_SETTINGS=0x1, SET_SETTINGS=0x2, RELOAD=0x4, SUSPEND=0x10, RESUME=0x20 } Action; typedef enum { GET_SETTINGS=0x1, SET_SETTINGS=0x2, RELOAD=0x4, SUSPEND=0x10, RESUME=0x20 } Action;
typedef enum { CLOSE_TIME, CLOSE_IDLE, CLOSE_ALARM } EventCloseMode; typedef enum { CLOSE_TIME, CLOSE_IDLE, CLOSE_ALARM } EventCloseMode;
/* sizeof(SharedData) expected to be 336 bytes on 32bit and 64bit */ /* sizeof(SharedData) expected to be 336 bytes on 32bit and 64bit */
typedef struct typedef struct {
{ uint32_t size; /* +0 */
uint32_t size; /* +0 */ uint32_t last_write_index; /* +4 */
uint32_t last_write_index; /* +4 */ uint32_t last_read_index; /* +8 */
uint32_t last_read_index; /* +8 */ uint32_t state; /* +12 */
uint32_t state; /* +12 */ uint32_t last_event; /* +16 */
uint32_t last_event; /* +16 */ uint32_t action; /* +20 */
uint32_t action; /* +20 */ int32_t brightness; /* +24 */
int32_t brightness; /* +24 */ int32_t hue; /* +28 */
int32_t hue; /* +28 */ int32_t colour; /* +32 */
int32_t colour; /* +32 */ int32_t contrast; /* +36 */
int32_t contrast; /* +36 */ int32_t alarm_x; /* +40 */
int32_t alarm_x; /* +40 */ int32_t alarm_y; /* +44 */
int32_t alarm_y; /* +44 */ uint8_t valid; /* +48 */
uint8_t valid; /* +48 */ uint8_t active; /* +49 */
uint8_t active; /* +49 */ uint8_t signal; /* +50 */
uint8_t signal; /* +50 */ uint8_t format; /* +51 */
uint8_t format; /* +51 */ uint32_t imagesize; /* +52 */
uint32_t imagesize; /* +52 */ uint32_t epadding1; /* +56 */
uint32_t epadding1; /* +56 */ uint32_t epadding2; /* +60 */
uint32_t epadding2; /* +60 */
/* /*
** This keeps 32bit time_t and 64bit time_t identical and compatible as long as time is before 2038. ** 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. ** Shared memory layout should be identical for both 32bit and 64bit and is multiples of 16.
*/ */
union { /* +64 */ union { /* +64 */
time_t last_write_time; time_t last_write_time;
uint64_t extrapad1; uint64_t extrapad1;
}; };
union { /* +72 */ union { /* +72 */
time_t last_read_time; time_t last_read_time;
uint64_t extrapad2; uint64_t extrapad2;
}; };
uint8_t control_state[256]; /* +80 */ uint8_t control_state[256]; /* +80 */
@ -134,8 +128,7 @@ protected:
typedef enum { TRIGGER_CANCEL, TRIGGER_ON, TRIGGER_OFF } TriggerState; typedef enum { TRIGGER_CANCEL, TRIGGER_ON, TRIGGER_OFF } TriggerState;
/* sizeof(TriggerData) expected to be 560 on 32bit & and 64bit */ /* sizeof(TriggerData) expected to be 560 on 32bit & and 64bit */
typedef struct typedef struct {
{
uint32_t size; uint32_t size;
uint32_t trigger_state; uint32_t trigger_state;
uint32_t trigger_score; uint32_t trigger_score;
@ -146,29 +139,26 @@ protected:
} TriggerData; } TriggerData;
/* sizeof(Snapshot) expected to be 16 bytes on 32bit and 32 bytes on 64bit */ /* sizeof(Snapshot) expected to be 16 bytes on 32bit and 32 bytes on 64bit */
struct Snapshot struct Snapshot {
{
struct timeval *timestamp; struct timeval *timestamp;
Image *image; Image *image;
void* padding; 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 //TODO: Technically we can't exclude this struct when people don't have avformat as the Memory.pm module doesn't know about avformat
#if 1 #if 1
//sizeOf(VideoStoreData) expected to be 4104 bytes on 32bit and 64bit //sizeOf(VideoStoreData) expected to be 4104 bytes on 32bit and 64bit
typedef struct typedef struct {
{ uint32_t size;
uint32_t size; char event_file[4096];
char event_file[4096]; uint32_t recording; //bool arch dependent so use uint32 instead
uint32_t recording; //bool arch dependent so use uint32 instead //uint32_t frameNumber;
//uint32_t frameNumber;
} VideoStoreData;
} VideoStoreData;
#endif // HAVE_LIBAVFORMAT #endif // HAVE_LIBAVFORMAT
class MonitorLink class MonitorLink {
{
protected: protected:
unsigned int id; unsigned int id;
char name[64]; char name[64];
@ -178,16 +168,16 @@ protected:
#if ZM_MEM_MAPPED #if ZM_MEM_MAPPED
int map_fd; int map_fd;
char mem_file[PATH_MAX]; char mem_file[PATH_MAX];
#else // ZM_MEM_MAPPED #else // ZM_MEM_MAPPED
int shm_id; int shm_id;
#endif // ZM_MEM_MAPPED #endif // ZM_MEM_MAPPED
off_t mem_size; off_t mem_size;
unsigned char *mem_ptr; unsigned char *mem_ptr;
volatile SharedData *shared_data; volatile SharedData *shared_data;
volatile TriggerData *trigger_data; volatile TriggerData *trigger_data;
volatile VideoStoreData *video_store_data; volatile VideoStoreData *video_store_data;
int last_state; int last_state;
int last_event; int last_event;
@ -196,21 +186,17 @@ protected:
MonitorLink( int p_id, const char *p_name ); MonitorLink( int p_id, const char *p_name );
~MonitorLink(); ~MonitorLink();
inline int Id() const inline int Id() const {
{
return( id ); return( id );
} }
inline const char *Name() const inline const char *Name() const {
{
return( name ); return( name );
} }
inline bool isConnected() const inline bool isConnected() const {
{
return( connected ); return( connected );
} }
inline time_t getLastConnectTime() const inline time_t getLastConnectTime() const {
{
return( last_connect_time ); return( last_connect_time );
} }
@ -227,58 +213,59 @@ protected:
unsigned int id; unsigned int id;
char name[64]; char name[64];
unsigned int server_id; unsigned int server_id;
Function function; // What the monitor is doing Function function; // What the monitor is doing
bool enabled; // Whether the monitor is enabled or asleep 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 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 unsigned int height; // Normally the same as the camera, but not if partly rotated
bool v4l_multi_buffer; bool v4l_multi_buffer;
unsigned int v4l_captures_per_frame; unsigned int v4l_captures_per_frame;
Orientation orientation; // Whether the image has to be rotated at all Orientation orientation; // Whether the image has to be rotated at all
unsigned int deinterlacing; unsigned int deinterlacing;
int savejpegspref; int savejpegspref;
int videowriterpref; int videowriterpref;
std::string encoderparams; std::string encoderparams;
std::vector<EncoderParameter_t> encoderparamsvec; std::vector<EncoderParameter_t> encoderparamsvec;
bool record_audio; // Whether to store the audio that we receive
int brightness; // The statically saved brightness of the camera int brightness; // The statically saved brightness of the camera
int contrast; // The statically saved contrast of the camera int contrast; // The statically saved contrast of the camera
int hue; // The statically saved hue of the camera int hue; // The statically saved hue of the camera
int colour; // The statically saved colour 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 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 char label_format[64]; // The format of the timestamp on the images
Coord label_coord; // The coordinates 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 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 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, int pre_event_buffer_count; // Size of dedicated circular pre event buffer used when analysis is not performed at capturing framerate,
// value is pre_event_count + alarm_frame_count - 1 // value is pre_event_count + alarm_frame_count - 1
int warmup_count; // How many images to process before looking for events 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 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 int post_event_count; // How many unalarmed images must occur before the alarm state is reset
int stream_replay_buffer; // How many frames to store to support DVR functions, IGNORED from this object, passed directly into zms now 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 int section_length; // How long events should last in continuous modes
bool adaptive_skip; // Whether to use the newer adaptive algorithm for this monitor 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 frame_skip; // How many frames to skip in continuous modes
int motion_frame_skip; // How many frames to skip in motion detection int motion_frame_skip; // How many frames to skip in motion detection
double analysis_fps; // Target framerate for video analysis double analysis_fps; // Target framerate for video analysis
unsigned int analysis_update_delay; // How long we wait before updating analysis parameters unsigned int analysis_update_delay; // How long we wait before updating analysis parameters
int capture_delay; // How long we wait between capture frames 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_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 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 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 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. 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 bool track_motion; // Whether this monitor tries to track detected motion
Rgb signal_check_colour; // The colour that the camera will emit when no video signal detected 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 embed_exif; // Whether to embed Exif data into each image frame or not
double fps; double fps;
Image delta_image; Image delta_image;
Image ref_image; Image ref_image;
Image alarm_image; // Used in creating analysis images, will be initialized in Analysis Image alarm_image; // Used in creating analysis images, will be initialized in Analysis
Image write_image; // Used when creating snapshot images Image write_image; // Used when creating snapshot images
Purpose purpose; // What this monitor has been created to do Purpose purpose; // What this monitor has been created to do
int event_count; int event_count;
int image_count; int image_count;
int ready_count; int ready_count;
@ -290,22 +277,22 @@ protected:
time_t start_time; time_t start_time;
time_t last_fps_time; time_t last_fps_time;
time_t auto_resume_time; time_t auto_resume_time;
unsigned int last_motion_score; unsigned int last_motion_score;
EventCloseMode event_close_mode; EventCloseMode event_close_mode;
#if ZM_MEM_MAPPED #if ZM_MEM_MAPPED
int map_fd; int map_fd;
char mem_file[PATH_MAX]; char mem_file[PATH_MAX];
#else // ZM_MEM_MAPPED #else // ZM_MEM_MAPPED
int shm_id; int shm_id;
#endif // ZM_MEM_MAPPED #endif // ZM_MEM_MAPPED
off_t mem_size; off_t mem_size;
unsigned char *mem_ptr; unsigned char *mem_ptr;
SharedData *shared_data; SharedData *shared_data;
TriggerData *trigger_data; TriggerData *trigger_data;
VideoStoreData *video_store_data; VideoStoreData *video_store_data;
Snapshot *image_buffer; Snapshot *image_buffer;
Snapshot next_buffer; /* Used by four field deinterlacing */ Snapshot next_buffer; /* Used by four field deinterlacing */
@ -332,54 +319,84 @@ protected:
public: public:
// OurCheckAlarms seems to be unused. Check it on zm_monitor.cpp for more info. // OurCheckAlarms seems to be unused. Check it on zm_monitor.cpp for more info.
//bool OurCheckAlarms( Zone *zone, const Image *pImage ); //bool OurCheckAlarms( Zone *zone, const Image *pImage );
Monitor( int p_id, const char *p_name, unsigned int p_server_id, int p_function, bool p_enabled, const char *p_linked_monitors, Camera *p_camera, int p_orientation, unsigned int p_deinterlacing, int p_savejpegs, int p_videowriter, std::string p_encoderparams, 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, int p_frame_skip, int p_motion_frame_skip, 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, Rgb p_signal_check_colour, bool p_embed_exif, Purpose p_purpose, int p_n_zones=0, Zone *p_zones[]=0 ); Monitor(
int p_id,
const char *p_name,
unsigned int p_server_id,
int p_function,
bool p_enabled,
const char *p_linked_monitors,
Camera *p_camera,
int p_orientation,
unsigned int p_deinterlacing,
int p_savejpegs,
int p_videowriter,
std::string p_encoderparams,
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,
int p_frame_skip,
int p_motion_frame_skip,
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,
Rgb p_signal_check_colour,
bool p_embed_exif,
Purpose p_purpose,
int p_n_zones=0,
Zone *p_zones[]=0
);
~Monitor(); ~Monitor();
void AddZones( int p_n_zones, Zone *p_zones[] ); void AddZones( int p_n_zones, Zone *p_zones[] );
void AddPrivacyBitmask( Zone *p_zones[] ); void AddPrivacyBitmask( Zone *p_zones[] );
bool connect(); bool connect();
inline int ShmValid() const inline int ShmValid() const {
{
return( shared_data->valid ); return( shared_data->valid );
} }
inline int Id() const inline int Id() const {
{
return( id ); return( id );
} }
inline const char *Name() const inline const char *Name() const {
{
return( name ); return( name );
} }
inline Function GetFunction() const inline Function GetFunction() const {
{
return( function ); return( function );
} }
inline bool Enabled() inline bool Enabled() {
{
if ( function <= MONITOR ) if ( function <= MONITOR )
return( false ); return( false );
return( enabled ); return( enabled );
} }
inline const char *EventPrefix() const inline const char *EventPrefix() const {
{
return( event_prefix ); return( event_prefix );
} }
inline bool Ready() inline bool Ready() {
{
if ( function <= MONITOR ) if ( function <= MONITOR )
return( false ); return( false );
return( image_count > ready_count ); return( image_count > ready_count );
} }
inline bool Active() inline bool Active() {
{
if ( function <= MONITOR ) if ( function <= MONITOR )
return( false ); return( false );
return( enabled && shared_data->active ); return( enabled && shared_data->active );
} }
inline bool Exif() inline bool Exif() {
{
return( embed_exif ); return( embed_exif );
} }
@ -390,7 +407,7 @@ public:
int GetOptSaveJPEGs() const { return( savejpegspref ); } int GetOptSaveJPEGs() const { return( savejpegspref ); }
int GetOptVideoWriter() const { return( videowriterpref ); } int GetOptVideoWriter() const { return( videowriterpref ); }
const std::vector<EncoderParameter_t>* GetOptEncoderParams() const { return( &encoderparamsvec ); } const std::vector<EncoderParameter_t>* GetOptEncoderParams() const { return( &encoderparamsvec ); }
State GetState() const; State GetState() const;
int GetImage( int index=-1, int scale=100 ); int GetImage( int index=-1, int scale=100 );
@ -420,17 +437,14 @@ public:
int actionColour( int p_colour=-1 ); int actionColour( int p_colour=-1 );
int actionContrast( int p_contrast=-1 ); int actionContrast( int p_contrast=-1 );
inline int PrimeCapture() inline int PrimeCapture() {
{
return( camera->PrimeCapture() ); return( camera->PrimeCapture() );
} }
inline int PreCapture() inline int PreCapture() {
{
return( camera->PreCapture() ); return( camera->PreCapture() );
} }
int Capture(); int Capture();
int PostCapture() int PostCapture() {
{
return( camera->PostCapture() ); return( camera->PostCapture() );
} }
@ -459,7 +473,7 @@ public:
static int LoadFfmpegMonitors( const char *file, Monitor **&monitors, Purpose purpose ); static int LoadFfmpegMonitors( const char *file, Monitor **&monitors, Purpose purpose );
#endif // HAVE_LIBAVFORMAT #endif // HAVE_LIBAVFORMAT
static Monitor *Load( unsigned int id, bool load_zones, Purpose purpose ); static Monitor *Load( unsigned int id, bool load_zones, Purpose purpose );
//void writeStreamImage( Image *image, struct timeval *timestamp, int scale, int mag, int x, int y ); //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 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 StreamImagesRaw( int scale=100, int maxfps=10, time_t ttl=0 );
//void StreamImagesZip( int scale=100, int maxfps=10, time_t ttl=0 ); //void StreamImagesZip( int scale=100, int maxfps=10, time_t ttl=0 );
@ -473,53 +487,48 @@ public:
#define MOD_ADD( var, delta, limit ) (((var)+(limit)+(delta))%(limit)) #define MOD_ADD( var, delta, limit ) (((var)+(limit)+(delta))%(limit))
class MonitorStream : public StreamBase class MonitorStream : public StreamBase {
{
protected: protected:
typedef struct SwapImage { typedef struct SwapImage {
bool valid; bool valid;
struct timeval timestamp; struct timeval timestamp;
char file_name[PATH_MAX]; char file_name[PATH_MAX];
} SwapImage; } SwapImage;
private: private:
SwapImage *temp_image_buffer; SwapImage *temp_image_buffer;
int temp_image_buffer_count; int temp_image_buffer_count;
int temp_read_index; int temp_read_index;
int temp_write_index; int temp_write_index;
protected: protected:
time_t ttl; time_t ttl;
protected: protected:
int playback_buffer; int playback_buffer;
bool delayed; bool delayed;
int frame_count; int frame_count;
protected: protected:
bool checkSwapPath( const char *path, bool create_path ); bool checkSwapPath( const char *path, bool create_path );
bool sendFrame( const char *filepath, struct timeval *timestamp ); bool sendFrame( const char *filepath, struct timeval *timestamp );
bool sendFrame( Image *image, struct timeval *timestamp ); bool sendFrame( Image *image, struct timeval *timestamp );
void processCommand( const CmdMsg *msg ); void processCommand( const CmdMsg *msg );
public: public:
MonitorStream() : playback_buffer( 0 ), delayed( false ), frame_count( 0 ) MonitorStream() : playback_buffer( 0 ), delayed( false ), frame_count( 0 ) {
{ }
} void setStreamBuffer( int p_playback_buffer ) {
void setStreamBuffer( int p_playback_buffer ) playback_buffer = p_playback_buffer;
{ }
playback_buffer = p_playback_buffer; void setStreamTTL( time_t p_ttl ) {
} ttl = p_ttl;
void setStreamTTL( time_t p_ttl ) }
{ bool setStreamStart( int monitor_id ) {
ttl = p_ttl; return loadMonitor( monitor_id );
} }
bool setStreamStart( int monitor_id )
{
return loadMonitor( monitor_id );
}
void runStream(); void runStream();
}; };