Skip to content

Commit

Permalink
sdp: support cameras with decimal numbers in origin (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 authored Oct 27, 2023
1 parent 3c04e7a commit 35bf96c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/sdp/sdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,14 @@ func (s *SessionDescription) unmarshalOrigin(value string) error {
tmp, value = value[i+1:], value[:i]

var err error
s.Origin.SessionVersion, err = strconv.ParseUint(tmp, 10, 64)

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 err != nil {
return fmt.Errorf("%w `%v`", errSDPInvalidNumericValue, tmp)
}
Expand All @@ -132,6 +139,9 @@ 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:
s.Origin.SessionID, err = strconv.ParseUint(tmp, 10, 64)
}
Expand Down
45 changes: 45 additions & 0 deletions pkg/sdp/sdp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2555,6 +2555,51 @@ var cases = []struct {
}},
},
},
{
"issue mediamtx/2558",
[]byte("v=0\r\n" +
"o=- 1698210484.879535 1698210484.879535 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" +
"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" +
"s=Playout\r\n" +
"m=video 0 RTP/AVP 96\r\n" +
"a=rtpmap:96 H264/90000\r\n" +
"a=fmtp:96 packetization-mode=1; profile-level-id=33;" +
" sprop-parameter-sets=Z00AM4qKUDwBE/L/4AAgAC2AgA==,aO48gA==\r\n"),
SessionDescription{
Origin: psdp.Origin{
Username: "-",
SessionID: 97041581188,
SessionVersion: 97041581188,
NetworkType: "IN",
AddressType: "IP4",
UnicastAddress: "46.242.10.231:12626",
},
SessionName: "Playout",
MediaDescriptions: []*psdp.MediaDescription{{
MediaName: psdp.MediaName{
Media: "video",
Protos: []string{"RTP", "AVP"},
Formats: []string{"96"},
},
Attributes: []psdp.Attribute{
{
Key: "rtpmap",
Value: "96 H264/90000",
},
{
Key: "fmtp",
Value: "96 packetization-mode=1; profile-level-id=33; sprop-parameter-sets=Z00AM4qKUDwBE/L/4AAgAC2AgA==,aO48gA==",
},
},
}},
},
},
}

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

0 comments on commit 35bf96c

Please sign in to comment.