Skip to content

Commit

Permalink
enable webrtc sctp zero checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricfung committed Oct 15, 2024
1 parent 0649d38 commit 8576a8d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
6 changes: 3 additions & 3 deletions engine/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,18 @@ func (peer *Peer) callbackOnTrack() error {
}

func (peer *Peer) copyTrack(src *webrtc.TrackRemote, dst *webrtc.TrackLocalStaticRTP) error {
go func() error {
go func() {
defer close(peer.queue)

for {
pkt, _, err := src.ReadRTP()
if err == io.EOF {
logger.Verbosef("copyTrack(%s) EOF\n", peer.id())
return nil
return
}
if err != nil {
logger.Verbosef("copyTrack(%s) error %s\n", peer.id(), err.Error())
return err
return
}
peer.queue <- pkt
}
Expand Down
18 changes: 14 additions & 4 deletions engine/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ func (r *Router) list(rid string) ([]map[string]any, error) {
func (r *Router) create(rid, uid, callback string, offer webrtc.SessionDescription) (*Peer, error) {
se := webrtc.SettingEngine{}
se.SetLite(true)
se.EnableSCTPZeroChecksum(true)
se.SetInterfaceFilter(func(in string) bool { return in == r.engine.Interface })
se.SetNAT1To1IPs([]string{r.engine.IP}, webrtc.ICECandidateTypeHost)
se.SetICETimeouts(10*time.Second, 30*time.Second, 2*time.Second)
se.SetEphemeralUDPPortRange(r.engine.PortMin, r.engine.PortMax)
se.SetDTLSInsecureSkipHelloVerify(true)
se.SetReceiveMTU(8192)
err := se.SetEphemeralUDPPortRange(r.engine.PortMin, r.engine.PortMax)
if err != nil {
return nil, err
}

me := &webrtc.MediaEngine{}
opusChrome := webrtc.RTPCodecParameters{
Expand All @@ -66,11 +70,17 @@ func (r *Router) create(rid, uid, callback string, offer webrtc.SessionDescripti
RTPCodecCapability: webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypeOpus, ClockRate: 48000, Channels: 2, SDPFmtpLine: "minptime=10;useinbandfec=1", RTCPFeedback: nil},
PayloadType: 109,
}
me.RegisterCodec(opusChrome, webrtc.RTPCodecTypeAudio)
me.RegisterCodec(opusFirefox, webrtc.RTPCodecTypeAudio)
err = me.RegisterCodec(opusChrome, webrtc.RTPCodecTypeAudio)
if err != nil {
return nil, err
}
err = me.RegisterCodec(opusFirefox, webrtc.RTPCodecTypeAudio)
if err != nil {
return nil, err
}

ir := &interceptor.Registry{}
err := webrtc.RegisterDefaultInterceptors(me, ir)
err = webrtc.RegisterDefaultInterceptors(me, ir)
if err != nil {
panic(err)
}
Expand Down

0 comments on commit 8576a8d

Please sign in to comment.