re_viewer_context/
app_options.rs

1use re_log_types::TimestampFormat;
2use re_video::{DecodeHardwareAcceleration, DecodeSettings};
3
4const MAPBOX_ACCESS_TOKEN_ENV_VAR: &str = "RERUN_MAPBOX_ACCESS_TOKEN";
5
6/// Global options for the viewer.
7#[derive(Debug, PartialEq, serde::Deserialize, serde::Serialize)]
8#[serde(default)]
9pub struct AppOptions {
10    /// Warn if the e2e latency exceeds this value.
11    pub warn_e2e_latency: f32,
12
13    /// Show milliseconds, RAM usage, etc.
14    pub show_metrics: bool,
15
16    /// Include the "Welcome screen" application in the recordings panel?
17    #[serde(alias = "include_welcome_screen_button_in_recordings_panel")]
18    pub include_rerun_examples_button_in_recordings_panel: bool,
19
20    /// Displays an overlay for debugging picking.
21    pub show_picking_debug_overlay: bool,
22
23    /// Inspect the blueprint timeline.
24    pub inspect_blueprint_timeline: bool,
25
26    /// Disable garbage collection of the blueprint.
27    pub blueprint_gc: bool,
28
29    /// What time zone to display timestamps in.
30    #[serde(rename = "timestamp_format")]
31    pub timestamp_format: TimestampFormat,
32
33    /// Preferred method for video decoding on web.
34    pub video_decoder_hw_acceleration: DecodeHardwareAcceleration,
35
36    /// Override the path to the FFmpeg binary.
37    ///
38    /// If set, use `video_decoder_ffmpeg_path` as the path to the FFmpeg binary.
39    /// Don't use this field directly, use [`AppOptions::video_decoder_settings`] instead.
40    ///
41    /// Implementation note: we avoid using `Option<PathBuf>` here to avoid losing the user-defined
42    /// path when disabling the override.
43    #[expect(clippy::doc_markdown)]
44    pub video_decoder_override_ffmpeg_path: bool,
45
46    /// Custom path to the FFmpeg binary.
47    ///
48    /// Don't use this field directly, use [`AppOptions::video_decoder_settings`] instead.
49    #[expect(clippy::doc_markdown)]
50    pub video_decoder_ffmpeg_path: String,
51
52    /// Mapbox API key (used to enable Mapbox-based map view backgrounds).
53    ///
54    /// Can also be set using the `RERUN_MAPBOX_ACCESS_TOKEN` environment variable.
55    pub mapbox_access_token: String,
56
57    /// Path to the directory suitable for storing cache data.
58    ///
59    /// By cache data, we mean data that is safe to be garbage collected by the OS. Defaults to
60    /// to [`directories::ProjectDirs::cache_dir`].
61    ///
62    /// *NOTE*: subsystems making use of the cache directory should use a unique sub-directory name,
63    /// see [`AppOptions::cache_subdirectory`].
64    #[cfg(not(target_arch = "wasm32"))]
65    pub cache_directory: Option<std::path::PathBuf>,
66}
67
68impl Default for AppOptions {
69    fn default() -> Self {
70        Self {
71            warn_e2e_latency: 1.0,
72
73            show_metrics: cfg!(debug_assertions),
74
75            include_rerun_examples_button_in_recordings_panel: true,
76
77            show_picking_debug_overlay: false,
78
79            inspect_blueprint_timeline: false,
80
81            blueprint_gc: true,
82
83            timestamp_format: TimestampFormat::default(),
84
85            video_decoder_hw_acceleration: DecodeHardwareAcceleration::default(),
86            video_decoder_override_ffmpeg_path: false,
87            video_decoder_ffmpeg_path: String::new(),
88
89            mapbox_access_token: String::new(),
90
91            #[cfg(not(target_arch = "wasm32"))]
92            cache_directory: Self::default_cache_directory(),
93        }
94    }
95}
96
97impl AppOptions {
98    pub fn mapbox_access_token(&self) -> Option<String> {
99        if self.mapbox_access_token.is_empty() {
100            std::env::var(MAPBOX_ACCESS_TOKEN_ENV_VAR).ok()
101        } else {
102            Some(self.mapbox_access_token.clone())
103        }
104    }
105
106    #[cfg(not(target_arch = "wasm32"))]
107    pub fn cache_subdirectory(
108        &self,
109        sub_dir: impl AsRef<std::path::Path>,
110    ) -> Option<std::path::PathBuf> {
111        self.cache_directory
112            .as_ref()
113            .map(|cache_dir| cache_dir.join(sub_dir))
114    }
115
116    /// Default cache directory
117    pub fn default_cache_directory() -> Option<std::path::PathBuf> {
118        directories::ProjectDirs::from("io", "rerun", "Rerun")
119            .map(|dirs| dirs.cache_dir().to_owned())
120    }
121
122    /// Get the video decoder settings.
123    pub fn video_decoder_settings(&self) -> DecodeSettings {
124        DecodeSettings {
125            hw_acceleration: self.video_decoder_hw_acceleration,
126
127            #[cfg(not(target_arch = "wasm32"))]
128            ffmpeg_path: self
129                .video_decoder_override_ffmpeg_path
130                .then(|| std::path::PathBuf::from(&self.video_decoder_ffmpeg_path)),
131        }
132    }
133}