Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jesustorresdev/26d8c5a0256b6f8d38ea9338a964f75b to your computer and use it in GitHub Desktop.
Save jesustorresdev/26d8c5a0256b6f8d38ea9338a964f75b to your computer and use it in GitHub Desktop.
class FiniteBuffer : public QObject
{
Q_OBJECT
public:
FiniteBuffer(int size);
~FiniteBuffer();
// Métodos de inserción y extracción para el productor y el
// consumidor, respectivamente.
void insertFrame(const QImage& frame);
QImage extractFrame();
private:
/* La cola de frames se puede construir con un array de C:
const int bufferSize_; // Tamaño de la cola
QImage[] buffer_; // Cola de frames como array de C
pero es más cómodo y menos propenso a errores usar QVector,
std::vector o estructuras de datos similares de C++ o Qt.
*/
QVector<QImage> buffer_; // Cola de frames
int bufferTail_; // Posición del último frame insertado
int bufferHead_; // Posición del último frame extraído
// Objetos de sincronización
QWaitCondition bufferNotEmpty_;
QMutex mutex_;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment