Skip to main content

RenditionConfig

Trait RenditionConfig 

Source
pub trait RenditionConfig<E: CatalogExt>:
    Clone
    + Send
    + 'static {
    // Required methods
    fn insert(self, catalog: &mut Catalog<E>, name: &str);
    fn get_mut<'a>(
        catalog: &'a mut Catalog<E>,
        name: &str,
    ) -> Option<&'a mut Self>;
    fn remove(catalog: &mut Catalog<E>, name: &str);

    // Provided methods
    fn detects() -> bool { ... }
    fn estimate(&self) -> Estimate { ... }
    fn set_estimate(&mut self, _estimate: Estimate) { ... }
}
Expand description

A catalog config that can be published as a named rendition.

Implement it on your own config type to get the full catalog lifecycle: reservation gating, removal on drop, and optional jitter/bitrate detection. VideoConfig and AudioConfig implement it for every extension; a custom config implements it for the one CatalogExt that holds it. Publish a media track under it with Reserved::track, or a data track with Producer::json_stream and the like when it embeds a data config (see IntoRendition):

#[derive(Serialize, Deserialize, Clone, Default)]
struct Ext {
    #[serde(rename = "com.example.mavlink", default)]
    mavlink: BTreeMap<String, Mavlink>,
}
impl CatalogExt for Ext {}

#[derive(Serialize, Deserialize, Clone)]
struct Mavlink {
    config: JsonConfig,
    sysid: u8,
}

impl AsMut<JsonConfig> for Mavlink {
    fn as_mut(&mut self) -> &mut JsonConfig {
        &mut self.config
    }
}

impl RenditionConfig<Ext> for Mavlink {
    fn insert(self, catalog: &mut Catalog<Ext>, name: &str) {
        catalog.ext.mavlink.insert(name.to_string(), self);
    }
    fn get_mut<'a>(catalog: &'a mut Catalog<Ext>, name: &str) -> Option<&'a mut Self> {
        catalog.ext.mavlink.get_mut(name)
    }
    fn remove(catalog: &mut Catalog<Ext>, name: &str) {
        catalog.ext.mavlink.remove(name);
    }

    // Opt into detection through the embedded config.
    fn detects() -> bool {
        true
    }
    fn estimate(&self) -> Estimate {
        Estimate::default()
            .with_bitrate(self.config.bitrate)
            .with_jitter(self.config.jitter)
            .with_delay(self.config.delay)
    }
    fn set_estimate(&mut self, estimate: Estimate) {
        self.config.bitrate = estimate.bitrate;
        self.config.jitter = estimate.jitter;
        self.config.delay = estimate.delay;
    }
}

let info = moq_net::track::Info::default()
    .with_timescale(moq_net::Timescale::MILLI)
    .with_compression(moq_net::track::Compression::Deflate);
let track = broadcast.create_track("telemetry", info).ok_or(moq_net::Error::Duplicate)?;
// The producer fixes the mode, so the one passed here is only a placeholder.
let entry = Mavlink { config: JsonConfig::new(Mode::Stream), sysid: 1 };
let mut telemetry = catalog.json_stream::<serde_json::Value>(track, entry)?;
telemetry.append(&serde_json::json!({ "heartbeat": 1 }), catalog.clock().now())?;

Note that insert takes the whole Catalog, not just the extension, so the built-in media configs use the same trait. Writing to catalog.video / catalog.audio / catalog.text from a custom config fights the media pipeline for those sections; stay in your own.

Reserved::track and Producer::track enroll the track in the broadcast timeline, measure it, and keep its estimate current automatically.

Required Methods§

Source

fn insert(self, catalog: &mut Catalog<E>, name: &str)

Insert or replace this config under name.

Source

fn get_mut<'a>(catalog: &'a mut Catalog<E>, name: &str) -> Option<&'a mut Self>

Borrow the config stored under name, if it’s present.

Source

fn remove(catalog: &mut Catalog<E>, name: &str)

Remove the config stored under name.

Provided Methods§

Source

fn detects() -> bool

Whether container or data-track writes should update this config’s estimate fields.

Source

fn estimate(&self) -> Estimate

The config’s current Estimate fields. Defaults to none, disabling detection.

Source

fn set_estimate(&mut self, _estimate: Estimate)

Replace the config’s Estimate fields. Defaults to discarding them.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<E: CatalogExt> RenditionConfig<E> for AudioConfig

Source§

fn detects() -> bool

Source§

fn insert(self, catalog: &mut Catalog<E>, name: &str)

Source§

fn get_mut<'a>(catalog: &'a mut Catalog<E>, name: &str) -> Option<&'a mut Self>

Source§

fn remove(catalog: &mut Catalog<E>, name: &str)

Source§

fn estimate(&self) -> Estimate

Source§

fn set_estimate(&mut self, estimate: Estimate)

Source§

impl<E: CatalogExt> RenditionConfig<E> for BinaryConfig

Source§

fn insert(self, catalog: &mut Catalog<E>, name: &str)

Source§

fn get_mut<'a>(catalog: &'a mut Catalog<E>, name: &str) -> Option<&'a mut Self>

Source§

fn remove(catalog: &mut Catalog<E>, name: &str)

Source§

fn detects() -> bool

Source§

fn estimate(&self) -> Estimate

Source§

fn set_estimate(&mut self, estimate: Estimate)

Source§

impl<E: CatalogExt> RenditionConfig<E> for JsonConfig

Source§

fn insert(self, catalog: &mut Catalog<E>, name: &str)

Source§

fn get_mut<'a>(catalog: &'a mut Catalog<E>, name: &str) -> Option<&'a mut Self>

Source§

fn remove(catalog: &mut Catalog<E>, name: &str)

Source§

fn detects() -> bool

Source§

fn estimate(&self) -> Estimate

Source§

fn set_estimate(&mut self, estimate: Estimate)

Source§

impl<E: CatalogExt> RenditionConfig<E> for TextConfig

Source§

fn insert(self, catalog: &mut Catalog<E>, name: &str)

Source§

fn get_mut<'a>(catalog: &'a mut Catalog<E>, name: &str) -> Option<&'a mut Self>

Source§

fn remove(catalog: &mut Catalog<E>, name: &str)

Source§

fn estimate(&self) -> Estimate

Source§

fn set_estimate(&mut self, estimate: Estimate)

Source§

impl<E: CatalogExt> RenditionConfig<E> for VideoConfig

Source§

fn detects() -> bool

Source§

fn insert(self, catalog: &mut Catalog<E>, name: &str)

Source§

fn get_mut<'a>(catalog: &'a mut Catalog<E>, name: &str) -> Option<&'a mut Self>

Source§

fn remove(catalog: &mut Catalog<E>, name: &str)

Source§

fn estimate(&self) -> Estimate

Source§

fn set_estimate(&mut self, estimate: Estimate)

Implementors§