From 1e50df741fbf64c5ba6e5a96511707a19f00ac14 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 28 Nov 2017 09:50:09 -0500 Subject: [PATCH 1/4] fix some memleaks --- src/zm_ffmpeg_camera.cpp | 12 ++++++++---- src/zm_monitor.cpp | 7 ++++++- src/zm_stream.cpp | 2 +- src/zm_videostore.cpp | 33 ++++++++++++++++++++++++++++----- src/zm_videostore.h | 3 +-- web/js/logger.js | 5 ++++- 6 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 7a7a5f157..4a5dbee0f 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -381,8 +381,8 @@ int FfmpegCamera::OpenFfmpeg() { return -1; } - AVDictionaryEntry *e; - if ( (e = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX)) != NULL ) { + AVDictionaryEntry *e=NULL; + while ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL ) { Warning( "Option %s not recognized by ffmpeg", e->key); } @@ -666,12 +666,16 @@ int FfmpegCamera::CloseFfmpeg() { if ( mVideoCodecContext ) { avcodec_close(mVideoCodecContext); - //av_free(mVideoCodecContext); +#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) + av_free(mVideoCodecContext); +#endif mVideoCodecContext = NULL; // Freed by av_close_input_file } if ( mAudioCodecContext ) { avcodec_close(mAudioCodecContext); - //av_free(mAudioCodecContext); +#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) + av_free(mAudioCodecContext); +#endif mAudioCodecContext = NULL; // Freed by av_close_input_file } diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 977f2da49..4f69012f3 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -73,7 +73,12 @@ std::vector split(const std::string &s, char delim) { return elems; } -Monitor::MonitorLink::MonitorLink( int p_id, const char *p_name ) : id( p_id ) { +Monitor::MonitorLink::MonitorLink( int p_id, const char *p_name ) : + id( p_id ), + shared_data(NULL), + trigger_data(NULL), + video_store_data(NULL) +{ strncpy( name, p_name, sizeof(name) ); #if ZM_MEM_MAPPED diff --git a/src/zm_stream.cpp b/src/zm_stream.cpp index 8c488194b..8cc444b6d 100644 --- a/src/zm_stream.cpp +++ b/src/zm_stream.cpp @@ -69,8 +69,8 @@ void StreamBase::updateFrameRate( double fps ) { while( effective_fps > maxfps ) { effective_fps /= 2.0; frame_mod *= 2; - } Debug( 3, "aEFPS:%.2f, aFM:%d", effective_fps, frame_mod ); + } } bool StreamBase::checkCommandQueue() { diff --git a/src/zm_videostore.cpp b/src/zm_videostore.cpp index 5285a0526..20b895c81 100644 --- a/src/zm_videostore.cpp +++ b/src/zm_videostore.cpp @@ -195,6 +195,7 @@ VideoStore::VideoStore(const char *filename_in, const char *format_in, converted_in_samples = NULL; audio_out_codec = NULL; + audio_in_codec = NULL; audio_in_ctx = NULL; audio_out_stream = NULL; in_frame = NULL; @@ -411,12 +412,34 @@ VideoStore::~VideoStore() { // Just do a file open/close/writeheader/etc. // What if we were only doing audio recording? if (video_out_stream) { +#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) + // We allocate and copy in newer ffmpeg, so need to free it + av_free(video_in_ctx); +#endif + video_in_ctx=NULL; + avcodec_close(video_out_ctx); +#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) + av_free(video_out_ctx); +#endif video_out_ctx = NULL; Debug(4, "Success freeing video_out_ctx"); } - if (audio_out_stream) { + if ( audio_out_stream ) { + if ( audio_in_codec ) { + avcodec_close(audio_in_ctx); +#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) + // We allocate and copy in newer ffmpeg, so need to free it + av_free(audio_in_ctx); +#endif + audio_in_ctx = NULL; + audio_in_codec = NULL; + } // end if audio_in_codec + avcodec_close(audio_out_ctx); +#if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) + av_free(audio_out_ctx); +#endif audio_out_ctx = NULL; #ifdef HAVE_LIBAVRESAMPLE if (resample_ctx) { @@ -459,10 +482,10 @@ bool VideoStore::setup_resampler() { #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) // Newer ffmpeg wants to keep everything separate... so have to lookup our own // decoder, can't reuse the one from the camera. - AVCodec *audio_in_codec = + audio_in_codec = avcodec_find_decoder(audio_in_stream->codecpar->codec_id); #else - AVCodec *audio_in_codec = + audio_in_codec = avcodec_find_decoder(audio_in_ctx->codec_id); #endif ret = avcodec_open2(audio_in_ctx, audio_in_codec, NULL); @@ -783,7 +806,6 @@ int VideoStore::writeVideoFramePacket(AVPacket *ipkt) { } opkt.flags = ipkt->flags; - int keyframe = opkt.flags & AV_PKT_FLAG_KEY; opkt.pos = -1; opkt.data = ipkt->data; @@ -797,7 +819,7 @@ int VideoStore::writeVideoFramePacket(AVPacket *ipkt) { Debug(1, "writing video packet keyframe(%d) pts(%d) dts(%d) duration(%d) " "ipkt.duration(%d)", - keyframe, opkt.pts, opkt.dts, duration, ipkt->duration); + opkt.flags & AV_PKT_FLAG_KEY, opkt.pts, opkt.dts, duration, ipkt->duration); if ((opkt.data == NULL) || (opkt.size < 1)) { Warning("%s:%d: Mangled AVPacket: discarding frame", __FILE__, __LINE__); dumpPacket(ipkt); @@ -870,6 +892,7 @@ int VideoStore::writeAudioFramePacket(AVPacket *ipkt) { * If we are at the end of the file, pass an empty packet to the decoder * to flush it. */ + int data_present; if ((ret = avcodec_decode_audio4(audio_in_ctx, in_frame, &data_present, ipkt)) < 0) { Error("Could not decode frame (error '%s')\n", diff --git a/src/zm_videostore.h b/src/zm_videostore.h index 0751114f8..8e439c313 100644 --- a/src/zm_videostore.h +++ b/src/zm_videostore.h @@ -16,7 +16,6 @@ extern "C" { class VideoStore { private: - unsigned int packets_written; AVOutputFormat *out_format; AVFormatContext *oc; @@ -34,13 +33,13 @@ private: AVFrame *out_frame; AVCodecContext *video_in_ctx; + AVCodec *audio_in_codec; AVCodecContext *audio_in_ctx; int ret; // The following are used when encoding the audio stream to AAC AVCodec *audio_out_codec; AVCodecContext *audio_out_ctx; - int data_present; AVAudioFifo *fifo; int out_frame_size; #ifdef HAVE_LIBAVRESAMPLE diff --git a/web/js/logger.js b/web/js/logger.js index 9cbe50268..6bd465c8a 100644 --- a/web/js/logger.js +++ b/web/js/logger.js @@ -50,7 +50,10 @@ function logReport( level, message, file, line ) if ( !debugReq ) { - debugParms = "view=request&request=log&task=create&browser[name]="+Browser.name+"&browser[version]="+Browser.version+"&browser[platform]="+Browser.Platform.name; + if ( Browser ) + debugParms = "view=request&request=log&task=create&browser[name]="+Browser.name+"&browser[version]="+Browser.version+"&browser[platform]="+(Browser.Platform?Browser.Platform.name:'unknown'); + else + debugParms = "view=request&request=log&task=create&browser[name]=unknown&browser[version]=unknown&browser[platform]=unknown"; debugReq = new Request.JSON( { url: thisUrl, method: 'post', timeout: AJAX_TIMEOUT, link: 'chain' } ); } var requestParms = debugParms; From d73f9e8a738529fdfc73066f71f8620674af7f75 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 28 Nov 2017 11:11:41 -0500 Subject: [PATCH 2/4] wip, crashes --- src/zm_ffmpeg.cpp | 2 +- src/zm_ffmpeg_camera.cpp | 33 +++++++++++++++++++++++---------- src/zm_monitor.cpp | 9 ++++++--- src/zm_videostore.cpp | 8 ++++---- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/zm_ffmpeg.cpp b/src/zm_ffmpeg.cpp index 1d7e25ec3..c73da27e8 100644 --- a/src/zm_ffmpeg.cpp +++ b/src/zm_ffmpeg.cpp @@ -190,7 +190,7 @@ int hacked_up_context2_for_older_ffmpeg(AVFormatContext **avctx, AVOutputFormat return ret; } else { s->oformat = oformat; -#if 0 +#if 1 // This is some very wrong code, and I don't think it is neccessary if (s->oformat->priv_data_size > 0) { s->priv_data = av_mallocz(s->oformat->priv_data_size); diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 4a5dbee0f..c368feefc 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -328,6 +328,9 @@ int FfmpegCamera::PostCapture() { int FfmpegCamera::OpenFfmpeg() { Debug ( 2, "OpenFfmpeg called." ); + uint32_t last_event_id = monitor->GetLastEventId() ; + uint32_t video_writer_event_id = monitor->GetVideoWriterEventId(); + Debug(2, "last_event(%d), our current (%d)", last_event_id, video_writer_event_id ); int ret; @@ -372,6 +375,9 @@ int FfmpegCamera::OpenFfmpeg() { //FIXME can speed up initial analysis but need sensible parameters... //mFormatContext->probesize = 32; //mFormatContext->max_analyze_duration = 32; + last_event_id = monitor->GetLastEventId() ; + video_writer_event_id = monitor->GetVideoWriterEventId(); + Debug(2, "last_event(%d), our current (%d), mpath (%s)", last_event_id, video_writer_event_id, mPath.c_str() ); if ( avformat_open_input( &mFormatContext, mPath.c_str(), NULL, &opts ) != 0 ) #endif @@ -380,12 +386,18 @@ int FfmpegCamera::OpenFfmpeg() { Error( "Unable to open input %s due to: %s", mPath.c_str(), strerror(errno) ); return -1; } - + last_event_id = monitor->GetLastEventId() ; + video_writer_event_id = monitor->GetVideoWriterEventId(); + Debug(2, "last_event(%d), our current (%d)", last_event_id, video_writer_event_id ); AVDictionaryEntry *e=NULL; while ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL ) { Warning( "Option %s not recognized by ffmpeg", e->key); } + last_event_id = monitor->GetLastEventId() ; + video_writer_event_id = monitor->GetVideoWriterEventId(); + Debug(2, "last_event(%d), our current (%d)", last_event_id, video_writer_event_id ); + mIsOpening = false; Debug ( 1, "Opened input" ); @@ -524,15 +536,15 @@ int FfmpegCamera::OpenFfmpeg() { Debug ( 1, "Calling avcodec_open2" ); if ( avcodec_open2(mVideoCodecContext, mVideoCodec, &opts) < 0 ) { #endif - AVDictionaryEntry *e; - if ( (e = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX)) != NULL ) { + AVDictionaryEntry *e = NULL; + while ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL ) { Warning( "Option %s not recognized by ffmpeg", e->key); } Fatal( "Unable to open codec for video stream from %s", mPath.c_str() ); } else { - AVDictionaryEntry *e; - if ( (e = av_dict_get(opts, "", NULL, AV_DICT_IGNORE_SUFFIX)) != NULL ) { + AVDictionaryEntry *e = NULL; + if ( (e = av_dict_get(opts, "", e, AV_DICT_IGNORE_SUFFIX)) != NULL ) { Warning( "Option %s not recognized by ffmpeg", e->key); } } @@ -567,7 +579,7 @@ int FfmpegCamera::OpenFfmpeg() { } } - Debug ( 1, "Opened codec" ); + Debug ( 1, "Opened audio codec" ); // Allocate space for the native video frame mRawFrame = zm_av_frame_alloc(); @@ -667,14 +679,14 @@ int FfmpegCamera::CloseFfmpeg() { if ( mVideoCodecContext ) { avcodec_close(mVideoCodecContext); #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) - av_free(mVideoCodecContext); + avcodec_free_context(&mVideoCodecContext); #endif mVideoCodecContext = NULL; // Freed by av_close_input_file } if ( mAudioCodecContext ) { avcodec_close(mAudioCodecContext); #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) - av_free(mAudioCodecContext); + avcodec_free_context(&mAudioCodecContext); #endif mAudioCodecContext = NULL; // Freed by av_close_input_file } @@ -784,9 +796,10 @@ int FfmpegCamera::CaptureAndRecord( Image &image, timeval recording, char* event if ( recording.tv_sec ) { uint32_t last_event_id = monitor->GetLastEventId() ; + uint32_t video_writer_event_id = monitor->GetVideoWriterEventId(); - if ( last_event_id != monitor->GetVideoWriterEventId() ) { - Debug(2, "Have change of event. last_event(%d), our current (%d)", last_event_id, monitor->GetVideoWriterEventId() ); + if ( last_event_id != video_writer_event_id ) { + Debug(2, "Have change of event. last_event(%d), our current (%d)", last_event_id, video_writer_event_id ); if ( videoStore ) { Info("Re-starting video storage module"); diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 4f69012f3..a550b4370 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -473,9 +473,12 @@ Monitor::Monitor( videoRecording = ((GetOptVideoWriter() == H264PASSTHROUGH) && camera->SupportsNativeVideo()); if ( purpose == ANALYSIS ) { - - while( shared_data->last_write_index == (unsigned int)image_buffer_count - && shared_data->last_write_time == 0) { +Debug(2,"last_write_index(%d), last_write_time(%d)", shared_data->last_write_index, shared_data->last_write_time ); + while( + ( shared_data->last_write_index == (unsigned int)image_buffer_count ) + && + ( shared_data->last_write_time == 0) + ) { Warning( "Waiting for capture daemon" ); sleep( 1 ); } diff --git a/src/zm_videostore.cpp b/src/zm_videostore.cpp index 20b895c81..8c02d6e3f 100644 --- a/src/zm_videostore.cpp +++ b/src/zm_videostore.cpp @@ -414,13 +414,13 @@ VideoStore::~VideoStore() { if (video_out_stream) { #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) // We allocate and copy in newer ffmpeg, so need to free it - av_free(video_in_ctx); + avcodec_free_context(&video_in_ctx); #endif video_in_ctx=NULL; avcodec_close(video_out_ctx); #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) - av_free(video_out_ctx); + avcodec_free_context(&video_out_ctx); #endif video_out_ctx = NULL; Debug(4, "Success freeing video_out_ctx"); @@ -430,7 +430,7 @@ VideoStore::~VideoStore() { avcodec_close(audio_in_ctx); #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) // We allocate and copy in newer ffmpeg, so need to free it - av_free(audio_in_ctx); + avcodec_free_context(&audio_in_ctx); #endif audio_in_ctx = NULL; audio_in_codec = NULL; @@ -438,7 +438,7 @@ VideoStore::~VideoStore() { avcodec_close(audio_out_ctx); #if LIBAVCODEC_VERSION_CHECK(57, 64, 0, 64, 0) - av_free(audio_out_ctx); + avcodec_free_context(&audio_out_ctx); #endif audio_out_ctx = NULL; #ifdef HAVE_LIBAVRESAMPLE From 344539f5dc16c799222220ceca16aed734ce75c5 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 28 Nov 2017 11:55:47 -0500 Subject: [PATCH 3/4] cleanup --- src/zm_monitor.cpp | 9 ++++++++- src/zm_monitor.h | 3 +-- src/zmu.cpp | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index a550b4370..44324adf5 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -779,7 +779,14 @@ unsigned int Monitor::GetLastWriteIndex() const { return( shared_data->last_write_index!=(unsigned int)image_buffer_count?shared_data->last_write_index:-1 ); } -unsigned int Monitor::GetLastEvent() const { +uint32_t Monitor::GetLastEventId() const { + Debug(2, "mem_ptr(%x), State(%d) last_read_index(%d) last_read_time(%d) last_event(%d)", + mem_ptr, + shared_data->state, + shared_data->last_read_index, + shared_data->last_read_time, + shared_data->last_event + ); return( shared_data->last_event ); } diff --git a/src/zm_monitor.h b/src/zm_monitor.h index 780c10b7c..0de71c424 100644 --- a/src/zm_monitor.h +++ b/src/zm_monitor.h @@ -432,7 +432,6 @@ public: int GetOptSaveJPEGs() const { return( savejpegspref ); } VideoWriter GetOptVideoWriter() const { return( videowriter ); } const std::vector* GetOptEncoderParams() const { return( &encoderparamsvec ); } - uint32_t GetLastEventId() const { return shared_data->last_event; } uint32_t GetVideoWriterEventId() const { return video_store_data->current_event; } void SetVideoWriterEventId( uint32_t p_event_id ) { video_store_data->current_event = p_event_id; } @@ -448,7 +447,7 @@ public: int GetAlarmCaptureDelay() const { return( alarm_capture_delay ); } unsigned int GetLastReadIndex() const; unsigned int GetLastWriteIndex() const; - unsigned int GetLastEvent() const; + uint32_t GetLastEventId() const; double GetFPS() const; void ForceAlarmOn( int force_score, const char *force_case, const char *force_text="" ); void ForceAlarmOff(); diff --git a/src/zmu.cpp b/src/zmu.cpp index 46ba35ac6..4c94d0b51 100644 --- a/src/zmu.cpp +++ b/src/zmu.cpp @@ -514,10 +514,10 @@ int main( int argc, char *argv[] ) { } if ( function & ZMU_EVENT ) { if ( verbose ) - printf( "Last event id: %d\n", monitor->GetLastEvent() ); + printf( "Last event id: %d\n", monitor->GetLastEventId() ); else { if ( have_output ) printf( "%c", separator ); - printf( "%d", monitor->GetLastEvent() ); + printf( "%d", monitor->GetLastEventId() ); have_output = true; } } @@ -712,7 +712,7 @@ int main( int argc, char *argv[] ) { tv.tv_sec, tv.tv_usec/10000, monitor->GetLastReadIndex(), monitor->GetLastWriteIndex(), - monitor->GetLastEvent(), + monitor->GetLastEventId(), monitor->GetFPS() ); delete monitor; From cb70a3627ff8af655887538dcd4f05b7dee32786 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 28 Nov 2017 14:50:21 -0500 Subject: [PATCH 4/4] Fixes to montagereview and only load event data when in History mode --- web/ajax/stream.php | 2 + web/includes/csrf/csrf-magic.php | 24 +++++------ web/includes/database.php | 2 +- web/index.php | 2 +- .../classic/css/flat/views/montagereview.css | 2 +- web/skins/classic/views/js/montagereview.js | 12 ++---- .../classic/views/js/montagereview.js.php | 10 ++++- web/skins/classic/views/montagereview.php | 42 ++++++++++--------- 8 files changed, 51 insertions(+), 45 deletions(-) diff --git a/web/ajax/stream.php b/web/ajax/stream.php index 5c653d068..1f0245a69 100644 --- a/web/ajax/stream.php +++ b/web/ajax/stream.php @@ -116,7 +116,9 @@ switch ( $data['type'] ) { case MSG_DATA_WATCH : { $data = unpack( "ltype/imonitor/istate/dfps/ilevel/irate/ddelay/izoom/Cdelayed/Cpaused/Cenabled/Cforced", $msg ); + Logger::Debug("FPS: " . $data['fps'] ); $data['fps'] = round( $data['fps'], 2 ); + Logger::Debug("FPS: " . $data['fps'] ); $data['rate'] /= RATE_BASE; $data['delay'] = round( $data['delay'], 2 ); $data['zoom'] = round( $data['zoom']/SCALE_BASE, 1 ); diff --git a/web/includes/csrf/csrf-magic.php b/web/includes/csrf/csrf-magic.php index afdfd7bd6..55819329c 100644 --- a/web/includes/csrf/csrf-magic.php +++ b/web/includes/csrf/csrf-magic.php @@ -189,21 +189,21 @@ function csrf_check($fatal = true) { $tokens = ''; do { if (!isset($_POST[$name])) { -Logger::Debug("POST[$name] is not set"); +#Logger::Debug("POST[$name] is not set"); break; -} else { -Logger::Debug("POST[$name] is set as " . $_POST[$name] ); +#} else { +#Logger::Debug("POST[$name] is set as " . $_POST[$name] ); } // we don't regenerate a token and check it because some token creation // schemes are volatile. $tokens = $_POST[$name]; if (!csrf_check_tokens($tokens)) { -Logger::Debug("Failed checking tokens"); +#Logger::Debug("Failed checking tokens"); break; -} else { -Logger::Debug("Token passed"); +#} else { +#Logger::Debug("Token passed"); } $ok = true; } while (false); @@ -308,27 +308,27 @@ function csrf_check_tokens($tokens) { * Checks if a token is valid. */ function csrf_check_token($token) { -Logger::Debug("Checking CSRF token $token"); +#Logger::Debug("Checking CSRF token $token"); if (strpos($token, ':') === false) { -Logger::Debug("Checking CSRF token $token bad because no :"); +#Logger::Debug("Checking CSRF token $token bad because no :"); return false; } list($type, $value) = explode(':', $token, 2); if (strpos($value, ',') === false) { -Logger::Debug("Checking CSRF token $token bad because no ,"); +#Logger::Debug("Checking CSRF token $token bad because no ,"); return false; } list($x, $time) = explode(',', $token, 2); if ($GLOBALS['csrf']['expires']) { if (time() > $time + $GLOBALS['csrf']['expires']) { -Logger::Debug("Checking CSRF token $token bad because expired"); +#Logger::Debug("Checking CSRF token $token bad because expired"); return false; } } switch ($type) { case 'sid': { - Logger::Debug("Checking sid: $value === " . csrf_hash(session_id(), $time) ); + #Logger::Debug("Checking sid: $value === " . csrf_hash(session_id(), $time) ); return $value === csrf_hash(session_id(), $time); } case 'cookie': @@ -341,7 +341,7 @@ return false; Logger::Debug("Checking key: no key set" ); return false; } - Logger::Debug("Checking sid: $value === " . csrf_hash($GLOBALS['csrf']['key'], $time) ); + #Logger::Debug("Checking sid: $value === " . csrf_hash($GLOBALS['csrf']['key'], $time) ); return $value === csrf_hash($GLOBALS['csrf']['key'], $time); // We could disable these 'weaker' checks if 'key' was set, but // that doesn't make me feel good then about the cookie-based diff --git a/web/includes/database.php b/web/includes/database.php index 227de8132..a1bcf66c3 100644 --- a/web/includes/database.php +++ b/web/includes/database.php @@ -134,7 +134,7 @@ function dbQuery( $sql, $params=NULL ) { } else { $result = $dbConn->query( $sql ); } -if ( 0 ) { +if ( 1 ) { if ( $params ) Warning("SQL: $sql" . implode(',',$params) . ' rows: '.$result->rowCount() ); else diff --git a/web/index.php b/web/index.php index 845540327..eb406ceb3 100644 --- a/web/index.php +++ b/web/index.php @@ -195,7 +195,7 @@ isset($action) || $action = NULL; if ( ZM_ENABLE_CSRF_MAGIC && $action != 'login' && $view != 'view_video' && $view != 'video' && $request != 'control' && $view != 'frames') { require_once( 'includes/csrf/csrf-magic.php' ); - Logger::Debug("Calling csrf_check with the following values: \$request = \"$request\", \$view = \"$view\", \$action = \"$action\""); + #Logger::Debug("Calling csrf_check with the following values: \$request = \"$request\", \$view = \"$view\", \$action = \"$action\""); csrf_check(); } diff --git a/web/skins/classic/css/flat/views/montagereview.css b/web/skins/classic/css/flat/views/montagereview.css index 743df40a1..6f8feddf3 100644 --- a/web/skins/classic/css/flat/views/montagereview.css +++ b/web/skins/classic/css/flat/views/montagereview.css @@ -4,7 +4,7 @@ display: inline-flex; border: 1px solid black; width: 25%; - padding: 9px; + padding: 4px; } #ScaleDiv label, #SpeedDiv label { diff --git a/web/skins/classic/views/js/montagereview.js b/web/skins/classic/views/js/montagereview.js index 561f7e6c2..03457f38f 100644 --- a/web/skins/classic/views/js/montagereview.js +++ b/web/skins/classic/views/js/montagereview.js @@ -42,7 +42,7 @@ function evaluateLoadTimes() { imageLoadTimesEvaluated=0; setSpeed(speedIndex); $('fps').innerHTML="Display refresh rate is " + (1000 / currentDisplayInterval).toFixed(1) + " per second, avgFrac=" + avgFrac.toFixed(3) + "."; -} +} // end evaluateLoadTimes() // time is seconds since epoch function SetImageSource( monId, time ) { @@ -465,12 +465,12 @@ function setSpeed( speed_index ) { playSecsperInterval = Math.floor( 1000 * currentSpeed * currentDisplayInterval ) / 1000000; console.log("playSecsPerInterval: " + playSecsperInterval + " = currentspeed:" + currentSpeed + " * " + currentDisplayInterval + " /1000"); showSpeed(speed_index); - if ( timerInterval != currentDisplayInterval || currentSpeed == 0 ) timerFire(); // if the timer isn't firing we need to trigger it to update + if ( timerInterval != currentDisplayInterval || currentSpeed == 0 ) timerFire(); // if the timer isn't firing we need to trigger it to update } function setLive(value) { liveMode = value; - redrawScreen(); + changeDateTime(); } @@ -510,16 +510,12 @@ function clicknav(minSecs,maxSecs,live) {// we use the current time if we can if ( live == 1 ) liveStr="&live=1"; - var fitStr="&fit=0"; - if ( fitMode == 1 ) - fitStr="&fit=1"; - var zoomStr=""; for ( var i=0; i < numMonitors; i++ ) if ( monitorZoomScale[monitorPtr[i]] < 0.99 || monitorZoomScale[monitorPtr[i]] > 1.01 ) // allow for some up/down changes and just treat as 1 of almost 1 zoomStr += "&z" + monitorPtr[i].toString() + "=" + monitorZoomScale[monitorPtr[i]].toFixed(2); - var uri = "?view=" + currentView + fitStr + groupStr + minStr + maxStr + currentStr + intervalStr + liveStr + zoomStr + "&scale=" + $j("#scaleslider")[0].value + "&speed=" + speeds[$j("#speedslider")[0].value]; + var uri = "?view=" + currentView + '&fit='+(fitMode==1?'1':'0') + groupStr + minStr + maxStr + currentStr + intervalStr + liveStr + zoomStr + "&scale=" + $j("#scaleslider")[0].value + "&speed=" + speeds[$j("#speedslider")[0].value]; window.location = uri; } // end function clicknav diff --git a/web/skins/classic/views/js/montagereview.js.php b/web/skins/classic/views/js/montagereview.js.php index d6943dac5..69d9c3d22 100644 --- a/web/skins/classic/views/js/montagereview.js.php +++ b/web/skins/classic/views/js/montagereview.js.php @@ -31,14 +31,18 @@ var groupStr=; // Because we might not have time as the criteria, figure out the min/max time when we run the query -$minTimeSecs = strtotime('2036-01-01 01:01:01'); -$maxTimeSecs = strtotime('1950-01-01 01:01:01'); +if ( ! $maxTimeSecs ) +$maxTimeSecs = time(); +if ( ! $minTimeSecs ) +$minTimeSecs = strtotime('2010-01-01 01:01:01'); // This builds the list of events that are eligible from this range $index = 0; $anyAlarms = false; +if ( ! $initialModeIsLive ) { + $result = dbQuery( $eventsSql ); if ( ! $result ) { Fatal('SQL-ERR'); @@ -81,6 +85,7 @@ if ( !isset($minTime) || !isset($maxTime) ) { $minTime = strftime($minTimeSecs); } else { $minTimeSecs = strtotime($minTime); + $maxTimeSecs = strtotime($maxTime); } @@ -136,6 +141,7 @@ if ( $mId > 0 ) { } echo "var maxScore=$maxScore;\n"; // used to skip frame load if we find no alarms. +} // end if initialmodeislive echo "var monitorName = [];\n"; echo "var monitorLoading = [];\n"; echo "var monitorImageObject = [];\n"; diff --git a/web/skins/classic/views/montagereview.php b/web/skins/classic/views/montagereview.php index 69a5c2921..37add6ddc 100644 --- a/web/skins/classic/views/montagereview.php +++ b/web/skins/classic/views/montagereview.php @@ -106,6 +106,7 @@ if ( !isset($_REQUEST['minTime']) && !isset($_REQUEST['maxTime']) ) { $time = time(); $maxTime = strftime("%FT%T",$time); $minTime = strftime("%FT%T",$time - 3600); + Logger::Debug("Defaulting to $minTime to $maxTime"); } if ( isset($_REQUEST['minTime']) ) $minTime = validHtmlStr($_REQUEST['minTime']); @@ -113,7 +114,7 @@ if ( isset($_REQUEST['minTime']) ) if ( isset($_REQUEST['maxTime']) ) $maxTime = validHtmlStr($_REQUEST['maxTime']); -// AS a special case a "all" is passed in as an exterme interval - if so , clear them here and let the database query find them +// AS a special case a "all" is passed in as an extreme interval - if so, clear them here and let the database query find them if ( (strtotime($maxTime) - strtotime($minTime))/(365*24*3600) > 30 ) { // test years @@ -161,6 +162,7 @@ $eventsSql .= ' GROUP BY E.Id,E.Name,E.StartTime,E.Length,E.Frames,E.MaxScore,E. if ( isset($minTime) && isset($maxTime) ) { $minTimeSecs = strtotime($minTime); $maxTimeSecs = strtotime($maxTime); + Logger::Debug("Min/max time secs: $minTimeSecs $maxTimeSecs"); $eventsSql .= " HAVING CalcEndTimeSecs > '" . $minTimeSecs . "' AND StartTimeSecs < '" . $maxTimeSecs . "'"; $frameSql .= " AND TimeStamp > '" . $minTime . "' AND TimeStamp < '" . $maxTime . "'"; } @@ -190,31 +192,31 @@ xhtmlHeaders(__FILE__, translate('MontageReview') );
- - - x + + + x
- - - fps + + + fps
- - - - - - - - - + + + + + + + + +
- - - - + + + +