From c74baf37c7afe745965fb2159d5e5a6900d95f24 Mon Sep 17 00:00:00 2001 From: shuhai Date: Mon, 31 Jan 2022 01:12:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=8E=B7=E5=8F=96App=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E5=92=8C=E6=B5=81=E5=90=8D=EF=BC=8CApp=20=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E5=8F=96=E4=B8=80=E7=BA=A7=E7=9B=AE=E5=BD=95=EF=BC=8C=E6=B5=81?= =?UTF-8?q?=E5=90=8D=E5=8F=96=E6=9C=80=E5=90=8E=E4=B8=80=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stream.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/stream.go b/stream.go index d5a47c5..a9b40e8 100644 --- a/stream.go +++ b/stream.go @@ -2,6 +2,7 @@ package engine import ( "context" + "strings" "sync" "time" @@ -107,6 +108,11 @@ type Stream struct { OnClose func() `json:"-"` ExtraProp interface{} //额外的属性,用于实现子类化,减少map的使用 closeDelay *time.Timer + + //AppName 应用名 + AppName string + //StreamName 流名 + StreamName string } func (r *Stream) Close() { @@ -153,6 +159,12 @@ func (r *Stream) Publish() bool { r.AudioTracks.Init(r) r.DataTracks.Init(r) r.StartTime = time.Now() + + //获取App名称和流名,App 名称取一级目录,流名取最后一级 + param := strings.Split(r.StreamPath, "/") + r.AppName = param[0] + r.StreamName = param[len(param)-1] + Streams.m[r.StreamPath] = r utils.Print(Green("Stream publish:"), BrightCyan(r.StreamPath)) go r.waitClose(closeChann) From 51e76ebda986554be35ef41a7a6848169b1f4f95 Mon Sep 17 00:00:00 2001 From: shuhai Date: Tue, 1 Feb 2022 22:20:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96stream=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stream.go | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/stream.go b/stream.go index da2e824..e619c03 100644 --- a/stream.go +++ b/stream.go @@ -55,7 +55,7 @@ func init() { var Streams StreamCollection var StreamTimeoutError = errors.New("timeout") -//FindStream 根据流路径查找流 +// FindStream 根据流路径查找流 func FindStream(streamPath string) *Stream { return Streams.GetStream(streamPath) } @@ -93,21 +93,34 @@ func (r *StreamContext) Update() { // Stream 流定义 type Stream struct { - URL string //远程地址,仅远程拉流有值 - StreamContext `json:"-"` - StreamPath string - Type string //流类型,来自发布者 - StartTime time.Time //流的创建时间 - Subscribers []*Subscriber // 订阅者 - VideoTracks Tracks - AudioTracks Tracks - DataTracks Tracks - AutoCloseAfter *int //当无人订阅时延迟N秒后自动停止发布 - Transcoding map[string]string //转码配置,key:目标编码,value:发布者提供的编码 + //URL 远程地址,仅远程拉流有值 + URL string + StreamContext `json:"-"` + StreamPath string + + //Type 流类型,来自发布者 + Type string + + //StartTime 流的创建时间 + StartTime time.Time + + //Subscribers 订阅者 + Subscribers []*Subscriber + VideoTracks Tracks + AudioTracks Tracks + DataTracks Tracks + + //AutoCloseAfter 当无人订阅时延迟N秒后自动停止发布 + AutoCloseAfter *int + + //Transcoding 转码配置,key:目标编码,value:发布者提供的编码 + Transcoding map[string]string subscribeMutex sync.Mutex - OnClose func() `json:"-"` - ExtraProp interface{} //额外的属性,用于实现子类化,减少map的使用 - closeDelay *time.Timer + OnClose func() `json:"-"` + + //ExtraProp 额外的属性,用于实现子类化,减少map的使用 + ExtraProp interface{} + closeDelay *time.Timer //AppName 应用名 AppName string