Vixen
02b45cc4
csharp
public sealed class VideoPlayer

Plays a video: decodes ahead of the clock, and says which frame is current.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Three moving parts and one rule. A decoder produces frames, a queue holds the next few, and a clock says what time it is; the rule is that the current frame is the newest one whose timestamp has passed. Everything else here — the thread, the pool, the loop offset, the counters — exists to make that rule survive a decoder that is occasionally slow.

Late frames are dropped, never shown late. If the clock has passed three frames since the last update — a stall, a breakpoint, a game running at 20 fps against 60 fps content — the player shows the third and counts two in FramesDropped. Showing them in sequence would put the picture behind the sound and keep it there, which is the failure mode that never recovers on its own.

The decode thread is optional and the pump is public. Exactly as AudioStreamPump is: Service does the whole job synchronously, so a single-threaded platform calls it from its own loop and a test drives it frame by frame with no timing at all.

CurrentFrame belongs to the player. It is valid until the next Update, which is when the frame goes back to the pool. Anything that needs to keep it copies it — see VideoFrame.CopyFrom — and anything that uploads it to a texture does so in the same frame, which is what VideoTexture is for.

Fields and properties (14)

  • public VideoPlayerOptions Options

    What it was set up with.

  • public IVideoStreamDecoder Decoder

    The decoder behind it.

  • public VideoClock Clock

    The clock deciding which frame is current.

  • public VideoPlaybackState State

    What the player is doing.

  • public bool Loop

    Whether it starts again when it ends.

  • public VideoFrame? CurrentFrame

    The frame that should be on screen, or before the first one.

  • public uint FrameVersion

    Bumped every time CurrentFrame becomes a different picture.

  • public long FramesShown

    How many frames have been shown.

  • public long FramesDropped

    How many were decoded, became due, and were skipped because a newer one was also due.

  • public long DecodeStalls

    How many updates found the queue empty with the video still playing.

  • public int QueuedFrames

    How many decoded frames are waiting.

  • public TimeSpan Position

    Where playback has got to.

  • public TimeSpan Duration

    How long the video is, or zero if the container did not say.

  • public Int2 DisplaySize

    How big the picture is meant to look, which anamorphic content answers differently.

Methods (10)

  • public VideoPlayer(IVideoStreamDecoder decoder)

    Creates a player over a decoder, set up the way a cutscene wants.

  • public VideoPlayer(IVideoStreamDecoder decoder, VideoPlayerOptions options)

    Creates a player over a decoder.

  • public void Dispose()

    Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

  • public void Play()

    Starts or resumes playback.

  • public void Pause()

    Holds the current frame.

  • public void Stop()

    Stops and returns to the start.

  • public void Seek(TimeSpan position)

    Moves to a position.

  • public void FollowAudio(IAudioSampleProvider audio, TimeSpan offset = default(TimeSpan))

    Makes the sound the master clock, and the picture follow it.

  • public void Update(TimeSpan delta)

    Advances the clock and chooses the frame to show.

  • public bool Service()

    Decodes at most one frame into the queue.

Used by (13)

  • VideoGameVideoPlayback
  • AudioMasterClockTestsVixen.Video.Tests
  • VideoFitVixen.Video
  • VideoPlaybackVixen.Video
  • VideoPlaybackTestsVixen.Video.Tests
  • VideoPlayerTestsVixen.Video.Tests
  • VideoRenderTargetVixen.Video.Rendering
  • VideoSurfaceVixen.Video
  • VideoSurfaceUploaderVixen.Video.Rendering
  • VideoSystemVixen.Video
  • VideoSystemTestsVixen.Video.Tests
  • VideoTextureVixen.Video
  • VideoTextureTestsVixen.Video.Tests