Skip to content

RTSP Ingestion

RUSEON Core connects to IP cameras and RTSP streaming sources using bluenviron/gortsplib/v4 and pion/rtp.


Connection Lifecycle

  1. Dial Throttling: Connection handshakes pass through a concurrency semaphore (dialSemaphore, max 10 concurrent initial dials) to prevent Thundering Herd issues and network interface saturation when booting large camera fleets.
  2. Describe & Setup: Issues RTSP DESCRIBE and sets up tracks via SETUP (using TCP interleaved transport by default, with configurable UDP mode).
  3. Play & Read: Issues PLAY and registers packet callbacks:
    • OnPacketRTP: Parses RTP payload into NAL units.
    • OnPacketLost: Increments error counters and logs warnings without dropping the session.
    • OnDecodeError: Handles corrupted frames gracefully.

Video Codec Processing

RUSEON Core demuxes video streams without CPU-intensive decoding:

  • H.264 (AVC): Extracts SPS (type 7), PPS (type 8), and IDR slices (type 5).
  • H.265 (HEVC): Extracts VPS (type 32), SPS (type 33), PPS (type 34), and IRAP/IDR slices (types 16–21).
  • Bitrate Calculation: Calculated over a rolling 1-second window and reported in camera telemetry.

Reconnection with Exponential Backoff & Jitter

When an RTSP connection drops:

  1. Emits a camera_offline event over the EventBus and updates state to offline.
  2. Initiates reconnection using an exponential backoff algorithm with jitter: $$\text{delay} = \min(60\text{s}, 1\text{s} \times 2^{\text{reconnectCount}}) \pm 20% \text{ jitter}$$
  3. Prevents synchronised reconnect spikes against target camera servers.
  4. Upon successful re-establishment, emits camera_online and transitions camera state back to online.

Released under the MIT License.