Skip to main content

drain_control

Function drain_control 

Source
pub fn drain_control<S: SourceElement>(
    control: &ControlReceiver,
    source: &mut S,
    bus: &Bus,
) -> Result<ControlOutcome>
Expand description

Call once per loop iteration in a SourceElement::run implementation, right before pulling the next unit of work — mirrors how a natural Eos is pushed into the source’s own pads at the end of that same loop, just for externally-triggered control instead.

Drains every pending message (see apply_one for what “handling one” means, including Pause’s blocking wait). Non-blocking if nothing’s pending — a SourceElement::run whose own “next unit of work” can’t be waited on via control’s own channel (e.g. crate::elements::FileDemuxer’s blocking file read) calls this once before that blocking step; one that can (e.g. crate::elements::AppSource’s channel receive) selects on both instead, calling apply_one/wait_out_pause directly so a pending Stop/Finish is never left waiting behind a slow/absent producer — same reason WasapiCaptureSource also drives the raw receiver directly, to bracket the wait with resetting/restarting its capture device rather than leaving it running unread through the whole pause.

See ControlOutcome for what the return value means.