Cleanup incoming stream handler
Cleaned up the incoming RTMP handler to close connections on error. The code aquireing the RTMP channel was also rewritten to be more idomatic and easier to follow.
This commit is contained in:
parent
b3b9255ea0
commit
238d80658b
26
handlers.go
26
handlers.go
|
@ -364,37 +364,39 @@ func handlePublish(conn *rtmp.Conn) {
|
|||
if len(urlParts) > 2 {
|
||||
common.LogErrorln("Extra garbage after stream key")
|
||||
l.Unlock()
|
||||
conn.Close()
|
||||
return
|
||||
}
|
||||
|
||||
if len(urlParts) != 2 {
|
||||
common.LogErrorln("Missing stream key")
|
||||
l.Unlock()
|
||||
conn.Close()
|
||||
return
|
||||
}
|
||||
|
||||
if urlParts[1] != settings.GetStreamKey() {
|
||||
common.LogErrorln("Stream key is incorrect. Denying stream.")
|
||||
l.Unlock()
|
||||
conn.Close()
|
||||
return //If key not match, deny stream
|
||||
}
|
||||
|
||||
streamPath := urlParts[0]
|
||||
ch := channels[streamPath]
|
||||
if ch == nil {
|
||||
ch = &Channel{}
|
||||
ch.que = pubsub.NewQueue()
|
||||
ch.que.WriteHeader(streams)
|
||||
channels[streamPath] = ch
|
||||
} else {
|
||||
ch = nil
|
||||
}
|
||||
l.Unlock()
|
||||
if ch == nil {
|
||||
common.LogErrorln("Unable to start stream, channel is nil.")
|
||||
ch, exists := channels[streamPath]
|
||||
if exists {
|
||||
common.LogErrorln("Stream already running. Denying publish.")
|
||||
conn.Close()
|
||||
l.Unlock()
|
||||
return
|
||||
}
|
||||
|
||||
ch = &Channel{}
|
||||
ch.que = pubsub.NewQueue()
|
||||
ch.que.WriteHeader(streams)
|
||||
channels[streamPath] = ch
|
||||
l.Unlock()
|
||||
|
||||
stats.startStream()
|
||||
|
||||
common.LogInfoln("Stream started")
|
||||
|
|
Loading…
Reference in New Issue