ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
esphome::rtsp_server::RTSPSession Class Reference

A single RTSP client: one TCP connection carrying both the RTSP control channel and, once playing, RTP/JPEG media interleaved on the same socket (RFC 2326 §10.12). More...

#include <rtsp_session.h>

Public Member Functions

bool is_active () const
 
bool is_playing () const
 
void open (std::unique_ptr< socket::Socket > socket, uint32_t now)
 
void loop (uint32_t now, uint16_t port)
 
void on_new_frame (const std::shared_ptr< camera::CameraImage > &image, const JpegInfo &jpeg, uint32_t now)
 Ignored unless playing with no output pending; packets of the frame being sent point into that frame.
 

Protected Types

enum class  State : uint8_t { INIT , READY , PLAYING }
 

Protected Member Functions

void service_ (uint32_t now, uint16_t port)
 
void close_ ()
 
void read_requests_ (uint32_t now, uint16_t port)
 
bool process_input_ (uint16_t port)
 Consumes buffered input up to and including the next request; true once a request was handled.
 
void consume_input_ (size_t len)
 
void handle_request_ (StringRef request, uint16_t port)
 
void handle_setup_ (StringRef transport_header)
 
void handle_play_ ()
 
void queue_response_ (uint16_t code, const char *reason, const char *extra_headers_fmt=nullptr,...) __attribute__((format(printf
 Queues "RTSP/1.0 <code> <reason>", CSeq, Session once set up, the extra headers and the blank line.
 
void void stop_playing_ ()
 
bool queue_next_packet_ ()
 
void drop_frame_ ()
 Releases the frame; the frame-backed rest of the current packet is sent as zeros to keep the framing.
 
bool flush_ (uint32_t now)
 Writes what is queued; true once all of it is written, false while backlogged or after a failure.
 

Protected Attributes

std::unique_ptr< socket::Socket > socket_
 
std::shared_ptr< camera::CameraImage > frame_
 
JpegInfo jpeg_
 
size_t frame_sent_ {0}
 
uint32_t cseq_ {0}
 
uint32_t rtp_timestamp_ {0}
 
uint32_t ssrc_ {0}
 
uint32_t last_activity_ms_ {0}
 
uint32_t last_frame_ms_ {0}
 
uint32_t frame_progress_ms_ {0}
 
uint32_t skip_len_ {0}
 
uint16_t sequence_number_ {0}
 
uint16_t request_len_ {0}
 
uint16_t filler_len_ {0}
 
std::array< struct iovec, 4 > iov_ {}
 
uint8_t iov_pos_ {0}
 
uint8_t iov_count_ {0}
 
State state_ {State::INIT}
 
bool should_close_ {false}
 
bool close_after_send_ {false}
 
bool sending_packet_ {false}
 
bool read_pending_ {false}
 
char session_id_ [9] {}
 
std::array< char, 512 > request_buf_ {}
 
std::array< char, 256 > send_buf_ {}
 

Detailed Description

A single RTSP client: one TCP connection carrying both the RTSP control channel and, once playing, RTP/JPEG media interleaved on the same socket (RFC 2326 §10.12).

No UDP transport is supported. The object is a reusable slot: open() starts a connection, and it closes itself when the connection ends.

Definition at line 47 of file rtsp_session.h.

Member Enumeration Documentation

◆ State

enum class esphome::rtsp_server::RTSPSession::State : uint8_t
strongprotected
Enumerator
INIT 
READY 
PLAYING 

Definition at line 58 of file rtsp_session.h.

Member Function Documentation

◆ close_()

void esphome::rtsp_server::RTSPSession::close_ ( )
protected

Definition at line 168 of file rtsp_session.cpp.

◆ consume_input_()

void esphome::rtsp_server::RTSPSession::consume_input_ ( size_t len)
protected

Definition at line 275 of file rtsp_session.cpp.

◆ drop_frame_()

void esphome::rtsp_server::RTSPSession::drop_frame_ ( )
protected

Releases the frame; the frame-backed rest of the current packet is sent as zeros to keep the framing.

Definition at line 489 of file rtsp_session.cpp.

◆ flush_()

bool esphome::rtsp_server::RTSPSession::flush_ ( uint32_t now)
protected

Writes what is queued; true once all of it is written, false while backlogged or after a failure.

Definition at line 501 of file rtsp_session.cpp.

◆ handle_play_()

void esphome::rtsp_server::RTSPSession::handle_play_ ( )
protected

Definition at line 389 of file rtsp_session.cpp.

◆ handle_request_()

void esphome::rtsp_server::RTSPSession::handle_request_ ( StringRef request,
uint16_t port )
protected

Definition at line 280 of file rtsp_session.cpp.

◆ handle_setup_()

void esphome::rtsp_server::RTSPSession::handle_setup_ ( StringRef transport_header)
protected

Definition at line 378 of file rtsp_session.cpp.

◆ is_active()

bool esphome::rtsp_server::RTSPSession::is_active ( ) const
inline

Definition at line 49 of file rtsp_session.h.

◆ is_playing()

bool esphome::rtsp_server::RTSPSession::is_playing ( ) const
inline

Definition at line 50 of file rtsp_session.h.

◆ loop()

void esphome::rtsp_server::RTSPSession::loop ( uint32_t now,
uint16_t port )

Definition at line 177 of file rtsp_session.cpp.

◆ on_new_frame()

void esphome::rtsp_server::RTSPSession::on_new_frame ( const std::shared_ptr< camera::CameraImage > & image,
const JpegInfo & jpeg,
uint32_t now )

Ignored unless playing with no output pending; packets of the frame being sent point into that frame.

Definition at line 404 of file rtsp_session.cpp.

◆ open()

void esphome::rtsp_server::RTSPSession::open ( std::unique_ptr< socket::Socket > socket,
uint32_t now )

Definition at line 148 of file rtsp_session.cpp.

◆ process_input_()

bool esphome::rtsp_server::RTSPSession::process_input_ ( uint16_t port)
protected

Consumes buffered input up to and including the next request; true once a request was handled.

Definition at line 247 of file rtsp_session.cpp.

◆ queue_next_packet_()

bool esphome::rtsp_server::RTSPSession::queue_next_packet_ ( )
protected

Definition at line 419 of file rtsp_session.cpp.

◆ queue_response_()

void esphome::rtsp_server::RTSPSession::queue_response_ ( uint16_t code,
const char * reason,
const char * extra_headers_fmt = nullptr,
... )
protected

Queues "RTSP/1.0 <code> <reason>", CSeq, Session once set up, the extra headers and the blank line.

Definition at line 357 of file rtsp_session.cpp.

◆ read_requests_()

void esphome::rtsp_server::RTSPSession::read_requests_ ( uint32_t now,
uint16_t port )
protected

Definition at line 210 of file rtsp_session.cpp.

◆ service_()

void esphome::rtsp_server::RTSPSession::service_ ( uint32_t now,
uint16_t port )
protected

Definition at line 190 of file rtsp_session.cpp.

◆ stop_playing_()

void esphome::rtsp_server::RTSPSession::stop_playing_ ( )
protected

Definition at line 399 of file rtsp_session.cpp.

Field Documentation

◆ close_after_send_

bool esphome::rtsp_server::RTSPSession::close_after_send_ {false}
protected

Definition at line 105 of file rtsp_session.h.

◆ cseq_

uint32_t esphome::rtsp_server::RTSPSession::cseq_ {0}
protected

Definition at line 85 of file rtsp_session.h.

◆ filler_len_

uint16_t esphome::rtsp_server::RTSPSession::filler_len_ {0}
protected

Definition at line 96 of file rtsp_session.h.

◆ frame_

std::shared_ptr<camera::CameraImage> esphome::rtsp_server::RTSPSession::frame_
protected

Definition at line 81 of file rtsp_session.h.

◆ frame_progress_ms_

uint32_t esphome::rtsp_server::RTSPSession::frame_progress_ms_ {0}
protected

Definition at line 90 of file rtsp_session.h.

◆ frame_sent_

size_t esphome::rtsp_server::RTSPSession::frame_sent_ {0}
protected

Definition at line 83 of file rtsp_session.h.

◆ iov_

std::array<struct iovec, 4> esphome::rtsp_server::RTSPSession::iov_ {}
protected

Definition at line 99 of file rtsp_session.h.

◆ iov_count_

uint8_t esphome::rtsp_server::RTSPSession::iov_count_ {0}
protected

Definition at line 101 of file rtsp_session.h.

◆ iov_pos_

uint8_t esphome::rtsp_server::RTSPSession::iov_pos_ {0}
protected

Definition at line 100 of file rtsp_session.h.

◆ jpeg_

JpegInfo esphome::rtsp_server::RTSPSession::jpeg_
protected

Definition at line 82 of file rtsp_session.h.

◆ last_activity_ms_

uint32_t esphome::rtsp_server::RTSPSession::last_activity_ms_ {0}
protected

Definition at line 88 of file rtsp_session.h.

◆ last_frame_ms_

uint32_t esphome::rtsp_server::RTSPSession::last_frame_ms_ {0}
protected

Definition at line 89 of file rtsp_session.h.

◆ read_pending_

bool esphome::rtsp_server::RTSPSession::read_pending_ {false}
protected

Definition at line 107 of file rtsp_session.h.

◆ request_buf_

std::array<char, 512> esphome::rtsp_server::RTSPSession::request_buf_ {}
protected

Definition at line 112 of file rtsp_session.h.

◆ request_len_

uint16_t esphome::rtsp_server::RTSPSession::request_len_ {0}
protected

Definition at line 94 of file rtsp_session.h.

◆ rtp_timestamp_

uint32_t esphome::rtsp_server::RTSPSession::rtp_timestamp_ {0}
protected

Definition at line 86 of file rtsp_session.h.

◆ send_buf_

std::array<char, 256> esphome::rtsp_server::RTSPSession::send_buf_ {}
protected

Definition at line 114 of file rtsp_session.h.

◆ sending_packet_

bool esphome::rtsp_server::RTSPSession::sending_packet_ {false}
protected

Definition at line 106 of file rtsp_session.h.

◆ sequence_number_

uint16_t esphome::rtsp_server::RTSPSession::sequence_number_ {0}
protected

Definition at line 93 of file rtsp_session.h.

◆ session_id_

char esphome::rtsp_server::RTSPSession::session_id_[9] {}
protected

Definition at line 108 of file rtsp_session.h.

◆ should_close_

bool esphome::rtsp_server::RTSPSession::should_close_ {false}
protected

Definition at line 104 of file rtsp_session.h.

◆ skip_len_

uint32_t esphome::rtsp_server::RTSPSession::skip_len_ {0}
protected

Definition at line 92 of file rtsp_session.h.

◆ socket_

std::unique_ptr<socket::Socket> esphome::rtsp_server::RTSPSession::socket_
protected

Definition at line 79 of file rtsp_session.h.

◆ ssrc_

uint32_t esphome::rtsp_server::RTSPSession::ssrc_ {0}
protected

Definition at line 87 of file rtsp_session.h.

◆ state_

State esphome::rtsp_server::RTSPSession::state_ {State::INIT}
protected

Definition at line 103 of file rtsp_session.h.


The documentation for this class was generated from the following files: