mirror of
https://github.com/bluenviron/mediamtx
synced 2024-12-17 20:24:38 +00:00
fix: clean up SDP before serving it to receivers
This commit is contained in:
parent
a9799c7cf1
commit
215a44fd33
1
Makefile
1
Makefile
@ -38,7 +38,6 @@ run:
|
||||
echo "$$DOCKERFILE_RUN" | docker build -q . -f - -t temp
|
||||
docker run --rm -it \
|
||||
--network=host \
|
||||
--name temp \
|
||||
temp \
|
||||
/out $(ARGS)
|
||||
|
||||
|
74
client.go
74
client.go
@ -6,6 +6,7 @@ import (
|
||||
"log"
|
||||
"net"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -13,6 +14,61 @@ import (
|
||||
"gortc.io/sdp"
|
||||
)
|
||||
|
||||
func sdpParse(in []byte) (*sdp.Message, error) {
|
||||
s, err := sdp.DecodeSession(in, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m := &sdp.Message{}
|
||||
d := sdp.NewDecoder(s)
|
||||
err = d.Decode(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(m.Medias) == 0 {
|
||||
return nil, fmt.Errorf("no tracks defined in SDP")
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// remove everything from SDP except infos about the tracks
|
||||
func sdpFilter(msgIn *sdp.Message, byteIn []byte) (*sdp.Message, []byte) {
|
||||
msgOut := &sdp.Message{}
|
||||
|
||||
for i, m := range msgIn.Medias {
|
||||
var attributes []sdp.Attribute
|
||||
for _, attr := range m.Attributes {
|
||||
if attr.Key == "rtpmap" || attr.Key == "fmtp" {
|
||||
attributes = append(attributes, attr)
|
||||
}
|
||||
}
|
||||
// control attribute is needed by gstreamer
|
||||
attributes = append(attributes, sdp.Attribute{
|
||||
Key: "control",
|
||||
Value: "streamid=" + strconv.FormatInt(int64(i), 10),
|
||||
})
|
||||
|
||||
msgOut.Medias = append(msgOut.Medias, sdp.Media{
|
||||
Bandwidths: m.Bandwidths,
|
||||
Description: sdp.MediaDescription{
|
||||
Type: m.Description.Type,
|
||||
Protocol: m.Description.Protocol,
|
||||
Formats: m.Description.Formats,
|
||||
},
|
||||
Attributes: attributes,
|
||||
})
|
||||
}
|
||||
|
||||
sdps := sdp.Session{}
|
||||
sdps = msgOut.Append(sdps)
|
||||
byteOut := sdps.AppendTo(nil)
|
||||
|
||||
return msgOut, byteOut
|
||||
}
|
||||
|
||||
func interleavedChannelToTrack(channel int) (int, trackFlow) {
|
||||
if (channel % 2) == 0 {
|
||||
return (channel / 2), _TRACK_FLOW_RTP
|
||||
@ -252,26 +308,14 @@ func (c *client) handleRequest(req *gortsplib.Request) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
sdpParsed, err := func() (*sdp.Message, error) {
|
||||
s, err := sdp.DecodeSession(req.Content, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
m := &sdp.Message{}
|
||||
d := sdp.NewDecoder(s)
|
||||
err = d.Decode(m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}()
|
||||
sdpParsed, err := sdpParse(req.Content)
|
||||
if err != nil {
|
||||
c.writeResError(req, fmt.Errorf("invalid SDP: %s", err))
|
||||
return false
|
||||
}
|
||||
|
||||
sdpParsed, req.Content = sdpFilter(sdpParsed, req.Content)
|
||||
|
||||
if c.p.publishKey != "" {
|
||||
q, err := url.ParseQuery(ur.RawQuery)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user