mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 11:03:08 +02:00
Save clip to asset
This commit is contained in:
parent
a7d5ca92ca
commit
1b18d3656f
2 changed files with 65 additions and 0 deletions
|
@ -18,10 +18,15 @@
|
|||
#include <recording/Frame.h>
|
||||
#include <recording/ClipCache.h>
|
||||
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtWidgets/QFileDialog>
|
||||
|
||||
#include "ScriptEngineLogging.h"
|
||||
|
||||
using namespace recording;
|
||||
|
||||
static const QString HFR_EXTENSION = ".hfr";
|
||||
const QString URL_SCHEME_ATP = "atp";
|
||||
|
||||
RecordingScriptingInterface::RecordingScriptingInterface() {
|
||||
_player = DependencyManager::get<Deck>();
|
||||
|
@ -171,6 +176,57 @@ void RecordingScriptingInterface::saveRecording(const QString& filename) {
|
|||
recording::Clip::toFile(filename, _lastClip);
|
||||
}
|
||||
|
||||
bool RecordingScriptingInterface::saveRecordingToAsset(QScriptValue getClipAtpUrl) {
|
||||
|
||||
if (!getClipAtpUrl.isFunction())
|
||||
return false;
|
||||
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "saveRecordingToAsset", Qt::BlockingQueuedConnection,
|
||||
Q_ARG(QScriptValue, getClipAtpUrl));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_lastClip) {
|
||||
qWarning() << "There is no recording to save";
|
||||
return false;
|
||||
}
|
||||
|
||||
QString filename = "./temp.hfr";
|
||||
recording::Clip::toFile(filename, _lastClip);
|
||||
|
||||
QUrl url{ filename };
|
||||
|
||||
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
|
||||
|
||||
QObject::connect(upload, &AssetUpload::finished, this, [=](AssetUpload* upload, const QString& hash) mutable {
|
||||
auto filename = QFileInfo(upload->getFilename()).fileName();
|
||||
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 {
|
||||
AssetUploadDialogFactory::getInstance().handleUploadFinished(upload, hash);
|
||||
}
|
||||
|
||||
QScriptValueList args;
|
||||
args << clip_atp_url;
|
||||
getClipAtpUrl.call(QScriptValue(), args);
|
||||
});
|
||||
|
||||
// start the upload now
|
||||
upload->start();
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void RecordingScriptingInterface::loadLastRecording() {
|
||||
if (QThread::currentThread() != thread()) {
|
||||
QMetaObject::invokeMethod(this, "loadLastRecording", Qt::BlockingQueuedConnection);
|
||||
|
|
|
@ -18,6 +18,11 @@
|
|||
#include <recording/Forward.h>
|
||||
#include <recording/Frame.h>
|
||||
|
||||
#include <QtScript/QScriptValue>
|
||||
#include <AssetClient.h>
|
||||
#include <AssetUpload.h>
|
||||
#include "../../../interface/src/ui/AssetUploadDialogFactory.h"
|
||||
|
||||
class RecordingScriptingInterface : public QObject, public Dependency {
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -60,6 +65,7 @@ public slots:
|
|||
float recorderElapsed() const;
|
||||
|
||||
void saveRecording(const QString& filename);
|
||||
bool saveRecordingToAsset(QScriptValue getClipAtpUrl);
|
||||
void loadLastRecording();
|
||||
|
||||
protected:
|
||||
|
@ -76,6 +82,9 @@ protected:
|
|||
Flag _useAttachments { false };
|
||||
Flag _useSkeletonModel { false };
|
||||
recording::ClipPointer _lastClip;
|
||||
|
||||
private:
|
||||
void clipUploadFinished(AssetUpload* upload, const QString& hash);
|
||||
};
|
||||
|
||||
#endif // hifi_RecordingScriptingInterface_h
|
||||
|
|
Loading…
Reference in a new issue