Fix a recording dequeue bug

I was going so insane over it I made the system more efficient in the process of figuring out the bug
This commit is contained in:
ArsenArsen 2017-07-01 22:34:11 +02:00
parent ebb21d05b1
commit acdfb117a0
6 changed files with 23 additions and 22 deletions

View File

@ -42,7 +42,7 @@ bool RecordingController::end() {
WorkerContext *c = new WorkerContext;
c->consumer = [&](QImage) {
_QueueContext contx;
contx.arr = _context->finalizer();
contx.file = _context->finalizer();
contx.format = _context->anotherFormat;
contx.postUploadTask = _context->postUploadTask;
queue(contx);
@ -94,11 +94,13 @@ void RecordingController::timeout() {
if (isRunning())
preview->setTime(QString("%1:%2").arg(QString::number(minute)).arg(QString::number(second)), frame);
} else {
timer.stop();
QMutexLocker l(&lock);
if (!uploadQueue.isEmpty()) {
auto a = uploadQueue.dequeue();
UploaderSingleton::inst().upload(a.arr, a.format);
if (!a.file.isEmpty()) {
QFile f(a.file);
UploaderSingleton::inst().upload(f, a.format);
}
if (a.postUploadTask) a.postUploadTask();
}
}

View File

@ -16,13 +16,13 @@ struct RecordingContext {
QImage::Format format;
std::function<void(QImage)> consumer;
std::function<bool(QSize)> validator;
std::function<QByteArray()> finalizer;
std::function<QString()> finalizer;
std::function<void()> postUploadTask;
QString anotherFormat;
};
struct _QueueContext {
QByteArray arr;
QString file;
QString format;
std::function<void()> postUploadTask;
};

View File

@ -33,15 +33,9 @@ RecordingFormats::RecordingFormats(formats::Recording f) {
delete enc;
if (interrupt || !frameAdded) {
tmpDir.removeRecursively();
return QByteArray();
return QString();
}
QFile res(path);
if (!res.open(QFile::ReadOnly)) {
qCritical().noquote() << "Could not open resulting file: " << res.errorString();
return QByteArray();
}
QByteArray data = res.readAll();
return data;
return QFile(path).size() > 0 ? path : QString();
};
validator = [&](QSize s) {
if (!enc) {
@ -86,7 +80,7 @@ std::function<void(QImage)> RecordingFormats::getConsumer() {
return consumer;
}
std::function<QByteArray()> RecordingFormats::getFinalizer() {
std::function<QString()> RecordingFormats::getFinalizer() {
return finalizer;
}

View File

@ -15,7 +15,7 @@ public:
RecordingFormats(formats::Recording f);
std::function<void(QImage)> getConsumer();
std::function<bool(QSize)> getValidator();
std::function<QByteArray()> getFinalizer();
std::function<QString()> getFinalizer();
std::function<void()> getPostUploadTask();
QImage::Format getFormat();
QString getAnotherFormat();
@ -23,7 +23,7 @@ public:
private:
std::function<void(QImage)> consumer;
std::function<bool(QSize)> validator;
std::function<QByteArray()> finalizer;
std::function<QString()> finalizer;
std::function<void()> postUploadTask;
std::vector<QImage> frames;
QImage::Format iFormat;

View File

@ -90,11 +90,16 @@ void UploaderSingleton::upload(QByteArray img, QString format) {
uploaders.value(uploader)->doUpload(img, format);
}
void UploaderSingleton::upload(QFile img, QString format) {
if (img.open(QIODevice::ReadOnly)) {
uploaders.value(uploader)->doUpload(img.readAll(), format);
img.close();
}
void UploaderSingleton::upload(QFile &img, QString format) {
if (img.size() <= 0) return;
if (img.rename(
saveDir.absoluteFilePath(formatter::format(settings::settings().value("fileFormat").toString(), format.toLower())))) {
if (img.open(QFile::ReadWrite))
uploaders.value(uploader)->doUpload(img.readAll(), format);
else
notifications::notify("KShare - Failed to save picture", img.errorString(), QSystemTrayIcon::Warning);
} else
notifications::notify("KShare - Failed to save picture", img.errorString(), QSystemTrayIcon::Warning);
}
void UploaderSingleton::showSettings() {

View File

@ -15,7 +15,7 @@ public:
void registerUploader(Uploader *uploader);
void upload(QPixmap *pixmap);
void upload(QByteArray img, QString format);
void upload(QFile img, QString format);
void upload(QFile &img, QString format);
void showSettings();
QList<Uploader *> uploaderList();
void set(QString uploader);