Skip to content

Commit

Permalink
webrtc: return an error when proxying stream with no tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Feb 18, 2024
1 parent 6e72120 commit 21c0aa0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
31 changes: 31 additions & 0 deletions internal/core/path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,37 @@ func TestPathRunOnRead(t *testing.T) {
Log: test.NilLogger{},
}

writerDone := make(chan struct{})
defer func() { <-writerDone }()

writerTerminate := make(chan struct{})
defer close(writerTerminate)

go func() {
defer close(writerDone)
i := uint16(0)
for {
select {
case <-time.After(100 * time.Millisecond):
case <-writerTerminate:
return
}
err := source.WritePacketRTP(testMediaH264, &rtp.Packet{
Header: rtp.Header{
Version: 2,
Marker: true,
PayloadType: 96,
SequenceNumber: 123 + i,
Timestamp: 45343,
SSRC: 563423,
},
Payload: []byte{5},
})
require.NoError(t, err)
i++
}
}()

_, err = c.Read(context.Background())
require.NoError(t, err)
defer checkClose(t, c.Close)
Expand Down
6 changes: 3 additions & 3 deletions internal/protocols/webrtc/peer_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ outer:
// GatherIncomingTracks gathers incoming tracks.
func (co *PeerConnection) GatherIncomingTracks(
ctx context.Context,
count int,
maxCount int,
) ([]*IncomingTrack, error) {
var tracks []*IncomingTrack

Expand All @@ -237,7 +237,7 @@ func (co *PeerConnection) GatherIncomingTracks(
for {
select {
case <-t.C:
if count == 0 {
if maxCount == 0 && len(tracks) != 0 {
return tracks, nil
}
return nil, fmt.Errorf("deadline exceeded while waiting tracks")
Expand All @@ -249,7 +249,7 @@ func (co *PeerConnection) GatherIncomingTracks(
}
tracks = append(tracks, track)

if len(tracks) == count || len(tracks) >= 2 {
if len(tracks) == maxCount || len(tracks) >= 2 {
return tracks, nil
}

Expand Down

0 comments on commit 21c0aa0

Please # to comment.