<commit_before>#ifndef OPENALPR_VIDEOBUFFER_H
#define OPENALPR_VIDEOBUFFER_H

#include <cstdio>

#include "opencv2/highgui/highgui.hpp"

#include "support/filesystem.h"
#include "support/tinythread.h"



class VideoDispatcher
{
  public:
    VideoDispatcher(std::string mjpeg_url, int fps)
    {
      this->active = true;
      this->latestFrameNumber = -1;
      this->lastFrameRead = -1;
      this->fps = fps;
      this->mjpeg_url = mjpeg_url;
    }
    
    
    int getLatestFrame(cv::Mat* frame)
    {
      if (latestFrameNumber == lastFrameRead)
	return -1;
      
      tthread::lock_guard<tthread::mutex> guard(mMutex);
      
      frame->create(latestFrame->size(), latestFrame->type());
      latestFrame->copyTo(*frame);
      
      this->lastFrameRead = this->latestFrameNumber;
      
      return this->lastFrameRead;
    }
    
    void setLatestFrame(cv::Mat* frame)
    {      
      this->latestFrame = frame;
      
      this->latestFrameNumber++;
    }
    
    bool active;
    
    int latestFrameNumber;
    int lastFrameRead;
    <commit_msg>Moved frame number counter to inside mutex<commit_after>#ifndef OPENALPR_VIDEOBUFFER_H
#define OPENALPR_VIDEOBUFFER_H

#include <cstdio>

#include "opencv2/highgui/highgui.hpp"

#include "support/filesystem.h"
#include "support/tinythread.h"



class VideoDispatcher
{
  public:
    VideoDispatcher(std::string mjpeg_url, int fps)
    {
      this->active = true;
      this->latestFrameNumber = -1;
      this->lastFrameRead = -1;
      this->fps = fps;
      this->mjpeg_url = mjpeg_url;
    }
    
    
    int getLatestFrame(cv::Mat* frame)
    {
      tthread::lock_guard<tthread::mutex> guard(mMutex);
      
      if (latestFrameNumber == lastFrameRead)
	return -1;
      
      frame->create(latestFrame->size(), latestFrame->type());
      latestFrame->copyTo(*frame);
      
      this->lastFrameRead = this->latestFrameNumber;
      
      return this->lastFrameRead;
    }
    
    void setLatestFrame(cv::Mat* frame)
    {      
      tthread::lock_guard<tthread::mutex> guard(mMutex);
      this->latestFrame = frame;
      
      this->latestFrameNumber++;
    }
    
    bool active;
    
    int latestFrameNumber;
    int lastFrameRead;
    
{'fraction_non_alphanumeric': 0.11603942652329749, 'fraction_numerical': 0.0035842293906810036, 'mean_word_length': 2.607431340872375, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2710905', 'n_tokens_mistral': 750, 'n_tokens_neox': 740, 'n_words': 124}