install go2rtc on bob

This commit is contained in:
2026-04-04 19:36:14 +02:00
parent f0b56e63d1
commit ccf88187b8
537 changed files with 69213 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
package debug
import (
"bytes"
"math/rand"
"net"
)
type badConn struct {
net.Conn
delay int
buf []byte
}
func NewBadConn(conn net.Conn) net.Conn {
return &badConn{Conn: conn}
}
const (
missChance = 0.05
delayChance = 0.1
)
func (c *badConn) Read(b []byte) (n int, err error) {
if rand.Float32() < missChance {
if _, err = c.Conn.Read(b); err != nil {
return
}
//log.Printf("bad conn: miss")
}
if c.delay > 0 {
if c.delay--; c.delay == 0 {
n = copy(b, c.buf)
return
}
} else if rand.Float32() < delayChance {
if n, err = c.Conn.Read(b); err != nil {
return
}
c.delay = 1 + rand.Intn(5)
c.buf = bytes.Clone(b[:n])
//log.Printf("bad conn: delay %d", c.delay)
}
return c.Conn.Read(b)
}
@@ -0,0 +1,58 @@
package debug
import (
"fmt"
"time"
"github.com/pion/rtp"
)
func Logger(include func(packet *rtp.Packet) bool) func(packet *rtp.Packet) {
var lastTime = time.Now()
var lastTS uint32
var secCnt int
var secSize int
var secTS uint32
var secTime time.Time
return func(packet *rtp.Packet) {
if include != nil && !include(packet) {
return
}
now := time.Now()
fmt.Printf(
"%s: size=%6d ts=%10d type=%2d ssrc=%d seq=%5d mark=%t dts=%4d dtime=%3dms\n",
now.Format("15:04:05.000"),
len(packet.Payload), packet.Timestamp, packet.PayloadType, packet.SSRC, packet.SequenceNumber, packet.Marker,
packet.Timestamp-lastTS, now.Sub(lastTime).Milliseconds(),
)
lastTS = packet.Timestamp
lastTime = now
if secTS == 0 {
secTS = lastTS
secTime = now
return
}
if dt := now.Sub(secTime); dt > time.Second {
fmt.Printf(
"%s: size=%6d cnt=%d dts=%d dtime=%3dms\n",
now.Format("15:04:05.000"),
secSize, secCnt, lastTS-secTS, dt.Milliseconds(),
)
secCnt = 0
secSize = 0
secTS = lastTS
secTime = now
}
secCnt++
secSize += len(packet.Payload)
}
}