diff --git a/examples/rtp-to-webrtc/README.md b/examples/rtp-to-webrtc/README.md index 9298e34d7b..e5acb03607 100644 --- a/examples/rtp-to-webrtc/README.md +++ b/examples/rtp-to-webrtc/README.md @@ -51,3 +51,9 @@ Copy the text that `rtp-to-webrtc` just emitted and copy into second text area A video should start playing in your browser above the input boxes. Congrats, you have used Pion WebRTC! Now start building something cool + +## Dealing with broken/lossy inputs +Pion WebRTC also provides a [SampleBuilder](https://pkg.go.dev/github.com/pion/webrtc/v3@v3.0.4/pkg/media/samplebuilder). This consumes RTP packets and returns samples. +It can be used to re-order and delay for lossy streams. You can see its usage in this example in [e4da70](https://github.com/pion/webrtc/commit/e4da709754639871266ca5e2cc2f945178caeb12). + +Currently it isn't working with H264, but is useful for VP8 and Opus. See [#1652](https://github.com/pion/webrtc/issues/1652) for the status of fixing for H264. diff --git a/examples/rtp-to-webrtc/main.go b/examples/rtp-to-webrtc/main.go index 71c3be4ce6..1c9fd9213a 100644 --- a/examples/rtp-to-webrtc/main.go +++ b/examples/rtp-to-webrtc/main.go @@ -6,11 +6,8 @@ import ( "fmt" "net" - "github.com/pion/rtp" - "github.com/pion/rtp/codecs" "github.com/pion/webrtc/v3" "github.com/pion/webrtc/v3/examples/internal/signal" - "github.com/pion/webrtc/v3/pkg/media/samplebuilder" ) func main() { @@ -37,7 +34,7 @@ func main() { }() // Create a video track - videoTrack, err := webrtc.NewTrackLocalStaticSample(webrtc.RTPCodecCapability{MimeType: "video/vp8"}, "video", "pion") + videoTrack, err := webrtc.NewTrackLocalStaticRTP(webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypeVP8}, "video", "pion") if err != nil { panic(err) } @@ -95,32 +92,16 @@ func main() { // Output the answer in base64 so we can paste it in browser fmt.Println(signal.Encode(*peerConnection.LocalDescription())) - videoBuilder := samplebuilder.New(10, &codecs.VP8Packet{}, 90000) - // Read RTP packets forever and send them to the WebRTC Client + inboundRTPPacket := make([]byte, 1600) // UDP MTU for { - inboundRTPPacket := make([]byte, 1500) // UDP MTU - packet := &rtp.Packet{} - n, _, err := listener.ReadFrom(inboundRTPPacket) if err != nil { panic(fmt.Sprintf("error during read: %s", err)) } - if err = packet.Unmarshal(inboundRTPPacket[:n]); err != nil { + if _, err = videoTrack.Write(inboundRTPPacket[:n]); err != nil { panic(err) } - - videoBuilder.Push(packet) - for { - sample := videoBuilder.Pop() - if sample == nil { - break - } - - if writeErr := videoTrack.WriteSample(*sample); writeErr != nil { - panic(writeErr) - } - } } }