From 061c88939429d53d0f8565c110290c4aaca989e3 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Tue, 6 Oct 2020 16:35:46 -0400 Subject: [PATCH] Implement SEEK to offset using two 32bit integers to represent the double value --- src/zm_eventstream.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/zm_eventstream.cpp b/src/zm_eventstream.cpp index aa0040bf7..33fc642a6 100644 --- a/src/zm_eventstream.cpp +++ b/src/zm_eventstream.cpp @@ -505,9 +505,18 @@ void EventStream::processCommand(const CmdMsg *msg) { case CMD_SEEK : { // offset is in seconds - 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 current frame id: %d offset %.f)", + + int int_part = ((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]; + int dec_part = ((unsigned char)msg->msg_data[5]<<24)|((unsigned char)msg->msg_data[6]<<16)|((unsigned char)msg->msg_data[7]<<8)|(unsigned char)msg->msg_data[8]; + + double offset = (double)int_part + (double)(dec_part / (double)1000000); + if ( offset < 0.0 ) { + Warning("Invalid offset, not seeking"); + break; + } + curr_frame_id = (int)(event_data->frame_count*offset/event_data->duration)+1; + curr_stream_time = event_data->frames[curr_frame_id-1].timestamp; + Debug(1, "Got SEEK command, to %f (new current frame id: %d offset %f)", offset, curr_frame_id, event_data->frames[curr_frame_id-1].offset); send_frame = true; break; @@ -903,6 +912,7 @@ void EventStream::runStream() { bool in_event = true; double time_to_event = 0; if ( replay_rate > 0 ) { + // As we are playing, curr_stream_time starts at first frame timestamp and increases so it should only be greater if event data has been loaded for the next event. time_to_event = event_data->frames[0].timestamp - curr_stream_time; if ( time_to_event > 0 ) in_event = false;