Advanced
Draw video frames
Player::video_frames() returns a VideoFrames stream of decoded
moq_video::Frame values, as Watch a broadcast shows.
It holds only the newest frame, so a renderer that falls behind skips to the
newest picture. This page draws those frames on screen.
Draw with wgpu
On the desktop, frames are drawn through wgpu, which needs the render
feature. moq_video::render::Renderer::new(device, queue, config) binds a
renderer to a wgpu device and queue, and render(&frame) returns a
wgpu::Texture to present, hand to a UI toolkit, or copy back.
moq-video documents backend
selection, color handling and zero-copy import.
- The renderer fixes the wgpu version.
iroh_live::media::wgpure-exports the wgpu it links, so name wgpu types through it instead of depending on wgpu yourself. A texture from another wgpu major version is a different type. - On Linux, request
wgpu::Features::VULKAN_EXTERNAL_MEMORY_DMA_BUFwhen you create the device. Without it, frames that arrive as DMA-BUFs, such as hardware-decoded video and PipeWire screen capture, are copied through the CPU.
Draw in egui
The moq-ext-egui crate draws frames in egui. VideoView draws a
VideoFrames stream:
use iroh_live::media::Player;
use moq_ext_egui::VideoView;
fn create(
ctx: &egui::Context,
player: &Player,
render_state: Option<&egui_wgpu::RenderState>,
) -> VideoView {
VideoView::new(ctx, "video", player.video_frames(), render_state)
}
// In the update loop.
fn draw(ui: &mut egui::Ui, view: &mut VideoView) {
ui.add(view.render());
}
Without a render_state, the view shows a black placeholder. The view wakes
the window when a frame arrives. set_frames switches to another stream and
keeps the last picture until the new stream delivers one. VideoView::new
must run inside a Tokio runtime.
Pass moq_ext_egui::egui_wgpu_config() to eframe as its wgpu_options:
let options = eframe::NativeOptions {
wgpu_options: moq_ext_egui::egui_wgpu_config(),
..Default::default()
};
drop(options);
On Linux it selects Vulkan and enables VULKAN_EXTERNAL_MEMORY_DMA_BUF when
the adapter supports it, which eframe does not do on its own. On every
platform it requests the adapter’s own limits, so the window also opens on a
GPU with limits below wgpu’s defaults. A view logs once at INFO when its
device leaves out a DMA-BUF import the adapter offers.
FrameView draws frames that you hand it with render_frame, and
overlay::DebugOverlay draws the stats bar that irl watch shows. An egui
update cannot await, so Pending::spawn runs a future such as a dial on the
runtime, and the window asks poll() on each frame until the result is
there. The call tutorial puts these together.
Other toolkits
A toolkit that shares a wgpu device can draw the renderer’s texture directly.
Otherwise, moq_video::Surface::to_rgba converts a frame to RGBA8 pixels on
the CPU. No library crate has a GLES renderer. The Pi demo has one in
demos/pi-zero/src/gles.rs, as
Publish from a Raspberry Pi describes.
Where to go next
- Tune quality and latency pins a rendition and picks the decoder.
- Subscribing explains decoding.