From 5e75588bfb85c6202dffbadcba5e4e91e3965fe9 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 21 Jun 2017 17:14:02 -0400 Subject: [PATCH] Fix event viewing. Output a frame immediately on zoom in/out. Fix recursive loop on play/pause --- src/zm_event.cpp | 31 +++++++++++++++++++---------- src/zm_event.h | 1 + web/skins/classic/views/event.php | 13 ++++++------ web/skins/classic/views/js/event.js | 23 ++++++++++++++------- 4 files changed, 44 insertions(+), 24 deletions(-) diff --git a/src/zm_event.cpp b/src/zm_event.cpp index 8648758a5..110faf2d2 100644 --- a/src/zm_event.cpp +++ b/src/zm_event.cpp @@ -783,8 +783,12 @@ 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) && ((unsigned int)curr_frame_id == event_data->frame_count) ) + if ( (mode == MODE_SINGLE) && ((unsigned int)curr_frame_id == event_data->frame_count) ) { + Debug(1, "Was in single_mode, and last frame, so jumping to 1st frame"); curr_frame_id = 1; + } else { + Debug(1, "mode is %s, current frame is %d, frame count is %d", (mode == MODE_SINGLE ? "single" : "not single" ), curr_frame_id, event_data->frame_count ); + } replay_rate = ZM_RATE_BASE; break; @@ -910,6 +914,8 @@ void EventStream::processCommand( const CmdMsg *msg ) { break; } break; + + send_frame = true; } case CMD_ZOOMOUT : { @@ -932,6 +938,7 @@ void EventStream::processCommand( const CmdMsg *msg ) { zoom = 100; break; } + send_frame = true; break; } case CMD_PAN : @@ -974,6 +981,7 @@ void EventStream::processCommand( const CmdMsg *msg ) { int offset = ((unsigned char)msg->msg_data[1]<<24)|((unsigned char)msg->msg_data[2]<<16)|((unsigned char)msg->msg_data[3]<<8)|(unsigned char)msg->msg_data[4]; curr_frame_id = (int)(event_data->frame_count*offset/event_data->duration); Debug( 1, "Got SEEK command, to %d (new cfid: %d)", offset, curr_frame_id ); + send_frame = true; break; } case CMD_QUERY : @@ -1004,7 +1012,7 @@ void EventStream::processCommand( const CmdMsg *msg ) { status_data.rate = replay_rate; status_data.zoom = zoom; status_data.paused = paused; - Debug( 2, "E:%d, P:%d, p:%d R:%d, Z:%d", + Debug( 2, "Event:%d, Paused:%d, progress:%d Rate:%d, Zoom:%d", status_data.event, status_data.paused, status_data.progress, @@ -1251,10 +1259,13 @@ void EventStream::runStream() { exit( 0 ); } - unsigned int delta_us = 0; while( !zm_terminate ) { gettimeofday( &now, NULL ); + unsigned int delta_us = 0; + send_frame = false; + + // commands may set send_frame to true while(checkCommandQueue()); if ( step != 0 ) @@ -1268,7 +1279,7 @@ void EventStream::runStream() { //Info( "cst:%.2f", curr_stream_time ); //Info( "cfid:%d", curr_frame_id ); //Info( "fdt:%d", frame_data->timestamp ); - if ( !paused ) { + if ( ! paused ) { bool in_event = true; double time_to_event = 0; if ( replay_rate > 0 ) { @@ -1280,7 +1291,7 @@ void EventStream::runStream() { if ( time_to_event > 0 ) in_event = false; } - if ( !in_event ) { + if ( ! in_event ) { double actual_delta_time = TV_2_FLOAT( now ) - last_frame_sent; if ( actual_delta_time > 1 ) { static char frame_text[64]; @@ -1296,11 +1307,8 @@ void EventStream::runStream() { //} continue; } - } - // Figure out if we should send this frame - bool send_frame = false; - if ( !paused ) { + // Figure out if we should send this frame // If we are streaming and this frame is due to be sent if ( ((curr_frame_id-1)%frame_mod) == 0 ) { delta_us = (unsigned int)(frame_data->delta * 1000000); @@ -1314,7 +1322,7 @@ void EventStream::runStream() { // We are paused and are just stepping forward or backward one frame step = 0; send_frame = true; - } else { + } else if ( ! send_frame ) { // We are paused, and doing nothing double actual_delta_time = TV_2_FLOAT( now ) - last_frame_sent; if ( actual_delta_time > MAX_STREAM_DELAY ) { @@ -1334,7 +1342,8 @@ void EventStream::runStream() { curr_frame_id += replay_rate>0?1:-1; if ( send_frame && type != STREAM_MPEG ) { Debug( 3, "dUs: %d", delta_us ); - usleep( delta_us ); + if ( usleep ) + usleep( delta_us ); } } else { usleep( (unsigned long)((1000000 * ZM_RATE_BASE)/((base_fps?base_fps:1)*abs(replay_rate*2))) ); diff --git a/src/zm_event.h b/src/zm_event.h index d6dd154fa..1b9fd5506 100644 --- a/src/zm_event.h +++ b/src/zm_event.h @@ -226,6 +226,7 @@ protected: protected: int curr_frame_id; double curr_stream_time; + bool send_frame; // Used as a flag whether or not to send out a frame. EventData *event_data; diff --git a/web/skins/classic/views/event.php b/web/skins/classic/views/event.php index c39b286ac..50b02f83f 100644 --- a/web/skins/classic/views/event.php +++ b/web/skins/classic/views/event.php @@ -50,6 +50,7 @@ if ( isset( $_REQUEST['scale'] ) ) { } $replayModes = array( + 'none' => translate('None'), 'single' => translate('ReplaySingle'), 'all' => translate('ReplayAll'), 'gapless' => translate('ReplayGapless'), @@ -64,9 +65,9 @@ if ( isset( $_REQUEST['replayMode'] ) ) $replayMode = validHtmlStr($_REQUEST['replayMode']); if ( isset( $_COOKIE['replayMode']) && preg_match('#^[a-z]+$#', $_COOKIE['replayMode']) ) $replayMode = validHtmlStr($_COOKIE['replayMode']); -else { - $keys = array_keys( $replayModes ); - $replayMode = array_shift( $keys ); + +if ( ( ! $replayMode ) or ( ! $replayModes[$replayMode] ) ) { + $replayMode = 'none'; } // videojs zoomrotate only when direct recording @@ -185,8 +186,8 @@ if ( ZM_WEB_STREAM_METHOD == 'mpeg' && ZM_MPEG_LIVE_FORMAT ) { - - + + @@ -206,7 +207,7 @@ if ( ZM_WEB_STREAM_METHOD == 'mpeg' && ZM_MPEG_LIVE_FORMAT ) { SaveJPEGs() & 3) { // frames or analysis + if ($Event->SaveJPEGs() & 3) { // frames or analysis ?>