mirror of
https://github.com/pion/mediadevices.git
synced 2026-04-22 15:57:27 +08:00
Add driver priority information
Make system default device selected by default.
This commit is contained in:
committed by
Lukas Herman
parent
f3dce689e4
commit
53d55a30e5
+2
-1
@@ -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
|
||||
|
||||
@@ -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(µphone{id: source.ID()}, driver.Info{
|
||||
Label: source.ID(),
|
||||
DeviceType: driver.Microphone,
|
||||
Priority: priority,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user