| 265 | s.Tracks.SetIDR(video) |
| 266 | } |
| 267 | func findOrCreateStream(streamPath string, waitTimeout time.Duration) (s *Stream, created bool) { |
| 268 | p := strings.Split(streamPath, "/") |
| 269 | pl := len(p) |
| 270 | if pl < 2 { |
| 271 | log.Warn(Red("Stream Path Format Error:"), streamPath) |
| 272 | return nil, false |
| 273 | } |
| 274 | actual, loaded := Streams.LoadOrStore(streamPath, &Stream{ |
| 275 | Path: streamPath, |
| 276 | AppName: strings.Join(p[1:pl-1], "/"), |
| 277 | StreamName: p[pl-1], |
| 278 | StartTime: time.Now(), |
| 279 | timeout: time.NewTimer(waitTimeout), |
| 280 | }) |
| 281 | if s := actual.(*Stream); loaded { |
| 282 | for s.Logger == nil { |
| 283 | runtime.Gosched() |
| 284 | } |
| 285 | s.Debug("found") |
| 286 | return s, false |
| 287 | } else { |
| 288 | s.ID = streamIdGen.Add(1) |
| 289 | s.Subscribers.Init() |
| 290 | s.actionChan.Init(10) |
| 291 | s.Logger = log.LocaleLogger.With(zap.String("stream", streamPath), zap.Uint32("id", s.ID)) |
| 292 | s.Info("created") |
| 293 | go s.run() |
| 294 | return s, true |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | func (r *Stream) resetTimer(dur time.Duration) { |
| 299 | r.Debug("reset timer", zap.Duration("timeout", dur)) |