mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-22 02:48:25 -05:00
Add synchronization between nodes for videoplayer
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user