From d8171750cdaab29068bc2affd5864b68cc4c0499 Mon Sep 17 00:00:00 2001 From: Isaac Date: Fri, 6 Apr 2018 23:02:15 +0200 Subject: [PATCH 1/6] only call avformat_close_input if mformatContext still has a value. On falure it should have been freed and NULL'd --- src/zm_ffmpeg_camera.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 0d5e70480..bd033fee6 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -362,9 +362,11 @@ int FfmpegCamera::OpenFfmpeg() { #if !LIBAVFORMAT_VERSION_CHECK(53, 17, 0, 25, 0) av_close_input_file( mFormatContext ); #else - avformat_close_input( &mFormatContext ); + if ( mFormatContext ) { + avformat_close_input( &mFormatContext ); + mFormatContext = NULL; + } #endif - mFormatContext = NULL; av_dict_free(&opts); return -1; From 64cfb39043da854e8457587f19141907165dd05c Mon Sep 17 00:00:00 2001 From: Isaac Date: Fri, 6 Apr 2018 23:21:22 +0200 Subject: [PATCH 2/6] do an initial fps report early on --- src/zm_monitor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index 0485ac32e..5c0064a1e 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -2436,7 +2436,7 @@ Debug(4, "Return from Capture (%d)", captureResult); image_count++; - if ( image_count && fps_report_interval && !(image_count%fps_report_interval) ) { + if ( image_count && fps_report_interval && ( (!(image_count%fps_report_interval)) || image_count < 5 ) ) { time_t now = image_buffer[index].timestamp->tv_sec; // If we are too fast, we get div by zero. This seems to happen in the case of audio packets. if ( now != last_fps_time ) { From da9d4c2a5cf696d4a16bc670bcf3e8c001227114 Mon Sep 17 00:00:00 2001 From: Isaac Date: Fri, 6 Apr 2018 23:21:40 +0200 Subject: [PATCH 3/6] whitespace, don't pre-allocate mFormatContext --- src/zm_ffmpeg_camera.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index bd033fee6..a3fef31cb 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -310,10 +310,6 @@ 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; @@ -347,23 +343,23 @@ int FfmpegCamera::OpenFfmpeg() { Warning("Could not set rtsp_transport method '%s'\n", method.c_str()); } - Debug ( 1, "Calling avformat_open_input for %s", mPath.c_str() ); + Debug(1, "Calling avformat_open_input for %s", mPath.c_str()); - mFormatContext = avformat_alloc_context( ); + //mFormatContext = avformat_alloc_context( ); // Speed up find_stream_info //FIXME can speed up initial analysis but need sensible parameters... //mFormatContext->probesize = 32; //mFormatContext->max_analyze_duration = 32; - if ( avformat_open_input( &mFormatContext, mPath.c_str(), NULL, &opts ) != 0 ) + if ( avformat_open_input(&mFormatContext, mPath.c_str(), NULL, &opts) != 0 ) #endif { Error("Unable to open input %s due to: %s", mPath.c_str(), strerror(errno)); #if !LIBAVFORMAT_VERSION_CHECK(53, 17, 0, 25, 0) - av_close_input_file( mFormatContext ); + av_close_input_file(mFormatContext); #else if ( mFormatContext ) { - avformat_close_input( &mFormatContext ); + avformat_close_input(&mFormatContext); mFormatContext = NULL; } #endif From 06fed41d5a7e4f7a91dedb594e4429be05b883d8 Mon Sep 17 00:00:00 2001 From: Isaac Date: Fri, 6 Apr 2018 23:21:47 +0200 Subject: [PATCH 4/6] whitespace --- src/zmc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/zmc.cpp b/src/zmc.cpp index 9baccadb7..871c380f6 100644 --- a/src/zmc.cpp +++ b/src/zmc.cpp @@ -239,8 +239,8 @@ int main(int argc, char *argv[]) { time_t now = (time_t)time(NULL); monitors[i]->setStartupTime(now); - snprintf( sql, sizeof(sql), "REPLACE INTO Monitor_Status (MonitorId, Status) VALUES ('%d','Running')", monitors[i]->Id() ); - if ( mysql_query( &dbconn, sql ) ) { + snprintf(sql, sizeof(sql), "REPLACE INTO Monitor_Status (MonitorId, Status) VALUES ('%d','Running')", monitors[i]->Id()); + if ( mysql_query(&dbconn, sql) ) { Error( "Can't run query: %s", mysql_error( &dbconn ) ); } } From 22f86da3720fdb402a28c1a64f96e77022719572 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 11 Apr 2018 10:38:13 -0400 Subject: [PATCH 5/6] Have to use the .sock file instead of w.lock --- web/ajax/stream.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/web/ajax/stream.php b/web/ajax/stream.php index 57e138254..48b7d4555 100644 --- a/web/ajax/stream.php +++ b/web/ajax/stream.php @@ -10,11 +10,12 @@ if ( !($_REQUEST['connkey'] && $_REQUEST['command']) ) { ajaxError( "Unexpected received message type '$type'" ); } -$key = ftok(ZM_PATH_SOCKS.'/zms-'.sprintf("%06d",$_REQUEST['connkey']).'w.lock', 'Z'); +# The file that we point ftok to has to exist, and only exist if zms is running, so we are pointing it at the .sock +$key = ftok(ZM_PATH_SOCKS.'/zms-'.sprintf('%06d',$_REQUEST['connkey']).'s.sock', 'Z'); $semaphore = sem_get($key,1); if ( sem_acquire($semaphore,1) !== false ) { - if ( !($socket = @socket_create( AF_UNIX, SOCK_DGRAM, 0 )) ) { - ajaxError( 'socket_create() failed: '.socket_strerror(socket_last_error()) ); + if ( !($socket = @socket_create(AF_UNIX, SOCK_DGRAM, 0)) ) { + ajaxError('socket_create() failed: '.socket_strerror(socket_last_error())); } $localSocketFile = ZM_PATH_SOCKS.'/zms-'.sprintf('%06d',$_REQUEST['connkey']).'w.sock'; From 989ed65f52e67a21276dd83843ddfd71661e6aa1 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 11 Apr 2018 10:50:28 -0400 Subject: [PATCH 6/6] spacing and braces, remove a dead unused function --- src/zm_logger.h | 43 ++++++++++++++++----------------- src/zm_monitorstream.cpp | 51 ++++++++-------------------------------- web/api/app/Plugin/Crud | 2 +- 3 files changed, 31 insertions(+), 65 deletions(-) diff --git a/src/zm_logger.h b/src/zm_logger.h index c55a322a9..8e2ab6c9d 100644 --- a/src/zm_logger.h +++ b/src/zm_logger.h @@ -108,10 +108,10 @@ private: bool mFlush; private: - static void usrHandler( int sig ); + static void usrHandler(int sig); public: - friend void logInit( const char *name, const Options &options ); + friend void logInit(const char *name, const Options &options); friend void logTerm(); static Logger *fetch() { @@ -120,7 +120,7 @@ public: Options options; smInstance->initialise( "undef", options ); } - return( smInstance ); + return smInstance; } private: @@ -128,16 +128,16 @@ private: ~Logger(); public: - void initialise( const std::string &id, const Options &options ); + void initialise(const std::string &id, const Options &options); void terminate(); private: - int limit( int level ) { + int limit(int level) { if ( level > DEBUG9 ) - return( DEBUG9 ); + return DEBUG9; if ( level < NOLOG ) - return( NOLOG ); - return( level ); + return NOLOG; + return level; } bool boolEnv(const std::string &name, bool defaultValue=false); @@ -157,19 +157,19 @@ public: Level level() const { return mLevel; } - Level level( Level=NOOPT ); + Level level(Level=NOOPT); bool debugOn() { - return( mEffectiveLevel >= DEBUG1 ); + return mEffectiveLevel >= DEBUG1; } - Level terminalLevel( Level=NOOPT ); - Level databaseLevel( Level=NOOPT ); - Level fileLevel( Level=NOOPT ); - Level syslogLevel( Level=NOOPT ); + Level terminalLevel(Level=NOOPT); + Level databaseLevel(Level=NOOPT); + Level fileLevel(Level=NOOPT); + Level syslogLevel(Level=NOOPT); private: - void logFile( const std::string &logFile ); + void logFile(const std::string &logFile); void openFile(); void closeFile(); void openSyslog(); @@ -177,22 +177,19 @@ private: void closeDatabase(); public: - void logPrint( bool hex, const char * const filepath, const int line, const int level, const char *fstring, ... ); + void logPrint(bool hex, const char * const filepath, const int line, const int level, const char *fstring, ...); }; -void logInit( const char *name, const Logger::Options &options=Logger::Options() ); +void logInit(const char *name, const Logger::Options &options=Logger::Options()); void logTerm(); inline const std::string &logId() { - return( Logger::fetch()->id() ); + return Logger::fetch()->id(); } inline Logger::Level logLevel() { - return( Logger::fetch()->level() ); -} -inline void logCapLevel( Logger::Level level ) { - Logger::fetch()->level( level ); + return Logger::fetch()->level(); } inline Logger::Level logDebugging() { - return( Logger::fetch()->debugOn() ); + return Logger::fetch()->debugOn(); } #define logPrintf(logLevel,params...) {\ diff --git a/src/zm_monitorstream.cpp b/src/zm_monitorstream.cpp index fb3c24f75..6bad8f3ef 100644 --- a/src/zm_monitorstream.cpp +++ b/src/zm_monitorstream.cpp @@ -78,19 +78,16 @@ void MonitorStream::processCommand( const CmdMsg *msg ) { // Check for incoming command switch( (MsgCommand)msg->msg_data[0] ) { case CMD_PAUSE : - { - Debug( 1, "Got PAUSE command" ); + Debug(1, "Got PAUSE command"); // Set paused flag paused = true; // Set delayed flag delayed = true; - last_frame_sent = TV_2_FLOAT( now ); + last_frame_sent = TV_2_FLOAT(now); break; - } case CMD_PLAY : - { - Debug( 1, "Got PLAY command" ); + Debug(1, "Got PLAY command"); if ( paused ) { // Clear paused flag paused = false; @@ -99,10 +96,8 @@ void MonitorStream::processCommand( const CmdMsg *msg ) { } replay_rate = ZM_RATE_BASE; break; - } case CMD_VARPLAY : - { - Debug( 1, "Got VARPLAY command" ); + Debug(1, "Got VARPLAY command"); if ( paused ) { // Clear paused flag paused = false; @@ -111,20 +106,16 @@ void MonitorStream::processCommand( const CmdMsg *msg ) { } replay_rate = ntohs(((unsigned char)msg->msg_data[2]<<8)|(unsigned char)msg->msg_data[1])-32768; break; - } case CMD_STOP : - { - Debug( 1, "Got STOP command" ); + Debug(1, "Got STOP command"); // Clear paused flag paused = false; // Clear delayed_play flag delayed = false; break; - } case CMD_FASTFWD : - { - Debug( 1, "Got FAST FWD command" ); + Debug(1, "Got FAST FWD command"); if ( paused ) { // Clear paused flag paused = false; @@ -132,8 +123,7 @@ void MonitorStream::processCommand( const CmdMsg *msg ) { delayed = true; } // Set play rate - switch ( replay_rate ) - { + switch ( replay_rate ) { case 2 * ZM_RATE_BASE : replay_rate = 5 * ZM_RATE_BASE; break; @@ -152,9 +142,7 @@ void MonitorStream::processCommand( const CmdMsg *msg ) { break; } break; - } case CMD_SLOWFWD : - { Debug( 1, "Got SLOW FWD command" ); // Set paused flag paused = true; @@ -165,9 +153,7 @@ void MonitorStream::processCommand( const CmdMsg *msg ) { // Set step step = 1; break; - } case CMD_SLOWREV : - { Debug( 1, "Got SLOW REV command" ); // Set paused flag paused = true; @@ -178,9 +164,7 @@ void MonitorStream::processCommand( const CmdMsg *msg ) { // Set step step = -1; break; - } case CMD_FASTREV : - { Debug( 1, "Got FAST REV command" ); if ( paused ) { // Clear paused flag @@ -208,9 +192,7 @@ void MonitorStream::processCommand( const CmdMsg *msg ) { break; } break; - } case CMD_ZOOMIN : - { x = ((unsigned char)msg->msg_data[1]<<8)|(unsigned char)msg->msg_data[2]; y = ((unsigned char)msg->msg_data[3]<<8)|(unsigned char)msg->msg_data[4]; Debug( 1, "Got ZOOM IN command, to %d,%d", x, y ); @@ -233,9 +215,7 @@ void MonitorStream::processCommand( const CmdMsg *msg ) { break; } break; - } case CMD_ZOOMOUT : - { Debug( 1, "Got ZOOM OUT command" ); switch ( zoom ) { case 500: @@ -256,36 +236,25 @@ void MonitorStream::processCommand( const CmdMsg *msg ) { break; } break; - } case CMD_PAN : - { x = ((unsigned char)msg->msg_data[1]<<8)|(unsigned char)msg->msg_data[2]; y = ((unsigned char)msg->msg_data[3]<<8)|(unsigned char)msg->msg_data[4]; Debug( 1, "Got PAN command, to %d,%d", x, y ); break; - } case CMD_SCALE : - { scale = ((unsigned char)msg->msg_data[1]<<8)|(unsigned char)msg->msg_data[2]; Debug( 1, "Got SCALE command, to %d", scale ); break; - } case CMD_QUIT : - { Info ("User initiated exit - CMD_QUIT"); break; - } case CMD_QUERY : - { Debug( 1, "Got QUERY command, sending STATUS" ); break; - } default : - { Error( "Got unexpected command %d", msg->msg_data[0] ); break; - } - } + } // end switch command struct { int id; @@ -331,7 +300,7 @@ void MonitorStream::processCommand( const CmdMsg *msg ) { status_msg.msg_type = MSG_DATA_WATCH; memcpy( &status_msg.msg_data, &status_data, sizeof(status_data) ); int nbytes = 0; - if ( (nbytes = sendto( sd, &status_msg, sizeof(status_msg), MSG_DONTWAIT, (sockaddr *)&rem_addr, sizeof(rem_addr) )) < 0 ) { + if ( (nbytes = sendto(sd, &status_msg, sizeof(status_msg), MSG_DONTWAIT, (sockaddr *)&rem_addr, sizeof(rem_addr))) < 0 ) { //if ( errno != EAGAIN ) { Error( "Can't sendto on sd %d: %s", sd, strerror(errno) ); @@ -346,7 +315,7 @@ Debug(2, "NUmber of bytes sent to (%s): (%d)", rem_addr.sun_path, nbytes ); exit(0); } - Debug(2,"Updating framrate"); + Debug(2,"Updating framerate"); updateFrameRate( monitor->GetFPS() ); } // end void MonitorStream::processCommand( const CmdMsg *msg ) diff --git a/web/api/app/Plugin/Crud b/web/api/app/Plugin/Crud index c3976f147..1351dde6b 160000 --- a/web/api/app/Plugin/Crud +++ b/web/api/app/Plugin/Crud @@ -1 +1 @@ -Subproject commit c3976f1478c681b0bbc132ec3a3e82c3984eeed5 +Subproject commit 1351dde6b4c75b215099ae8bcf5a21d6c6e10298