pub struct Engine { /* private fields */ }Expand description
The engine. Many instances may coexist in one process (ideal for tests).
Cheap to Arc-share.
Implementations§
Source§impl Engine
impl Engine
Sourcepub async fn serve(
self: &Arc<Self>,
handlers: Vec<Box<dyn InboundProtocol>>,
shutdown: CancellationToken,
) -> Result<()>
pub async fn serve( self: &Arc<Self>, handlers: Vec<Box<dyn InboundProtocol>>, shutdown: CancellationToken, ) -> Result<()>
Drive the engine: run every protocol handler concurrently until
shutdown fires, then let them observe the cancellation and wind down.
Coordinated teardown: when any handler returns — cleanly, with an
error, or by panicking — the shared shutdown token is cancelled so the
remaining handlers wind down too. A single listener dying never leaves
its siblings orphaned.
Returns the first fatal handler error, if any; otherwise Ok(()) once
all handlers have returned.
Accepts any InboundProtocol worker — the bundled RtmpHandler, a
legacy ProtocolHandler (bridged automatically),
or your own custom protocol. Prefer
EngineBuilder::protocol +
serve_registered for the builder-driven path.
engine.serve(vec![h], CancellationToken::new()).awaitSourcepub async fn serve_until_signal(
self: &Arc<Self>,
handlers: Vec<Box<dyn InboundProtocol>>,
) -> Result<()>
pub async fn serve_until_signal( self: &Arc<Self>, handlers: Vec<Box<dyn InboundProtocol>>, ) -> Result<()>
Like serve, but owns the shutdown trigger: it runs until
Ctrl-C (SIGINT) or, on Unix, SIGTERM — the two signals an
orchestrator (systemd, Kubernetes) uses to stop a process — then cancels
the handlers and waits for them to drain.
This is the batteries-included entry point for a binary; use
serve when the host already owns a cancellation token
(e.g. to compose the engine into a larger shutdown graph).
engine.serve_until_signal(vec![h]).awaitSourcepub async fn serve_registered(
self: &Arc<Self>,
shutdown: CancellationToken,
) -> Result<()>
pub async fn serve_registered( self: &Arc<Self>, shutdown: CancellationToken, ) -> Result<()>
Run the protocol workers registered on the EngineBuilder via
protocol, until shutdown fires.
This is the builder-driven counterpart to serve: register
workers fluently, keep the Arc<Engine> for your own use (subscribing,
packaging), then drive them. The registered workers are consumed on the
first call; a second call serves an empty set.
let engine = Engine::builder()
.application(AppSpec::new("live"))
.protocol(RtmpHandler::new("0.0.0.0:1935".parse().unwrap()))
.build();
engine.serve_registered(CancellationToken::new()).awaitSourcepub async fn serve_registered_until_signal(self: &Arc<Self>) -> Result<()>
pub async fn serve_registered_until_signal(self: &Arc<Self>) -> Result<()>
Like serve_registered but owns the shutdown
trigger, running the builder-registered workers until Ctrl-C/SIGTERM.
Sourcepub async fn pump_source<S: MediaSource>(
self: &Arc<Self>,
key: &StreamKey,
source: S,
shutdown: CancellationToken,
) -> Result<()>
pub async fn pump_source<S: MediaSource>( self: &Arc<Self>, key: &StreamKey, source: S, shutdown: CancellationToken, ) -> Result<()>
Drive a MediaSource into the bus: claim key, pump every frame the
source yields, and end the publish session when the source is exhausted,
errors, or shutdown fires.
This is the first-class runner for the MediaSource trait — the
in-process counterpart to a socket-driven
ProtocolHandler. Useful for
file/loopback ingest, test fixtures, and generated streams.
Sourcepub async fn reap_idle(self: &Arc<Self>) -> usize
pub async fn reap_idle(self: &Arc<Self>) -> usize
Reap every publishing stream that has not received a frame within the
configured idle_timeout. Returns
the number of streams reaped. A no-op when no timeout is configured.
Sourcepub fn spawn_idle_reaper(
self: &Arc<Self>,
interval: Duration,
shutdown: CancellationToken,
)
pub fn spawn_idle_reaper( self: &Arc<Self>, interval: Duration, shutdown: CancellationToken, )
Spawn a background task that calls reap_idle every
interval until shutdown fires. No-op (returns immediately) when no
idle timeout is configured.
Source§impl Engine
impl Engine
Sourcepub fn builder() -> EngineBuilder
pub fn builder() -> EngineBuilder
Start building an engine.
Sourcepub fn register_app(&self, spec: AppSpec) -> Result<()>
pub fn register_app(&self, spec: AppSpec) -> Result<()>
Register an application after construction (e.g. on config reload).
Rejects a name that is already registered with
StreamError::AppAlreadyRegistered rather than silently replacing the
live Application — an overwrite would orphan that app’s active
streams and leak the engine-wide publisher count that gates
StreamError::PublisherLimitReached. To change an app’s settings,
drain and remove it first (a future remove_app), then re-register.
Sourcepub fn total_stream_count(&self) -> usize
pub fn total_stream_count(&self) -> usize
Total active publishers across all applications (single atomic load).
Claim a publish slot only if the injected StreamAuthenticator permits
creds to publish key. Protocol handlers should call this rather than
start_publish directly so the auth
policy is enforced uniformly across every transport.
Resolve a live stream for playback only if the authenticator permits
creds to play key.
Trait Implementations§
Source§impl EventBus for Engine
impl EventBus for Engine
Source§fn subscribe_events(&self, app: &AppName) -> Result<Receiver<StreamEvent>>
fn subscribe_events(&self, app: &AppName) -> Result<Receiver<StreamEvent>>
StreamEvent feed for an application.Source§impl PlaybackRegistry for Engine
impl PlaybackRegistry for Engine
Source§fn get_stream(&self, key: &StreamKey) -> Result<StreamHandle>
fn get_stream(&self, key: &StreamKey) -> Result<StreamHandle>
StreamNotFound.Source§impl PublishRegistry for Engine
impl PublishRegistry for Engine
Source§fn start_publish<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 StreamKey,
) -> Pin<Box<dyn Future<Output = Result<StreamHandle>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn start_publish<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 StreamKey,
) -> Pin<Box<dyn Future<Output = Result<StreamHandle>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
StreamAlreadyPublishing on a live duplicate,
or PublisherLimitReached at capacity.