Skip to content

Commit

Permalink
fix SDP error with AXIS 221 (bluenviron/mediamtx#2708)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Apr 16, 2024
1 parent 605b784 commit 22db179
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 14 deletions.
22 changes: 11 additions & 11 deletions pkg/sdp/sdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,13 @@ func (s *SessionDescription) unmarshalOrigin(value string) error {
var tmp string
tmp, value = value[i+1:], value[:i]

var err error

switch {
case strings.ContainsAny(tmp, "."):
i := strings.Index(tmp, ".")
s.Origin.SessionVersion, err = strconv.ParseUint(tmp[:i], 16, 64)
default:
s.Origin.SessionVersion, err = strconv.ParseUint(tmp, 10, 64)
if i := strings.Index(tmp, "."); i >= 0 {
tmp = tmp[:i]
}
tmp = strings.TrimPrefix(tmp, "-")

var err error
s.Origin.SessionVersion, err = strconv.ParseUint(tmp, 10, 64)
if err != nil {
return fmt.Errorf("%w `%v`", errSDPInvalidNumericValue, tmp)
}
Expand All @@ -143,10 +141,12 @@ func (s *SessionDescription) unmarshalOrigin(value string) error {
s.Origin.SessionID, err = strconv.ParseUint(tmp[2:], 16, 64)
case strings.ContainsAny(tmp, "abcdefABCDEF"):
s.Origin.SessionID, err = strconv.ParseUint(tmp, 16, 64)
case strings.ContainsAny(tmp, "."):
i := strings.Index(tmp, ".")
s.Origin.SessionID, err = strconv.ParseUint(tmp[:i], 16, 64)
default:
if i := strings.Index(tmp, "."); i >= 0 {
tmp = tmp[:i]
}
tmp = strings.TrimPrefix(tmp, "-")

s.Origin.SessionID, err = strconv.ParseUint(tmp, 10, 64)
}
if err != nil {
Expand Down
128 changes: 125 additions & 3 deletions pkg/sdp/sdp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2561,7 +2561,7 @@ var cases = []struct {
"a=fmtp:96 packetization-mode=1; profile-level-id=33;" +
" sprop-parameter-sets=Z00AM4qKUDwBE/L/4AAgAC2AgA==,aO48gA==\r\n"),
[]byte("v=0\r\n" +
"o=- 97041581188 97041581188 IN IP4 46.242.10.231:12626\r\n" +
"o=- 1698210484 1698210484 IN IP4 46.242.10.231:12626\r\n" +
"s=Playout\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"a=rtpmap:96 H264/90000\r\n" +
Expand All @@ -2570,8 +2570,8 @@ var cases = []struct {
SessionDescription{
Origin: psdp.Origin{
Username: "-",
SessionID: 97041581188,
SessionVersion: 97041581188,
SessionID: 1698210484,
SessionVersion: 1698210484,
NetworkType: "IN",
AddressType: "IP4",
UnicastAddress: "46.242.10.231:12626",
Expand Down Expand Up @@ -2919,6 +2919,128 @@ var cases = []struct {
},
},
},
{
"issue mediamtx/2708",
[]byte("v=0\r\n" +
"o=- -1962418793961427 -1962418793961418 IN IP4 192.168.221.104\r\n" +
"s=Media Presentation\r\n" +
"e=NONE\r\n" +
"c=IN IP4 0.0.0.0\r\n" +
"b=AS:8000\r\n" +
"t=0 0\r\n" +
"a=control:*\r\n" +
"a=range:npt=now-\r\n" +
"a=mpeg4-iod: \"data:application/mpeg4-iod;base64,AoDUAE8BAf/1AQOAbwABQFBkYXRhOmFwcGxpY2F0aW9uL21wZWc" +
"0LW9kLWF1O2Jhc2U2NCxBUjBCR3dVZkF4Y0F5U1FBWlFRTklCRUVrK0FBZWhJQUFIb1NBQVlCQkE9PQQNAQUABAAAAAAAAAAAAAY" +
"JAQAAAAAAAAAAAzoAAkA2ZGF0YTphcHBsaWNhdGlvbi9tcGVnNC1iaWZzLWF1O2Jhc2U2NCx3QkFTWVFTSVVFVUZQd0E9BBICDQAAA" +
"gAAAAAAAAAABQMAAEAGCQEAAAAAAAAAAA==\"\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"b=AS:8000\r\n" +
"a=framerate:30.0\r\n" +
"a=control:trackID=1\r\n" +
"a=rtpmap:96 MP4V-ES/90000\r\n" +
"a=fmtp:96 profile-level-id=245; config=000001B0F5000001B509000001000000012008D48D88032514043C14440F\r\n" +
"a=mpeg4-esid:201\r\n"),
[]byte("v=0\r\n" +
"o=- 1962418793961427 1962418793961418 IN IP4 192.168.221.104\r\n" +
"s=Media Presentation\r\n" +
"e=NONE\r\n" +
"c=IN IP4 0.0.0.0\r\n" +
"b=AS:8000\r\n" +
"t=0 0\r\n" +
"a=control:*\r\n" +
"a=range:npt=now-\r\n" +
"a=mpeg4-iod: \"data:application/mpeg4-iod;base64,AoDUAE8BAf/1AQOAbwABQFBkYXRhOmFwcGxpY2F0aW9uL21wZWc" +
"0LW9kLWF1O2Jhc2U2NCxBUjBCR3dVZkF4Y0F5U1FBWlFRTklCRUVrK0FBZWhJQUFIb1NBQVlCQkE9PQQNAQUABAAAAAAAAAAAAAY" +
"JAQAAAAAAAAAAAzoAAkA2ZGF0YTphcHBsaWNhdGlvbi9tcGVnNC1iaWZzLWF1O2Jhc2U2NCx3QkFTWVFTSVVFVUZQd0E9BBICDQAAA" +
"gAAAAAAAAAABQMAAEAGCQEAAAAAAAAAAA==\"\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"b=AS:8000\r\n" +
"a=framerate:30.0\r\n" +
"a=control:trackID=1\r\n" +
"a=rtpmap:96 MP4V-ES/90000\r\n" +
"a=fmtp:96 profile-level-id=245; config=000001B0F5000001B509000001000000012008D48D88032514043C14440F\r\n" +
"a=mpeg4-esid:201\r\n"),
SessionDescription{
Origin: psdp.Origin{
Username: "-",
SessionID: 1962418793961427,
SessionVersion: 1962418793961418,
NetworkType: "IN",
AddressType: "IP4",
UnicastAddress: "192.168.221.104",
},
SessionName: "Media Presentation",
EmailAddress: func() *psdp.EmailAddress {
v := psdp.EmailAddress("NONE")
return &v
}(),
ConnectionInformation: &psdp.ConnectionInformation{
NetworkType: "IN",
AddressType: "IP4",
Address: &psdp.Address{
Address: "0.0.0.0",
},
},
Bandwidth: []psdp.Bandwidth{{
Type: "AS",
Bandwidth: 8000,
}},
TimeDescriptions: []psdp.TimeDescription{{}},
Attributes: []psdp.Attribute{
{
Key: "control",
Value: "*",
},
{
Key: "range",
Value: "npt=now-",
},
{
Key: "mpeg4-iod",
Value: " \"data:application/mpeg4-iod;base64,AoDUAE8BAf/1AQOAbwABQFBkYXRhOmFwcGxpY2" +
"F0aW9uL21wZWc0LW9kLWF1O2Jhc2U2NCxBUjBCR3dVZkF4Y0F5U1FBWlFRTklCRUVrK0FBZWhJQUFIb1NBQV" +
"lCQkE9PQQNAQUABAAAAAAAAAAAAAYJAQAAAAAAAAAAAzoAAkA2ZGF0YTphcHBsaWNhdGlvbi9tcGVnNC1iaWZ" +
"zLWF1O2Jhc2U2NCx3QkFTWVFTSVVFVUZQd0E9BBICDQAAAgAAAAAAAAAABQMAAEAGCQEAAAAAAAAAAA==\"",
},
},
MediaDescriptions: []*psdp.MediaDescription{
{
MediaName: psdp.MediaName{
Media: "video",
Protos: []string{"RTP", "AVP"},
Formats: []string{"96"},
},
Bandwidth: []psdp.Bandwidth{{
Type: "AS",
Bandwidth: 8000,
}},
Attributes: []psdp.Attribute{
{
Key: "framerate",
Value: "30.0",
},
{
Key: "control",
Value: "trackID=1",
},
{
Key: "rtpmap",
Value: "96 MP4V-ES/90000",
},
{
Key: "fmtp",
Value: "96 profile-level-id=245; config=000001B0F5000001B509000001000000012008D48D88032514043C14440F",
},
{
Key: "mpeg4-esid",
Value: "201",
},
},
},
},
},
},
}

func TestUnmarshal(t *testing.T) {
Expand Down

0 comments on commit 22db179

Please sign in to comment.