KShare/recording/recordingformats.cpp

86 lines
2.3 KiB
C++
Raw Normal View History

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