Merge branch 'storageareas' of github.com:connortechnology/ZoneMinder into storageareas

This commit is contained in:
Isaac Connor 2018-04-24 11:22:48 -07:00
commit 28921a653b
10 changed files with 82 additions and 22 deletions

View File

@ -528,6 +528,7 @@ CREATE TABLE `Monitor_Status` (
`Status` enum('Unknown','NotRunning','Running','Connected','Signal') NOT NULL default 'Unknown', `Status` enum('Unknown','NotRunning','Running','Connected','Signal') NOT NULL default 'Unknown',
`CaptureFPS` DECIMAL(10,2) NOT NULL default 0, `CaptureFPS` DECIMAL(10,2) NOT NULL default 0,
`AnalysisFPS` DECIMAL(5,2) NOT NULL default 0, `AnalysisFPS` DECIMAL(5,2) NOT NULL default 0,
`CaptureBandwidth` INT NOT NULL default 0,
PRIMARY KEY (`MonitorId`) PRIMARY KEY (`MonitorId`)
) ENGINE=MEMORY; ) ENGINE=MEMORY;
-- --

20
db/zm_update-1.31.30.sql Normal file
View File

@ -0,0 +1,20 @@
DROP TABLE IF EXISTS `Monitor_Status`;
CREATE TABLE `Monitor_Status` (
`MonitorId` int(10) unsigned NOT NULL,
`Status` enum('Unknown','NotRunning','Running','Connected','Signal') NOT NULL default 'Unknown',
`CaptureFPS` DECIMAL(10,2) NOT NULL default 0,
`AnalysisFPS` DECIMAL(5,2) NOT NULL default 0,
PRIMARY KEY (`MonitorId`)
) ENGINE=MEMORY;
SET SESSION sql_mode='NO_AUTO_VALUE_ON_ZERO';
SET @s = (SELECT IF(
(SELECT COUNT(*) FROM Storage WHERE Name = 'Default' AND Id=0 AND Path='/var/cache/zoneminder/events'
) > 0,
"SELECT 'Default Storage Area already exists.'",
"INSERT INTO Storage (Id,Name,Path,Scheme,ServerId) VALUES (0,'Default','/var/cache/zoneminder/events','Medium',NULL)"
));
PREPARE stmt FROM @s;
EXECUTE stmt;

12
db/zm_update-1.31.44.sql Normal file
View File

@ -0,0 +1,12 @@
SET @s = (SELECT IF(
(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema = DATABASE()
AND table_name = 'Monitor_Status'
AND column_name = 'CaptureBandwidth'
) > 0,
"SELECT 'Column CaptureBandwidth already exists in Monitor_Status'",
"ALTER TABLE `Monitor_Status` ADD `CaptureBandwidth` INT NOT NULL default 0 AFTER `AnalysisFPS`"
));
PREPARE stmt FROM @s;
EXECUTE stmt;

View File

@ -53,6 +53,8 @@ protected:
int contrast; int contrast;
bool capture; bool capture;
bool record_audio; bool record_audio;
unsigned int bytes;
public: public:
Camera( unsigned int p_monitor_id, SourceType p_type, unsigned int p_width, unsigned int p_height, int p_colours, int p_subpixelorder, int p_brightness, int p_contrast, int p_hue, int p_colour, bool p_capture, bool p_record_audio ); Camera( unsigned int p_monitor_id, SourceType p_type, unsigned int p_width, unsigned int p_height, int p_colours, int p_subpixelorder, int p_brightness, int p_contrast, int p_hue, int p_colour, bool p_capture, bool p_record_audio );
@ -74,6 +76,7 @@ public:
unsigned int SubpixelOrder() const { return( subpixelorder ); } unsigned int SubpixelOrder() const { return( subpixelorder ); }
unsigned int Pixels() const { return( pixels ); } unsigned int Pixels() const { return( pixels ); }
unsigned int ImageSize() const { return( imagesize ); } unsigned int ImageSize() const { return( imagesize ); }
unsigned int Bytes() const { return bytes; };
virtual int Brightness( int/*p_brightness*/=-1 ) { return( -1 ); } virtual int Brightness( int/*p_brightness*/=-1 ) { return( -1 ); }
virtual int Hue( int/*p_hue*/=-1 ) { return( -1 ); } virtual int Hue( int/*p_hue*/=-1 ) { return( -1 ); }

View File

@ -292,6 +292,7 @@ int FfmpegCamera::Capture( Image &image ) {
} else { } else {
Debug( 4, "Different stream_index %d", packet.stream_index ); Debug( 4, "Different stream_index %d", packet.stream_index );
} // end if packet.stream_index == mVideoStreamId } // end if packet.stream_index == mVideoStreamId
bytes += packet.size;
zm_av_packet_unref( &packet ); zm_av_packet_unref( &packet );
} // end while ! frameComplete } // end while ! frameComplete
return 1; return 1;
@ -708,6 +709,7 @@ int FfmpegCamera::CaptureAndRecord( Image &image, timeval recording, char* event
} }
int keyframe = packet.flags & AV_PKT_FLAG_KEY; int keyframe = packet.flags & AV_PKT_FLAG_KEY;
bytes += packet.size;
dumpPacket(&packet); dumpPacket(&packet);
//Video recording //Video recording

