From bc525a4e01f42a74996547bb7dc195266ba9abea Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sat, 2 Dec 2017 13:55:26 -0500 Subject: [PATCH 1/2] blah --- src/zm_camera.cpp | 7 +++++-- src/zm_ffmpeg.cpp | 8 ++++++-- src/zm_ffmpeg_camera.cpp | 18 +----------------- src/zm_ffmpeg_camera.h | 3 --- 4 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/zm_camera.cpp b/src/zm_camera.cpp index f9e0c154d..ce0a9bc60 100644 --- a/src/zm_camera.cpp +++ b/src/zm_camera.cpp @@ -36,6 +36,7 @@ Camera::Camera( unsigned int p_monitor_id, SourceType p_type, unsigned int p_wid mVideoStreamId(-1), mAudioStreamId(-1), mVideoCodecContext(NULL), + mAudioCodecContext(NULL), video_stream(NULL) { pixels = width * height; @@ -49,15 +50,17 @@ Camera::Camera( unsigned int p_monitor_id, SourceType p_type, unsigned int p_wid } else if(colours == ZM_COLOUR_RGB24 && ((imagesize % 64) != 0 || (imagesize % 12) != 0)) { Fatal("Image size is not multiples of 12 and 64"); } - monitor = NULL; + monitor = NULL; } Camera::~Camera() { } Monitor *Camera::getMonitor() { - if ( ! monitor ) + if ( ! monitor ) { + Warning("Loading monitor"); monitor = Monitor::Load( monitor_id, false, Monitor::QUERY ); + } return monitor; } diff --git a/src/zm_ffmpeg.cpp b/src/zm_ffmpeg.cpp index d943d399b..a96bced26 100644 --- a/src/zm_ffmpeg.cpp +++ b/src/zm_ffmpeg.cpp @@ -26,9 +26,13 @@ void FFMPEGInit() { static bool bInit = false; - if(!bInit) { + if ( !bInit ) { + if ( logDebugging() ) + av_log_set_level( AV_LOG_DEBUG ); + else + av_log_set_level( AV_LOG_QUIET ); av_register_all(); - av_log_set_level(AV_LOG_DEBUG); + avformat_network_init(); bInit = true; } } diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 4f9f42fea..1783183f2 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -88,7 +88,7 @@ FfmpegCamera::FfmpegCamera( int p_id, const std::string &p_path, const std::stri mOptions( p_options ) { if ( capture ) { - Initialise(); + FFMPEGInit(); } hwaccel = false; @@ -118,25 +118,9 @@ FfmpegCamera::~FfmpegCamera() { CloseFfmpeg(); - if ( capture ) { - Terminate(); - } avformat_network_deinit(); } -void FfmpegCamera::Initialise() { - if ( logDebugging() ) - av_log_set_level( AV_LOG_DEBUG ); - else - av_log_set_level( AV_LOG_QUIET ); - - av_register_all(); - avformat_network_init(); -} - -void FfmpegCamera::Terminate() { -} - int FfmpegCamera::PrimeCapture() { mVideoStreamId = -1; mAudioStreamId = -1; diff --git a/src/zm_ffmpeg_camera.h b/src/zm_ffmpeg_camera.h index a5f4d1f12..9220ca46f 100644 --- a/src/zm_ffmpeg_camera.h +++ b/src/zm_ffmpeg_camera.h @@ -100,9 +100,6 @@ class FfmpegCamera : public Camera { const std::string &Options() const { return( mOptions ); } const std::string &Method() const { return( mMethod ); } - void Initialise(); - void Terminate(); - int PrimeCapture(); int PreCapture(); int Capture(ZMPacket &p); From b8f455ee7c46ad7524e9b09ae4ee64e0401247dc Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Sun, 3 Dec 2017 11:00:40 -0500 Subject: [PATCH 2/2] some cleanup, add a note about the lines that cause zm to crash --- src/zm_db.cpp | 7 ++++--- src/zm_db.h | 31 +++++++++++-------------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/zm_db.cpp b/src/zm_db.cpp index bb83d09ab..ac09dca13 100644 --- a/src/zm_db.cpp +++ b/src/zm_db.cpp @@ -25,11 +25,12 @@ MYSQL dbconn; -int zmDbConnected = false; +bool zmDbConnected = false; void zmDbConnect() { - if ( zmDbConnected ) - return; + // If these lines are uncommented, we get memory corruption and crashes + //if ( zmDbConnected ) + //return; if ( !mysql_init( &dbconn ) ) { Error( "Can't initialise database connection: %s", mysql_error( &dbconn ) ); diff --git a/src/zm_db.h b/src/zm_db.h index f9b158be8..f53a8c738 100644 --- a/src/zm_db.h +++ b/src/zm_db.h @@ -23,35 +23,26 @@ #include class zmDbRow { - private: - MYSQL_RES *result_set; - MYSQL_ROW row; - public: - zmDbRow() { result_set = NULL; row = NULL; }; - MYSQL_RES *fetch( const char *query ); - zmDbRow( MYSQL_RES *, MYSQL_ROW *row ); - ~zmDbRow(); + private: + MYSQL_RES *result_set; + MYSQL_ROW row; + public: + zmDbRow() { result_set = NULL; row = NULL; }; + MYSQL_RES *fetch( const char *query ); + zmDbRow( MYSQL_RES *, MYSQL_ROW *row ); + ~zmDbRow(); - char *operator[](unsigned int index) const { - return row[index]; - } + char *operator[](unsigned int index) const { + return row[index]; + } }; -#ifdef __cplusplus -extern "C" { -#endif extern MYSQL dbconn; -extern int zmDbConnected; - void zmDbConnect(); void zmDbClose(); MYSQL_RES * zmDbFetch( const char *query ); zmDbRow *zmDbFetchOne( const char *query ); -#ifdef __cplusplus -} /* extern "C" */ -#endif - #endif // ZM_DB_H