mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:24:00 +02:00
Merge pull request #6444 from EdgarPironti/asset_branch
Save clip to asset
This commit is contained in:
commit
de56f698aa
2 changed files with 55 additions and 0 deletions
|
@ -18,10 +18,18 @@
|
|||
#include <recording/Frame.h>
|
||||
#include <recording/ClipCache.h>
|
||||
|
||||
|
||||
#include <QtScript/QScriptValue>
|
||||
#include <AssetClient.h>
|
||||
#include <AssetUpload.h>
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtWidgets/QFileDialog>
|
||||
|
||||
#include "ScriptEngineLogging.h"
|
||||
|
||||
using namespace recording;
|
||||
|
||||
static const QString HFR_EXTENSION = "hfr";
|
||||
|
||||
RecordingScriptingInterface::RecordingScriptingInterface() {
|
||||
_player = DependencyManager::get<Deck>();
|
||||
|
@ -171,6 +179,50 @@ void RecordingScriptingInterface::saveRecording(const QString& filename) {
|
|||
recording::Clip::toFile(filename, _lastClip);
|
||||
}
|
||||
|
||||
bool RecordingScriptingInterface::saveRecordingToAsset(QScriptValue getClipAtpUrl) {
|
||||
if (!getClipAtpUrl.isFunction()) {
|
||||
qCWarning(scriptengine) << "The argument is not a function.";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
if (QThread::currentThread() != thread()) {
|
||||
bool result{ false };
|
||||
QMetaObject::invokeMethod(this, "saveRecordingToAsset", Qt::BlockingQueuedConnection,
|
||||
Q_ARG(QScriptValue, getClipAtpUrl),
|
||||
Q_RETURN_ARG(bool, result));
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!_lastClip) {
|
||||
qWarning() << "There is no recording to save";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (auto upload = DependencyManager::get<AssetClient>()->createUpload(recording::Clip::toBuffer(_lastClip), HFR_EXTENSION)) {
|
||||
QObject::connect(upload, &AssetUpload::finished, this, [=](AssetUpload* upload, const QString& hash) mutable {
|
||||
QString clip_atp_url = "";
|
||||
|
||||
if (upload->getError() == AssetUpload::NoError) {
|
||||
|
||||
clip_atp_url = QString("%1:%2.%3").arg(URL_SCHEME_ATP, hash, upload->getExtension());
|
||||
upload->deleteLater();
|
||||
} else {
|
||||
qCWarning(scriptengine) << "Error during the Asset upload.";
|
||||
}
|
||||
|
||||
QScriptValueList args;
|
||||
args << clip_atp_url;
|
||||
getClipAtpUrl.call(QScriptValue(), args);
|
||||
});
|
||||
upload->start();
|
||||
return true;
|
||||
}
|
||||
|
||||
qCWarning(scriptengine) << "Saving on asset failed.";
|
||||
return false;
|
||||
}
|
||||
|
||||
void RecordingScriptingInterface::loadLastRecording() {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "loadLastRecording", Qt::BlockingQueuedConnection);
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include <recording/Forward.h>
|
||||
#include <recording/Frame.h>
|
||||
|
||||
class QScriptValue;
|
||||
|
||||
class RecordingScriptingInterface : public QObject, public Dependency {
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -60,6 +62,7 @@ public slots:
|
|||
float recorderElapsed() const;
|
||||
|
||||
void saveRecording(const QString& filename);
|
||||
bool saveRecordingToAsset(QScriptValue getClipAtpUrl);
|
||||
void loadLastRecording();
|
||||
|
||||
protected:
|
||||
|
|
Loading…
Reference in a new issue