Browse Source

fix: stream is nil course panic

pull/6/head 0.0.4
halwu(吴浩麟) 8 years ago
parent
commit
3979be9d24
  1. 4
      protocol/hls/source.go
  2. 20
      protocol/rtmp/stream.go

4
protocol/hls/source.go

@ -100,7 +100,9 @@ func (source *Source) Write(p av.Packet) error {
if len(source.packetQueue) >= maxQueueNum-24 { if len(source.packetQueue) >= maxQueueNum-24 {
source.DropPacket(source.packetQueue, source.info) source.DropPacket(source.packetQueue, source.info)
} else { } else {
source.packetQueue <- p if !source.closed {
source.packetQueue <- p
}
} }
return nil return nil
} }

20
protocol/rtmp/stream.go

@ -29,18 +29,16 @@ func (rs *RtmpStream) HandleReader(r av.ReadCloser) {
info := r.Info() info := r.Info()
var stream *Stream var stream *Stream
i, ok := rs.streams.Get(info.Key) i, ok := rs.streams.Get(info.Key)
if ok { if stream, ok = i.(*Stream); ok {
if s, ok := i.(*Stream); ok { stream.TransStop()
s.TransStop() id := stream.ID()
id := s.ID() if id != EmptyID && id != info.UID {
if id != EmptyID && id != info.UID { ns := NewStream()
ns := NewStream() stream.Copy(ns)
s.Copy(ns) stream = ns
s = ns rs.streams.Set(info.Key, ns)
rs.streams.Set(info.Key, ns)
}
} }
} else { }else {
stream = NewStream() stream = NewStream()
rs.streams.Set(info.Key, stream) rs.streams.Set(info.Key, stream)
} }

Loading…
Cancel
Save