Simplify HLS storage paths (#1393)
* Remove private vs public HLS paths and add a HLS controller. Closes #875 * Use http.ServeFile instead
This commit is contained in:
@@ -118,9 +118,8 @@ func transitionToOfflineVideoStreamContent() {
|
||||
func resetDirectories() {
|
||||
log.Trace("Resetting file directories to a clean slate.")
|
||||
|
||||
// Wipe the public, web-accessible hls data directory
|
||||
utils.CleanupDirectory(config.PublicHLSStoragePath)
|
||||
utils.CleanupDirectory(config.PrivateHLSStoragePath)
|
||||
// Wipe hls data directory
|
||||
utils.CleanupDirectory(config.HLSStoragePath)
|
||||
|
||||
// Remove the previous thumbnail
|
||||
logo := data.GetLogoPath()
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
package storageproviders
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/owncast/owncast/config"
|
||||
"github.com/owncast/owncast/core/transcoder"
|
||||
"github.com/owncast/owncast/utils"
|
||||
)
|
||||
|
||||
// LocalStorage represents an instance of the local storage provider for HLS video.
|
||||
@@ -25,7 +23,7 @@ func (s *LocalStorage) Setup() error {
|
||||
_onlineCleanupTicker = time.NewTicker(1 * time.Minute)
|
||||
go func() {
|
||||
for range _onlineCleanupTicker.C {
|
||||
transcoder.CleanupOldContent(config.PublicHLSStoragePath)
|
||||
transcoder.CleanupOldContent(config.HLSStoragePath)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
@@ -55,15 +53,5 @@ func (s *LocalStorage) MasterPlaylistWritten(localFilePath string) {
|
||||
|
||||
// Save will save a local filepath using the storage provider.
|
||||
func (s *LocalStorage) Save(filePath string, retryCount int) (string, error) {
|
||||
newPath := ""
|
||||
|
||||
// This is a hack
|
||||
if filePath == "hls/stream.m3u8" {
|
||||
newPath = filepath.Join(config.PublicHLSStoragePath, filepath.Base(filePath))
|
||||
} else {
|
||||
newPath = filepath.Join(config.WebRoot, filePath)
|
||||
}
|
||||
|
||||
err := utils.Copy(filePath, newPath)
|
||||
return newPath, err
|
||||
return filePath, nil
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ func (s *S3Storage) rewriteRemotePlaylist(filePath string) error {
|
||||
item.URI = s.host + filepath.Join("/hls", item.URI)
|
||||
}
|
||||
|
||||
publicPath := filepath.Join(config.PublicHLSStoragePath, filepath.Base(filePath))
|
||||
publicPath := filepath.Join(config.HLSStoragePath, filepath.Base(filePath))
|
||||
|
||||
newPlaylist := p.String()
|
||||
|
||||
|
||||
@@ -50,17 +50,12 @@ func setStreamAsConnected(rtmpOut *io.PipeReader) {
|
||||
go _yp.Start()
|
||||
}
|
||||
|
||||
segmentPath := config.PublicHLSStoragePath
|
||||
s3Config := data.GetS3Config()
|
||||
segmentPath := config.HLSStoragePath
|
||||
|
||||
if err := setupStorage(); err != nil {
|
||||
log.Fatalln("failed to setup the storage", err)
|
||||
}
|
||||
|
||||
if s3Config.Enabled {
|
||||
segmentPath = config.PrivateHLSStoragePath
|
||||
}
|
||||
|
||||
go func() {
|
||||
_transcoder = transcoder.NewTranscoder()
|
||||
_transcoder.TranscoderCompleted = func(error) {
|
||||
@@ -100,8 +95,8 @@ func SetStreamAsDisconnected() {
|
||||
}
|
||||
|
||||
for index := range _currentBroadcast.OutputSettings {
|
||||
playlistFilePath := fmt.Sprintf(filepath.Join(config.PrivateHLSStoragePath, "%d/stream.m3u8"), index)
|
||||
segmentFilePath := fmt.Sprintf(filepath.Join(config.PrivateHLSStoragePath, "%d/%s"), index, offlineFilename)
|
||||
playlistFilePath := fmt.Sprintf(filepath.Join(config.HLSStoragePath, "%d/stream.m3u8"), index)
|
||||
segmentFilePath := fmt.Sprintf(filepath.Join(config.HLSStoragePath, "%d/%s"), index, offlineFilename)
|
||||
|
||||
if err := utils.Copy(offlineFilePath, segmentFilePath); err != nil {
|
||||
log.Warnln(err)
|
||||
@@ -191,7 +186,7 @@ func startOnlineCleanupTimer() {
|
||||
_onlineCleanupTicker = time.NewTicker(1 * time.Minute)
|
||||
go func() {
|
||||
for range _onlineCleanupTicker.C {
|
||||
transcoder.CleanupOldContent(config.PrivateHLSStoragePath)
|
||||
transcoder.CleanupOldContent(config.HLSStoragePath)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func (s *FileWriterReceiverService) uploadHandler(w http.ResponseWriter, r *http
|
||||
}
|
||||
|
||||
path := r.URL.Path
|
||||
writePath := filepath.Join(config.PrivateHLSStoragePath, path)
|
||||
writePath := filepath.Join(config.HLSStoragePath, path)
|
||||
|
||||
var buf bytes.Buffer
|
||||
defer r.Body.Close()
|
||||
|
||||
@@ -233,19 +233,8 @@ func NewTranscoder() *Transcoder {
|
||||
transcoder.currentStreamOutputSettings = data.GetStreamOutputVariants()
|
||||
transcoder.currentLatencyLevel = data.GetStreamLatencyLevel()
|
||||
transcoder.codec = getCodec(data.GetVideoCodec())
|
||||
|
||||
var outputPath string
|
||||
if data.GetS3Config().Enabled {
|
||||
// Segments are not available via the local HTTP server
|
||||
outputPath = config.PrivateHLSStoragePath
|
||||
} else {
|
||||
// Segments are available via the local HTTP server
|
||||
outputPath = config.PublicHLSStoragePath
|
||||
}
|
||||
|
||||
transcoder.segmentOutputPath = outputPath
|
||||
// Playlists are available via the local HTTP server
|
||||
transcoder.playlistOutputPath = config.PublicHLSStoragePath
|
||||
transcoder.segmentOutputPath = config.HLSStoragePath
|
||||
transcoder.playlistOutputPath = config.HLSStoragePath
|
||||
|
||||
transcoder.input = "pipe:0" // stdin
|
||||
|
||||
|
||||
@@ -94,27 +94,16 @@ func handleTranscoderMessage(message string) {
|
||||
|
||||
func createVariantDirectories() {
|
||||
// Create private hls data dirs
|
||||
utils.CleanupDirectory(config.PublicHLSStoragePath)
|
||||
utils.CleanupDirectory(config.PrivateHLSStoragePath)
|
||||
utils.CleanupDirectory(config.HLSStoragePath)
|
||||
|
||||
if len(data.GetStreamOutputVariants()) != 0 {
|
||||
for index := range data.GetStreamOutputVariants() {
|
||||
if err := os.MkdirAll(path.Join(config.PrivateHLSStoragePath, strconv.Itoa(index)), 0750); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
dir := path.Join(config.PublicHLSStoragePath, strconv.Itoa(index))
|
||||
log.Traceln("Creating", dir)
|
||||
if err := os.MkdirAll(dir, 0750); err != nil {
|
||||
if err := os.MkdirAll(path.Join(config.HLSStoragePath, strconv.Itoa(index)), 0750); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dir := path.Join(config.PrivateHLSStoragePath, strconv.Itoa(0))
|
||||
log.Traceln("Creating", dir)
|
||||
if err := os.MkdirAll(dir, 0750); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
dir = path.Join(config.PublicHLSStoragePath, strconv.Itoa(0))
|
||||
dir := path.Join(config.HLSStoragePath, strconv.Itoa(0))
|
||||
log.Traceln("Creating", dir)
|
||||
if err := os.MkdirAll(dir, 0750); err != nil {
|
||||
log.Fatalln(err)
|
||||
|
||||
Reference in New Issue
Block a user