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() {
|
|
|
|
if config.EnableRecordingFeatures {
|
|
|
|
h.Recorder.StreamEnded()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *HLSHandler) SetStreamId(streamId string) {
|
|
|
|
h.Storage.SetStreamId(streamId)
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|