input/gvctrl/gvctrl.go: renamed convRate function to closestValStr to generalise and finished Refresh option function

This commit is contained in:
Saxon 2019-10-12 15:39:27 +10:30
parent e56455f7d0
commit bab1a510b1
2 changed files with 19 additions and 7 deletions

View File

@ -190,6 +190,7 @@ func Quality(q quality) option {
}
}
// TODO: add check of r
func BitRate(r int) option {
return func(s settings) error {
var (
@ -200,17 +201,17 @@ func BitRate(r int) option {
)
if s.vbr == "1" {
s.bitRate = convRate(r, vbrRates)
s.bitRate = closestValStr(r, vbrRates)
return nil
}
switch s.res {
case "12800720":
s.bitRate = convRate(r, cbrRates720)
s.bitRate = closestValStr(r, cbrRates720)
case "6400360":
s.bitRate = convRate(r, cbrRates360)
s.bitRate = closestValStr(r, cbrRates360)
case "4480256":
s.bitRate = convRate(r, cbrRates256)
s.bitRate = closestValStr(r, cbrRates256)
default:
panic("bad resolution")
}
@ -218,8 +219,19 @@ func BitRate(r int) option {
}
}
func Refresh(r int) option {
return func(settings) error {
func Refresh(r float64) option {
return func(s settings) error {
const (
maxRefreshPeriod = 5
minRefreshPeriod = .25
)
if minRefreshPeriod > r || r > maxRefreshPeriod {
return fmt.Errorf("invalid refresh period: %g", r)
}
refOptions := []int{250, 500, 1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500, 5000}
s.refresh = closestValStr(int(r*1000), refOptions)
return nil
}
}

View File

@ -49,6 +49,6 @@ func closestValIdx(v int, l []int) int {
return idx
}
func convRate(v int, l []int) string {
func closestValStr(v int, l []int) string {
return strconv.Itoa(l[closestValIdx(v, l)] * 1000)
}