diff --git a/mediadevices.go b/mediadevices.go index 5ea8f2a..16a79e0 100644 --- a/mediadevices.go +++ b/mediadevices.go @@ -60,8 +60,7 @@ func (m *mediaDevices) GetUserMedia(constraints MediaStreamConstraints) (MediaSt // videoSelect implements SelectSettings algorithm for video type. // Reference: https://w3c.github.io/mediacapture-main/#dfn-selectsettings func (m *mediaDevices) videoSelect(constraints VideoTrackConstraints) (Tracker, error) { - videoFilterFn := driver.FilterKind(driver.Video) - drivers := driver.GetManager().Query(videoFilterFn) + drivers := driver.GetManager().VideoDrivers() var bestDriver driver.VideoDriver var bestSetting driver.VideoSetting @@ -111,8 +110,7 @@ func (m *mediaDevices) videoSelect(constraints VideoTrackConstraints) (Tracker, // audioSelect implements SelectSettings algorithm for audio type. // Reference: https://w3c.github.io/mediacapture-main/#dfn-selectsettings func (m *mediaDevices) audioSelect(constraints AudioTrackConstraints) (Tracker, error) { - audioFilterFn := driver.FilterKind(driver.Audio) - drivers := driver.GetManager().Query(audioFilterFn) + drivers := driver.GetManager().AudioDrivers() var bestDriver driver.AudioDriver var bestSetting driver.AudioSetting diff --git a/pkg/driver/camera_linux.go b/pkg/driver/camera_linux.go index 65ef3a4..1710e49 100644 --- a/pkg/driver/camera_linux.go +++ b/pkg/driver/camera_linux.go @@ -15,11 +15,11 @@ import ( // Camera implementation using v4l2 // Reference: https://linuxtv.org/downloads/v4l-dvb-apis/uapi/v4l/videodev.html#videodev type camera struct { - path string - cam *webcam.Webcam - formats map[webcam.PixelFormat]frame.Format + path string + cam *webcam.Webcam + formats map[webcam.PixelFormat]frame.Format reversedFormats map[frame.Format]webcam.PixelFormat - settings []VideoSetting + settings []VideoSetting } var _ VideoAdapter = &camera{} @@ -34,8 +34,8 @@ func init() { func newCamera(path string) *camera { formats := map[webcam.PixelFormat]frame.Format{ - webcam.PixelFormat(C.V4L2_PIX_FMT_YUYV): frame.FormatYUYV, - webcam.PixelFormat(C.V4L2_PIX_FMT_NV12): frame.FormatNV21, + webcam.PixelFormat(C.V4L2_PIX_FMT_YUYV): frame.FormatYUYV, + webcam.PixelFormat(C.V4L2_PIX_FMT_NV12): frame.FormatNV21, webcam.PixelFormat(C.V4L2_PIX_FMT_MJPEG): frame.FormatMJPEG, } @@ -45,8 +45,8 @@ func newCamera(path string) *camera { } return &camera{ - path: path, - formats: formats, + path: path, + formats: formats, reversedFormats: reversedFormats, } } @@ -61,8 +61,8 @@ func (c *camera) Open() error { for format := range cam.GetSupportedFormats() { for _, frameSize := range cam.GetSupportedFrameSizes(format) { settings = append(settings, VideoSetting{ - Width: int(frameSize.MaxWidth), - Height: int(frameSize.MaxHeight), + Width: int(frameSize.MaxWidth), + Height: int(frameSize.MaxHeight), FrameFormat: c.formats[format], }) } @@ -135,7 +135,6 @@ func (c *camera) Stop() error { func (c *camera) Info() Info { return Info{ - Kind: Video, DeviceType: Camera, } } diff --git a/pkg/driver/const.go b/pkg/driver/const.go index 8feee29..ecb5d51 100644 --- a/pkg/driver/const.go +++ b/pkg/driver/const.go @@ -1,12 +1,5 @@ package driver -type Kind string - -const ( - Video Kind = "video" - Audio = "audio" -) - type DeviceType string const ( diff --git a/pkg/driver/driver.go b/pkg/driver/driver.go index a7f0e50..3f24a43 100644 --- a/pkg/driver/driver.go +++ b/pkg/driver/driver.go @@ -1,10 +1,11 @@ package driver import ( + "time" + "github.com/pion/mediadevices/pkg/frame" "github.com/pion/mediadevices/pkg/io/audio" "github.com/pion/mediadevices/pkg/io/video" - "time" ) type OpenCloser interface { @@ -17,7 +18,6 @@ type Infoer interface { } type Info struct { - Kind Kind DeviceType DeviceType } diff --git a/pkg/driver/manager.go b/pkg/driver/manager.go index c7c3eac..ffd8b3a 100644 --- a/pkg/driver/manager.go +++ b/pkg/driver/manager.go @@ -2,14 +2,10 @@ package driver import "fmt" +// FilterFn is being used to decide if a driver should be included in the +// query result. type FilterFn func(Driver) bool -func FilterKind(k Kind) FilterFn { - return func(d Driver) bool { - return d.Info().Kind == k - } -} - // Manager is a singleton to manage multiple drivers and their states type Manager struct { drivers map[string]Driver @@ -46,3 +42,19 @@ func (m *Manager) Query(f FilterFn) []Driver { return results } + +// VideoDrivers gets a list of registered VideoDriver +func (m *Manager) VideoDrivers() []Driver { + return m.Query(func(d Driver) bool { + _, ok := d.(VideoDriver) + return ok + }) +} + +// AudioDrivers gets a list of registered AudioDriver +func (m *Manager) AudioDrivers() []Driver { + return m.Query(func(d Driver) bool { + _, ok := d.(AudioDriver) + return ok + }) +} diff --git a/pkg/driver/microphone_linux.go b/pkg/driver/microphone_linux.go index 0629570..2927074 100644 --- a/pkg/driver/microphone_linux.go +++ b/pkg/driver/microphone_linux.go @@ -100,7 +100,6 @@ func (m *microphone) Stop() error { func (m *microphone) Info() Info { return Info{ - Kind: Audio, DeviceType: Microphone, } } diff --git a/track.go b/track.go index 0b085ca..866be3f 100644 --- a/track.go +++ b/track.go @@ -27,10 +27,10 @@ type track struct { func newTrack(pc *webrtc.PeerConnection, d driver.Driver, codecName string) (*track, error) { var kind webrtc.RTPCodecType - switch d.Info().Kind { - case driver.Video: + switch d.(type) { + case driver.VideoDriver: kind = webrtc.RTPCodecTypeVideo - case driver.Audio: + case driver.AudioDriver: kind = webrtc.RTPCodecTypeAudio }