2020-06-23 04:11:56 +03:00
|
|
|
package core
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
|
|
|
"github.com/gabek/owncast/config"
|
2020-06-23 23:11:01 +03:00
|
|
|
"github.com/gabek/owncast/core/chat"
|
2020-06-23 04:11:56 +03:00
|
|
|
"github.com/gabek/owncast/core/ffmpeg"
|
|
|
|
"github.com/gabek/owncast/models"
|
|
|
|
"github.com/gabek/owncast/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
_stats *models.Stats
|
|
|
|
_storage models.ChunkStorageProvider
|
|
|
|
)
|
|
|
|
|
|
|
|
//Start starts up the core processing
|
|
|
|
func Start() error {
|
|
|
|
resetDirectories()
|
|
|
|
|
|
|
|
if err := setupStats(); err != nil {
|
2020-07-07 07:27:31 +03:00
|
|
|
log.Error("failed to setup the stats")
|
2020-06-23 04:11:56 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := setupStorage(); err != nil {
|
2020-07-07 07:27:31 +03:00
|
|
|
log.Error("failed to setup the storage")
|
2020-06-23 04:11:56 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := createInitialOfflineState(); err != nil {
|
2020-07-07 07:27:31 +03:00
|
|
|
log.Error("failed to create the initial offline state")
|
2020-06-23 04:11:56 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-06-23 23:11:01 +03:00
|
|
|
chat.Setup(ChatListenerImpl{})
|
|
|
|
|
2020-06-23 04:11:56 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func createInitialOfflineState() error {
|
|
|
|
// Provide default files
|
|
|
|
if !utils.DoesFileExists("webroot/thumbnail.jpg") {
|
|
|
|
if err := utils.Copy("static/logo.png", "webroot/thumbnail.jpg"); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-26 03:44:47 +03:00
|
|
|
ffmpeg.ShowStreamOfflineState()
|
|
|
|
|
|
|
|
return nil
|
2020-06-23 04:11:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func resetDirectories() {
|
2020-07-07 07:27:31 +03:00
|
|
|
log.Trace("Resetting file directories to a clean slate.")
|
2020-06-23 04:11:56 +03:00
|
|
|
|
|
|
|
// Wipe the public, web-accessible hls data directory
|
|
|
|
os.RemoveAll(config.Config.PublicHLSPath)
|
|
|
|
os.RemoveAll(config.Config.PrivateHLSPath)
|
|
|
|
os.MkdirAll(config.Config.PublicHLSPath, 0777)
|
|
|
|
os.MkdirAll(config.Config.PrivateHLSPath, 0777)
|
|
|
|
|
|
|
|
// Remove the previous thumbnail
|
|
|
|
os.Remove("webroot/thumbnail.jpg")
|
|
|
|
|
|
|
|
// Create private hls data dirs
|
2020-07-06 08:03:53 +03:00
|
|
|
if len(config.Config.VideoSettings.StreamQualities) != 0 {
|
2020-06-23 04:11:56 +03:00
|
|
|
for index := range config.Config.VideoSettings.StreamQualities {
|
|
|
|
os.MkdirAll(path.Join(config.Config.PrivateHLSPath, strconv.Itoa(index)), 0777)
|
|
|
|
os.MkdirAll(path.Join(config.Config.PublicHLSPath, strconv.Itoa(index)), 0777)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
os.MkdirAll(path.Join(config.Config.PrivateHLSPath, strconv.Itoa(0)), 0777)
|
|
|
|
os.MkdirAll(path.Join(config.Config.PublicHLSPath, strconv.Itoa(0)), 0777)
|
|
|
|
}
|
|
|
|
}
|