Skip to main content

AsyncRtspClient

Struct AsyncRtspClient 

Source
pub struct AsyncRtspClient<S> { /* private fields */ }
Available on crate feature tokio only.
Expand description

An async RTSP client that owns a socket and drives a ClientSession.

Each request method (options/describe/setup/play/pause/teardown) writes the request bytes the session produces, reads the response off the socket, feeds it through the sans-IO engine, and returns the resulting ClientEvents. A Digest 401 is answered transparently: when the engine emits ClientEvent::AuthRetry, the adapter writes the retried request and reads its response before returning, so the caller only sees the final ClientEvent::Response.

Interleaved media ($-framed RTP/RTCP, §10.12) is pulled with recv_interleaved.

Implementations§

Source§

impl AsyncRtspClient<TcpStream>

Source

pub async fn connect<A: ToSocketAddrs>(addr: A) -> Result<Self>

Connects a plain-TCP (rtsp://) client to addr.

addr is any tokio::net::ToSocketAddrs; for the RTSP default port use (host, RTSP_DEFAULT_PORT).

Source

pub async fn connect_with<A: ToSocketAddrs>( addr: A, session: ClientSession, ) -> Result<Self>

Connects a plain-TCP client to addr using a pre-configured session (e.g. one carrying Credentials).

Source

pub async fn connect_with_timeouts<A: ToSocketAddrs>( addr: A, session: ClientSession, timeouts: RtspTimeouts, ) -> Result<Self>

Like connect_with, with explicit RtspTimeouts.

Source§

impl<S> AsyncRtspClient<S>
where S: AsyncRead + AsyncWrite + Unpin,

Source

pub fn with_stream(stream: S, session: ClientSession) -> Self

Wraps an already-connected stream (plain or TLS) and a session, with the default RtspTimeouts.

Source

pub fn with_stream_timeouts( stream: S, session: ClientSession, timeouts: RtspTimeouts, ) -> Self

Wraps an already-connected stream with explicit RtspTimeouts.

Source

pub fn timeouts(&self) -> RtspTimeouts

The timeouts this adapter applies.

Source

pub fn state(&self) -> SessionState

The current session state.

Source

pub fn session_id(&self) -> Option<&str>

The negotiated session id, once a SETUP response has been processed.

Source

pub fn session(&self) -> &ClientSession

Borrows the underlying sans-IO session (read-only inspection).

Source

pub async fn options(&mut self, uri: &str) -> Result<ClientEvent>

Sends OPTIONS and awaits the response.

Source

pub async fn describe(&mut self, uri: &str) -> Result<ClientEvent>

Sends DESCRIBE (with Accept: application/sdp) and awaits the response.

Source

pub async fn setup( &mut self, uri: &str, transport: &Transport, ) -> Result<ClientEvent>

Sends SETUP carrying transport and awaits the response.

Source

pub async fn play(&mut self, uri: &str) -> Result<ClientEvent>

Sends PLAY and awaits the response.

Source

pub async fn pause(&mut self, uri: &str) -> Result<ClientEvent>

Sends PAUSE and awaits the response.

Source

pub async fn teardown(&mut self, uri: &str) -> Result<ClientEvent>

Sends TEARDOWN and awaits the response.

Source

pub async fn get_parameter( &mut self, uri: &str, body: &[u8], ) -> Result<ClientEvent>

Sends GET_PARAMETER (empty body = liveness ping) and awaits the response.

Source

pub async fn announce(&mut self, uri: &str, sdp: &str) -> Result<ClientEvent>

Sends ANNOUNCE carrying sdp and awaits the response (RFC 2326 §10.3) — the first request of an RTSP push (ANNOUNCE -> SETUP -> record).

Source

pub async fn record(&mut self, uri: &str) -> Result<ClientEvent>

Sends RECORD and awaits the response (RFC 2326 §10.11) — starts the media push negotiated by a preceding announce + setup.

Source

pub async fn send_interleaved( &mut self, channel: u8, payload: &[u8], ) -> Result<()>

Sends payload as an interleaved ($-framed) media packet on channel (§10.12) — the mirror of the server’s AsyncRtspServer::send_interleaved, for an RTSP push that delivers media interleaved over the control connection. The frame is built by crate::interleaved::InterleavedFrame::new and the write is bounded by RtspTimeouts::write.

Before the write this drives the push keepalive (see poll_keepalive) and drains any server→client bytes already buffered, so a SEND-ONLY pusher that only ever calls this method still refreshes its session and does not let the peer’s responses/notifications fill the socket buffer (RFC 2326 §12.37).

A Timeout/cancelled write leaves a partial $ frame in the codec’s write buffer and the connection is dead — an interleaved frame cannot be resynchronised mid-flight, so the caller must reconnect rather than retry. Bytes already read stay buffered.

Source

pub async fn poll_keepalive(&mut self) -> Result<()>

Drive the RTSP keepalive for a SEND-ONLY pusher: if the session’s keepalive deadline (ClientSession::poll_timeout) has passed, write a GET_PARAMETER liveness ping now. A no-op otherwise. Honours the crate’s rule that only requests we send count as keepalive activity (inbound media/responses never do — see next_event), and the same half-timeout floor inside poll_timeout.

send_interleaved calls this automatically; call it directly from a pusher loop that sends media by any other path (e.g. a separate RTCP/send split), or when the media flow is idle.

Source

pub async fn recv_interleaved(&mut self) -> Result<Option<ClientEvent>>

Receives the next interleaved media frame (ClientEvent::MediaData), driving the socket until one is available (§10.12).

Returns Ok(None) if the peer closes the connection cleanly before a frame arrives. Any control responses interleaved with media are consumed and their state transitions applied, but not returned here.

While waiting, a GET_PARAMETER keepalive is sent at half the session timeout (ClientSession::poll_timeout), so an idle-but-healthy stream does not lose its session.

Source§

impl AsyncRtspClient<TlsStream<TcpStream>>

Source

pub async fn connect_tls<A: ToSocketAddrs>( addr: A, server_name: &str, config: ClientConfig, ) -> Result<Self>

Available on crate feature tls only.

Connects an rtsps:// (TLS) client to addr, verifying the server against the given config and presenting server_name for SNI/cert validation.

For the public-CA default trust store, build config with default_tls_client_config. For a self-signed camera cert, build a rustls::ClientConfig whose root store contains that cert. For the rtsps default port use (host, RTSPS_DEFAULT_PORT).

Source

pub async fn connect_tls_with<A: ToSocketAddrs>( addr: A, server_name: &str, config: ClientConfig, session: ClientSession, ) -> Result<Self>

Available on crate feature tls only.

Connects an rtsps:// (TLS) client to addr using a pre-configured session (e.g. one carrying Credentials via ClientSession::with_credentials), otherwise identical to connect_tls.

Source

pub async fn connect_tls_with_timeouts<A: ToSocketAddrs>( addr: A, server_name: &str, config: ClientConfig, session: ClientSession, timeouts: RtspTimeouts, ) -> Result<Self>

Available on crate feature tls only.

Like connect_tls_with, with explicit RtspTimeouts: connect bounds the TCP connect, handshake the TLS handshake.

Trait Implementations§

Source§

impl<S: Debug> Debug for AsyncRtspClient<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> Freeze for AsyncRtspClient<S>
where Framed<S, ClientCodec>: Freeze,

§

impl<S> RefUnwindSafe for AsyncRtspClient<S>
where Framed<S, ClientCodec>: RefUnwindSafe,

§

impl<S> Send for AsyncRtspClient<S>
where Framed<S, ClientCodec>: Send,

§

impl<S> Sync for AsyncRtspClient<S>
where Framed<S, ClientCodec>: Sync,

§

impl<S> Unpin for AsyncRtspClient<S>
where Framed<S, ClientCodec>: Unpin,

§

impl<S> UnsafeUnpin for AsyncRtspClient<S>
where Framed<S, ClientCodec>: UnsafeUnpin,

§

impl<S> UnwindSafe for AsyncRtspClient<S>
where Framed<S, ClientCodec>: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V