[threading] ensure threads are terminated before exiting
This commit is contained in:
parent
1381ceda53
commit
ffe4052832
@ -93,6 +93,14 @@ PylonRecorder::PylonRecorder(QWidget *parent)
|
||||
}
|
||||
|
||||
PylonRecorder::~PylonRecorder(){
|
||||
if (grabber->isRunning()) {
|
||||
grabber->requestStop();
|
||||
grabber->wait(1000);
|
||||
}
|
||||
if (writer->isRunning()) {
|
||||
writer->forceStop();
|
||||
writer->wait(1000);
|
||||
}
|
||||
delete pylon;
|
||||
delete buffer;
|
||||
delete grabber;
|
||||
|
@ -9,12 +9,13 @@ void Writer::run() {
|
||||
int64_t count = 0;
|
||||
if (valid) {
|
||||
stop_request = false;
|
||||
stopNow = false;
|
||||
Pylon::CVideoWriter videoWriter;
|
||||
videoWriter.SetParameter(videoSpecs.width, videoSpecs.height, videoSpecs.pixelType,
|
||||
videoSpecs.fps, videoSpecs.quality);
|
||||
videoWriter.Open(videoSpecs.filename.c_str());
|
||||
MyImage img;
|
||||
while (!stop_request || buffer->bufferLoad() > 0) {
|
||||
while ((!stop_request || buffer->bufferLoad() > 0) && !stopNow) {
|
||||
if (buffer->bufferLoad() > 0 ) {
|
||||
bool valid = buffer->pop(img);
|
||||
if (valid) {
|
||||
|
6
writer.h
6
writer.h
@ -33,13 +33,17 @@ signals:
|
||||
private:
|
||||
ImageBuffer *buffer;
|
||||
VideoSpecs videoSpecs;
|
||||
bool stop_request = false;
|
||||
bool stop_request = false, stopNow = false;
|
||||
bool valid = false;
|
||||
|
||||
public slots:
|
||||
void requestStop() {
|
||||
stop_request=true;
|
||||
}
|
||||
|
||||
void forceStop() {
|
||||
stopNow = true;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // WRITER_H
|
||||
|
Loading…
Reference in New Issue
Block a user