Skip to content

Take control over your live stream video by running it yourself. Streaming + chat out of the box.

Split out setting broadcaster details into its own file

Gabe Kangas78376ed80cd4
diff --git a/core/rtmp/broadcaster.go b/core/rtmp/broadcaster.go
new file mode 100644
index 0000000000..3645bf5a0a
--- /dev/null
+++ b/core/rtmp/broadcaster.go
@@ -0,0 +1,35 @@
+package rtmp
+
+import (
+ "time"
+
+ "github.com/nareix/joy5/format/flv/flvio"
+ "github.com/owncast/owncast/core"
+ "github.com/owncast/owncast/models"
+ log "github.com/sirupsen/logrus"
+)
+
+func setCurrentBroadcasterInfo(t flvio.Tag, remoteAddr string) {
+ data, err := getInboundDetailsFromMetadata(t.DebugFields())
+ if err != nil {
+ log.Errorln(err)
+ return
+ }
+
+ broadcaster := models.Broadcaster{
+ RemoteAddr: remoteAddr,
+ Time: time.Now(),
+ StreamDetails: models.InboundStreamDetails{
+ Width: data.Width,
+ Height: data.Height,
+ VideoBitrate: int(data.VideoBitrate),
+ VideoCodec: getVideoCodec(data.VideoCodec),
+ VideoFramerate: data.VideoFramerate,
+ AudioBitrate: int(data.AudioBitrate),
+ AudioCodec: getAudioCodec(data.AudioCodec),
+ Encoder: data.Encoder,
+ },
+ }
+
+ core.SetBroadcaster(broadcaster)
+}
diff --git a/core/rtmp/rtmp.go b/core/rtmp/rtmp.go
index 419e289cef..a93c9576bd 100644
--- a/core/rtmp/rtmp.go
+++ b/core/rtmp/rtmp.go
@@ -17,13 +17,11 @@ import (
"github.com/nareix/joy5/format/rtmp"
"github.com/owncast/owncast/config"
"github.com/owncast/owncast/core"
- "github.com/owncast/owncast/models"
"github.com/owncast/owncast/utils"
)
var (
- //IsConnected whether there is a connection or not
- _isConnected = false
+ _hasInboundRTMPConnection = false
)
var _pipe *os.File
@@ -61,31 +59,6 @@ func Start() {
}
}
-func setCurrentBroadcasterInfo(t flvio.Tag, remoteAddr string) {
- data, err := getInboundDetailsFromMetadata(t.DebugFields())
- if err != nil {
- log.Errorln(err)
- return
- }
-
- broadcaster := models.Broadcaster{
- RemoteAddr: remoteAddr,
- Time: time.Now(),
- StreamDetails: models.InboundStreamDetails{
- Width: data.Width,
- Height: data.Height,
- VideoBitrate: int(data.VideoBitrate),
- VideoCodec: getVideoCodec(data.VideoCodec),
- VideoFramerate: data.VideoFramerate,
- AudioBitrate: int(data.AudioBitrate),
- AudioCodec: getAudioCodec(data.AudioCodec),
- Encoder: data.Encoder,
- },
- }
-
- core.SetBroadcaster(broadcaster)
-}
-
func HandleConn(c *rtmp.Conn, nc net.Conn) {
c.LogTagEvent = func(isRead bool, t flvio.Tag) {
if t.Type == flvio.TAG_AMF0 {
@@ -94,7 +67,7 @@ func HandleConn(c *rtmp.Conn, nc net.Conn) {
}
}
- if _isConnected {
+ if _hasInboundRTMPConnection {
log.Errorln("stream already running; can not overtake an existing stream")
nc.Close()
return
@@ -113,7 +86,7 @@ func HandleConn(c *rtmp.Conn, nc net.Conn) {
pipePath := utils.GetTemporaryPipePath()
syscall.Mkfifo(pipePath, 0666)
- _isConnected = true
+ _hasInboundRTMPConnection = true
core.SetStreamAsConnected()
_rtmpConnection = nc
@@ -126,7 +99,7 @@ func HandleConn(c *rtmp.Conn, nc net.Conn) {
w := flv.NewMuxer(f)
for {
- if !_isConnected {
+ if !_hasInboundRTMPConnection {
break
}
@@ -147,7 +120,7 @@ func handleDisconnect(conn net.Conn) {
log.Infoln("RTMP disconnected.")
conn.Close()
_pipe.Close()
- _isConnected = false
+ _hasInboundRTMPConnection = false
}
// Disconnect will force disconnect the current inbound RTMP connection.
@@ -159,9 +132,3 @@ func Disconnect() {
log.Infoln("Inbound stream disconnect requested.")
handleDisconnect(_rtmpConnection)
}
-
-//IsConnected gets whether there is an rtmp connection or not
-//this is only a getter since it is controlled by the rtmp handler
-func IsConnected() bool {
- return _isConnected
-}