diff --git a/protocol/hls/source.go b/protocol/hls/source.go index 2b98069f..53a8f5ac 100644 --- a/protocol/hls/source.go +++ b/protocol/hls/source.go @@ -100,7 +100,9 @@ func (source *Source) Write(p av.Packet) error { if len(source.packetQueue) >= maxQueueNum-24 { source.DropPacket(source.packetQueue, source.info) } else { - source.packetQueue <- p + if !source.closed { + source.packetQueue <- p + } } return nil } diff --git a/protocol/rtmp/stream.go b/protocol/rtmp/stream.go index 1586222b..09f0ec4d 100755 --- a/protocol/rtmp/stream.go +++ b/protocol/rtmp/stream.go @@ -29,18 +29,16 @@ func (rs *RtmpStream) HandleReader(r av.ReadCloser) { info := r.Info() var stream *Stream i, ok := rs.streams.Get(info.Key) - if ok { - if s, ok := i.(*Stream); ok { - s.TransStop() - id := s.ID() - if id != EmptyID && id != info.UID { - ns := NewStream() - s.Copy(ns) - s = ns - rs.streams.Set(info.Key, ns) - } + if stream, ok = i.(*Stream); ok { + stream.TransStop() + id := stream.ID() + if id != EmptyID && id != info.UID { + ns := NewStream() + stream.Copy(ns) + stream = ns + rs.streams.Set(info.Key, ns) } - } else { + }else { stream = NewStream() rs.streams.Set(info.Key, stream) }