feat: wait publish tracks longger

This commit is contained in:
langhuihui
2024-03-13 09:52:40 +08:00
parent 0280cfa655
commit 9dc92eca7b
2 changed files with 10 additions and 6 deletions

View File

@@ -17,6 +17,7 @@ version: 版本
name: 名称
state: 状态
initialize: 初始化
"no tracks": 没有轨道
"start read": 开始读取
"start pull": 开始从远端拉流
"stop pull": 停止从远端拉流

View File

@@ -266,14 +266,15 @@ func (s *Stream) SetIDR(video common.Track) {
}
func findOrCreateStream(streamPath string, waitTimeout time.Duration) (s *Stream, created bool) {
p := strings.Split(streamPath, "/")
if len(p) < 2 {
pl := len(p)
if pl < 2 {
log.Warn(Red("Stream Path Format Error:"), streamPath)
return nil, false
}
actual, loaded := Streams.LoadOrStore(streamPath, &Stream{
Path: streamPath,
AppName: p[0],
StreamName: strings.Join(p[1:], "/"),
AppName: strings.Join(p[1:pl-1], "/"),
StreamName: p[pl-1],
StartTime: time.Now(),
timeout: time.NewTimer(waitTimeout),
})
@@ -484,8 +485,10 @@ func (s *Stream) run() {
if !lost {
if trackCount == 0 {
s.Warn("no tracks")
if time.Since(s.StartTime) > timeout {
lost = true
s.action(ACTION_CLOSE)
}
continue
} else if s.Publisher != nil && s.Publisher.IsClosed() {
s.Warn("publish is closed", zap.Error(context.Cause(s.publisher)), zap.String("ptr", fmt.Sprintf("%p", s.publisher.Context)))
@@ -543,7 +546,7 @@ func (s *Stream) run() {
needKick := !republish && oldPuber != nil && conf.KickExist // 需要踢掉老的发布者
if needKick {
s.Warn("kick", zap.String("old type", oldPuber.Type))
s.Publisher.OnEvent(SEKick{CreateEvent[struct{}](util.Null)})
s.Publisher.OnEvent(SEKick{CreateEvent(util.Null)})
}
s.Publisher = v.Value
s.PublishTimeout = conf.PublishTimeout