Skip to main content

Module stream_source

Module stream_source 

Source
Expand description

Per-(camera, stream_kind) live media source.

A StreamSource owns a single BcCamera::start_video() stream and fans the decoded Frames out via a tokio::sync::broadcast channel so that many RTSP sessions can subscribe to the same camera without opening multiple Baichuan video streams.

Responsibilities:

  1. Spawn a tokio task that pulls BcMedia packets from bairelay_neolink_core.
  2. Split Annex-B NAL streams, detect the video codec, and translate each packet into bairelay_rtsp::provider::Frame.
  3. Update the shared LastFrameBuffer on I-frames / P-frames.
  4. Maintain the SdpParams needed to render the RTSP DESCRIBE body for this source (codec, SPS/PPS/VPS).
  5. Exit cleanly when the owning StreamSource is dropped (or StreamSource::stop is called) — including sending a matching stop_video command to the camera.

§Audio + multi-track status

Audio flows end-to-end: BcMedia::Aac passthrough via RFC 3640 AAC-hbr, BcMedia::Adpcm transcoded to G.711 µ-law (8 kHz, static PT 0). SdpParams.audio is populated on the first observed audio packet; AudioPresence on the owning CameraHandle advances Unknown → Present { codec } at the same time. Dispatch to the right RTSP transport (video vs. audio track) happens inside crates/rtsp/src/server/session_task.rs.

Structs§

FakeFrameInjector
Test-only handle for simulating a live Frame::Video arrival in unit tests. See StreamSource::start_inert_for_test_with_gap_and_injector.
PacedFrame
Audio frame queued for paced emission to the broadcast channel.
StreamSource
A live (camera, stream_kind) media source. See module docs.
StreamTranslatorState
Mutable state owned by the reader task’s translator loop.

Enums§

GapState
Upstream live-frame presence for a StreamSource, maintained by reader_task.

Functions§

apply_bcmedia_packet
Apply a decoded BcMedia packet to the outbound channels, maintaining all translator state via StreamTranslatorState.
await_audio_or_deadline
Wait for SdpParams.audio specifically to become Some (video is assumed populated). Returns Ok(()) on audio arrival, a static reason string on timeout. The caller re-reads the SDP snapshot after.
await_sdp_both
Wait until both SdpParams.video and SdpParams.audio are populated (Some), or timeout elapses. Returns the snapshot on success; a static reason string on timeout. Used by CameraProvider::subscribe when the camera’s AudioPresence is Present { codec }.