pub struct AsyncRtspClient<S> { /* private fields */ }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>
impl AsyncRtspClient<TcpStream>
Sourcepub async fn connect<A: ToSocketAddrs>(addr: A) -> Result<Self>
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).
Sourcepub async fn connect_with<A: ToSocketAddrs>(
addr: A,
session: ClientSession,
) -> Result<Self>
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).
Sourcepub async fn connect_with_timeouts<A: ToSocketAddrs>(
addr: A,
session: ClientSession,
timeouts: RtspTimeouts,
) -> Result<Self>
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>
impl<S> AsyncRtspClient<S>
Sourcepub fn with_stream(stream: S, session: ClientSession) -> Self
pub fn with_stream(stream: S, session: ClientSession) -> Self
Wraps an already-connected stream (plain or TLS) and a session, with the
default RtspTimeouts.
Sourcepub fn with_stream_timeouts(
stream: S,
session: ClientSession,
timeouts: RtspTimeouts,
) -> Self
pub fn with_stream_timeouts( stream: S, session: ClientSession, timeouts: RtspTimeouts, ) -> Self
Wraps an already-connected stream with explicit RtspTimeouts.
Sourcepub fn timeouts(&self) -> RtspTimeouts
pub fn timeouts(&self) -> RtspTimeouts
The timeouts this adapter applies.
Sourcepub fn state(&self) -> SessionState
pub fn state(&self) -> SessionState
The current session state.
Sourcepub fn session_id(&self) -> Option<&str>
pub fn session_id(&self) -> Option<&str>
The negotiated session id, once a SETUP response has been processed.
Sourcepub fn session(&self) -> &ClientSession
pub fn session(&self) -> &ClientSession
Borrows the underlying sans-IO session (read-only inspection).
Sourcepub async fn options(&mut self, uri: &str) -> Result<ClientEvent>
pub async fn options(&mut self, uri: &str) -> Result<ClientEvent>
Sends OPTIONS and awaits the response.
Sourcepub async fn describe(&mut self, uri: &str) -> Result<ClientEvent>
pub async fn describe(&mut self, uri: &str) -> Result<ClientEvent>
Sends DESCRIBE (with Accept: application/sdp) and awaits the response.
Sourcepub async fn setup(
&mut self,
uri: &str,
transport: &Transport,
) -> Result<ClientEvent>
pub async fn setup( &mut self, uri: &str, transport: &Transport, ) -> Result<ClientEvent>
Sends SETUP carrying transport and awaits the response.
Sourcepub async fn play(&mut self, uri: &str) -> Result<ClientEvent>
pub async fn play(&mut self, uri: &str) -> Result<ClientEvent>
Sends PLAY and awaits the response.
Sourcepub async fn pause(&mut self, uri: &str) -> Result<ClientEvent>
pub async fn pause(&mut self, uri: &str) -> Result<ClientEvent>
Sends PAUSE and awaits the response.
Sourcepub async fn teardown(&mut self, uri: &str) -> Result<ClientEvent>
pub async fn teardown(&mut self, uri: &str) -> Result<ClientEvent>
Sends TEARDOWN and awaits the response.
Sourcepub async fn get_parameter(
&mut self,
uri: &str,
body: &[u8],
) -> Result<ClientEvent>
pub async fn get_parameter( &mut self, uri: &str, body: &[u8], ) -> Result<ClientEvent>
Sends GET_PARAMETER (empty body = liveness ping) and awaits the response.
Sourcepub async fn announce(&mut self, uri: &str, sdp: &str) -> Result<ClientEvent>
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).
Sourcepub async fn record(&mut self, uri: &str) -> Result<ClientEvent>
pub async fn record(&mut self, uri: &str) -> Result<ClientEvent>
Sourcepub async fn send_interleaved(
&mut self,
channel: u8,
payload: &[u8],
) -> Result<()>
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.
Sourcepub async fn poll_keepalive(&mut self) -> Result<()>
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.
Sourcepub async fn recv_interleaved(&mut self) -> Result<Option<ClientEvent>>
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>>
impl AsyncRtspClient<TlsStream<TcpStream>>
Sourcepub async fn connect_tls<A: ToSocketAddrs>(
addr: A,
server_name: &str,
config: ClientConfig,
) -> Result<Self>
pub async fn connect_tls<A: ToSocketAddrs>( addr: A, server_name: &str, config: ClientConfig, ) -> Result<Self>
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).
Sourcepub async fn connect_tls_with<A: ToSocketAddrs>(
addr: A,
server_name: &str,
config: ClientConfig,
session: ClientSession,
) -> Result<Self>
pub async fn connect_tls_with<A: ToSocketAddrs>( addr: A, server_name: &str, config: ClientConfig, session: ClientSession, ) -> Result<Self>
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.
Sourcepub async fn connect_tls_with_timeouts<A: ToSocketAddrs>(
addr: A,
server_name: &str,
config: ClientConfig,
session: ClientSession,
timeouts: RtspTimeouts,
) -> Result<Self>
pub async fn connect_tls_with_timeouts<A: ToSocketAddrs>( addr: A, server_name: &str, config: ClientConfig, session: ClientSession, timeouts: RtspTimeouts, ) -> Result<Self>
Like connect_tls_with, with explicit
RtspTimeouts: connect bounds the TCP connect, handshake the TLS
handshake.