implement capturing bandwidth
This commit is contained in:
parent
e4465c0a61
commit
20f6985dff
|
@ -528,6 +528,7 @@ CREATE TABLE `Monitor_Status` (
|
|||
`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,
|
||||
`CaptureBandwidth` INT NOT NULL default 0,
|
||||
PRIMARY KEY (`MonitorId`)
|
||||
) ENGINE=MEMORY;
|
||||
--
|
||||
|
|
|
@ -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;
|
|
@ -53,6 +53,8 @@ protected:
|
|||
int contrast;
|
||||
bool capture;
|
||||
bool record_audio;
|
||||
unsigned int bytes;
|
||||
|
||||
|
||||
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 );
|
||||
|
@ -74,6 +76,7 @@ public:
|
|||
unsigned int SubpixelOrder() const { return( subpixelorder ); }
|
||||
unsigned int Pixels() const { return( pixels ); }
|
||||
unsigned int ImageSize() const { return( imagesize ); }
|
||||
unsigned int Bytes() const { return bytes; };
|
||||
|
||||
virtual int Brightness( int/*p_brightness*/=-1 ) { return( -1 ); }
|
||||
virtual int Hue( int/*p_hue*/=-1 ) { return( -1 ); }
|
||||
|
|
|
@ -292,6 +292,7 @@ int FfmpegCamera::Capture( Image &image ) {
|
|||
} else {
|
||||
Debug( 4, "Different stream_index %d", packet.stream_index );
|
||||
} // end if packet.stream_index == mVideoStreamId
|
||||
bytes += packet.size;
|
||||
zm_av_packet_unref( &packet );
|
||||
} // end while ! frameComplete
|
||||
return 1;
|
||||
|
@ -708,6 +709,7 @@ int FfmpegCamera::CaptureAndRecord( Image &image, timeval recording, char* event
|
|||
}
|
||||
|
||||
int keyframe = packet.flags & AV_PKT_FLAG_KEY;
|
||||
bytes += packet.size;
|
||||
dumpPacket(&packet);
|
||||
|
||||
//Video recording
|
||||
|
|
|
@ -380,6 +380,7 @@ Monitor::Monitor(
|
|||
ParseEncoderParameters(encoderparams.c_str(), &encoderparamsvec);
|
||||
|
||||
fps = 0.0;
|
||||
last_camera_bytes = 0;
|
||||
event_count = 0;
|
||||
image_count = 0;
|
||||
ready_count = warmup_count;
|
||||
|
@ -2457,15 +2458,21 @@ int Monitor::Capture() {
|
|||
if ( now != last_fps_time ) {
|
||||
// # of images per interval / the amount of time it took
|
||||
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 -> %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;
|
||||
if ( new_fps != fps ) {
|
||||
fps = new_fps;
|
||||
|
||||
db_mutex.lock();
|
||||
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) ) {
|
||||
Error("Can't run query: %s", mysql_error(&dbconn));
|
||||
}
|
||||
|
|
|
@ -288,6 +288,8 @@ protected:
|
|||
bool embed_exif; // Whether to embed Exif data into each image frame or not
|
||||
|
||||
double fps;
|
||||
unsigned int last_camera_bytes;
|
||||
|
||||
Image delta_image;
|
||||
Image ref_image;
|
||||
Image alarm_image; // Used in creating analysis images, will be initialized in Analysis
|
||||
|
|
|
@ -24,6 +24,7 @@ private $defaults = array(
|
|||
private $status_fields = array(
|
||||
'AnalysisFPS' => null,
|
||||
'CaptureFPS' => null,
|
||||
'CaptureBandwidth' => null,
|
||||
);
|
||||
private $control_fields = array(
|
||||
'Name' => '',
|
||||
|
|
|
@ -152,7 +152,7 @@ $html .= htmlSelect( 'Status[]', $status_options,
|
|||
) );
|
||||
$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 ' .
|
||||
( count($conditions) ? ' WHERE ' . implode(' AND ', $conditions) : '' ).' ORDER BY Sequence ASC';
|
||||
$monitors = dbFetchAll($sql, null, $values);
|
||||
|
|
|
@ -275,6 +275,7 @@ if ( $fclass != 'infoText' ) $dot_class=$fclass;
|
|||
$fps_string .= '/' . $monitor['AnalysisFPS'];
|
||||
}
|
||||
if ($fps_string) $fps_string .= ' fps';
|
||||
$fps_string .= ' ' . human_filesize($monitor['CaptureBandwidth']).'/s';
|
||||
echo $fps_string;
|
||||
?>
|
||||
</div></td>
|
||||
|
|
Loading…
Reference in New Issue