Skip to content

Commit

Permalink
removed wirehair repair symbol additions
Browse files Browse the repository at this point in the history
  • Loading branch information
klaxalk committed Oct 11, 2023
1 parent 695b342 commit b73ea32
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 87 deletions.
4 changes: 0 additions & 4 deletions nimbro_topic_transport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")

add_library(nimbro_topic_transport
contrib/wirehair/wirehair.cpp
contrib/wirehair/gf256.cpp
contrib/wirehair/WirehairCodec.cpp
contrib/wirehair/WirehairTools.cpp
src/sender/compressor.cpp
src/sender/get_route.cpp
src/sender/packetizer.cpp
Expand Down
78 changes: 39 additions & 39 deletions nimbro_topic_transport/src/receiver/depacketizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <ros/console.h>

#include <wirehair/wirehair.h>
/* #include <wirehair/wirehair.h> */

#include "../topic_info.h"

Expand Down Expand Up @@ -67,43 +67,43 @@ void Depacketizer::handleMessagePacket(std::list<PartialMessage>::iterator it, c
std::vector<uint8_t> recoveredData;

// Do we need to do FEC decoding?
if(header.repair_symbols())
{
if(header.source_symbols() > 1)
{
if(!msg->decoder)
{
msg->decoder.reset(wirehair_decoder_create(nullptr, header.source_symbols() * UDPPacket::MaxDataSize, UDPPacket::MaxDataSize), wirehair_free);
}

WirehairResult res = wirehair_decode(msg->decoder.get(), header.symbol_id, packet->packet()->data, packet->length - sizeof(UDPPacket::Header));
if(res == Wirehair_NeedMore)
return;

if(res != Wirehair_Success)
{
ROS_ERROR("Wirehair decode() error: %s", wirehair_result_string(res));
ROS_ERROR(" ^- on packet with symbol_id=%u, length=%lu", header.symbol_id(), packet->length);
ROS_ERROR(" ^- source_symbols=%u, repair_symbols=%u", header.source_symbols(), header.repair_symbols());
return;
}

recoveredData.resize(header.source_symbols() * UDPPacket::MaxDataSize);
res = wirehair_recover(msg->decoder.get(), recoveredData.data(), recoveredData.size());
if(res != Wirehair_Success)
{
ROS_ERROR("Wirehair recover() error: %s", wirehair_result_string(res));
return;
}
}
else
{
recoveredData.resize(packet->length - sizeof(UDPPacket::Header));
memcpy(recoveredData.data(), packet->packet()->data, packet->length - sizeof(UDPPacket::Header));
}
}
else
{
/* if(header.repair_symbols()) */
/* { */
/* if(header.source_symbols() > 1) */
/* { */
/* if(!msg->decoder) */
/* { */
/* msg->decoder.reset(wirehair_decoder_create(nullptr, header.source_symbols() * UDPPacket::MaxDataSize, UDPPacket::MaxDataSize), wirehair_free); */
/* } */

/* WirehairResult res = wirehair_decode(msg->decoder.get(), header.symbol_id, packet->packet()->data, packet->length - sizeof(UDPPacket::Header)); */
/* if(res == Wirehair_NeedMore) */
/* return; */

/* if(res != Wirehair_Success) */
/* { */
/* ROS_ERROR("Wirehair decode() error: %s", wirehair_result_string(res)); */
/* ROS_ERROR(" ^- on packet with symbol_id=%u, length=%lu", header.symbol_id(), packet->length); */
/* ROS_ERROR(" ^- source_symbols=%u, repair_symbols=%u", header.source_symbols(), header.repair_symbols()); */
/* return; */
/* } */

/* recoveredData.resize(header.source_symbols() * UDPPacket::MaxDataSize); */
/* res = wirehair_recover(msg->decoder.get(), recoveredData.data(), recoveredData.size()); */
/* if(res != Wirehair_Success) */
/* { */
/* ROS_ERROR("Wirehair recover() error: %s", wirehair_result_string(res)); */
/* return; */
/* } */
/* } */
/* else */
/* { */
/* recoveredData.resize(packet->length - sizeof(UDPPacket::Header)); */
/* memcpy(recoveredData.data(), packet->packet()->data, packet->length - sizeof(UDPPacket::Header)); */
/* } */
/* } */
/* else */
/* { */
msg->received_symbols++;
if(msg->received_symbols < header.source_symbols())
return;
Expand All @@ -129,7 +129,7 @@ void Depacketizer::handleMessagePacket(std::list<PartialMessage>::iterator it, c
off += len;
}
}
}
/* } */

msg->complete = true;

Expand Down
86 changes: 42 additions & 44 deletions nimbro_topic_transport/src/sender/packetizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include <random>

#include <wirehair/wirehair.h>

#include "../udp_packet.h"

namespace nimbro_topic_transport
Expand Down Expand Up @@ -48,8 +46,8 @@ TopicPacketizer::TopicPacketizer(const Packetizer::Ptr& packetizer, const Topic:
throw std::runtime_error("Invalid FEC percentage.");
}

if(wirehair_init() != Wirehair_Success)
throw std::runtime_error("Could not initialize wirehair FEC library");
/* if(wirehair_init() != Wirehair_Success) */
/* throw std::runtime_error("Could not initialize wirehair FEC library"); */
}

