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-06 01:26:26 +02:00
|
|
|
#include <gif-h/gif.h>
|
|
|
|
#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-06 17:05:34 +02:00
|
|
|
RecordingFormats::RecordingFormats(formats::Recording f) {
|
2017-06-13 01:15:57 +02:00
|
|
|
QString tmp = QStandardPaths::writableLocation(QStandardPaths::TempLocation);
|
2017-06-06 01:26:26 +02:00
|
|
|
|
2017-06-13 01:15:57 +02:00
|
|
|
if (tmp.isEmpty()) {
|
2017-06-13 00:38:32 +02:00
|
|
|
validator = [](QSize) { return false; };
|
2017-06-06 01:26:26 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-06-13 01:15:57 +02:00
|
|
|
tmpDir = QDir(tmp);
|
2017-06-06 01:26:26 +02:00
|
|
|
QString name
|
|
|
|
= QString("KShareTemp-") + QString::number(PlatformBackend::inst().pid()) + "-" + QTime::currentTime().toString();
|
|
|
|
tmpDir.mkdir(name);
|
|
|
|
tmpDir.cd(name);
|
2017-06-13 01:15:57 +02:00
|
|
|
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();
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
validator = [&](QSize s) {
|
|
|
|
if (!enc) {
|
|
|
|
enc = new Encoder(path, s);
|
|
|
|
if (!enc->isRunning()) {
|
|
|
|
delete enc;
|
|
|
|
return false;
|
2017-06-06 12:51:16 +02:00
|
|
|
}
|
2017-06-13 01:15:57 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
consumer = [&](QImage img) { enc->addFrame(img); };
|
|
|
|
anotherFormat = formats::recordingFormatName(f);
|
2017-06-04 22:58:29 +02:00
|
|
|
}
|
|
|
|
|
2017-06-13 00:38:32 +02:00
|
|
|
RecordingFormats::~RecordingFormats() {
|
|
|
|
tmpDir.removeRecursively();
|
|
|
|
}
|
|
|
|
|
2017-06-04 22:58:29 +02:00
|
|
|
std::function<void(QImage)> RecordingFormats::getConsumer() {
|
|
|
|
return consumer;
|
|
|
|
}
|
|
|
|
|
2017-06-04 23:04:35 +02:00
|
|
|
std::function<QByteArray()> RecordingFormats::getFinalizer() {
|
2017-06-04 22:58:29 +02:00
|
|
|
return finalizer;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|