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:
| Source | Constructor | Feature |
|---|---|---|
| Test picture | VideoSource::test_pattern, AudioSource::test_pattern | pattern |
| Moving gradient | VideoSource::test_gradient | pattern |
| Bouncing square, also drawn on demand | VideoSource::test_bounce, BouncePattern | pattern for the source |
| Sine tone | AudioSource::tone | pattern |
| WAV, MP3 and MP4 audio file | AudioSource::file | file |
| MP4 file, decoded or passed through | MediaFile | file |
| Camera, display, window | VideoSource::capture, VideoSource::camera, VideoSource::screen | capture |
| Microphone | AudioSource::microphone | capture |
Raspberry Pi camera through rpicam-vid | VideoSource::rpicam, rpicam_h264 | rpicam (Linux) |
| Pushed by the application | VideoSource::push, AudioSource::push, VideoSource::spawn, AudioSource::spawn | always |
| Any of the above, switched while published | VideoSource::switchable | always |
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§
- Audio
Format - The sample rate and speaker layout of a raw audio source.
- Audio
Info - The audio track of a
MediaFile. - Audio
Source - A raw audio source.
- Bounce
Pattern - A white square bouncing left and right on a background that drifts through the hues.
- ByPtr
- An
Arcthat compares by pointer, so a watcher tells an update from a repeat. - Encoded
Frame - One encoded frame and the time it presents at.
- Frame
Sender - The push end of a source.
- Media
File - An MP4 file, ready to publish as it is or to decode.
- Media
Info - What a
MediaFileholds, asMediaFile::inforeports it. - Portal
Grant - A desktop portal grant kept in a file, so a later run can skip the picker.
- Rpicam
Config - How to run the Raspberry Pi camera.
- Source
Closed - The source a
FrameSenderfeeds has gone. - Unknown
Backend - An error from parsing a backend name that is no strategy and no known backend.
- Video
File Config - How
MediaFile::videodecodes the video. - Video
Format - The size and cadence of a raw video source.
- Video
Info - The video track of a
MediaFile. - Video
Source - A raw video source running on its own thread.
- Video
Switch - The handle that swaps the input of a
VideoSource::switchablesource.
Enums§
- Backend
- A choice of encoder or decoder backend: a strategy, or one backend by name.
- Encoded
Audio - Encoded audio for
LocalBroadcast::set_encoded_audio. - Encoded
Video - 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.
- Slot
State - 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::screenopens it.