Convert event_id to a 64bit unsigned int

This commit is contained in:
Isaac Connor 2018-04-12 13:40:11 -07:00
parent b974b4dcd1
commit f9f78e9aa3
14 changed files with 172 additions and 198 deletions

View File

@ -23,35 +23,3 @@ SET @s = (SELECT IF(
PREPARE stmt FROM @s; PREPARE stmt FROM @s;
EXECUTE stmt; EXECUTE stmt;
ALTER TABLE `Frames` MODIFY `Id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE `Events` MODIFY `Id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE `Frames` MODIFY `EventId` BIGINT UNSIGNED NOT NULL;
ALTER TABLE `Stats` MODIFY `EventId` BIGINT UNSIGNED NOT NULL;
ALTER TABLE `Events_Hour` MODIFY `EventId` BIGINT UNSIGNED NOT NULL;
SET @s = (SELECT IF(
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE='FOREIGN KEY'
AND table_name = 'Events'
AND column_name = 'Locked'
) > 0,
"SELECT 'Column Locked already exists in Events'",
"ALTER TABLE `Events` ADD `Locked` BOOLEAN NOT NULL default false AFTER `Scheme`"
));
ALTER TABLE `Events_Hour` ADD CONSTRAINT Events_Hour_EventId_fk FOREIGN KEY (`EventId`) REFERENCES `Events`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Events_Day` MODIFY `EventId` BIGINT UNSIGNED NOT NULL;
ALTER TABLE `Events_Day` ADD CONSTRAINT Events_Day_EventId_fk FOREIGN KEY (`EventId`) REFERENCES `Events`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Events_Week` MODIFY `EventId` BIGINT UNSIGNED NOT NULL;
ALTER TABLE `Events_Week` ADD CONSTRAINT Events_Week_EventId_fk FOREIGN KEY (`EventId`) REFERENCES `Events`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Events_Month` MODIFY `EventId` BIGINT UNSIGNED NOT NULL;
ALTER TABLE `Events_Month` ADD CONSTRAINT Events_Month_EventId_fk FOREIGN KEY (`EventId`) REFERENCES `Events`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Events_Archived` MODIFY `EventId` BIGINT UNSIGNED NOT NULL;
ALTER TABLE `Events_Archived` ADD CONSTRAINT Events_Archived_EventId_fk FOREIGN KEY (`EventId`) REFERENCES `Events`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Stats` ADD CONSTRAINT Stats_MonitorId_fk FOREIGN KEY (`MonitorId`) REFERENCES `Monitors`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Stats` ADD CONSTRAINT Stats_EventId_fk FOREIGN KEY (`EventId`) REFERENCES `Events`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Stats` ADD CONSTRAINT Stats_ZoneId_fk FOREIGN KEY (`ZoneId`) REFERENCES `Zones`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Frames` ADD CONSTRAINT Frames_EventId_fk FOREIGN KEY (`EventId`) REFERENCES `Events`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Frames` DROP INDEX `Type`;

32
db/zm_update-1.31.42.sql Normal file
View File

@ -0,0 +1,32 @@
ALTER TABLE `Frames` MODIFY `Id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE `Events` MODIFY `Id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT;
ALTER TABLE `Frames` MODIFY `EventId` BIGINT UNSIGNED NOT NULL;
ALTER TABLE `Stats` MODIFY `EventId` BIGINT UNSIGNED NOT NULL;
ALTER TABLE `Events_Hour` MODIFY `EventId` BIGINT UNSIGNED NOT NULL;
SET @s = (SELECT IF(
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_TYPE='FOREIGN KEY'
AND table_name = 'Events'
AND column_name = 'Locked'
) > 0,
"SELECT 'Column Locked already exists in Events'",
"ALTER TABLE `Events` ADD `Locked` BOOLEAN NOT NULL default false AFTER `Scheme`"
));
ALTER TABLE `Events_Hour` ADD CONSTRAINT Events_Hour_EventId_fk FOREIGN KEY (`EventId`) REFERENCES `Events`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Events_Day` MODIFY `EventId` BIGINT UNSIGNED NOT NULL;
ALTER TABLE `Events_Day` ADD CONSTRAINT Events_Day_EventId_fk FOREIGN KEY (`EventId`) REFERENCES `Events`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Events_Week` MODIFY `EventId` BIGINT UNSIGNED NOT NULL;
ALTER TABLE `Events_Week` ADD CONSTRAINT Events_Week_EventId_fk FOREIGN KEY (`EventId`) REFERENCES `Events`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Events_Month` MODIFY `EventId` BIGINT UNSIGNED NOT NULL;
ALTER TABLE `Events_Month` ADD CONSTRAINT Events_Month_EventId_fk FOREIGN KEY (`EventId`) REFERENCES `Events`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Events_Archived` MODIFY `EventId` BIGINT UNSIGNED NOT NULL;
ALTER TABLE `Events_Archived` ADD CONSTRAINT Events_Archived_EventId_fk FOREIGN KEY (`EventId`) REFERENCES `Events`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Stats` ADD CONSTRAINT Stats_MonitorId_fk FOREIGN KEY (`MonitorId`) REFERENCES `Monitors`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Stats` ADD CONSTRAINT Stats_EventId_fk FOREIGN KEY (`EventId`) REFERENCES `Events`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Stats` ADD CONSTRAINT Stats_ZoneId_fk FOREIGN KEY (`ZoneId`) REFERENCES `Zones`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Frames` ADD CONSTRAINT Frames_EventId_fk FOREIGN KEY (`EventId`) REFERENCES `Events`(`Id`) ON DELETE CASCADE;
ALTER TABLE `Frames` DROP INDEX `Type`;

View File

@ -350,6 +350,10 @@ sub delete {
Warning( "Can't Delete event $event->{Id} from Monitor $event->{MonitorId} StartTime:$event->{StartTime} from $caller:$line\n" ); Warning( "Can't Delete event $event->{Id} from Monitor $event->{MonitorId} StartTime:$event->{StartTime} from $caller:$line\n" );
return; return;
} }
if ( ! -e $event->Storage()->Path() ) {
Warning("Not deleting event because storage path doesn't exist");
return;
}
Info( "Deleting event $event->{Id} from Monitor $event->{MonitorId} StartTime:$event->{StartTime}\n" ); Info( "Deleting event $event->{Id} from Monitor $event->{MonitorId} StartTime:$event->{StartTime}\n" );
$ZoneMinder::Database::dbh->ping(); $ZoneMinder::Database::dbh->ping();

View File

@ -327,6 +327,7 @@ sub checkFilter {
Error( "Unable toto delete event $event->{Id} as previous operations failed\n" ); Error( "Unable toto delete event $event->{Id} as previous operations failed\n" );
} }
} # end if AutoDelete } # end if AutoDelete
if ( $filter->{AutoMove} ) { if ( $filter->{AutoMove} ) {
my $Event = new ZoneMinder::Event( $$event{Id}, $event ); my $Event = new ZoneMinder::Event( $$event{Id}, $event );
my $NewStorage = new ZoneMinder::Storage( $filter->{AutoMoveTo} ); my $NewStorage = new ZoneMinder::Storage( $filter->{AutoMoveTo} );

View File

@ -147,7 +147,7 @@ Event::Event(
time_path_ptr += snprintf( time_path_ptr, sizeof(time_path)-(time_path_ptr-time_path), "%s%02d", i>3?"/":"", dt_parts[i] ); time_path_ptr += snprintf( time_path_ptr, sizeof(time_path)-(time_path_ptr-time_path), "%s%02d", i>3?"/":"", dt_parts[i] );
} }
// Create event id symlink // Create event id symlink
snprintf( id_file, sizeof(id_file), "%s/.%d", date_path, id ); snprintf( id_file, sizeof(id_file), "%s/.%llu", date_path, id );
if ( symlink( time_path, id_file ) < 0 ) if ( symlink( time_path, id_file ) < 0 )
Error( "Can't symlink %s -> %s: %s", id_file, path, strerror(errno)); Error( "Can't symlink %s -> %s: %s", id_file, path, strerror(errno));
} else if ( storage->Scheme() == Storage::MEDIUM ) { } else if ( storage->Scheme() == Storage::MEDIUM ) {
@ -160,14 +160,14 @@ Event::Event(
if ( errno != EEXIST ) if ( errno != EEXIST )
Error( "Can't mkdir %s: %s", path, strerror(errno)); Error( "Can't mkdir %s: %s", path, strerror(errno));
} }
path_ptr += snprintf( path_ptr, sizeof(path), "/%d", id ); path_ptr += snprintf( path_ptr, sizeof(path), "/%llu", id );
if ( mkdir( path, 0755 ) ) { if ( mkdir( path, 0755 ) ) {
// FIXME This should not be fatal. Should probably move to a different storage area. // FIXME This should not be fatal. Should probably move to a different storage area.
if ( errno != EEXIST ) if ( errno != EEXIST )
Error( "Can't mkdir %s: %s", path, strerror(errno)); Error( "Can't mkdir %s: %s", path, strerror(errno));
} }
} else { } else {
snprintf( path, sizeof(path), "%s/%d/%d", storage->Path(), monitor->Id(), id ); snprintf( path, sizeof(path), "%s/%d/%llu", storage->Path(), monitor->Id(), id );
if ( mkdir( path, 0755 ) ) { if ( mkdir( path, 0755 ) ) {
if ( errno != EEXIST ) { if ( errno != EEXIST ) {
Error( "Can't mkdir %s: %s", path, strerror(errno)); Error( "Can't mkdir %s: %s", path, strerror(errno));
@ -175,7 +175,7 @@ Event::Event(
} }
// Create empty id tag file // Create empty id tag file
snprintf( id_file, sizeof(id_file), "%s/.%d", path, id ); snprintf( id_file, sizeof(id_file), "%s/.%llu", path, id );
if ( FILE *id_fp = fopen( id_file, "w" ) ) if ( FILE *id_fp = fopen( id_file, "w" ) )
fclose( id_fp ); fclose( id_fp );
else else
@ -189,7 +189,7 @@ Event::Event(
/* Save as video */ /* Save as video */
if ( monitor->GetOptVideoWriter() != 0 ) { if ( monitor->GetOptVideoWriter() != 0 ) {
snprintf( video_name, sizeof(video_name), "%d-%s", id, "video.mp4" ); snprintf( video_name, sizeof(video_name), "%llu-%s", id, "video.mp4" );
snprintf( video_file, sizeof(video_file), staticConfig.video_file_format, path, video_name ); snprintf( video_file, sizeof(video_file), staticConfig.video_file_format, path, video_name );
Debug(1,"Writing video file to %s", video_file ); Debug(1,"Writing video file to %s", video_file );
@ -241,7 +241,7 @@ Event::~Event() {
if ( frames > last_db_frame ) { if ( frames > last_db_frame ) {
Debug(1, "Adding closing frame %d to DB", frames); Debug(1, "Adding closing frame %d to DB", frames);
snprintf(sql, sizeof(sql), snprintf(sql, sizeof(sql),
"INSERT INTO Frames ( EventId, FrameId, TimeStamp, Delta ) VALUES ( %d, %d, from_unixtime( %ld ), %s%ld.%02ld )", "INSERT INTO Frames ( EventId, FrameId, TimeStamp, Delta ) VALUES ( %llu, %d, from_unixtime( %ld ), %s%ld.%02ld )",
id, frames, end_time.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec); id, frames, end_time.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec);
db_mutex.lock(); db_mutex.lock();
if ( mysql_query(&dbconn, sql) ) { if ( mysql_query(&dbconn, sql) ) {
@ -252,7 +252,9 @@ Event::~Event() {
db_mutex.unlock(); db_mutex.unlock();
} }
snprintf(sql, sizeof(sql), "UPDATE Events SET Name='%s%d', EndTime = from_unixtime( %ld ), Length = %s%ld.%02ld, Frames = %d, AlarmFrames = %d, TotScore = %d, AvgScore = %d, MaxScore = %d, DefaultVideo = '%s' where Id = %d", monitor->EventPrefix(), id, end_time.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec, frames, alarm_frames, tot_score, (int)(alarm_frames?(tot_score/alarm_frames):0), max_score, video_name, id ); snprintf(sql, sizeof(sql),
"UPDATE Events SET Name='%s %llu', EndTime = from_unixtime( %ld ), Length = %s%ld.%02ld, Frames = %d, AlarmFrames = %d, TotScore = %d, AvgScore = %d, MaxScore = %d, DefaultVideo = '%s' where Id = %llu",
monitor->EventPrefix(), id, end_time.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec, frames, alarm_frames, tot_score, (int)(alarm_frames?(tot_score/alarm_frames):0), max_score, video_name, id );
db_mutex.lock(); db_mutex.lock();
while ( mysql_query(&dbconn, sql) ) { while ( mysql_query(&dbconn, sql) ) {
Error("Can't update event: %s reason: %s", sql, mysql_error(&dbconn)); Error("Can't update event: %s reason: %s", sql, mysql_error(&dbconn));
@ -421,7 +423,7 @@ void Event::updateNotes( const StringSetMap &newNoteSetMap ) {
mysql_real_escape_string( &dbconn, escapedNotes, notes.c_str(), notes.length() ); mysql_real_escape_string( &dbconn, escapedNotes, notes.c_str(), notes.length() );
snprintf( sql, sizeof(sql), "update Events set Notes = '%s' where Id = %d", escapedNotes, id ); snprintf( sql, sizeof(sql), "UPDATE Events SET Notes = '%s' WHERE Id = %llu", escapedNotes, id );
db_mutex.lock(); db_mutex.lock();
if ( mysql_query( &dbconn, sql ) ) { if ( mysql_query( &dbconn, sql ) ) {
Error( "Can't insert event: %s", mysql_error( &dbconn ) ); Error( "Can't insert event: %s", mysql_error( &dbconn ) );
@ -479,7 +481,7 @@ void Event::AddFramesInternal( int n_frames, int start_frame, Image **images, st
} }
int sql_len = strlen(sql); int sql_len = strlen(sql);
snprintf( sql+sql_len, sizeof(sql)-sql_len, "( %d, %d, from_unixtime(%ld), %s%ld.%02ld ), ", id, frames, timestamps[i]->tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec ); snprintf( sql+sql_len, sizeof(sql)-sql_len, "( %llu, %d, from_unixtime(%ld), %s%ld.%02ld ), ", id, frames, timestamps[i]->tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec );
frameCount++; frameCount++;
} }
@ -540,7 +542,7 @@ Debug(3, "Writing video");
Debug( 1, "Adding frame %d of type \"%s\" to DB", frames, Event::frame_type_names[frame_type] ); Debug( 1, "Adding frame %d of type \"%s\" to DB", frames, Event::frame_type_names[frame_type] );
static char sql[ZM_SQL_MED_BUFSIZ]; static char sql[ZM_SQL_MED_BUFSIZ];
snprintf(sql, sizeof(sql), "insert into Frames ( EventId, FrameId, Type, TimeStamp, Delta, Score ) values ( %d, %d, '%s', from_unixtime( %ld ), %s%ld.%02ld, %d )", id, frames, frame_type_names[frame_type], timestamp.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec, score); snprintf(sql, sizeof(sql), "INSERT INTO Frames ( EventId, FrameId, Type, TimeStamp, Delta, Score ) values ( %llu, %d, '%s', from_unixtime( %ld ), %s%ld.%02ld, %d )", id, frames, frame_type_names[frame_type], timestamp.tv_sec, delta_time.positive?"":"-", delta_time.sec, delta_time.fsec, score);
db_mutex.lock(); db_mutex.lock();
if ( mysql_query(&dbconn, sql) ) { if ( mysql_query(&dbconn, sql) ) {
Error("Can't insert frame: %s", mysql_error(&dbconn)); Error("Can't insert frame: %s", mysql_error(&dbconn));
@ -553,7 +555,8 @@ Debug(3, "Writing video");
// We are writing a Bulk frame // We are writing a Bulk frame
if ( frame_type == BULK ) { if ( frame_type == BULK ) {
snprintf( sql, sizeof(sql), "update Events set Length = %s%ld.%02ld, Frames = %d, AlarmFrames = %d, TotScore = %d, AvgScore = %d, MaxScore = %d where Id = %d", snprintf( sql, sizeof(sql),
"UPDATE Events SET Length = %s%ld.%02ld, Frames = %d, AlarmFrames = %d, TotScore = %d, AvgScore = %d, MaxScore = %d where Id = %llu",
( delta_time.positive?"":"-" ), ( delta_time.positive?"":"-" ),
delta_time.sec, delta_time.fsec, delta_time.sec, delta_time.fsec,
frames, frames,
@ -564,9 +567,11 @@ Debug(3, "Writing video");
id id
); );
db_mutex.lock(); db_mutex.lock();
while ( mysql_query( &dbconn, sql ) ) { while ( mysql_query(&dbconn, sql) ) {
Error( "Can't update event: %s", mysql_error( &dbconn ) ); Error("Can't update event: %s", mysql_error(&dbconn));
db_mutex.unlock();
sleep(1); sleep(1);
db_mutex.lock();
} }
db_mutex.unlock(); db_mutex.unlock();
} }
@ -583,9 +588,9 @@ Debug(3, "Writing video");
max_score = score; max_score = score;
if ( alarm_image ) { if ( alarm_image ) {
snprintf( event_file, sizeof(event_file), staticConfig.analyse_file_format, path, frames ); snprintf(event_file, sizeof(event_file), staticConfig.analyse_file_format, path, frames);
Debug( 1, "Writing analysis frame %d", frames ); Debug(1, "Writing analysis frame %d", frames);
if ( monitor->GetOptSaveJPEGs() & 2 ) { if ( monitor->GetOptSaveJPEGs() & 2 ) {
WriteFrameImage(alarm_image, timestamp, event_file, true); WriteFrameImage(alarm_image, timestamp, event_file, true);
} }

View File

@ -73,7 +73,7 @@ class Event {
static int pre_alarm_count; static int pre_alarm_count;
static PreAlarmData pre_alarm_data[MAX_PRE_ALARM_FRAMES]; static PreAlarmData pre_alarm_data[MAX_PRE_ALARM_FRAMES];
unsigned int id; unsigned long long int id;
Monitor *monitor; Monitor *monitor;
struct timeval start_time; struct timeval start_time;
struct timeval end_time; struct timeval end_time;
@ -103,15 +103,15 @@ class Event {
Event( Monitor *p_monitor, struct timeval p_start_time, const std::string &p_cause, const StringSetMap &p_noteSetMap, bool p_videoEvent=false ); Event( Monitor *p_monitor, struct timeval p_start_time, const std::string &p_cause, const StringSetMap &p_noteSetMap, bool p_videoEvent=false );
~Event(); ~Event();
int Id() const { return( id ); } unsigned long long int Id() const { return id; }
const std::string &Cause() { return( cause ); } const std::string &Cause() { return cause; }
int Frames() const { return( frames ); } int Frames() const { return frames; }
int AlarmFrames() const { return( alarm_frames ); } int AlarmFrames() const { return alarm_frames; }
const struct timeval &StartTime() const { return( start_time ); } const struct timeval &StartTime() const { return start_time; }
const struct timeval &EndTime() const { return( end_time ); } const struct timeval &EndTime() const { return end_time; }
struct timeval &StartTime() { return( start_time ); } struct timeval &StartTime() { return start_time; }
struct timeval &EndTime() { return( end_time ); } struct timeval &EndTime() { return end_time; }
bool SendFrameImage( const Image *image, bool alarm_frame=false ); bool SendFrameImage( const Image *image, bool alarm_frame=false );
bool WriteFrameImage( Image *image, struct timeval timestamp, const char *event_file, bool alarm_frame=false ); bool WriteFrameImage( Image *image, struct timeval timestamp, const char *event_file, bool alarm_frame=false );
@ -132,7 +132,7 @@ class Event {
return( subpath ); return( subpath );
} }
static const char *getSubPath( time_t *time ) { static const char *getSubPath( time_t *time ) {
return( Event::getSubPath( localtime( time ) ) ); return Event::getSubPath( localtime( time ) );
} }
char* getEventFile(void) { char* getEventFile(void) {
@ -141,7 +141,7 @@ class Event {
public: public:
static int PreAlarmCount() { static int PreAlarmCount() {
return( pre_alarm_count ); return pre_alarm_count;
} }
static void EmptyPreAlarmFrames() { static void EmptyPreAlarmFrames() {
if ( pre_alarm_count > 0 ) { if ( pre_alarm_count > 0 ) {

View File

@ -62,7 +62,7 @@ bool EventStream::loadInitialEventData( int monitor_id, time_t event_time ) {
exit( mysql_errno(&dbconn)); exit( mysql_errno(&dbconn));
} }
int init_event_id = atoi(dbrow[0]); unsigned long long init_event_id = atoll(dbrow[0]);
mysql_free_result(result); mysql_free_result(result);
@ -84,10 +84,10 @@ bool EventStream::loadInitialEventData( int monitor_id, time_t event_time ) {
Debug( 3, "Skipping %ld frames", event_data->frame_count ); Debug( 3, "Skipping %ld frames", event_data->frame_count );
} }
} }
return( true ); return true;
} }
bool EventStream::loadInitialEventData( int init_event_id, unsigned int init_frame_id ) { bool EventStream::loadInitialEventData( unsigned long long init_event_id, unsigned int init_frame_id ) {
loadEventData(init_event_id); loadEventData(init_event_id);
if ( init_frame_id ) { if ( init_frame_id ) {
@ -105,10 +105,10 @@ bool EventStream::loadInitialEventData( int init_event_id, unsigned int init_fra
return true; return true;
} }
bool EventStream::loadEventData(int event_id) { bool EventStream::loadEventData(unsigned long long event_id) {
static char sql[ZM_SQL_MED_BUFSIZ]; static char sql[ZM_SQL_MED_BUFSIZ];
snprintf(sql, sizeof(sql), "SELECT MonitorId, StorageId, Frames, unix_timestamp( StartTime ) AS StartTimestamp, (SELECT max(Delta)-min(Delta) FROM Frames WHERE EventId=Events.Id) AS Duration, DefaultVideo, Scheme FROM Events WHERE Id = %d", event_id); snprintf(sql, sizeof(sql), "SELECT MonitorId, StorageId, Frames, unix_timestamp( StartTime ) AS StartTimestamp, (SELECT max(Delta)-min(Delta) FROM Frames WHERE EventId=Events.Id) AS Duration, DefaultVideo, Scheme FROM Events WHERE Id = %llu", event_id);
if ( mysql_query(&dbconn, sql) ) { if ( mysql_query(&dbconn, sql) ) {
Error("Can't run query: %s", mysql_error(&dbconn)); Error("Can't run query: %s", mysql_error(&dbconn));
@ -159,30 +159,34 @@ bool EventStream::loadEventData(int event_id) {
struct tm *event_time = localtime(&event_data->start_time); struct tm *event_time = localtime(&event_data->start_time);
if ( storage_path[0] == '/' ) if ( storage_path[0] == '/' )
snprintf( event_data->path, sizeof(event_data->path), "%s/%ld/%02d/%02d/%02d/%02d/%02d/%02d", storage_path, event_data->monitor_id, event_time->tm_year-100, event_time->tm_mon+1, event_time->tm_mday, event_time->tm_hour, event_time->tm_min, event_time->tm_sec ); snprintf( event_data->path, sizeof(event_data->path), "%s/%ld/%02d/%02d/%02d/%02d/%02d/%02d",
storage_path, event_data->monitor_id, event_time->tm_year-100, event_time->tm_mon+1, event_time->tm_mday, event_time->tm_hour, event_time->tm_min, event_time->tm_sec );
else else
snprintf( event_data->path, sizeof(event_data->path), "%s/%s/%ld/%02d/%02d/%02d/%02d/%02d/%02d", staticConfig.PATH_WEB.c_str(), storage_path, event_data->monitor_id, event_time->tm_year-100, event_time->tm_mon+1, event_time->tm_mday, event_time->tm_hour, event_time->tm_min, event_time->tm_sec ); snprintf( event_data->path, sizeof(event_data->path), "%s/%s/%ld/%02d/%02d/%02d/%02d/%02d/%02d",
staticConfig.PATH_WEB.c_str(), storage_path, event_data->monitor_id, event_time->tm_year-100, event_time->tm_mon+1, event_time->tm_mday, event_time->tm_hour, event_time->tm_min, event_time->tm_sec );
} else if ( event_data->scheme == Storage::MEDIUM ) { } else if ( event_data->scheme == Storage::MEDIUM ) {
struct tm *event_time = localtime( &event_data->start_time ); struct tm *event_time = localtime( &event_data->start_time );
if ( storage_path[0] == '/' ) if ( storage_path[0] == '/' )
snprintf( event_data->path, sizeof(event_data->path), "%s/%ld/%04d-%02d-%02d/%ld", snprintf( event_data->path, sizeof(event_data->path), "%s/%ld/%04d-%02d-%02d/%llu",
storage_path, event_data->monitor_id, event_time->tm_year+1900, event_time->tm_mon+1, event_time->tm_mday, event_data->event_id ); storage_path, event_data->monitor_id, event_time->tm_year+1900, event_time->tm_mon+1, event_time->tm_mday, event_data->event_id );
else else
snprintf( event_data->path, sizeof(event_data->path), "%s/%s/%ld/%04d-%02d-%02d/%ld", snprintf( event_data->path, sizeof(event_data->path), "%s/%s/%ld/%04d-%02d-%02d/%llu",
staticConfig.PATH_WEB.c_str(), storage_path, event_data->monitor_id, event_time->tm_year+1900, event_time->tm_mon+1, event_time->tm_mday, staticConfig.PATH_WEB.c_str(), storage_path, event_data->monitor_id, event_time->tm_year+1900, event_time->tm_mon+1, event_time->tm_mday,
event_data->event_id ); event_data->event_id );
} else { } else {
if ( storage_path[0] == '/' ) if ( storage_path[0] == '/' )
snprintf( event_data->path, sizeof(event_data->path), "%s/%ld/%ld", storage_path, event_data->monitor_id, event_data->event_id ); snprintf( event_data->path, sizeof(event_data->path), "%s/%ld/%llu",
storage_path, event_data->monitor_id, event_data->event_id );
else else
snprintf( event_data->path, sizeof(event_data->path), "%s/%s/%ld/%ld", staticConfig.PATH_WEB.c_str(), storage_path, event_data->monitor_id, event_data->event_id ); snprintf( event_data->path, sizeof(event_data->path), "%s/%s/%ld/%llu",
staticConfig.PATH_WEB.c_str(), storage_path, event_data->monitor_id, event_data->event_id );
} }
delete storage; storage = NULL; delete storage; storage = NULL;
updateFrameRate( (double)event_data->frame_count/event_data->duration ); updateFrameRate( (double)event_data->frame_count/event_data->duration );
snprintf(sql, sizeof(sql), "select FrameId, unix_timestamp( `TimeStamp` ), Delta from Frames where EventId = %d order by FrameId asc", event_id); snprintf(sql, sizeof(sql), "SELECT FrameId, unix_timestamp( `TimeStamp` ), Delta FROM Frames where EventId = %llu ORDER BY FrameId ASC", event_id);
if ( mysql_query(&dbconn, sql) ) { if ( mysql_query(&dbconn, sql) ) {
Error("Can't run query: %s", mysql_error(&dbconn)); Error("Can't run query: %s", mysql_error(&dbconn));
exit(mysql_errno(&dbconn)); exit(mysql_errno(&dbconn));
@ -227,7 +231,7 @@ bool EventStream::loadEventData(int event_id) {
exit( mysql_errno( &dbconn ) ); exit( mysql_errno( &dbconn ) );
} }
mysql_free_result( result ); mysql_free_result(result);
//for ( int i = 0; i < 250; i++ ) //for ( int i = 0; i < 250; i++ )
//{ //{
//Info( "%d -> %d @ %f (%d)", i+1, event_data->frames[i].timestamp, event_data->frames[i].delta, event_data->frames[i].in_db ); //Info( "%d -> %d @ %f (%d)", i+1, event_data->frames[i].timestamp, event_data->frames[i].delta, event_data->frames[i].in_db );
@ -250,7 +254,7 @@ bool EventStream::loadEventData(int event_id) {
else else
curr_stream_time = event_data->frames[event_data->frame_count-1].timestamp; curr_stream_time = event_data->frames[event_data->frame_count-1].timestamp;
} }
Debug(2, "Event:%ld, Frames:%ld, Duration: %.2f", event_data->event_id, event_data->frame_count, event_data->duration); Debug(2, "Event:%llu, Frames:%ld, Duration: %.2f", event_data->event_id, event_data->frame_count, event_data->duration);
return true; return true;
} // bool EventStream::loadEventData( int event_id ) } // bool EventStream::loadEventData( int event_id )
@ -260,7 +264,6 @@ void EventStream::processCommand(const CmdMsg *msg) {
// Check for incoming command // Check for incoming command
switch( (MsgCommand)msg->msg_data[0] ) { switch( (MsgCommand)msg->msg_data[0] ) {
case CMD_PAUSE : case CMD_PAUSE :
{
Debug( 1, "Got PAUSE command" ); Debug( 1, "Got PAUSE command" );
// Set paused flag // Set paused flag
@ -268,12 +271,9 @@ void EventStream::processCommand(const CmdMsg *msg) {
replay_rate = ZM_RATE_BASE; replay_rate = ZM_RATE_BASE;
last_frame_sent = TV_2_FLOAT( now ); last_frame_sent = TV_2_FLOAT( now );
break; break;
}
case CMD_PLAY : case CMD_PLAY :
{
Debug( 1, "Got PLAY command" ); Debug( 1, "Got PLAY command" );
if ( paused ) { if ( paused ) {
// Clear paused flag
paused = false; paused = false;
} }
@ -287,30 +287,20 @@ void EventStream::processCommand(const CmdMsg *msg) {
replay_rate = ZM_RATE_BASE; replay_rate = ZM_RATE_BASE;
break; break;
}
case CMD_VARPLAY : case CMD_VARPLAY :
{
Debug( 1, "Got VARPLAY command" ); Debug( 1, "Got VARPLAY command" );
if ( paused ) { if ( paused ) {
// Clear paused flag
paused = false; paused = false;
} }
replay_rate = ntohs(((unsigned char)msg->msg_data[2]<<8)|(unsigned char)msg->msg_data[1])-32768; replay_rate = ntohs(((unsigned char)msg->msg_data[2]<<8)|(unsigned char)msg->msg_data[1])-32768;
break; break;
}
case CMD_STOP : case CMD_STOP :
{
Debug( 1, "Got STOP command" ); Debug( 1, "Got STOP command" );
// Clear paused flag
paused = false; paused = false;
break; break;
}
case CMD_FASTFWD : case CMD_FASTFWD :
{
Debug( 1, "Got FAST FWD command" ); Debug( 1, "Got FAST FWD command" );
if ( paused ) { if ( paused ) {
// Clear paused flag
paused = false; paused = false;
} }
// Set play rate // Set play rate
@ -333,36 +323,21 @@ void EventStream::processCommand(const CmdMsg *msg) {
break; break;
} }
break; break;
}
case CMD_SLOWFWD : case CMD_SLOWFWD :
{
Debug( 1, "Got SLOW FWD command" ); Debug( 1, "Got SLOW FWD command" );
// Set paused flag
paused = true; paused = true;
// Set play rate
replay_rate = ZM_RATE_BASE; replay_rate = ZM_RATE_BASE;
// Set step
step = 1; step = 1;
break; break;
}
case CMD_SLOWREV : case CMD_SLOWREV :
{
Debug( 1, "Got SLOW REV command" ); Debug( 1, "Got SLOW REV command" );
// Set paused flag
paused = true; paused = true;
// Set play rate
replay_rate = ZM_RATE_BASE; replay_rate = ZM_RATE_BASE;
// Set step
step = -1; step = -1;
break; break;
}
case CMD_FASTREV : case CMD_FASTREV :
{
Debug( 1, "Got FAST REV command" ); Debug( 1, "Got FAST REV command" );
if ( paused ) { paused = false;
// Clear paused flag
paused = false;
}
// Set play rate // Set play rate
switch ( replay_rate ) { switch ( replay_rate ) {
case -2 * ZM_RATE_BASE : case -2 * ZM_RATE_BASE :
@ -383,9 +358,7 @@ void EventStream::processCommand(const CmdMsg *msg) {
break; break;
} }
break; break;
}
case CMD_ZOOMIN : case CMD_ZOOMIN :
{
x = ((unsigned char)msg->msg_data[1]<<8)|(unsigned char)msg->msg_data[2]; x = ((unsigned char)msg->msg_data[1]<<8)|(unsigned char)msg->msg_data[2];
y = ((unsigned char)msg->msg_data[3]<<8)|(unsigned char)msg->msg_data[4]; y = ((unsigned char)msg->msg_data[3]<<8)|(unsigned char)msg->msg_data[4];
Debug( 1, "Got ZOOM IN command, to %d,%d", x, y ); Debug( 1, "Got ZOOM IN command, to %d,%d", x, y );
@ -409,10 +382,7 @@ void EventStream::processCommand(const CmdMsg *msg) {
} }
send_frame = true; send_frame = true;
break; break;
}
case CMD_ZOOMOUT : case CMD_ZOOMOUT :
{
Debug( 1, "Got ZOOM OUT command" ); Debug( 1, "Got ZOOM OUT command" );
switch ( zoom ) { switch ( zoom ) {
case 500: case 500:
@ -434,22 +404,16 @@ void EventStream::processCommand(const CmdMsg *msg) {
} }
send_frame = true; send_frame = true;
break; break;
}
case CMD_PAN : case CMD_PAN :
{
x = ((unsigned char)msg->msg_data[1]<<8)|(unsigned char)msg->msg_data[2]; x = ((unsigned char)msg->msg_data[1]<<8)|(unsigned char)msg->msg_data[2];
y = ((unsigned char)msg->msg_data[3]<<8)|(unsigned char)msg->msg_data[4]; y = ((unsigned char)msg->msg_data[3]<<8)|(unsigned char)msg->msg_data[4];
Debug( 1, "Got PAN command, to %d,%d", x, y ); Debug( 1, "Got PAN command, to %d,%d", x, y );
break; break;
}
case CMD_SCALE : case CMD_SCALE :
{
scale = ((unsigned char)msg->msg_data[1]<<8)|(unsigned char)msg->msg_data[2]; scale = ((unsigned char)msg->msg_data[1]<<8)|(unsigned char)msg->msg_data[2];
Debug( 1, "Got SCALE command, to %d", scale ); Debug( 1, "Got SCALE command, to %d", scale );
break; break;
}
case CMD_PREV : case CMD_PREV :
{
Debug( 1, "Got PREV command" ); Debug( 1, "Got PREV command" );
if ( replay_rate >= 0 ) if ( replay_rate >= 0 )
curr_frame_id = 0; curr_frame_id = 0;
@ -458,9 +422,7 @@ void EventStream::processCommand(const CmdMsg *msg) {
paused = false; paused = false;
forceEventChange = true; forceEventChange = true;
break; break;
}
case CMD_NEXT : case CMD_NEXT :
{
Debug( 1, "Got NEXT command" ); Debug( 1, "Got NEXT command" );
if ( replay_rate >= 0 ) if ( replay_rate >= 0 )
curr_frame_id = event_data->frame_count+1; curr_frame_id = event_data->frame_count+1;
@ -469,7 +431,6 @@ void EventStream::processCommand(const CmdMsg *msg) {
paused = false; paused = false;
forceEventChange = true; forceEventChange = true;
break; break;
}
case CMD_SEEK : case CMD_SEEK :
{ {
int offset = ((unsigned char)msg->msg_data[1]<<24)|((unsigned char)msg->msg_data[2]<<16)|((unsigned char)msg->msg_data[3]<<8)|(unsigned char)msg->msg_data[4]; int offset = ((unsigned char)msg->msg_data[1]<<24)|((unsigned char)msg->msg_data[2]<<16)|((unsigned char)msg->msg_data[3]<<8)|(unsigned char)msg->msg_data[4];
@ -479,35 +440,30 @@ void EventStream::processCommand(const CmdMsg *msg) {
break; break;
} }
case CMD_QUERY : case CMD_QUERY :
{
Debug( 1, "Got QUERY command, sending STATUS" ); Debug( 1, "Got QUERY command, sending STATUS" );
break; break;
}
case CMD_QUIT : case CMD_QUIT :
{ Info("User initiated exit - CMD_QUIT");
Info ("User initiated exit - CMD_QUIT");
break; break;
}
default : default :
{
// Do nothing, for now // Do nothing, for now
} break;
} }
struct { struct {
int event; unsigned long long event_id;
int progress; int progress;
int rate; int rate;
int zoom; int zoom;
bool paused; bool paused;
} status_data; } status_data;
status_data.event = event_data->event_id; status_data.event_id = event_data->event_id;
status_data.progress = (int)event_data->frames[curr_frame_id-1].offset; status_data.progress = (int)event_data->frames[curr_frame_id-1].offset;
status_data.rate = replay_rate; status_data.rate = replay_rate;
status_data.zoom = zoom; status_data.zoom = zoom;
status_data.paused = paused; status_data.paused = paused;
Debug( 2, "Event:%d, Paused:%d, progress:%d Rate:%d, Zoom:%d", Debug( 2, "Event:%llu, Paused:%d, progress:%d Rate:%d, Zoom:%d",
status_data.event, status_data.event_id,
status_data.paused, status_data.paused,
status_data.progress, status_data.progress,
status_data.rate, status_data.rate,
@ -516,19 +472,19 @@ void EventStream::processCommand(const CmdMsg *msg) {
DataMsg status_msg; DataMsg status_msg;
status_msg.msg_type = MSG_DATA_EVENT; status_msg.msg_type = MSG_DATA_EVENT;
memcpy( &status_msg.msg_data, &status_data, sizeof(status_data) ); memcpy(&status_msg.msg_data, &status_data, sizeof(status_data));
if ( sendto( sd, &status_msg, sizeof(status_msg), MSG_DONTWAIT, (sockaddr *)&rem_addr, sizeof(rem_addr) ) < 0 ) { if ( sendto(sd, &status_msg, sizeof(status_msg), MSG_DONTWAIT, (sockaddr *)&rem_addr, sizeof(rem_addr)) < 0 ) {
//if ( errno != EAGAIN ) //if ( errno != EAGAIN )
{ {
Error( "Can't sendto on sd %d: %s", sd, strerror(errno) ); Error("Can't sendto on sd %d: %s", sd, strerror(errno));
exit( -1 ); exit(-1);
} }
} }
// quit after sending a status, if this was a quit request // quit after sending a status, if this was a quit request
if ( (MsgCommand)msg->msg_data[0]==CMD_QUIT ) if ( (MsgCommand)msg->msg_data[0]==CMD_QUIT )
exit(0); exit(0);
updateFrameRate( (double)event_data->frame_count/event_data->duration ); updateFrameRate((double)event_data->frame_count/event_data->duration);
} }
void EventStream::checkEventLoaded() { void EventStream::checkEventLoaded() {
@ -536,10 +492,10 @@ void EventStream::checkEventLoaded() {
static char sql[ZM_SQL_SML_BUFSIZ]; static char sql[ZM_SQL_SML_BUFSIZ];
if ( curr_frame_id <= 0 ) { if ( curr_frame_id <= 0 ) {
snprintf( sql, sizeof(sql), "select Id from Events where MonitorId = %ld and Id < %ld order by Id desc limit 1", event_data->monitor_id, event_data->event_id ); snprintf( sql, sizeof(sql), "SELECT Id FROM Events WHERE MonitorId = %ld AND Id < %llu ORDER BY Id DESC LIMIT 1", event_data->monitor_id, event_data->event_id );
reload_event = true; reload_event = true;
} else if ( (unsigned int)curr_frame_id > event_data->frame_count ) { } else if ( (unsigned int)curr_frame_id > event_data->frame_count ) {
snprintf( sql, sizeof(sql), "select Id from Events where MonitorId = %ld and Id > %ld order by Id asc limit 1", event_data->monitor_id, event_data->event_id ); snprintf( sql, sizeof(sql), "SELECT Id FROM Events WHERE MonitorId = %ld AND Id > %llu ORDER BY Id ASC LIMIT 1", event_data->monitor_id, event_data->event_id );
reload_event = true; reload_event = true;
} }
@ -564,10 +520,10 @@ void EventStream::checkEventLoaded() {
} }
if ( dbrow ) { if ( dbrow ) {
int event_id = atoi(dbrow[0]); unsigned long long event_id = atoll(dbrow[0]);
Debug( 1, "Loading new event %d", event_id ); Debug( 1, "Loading new event %llu", event_id );
loadEventData( event_id ); loadEventData(event_id);
Debug( 2, "Current frame id = %d", curr_frame_id ); Debug( 2, "Current frame id = %d", curr_frame_id );
if ( replay_rate < 0 ) if ( replay_rate < 0 )
@ -657,25 +613,25 @@ Debug(2,"Streaming MPEG");
send_raw = false; send_raw = false;
if ( send_raw ) { if ( send_raw ) {
fdj = fopen( filepath, "rb" ); fdj = fopen(filepath, "rb");
if ( !fdj ) { if ( !fdj ) {
Error( "Can't open %s: %s", filepath, strerror(errno) ); Error("Can't open %s: %s", filepath, strerror(errno));
return( false ); return false;
} }
#if HAVE_SENDFILE #if HAVE_SENDFILE
if( fstat(fileno(fdj),&filestat) < 0 ) { if( fstat(fileno(fdj),&filestat) < 0 ) {
Error( "Failed getting information about file %s: %s", filepath, strerror(errno) ); Error( "Failed getting information about file %s: %s", filepath, strerror(errno) );
return( false ); return false;
} }
#else #else
img_buffer_size = fread( img_buffer, 1, sizeof(temp_img_buffer), fdj ); img_buffer_size = fread(img_buffer, 1, sizeof(temp_img_buffer), fdj);
#endif #endif
} else { } else {
Image *image = NULL; Image *image = NULL;
if ( filepath[0] ) { if ( filepath[0] ) {
Debug(1, "Loading image"); Debug(1, "Loading image");
image = new Image( filepath ); image = new Image(filepath);
} else if ( ffmpeg_input ) { } else if ( ffmpeg_input ) {
// Get the frame from the mp4 input // Get the frame from the mp4 input
Debug(1,"Getting frame from ffmpeg"); Debug(1,"Getting frame from ffmpeg");
@ -722,16 +678,16 @@ Debug(1, "Loading image");
switch( type ) { switch( type ) {
case STREAM_JPEG : case STREAM_JPEG :
fprintf( stdout, "Content-Type: image/jpeg\r\n" ); fputs( "Content-Type: image/jpeg\r\n", stdout );
break; break;
case STREAM_RAW : case STREAM_RAW :
fprintf( stdout, "Content-Type: image/x-rgb\r\n" ); fputs( "Content-Type: image/x-rgb\r\n", stdout );
break; break;
case STREAM_ZIP : case STREAM_ZIP :
fprintf( stdout, "Content-Type: image/x-rgbz\r\n" ); fputs( "Content-Type: image/x-rgbz\r\n", stdout );
break; break;
default : default :
Fatal( "Unexpected frame type %d", type ); Fatal("Unexpected frame type %d", type);
break; break;
} }
@ -765,11 +721,11 @@ Debug(1, "Loading image");
} }
} }
fprintf( stdout, "\r\n\r\n" ); fputs("\r\n\r\n", stdout);
fflush( stdout ); fflush(stdout);
} }
last_frame_sent = TV_2_FLOAT( now ); last_frame_sent = TV_2_FLOAT(now);
return( true ); return true;
} }
void EventStream::runStream() { void EventStream::runStream() {
@ -890,7 +846,7 @@ void EventStream::runStream() {
closeComms(); closeComms();
} }
void EventStream::setStreamStart( int init_event_id, unsigned int init_frame_id=0 ) { void EventStream::setStreamStart( unsigned long long init_event_id, unsigned int init_frame_id=0 ) {
loadInitialEventData( init_event_id, init_frame_id ); loadInitialEventData( init_event_id, init_frame_id );
if ( !(monitor = Monitor::Load( event_data->monitor_id, false, Monitor::QUERY )) ) { if ( !(monitor = Monitor::Load( event_data->monitor_id, false, Monitor::QUERY )) ) {
Fatal( "Unable to load monitor id %d for streaming", event_data->monitor_id ); Fatal( "Unable to load monitor id %d for streaming", event_data->monitor_id );
@ -898,9 +854,9 @@ void EventStream::setStreamStart( int init_event_id, unsigned int init_frame_id=
} }
} }
void EventStream::setStreamStart( int monitor_id, time_t event_time ) { void EventStream::setStreamStart( int monitor_id, time_t event_time ) {
loadInitialEventData( monitor_id, event_time ); loadInitialEventData(monitor_id, event_time);
if ( !(monitor = Monitor::Load( event_data->monitor_id, false, Monitor::QUERY )) ) { if ( !(monitor = Monitor::Load(event_data->monitor_id, false, Monitor::QUERY)) ) {
Fatal( "Unable to load monitor id %d for streaming", monitor_id ); Fatal("Unable to load monitor id %d for streaming", monitor_id);
return; return;
} }
} }

View File

@ -54,7 +54,7 @@ class EventStream : public StreamBase {
}; };
struct EventData { struct EventData {
unsigned long event_id; unsigned long long event_id;
unsigned long monitor_id; unsigned long monitor_id;
unsigned long storage_id; unsigned long storage_id;
unsigned long frame_count; unsigned long frame_count;
@ -83,8 +83,8 @@ class EventStream : public StreamBase {
FFmpeg_Input *ffmpeg_input; FFmpeg_Input *ffmpeg_input;
protected: protected:
bool loadEventData( int event_id ); bool loadEventData( unsigned long long event_id );
bool loadInitialEventData( int init_event_id, unsigned int init_frame_id ); bool loadInitialEventData( unsigned long long init_event_id, unsigned int init_frame_id );
bool loadInitialEventData( int monitor_id, time_t event_time ); bool loadInitialEventData( int monitor_id, time_t event_time );
void checkEventLoaded(); void checkEventLoaded();
@ -110,7 +110,7 @@ class EventStream : public StreamBase {
ffmpeg_input = NULL; ffmpeg_input = NULL;
} }
void setStreamStart( int init_event_id, unsigned int init_frame_id ); void setStreamStart( unsigned long long init_event_id, unsigned int init_frame_id );
void setStreamStart( int monitor_id, time_t event_time ); void setStreamStart( int monitor_id, time_t event_time );
void setStreamMode( StreamMode p_mode ) { void setStreamMode( StreamMode p_mode ) {
mode = p_mode; mode = p_mode;

View File

@ -261,11 +261,11 @@ bool Monitor::MonitorLink::inAlarm() {
bool Monitor::MonitorLink::hasAlarmed() { bool Monitor::MonitorLink::hasAlarmed() {
if ( shared_data->state == ALARM ) { if ( shared_data->state == ALARM ) {
return( true ); return true;
} else if ( shared_data->last_event != (unsigned int)last_event ) { } else if ( shared_data->last_event != last_event ) {
last_event = shared_data->last_event; last_event = shared_data->last_event;
} }
return( false ); return false;
} }
Monitor::Monitor( Monitor::Monitor(
@ -634,7 +634,7 @@ Monitor::~Monitor() {
} }
if ( mem_ptr ) { if ( mem_ptr ) {
if ( event ) { if ( event ) {
Info( "%s: image_count:%d - Closing event %d, shutting down", name, image_count, event->Id() ); Info( "%s: image_count:%d - Closing event %llu, shutting down", name, image_count, event->Id() );
closeEvent(); closeEvent();
// closeEvent may start another thread to close the event, so wait for it to finish // closeEvent may start another thread to close the event, so wait for it to finish
@ -808,15 +808,15 @@ unsigned int Monitor::GetLastWriteIndex() const {
return( shared_data->last_write_index!=(unsigned int)image_buffer_count?shared_data->last_write_index:-1 ); return( shared_data->last_write_index!=(unsigned int)image_buffer_count?shared_data->last_write_index:-1 );
} }
uint32_t Monitor::GetLastEventId() const { uint64_t Monitor::GetLastEventId() const {
Debug(2, "mem_ptr(%x), State(%d) last_read_index(%d) last_read_time(%d) last_event(%d)", Debug(2, "mem_ptr(%x), State(%d) last_read_index(%d) last_read_time(%d) last_event(%llu)",
mem_ptr, mem_ptr,
shared_data->state, shared_data->state,
shared_data->last_read_index, shared_data->last_read_index,
shared_data->last_read_time, shared_data->last_read_time,
shared_data->last_event shared_data->last_event
); );
return( shared_data->last_event ); return shared_data->last_event;
} }
// This function is crap. // This function is crap.
@ -1090,9 +1090,9 @@ void Monitor::DumpZoneImage( const char *zone_string ) {
std::string sql = stringtf("SELECT MAX(Id) FROM Events WHERE MonitorId=%d AND Frames > 0", id); std::string sql = stringtf("SELECT MAX(Id) FROM Events WHERE MonitorId=%d AND Frames > 0", id);
zmDbRow eventid_row; zmDbRow eventid_row;
if ( eventid_row.fetch(sql.c_str()) ) { if ( eventid_row.fetch(sql.c_str()) ) {
int event_id = atoi(eventid_row[0]); uint64_t event_id = atoll(eventid_row[0]);
Debug(3, "Got event %d", event_id); Debug(3, "Got event %llu", event_id);
EventStream *stream = new EventStream(); EventStream *stream = new EventStream();
stream->setStreamStart(event_id, (unsigned int)1); stream->setStreamStart(event_id, (unsigned int)1);
zone_image = stream->getImage(); zone_image = stream->getImage();
@ -1369,7 +1369,7 @@ bool Monitor::Analyse() {
} }
Warning( "%s: %s", SIGNAL_CAUSE, signalText ); Warning( "%s: %s", SIGNAL_CAUSE, signalText );
if ( event && !signal ) { if ( event && !signal ) {
Info( "%s: %03d - Closing event %d, signal loss", name, image_count, event->Id() ); Info( "%s: %03d - Closing event %llu, signal loss", name, image_count, event->Id() );
closeEvent(); closeEvent();
last_section_mod = 0; last_section_mod = 0;
} }
@ -1454,7 +1454,7 @@ bool Monitor::Analyse() {
//shared_data->state = state = IDLE; //shared_data->state = state = IDLE;
//Info( "%s: %03d - Closing event %d, section end", name, image_count, event->Id() ) //Info( "%s: %03d - Closing event %d, section end", name, image_count, event->Id() )
//} else { //} else {
Info( "%s: %03d - Closing event %d, section end forced ", name, image_count, event->Id() ); Info( "%s: %03d - Closing event %llu, section end forced ", name, image_count, event->Id() );
//} //}
closeEvent(); closeEvent();
last_section_mod = 0; last_section_mod = 0;
@ -1476,7 +1476,7 @@ bool Monitor::Analyse() {
snprintf(video_store_data->event_file, sizeof(video_store_data->event_file), "%s", event->getEventFile()); snprintf(video_store_data->event_file, sizeof(video_store_data->event_file), "%s", event->getEventFile());
video_store_data->recording = event->StartTime(); video_store_data->recording = event->StartTime();
Info( "%s: %03d - Opening new event %d, section start", name, image_count, event->Id() ); Info( "%s: %03d - Opening new event %llu, section start", name, image_count, event->Id() );
/* To prevent cancelling out an existing alert\prealarm\alarm state */ /* To prevent cancelling out an existing alert\prealarm\alarm state */
if ( state == IDLE ) { if ( state == IDLE ) {
@ -1592,7 +1592,7 @@ bool Monitor::Analyse() {
snprintf(video_store_data->event_file, sizeof(video_store_data->event_file), "%s", event->getEventFile()); snprintf(video_store_data->event_file, sizeof(video_store_data->event_file), "%s", event->getEventFile());
video_store_data->recording = event->StartTime(); video_store_data->recording = event->StartTime();
Info( "%s: %03d - Opening new event %d, alarm start", name, image_count, event->Id() ); Info( "%s: %03d - Opening new event %llu, alarm start", name, image_count, event->Id() );
if ( pre_event_images ) { if ( pre_event_images ) {
if ( analysis_fps ) { if ( analysis_fps ) {
@ -1630,11 +1630,11 @@ bool Monitor::Analyse() {
shared_data->state = state = ALERT; shared_data->state = state = ALERT;
} else if ( state == ALERT ) { } else if ( state == ALERT ) {
if ( image_count-last_alarm_count > post_event_count ) { if ( image_count-last_alarm_count > post_event_count ) {
Info( "%s: %03d - Left alarm state (%d) - %d(%d) images", name, image_count, event->Id(), event->Frames(), event->AlarmFrames() ); Info( "%s: %03d - Left alarm state (%llu) - %d(%d) images", name, image_count, event->Id(), event->Frames(), event->AlarmFrames() );
//if ( function != MOCORD || event_close_mode == CLOSE_ALARM || event->Cause() == SIGNAL_CAUSE ) //if ( function != MOCORD || event_close_mode == CLOSE_ALARM || event->Cause() == SIGNAL_CAUSE )
if ( function != MOCORD || event_close_mode == CLOSE_ALARM ) { if ( function != MOCORD || event_close_mode == CLOSE_ALARM ) {
shared_data->state = state = IDLE; shared_data->state = state = IDLE;
Info( "%s: %03d - Closing event %d, alarm end%s", name, image_count, event->Id(), (function==MOCORD)?", section truncated":"" ); Info( "%s: %03d - Closing event %llu, alarm end%s", name, image_count, event->Id(), (function==MOCORD)?", section truncated":"" );
closeEvent(); closeEvent();
} else { } else {
shared_data->state = state = TAPE; shared_data->state = state = TAPE;
@ -1716,7 +1716,7 @@ bool Monitor::Analyse() {
} }
} else { } else {
if ( event ) { if ( event ) {
Info( "%s: %03d - Closing event %d, trigger off", name, image_count, event->Id() ); Info( "%s: %03d - Closing event %llu, trigger off", name, image_count, event->Id() );
closeEvent(); closeEvent();
} }
shared_data->state = state = IDLE; shared_data->state = state = IDLE;
@ -1753,7 +1753,7 @@ void Monitor::Reload() {
Debug( 1, "Reloading monitor %s", name ); Debug( 1, "Reloading monitor %s", name );
if ( event ) { if ( event ) {
Info( "%s: %03d - Closing event %d, reloading", name, image_count, event->Id() ); Info( "%s: %03d - Closing event %llu, reloading", name, image_count, event->Id() );
closeEvent(); closeEvent();
} }

View File

@ -174,7 +174,7 @@ protected:
//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;
uint32_t current_event; uint64_t current_event;
char event_file[4096]; char event_file[4096];
timeval recording; // used as both bool and a pointer to the timestamp when recording should begin timeval recording; // used as both bool and a pointer to the timestamp when recording should begin
//uint32_t frameNumber; //uint32_t frameNumber;
@ -204,7 +204,7 @@ protected:
volatile VideoStoreData *video_store_data; volatile VideoStoreData *video_store_data;
int last_state; int last_state;
int last_event; uint64_t last_event;
public: public:
@ -212,7 +212,7 @@ protected:
~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 );
@ -401,40 +401,40 @@ public:
} }
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 Storage *getStorage() { inline Storage *getStorage() {
if ( ! storage ) { if ( ! storage ) {
storage = new Storage( storage_id ); storage = new Storage( storage_id );
} }
return( storage ); return storage;
} }
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;
} }
Orientation getOrientation() const; Orientation getOrientation() const;
@ -446,8 +446,8 @@ public:
int GetOptSaveJPEGs() const { return savejpegs; } int GetOptSaveJPEGs() const { return savejpegs; }
VideoWriter GetOptVideoWriter() const { return videowriter; } VideoWriter GetOptVideoWriter() const { return videowriter; }
const std::vector<EncoderParameter_t>* GetOptEncoderParams() const { return &encoderparamsvec; } const std::vector<EncoderParameter_t>* GetOptEncoderParams() const { return &encoderparamsvec; }
uint32_t GetVideoWriterEventId() const { return video_store_data->current_event; } uint64_t GetVideoWriterEventId() const { return video_store_data->current_event; }
void SetVideoWriterEventId( uint32_t p_event_id ) { video_store_data->current_event = p_event_id; } void SetVideoWriterEventId( uint64_t p_event_id ) { video_store_data->current_event = p_event_id; }
unsigned int GetPreEventCount() const { return pre_event_count; }; unsigned int GetPreEventCount() const { return pre_event_count; };
State GetState() const; State GetState() const;
@ -461,7 +461,7 @@ public:
int GetAlarmCaptureDelay() const { return alarm_capture_delay; } int GetAlarmCaptureDelay() const { return alarm_capture_delay; }
unsigned int GetLastReadIndex() const; unsigned int GetLastReadIndex() const;
unsigned int GetLastWriteIndex() const; unsigned int GetLastWriteIndex() const;
uint32_t GetLastEventId() const; uint64_t GetLastEventId() const;
double GetFPS() const; double GetFPS() const;
void ForceAlarmOn( int force_score, const char *force_case, const char *force_text="" ); void ForceAlarmOn( int force_score, const char *force_case, const char *force_text="" );
void ForceAlarmOff(); void ForceAlarmOff();

View File

@ -58,7 +58,7 @@ int main( int argc, const char *argv[] ) {
char format[32] = ""; char format[32] = "";
int monitor_id = 0; int monitor_id = 0;
time_t event_time = 0; time_t event_time = 0;
int event_id = 0; unsigned long long event_id = 0;
unsigned int frame_id = 1; unsigned int frame_id = 1;
unsigned int scale = 100; unsigned int scale = 100;
unsigned int rate = 100; unsigned int rate = 100;
@ -174,7 +174,7 @@ int main( int argc, const char *argv[] ) {
if ( monitor_id ) { if ( monitor_id ) {
snprintf(log_id_string, sizeof(log_id_string), "zms_m%d", monitor_id); snprintf(log_id_string, sizeof(log_id_string), "zms_m%d", monitor_id);
} else { } else {
snprintf(log_id_string, sizeof(log_id_string), "zms_e%d", event_id); snprintf(log_id_string, sizeof(log_id_string), "zms_e%llu", event_id);
} }
logInit( log_id_string ); logInit( log_id_string );

View File

@ -1 +1 @@
1.31.40 1.31.41

@ -1 +1 @@
Subproject commit 1351dde6b4c75b215099ae8bcf5a21d6c6e10298 Subproject commit c3976f1478c681b0bbc132ec3a3e82c3984eeed5

View File

@ -176,6 +176,16 @@ xhtmlHeaders( __FILE__, translate('Console') );
</div> </div>
<div class="container-fluid"> <div class="container-fluid">
<?php
for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) {
$monitor = $displayMonitors[$monitor_i];
$Monitor = new Monitor($monitor);
if ( $monitor_i % 100 == 0 ) {
if ( $monitor_i ) {
echo '</table>';
}
?>
<table class="table table-striped table-hover table-condensed" id="consoleTable"> <table class="table table-striped table-hover table-condensed" id="consoleTable">
<thead class="thead-highlight"> <thead class="thead-highlight">
<tr> <tr>
@ -203,9 +213,7 @@ xhtmlHeaders( __FILE__, translate('Console') );
</thead> </thead>
<tbody id="consoleTableBody"> <tbody id="consoleTableBody">
<?php <?php
for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) { } # monitor_i % 100
$monitor = $displayMonitors[$monitor_i];
$Monitor = new Monitor($monitor);
?> ?>
<tr id="<?php echo 'monitor_id-'.$monitor['Id'] ?>" title="<?php echo $monitor['Id'] ?>"> <tr id="<?php echo 'monitor_id-'.$monitor['Id'] ?>" title="<?php echo $monitor['Id'] ?>">
<?php <?php