cert renew
This commit is contained in:
1 parent
3a6fae5bf2
commit
18a99b3715
40 files changed
+122
-8296
No files matched your search
+13
-11
@@ -27,12 +27,12 @@ type ConfigLogging struct {
|
||||
}
|
||||
|
||||
type ConfigRing struct {
|
||||
Device string `arg:"--input-device,env:INPUT_DEVICE" default:"/dev/input/by-path/platform-gpio-keys-user-event"`
|
||||
Key string `arg:"--ring-key" default:"KEY_F1"`
|
||||
JingleName string `arg:"--jingle-name,env:JINGLE_NAME" default:"ding-dong.wav"`
|
||||
JinglePath *string `arg:"--jingle-path,env:JINGLE_PATH"`
|
||||
SonosTarget string `arg:"--sonos-target,env:SONOS_TARGET" default:"-"`
|
||||
SonosVolume int `arg:"--sonos-volume,env:SONOS_VOLUME" default:"50"`
|
||||
Device *string `arg:"--input-device,env:INPUT_DEVICE"`
|
||||
Key string `arg:"--ring-key" default:"KEY_F1"`
|
||||
JingleBaseUri *string `arg:"--jingle-base-uri,env:JINGLE_BASE_URI"`
|
||||
JinglePath string `arg:"--jingle-path,env:JINGLE_PATH" default:"audio/ding-dong.wav"`
|
||||
SonosTarget string `arg:"--sonos-target,env:SONOS_TARGET" default:"-"`
|
||||
SonosVolume int `arg:"--sonos-volume,env:SONOS_VOLUME" default:"50"`
|
||||
}
|
||||
|
||||
type ConfigHTTP struct {
|
||||
@@ -47,11 +47,12 @@ type ConfigHTTP struct {
|
||||
}
|
||||
|
||||
type ConfigVideoOutputStream struct {
|
||||
Source string `arg:"--video-out-src,env:VIDEO_OUT_SRC" default:"v4l2src"`
|
||||
Device string `arg:"--video-out-device,env:VIDEO_OUT_DEVICE" default:"/dev/video0"`
|
||||
Codec string `arg:"--video-out-codec,env:VIDEO_OUT_CODEC" default:"vp8"`
|
||||
Height uint `arg:"--video-out-height,env:VIDEO_OUT_HEIGHT" default:"480"`
|
||||
Width uint `arg:"--video-out-width,env:VIDEO_OUT_WIDTH" default:"640"`
|
||||
Source string `arg:"--video-out-src,env:VIDEO_OUT_SRC" default:"v4l2src"`
|
||||
Device string `arg:"--video-out-device,env:VIDEO_OUT_DEVICE" default:"/dev/video0"`
|
||||
Codec string `arg:"--video-out-codec,env:VIDEO_OUT_CODEC" default:"vp8"`
|
||||
Height uint `arg:"--video-out-height,env:VIDEO_OUT_HEIGHT" default:"480"`
|
||||
Width uint `arg:"--video-out-width,env:VIDEO_OUT_WIDTH" default:"640"`
|
||||
USE_QUEUE bool `arg:"--video-out-queue,env:VIDEO_OUT_QUEUE" default:"false"`
|
||||
}
|
||||
|
||||
type ConfigAudioOutputStream struct {
|
||||
@@ -60,6 +61,7 @@ type ConfigAudioOutputStream struct {
|
||||
Device *string `arg:"--audio-out-device,env:AUDIO_OUT_DEVICE"`
|
||||
Codec string `arg:"--audio-out-codec,env:AUDIO_OUT_CODEC" default:"opus"`
|
||||
Channels uint `arg:"--audio-out-channels,env:AUDIO_OUT_CHANNELS" default:"1"`
|
||||
USE_QUEUE bool `arg:"--audio-out-queue,env:AUDIO_OUT_QUEUE" default:"false"`
|
||||
}
|
||||
|
||||
type ConfigAudioInputStream struct {
|
||||
|
||||
+15
-5
@@ -32,13 +32,23 @@ func NewRingHandler(lg *zap.Logger, cfg *common.ConfigRing) (*RingHandler, error
|
||||
}
|
||||
|
||||
func (h *RingHandler) Watch(ctx context.Context) error {
|
||||
if h.cfg.Device == nil {
|
||||
h.lg.Warn("nothing to watch for key press")
|
||||
return nil
|
||||
}
|
||||
|
||||
if h.cfg.JingleBaseUri == nil {
|
||||
h.lg.Warn("missing jingle base uri, nothing to play")
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, p := range h.playHandlers {
|
||||
if err := p.Watch(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
d, err := evdev.Open(h.cfg.Device)
|
||||
d, err := evdev.Open(*h.cfg.Device)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -48,9 +58,9 @@ func (h *RingHandler) Watch(ctx context.Context) error {
|
||||
|
||||
key := evdev.KEYFromString[h.cfg.Key]
|
||||
|
||||
bu := url.URL{
|
||||
Scheme: "http",
|
||||
Host: "192.168.60.141:9099",
|
||||
bu, err := url.Parse(*h.cfg.JingleBaseUri)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
go func() {
|
||||
@@ -62,7 +72,7 @@ func (h *RingHandler) Watch(ctx context.Context) error {
|
||||
for {
|
||||
e, err := d.ReadOne()
|
||||
if err == nil && e.Code == key && e.Value == 0 {
|
||||
tu := bu.JoinPath(h.cfg.JingleName)
|
||||
tu := bu.JoinPath(h.cfg.JinglePath)
|
||||
for _, p := range h.playHandlers {
|
||||
if err := p.Play(tu); err != nil {
|
||||
h.lg.Error("failed to play", zap.Error(err))
|
||||
|
||||
@@ -43,6 +43,7 @@ type sonosInfo struct {
|
||||
type sonosAudioClip struct {
|
||||
Name string `json:"name"`
|
||||
AppId string `json:"appId"`
|
||||
ClipType string `json:"clipType,omitempty"`
|
||||
StreamUrl string `json:"streamUrl"`
|
||||
Volume int `json:"volume"`
|
||||
}
|
||||
@@ -108,6 +109,7 @@ func (p *SonosPlayer) Play(uri *url.URL, volume int) error {
|
||||
sab := sonosAudioClip{
|
||||
Name: "Pull Bell",
|
||||
AppId: "com.acme.app",
|
||||
ClipType: "CHIME",
|
||||
StreamUrl: uri.String(),
|
||||
Volume: volume,
|
||||
}
|
||||
@@ -181,6 +183,7 @@ func (h *SonosHandler) Watch(ctx context.Context) error {
|
||||
|
||||
func (h *SonosHandler) Play(uri *url.URL) error {
|
||||
for _, p := range h.players {
|
||||
h.lg.Info("playing clip", zap.String("target", p.address.String()), zap.String("clip", uri.String()))
|
||||
if err := p.Play(uri, h.cfg.SonosVolume); err != nil {
|
||||
h.lg.Error("failed to play", zap.String("address", p.address.String()), zap.Error(err))
|
||||
}
|
||||
|
||||
@@ -71,6 +71,15 @@ func CreateVideoPipelineSink(s StreamElement) (*gst.Pipeline, <-chan media.Sampl
|
||||
}
|
||||
elems = append(elems, conv)
|
||||
|
||||
if s.Queue {
|
||||
// add a queue
|
||||
queue, err := gst.NewElement("queue")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
elems = append(elems, queue)
|
||||
}
|
||||
|
||||
// Create the enc
|
||||
enc, err := gst.NewElement("vp8enc")
|
||||
if err != nil {
|
||||
@@ -140,6 +149,15 @@ func CreateAudioPipelineSink(s StreamElement) (*gst.Pipeline, <-chan media.Sampl
|
||||
}
|
||||
elems = append(elems, conv)
|
||||
|
||||
if s.Queue {
|
||||
// add a queue
|
||||
queue, err := gst.NewElement("queue")
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
elems = append(elems, queue)
|
||||
}
|
||||
|
||||
// Create the enc
|
||||
enc, err := gst.NewElement("opusenc")
|
||||
if err != nil {
|
||||
|
||||
@@ -30,6 +30,7 @@ type StreamElement struct {
|
||||
Kind string
|
||||
Properties map[string]interface{}
|
||||
Caps *StreamElementCaps
|
||||
Queue bool
|
||||
}
|
||||
|
||||
func (se StreamElement) ToGstCaps() *gst.Caps {
|
||||
|
||||
+30
-6
@@ -2,6 +2,8 @@ package webrtc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -121,6 +123,7 @@ func (wh *WebrtcHandler) handleAudioSamples(ctx context.Context, cfg *common.Con
|
||||
Channels: cfg.Channels,
|
||||
Rate: 48000,
|
||||
},
|
||||
Queue: cfg.USE_QUEUE,
|
||||
}
|
||||
|
||||
var err error
|
||||
@@ -164,6 +167,7 @@ func (wh *WebrtcHandler) handleVideoSamples(ctx context.Context, cfg *common.Con
|
||||
Width: cfg.Width,
|
||||
Height: cfg.Height,
|
||||
},
|
||||
Queue: cfg.USE_QUEUE,
|
||||
}
|
||||
|
||||
var err error
|
||||
@@ -195,7 +199,7 @@ func (wh *WebrtcHandler) handleVideoSamples(ctx context.Context, cfg *common.Con
|
||||
return nil
|
||||
}
|
||||
|
||||
func (wh *WebrtcHandler) createPeerHandle(ctx context.Context, sh *server.SignalingHandle) error {
|
||||
func (wh *WebrtcHandler) createPeerHandle(rctx context.Context, sh *server.SignalingHandle) error {
|
||||
wh.mu.Lock()
|
||||
defer wh.mu.Unlock()
|
||||
|
||||
@@ -210,6 +214,9 @@ func (wh *WebrtcHandler) createPeerHandle(ctx context.Context, sh *server.Signal
|
||||
return err
|
||||
}
|
||||
|
||||
// create a context for this handle
|
||||
hctx, hcancel := context.WithCancel(rctx)
|
||||
|
||||
// Set a handler for when a new remote track starts, this handler creates a gstreamer pipeline
|
||||
// for the given codec
|
||||
peerConnection.OnTrack(func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
|
||||
@@ -227,9 +234,13 @@ func (wh *WebrtcHandler) createPeerHandle(ctx context.Context, sh *server.Signal
|
||||
select {
|
||||
case <-ticker.C:
|
||||
if err := peerConnection.WriteRTCP([]rtcp.Packet{&rtcp.PictureLossIndication{MediaSSRC: uint32(track.SSRC())}}); err != nil {
|
||||
if errors.Is(err, io.ErrClosedPipe) {
|
||||
return
|
||||
}
|
||||
|
||||
wh.lg.Error("failed to send PLI", zap.Error(err))
|
||||
}
|
||||
case <-ctx.Done():
|
||||
case <-hctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -240,18 +251,24 @@ func (wh *WebrtcHandler) createPeerHandle(ctx context.Context, sh *server.Signal
|
||||
})
|
||||
if err != nil {
|
||||
wh.lg.Error("failed to create src pipeline", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
pipeline.Start()
|
||||
buf := make([]byte, 1400)
|
||||
for {
|
||||
i, _, readErr := track.Read(buf)
|
||||
n, _, readErr := track.Read(buf)
|
||||
if readErr != nil {
|
||||
if errors.Is(readErr, io.EOF) {
|
||||
return
|
||||
}
|
||||
|
||||
wh.lg.Error("read failed", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
|
||||
if i > 0 {
|
||||
pipeline.Push(buf[:i])
|
||||
if n > 0 {
|
||||
err := pipeline.Push(buf[:n])
|
||||
if err != nil {
|
||||
wh.lg.Error("push failed", zap.Error(err))
|
||||
}
|
||||
@@ -266,10 +283,17 @@ func (wh *WebrtcHandler) createPeerHandle(ctx context.Context, sh *server.Signal
|
||||
|
||||
if connectionState == webrtc.ICEConnectionStateDisconnected {
|
||||
peerConnection.Close()
|
||||
hcancel()
|
||||
|
||||
// remove this handle
|
||||
wh.mu.Lock()
|
||||
|
||||
delete(wh.peerHandles, sh.Id)
|
||||
|
||||
if len(wh.peerHandles) == 0 {
|
||||
wh.stopPipelines()
|
||||
}
|
||||
|
||||
wh.mu.Unlock()
|
||||
}
|
||||
})
|
||||
@@ -354,7 +378,7 @@ func (wh *WebrtcHandler) createPeerHandle(ctx context.Context, sh *server.Signal
|
||||
if err != nil {
|
||||
wh.lg.Error("failed to handle offer", zap.Error(err))
|
||||
}
|
||||
case <-ctx.Done():
|
||||
case <-hctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user