From 5f19136fa401baf442f42878e7921b34bd4c34f0 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Sat, 15 Jun 2019 13:00:06 +0300 Subject: [PATCH] Get snapshot sources working --- components/rgbd-sources/src/snapshot_source.hpp | 4 ++-- components/rgbd-sources/src/source.cpp | 9 ++++++++- components/rgbd-sources/test/source_unit.cpp | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/components/rgbd-sources/src/snapshot_source.hpp b/components/rgbd-sources/src/snapshot_source.hpp index 3ba9a7f02..7b5b491fc 100644 --- a/components/rgbd-sources/src/snapshot_source.hpp +++ b/components/rgbd-sources/src/snapshot_source.hpp @@ -4,8 +4,8 @@ #include <loguru.hpp> -#include "ftl/rgbd/source.hpp" -#include "ftl/rgbd/snapshot.hpp" +#include <ftl/rgbd/source.hpp> +#include <ftl/rgbd/snapshot.hpp> namespace ftl { namespace rgbd { diff --git a/components/rgbd-sources/src/source.cpp b/components/rgbd-sources/src/source.cpp index 4c7379574..f050a1648 100644 --- a/components/rgbd-sources/src/source.cpp +++ b/components/rgbd-sources/src/source.cpp @@ -6,6 +6,7 @@ #include "image.hpp" #ifdef HAVE_LIBARCHIVE +#include <ftl/rgbd/snapshot.hpp> #include "snapshot_source.hpp" #endif @@ -101,8 +102,14 @@ ftl::rgbd::detail::Source *Source::_createFileImpl(const ftl::URI &uri) { return new ImageSource(this, path); } else if (ext == "mp4") { return new StereoVideoSource(this, path); - } else if (ext == "tar") { + } else if (ext == "tar" || ext == "gz") { +#ifdef HAVE_LIBARCHIVE + ftl::rgbd::SnapshotReader reader(path); + return new ftl::rgbd::detail::SnapshotSource(this, reader, "0"); // TODO Get ID from config +#else + LOG(ERROR) << "Cannot read snapshots, libarchive not installed"; return nullptr; +#endif // HAVE_LIBARCHIVE } else { LOG(WARNING) << "Unrecognised file type: " << path; } diff --git a/components/rgbd-sources/test/source_unit.cpp b/components/rgbd-sources/test/source_unit.cpp index 553d2ecbe..baea61824 100644 --- a/components/rgbd-sources/test/source_unit.cpp +++ b/components/rgbd-sources/test/source_unit.cpp @@ -9,6 +9,12 @@ static std::string last_type = ""; namespace ftl { namespace rgbd { + +class SnapshotReader { + public: + SnapshotReader(const std::string &) {} +}; + namespace detail { class ImageSource : public ftl::rgbd::detail::Source { @@ -47,6 +53,16 @@ class NetSource : public ftl::rgbd::detail::Source { bool isReady() { return true; }; }; +class SnapshotSource : public ftl::rgbd::detail::Source { + public: + SnapshotSource(ftl::rgbd::Source *host, ftl::rgbd::SnapshotReader &r, const std::string &) : ftl::rgbd::detail::Source(host) { + last_type = "snapshot"; + } + + bool grab() { return true; }; + bool isReady() { return true; }; +}; + class RealsenseSource : public ftl::rgbd::detail::Source { public: RealsenseSource(ftl::rgbd::Source *host) : ftl::rgbd::detail::Source(host) { @@ -66,6 +82,7 @@ class RealsenseSource : public ftl::rgbd::detail::Source { // Prevent these headers... #define _FTL_RGBD_STEREOVIDEO_HPP_ #define _FTL_RGBD_NET_HPP_ +#define _FTL_RGBD_SNAPSHOT_HPP_ #define _FTL_RGBD_SNAPSHOT_SOURCE_HPP_ #define _FTL_RGBD_IMAGE_HPP_ #define _FTL_RGBD_REALSENSE_HPP_ -- GitLab