From 4976fb5ec4a36070d26edba4f311ea9a4b0a9c31 Mon Sep 17 00:00:00 2001 From: johandinox Date: Fri, 15 Sep 2023 13:54:56 +0200 Subject: [PATCH 1/2] Limit queue to ring buffer size --- src/pyvcam/pvcmodule.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pyvcam/pvcmodule.cpp b/src/pyvcam/pvcmodule.cpp index 43d48ca..5b68d11 100644 --- a/src/pyvcam/pvcmodule.cpp +++ b/src/pyvcam/pvcmodule.cpp @@ -68,6 +68,7 @@ class Cam_Instance_T { , hFileStreamToDisk_(cInvalidFileHandle) , readIndex_(0) , frameResidual_(0) + , buffer_frame_count_(0) { } @@ -223,6 +224,7 @@ class Cam_Instance_T { bool abortData_; bool newData_; bool seqMode_; + uns16 buffer_frame_count_; std::mutex frameMutex_; std::condition_variable conditionalVariable_; @@ -287,8 +289,9 @@ void NewFrameHandler(FRAME_INFO *pFrameInfo, void *context) // Pop from queue once maximal size is reached. No resets. if (!camInstance.seqMode_){ - if ((int)camInstance.frameQueue_.size() >= 400) { + if ((int)camInstance.frameQueue_.size() >= camInstance.buffer_frame_count_) { //printf("Queue size: %zd",camInstance.frameQueue_.size()); + //printf("Buffer size: %zd",camInstance.buffer_frame_count_); camInstance.frameQueue_.pop(); printf("Lost frame\n"); } @@ -714,7 +717,7 @@ pvc_start_live(PyObject *self, PyObject *args) PyErr_SetString(PyExc_RuntimeError, g_msg); return NULL; } - + camInstance.buffer_frame_count_ = buffer_frame_count; camInstance.setAcquisitiontMode(false); } catch (const std::out_of_range& oor) { From a601cba22c62b602ac96b94b455037bba07cd3dc Mon Sep 17 00:00:00 2001 From: johandinox Date: Fri, 15 Sep 2023 14:47:52 +0200 Subject: [PATCH 2/2] Get frames as long as frames are in buffer --- src/pyvcam/pvcmodule.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pyvcam/pvcmodule.cpp b/src/pyvcam/pvcmodule.cpp index 5b68d11..a69d412 100644 --- a/src/pyvcam/pvcmodule.cpp +++ b/src/pyvcam/pvcmodule.cpp @@ -960,7 +960,9 @@ pvc_get_frame(PyObject *self, PyObject *args) //printf("New Data FPS: %f Cnt: %d\r\n", camInstance.fps_, frame.count); // Toggle newData_ flag unless we are in sequence mode and another frame is available - camInstance.newData_ = camInstance.seqMode_ && !camInstance.frameQueue_.empty(); + //camInstance.newData_ = camInstance.seqMode_ && !camInstance.frameQueue_.empty(); + // Toggle newData_ flag unless another frame is available + camInstance.newData_ = !camInstance.frameQueue_.empty(); PyObject *frameDict = PyDict_New(); PyObject* roiDataList = PyList_New(0);