[Interest] QtConcurrent::run with lambdas
Jason H
jhihn at gmx.com
Tue Feb 27 16:47:58 CET 2018
I wish to achieve the following scenario in a QAbstractVideoSurface derived class called FrameHandler:
class FrameInfo {
public:
unsigned int frameNumber;
std::function<void(const FrameInfo &info)> frameFunction; // not sure this is right
QImage image;
};
class FrameHandler: public QAbstractVideoSurface {
std::function<void(const FrameInfo &info)> frameFunction;
FrameInfo *_currentFrameInfo;
FrameHandler(std::function<void(const FrameInfo &info)> func, QObject *parent = NULL);
...
};
bool FrameHandler::present(const QVideoFrame &frame) {
frameInfo = new FrameInfo;
frameInfo->frameFunction = frameFunction;
frameInfo->frameNumber = frameCount;
if (frame.pixelFormat() == QVideoFrame::Format_ARGB32) {
QVideoFrame frame2 = frame;
QSize size = frame2.size();
int bytes = frame.size().width() * frame.size().height() * 4; // 4=ARGB
frameInfo->image = QImage(size, QImage::Format_ARGB32);
frame2.map(QAbstractVideoBuffer::ReadOnly);
memcpy(_currentFrameInfo->image.bits(), frame2.bits(), bytes); // takes about 1280x720 takes ~750 usec on a MBP
frame2.unmap();
QFuture<void> future = QtConcurrent::run(frameFunction, frameInfo); // I can't find any way to pass these to work
// QFuture<void> future = QtConcurrent::run(frameInfo, &FrameInfo::frameFunction);
// QFuture<void> future = QtConcurrent::run(frameFunction, frameInfo);
QFuture<void> future = QtConcurrent::run(frameFunction, frameInfo);
}
}
// else where in the application (main.cpp) I'd like to do
FrameHandler saver([] {
QString filename = QString("test_%1.png").arg(info.frameNumber);
info.image(filename); // will run on another core because of QtConcurrent::run(), takes about 600ms due to PNG compression
});
How can I do this?
More information about the Interest
mailing list