44 lines
903 B
C++
44 lines
903 B
C++
#ifndef IMAGEBUFFER_H
|
|
#define IMAGEBUFFER_H
|
|
|
|
#include <QMutex>
|
|
#include <QObject>
|
|
#include <QWaitCondition>
|
|
#include <myimage.h>
|
|
|
|
|
|
class ImageBuffer : public QObject
|
|
{
|
|
Q_OBJECT
|
|
public:
|
|
explicit ImageBuffer(size_t buffer_size=100, QObject *parent = nullptr);
|
|
|
|
void clear();
|
|
void resize(size_t new_size);
|
|
void push(const MyImage &img);
|
|
bool pop(MyImage &img);
|
|
bool readLast(MyImage &img);
|
|
size_t capacity();
|
|
double bufferPreassure();
|
|
int64_t bufferLoad();
|
|
bool bufferNotEmpty();
|
|
|
|
private:
|
|
// QWaitCondition bufferNotEmpty; // signals that the consumer can get data
|
|
// QWaitCondition bufferNotFull; // signals that the producer can store data
|
|
QMutex mutex;
|
|
int numUsedBytes = 0;
|
|
|
|
std::vector<MyImage> buffer;
|
|
int64_t current_write_index = -1;
|
|
int64_t current_read_index = 0;
|
|
int64_t load = 0;
|
|
size_t buffer_size;
|
|
|
|
signals:
|
|
|
|
public slots:
|
|
};
|
|
|
|
#endif // IMAGEBUFFER_H
|