MCPcopy Index your code
hub / github.com/Monibuca/engine / findOrCreateStream

Function findOrCreateStream

stream.go:267–296  ·  view source on GitHub ↗
(streamPath string, waitTimeout time.Duration)

Source from the content-addressed store, hash-verified

265 s.Tracks.SetIDR(video)
266}
267func 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
298func (r *Stream) resetTimer(dur time.Duration) {
299 r.Debug("reset timer", zap.Duration("timeout", dur))

Callers 1

receiveMethod · 0.85

Calls 10

WarnFunction · 0.92
SplitMethod · 0.80
DebugMethod · 0.65
WithMethod · 0.65
InfoMethod · 0.65
AddMethod · 0.45
InitMethod · 0.45
StringMethod · 0.45
Uint32Method · 0.45
runMethod · 0.45

Tested by

no test coverage detected