pub trait VideoFrame:
Any
+ Send
+ Sync {
// Required methods
fn width(&self) -> u32;
fn height(&self) -> u32;
fn read_pixels(&self) -> ImageFuture<PixelBuffer>;
fn hardware_buffer(&self) -> Arc<dyn HardwareBuffer> ⓘ;
fn rotation(&self) -> u32;
fn flip(&self) -> bool;
// Provided methods
fn timestamp(&self) -> Option<i64> { ... }
fn duration(&self) -> Option<Duration> { ... }
fn visible_rect(&self) -> PixelRect { ... }
fn pixel_aspect(&self) -> PixelAspect { ... }
fn color(&self) -> VideoColor { ... }
fn hdr_metadata(&self) -> Option<HdrMetadata> { ... }
}Expand description
One picture of a video as the system hands it out, as WebCodecs’ VideoFrame: lent with its
slot in the decoder’s pool, which it holds until it, its hardware buffer and every texture
imported of the buffer are dropped. Its memory is a HardwareBuffer,
GPU memory the system’s compositor reaches too, which the app draws through a texture it
imports (Platform::import_texture), the hardware codecs
encode and a composition layer shows; memory the app holds of its own, which no pool waits for,
is a buffer it allocates (HardwareBufferAllocator) or an
image the hardware codecs decoded.
Each host implements it over the frames its system hands out. Platform code reaches the
system’s own frame by downcasting through Any to the type of the host that handed it out:
on Apple’s systems waft-embedder-winit’s CoreVideoFrame, whose pixel_buffer is the
CVPixelBuffer AVFoundation handed out.
Required Methods§
Sourcefn read_pixels(&self) -> ImageFuture<PixelBuffer>
fn read_pixels(&self) -> ImageFuture<PixelBuffer>
The frame’s pixels copied into the app’s memory, in the layout the frame holds them: BGRA
on Apple’s systems. The one way back from GPU memory to the app’s;
ImageErrorKind::Unsupported for a
frame whose pixels are in no PixelFormat, as a
decoder’s planes (HardwareBufferFormat::Nv12 and
P010) are.
Sourcefn hardware_buffer(&self) -> Arc<dyn HardwareBuffer> ⓘ
fn hardware_buffer(&self) -> Arc<dyn HardwareBuffer> ⓘ
The frame’s memory, for sampling, which keeps the frame, and its slot in the pool, while it and every texture imported of it are held: what the app draws through a texture it imports, the hardware codecs encode and a composition layer shows.
Sourcefn rotation(&self) -> u32
fn rotation(&self) -> u32
The rotation applied to the frame when it is shown, in degrees clockwise: 0, 90, 180 or
270, as WebCodecs’ VideoFrame.rotation. It applies before flip. The
pixels are not turned: width and height are the
frame’s own, so a frame turned a quarter shows height wide. A camera’s frame on a phone
is turned so, unless its session asked for upright frames.
Provided Methods§
Sourcefn timestamp(&self) -> Option<i64>
fn timestamp(&self) -> Option<i64>
When the picture is shown, in nanoseconds on its stream’s own timeline: for a decoder’s
frame, the timestamp of the chunk it came from. None for a frame whose source gives
none, as a reader’s, which comes for a display time.
Sourcefn visible_rect(&self) -> PixelRect
fn visible_rect(&self) -> PixelRect
The part of the frame’s memory that is picture, in its own pixels and before
rotation. A decoder pads a picture to its blocks’ size, so the memory
may be larger than the picture: 1920 by 1088 for a picture of 1920 by 1080. All of it,
for a frame whose source pads nothing.
Sourcefn pixel_aspect(&self) -> PixelAspect
fn pixel_aspect(&self) -> PixelAspect
The shape of one pixel, width to height: 1 to 1 unless the video is anamorphic.
Sourcefn color(&self) -> VideoColor
fn color(&self) -> VideoColor
What the samples mean as colour. A frame that says nothing more is red, green and blue over its whole range, as a reader’s is.
Sourcefn hdr_metadata(&self) -> Option<HdrMetadata>
fn hdr_metadata(&self) -> Option<HdrMetadata>
The brightness the picture was mastered for, where its stream says: what a display needs to show an HDR picture.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".