Use async save for SaveToFile and add option to include all ar metadata

This commit is contained in:
Georg Hagen
2025-05-19 15:53:04 +02:00
parent 369528c170
commit 31bd94f939
4 changed files with 63 additions and 16 deletions

View File

@@ -9,6 +9,7 @@
#include "Math/ByteSize.hpp"
#include "Base/Event.hpp"
#include "Base/Timer.hpp"
#include "Base/Wrapper.hpp"
#include <atomic>
#include <condition_variable>
#include <filesystem>
@@ -21,6 +22,7 @@
namespace OpenVulkano
{
class IEventHandler;
class IArchiveWriter;
class MultiPartArchiveWriter;
}
@@ -58,11 +60,19 @@ namespace OpenVulkano::AR
class ArRecorder final
{
struct SaveToFileRequest final
{
Ptr<ArFrame> frame;
std::filesystem::path path;
bool downsample, addAux;
};
struct AsyncProcessor final
{
ArRecorder* recorder;
std::thread processingThread;
std::queue<std::shared_ptr<ArFrame>> frameQueue, highResFrameQueue;
std::queue<Ptr<ArFrame>> frameQueue, highResFrameQueue;
std::queue<SaveToFileRequest> toFile;
std::mutex queueMutex;
std::condition_variable newDataAvailable;
std::atomic_bool requestExit{};
@@ -70,8 +80,10 @@ namespace OpenVulkano::AR
explicit AsyncProcessor(ArRecorder* recorder);
~AsyncProcessor();
void Close();
void Queue(const std::shared_ptr<ArFrame>& frame, bool highRes);
void Queue(const Ptr<ArFrame>& frame, bool highRes);
void Queue(const Ptr<ArFrame>& frame, const std::filesystem::path& path, bool downsample, bool aux);
void Handler();
bool Empty() { return frameQueue.empty() && highResFrameQueue.empty() && toFile.empty(); }
};
ArSession* m_session;
@@ -87,9 +99,10 @@ namespace OpenVulkano::AR
AsyncProcessor m_asyncProcessor;
void Write(ArFrame* frame, bool highRes = false);
void WriteMetadata(ArFrame* frame, MultiPartArchiveWriter* metaWriter);
void WriteColorImage(ArFrame* arFrame, MultiPartArchiveWriter* colorWriter, const std::filesystem::path* path, bool highRes) const;
void WriteDepthImage(ArFrame *arFrame, MultiPartArchiveWriter* depthWriter, MultiPartArchiveWriter* confWriter);
void WriteMetadata(ArFrame* frame, IArchiveWriter* metaWriter);
void WriteColorImage(ArFrame* arFrame, IArchiveWriter* colorWriter, const std::filesystem::path* path, bool highRes) const;
void WriteDepthImage(ArFrame *arFrame, IArchiveWriter* depthWriter, IArchiveWriter* confWriter);
void WriteToFile(const std::shared_ptr<ArFrame>& frame, const std::filesystem::path& path, bool downsample, bool saveAux);
void SplitWriters();
void WriteMetadataFile();
@@ -103,7 +116,7 @@ namespace OpenVulkano::AR
void SaveHighResolution(const std::shared_ptr<ArFrame>& frame);
void SaveToFile(const std::shared_ptr<ArFrame>& frame, const std::filesystem::path& path, bool downsample = false);
void SaveToFile(const std::shared_ptr<ArFrame>& frame, const std::filesystem::path& path, bool downsample = false, bool saveAux = true);
/**
* Starts the recording of the owning AR session