From 3bc006534a107b11a6f8ebb7838a2e2285e65c81 Mon Sep 17 00:00:00 2001 From: Avi Saranga Date: Wed, 15 Nov 2017 13:18:15 -0800 Subject: [PATCH] Do not check queues empty state with empty() but our counter since boosts lock free queue implementation is not thread safe for empty() --- .../objects/TelmateFrameGrabberOpenCVImpl.cpp | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/module/src/server/implementation/objects/TelmateFrameGrabberOpenCVImpl.cpp b/module/src/server/implementation/objects/TelmateFrameGrabberOpenCVImpl.cpp index be4845c..00716c9 100644 --- a/module/src/server/implementation/objects/TelmateFrameGrabberOpenCVImpl.cpp +++ b/module/src/server/implementation/objects/TelmateFrameGrabberOpenCVImpl.cpp @@ -76,13 +76,14 @@ void TelmateFrameGrabberOpenCVImpl::process(cv::Mat &mat) { * to ensure the cpu isn't exhausted while the queue is empty. */ void TelmateFrameGrabberOpenCVImpl::queueHandler() { - VideoFrame *ptrVf; - cv::Mat image; - std::vector params; - std::string image_extension; + VideoFrame *ptrVf; + cv::Mat image; + std::vector params; + std::string image_extension; - while (this->thrLoop) { - if (!this->frameQueue->empty()) { + while (this->thrLoop) { + + if (this->queueLength > 0) { params.clear(); // clear the vector since the last iteration. this->frameQueue->pop(ptrVf); @@ -109,34 +110,40 @@ void TelmateFrameGrabberOpenCVImpl::queueHandler() { break; } - std::string filename = std::to_string((long)this->framesCounter) + "_" + ptrVf->ts + image_extension; + std::string filename = + std::to_string((long) this->framesCounter) + "_" + ptrVf->ts + image_extension; if (this->storagePathSubdir.empty()) { this->storagePathSubdir = this->storagePath + "/frames_" + this->getCurrentTimestampString(); boost::filesystem::path dir(this->storagePathSubdir.c_str()); if (!boost::filesystem::create_directories(dir)) { - GST_ERROR("%s create_directories() failed for: %s", this->epName.c_str(), this->storagePathSubdir.c_str()); + GST_ERROR("%s create_directories() failed for: %s", this->epName.c_str(), + this->storagePathSubdir.c_str()); } } - std::string fullpath = this->storagePathSubdir + "/" + filename; + std::string fullpath = this->storagePathSubdir + "/" + filename; try { cv::imwrite(fullpath.c_str(), ptrVf->mat, params); } catch (...) { GST_ERROR("TelmateFrameGrabberOpenCVImpl::queueHandler() imgwrite() failed."); - throw KurentoException(NOT_IMPLEMENTED, "TelmateFrameGrabberOpenCVImpl::queueHandler() imgwrite() failed. \n"); + throw KurentoException(NOT_IMPLEMENTED, + "TelmateFrameGrabberOpenCVImpl::queueHandler() imgwrite() failed. \n"); } ptrVf->mat.release(); // release internal memory allocations delete ptrVf; ptrVf = NULL; - } else { - boost::this_thread::sleep(boost::posix_time::seconds(1)); + } else { + boost::this_thread::sleep(boost::posix_time::seconds(1)); + } } - } + + + }