mirror of https://bitbucket.org/ausocean/av.git
input/gvctrl/gvctrl.go: renamed convRate function to closestValStr to generalise and finished Refresh option function
This commit is contained in:
parent
e56455f7d0
commit
bab1a510b1
|
@ -190,6 +190,7 @@ func Quality(q quality) option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: add check of r
|
||||||
func BitRate(r int) option {
|
func BitRate(r int) option {
|
||||||
return func(s settings) error {
|
return func(s settings) error {
|
||||||
var (
|
var (
|
||||||
|
@ -200,17 +201,17 @@ func BitRate(r int) option {
|
||||||
)
|
)
|
||||||
|
|
||||||
if s.vbr == "1" {
|
if s.vbr == "1" {
|
||||||
s.bitRate = convRate(r, vbrRates)
|
s.bitRate = closestValStr(r, vbrRates)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
switch s.res {
|
switch s.res {
|
||||||
case "12800720":
|
case "12800720":
|
||||||
s.bitRate = convRate(r, cbrRates720)
|
s.bitRate = closestValStr(r, cbrRates720)
|
||||||
case "6400360":
|
case "6400360":
|
||||||
s.bitRate = convRate(r, cbrRates360)
|
s.bitRate = closestValStr(r, cbrRates360)
|
||||||
case "4480256":
|
case "4480256":
|
||||||
s.bitRate = convRate(r, cbrRates256)
|
s.bitRate = closestValStr(r, cbrRates256)
|
||||||
default:
|
default:
|
||||||
panic("bad resolution")
|
panic("bad resolution")
|
||||||
}
|
}
|
||||||
|
@ -218,8 +219,19 @@ func BitRate(r int) option {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Refresh(r int) option {
|
func Refresh(r float64) option {
|
||||||
return func(settings) error {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,6 @@ func closestValIdx(v int, l []int) int {
|
||||||
return idx
|
return idx
|
||||||
}
|
}
|
||||||
|
|
||||||
func convRate(v int, l []int) string {
|
func closestValStr(v int, l []int) string {
|
||||||
return strconv.Itoa(l[closestValIdx(v, l)] * 1000)
|
return strconv.Itoa(l[closestValIdx(v, l)] * 1000)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue