bring kcp over vp8 (#160)

* bring kcp over vp8 for wbstream

* add multitrack kcp

* make kcp configurable param

* fix lingered kcp tunnel after switch into raw vp8 tunnel

* add reliable setting into ios and desktop joiners
This commit is contained in:
kulikov0 authored and GitHub committed 2026-07-24 13:38:08 +02:00
1 parent 99e5630f19
commit a0229885ca
50 files changed
+1503 -96

No files matched your search

+38 -7
View File
@@ -8,12 +8,13 @@ import (
type MultiTrackTunnel struct {
tunnels []*VP8DataTunnel
mu sync.Mutex
onData func([]byte)
onClose func()
isClosed bool
fps int
batch int
mu sync.Mutex
onData func([]byte)
onClose func()
onPeerRestart func()
isClosed bool
fps int
batch int
}
func NewMultiTrackTunnel(tunnels []*VP8DataTunnel) *MultiTrackTunnel {
@@ -40,6 +41,14 @@ func (m *MultiTrackTunnel) wireSubTunnel(tun *VP8DataTunnel, isCamera bool) {
// the cam writer or notify the parent that the whole tunnel died.
return
}
tun.SetOnPeerRestart(func() {
m.mu.Lock()
handler := m.onPeerRestart
m.mu.Unlock()
if handler != nil {
handler()
}
})
tun.SetOnClose(func() {
m.mu.Lock()
if m.isClosed {
@@ -111,6 +120,23 @@ func (m *MultiTrackTunnel) SendData(data []byte) {
tunnels[idx].SendData(data)
}
func (m *MultiTrackTunnel) DeliverData(data []byte) {
m.mu.Lock()
handler := m.onData
m.mu.Unlock()
if handler != nil {
handler(data)
}
}
func (m *MultiTrackTunnel) SubTunnels() []*VP8DataTunnel {
m.mu.Lock()
defer m.mu.Unlock()
subs := make([]*VP8DataTunnel, len(m.tunnels))
copy(subs, m.tunnels)
return subs
}
func (m *MultiTrackTunnel) SetOnData(fn func([]byte)) {
m.mu.Lock()
defer m.mu.Unlock()
@@ -123,6 +149,12 @@ func (m *MultiTrackTunnel) SetOnClose(fn func()) {
m.onClose = fn
}
func (m *MultiTrackTunnel) SetOnPeerRestart(fn func()) {
m.mu.Lock()
defer m.mu.Unlock()
m.onPeerRestart = fn
}
func (m *MultiTrackTunnel) Reconfigure(fps, batch int) {
m.mu.Lock()
m.fps = fps
@@ -170,4 +202,3 @@ func (m *MultiTrackTunnel) HandleFrame(frame []byte) {
first.HandleFrame(frame)
}
}