diff --git a/io.go b/io.go index 79ab876..107ac77 100644 --- a/io.go +++ b/io.go @@ -214,7 +214,7 @@ func (io *IO) receive(streamPath string, specific common.IIO) error { io.Info("publish", zap.String("ptr", fmt.Sprintf("%p", iPub))) s.pubLocker.Lock() defer s.pubLocker.Unlock() - if config.Global.EnableAuth { + if _, isPuller := specific.(IPuller); config.Global.EnableAuth && !isPuller { onAuthPub := OnAuthPub if auth, ok := specific.(AuthPub); ok { onAuthPub = auth.OnAuth diff --git a/subscriber.go b/subscriber.go index 4bd8022..0df59e5 100644 --- a/subscriber.go +++ b/subscriber.go @@ -321,7 +321,15 @@ func (s *Subscriber) PlayBlock(subType byte) { subMode, _ = strconv.Atoi(s.Args.Get(conf.SubModeArgName)) } var initState = 0 - var videoFrame, audioFrame *AVFrame + var videoFrame, audioFrame ,lastSentAF, lastSentVF *AVFrame + defer func(){ + if lastSentVF != nil { + lastSentVF.ReaderLeave() + } + if lastSentAF != nil { + lastSentAF.ReaderLeave() + } + }() for ctx.Err() == nil { if hasVideo { for ctx.Err() == nil { @@ -343,6 +351,7 @@ func (s *Subscriber) PlayBlock(subType byte) { if audioFrame != nil { if util.Conditoinal(conf.SyncMode == 0, videoFrame.Timestamp > audioFrame.Timestamp, videoFrame.WriteTime.After(audioFrame.WriteTime)) { // fmt.Println("switch audio", audioFrame.CanRead) + lastSentAF = audioFrame sendAudioFrame(audioFrame) audioFrame = nil break @@ -353,6 +362,7 @@ func (s *Subscriber) PlayBlock(subType byte) { } if !conf.IFrameOnly || videoFrame.IFrame { + lastSentVF = videoFrame sendVideoFrame(videoFrame) } else { // fmt.Println("skip video", frame.Sequence) @@ -389,12 +399,14 @@ func (s *Subscriber) PlayBlock(subType byte) { } if hasVideo && videoFrame != nil { if util.Conditoinal(conf.SyncMode == 0, audioFrame.Timestamp > videoFrame.Timestamp, audioFrame.WriteTime.After(videoFrame.WriteTime)) { + lastSentVF = videoFrame sendVideoFrame(videoFrame) videoFrame = nil break } } if audioFrame.Timestamp >= s.AudioReader.SkipTs { + lastSentAF = audioFrame sendAudioFrame(audioFrame) } else { // fmt.Println("skip audio", frame.AbsTime, s.AudioReader.SkipTs) @@ -402,12 +414,7 @@ func (s *Subscriber) PlayBlock(subType byte) { } } } - if videoFrame != nil { - videoFrame.ReaderLeave() - } - if audioFrame != nil { - audioFrame.ReaderLeave() - } + stopReason = zap.Error(ctx.Err()) }