2003-03-26 19:57:29 +08:00
|
|
|
//
|
|
|
|
// ZoneMinder Core Interfaces, $Date$, $Revision$
|
2005-02-24 22:40:14 +08:00
|
|
|
// Copyright (C) 2003, 2004, 2005 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
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ZM_EVENT_H
|
|
|
|
#define ZM_EVENT_H
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <time.h>
|
2004-03-03 00:32:49 +08:00
|
|
|
#include <sys/time.h>
|
2003-03-26 19:57:29 +08:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <mysql/mysql.h>
|
|
|
|
|
|
|
|
#include "zm.h"
|
|
|
|
#include "zm_image.h"
|
|
|
|
|
|
|
|
class Monitor;
|
|
|
|
|
2004-09-25 20:37:45 +08:00
|
|
|
#define MAX_PRE_ALARM_FRAMES 16 // Maximum number of prealarm frames that can be stored
|
|
|
|
|
2003-03-26 19:57:29 +08:00
|
|
|
//
|
|
|
|
// Class describing events, i.e. captured periods of activity.
|
|
|
|
//
|
|
|
|
class Event
|
|
|
|
{
|
2004-02-16 04:07:16 +08:00
|
|
|
protected:
|
|
|
|
static bool initialised;
|
2004-03-22 18:33:40 +08:00
|
|
|
static char capture_file_format[PATH_MAX];
|
|
|
|
static char analyse_file_format[PATH_MAX];
|
|
|
|
static char general_file_format[PATH_MAX];
|
2004-02-16 04:07:16 +08:00
|
|
|
|
2003-04-22 22:15:01 +08:00
|
|
|
protected:
|
|
|
|
static int sd;
|
|
|
|
|
2004-09-25 20:37:45 +08:00
|
|
|
protected:
|
|
|
|
struct PreAlarmData
|
|
|
|
{
|
|
|
|
Image *image;
|
|
|
|
struct timeval timestamp;
|
|
|
|
unsigned int score;
|
|
|
|
Image *alarm_frame;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int pre_alarm_count;
|
|
|
|
static PreAlarmData pre_alarm_data[MAX_PRE_ALARM_FRAMES];
|
|
|
|
|
2003-03-26 19:57:29 +08:00
|
|
|
protected:
|
|
|
|
int id;
|
|
|
|
Monitor *monitor;
|
|
|
|
struct timeval start_time;
|
|
|
|
struct timeval end_time;
|
|
|
|
int frames;
|
|
|
|
int alarm_frames;
|
|
|
|
unsigned int tot_score;
|
|
|
|
unsigned int max_score;
|
|
|
|
char path[PATH_MAX];
|
|
|
|
|
2004-05-05 17:19:07 +08:00
|
|
|
protected:
|
|
|
|
int last_db_frame;
|
|
|
|
|
2004-02-16 04:07:16 +08:00
|
|
|
protected:
|
|
|
|
static void Initialise()
|
|
|
|
{
|
|
|
|
initialised = true;
|
|
|
|
|
2005-05-16 17:27:06 +08:00
|
|
|
snprintf( capture_file_format, sizeof(capture_file_format), "%%s/%%0%dd-capture.jpg", config.event_image_digits );
|
|
|
|
snprintf( analyse_file_format, sizeof(analyse_file_format), "%%s/%%0%dd-analyse.jpg", config.event_image_digits );
|
|
|
|
snprintf( general_file_format, sizeof(general_file_format), "%%s/%%0%dd-%%s", config.event_image_digits );
|
2004-02-16 04:07:16 +08:00
|
|
|
}
|
|
|
|
|
2003-04-22 22:15:01 +08:00
|
|
|
public:
|
|
|
|
static bool OpenFrameSocket( int );
|
|
|
|
static bool ValidateFrameSocket( int );
|
|
|
|
|
2003-03-26 19:57:29 +08:00
|
|
|
public:
|
2004-12-29 01:41:55 +08:00
|
|
|
Event( Monitor *p_monitor, struct timeval p_start_time, const char *event_cause, const char *event_text="" );
|
2003-03-26 19:57:29 +08:00
|
|
|
~Event();
|
|
|
|
|
|
|
|
int Id() const { return( id ); }
|
|
|
|
int Frames() const { return( frames ); }
|
|
|
|
int AlarmFrames() const { return( alarm_frames ); }
|
|
|
|
|
2003-09-23 17:52:45 +08:00
|
|
|
const struct timeval &StartTime() const { return( start_time ); }
|
|
|
|
const struct timeval &EndTime() const { return( end_time ); }
|
2003-10-08 20:54:35 +08:00
|
|
|
struct timeval &EndTime() { return( end_time ); }
|
2003-09-23 17:52:45 +08:00
|
|
|
|
2003-04-22 22:15:01 +08:00
|
|
|
bool SendFrameImage( const Image *image, bool alarm_frame=false );
|
2004-02-16 04:07:16 +08:00
|
|
|
bool WriteFrameImage( Image *image, struct timeval timestamp, const char *event_file, bool alarm_frame=false );
|
2003-04-22 22:15:01 +08:00
|
|
|
|
2004-02-16 04:07:16 +08:00
|
|
|
void AddFrames( int n_frames, Image **images, struct timeval **timestamps );
|
2004-03-04 23:13:10 +08:00
|
|
|
void AddFrame( Image *image, struct timeval timestamp, int score=0, Image *alarm_frame=NULL );
|
2003-03-26 19:57:29 +08:00
|
|
|
|
2004-03-15 17:37:21 +08:00
|
|
|
static void StreamEvent( int event_id, int scale=100, int rate=100, int maxfps=10 );
|
2004-03-04 23:05:54 +08:00
|
|
|
#if HAVE_LIBAVCODEC
|
2004-03-15 17:37:21 +08:00
|
|
|
static void StreamMpeg( int event_id, const char *format, int scale=100, int rate=100, int maxfps=10, int bitrate=100000 );
|
2004-03-04 23:05:54 +08:00
|
|
|
#endif // HAVE_LIBAVCODEC
|
2004-09-25 20:37:45 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
static int PreAlarmCount()
|
|
|
|
{
|
|
|
|
return( pre_alarm_count );
|
|
|
|
}
|
|
|
|
static void EmptyPreAlarmFrames()
|
|
|
|
{
|
|
|
|
if ( pre_alarm_count > 0 )
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < MAX_PRE_ALARM_FRAMES; i++ )
|
|
|
|
{
|
|
|
|
delete pre_alarm_data[i].image;
|
|
|
|
delete pre_alarm_data[i].alarm_frame;
|
|
|
|
}
|
|
|
|
memset( pre_alarm_data, 0, sizeof(pre_alarm_data) );
|
|
|
|
}
|
|
|
|
pre_alarm_count = 0;
|
|
|
|
}
|
|
|
|
static void AddPreAlarmFrame( Image *image, struct timeval timestamp, int score=0, Image *alarm_frame=NULL )
|
|
|
|
{
|
|
|
|
pre_alarm_data[pre_alarm_count].image = new Image( *image );
|
|
|
|
pre_alarm_data[pre_alarm_count].timestamp = timestamp;
|
|
|
|
pre_alarm_data[pre_alarm_count].score = score;
|
|
|
|
if ( alarm_frame )
|
|
|
|
{
|
|
|
|
pre_alarm_data[pre_alarm_count].alarm_frame = new Image( *alarm_frame );
|
|
|
|
}
|
|
|
|
pre_alarm_count++;
|
|
|
|
}
|
|
|
|
void SavePreAlarmFrames()
|
|
|
|
{
|
|
|
|
for ( int i = 0; i < pre_alarm_count; i++ )
|
|
|
|
{
|
|
|
|
AddFrame( pre_alarm_data[i].image, pre_alarm_data[i].timestamp, pre_alarm_data[i].score, pre_alarm_data[i].alarm_frame );
|
|
|
|
}
|
|
|
|
EmptyPreAlarmFrames();
|
|
|
|
}
|
|
|
|
|
2003-03-26 19:57:29 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ZM_EVENT_H
|