Vixen
02b45cc4
csharp
public sealed class VideoFrame

One decoded picture and the moment it should be shown.

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

Remarks

One allocation, not one per plane. The planes live end to end in a single array, which is what lets the whole frame reach the GPU as one memcpy into a staging buffer and one copy per plane out of it. Three arrays would mean three copies and three things for a pool to keep in step.

Rows are tightly packed. Stride is the plane's width in bytes and nothing else — there is no alignment padding, because the only consumer that would want it is the upload path, and a staging buffer is written by this code rather than by a driver. A codec that decodes into padded rows copies out; that cost is the codec's, and it is what every codec does anyway when it hands a picture over.

A frame is mutable and reused. It is rented from a VideoFramePool, decoded into, shown, and returned. Holding one past Return is a use-after-free that the type cannot prevent and the player is careful about — see VideoPlayer, where the queue owns every frame it has not handed out.

Fields and properties (6)

  • public VideoFormat Format

    What the frame holds and how to read it.

  • public TimeSpan Timestamp

    When it should be shown, measured from the start of the stream.

  • public TimeSpan Duration

    How long it stays on screen, or Zero if nothing said.

  • public bool IsKeyFrame

    Whether the stream could be joined at this frame.

  • public int Size

    How many bytes of Pixels the picture occupies.

  • public ReadOnlySpan<byte> Pixels

    Every plane, end to end.

Methods (7)

  • public void Reset(in VideoFormat format)

    Points the frame at a format, allocating if what it has will not do.

  • public int Stride(int plane)

    How many bytes one row of a plane takes.

  • public int Offset(int plane)

    Where a plane starts within Pixels.

  • public Span<byte> Plane(int plane)

    A plane, to write into.

  • public Span<byte> Row(int plane, int row)

    One row of a plane, to write into.

  • public void CopyFrom(VideoFrame source)

    Copies another frame's pixels and timing into this one.

  • public void Clear()

    Fills the frame with black.

Used by (21)

  • ColourRoundTripTestsVixen.Video.Tests
  • CountingCodecVixen.Video.Tests
  • IVideoCodecVixen.Video
  • IVideoStreamDecoderVixen.Video
  • MatroskaAudioTestsVixen.Video.Tests
  • OpusAudioTrackTestsVixen.Video.Codecs.Tests
  • StarvedDecoderVixen.Video.Tests
  • StepDecoderVixen.Video.Tests
  • UncompressedVideoCodecVixen.Video
  • VideoColourConversionVixen.Video
  • VideoColourConversionTestsVixen.Video.Tests
  • VideoConstantsTestsVixen.Video.Rendering.Tests
  • VideoFramePoolVixen.Video
  • VideoFrameTestsVixen.Video.Tests
  • VideoPlayerVixen.Video
  • VideoPlayerTestsVixen.Video.Tests
  • VideoRendererTestsVixen.Video.Rendering.Tests
  • VideoTextureVixen.Video
  • VideoTextureTestsVixen.Video.Tests
  • WebMVideoStreamDecoderVixen.Video
  • WebMVideoStreamDecoderTestsVixen.Video.Tests