[writer] thread
This commit is contained in:
parent
df27794dd5
commit
d336000553
43
writer.cpp
Normal file
43
writer.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
#include "writer.h"
|
||||
|
||||
void Writer::setVideoSpecs(VideoSpecs specs) {
|
||||
videoSpecs = specs;
|
||||
valid = true;
|
||||
}
|
||||
|
||||
void Writer::run() {
|
||||
if (valid) {
|
||||
stop_request = false;
|
||||
Pylon::CVideoWriter videoWriter;
|
||||
videoWriter.SetParameter(videoSpecs.width, videoSpecs.height, videoSpecs.pixelType,
|
||||
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) {
|
||||
count ++;
|
||||
Pylon::CPylonImage pyImage;
|
||||
try {
|
||||
pyImage.AttachUserBuffer(img.data(), videoSpecs.width * videoSpecs.height, videoSpecs.pixelType, videoSpecs.width, videoSpecs.height, 0, videoSpecs.orientation);
|
||||
videoWriter.Add( pyImage );
|
||||
} catch (const Pylon::GenericException &e) {
|
||||
std::cerr << "An exception occurred." << std::endl << e.GetDescription() << std::endl;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while (buffer->bufferLoad() < 5 && !stop_request) {
|
||||
msleep(10);
|
||||
std::cerr << "waiting.." << buffer->bufferLoad() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
videoWriter.Close();
|
||||
std::cerr << "writer terminated: " << count << std::endl;
|
||||
} else {
|
||||
std::cerr << "Got no video specifications, not writing!" << std::endl;
|
||||
}
|
||||
}
|
44
writer.h
Normal file
44
writer.h
Normal file
@ -0,0 +1,44 @@
|
||||
#ifndef WRITER_H
|
||||
#define WRITER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <pylon/PylonIncludes.h>
|
||||
#include "pylonwrapper.h"
|
||||
#include "imagebuffer.h"
|
||||
|
||||
struct VideoSpecs {
|
||||
std::string filename;
|
||||
uint32_t width, height, quality = 95;
|
||||
int fps;
|
||||
Pylon::EPixelType pixelType;
|
||||
Pylon::EImageOrientation orientation;
|
||||
};
|
||||
|
||||
class Writer : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit Writer(ImageBuffer*buffer, QObject *parent = nullptr) :
|
||||
QThread(parent), buffer(buffer) {}
|
||||
|
||||
void setVideoSpecs(VideoSpecs specs);
|
||||
void run() override;
|
||||
void stop();
|
||||
|
||||
private:
|
||||
ImageBuffer *buffer;
|
||||
VideoSpecs videoSpecs;
|
||||
bool stop_request = false;
|
||||
bool valid = false;
|
||||
|
||||
public slots:
|
||||
void requestStop() {
|
||||
stop_request=true;
|
||||
}
|
||||
|
||||
signals:
|
||||
void terminated();
|
||||
};
|
||||
|
||||
#endif // WRITER_H
|
Loading…
Reference in New Issue
Block a user