View File

@ -380,6 +380,7 @@ Monitor::Monitor(
ParseEncoderParameters(encoderparams.c_str(), &encoderparamsvec); ParseEncoderParameters(encoderparams.c_str(), &encoderparamsvec);
fps = 0.0; fps = 0.0;
last_camera_bytes = 0;
event_count = 0; event_count = 0;
image_count = 0; image_count = 0;
ready_count = warmup_count; ready_count = warmup_count;
@ -2457,15 +2458,21 @@ int Monitor::Capture() {
if ( now != last_fps_time ) { if ( now != last_fps_time ) {
// # of images per interval / the amount of time it took // # of images per interval / the amount of time it took
double new_fps = double(fps_report_interval)/(now-last_fps_time); double new_fps = double(fps_report_interval)/(now-last_fps_time);
unsigned int new_camera_bytes = camera->Bytes();
unsigned int new_capture_bandwidth = (new_camera_bytes - last_camera_bytes)/(now-last_fps_time);
last_camera_bytes = new_camera_bytes;
//Info( "%d -> %d -> %d", fps_report_interval, now, last_fps_time ); //Info( "%d -> %d -> %d", fps_report_interval, now, last_fps_time );
//Info( "%d -> %d -> %lf -> %lf", now-last_fps_time, fps_report_interval/(now-last_fps_time), double(fps_report_interval)/(now-last_fps_time), fps ); //Info( "%d -> %d -> %lf -> %lf", now-last_fps_time, fps_report_interval/(now-last_fps_time), double(fps_report_interval)/(now-last_fps_time), fps );
Info("%s: images:%d - Capturing at %.2lf fps", name, image_count, new_fps); Info("%s: images:%d - Capturing at %.2lf fps, capturing bandwidth %ubytes/sec", name, image_count, new_fps, new_capture_bandwidth);
last_fps_time = now; last_fps_time = now;
if ( new_fps != fps ) { if ( new_fps != fps ) {
fps = new_fps; fps = new_fps;
db_mutex.lock(); db_mutex.lock();
static char sql[ZM_SQL_SML_BUFSIZ]; static char sql[ZM_SQL_SML_BUFSIZ];
snprintf(sql, sizeof(sql), "INSERT INTO Monitor_Status (MonitorId,CaptureFPS) VALUES (%d, %.2lf) ON DUPLICATE KEY UPDATE CaptureFPS = %.2lf", id, fps, fps); snprintf(sql, sizeof(sql),
"INSERT INTO Monitor_Status (MonitorId,CaptureFPS,CaptureBandwidth) VALUES (%d, %.2lf,%u) ON DUPLICATE KEY UPDATE CaptureFPS = %.2lf, CaptureBandwidth=%u",
id, fps, new_capture_bandwidth, fps, new_capture_bandwidth);
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));
} }

View File

@ -288,6 +288,8 @@ protected:
bool embed_exif; // Whether to embed Exif data into each image frame or not bool embed_exif; // Whether to embed Exif data into each image frame or not
double fps; double fps;
unsigned int last_camera_bytes;
Image delta_image; Image delta_image;
Image ref_image; Image ref_image;
Image alarm_image; // Used in creating analysis images, will be initialized in Analysis Image alarm_image; // Used in creating analysis images, will be initialized in Analysis

View File

@ -24,6 +24,7 @@ private $defaults = array(
private $status_fields = array( private $status_fields = array(
'AnalysisFPS' => null, 'AnalysisFPS' => null,
'CaptureFPS' => null, 'CaptureFPS' => null,
'CaptureBandwidth' => null,
); );
private $control_fields = array( private $control_fields = array(
'Name' => '', 'Name' => '',

View File

@ -152,7 +152,7 @@ $html .= htmlSelect( 'Status[]', $status_options,
) ); ) );
$html .= '</span>'; $html .= '</span>';
$sql = 'SELECT *,S.Status AS Status, S.CaptureFPS AS CaptureFPS, S.AnalysisFPS AS AnalysisFPS $sql = 'SELECT *,S.Status AS Status, S.CaptureFPS AS CaptureFPS, S.AnalysisFPS AS AnalysisFPS, S.CaptureBandwidth AS CaptureBandwidth
FROM Monitors AS M LEFT JOIN Monitor_Status AS S ON MonitorId=Id ' . FROM Monitors AS M LEFT JOIN Monitor_Status AS S ON MonitorId=Id ' .
( count($conditions) ? ' WHERE ' . implode(' AND ', $conditions) : '' ).' ORDER BY Sequence ASC'; ( count($conditions) ? ' WHERE ' . implode(' AND ', $conditions) : '' ).' ORDER BY Sequence ASC';
$monitors = dbFetchAll($sql, null, $values); $monitors = dbFetchAll($sql, null, $values);

View File

@ -105,6 +105,7 @@ $show_storage_areas = count($storage_areas) > 1 and canEdit( 'System' ) ? 1 : 0;
$maxWidth = 0; $maxWidth = 0;
$maxHeight = 0; $maxHeight = 0;
$zoneCount = 0; $zoneCount = 0;
$total_capturing_bandwidth=0;
$status_counts = array(); $status_counts = array();
for ( $i = 0; $i < count($displayMonitors); $i++ ) { for ( $i = 0; $i < count($displayMonitors); $i++ ) {
@ -176,6 +177,23 @@ xhtmlHeaders( __FILE__, translate('Console') );
</div> </div>
<div class="container-fluid"> <div class="container-fluid">
<button type="button" name="addBtn" onclick="addMonitor(this);"
<?php echo (canEdit('Monitors') && !$user['MonitorIds']) ? '' : ' disabled="disabled"' ?>
>
<span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>&nbsp;<?php echo translate('AddNewMonitor') ?>
</button>
<button type="button" name="cloneBtn" onclick="cloneMonitor(this);"
<?php echo (canEdit('Monitors') && !$user['MonitorIds']) ? '' : ' disabled="disabled"' ?>
style="display:none;">
<span class="glyphicon glyphicon-copy"></span>&nbsp;<?php echo translate('CloneMonitor') ?>
</button>
<button type="button" name="editBtn" onclick="editMonitor(this);" disabled="disabled">
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>&nbsp;<?php echo translate('Edit') ?>
</button>
<button type="button" name="deleteBtn" onclick="deleteMonitor(this);" disabled="disabled">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>&nbsp;<?php echo translate('Delete') ?>
</button>
<button type="button" name="selectBtn" onclick="selectMonitor(this);" disabled="disabled"><?php echo translate('Select')?></button>
<?php <?php
ob_start(); ob_start();
?> ?>
@ -275,6 +293,8 @@ if ( $fclass != 'infoText' ) $dot_class=$fclass;
$fps_string .= '/' . $monitor['AnalysisFPS']; $fps_string .= '/' . $monitor['AnalysisFPS'];
} }
if ($fps_string) $fps_string .= ' fps'; if ($fps_string) $fps_string .= ' fps';
$fps_string .= ' ' . human_filesize($monitor['CaptureBandwidth']).'/s';
$total_capturing_bandwidth += $monitor['CaptureBandwidth'];
echo $fps_string; echo $fps_string;
?> ?>
</div></td> </div></td>
@ -339,27 +359,19 @@ if ( $fclass != 'infoText' ) $dot_class=$fclass;
</tbody> </tbody>
<tfoot> <tfoot>
<tr> <tr>
<?php if ( ZM_WEB_ID_ON_CONSOLE ) { ?>
<td class="colId"><?php echo translate('Total').":".count($displayMonitors) ?></td> <td class="colId"><?php echo translate('Total').":".count($displayMonitors) ?></td>
<td class="colLeftButtons" colspan="<?php echo $left_columns -1?>"> <?php } ?>
<button type="button" name="addBtn" onclick="addMonitor(this);" <td class="colName"></td>
<?php echo (canEdit('Monitors') && !$user['MonitorIds']) ? '' : ' disabled="disabled"' ?> <td class="colFunction"><?php echo human_filesize($total_capturing_bandwidth ).'/s' ?></td>
> <?php if ( count($servers) ) { ?>
<span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>&nbsp;<?php echo translate('AddNewMonitor') ?> <td class="colServer"></td>
</button> <?php } ?>
<button type="button" name="cloneBtn" onclick="cloneMonitor(this);" <td class="colSource"></td>
<?php echo (canEdit('Monitors') && !$user['MonitorIds']) ? '' : ' disabled="disabled"' ?> <?php if ( $show_storage_areas ) { ?>
style="display:none;"> <td class="colStorage"></td>
<span class="glyphicon glyphicon-copy"></span>&nbsp;<?php echo translate('CloneMonitor') ?>
</button>
<button type="button" name="editBtn" onclick="editMonitor(this);" disabled="disabled">
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>&nbsp;<?php echo translate('Edit') ?>
</button>
<button type="button" name="deleteBtn" onclick="deleteMonitor(this);" disabled="disabled">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>&nbsp;<?php echo translate('Delete') ?>
</button>
<button type="button" name="selectBtn" onclick="selectMonitor(this);" disabled="disabled"><?php echo translate('Select')?></button>
</td>
<?php <?php
}
foreach ( array_keys( $eventCounts ) as $i ) { foreach ( array_keys( $eventCounts ) as $i ) {
parseFilter( $eventCounts[$i]['filter'] ); parseFilter( $eventCounts[$i]['filter'] );
?> ?>