mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -04:00
Add videostream cache
This commit is contained in:
parent
f04d1dcf1e
commit
892060334c
@ -8,6 +8,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -18,11 +19,12 @@ type FileStream struct {
|
|||||||
CanTransmux bool
|
CanTransmux bool
|
||||||
Info *MediaInfo
|
Info *MediaInfo
|
||||||
streams map[Quality]*VideoStream
|
streams map[Quality]*VideoStream
|
||||||
|
vlock sync.RWMutex
|
||||||
// audios map[uint32]*AudioStream
|
// audios map[uint32]*AudioStream
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetOutPath() string {
|
func GetOutPath() string {
|
||||||
out := os.Getenv("CACHE_ROOT")
|
out := os.Getenv("GOCODER_CACHE_ROOT")
|
||||||
if out == "" {
|
if out == "" {
|
||||||
return "/cache"
|
return "/cache"
|
||||||
}
|
}
|
||||||
@ -185,12 +187,27 @@ func (fs *FileStream) GetMaster() string {
|
|||||||
return master
|
return master
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fs *FileStream) getVideoStream(quality Quality) *VideoStream {
|
||||||
|
fs.vlock.RLock()
|
||||||
|
stream, ok := fs.streams[quality]
|
||||||
|
fs.vlock.RUnlock()
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
return stream
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.vlock.Lock()
|
||||||
|
defer fs.vlock.Unlock()
|
||||||
|
fs.streams[quality] = NewVideoStream(fs, quality)
|
||||||
|
return fs.streams[quality]
|
||||||
|
}
|
||||||
|
|
||||||
func (fs *FileStream) GetVideoIndex(quality Quality, client string) (string, error) {
|
func (fs *FileStream) GetVideoIndex(quality Quality, client string) (string, error) {
|
||||||
stream := fs.streams[quality]
|
stream := fs.getVideoStream(quality)
|
||||||
return stream.GetIndex(client)
|
return stream.GetIndex(client)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FileStream) GetVideoSegment(quality Quality, segment int32, client string) (string, error) {
|
func (fs *FileStream) GetVideoSegment(quality Quality, segment int32, client string) (string, error) {
|
||||||
stream := fs.streams[quality]
|
stream := fs.getVideoStream(quality)
|
||||||
return stream.GetSegment(segment, client)
|
return stream.GetSegment(segment, client)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user