Add support mic mode for wyoming module
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package wyoming
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||
)
|
||||
|
||||
func (s *Server) HandleMic(conn net.Conn) error {
|
||||
defer conn.Close()
|
||||
|
||||
var closed core.Waiter
|
||||
var timestamp int
|
||||
|
||||
api := NewAPI(conn)
|
||||
mic := newMicConsumer(func(chunk []byte) {
|
||||
data := fmt.Sprintf(`{"rate":16000,"width":2,"channels":1,"timestamp":%d}`, timestamp)
|
||||
evt := &Event{Type: "audio-chunk", Data: []byte(data), Payload: chunk}
|
||||
if err := api.WriteEvent(evt); err != nil {
|
||||
closed.Done(nil)
|
||||
}
|
||||
|
||||
timestamp += len(chunk) / 2
|
||||
})
|
||||
mic.RemoteAddr = api.conn.RemoteAddr().String()
|
||||
|
||||
if err := s.MicHandler(mic); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer mic.Stop()
|
||||
|
||||
return closed.Wait()
|
||||
}
|
||||
@@ -142,9 +142,6 @@ func (s *satellite) pause() {
|
||||
|
||||
s.state = stateUnavailable
|
||||
if s.mic != nil {
|
||||
if s.mic.onClose != nil {
|
||||
s.mic.onClose()
|
||||
}
|
||||
_ = s.mic.Stop()
|
||||
s.mic = nil
|
||||
}
|
||||
@@ -296,6 +293,13 @@ func (c *micConsumer) AddTrack(media *core.Media, codec *core.Codec, track *core
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *micConsumer) Stop() error {
|
||||
if c.onClose != nil {
|
||||
c.onClose()
|
||||
}
|
||||
return c.Connection.Stop()
|
||||
}
|
||||
|
||||
type sndProducer struct {
|
||||
core.Connection
|
||||
data []byte
|
||||
|
||||
Reference in New Issue
Block a user