History

Save clip to asset

EdgarPironti committed 10 years ago

Commit 1b18d361 parent a7d5ca92 files · +65 −0Browse files

Showing the changes to libraries/script-engine/src/RecordingScriptingInterface.cpp (1 of 2 files). Show all

Unified · Split

libraries/script-engine/src/RecordingScriptingInterface.cpp+56−0
@@ -18,10 +18,15 @@ · 17 unmodified lines
18#include <recording/Frame.h>18#include <recording/Frame.h>
19#include <recording/ClipCache.h>19#include <recording/ClipCache.h>
20 20
21#include <QtCore/QUrl>
22#include <QtWidgets/QFileDialog>
23
21#include "ScriptEngineLogging.h"24#include "ScriptEngineLogging.h"
22 25
23using namespace recording;26using namespace recording;
24 27
28static const QString HFR_EXTENSION = ".hfr";
29const QString URL_SCHEME_ATP = "atp";
25 30
26RecordingScriptingInterface::RecordingScriptingInterface() {31RecordingScriptingInterface::RecordingScriptingInterface() {
27 _player = DependencyManager::get<Deck>();32 _player = DependencyManager::get<Deck>();
@@ -171,6 +176,57 @@ void RecordingScriptingInterface::saveRecording(const QString& filename) { · 143 unmodified lines
171 recording::Clip::toFile(filename, _lastClip);176 recording::Clip::toFile(filename, _lastClip);
172}177}
173 178
179bool 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
174void RecordingScriptingInterface::loadLastRecording() {230void RecordingScriptingInterface::loadLastRecording() {
175 if (QThread::currentThread() != thread()) {231 if (QThread::currentThread() != thread()) {
176 QMetaObject::invokeMethod(this, "loadLastRecording", Qt::BlockingQueuedConnection);232 QMetaObject::invokeMethod(this, "loadLastRecording", Qt::BlockingQueuedConnection);