Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iron] Make rosbag2_transport::Player::play() run in a separate thread (backport #1503) #1505

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions rosbag2_py/src/rosbag2_py/_transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ class Player
exec.spin();
});
player->play();
player->wait_for_playback_to_finish();

exec.cancel();
spin_thread.join();
Expand All @@ -175,15 +176,11 @@ class Player
[&exec]() {
exec.spin();
});
auto play_thread = std::thread(
[&player]() {
player->play();
});
player->play();
player->burst(num_messages);

exec.cancel();
spin_thread.join();
play_thread.join();
}
};

Expand Down
11 changes: 10 additions & 1 deletion rosbag2_transport/include/rosbag2_transport/player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <functional>
#include <future>
#include <memory>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility>
Expand Down Expand Up @@ -110,9 +109,19 @@ class Player : public rclcpp::Node
ROSBAG2_TRANSPORT_PUBLIC
virtual ~Player();

/// \brief Start playback asynchronously in a separate thread
/// \return false if playback thread already running, otherwise true
ROSBAG2_TRANSPORT_PUBLIC
bool play();

/// \brief Waits on the condition variable until the play thread finishes.
/// @param timeout Maximum time in the fraction of seconds to wait for player to finish.
/// If timeout is negative, the wait_for_playback_to_finish will be a blocking call.
/// @return true if playback finished during timeout, otherwise false.
ROSBAG2_TRANSPORT_PUBLIC
bool wait_for_playback_to_finish(
std::chrono::duration<double> timeout = std::chrono::seconds(-1));

/// \brief Unpause if in pause mode, stop playback and exit from play.
ROSBAG2_TRANSPORT_PUBLIC
void stop();
Expand Down
Loading
Loading