diff --git a/recording/recordingformats.cpp b/recording/recordingformats.cpp index 93b151f..2eceeb3 100644 --- a/recording/recordingformats.cpp +++ b/recording/recordingformats.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -15,7 +16,6 @@ RecordingFormats::RecordingFormats(formats::Recording f) { QString tmp = QStandardPaths::writableLocation(QStandardPaths::TempLocation); - if (tmp.isEmpty()) { validator = [](QSize) { return false; }; return; @@ -29,6 +29,10 @@ RecordingFormats::RecordingFormats(formats::Recording f) { path = tmpDir.absoluteFilePath("res." + formats::recordingFormatName(f).toLower()); finalizer = [&] { delete enc; + if (interrupt) { + tmpDir.removeRecursively(); + return; + } QFile res(path); if (!res.open(QFile::ReadOnly)) { return QByteArray(); @@ -40,15 +44,31 @@ RecordingFormats::RecordingFormats(formats::Recording f) { }; validator = [&](QSize s) { if (!enc) { - enc = new Encoder(path, s); - if (!enc->isRunning()) { + try { + enc = new Encoder(path, s); + if (!enc->isRunning()) { + delete enc; + return false; + } + } catch (std::runtime_error e) { + notifications::notify("KShare Video Encoder Error", e.what(), QSystemTrayIcon::Critical); + qCritical() << "Encoder error: " << e.what(); + interrupt = true; delete enc; return false; } } return true; }; - consumer = [&](QImage img) { enc->addFrame(img); }; + consumer = [&](QImage img) { + if (interrupt) try { + enc->addFrame(img); + } catch (std::runtime_error e) { + notifications::notify("KShare Video Encoder Error", e.what(), QSystemTrayIcon::Critical); + qCritical() << "Encoder error: " << e.what(); + interrupt = true; + } + }; anotherFormat = formats::recordingFormatName(f); } diff --git a/recording/recordingformats.hpp b/recording/recordingformats.hpp index 865724a..16e0cb6 100644 --- a/recording/recordingformats.hpp +++ b/recording/recordingformats.hpp @@ -28,6 +28,7 @@ private: QDir tmpDir; QString path; Encoder *enc = NULL; + bool interrupt = false; QString anotherFormat; };