From 2f13007351cd84a1baf40511dbe9a9c9359fda1b Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Fri, 26 Jan 2024 13:29:07 +0100 Subject: [PATCH] fix compatibility with some TP-Link cameras (#509) (#510) --- pkg/description/media.go | 14 ++++++++----- pkg/description/session_test.go | 35 ++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/pkg/description/media.go b/pkg/description/media.go index a7463032..d044bb3c 100644 --- a/pkg/description/media.go +++ b/pkg/description/media.go @@ -16,15 +16,19 @@ import ( "github.com/bluenviron/gortsplib/v4/pkg/format" ) -var smartRegexp = regexp.MustCompile("^([0-9]+) (.*?)/90000") +var ( + smartPayloadTypeRegexp = regexp.MustCompile("^smart/[0-9]/[0-9]+$") + smartRtpmapRegexp = regexp.MustCompile("^([0-9]+) (.+)/[0-9]+$") +) func replaceSmartPayloadType(payloadType string, attributes []psdp.Attribute) string { - if payloadType == "smart/1/90000" { + re1 := smartPayloadTypeRegexp.FindStringSubmatch(payloadType) + if re1 != nil { for _, attr := range attributes { if attr.Key == "rtpmap" { - sm := smartRegexp.FindStringSubmatch(attr.Value) - if sm != nil { - return sm[1] + re2 := smartRtpmapRegexp.FindStringSubmatch(attr.Value) + if re2 != nil { + return re2[1] } } } diff --git a/pkg/description/session_test.go b/pkg/description/session_test.go index eca58382..864bffb8 100644 --- a/pkg/description/session_test.go +++ b/pkg/description/session_test.go @@ -550,7 +550,7 @@ var casesSession = []struct { }, }, { - "tp-link", + "issue mediamtx/1267 (tp-link)", "v=0\r\n" + "o=- 4158123474391860926 2 IN IP4 127.0.0.1\r\n" + "s=-\r\n" + @@ -579,6 +579,39 @@ var casesSession = []struct { }, }, }, + { + "issue gortsplib/509 (tp-link)", + "v=0\n" + + "o=- 14665860 31787219 1 IN IP4 192.168.1.102\n" + + "s=Session streamed by \"TP-LINK RTSP Server\"\n" + + "t=0 0\n" + + "a=smart_encoder:virtualIFrame=1\n" + + "m=application/tp-link 0 RTP/AVP smart/0/25000\n" + + "a=rtpmap:95 tp-link/25000\n" + + "a=control:track3\n", + "v=0\r\n" + + "o=- 0 0 IN IP4 127.0.0.1\r\n" + + "s=Session streamed by \"TP-LINK RTSP Server\"\r\n" + + "c=IN IP4 0.0.0.0\r\n" + + "t=0 0\r\n" + + "m=application/tp-link 0 RTP/AVP 95\r\n" + + "a=control:track3\r\n" + + "a=rtpmap:95 tp-link/25000\r\n", + Session{ + Title: `Session streamed by "TP-LINK RTSP Server"`, + Medias: []*Media{ + { + Type: "application/tp-link", + Formats: []format.Format{&format.Generic{ + PayloadTyp: 95, + RTPMa: "tp-link/25000", + ClockRat: 25000, + }}, + Control: "track3", + }, + }, + }, + }, { "mercury", "v=0\n" +