whitespace and comments.

pull/2414/head
Isaac Connor 2019-01-16 11:20:10 -05:00
parent 5f5f28378d
commit 3560d6247f
1 changed files with 146 additions and 134 deletions

View File

@ -77,8 +77,7 @@ bool EventStream::loadInitialEventData( int monitor_id, time_t event_time ) {
//Info( "eft %d > et %d", event_data->frames[i].timestamp, event_time ); //Info( "eft %d > et %d", event_data->frames[i].timestamp, event_time );
if ( event_data->frames[i].timestamp >= event_time ) { if ( event_data->frames[i].timestamp >= event_time ) {
curr_frame_id = i+1; curr_frame_id = i+1;
Debug( 3, "Set cst:%.2f", curr_stream_time ); Debug(3, "Set curr_stream_time:%.2f, curr_frame_id:%d", curr_stream_time, curr_frame_id);
Debug( 3, "Set cfid:%d", curr_frame_id );
break; break;
} }
} }
@ -141,7 +140,7 @@ bool EventStream::loadEventData(uint64_t event_id) {
event_data->storage_id = dbrow[1] ? atoi(dbrow[1]) : 0; event_data->storage_id = dbrow[1] ? atoi(dbrow[1]) : 0;
event_data->frame_count = dbrow[2] == NULL ? 0 : atoi(dbrow[2]); event_data->frame_count = dbrow[2] == NULL ? 0 : atoi(dbrow[2]);
event_data->start_time = atoi(dbrow[3]); event_data->start_time = atoi(dbrow[3]);
event_data->duration = atof(dbrow[4]); event_data->duration = dbrow[4] ? atof(dbrow[4]) : 0.0;
strncpy(event_data->video_file, dbrow[5], sizeof(event_data->video_file)-1); strncpy(event_data->video_file, dbrow[5], sizeof(event_data->video_file)-1);
std::string scheme_str = std::string(dbrow[6]); std::string scheme_str = std::string(dbrow[6]);
if ( scheme_str == "Deep" ) { if ( scheme_str == "Deep" ) {
@ -160,19 +159,30 @@ bool EventStream::loadEventData(uint64_t 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", snprintf(event_data->path, sizeof(event_data->path),
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 ); "%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", snprintf(event_data->path, sizeof(event_data->path),
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 ); "%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/%" PRIu64, snprintf(event_data->path, sizeof(event_data->path),
storage_path, event_data->monitor_id, event_time->tm_year+1900, event_time->tm_mon+1, event_time->tm_mday, event_data->event_id ); "%s/%ld/%04d-%02d-%02d/%" PRIu64,
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/%" PRIu64, snprintf(event_data->path, sizeof(event_data->path),
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, "%s/%s/%ld/%04d-%02d-%02d/%" PRIu64,
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 {
@ -181,13 +191,14 @@ bool EventStream::loadEventData(uint64_t event_id) {
storage_path, event_data->monitor_id, event_data->event_id); storage_path, event_data->monitor_id, event_data->event_id);
else else
snprintf(event_data->path, sizeof(event_data->path), "%s/%s/%ld/%" PRIu64, snprintf(event_data->path, sizeof(event_data->path), "%s/%s/%ld/%" PRIu64,
staticConfig.PATH_WEB.c_str(), storage_path, event_data->monitor_id, event_data->event_id ); 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 = %" PRIu64 " ORDER BY FrameId ASC", event_id); snprintf(sql, sizeof(sql), "SELECT FrameId, unix_timestamp( `TimeStamp` ), Delta FROM Frames WHERE EventId = %" PRIu64 " 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));
@ -489,20 +500,19 @@ void EventStream::processCommand(const CmdMsg *msg) {
} }
void EventStream::checkEventLoaded() { void EventStream::checkEventLoaded() {
bool reload_event = false;
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 < %" PRIu64 " 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 < %" PRIu64 " ORDER BY Id DESC LIMIT 1", event_data->monitor_id, event_data->event_id);
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 > %" PRIu64 " 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 > %" PRIu64 " ORDER BY Id ASC LIMIT 1", event_data->monitor_id, event_data->event_id);
reload_event = true; } else {
// No event change required
return;
} }
if ( reload_event ) { // Event change required.
if ( forceEventChange || ( mode != MODE_SINGLE && mode != MODE_NONE ) ) { if ( forceEventChange || ( mode != MODE_SINGLE && mode != MODE_NONE ) ) {
//Info( "SQL:%s", sql );
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));
@ -527,7 +537,7 @@ void EventStream::checkEventLoaded() {
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 ) //rewind
curr_frame_id = event_data->frame_count; curr_frame_id = event_data->frame_count;
else else
curr_frame_id = 1; curr_frame_id = 1;
@ -538,7 +548,7 @@ void EventStream::checkEventLoaded() {
else else
curr_frame_id = event_data->frame_count; curr_frame_id = event_data->frame_count;
paused = true; paused = true;
} } // end if found a new event or not
mysql_free_result(result); mysql_free_result(result);
forceEventChange = false; forceEventChange = false;
} else { } else {
@ -548,8 +558,7 @@ void EventStream::checkEventLoaded() {
curr_frame_id = event_data->frame_count; curr_frame_id = event_data->frame_count;
paused = true; paused = true;
} }
} } // void EventStream::checkEventLoaded()
}
Image * EventStream::getImage( ) { Image * EventStream::getImage( ) {
static char filepath[PATH_MAX]; static char filepath[PATH_MAX];
@ -675,7 +684,7 @@ Debug(1, "Loading image");
} }
delete image; delete image;
image = NULL; image = NULL;
} } // end if send_raw or not
switch ( type ) { switch ( type ) {
case STREAM_JPEG : case STREAM_JPEG :
@ -701,7 +710,7 @@ Debug(1, "Loading image");
if ( fwrite(img_buffer, img_buffer_size, 1, stdout) != 1 ) { if ( fwrite(img_buffer, img_buffer_size, 1, stdout) != 1 ) {
fclose(fdj); /* Close the file handle */ fclose(fdj); /* Close the file handle */
Error("Unable to send raw frame %u: %s",curr_frame_id,strerror(errno)); Error("Unable to send raw frame %u: %s",curr_frame_id,strerror(errno));
return( false ); return false;
} }
} }
#else #else
@ -709,7 +718,7 @@ Debug(1, "Loading image");
if ( fwrite(img_buffer, img_buffer_size, 1, stdout) != 1 ) { if ( fwrite(img_buffer, img_buffer_size, 1, stdout) != 1 ) {
fclose(fdj); /* Close the file handle */ fclose(fdj); /* Close the file handle */
Error("Unable to send raw frame %u: %s",curr_frame_id,strerror(errno)); Error("Unable to send raw frame %u: %s",curr_frame_id,strerror(errno));
return( false ); return false;
} }
#endif #endif
fclose(fdj); /* Close the file handle */ fclose(fdj); /* Close the file handle */
@ -718,16 +727,16 @@ Debug(1, "Loading image");
fprintf(stdout, "Content-Length: %d\r\n\r\n", img_buffer_size); fprintf(stdout, "Content-Length: %d\r\n\r\n", img_buffer_size);
if ( fwrite(img_buffer, img_buffer_size, 1, stdout) != 1 ) { if ( fwrite(img_buffer, img_buffer_size, 1, stdout) != 1 ) {
Error("Unable to send stream frame: %s", strerror(errno)); Error("Unable to send stream frame: %s", strerror(errno));
return( false ); return false;
}
} }
} // end if send_raw or not
fputs("\r\n\r\n", stdout); fputs("\r\n\r\n", stdout);
fflush(stdout); fflush(stdout);
} } // end if stream MPEG or other
last_frame_sent = TV_2_FLOAT(now); last_frame_sent = TV_2_FLOAT(now);
return true; return true;
} } // bool EventStream::sendFrame( int delta_us )
void EventStream::runStream() { void EventStream::runStream() {
openComms(); openComms();
@ -787,6 +796,7 @@ void EventStream::runStream() {
} }
if ( !in_event ) { if ( !in_event ) {
double actual_delta_time = TV_2_FLOAT(now) - last_frame_sent; double actual_delta_time = TV_2_FLOAT(now) - last_frame_sent;
// > 1 second
if ( actual_delta_time > 1 ) { if ( actual_delta_time > 1 ) {
static char frame_text[64]; static char frame_text[64];
snprintf(frame_text, sizeof(frame_text), "Time to next event = %d seconds", (int)time_to_event); snprintf(frame_text, sizeof(frame_text), "Time to next event = %d seconds", (int)time_to_event);
@ -800,7 +810,7 @@ void EventStream::runStream() {
curr_stream_time += (1.0L * replay_rate * STREAM_PAUSE_WAIT)/(ZM_RATE_BASE * 1000000); curr_stream_time += (1.0L * replay_rate * STREAM_PAUSE_WAIT)/(ZM_RATE_BASE * 1000000);
//} //}
continue; continue;
} } // end if !in_event
// Figure out if we should send this frame // Figure out if we should send this frame
@ -825,7 +835,7 @@ void EventStream::runStream() {
Debug(2, "Sending keepalive frame"); Debug(2, "Sending keepalive frame");
send_frame = true; send_frame = true;
} }
} } // end if streaming stepping or doing nothing
if ( send_frame ) if ( send_frame )
if ( !sendFrame(delta_us) ) if ( !sendFrame(delta_us) )
@ -854,7 +864,8 @@ void EventStream::runStream() {
#endif // HAVE_LIBAVCODEC #endif // HAVE_LIBAVCODEC
closeComms(); closeComms();
} } // void EventStream::runStream()
void EventStream::setStreamStart( uint64_t init_event_id, unsigned int init_frame_id=0 ) { void EventStream::setStreamStart( uint64_t 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)) ) {
@ -862,6 +873,7 @@ void EventStream::setStreamStart( uint64_t init_event_id, unsigned int init_fram
return; return;
} }
} }
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)) ) {