vomit prevention from stream finish with clients still connected
This commit is contained in:
Generated
+1
-1
@@ -2866,7 +2866,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "server"
|
||||
version = "0.1.1"
|
||||
version = "0.2.0"
|
||||
dependencies = [
|
||||
"argon2",
|
||||
"async-broadcast",
|
||||
|
||||
@@ -46,8 +46,8 @@ pub struct AppState {
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum StreamCodec {
|
||||
H264,
|
||||
H265,
|
||||
AV1, // Unsupported
|
||||
H265, // Very shity suport
|
||||
AV1,
|
||||
}
|
||||
|
||||
pub struct StreamSession {
|
||||
@@ -61,11 +61,7 @@ pub struct StreamSession {
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn Error>> {
|
||||
let env_filter = EnvFilter::builder()
|
||||
.with_default_directive(LevelFilter::DEBUG.into())
|
||||
.from_env()
|
||||
// .parse("")
|
||||
.unwrap();
|
||||
let env_filter = EnvFilter::builder().from_env().unwrap();
|
||||
|
||||
tracing_subscriber::fmt().with_env_filter(env_filter).init();
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use std::{
|
||||
use tokio::{
|
||||
net::UdpSocket,
|
||||
sync::mpsc::{Receiver, Sender},
|
||||
time::sleep,
|
||||
};
|
||||
use tracing::{debug, error, info, warn};
|
||||
|
||||
@@ -137,7 +138,8 @@ impl Webrtc {
|
||||
});
|
||||
if !video_has_pts {
|
||||
warn!(
|
||||
request_id, stream_id,
|
||||
request_id,
|
||||
stream_id,
|
||||
"no video codec negotiated — browser likely doesn't support {:?}; rejecting offer",
|
||||
stream_codec
|
||||
);
|
||||
@@ -222,7 +224,10 @@ impl Webrtc {
|
||||
video_pt = Some(params.pt());
|
||||
video_mid = Some(ma.mid);
|
||||
} else {
|
||||
warn!(stream_id, "video writer has no payload params — codec not negotiated");
|
||||
warn!(
|
||||
stream_id,
|
||||
"video writer has no payload params — codec not negotiated"
|
||||
);
|
||||
}
|
||||
} else {
|
||||
warn!(stream_id, mid = ?ma.mid, "no writer for video mid");
|
||||
@@ -301,13 +306,16 @@ impl Webrtc {
|
||||
for _ in 0..8 {
|
||||
match stream.try_recv() {
|
||||
Ok(frame) => {
|
||||
debug!(stream_id, is_keyframe = frame.is_keyframe, ts = frame.timestamp_ms, bytes = frame.data.len(), "WebRTC received video frame");
|
||||
if !saw_keyframe {
|
||||
if !frame.is_keyframe {
|
||||
continue;
|
||||
}
|
||||
saw_keyframe = true;
|
||||
info!(stream_id, ts = frame.timestamp_ms, "first keyframe — starting RTP send");
|
||||
info!(
|
||||
stream_id,
|
||||
ts = frame.timestamp_ms,
|
||||
"first keyframe — starting RTP send"
|
||||
);
|
||||
}
|
||||
let now = Instant::now();
|
||||
let rtp_time =
|
||||
@@ -316,7 +324,9 @@ impl Webrtc {
|
||||
(Some(pt), Some(writer)) => {
|
||||
match writer.write(pt, now, rtp_time, frame.data.to_vec()) {
|
||||
Ok(_) => wrote_any = true,
|
||||
Err(e) => error!(stream_id, "video RTP write error: {:?}", e),
|
||||
Err(e) => {
|
||||
error!(stream_id, "video RTP write error: {:?}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => warn!(
|
||||
@@ -330,6 +340,7 @@ impl Webrtc {
|
||||
Err(async_broadcast::TryRecvError::Empty) => break,
|
||||
Err(async_broadcast::TryRecvError::Closed) => {
|
||||
warn!("video channel closed, stream ended");
|
||||
sleep(Duration::from_secs(1)).await;
|
||||
break;
|
||||
}
|
||||
Err(async_broadcast::TryRecvError::Overflowed(_)) => {
|
||||
|
||||
Reference in New Issue
Block a user