Unset holdbuffer so that when we connect, we reset the shm buffer pointer. cleanup initializers in Image

This commit is contained in:
Isaac Connor 2022-01-19 15:01:37 -05:00
parent 05043a37b1
commit dec440ead1
3 changed files with 23 additions and 19 deletions

View File

@ -114,22 +114,23 @@ Image::Image() :
delta8_argb(&std_delta8_argb), delta8_argb(&std_delta8_argb),
delta8_abgr(&std_delta8_abgr), delta8_abgr(&std_delta8_abgr),
delta8_gray8(&std_delta8_gray8), 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(); Initialise();
width = 0; // Update blend to fast function determined by Initialise, I'm sure this can be improve.
linesize = 0;
height = 0;
padding = 0;
pixels = 0;
colours = 0;
subpixelorder = 0;
size = 0;
allocation = 0;
buffer = 0;
buffertype = ZM_BUFTYPE_DONTFREE;
holdbuffer = 0;
blend = fptr_blend; 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), colours(p_colours),
padding(p_padding), padding(p_padding),
subpixelorder(p_subpixelorder), subpixelorder(p_subpixelorder),
buffer(p_buffer) { buffer(p_buffer),
holdbuffer(0)
{
if (!initialised) if (!initialised)
Initialise(); Initialise();
pixels = width * height; pixels = width * height;
linesize = p_width * p_colours; linesize = p_width * p_colours;
size = linesize * height + padding; size = linesize * height + padding;
buffer = nullptr;
holdbuffer = 0;
if (p_buffer) { if (p_buffer) {
allocation = size; allocation = size;
buffertype = ZM_BUFTYPE_DONTFREE; buffertype = ZM_BUFTYPE_DONTFREE;
@ -174,7 +175,7 @@ Image::Image(int p_width, int p_height, int p_colours, int p_subpixelorder, uint
} else { } else {
AllocImgBuffer(size); AllocImgBuffer(size);
} }
if (!subpixelorder and colours>1) { if (!subpixelorder and (colours>1)) {
// Default to RGBA when no subpixelorder is specified. // Default to RGBA when no subpixelorder is specified.
subpixelorder = ZM_SUBPIX_ORDER_RGBA; subpixelorder = ZM_SUBPIX_ORDER_RGBA;
} }

View File

@ -145,11 +145,13 @@ class Image {
explicit Image(const AVFrame *frame); explicit Image(const AVFrame *frame);
~Image(); ~Image();
static void Initialise(); static void Initialise();
static void Deinitialise(); static void Deinitialise();
inline void DumpImgBuffer() { inline void DumpImgBuffer() {
DumpBuffer(buffer, buffertype); if (buffertype != ZM_BUFTYPE_DONTFREE)
DumpBuffer(buffer, buffertype);
buffertype = ZM_BUFTYPE_DONTFREE; buffertype = ZM_BUFTYPE_DONTFREE;
buffer = nullptr; buffer = nullptr;
allocation = 0; allocation = 0;

View File

@ -1153,6 +1153,7 @@ bool Monitor::disconnect() {
} }
if (purpose == CAPTURE) { if (purpose == CAPTURE) {
alarm_image.HoldBuffer(false); /* Allow to reset buffer */
if (unlink(mem_file.c_str()) < 0) { if (unlink(mem_file.c_str()) < 0) {
Warning("Can't unlink '%s': %s", mem_file.c_str(), strerror(errno)); Warning("Can't unlink '%s': %s", mem_file.c_str(), strerror(errno));
} }