2017-06-04 01:04:42 +02:00
|
|
|
#include "recordingcontroller.hpp"
|
|
|
|
#include <QImage>
|
|
|
|
#include <QRect>
|
|
|
|
#include <QTimer>
|
|
|
|
#include <iostream>
|
|
|
|
#include <mainwindow.hpp>
|
|
|
|
#include <screenareaselector/screenareaselector.hpp>
|
|
|
|
#include <screenshotutil.hpp>
|
|
|
|
#include <settings.hpp>
|
|
|
|
#include <stdio.h>
|
2017-06-04 22:58:29 +02:00
|
|
|
#include <uploaders/uploadersingleton.hpp>
|
2017-06-04 01:04:42 +02:00
|
|
|
#include <worker/worker.hpp>
|
|
|
|
|
|
|
|
RecordingController::RecordingController() : timer(this) {
|
|
|
|
connect(&timer, &QTimer::timeout, this, &RecordingController::timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RecordingController::isRunning() {
|
2017-06-06 12:51:16 +02:00
|
|
|
return preview;
|
2017-06-04 01:04:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RecordingController::start(RecordingContext *context) {
|
|
|
|
if (isRunning()) return false;
|
|
|
|
if (_context) delete _context;
|
|
|
|
_context = context;
|
|
|
|
ScreenAreaSelector *sel = new ScreenAreaSelector;
|
|
|
|
connect(sel, &ScreenAreaSelector::selectedArea, this, &RecordingController::startWithArea);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RecordingController::end() {
|
|
|
|
if (!isRunning()) return false;
|
|
|
|
area = QRect();
|
2017-06-06 12:51:16 +02:00
|
|
|
if (preview) {
|
|
|
|
preview->close();
|
|
|
|
preview->deleteLater();
|
|
|
|
}
|
|
|
|
|
2017-06-04 01:04:42 +02:00
|
|
|
preview = 0;
|
2017-06-06 01:26:26 +02:00
|
|
|
WorkerContext *c = new WorkerContext;
|
2017-06-06 17:05:34 +02:00
|
|
|
c->consumer = [&](QImage) {
|
|
|
|
_QueueContext contx;
|
|
|
|
contx.arr = _context->finalizer();
|
|
|
|
contx.format = _context->anotherFormat;
|
|
|
|
queue(contx);
|
|
|
|
};
|
2017-06-06 01:26:26 +02:00
|
|
|
c->targetFormat = QImage::Format_Alpha8;
|
|
|
|
c->pixmap = QPixmap(0, 0);
|
2017-06-06 12:51:16 +02:00
|
|
|
Worker::queue(c);
|
2017-06-06 01:26:26 +02:00
|
|
|
|
2017-06-04 01:04:42 +02:00
|
|
|
frame = 0;
|
|
|
|
time = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-06-06 17:05:34 +02:00
|
|
|
void RecordingController::queue(_QueueContext arr) {
|
2017-06-06 01:26:26 +02:00
|
|
|
QMutexLocker l(&lock);
|
|
|
|
uploadQueue.enqueue(arr);
|
|
|
|
}
|
|
|
|
|
2017-06-04 01:04:42 +02:00
|
|
|
void RecordingController::timeout() {
|
|
|
|
if (isRunning()) {
|
2017-06-13 00:38:32 +02:00
|
|
|
if (!_context->validator(area.size())) {
|
2017-06-06 12:51:16 +02:00
|
|
|
if (preview) {
|
|
|
|
preview->close();
|
|
|
|
preview->deleteLater();
|
|
|
|
}
|
2017-06-06 01:26:26 +02:00
|
|
|
frame = 0;
|
|
|
|
time = 0;
|
|
|
|
preview = 0;
|
|
|
|
area = QRect();
|
2017-06-06 12:51:16 +02:00
|
|
|
return;
|
2017-06-06 01:26:26 +02:00
|
|
|
}
|
2017-06-04 01:04:42 +02:00
|
|
|
time++;
|
|
|
|
int localTime = time * timer.interval() - 3000;
|
|
|
|
if (localTime > 0) {
|
|
|
|
QPixmap *pp = screenshotutil::fullscreenArea(settings::settings().value("captureCursor", true).toBool(),
|
|
|
|
area.x(), area.y(), area.width(), area.height());
|
|
|
|
QScopedPointer<QPixmap> p(pp);
|
|
|
|
WorkerContext *context = new WorkerContext;
|
|
|
|
context->consumer = _context->consumer;
|
|
|
|
context->targetFormat = _context->format;
|
|
|
|
context->pixmap = *pp;
|
|
|
|
frame++;
|
|
|
|
preview->setPixmap(*pp);
|
|
|
|
Worker::queue(context);
|
|
|
|
}
|
|
|
|
long second = localTime / 1000 % 60;
|
|
|
|
long minute = localTime / 60000;
|
2017-06-06 12:51:16 +02:00
|
|
|
if (isRunning())
|
|
|
|
preview->setTime(QString("%1:%2").arg(QString::number(minute)).arg(QString::number(second)), frame);
|
2017-06-06 01:26:26 +02:00
|
|
|
} else {
|
|
|
|
QMutexLocker l(&lock);
|
2017-06-06 17:05:34 +02:00
|
|
|
if (!uploadQueue.isEmpty()) {
|
|
|
|
auto a = uploadQueue.dequeue();
|
|
|
|
UploaderSingleton::inst().upload(a.arr, a.format);
|
|
|
|
}
|
2017-06-04 01:04:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RecordingController::startWithArea(QRect newArea) {
|
|
|
|
area = newArea;
|
|
|
|
preview = new RecordingPreview(newArea);
|
|
|
|
timer.start(1000 / settings::settings().value("recording/framerate", 30).toInt());
|
|
|
|
}
|