Use a memory table called Monitor_Status to store FPS and Status info for Monitors. This is to reduce locking and updates on the main Monitors table.
This commit is contained in:
parent
cf4ac74d02
commit
50fc4a2d94
|
@ -608,9 +608,6 @@ CREATE TABLE `Monitors` (
|
|||
`WebColour` varchar(32) NOT NULL default 'red',
|
||||
`Exif` tinyint(1) unsigned NOT NULL default '0',
|
||||
`Sequence` smallint(5) unsigned default NULL,
|
||||
`Status` enum('Unknown','NotRunning','Running','NoSignal','Signal') NOT NULL default 'Unknown',
|
||||
`CaptureFPS` DECIMAL(10,2) NOT NULL default 0,
|
||||
`AnalysisFPS` DECIMAL(5,2) NOT NULL default 0,
|
||||
`TotalEvents` int(10) unsigned,
|
||||
`TotalEventDiskSpace` bigint unsigned,
|
||||
`HourEvents` int(10) unsigned,
|
||||
|
@ -629,6 +626,14 @@ CREATE TABLE `Monitors` (
|
|||
|
||||
CREATE INDEX `Monitors_ServerId_idx` ON `Monitors` (`ServerId`);
|
||||
|
||||
DROP TABLE IF EXISTS `Monitor_Status`;
|
||||
CREATE TABLE `Monitor_Status` (
|
||||
`Id` int(10) unsigned NOT NULL,
|
||||
`Status` enum('Unknown','NotRunning','Running','NoSignal','Signal') NOT NULL default 'Unknown',
|
||||
`CaptureFPS` DECIMAL(10,2) NOT NULL default 0,
|
||||
`AnalysisFPS` DECIMAL(5,2) NOT NULL default 0,
|
||||
PRIMARY KEY (`Id`)
|
||||
) ENGINE=MEMORY;
|
||||
--
|
||||
-- Table structure for table `States`
|
||||
-- PP - Added IsActive to track custom run states
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
SET @s = (SELECT IF(
|
||||
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE()
|
||||
AND table_name = 'Monitor_Status'
|
||||
) > 0
|
||||
,
|
||||
"SELECT 'Monitor_Status Already exists'",
|
||||
"
|
||||
CREATE TABLE `Monitor_Status` (
|
||||
`Id` int(10) unsigned NOT NULL,
|
||||
`Status` enum('Unknown','NotRunning','Running','NoSignal','Signal') NOT NULL default 'Unknown',
|
||||
`CaptureFPS` DECIMAL(10,2) NOT NULL default 0,
|
||||
`AnalysisFPS` DECIMAL(5,2) NOT NULL default 0,
|
||||
PRIMARY KEY (`Id`)
|
||||
) ENGINE=MEMORY"
|
||||
));
|
||||
|
||||
PREPARE stmt FROM @s;
|
||||
EXECUTE stmt;
|
||||
|
||||
SET @s = (SELECT IF(
|
||||
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE()
|
||||
AND table_name = 'Monitors'
|
||||
AND column_name = 'Status'
|
||||
) > 0
|
||||
,
|
||||
"ALTER TABLE Monitors DROP COLUMN Status"
|
||||
"SELECT 'Monitor Status already removed.'",
|
||||
));
|
||||
|
||||
PREPARE stmt FROM @s;
|
||||
EXECUTE stmt;
|
||||
|
||||
SET @s = (SELECT IF(
|
||||
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE()
|
||||
AND table_name = 'Monitors'
|
||||
AND column_name = 'CaptureFPS'
|
||||
) > 0
|
||||
,
|
||||
"ALTER TABLE Monitors DROP COLUMN CaptureFPS"
|
||||
"SELECT 'Monitor CaptureFPS already removed.'",
|
||||
));
|
||||
|
||||
PREPARE stmt FROM @s;
|
||||
EXECUTE stmt;
|
||||
|
||||
SET @s = (SELECT IF(
|
||||
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE()
|
||||
AND table_name = 'Monitors'
|
||||
AND column_name = 'AnalysisFPS'
|
||||
) > 0
|
||||
,
|
||||
"ALTER TABLE Monitors DROP COLUMN AnalysisFPS"
|
||||
"SELECT 'Monitor AnalysisFPS already removed.'",
|
||||
));
|
||||
|
||||
PREPARE stmt FROM @s;
|
||||
EXECUTE stmt;
|
|
@ -738,7 +738,8 @@ int FfmpegCamera::CaptureAndRecord( Image &image, timeval recording, char* event
|
|||
int ret;
|
||||
static char errbuf[AV_ERROR_MAX_STRING_SIZE];
|
||||
|
||||
// If the reopen thread has a value, but mCanCapture != 0, then we have just reopened the connection to the ffmpeg device, and we can clean up the thread.
|
||||
// If the reopen thread has a value, but mCanCapture != 0, then we have just reopened
|
||||
// the connection to the ffmpeg device, and we can clean up the thread.
|
||||
if ( mReopenThread != 0 ) {
|
||||
void *retval = 0;
|
||||
|
||||
|
@ -751,7 +752,6 @@ int FfmpegCamera::CaptureAndRecord( Image &image, timeval recording, char* event
|
|||
mReopenThread = 0;
|
||||
}
|
||||
|
||||
|
||||
int frameComplete = false;
|
||||
while ( ! frameComplete ) {
|
||||
av_init_packet( &packet );
|
||||
|
@ -774,7 +774,7 @@ int FfmpegCamera::CaptureAndRecord( Image &image, timeval recording, char* event
|
|||
}
|
||||
|
||||
int keyframe = packet.flags & AV_PKT_FLAG_KEY;
|
||||
dumpPacket(&packet);
|
||||
dumpPacket(&packet);
|
||||
|
||||
//Video recording
|
||||
if ( recording.tv_sec ) {
|
||||
|
@ -836,6 +836,7 @@ dumpPacket(&packet);
|
|||
startTime,
|
||||
this->getMonitor());
|
||||
} // end if record_audio
|
||||
|
||||
if ( ! videoStore->open() ) {
|
||||
delete videoStore;
|
||||
videoStore = NULL;
|
||||
|
|
|
@ -1205,7 +1205,7 @@ bool Monitor::Analyse() {
|
|||
fps = double(fps_report_interval)/(now.tv_sec - last_fps_time);
|
||||
Info( "%s: %d - Analysing at %.2f fps", name, image_count, fps );
|
||||
static char sql[ZM_SQL_SML_BUFSIZ];
|
||||
snprintf( sql, sizeof(sql), "UPDATE Monitors SET AnalysisFPS = '%.2lf' WHERE Id = '%d'", fps, id );
|
||||
snprintf( sql, sizeof(sql), "INSERT INTO Monitor_Status (Id,AnalysisFPS) VALUES (%d, %.2lf) ON DUPLICATE KEY UPDATE AnalysisFPS = %.2lf", id, fps, fps );
|
||||
if ( mysql_query( &dbconn, sql ) ) {
|
||||
Error( "Can't run query: %s", mysql_error( &dbconn ) );
|
||||
}
|
||||
|
@ -3022,7 +3022,7 @@ Debug(4, "Return from Capture (%d)", captureResult);
|
|||
Info( "%s: images:%d - Capturing at %.2lf fps", name, image_count, fps );
|
||||
last_fps_time = now;
|
||||
static char sql[ZM_SQL_SML_BUFSIZ];
|
||||
snprintf( sql, sizeof(sql), "UPDATE Monitors SET CaptureFPS='%.2lf' WHERE Id=%d", fps, id );
|
||||
snprintf( sql, sizeof(sql), "INSERT INTO Monitor_Status (Id,CaptureFPS) VALUES (%d, %.2lf) ON DUPLICATE KEY UPDATE CaptureFPS = %.2lf", id, fps, fps );
|
||||
if ( mysql_query( &dbconn, sql ) ) {
|
||||
Error( "Can't run query: %s", mysql_error( &dbconn ) );
|
||||
}
|
||||
|
|
|
@ -223,7 +223,7 @@ int main(int argc, char *argv[]) {
|
|||
Info("Starting Capture version %s", ZM_VERSION);
|
||||
static char sql[ZM_SQL_SML_BUFSIZ];
|
||||
for ( int i = 0; i < n_monitors; i ++ ) {
|
||||
snprintf( sql, sizeof(sql), "UPDATE Monitors SET Status = 'Running' WHERE Id = '%d'", monitors[i]->Id() );
|
||||
snprintf( sql, sizeof(sql), "REPLACE INTO Monitor_Status (Id, Status ) VALUES ('%d','Running')", monitors[i]->Id() );
|
||||
if ( mysql_query( &dbconn, sql ) ) {
|
||||
Error( "Can't run query: %s", mysql_error( &dbconn ) );
|
||||
}
|
||||
|
|
|
@ -89,7 +89,7 @@ if ( ! is_array( $selected_monitor_ids ) ) {
|
|||
$values += $ids;
|
||||
}
|
||||
|
||||
$sql = 'SELECT * FROM Monitors' . ( count($conditions) ? ' WHERE ' . implode(' AND ', $conditions ) : '' ).' ORDER BY Sequence ASC';
|
||||
$sql = 'SELECT *,S.Status AS Status, S.CaptureFPS AS CaptureFPS FROM Monitors AS M LEFT JOIN Monitor_Status AS S ON S.Id=M.Id ' . ( count($conditions) ? ' WHERE ' . implode(' AND ', $conditions ) : '' ).' ORDER BY Sequence ASC';
|
||||
$monitors = dbFetchAll( $sql, null, $values );
|
||||
$displayMonitors = array();
|
||||
$monitors_dropdown = array();
|
||||
|
|
|
@ -215,7 +215,18 @@ for( $monitor_i = 0; $monitor_i < count($displayMonitors); $monitor_i += 1 ) {
|
|||
<td class="colName"><a <?php echo (canView('Stream') && $monitor['Function'] != 'None' ? 'href="?view=watch&mid='.$monitor['Id'].'">' : '>') . $monitor['Name'] ?></a></td>
|
||||
<td class="colFunction">
|
||||
<?php echo makePopupLink( '?view=function&mid='.$monitor['Id'], 'zmFunction', 'function', '<span class="'.$fclass.'">'.translate('Fn'.$monitor['Function']).( empty($monitor['Enabled']) ? ', disabled' : '' ) .'</span>', canEdit( 'Monitors' ) ) ?><br/>
|
||||
<?php echo $monitor['CaptureFPS'] . ( ( $monitor['Function'] == 'Mocord' or $monitor['Function'] == 'Modect' ) ? ' / ' . $monitor['AnalysisFPS'] : '' ) . ' FPS' ?>
|
||||
<?php
|
||||
$fps_string = '';
|
||||
if ( isset($monitor['CaptureFPS']) ) {
|
||||
$fps_string .= $monitor['CaptureFPS'];
|
||||
}
|
||||
|
||||
if ( isset($monitor['AnalysisFPS']) and ( $monitor['Function'] == 'Mocord' or $monitor['Function'] == 'Modect' ) ) {
|
||||
$fps_string .= ' / ' . $monitor['AnalysisFPS'];
|
||||
}
|
||||
if ($fps_string) $fps_string .= ' FPS';
|
||||
echo $fps_string;
|
||||
?>
|
||||
</td>
|
||||
<?php
|
||||
if ( count($servers) ) { ?>
|
||||
|
|
Loading…
Reference in New Issue