Skip to content

datachannel-to-udp forwarding#336

Open
yingchuan8985 wants to merge 10 commits intobinbat:mainfrom
yingchuan8985:feat/udp-core
Open

datachannel-to-udp forwarding#336
yingchuan8985 wants to merge 10 commits intobinbat:mainfrom
yingchuan8985:feat/udp-core

Conversation

@yingchuan8985
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown
Member

@a-wing a-wing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There have a very import problem:

Live777 support mutil-stream:

  • each stream include a datachannel
  • each datachannel should use independent udp port

Comment thread liveion/src/forward/internal.rs Outdated
Comment thread liveion/src/forward/ptz_udp.rs Outdated
Comment thread liveion/src/forward/ptz_udp.rs Outdated
Comment thread liveion/src/forward/ptz_udp.rs Outdated
Copy link
Copy Markdown
Member

@a-wing a-wing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Rename add ptz_udp => channel or datachannel
  2. Merge datachannel some config and add example conf/live777.toml
  3. Signed CLA: https://github.com/binbat/live777/blob/main/.github/CLA.md#list-of-contributors

Comment thread liveion/src/forward/channel.rs
Comment thread liveion/src/forward/ptz_udp.rs Outdated
@a-wing
Copy link
Copy Markdown
Member

a-wing commented Apr 8, 2026

BTW: Must resolved this conflicts

Comment thread conf/live777.toml Outdated
Comment thread conf/live777.toml Outdated
Comment thread livecam/src/whep_handler.rs Outdated
Comment thread liveion/src/forward/channel.rs Outdated
Comment thread liveion/src/forward/channel.rs Outdated
Comment thread liveion/src/forward/channel.rs Outdated
Comment thread liveion/src/forward/channel.rs Outdated
Comment thread liveion/src/config.rs
Comment thread .gitattributes Outdated
Comment thread .gitignore Outdated
Copy link
Copy Markdown
Member

@a-wing a-wing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Need check each commit can pass CI format and lint
  2. Add some unit test

Comment thread conf/live777.toml Outdated
Comment on lines +4 to +5
# listen_addr:listen_port - liveion listens here for replies from downstream
# target_host:target_port - liveion sends DataChannel messages to this address
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

listen_addr:listen_port => listen_host:listen_port

Usually listen_addr = listen_host + listen_port

Comment thread liveion/src/forward/channel.rs Outdated
Comment on lines +47 to +57
// Format addresses, wrapping IPv6 in brackets
let target = if target_host.contains(':') {
format!("[{}]:{}", target_host, target_port)
} else {
format!("{}:{}", target_host, target_port)
};
let bind_addr = if listen_addr.contains(':') {
format!("[{}]:{}", listen_addr, listen_port)
} else {
format!("{}:{}", listen_addr, listen_port)
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread liveion/src/forward/internal.rs Outdated
Comment thread liveion/src/forward/internal.rs Outdated
Comment thread liveion/src/forward/internal.rs Outdated
Comment thread liveion/src/config.rs
Comment thread liveion/src/forward/internal.rs Outdated
Comment on lines +468 to +479
// DataChannel ↔ UDP bidirectional forwarding.
// Messages from the WHIP publisher arrive on the subscribe channel.
let dc_rx = self.data_channel_forward.subscribe.subscribe();
let dc_tx = self.data_channel_forward.publish.clone();
let stream_cfg = self.ptz_udp.streams.get(&self.stream).cloned();
super::channel::spawn_channel(
self.stream.clone(),
dc_rx,
dc_tx,
stream_cfg,
)
.await;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If has stream no set about data_channel config. We shouldn't start any data_channel function

Comment thread liveion/src/forward/channel.rs Outdated
Comment on lines +59 to +68
let socket = match UdpSocket::bind(&bind_addr).await {
Ok(s) => {
info!("channel [{}]: listen={} target={}", stream, bind_addr, target);
Arc::new(s)
}
Err(e) => {
warn!("channel [{}]: bind socket failed: {}", stream, e);
return;
}
};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There function should add a return Error

When UdpSocket::bind has error, should stop and return Error

Comment thread liveion/src/forward/channel.rs Outdated
Comment on lines +73 to +111
tokio::spawn(async move {
loop {
match dc_rx.recv().await {
Ok(data) => {
if let Err(e) = socket_dc.send_to(&data, &target).await {
warn!("channel [{}]: send to {} failed: {}", stream_dc, target, e);
} else {
debug!("channel [{}]: DC->UDP {} bytes -> {}", stream_dc, data.len(), target);
}
}
Err(broadcast::error::RecvError::Lagged(n)) => {
warn!("channel [{}]: lagged, dropped {} messages", stream_dc, n);
}
Err(broadcast::error::RecvError::Closed) => {
info!("channel [{}]: channel closed", stream_dc);
break;
}
}
}
});

// --- UDP -> DataChannel (passthrough, no wrapping) ---
tokio::spawn(async move {
let mut buf = vec![0u8; 1024];
loop {
match socket.recv_from(&mut buf).await {
Ok((n, addr)) => {
let data = buf[..n].to_vec();
debug!("channel [{}]: UDP->DC {} bytes from {}", stream, n, addr);
if let Err(e) = dc_tx.send(data) {
warn!("channel [{}]: forward to DC failed: {}", stream, e);
}
}
Err(e) => {
warn!("channel [{}]: recv_from failed: {}", stream, e);
}
}
}
});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There has two tokio::spawn. I think merge only one tokio::spawn is more good

Comment thread liveion/src/forward/channel.rs Outdated
Comment thread liveion/src/forward/channel.rs Outdated
Comment thread liveion/src/config.rs Outdated
Comment thread liveion/src/config.rs Outdated
Comment thread liveion/src/forward/channel.rs
Comment thread liveion/src/forward/channel.rs Outdated
Comment thread liveion/src/forward/internal.rs Outdated
Comment thread liveion/Cargo.toml

glob = "0.3"
url = { version = "2.5", optional = true }
url = { workspace = true, optional = true }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to remove url use std parse url, there no change here.

If you want to use url, change here is ok

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 17, 2026

Codecov Report

❌ Patch coverage is 57.89474% with 56 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
liveion/src/forward/channel.rs 0.00% 49 Missing ⚠️
liveion/src/forward/internal.rs 54.54% 5 Missing ⚠️
liveion/src/config.rs 96.96% 2 Missing ⚠️
Files with missing lines Coverage Δ
liveion/src/forward/mod.rs 51.07% <100.00%> (+3.06%) ⬆️
liveion/src/stream/config.rs 100.00% <100.00%> (ø)
liveion/src/stream/manager.rs 39.01% <100.00%> (+11.88%) ⬆️
liveion/src/config.rs 77.19% <96.96%> (+28.21%) ⬆️
liveion/src/forward/internal.rs 68.87% <54.54%> (+12.65%) ⬆️
liveion/src/forward/channel.rs 0.00% <0.00%> (ø)

... and 57 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants