修复hook重复通知publish done事件

This commit is contained in:
yangjiechina
2024-07-14 17:59:56 +08:00
parent f1c6b3cada
commit db435f17aa
4 changed files with 17 additions and 9 deletions

View File

@@ -66,7 +66,7 @@
"on_record": "http://localhost:9000/api/v1/hook/on_reocrd",
"on_idle_timeout": "http://localhost:9000/api/v1/hook/on_idle_timeout",
"on_receive_timeout": "http://localhost:9000/api/v1/hook/on_recv_timeout"
"on_receive_timeout": "http://localhost:9000/api/v1/hook/on_receive_timeout"
},
"log": {

View File

@@ -109,7 +109,10 @@ func (t *transStream) AddSink(sink_ stream.Sink) error {
<-complete
connection.OnICEConnectionStateChange(func(state webrtc.ICEConnectionState) {
rtcSink.state = state
if webrtc.ICEConnectionStateDisconnected > state {
log.Sugar.Infof("ice state:%v sink:%d source:%s", state.String(), rtcSink.Id_, rtcSink.SourceId_)
if state > webrtc.ICEConnectionStateDisconnected {
log.Sugar.Errorf("webrtc peer断开链接 sink:%v source:%s", rtcSink.Id_, rtcSink.SourceId_)
rtcSink.Close()
}
})

View File

@@ -190,7 +190,7 @@ func (s *BaseSink) DesiredVideoCodecId() utils.AVCodecID {
// 拉流断开连接,不需要考虑线程安全
// 踢流走source管道删除,并且关闭Conn
func (s *BaseSink) Close() {
if SessionStateClosed != s.State_ {
if SessionStateClosed == s.State_ {
return
}

View File

@@ -2,6 +2,7 @@ package stream
import (
"fmt"
"github.com/lkmio/avformat/transport"
"github.com/lkmio/lkm/collections"
"github.com/lkmio/lkm/log"
"net"
@@ -408,6 +409,7 @@ func (s *PublishSource) AddSink(sink Sink) bool {
}
s.sinkCount++
log.Sugar.Infof("sink count:%d source:%s", s.sinkCount, s.Id_)
//新的传输流,发送缓存的音视频帧
if !ok && AppConfig.GOPCache && s.existVideo {
@@ -429,6 +431,7 @@ func (s *PublishSource) RemoveSink(sink Sink) bool {
s.sinkCount--
s.removeSinkTime = time.Now()
HookPlayDoneEvent(sink)
log.Sugar.Infof("sink count:%d source:%s", s.sinkCount, s.Id_)
return true
}
}
@@ -458,11 +461,6 @@ func (s *PublishSource) doClose() {
return
}
if s.Conn != nil {
s.Conn.Close()
s.Conn = nil
}
if s.TransDeMuxer != nil {
s.TransDeMuxer.Close()
s.TransDeMuxer = nil
@@ -527,7 +525,14 @@ func (s *PublishSource) doClose() {
s.closed = true
s.transStreams = nil
go HookPublishDoneEvent(s)
go func() {
if s.Conn != nil && s.Conn.(*transport.Conn).IsActive() {
s.Conn.Close()
s.Conn = nil
}
HookPublishDoneEvent(s)
}()
}
func (s *PublishSource) Close() {