MixinNetwork / kraken

🐙 High performance WebRTC SFU implemented with pure Go.
Apache License 2.0
334 stars 49 forks source link

Question: video only #18

Closed ldenoue closed 3 years ago

ldenoue commented 3 years ago

I am trying to reuse this awesome audio only SFU to make it video only. I replaced the registered codec to accept VP8 and accept 96 as PayloadType in peer.go

However, it seems that for video I have to send a PLI every 3 seconds inside the same peer.pc.OnTrack method.

Question: why don't we need to send these PLI for audio only?

Here's the code I've added:

peer.pc.OnTrack(func(rt *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
        logger.Printf("HandlePeer(%s) OnTrack(%d, %d)\n", peer.id(), rt.PayloadType(), rt.SSRC())
        if peer.track != nil || (111 != rt.PayloadType() && 109 != rt.PayloadType() && 96 != rt.PayloadType()) {
            return
        }
        peer.connected <- true

        peer.Lock()
        lt, err := webrtc.NewTrackLocalStaticRTP(rt.Codec().RTPCodecCapability, peer.cid, peer.uid)
        if err != nil {
            panic(err)
        }
        peer.track = lt
        peer.Unlock()

                 // NEW FUNCTION HERE TO REQUEST A PLI FROM THE REMOTE VIDEO TRACK
        go func() {
            ticker := time.NewTicker(rtcpPLIInterval)
            for range ticker.C {
                if rtcpSendErr := peer.pc.WriteRTCP([]rtcp.Packet{&rtcp.PictureLossIndication{MediaSSRC: uint32(rt.SSRC())}}); rtcpSendErr != nil {
                    fmt.Println(rtcpSendErr)
                }
            }
        }()

The issue is how do I stop this function when the remote track ends or the connection closes?

Currently, my code displays the rtcpSendErr but I'd like to stop this go func.

ldenoue commented 3 years ago

Found out I just need to return from the for loop...