diff --git a/imagebuffer.cpp b/imagebuffer.cpp index 2af6bfb..af9b3ef 100644 --- a/imagebuffer.cpp +++ b/imagebuffer.cpp @@ -33,7 +33,7 @@ void ImageBuffer::resize(size_t new_size) { buffer_size = new_size; buffer.clear(); buffer.resize(new_size); - current_read_index = -1; + current_read_index = 0; current_write_index = -1; load = 0; mutex.unlock(); @@ -46,7 +46,6 @@ void ImageBuffer::push(const MyImage &img) { if (load < static_cast(buffer.capacity())) load += 1; mutex.unlock(); - //std::cerr << "load: " << bufferLoad() << "\t pressure: " << bufferPreassure() << std::endl; } bool ImageBuffer::bufferNotEmpty() { @@ -61,9 +60,11 @@ bool ImageBuffer::pop(MyImage &img) { bool ret = false; mutex.lock(); if (load > 0) { + std::cerr << "Buffer.pop, load: " << load << " read_idx: " << current_read_index << " write_idx: " << current_write_index << std::endl; img = buffer[static_cast(current_read_index)]; static_cast(current_read_index) < (buffer.capacity() - 1) ? current_read_index += 1 : current_read_index = 0; load -= 1; + ret = true; } mutex.unlock(); return ret; diff --git a/imagebuffer.h b/imagebuffer.h index 8b272a3..2c8fad9 100644 --- a/imagebuffer.h +++ b/imagebuffer.h @@ -24,8 +24,6 @@ public: 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;