fix: stream close process

This commit is contained in:
langhuihui
2023-09-13 17:06:36 +08:00
parent 148768d9fc
commit ff6d3a7bfc
4 changed files with 12 additions and 11 deletions

View File

@@ -42,8 +42,7 @@ type Publish struct {
Key string // 发布鉴权key
SecretArgName string `default:"secret"` // 发布鉴权参数名
ExpireArgName string `default:"expire"` // 发布鉴权失效时间参数名
RingSize int `default:"256"` // 初始缓冲区大小
RingSizeMax int `default:"1024"` // 最大缓冲区大小
RingSize string `default:"256-1024"` // 初始缓冲区大小
}
func (c Publish) GetPublishConfig() Publish {

View File

@@ -327,16 +327,13 @@ func (r *Stream) action(action StreamAction) (ok bool) {
case STATE_CLOSED:
Streams.Delete(r.Path)
r.timeout.Stop()
r.Subscribers.Dispose()
for !r.actionChan.Close() {
// 等待channel发送完毕伪自旋锁
time.Sleep(time.Millisecond * 100)
}
stateEvent = SEclose{event}
r.Subscribers.Broadcast(stateEvent)
r.Tracks.Range(func(_ string, t Track) {
t.Dispose()
})
r.Subscribers.Dispose()
r.actionChan.Close()
}
EventBus <- stateEvent
if r.Publisher != nil {
@@ -475,6 +472,11 @@ func (s *Stream) run() {
case action, ok := <-s.actionChan.C:
if !ok {
return
} else if s.State == STATE_CLOSED {
if s.actionChan.Close() { //再次尝试关闭
return
}
continue
}
timeStart = time.Now()
switch v := action.(type) {

View File

@@ -153,7 +153,7 @@ func (av *Media) SetStuff(stuff ...any) {
case IStream:
pubConf := v.GetPublisherConfig()
av.Base.SetStuff(v)
av.Init(pubConf.RingSize, NewAVFrame)
av.Init(256, NewAVFrame)
av.SSRC = uint32(uintptr(unsafe.Pointer(av)))
av.等待上限 = pubConf.SpeedLimit
case uint32:

View File

@@ -20,7 +20,7 @@ const (
SUBMODE_BUFFER
)
var ErrDiscard = errors.New("dsicard")
var ErrDiscard = errors.New("discard")
type AVRingReader struct {
RingReader[any, *common.AVFrame]