Skip to content

Commit

Permalink
Fix split by time. (backport #1022)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya Fujita <[email protected]>
  • Loading branch information
fujitatomoya committed Apr 17, 2024
1 parent 04afde6 commit 618ed2f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions rosbag2_cpp/src/rosbag2_cpp/writers/sequential_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ void SequentialWriter::split_bagfile()
metadata_.relative_file_paths.push_back(strip_parent_path(storage_->get_relative_file_path()));

rosbag2_storage::FileInformation file_info{};
file_info.starting_time = std::chrono::time_point<std::chrono::high_resolution_clock>(
std::chrono::nanoseconds::max());
file_info.path = strip_parent_path(storage_->get_relative_file_path());
metadata_.files.push_back(file_info);

Expand All @@ -305,10 +307,14 @@ void SequentialWriter::write(std::shared_ptr<rosbag2_storage::SerializedBagMessa
const auto message_timestamp = std::chrono::time_point<std::chrono::high_resolution_clock>(
std::chrono::nanoseconds(message->time_stamp));

if (should_split_bagfile(message_timestamp)) {
split_bagfile();
if (is_first_message_) {
// Update bagfile starting time
metadata_.starting_time = message_timestamp;
is_first_message_ = false;
}

if (should_split_bagfile(message_timestamp)) {
split_bagfile();
metadata_.files.back().starting_time = message_timestamp;
}

Expand Down Expand Up @@ -373,7 +379,7 @@ bool SequentialWriter::should_split_bagfile(
auto max_duration_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::seconds(storage_options_.max_bagfile_duration));
should_split = should_split ||
((current_time - metadata_.starting_time) > max_duration_ns);
((current_time - metadata_.files.back().starting_time) > max_duration_ns);
}

return should_split;
Expand Down

0 comments on commit 618ed2f

Please sign in to comment.