mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -04:00
Allow transcoder to run concurently
This commit is contained in:
parent
8805f0f804
commit
68304af99e
@ -3,7 +3,7 @@ package main
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/zoriya/kyoo/transcoder/transcoder"
|
||||
"github.com/zoriya/kyoo/transcoder/src"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
@ -55,7 +55,7 @@ func (h *Handler) GetMaster(c echo.Context) error {
|
||||
}
|
||||
|
||||
type Handler struct {
|
||||
transcoder *transcoder.Transcoder
|
||||
transcoder *src.Transcoder
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -1,4 +1,4 @@
|
||||
package transcoder
|
||||
package src
|
||||
|
||||
import (
|
||||
"math"
|
@ -1,4 +1,4 @@
|
||||
package transcoder
|
||||
package src
|
||||
|
||||
type Quality int8
|
||||
|
@ -1,4 +1,4 @@
|
||||
package transcoder
|
||||
package src
|
||||
|
||||
type TranscodeStream struct {
|
||||
File FileStream
|
43
transcoder/src/transcoder.go
Normal file
43
transcoder/src/transcoder.go
Normal file
@ -0,0 +1,43 @@
|
||||
package src
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Transcoder struct {
|
||||
// All file streams currently running, index is file path
|
||||
streams map[string]FileStream
|
||||
// Streams that are staring up
|
||||
preparing map[string]bool
|
||||
|
||||
mutex sync.RWMutex
|
||||
channel chan *FileStream
|
||||
}
|
||||
|
||||
func (t *Transcoder) GetMaster(path string, client string) (string, error) {
|
||||
t.mutex.RLock()
|
||||
stream, ok := t.streams[path]
|
||||
preparing := t.preparing[path]
|
||||
t.mutex.RUnlock()
|
||||
|
||||
if preparing {
|
||||
stream = *<- t.channel
|
||||
} else if !ok {
|
||||
t.mutex.Lock()
|
||||
t.preparing[path] = true
|
||||
t.mutex.Unlock()
|
||||
|
||||
stream, err := NewFileStream(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
t.mutex.Lock()
|
||||
t.streams[path] = *stream
|
||||
delete(t.preparing, path)
|
||||
t.mutex.Unlock()
|
||||
|
||||
t.channel <- stream
|
||||
}
|
||||
return stream.GetMaster(), nil
|
||||
}
|
BIN
transcoder/transcoder
Executable file
BIN
transcoder/transcoder
Executable file
Binary file not shown.
@ -1,18 +0,0 @@
|
||||
package transcoder
|
||||
|
||||
type Transcoder struct {
|
||||
// All file streams currently running, index is file path
|
||||
streams map[string]FileStream
|
||||
}
|
||||
|
||||
func (t *Transcoder) GetMaster(path string, client string) (string, error) {
|
||||
stream, ok := t.streams[path]
|
||||
if !ok {
|
||||
stream, err := NewFileStream(path)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
t.streams[path] = *stream
|
||||
}
|
||||
return stream.GetMaster(), nil
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user