Sync video with OpenSpace time

This commit is contained in:
Malin E
2022-12-21 10:31:12 +01:00
parent a2bbc44410
commit 4ba97bde52
2 changed files with 28 additions and 3 deletions

View File

@@ -327,7 +327,7 @@ void FfmpegTileProvider::update() {
}
// Check if we need to seek in the video
if (OSvideoTime - currentVideoTime > _frameTime) {
if (OSvideoTime - currentVideoTime > 2.0 * _frameTime) {
LINFO(fmt::format(
"Seek needed OS curr: {}, video curr: {}",
OSvideoTime, currentVideoTime
@@ -345,12 +345,36 @@ void FfmpegTileProvider::update() {
}
// Check if it is time for a new frame
if (currentVideoTime - _prevVideoTime < _frameTime) {
// Dont need a new frame just now
if (OSvideoTime - currentVideoTime < _frameTime) {
if (_isWaiting) {
return;
}
// Don't need a new frame just now
LINFO("Waiting..");
int setPauseTrue = 1;
result = mpv_set_property(_mpvHandle, "pause", MPV_FORMAT_FLAG, &setPauseTrue);
if (!checkMpvError(result)) {
LWARNING("Could not pause video");
}
_isWaiting = true;
return;
}
// If we get this far then we want a new frame
if (_isWaiting) {
LINFO("Un-waiting :)");
int setPauseFalse = 0;
result = mpv_set_property(_mpvHandle, "pause", MPV_FORMAT_FLAG, &setPauseFalse);
if (!checkMpvError(result)) {
LWARNING("Could not un-pause video");
}
_isWaiting = false;
}
_tileIsReady = false;
// Render video frame to texture

View File

@@ -82,6 +82,7 @@ private:
double _frameTime = 1.0 / 24.0;
bool _tileIsReady = false;
bool _isInitialized = false;
bool _isWaiting = false;
glm::ivec2 _resolution = { 2048, 1024 };
// libmpv