Skip to content

Commit

Permalink
play: refuse to play non-monotonic bags
Browse files Browse the repository at this point in the history
  • Loading branch information
xqms committed Mar 19, 2024
1 parent 5216a83 commit dcf1fff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
10 changes: 10 additions & 0 deletions rosbag_fancy/src/bag_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ class BagReader::Private

ros::Time startTime;
ros::Time endTime;

bool isMonotonic = true;
};

class BagReader::ChunkIterator::Private
Expand Down Expand Up @@ -713,6 +715,9 @@ BagReader::BagReader(const std::string& filename)
chunk.startTime = ros::Time(startTime & 0xFFFFFFFF, startTime >> 32);
chunk.endTime = ros::Time(endTime & 0xFFFFFFFF, endTime >> 32);

if(lastChunk && lastChunk->endTime > chunk.startTime)
m_d->isMonotonic = false;

auto numConnections = rec.integralHeader<std::uint32_t>("count");

if(rec.dataSize < numConnections * sizeof(ConnectionInfo))
Expand Down Expand Up @@ -825,6 +830,11 @@ std::size_t BagReader::numChunks() const
return m_d->chunks.size();
}

bool BagReader::isMonotonic() const
{
return m_d->isMonotonic;
}


// TESTS

Expand Down
2 changes: 2 additions & 0 deletions rosbag_fancy/src/bag_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ class BagReader

int findChunk(const ros::Time& time) const;
Iterator chunkBegin(int chunk) const;

bool isMonotonic() const;
private:
class Private;
std::unique_ptr<Private> m_d;
Expand Down
9 changes: 9 additions & 0 deletions rosbag_fancy/src/cmd_play.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,15 @@ int play(const std::vector<std::string>& options)
{
auto& bag = bags.emplace_back(filename);

if(!bag.reader.isMonotonic())
{
throw std::runtime_error{fmt::format(
"Bag '{}' contains non-monotonic chunks. This is not supported by rosbag_fancy play at the moment. "
"You can convert a non-monotonic bag to a monotonic one by running 'rosbag filter in.bag out.bag True'.",
filename
)};
}

if(startTime == ros::Time(0) || bag.reader.startTime() < startTime)
startTime = bag.reader.startTime();

Expand Down

0 comments on commit dcf1fff

Please sign in to comment.