pub enum Sent {
Accepted,
MustDrain,
}Expand description
What a submission answered.
Returned by every send_packet / send_frame / send_eof in this
crate — VideoStreamDecoder,
AudioStreamDecoder,
SubtitleDecoder,
AudioResampler, and their
future mirrors.
§The name
MustDrain means nothing was sent, so the type’s
name is read as what the send call answered rather than as a claim
that a send happened — exactly as Received::NeedsInput is read.
The pair is named for the two calls, not for the two outcomes,
because that is what a caller is holding when it reads one.
§The feeder loop
use mediadecode::{Received, Sent, decoder::AudioStreamDecoder};
/// Feeds one packet, draining as required, and delivers every frame
/// it makes ready. Answers `true` once the stream is over.
fn feed<D: AudioStreamDecoder>(
decoder: &mut D,
packet: &Packet<D>,
dst: &mut Frame<D>,
mut on_frame: impl FnMut(&Frame<D>),
) -> Result<bool, D::Error> {
loop {
// `?` means what it says on both faces: only a fault leaves.
match decoder.send_packet(packet)? {
Sent::Accepted => break,
// Not a failed submission — a full decoder. Drain and
// re-offer *this same packet*; nothing consumed it.
Sent::MustDrain => loop {
match decoder.receive_frame(dst)? {
Received::Frame => on_frame(dst),
Received::NeedsInput | Received::Ended => break,
}
},
}
}
loop {
match decoder.receive_frame(dst)? {
Received::Frame => on_frame(dst),
Received::NeedsInput => return Ok(false),
Received::Ended => return Ok(true),
}
}
}That loop is the point. Under the older convention it could not be
written against the trait at all: “drain me first” and “this packet
is damaged” were both Err, indistinguishable to a generic
consumer, so the idiom that survived was to offer the packet
twice — submit, drain on any failure, submit again, and treat the
second failure as real. Twice, because once meant nothing.
Variants§
Accepted
The session took it. A packet is consumed; an end-of-stream is recorded.
MustDrain
Nothing was consumed. The session cannot take more until its
output is drained: call
receive_frame
until it stops producing, then offer the same packet again.
This is back pressure, not refusal. The submission left no trace — the packet is still the caller’s to re-send, and the session’s state is exactly what it was before the call.
Implementations§
Source§impl Sent
impl Sent
Sourcepub const fn is_accepted(&self) -> bool
pub const fn is_accepted(&self) -> bool
Returns true if this value is of type Accepted. Returns false otherwise
Sourcepub const fn is_must_drain(&self) -> bool
pub const fn is_must_drain(&self) -> bool
Returns true if this value is of type MustDrain. Returns false otherwise