ff_decode/shared/seek.rs
1//! Seek mode configuration for decoder positioning.
2
3/// Seek mode for positioning the decoder.
4///
5/// This enum determines how seeking is performed when navigating
6/// through a media file.
7///
8/// # Performance Considerations
9///
10/// - [`Keyframe`](Self::Keyframe) is fastest but may land slightly before or after the target
11/// - [`Exact`](Self::Exact) is slower but guarantees landing on the exact frame
12/// - [`Backward`](Self::Backward) is useful for editing workflows where the previous keyframe is needed
13///
14/// # Examples
15///
16/// ```
17/// use ff_decode::SeekMode;
18///
19/// // Default is Keyframe mode
20/// let mode = SeekMode::default();
21/// assert_eq!(mode, SeekMode::Keyframe);
22///
23/// // Use exact mode for frame-accurate positioning
24/// let exact = SeekMode::Exact;
25/// assert_eq!(format!("{:?}", exact), "Exact");
26/// ```
27#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
28#[repr(u8)]
29pub enum SeekMode {
30 /// Seek to nearest keyframe (fast, may have small offset).
31 ///
32 /// This mode seeks to the closest keyframe to the target position.
33 /// It's the fastest option but the actual position may differ from
34 /// the requested position by up to the GOP (Group of Pictures) size.
35 #[default]
36 Keyframe = 0,
37
38 /// Seek to exact frame (slower but precise).
39 ///
40 /// This mode first seeks to the previous keyframe, then decodes
41 /// frames until reaching the exact target position. This guarantees
42 /// frame-accurate positioning but is slower, especially for long GOPs.
43 Exact = 1,
44
45 /// Seek to keyframe at or before the target position.
46 ///
47 /// Similar to [`Keyframe`](Self::Keyframe), but guarantees the resulting
48 /// position is at or before the target. Useful for editing workflows
49 /// where you need to start decoding before a specific point.
50 Backward = 2,
51}
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn seek_mode_default_should_be_keyframe() {
59 let mode = SeekMode::default();
60 assert_eq!(mode, SeekMode::Keyframe);
61 }
62
63 #[test]
64 fn seek_mode_variants_should_be_accessible() {
65 let modes = [SeekMode::Keyframe, SeekMode::Exact, SeekMode::Backward];
66 for mode in modes {
67 let _ = format!("{mode:?}");
68 }
69 }
70}