New Track API

The Pion WebRTC API has been dramatically redesigned. The design docs
are located here [0]

You can also read the release notes [1] on how to migrate your
application.

[0] https://github.com/pion/webrtc-v3-design
[1] https://github.com/pion/webrtc/wiki/Release-WebRTC@v3.0.0
This commit is contained in:
Sean DuBois
2020-11-11 12:03:08 -08:00
parent 159ba5aca3
commit 7edfb701e0
46 changed files with 1750 additions and 2059 deletions

View File

@@ -23,16 +23,6 @@ func main() { // nolint:gocognit
signal.Decode(<-sdpChan, &offer)
fmt.Println("")
// Since we are answering use PayloadTypes declared by offerer
mediaEngine := webrtc.MediaEngine{}
err := mediaEngine.PopulateFromSDP(offer)
if err != nil {
panic(err)
}
// Create the API object with the MediaEngine
api := webrtc.NewAPI(webrtc.WithMediaEngine(mediaEngine))
peerConnectionConfig := webrtc.Configuration{
ICEServers: []webrtc.ICEServer{
{
@@ -42,7 +32,7 @@ func main() { // nolint:gocognit
}
// Create a new RTCPeerConnection
peerConnection, err := api.NewPeerConnection(peerConnectionConfig)
peerConnection, err := webrtc.NewPeerConnection(peerConnectionConfig)
if err != nil {
panic(err)
}
@@ -52,23 +42,23 @@ func main() { // nolint:gocognit
panic(err)
}
localTrackChan := make(chan *webrtc.Track)
localTrackChan := make(chan *webrtc.TrackLocalStaticRTP)
// Set a handler for when a new remote track starts, this just distributes all our packets
// to connected peers
peerConnection.OnTrack(func(remoteTrack *webrtc.Track, receiver *webrtc.RTPReceiver) {
peerConnection.OnTrack(func(remoteTrack *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
// Send a PLI on an interval so that the publisher is pushing a keyframe every rtcpPLIInterval
// This can be less wasteful by processing incoming RTCP events, then we would emit a NACK/PLI when a viewer requests it
go func() {
ticker := time.NewTicker(rtcpPLIInterval)
for range ticker.C {
if rtcpSendErr := peerConnection.WriteRTCP([]rtcp.Packet{&rtcp.PictureLossIndication{MediaSSRC: remoteTrack.SSRC()}}); rtcpSendErr != nil {
if rtcpSendErr := peerConnection.WriteRTCP([]rtcp.Packet{&rtcp.PictureLossIndication{MediaSSRC: uint32(remoteTrack.SSRC())}}); rtcpSendErr != nil {
fmt.Println(rtcpSendErr)
}
}
}()
// Create a local track, all our SFU clients will be fed via this track
localTrack, newTrackErr := peerConnection.NewTrack(remoteTrack.PayloadType(), remoteTrack.SSRC(), "video", "pion")
localTrack, newTrackErr := webrtc.NewTrackLocalStaticRTP(remoteTrack.Codec().RTPCodecCapability, "video", "pion")
if newTrackErr != nil {
panic(newTrackErr)
}
@@ -126,7 +116,7 @@ func main() { // nolint:gocognit
signal.Decode(<-sdpChan, &recvOnlyOffer)
// Create a new PeerConnection
peerConnection, err := api.NewPeerConnection(peerConnectionConfig)
peerConnection, err := webrtc.NewPeerConnection(peerConnectionConfig)
if err != nil {
panic(err)
}