Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdp: support cameras with decimal numbers in origin #455

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading