continuous-integration/drone/push Build encountered an error
- src/buffer_state.go replaces the two sync.Maps plus a global RWMutex with one bufferMu guarding a map of *Playlist. Each stream has one shared bufferStream (URL, folder, status, client count, error, cancel hook); downloaders keep a private ThisStream and publish through helpers. Playlist.Clients / ThisClient / ClientConnection are gone: there was one client counter per stream in two places that could disagree. - bufferAcquireStream does the tuner check and the registration under the same lock, so two clients tuning at once cannot both pass the limit. bufferReleaseClient removes the stream when the last client leaves, cancels its process and deletes its segment folder. - bufferingStream rewritten: waits on r.Context() instead of the deprecated CloseNotifier, sets Content-Type before WriteHeader (the old code set headers after and one was literally named "Content-Length:"), flushes each segment to the client, no defer inside the segment loop. - connectToStreamingServer: shared streamHTTPClient with dial, TLS and response-header timeouts (no overall timeout, bodies are endless); the deferred Body/segment closes inside the redirect and read loops are now explicit closes, so a multi-hour stream no longer accumulates them. - thirdPartyBuffer rewritten around exec.CommandContext: the process is killed when the last client leaves or when no usable data arrives within 20 s (time.AfterFunc watchdog, no leaked goroutine); cmd.Start error is checked; no panic; one file handle per segment. ffmpeg and VLC command lines come from buildFFmpegArgs / buildVLCArgs, which are unit tested. - Data.Cache.StreamingURLS is guarded by streamingURLsMu and persisted from a snapshot. - Tests (src/buffer_test.go, run with -race): restream shares one provider connection, six concurrent tunes against a tuner limit of two, 50-way acquire/release contention, cleanup and cancel on last release.
243 lines
6.5 KiB
Go
243 lines
6.5 KiB
Go
package src
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
// System : Beinhaltet alle Systeminformationen
|
|
var System SystemStruct
|
|
|
|
// WebScreenLog : Logs werden im RAM gespeichert und für das Webinterface bereitgestellt
|
|
var WebScreenLog WebScreenLogStruct
|
|
|
|
// Settings : Inhalt der settings.json
|
|
var Settings SettingsStruct
|
|
|
|
// Data : Alle Daten werden hier abgelegt. (Lineup, XMLTV)
|
|
var Data DataStruct
|
|
|
|
// SystemFiles : Alle Systemdateien
|
|
var SystemFiles = []string{"authentication.json", "pms.json", "settings.json", "xepg.json", "urls.json"}
|
|
|
|
// Init : Systeminitialisierung
|
|
func Init() (err error) {
|
|
|
|
var debug string
|
|
|
|
// System Einstellungen
|
|
System.AppName = strings.ToLower(System.Name)
|
|
System.ARCH = runtime.GOARCH
|
|
System.OS = runtime.GOOS
|
|
System.ServerProtocol.API = "http"
|
|
System.ServerProtocol.DVR = "http"
|
|
System.ServerProtocol.M3U = "http"
|
|
System.ServerProtocol.WEB = "http"
|
|
System.ServerProtocol.XML = "http"
|
|
System.PlexChannelLimit = 480
|
|
System.UnfilteredChannelLimit = 480
|
|
System.Compatibility = "1.4.4"
|
|
|
|
// FFmpeg Default Einstellungen
|
|
System.FFmpeg.DefaultOptions = "-hide_banner -loglevel error -i [URL] -c copy -f mpegts pipe:1"
|
|
System.VLC.DefaultOptions = "-I dummy [URL] --sout #std{mux=ts,access=file,dst=-}"
|
|
|
|
// Default Logeinträge, wird später von denen aus der settings.json überschrieben. Muss gemacht werden, damit die ersten Einträge auch im Log (webUI aangezeigt werden)
|
|
Settings.LogEntriesRAM = 500
|
|
|
|
// Ordnerpfade festlegen
|
|
var tempFolder = os.TempDir() + string(os.PathSeparator) + System.AppName + string(os.PathSeparator)
|
|
tempFolder = getPlatformPath(strings.Replace(tempFolder, "//", "/", -1))
|
|
|
|
if len(System.Folder.Config) == 0 {
|
|
System.Folder.Config = GetUserHomeDirectory() + string(os.PathSeparator) + "." + System.AppName + string(os.PathSeparator)
|
|
} else {
|
|
System.Folder.Config = strings.TrimRight(System.Folder.Config, string(os.PathSeparator)) + string(os.PathSeparator)
|
|
}
|
|
|
|
System.Folder.Config = getPlatformPath(System.Folder.Config)
|
|
|
|
System.Folder.Backup = System.Folder.Config + "backup" + string(os.PathSeparator)
|
|
System.Folder.Data = System.Folder.Config + "data" + string(os.PathSeparator)
|
|
System.Folder.Cache = System.Folder.Config + "cache" + string(os.PathSeparator)
|
|
System.Folder.ImagesCache = System.Folder.Cache + "images" + string(os.PathSeparator)
|
|
System.Folder.ImagesUpload = System.Folder.Data + "images" + string(os.PathSeparator)
|
|
System.Folder.Temp = tempFolder
|
|
|
|
// Dev Info
|
|
showDevInfo()
|
|
|
|
// System Ordner erstellen
|
|
err = createSystemFolders()
|
|
if err != nil {
|
|
ShowError(err, 1070)
|
|
return
|
|
}
|
|
|
|
if len(System.Flag.Restore) > 0 {
|
|
// Einstellungen werden über CLI wiederhergestellt. Weitere Initialisierung ist nicht notwendig.
|
|
return
|
|
}
|
|
|
|
System.File.XML = getPlatformFile(fmt.Sprintf("%s%s.xml", System.Folder.Data, System.AppName))
|
|
System.File.M3U = getPlatformFile(fmt.Sprintf("%s%s.m3u", System.Folder.Data, System.AppName))
|
|
|
|
System.Compressed.GZxml = getPlatformFile(fmt.Sprintf("%s%s.xml.gz", System.Folder.Data, System.AppName))
|
|
|
|
err = activatedSystemAuthentication()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = resolveHostIP()
|
|
if err != nil {
|
|
ShowError(err, 1002)
|
|
}
|
|
|
|
// Menü für das Webinterface
|
|
System.WEB.Menu = []string{"playlist", "filter", "xmltv", "mapping", "users", "settings", "log", "logout"}
|
|
|
|
fmt.Println("For help run: " + getPlatformFile(os.Args[0]) + " -h")
|
|
fmt.Println()
|
|
|
|
// Überprüfen ob xTeVe als root läuft
|
|
if os.Geteuid() == 0 {
|
|
showWarning(2110)
|
|
}
|
|
|
|
if System.Flag.Debug > 0 {
|
|
debug = fmt.Sprintf("Debug Level:%d", System.Flag.Debug)
|
|
showDebug(debug, 1)
|
|
}
|
|
|
|
showInfo(fmt.Sprintf("Version:%s Build: %s", System.Version, System.Build))
|
|
showInfo(fmt.Sprintf("Database Version:%s", System.DBVersion))
|
|
showInfo(fmt.Sprintf("System IP Addresses:IPv4: %d | IPv6: %d", len(System.IPAddressesV4), len(System.IPAddressesV6)))
|
|
showInfo("Hostname:" + System.Hostname)
|
|
showInfo(fmt.Sprintf("System Folder:%s", getPlatformPath(System.Folder.Config)))
|
|
|
|
// Systemdateien erstellen (Falls nicht vorhanden)
|
|
err = createSystemFiles()
|
|
if err != nil {
|
|
ShowError(err, 1071)
|
|
return
|
|
}
|
|
|
|
// Bedingte Update Änderungen durchführen
|
|
err = conditionalUpdateChanges()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
// Einstellungen laden (settings.json)
|
|
showInfo(fmt.Sprintf("Load Settings:%s", System.File.Settings))
|
|
|
|
_, err = loadSettings()
|
|
if err != nil {
|
|
ShowError(err, 0)
|
|
return
|
|
}
|
|
|
|
// Berechtigung aller Ordner überprüfen
|
|
err = checkFilePermission(System.Folder.Config)
|
|
if err != nil {
|
|
ShowError(err, 0)
|
|
return
|
|
}
|
|
|
|
// Separaten tmp Ordner für jede Instanz
|
|
//System.Folder.Temp = System.Folder.Temp + Settings.UUID + string(os.PathSeparator)
|
|
showInfo(fmt.Sprintf("Temporary Folder:%s", getPlatformPath(System.Folder.Temp)))
|
|
|
|
err = checkFolder(System.Folder.Temp)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = checkFilePermission(System.Folder.Temp)
|
|
if err != nil {
|
|
ShowError(err, 0)
|
|
return
|
|
}
|
|
|
|
err = removeChildItems(getPlatformPath(System.Folder.Temp))
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
// Branch festlegen
|
|
System.Branch = Settings.Branch
|
|
|
|
if System.Dev {
|
|
System.Branch = "Development"
|
|
}
|
|
|
|
if len(System.Branch) == 0 {
|
|
System.Branch = "master"
|
|
}
|
|
|
|
showInfo(fmt.Sprintf("Branch:%s", System.Branch))
|
|
|
|
// Domainnamen setzten
|
|
setGlobalDomain(fmt.Sprintf("%s:%s", System.IPAddress, Settings.Port))
|
|
|
|
System.URLBase = fmt.Sprintf("%s://%s:%s", System.ServerProtocol.WEB, System.IPAddress, Settings.Port)
|
|
|
|
// Mit dev == true werden die lokalen HTML Dateien verwendet, sonst die eingebetteten
|
|
initWebFS(System.Dev)
|
|
|
|
// DLNA Server starten
|
|
err = SSDP()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// StartSystem : System wird gestartet
|
|
func StartSystem(updateProviderFiles bool) (err error) {
|
|
|
|
setDeviceID()
|
|
|
|
if System.ScanInProgress == 1 {
|
|
return
|
|
}
|
|
|
|
// Systeminformationen in der Konsole ausgeben
|
|
showInfo(fmt.Sprintf("UUID:%s", Settings.UUID))
|
|
showInfo(fmt.Sprintf("Tuner (Plex / Emby):%d", Settings.Tuner))
|
|
showInfo(fmt.Sprintf("EPG Source:%s", Settings.EpgSource))
|
|
showInfo(fmt.Sprintf("Plex Channel Limit:%d", System.PlexChannelLimit))
|
|
showInfo(fmt.Sprintf("Unfiltered Chan. Limit:%d", System.UnfilteredChannelLimit))
|
|
|
|
// Providerdaten aktualisieren
|
|
if len(Settings.Files.M3U) > 0 && Settings.FilesUpdate || updateProviderFiles {
|
|
|
|
err = xTeVeAutoBackup()
|
|
if err != nil {
|
|
ShowError(err, 1090)
|
|
}
|
|
|
|
getProviderData("m3u", "")
|
|
getProviderData("hdhr", "")
|
|
|
|
if Settings.EpgSource == "XEPG" {
|
|
getProviderData("xmltv", "")
|
|
}
|
|
|
|
}
|
|
|
|
err = buildDatabaseDVR()
|
|
if err != nil {
|
|
ShowError(err, 0)
|
|
return
|
|
}
|
|
|
|
buildXEPG(false)
|
|
|
|
return
|
|
}
|