diff --git a/data_tamer/include/data_tamer/sinks/mcap_sink.hpp b/data_tamer/include/data_tamer/sinks/mcap_sink.hpp index 04b3716..9fc18a7 100644 --- a/data_tamer/include/data_tamer/sinks/mcap_sink.hpp +++ b/data_tamer/include/data_tamer/sinks/mcap_sink.hpp @@ -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 writer_; std::unordered_map hash_to_channel_id_; diff --git a/data_tamer/src/sinks/mcap_sink.cpp b/data_tamer/src/sinks/mcap_sink.cpp index db195b2..f60c8f4 100644 --- a/data_tamer/src/sinks/mcap_sink.cpp +++ b/data_tamer/src/sinks/mcap_sink.cpp @@ -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::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()) {