@@ -52,21 +52,14 @@ K4AROSDevice::K4AROSDevice(const NodeHandle &n, const NodeHandle &p) : k4a_devic
5252 {
5353 ROS_INFO (" Node is started in playback mode" );
5454 ROS_INFO_STREAM (" Try to open recording file " << params_.recording_file );
55- // Open recording file
56- if (k4a_playback_open (params_.recording_file .c_str (), &k4a_playback_handle_) != K4A_RESULT_SUCCEEDED)
57- {
58- ROS_ERROR_STREAM (" Failed to open recording" );
59- return ;
60- }
61- uint64_t recording_length = k4a_playback_get_last_timestamp_usec (k4a_playback_handle_);
62- ROS_INFO_STREAM (" Successfully openend recording file. Recording is " << recording_length / 1000000 << " seconds long" );
6355
64- k4a_record_configuration_t record_config;
65- if (k4a_playback_get_record_configuration (k4a_playback_handle_, &record_config) != K4A_RESULT_SUCCEEDED)
66- {
67- ROS_ERROR_STREAM (" Failed to get record configuration" );
68- return ;
69- }
56+ // Open recording file and print its length
57+ k4a_playback_handle_ = k4a::playback::open (params_.recording_file .c_str ());
58+ auto recording_length = k4a_playback_handle_.get_recording_length ();
59+ ROS_INFO_STREAM (" Successfully openend recording file. Recording is " << recording_length.count () / 1000000 << " seconds long" );
60+
61+ // Get the recordings configuration to overwrite node parameters
62+ k4a_record_configuration_t record_config = k4a_playback_handle_.get_record_configuration ();
7063
7164 // Overwrite fps param with recording configuration for a correct loop rate in the frame publisher thread
7265 switch (record_config.camera_fps )
@@ -95,7 +88,7 @@ K4AROSDevice::K4AROSDevice(const NodeHandle &n, const NodeHandle &p) : k4a_devic
9588 // This is necessary because at the moment there are only checks in place which use BgraPixel size
9689 else if (params_.color_enabled && record_config.color_track_enabled && record_config.color_format != K4A_IMAGE_FORMAT_COLOR_BGRA32)
9790 {
98- k4a_playback_set_color_conversion ( k4a_playback_handle_, K4A_IMAGE_FORMAT_COLOR_BGRA32);
91+ k4a_playback_handle_. set_color_conversion ( K4A_IMAGE_FORMAT_COLOR_BGRA32);
9992 }
10093
10194 // Disable depth if the recording has neither ir track nor depth track
@@ -256,7 +249,7 @@ K4AROSDevice::~K4AROSDevice()
256249
257250 if (k4a_playback_handle_)
258251 {
259- k4a_playback_close ( k4a_playback_handle_);
252+ k4a_playback_handle_. close ( );
260253 }
261254
262255#if defined(K4A_BODY_TRACKING)
@@ -833,8 +826,6 @@ void K4AROSDevice::framePublisherThread()
833826
834827 while (running_ && ros::ok () && !ros::isShuttingDown ())
835828 {
836- bool success = true ;
837-
838829 if (k4a_device_)
839830 {
840831 // TODO: consider appropriate capture timeout based on camera framerate
@@ -848,21 +839,13 @@ void K4AROSDevice::framePublisherThread()
848839 else if (k4a_playback_handle_)
849840 {
850841 std::lock_guard<std::mutex> guard (k4a_playback_handle_mutex_);
851- k4a_capture_t capture_temp;
852- k4a_stream_result_t stream_result = k4a_playback_get_next_capture (k4a_playback_handle_, &capture_temp);
853-
854- if (stream_result == K4A_STREAM_RESULT_EOF)
842+ if (!k4a_playback_handle_.get_next_capture (&capture))
855843 {
856844 // rewind recording if looping is enabled
857845 if (params_.recording_loop_enabled )
858846 {
859- if (k4a_playback_seek_timestamp (k4a_playback_handle_, 0 , K4A_PLAYBACK_SEEK_BEGIN) != K4A_RESULT_SUCCEEDED)
860- {
861- ROS_FATAL (" Error seeking recording to beginning. node cannot continue." );
862- ros::requestShutdown ();
863- return ;
864- }
865- stream_result = k4a_playback_get_next_capture (k4a_playback_handle_, &capture_temp);
847+ k4a_playback_handle_.seek_timestamp (std::chrono::microseconds (0 ), K4A_PLAYBACK_SEEK_BEGIN);
848+ k4a_playback_handle_.get_next_capture (&capture);
866849 imu_stream_end_of_file_ = false ;
867850 last_imu_time_usec_ = 0 ;
868851 }
@@ -873,14 +856,7 @@ void K4AROSDevice::framePublisherThread()
873856 return ;
874857 }
875858 }
876- else if (stream_result != K4A_STREAM_RESULT_SUCCEEDED)
877- {
878- ROS_FATAL (" Failed to get next capture from recording file: node cannot continue." );
879- ros::requestShutdown ();
880- return ;
881- }
882859
883- capture = k4a::capture (capture_temp);
884860 last_capture_time_usec_ = getCaptureTimestamp (capture).count ();
885861 }
886862
@@ -1141,14 +1117,11 @@ void K4AROSDevice::imuPublisherThread()
11411117{
11421118 ros::Rate loop_rate (300 );
11431119
1144- k4a_wait_result_t waitResult;
11451120 k4a_result_t result;
1146-
11471121 k4a_imu_sample_t sample;
11481122
11491123 while (running_ && ros::ok () && !ros::isShuttingDown ())
11501124 {
1151-
11521125 if (k4a_device_)
11531126 {
11541127 // IMU messages are delivered in batches at 300 Hz. Drain the queue of IMU messages by
@@ -1177,12 +1150,11 @@ void K4AROSDevice::imuPublisherThread()
11771150 while (last_imu_time_usec_ <= last_capture_time_usec_ && !imu_stream_end_of_file_)
11781151 {
11791152 std::lock_guard<std::mutex> guard (k4a_playback_handle_mutex_);
1180- k4a_stream_result_t stream_result = k4a_playback_get_next_imu_sample (k4a_playback_handle_, &sample);
1181- if (stream_result == K4A_STREAM_RESULT_EOF)
1153+ if (!k4a_playback_handle_.get_next_imu_sample (&sample))
11821154 {
11831155 imu_stream_end_of_file_ = true ;
11841156 }
1185- else if (stream_result == K4A_STREAM_RESULT_SUCCEEDED)
1157+ else
11861158 {
11871159 ImuPtr imu_msg (new Imu);
11881160 result = getImuFrame (sample, imu_msg);
@@ -1192,13 +1164,6 @@ void K4AROSDevice::imuPublisherThread()
11921164
11931165 last_imu_time_usec_ = sample.acc_timestamp_usec ;
11941166 }
1195- else
1196- {
1197- ROS_FATAL (" Failed to get next imu sample from recording. node cannot continue." );
1198- ros::requestShutdown ();
1199- return ;
1200- }
1201-
12021167 }
12031168 }
12041169
0 commit comments