diff --git a/src/video/videobuffer.cpp b/src/video/videobuffer.cpp index cdaec56..9994874 100644 --- a/src/video/videobuffer.cpp +++ b/src/video/videobuffer.cpp @@ -156,6 +156,7 @@ void getALPRImages(cv::VideoCapture cap, VideoDispatcher* dispatcher) while (dispatcher->active) { + dispatcher->mMutex.lock(); bool hasImage = false; try { @@ -163,16 +164,15 @@ void getALPRImages(cv::VideoCapture cap, VideoDispatcher* dispatcher) // Double check the image to make sure it's valid. if (!frame.data || frame.empty()) { + dispatcher->mMutex.unlock(); std::stringstream ss; ss << "Stream " << dispatcher->mjpeg_url << " received invalid frame"; dispatcher->log_error(ss.str()); return; } - dispatcher->mMutex.lock(); dispatcher->setLatestFrame(&frame); - dispatcher->mMutex.unlock(); - } + } catch (const std::runtime_error& error) { // Error occured while trying to gather image. Retry, don't exit.