The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

d/euroc: Add configuration options to the player

Specifically:
- EUROC_PLAY_FROM_START
- EUROC_USE_SOURCE_TS
- EUROC_PRINT_PROGRESS
- EUROC_MAX_SPEED
- EUROC_PLAYBACK_SPEED

+54 -12
+1 -1
src/xrt/drivers/euroc/euroc_driver.h
··· 38 38 #endif 39 39 40 40 DEBUG_GET_ONCE_LOG_OPTION(euroc_log, "EUROC_LOG", U_LOGGING_WARN) 41 - DEBUG_GET_ONCE_OPTION(euroc_path, "EUROC_PATH", NULL) 41 + DEBUG_GET_OPTION(euroc_path, "EUROC_PATH", NULL) 42 42 43 43 /*! 44 44 * @}
+53 -11
src/xrt/drivers/euroc/euroc_player.cpp
··· 12 12 #include "os/os_threading.h" 13 13 #include "util/u_debug.h" 14 14 #include "util/u_misc.h" 15 + #include "util/u_time.h" 15 16 #include "util/u_var.h" 16 17 #include "util/u_sink.h" 17 18 #include "tracking/t_frame_cv_mat_wrapper.hpp" ··· 26 27 #include <thread> 27 28 28 29 DEBUG_GET_ONCE_OPTION(euroc_gt_device_name, "EUROC_GT_DEVICE_NAME", NULL) 30 + DEBUG_GET_ONCE_OPTION(euroc_skip_first, "EUROC_SKIP_FIRST", "0%") 31 + DEBUG_GET_ONCE_BOOL_OPTION(euroc_play_from_start, "EUROC_PLAY_FROM_START", false) 32 + DEBUG_GET_ONCE_BOOL_OPTION(euroc_use_source_ts, "EUROC_USE_SOURCE_TS", false) 33 + DEBUG_GET_ONCE_BOOL_OPTION(euroc_print_progress, "EUROC_PRINT_PROGRESS", false) 34 + DEBUG_GET_ONCE_BOOL_OPTION(euroc_max_speed, "EUROC_MAX_SPEED", false) 35 + DEBUG_GET_ONCE_FLOAT_OPTION(euroc_playback_speed, "EUROC_PLAYBACK_SPEED", 1.0) 29 36 30 37 #define EUROC_PLAYER_STR "Euroc Player" 31 38 #define CLAMP(X, A, B) (MIN(MAX((X), (A)), (B))) ··· 35 42 using std::is_same_v; 36 43 using std::launch; 37 44 using std::pair; 45 + using std::stof; 38 46 using std::string; 39 47 using std::vector; 40 48 ··· 111 119 bool stereo; //!< Whether to stream both left and right sinks or only left 112 120 bool color; //!< If RGB available but this is false, images will be loaded in grayscale 113 121 bool gt; //!< Whether to send groundtruth data (if available) to the SLAM tracker 114 - float skip_first_s; //!< Amount of initial seconds of the dataset to skip 122 + bool skip_perc; //!< Whether @ref skip_first represents percentage or seconds 123 + float skip_first; //!< How much of the first dataset samples to skip, @see skip_perc 115 124 float scale; //!< Scale of each frame; e.g., 0.5 (half), 1.0 (avoids resize) 116 - double speed; //!< Intended reproduction speed, could be slower due to read times 125 + bool max_speed; //!< If true, push samples as fast as possible, other wise @see speed 126 + double speed; //!< Intended reproduction speed if @ref max_speed is false 117 127 bool send_all_imus_first; //!< If enabled all imu samples will be sent before img samples 118 128 bool paused; //!< Whether to pause the playback 119 129 bool use_source_ts; //!< If true, use the original timestamps from the dataset 120 130 } playback; 121 131 timepoint_ns last_pause_ts; //!< Last time the stream was paused 132 + bool play_from_start; //!< If set, the euroc player does not way for user input to start 133 + bool print_progress; //!< Whether to print progress to stdout (useful for CLI runs) 122 134 123 135 // UI related fields 124 136 enum euroc_player_ui_state ui_state; ··· 295 307 static void 296 308 euroc_player_user_skip(struct euroc_player *ep) 297 309 { 298 - timepoint_ns skip_first_ns = ep->playback.skip_first_s * 1000 * 1000 * 1000; 310 + 311 + float skip_first_s = 0; 312 + if (ep->playback.skip_perc) { 313 + float skip_percentage = ep->playback.skip_first; 314 + timepoint_ns last_ts = MAX(ep->left_imgs->back().first, ep->imus->back().timestamp_ns); 315 + double dataset_length_s = (last_ts - ep->base_ts) / U_TIME_1S_IN_NS; 316 + skip_first_s = dataset_length_s * skip_percentage / 100.0f; 317 + } else { 318 + skip_first_s = ep->playback.skip_first; 319 + } 320 + 321 + time_duration_ns skip_first_ns = skip_first_s * U_TIME_1S_IN_NS; 299 322 timepoint_ns skipped_ts = ep->base_ts + skip_first_ns; 300 323 301 324 while (ep->imus->at(ep->imu_seq).timestamp_ns < skipped_ts) { ··· 445 468 446 469 snprintf(ep->progress_text, sizeof(ep->progress_text), "Frames %lu/%lu - IMUs %lu/%lu", ep->img_seq, 447 470 ep->left_imgs->size(), ep->imu_seq, ep->imus->size()); 471 + 472 + if (ep->print_progress) { 473 + printf("Playback %.2f%% - Frame %lu/%lu\r", float(ep->img_seq) / float(ep->left_imgs->size()) * 100, 474 + ep->img_seq, ep->left_imgs->size()); 475 + fflush(stdout); 476 + } 448 477 } 449 478 450 479 static void ··· 537 566 constexpr int64_t PAUSE_POLL_INTERVAL_NS = 15L * U_TIME_1MS_IN_NS; 538 567 os_nanosleep(PAUSE_POLL_INTERVAL_NS); 539 568 } 540 - sleep_until_next_sample(ep); 569 + 570 + if (!ep->playback.max_speed) { 571 + sleep_until_next_sample(ep); 572 + } 573 + 541 574 push_next_sample(ep); 542 575 } 543 576 } ··· 661 694 } 662 695 663 696 //! This is the @ref xrt_fs stream start method, however as the euroc playback 664 - //! is heavily customizable, it will be managed through the UI. So this will not 665 - //! really start outputting frames but mainly prepare everything to start doing 666 - //! so when the user decides. 697 + //! is heavily customizable, it will be managed through the UI. So, unless 698 + //! EUROC_PLAY_FROM_START is set, this will not start outputting frames until 699 + //! the user clicks the start button. 667 700 static bool 668 701 euroc_player_stream_start(struct xrt_fs *xfs, 669 702 struct xrt_frame_sink *xs, ··· 677 710 if (ep->out_sinks.left == NULL) { 678 711 EUROC_WARN(ep, "No left sink provided, will keep running but tracking is unlikely to work"); 679 712 } 713 + if (ep->play_from_start) { 714 + euroc_player_start_btn_cb(ep); 715 + } 680 716 } else if (xs != NULL && capture_type == XRT_FS_CAPTURE_TYPE_CALIBRATION) { 681 717 EUROC_INFO(ep, "Starting Euroc Player in calibration mode, will stream only left frames right away"); 682 718 ep->out_sinks.left = xs; ··· 839 875 u_var_add_bool(ep, &ep->playback.stereo, "Stereo (if available)"); 840 876 u_var_add_bool(ep, &ep->playback.color, "Color (if available)"); 841 877 u_var_add_bool(ep, &ep->playback.gt, "Groundtruth (if available)"); 842 - u_var_add_f32(ep, &ep->playback.skip_first_s, "First seconds to skip"); 878 + u_var_add_bool(ep, &ep->playback.skip_perc, "Skip percentage, otherwise skips seconds"); 879 + u_var_add_f32(ep, &ep->playback.skip_first, "How much to skip"); 843 880 u_var_add_f32(ep, &ep->playback.scale, "Scale"); 881 + u_var_add_bool(ep, &ep->playback.max_speed, "Max speed"); 844 882 u_var_add_f64(ep, &ep->playback.speed, "Speed"); 845 883 u_var_add_bool(ep, &ep->playback.send_all_imus_first, "Send all IMU samples first"); 846 884 u_var_add_bool(ep, &ep->playback.use_source_ts, "Use original timestamps"); ··· 877 915 ep->playback.stereo = ep->dataset.is_stereo; 878 916 ep->playback.color = ep->dataset.is_colored; 879 917 ep->playback.gt = ep->dataset.has_gt; 880 - ep->playback.skip_first_s = 0.0; 918 + ep->playback.skip_perc = string(debug_get_option_euroc_skip_first()).back() == '%'; 919 + ep->playback.skip_first = stof(debug_get_option_euroc_skip_first()); 881 920 ep->playback.scale = 1.0; 882 - ep->playback.speed = 1.0; 921 + ep->playback.max_speed = debug_get_bool_option_euroc_max_speed(); 922 + ep->playback.speed = debug_get_float_option_euroc_playback_speed(); 883 923 ep->playback.send_all_imus_first = false; 884 - ep->playback.use_source_ts = false; 924 + ep->playback.use_source_ts = debug_get_bool_option_euroc_use_source_ts(); 925 + ep->play_from_start = debug_get_bool_option_euroc_play_from_start(); 885 926 886 927 ep->log_level = debug_get_log_option_euroc_log(); 928 + ep->print_progress = debug_get_bool_option_euroc_print_progress(); 887 929 euroc_player_setup_gui(ep); 888 930 889 931 ep->left_sink.push_frame = receive_left_frame;