Move to new Track API

See v2.0.0 Release Notes[0] for all changes

Resolves #405

[0] https://github.com/pions/webrtc/wiki/v2.0.0-Release-Notes#media-api
This commit is contained in:
Sean DuBois
2019-02-21 14:53:35 -08:00
parent f5d11df18d
commit 6aeb3425b0
18 changed files with 715 additions and 537 deletions

View File

@@ -44,27 +44,32 @@ func main() {
// Set a handler for when a new remote track starts, this handler saves buffers to disk as
// an ivf file, since we could have multiple video tracks we provide a counter.
// In your application this is where you would handle/process video
peerConnection.OnTrack(func(track *webrtc.Track) {
peerConnection.OnTrack(func(track *webrtc.Track, receiver *webrtc.RTPReceiver) {
// Send a PLI on an interval so that the publisher is pushing a keyframe every rtcpPLIInterval
// This is a temporary fix until we implement incoming RTCP events, then we would push a PLI only when a viewer requests it
go func() {
ticker := time.NewTicker(time.Second * 3)
for range ticker.C {
err := peerConnection.SendRTCP(&rtcp.PictureLossIndication{MediaSSRC: track.SSRC})
err := peerConnection.SendRTCP(&rtcp.PictureLossIndication{MediaSSRC: track.SSRC()})
if err != nil {
fmt.Println(err)
}
}
}()
if track.Codec.Name == webrtc.VP8 {
if track.Codec().Name == webrtc.VP8 {
fmt.Println("Got VP8 track, saving to disk as output.ivf")
i, err := ivfwriter.New("output.ivf")
if err != nil {
panic(err)
}
for {
err = i.AddPacket(<-track.Packets)
packet, err := track.ReadRTP()
if err != nil {
panic(err)
}
err = i.AddPacket(packet)
if err != nil {
panic(err)
}