Skip to main content

RtmpSession

Struct RtmpSession 

Source
pub struct RtmpSession { /* private fields */ }
Expand description

Active publish after accept. Iterate via RtmpSession::next_packet.

Implementations§

Source§

impl RtmpSession

Source

pub fn app(&self) -> &str

Source

pub fn stream_name(&self) -> &str

Source

pub fn publish_type(&self) -> &str

Source

pub fn peer_addr(&self) -> SocketAddr

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn close(self) -> Result<()>

Close the session politely.

On the wire we emit, in order:

  1. 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).
  2. onStatus(NetStream.Unpublish.Success) on the publish stream.
  3. 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.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.