Showing the changes to libraries/script-engine/src/RecordingScriptingInterface.cpp (1 of 2 files). Show all
Unified · Split
| @@ -18,10 +18,15 @@ · 17 unmodified lines | ||
| 18 | 18 | #include <recording/Frame.h> |
| 19 | 19 | #include <recording/ClipCache.h> |
| 20 | 20 | |
| 21 | +#include <QtCore/QUrl> | |
| 22 | +#include <QtWidgets/QFileDialog> | |
| 23 | + | |
| 21 | 24 | #include "ScriptEngineLogging.h" |
| 22 | 25 | |
| 23 | 26 | using namespace recording; |
| 24 | 27 | |
| 28 | +static const QString HFR_EXTENSION = ".hfr"; | |
| 29 | +const QString URL_SCHEME_ATP = "atp"; | |
| 25 | 30 | |
| 26 | 31 | RecordingScriptingInterface::RecordingScriptingInterface() { |
| 27 | 32 | _player = DependencyManager::get<Deck>(); |
| @@ -171,6 +176,57 @@ void RecordingScriptingInterface::saveRecording(const QString& filename) { · 143 unmodified lines | ||
| 171 | 176 | recording::Clip::toFile(filename, _lastClip); |
| 172 | 177 | } |
| 173 | 178 | |
| 179 | +bool RecordingScriptingInterface::saveRecordingToAsset(QScriptValue getClipAtpUrl) { | |
| 180 | + | |
| 181 | + if (!getClipAtpUrl.isFunction()) | |
| 182 | + return false; | |
| 183 | + | |
| 184 | + if (QThread::currentThread() != thread()) { | |
| 185 | + QMetaObject::invokeMethod(this, "saveRecordingToAsset", Qt::BlockingQueuedConnection, | |
| 186 | + Q_ARG(QScriptValue, getClipAtpUrl)); | |
| 187 | + return false; | |
| 188 | + } | |
| 189 | + | |
| 190 | + if (!_lastClip) { | |
| 191 | + qWarning() << "There is no recording to save"; | |
| 192 | + return false; | |
| 193 | + } | |
| 194 | + | |
| 195 | + QString filename = "./temp.hfr"; | |
| 196 | + recording::Clip::toFile(filename, _lastClip); | |
| 197 | + | |
| 198 | + QUrl url{ filename }; | |
| 199 | + | |
| 200 | + if (auto upload = DependencyManager::get<AssetClient>()->createUpload(url.toLocalFile())) { // Here we should use the other implementation of createUpload, but we need the QByteArray of the _lastClip | |
| 201 | + | |
| 202 | + QObject::connect(upload, &AssetUpload::finished, this, [=](AssetUpload* upload, const QString& hash) mutable { | |
| 203 | + auto filename = QFileInfo(upload->getFilename()).fileName(); | |
| 204 | + QString clip_atp_url = ""; | |
| 205 | + | |
| 206 | + if (upload->getError() == AssetUpload::NoError) { | |
| 207 | + | |
| 208 | + clip_atp_url = QString("%1:%2.%3").arg(URL_SCHEME_ATP, hash, upload->getExtension()); | |
| 209 | + upload->deleteLater(); | |
| 210 | + } else { | |
| 211 | + AssetUploadDialogFactory::getInstance().handleUploadFinished(upload, hash); | |
| 212 | + } | |
| 213 | + | |
| 214 | + QScriptValueList args; | |
| 215 | + args << clip_atp_url; | |
| 216 | + getClipAtpUrl.call(QScriptValue(), args); | |
| 217 | + }); | |
| 218 | + | |
| 219 | + // start the upload now | |
| 220 | + upload->start(); | |
| 221 | + return true; | |
| 222 | + | |
| 223 | + } | |
| 224 | + | |
| 225 | + return false; | |
| 226 | + | |
| 227 | +} | |
| 228 | + | |
| 229 | + | |
| 174 | 230 | void RecordingScriptingInterface::loadLastRecording() { |
| 175 | 231 | if (QThread::currentThread() != thread()) { |
| 176 | 232 | QMetaObject::invokeMethod(this, "loadLastRecording", Qt::BlockingQueuedConnection); |