TopicPacketizer::~TopicPacketizer()
Expand Down Expand Up @@ -172,46 +170,46 @@ std::vector<Packet::Ptr> TopicPacketizer::packetize(const Message::ConstPtr& msg
}
else
{
WirehairCodec encoder = wirehair_encoder_create(nullptr, messageData.data(), messageData.size(), UDPPacket::MaxDataSize);
if(!encoder)
{
ROS_ERROR("Could not create wirehair encoder!");
return {};
}

for(std::size_t i = 0; i < repairSymbols; ++i)
{
auto buf = std::make_shared<Packet>();
UDPPacket* packet = buf->packet();

packet->header.msg_id = messageID;
packet->header.source_symbols = sourceSymbols;
packet->header.repair_symbols = repairSymbols;
packet->header.symbol_id = sourceSymbols + i;
packet->header.prng_seed = seed;

uint32_t length = 0;

WirehairResult res = wirehair_encode(encoder, sourceSymbols + i, packet->data, UDPPacket::MaxDataSize, &length);
if(res != Wirehair_Success)
{
ROS_ERROR("Wirehair encode() error: %s", wirehair_result_string(res));
return {};
}

if(length != UDPPacket::MaxDataSize)
{
ROS_ERROR("Unexpected wirehair output size: %u, expected %u",
length, UDPPacket::MaxDataSize
);
}

buf->length = length + sizeof(UDPPacket::Header);

packets.emplace_back(std::move(buf));
}

wirehair_free(encoder);
/* WirehairCodec encoder = wirehair_encoder_create(nullptr, messageData.data(), messageData.size(), UDPPacket::MaxDataSize); */
/* if(!encoder) */
/* { */
/* ROS_ERROR("Could not create wirehair encoder!"); */
/* return {}; */
/* } */

/* for(std::size_t i = 0; i < repairSymbols; ++i) */
/* { */
/* auto buf = std::make_shared<Packet>(); */
/* UDPPacket* packet = buf->packet(); */

/* packet->header.msg_id = messageID; */
/* packet->header.source_symbols = sourceSymbols; */
/* packet->header.repair_symbols = repairSymbols; */
/* packet->header.symbol_id = sourceSymbols + i; */
/* packet->header.prng_seed = seed; */

/* uint32_t length = 0; */

/* WirehairResult res = wirehair_encode(encoder, sourceSymbols + i, packet->data, UDPPacket::MaxDataSize, &length); */
/* if(res != Wirehair_Success) */
/* { */
/* ROS_ERROR("Wirehair encode() error: %s", wirehair_result_string(res)); */
/* return {}; */
/* } */

/* if(length != UDPPacket::MaxDataSize) */
/* { */
/* ROS_ERROR("Unexpected wirehair output size: %u, expected %u", */
/* length, UDPPacket::MaxDataSize */
/* ); */
/* } */

/* buf->length = length + sizeof(UDPPacket::Header); */

/* packets.emplace_back(std::move(buf)); */
/* } */

/* wirehair_free(encoder); */
}

{
Expand Down

0 comments on commit b73ea32

Please sign in to comment.