Add synchronization between nodes for videoplayer

This commit is contained in:
Ylva Selling
2023-02-22 14:56:14 -05:00
parent 5ac1bb89e1
commit 6f0b7fbb53
2 changed files with 36 additions and 6 deletions
+10 -1
View File
@@ -26,6 +26,7 @@
#define __OPENSPACE_MODULE_GLOBEBROWSING___TILEPROVIDER__VIDEOPLAYER___H__
#include <openspace/properties/propertyowner.h>
#include <openspace/util/syncable.h>
#include <openspace/documentation/documentation.h>
#include <openspace/properties/triggerproperty.h>
@@ -45,7 +46,7 @@ enum class PlaybackMode {
RealTimeLoop
};
class VideoPlayer : public properties::PropertyOwner {
class VideoPlayer : public properties::PropertyOwner, Syncable {
public:
VideoPlayer(const ghoul::Dictionary& dictionary);
~VideoPlayer();
@@ -64,6 +65,11 @@ public:
void reset();
void destroy();
virtual void preSync(bool isMaster) override;
virtual void encode(SyncBuffer* syncBuffer) override;
virtual void decode(SyncBuffer* syncBuffer) override;
virtual void postSync(bool isMaster) override;
documentation::Documentation Documentation();
private:
// Libmpv keys
@@ -128,6 +134,9 @@ private:
std::map<MpvKey, const char*> keys;
std::map<MpvKey, mpv_format> formats;
// Syncing with multiple nodes
double _correctPlaybackTime = 0.0;
// Video stretching: map to simulation time animation mode
double _startJ200Time = 0.0;
double _endJ200Time = 0.0;
+26 -5
View File
@@ -277,11 +277,6 @@ VideoPlayer::VideoPlayer(const ghoul::Dictionary& dictionary)
global::timeManager->addTimeJumpCallback([this]() {
seekToTime(correctVideoPlaybackTime());
});
// Ensure we are synchronized to OpenSpace time in presync step
global::callback::preSync->emplace_back([this]() {
syncToSimulationTime();
});
}
global::callback::postSyncPreDraw->emplace_back([this]() {
@@ -813,6 +808,29 @@ void VideoPlayer::destroy() {
glDeleteFramebuffers(1, &_fbo);
}
void VideoPlayer::preSync(bool isMaster) {
if (isMaster) {
syncToSimulationTime();
_correctPlaybackTime = _currentVideoTime;
}
}
void VideoPlayer::encode(SyncBuffer* syncBuffer) {
syncBuffer->encode(_correctPlaybackTime);
}
void VideoPlayer::decode(SyncBuffer* syncBuffer) {
syncBuffer->decode(_correctPlaybackTime);
}
void VideoPlayer::postSync(bool isMaster) {
if (!isMaster) {
if (abs(_currentVideoTime - _correctPlaybackTime) < glm::epsilon<double>()) {
seekToTime(_correctPlaybackTime);
}
}
}
const std::unique_ptr<ghoul::opengl::Texture>& VideoPlayer::frameTexture() const {
return _frameTexture;
}
@@ -856,6 +874,9 @@ double VideoPlayer::correctVideoPlaybackTime() const {
}
void VideoPlayer::syncToSimulationTime() {
if (!global::windowDelegate->isMaster()) {
return;
}
if (_playbackMode == PlaybackMode::MapToSimulationTime) {
// If we are in valid times, step frames accordingly
if (isWithingStartEndTime()) {