From c98b3b0909193d27b5808a1c6d9b64840cd07a58 Mon Sep 17 00:00:00 2001 From: Lukas Herman Date: Fri, 30 Oct 2020 17:32:40 -0700 Subject: [PATCH] Enhance driver discovery logging --- go.mod | 1 + internal/logging/logging.go | 11 +++++++++++ logging.go | 7 +++++++ mediadevices.go | 29 ++++++++++++----------------- 4 files changed, 31 insertions(+), 17 deletions(-) create mode 100644 internal/logging/logging.go create mode 100644 logging.go diff --git a/go.mod b/go.mod index 822e5194..9f016916 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/blackjack/webcam v0.0.0-20200313125108-10ed912a8539 github.com/jfreymuth/pulse v0.0.0-20201014123913-1e525c426c93 github.com/lherman-cs/opus v0.0.2 + github.com/pion/logging v0.2.2 github.com/pion/webrtc/v2 v2.2.26 github.com/satori/go.uuid v1.2.0 golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 diff --git a/internal/logging/logging.go b/internal/logging/logging.go new file mode 100644 index 00000000..10539ab4 --- /dev/null +++ b/internal/logging/logging.go @@ -0,0 +1,11 @@ +package logging + +import ( + "github.com/pion/logging" +) + +var loggerFactory = logging.NewDefaultLoggerFactory() + +func NewLogger(scope string) logging.LeveledLogger { + return loggerFactory.NewLogger(scope) +} diff --git a/logging.go b/logging.go new file mode 100644 index 00000000..cc95eff9 --- /dev/null +++ b/logging.go @@ -0,0 +1,7 @@ +package mediadevices + +import ( + "github.com/pion/mediadevices/internal/logging" +) + +var logger = logging.NewLogger("mediadevices") diff --git a/mediadevices.go b/mediadevices.go index 8dbb0202..2f681735 100644 --- a/mediadevices.go +++ b/mediadevices.go @@ -120,12 +120,15 @@ func queryDriverProperties(filter driver.FilterFn) map[driver.Driver][]prop.Medi func selectBestDriver(filter driver.FilterFn, constraints MediaTrackConstraints) (driver.Driver, MediaTrackConstraints, error) { var bestDriver driver.Driver var bestProp prop.Media + var foundPropertiesLog []string minFitnessDist := math.Inf(1) + foundPropertiesLog = append(foundPropertiesLog, "\n============ Found Properties ============") driverProperties := queryDriverProperties(filter) for d, props := range driverProperties { priority := float64(d.Info().Priority) for _, p := range props { + foundPropertiesLog = append(foundPropertiesLog, p.String()) fitnessDist, ok := constraints.MediaConstraints.FitnessDistance(p) if !ok { continue @@ -139,26 +142,18 @@ func selectBestDriver(filter driver.FilterFn, constraints MediaTrackConstraints) } } - if bestDriver == nil { - var foundProperties []string - for _, props := range driverProperties { - for _, p := range props { - foundProperties = append(foundProperties, fmt.Sprint(&p)) - } - } - - err := fmt.Errorf(`%w: -============ Found Properties ============ + foundPropertiesLog = append(foundPropertiesLog, "=============== Constraints ==============") + foundPropertiesLog = append(foundPropertiesLog, constraints.String()) + foundPropertiesLog = append(foundPropertiesLog, "================ Best Fit ================") -%s - -=============== Constraints ============== - -%s -`, errNotFound, strings.Join(foundProperties, "\n\n"), &constraints) - return nil, MediaTrackConstraints{}, err + if bestDriver == nil { + foundPropertiesLog = append(foundPropertiesLog, "Not found") + logger.Debug(strings.Join(foundPropertiesLog, "\n\n")) + return nil, MediaTrackConstraints{}, errNotFound } + foundPropertiesLog = append(foundPropertiesLog, bestProp.String()) + logger.Debug(strings.Join(foundPropertiesLog, "\n\n")) constraints.selectedMedia = prop.Media{} constraints.selectedMedia.MergeConstraints(constraints.MediaConstraints) constraints.selectedMedia.Merge(bestProp)