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§
Sourcefn name(&self) -> Arc<str> ⓘ
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.
Sourcefn element_type(&self) -> ElementType
fn element_type(&self) -> ElementType
See ElementType.
Sourcefn pp_log(&self) -> &PpLog
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.
Sourcefn pp_log_mut(&mut self) -> &mut PpLog
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§
Sourcefn graph_id(&self) -> Option<ElementId>
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.
Sourcefn attach_context(&mut self, _context: &Arc<Context>)
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§
impl Element for AppSource
impl Element for AudioMixer
impl Element for AudioResampler
impl Element for AudioVolume
impl Element for ChangeGate
impl Element for FileDemuxer
impl Element for FileMuxerStreamSink
impl Element for FrameCounter
impl Element for FrameRateLimiter
impl Element for HlsMuxerStreamSink
impl Element for MixerInputSink
impl Element for Pacer
impl Element for PacketCounter
impl Element for PauseGate
impl Element for PipelineBridge
impl Element for Queue
impl Element for RtspSink
impl Element for RtspSource
impl Element for SwAudioEncoder
impl Element for SwChromaKey
impl Element for SwDecoder
impl Element for SwEncoder
impl Element for SwScaler
impl Element for SwVideoCompositor
impl Element for SwVideoCompositorInputSink
impl Element for Tee
impl Element for TestAudioSource
impl Element for TestVideoSource
impl Element for TimestampOrigin
impl Element for VideoSynchronizer
impl Element for WebRtcPeer
webrtc only.impl Element for WebRtcTrackSink
webrtc only.impl Element for WebRtcTrackSource
webrtc only.impl<F, C> Element for AppSink<F, C>where
F: FnMut(MediaBuffer) -> Result<()> + Send + 'static,
C: FnMut(ControlMsg) -> Result<()> + Send + 'static,
impl<F> Element for OrtDetector<F>
ort only.