limit MPV in-memory cache size and make it configurable
This commit is contained in:
+3
-1
@@ -80,7 +80,9 @@ func (a *App) readConfig() {
|
|||||||
|
|
||||||
func (a *App) initMPV() error {
|
func (a *App) initMPV() error {
|
||||||
p := player.NewWithClientName(AppName)
|
p := player.NewWithClientName(AppName)
|
||||||
if err := p.Init(a.Config.LocalPlayback.AudioExclusive); err != nil {
|
c := a.Config.LocalPlayback
|
||||||
|
c.InMemoryCacheSizeMB = clamp(c.InMemoryCacheSizeMB, 10, 500)
|
||||||
|
if err := p.Init(c.AudioExclusive, c.InMemoryCacheSizeMB); err != nil {
|
||||||
return fmt.Errorf("failed to initialize mpv player: %s", err.Error())
|
return fmt.Errorf("failed to initialize mpv player: %s", err.Error())
|
||||||
}
|
}
|
||||||
a.Player = p
|
a.Player = p
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ type PlaylistPageConfig struct {
|
|||||||
|
|
||||||
type LocalPlaybackConfig struct {
|
type LocalPlaybackConfig struct {
|
||||||
AudioExclusive bool
|
AudioExclusive bool
|
||||||
|
InMemoryCacheSizeMB int
|
||||||
Volume int
|
Volume int
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,6 +100,7 @@ func DefaultConfig() *Config {
|
|||||||
},
|
},
|
||||||
LocalPlayback: LocalPlaybackConfig{
|
LocalPlayback: LocalPlaybackConfig{
|
||||||
AudioExclusive: false,
|
AudioExclusive: false,
|
||||||
|
InMemoryCacheSizeMB: 30,
|
||||||
Volume: 100,
|
Volume: 100,
|
||||||
},
|
},
|
||||||
Scrobbling: ScrobbleConfig{
|
Scrobbling: ScrobbleConfig{
|
||||||
|
|||||||
+4
-1
@@ -77,7 +77,7 @@ func NewWithClientName(c string) *Player {
|
|||||||
|
|
||||||
// Initializes the Player and makes it ready for playback.
|
// Initializes the Player and makes it ready for playback.
|
||||||
// Most Player functions will return ErrUnitialized if called before Init.
|
// Most Player functions will return ErrUnitialized if called before Init.
|
||||||
func (p *Player) Init(audioExclusive bool) error {
|
func (p *Player) Init(audioExclusive bool, maxCacheMB int) error {
|
||||||
if !p.initialized {
|
if !p.initialized {
|
||||||
m, err := CreateMPV()
|
m, err := CreateMPV()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -91,6 +91,9 @@ func (p *Player) Init(audioExclusive bool) error {
|
|||||||
m.SetOptionString("force-seekable", "yes")
|
m.SetOptionString("force-seekable", "yes")
|
||||||
m.SetOptionString("terminal", "no")
|
m.SetOptionString("terminal", "no")
|
||||||
|
|
||||||
|
// limit in-memory cache size
|
||||||
|
m.SetOptionString("demuxer-max-bytes", fmt.Sprintf("%dMiB", maxCacheMB))
|
||||||
|
|
||||||
if p.vol < 0 {
|
if p.vol < 0 {
|
||||||
p.vol = 100
|
p.vol = 100
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user