Write duration and frame count to metadata file
This commit is contained in:
@@ -38,9 +38,7 @@ namespace OpenVulkano::AR
|
||||
|
||||
std::string GetFileName(size_t frameId, std::string_view fileExtension)
|
||||
{
|
||||
std::stringstream fnStream;
|
||||
fnStream << std::setw(7) << std::setfill('0') << frameId << '.' << fileExtension;
|
||||
return fnStream.str();
|
||||
return fmt::format("{:07d}.{}", frameId, fileExtension);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +50,10 @@ namespace OpenVulkano::AR
|
||||
session->OnNewFrameHighResolution += EventHandler(this, &ArRecorder::SaveHighResolution);
|
||||
}
|
||||
|
||||
ArRecorder::~ArRecorder() = default;
|
||||
ArRecorder::~ArRecorder()
|
||||
{
|
||||
if (!m_settings.asyncRecording) WriteMetadataFile();
|
||||
}
|
||||
|
||||
void ArRecorder::WriteColorImage(ArFrame* arFrame, MultiPartArchiveWriter* colorWriter, const std::filesystem::path* path, bool highRes) const
|
||||
{
|
||||
@@ -165,6 +166,7 @@ namespace OpenVulkano::AR
|
||||
WriteDepthImage(frame,
|
||||
useHighResWriter ? m_highResWriter.get() : m_depthWriter.get(),
|
||||
useHighResWriter ? m_highResWriter.get() : m_confidenceWriter.get());
|
||||
m_frameCount++;
|
||||
}
|
||||
|
||||
void ArRecorder::Start()
|
||||
@@ -178,23 +180,29 @@ namespace OpenVulkano::AR
|
||||
m_metadataWriter = std::make_unique<MultiPartArchiveWriter>(m_settings.path.string(), "meta_{:05d}.tar.gz", ArchiveConfig::TAR_GZ, m_settings.archiveSize * 10, true);
|
||||
m_highResWriter = std::make_unique<MultiPartArchiveWriter>(m_settings.path.string(), "highres_{:05d}.tar", ArchiveConfig::TAR, m_settings.archiveSize, true);
|
||||
|
||||
std::ofstream platformInfoStream(m_settings.path / ArSessionMetadata::RECORDING_METADATA_FILENAME);
|
||||
platformInfoStream << m_session->GetSessionMetadata().ToYaml();
|
||||
platformInfoStream.close();
|
||||
WriteMetadataFile();
|
||||
}
|
||||
m_recording = true;
|
||||
OnRecordingStateChanged(this, m_recording);
|
||||
m_timer.Start();
|
||||
}
|
||||
|
||||
void ArRecorder::SplitWriters()
|
||||
{
|
||||
for(MultiPartArchiveWriter* writer : { m_colorWriter.get(), m_depthWriter.get(), m_confidenceWriter.get(), m_metadataWriter.get(), m_highResWriter.get() })
|
||||
{
|
||||
writer->Split();
|
||||
}
|
||||
}
|
||||
|
||||
void ArRecorder::Stop()
|
||||
{
|
||||
if (!m_recording) return;
|
||||
m_recording = false;
|
||||
for(MultiPartArchiveWriter* writer : { m_colorWriter.get(), m_depthWriter.get(), m_confidenceWriter.get(), m_metadataWriter.get(), m_highResWriter.get() })
|
||||
{
|
||||
writer->Split();
|
||||
}
|
||||
OnRecordingStateChanged(this, m_recording);
|
||||
if (!m_settings.asyncRecording) SplitWriters();
|
||||
m_timer.Tick();
|
||||
m_timer.Start();
|
||||
}
|
||||
|
||||
void ArRecorder::SetRecordingPath(const std::filesystem::path& path)
|
||||
@@ -256,6 +264,17 @@ namespace OpenVulkano::AR
|
||||
WriteColorImage(frame.get(), nullptr, &path, !downsample);
|
||||
}
|
||||
|
||||
void ArRecorder::WriteMetadataFile()
|
||||
{
|
||||
m_timer.Tick();
|
||||
m_session->GetSessionMetadata().recFrameCount = m_frameCount;
|
||||
m_session->GetSessionMetadata().recSkippedFrames = m_skippedFrames;
|
||||
m_session->GetSessionMetadata().recDuration = static_cast<int32_t>(m_timer.GetTotalSeconds());
|
||||
std::ofstream platformInfoStream(m_settings.path / ArSessionMetadata::RECORDING_METADATA_FILENAME);
|
||||
platformInfoStream << m_session->GetSessionMetadata().ToYaml();
|
||||
platformInfoStream.close();
|
||||
}
|
||||
|
||||
//region AsyncProcessor
|
||||
ArRecorder::AsyncProcessor::AsyncProcessor(ArRecorder* recorder)
|
||||
: recorder(recorder), processingThread(&ArRecorder::AsyncProcessor::Handler, this)
|
||||
@@ -270,7 +289,7 @@ namespace OpenVulkano::AR
|
||||
|
||||
void ArRecorder::AsyncProcessor::Queue(const std::shared_ptr<ArFrame>& frame, bool highRes)
|
||||
{
|
||||
if (requestExit) return; // no need to queue up on shutdown
|
||||
if (requestExit || !recorder->m_recording) return; // no need to queue up on shutdown
|
||||
{
|
||||
std::unique_lock lock(queueMutex);
|
||||
if (highRes) highResFrameQueue.push(frame);
|
||||
@@ -302,6 +321,7 @@ namespace OpenVulkano::AR
|
||||
if (frameQueue.size() > 3)
|
||||
{
|
||||
Logger::AR->warn("Falling behind saving frames, skipping ...");
|
||||
recorder->m_skippedFrames++;
|
||||
//while(frameQueue.size() > 3) frameQueue.pop();
|
||||
}
|
||||
auto frame = std::move(frameQueue.front());
|
||||
@@ -311,8 +331,10 @@ namespace OpenVulkano::AR
|
||||
recorder->Write(frame.get(), false);
|
||||
lock.lock();
|
||||
}
|
||||
if (!recorder->m_recording) recorder->SplitWriters();
|
||||
}
|
||||
while (!requestExit);
|
||||
recorder->WriteMetadataFile();
|
||||
}
|
||||
//endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user