Skip to content

Commit 5d890ba

Browse files
committed
feat(sdp): pass direction to offer media and default empty to sendrecv
1 parent 8add608 commit 5d890ba

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

sdp/offer.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func appendCryptoProfiles(attrs []sdp.Attribute, profiles []srtp.Profile) []sdp.
119119
}
120120

121121
// OfferMediaWith creates a new SDP media description with a given codec set, public IP address and listening port.
122-
func OfferMediaWith(s *media.CodecSet, rtpListenerPort int, encrypted Encryption) (MediaDesc, *sdp.MediaDescription, error) {
122+
func OfferMediaWith(s *media.CodecSet, rtpListenerPort int, encrypted Encryption, dir sdp.Direction) (MediaDesc, *sdp.MediaDescription, error) {
123123
// Static compiler check for frame duration hardcoded below.
124124
var _ = [1]struct{}{}[20*time.Millisecond-rtp.DefFrameDur]
125125

@@ -153,9 +153,12 @@ func OfferMediaWith(s *media.CodecSet, rtpListenerPort int, encrypted Encryption
153153
attrs = appendCryptoProfiles(attrs, cryptoProfiles)
154154
}
155155

156+
if dir == 0 {
157+
dir = sdp.DirectionSendRecv
158+
}
156159
attrs = append(attrs, []sdp.Attribute{
157160
{Key: "ptime", Value: "20"},
158-
{Key: "sendrecv"},
161+
{Key: dir.String()},
159162
}...)
160163

161164
proto := "AVP"
@@ -182,7 +185,7 @@ func OfferMediaWith(s *media.CodecSet, rtpListenerPort int, encrypted Encryption
182185
//
183186
// Deprecated: use OfferMediaWith
184187
func OfferMedia(rtpListenerPort int, encrypted Encryption) (MediaDesc, *sdp.MediaDescription, error) {
185-
return OfferMediaWith(media.GlobalCodecs(), rtpListenerPort, encrypted)
188+
return OfferMediaWith(media.GlobalCodecs(), rtpListenerPort, encrypted, sdp.DirectionSendRecv)
186189
}
187190

188191
// AnswerMedia creates a new SDP media description for an answer.
@@ -208,6 +211,9 @@ func AnswerMedia(rtpListenerPort int, audio *AudioConfig, crypt *srtp.Profile, d
208211
proto = "SAVP"
209212
attrs = appendCryptoProfiles(attrs, []srtp.Profile{*crypt})
210213
}
214+
if dir == 0 {
215+
dir = sdp.DirectionSendRecv
216+
}
211217
attrs = append(attrs, []sdp.Attribute{
212218
{Key: "ptime", Value: "20"},
213219
{Key: dir.String()},
@@ -252,7 +258,7 @@ type Answer Description
252258
func NewOfferWith(s *media.CodecSet, publicIp netip.Addr, rtpListenerPort int, encrypted Encryption) (*Offer, error) {
253259
sessId := rand.Uint64() // TODO: do we need to track these?
254260

255-
m, mediaDesc, err := OfferMediaWith(s, rtpListenerPort, encrypted)
261+
m, mediaDesc, err := OfferMediaWith(s, rtpListenerPort, encrypted, sdp.DirectionSendRecv)
256262
if err != nil {
257263
return nil, err
258264
}

sdp/offer_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestSDPMediaOffer(t *testing.T) {
4848
g := media.GlobalCodecs()
4949

5050
const port = 12345
51-
_, offer, err := OfferMediaWith(g, port, EncryptionNone)
51+
_, offer, err := OfferMediaWith(g, port, EncryptionNone, 0)
5252
require.NoError(t, err)
5353
require.Equal(t, &sdp.MediaDescription{
5454
MediaName: sdp.MediaName{
@@ -68,7 +68,7 @@ func TestSDPMediaOffer(t *testing.T) {
6868
},
6969
}, offer)
7070

71-
_, offer, err = OfferMediaWith(g, port, EncryptionRequire)
71+
_, offer, err = OfferMediaWith(g, port, EncryptionRequire, 0)
7272
require.NoError(t, err)
7373
i := slices.IndexFunc(offer.Attributes, func(a sdp.Attribute) bool {
7474
return a.Key == "crypto"
@@ -99,7 +99,7 @@ func TestSDPMediaOffer(t *testing.T) {
9999
noG722 := g.NewSet()
100100
noG722.SetEnabled(g722.SDPNameAndRate, false)
101101

102-
_, offer, err = OfferMediaWith(noG722, port, EncryptionNone)
102+
_, offer, err = OfferMediaWith(noG722, port, EncryptionNone, 0)
103103
require.NoError(t, err)
104104
require.Equal(t, &sdp.MediaDescription{
105105
MediaName: sdp.MediaName{
@@ -326,7 +326,7 @@ func TestSDPMediaAnswer(t *testing.T) {
326326
require.Equal(t, c.exp, got)
327327
})
328328
}
329-
_, offer, err := OfferMediaWith(g, port, EncryptionNone)
329+
_, offer, err := OfferMediaWith(g, port, EncryptionNone, 0)
330330
require.NoError(t, err)
331331
require.Equal(t, &sdp.MediaDescription{
332332
MediaName: sdp.MediaName{

0 commit comments

Comments
 (0)