Skip to content

Commit

Permalink
add MCAP option
Browse files Browse the repository at this point in the history
facontidavide committed Nov 28, 2023
1 parent 753588b commit 8d5d75c
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion data_tamer/include/data_tamer/sinks/mcap_sink.hpp
Original file line number Diff line number Diff line change
@@ -26,7 +26,14 @@ namespace DataTamer
class MCAPSink : public DataSinkBase
{
public:
explicit MCAPSink(std::string const& filepath);
/**
* @brief MCAPSink
*
* @param filepath path of the file to be saved. Should have extension ".mcap"
* @param do_compression if true, compress the data on the fly. Note that in case of a crash/segfault
* some of the data may be lost; it is therefore more conservative to leave this to false.
*/
explicit MCAPSink(std::string const& filepath, bool do_compression = false);

~MCAPSink() override;

@@ -43,6 +50,7 @@ class MCAPSink : public DataSinkBase

private:
std::string filepath_;
bool compression_ = false;
std::unique_ptr<mcap::McapWriter> writer_;

std::unordered_map<uint64_t, uint16_t> hash_to_channel_id_;
4 changes: 2 additions & 2 deletions data_tamer/src/sinks/mcap_sink.cpp
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ namespace DataTamer

static constexpr char const* kDataTamer = "data_tamer";

MCAPSink::MCAPSink(const std::string& filepath) : filepath_(filepath)
MCAPSink::MCAPSink(const std::string& filepath, bool do_compression) : filepath_(filepath), compression_(do_compression)
{
openFile(filepath_);
}
@@ -43,7 +43,7 @@ void DataTamer::MCAPSink::openFile(std::string const& filepath)
std::scoped_lock wlk(writer_mutex_);
writer_ = std::make_unique<mcap::McapWriter>();
mcap::McapWriterOptions options(kDataTamer);
options.compression = mcap::Compression::Zstd;
options.compression = compression_ ? mcap::Compression::Zstd : mcap::Compression::None;
auto status = writer_->open(filepath, options);
if (!status.ok())
{

0 comments on commit 8d5d75c

Please sign in to comment.