Skip to main content

Crate moq_ext_sources

Crate moq_ext_sources 

Source
Expand description

Media sources for moq_video and moq_audio that upstream moq lacks.

A source is an opened device, file or generator that produces raw frames, on a thread of its own, for a publisher to encode. A VideoSource can feed several encoders at once and offers a latest-wins preview through VideoFrames. An AudioSource fans PCM out to every broadcast that reads it.

The crate has no dependency on iroh and none on a transport. Its Error is the one the player and the publisher return too, so an error passes from a source to a broadcast unchanged. SlotState is the state of a media slot on a broadcast and on a player, so a UI reports both the same way, and stats counts rates the same way on both sides.

The sources, their constructors and the features they need:

SourceConstructorFeature
Test pictureVideoSource::test_pattern, AudioSource::test_patternpattern
Moving gradientVideoSource::test_gradientpattern
Bouncing square, also drawn on demandVideoSource::test_bounce, BouncePatternpattern for the source
Sine toneAudioSource::tonepattern
WAV, MP3 and MP4 audio fileAudioSource::filefile
MP4 file, decoded or passed throughMediaFilefile
Camera, display, windowVideoSource::capture, VideoSource::camera, VideoSource::screencapture
MicrophoneAudioSource::microphonecapture
Raspberry Pi camera through rpicam-vidVideoSource::rpicam, rpicam_h264rpicam (Linux)
Pushed by the applicationVideoSource::push, AudioSource::push, VideoSource::spawn, AudioSource::spawnalways
Any of the above, switched while publishedVideoSource::switchablealways

EncodedVideo and EncodedAudio are media that arrives encoded, from MediaFile or rpicam_h264, for a broadcast to publish without an encoder.

VideoSource::scaled scales any of them to a fixed size as CPU I420, not for publishing.

PortalGrant keeps the desktop portal’s grant in a file, so a later run can skip the picker (Linux, pipewire feature).

Backend is a choice of video encoder or decoder backend, as a --encoder or --decoder flag takes it.

spec parses text specifiers such as cam:2 or test:gradient, as a --video or --audio flag takes them, and opens the source they name.

The crate README lists every feature flag. local_task::spawn runs a future on a thread of its own for capture streams that are not Send.

Most of this belongs upstream. The pattern and tone generators fit in moq-video, the audio file source in moq-audio, and the rpicam source as a moq-video capture backend.

Every constructor that is async is cancellation safe. Dropping the future stops the thread or subprocess it started and releases the device. VideoFrames::next and FrameSender::closed lose nothing when dropped.

§Examples

use moq_ext_sources::VideoSource;

let source = VideoSource::test_pattern(
    moq_video::Size::new(640, 360),
    moq_video::FrameRate::new(30, 1).expect("a valid rate"),
)
.expect("the pattern thread starts");
let mut frames = source.frames();
while let Some(frame) = frames.next().await {
    // draw `frame`
}

Re-exports§

pub use self::backend::Backend;
pub use self::backend::UnknownBackend;
pub use self::bounce::BouncePattern;
pub use self::encoded::EncodedAudio;
pub use self::encoded::EncodedFrame;
pub use self::encoded::EncodedVideo;
pub use self::error::Error;
pub use self::error::SourceClosed;
pub use self::frames::VideoFrames;
pub use self::source::AudioFormat;
pub use self::source::AudioSource;
pub use self::source::FileEnd;
pub use self::source::FrameSender;
pub use self::source::VideoFormat;
pub use self::source::VideoSource;
pub use self::source::VideoSwitch;
pub use self::status::ByPtr;
pub use self::status::SlotState;

Modules§

frames
Latest-frame-wins video frames, with a cursor per handle.
local_task
A task on a thread of its own, for capture streams that cannot move.
spec
Text specifiers that name a video or an audio source, and open it.
stats
Small helpers for the figures a broadcast and a player report.

Structs§

AudioFormat
The sample rate and speaker layout of a raw audio source.
AudioInfo
The audio track of a MediaFile.
AudioSource
A raw audio source.
BouncePattern
A white square bouncing left and right on a background that drifts through the hues.
ByPtr
An Arc that compares by pointer, so a watcher tells an update from a repeat.
EncodedFrame
One encoded frame and the time it presents at.
FrameSender
The push end of a source.
MediaFile
An MP4 file, ready to publish as it is or to decode.
MediaInfo
What a MediaFile holds, as MediaFile::info reports it.
PortalGrant
A desktop portal grant kept in a file, so a later run can skip the picker.
RpicamConfig
How to run the Raspberry Pi camera.
SourceClosed
The source a FrameSender feeds has gone.
UnknownBackend
An error from parsing a backend name that is no strategy and no known backend.
VideoFileConfig
How MediaFile::video decodes the video.
VideoFormat
The size and cadence of a raw video source.
VideoInfo
The video track of a MediaFile.
VideoSource
A raw video source running on its own thread.
VideoSwitch
The handle that swaps the input of a VideoSource::switchable source.

Enums§

Backend
A choice of encoder or decoder backend: a strategy, or one backend by name.
EncodedAudio
Encoded audio for LocalBroadcast::set_encoded_audio.
EncodedVideo
Encoded video for LocalBroadcast::set_encoded_video.
Error
An error from the media crates.
FileEnd
What a file source does when it reaches the end of the file.
SlotState
The state of one media slot, on a broadcast or on a player.

Functions§

rpicam_h264
Starts the Raspberry Pi camera’s hardware H.264 through rpicam-vid.
screen_source
Returns the capture source of the main screen, as VideoSource::screen opens it.