This commit is contained in:
marmei
2019-11-04 18:23:20 +01:00
parent 3d9266dabe
commit 3ef95c1950
3 changed files with 21 additions and 4 deletions

View File

@@ -261,7 +261,9 @@ func bufferingStream(playlistID, streamingURL, channelName string, w http.Respon
var oldSegments []string var oldSegments []string
for { // Loop 2: Temporäre Datein sind vorhanden, Daten können zum Client gesendet werden for { // Loop 2: Temporäre Datein sind vorhanden, Daten können zum Client gesendet werden
// HTTP Clientverbindung überwachen // HTTP Clientverbindung überwachen
cn, ok := w.(http.CloseNotifier) cn, ok := w.(http.CloseNotifier)
if ok { if ok {
@@ -449,6 +451,9 @@ func getTmpFiles(stream *ThisStream) (tmpFiles []string) {
func killClientConnection(streamID int, playlistID string, force bool) { func killClientConnection(streamID int, playlistID string, force bool) {
Lock.Lock()
defer Lock.Unlock()
if p, ok := BufferInformation.Load(playlistID); ok { if p, ok := BufferInformation.Load(playlistID); ok {
var playlist = p.(Playlist) var playlist = p.(Playlist)
@@ -493,6 +498,8 @@ func killClientConnection(streamID int, playlistID string, force bool) {
func clientConnection(stream ThisStream) (status bool) { func clientConnection(stream ThisStream) (status bool) {
status = true status = true
Lock.Lock()
defer Lock.Unlock()
if _, ok := BufferClients.Load(stream.PlaylistID + stream.MD5); !ok { if _, ok := BufferClients.Load(stream.PlaylistID + stream.MD5); !ok {
@@ -901,6 +908,8 @@ func connectToStreamingServer(streamID int, playlistID string) {
// Buffer auf die Festplatte speichern // Buffer auf die Festplatte speichern
if fileSize >= tmpFileSize/2 || n == 0 { if fileSize >= tmpFileSize/2 || n == 0 {
Lock.Lock()
bandwidth.Stop = time.Now() bandwidth.Stop = time.Now()
bandwidth.Size += fileSize bandwidth.Size += fileSize
@@ -919,6 +928,7 @@ func connectToStreamingServer(streamID int, playlistID string) {
stream.Status = true stream.Status = true
playlist.Streams[streamID] = stream playlist.Streams[streamID] = stream
BufferInformation.Store(playlistID, playlist) BufferInformation.Store(playlistID, playlist)
Lock.Unlock()
tmpSegment++ tmpSegment++
@@ -1551,9 +1561,11 @@ func thirdPartyBuffer(streamID int, playlistID string) {
tmpSegment++ tmpSegment++
if stream.Status == false { if stream.Status == false {
Lock.Lock()
stream.Status = true stream.Status = true
playlist.Streams[streamID] = stream playlist.Streams[streamID] = stream
BufferInformation.Store(playlistID, playlist) BufferInformation.Store(playlistID, playlist)
Lock.Unlock()
} }
tmpFile = fmt.Sprintf("%s%d.ts", tmpFolder, tmpSegment) tmpFile = fmt.Sprintf("%s%d.ts", tmpFolder, tmpSegment)

View File

@@ -29,6 +29,9 @@ var BufferInformation sync.Map
// BufferClients : Anzahl der Clients die einen Stream über den Buffer abspielen // BufferClients : Anzahl der Clients die einen Stream über den Buffer abspielen
var BufferClients sync.Map var BufferClients sync.Map
// Lock : Lock Map
var Lock = sync.RWMutex{}
// Init : Systeminitialisierung // Init : Systeminitialisierung
func Init() (err error) { func Init() (err error) {

View File

@@ -316,10 +316,12 @@ func WS(w http.ResponseWriter, r *http.Request) {
var newToken string var newToken string
/*
if r.Header.Get("Origin") != "http://"+r.Host { if r.Header.Get("Origin") != "http://"+r.Host {
httpStatusError(w, r, 403) httpStatusError(w, r, 403)
return return
} }
*/
conn, err := websocket.Upgrade(w, r, w.Header(), 1024, 1024) conn, err := websocket.Upgrade(w, r, w.Header(), 1024, 1024)
if err != nil { if err != nil {