Add driver priority information

Make system default device selected by default.
This commit is contained in:
Atsushi Watanabe
2020-02-15 13:37:49 +09:00
committed by Lukas Herman
parent f3dce689e4
commit 53d55a30e5
4 changed files with 30 additions and 2 deletions
+2 -1
View File
@@ -181,8 +181,9 @@ func selectBestDriver(filter driver.FilterFn, constraints MediaTrackConstraints)
driverProperties := queryDriverProperties(filter)
for d, props := range driverProperties {
priority := float64(d.Info().Priority)
for _, p := range props {
fitnessDist := constraints.Media.FitnessDistance(p)
fitnessDist := constraints.Media.FitnessDistance(p) - priority
if fitnessDist < minFitnessDist {
minFitnessDist = fitnessDist
bestDriver = d
+13
View File
@@ -14,9 +14,22 @@ type AudioRecorder interface {
AudioRecord(p prop.Media) (r audio.Reader, err error)
}
// Priority represents device selection priority level
type Priority float32
const (
// PriorityHigh is a value for system default devices
PriorityHigh Priority = 0.1
// PriorityNormal is a value for normal devices
PriorityNormal Priority = 0.0
// PriorityLow is a value for unrecommended devices
PriorityLow Priority = -0.1
)
type Info struct {
Label string
DeviceType DeviceType
Priority Priority
}
type Adapter interface {
@@ -27,10 +27,19 @@ func init() {
if err != nil {
panic(err)
}
defaultSource, err := pa.DefaultSource()
if err != nil {
panic(err)
}
for _, source := range sources {
priority := driver.PriorityNormal
if defaultSource.ID() == source.ID() {
priority = driver.PriorityHigh
}
driver.GetManager().Register(&microphone{id: source.ID()}, driver.Info{
Label: source.ID(),
DeviceType: driver.Microphone,
Priority: priority,
})
}
}
+6 -1
View File
@@ -9,7 +9,12 @@ import (
func wrapAdapter(a Adapter, info Info) Driver {
id := uuid.NewV4().String()
d := &adapterWrapper{Adapter: a, id: id, info: info, state: StateClosed}
d := &adapterWrapper{
Adapter: a,
id: id,
info: info,
state: StateClosed,
}
switch v := a.(type) {
case VideoRecorder: