pub struct RtmpSession { /* private fields */ }Expand description
Active publish after accept. Iterate via RtmpSession::next_packet.
Implementations§
Source§impl RtmpSession
impl RtmpSession
pub fn app(&self) -> &str
pub fn stream_name(&self) -> &str
pub fn publish_type(&self) -> &str
pub fn peer_addr(&self) -> SocketAddr
Sourcepub fn set_read_timeout(&mut self, d: Option<Duration>) -> Result<()>
pub fn set_read_timeout(&mut self, d: Option<Duration>) -> Result<()>
Configure a read timeout on the underlying TCP socket — helpful
when you want next_packet to return periodically so an outer
shutdown signal can be observed. Passes through to
TcpStream::set_read_timeout.
The timeout is applied to the chunk reader’s actual socket
clone (the one next_packet reads
through) rather than the session’s bookkeeping clone. On
Linux a sockopt set through one try_clone descriptor carries
to its sibling clones because they share one file description;
Windows assigns each clone its own kernel handle with
independent socket options, so the timeout must be installed
on the exact socket that will issue the recv call.
Sourcepub fn send_stream_dry(&mut self) -> Result<()>
pub fn send_stream_dry(&mut self) -> Result<()>
Emit a UserControl StreamDry(stream_id) event on the publish
stream (RTMP 1.0 §3.7, UCM type 2).
Per spec: “the server sends this event to notify the client
that there is no more data on the stream. If the server does
not detect any message for a time period, it can notify the
subscribed clients that the stream is dry.” Distinct from
close’s StreamEOF: StreamDry is a
transient “we have nothing right now” signal that may resolve
when more data arrives, not a teardown.
Sourcepub fn send_stream_is_recorded(&mut self) -> Result<()>
pub fn send_stream_is_recorded(&mut self) -> Result<()>
Emit a UserControl StreamIsRecorded(stream_id) event on the
publish stream (RTMP 1.0 §3.7, UCM type 4).
Per spec: “the server sends this event to notify the client that the stream is a recorded stream.” A server fronting an archival recorder may want to advertise this after the publish handshake settles so a forwarding peer knows the captured stream is replayable rather than ephemeral.
Sourcepub fn send_ping_request(&mut self, timestamp_ms: u32) -> Result<()>
pub fn send_ping_request(&mut self, timestamp_ms: u32) -> Result<()>
Emit a UserControl PingRequest(timestamp_ms) event (RTMP 1.0
§3.7, UCM type 6).
Per spec, “the server sends this event to test whether the
client is reachable. Event data is a 4-byte timestamp,
representing the local server time when the server dispatched
the command.” The client (our [RtmpClient]) replies with the
matching PingResponse carrying the same 4 bytes —
RtmpClient::poll_event answers the ping internally without
surfacing the request to the publisher caller.
Sourcepub fn send_reconnect_request(
&mut self,
tc_url: Option<&str>,
description: Option<&str>,
) -> Result<()>
pub fn send_reconnect_request( &mut self, tc_url: Option<&str>, description: Option<&str>, ) -> Result<()>
Ask the publisher to reconnect — Enhanced RTMP v2 §“Reconnect Request”.
Emits the onStatus(NetConnection.Connect.ReconnectRequest)
NetConnection command (message stream 0, transaction id 0, null
Command Object). Per the spec’s message flow, a server does
this “prior to the shutdown of the live streaming server or
when the server intends to remap the client to another server
instance” — and when remapping, it MUST pass the target via
tc_url (absolute or relative URI reference; None tells the
client to re-dial the tcUrl of the current connection).
After sending, the spec requires the old server to “continue
processing messages from the client until the client
disconnects” — so keep pumping
next_packet as usual; the publisher
drains up to its next appropriate media boundary (such as a
keyframe) before it actually moves.
Note: per §“Enhancing NetConnection connect Command” the peer
advertises reconnect support via the capsEx
CAPS_EX_RECONNECT bit —
check PublishRequest::capabilities before relying on the
client honouring this event.
Sourcepub fn close(self) -> Result<()>
pub fn close(self) -> Result<()>
Close the session politely.
On the wire we emit, in order:
- A
UserControl StreamEOF(stream_id)event so the peer’s chunk-stream state machine learns the publish is done before it observes the TCP FIN (RTMP 1.0 §7.1.7). onStatus(NetStream.Unpublish.Success)on the publish stream.- A chunk-writer
flush()so every buffered chunk reaches the kernel before the half-close.
Then we send a write-half FIN (Shutdown::Write) rather than
tearing both halves down at once. Shutdown::Both instantly
closes the read half too, which on some platforms makes the
kernel answer the peer’s still-unacked data with a RST and
discard any A/V messages the peer hasn’t yet drained from its
receive buffer — closeStream / the StreamEOF event / the last
frames just written can be thrown away mid-stream. A write-half
FIN lets the peer read everything we just wrote, then observe
EOF cleanly. The read half closes when self (and its owned
TcpStream) drops at end of scope.
Sourcepub fn next_packet(&mut self) -> Result<Option<StreamPacket>>
pub fn next_packet(&mut self) -> Result<Option<StreamPacket>>
Read the next audio / video / metadata packet from the
publisher. Returns Ok(None) when the peer cleanly closed the
stream (via closeStream / deleteStream / FCUnpublish).
Aggregate Messages (RTMP 1.0 §7.1.6, message type id 22) are
decomposed transparently: the sub-messages enter an internal
queue and the dispatch loop drains them in publish order ahead
of any further wire read, so a publisher that bundles several
frames into one aggregate (fewer chunk headers on the wire)
surfaces the same per-frame StreamPacket sequence as a
publisher that sends them individually.