From 53bccaaaa75897e916149d312ec50d52735ae868 Mon Sep 17 00:00:00 2001 From: scruzin Date: Fri, 11 Jan 2019 00:01:26 +1030 Subject: [PATCH] Simplifed connectStream(). --- rtmp/rtmp.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/rtmp/rtmp.go b/rtmp/rtmp.go index 4d432a00..a481aa84 100644 --- a/rtmp/rtmp.go +++ b/rtmp/rtmp.go @@ -192,22 +192,19 @@ func connect(s *Session) error { // connectStream reads a packet and handles it func connectStream(s *Session) error { var err error - for !s.isPlaying && s.isConnected() { + for !s.isPlaying { pkt := packet{} err = pkt.read(s) if err != nil { break } - if pkt.bodySize == 0 { - continue - } - if pkt.packetType == RTMP_PACKET_TYPE_AUDIO || - pkt.packetType == RTMP_PACKET_TYPE_VIDEO || - pkt.packetType == RTMP_PACKET_TYPE_INFO { - s.log(DebugLevel, pkg+"got packet before play; ignoring") - continue - } + switch pkt.packetType { + case RTMP_PACKET_TYPE_AUDIO, RTMP_PACKET_TYPE_VIDEO, RTMP_PACKET_TYPE_INFO: + s.log(WarnLevel, pkg+"got packet before play; ignoring", "type", pkt.packetType) + default: + handlePacket(s, &pkt) // ignore errors + } err = handlePacket(s, &pkt) if err != nil { break