From dd2fd91964771ee3739d1a11fb01edcab4b2bd78 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Mon, 20 Jan 2020 15:52:04 +0200 Subject: [PATCH] Send and receive data channels --- applications/gui/src/src_window.cpp | 6 ++++++ applications/reconstruct/src/main.cpp | 1 + .../rgbd-sources/include/ftl/rgbd/frame.hpp | 10 ++++++++++ components/rgbd-sources/src/frame.cpp | 12 ++++++++++++ components/streams/src/receiver.cpp | 6 +++++- components/streams/src/sender.cpp | 19 +++++++++++++++++++ 6 files changed, 53 insertions(+), 1 deletion(-) diff --git a/applications/gui/src/src_window.cpp b/applications/gui/src/src_window.cpp index bb2105ce9..baa3a6f41 100644 --- a/applications/gui/src/src_window.cpp +++ b/applications/gui/src/src_window.cpp @@ -83,6 +83,12 @@ SourceWindow::SourceWindow(ftl::gui::Screen *screen) // Request the channels required by current camera configuration interceptor_->select(fs.id, _aggregateChannels()); + /*if (fs.frames[0].hasChannel(Channel::Data)) { + int data = 0; + fs.frames[0].get(Channel::Data, data); + LOG(INFO) << "GOT DATA : " << data; + }*/ + const auto *cstream = interceptor_; _createDefaultCameras(fs, cstream->available(fs.id).has(Channel::Depth)); diff --git a/applications/reconstruct/src/main.cpp b/applications/reconstruct/src/main.cpp index 9eabd9e0a..6d91839dc 100644 --- a/applications/reconstruct/src/main.cpp +++ b/applications/reconstruct/src/main.cpp @@ -188,6 +188,7 @@ static void run(ftl::Configurable *root) { reconstr->setGenerator(gen); reconstr->onFrameSet([sender,i](ftl::rgbd::FrameSet &fs) { fs.id = i; + //fs.frames[0].create(Channel::Data, 44); sender->post(fs); return true; }); diff --git a/components/rgbd-sources/include/ftl/rgbd/frame.hpp b/components/rgbd-sources/include/ftl/rgbd/frame.hpp index eb59f9393..69ed68746 100644 --- a/components/rgbd-sources/include/ftl/rgbd/frame.hpp +++ b/components/rgbd-sources/include/ftl/rgbd/frame.hpp @@ -284,6 +284,9 @@ public: * Obtain a mask of all available channels in the frame. */ inline ftl::codecs::Channels<0> getChannels() const { return channels_; } + inline ftl::codecs::Channels<0> getVideoChannels() const { return channels_; } + + inline ftl::codecs::Channels<2048> getDataChannels() const { return data_channels_; } /** * Is the channel data currently located on GPU. This also returns false if @@ -381,6 +384,13 @@ public: */ std::string getConfigString() const; + /** + * Access the raw data channel vector object. + */ + const std::vector<unsigned char> &getRawData(ftl::codecs::Channel c) const; + + void createRawData(ftl::codecs::Channel c, const std::vector<unsigned char> &v); + /** * Wrapper to access a config property. If the property does not exist or * is not of the requested type then the returned optional is false. diff --git a/components/rgbd-sources/src/frame.cpp b/components/rgbd-sources/src/frame.cpp index 4ed2b4351..6fb82e19e 100644 --- a/components/rgbd-sources/src/frame.cpp +++ b/components/rgbd-sources/src/frame.cpp @@ -443,3 +443,15 @@ std::string ftl::rgbd::Frame::getConfigString() const { return get<nlohmann::json>(ftl::codecs::Channel::Configuration).dump(); } +const std::vector<unsigned char> &ftl::rgbd::Frame::getRawData(ftl::codecs::Channel channel) const { + if (static_cast<int>(channel) < static_cast<int>(ftl::codecs::Channel::Data)) throw ftl::exception("Non data channel"); + if (!hasChannel(channel)) throw ftl::exception("Data channel does not exist"); + + return data_data_.at(static_cast<int>(channel)); +} + +void ftl::rgbd::Frame::createRawData(ftl::codecs::Channel c, const std::vector<unsigned char> &v) { + data_data_.insert({static_cast<int>(c), v}); + data_channels_ += c; +} + diff --git a/components/streams/src/receiver.cpp b/components/streams/src/receiver.cpp index ad74db5d7..5e525ea0f 100644 --- a/components/streams/src/receiver.cpp +++ b/components/streams/src/receiver.cpp @@ -103,7 +103,11 @@ void Receiver::setStream(ftl::stream::Stream *s) { //return; //} - if (channum >= 64) { + if (channum >= 2048) { + InternalStates &frame = _getFrame(spkt); + frame.frame.createRawData(spkt.channel, pkt.data); + return; + } else if (channum >= 64) { for (int i=0; i<pkt.frame_count; ++i) { InternalStates &frame = _getFrame(spkt,i); diff --git a/components/streams/src/sender.cpp b/components/streams/src/sender.cpp index 261c8b2fe..db7bb7c04 100644 --- a/components/streams/src/sender.cpp +++ b/components/streams/src/sender.cpp @@ -141,6 +141,25 @@ void Sender::post(const ftl::rgbd::FrameSet &fs) { available += c; } } + + // FIXME: Allow data channel selection rather than always send + for (auto c : frame.getDataChannels()) { + StreamPacket spkt; + spkt.version = 4; + spkt.timestamp = fs.timestamp; + spkt.streamID = 0; //fs.id; + spkt.frame_number = i; + spkt.channel = c; + + ftl::codecs::Packet pkt; + pkt.codec = ftl::codecs::codec_t::MSGPACK; + pkt.definition = ftl::codecs::definition_t::Any; + pkt.frame_count = 1; + pkt.flags = 0; + pkt.bitrate = 0; + pkt.data = frame.getRawData(c); + stream_->post(spkt, pkt); + } } for (auto c : available) { -- GitLab