tsc-stream: stream sessions and a frame-source seam
Streams drives one connection's TS6 streams without doing connection IO: it takes stream notifications and app decisions, owns the str0m peers and queues requests (to send as commands) and events. - StreamerSession: setupstream, join requests (auto-accept or ask the app), one peer per viewer with the offer in respondjoinstreamrequest, answers and trickled candidates, withdrawal, reconnect (new offer as reconnectOffer), kick, stop (also before the stream went live), merged keyframe requests, frame fan-out to connected viewers - ViewerSession: joinstreamrequest, answer the offer from the response or an offer/reconnectOffer signal, candidates, denial, stop, removal, leave, reconnect after a lost connection (up to three times) - StreamDirectory: streams in the channel from notifications and client_is_streaming - FrameSource + SyntheticSource: decodable 1x1 VP8 keyframes (padded) and Opus silence in real time, for tests and tsctl - Peer: poll_event for driving many peers from one task; trickled local candidates carry the bundle mid Transcript unit tests and an end-to-end test through a fake relay server. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01NJvYyRmTjKcb9i8eyYXK5G
This commit is contained in:
1 parent
0b1aa5664e
commit
8d8a8c5eab
5 files changed
+1971
-4
No files matched your search
@@ -9,6 +9,7 @@ use std::collections::HashMap;
|
||||
use std::hash::{BuildHasher, RandomState};
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use std::sync::Arc;
|
||||
use std::task::{Context, Poll};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use str0m::change::{SdpAnswer, SdpOffer, SdpPendingOffer};
|
||||
@@ -100,8 +101,9 @@ pub enum PeerEvent {
|
||||
/// ICE and DTLS are up; media can flow.
|
||||
Connected,
|
||||
/// A candidate found after the SDP was sent (server reflexive), as an SDP
|
||||
/// `candidate:` line for [`crate::Signal::IceCandidate`].
|
||||
LocalCandidate(String),
|
||||
/// `candidate:` line for [`crate::Signal::IceCandidate`], with the mid of
|
||||
/// the first (bundled) media line.
|
||||
LocalCandidate { candidate: String, mid: Option<String> },
|
||||
/// A received frame (depacketized).
|
||||
Media(MediaFrame),
|
||||
/// The viewer asks for a keyframe.
|
||||
@@ -225,6 +227,11 @@ impl Peer {
|
||||
pub fn try_next_event(&mut self) -> Option<PeerEvent> {
|
||||
self.events.try_recv().ok()
|
||||
}
|
||||
|
||||
/// Poll for the next event, for driving many peers from one task.
|
||||
pub fn poll_event(&mut self, cx: &mut Context<'_>) -> Poll<Option<PeerEvent>> {
|
||||
self.events.poll_recv(cx)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Peer {
|
||||
@@ -420,9 +427,10 @@ impl Task {
|
||||
}
|
||||
match Candidate::server_reflexive(mapped, pending.base, "udp") {
|
||||
Ok(c) => {
|
||||
let line = c.to_sdp_string();
|
||||
let candidate = c.to_sdp_string();
|
||||
let mid = self.mids.first().map(|(mid, _)| mid.to_string());
|
||||
if self.rtc.add_local_candidate(c).is_some() {
|
||||
let _ = self.events.send(PeerEvent::LocalCandidate(line));
|
||||
let _ = self.events.send(PeerEvent::LocalCandidate { candidate, mid });
|
||||
}
|
||||
}
|
||||
Err(e) => debug!("bad reflexive candidate {mapped}: {e}"),
|
||||
|
||||
Reference in new issue
Block a user