From dec440ead1ba8b4b3c3baf17543e7ccd56e901d5 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Wed, 19 Jan 2022 15:01:37 -0500 Subject: [PATCH] Unset holdbuffer so that when we connect, we reset the shm buffer pointer. cleanup initializers in Image --- src/zm_image.cpp | 37 +++++++++++++++++++------------------ src/zm_image.h | 4 +++- src/zm_monitor.cpp | 1 + 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/zm_image.cpp b/src/zm_image.cpp index 1c58130cc..a4aad8b61 100644 --- a/src/zm_image.cpp +++ b/src/zm_image.cpp @@ -114,22 +114,23 @@ Image::Image() : delta8_argb(&std_delta8_argb), delta8_abgr(&std_delta8_abgr), delta8_gray8(&std_delta8_gray8), - blend(&std_blend) + blend(&std_blend), + width(0), + linesize(0), + height(0), + pixels(0), + colours(0), + padding(0), + size(0), + subpixelorder(0), + allocation(0), + buffer(nullptr), + buffertype(ZM_BUFTYPE_DONTFREE), + holdbuffer(0) { - if ( !initialised ) + if (!initialised) Initialise(); - width = 0; - linesize = 0; - height = 0; - padding = 0; - pixels = 0; - colours = 0; - subpixelorder = 0; - size = 0; - allocation = 0; - buffer = 0; - buffertype = ZM_BUFTYPE_DONTFREE; - holdbuffer = 0; + // Update blend to fast function determined by Initialise, I'm sure this can be improve. blend = fptr_blend; } @@ -158,15 +159,15 @@ Image::Image(int p_width, int p_height, int p_colours, int p_subpixelorder, uint colours(p_colours), padding(p_padding), subpixelorder(p_subpixelorder), - buffer(p_buffer) { + buffer(p_buffer), + holdbuffer(0) +{ if (!initialised) Initialise(); pixels = width * height; linesize = p_width * p_colours; size = linesize * height + padding; - buffer = nullptr; - holdbuffer = 0; if (p_buffer) { allocation = size; buffertype = ZM_BUFTYPE_DONTFREE; @@ -174,7 +175,7 @@ Image::Image(int p_width, int p_height, int p_colours, int p_subpixelorder, uint } else { AllocImgBuffer(size); } - if (!subpixelorder and colours>1) { + if (!subpixelorder and (colours>1)) { // Default to RGBA when no subpixelorder is specified. subpixelorder = ZM_SUBPIX_ORDER_RGBA; } diff --git a/src/zm_image.h b/src/zm_image.h index 74e5931eb..8bcb92c4c 100644 --- a/src/zm_image.h +++ b/src/zm_image.h @@ -145,11 +145,13 @@ class Image { explicit Image(const AVFrame *frame); ~Image(); + static void Initialise(); static void Deinitialise(); inline void DumpImgBuffer() { - DumpBuffer(buffer, buffertype); + if (buffertype != ZM_BUFTYPE_DONTFREE) + DumpBuffer(buffer, buffertype); buffertype = ZM_BUFTYPE_DONTFREE; buffer = nullptr; allocation = 0; diff --git a/src/zm_monitor.cpp b/src/zm_monitor.cpp index f5d225d66..2179197e8 100644 --- a/src/zm_monitor.cpp +++ b/src/zm_monitor.cpp @@ -1153,6 +1153,7 @@ bool Monitor::disconnect() { } if (purpose == CAPTURE) { + alarm_image.HoldBuffer(false); /* Allow to reset buffer */ if (unlink(mem_file.c_str()) < 0) { Warning("Can't unlink '%s': %s", mem_file.c_str(), strerror(errno)); }