#include "recordingformats.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #include RecordingFormats::RecordingFormats(formats::Recording f) { if (!tmpDir.isValid()) { validator = [](QSize) { return false; }; qCritical().noquote() << "Could not create temporary directory. Error: " + tmpDir.errorString(); return; } iFormat = QImage::Format_RGB888; path = tmpDir.path() + "/res." + formats::recordingFormatName(f).toLower(); finalizer = [&] { delete enc; return QFile(path).size() > 0 ? path : QString(); }; validator = [&](QSize s) { if (!enc) { try { auto es = EncoderSettings::inst().getSettings(); enc = new Encoder(path, s, es); delete es; if (!enc->isRunning()) { delete enc; return false; } } catch (std::runtime_error &e) { qCritical() << "Encoder error: " << e.what(); interrupt = true; delete enc; return false; } } return !interrupt; }; consumer = [&](QImage img) { if (!interrupt) try { frameAdded = true; enc->addFrame(img); } catch (std::runtime_error &e) { qCritical() << "Encoder error: " << e.what(); interrupt = true; } }; postUploadTask = [&] { QScopedPointer th(this); }; anotherFormat = formats::recordingFormatName(f); } std::function RecordingFormats::getConsumer() { return consumer; } std::function RecordingFormats::getFinalizer() { return finalizer; } std::function RecordingFormats::getPostUploadTask() { return postUploadTask; } std::function RecordingFormats::getValidator() { return validator; } QImage::Format RecordingFormats::getFormat() { return iFormat; } QString RecordingFormats::getAnotherFormat() { return anotherFormat; }