fixed load meter during saving, writer emits signal when done

This commit is contained in:
Jan Grewe 2020-03-16 11:01:18 +01:00
parent 6a0570666e
commit 519b84064e
6 changed files with 29 additions and 9 deletions

View File

@ -60,7 +60,7 @@ 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;
// std::cerr << "Buffer.pop, load: " << load << " read_idx: " << current_read_index << " write_idx: " << current_write_index << std::endl;
img = buffer[static_cast<size_t>(current_read_index)];
static_cast<size_t>(current_read_index) < (buffer.capacity() - 1) ? current_read_index += 1 : current_read_index = 0;
load -= 1;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

After

Width:  |  Height:  |  Size: 7.0 KiB

View File

@ -40,10 +40,13 @@ PylonRecorder::PylonRecorder(QWidget *parent)
scrollArea->setWidget(imageLabel);
scrollArea->setVisible(false);
setCentralWidget(scrollArea);
pylon = new PylonWrapper();
buffer = new ImageBuffer(1000);
grabber = new Grabber(pylon, buffer);
writer = new Writer(buffer);
connect(writer, &Writer::writingDone, this, &PylonRecorder::writerDone);
createActions();
updateActions();
@ -61,8 +64,15 @@ PylonRecorder::PylonRecorder(QWidget *parent)
preassureBar->setPalette(progressPalette);
QLabel *preassureLabel = new QLabel("Buffer preassure:", this);
loadBar = new QProgressBar(this);
loadBar->setRange(0, 1000);
QLabel *loadLabel = new QLabel("Load:", this);
statusBar()->addWidget(preassureLabel);
statusBar()->addWidget(preassureBar);
statusBar()->addWidget(loadLabel);
statusBar()->addWidget(loadBar);
resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5);
}
@ -408,14 +418,18 @@ void PylonRecorder::startRecording() {
}
void PylonRecorder::stopRecording() {
frameTimer->stop();
grabber->requestStop();
writer->requestStop();
}
void PylonRecorder::writerDone() {
preassureTimer->stop();
preassureBar->reset();
loadBar->reset();
grabber->wait(10000);
writer->wait(10000);
grabbing = false;
frameTimer->stop();
preassureTimer->stop();
preassureBar->reset();
updateActions();
}
@ -448,6 +462,9 @@ void PylonRecorder::displayBufferPreassure() {
QColor color = progressColor(value);
progressPalette.setBrush(QPalette::Highlight, QBrush(color));
preassureBar->setPalette(progressPalette);
int load = static_cast<int>(buffer->bufferLoad());
loadBar->setValue(load);
}
void PylonRecorder::grabStillFromPylon() {

View File

@ -56,6 +56,7 @@ private slots:
void quitApplication();
void displaySingleFrame();
void displayBufferPreassure();
void writerDone();
private:
void createActions();
@ -74,6 +75,7 @@ private:
QTimer *preassureTimer;
QLabel *imageLabel;
QProgressBar *preassureBar;
QProgressBar *loadBar;
QScrollArea *scrollArea;
double scaleFactor = 1;
PylonWrapper *pylon;

View File

@ -6,6 +6,7 @@ void Writer::setVideoSpecs(VideoSpecs specs) {
}
void Writer::run() {
int64_t count = 0;
if (valid) {
stop_request = false;
Pylon::CVideoWriter videoWriter;
@ -13,9 +14,7 @@ void Writer::run() {
videoSpecs.fps, videoSpecs.quality);
videoWriter.Open(videoSpecs.filename.c_str());
MyImage img;
int64_t count = 0;
while (!stop_request || buffer->bufferLoad() > 0) {
std::cerr << "running!\n";
if (buffer->bufferLoad() > 0 ) {
bool valid = buffer->pop(img);
if (valid) {
@ -40,4 +39,5 @@ void Writer::run() {
} else {
std::cerr << "Got no video specifications, not writing!" << std::endl;
}
emit writingDone();
}

View File

@ -26,6 +26,10 @@ public:
void run() override;
void stop();
signals:
void terminated();
void writingDone();
private:
ImageBuffer *buffer;
VideoSpecs videoSpecs;
@ -36,9 +40,6 @@ public slots:
void requestStop() {
stop_request=true;
}
signals:
void terminated();
};
#endif // WRITER_H