From daf27bd0598233b57428b7809587ec3c09510413 Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Fri, 29 Jan 2021 23:04:44 -0800 Subject: [PATCH] Remove SampleBuilder from rtp-to-webrtc SampleBuilder isn't able to properly handle H264. We have multiple issues and until resolved we shouldn't suggest it. Relates to #1652 --- examples/rtp-to-webrtc/README.md | 6 ++++++ examples/rtp-to-webrtc/main.go | 25 +++---------------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/examples/rtp-to-webrtc/README.md b/examples/rtp-to-webrtc/README.md index 9298e34d7bd..e5acb036071 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 71c3be4ce6a..1c9fd9213aa 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) - } - } } }