From 4895f2ec422b278f6cb0ef21703b718cca694a11 Mon Sep 17 00:00:00 2001 From: dexter <178529795@qq.com> Date: Mon, 13 Dec 2021 10:17:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=8E=B7=E5=8F=96rtsp?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 17 ++++++++++++++--- publisher.go | 10 ++++++++++ server.go | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index a646b59..7080d0a 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,14 @@ var config = struct { AutoPushList map[string]string }{":554", ":8000", ":8001", 0, false, nil, nil} +type RTSPStreamInfo struct { + StreamPath string + Type string //流类型,来自发布者 + StartTime time.Time + URL string + SubscriberCount int +} + func init() { InstallPlugin(&PluginConfig{ Name: "RTSP", @@ -29,10 +37,13 @@ func init() { Run: runPlugin, }) } -func getRtspList() (info []*RTSPublisher) { +func getRtspList() (info []*RTSPStreamInfo) { for _, s := range Streams.ToList() { - if rtsp, ok := s.ExtraProp.(*RTSPublisher); ok { - info = append(info, rtsp) + switch rtsp := s.ExtraProp.(type) { + case *RTSPublisher: + info = append(info, rtsp.GetInfo()) + case *RTSPClient: + info = append(info, rtsp.GetInfo()) } } return diff --git a/publisher.go b/publisher.go index a3cae81..3b520bc 100644 --- a/publisher.go +++ b/publisher.go @@ -18,6 +18,16 @@ type RTSPublisher struct { processFunc []func([]byte) } +func (p *RTSPublisher) GetInfo() (info *RTSPStreamInfo) { + info = &RTSPStreamInfo{ + URL: p.URL, + StreamPath: p.StreamPath, + Type: p.Type, + StartTime: p.StartTime, + SubscriberCount: len(p.Subscribers), + } + return +} func (p *RTSPublisher) setTracks(tracks gortsplib.Tracks) { if p.processFunc != nil { p.processFunc = p.processFunc[:len(tracks)] diff --git a/server.go b/server.go index 801f537..aadacbc 100644 --- a/server.go +++ b/server.go @@ -177,6 +177,7 @@ func (sh *RTSPServer) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (*ba Type: "RTSP push", }, } + p.ExtraProp = p p.URL = ctx.Req.URL.String() if p.Publish() { p.setTracks(ctx.Tracks)