Files
OpenVulkano/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.cpp
2021-06-21 16:12:31 +02:00

87 lines
2.1 KiB
C++

/*
* 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 <filesystem>
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<ArFrame> ArSessionPlayback::GetFrame()
{
try
{
if (playbackReader.HasNext())
{
std::shared_ptr<ArFrame> frame = std::make_shared<ArFramePlayback>(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();
OnSessionInterruptionChange(true);
return nullptr;
}
ArRecorder* ArSessionPlayback::GetRecorder()
{
return nullptr;
}
ArType ArSessionPlayback::GetArType()
{
return capabilities.GetArType();
}
}