rework zmu to load data from the last event with frames when it can't connect to zmc
This commit is contained in:
parent
0ab6e27259
commit
1262e831ac
|
@ -1221,6 +1221,17 @@ void EventStream::checkEventLoaded()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Image * EventStream::getImage( ) {
|
||||||
|
Event::Initialise();
|
||||||
|
static char filepath[PATH_MAX];
|
||||||
|
|
||||||
|
Debug( 2, "EventStream::getImage path(%s) frame(%d)", event_data->path, curr_frame_id );
|
||||||
|
snprintf( filepath, sizeof(filepath), Event::capture_file_format, event_data->path, curr_frame_id );
|
||||||
|
Debug( 2, "EventStream::getImage path(%s) ", filepath, curr_frame_id );
|
||||||
|
Image *image = new Image( filepath );
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
bool EventStream::sendFrame( int delta_us )
|
bool EventStream::sendFrame( int delta_us )
|
||||||
{
|
{
|
||||||
Debug( 2, "Sending frame %d", curr_frame_id );
|
Debug( 2, "Sending frame %d", curr_frame_id );
|
||||||
|
|
|
@ -253,18 +253,19 @@ public:
|
||||||
void setStreamStart( int init_event_id, int init_frame_id=0 )
|
void setStreamStart( int init_event_id, int init_frame_id=0 )
|
||||||
{
|
{
|
||||||
loadInitialEventData( init_event_id, init_frame_id );
|
loadInitialEventData( init_event_id, init_frame_id );
|
||||||
loadMonitor( event_data->monitor_id );
|
loadMonitor( event_data->monitor_id );
|
||||||
}
|
}
|
||||||
void setStreamStart( int monitor_id, time_t event_time )
|
void setStreamStart( int monitor_id, time_t event_time )
|
||||||
{
|
{
|
||||||
loadInitialEventData( monitor_id, event_time );
|
loadInitialEventData( monitor_id, event_time );
|
||||||
loadMonitor( monitor_id );
|
loadMonitor( monitor_id );
|
||||||
}
|
}
|
||||||
void setStreamMode( StreamMode p_mode )
|
void setStreamMode( StreamMode p_mode )
|
||||||
{
|
{
|
||||||
mode = p_mode;
|
mode = p_mode;
|
||||||
}
|
}
|
||||||
void runStream();
|
void runStream();
|
||||||
|
Image *getImage();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // ZM_EVENT_H
|
#endif // ZM_EVENT_H
|
||||||
|
|
|
@ -1131,13 +1131,32 @@ void Monitor::DumpZoneImage( const char *zone_string )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int index = shared_data->last_write_index;
|
Image *zone_image = NULL;
|
||||||
Snapshot *snap = &image_buffer[index];
|
if ( ( (!staticConfig.SERVER_ID) || ( staticConfig.SERVER_ID == server_id ) ) && connected ) {
|
||||||
Image *snap_image = snap->image;
|
Debug(3, "Trying to load from local zmc");
|
||||||
|
int index = shared_data->last_write_index;
|
||||||
|
Snapshot *snap = &image_buffer[index];
|
||||||
|
zone_image = new Image( *snap->image );
|
||||||
|
} else {
|
||||||
|
Debug(3, "Trying to load from event");
|
||||||
|
// Grab the most revent event image
|
||||||
|
std::string sql = stringtf( "SELECT MAX(Id) FROM Events WHERE MonitorId=%d AND Frames > 0", id );
|
||||||
|
MYSQL_ROW eventid_row = zmDbFetchOne(sql.c_str() );
|
||||||
|
if ( eventid_row ) {
|
||||||
|
int event_id = atoi( eventid_row[0] );
|
||||||
|
|
||||||
Image zone_image( *snap_image );
|
Debug( 3, "Got event %d", event_id );
|
||||||
if(zone_image.Colours() == ZM_COLOUR_GRAY8) {
|
EventStream *stream = new EventStream();
|
||||||
zone_image.Colourise(ZM_COLOUR_RGB24, ZM_SUBPIX_ORDER_RGB );
|
stream->setStreamStart( event_id, 1 );
|
||||||
|
zone_image = stream->getImage();
|
||||||
|
} else {
|
||||||
|
Error("Unable to load an event for monitor %d", id );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(zone_image->Colours() == ZM_COLOUR_GRAY8) {
|
||||||
|
zone_image->Colourise(ZM_COLOUR_RGB24, ZM_SUBPIX_ORDER_RGB );
|
||||||
}
|
}
|
||||||
|
|
||||||
for( int i = 0; i < n_zones; i++ )
|
for( int i = 0; i < n_zones; i++ )
|
||||||
|
@ -1173,19 +1192,20 @@ void Monitor::DumpZoneImage( const char *zone_string )
|
||||||
colour = RGB_WHITE;
|
colour = RGB_WHITE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zone_image.Fill( colour, 2, zones[i]->GetPolygon() );
|
zone_image->Fill( colour, 2, zones[i]->GetPolygon() );
|
||||||
zone_image.Outline( colour, zones[i]->GetPolygon() );
|
zone_image->Outline( colour, zones[i]->GetPolygon() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( extra_zone.getNumCoords() )
|
if ( extra_zone.getNumCoords() )
|
||||||
{
|
{
|
||||||
zone_image.Fill( extra_colour, 2, extra_zone );
|
zone_image->Fill( extra_colour, 2, extra_zone );
|
||||||
zone_image.Outline( extra_colour, extra_zone );
|
zone_image->Outline( extra_colour, extra_zone );
|
||||||
}
|
}
|
||||||
|
|
||||||
static char filename[PATH_MAX];
|
static char filename[PATH_MAX];
|
||||||
snprintf( filename, sizeof(filename), "Zones%d.jpg", id );
|
snprintf( filename, sizeof(filename), "Zones%d.jpg", id );
|
||||||
zone_image.WriteJpeg( filename );
|
zone_image->WriteJpeg( filename );
|
||||||
|
delete zone_image;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Monitor::DumpImage( Image *dump_image ) const
|
void Monitor::DumpImage( Image *dump_image ) const
|
||||||
|
|
|
@ -493,7 +493,6 @@ int main( int argc, char *argv[] )
|
||||||
}
|
}
|
||||||
if ( ! monitor->connect() ) {
|
if ( ! monitor->connect() ) {
|
||||||
Error( "Can't connect to capture daemon: %d %s", monitor->Id(), monitor->Name() );
|
Error( "Can't connect to capture daemon: %d %s", monitor->Id(), monitor->Name() );
|
||||||
exit( -1 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char separator = ' ';
|
char separator = ' ';
|
||||||
|
|
Loading…
Reference in New Issue