pub struct MultiTrackSeeker { /* private fields */ }Expand description
Multi-track sample-accurate seeker with a per-track PTS→byte-offset index.
Unlike SampleAccurateSeeker (which wraps a single TrackIndex),
MultiTrackSeeker manages a separate sorted index for each track and
exposes an O(log n) seek_to_pts lookup.
§Example
use oximedia_container::seek::{MultiTrackSeeker, SampleIndexEntry};
let mut seeker = MultiTrackSeeker::new();
let samples = vec![
SampleIndexEntry::keyframe(0, 1000),
SampleIndexEntry::delta(3000, 1200),
SampleIndexEntry::keyframe(6000, 1500),
];
seeker.build_index(1, &samples).expect("index built");
let result = seeker.seek_to_pts(1, 4500).expect("seek ok");
println!("found_pts={} offset={} idx={}", result.found_pts, result.byte_offset, result.sample_idx);Implementations§
Source§impl MultiTrackSeeker
impl MultiTrackSeeker
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty MultiTrackSeeker.
Sourcepub fn build_index(
&mut self,
track_id: u32,
samples: &[SampleIndexEntry],
) -> Result<(), MultiTrackSeekerError>
pub fn build_index( &mut self, track_id: u32, samples: &[SampleIndexEntry], ) -> Result<(), MultiTrackSeekerError>
Builds (or replaces) the index for track_id from the provided sample list.
The entries are sorted by PTS so that seek_to_pts
can use binary search.
§Errors
This method currently always succeeds. It is defined with Result for
forward compatibility (e.g. if validation logic is added later).
Sourcepub fn seek_to_pts(
&self,
track_id: u32,
target_pts: i64,
) -> Result<PtsSeekResult, MultiTrackSeekerError>
pub fn seek_to_pts( &self, track_id: u32, target_pts: i64, ) -> Result<PtsSeekResult, MultiTrackSeekerError>
Seeks to the sample-accurate position for target_pts within track_id.
Uses binary search (O(log n)) to locate the last sample whose PTS is ≤
target_pts. If the target_pts is exactly a sample boundary the
result is exact; otherwise the sample immediately preceding the target
is returned (the decoder must decode from that point).
§Errors
MultiTrackSeekerError::NoIndex— the track has no index.MultiTrackSeekerError::EmptyIndex— the index is empty.MultiTrackSeekerError::BeforeFirstSample—target_ptsis earlier than the first indexed sample.
Sourcepub fn indexed_track_count(&self) -> usize
pub fn indexed_track_count(&self) -> usize
Returns the number of tracks that have been indexed.
Sourcepub fn sample_count(&self, track_id: u32) -> Option<usize>
pub fn sample_count(&self, track_id: u32) -> Option<usize>
Returns the number of indexed samples for track_id, or None.
Sourcepub fn clear_index(&mut self, track_id: u32)
pub fn clear_index(&mut self, track_id: u32)
Clears the index for track_id.
Sourcepub fn entries(&self, track_id: u32) -> Option<&[SampleIndexEntry]>
pub fn entries(&self, track_id: u32) -> Option<&[SampleIndexEntry]>
Returns a sorted slice of index entries for track_id, or None.