6#include "videoscanner.h"
7#include "videoscannerframe_p.h"
8#include "videoscannerworker_p.h"
16class VideoScannerPrivate
19 void newFrame(
const QVideoFrame &videoFrame,
bool verticallyFlipped);
20 void setResult(VideoScanner *q,
const ScanResult &result);
22 QVideoSink *m_sink =
nullptr;
23 VideoScannerThread m_thread;
24 VideoScannerWorker m_worker;
25 QByteArray m_frameDataBuffer;
27 QVariant m_previousContent;
28 Format::BarcodeFormats m_formats = Format::NoFormat;
29 bool m_workerBusy =
false;
33void VideoScannerPrivate::newFrame(
const QVideoFrame &videoFrame,
bool verticallyFlipped)
36 if (!m_workerBusy && videoFrame.isValid()) {
39 VideoScannerFrame frame(videoFrame, verticallyFlipped, m_formats);
41 if (frame.copyRequired()) {
43 if (frame.needsConversion()) {
44 frame.convertToImage();
46 frame.copyFrameData(m_frameDataBuffer);
51 Q_EMIT m_worker.scanFrameRequest(frame);
58 if (m_result == result) {
65 if (m_previousContent == result.content()) {
68 m_previousContent = result.content();
72VideoScanner::VideoScanner(QObject *parent)
74 , d(new VideoScannerPrivate)
76 d->m_worker.moveToThread(&d->m_thread);
79 &VideoScannerWorker::result,
82 d->setResult(this, result);
86 d->m_thread.setObjectName(QStringLiteral(
"Prison Barcode Scanner Worker"));
90VideoScanner::~VideoScanner()
101Format::BarcodeFormats VideoScanner::formats()
const
108 if (d->m_formats == formats) {
112 d->m_formats = formats;
116QVideoSink *VideoScanner::videoSink()
const
123 if (d->m_sink == sink) {
128 disconnect(d->m_sink,
nullptr,
this,
nullptr);
131 connect(d->m_sink, &QVideoSink::videoFrameChanged,
this, [
this](
const QVideoFrame &frame) {
132 d->newFrame(frame, frame.surfaceFormat().scanLineDirection() == QVideoFrameFormat::BottomToTop);
134 Q_EMIT videoSinkChanged();
137#include "moc_videoscanner.cpp"
Result of a barcode scan attempt.
Scans a live video feed for barcodes.
void resultContentChanged(const Prison::ScanResult &scanResult)
Emitted when a barcode with a new content has been detected, but not when merely the position of a ba...
void setFormats(Format::BarcodeFormats formats)
Sets the barcode formats to detect.
void setVideoSink(QVideoSink *sink)
Sets the video sink to scan for barcodes.
void resultChanged(const Prison::ScanResult &scanResult)
Emitted whenever we get a new scan result, as long as any property of the result changes.
Provides classes and methods for generating barcodes.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)