2021-02-19 10:05:52 +03:00
|
|
|
package transcoder
|
2020-10-15 00:07:38 +03:00
|
|
|
|
|
|
|
import (
|
2023-08-10 02:19:09 +03:00
|
|
|
"github.com/owncast/owncast/config"
|
2020-10-15 00:07:38 +03:00
|
|
|
"github.com/owncast/owncast/models"
|
2023-08-10 02:19:09 +03:00
|
|
|
"github.com/owncast/owncast/replays"
|
|
|
|
log "github.com/sirupsen/logrus"
|
2020-10-15 00:07:38 +03:00
|
|
|
)
|
|
|
|
|
2020-11-13 02:14:59 +03:00
|
|
|
// HLSHandler gets told about available HLS playlists and segments.
|
2020-10-15 00:07:38 +03:00
|
|
|
type HLSHandler struct {
|
2023-08-10 02:19:09 +03:00
|
|
|
Storage models.StorageProvider
|
|
|
|
Recorder *replays.HLSRecorder
|
|
|
|
}
|
|
|
|
|
|
|
|
// StreamEnded is called when a stream is ended so the end time can be noted
|
|
|
|
// in the stream's metadata.
|
|
|
|
func (h *HLSHandler) StreamEnded() {
|
2023-08-10 02:35:42 +03:00
|
|
|
if config.EnableReplayFeatures {
|
2023-08-10 02:19:09 +03:00
|
|
|
h.Recorder.StreamEnded()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *HLSHandler) SetStreamId(streamId string) {
|
|
|
|
h.Storage.SetStreamId(streamId)
|
2023-09-01 07:12:32 +03:00
|
|
|
if config.EnableReplayFeatures {
|
|
|
|
h.Recorder = replays.NewRecording(streamId)
|
|
|
|
}
|
2020-10-15 00:07:38 +03:00
|
|
|
}
|
|
|
|
|
2020-11-13 02:14:59 +03:00
|
|
|
// SegmentWritten is fired when a HLS segment is written to disk.
|
2020-10-15 00:07:38 +03:00
|
|
|
func (h *HLSHandler) SegmentWritten(localFilePath string) {
|
2023-08-10 02:19:09 +03:00
|
|
|
remotePath, _, err := h.Storage.SegmentWritten(localFilePath)
|
|
|
|
if err != nil {
|
|
|
|
log.Errorln(err)
|
2023-08-21 07:13:59 +03:00
|
|
|
return
|
2023-08-10 02:19:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if h.Recorder != nil {
|
|
|
|
h.Recorder.SegmentWritten(remotePath)
|
|
|
|
} else {
|
|
|
|
log.Debugln("No HLS recorder available to notify of segment written.")
|
|
|
|
}
|
2020-10-15 00:07:38 +03:00
|
|
|
}
|
|
|
|
|
2020-11-13 02:14:59 +03:00
|
|
|
// VariantPlaylistWritten is fired when a HLS variant playlist is written to disk.
|
2020-10-15 00:07:38 +03:00
|
|
|
func (h *HLSHandler) VariantPlaylistWritten(localFilePath string) {
|
|
|
|
h.Storage.VariantPlaylistWritten(localFilePath)
|
|
|
|
}
|
|
|
|
|
2020-11-13 02:14:59 +03:00
|
|
|
// MasterPlaylistWritten is fired when a HLS master playlist is written to disk.
|
2020-10-15 00:07:38 +03:00
|
|
|
func (h *HLSHandler) MasterPlaylistWritten(localFilePath string) {
|
|
|
|
h.Storage.MasterPlaylistWritten(localFilePath)
|
|
|
|
}
|