Minor corrections based on feedback to date

pull/961/head
Linwood-F 2015-07-23 15:01:53 -04:00
parent 84ed491765
commit b88403cd41
7 changed files with 149 additions and 47 deletions

View File

@ -67,6 +67,14 @@ Event::Event( Monitor *p_monitor, struct timeval p_start_time, const std::string
if ( !initialised )
Initialise();
// >>> Real time image extrat settings <<< these need to go in conf options
UpldCount=0;
strcpy(UpldPath,"/home/ferguson/ToUpload");
UpldWriteEvery=600;
UpldWriteEveryAlarm=2;
std::string notes;
createNotes( notes );
@ -349,28 +357,42 @@ bool Event::SendFrameImage( const Image *image, bool alarm_frame )
bool Event::WriteFrameImage( Image *image, struct timeval timestamp, const char *event_file, bool alarm_frame )
{
if ( config.timestamp_on_capture )
bool toUpld=false;
char UpldFile[PATH_MAX];
char UpldFileRename[PATH_MAX];
if( ( UpldCount++ % (alarm_frame ? UpldWriteEveryAlarm : UpldWriteEvery) ) == 0) // notice this grabs frame #1 so it gets the first of every event (zero count = frame 1)
{
if ( !config.opt_frame_server || !SendFrameImage( image, alarm_frame) )
{
if ( alarm_frame && (config.jpeg_alarm_file_quality > config.jpeg_file_quality) )
image->WriteJpeg( event_file, config.jpeg_alarm_file_quality );
else
image->WriteJpeg( event_file );
}
toUpld=true;
char tmbuf[64], buf[64];
strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d-%H-%M-%S", localtime(&(timestamp.tv_sec)));
snprintf(buf, sizeof buf, "%s-%06d", tmbuf,(int)(timestamp.tv_usec));
snprintf(UpldFile, sizeof(UpldFile),"%s/%s-%06d_%s_%s.jpg_saving",UpldPath, tmbuf,(int)(timestamp.tv_usec),this->monitor->Name(),alarm_frame?"Alarm":"Periodic");
snprintf(UpldFileRename, sizeof(UpldFile),"%s/%s-%06d_%s_%s.jpg", UpldPath, tmbuf,(int)(timestamp.tv_usec),this->monitor->Name(),alarm_frame?"Alarm":"Periodic");
}
Image* ImgToWrite;
Image ts_image( *image );
if ( config.timestamp_on_capture ) // stash the image we plan to use in another pointer regardless if timestamped.
{
monitor->TimestampImage( &ts_image, &timestamp );
ImgToWrite=&ts_image;
}
else
ImgToWrite=image;
if ( !config.opt_frame_server || !SendFrameImage( ImgToWrite, alarm_frame) )
{
Image ts_image( *image );
monitor->TimestampImage( &ts_image, &timestamp );
if ( !config.opt_frame_server || !SendFrameImage( &ts_image, alarm_frame) )
{
if ( alarm_frame && (config.jpeg_alarm_file_quality > config.jpeg_file_quality) )
ts_image.WriteJpeg( event_file, config.jpeg_alarm_file_quality );
else
ts_image.WriteJpeg( event_file );
int thisquality = ( alarm_frame && (config.jpeg_alarm_file_quality > config.jpeg_file_quality) ) ? config.jpeg_alarm_file_quality : 0 ; // quality to use
ImgToWrite->WriteJpeg( event_file, thisquality, timestamp );
if(toUpld)
{ // Because these are for real-time use and may be grabbed as they are being written, write under one name then rename
ImgToWrite->WriteJpeg(UpldFile, thisquality, timestamp);
if(rename(UpldFile, UpldFileRename)!=0)
Error ("Failure to rename real time capture file %s to %s, ignored",UpldFile, UpldFileRename);
}
}
return( true );
}
@ -885,7 +907,7 @@ void EventStream::processCommand( const CmdMsg *msg )
}
// If we are in single event mode and at the last frame, replay the current event
if ( (mode == MODE_SINGLE) && (curr_frame_id == event_data->frame_count) )
if ( (mode == MODE_SINGLE) && ((unsigned int)curr_frame_id == event_data->frame_count) )
curr_frame_id = 1;
replay_rate = ZM_RATE_BASE;

View File

@ -59,6 +59,12 @@ protected:
protected:
static int sd;
private:
int UpldCount;
char UpldPath[PATH_MAX];
int UpldWriteEvery;
int UpldWriteEveryAlarm;
public:
typedef std::set<std::string> StringSet;
typedef std::map<std::string,StringSet> StringSetMap;

View File

@ -787,7 +787,22 @@ bool Image::ReadJpeg( const char *filename, unsigned int p_colours, unsigned int
return( true );
}
bool Image::WriteJpeg( const char *filename, int quality_override ) const
// Multiple calling formats to permit inclusion (or not) of both quality_override and timestamp (exif), with suitable defaults.
bool Image::WriteJpeg( const char *filename, int quality_override) const
{
return Image::WriteJpeg(filename, quality_override, (timeval){0,0});
}
bool Image::WriteJpeg( const char *filename) const
{
return Image::WriteJpeg(filename, 0, (timeval){0,0});
}
bool Image::WriteJpeg( const char *filename, struct timeval timestamp ) const
{
return Image::WriteJpeg(filename,0,timestamp);
}
bool Image::WriteJpeg( const char *filename, int quality_override, struct timeval timestamp ) const
{
if ( config.colour_jpeg_files && colours == ZM_COLOUR_GRAY8 )
{
@ -795,7 +810,6 @@ bool Image::WriteJpeg( const char *filename, int quality_override ) const
temp_image.Colourise( ZM_COLOUR_RGB24, ZM_SUBPIX_ORDER_RGB );
return( temp_image.WriteJpeg( filename, quality_override ) );
}
int quality = quality_override?quality_override:config.jpeg_file_quality;
struct jpeg_compress_struct *cinfo = jpg_ccinfo[quality];
@ -887,6 +901,30 @@ bool Image::WriteJpeg( const char *filename, int quality_override ) const
jpeg_write_marker( cinfo, JPEG_COM, (const JOCTET *)text, strlen(text) );
}
if(timestamp.tv_sec)
{
#define EXIFTIMES_MS_OFFSET 0x36 // three decimal digits for milliseconds
#define EXIFTIMES_MS_LEN 0x03
#define EXIFTIMES_OFFSET 0x3E // 19 characters format '2015:07:21 13:14:45' not including quotes
#define EXIFTIMES_LEN 0x13 // = 19
#define EXIF_CODE 0xE1
char timebuf[64], msbuf[64];
strftime(timebuf, sizeof timebuf, "%Y:%m:%d %H:%M:%S", localtime(&(timestamp.tv_sec)));
snprintf(msbuf, sizeof msbuf, "%06d",(int)(timestamp.tv_usec)); // we only use milliseconds because that's all defined in exif, but this is the whole microseconds because we have it
unsigned char exiftimes[82] = {
0x45, 0x78, 0x69, 0x66, 0x00, 0x00, 0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00,
0x69, 0x87, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x03, 0x90, 0x02, 0x00, 0x14, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x91, 0x92,
0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0x00 };
memcpy(&exiftimes[EXIFTIMES_OFFSET], timebuf,EXIFTIMES_LEN);
memcpy(&exiftimes[EXIFTIMES_MS_OFFSET],msbuf ,EXIFTIMES_MS_LEN); // first character after the decimal point
jpeg_write_marker (cinfo, EXIF_CODE, (const JOCTET *)exiftimes, sizeof(exiftimes) );
}
JSAMPROW row_pointer; /* pointer to a single row */
int row_stride = cinfo->image_width * colours; /* physical row width in buffer */
while ( cinfo->next_scanline < cinfo->image_height )

View File

@ -204,7 +204,12 @@ public:
bool WriteRaw( const char *filename ) const;
bool ReadJpeg( const char *filename, unsigned int p_colours, unsigned int p_subpixelorder);
bool WriteJpeg( const char *filename, int quality_override=0 ) const;
bool WriteJpeg ( const char *filename) const;
bool WriteJpeg ( const char *filename, int quality_override ) const;
bool WriteJpeg ( const char *filename, struct timeval timestamp ) const;
bool WriteJpeg ( const char *filename, int quality_override, struct timeval timestamp ) const;
bool DecodeJpeg( const JOCTET *inbuffer, int inbuffer_size, unsigned int p_colours, unsigned int p_subpixelorder);
bool EncodeJpeg( JOCTET *outbuffer, int *outbuffer_size, int quality_override=0 ) const;

View File

@ -222,12 +222,12 @@
/**
* A random string used in security hashing methods.
*/
Configure::write('Security.salt', 'Q0MjGG2xRQEhJVQR85WhFJKI7f2St8RYMlVR7GNQ');
Configure::write('Security.salt', 'olX2TOlboOnC474y3Tk4W4JOyuirw1EaadeHCcr4');
/**
* A random numeric string (digits only) used to encrypt/decrypt strings.
*/
Configure::write('Security.cipherSeed', '02670120062639232092038865362');
Configure::write('Security.cipherSeed', '84684583012508019120061282965');
/**
* Apply timestamps with the last modified time to static assets (js, css, images).

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

View File

@ -28,14 +28,34 @@
// This is very much a preliminary version, very lightly tested, mostly on Firefox, but should work on IE and Chrome (at least)
// It takes very high bandwidth to the server, and a pretty fast client to keep up with the image rate. To reduce the rate
// change the playback slider to 0 and then it does not try to play at the same time it is scrubbing.
//
// Jul 23 2015 update:
// - Correct problem propagating selected playback speed
// - Change from blank monitor to specific message about no data in times with no recording
// - Enlarge and better center fonts on labels for lines.
// - Add support for monitor groups in selecting criteria from console
// - Fix some no-update conditions when playback was off but scale changed or refreshed.
// - Added translate call around buttons so as to facilitate possible translations later
// - Removed range from/to labels on very small graphs to keep from overlapping slider
// - Changed initial (from other page) position of slider to be in the middle to be more obvious
//
if ( !canView( 'Events' ) )
{
$view = "error";
return;
}
$monitorsSql = "select * from Monitors ";
if ( !empty($_REQUEST['group']) )
{
$group = $_REQUEST['group'];
$row = dbFetchOne( 'select * from Groups where Id = ?', NULL, array($_REQUEST['group']) );
$monitorsSql = "select * from Monitors where Function != 'None' and find_in_set( Id, '".$row['MonitorIds']."' ) ";
}
else
{
$monitorsSql = "select * from Monitors ";
$group = "";
}
// Note that this finds incomplete events as well, and any frame records written, but still cannot "see" to the end frame
// if the bulk record has not been written - to get more current reduce bulk frame sizes
@ -123,23 +143,23 @@ input[type=range]::-ms-tooltip {
</div>
<div style='display: inline-flex; border: 1px solid black;'>
<label style='margin:5px;' for=scaleslider>Scale</label>
<label style='margin:5px;' for=scaleslider><?php echo translate('Scale') ?></label>
<input id=scaleslider type=range min=0.10 max=1.00 value=<?php echo $defaultScale ?> step=0.10 width=20% onchange='changescale(this.value)'/>
<output style='margin:5px;' id=scaleslideroutput from=scaleslider><?php echo $defaultScale?>x</output>
</div>
<div style='display: inline-flex; border: 1px solid black;'>
<label style='margin:5px;' for=speedslider>Speed</label>
<label style='margin:5px;' for=speedslider><?php echo translate('Speed') ?></label>
<input id=speedslider type=range min=0 max=50 value=<?php echo $defaultSpeed ?> step=1 wdth=20% onchange='changespeed(this.value)'/>
<output style='margin:5px;' id=speedslideroutput from=speedslider><?php echo $defaultSpeed ?>x</output>
</div>
<div style='display: inline-flex; border: 1px solid black; flex-flow: row wrap;'>
<button type='button' id=panleft onclick='panleft() '>&lt;&nbsp;Pan&nbsp;Left</button>
<button type='button' id=zoomin onclick='zoomin() '>Zoom&nbsp;In&nbsp;+</button>
<button type='button' id=zoomout onclick='zoomout() '>Zoom&nbsp;Out&nbsp;-</button>
<button type='button' id=lasthour onclick='lasthour()'>LastHour</button>
<button type='button' id=allof onclick='allof() '>All</button>
<button type='button' id=allnon onclick='allnon() '>All&nbsp;Non-Archive</button>
<button type='button' id=panright onclick='panright()'>Pan&nbsp;Right&nbsp;&gt;</button>
<button type='button' id=panleft onclick='panleft() '>&lt;&nbsp;<?php echo translate('Pan&nbsp;Left') ?></button>
<button type='button' id=zoomin onclick='zoomin() '><?php echo translate('Zoom&nbsp;In&nbsp;+') ?></button>
<button type='button' id=zoomout onclick='zoomout() '><?php echo translate('Zoom&nbsp;Out&nbsp;-') ?></button>
<button type='button' id=lasthour onclick='lasthour()'><?php echo translate('Last Hour') ?></button>
<button type='button' id=allof onclick='allof() '><?php echo translate('All') ?></button>
<button type='button' id=allnon onclick='allnon() '><?php echo translate('All&nbsp;Non-Archive') ?></button>
<button type='button' id=panright onclick='panright()'><?php echo translate('Pan&nbsp;Right&nbsp;&gt;') ?></button>
</div>
<div id=timelinediv style='position:relative; width:93%;'>
@ -166,6 +186,7 @@ foreach( dbFetchAll( $monitorsSql ) as $row )
// This builds the list of events that are eligible from this range
echo "<script>\n";
echo "var timeLabelsFractOfRow = 0.9;\n";
echo "var eventMonitorId = [];\n";
echo "var eventId = [];\n";
echo "var eventStartTimeSecs = [];\n";
@ -302,7 +323,7 @@ echo "var rangeTimeSecs=" . ( $maxTimeSecs - $minTimeSecs + 1) . ";\n";
if(isset($defaultCurrentTime))
echo "var currentTimeSecs=" . strtotime($defaultCurrentTime) . ";\n";
else
echo "var currentTimeSecs=" . $minTimeSecs . ";\n";
echo "var currentTimeSecs=" . ($minTimeSecs + $maxTimeSecs)/2 . ";\n";
?>
@ -340,19 +361,24 @@ function SetImageSource(monId,val)
return img;
}
}
return "graphics/transparent.gif";
return "graphics/NoDataImage.gif";
}
function imagedone(monId,success)
{
monitorCanvasCtx[monId].clearRect(0,0,monitorCanvasObj[monId].width,monitorCanvasObj[monId].height); // just in case image is no good
if(success)
monitorCanvasCtx[monId].drawImage(monitorImageObject[monId],0,0,monitorCanvasObj[monId].width,monitorCanvasObj[monId].height); // we ignore errors and just clear the image and keep going
monitorCanvasCtx[monId].drawImage(monitorImageObject[monId],0,0,monitorCanvasObj[monId].width,monitorCanvasObj[monId].height);
monitorImageObject[monId]=null;
monitorLoading[monId]=false;
if(monitorLoadingStageURL[monId]=="") return;
loadImage2Monitor(monId,monitorLoadingStageURL[monId]);
monitorLoadingStageURL[monId]="";
if(!success) // if we had a failrue queue up the no-data image
loadImage2Monitor(monId,"graphics/NoDataImage.gif"); // leave the staged URL if there is one, just ignore it here.
else
{
if(monitorLoadingStageURL[monId]=="") return;
loadImage2Monitor(monId,monitorLoadingStageURL[monId]);
monitorLoadingStageURL[monId]="";
}
return;
}
@ -382,6 +408,7 @@ function changescale(newscale)
}
}
document.getElementById('scaleslideroutput').value = newscale.toString() + " x";
outputUpdate(currentTimeSecs);
return;
}
var playSecsperSec = 1;
@ -421,7 +448,7 @@ function drawSliderOnGraph(val)
// Set some sizes
labelpx = Math.max( 6, Math.min( 20, parseInt(cHeight * 0.6 / (numMonitors+1)) ) );
labelpx = Math.max( 6, Math.min( 20, parseInt(cHeight * timeLabelsFractOfRow / (numMonitors+1)) ) );
labbottom=parseInt(cHeight * 0.2 / (numMonitors+1)).toString() + "px"; // This is positioning same as row labels below, but from bottom so 1-position
labfont=labelpx + "px Georgia"; // set this like below row labels
@ -470,11 +497,11 @@ function drawSliderOnGraph(val)
o.style.position="absolute";
o.style.bottom=labbottom;
o.style.font=labfont;
o.style.left="3px";
o.style.left="5px";
if(numMonitors==0) // we need a len calculation if we skipped the slider
len = o.offsetWidth;
// If the slider will overlay part of this suppress (this is the left side)
if(len + 5 > sliderX)
if(len + 10 > sliderX || cWidth < len * 5 ) // that last check is for very narrow browsers
o.style.display="none";
else
o.style.display="inline";
@ -485,8 +512,8 @@ function drawSliderOnGraph(val)
o.style.bottom=labbottom;
o.style.font=labfont;
// If the slider will overlay part of this suppress (this is the right side)
o.style.left=(cWidth - len - 5).toString() + "px";
if(sliderX > cWidth - len - 10)
o.style.left=(cWidth - len - 15).toString() + "px";
if(sliderX > cWidth - len - 20 || cWidth < len * 5 )
o.style.display="none";
else
o.style.display="inline";
@ -534,13 +561,14 @@ function drawGraph()
{
if(monitorName[i]>"")
{
ctx.font= parseInt(rowHeight * 0.6).toString() + "px Georgia";
ctx.font= parseInt(rowHeight * timeLabelsFractOfRow).toString() + "px Georgia";
ctx.fillStyle="Black";
ctx.globalAlpha=1;
ctx.fillText(monitorName[i], 0, (monitorIndex[i] + 0.8) * rowHeight);
ctx.fillText(monitorName[i], 0, (monitorIndex[i] + 1 - (1 - timeLabelsFractOfRow)/2 ) * rowHeight ); // This should roughly center font in row
}
}
underSlider=undefined; // flag we don't have a slider cached
drawSliderOnGraph(currentTimeSecs);
return;
}
@ -613,7 +641,8 @@ function clicknav(minSecs,maxSecs,arch) // we use the current time if we can
if(currentTimeSecs > minSecs && currentTimeSecs < maxSecs) // make sure time is in the new range
currentStr="&current=" + secs2dbstr(currentTimeSecs);
}
var uri = "?view=" + currentView + minStr + maxStr + currentStr + "&scale=" + document.getElementById("scaleslider").value + "&speed=" + document.getElementById("speedslider").value + "&archive=" + arch;
var groupStr=<?php if($group=="") echo '""'; else echo "\"&group=$group\""; fi; ?>;
var uri = "?view=" + currentView + groupStr + minStr + maxStr + currentStr + "&scale=" + document.getElementById("scaleslider").value + "&speed=" + document.getElementById("speedslider").value + "&archive=" + arch;
window.location=uri;
}
@ -677,6 +706,8 @@ function showOneEvent(monId) // link out to the normal view of one event's data
// Do this on load implicitly
drawGraph();
changespeed(<?php echo $defaultSpeed ?>); // This makes sure we start at the requested rate
outputUpdate(currentTimeSecs);
window.addEventListener("resize",drawGraph);
</script>