Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion media/whep_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func (s *WHEPServer) CreateWHEP(ctx context.Context, w http.ResponseWriter, r *h
return
}

// Read any query params
queryParams := r.URL.Query()
desync := queryParams.Get("desync") != ""

// Read the SDP offer
offerBytes, err := io.ReadAll(r.Body)
if err != nil {
Expand Down Expand Up @@ -108,11 +112,18 @@ func (s *WHEPServer) CreateWHEP(ctx context.Context, w http.ResponseWriter, r *h
hasVideo = true

case *mpegts.CodecOpus:
// if tracks share the same mid the browser will sync them for playback
// this may lead to buffering / latency so use a separate mid if requested
audioMid := "livepeer"
if desync {
clog.Info(ctx, "Using a separate mid for audio")
audioMid = audioMid + "-audio"
}
webrtcTrack, err := NewLocalTrack(
// NB: Don't signal sample rate or channel count here. Leave empty to use defaults.
// Opus RTP RFC 7587 requires opus/48000/2 regardless of the actual content
webrtc.RTPCodecCapability{MimeType: webrtc.MimeTypeOpus},
"audio", "livepeer", // NB: can be another MediaID to desync a/v for latency
"audio", audioMid, // NB: can be another MediaID to desync a/v for latency
)
if err != nil {
clog.InfofErr(ctx, "Error creating track for opus", err)
Expand Down
Loading