/* * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ #include "ArSessionPlayback.h" #include "ArFramePlayback.hpp" #include "Base/Logger.hpp" #include namespace openVulkanoCpp::AR::Playback { ArSessionPlayback::ArSessionPlayback(const std::string& recordingPath, bool autoAdvance) : ArSession(ArSessionMetadata(recordingPath)), recordingPath(recordingPath), autoAdvance(autoAdvance), playbackReader(recordingPath) { capabilities = ArSessionCapabilities(metadata.type, ArSessionType::PLAYBACK, false, metadata.depthFormat != ArDepthFormat::UNAVAILABLE, false); constants = { Math::Matrix4f(1), metadata.confidenceRange }; } ArSessionPlayback::~ArSessionPlayback() = default; void ArSessionPlayback::Start() { running = true; } void ArSessionPlayback::Stop() { running = false; } void ArSessionPlayback::Pause() { running = false; } std::shared_ptr ArSessionPlayback::GetFrame() { try { if (playbackReader.HasNext()) { std::shared_ptr frame = std::make_shared(shared_from_this(), playbackReader); //if (lastTimestamp == frame->GetTimestamp()) return nullptr; lastTimestamp = frame->GetTimestamp(); // Trigger events OnNewFrame(frame); OnNewCameraTransformation(frame->GetCameraTransformation()); if (OnNewCameraViewMatrix.HasHandlers()) { auto view = frame->GetCameraViewForCurrentDeviceOrientation(); OnNewCameraViewMatrix(view); } if (playbackReader.HasNext()) { OnNewFrameAvailable(); } else { OnSessionInterruptionChange(true); } return frame; } } catch (const std::exception& e) { Logger::AR->error("Failed to read AR frame: {}", e.what()); } Stop(); return nullptr; } ArRecorder* ArSessionPlayback::GetRecorder() { return nullptr; } ArType ArSessionPlayback::GetArType() { return capabilities.GetArType(); } }