Skip to main content

Element

Trait Element 

Source
pub trait Element: Send {
    // Required methods
    fn name(&self) -> Arc<str> ;
    fn element_type(&self) -> ElementType;
    fn pp_log(&self) -> &PpLog;
    fn pp_log_mut(&mut self) -> &mut PpLog;

    // Provided methods
    fn graph_id(&self) -> Option<ElementId> { ... }
    fn attach_context(&mut self, _context: &Arc<Context>) { ... }
}
Expand description

A node in the pipeline graph with a name. Plain identity only — says nothing about whether the node has an input, an output, both, or neither.

Required Methods§

Source

fn name(&self) -> Arc<str>

Returns a cheap clone (refcount bump, not a deep copy) of this element’s name — crate::bus::BusEvent stores names as Arc<str> for exactly this reason: a hot path like crate::queue::Queue posting BusEvent::Dropped once per overflowed buffer shouldn’t pay for a fresh heap allocation every time it wants to report which element it is.

Source

fn element_type(&self) -> ElementType

Source

fn pp_log(&self) -> &PpLog

This element’s identity for crate::bus::Bus::post — same id/name as Element::name, just already wrapped as the crate::pp_log::PpLog its pp_info!/pp_warn!/pp_error! macros need. A stored private field, not built fresh per call, for the same reason name() returns a cheap Arc<str> clone instead of a fresh String — see its own docs.

Source

fn pp_log_mut(&mut self) -> &mut PpLog

Mutable access to the same field Element::pp_log reads — used by crate::pipeline::ChainBuilder to stamp the owning crate::pipeline::Pipeline’s id onto every element that passes through it, via element_pp_log. Not meant to be called from anywhere else.

Provided Methods§

Source

fn graph_id(&self) -> Option<ElementId>

A pre-reserved graph identity for elements that expose dynamic attachment handles. Most elements receive an ID from ChainBuilder and keep the default None implementation.

Source

fn attach_context(&mut self, _context: &Arc<Context>)

Hands this element the pipeline it is being wired into, at the moment and for the reason Element::pp_log_mut hands it the pipeline’s identity: the clock, the playback clock and the bus are the pipeline’s to give, not the caller’s to choose.

§Why this is not a constructor argument

It used to be, and an element could then be handed a clock from somewhere else entirely. That fails quietly. A Pacer on a foreign clock never sees Pipeline::pause shift the anchor and goes on pacing through a paused pipeline; an audio renderer registered on a foreign PlaybackClock succeeds — nothing is holding that one — and the video scheduled against the pipeline’s own clock simply never hears about it. No error either way, just timing that does not work.

Taking it here instead makes the mistake unrepresentable: there is nowhere else to get one from.

§What an implementation should do

Take what it needs and let the rest go. Holding the context keeps the graph and the bus alive for as long as the element, and invites reaching into the pipeline at moments it is not expecting one. crate::elements::Tee is the exception and has a reason: it builds branches later.

Called once, before any buffer arrives — from the branch wiring for a filter or a terminal, and from crate::pipeline::PipelineBuilder::add_source for a source. An element that needs something from it and never receives one has been built outside a pipeline, which is a wiring mistake rather than a runtime condition; say so with a typed error rather than carrying on unpaced.

Claiming something exclusive here — the playback clock’s audio master is the only such thing today — is settled once, when the element is wired. A second claimant loses and is not offered the role again if the first one later goes away.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl Element for AppSource

Source§

impl Element for AudioMixer

Source§

impl Element for AudioResampler

Source§

impl Element for AudioVolume

Source§

impl Element for ChangeGate

Source§

impl Element for FileDemuxer

Source§

impl Element for FileMuxerStreamSink

Source§

impl Element for FrameCounter

Source§

impl Element for FrameRateLimiter

Source§

impl Element for HlsMuxerStreamSink

Source§

impl Element for MixerInputSink

Source§

impl Element for Pacer

Source§

impl Element for PacketCounter

Source§

impl Element for PauseGate

Source§

impl Element for PipelineBridge

Source§

impl Element for Queue

Source§

impl Element for RtspSink

Source§

impl Element for RtspSource

Source§

impl Element for SwAudioEncoder

Source§

impl Element for SwChromaKey

Source§

impl Element for SwDecoder

Source§

impl Element for SwEncoder

Source§

impl Element for SwScaler

Source§

impl Element for SwVideoCompositor

Source§

impl Element for SwVideoCompositorInputSink

Source§

impl Element for Tee

Source§

impl Element for TestAudioSource

Source§

impl Element for TestVideoSource

Source§

impl Element for TimestampOrigin

Source§

impl Element for VideoSynchronizer

Source§

impl Element for WebRtcPeer

Available on crate feature webrtc only.
Source§

impl Element for WebRtcTrackSink

Available on crate feature webrtc only.
Source§

impl Element for WebRtcTrackSource

Available on crate feature webrtc only.
Source§

impl<F, C> Element for AppSink<F, C>
where F: FnMut(MediaBuffer) -> Result<()> + Send + 'static, C: FnMut(ControlMsg) -> Result<()> + Send + 'static,

Source§

impl<F> Element for OrtDetector<F>
where F: FnMut(&Video, &[Detection]) -> Result<()> + Send + 'static,

Available on crate feature ort only.