HLS video handling/storage/state refactor (#151)

* WIP with new transcoder progress monitor

* A whole different WIP in progress monitoring via local PUTs

* Use an actual hls playlist parser to rewrite master playlist

* Cleanup

* Private vs public path for thumbnail generation

* Allow each storage provider to make decisions of how to store different types of files

* Simplify inbound file writes

* Revert

* Split out set stream as connected/disconnected state methods

* Update videojs

* Add comment about the hls handler

* Rework of the offline stream state.  For #85

* Delete old unreferenced video segment files from disk

* Cleanup all segments and revert to a completely offline state after 5min

* Stop thumbnail generation on stream stop. Copy logo to thumbnail on cleanup.

* Update transcoder test

* Add comment

* Return http 200 on success to transcoder. Tweak how files are written to disk

* Force pixel color format in transcoder

* Add debugging info for S3 transfers. Add default ACL.

* Fix cleanup timer

* Reset session stats when we cleanup the session.

* Put log file back

* Update test

* File should not be a part of this commit

* Add centralized shared performance timer for use anywhere

* Post-rebase cleanup

* Support returning nil from storage provider save

* Updates to reflect package changes + other updates in master

* Fix storage providers being overwritten

* Do not return pointer in save. Support cache headers with S3 providers

* Split out videojs + vhs and point to specific working versions of them

* Bump vjs and vhs versions

* Fix test

* Remove unused

* Update upload warning message

* No longer valid comment

* Pin videojs and vhs versions
This commit is contained in:
Gabe Kangas
2020-10-14 14:07:38 -07:00
committed by GitHub
parent 57f2e4b567
commit 6ea9affce0
43 changed files with 30296 additions and 56701 deletions

View File

@@ -5,7 +5,6 @@ import (
"path"
"path/filepath"
"strconv"
"time"
log "github.com/sirupsen/logrus"
@@ -18,13 +17,16 @@ import (
)
var (
_stats *models.Stats
_storage models.ChunkStorageProvider
_cleanupTimer *time.Timer
_yp *yp.YP
_broadcaster *models.Broadcaster
_stats *models.Stats
_storage models.StorageProvider
_transcoder *ffmpeg.Transcoder
_yp *yp.YP
_broadcaster *models.Broadcaster
)
var handler ffmpeg.HLSHandler
var fileWriter = ffmpeg.FileWriterReceiverService{}
//Start starts up the core processing
func Start() error {
resetDirectories()
@@ -39,6 +41,13 @@ func Start() error {
return err
}
// The HLS handler takes the written HLS playlists and segments
// and makes storage decisions. It's rather simple right now
// but will play more useful when recordings come into play.
handler = ffmpeg.HLSHandler{}
handler.Storage = _storage
fileWriter.SetupFileWriterReceiverService(&handler)
if err := createInitialOfflineState(); err != nil {
log.Error("failed to create the initial offline state")
return err
@@ -63,31 +72,26 @@ func createInitialOfflineState() error {
}
}
ffmpeg.ShowStreamOfflineState()
transitionToOfflineVideoStreamContent()
return nil
}
func startCleanupTimer() {
_cleanupTimer = time.NewTimer(5 * time.Minute)
go func() {
for {
select {
case <-_cleanupTimer.C:
// Reset the session count since the session is over
_stats.SessionMaxViewerCount = 0
resetDirectories()
ffmpeg.ShowStreamOfflineState()
}
}
}()
}
// transitionToOfflineVideoStreamContent will overwrite the current stream with the
// offline video stream state only. No live stream HLS segments will continue to be
// referenced.
func transitionToOfflineVideoStreamContent() {
log.Traceln("Firing transcoder with offline stream state")
// StopCleanupTimer will stop the previous cleanup timer
func stopCleanupTimer() {
if _cleanupTimer != nil {
_cleanupTimer.Stop()
}
offlineFilename := "offline.ts"
offlineFilePath := "static/" + offlineFilename
_transcoder := ffmpeg.NewTranscoder()
_transcoder.SetSegmentLength(10)
_transcoder.SetInput(offlineFilePath)
_transcoder.Start()
// Copy the logo to be the thumbnail
utils.Copy(filepath.Join("webroot", config.Config.InstanceDetails.Logo.Large), "webroot/thumbnail.jpg")
}
func resetDirectories() {
@@ -112,4 +116,7 @@ func resetDirectories() {
os.MkdirAll(path.Join(config.PrivateHLSStoragePath, strconv.Itoa(0)), 0777)
os.MkdirAll(path.Join(config.PublicHLSStoragePath, strconv.Itoa(0)), 0777)
}
// Remove the previous thumbnail
utils.Copy(config.Config.InstanceDetails.Logo.Large, "webroot/thumbnail.jpg")
}