Skip to content
Snippets Groups Projects
Commit 22cfb88d authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Merge branch 'feature/sdkwrite' into 'master'

SDK memory fixes and pipelines

See merge request nicolas.pope/ftl!355
parents 54ac6917 c1be058f
No related branches found
No related tags found
1 merge request!355SDK memory fixes and pipelines
Pipeline #33742 passed
Showing
with 489 additions and 16 deletions
......@@ -6,6 +6,9 @@ add_library(voltu SHARED
private/image_impl.cpp
private/observer_impl.cpp
private/pointcloud_impl.cpp
private/pipeline_impl.cpp
private/operator_impl.cpp
private/property_impl.cpp
)
target_include_directories(voltu
......
#include "feed_impl.hpp"
#include <voltu/types/errors.hpp>
using voltu::internal::FeedImpl;
using voltu::internal::InputFeedImpl;
using voltu::internal::OutputFeedImpl;
FeedImpl::FeedImpl(ftl::stream::Feed* feed, uint32_t fsid)
// ==== Input ==================================================================
InputFeedImpl::InputFeedImpl(ftl::stream::Feed* feed, uint32_t fsid)
: feed_(feed)
{
fsids_.insert(fsid);
}
FeedImpl::~FeedImpl()
InputFeedImpl::~InputFeedImpl()
{
remove();
//remove();
}
std::string FeedImpl::getURI()
std::string InputFeedImpl::getURI()
{
return feed_->getURI(*fsids_.begin());
}
void FeedImpl::remove()
void InputFeedImpl::remove()
{
throw voltu::exceptions::NotImplemented();
}
void InputFeedImpl::submit(const voltu::FramePtr &frame)
{
throw voltu::exceptions::ReadOnly();
}
voltu::FeedType InputFeedImpl::type()
{
throw voltu::exceptions::NotImplemented();
}
voltu::PropertyPtr InputFeedImpl::property(voltu::FeedProperty)
{
throw voltu::exceptions::NotImplemented();
}
// ==== Output =================================================================
OutputFeedImpl::OutputFeedImpl(ftl::stream::Feed* feed, const std::string &uri)
: feed_(feed), uri_(uri)
{
}
OutputFeedImpl::~OutputFeedImpl()
{
//remove();
}
std::string OutputFeedImpl::getURI()
{
return uri_;
}
void OutputFeedImpl::remove()
{
throw voltu::exceptions::NotImplemented();
}
void OutputFeedImpl::submit(const voltu::FramePtr &frame)
{
throw voltu::exceptions::NotImplemented();
}
voltu::FeedType OutputFeedImpl::type()
{
throw voltu::exceptions::NotImplemented();
}
voltu::PropertyPtr OutputFeedImpl::property(voltu::FeedProperty)
{
throw voltu::exceptions::NotImplemented();
}
......@@ -9,20 +9,47 @@ namespace voltu
namespace internal
{
class FeedImpl : public voltu::Feed
class InputFeedImpl : public voltu::Feed
{
public:
FeedImpl(ftl::stream::Feed*, uint32_t fsid);
~FeedImpl();
InputFeedImpl(ftl::stream::Feed*, uint32_t fsid);
~InputFeedImpl() override;
std::string getURI() override;
void remove() override;
void submit(const voltu::FramePtr &frame) override;
voltu::FeedType type() override;
voltu::PropertyPtr property(voltu::FeedProperty) override;
private:
ftl::stream::Feed *feed_;
std::unordered_set<uint32_t> fsids_;
};
class OutputFeedImpl : public voltu::Feed
{
public:
OutputFeedImpl(ftl::stream::Feed*, const std::string &uri);
~OutputFeedImpl() override;
std::string getURI() override;
void remove() override;
void submit(const voltu::FramePtr &frame) override;
voltu::FeedType type() override;
voltu::PropertyPtr property(voltu::FeedProperty) override;
private:
ftl::stream::Feed *feed_;
std::string uri_;
};
}
}
......@@ -24,6 +24,7 @@ std::list<voltu::ImagePtr> FrameImpl::getImageSet(voltu::Channel c)
{
case voltu::Channel::kColour : channel = ftl::codecs::Channel::Colour; break;
case voltu::Channel::kDepth : channel = ftl::codecs::Channel::Depth; break;
case voltu::Channel::kNormals : channel = ftl::codecs::Channel::Normals; break;
default: throw voltu::exceptions::BadImageChannel();
}
......@@ -49,6 +50,25 @@ voltu::PointCloudPtr FrameImpl::getPointCloud(voltu::PointCloudFormat cloudfmt,
return nullptr;
}
std::vector<std::string> FrameImpl::getMessages()
{
std::vector<std::string> msgs;
for (const auto &fs : framesets_)
{
for (const auto &f : fs->frames)
{
if (f.hasChannel(ftl::codecs::Channel::Messages))
{
const auto &m = f.get<std::vector<std::string>>(ftl::codecs::Channel::Messages);
msgs.insert(msgs.end(), m.begin(), m.end());
}
}
}
return msgs;
}
void FrameImpl::pushFrameSet(const std::shared_ptr<ftl::data::FrameSet> &fs)
{
framesets_.push_back(fs);
......
......@@ -14,12 +14,14 @@ class FrameImpl : public voltu::Frame
{
public:
FrameImpl();
~FrameImpl();
~FrameImpl() override;
std::list<voltu::ImagePtr> getImageSet(voltu::Channel) override;
voltu::PointCloudPtr getPointCloud(voltu::PointCloudFormat cloudfmt, voltu::PointFormat pointfmt) override;
std::vector<std::string> getMessages() override;
int64_t getTimestamp() override;
void pushFrameSet(const std::shared_ptr<ftl::data::FrameSet> &fs);
......
......@@ -30,6 +30,10 @@ voltu::ImageData ImageImpl::getHost()
{
r.format = voltu::ImageFormat::kFloat32;
}
else if (m.type() == CV_16FC4)
{
r.format = voltu::ImageFormat::kFloat16_4;
}
return r;
}
......@@ -51,6 +55,10 @@ voltu::ImageData ImageImpl::getDevice()
{
r.format = voltu::ImageFormat::kFloat32;
}
else if (m.type() == CV_16FC4)
{
r.format = voltu::ImageFormat::kFloat16_4;
}
return r;
}
......@@ -66,6 +74,7 @@ voltu::Channel ImageImpl::getChannel()
{
case ftl::codecs::Channel::Colour : return voltu::Channel::kColour;
case ftl::codecs::Channel::Depth : return voltu::Channel::kDepth;
case ftl::codecs::Channel::Normals : return voltu::Channel::kNormals;
default: return voltu::Channel::kInvalid;
}
}
......
......@@ -12,7 +12,7 @@ class ImageImpl : public voltu::Image
{
public:
ImageImpl(const ftl::rgbd::Frame&, ftl::codecs::Channel c);
~ImageImpl();
~ImageImpl() override;
voltu::ImageData getHost() override;
......
......@@ -9,9 +9,10 @@ using voltu::internal::ObserverImpl;
using ftl::rgbd::Capability;
ObserverImpl::ObserverImpl(ftl::Configurable *base)
: id_(254) // FIXME: Allocate this
{
pool_ = new ftl::data::Pool(2,5);
rend_ = ftl::create<ftl::render::CUDARender>(base, "camN");
rend_ = ftl::create<ftl::render::CUDARender>(base, "camN"); // FIXME: Generate name properly
intrinsics_.fx = 700.0f;
intrinsics_.fy = 700.0f;
......@@ -28,7 +29,9 @@ ObserverImpl::ObserverImpl(ftl::Configurable *base)
ObserverImpl::~ObserverImpl()
{
frameset_.reset();
delete rend_;
delete pool_;
}
void ObserverImpl::setResolution(uint32_t w, uint32_t h)
......
......@@ -17,7 +17,7 @@ class ObserverImpl : public voltu::Observer
public:
explicit ObserverImpl(ftl::Configurable *base);
~ObserverImpl();
~ObserverImpl() override;
void setResolution(uint32_t w, uint32_t h) override;
......
#include "operator_impl.hpp"
#include "property_impl.hpp"
#include <voltu/types/errors.hpp>
using voltu::internal::OperatorImpl;
OperatorImpl::OperatorImpl(ftl::Configurable *cfg)
: cfg_(cfg)
{
}
OperatorImpl::~OperatorImpl()
{
}
voltu::PropertyPtr OperatorImpl::property(const std::string &name)
{
if (!cfg_->has(name)) throw voltu::exceptions::BadPropertyName();
return std::make_shared<voltu::internal::CfgPropertyImpl>(cfg_, name);
}
#pragma once
#include <voltu/operator.hpp>
#include <ftl/configurable.hpp>
#include <string>
namespace voltu
{
namespace internal
{
class OperatorImpl : public voltu::Operator
{
public:
OperatorImpl(ftl::Configurable*);
~OperatorImpl() override;
voltu::PropertyPtr property(const std::string &name) override;
private:
ftl::Configurable *cfg_;
};
}
}
\ No newline at end of file
#include "pipeline_impl.hpp"
#include "frame_impl.hpp"
#include "operator_impl.hpp"
#include <voltu/types/errors.hpp>
#include <ftl/operators/fusion.hpp>
#include <ftl/operators/gt_analysis.hpp>
using voltu::internal::PipelineImpl;
PipelineImpl::PipelineImpl(ftl::Configurable *root)
{
graph_ = ftl::create<ftl::operators::Graph>(root, "pipe1");
}
PipelineImpl::~PipelineImpl()
{
delete graph_;
}
void PipelineImpl::submit(const voltu::FramePtr &frame)
{
auto *fimp = dynamic_cast<voltu::internal::FrameImpl*>(frame.get());
if (!fimp)
{
throw voltu::exceptions::InvalidFrameObject();
}
const auto &sets = fimp->getInternalFrameSets();
if (sets.size() > 1) throw voltu::exceptions::IncompatibleOperation();
for (const auto &fs : sets)
{
ready_ = false;
graph_->queue(fs, [this]()
{
ready_ = true;
});
}
}
bool PipelineImpl::waitCompletion(int timeout)
{
int count = timeout / 5;
while (!ready_ && --count >= 0) std::this_thread::sleep_for(std::chrono::milliseconds(5));
return ready_;
}
voltu::OperatorPtr PipelineImpl::appendOperator(voltu::OperatorId id)
{
switch (id)
{
case voltu::OperatorId::kFusion : return std::make_shared<voltu::internal::OperatorImpl>(graph_->append<ftl::operators::Fusion>("fusion"));
case voltu::OperatorId::kGTEvaluator : return std::make_shared<voltu::internal::OperatorImpl>(graph_->append<ftl::operators::GTAnalysis>("gtanal"));
default: throw voltu::exceptions::NotImplemented();
}
}
\ No newline at end of file
#pragma once
#include <voltu/pipeline.hpp>
#include <ftl/operators/operator.hpp>
namespace voltu
{
namespace internal
{
class PipelineImpl : public voltu::Pipeline
{
public:
PipelineImpl(ftl::Configurable *root);
~PipelineImpl() override;
void submit(const voltu::FramePtr &frame) override;
bool waitCompletion(int timeout) override;
voltu::OperatorPtr appendOperator(voltu::OperatorId id) override;
private:
ftl::operators::Graph *graph_;
bool ready_ = false;
};
}
}
\ No newline at end of file
#include "property_impl.hpp"
#include <voltu/types/errors.hpp>
using voltu::internal::CfgPropertyImpl;
//using voltu::internal::FloatCfgProperty;
CfgPropertyImpl::CfgPropertyImpl(ftl::Configurable *cfg, const std::string &name)
: cfg_(cfg), name_(name)
{
}
CfgPropertyImpl::~CfgPropertyImpl()
{
}
void CfgPropertyImpl::setInt(int value)
{
if (cfg_->is<int>(name_))
{
cfg_->set(name_, value);
}
else
{
throw voltu::exceptions::BadPropertyType();
}
}
void CfgPropertyImpl::setFloat(float value)
{
if (cfg_->is<float>(name_))
{
cfg_->set(name_, value);
}
else
{
throw voltu::exceptions::BadPropertyType();
}
}
void CfgPropertyImpl::setString(const std::string &value)
{
if (cfg_->is<std::string>(name_))
{
cfg_->set(name_, value);
}
else
{
throw voltu::exceptions::BadPropertyType();
}
}
void CfgPropertyImpl::setBool(bool value)
{
if (cfg_->is<bool>(name_))
{
cfg_->set(name_, value);
}
else
{
throw voltu::exceptions::BadPropertyType();
}
}
int CfgPropertyImpl::getInt()
{
if (cfg_->is<int>(name_))
{
return *cfg_->get<int>(name_);
}
else
{
throw voltu::exceptions::BadPropertyType();
}
}
float CfgPropertyImpl::getFloat()
{
if (cfg_->is<float>(name_))
{
return *cfg_->get<float>(name_);
}
else
{
throw voltu::exceptions::BadPropertyType();
}
}
std::string CfgPropertyImpl::getString()
{
if (cfg_->is<std::string>(name_))
{
return *cfg_->get<std::string>(name_);
}
else
{
throw voltu::exceptions::BadPropertyType();
}
}
bool CfgPropertyImpl::getBool()
{
if (cfg_->is<bool>(name_))
{
return *cfg_->get<bool>(name_);
}
else
{
throw voltu::exceptions::BadPropertyType();
}
}
// ==== Float ====
/*FloatCfgProperty::FloatCfgProperty(ftl::Configurable *cfg, const std::string &name)
: CfgPropertyImpl(cfg, name)
{
}
FloatCfgProperty::~FloatCfgProperty()
{
}
void FloatCfgProperty::setFloat(float)
{
}
float FloatCfgProperty::getFloat()
{
}*/
#pragma once
#include <ftl/configurable.hpp>
#include <voltu/types/property.hpp>
#include <string>
namespace voltu
{
namespace internal
{
class CfgPropertyImpl : public voltu::Property
{
public:
CfgPropertyImpl(ftl::Configurable *cfg, const std::string &name);
virtual ~CfgPropertyImpl() override;
virtual void setInt(int) override;
virtual void setFloat(float) override;
virtual void setString(const std::string &) override;
virtual void setBool(bool) override;
virtual int getInt() override;
virtual float getFloat() override;
virtual std::string getString() override;
virtual bool getBool() override;
private:
ftl::Configurable *cfg_;
std::string name_;
};
/*class FloatCfgProperty : public CfgPropertyImpl
{
public:
FloatCfgProperty(ftl::Configurable *cfg, const std::string &name);
~FloatCfgProperty() override;
void setFloat(float) override;
float getFloat() override;
};*/
}
}
......@@ -11,6 +11,11 @@ RoomImpl::RoomImpl(ftl::stream::Feed* feed)
}
RoomImpl::~RoomImpl()
{
if (filter_) filter_->remove();
}
bool RoomImpl::waitNextFrame(int64_t timeout)
{
if (!filter_)
......
......@@ -14,6 +14,8 @@ class RoomImpl : public voltu::Room
public:
explicit RoomImpl(ftl::stream::Feed*);
~RoomImpl() override;
bool waitNextFrame(int64_t) override;
voltu::FramePtr getFrame() override;
......
......@@ -2,6 +2,7 @@
#include "feed_impl.hpp"
#include "room_impl.hpp"
#include "observer_impl.hpp"
#include "pipeline_impl.hpp"
#include <voltu/voltu.hpp>
#include <voltu/types/errors.hpp>
#include <ftl/timer.hpp>
......@@ -44,7 +45,11 @@ SystemImpl::SystemImpl()
SystemImpl::~SystemImpl()
{
ftl::timer::stop(true);
net_->shutdown();
ftl::pool.stop(true);
delete feed_;
delete net_;
delete root_;
}
voltu::Version SystemImpl::getVersion() const
......@@ -61,7 +66,7 @@ voltu::FeedPtr SystemImpl::open(const std::string& uri)
try
{
uint32_t fsid = feed_->add(uri);
return std::make_shared<voltu::internal::FeedImpl>(feed_, fsid);
return std::make_shared<voltu::internal::InputFeedImpl>(feed_, fsid);
}
catch(const std::exception &e)
{
......@@ -88,3 +93,13 @@ voltu::ObserverPtr SystemImpl::createObserver()
{
return std::make_shared<voltu::internal::ObserverImpl>(root_);
}
voltu::FeedPtr SystemImpl::createFeed(const std::string &uri)
{
return std::make_shared<voltu::internal::OutputFeedImpl>(feed_, uri);
}
voltu::PipelinePtr SystemImpl::createPipeline()
{
return std::make_shared<voltu::internal::PipelineImpl>(root_);
}
......@@ -14,7 +14,7 @@ class SystemImpl : public voltu::System
{
public:
SystemImpl();
~SystemImpl();
~SystemImpl() override;
voltu::Version getVersion() const override;
......@@ -28,6 +28,10 @@ public:
voltu::RoomPtr getRoom(voltu::RoomId) override;
voltu::FeedPtr createFeed(const std::string &uri) override;
voltu::PipelinePtr createPipeline() override;
private:
ftl::Configurable* root_;
ftl::stream::Feed* feed_;
......
......@@ -62,6 +62,11 @@ add_executable(voltu_basic_virtual_cam
)
target_link_libraries(voltu_basic_virtual_cam voltu_sdk)
add_executable(voltu_fusion_evaluator
samples/fusion_evaluator/main.cpp
)
target_link_libraries(voltu_fusion_evaluator voltu_sdk)
if (WITH_PYTHON)
add_subdirectory(ext/pybind11)
add_subdirectory(python)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment