Skip to content

Commit

Permalink
Merge pull request #33 from pdnews/feature/appAndStreamName
Browse files Browse the repository at this point in the history
Feature/app and stream name
  • Loading branch information
langhuihui authored Feb 2, 2022
2 parents bb93204 + 51e76eb commit ed42940
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package engine

import (
"context"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -54,7 +55,7 @@ func init() {
var Streams StreamCollection
var StreamTimeoutError = errors.New("timeout")

//FindStream 根据流路径查找流
// FindStream 根据流路径查找流
func FindStream(streamPath string) *Stream {
return Streams.GetStream(streamPath)
}
Expand Down Expand Up @@ -92,21 +93,39 @@ 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
//StreamName 流名
StreamName string
}

func (r *Stream) Close() {
Expand Down Expand Up @@ -153,6 +172,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)
Expand Down

0 comments on commit ed42940

Please sign in to comment.