Skip to content

Adopt Jitter HandlerCloser #397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/icholy/digest v1.1.0
github.com/jfreymuth/oggvorbis v1.0.5
github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731
github.com/livekit/media-sdk v0.0.0-20250518151703-b07af88637c5
github.com/livekit/media-sdk v0.0.0-20250620175140-c86da91c22a2
github.com/livekit/mediatransportutil v0.0.0-20250519131108-fb90f5acfded
github.com/livekit/protocol v1.39.0
github.com/livekit/psrpc v0.6.1-0.20250511053145-465289d72c3c
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ github.com/lithammer/shortuuid/v4 v4.2.0 h1:LMFOzVB3996a7b8aBuEXxqOBflbfPQAiVzkI
github.com/lithammer/shortuuid/v4 v4.2.0/go.mod h1:D5noHZ2oFw/YaKCfGy0YxyE7M0wMbezmMjPdhyEFe6Y=
github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731 h1:9x+U2HGLrSw5ATTo469PQPkqzdoU7be46ryiCDO3boc=
github.com/livekit/mageutil v0.0.0-20250511045019-0f1ff63f7731/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ=
github.com/livekit/media-sdk v0.0.0-20250518151703-b07af88637c5 h1:aFCwt/rticj5Lw13woaOJ51yMivbiQ7XkfGX8T+bP90=
github.com/livekit/media-sdk v0.0.0-20250518151703-b07af88637c5/go.mod h1:7ssWiG+U4xnbvLih9WiZbhQP6zIKMjgXdUtIE1bm/E8=
github.com/livekit/media-sdk v0.0.0-20250620175140-c86da91c22a2 h1:uHDhc7gk5WcxdwaZD0JKjNM/G37CklZ2QOuJVzaGVo4=
github.com/livekit/media-sdk v0.0.0-20250620175140-c86da91c22a2/go.mod h1:7ssWiG+U4xnbvLih9WiZbhQP6zIKMjgXdUtIE1bm/E8=
github.com/livekit/mediatransportutil v0.0.0-20250519131108-fb90f5acfded h1:ylZPdnlX1RW9Z15SD4mp87vT2D2shsk0hpLJwSPcq3g=
github.com/livekit/mediatransportutil v0.0.0-20250519131108-fb90f5acfded/go.mod h1:mSNtYzSf6iY9xM3UX42VEI+STHvMgHmrYzEHPcdhB8A=
github.com/livekit/protocol v1.39.0 h1:xmpkEr0+29xiAu+Z/m7CmsGuLKHf5ba5+5rkGdMdZEY=
Expand Down
9 changes: 7 additions & 2 deletions pkg/sip/media_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ type MediaPort struct {
mu sync.Mutex
conf *MediaConf
sess rtp.Session
hnd atomic.Pointer[rtp.Handler]
hnd atomic.Pointer[rtp.HandlerCloser]
dtmfOutRTP *rtp.Stream
dtmfOutAudio msdk.PCM16Writer

Expand Down Expand Up @@ -291,6 +291,11 @@ func (p *MediaPort) Close() {
_ = p.sess.Close()
}
_ = p.port.Close()

hnd := p.hnd.Load()
if hnd != nil {
(*hnd).Close()
}
})
}

Expand Down Expand Up @@ -547,7 +552,7 @@ func (p *MediaPort) setupInput() {
),
)
}
var hnd rtp.Handler = newRTPHandlerCount(mux, &p.stats.MuxPackets, &p.stats.MuxBytes)
var hnd rtp.HandlerCloser = rtp.NewNopCloser(newRTPHandlerCount(mux, &p.stats.MuxPackets, &p.stats.MuxBytes))
if p.jitterEnabled {
hnd = rtp.HandleJitter(hnd)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/sip/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func (r *Room) Connect(conf *config.Config, rconf RoomConfig) error {
}
defer odec.Close()

var h rtp.Handler = rtp.NewMediaStreamIn[opus.Sample](odec)
var h rtp.HandlerCloser = rtp.NewNopCloser(rtp.NewMediaStreamIn[opus.Sample](odec))
if conf.EnableJitterBuffer {
h = rtp.HandleJitter(h)
}
Expand Down
2 changes: 1 addition & 1 deletion test/lktest/livekit.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func (lk *LiveKit) ConnectParticipant(t TB, room, identity string, cb *RoomParti
}
defer odec.Close()

h := rtp.NewMediaStreamIn[opus.Sample](odec)
h := rtp.NewNopCloser(rtp.NewMediaStreamIn[opus.Sample](odec))
_ = rtp.HandleLoop(track, h)
}
cb.OnParticipantConnected = func(p *lksdk.RemoteParticipant) {
Expand Down
Loading