mirror of
https://github.com/livekit/livekit.git
synced 2026-08-28 05:04:10 +00:00
use context to detect when channel is properly closed
This commit is contained in:
@@ -99,7 +99,6 @@ func (w *TrackWriter) writeOgg() {
|
||||
return
|
||||
}
|
||||
|
||||
// Convert seconds to Milliseconds, Sleep doesn't accept floats
|
||||
time.Sleep(sampleDuration)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ type SimpleForwarder struct {
|
||||
onClose func(forwarder Forwarder)
|
||||
}
|
||||
|
||||
func NewSimpleForwarder(rtcpCh chan []rtcp.Packet, track *sfu.DownTrack, pb PacketBuffer) *SimpleForwarder {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
func NewSimpleForwarder(ctx context.Context, rtcpCh chan []rtcp.Packet, track *sfu.DownTrack, pb PacketBuffer) *SimpleForwarder {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
f := &SimpleForwarder{
|
||||
ctx: ctx,
|
||||
cancel: cancel,
|
||||
|
||||
+4
-1
@@ -1,6 +1,7 @@
|
||||
package rtc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -22,6 +23,7 @@ var (
|
||||
|
||||
// Track represents a remoteTrack that needs to be forwarded
|
||||
type Track struct {
|
||||
ctx context.Context
|
||||
id string
|
||||
participantId string
|
||||
// source remoteTrack
|
||||
@@ -37,6 +39,7 @@ type Track struct {
|
||||
|
||||
func NewTrack(pId string, rtcpCh chan []rtcp.Packet, track *webrtc.TrackRemote, receiver *Receiver) *Track {
|
||||
t := &Track{
|
||||
ctx: context.Background(),
|
||||
id: utils.NewGuid(utils.TrackPrefix),
|
||||
participantId: pId,
|
||||
remoteTrack: track,
|
||||
@@ -96,7 +99,7 @@ func (t *Track) AddSubscriber(participant *Participant) error {
|
||||
//})
|
||||
participant.addDownTrack(t.StreamID(), outTrack)
|
||||
|
||||
forwarder := NewSimpleForwarder(t.rtcpCh, outTrack, t.receiver)
|
||||
forwarder := NewSimpleForwarder(t.ctx, t.rtcpCh, outTrack, t.receiver)
|
||||
forwarder.OnClose(func(f Forwarder) {
|
||||
t.lock.Lock()
|
||||
delete(t.forwarders, participant.ID())
|
||||
|
||||
Reference in New Issue
Block a user