mirror of
https://github.com/pion/mediadevices.git
synced 2026-04-23 00:07:29 +08:00
Implement EnumerateDevices and register all devices
This commit is contained in:
committed by
Lukas Herman
parent
ed1352b6ff
commit
5653cdf9e8
@@ -12,11 +12,24 @@ import (
|
||||
|
||||
type microphone struct {
|
||||
c *pulse.Client
|
||||
id string
|
||||
samplesChan chan<- []float32
|
||||
}
|
||||
|
||||
func init() {
|
||||
driver.GetManager().Register(µphone{})
|
||||
pa, err := pulse.NewClient()
|
||||
if err != nil {
|
||||
// No pulseaudio
|
||||
return
|
||||
}
|
||||
defer pa.Close()
|
||||
sources, err := pa.ListSources()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, source := range sources {
|
||||
driver.GetManager().Register(µphone{id: source.ID()}, source.ID())
|
||||
}
|
||||
}
|
||||
|
||||
func (m *microphone) Open() error {
|
||||
@@ -47,7 +60,17 @@ func (m *microphone) AudioRecord(p prop.Media) (audio.Reader, error) {
|
||||
options = append(options, pulse.RecordStereo)
|
||||
}
|
||||
latency := p.Latency.Seconds()
|
||||
options = append(options, pulse.RecordSampleRate(p.SampleRate), pulse.RecordLatency(latency))
|
||||
|
||||
src, err := m.c.SourceByID(m.id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
options = append(options,
|
||||
pulse.RecordSampleRate(p.SampleRate),
|
||||
pulse.RecordLatency(latency),
|
||||
pulse.RecordSource(src),
|
||||
)
|
||||
|
||||
samplesChan := make(chan []float32, 1)
|
||||
var buff []float32
|
||||
|
||||
Reference in New Issue
Block a user