diff --git a/openVulkanoCpp/AR/ArRecorder.cpp b/openVulkanoCpp/AR/ArRecorder.cpp index 336c6a5..7c1a0a5 100644 --- a/openVulkanoCpp/AR/ArRecorder.cpp +++ b/openVulkanoCpp/AR/ArRecorder.cpp @@ -182,6 +182,7 @@ namespace OpenVulkano::AR platformInfoStream.close(); } m_recording = true; + OnRecordingStateChanged(this, m_recording); } void ArRecorder::Stop() @@ -192,6 +193,7 @@ namespace OpenVulkano::AR { writer->Split(); } + OnRecordingStateChanged(this, m_recording); } void ArRecorder::SetRecordingPath(const std::filesystem::path& path) diff --git a/openVulkanoCpp/AR/ArRecorder.hpp b/openVulkanoCpp/AR/ArRecorder.hpp index bd02b79..72723c8 100644 --- a/openVulkanoCpp/AR/ArRecorder.hpp +++ b/openVulkanoCpp/AR/ArRecorder.hpp @@ -7,6 +7,7 @@ #pragma once #include "Math/ByteSize.hpp" +#include "Base/Event.hpp" #include #include #include @@ -190,5 +191,7 @@ namespace OpenVulkano::AR const RecordingSettings& GetRecordingSettings() const { return m_settings; } void SetRecordHighResImages(bool recHighRes = true) { m_settings.saveHighResFrames = recHighRes; } + + Event OnRecordingStateChanged; }; } diff --git a/openVulkanoCpp/AR/Provider/Playback/ArPlaybackReader.hpp b/openVulkanoCpp/AR/Provider/Playback/ArPlaybackReader.hpp index 7644ee6..495297e 100644 --- a/openVulkanoCpp/AR/Provider/Playback/ArPlaybackReader.hpp +++ b/openVulkanoCpp/AR/Provider/Playback/ArPlaybackReader.hpp @@ -32,13 +32,15 @@ namespace OpenVulkano::AR::Playback static constexpr std::string_view TAR_EXTENSIONS_REGEX = R"(\.(tar(\.gz|\.bz2)?|tgz|tbz|tb2|tbz2))"; ArchiveReader m_archiveMetadata, m_archiveColor, m_archiveDepth, m_archiveConfidence; + size_t m_depthTotalSize = 0, m_depthReadSize = 0; + public: ArPlaybackReader(const std::string& recDir) { std::string extensions = R"((_\d+|\.part\d+)?)" + std::string(TAR_EXTENSIONS_REGEX); m_archiveMetadata.Open(recDir, ".*meta(data)?" + extensions); m_archiveColor.Open(recDir, ".*(color|image)" + extensions); - m_archiveDepth.Open(recDir, ".*depth" + extensions); + m_archiveDepth.Open(recDir, ".*depth" + extensions, &m_depthTotalSize); m_archiveConfidence.Open(recDir, ".*conf(idence)?" + extensions); } @@ -58,10 +60,17 @@ namespace OpenVulkano::AR::Playback DepthImage ReadDepthImage() { DepthImage img; - m_archiveDepth.GetNextFileAsStream([&img](const FileDescription&, std::istream& stream) { img.depth.Read(stream); }); + size_t& depthRead = m_depthReadSize; + m_archiveDepth.GetNextFileAsStream([&img, &depthRead](const FileDescription& desc, std::istream& stream) { img.depth.Read(stream); depthRead += desc.size + 1000; }); m_archiveConfidence.GetNextFileAsStream([&img](const FileDescription&, std::istream& stream) { img.confidence.Read(stream); }); + return img; } + + [[nodiscard]] double GetProgress() const + { + return static_cast(m_depthReadSize) / static_cast(m_depthTotalSize); + } [[nodiscard]] bool HasNext() const { diff --git a/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.cpp b/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.cpp index 480708e..1ea63d8 100644 --- a/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.cpp +++ b/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.cpp @@ -62,6 +62,7 @@ namespace OpenVulkano::AR::Playback void ArSessionPlayback::ReadWorker() { + Utils::SetThreadName("AR_Playback"); std::this_thread::sleep_for(128ms); // Delay startup of playback while (playbackReader.HasNext() && IsRunning()) { @@ -88,6 +89,7 @@ namespace OpenVulkano::AR::Playback auto view = frame->GetCameraViewForCurrentDeviceOrientation(); OnNewCameraViewMatrix(view); } + OnPlaybackProgress(playbackReader.GetProgress()); } catch (const std::exception& e) { diff --git a/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.hpp b/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.hpp index 6681124..aa3c75e 100644 --- a/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.hpp +++ b/openVulkanoCpp/AR/Provider/Playback/ArSessionPlayback.hpp @@ -31,7 +31,11 @@ class ArSessionPlayback final : public ArSession, public std::enable_shared_from [[nodiscard]] ArType GetArType() override; + [[nodiscard]] const std::string& GetPlaybackPath() const { return recordingPath; } + void SetRenderer(IRenderer* renderer) override; + + Event OnPlaybackProgress; protected: Scene::Texture * MakeTexture(OpenVulkano::AR::ArFrame *frame) override; diff --git a/openVulkanoCpp/IO/Archive/ArchiveReader.cpp b/openVulkanoCpp/IO/Archive/ArchiveReader.cpp index 1d028fb..6841685 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveReader.cpp +++ b/openVulkanoCpp/IO/Archive/ArchiveReader.cpp @@ -101,7 +101,7 @@ namespace OpenVulkano } } - bool ArchiveReader::Open(const std::filesystem::path& dir, const std::string& fileNamePattern) + bool ArchiveReader::Open(const std::filesystem::path& dir, const std::string& fileNamePattern, size_t* outSize) { std::vector files; @@ -109,9 +109,13 @@ namespace OpenVulkano for(const std::filesystem::directory_entry& dirEntry : std::filesystem::directory_iterator(dir)) { std::string entryPath = dirEntry.path().string(); - if (std::regex_match(entryPath, fileRegex)) + if (!dirEntry.is_directory() && std::regex_match(entryPath, fileRegex)) { files.push_back(std::move(entryPath)); + if (outSize) + { + *outSize += dirEntry.file_size(); + } } } diff --git a/openVulkanoCpp/IO/Archive/ArchiveReader.hpp b/openVulkanoCpp/IO/Archive/ArchiveReader.hpp index 89ce49c..776a57c 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveReader.hpp +++ b/openVulkanoCpp/IO/Archive/ArchiveReader.hpp @@ -42,7 +42,7 @@ namespace OpenVulkano bool Open(const std::vector& archiveFiles); - bool Open(const std::filesystem::path& dir, const std::string& fileNamePattern); + bool Open(const std::filesystem::path& dir, const std::string& fileNamePattern, size_t* outSize = nullptr); [[nodiscard]] bool IsOpen() const { return m_open; } diff --git a/openVulkanoCpp/IO/Archive/ArchiveWriter.cpp b/openVulkanoCpp/IO/Archive/ArchiveWriter.cpp index b9299d5..f32e281 100644 --- a/openVulkanoCpp/IO/Archive/ArchiveWriter.cpp +++ b/openVulkanoCpp/IO/Archive/ArchiveWriter.cpp @@ -36,7 +36,7 @@ namespace OpenVulkano ArchiveWriter::~ArchiveWriter() { if (m_asBuffer) { m_asBuffer->Close(); m_asBuffer = nullptr; } - archive_write_close(m_archive); + ChkErr(archive_write_close(m_archive)); archive_entry_free(m_archiveEntry); }