From 3f7e4c67a086c97066c72687f75011c3e5afaa4e Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 10 Jan 2022 12:49:13 -0500 Subject: [PATCH 01/12] Provide better logging when there is no data passwed to setAlarmCues --- web/skins/classic/views/js/event.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/web/skins/classic/views/js/event.js b/web/skins/classic/views/js/event.js index 2c03dd9ca..ac05f51fe 100644 --- a/web/skins/classic/views/js/event.js +++ b/web/skins/classic/views/js/event.js @@ -88,9 +88,15 @@ function initialAlarmCues(eventId) { } function setAlarmCues(data) { - cueFrames = data.frames; - alarmSpans = renderAlarmCues(vid ? $j("#videoobj") : $j("#evtStream"));//use videojs width or zms width - $j(".alarmCue").html(alarmSpans); + if (!data) { + Error('No data in setAlarmCues for event ' + eventData.Id); + } else if (!data.frames) { + Error('No data.frames in setAlarmCues for event ' + eventData.Id); + } else { + cueFrames = data.frames; + alarmSpans = renderAlarmCues(vid ? $j("#videoobj") : $j("#evtStream"));//use videojs width or zms width + $j(".alarmCue").html(alarmSpans); + } } function renderAlarmCues(containerEl) { From ec95c8da575359c5b79f2f01b573e0a7b818da32 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 10 Jan 2022 15:24:57 -0500 Subject: [PATCH 02/12] Rename the monitor type define from CURL to LIBCURL to fix namespace conflict --- src/zm_monitor.cpp | 4 ++-- src/zm_monitor.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index e07b872fc..eb82b3f39 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -487,7 +487,7 @@ void Monitor::Load(MYSQL_ROW dbrow, bool load_zones=true, Purpose p = QUERY) { } else if ( ! strcmp(dbrow[col], "Libvlc") ) { type = LIBVLC; } else if ( ! strcmp(dbrow[col], "cURL") ) { - type = CURL; + type = LIBCURL; } else if ( ! strcmp(dbrow[col], "VNC") ) { type = VNC; } else { @@ -859,7 +859,7 @@ void Monitor::LoadCamera() { #endif // HAVE_LIBVLC break; } - case CURL: { + case LIBCURL: { #if HAVE_LIBCURL camera = zm::make_unique(this, path.c_str(), diff --git a/src/zm_monitor.h b/src/zm_monitor.h index 0396253ca..4be731c5b 100644 --- a/src/zm_monitor.h +++ b/src/zm_monitor.h @@ -76,7 +76,7 @@ public: FILE, FFMPEG, LIBVLC, - CURL, + LIBCURL, NVSOCKET, VNC, } CameraType; From ed7bc7c4b473c4e4c5e3478840bc25840267a52d Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 10 Jan 2022 15:25:12 -0500 Subject: [PATCH 03/12] whitespace --- src/zm_ffmpeg_camera.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/zm_ffmpeg_camera.cpp b/src/zm_ffmpeg_camera.cpp index 2b36c34f6..4a0c94ec9 100644 --- a/src/zm_ffmpeg_camera.cpp +++ b/src/zm_ffmpeg_camera.cpp @@ -293,18 +293,16 @@ int FfmpegCamera::OpenFfmpeg() { mFormatContext->interrupt_callback.opaque = this; ret = avformat_open_input(&mFormatContext, mPath.c_str(), nullptr, &opts); - if ( ret != 0 ) - { + if (ret != 0) { logPrintf(Logger::ERROR + monitor->Importance(), "Unable to open input %s due to: %s", mPath.c_str(), av_make_error_string(ret).c_str()); - if ( mFormatContext ) { + if (mFormatContext) { avformat_close_input(&mFormatContext); mFormatContext = nullptr; } av_dict_free(&opts); - return -1; } AVDictionaryEntry *e = nullptr; From b406bf8fd101d358bbbaa7633185ff281d49fdb4 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 10 Jan 2022 10:13:11 -0500 Subject: [PATCH 04/12] remove last_send_image_width/height. Not really useful or relevant --- src/zm_stream.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/zm_stream.cpp b/src/zm_stream.cpp index aba98e0c3..084bd6754 100644 --- a/src/zm_stream.cpp +++ b/src/zm_stream.cpp @@ -157,7 +157,6 @@ Image *StreamBase::prepareImage(Image *image) { int disp_image_width = (image->Width() * scale) / ZM_SCALE_BASE, disp_image_height = (image->Height() * scale) / ZM_SCALE_BASE; int last_disp_image_width = (image->Width() * last_scale) / ZM_SCALE_BASE, last_disp_image_height = (image->Height() * last_scale) / ZM_SCALE_BASE; int send_image_width = (disp_image_width * act_mag ) / mag, send_image_height = (disp_image_height * act_mag ) / mag; - int last_send_image_width = (last_disp_image_width * last_act_mag ) / last_mag, last_send_image_height = (last_disp_image_height * last_act_mag ) / last_mag; Debug(3, "Scaling by %d, zooming by %d = magnifying by %d(%d)\n" @@ -169,8 +168,7 @@ Image *StreamBase::prepareImage(Image *image) { "Last actual image width = %d, height = %d\n" "Display image width = %d, height = %d\n" "Last display image width = %d, height = %d\n" - "Send image width = %d, height = %d\n" - "Last send image width = %d, height = %d\n", + "Send image width = %d, height = %d\n", scale, zoom, mag, act_mag, last_scale, last_zoom, last_mag, last_act_mag, base_image_width, base_image_height, @@ -180,8 +178,7 @@ Image *StreamBase::prepareImage(Image *image) { last_act_image_width, last_act_image_height, disp_image_width, disp_image_height, last_disp_image_width, last_disp_image_height, - send_image_width, send_image_height, - last_send_image_width, last_send_image_height + send_image_width, send_image_height ); if ( ( mag != ZM_SCALE_BASE ) && (act_mag != ZM_SCALE_BASE) ) { From 037771539d9973bc46dea58c7983acc850569b75 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 10 Jan 2022 10:13:53 -0500 Subject: [PATCH 05/12] spacing, return a success value from setupCodec instead of using Fatal --- src/zm_mpeg.cpp | 182 ++++++++++++++++++++++++------------------------ src/zm_mpeg.h | 2 +- 2 files changed, 93 insertions(+), 91 deletions(-) diff --git a/src/zm_mpeg.cpp b/src/zm_mpeg.cpp index b8f7eeb66..275e36628 100644 --- a/src/zm_mpeg.cpp +++ b/src/zm_mpeg.cpp @@ -1,17 +1,17 @@ /* * ZoneMinder MPEG class implementation, $Date$, $Revision$ * Copyright (C) 2001-2008 Philip Coombes - * + * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. @@ -42,19 +42,26 @@ void VideoStream::SetupFormat( ) { ofc = nullptr; avformat_alloc_output_context2(&ofc, nullptr, format, filename); - if ( !ofc ) { + if (!ofc) { Fatal("avformat_alloc_..._context failed"); } of = ofc->oformat; - Debug(1, "Using output format: %s (%s)", of->name, of->long_name); + Debug(1, "Using output format: %s (%s)", of->name, of->long_name); } -void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int height, int bitrate, double frame_rate ) { +int VideoStream::SetupCodec( + int colours, + int subpixelorder, + int width, + int height, + int bitrate, + double frame_rate + ) { /* ffmpeg format matching */ - switch ( colours ) { + switch (colours) { case ZM_COLOUR_RGB24: - if ( subpixelorder == ZM_SUBPIX_ORDER_BGR ) { + if (subpixelorder == ZM_SUBPIX_ORDER_BGR) { /* BGR subpixel order */ pf = AV_PIX_FMT_BGR24; } else { @@ -63,13 +70,13 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei } break; case ZM_COLOUR_RGB32: - if ( subpixelorder == ZM_SUBPIX_ORDER_ARGB ) { + if (subpixelorder == ZM_SUBPIX_ORDER_ARGB) { /* ARGB subpixel order */ pf = AV_PIX_FMT_ARGB; - } else if ( subpixelorder == ZM_SUBPIX_ORDER_ABGR ) { + } else if (subpixelorder == ZM_SUBPIX_ORDER_ABGR) { /* ABGR subpixel order */ pf = AV_PIX_FMT_ABGR; - } else if ( subpixelorder == ZM_SUBPIX_ORDER_BGRA ) { + } else if (subpixelorder == ZM_SUBPIX_ORDER_BGRA) { /* BGRA subpixel order */ pf = AV_PIX_FMT_BGRA; } else { @@ -85,22 +92,22 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei break; } - if ( strcmp("rtp", of->name) == 0 ) { + if (strcmp("rtp", of->name) == 0) { // RTP must have a packet_size. // Not sure what this value should be really... ofc->packet_size = width*height; Debug(1,"Setting packet_size to %d", ofc->packet_size); - - if ( of->video_codec == AV_CODEC_ID_NONE ) { + + if (of->video_codec == AV_CODEC_ID_NONE) { // RTP does not have a default codec in ffmpeg <= 0.8. of->video_codec = AV_CODEC_ID_MPEG4; } } - + _AVCODECID codec_id = of->video_codec; - if ( codec_name ) { + if (codec_name) { AVCodec *a = avcodec_find_encoder_by_name(codec_name); - if ( a ) { + if (a) { codec_id = a->id; Debug(1, "Using codec \"%s\"", codec_name); } else { @@ -111,31 +118,29 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei /* add the video streams using the default format codecs and initialize the codecs */ ost = nullptr; - if ( codec_id != AV_CODEC_ID_NONE ) { + if (codec_id != AV_CODEC_ID_NONE) { codec = avcodec_find_encoder(codec_id); - if ( !codec ) { - Fatal("Could not find encoder for '%s'", avcodec_get_name(codec_id)); + if (!codec) { + Error("Could not find encoder for '%s'", avcodec_get_name(codec_id)); + return -1; } Debug(1, "Found encoder for '%s'", avcodec_get_name(codec_id)); - - ost = avformat_new_stream( ofc, codec ); - - if ( !ost ) { - Fatal( "Could not alloc stream" ); - return; + ost = avformat_new_stream(ofc, codec); + if (!ost) { + Error("Could not alloc stream"); + return -1; } - Debug( 1, "Allocated stream (%d) !=? (%d)", ost->id , ofc->nb_streams - 1 ); + Debug(1, "Allocated stream (%d) !=? (%d)", ost->id , ofc->nb_streams - 1); ost->id = ofc->nb_streams - 1; codec_context = avcodec_alloc_context3(nullptr); //avcodec_parameters_to_context(codec_context, ost->codecpar); - codec_context->codec_id = codec->id; codec_context->codec_type = codec->type; codec_context->pix_fmt = strcmp("mjpeg", ofc->oformat->name) == 0 ? AV_PIX_FMT_YUVJ422P : AV_PIX_FMT_YUV420P; - if ( bitrate <= 100 ) { + if (bitrate <= 100) { // Quality based bitrate control (VBR). Scale is 1..31 where 1 is best. // This gets rid of artifacts in the beginning of the movie; and well, even quality. codec_context->flags |= AV_CODEC_FLAG_QSCALE; @@ -155,22 +160,22 @@ void VideoStream::SetupCodec( int colours, int subpixelorder, int width, int hei codec_context->time_base.num = 1; ost->time_base.den = frame_rate; ost->time_base.num = 1; - - Debug( 1, "Will encode in %d fps. %dx%d", codec_context->time_base.den, width, height ); - + /* emit one intra frame every second */ codec_context->gop_size = frame_rate; // some formats want stream headers to be separate - if ( of->flags & AVFMT_GLOBALHEADER ) + if (of->flags & AVFMT_GLOBALHEADER) codec_context->flags |= AV_CODEC_FLAG_GLOBAL_HEADER; avcodec_parameters_from_context(ost->codecpar, codec_context); zm_dump_codecpar(ost->codecpar); } else { - Fatal( "of->video_codec == AV_CODEC_ID_NONE" ); - } + Error("of->video_codec == AV_CODEC_ID_NONE"); + return -1; + } + return 0; } void VideoStream::SetParameters( ) { @@ -198,11 +203,11 @@ const char *VideoStream::MimeType() const { bool VideoStream::OpenStream( ) { int ret; - /* now that all the parameters are set, we can open the + /* now that all the parameters are set, we can open the video codecs and allocate the necessary encode buffers */ if ( ost ) { Debug(1,"Opening codec"); - + /* open the codec */ if ((ret = avcodec_open2(codec_context, codec, nullptr)) < 0) { @@ -319,7 +324,7 @@ VideoStream::VideoStream( const char *in_filename, const char *in_format, int bi if ( !initialised ) { Initialise( ); } - + if ( format ) { int length = strlen(format); codec_and_format = new char[length+1];; @@ -337,13 +342,13 @@ VideoStream::VideoStream( const char *in_filename, const char *in_format, int bi SetupFormat( ); SetupCodec( colours, subpixelorder, width, height, bitrate, frame_rate ); SetParameters( ); - + // Allocate buffered packets. packet_buffers = new AVPacket*[2]; packet_buffers[0] = new AVPacket(); packet_buffers[1] = new AVPacket(); packet_index = 0; - + // Initialize mutex used by streaming thread. if ( pthread_mutex_init( buffer_copy_lock, nullptr ) != 0 ) { Fatal("pthread_mutex_init failed"); @@ -353,35 +358,35 @@ VideoStream::VideoStream( const char *in_filename, const char *in_format, int bi VideoStream::~VideoStream( ) { Debug( 1, "VideoStream destructor." ); - + // Stop streaming thread. if ( streaming_thread ) { do_streaming = false; void* thread_exit_code; - + Debug( 1, "Asking streaming thread to exit." ); - + // Wait for thread to exit. pthread_join(streaming_thread, &thread_exit_code); } - + if ( buffer_copy != nullptr ) { av_free( buffer_copy ); } - + if ( buffer_copy_lock ) { if ( pthread_mutex_destroy( buffer_copy_lock ) != 0 ) { Error( "pthread_mutex_destroy failed" ); } delete buffer_copy_lock; } - + if (packet_buffers) { delete packet_buffers[0]; delete packet_buffers[1]; delete[] packet_buffers; } - + /* close each codec */ if ( ost ) { avcodec_close( codec_context ); @@ -409,7 +414,7 @@ VideoStream::~VideoStream( ) { /* free the stream */ av_free( ofc ); - + /* free format and codec_name data. */ if ( codec_and_format ) { delete codec_and_format; @@ -420,12 +425,12 @@ double VideoStream::EncodeFrame( const uint8_t *buffer, int buffer_size, bool _a if ( pthread_mutex_lock(buffer_copy_lock) != 0 ) { Fatal( "EncodeFrame: pthread_mutex_lock failed." ); } - + if (buffer_copy_size < buffer_size) { if ( buffer_copy ) { av_free(buffer_copy); } - + // Allocate a buffer to store source images for the streaming thread to encode. buffer_copy = (uint8_t *)av_malloc(buffer_size); if ( !buffer_copy ) { @@ -435,35 +440,34 @@ double VideoStream::EncodeFrame( const uint8_t *buffer, int buffer_size, bool _a } buffer_copy_size = buffer_size; } - + add_timestamp = _add_timestamp; timestamp = _timestamp; buffer_copy_used = buffer_size; memcpy(buffer_copy, buffer, buffer_size); - + if ( pthread_mutex_unlock(buffer_copy_lock) != 0 ) { Fatal( "EncodeFrame: pthread_mutex_unlock failed." ); } - + if ( streaming_thread == 0 ) { Debug( 1, "Starting streaming thread" ); - + // Start a thread for streaming encoded video. if (pthread_create( &streaming_thread, nullptr, StreamingThreadCallback, (void*) this) != 0){ // Log a fatal error and exit the process. Fatal( "VideoStream failed to create streaming thread." ); } } - + //return ActuallyEncodeFrame( buffer, buffer_size, add_timestamp, timestamp); - + return _timestamp; } double VideoStream::ActuallyEncodeFrame( const uint8_t *buffer, int buffer_size, bool add_timestamp, unsigned int timestamp ) { - if ( codec_context->pix_fmt != pf ) { - static struct SwsContext *img_convert_ctx = nullptr; + static struct SwsContext *img_convert_ctx = nullptr; memcpy( tmp_opicture->data[0], buffer, buffer_size ); if ( !img_convert_ctx ) { img_convert_ctx = sws_getCachedContext( nullptr, codec_context->width, codec_context->height, pf, codec_context->width, codec_context->height, codec_context->pix_fmt, SWS_BICUBIC, nullptr, nullptr, nullptr ); @@ -475,37 +479,36 @@ double VideoStream::ActuallyEncodeFrame( const uint8_t *buffer, int buffer_size, memcpy( opicture->data[0], buffer, buffer_size ); } AVFrame *opicture_ptr = opicture; - + AVPacket *pkt = packet_buffers[packet_index]; av_init_packet( pkt ); - int got_packet = 0; - if (codec_context->codec_type == AVMEDIA_TYPE_VIDEO && - codec_context->codec_id == AV_CODEC_ID_RAWVIDEO) { - pkt->flags |= AV_PKT_FLAG_KEY; - pkt->stream_index = ost->index; - pkt->data = (uint8_t *)opicture_ptr; - pkt->size = sizeof (AVPicture); - got_packet = 1; + int got_packet = 0; + if (codec_context->codec_type == AVMEDIA_TYPE_VIDEO && + codec_context->codec_id == AV_CODEC_ID_RAWVIDEO) { + pkt->flags |= AV_PKT_FLAG_KEY; + pkt->stream_index = ost->index; + pkt->data = (uint8_t *)opicture_ptr; + pkt->size = sizeof (AVPicture); + got_packet = 1; } else { opicture_ptr->pts = codec_context->frame_number; opicture_ptr->quality = codec_context->global_quality; - avcodec_send_frame(codec_context, opicture_ptr); - int ret = avcodec_receive_packet(codec_context, pkt); - if ( ret < 0 ) { - if ( AVERROR_EOF != ret ) { - Error("ERror encoding video (%d) (%s)", ret, - av_err2str(ret)); - } - } else { - got_packet = 1; + avcodec_send_frame(codec_context, opicture_ptr); + int ret = avcodec_receive_packet(codec_context, pkt); + if (ret < 0) { + if (AVERROR_EOF != ret) { + Error("ERror encoding video (%d) (%s)", ret, av_err2str(ret)); } + } else { + got_packet = 1; + } - if ( got_packet ) { -// if ( c->coded_frame->key_frame ) -// { -// pkt->flags |= AV_PKT_FLAG_KEY; -// } + if (got_packet) { + // if ( c->coded_frame->key_frame ) + // { + // pkt->flags |= AV_PKT_FLAG_KEY; + // } if ( pkt->pts != (int64_t)AV_NOPTS_VALUE ) { pkt->pts = av_rescale_q( pkt->pts, codec_context->time_base, ost->time_base ); @@ -517,18 +520,17 @@ double VideoStream::ActuallyEncodeFrame( const uint8_t *buffer, int buffer_size, pkt->stream_index = ost->index; } } - - return ( opicture_ptr->pts); + + return opicture_ptr->pts; } int VideoStream::SendPacket(AVPacket *packet) { - - int ret = av_write_frame( ofc, packet ); - if ( ret != 0 ) { - Fatal( "Error %d while writing video frame: %s", ret, av_err2str( errno ) ); - } - av_packet_unref( packet ); - return ret; + int ret = av_write_frame(ofc, packet); + if (ret < 0) { + Error("Error %d while writing video frame: %s", ret, av_err2str(errno)); + } + av_packet_unref(packet); + return ret; } void *VideoStream::StreamingThreadCallback(void *ctx) { diff --git a/src/zm_mpeg.h b/src/zm_mpeg.h index b6a6f49be..552652a1d 100644 --- a/src/zm_mpeg.h +++ b/src/zm_mpeg.h @@ -68,7 +68,7 @@ protected: static void Initialise(); void SetupFormat( ); - void SetupCodec( int colours, int subpixelorder, int width, int height, int bitrate, double frame_rate ); + int SetupCodec( int colours, int subpixelorder, int width, int height, int bitrate, double frame_rate ); void SetParameters(); void ActuallyOpenStream(); double ActuallyEncodeFrame( const uint8_t *buffer, int buffer_size, bool add_timestamp=false, unsigned int timestamp=0 ); From 4697e36f114474a8ad5746728207a281c5541901 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 10 Jan 2022 10:14:03 -0500 Subject: [PATCH 06/12] add explicit --- src/zm_rtsp_server_server_media_subsession.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zm_rtsp_server_server_media_subsession.h b/src/zm_rtsp_server_server_media_subsession.h index d3780cd6e..04632c44b 100644 --- a/src/zm_rtsp_server_server_media_subsession.h +++ b/src/zm_rtsp_server_server_media_subsession.h @@ -21,7 +21,7 @@ class ZoneMinderDeviceSource; class BaseServerMediaSubsession { public: - BaseServerMediaSubsession(StreamReplicator* replicator): + explicit BaseServerMediaSubsession(StreamReplicator* replicator): m_replicator(replicator) {}; FramedSource* createSource( From 9f86fd3b1608384682d1d12bab17450e9e9c9be9 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 10 Jan 2022 10:16:07 -0500 Subject: [PATCH 07/12] add default_width and height to constructor --- src/zm_swscale.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/zm_swscale.cpp b/src/zm_swscale.cpp index 20b322ab9..68e7af4ef 100644 --- a/src/zm_swscale.cpp +++ b/src/zm_swscale.cpp @@ -22,7 +22,14 @@ #include "zm_image.h" #include "zm_logger.h" -SWScale::SWScale() : gotdefaults(false), swscale_ctx(nullptr), input_avframe(nullptr), output_avframe(nullptr) { +SWScale::SWScale() : + gotdefaults(false), + swscale_ctx(nullptr), + input_avframe(nullptr), + output_avframe(nullptr), + default_width(0), + default_height(0) +{ Debug(4, "SWScale object created"); } From 78a10b6095b3759d341a1a336ac2b73a880871b4 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 10 Jan 2022 17:35:11 -0500 Subject: [PATCH 08/12] cppcheck fixes --- src/zm_utils.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/zm_utils.cpp b/src/zm_utils.cpp index 409429667..bc17e5758 100644 --- a/src/zm_utils.cpp +++ b/src/zm_utils.cpp @@ -120,9 +120,6 @@ std::string Join(const StringVector &values, const std::string &delim) { std::string stringtf(const char* format, ...) { va_list args; va_start(args, format); - va_list args2; - va_copy(args2, args); - int size = vsnprintf(nullptr, 0, format, args) + 1; // Extra space for '\0' va_end(args); @@ -131,6 +128,8 @@ std::string stringtf(const char* format, ...) { } std::unique_ptr buf(new char[size]); + va_list args2; + va_copy(args2, args); vsnprintf(buf.get(), size, format, args2); va_end(args2); @@ -259,6 +258,8 @@ void HwCapsDetect() { unsigned long auxval = 0; elf_aux_info(AT_HWCAP, &auxval, sizeof(auxval)); if (auxval & HWCAP_NEON) { + #else + { #error Unsupported OS. #endif Debug(1,"Detected ARM (AArch32) processor with Neon"); From 376d7fd7e530a66293c7b932ef2404388028d39e Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 10 Jan 2022 17:35:57 -0500 Subject: [PATCH 09/12] log error if avcodec_parameters_to_context fails. Mostly to quiet cppcheck. Remove duplicated assignment to sample_fmt. --- src/zm_videostore.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/zm_videostore.cpp b/src/zm_videostore.cpp index ad401b22c..abd541535 100644 --- a/src/zm_videostore.cpp +++ b/src/zm_videostore.cpp @@ -401,6 +401,10 @@ bool VideoStore::open() { } else { audio_in_ctx = avcodec_alloc_context3(audio_out_codec); ret = avcodec_parameters_to_context(audio_in_ctx, audio_in_stream->codecpar); + if (ret < 0) + Error("Failure from avcodec_parameters_to_context %s", + av_make_error_string(ret).c_str()); + audio_in_ctx->time_base = audio_in_stream->time_base; audio_out_ctx = avcodec_alloc_context3(audio_out_codec); @@ -729,7 +733,6 @@ bool VideoStore::setup_resampler() { audio_out_ctx->sample_fmt = audio_in_ctx->sample_fmt; audio_out_ctx->channels = audio_in_ctx->channels; audio_out_ctx->channel_layout = audio_in_ctx->channel_layout; - audio_out_ctx->sample_fmt = audio_in_ctx->sample_fmt; if (!audio_out_ctx->channel_layout) { Debug(3, "Correcting channel layout from (%" PRIi64 ") to (%" PRIi64 ")", audio_out_ctx->channel_layout, @@ -852,7 +855,7 @@ bool VideoStore::setup_resampler() { return false; } if ((ret = swr_init(resample_ctx)) < 0) { - Error("Could not open resampler"); + Error("Could not open resampler %d", ret); av_frame_free(&in_frame); av_frame_free(&out_frame); swr_free(&resample_ctx); From 3f7b9dfff7c57fcf80fa8a6998e2a29d26642cb9 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 10 Jan 2022 17:36:45 -0500 Subject: [PATCH 10/12] fix cppcheck error about lo_x. Inner scope overwriting it. --- src/zm_zone.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/zm_zone.cpp b/src/zm_zone.cpp index 4fc1bf61b..29511f6bd 100644 --- a/src/zm_zone.cpp +++ b/src/zm_zone.cpp @@ -219,7 +219,7 @@ bool Zone::CheckAlarms(const Image *delta_image) { int alarm_mid_x = -1; int alarm_mid_y = -1; - unsigned int lo_x = polygon.Extent().Lo().x_; + //unsigned int lo_x = polygon.Extent().Lo().x_; unsigned int lo_y = polygon.Extent().Lo().y_; unsigned int hi_x = polygon.Extent().Hi().x_; unsigned int hi_y = polygon.Extent().Hi().y_; @@ -699,6 +699,7 @@ bool Zone::CheckAlarms(const Image *delta_image) { if ((type < PRECLUSIVE) && (check_method >= BLOBS) && (monitor->GetOptSaveJPEGs() > 1)) { + unsigned int lo_x = polygon.Extent().Lo().x_; // First mask out anything we don't want for (unsigned int y = lo_y; y <= hi_y; y++) { pdiff = diff_buff + ((diff_width * y) + lo_x); From a0c34f0d96deea7015e60f7f8629e30fd3696966 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 10 Jan 2022 18:33:01 -0500 Subject: [PATCH 11/12] Fix. cppcheck was wrong about divider being able to go into deeper scope. --- src/zm_image.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/zm_image.cpp b/src/zm_image.cpp index 99fcf4ee1..1c58130cc 100644 --- a/src/zm_image.cpp +++ b/src/zm_image.cpp @@ -3306,9 +3306,9 @@ void neon32_armv7_fastblend(const uint8_t* col1, const uint8_t* col2, uint8_t* r __attribute__((noinline)) void neon64_armv8_fastblend(const uint8_t* col1, const uint8_t* col2, uint8_t* result, unsigned long count, double blendpercent) { #if (defined(__aarch64__) && !defined(ZM_STRIP_NEON)) static double current_blendpercent = 0.0; + static int8_t divider = 0; if (current_blendpercent != blendpercent) { - static int8_t divider = 0; /* Attempt to match the blending percent to one of the possible values */ if(blendpercent < 2.34375) { // 1.5625% blending From cb30f7639f29ec21214450094ea3ddd4f4505273 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 10 Jan 2022 18:47:26 -0500 Subject: [PATCH 12/12] revert broken commit. Isaac doesn't know what he's doing. --- src/zm_utils.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/zm_utils.cpp b/src/zm_utils.cpp index bc17e5758..6ea4e0dae 100644 --- a/src/zm_utils.cpp +++ b/src/zm_utils.cpp @@ -120,16 +120,18 @@ std::string Join(const StringVector &values, const std::string &delim) { std::string stringtf(const char* format, ...) { va_list args; va_start(args, format); - int size = vsnprintf(nullptr, 0, format, args) + 1; // Extra space for '\0' - va_end(args); - - if (size <= 0) { - throw std::runtime_error("Error during formatting."); - } - - std::unique_ptr buf(new char[size]); va_list args2; va_copy(args2, args); + int size = vsnprintf(nullptr, 0, format, args); + va_end(args); + + if (size < 0) { + va_end(args2); + throw std::runtime_error("Error during formatting."); + } + size += 1; // Extra space for '\0' + + std::unique_ptr buf(new char[size]); vsnprintf(buf.get(), size, format, args2); va_end(args2);