(puller IPuller)
| 39 | } |
| 40 | |
| 41 | func (pub *Puller) startPull(puller IPuller) { |
| 42 | // badPuller := true |
| 43 | var stream *Stream |
| 44 | var err error |
| 45 | streamPath := pub.StreamPath |
| 46 | if i := strings.Index(streamPath, "?"); i >= 0 { |
| 47 | streamPath = streamPath[:i] |
| 48 | } |
| 49 | if oldPuller, loaded := Pullers.LoadOrStore(streamPath, puller); loaded { |
| 50 | pub := oldPuller.(IPuller).GetPublisher() |
| 51 | stream = pub.Stream |
| 52 | if stream != nil { |
| 53 | puller.Error("puller already exists", zap.Int8("streamState", int8(stream.State))) |
| 54 | if stream.State == STATE_CLOSED { |
| 55 | oldPuller.(IPuller).Stop(zap.String("reason", "dead puller")) |
| 56 | } |
| 57 | } else { |
| 58 | puller.Error("puller already exists", zap.Time("createAt", pub.StartTime)) |
| 59 | } |
| 60 | return |
| 61 | } |
| 62 | defer func() { |
| 63 | Pullers.Delete(streamPath) |
| 64 | puller.Disconnect() |
| 65 | if stream != nil { |
| 66 | stream.Close() |
| 67 | } |
| 68 | }() |
| 69 | puber := puller.GetPublisher() |
| 70 | var startTime time.Time |
| 71 | for puller.Info("start pull"); puller.Reconnect(); puller.Warn("restart pull") { |
| 72 | if time.Since(startTime) < 5*time.Second { |
| 73 | time.Sleep(5 * time.Second) |
| 74 | } |
| 75 | startTime = time.Now() |
| 76 | if err = puller.Connect(); err != nil { |
| 77 | // if err == io.EOF { |
| 78 | // puller.Info("pull complete") |
| 79 | // return |
| 80 | // } |
| 81 | puller.Error("pull connect", zap.Error(err)) |
| 82 | // if badPuller { |
| 83 | // return |
| 84 | // } |
| 85 | } else { |
| 86 | if err = puller.Publish(pub.StreamPath, puller); err != nil { |
| 87 | puller.Error("pull publish", zap.Error(err)) |
| 88 | continue |
| 89 | } |
| 90 | if stream != puber.Stream { |
| 91 | // 老流中的音视频轨道不可再使用 |
| 92 | puber.AudioTrack = nil |
| 93 | puber.VideoTrack = nil |
| 94 | } |
| 95 | stream = puber.Stream |
| 96 | // badPuller = false |
| 97 | if err = puller.Pull(); err != nil && !puller.IsShutdown() { |
| 98 | puller.Error("pull interrupt", zap.Error(err)) |
nothing calls this directly
no test coverage detected