pub struct VideoPlayer { /* private fields */ }Expand description
Stateful local video player composed from VideoDemuxer and VideoDecoder.
open decodes through the first display-order frame, so current_frame
is immediately available on success. Timing controls do not create a second
decoder or runtime owner; all hardware work remains inside the supplied
Runtime-owned decoder session.
Implementations§
Source§impl VideoPlayer
impl VideoPlayer
Sourcepub fn open(
runtime: &Runtime,
path: impl AsRef<Path>,
config: VideoPlayerConfig,
) -> Result<Self>
pub fn open( runtime: &Runtime, path: impl AsRef<Path>, config: VideoPlayerConfig, ) -> Result<Self>
Open a local source and present its first display-order frame.
§Errors
Returns an error for invalid pacing, demux/decode failure, unsupported codec/device capabilities, or a source with no displayable frame.
Sourcepub fn new_native(
runtime: &Runtime,
path: impl AsRef<Path>,
config: VideoPlayerConfig,
) -> Result<Self>
pub fn new_native( runtime: &Runtime, path: impl AsRef<Path>, config: VideoPlayerConfig, ) -> Result<Self>
Open a player whose frames retain the decoder’s native Vulkan images.
This route does not read decoded pixels back to the host. Frames returned
by current_frame retain their decoder slots;
GPU consumers must register completion with VideoFrame::mark_consumed.
Converted presentation textures use the configured bounded history;
decoder slots themselves are never cached. A backward cache miss rebuilds
a preceding window once, so subsequent reverse steps reuse GPU textures.
A native frame is not a render crate::Texture. A renderer must
explicitly convert or sample its planes before displaying it.
§Errors
Returns the same stream and device errors as open.
Sourcepub fn advance(&mut self) -> Result<bool>
pub fn advance(&mut self) -> Result<bool>
Present exactly one next display-order frame, independent of play/pause state.
Returns false only after a non-looping source is exhausted.
Sourcepub fn step_backward(&mut self) -> Result<()>
pub fn step_backward(&mut self) -> Result<()>
Present the preceding display-order frame.
Retained history is presented without decoding. If the requested frame has already been evicted, the player seeks through a bounded preceding presentation window and deterministically rebuilds through the target.
Sourcepub fn step_frames(&mut self, delta: i32) -> Result<()>
pub fn step_frames(&mut self, delta: i32) -> Result<()>
Move by a signed number of display-order frames.
Positive movement stops successfully at the end of a non-looping stream. Negative movement saturates at the first indexed display frame. A zero delta is a no-op.
Sourcepub fn tick(&mut self, elapsed: Duration) -> Result<u32>
pub fn tick(&mut self, elapsed: Duration) -> Result<u32>
Advance according to elapsed wall-clock time while playing.
Returns the number of frames presented. Paused players do not accumulate elapsed time, preventing a burst of implicit skipping after resume.
Sourcepub fn seek(&mut self, timestamp: u64) -> Result<()>
pub fn seek(&mut self, timestamp: u64) -> Result<()>
Seek to a presentation timestamp in the selected track time base.
The demuxer rewinds to the preceding keyframe; the player then decodes
forward until it reaches the first frame at or after timestamp.
Sourcepub fn seek_at_or_before(&mut self, timestamp: u64) -> Result<()>
pub fn seek_at_or_before(&mut self, timestamp: u64) -> Result<()>
Present the most recent indexed frame at or before a track timestamp.
This is the seek policy for an external audio clock: choosing the first frame after the requested time would display future video early. A timestamp before the first frame selects that first frame. Unindexed streams can only be rewound to zero.
Sourcepub fn seek_frame(&mut self, index: u64) -> Result<()>
pub fn seek_frame(&mut self, index: u64) -> Result<()>
Seek to an exact zero-based display-order frame.
A retained target is presented without decoding. Otherwise the player seeks to a bounded preceding presentation window and rebuilds decoder state through the requested frame.
Sourcepub fn close(&mut self)
pub fn close(&mut self)
Explicitly release decoder and demuxer state. A second close is harmless.
Sourcepub fn pause(&mut self) -> Result<()>
pub fn pause(&mut self) -> Result<()>
Pause time-paced playback and discard fractional accumulated time.
Sourcepub fn toggle_play(&mut self) -> Result<()>
pub fn toggle_play(&mut self) -> Result<()>
Toggle time-paced playback.
Sourcepub fn set_looping(&mut self, looping: bool) -> Result<()>
pub fn set_looping(&mut self, looping: bool) -> Result<()>
Change end-of-stream looping policy.
Sourcepub fn current_frame(&self) -> Result<&VideoFrame>
pub fn current_frame(&self) -> Result<&VideoFrame>
Borrow the currently presented frame.
Sourcepub fn current_frame_texture(&mut self) -> Result<Texture>
pub fn current_frame_texture(&mut self) -> Result<Texture>
Convert the currently presented frame into a Texture for rendering.
Native decoded frames convert on-device through the decoder’s
native-plane-to-RGBA path. The presented frame is then re-seated on the
texture: its timing, extent, and color metadata remain observable
through current_frame while the decoder slot
is released for the next decode. A texture-backed frame returns its
backing directly, so repeated calls for the same presented frame are
free. Host-planar playback has no texture path.
§Errors
Returns an error after close, when no frame is presented, for a non-native frame without a texture backing, or when the conversion submission fails.
Sourcepub fn next_presentation_boundary(&self) -> Result<Option<Duration>>
pub fn next_presentation_boundary(&self) -> Result<Option<Duration>>
Timestamp at which the next display frame may replace the current one.
Indexed containers use the next frame’s PTS, which respects variable
frame rate and gaps. Sequential sources use the current frame’s declared
end; an unknown duration cannot be paced by an external clock.
None means the indexed stream has no further display frame.
Sourcepub fn current_frame_index(&self) -> Result<u64>
pub fn current_frame_index(&self) -> Result<u64>
Return the absolute zero-based display index in the selected track.
Sourcepub fn info(&self) -> Option<VideoContainerInfo>
pub fn info(&self) -> Option<VideoContainerInfo>
Return selected stream metadata while open.
Sourcepub fn stats(&self) -> Option<VideoPlayerStats>
pub fn stats(&self) -> Option<VideoPlayerStats>
Return a snapshot of playback counters while open.
Sourcepub fn is_playing(&self) -> bool
pub fn is_playing(&self) -> bool
Return whether time-paced playback is enabled.