From 3979be9d24f1f6a30a5d6ab8569829e952d6cdf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?halwu=28=E5=90=B4=E6=B5=A9=E9=BA=9F=29?= Date: Tue, 30 May 2017 18:43:48 +0800 Subject: [PATCH] fix: stream is nil course panic --- protocol/hls/source.go | 4 +++- protocol/rtmp/stream.go | 20 +++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) 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) }