pub struct Player {
pub(crate) stream: Box<dyn VideoStream + Send>,
pub(crate) texture: VideoTexture,
pub(crate) state: PlayState,
pub(crate) elapsed: Duration,
pub(crate) next_due: Duration,
pub(crate) last_uploaded_pts: Option<f64>,
pub(crate) last_uploaded_index: Option<u64>,
}Expand description
Player state machine. Owns the upstream stream and the GPU texture holding the current frame.
Fields§
§stream: Box<dyn VideoStream + Send>§texture: VideoTexture§state: PlayState§elapsed: Duration§next_due: DurationWallclock time at which the next frame in the stream becomes
presentable. Initialised to zero so the first tick always pulls.
last_uploaded_pts: Option<f64>§last_uploaded_index: Option<u64>Implementations§
Source§impl Player
impl Player
Sourcepub fn new(app: &Application, stream: Box<dyn VideoStream + Send>) -> Self
pub fn new(app: &Application, stream: Box<dyn VideoStream + Send>) -> Self
Build a player around an arbitrary [VideoStream].
Allocates a VideoTexture matching the stream dimensions; that
allocation is reused for every frame.
Sourcepub fn play(&mut self)
pub fn play(&mut self)
Transition to PlayState::Playing. No-op if already playing or
the stream has ended.
Sourcepub fn pause(&mut self)
pub fn pause(&mut self)
Transition to PlayState::Paused. No-op if not playing.
Sourcepub fn tick(&mut self, app: &Application, dt: Duration) -> u32
pub fn tick(&mut self, app: &Application, dt: Duration) -> u32
Advance playback by dt. Pulls and uploads as many frames as have
come due — typically zero or one per render tick, but this handles
burst catch-up (multiple frames due) cleanly.
No-op when paused / ended. Returns the number of frames uploaded so callers can drive a redraw signal off it.
pub(crate) fn upload(&mut self, app: &Application, frame: &VideoFrame)
Sourcepub fn texture(&self) -> &Texture
pub fn texture(&self) -> &Texture
Borrow the current frame’s GPU texture for use as a Sprite source.
Sourcepub fn last_uploaded_pts(&self) -> Option<f64>
pub fn last_uploaded_pts(&self) -> Option<f64>
Presentation timestamp of the last uploaded frame, if any.
Sourcepub fn last_uploaded_index(&self) -> Option<u64>
pub fn last_uploaded_index(&self) -> Option<u64>
Frame index of the last uploaded frame, if any.
Sourcepub fn duration_hint(&self) -> Option<Duration>
pub fn duration_hint(&self) -> Option<Duration>
Duration hint, derived from the stream’s frame count + frame rate.
Auto Trait Implementations§
impl Freeze for Player
impl !RefUnwindSafe for Player
impl Send for Player
impl !Sync for Player
impl Unpin for Player
impl UnsafeUnpin for Player
impl !UnwindSafe for Player
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more