Skip to main content

moq_ext_publisher/
lib.rs

1//! A broadcast that encodes sources into renditions, apart from any transport.
2//!
3//! A [`LocalBroadcast`] holds a catalog, a media clock, one video slot and one
4//! audio slot. The video slot opens its source once and encodes it into a
5//! ladder of renditions, each encoding only while someone watches it. A
6//! transport publishes the broadcast by creating the `broadcast::Producer` it
7//! fills ([`LocalBroadcast::new_in`], or `TryFrom`), so readers get it without
8//! a copy. [`LocalBroadcast::consume`] reads it in-process.
9//!
10//! The sources come from `moq-ext-sources`, and the codecs from `moq_video`
11//! and `moq_audio`. Nothing here depends on iroh or on a player.
12//! [`LocalBroadcast::set_spec`] opens the sources a text specifier such as
13//! `cam` or `file:clip.mp4` names, and sets them in one call.
14//!
15//! # Examples
16//!
17//! ```no_run
18//! # fn example() -> Result<(), moq_ext_publisher::Error> {
19//! use moq_ext_publisher::{LocalBroadcast, VideoEncoding, VideoRendition};
20//! use moq_ext_sources::VideoSource;
21//! use moq_video as video;
22//!
23//! let source = VideoSource::test_pattern(
24//!     video::Size::new(1280, 720),
25//!     video::FrameRate::new(30, 1).expect("a valid rate"),
26//! )
27//! .expect("the pattern thread starts");
28//! let broadcast = LocalBroadcast::new();
29//! broadcast.set_video(
30//!     source,
31//!     VideoEncoding::ladder([VideoRendition::p360(), VideoRendition::p720()]),
32//! )?;
33//! # Ok(())
34//! # }
35//! ```
36//!
37//! A microphone is opened inside the publication that encodes it, so a device
38//! that fails after `AudioSource::microphone` returned shows in
39//! [`LocalBroadcast::status`]. A failed microphone is not opened again: the
40//! audio slot stays failed until the audio is set again.
41
42#![forbid(unsafe_code)]
43
44mod publish;
45mod stats;
46
47/// Audio encoding presets for [`LocalBroadcast::set_audio`].
48///
49/// Each returns an [`AudioEncoding`] with moq-audio's default group span of
50/// 100 ms. [`AudioEncoding::with_group_span`] sets another, such as 20 ms for
51/// finer loss recovery at the cost of more streams.
52pub mod audio_encoding {
53    pub use crate::publish::{music, pcm, voice};
54}
55
56pub use moq_ext_json::{ValueError, ValueWriter};
57pub use moq_ext_sources::{Error, SlotState, SourceClosed};
58
59pub use self::{
60    publish::{
61        AudioEncoding, LocalBroadcast, MediaEncoding, PublishStatus, RenditionState, VideoEncoding,
62        VideoRendition,
63    },
64    stats::{AudioEncodeStats, EncodeStats, PublishStats},
65};