test: add pkttimestamp and timestamp to samples to improve WebRTC streaming

This commit is contained in:
Cedric Verstraeten
2024-08-04 10:15:01 +02:00
parent b2b8485b28
commit b067758915

View File

@@ -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())
}