From 1c57f1bec4fe63cc5d61cfc9b8b3250403e3ce11 Mon Sep 17 00:00:00 2001 From: cnotch Date: Mon, 25 Nov 2024 19:41:35 +0800 Subject: [PATCH] fixed bug for tp-link rtsp session format --- service/rtsp/pull_client.go | 12 ++++++++++++ service/rtsp/sdp_test.go | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/service/rtsp/pull_client.go b/service/rtsp/pull_client.go index 7e368f1..5866283 100755 --- a/service/rtsp/pull_client.go +++ b/service/rtsp/pull_client.go @@ -464,6 +464,14 @@ func (c *PullClient) receiveResponse() (resp *Response, err error) { return } +func trimSessionString(s string) string { + idx := strings.Index(s, ";") + if idx > 0 { + return strings.TrimSpace(s[:idx]) + } + return s +} + func (c *PullClient) requestWithResponse(r *Request) (*Response, error) { err := c.request(r) if err != nil { @@ -477,6 +485,10 @@ func (c *PullClient) requestWithResponse(r *Request) (*Response, error) { // 保存 session c.rsession = resp.Header.Get(FieldSession) + if len(c.rsession) > 0 { + // Fixed: TP-Link RTSP session fields(5EA2A41D;timeout=15) + c.rsession = trimSessionString(c.rsession) + } // 如果需要安全信息,增加安全信息并再次请求 if resp.StatusCode == StatusUnauthorized { diff --git a/service/rtsp/sdp_test.go b/service/rtsp/sdp_test.go index 615bef1..7b50576 100755 --- a/service/rtsp/sdp_test.go +++ b/service/rtsp/sdp_test.go @@ -100,6 +100,24 @@ a=rtpmap:97 MPEG4-GENERIC/44100/2 a=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=121056E500 a=control:streamid=1 ` +const sdpTplink500 = `v=0 +o=- 14665860 31787219 1 IN IP4 192.168.1.60 +s=Session streamed by "TP-LINK RTSP Server" +t=0 0 +m=video 0 RTP/AVP 96 +c=IN IP4 0.0.0.0 +b=AS:4096 +a=range:npt=0- +a=control:track1 +a=rtpmap:96 H265/90000 +a=fmtp:96 profile-space=0;profile-id=12;tier-flag=0;level-id=0;interop-constraints=600000000000;sprop-vps=AAAAAUABDAH//wFgAAADAAADAAADAAADAJasCQ==;sprop-sps=AAAAAUIBAQFgAAADAAADAAADAAADAJagAWggBln3ja5JMmuWMAgAAAMACAAAAwB4QA==;sprop-pps=AAAAAUQB4HawJkA= +m=audio 0 RTP/AVP 8 +a=rtpmap:8 PCMA/8000 +a=control:track2 +m=application/TP-LINK 0 RTP/AVP smart/1/90000 +a=rtpmap:95 TP-LINK/90000 +a=control:track3 +` func Benchmark_ThirdSdpParse(b *testing.B) { b.ResetTimer()