Skip to content

Commit

Permalink
test: add pkttimestamp and timestamp to samples to improve WebRTC str…
Browse files Browse the repository at this point in the history
…eaming
  • Loading branch information
cedricve committed Aug 4, 2024
1 parent b2b8485 commit b067758
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions machinery/src/webrtc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package webrtc
import (
"encoding/base64"
"encoding/json"
"fmt"
"io"
"strconv"
"sync"
Expand Down Expand Up @@ -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..
Expand All @@ -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())
}
Expand Down

0 comments on commit b067758

Please sign in to comment.