From b06775891537746477688d88046c9f6bc5e10900 Mon Sep 17 00:00:00 2001 From: Cedric Verstraeten Date: Sun, 4 Aug 2024 10:15:01 +0200 Subject: [PATCH] test: add pkttimestamp and timestamp to samples to improve WebRTC streaming --- machinery/src/webrtc/main.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/machinery/src/webrtc/main.go b/machinery/src/webrtc/main.go index fe92c22..bd78b59 100644 --- a/machinery/src/webrtc/main.go +++ b/machinery/src/webrtc/main.go @@ -3,6 +3,7 @@ package webrtc import ( "encoding/base64" "encoding/json" + "fmt" "io" "strconv" "sync" @@ -409,7 +410,15 @@ func WriteToTrack(livestreamCursor *packets.QueueCursor, configuration *models.C start = true } if start { - sample := pionMedia.Sample{Data: pkt.Data, Duration: bufferDuration} + sample := pionMedia.Sample{ + Data: pkt.Data, + Duration: bufferDuration, + //Timestamp: time.Unix(0, int64(pkt.Time)), + Timestamp: time.Now(), + PacketTimestamp: uint32(pkt.Time), + } + fmt.Println(sample) + if config.Capture.ForwardWebRTC == "true" { // We will send the video to a remote peer // TODO.. @@ -436,7 +445,12 @@ func WriteToTrack(livestreamCursor *packets.QueueCursor, configuration *models.C previousTimeAudio = pkt.Time // We will send the audio - sample := pionMedia.Sample{Data: pkt.Data, Duration: bufferDuration} + sample := pionMedia.Sample{ + Data: pkt.Data, + Duration: bufferDuration, + Timestamp: time.Unix(0, int64(pkt.Time)), + PacketTimestamp: uint32(pkt.Time), + } if err := audioTrack.WriteSample(sample); err != nil && err != io.ErrClosedPipe { log.Log.Error("webrtc.main.WriteToTrack(): something went wrong while writing sample: " + err.Error()) }