hmm idk
This commit is contained in:
parent
d09c96f5d5
commit
825a6ede2b
1 changed files with 58 additions and 0 deletions
|
|
@ -35,6 +35,64 @@ diff --git a/transcoder/handler.go b/transcoder/handler.go
|
|||
chunk := parts[len(parts)-1]
|
||||
|
||||
// Check if POST request to create temp file
|
||||
@@ -133,10 +141,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
// Get existing manager or create new one
|
||||
- manager := h.getManager(path, streamid)
|
||||
- if manager == nil {
|
||||
- manager = h.createManager(path, streamid)
|
||||
- }
|
||||
+ manager := h.getOrCreateManager(path, streamid)
|
||||
|
||||
// Failed to create manager
|
||||
if manager == nil {
|
||||
@@ -166,33 +172,29 @@ func (h *Handler) versionOk(w http.ResponseWriter, r *http.Request) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
-func (h *Handler) getManager(path string, streamid string) *Manager {
|
||||
- h.mutex.RLock()
|
||||
- defer h.mutex.RUnlock()
|
||||
-
|
||||
- m := h.managers[streamid]
|
||||
- if m == nil || m.path != path {
|
||||
- return nil
|
||||
- }
|
||||
- return m
|
||||
-}
|
||||
-
|
||||
-func (h *Handler) createManager(path string, streamid string) *Manager {
|
||||
+func (h *Handler) getOrCreateManager(path string, streamid string) *Manager {
|
||||
+ // Lookup and creation must be atomic. Master, variant, and segment requests
|
||||
+ // commonly arrive together; concurrent creators share a tempDir, and the
|
||||
+ // losing manager's Destroy would delete the winner's active segment files.
|
||||
+ h.mutex.Lock()
|
||||
+ defer h.mutex.Unlock()
|
||||
+
|
||||
+ old := h.managers[streamid]
|
||||
+ if old != nil && old.path == path {
|
||||
+ return old
|
||||
+ }
|
||||
+
|
||||
manager, err := NewManager(h.c, path, streamid, h.close)
|
||||
if err != nil {
|
||||
log.Println("Error creating manager", err)
|
||||
freeIfTemp(path)
|
||||
return nil
|
||||
}
|
||||
|
||||
- h.mutex.Lock()
|
||||
- defer h.mutex.Unlock()
|
||||
-
|
||||
- old := h.managers[streamid]
|
||||
if old != nil {
|
||||
old.Destroy()
|
||||
}
|
||||
|
||||
h.managers[streamid] = manager
|
||||
return manager
|
||||
}
|
||||
diff --git a/transcoder/stream.go b/transcoder/stream.go
|
||||
--- a/transcoder/stream.go
|
||||
+++ b/transcoder/stream.go
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue