#include "recordingformats.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include RecordingFormats::RecordingFormats(formats::Recording f) { QString tmp = QStandardPaths::writableLocation(QStandardPaths::TempLocation); if (tmp.isEmpty()) { validator = [](QSize) { return false; }; return; } tmpDir = QDir(tmp); QString name = QString("KShareTemp-") + QString::number(PlatformBackend::inst().pid()) + "-" + QTime::currentTime().toString(); tmpDir.mkdir(name); tmpDir.cd(name); iFormat = QImage::Format_RGB888; path = tmpDir.absoluteFilePath("res." + formats::recordingFormatName(f).toLower()); finalizer = [&] { delete enc; QFile res(path); if (!res.open(QFile::ReadOnly)) { return QByteArray(); } QByteArray data = res.readAll(); tmpDir.removeRecursively(); QScopedPointer(this); return data; }; validator = [&](QSize s) { if (!enc) { enc = new Encoder(path, s); if (!enc->isRunning()) { delete enc; return false; } } return true; }; consumer = [&](QImage img) { enc->addFrame(img); }; anotherFormat = formats::recordingFormatName(f); } std::function RecordingFormats::getConsumer() { return consumer; } std::function RecordingFormats::getFinalizer() { return finalizer; } std::function RecordingFormats::getValidator() { return validator; } QImage::Format RecordingFormats::getFormat() { return iFormat; } QString RecordingFormats::getAnotherFormat() { return anotherFormat; }