Skip to content

Commit b4fc0fe

Browse files
takidogSean-Der
authored andcommitted
Fix audio-only crash on sendVideoPacket
1 parent d28ba61 commit b4fc0fe

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

internal/webrtc/whep.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ func WHEP(offer, streamKey string) (string, string, error) {
161161
}
162162

163163
func (w *whepSession) sendVideoPacket(rtpPkt *rtp.Packet, layer string, timeDiff int64, sequenceDiff int, codec videoTrackCodec, isKeyframe bool) {
164+
// Skip if video track is not available (e.g., audio-only)
165+
if w.videoTrack == nil || w.videoTrack.writeStream == nil {
166+
return
167+
}
168+
164169
if w.currentLayer.Load() == "" {
165170
w.currentLayer.Store(layer)
166171
} else if layer != w.currentLayer.Load() {

internal/webrtc/whep_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package webrtc
2+
3+
import "testing"
4+
5+
func TestAudioOnly(t *testing.T) {
6+
session := &whepSession{
7+
videoTrack: nil,
8+
timestamp: 50000,
9+
}
10+
11+
session.sendVideoPacket(nil, "", 0, 0, 0, true)
12+
}

0 commit comments

Comments
 (0)