2017-06-04 22:58:29 +02:00
|
|
|
#include "recordingformats.hpp"
|
|
|
|
|
2017-06-06 01:26:26 +02:00
|
|
|
#include <QBuffer>
|
|
|
|
#include <QDateTime>
|
2017-06-06 12:51:16 +02:00
|
|
|
#include <QDebug>
|
2017-06-06 01:26:26 +02:00
|
|
|
#include <QDir>
|
2017-06-04 22:58:29 +02:00
|
|
|
#include <QFile>
|
2017-06-06 01:26:26 +02:00
|
|
|
#include <QStandardPaths>
|
|
|
|
#include <QTimer>
|
2017-06-06 17:05:34 +02:00
|
|
|
#include <formats.hpp>
|
2017-06-13 14:15:37 +02:00
|
|
|
#include <notifications.hpp>
|
2017-06-06 01:26:26 +02:00
|
|
|
#include <platformbackend.hpp>
|
|
|
|
#include <settings.hpp>
|
|
|
|
#include <time.h>
|
2017-06-06 12:51:16 +02:00
|
|
|
#include <unistd.h>
|
2017-06-04 22:58:29 +02:00
|
|
|
|
2017-06-17 17:32:47 +02:00
|
|
|
#include <recording/encoders/encodersettings.hpp>
|
|
|
|
|
2017-06-06 17:05:34 +02:00
|
|
|
RecordingFormats::RecordingFormats(formats::Recording f) {
|
2017-07-10 16:33:04 +02:00
|
|
|
if (!tmpDir.isValid()) {
|
2017-06-13 00:38:32 +02:00
|
|
|
validator = [](QSize) { return false; };
|
2017-07-29 17:22:17 +02:00
|
|
|
qCritical().noquote() << tr("Could not create temporary directory. Error: ") + tmpDir.errorString();
|
2017-06-06 01:26:26 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-06-13 01:15:57 +02:00
|
|
|
iFormat = QImage::Format_RGB888;
|
2017-07-10 15:44:03 +02:00
|
|
|
path = tmpDir.path() + "/res." + formats::recordingFormatName(f).toLower();
|
2017-06-13 01:15:57 +02:00
|
|
|
finalizer = [&] {
|
|
|
|
delete enc;
|
2017-07-01 22:34:11 +02:00
|
|
|
return QFile(path).size() > 0 ? path : QString();
|
2017-06-13 01:15:57 +02:00
|
|
|
};
|
|
|
|
validator = [&](QSize s) {
|
|
|
|
if (!enc) {
|
2017-06-13 14:15:37 +02:00
|
|
|
try {
|
2017-06-17 17:32:47 +02:00
|
|
|
auto es = EncoderSettings::inst().getSettings();
|
|
|
|
enc = new Encoder(path, s, es);
|
|
|
|
delete es;
|
2017-06-13 14:15:37 +02:00
|
|
|
if (!enc->isRunning()) {
|
|
|
|
delete enc;
|
|
|
|
return false;
|
|
|
|
}
|
2017-06-30 15:05:37 +02:00
|
|
|
} catch (std::runtime_error &e) {
|
2017-07-29 17:22:17 +02:00
|
|
|
qCritical() << tr("Encoder error: ") << e.what();
|
2017-06-13 14:15:37 +02:00
|
|
|
interrupt = true;
|
2017-06-13 01:15:57 +02:00
|
|
|
delete enc;
|
|
|
|
return false;
|
2017-06-06 12:51:16 +02:00
|
|
|
}
|
2017-06-13 01:15:57 +02:00
|
|
|
}
|
2017-06-17 17:32:47 +02:00
|
|
|
return !interrupt;
|
2017-06-13 01:15:57 +02:00
|
|
|
};
|
2017-06-13 14:15:37 +02:00
|
|
|
consumer = [&](QImage img) {
|
2017-06-13 18:23:33 +02:00
|
|
|
if (!interrupt) try {
|
2017-06-28 11:12:34 +02:00
|
|
|
frameAdded = true;
|
2017-06-13 14:15:37 +02:00
|
|
|
enc->addFrame(img);
|
2017-06-30 15:05:37 +02:00
|
|
|
} catch (std::runtime_error &e) {
|
2017-07-29 17:22:17 +02:00
|
|
|
qCritical() << tr("Encoder error: ") << e.what();
|
2017-06-13 14:15:37 +02:00
|
|
|
interrupt = true;
|
|
|
|
}
|
|
|
|
};
|
2017-07-09 21:04:21 +02:00
|
|
|
postUploadTask = [&] { QScopedPointer<RecordingFormats> th(this); };
|
2017-06-13 01:15:57 +02:00
|
|
|
anotherFormat = formats::recordingFormatName(f);
|
2017-06-04 22:58:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::function<void(QImage)> RecordingFormats::getConsumer() {
|
|
|
|
return consumer;
|
|
|
|
}
|
|
|
|
|
2017-07-01 22:34:11 +02:00
|
|
|
std::function<QString()> RecordingFormats::getFinalizer() {
|
2017-06-04 22:58:29 +02:00
|
|
|
return finalizer;
|
|
|
|
}
|
|
|
|
|
2017-06-13 18:23:33 +02:00
|
|
|
std::function<void()> RecordingFormats::getPostUploadTask() {
|
|
|
|
return postUploadTask;
|
|
|
|
}
|
|
|
|
|
2017-06-13 00:38:32 +02:00
|
|
|
std::function<bool(QSize)> RecordingFormats::getValidator() {
|
2017-06-06 01:26:26 +02:00
|
|
|
return validator;
|
|
|
|
}
|
|
|
|
|
|
|
|
QImage::Format RecordingFormats::getFormat() {
|
|
|
|
return iFormat;
|
|
|
|
}
|
|
|
|
|
2017-06-06 17:05:34 +02:00
|
|
|
QString RecordingFormats::getAnotherFormat() {
|
|
|
|
return anotherFormat;
|
2017-06-04 22:58:29 +02:00
|
|
|
}
|