diff --git a/cmd/rtsp/rtsp.go b/cmd/rtsp/rtsp.go index 7db8cd76..4ae86b77 100644 --- a/cmd/rtsp/rtsp.go +++ b/cmd/rtsp/rtsp.go @@ -162,6 +162,8 @@ func tcpHandler(conn *rtsp.Conn) { log.Debug().Str("stream", name).Msg("[rtsp] new consumer") + conn.SessionName = app.UserAgent + initMedias(conn) if err := stream.AddConsumer(conn); err != nil { diff --git a/pkg/rtsp/conn.go b/pkg/rtsp/conn.go index 7611cde5..d21c63dd 100644 --- a/pkg/rtsp/conn.go +++ b/pkg/rtsp/conn.go @@ -78,6 +78,7 @@ type Conn struct { // public Backchannel bool + SessionName string Medias []*streamer.Media Session string @@ -618,7 +619,7 @@ func (c *Conn) Accept() error { medias = append(medias, media) } - res.Body, err = streamer.MarshalSDP(medias) + res.Body, err = streamer.MarshalSDP(c.SessionName, medias) if err != nil { return err } diff --git a/pkg/streamer/media.go b/pkg/streamer/media.go index 4b2b783f..9d638649 100644 --- a/pkg/streamer/media.go +++ b/pkg/streamer/media.go @@ -183,8 +183,22 @@ func UnmarshalSDP(rawSDP []byte) ([]*Media, error) { return medias, nil } -func MarshalSDP(medias []*Media) ([]byte, error) { - sd := &sdp.SessionDescription{} +func MarshalSDP(name string, medias []*Media) ([]byte, error) { + sd := &sdp.SessionDescription{ + Origin: sdp.Origin{ + Username: "-", SessionID: 1, SessionVersion: 1, + NetworkType: "IN", AddressType: "IP4", UnicastAddress: "0.0.0.0", + }, + SessionName: sdp.SessionName(name), + ConnectionInformation: &sdp.ConnectionInformation{ + NetworkType: "IN", AddressType: "IP4", Address: &sdp.Address{ + Address: "0.0.0.0", + }, + }, + TimeDescriptions: []sdp.TimeDescription{ + {Timing: sdp.Timing{}}, + }, + } payloadType := uint8(96) diff --git a/pkg/streamer/media_test.go b/pkg/streamer/media_test.go new file mode 100644 index 00000000..e6b01be7 --- /dev/null +++ b/pkg/streamer/media_test.go @@ -0,0 +1,23 @@ +package streamer + +import ( + "github.com/pion/sdp/v3" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestSDP(t *testing.T) { + medias := []*Media{{ + Kind: KindAudio, Direction: DirectionSendonly, + Codecs: []*Codec{ + {Name: CodecPCMU, ClockRate: 8000}, + }, + }} + + data, err := MarshalSDP("go2rtc/1.0.0", medias) + assert.Empty(t, err) + + sd := &sdp.SessionDescription{} + err = sd.Unmarshal(data) + assert.Empty(t, err) +}