From 3c9da1ccb66b88b71325b1d14f5042d75372ba8c Mon Sep 17 00:00:00 2001 From: David Colburn Date: Fri, 25 Oct 2024 13:13:38 -0400 Subject: [PATCH] outbound processor --- go.mod | 2 +- go.sum | 4 ++-- pkg/sip/client.go | 1 + pkg/sip/media_port.go | 8 ++++---- pkg/sip/media_port_test.go | 8 ++++++-- pkg/sip/outbound.go | 10 +++++++++- 6 files changed, 23 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 46bb311..602608b 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/jfreymuth/oggvorbis v1.0.5 github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 github.com/livekit/mediatransportutil v0.0.0-20240730083616-559fa5ece598 - github.com/livekit/protocol v1.26.1-0.20241022031344-538889e5de0a + github.com/livekit/protocol v1.27.1-0.20241025171050-32abc4d3e929 github.com/livekit/psrpc v0.6.1-0.20240924010758-9f0a4268a3b9 github.com/livekit/server-sdk-go/v2 v2.2.2-0.20241015094126-b8538ae5d67b github.com/mjibson/go-dsp v0.0.0-20180508042940-11479a337f12 diff --git a/go.sum b/go.sum index 2b14ce4..37b0f86 100644 --- a/go.sum +++ b/go.sum @@ -118,8 +118,8 @@ github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 h1:jm09419p0lqTkD github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ= github.com/livekit/mediatransportutil v0.0.0-20240730083616-559fa5ece598 h1:yLlkHk2feSLHstD9n4VKg7YEBR4rLODTI4WE8gNBEnQ= github.com/livekit/mediatransportutil v0.0.0-20240730083616-559fa5ece598/go.mod h1:jwKUCmObuiEDH0iiuJHaGMXwRs3RjrB4G6qqgkr/5oE= -github.com/livekit/protocol v1.26.1-0.20241022031344-538889e5de0a h1:31YXXJLEwCflp7KEe9rRAwmONyCwHFujTl4MdxegTxw= -github.com/livekit/protocol v1.26.1-0.20241022031344-538889e5de0a/go.mod h1:nxRzmQBKSYK64gqr7ABWwt78hvrgiO2wYuCojRYb7Gs= +github.com/livekit/protocol v1.27.1-0.20241025171050-32abc4d3e929 h1:qunGP1opJF4NfcJW5tLyV/cLE/npfnh7P3nyyLECb68= +github.com/livekit/protocol v1.27.1-0.20241025171050-32abc4d3e929/go.mod h1:nxRzmQBKSYK64gqr7ABWwt78hvrgiO2wYuCojRYb7Gs= github.com/livekit/psrpc v0.6.1-0.20240924010758-9f0a4268a3b9 h1:33oBjGpVD9tYkDXQU42tnHl8eCX9G6PVUToBVuCUyOs= github.com/livekit/psrpc v0.6.1-0.20240924010758-9f0a4268a3b9/go.mod h1:CQUBSPfYYAaevg1TNCc6/aYsa8DJH4jSRFdCeSZk5u0= github.com/livekit/server-sdk-go/v2 v2.2.2-0.20241015094126-b8538ae5d67b h1:R1GpKwVbSYsG08k5sIkNCukvnrkOE18R8IO1YeujR8o= diff --git a/pkg/sip/client.go b/pkg/sip/client.go index c223e12..5bf707e 100644 --- a/pkg/sip/client.go +++ b/pkg/sip/client.go @@ -196,6 +196,7 @@ func (c *Client) createSIPParticipant(ctx context.Context, req *rpc.InternalCrea headersToAttrs: req.HeadersToAttributes, ringingTimeout: req.RingingTimeout.AsDuration(), maxCallDuration: req.MaxCallDuration.AsDuration(), + enabledFeatures: req.EnabledFeatures, } log.Infow("Creating SIP participant") call, err := c.newCall(ctx, c.conf, log, LocalTag(req.SipCallId), roomConf, sipConf) diff --git a/pkg/sip/media_port.go b/pkg/sip/media_port.go index 1b5c728..93a66b2 100644 --- a/pkg/sip/media_port.go +++ b/pkg/sip/media_port.go @@ -165,13 +165,13 @@ func (p *MediaPort) decodeSDP(data []byte) (*sdp.SessionDescription, *MediaConf, return desc, c, nil } -// SetAnswer decodes and applies SDP answer for offer from NewOffer. It calls SetConfig with a decoded configuration. -func (p *MediaPort) SetAnswer(answer []byte) error { +// SetAnswer decodes and applies SDP answer for offer from NewOffer. SetConfig must be called with the decoded configuration. +func (p *MediaPort) SetAnswer(answer []byte) (*MediaConf, error) { _, c, err := p.decodeSDP(answer) if err != nil { - return err + return nil, err } - return p.SetConfig(c) + return c, nil } // SetOffer decodes the offer from another party and returns encoded answer. To accept the offer, call SetConfig. diff --git a/pkg/sip/media_port_test.go b/pkg/sip/media_port_test.go index 4407953..220fa5d 100644 --- a/pkg/sip/media_port_test.go +++ b/pkg/sip/media_port_test.go @@ -27,9 +27,10 @@ import ( "testing" "time" + "github.com/stretchr/testify/require" + "github.com/livekit/mediatransportutil/pkg/rtcconfig" "github.com/livekit/protocol/logger" - "github.com/stretchr/testify/require" "github.com/livekit/sip/pkg/media" "github.com/livekit/sip/pkg/media/rtp" @@ -183,7 +184,10 @@ func TestMediaPort(t *testing.T) { t.Logf("SDP answer:\n%s", string(answer)) - err = m1.SetAnswer(answer) + mc, err := m1.SetAnswer(answer) + require.NoError(t, err) + + err = m1.SetConfig(mc) require.NoError(t, err) err = m2.SetConfig(conf) diff --git a/pkg/sip/outbound.go b/pkg/sip/outbound.go index b65bd92..f86267c 100644 --- a/pkg/sip/outbound.go +++ b/pkg/sip/outbound.go @@ -30,6 +30,7 @@ import ( "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/logger" + "github.com/livekit/protocol/rpc" "github.com/livekit/protocol/tracer" "github.com/livekit/psrpc" lksdk "github.com/livekit/server-sdk-go/v2" @@ -55,6 +56,7 @@ type sipOutboundConfig struct { headersToAttrs map[string]string ringingTimeout time.Duration maxCallDuration time.Duration + enabledFeatures []rpc.SIPFeature } type outboundCall struct { @@ -399,9 +401,15 @@ func (c *outboundCall) sipSignal(ctx context.Context) error { c.log = LoggerWithHeaders(c.log, c.cc) - if err := c.media.SetAnswer(sdpResp); err != nil { + mc, err := c.media.SetAnswer(sdpResp) + if err != nil { + return err + } + mc.Processor = c.c.handler.GetMediaProcessor(c.sipConf.enabledFeatures) + if err = c.media.SetConfig(mc); err != nil { return err } + c.c.cmu.Lock() c.c.byRemote[c.cc.Tag()] = c c.c.cmu.Unlock()