mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-11-17 04:02:21 -05:00
streamer movement
This commit is contained in:
@@ -100,18 +100,9 @@ func (c *WSClient) applyMixerGain(control string, gain float64) {
|
||||
}
|
||||
|
||||
func (c *WSClient) trySetMixerControl(control, value string) error {
|
||||
// Prefer the active ALSA default route; fall back to card index for compatibility.
|
||||
candidates := [][]string{
|
||||
{"-q", "-D", "default", "sset", control, value},
|
||||
{"-q", "-c", "0", "sset", control, value},
|
||||
out, err := exec.Command("amixer", "-q", "-c", c.cfg.Audio.MixerCard, "sset", control, value).CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w (%s)", err, string(out))
|
||||
}
|
||||
var lastErr error
|
||||
for _, args := range candidates {
|
||||
out, err := exec.Command("amixer", args...).CombinedOutput()
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
lastErr = fmt.Errorf("%w (%s)", err, string(out))
|
||||
}
|
||||
return lastErr
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package roverd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const audioConfigPath = "/var/lib/roverd/asound.conf"
|
||||
|
||||
func validateAudioRouting(cfg AudioConfig) error {
|
||||
for name, value := range map[string]string{"inputDevice": cfg.InputDevice, "outputDevice": cfg.OutputDevice, "mixerCard": cfg.MixerCard} {
|
||||
if value == "" || strings.ContainsAny(value, "\x00\r\n") {
|
||||
return fmt.Errorf("audio.%s must be a nonempty single-line ALSA identifier", name)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Generate a private ALSA configuration inherited by all roverd children. Do
|
||||
// not overwrite the host's /etc/asound.conf or impose the AIY card on other hosts.
|
||||
func AudioConfiguration(cfg AudioConfig) string {
|
||||
text := "</usr/share/alsa/alsa.conf>\n"
|
||||
text += fmt.Sprintf(`pcm.rover_capture { type plug slave.pcm %s }
|
||||
pcm.rover_mix {
|
||||
type dmix
|
||||
ipc_key 70601
|
||||
ipc_key_add_uid true
|
||||
slave { pcm %s format S16_LE rate %d channels %d }
|
||||
}
|
||||
`, strconv.Quote(cfg.InputDevice), strconv.Quote(cfg.OutputDevice), cfg.OutputSampleRate, cfg.OutputChannels)
|
||||
for _, pair := range [][2]string{{"tts", "TTSMaster"}, {"horn", "HornMaster"}, {"forward", "ForwardMaster"}} {
|
||||
text += fmt.Sprintf(`pcm.rover_%s_volume {
|
||||
type softvol
|
||||
slave.pcm "rover_mix"
|
||||
control { name %s card %s }
|
||||
min_dB -60.0
|
||||
max_dB 12.0
|
||||
}
|
||||
pcm.rover_%s { type plug slave.pcm "rover_%s_volume" }
|
||||
`, pair[0], strconv.Quote(pair[1]), strconv.Quote(cfg.MixerCard), pair[0], pair[0])
|
||||
}
|
||||
text += fmt.Sprintf(`pcm.!default { type asym playback.pcm "rover_tts" capture.pcm "rover_capture" }
|
||||
ctl.!default { type hw card %s }
|
||||
`, strconv.Quote(cfg.MixerCard))
|
||||
return text
|
||||
}
|
||||
|
||||
func ConfigureAudio(cfg AudioConfig) error {
|
||||
text := AudioConfiguration(cfg)
|
||||
if err := os.MkdirAll(filepath.Dir(audioConfigPath), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.WriteFile(audioConfigPath, []byte(text), 0600); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Setenv("ALSA_CONFIG_PATH", audioConfigPath)
|
||||
}
|
||||
@@ -17,11 +17,24 @@ import (
|
||||
|
||||
func main() {
|
||||
var cfgPath string
|
||||
var repoPath string
|
||||
flag.StringVar(&repoPath, "repo", "/opt/roverd", "managed repository checkout")
|
||||
flag.StringVar(&cfgPath, "config", "/etc/roverd.json", "path to roverd JSON configuration")
|
||||
printDefaults := flag.Bool("print-default-config", false, "print a complete initial JSON configuration and exit")
|
||||
printProfiles := flag.Bool("print-media-profiles", false, "read and print media profiles without running commands")
|
||||
printAudio := flag.Bool("print-audio-config", false, "print generated ALSA configuration without installing it")
|
||||
printSchema := flag.Bool("print-config-schema", false, "print the configuration JSON Schema and exit")
|
||||
checkConfig := flag.Bool("check-config", false, "validate configuration without opening hardware or connecting")
|
||||
flag.Parse()
|
||||
if *printProfiles {
|
||||
profiles, err := roverd.LoadMediaProfiles(repoPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
data, _ := json.MarshalIndent(profiles, "", " ")
|
||||
fmt.Println(string(data))
|
||||
return
|
||||
}
|
||||
if *printDefaults {
|
||||
data, _ := json.MarshalIndent(roverd.DefaultConfig(), "", " ")
|
||||
fmt.Println(string(data))
|
||||
@@ -35,11 +48,15 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatalf("load config: %v", err)
|
||||
}
|
||||
if *printAudio {
|
||||
fmt.Print(roverd.AudioConfiguration(cfg.Audio))
|
||||
return
|
||||
}
|
||||
if *checkConfig {
|
||||
fmt.Println("Configuration valid")
|
||||
return
|
||||
}
|
||||
if run(cfg, cfgPath) {
|
||||
if run(cfg, cfgPath, repoPath) {
|
||||
executable, err := os.Executable()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -50,7 +67,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func run(cfg *roverd.Config, cfgPath string) bool {
|
||||
func run(cfg *roverd.Config, cfgPath, repoPath string) bool {
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
||||
defer cancel()
|
||||
logger := log.New(os.Stdout, "roverd: ", log.LstdFlags|log.Lmicroseconds|log.LUTC)
|
||||
@@ -59,14 +76,20 @@ func run(cfg *roverd.Config, cfgPath string) bool {
|
||||
console.SetEvents(events)
|
||||
var restarting atomic.Bool
|
||||
management := roverd.NewManagementClient(cfg, cfgPath, events, logger, func() { restarting.Store(true); cancel() })
|
||||
if err := roverd.ConfigureAudio(cfg.Audio); err != nil {
|
||||
console.Notify(fmt.Sprintf("Audio routing unavailable: %v", err))
|
||||
}
|
||||
media, err := roverd.NewMediaSupervisor(cfg, repoPath, events, logger)
|
||||
if err != nil {
|
||||
console.Notify(fmt.Sprintf("Media profiles unavailable: %v", err))
|
||||
}
|
||||
management.SetMedia(media)
|
||||
management.SetRepository(repoPath)
|
||||
managementDone := make(chan struct{})
|
||||
go func() { defer close(managementDone); management.Run(ctx) }()
|
||||
// Hardware failures leave management connected until a corrected config
|
||||
// requests restart. runHardware unwinds its own resources on failure.
|
||||
media := roverd.NewMediaSupervisor(cfg.Media, logger)
|
||||
management.SetMedia(media)
|
||||
if media != nil {
|
||||
media.Start(ctx)
|
||||
defer media.Stop()
|
||||
}
|
||||
if err := runHardware(ctx, cfg, events, management, media, logger, console); err != nil {
|
||||
console.Notify(fmt.Sprintf("Hardware unavailable: %v. Management remains connected.", err))
|
||||
|
||||
+41
-66
@@ -55,13 +55,15 @@ type BatteryConfig struct {
|
||||
}
|
||||
|
||||
type AudioConfig struct {
|
||||
// AudioConfig is only for sounds generated by roverd itself. Live capture
|
||||
// and playback are media-publisher concerns, so those settings live under
|
||||
// MediaConfig where they can be written directly into media.env.
|
||||
TTSEnabled bool `json:"ttsEnabled"`
|
||||
DefaultEngine string `json:"defaultEngine"`
|
||||
DefaultVoice string `json:"defaultVoice"`
|
||||
DefaultPitch int `json:"defaultPitch"`
|
||||
InputDevice string `json:"inputDevice" jsonschema:"minLength=1"`
|
||||
OutputDevice string `json:"outputDevice" jsonschema:"minLength=1"`
|
||||
MixerCard string `json:"mixerCard" jsonschema:"minLength=1"`
|
||||
OutputSampleRate int `json:"outputSampleRate" jsonschema:"minimum=8000,maximum=192000"`
|
||||
OutputChannels int `json:"outputChannels" jsonschema:"minimum=1,maximum=8"`
|
||||
TTSEnabled bool `json:"ttsEnabled"`
|
||||
DefaultEngine string `json:"defaultEngine"`
|
||||
DefaultVoice string `json:"defaultVoice"`
|
||||
DefaultPitch int `json:"defaultPitch"`
|
||||
}
|
||||
|
||||
type HornConfig struct {
|
||||
@@ -69,7 +71,6 @@ type HornConfig struct {
|
||||
Volume float64 `json:"volume"`
|
||||
SampleRate int `json:"sampleRate"`
|
||||
Channels int `json:"channels"`
|
||||
Device string `json:"device"`
|
||||
SineGain float64 `json:"sineGain"`
|
||||
SawGain float64 `json:"sawGain"`
|
||||
MaxDuration Duration `json:"maxDuration"`
|
||||
@@ -79,22 +80,15 @@ type MediaConfig struct {
|
||||
// RTSPPort is shared by the derived video, microphone, and forwarded-audio
|
||||
// RTSP URLs. Keeping it at this level prevents each nested block from needing
|
||||
// to repeat the same server port when the common MediaMTX listener is used.
|
||||
RTSPPort int `json:"rtspPort" jsonschema:"minimum=1,maximum=65535"`
|
||||
Manage bool `json:"manage"`
|
||||
HealthURL string `json:"healthUrl"`
|
||||
HealthInterval Duration `json:"healthInterval"`
|
||||
Video VideoMediaConfig `json:"video"`
|
||||
AudioCapture AudioCaptureConfig `json:"audioCapture"`
|
||||
AudioPlayback AudioPlaybackConfig `json:"audioPlayback"`
|
||||
RTSPPort int `json:"rtspPort" jsonschema:"minimum=1,maximum=65535"`
|
||||
Video VideoMediaConfig `json:"video"`
|
||||
AudioCapture AudioCaptureConfig `json:"audioCapture"`
|
||||
AudioPlayback AudioPlaybackConfig `json:"audioPlayback"`
|
||||
}
|
||||
|
||||
type VideoMediaConfig struct {
|
||||
// Publisher selects the installed publisher script/pipeline family. The
|
||||
// first pass uses pi-libcamera for current rovers; laptop-v4l2 can be added
|
||||
// without changing the server-facing media shape again.
|
||||
Enabled bool `json:"enabled"`
|
||||
Service string `json:"service"`
|
||||
Publisher string `json:"publisher"`
|
||||
Profile string `json:"profile" jsonschema:"minLength=1"`
|
||||
Enabled bool `json:"enabled"`
|
||||
// PublishURL is derived during validation. It remains in rover metadata for server-side
|
||||
// consumers through MediaMetadata, but is never persisted in configuration.
|
||||
PublishURL string `json:"-"`
|
||||
@@ -109,29 +103,29 @@ type VideoMediaConfig struct {
|
||||
}
|
||||
|
||||
type AudioCaptureConfig struct {
|
||||
Profile string `json:"profile" jsonschema:"minLength=1"`
|
||||
// AudioCapture describes the rover microphone stream that browsers can
|
||||
// subscribe to as "<rover>-audio". A disabled capture block still has
|
||||
// normalized defaults so enabling it only requires flipping enabled: true.
|
||||
Enabled bool `json:"enabled"`
|
||||
Service string `json:"service"`
|
||||
Enabled bool `json:"enabled"`
|
||||
// PublishURL follows the same derived-only contract as the video path.
|
||||
PublishURL string `json:"-"`
|
||||
Device string `json:"device"`
|
||||
SampleRate int `json:"sampleRate"`
|
||||
Channels int `json:"channels"`
|
||||
Bitrate int `json:"bitrate"`
|
||||
|
||||
SampleRate int `json:"sampleRate"`
|
||||
Channels int `json:"channels"`
|
||||
Bitrate int `json:"bitrate"`
|
||||
}
|
||||
|
||||
type AudioPlaybackConfig struct {
|
||||
Profile string `json:"profile" jsonschema:"minLength=1"`
|
||||
// AudioPlayback describes the reverse stream that VIP users publish into
|
||||
// MediaMTX for playback on the rover speaker. The URL is a request/read URL
|
||||
// for the rover listener, while the server converts it to publish mode when
|
||||
// it needs to inject audio.
|
||||
Enabled bool `json:"enabled"`
|
||||
Service string `json:"service"`
|
||||
Enabled bool `json:"enabled"`
|
||||
// ForwardURL is derived because the server and rover must agree on the exact -fwd path.
|
||||
ForwardURL string `json:"-"`
|
||||
Device string `json:"device"`
|
||||
ForwardURL string `json:"-"`
|
||||
|
||||
Normalize bool `json:"normalize"`
|
||||
NormalizeFilter string `json:"normalizeFilter"`
|
||||
}
|
||||
@@ -267,12 +261,13 @@ func DefaultConfig() Config {
|
||||
},
|
||||
MaxWheelMMs: 500,
|
||||
Media: MediaConfig{
|
||||
RTSPPort: 8554,
|
||||
HealthInterval: Duration{Duration: 30 * time.Second},
|
||||
RTSPPort: 8554,
|
||||
|
||||
Video: VideoMediaConfig{
|
||||
Enabled: true,
|
||||
Service: "video-publisher.service",
|
||||
Publisher: "pi-libcamera",
|
||||
Profile: "v4l2",
|
||||
Enabled: false,
|
||||
Device: "/dev/video0", InputFormat: "mjpeg",
|
||||
|
||||
Width: 640,
|
||||
Height: 480,
|
||||
FPS: 30,
|
||||
@@ -281,22 +276,23 @@ func DefaultConfig() Config {
|
||||
SensorMode: "1296:972",
|
||||
},
|
||||
AudioCapture: AudioCaptureConfig{
|
||||
Enabled: false,
|
||||
Service: "audio-only-publisher.service",
|
||||
Device: "hw:0,0",
|
||||
Profile: "alsa",
|
||||
Enabled: false,
|
||||
|
||||
SampleRate: 48000,
|
||||
Channels: 2,
|
||||
Bitrate: 510000,
|
||||
},
|
||||
AudioPlayback: AudioPlaybackConfig{
|
||||
Enabled: true,
|
||||
Service: "audio-forward-listener.service",
|
||||
Device: "forward",
|
||||
Profile: "alsa",
|
||||
Enabled: false,
|
||||
|
||||
Normalize: true,
|
||||
NormalizeFilter: "dynaudnorm=f=75:g=15:m=10:p=0.9,alimiter=limit=0.85:level=disabled",
|
||||
},
|
||||
},
|
||||
Audio: AudioConfig{
|
||||
InputDevice: "hw:0,0", OutputDevice: "hw:0,0", MixerCard: "0", OutputSampleRate: 48000, OutputChannels: 2,
|
||||
TTSEnabled: false,
|
||||
DefaultEngine: "flite",
|
||||
DefaultVoice: "rms",
|
||||
@@ -410,6 +406,9 @@ func validateConfig(cfg *Config) error {
|
||||
return errors.New("piGpio.brc: nonnegative pin and positive pulse durations required")
|
||||
}
|
||||
}
|
||||
if err := validateAudioRouting(cfg.Audio); err != nil {
|
||||
return err
|
||||
}
|
||||
validateAudioConfig(&cfg.Audio)
|
||||
validateHornConfig(&cfg.Horn)
|
||||
validateAutoSideBrushConfig(&cfg.AutoSideBrush)
|
||||
@@ -481,9 +480,6 @@ func validateMediaConfig(cfg *MediaConfig, serverURL string, roverName string) e
|
||||
if cfg.RTSPPort <= 0 {
|
||||
cfg.RTSPPort = 8554
|
||||
}
|
||||
if cfg.HealthInterval.Duration <= 0 {
|
||||
cfg.HealthInterval = Duration{Duration: 30 * time.Second}
|
||||
}
|
||||
if err := validateVideoMediaConfig(&cfg.Video, serverURL, roverName, cfg.RTSPPort); err != nil {
|
||||
return fmt.Errorf("video: %w", err)
|
||||
}
|
||||
@@ -497,12 +493,6 @@ func validateMediaConfig(cfg *MediaConfig, serverURL string, roverName string) e
|
||||
}
|
||||
|
||||
func validateVideoMediaConfig(cfg *VideoMediaConfig, serverURL string, roverName string, rtspPort int) error {
|
||||
if cfg.Service == "" {
|
||||
cfg.Service = "video-publisher.service"
|
||||
}
|
||||
if cfg.Publisher == "" {
|
||||
cfg.Publisher = "pi-libcamera"
|
||||
}
|
||||
// V4L2 input formats are consumed by ffmpeg as lowercase names such as
|
||||
// mjpeg or yuyv422. Normalizing here keeps the publisher script simple and
|
||||
// makes hand-edited Debian laptop configs less sensitive to capitalization.
|
||||
@@ -519,9 +509,6 @@ func validateVideoMediaConfig(cfg *VideoMediaConfig, serverURL string, roverName
|
||||
if cfg.Bitrate <= 0 {
|
||||
cfg.Bitrate = 2000000
|
||||
}
|
||||
if cfg.SensorMode == "" && cfg.Publisher == "pi-libcamera" {
|
||||
cfg.SensorMode = "1296:972"
|
||||
}
|
||||
/*
|
||||
Always derive this endpoint. Older rover configs can contain an explicit SRT publishUrl;
|
||||
honoring it after a binary update would silently leave that rover on the old transport.
|
||||
@@ -535,12 +522,6 @@ func validateVideoMediaConfig(cfg *VideoMediaConfig, serverURL string, roverName
|
||||
}
|
||||
|
||||
func validateAudioCaptureConfig(cfg *AudioCaptureConfig, serverURL string, roverName string, rtspPort int) error {
|
||||
if cfg.Service == "" {
|
||||
cfg.Service = "audio-only-publisher.service"
|
||||
}
|
||||
if cfg.Device == "" {
|
||||
cfg.Device = "hw:0,0"
|
||||
}
|
||||
if cfg.SampleRate <= 0 {
|
||||
cfg.SampleRate = 48000
|
||||
}
|
||||
@@ -559,12 +540,6 @@ func validateAudioCaptureConfig(cfg *AudioCaptureConfig, serverURL string, rover
|
||||
}
|
||||
|
||||
func validateAudioPlaybackConfig(cfg *AudioPlaybackConfig, serverURL string, roverName string, rtspPort int) error {
|
||||
if cfg.Service == "" {
|
||||
cfg.Service = "audio-forward-listener.service"
|
||||
}
|
||||
if cfg.Device == "" {
|
||||
cfg.Device = "forward"
|
||||
}
|
||||
if cfg.NormalizeFilter == "" {
|
||||
cfg.NormalizeFilter = "dynaudnorm=f=75:g=15:m=10:p=0.9,alimiter=limit=0.85:level=disabled"
|
||||
}
|
||||
|
||||
@@ -124,10 +124,7 @@ func (h *HornSynth) run(waveform string, freqs []float64, stop <-chan struct{})
|
||||
h.mu.Unlock()
|
||||
volume *= gain
|
||||
|
||||
device := strings.TrimSpace(h.cfg.Device)
|
||||
if device == "" {
|
||||
device = "horn"
|
||||
}
|
||||
device := "rover_horn"
|
||||
args := []string{"-q", "-D", device, "-f", "S16_LE", "-c", fmt.Sprintf("%d", channels), "-r", fmt.Sprintf("%d", rate), "-t", "raw"}
|
||||
cmd := exec.Command("aplay", args...)
|
||||
stdin, err := cmd.StdinPipe()
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
type ManagementClient struct {
|
||||
cfg *Config
|
||||
repo string
|
||||
configPath string
|
||||
events chan RoverEvent
|
||||
log *log.Logger
|
||||
@@ -26,11 +27,13 @@ type ManagementClient struct {
|
||||
}
|
||||
|
||||
type managementCommand struct {
|
||||
Type string `json:"type"`
|
||||
ID string `json:"id"`
|
||||
Config json.RawMessage `json:"config"`
|
||||
Reboot *rebootPayload `json:"reboot"`
|
||||
Media *mediaCommand `json:"media"`
|
||||
Type string `json:"type"`
|
||||
ID string `json:"id"`
|
||||
Config json.RawMessage `json:"config"`
|
||||
Reboot *rebootPayload `json:"reboot"`
|
||||
Category string `json:"category"`
|
||||
Profile *MediaProfile `json:"profile"`
|
||||
Media *mediaCommand `json:"media"`
|
||||
}
|
||||
|
||||
func NewManagementClient(cfg *Config, path string, events chan RoverEvent, logger *log.Logger, restart func()) *ManagementClient {
|
||||
@@ -78,7 +81,7 @@ func (m *ManagementClient) connect(parent context.Context) error {
|
||||
conn.SetReadLimit(1024 * 1024)
|
||||
if err := writeJSON(ctx, conn, map[string]any{
|
||||
"type": "hello", "name": m.cfg.Name, "config": m.cfg,
|
||||
"schema": ConfigurationSchema(), "profiles": map[string]any{"video": []any{}, "audioCapture": []any{}, "audioPlayback": []any{}},
|
||||
"schema": ConfigurationSchema(), "profiles": m.profileCatalog(), "mediaStatus": m.mediaStatus(),
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -144,6 +147,19 @@ func (m *ManagementClient) execute(ctx context.Context, command managementComman
|
||||
if m.stopping {
|
||||
return nil, fmt.Errorf("management action already pending")
|
||||
}
|
||||
if command.Type == "profile.set" {
|
||||
if command.Profile == nil {
|
||||
return nil, fmt.Errorf("profile required")
|
||||
}
|
||||
if err := SaveCustomProfile(command.Category, *command.Profile); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m.stopping = true
|
||||
if m.runtime != nil {
|
||||
_ = m.runtime.PrepareShutdown()
|
||||
}
|
||||
return m.restart, nil
|
||||
}
|
||||
if command.Type == "media" {
|
||||
if m.media == nil || command.Media == nil {
|
||||
return nil, fmt.Errorf("media supervisor unavailable")
|
||||
@@ -271,3 +287,20 @@ func (m *ManagementClient) emit(event string, data map[string]any) {
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
func (m *ManagementClient) SetRepository(repo string) { m.repo = repo }
|
||||
func (m *ManagementClient) profileCatalog() map[string][]MediaProfile {
|
||||
profiles, err := LoadMediaProfiles(m.repo)
|
||||
if err != nil {
|
||||
m.log.Printf("profile catalog: %v", err)
|
||||
return map[string][]MediaProfile{}
|
||||
}
|
||||
return profiles
|
||||
}
|
||||
|
||||
func (m *ManagementClient) mediaStatus() map[string]string {
|
||||
if m.media == nil {
|
||||
return nil
|
||||
}
|
||||
return m.media.Status()
|
||||
}
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
package roverd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
const publisherEnvPath = "/var/lib/roverd/media.env"
|
||||
|
||||
func UpdatePublisherEnv(media MediaConfig) error {
|
||||
if media.Video.Enabled && media.Video.PublishURL == "" {
|
||||
return fmt.Errorf("media video publishUrl missing")
|
||||
}
|
||||
if media.AudioCapture.Enabled && media.AudioCapture.PublishURL == "" {
|
||||
return fmt.Errorf("media audioCapture publishUrl missing")
|
||||
}
|
||||
if media.AudioPlayback.Enabled && media.AudioPlayback.ForwardURL == "" {
|
||||
return fmt.Errorf("media audioPlayback forwardUrl missing")
|
||||
}
|
||||
if media.Video.Width <= 0 || media.Video.Height <= 0 || media.Video.FPS <= 0 || media.Video.Bitrate <= 0 {
|
||||
return fmt.Errorf("invalid media video dimensions/bitrate")
|
||||
}
|
||||
if err := os.MkdirAll(filepath.Dir(publisherEnvPath), 0o755); err != nil {
|
||||
return err
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
/*
|
||||
The env file is intentionally verbose: every publisher receives concrete
|
||||
values instead of silently falling back to script-local defaults. That
|
||||
makes roverd.json the owner of media behavior while keeping the shell
|
||||
scripts as small pipeline launchers.
|
||||
*/
|
||||
fmt.Fprintf(&buf, "ROVERD_VIDEO_ENABLE=%d\n", boolToInt(media.Video.Enabled))
|
||||
fmt.Fprintf(&buf, "ROVERD_VIDEO_PUBLISHER=%s\n", media.Video.Publisher)
|
||||
fmt.Fprintf(&buf, "ROVERD_VIDEO_PUBLISH_URL=%s\n", media.Video.PublishURL)
|
||||
fmt.Fprintf(&buf, "ROVERD_VIDEO_DEVICE=%s\n", media.Video.Device)
|
||||
fmt.Fprintf(&buf, "ROVERD_VIDEO_INPUT_FORMAT=%s\n", media.Video.InputFormat)
|
||||
fmt.Fprintf(&buf, "ROVERD_VIDEO_WIDTH=%d\n", media.Video.Width)
|
||||
fmt.Fprintf(&buf, "ROVERD_VIDEO_HEIGHT=%d\n", media.Video.Height)
|
||||
fmt.Fprintf(&buf, "ROVERD_VIDEO_FPS=%d\n", media.Video.FPS)
|
||||
fmt.Fprintf(&buf, "ROVERD_VIDEO_BITRATE=%d\n", media.Video.Bitrate)
|
||||
fmt.Fprintf(&buf, "ROVERD_VIDEO_INVERT=%d\n", boolToInt(media.Video.Inverted))
|
||||
fmt.Fprintf(&buf, "ROVERD_VIDEO_SENSOR_MODE=%s\n", media.Video.SensorMode)
|
||||
fmt.Fprintf(&buf, "ROVERD_AUDIO_CAPTURE_ENABLE=%d\n", boolToInt(media.AudioCapture.Enabled))
|
||||
fmt.Fprintf(&buf, "ROVERD_AUDIO_CAPTURE_PUBLISH_URL=%s\n", media.AudioCapture.PublishURL)
|
||||
fmt.Fprintf(&buf, "ROVERD_AUDIO_CAPTURE_DEVICE=%s\n", media.AudioCapture.Device)
|
||||
fmt.Fprintf(&buf, "ROVERD_AUDIO_CAPTURE_SAMPLE_RATE=%d\n", media.AudioCapture.SampleRate)
|
||||
fmt.Fprintf(&buf, "ROVERD_AUDIO_CAPTURE_CHANNELS=%d\n", media.AudioCapture.Channels)
|
||||
fmt.Fprintf(&buf, "ROVERD_AUDIO_CAPTURE_BITRATE=%d\n", media.AudioCapture.Bitrate)
|
||||
fmt.Fprintf(&buf, "ROVERD_AUDIO_PLAYBACK_ENABLE=%d\n", boolToInt(media.AudioPlayback.Enabled))
|
||||
fmt.Fprintf(&buf, "ROVERD_AUDIO_PLAYBACK_FORWARD_URL=%s\n", media.AudioPlayback.ForwardURL)
|
||||
fmt.Fprintf(&buf, "ROVERD_AUDIO_PLAYBACK_DEVICE=%s\n", media.AudioPlayback.Device)
|
||||
fmt.Fprintf(&buf, "ROVERD_AUDIO_PLAYBACK_NORMALIZE=%d\n", boolToInt(media.AudioPlayback.Normalize))
|
||||
fmt.Fprintf(&buf, "ROVERD_AUDIO_PLAYBACK_NORMALIZE_FILTER=%s\n", media.AudioPlayback.NormalizeFilter)
|
||||
if err := os.WriteFile(publisherEnvPath, buf.Bytes(), 0o640); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func boolToInt(v bool) int {
|
||||
if v {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package roverd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"gopkg.in/yaml.v3"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var mediaCategories = []string{"video", "audioCapture", "audioPlayback"}
|
||||
var profileID = regexp.MustCompile(`^[a-z0-9][a-z0-9_-]*$`)
|
||||
|
||||
type MediaProfile struct {
|
||||
ID string `yaml:"id" json:"id"`
|
||||
Name string `yaml:"name" json:"name"`
|
||||
Description string `yaml:"description" json:"description"`
|
||||
Setup string `yaml:"setup" json:"setup"`
|
||||
Run string `yaml:"run" json:"run"`
|
||||
}
|
||||
|
||||
func validateProfile(p MediaProfile) error {
|
||||
if !profileID.MatchString(p.ID) || p.Name == "" || p.Run == "" {
|
||||
return fmt.Errorf("profile requires a lowercase identifier, name, and run command")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func LoadMediaProfiles(repo string) (map[string][]MediaProfile, error) {
|
||||
catalogs := make(map[string][]MediaProfile)
|
||||
for _, category := range mediaCategories {
|
||||
data, err := os.ReadFile(filepath.Join(repo, "rover", "profiles", category+".yaml"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
decoder := yaml.NewDecoder(bytes.NewReader(data))
|
||||
decoder.KnownFields(true)
|
||||
var profiles []MediaProfile
|
||||
if err := decoder.Decode(&profiles); err != nil {
|
||||
return nil, fmt.Errorf("%s: %w", category, err)
|
||||
}
|
||||
seen := map[string]bool{}
|
||||
for _, p := range profiles {
|
||||
if err := validateProfile(p); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if p.ID == "custom" || seen[p.ID] {
|
||||
return nil, fmt.Errorf("duplicate/reserved profile %s", p.ID)
|
||||
}
|
||||
seen[p.ID] = true
|
||||
}
|
||||
data, err = os.ReadFile(filepath.Join("/etc/roverd/profiles", category+".yaml"))
|
||||
if err == nil {
|
||||
var custom MediaProfile
|
||||
decoder = yaml.NewDecoder(bytes.NewReader(data))
|
||||
decoder.KnownFields(true)
|
||||
if err = decoder.Decode(&custom); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = validateProfile(custom); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if custom.ID != "custom" {
|
||||
return nil, fmt.Errorf("custom profile ID must be custom")
|
||||
}
|
||||
profiles = append(profiles, custom)
|
||||
} else if !os.IsNotExist(err) {
|
||||
return nil, err
|
||||
}
|
||||
catalogs[category] = profiles
|
||||
}
|
||||
return catalogs, nil
|
||||
}
|
||||
|
||||
func SaveCustomProfile(category string, profile MediaProfile) error {
|
||||
valid := false
|
||||
for _, name := range mediaCategories {
|
||||
if category == name {
|
||||
valid = true
|
||||
}
|
||||
}
|
||||
if !valid {
|
||||
return fmt.Errorf("unknown media category")
|
||||
}
|
||||
profile.ID = "custom"
|
||||
if err := validateProfile(profile); err != nil {
|
||||
return err
|
||||
}
|
||||
data, err := yaml.Marshal(profile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dir := "/etc/roverd/profiles"
|
||||
if err = os.MkdirAll(dir, 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
file, err := os.CreateTemp(dir, ".profile-*")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer os.Remove(file.Name())
|
||||
defer file.Close()
|
||||
if _, err = file.Write(data); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = file.Sync(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = file.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Rename(file.Name(), filepath.Join(dir, category+".yaml"))
|
||||
}
|
||||
+173
-125
@@ -2,162 +2,210 @@ package roverd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
type MediaSupervisor struct {
|
||||
cfg MediaConfig
|
||||
logger *log.Logger
|
||||
client *http.Client
|
||||
checkInterval time.Duration
|
||||
statusMu sync.Mutex
|
||||
statuses map[string]string
|
||||
cfg *Config
|
||||
repo string
|
||||
profiles map[string][]MediaProfile
|
||||
events chan RoverEvent
|
||||
logger *log.Logger
|
||||
mu sync.Mutex
|
||||
setupMu sync.Mutex
|
||||
cancel context.CancelFunc
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
func NewMediaSupervisor(cfg MediaConfig, logger *log.Logger) *MediaSupervisor {
|
||||
if err := UpdatePublisherEnv(cfg); err != nil {
|
||||
logger.Printf("media supervisor: update env failed: %v", err)
|
||||
}
|
||||
if !cfg.Manage {
|
||||
return nil
|
||||
}
|
||||
interval := cfg.HealthInterval.Duration
|
||||
if interval <= 0 {
|
||||
interval = 30 * time.Second
|
||||
}
|
||||
var client *http.Client
|
||||
if cfg.HealthURL != "" {
|
||||
client = &http.Client{Timeout: 5 * time.Second}
|
||||
}
|
||||
return &MediaSupervisor{
|
||||
cfg: cfg,
|
||||
logger: logger,
|
||||
client: client,
|
||||
checkInterval: interval,
|
||||
func NewMediaSupervisor(cfg *Config, repo string, events chan RoverEvent, logger *log.Logger) (*MediaSupervisor, error) {
|
||||
profiles, err := LoadMediaProfiles(repo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &MediaSupervisor{cfg: cfg, repo: repo, profiles: profiles, events: events, logger: logger, statuses: make(map[string]string)}, nil
|
||||
}
|
||||
func (m *MediaSupervisor) Profiles() map[string][]MediaProfile { return m.profiles }
|
||||
func (m *MediaSupervisor) emit(kind, category, message string) {
|
||||
if kind == "media.status" {
|
||||
m.statusMu.Lock()
|
||||
m.statuses[category] = message
|
||||
m.statusMu.Unlock()
|
||||
}
|
||||
event := RoverEvent{Type: "event", Event: kind, Ts: time.Now().UnixMilli(), Data: map[string]any{"category": category, "message": message}}
|
||||
select {
|
||||
case m.events <- event:
|
||||
default:
|
||||
} // Never block a child on a slow/disconnected server.
|
||||
}
|
||||
|
||||
func (m *MediaSupervisor) Start(ctx context.Context) {
|
||||
if m == nil {
|
||||
return
|
||||
}
|
||||
if err := UpdatePublisherEnv(m.cfg); err != nil {
|
||||
m.logger.Printf("media supervisor: update env failed: %v", err)
|
||||
}
|
||||
if m.cfg.HealthURL == "" || m.client == nil {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if m.cancel != nil {
|
||||
return
|
||||
}
|
||||
ctx, m.cancel = context.WithCancel(ctx)
|
||||
m.done = make(chan struct{})
|
||||
go func() {
|
||||
ticker := time.NewTicker(m.checkInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
if err := m.checkAndRepair(); err != nil {
|
||||
m.logger.Printf("media supervisor: %v", err)
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-ticker.C:
|
||||
if err := m.checkAndRepair(); err != nil {
|
||||
m.logger.Printf("media supervisor: %v", err)
|
||||
}
|
||||
defer close(m.done)
|
||||
var workers sync.WaitGroup
|
||||
for _, category := range mediaCategories {
|
||||
enabled, id := m.selection(category)
|
||||
if !enabled {
|
||||
m.emit("media.status", category, "disabled")
|
||||
continue
|
||||
}
|
||||
workers.Add(1)
|
||||
go func(category, id string) { defer workers.Done(); m.supervise(ctx, category, id) }(category, id)
|
||||
}
|
||||
workers.Wait()
|
||||
}()
|
||||
}
|
||||
|
||||
func (m *MediaSupervisor) HandleAction(ctx context.Context, action string) error {
|
||||
if m == nil {
|
||||
return errors.New("media supervisor disabled")
|
||||
func (m *MediaSupervisor) Stop() {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
if m.cancel == nil {
|
||||
return
|
||||
}
|
||||
if err := UpdatePublisherEnv(m.cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
switch action {
|
||||
case "start", "stop", "restart", "reload", "status":
|
||||
return m.runSystemctl(ctx, action)
|
||||
m.cancel()
|
||||
<-m.done
|
||||
m.cancel = nil
|
||||
}
|
||||
func (m *MediaSupervisor) selection(category string) (bool, string) {
|
||||
switch category {
|
||||
case "video":
|
||||
return m.cfg.Media.Video.Enabled, m.cfg.Media.Video.Profile
|
||||
case "audioCapture":
|
||||
return m.cfg.Media.AudioCapture.Enabled, m.cfg.Media.AudioCapture.Profile
|
||||
default:
|
||||
return fmt.Errorf("unknown media action: %s", action)
|
||||
return m.cfg.Media.AudioPlayback.Enabled, m.cfg.Media.AudioPlayback.Profile
|
||||
}
|
||||
}
|
||||
|
||||
func (m *MediaSupervisor) checkAndRepair() error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 7*time.Second)
|
||||
defer cancel()
|
||||
|
||||
if m.checkHealth(ctx) {
|
||||
return nil
|
||||
}
|
||||
m.logger.Printf("media supervisor: health check failed, restarting configured media services")
|
||||
if err := m.runSystemctl(ctx, "restart"); err != nil {
|
||||
return fmt.Errorf("restart media services: %w", err)
|
||||
func (m *MediaSupervisor) HandleAction(_ context.Context, action string) error {
|
||||
if action != "stop" {
|
||||
return fmt.Errorf("save configuration to start or restart media")
|
||||
}
|
||||
m.Stop()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *MediaSupervisor) checkHealth(ctx context.Context) bool {
|
||||
if m.client == nil || m.cfg.HealthURL == "" {
|
||||
return true
|
||||
}
|
||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, m.cfg.HealthURL, nil)
|
||||
if err != nil {
|
||||
m.logger.Printf("media supervisor: health request: %v", err)
|
||||
return false
|
||||
}
|
||||
resp, err := m.client.Do(req)
|
||||
if err != nil {
|
||||
m.logger.Printf("media supervisor: health request failed: %v", err)
|
||||
return false
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
_, _ = io.Copy(io.Discard, resp.Body)
|
||||
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
|
||||
return true
|
||||
}
|
||||
m.logger.Printf("media supervisor: unexpected health status %d", resp.StatusCode)
|
||||
return false
|
||||
}
|
||||
|
||||
func (m *MediaSupervisor) runSystemctl(ctx context.Context, action string) error {
|
||||
services := m.managedServices()
|
||||
if len(services) == 0 {
|
||||
return errors.New("no media services configured")
|
||||
}
|
||||
runCtx, cancel := context.WithTimeout(ctx, 15*time.Second)
|
||||
defer cancel()
|
||||
|
||||
for _, service := range services {
|
||||
cmd := exec.CommandContext(runCtx, "systemctl", action, service)
|
||||
output, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("systemctl %s %s: %w (%s)", action, service, err, string(output))
|
||||
func (m *MediaSupervisor) supervise(ctx context.Context, category, id string) {
|
||||
var profile *MediaProfile
|
||||
for _, p := range m.profiles[category] {
|
||||
if p.ID == id {
|
||||
copy := p
|
||||
profile = ©
|
||||
break
|
||||
}
|
||||
}
|
||||
return nil
|
||||
if profile == nil {
|
||||
m.emit("media.status", category, "unknown profile: "+id)
|
||||
return
|
||||
}
|
||||
dir := filepath.Join("/var/lib/roverd/profiles", category, id)
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
m.emit("media.status", category, err.Error())
|
||||
return
|
||||
}
|
||||
env := m.environment(dir)
|
||||
if profile.Setup != "" {
|
||||
m.emit("media.status", category, "setup")
|
||||
m.setupMu.Lock()
|
||||
err := m.command(ctx, category, dir, env, profile.Setup)
|
||||
m.setupMu.Unlock()
|
||||
if err != nil {
|
||||
m.emit("media.status", category, "setup failed: "+err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
for ctx.Err() == nil {
|
||||
m.emit("media.status", category, "running")
|
||||
err := m.command(ctx, category, dir, env, profile.Run)
|
||||
if ctx.Err() != nil {
|
||||
break
|
||||
}
|
||||
m.emit("media.status", category, fmt.Sprintf("exited (%v); retrying in 2s", err))
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case <-time.After(2 * time.Second):
|
||||
}
|
||||
}
|
||||
m.emit("media.status", category, "stopped")
|
||||
}
|
||||
|
||||
func (m *MediaSupervisor) managedServices() []string {
|
||||
/*
|
||||
Only enabled streams are service-managed. This matters for audio capture:
|
||||
the service may be installed everywhere, but a rover with capture disabled
|
||||
should not have remote media commands starting a publisher that the config
|
||||
says should stay off.
|
||||
*/
|
||||
services := []string{}
|
||||
if m.cfg.Video.Enabled && m.cfg.Video.Service != "" {
|
||||
services = append(services, m.cfg.Video.Service)
|
||||
type mediaOutput struct {
|
||||
supervisor *MediaSupervisor
|
||||
category string
|
||||
}
|
||||
|
||||
func (w mediaOutput) Write(data []byte) (int, error) {
|
||||
// Split even output without newlines into bounded messages.
|
||||
count := len(data)
|
||||
for len(data) > 0 {
|
||||
n := len(data)
|
||||
if n > 4096 {
|
||||
n = 4096
|
||||
}
|
||||
w.supervisor.emit("media.output", w.category, string(data[:n]))
|
||||
data = data[n:]
|
||||
}
|
||||
if m.cfg.AudioCapture.Enabled && m.cfg.AudioCapture.Service != "" {
|
||||
services = append(services, m.cfg.AudioCapture.Service)
|
||||
return count, nil
|
||||
}
|
||||
func (m *MediaSupervisor) command(ctx context.Context, category, dir string, env []string, command string) error {
|
||||
cmd := exec.CommandContext(ctx, "/bin/bash", "-e", "-o", "pipefail", "-c", command)
|
||||
cmd.Dir = dir
|
||||
cmd.Env = env
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
||||
cmd.Stdout = mediaOutput{m, category}
|
||||
cmd.Stderr = mediaOutput{m, category}
|
||||
// Kill the entire group: shell pipelines must not survive cancellation or
|
||||
// retain stdout pipes after their parent shell exits.
|
||||
cmd.Cancel = func() error { return syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) }
|
||||
cmd.WaitDelay = 2 * time.Second
|
||||
if err := cmd.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
if m.cfg.AudioPlayback.Enabled && m.cfg.AudioPlayback.Service != "" {
|
||||
services = append(services, m.cfg.AudioPlayback.Service)
|
||||
err := cmd.Wait()
|
||||
_ = syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
|
||||
return err
|
||||
}
|
||||
func (m *MediaSupervisor) environment(dir string) []string {
|
||||
cfg := m.cfg
|
||||
host, _ := url.Parse(cfg.ServerURL)
|
||||
values := map[string]string{
|
||||
"ROVER_NAME": cfg.Name, "ROVER_SERVER_HOST": host.Hostname(), "ROVER_PROFILE_DIR": dir, "ROVER_REPO_DIR": m.repo,
|
||||
"ROVER_VIDEO_DEVICE": cfg.Media.Video.Device, "ROVER_VIDEO_INPUT_FORMAT": cfg.Media.Video.InputFormat,
|
||||
"ROVER_VIDEO_WIDTH": strconv.Itoa(cfg.Media.Video.Width), "ROVER_VIDEO_HEIGHT": strconv.Itoa(cfg.Media.Video.Height),
|
||||
"ROVER_VIDEO_FPS": strconv.Itoa(cfg.Media.Video.FPS), "ROVER_VIDEO_BITRATE": strconv.Itoa(cfg.Media.Video.Bitrate),
|
||||
"ROVER_VIDEO_INVERTED": strconv.FormatBool(cfg.Media.Video.Inverted), "ROVER_VIDEO_SENSOR_MODE": cfg.Media.Video.SensorMode,
|
||||
"ROVER_VIDEO_PUBLISH_URL": cfg.Media.Video.PublishURL, "ROVER_AUDIO_PUBLISH_URL": cfg.Media.AudioCapture.PublishURL,
|
||||
"ROVER_AUDIO_PLAYBACK_URL": cfg.Media.AudioPlayback.ForwardURL, "ROVER_AUDIO_INPUT_DEVICE": "rover_capture", "ROVER_AUDIO_OUTPUT_DEVICE": "rover_forward",
|
||||
"ROVER_AUDIO_SAMPLE_RATE": strconv.Itoa(cfg.Media.AudioCapture.SampleRate), "ROVER_AUDIO_CHANNELS": strconv.Itoa(cfg.Media.AudioCapture.Channels),
|
||||
"ROVER_AUDIO_BITRATE": strconv.Itoa(cfg.Media.AudioCapture.Bitrate), "ROVER_AUDIO_NORMALIZE": strconv.FormatBool(cfg.Media.AudioPlayback.Normalize),
|
||||
"ROVER_AUDIO_NORMALIZE_FILTER": cfg.Media.AudioPlayback.NormalizeFilter,
|
||||
}
|
||||
return services
|
||||
env := os.Environ()
|
||||
for key, value := range values {
|
||||
env = append(env, key+"="+value)
|
||||
}
|
||||
return env
|
||||
}
|
||||
|
||||
func (m *MediaSupervisor) Status() map[string]string {
|
||||
m.statusMu.Lock()
|
||||
defer m.statusMu.Unlock()
|
||||
result := make(map[string]string)
|
||||
for key, value := range m.statuses {
|
||||
result[key] = value
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
+10
-12
@@ -53,15 +53,11 @@
|
||||
"maxWheelSpeed": 350,
|
||||
"media": {
|
||||
"rtspPort": 8554,
|
||||
"manage": false,
|
||||
"healthUrl": "http://127.0.0.1:9997/v3/paths/list",
|
||||
"healthInterval": "30s",
|
||||
"video": {
|
||||
"profile": "rpicam",
|
||||
"enabled": true,
|
||||
"service": "video-publisher.service",
|
||||
"publisher": "pi-libcamera",
|
||||
"device": "",
|
||||
"inputFormat": "",
|
||||
"device": "/dev/video0",
|
||||
"inputFormat": "mjpeg",
|
||||
"width": 640,
|
||||
"height": 480,
|
||||
"fps": 30,
|
||||
@@ -70,22 +66,25 @@
|
||||
"sensorMode": "1296:972"
|
||||
},
|
||||
"audioCapture": {
|
||||
"profile": "alsa",
|
||||
"enabled": false,
|
||||
"service": "audio-only-publisher.service",
|
||||
"device": "hw:0,0",
|
||||
"sampleRate": 48000,
|
||||
"channels": 2,
|
||||
"bitrate": 510000
|
||||
},
|
||||
"audioPlayback": {
|
||||
"profile": "alsa",
|
||||
"enabled": true,
|
||||
"service": "audio-forward-listener.service",
|
||||
"device": "forward",
|
||||
"normalize": true,
|
||||
"normalizeFilter": "dynaudnorm=f=75:g=15:m=10:p=0.9,alimiter=limit=0.85:level=disabled"
|
||||
}
|
||||
},
|
||||
"audio": {
|
||||
"inputDevice": "hw:0,0",
|
||||
"outputDevice": "hw:0,0",
|
||||
"mixerCard": "0",
|
||||
"outputSampleRate": 48000,
|
||||
"outputChannels": 2,
|
||||
"ttsEnabled": false,
|
||||
"defaultEngine": "flite",
|
||||
"defaultVoice": "rms",
|
||||
@@ -96,7 +95,6 @@
|
||||
"volume": 0.25,
|
||||
"sampleRate": 48000,
|
||||
"channels": 1,
|
||||
"device": "",
|
||||
"sineGain": 1,
|
||||
"sawGain": 0.7,
|
||||
"maxDuration": "10s"
|
||||
|
||||
@@ -53,15 +53,11 @@
|
||||
"maxWheelSpeed": 350,
|
||||
"media": {
|
||||
"rtspPort": 8554,
|
||||
"manage": true,
|
||||
"healthUrl": "",
|
||||
"healthInterval": "30s",
|
||||
"video": {
|
||||
"profile": "rpicam",
|
||||
"enabled": true,
|
||||
"service": "video-publisher.service",
|
||||
"publisher": "pi-libcamera",
|
||||
"device": "",
|
||||
"inputFormat": "",
|
||||
"device": "/dev/video0",
|
||||
"inputFormat": "mjpeg",
|
||||
"width": 640,
|
||||
"height": 480,
|
||||
"fps": 30,
|
||||
@@ -70,22 +66,25 @@
|
||||
"sensorMode": "1296:972"
|
||||
},
|
||||
"audioCapture": {
|
||||
"profile": "alsa",
|
||||
"enabled": false,
|
||||
"service": "audio-only-publisher.service",
|
||||
"device": "hw:0,0",
|
||||
"sampleRate": 48000,
|
||||
"channels": 2,
|
||||
"bitrate": 510000
|
||||
},
|
||||
"audioPlayback": {
|
||||
"profile": "alsa",
|
||||
"enabled": true,
|
||||
"service": "audio-forward-listener.service",
|
||||
"device": "forward",
|
||||
"normalize": true,
|
||||
"normalizeFilter": "dynaudnorm=f=75:g=15:m=10:p=0.9,alimiter=limit=0.85:level=disabled"
|
||||
}
|
||||
},
|
||||
"audio": {
|
||||
"inputDevice": "hw:0,0",
|
||||
"outputDevice": "hw:0,0",
|
||||
"mixerCard": "0",
|
||||
"outputSampleRate": 48000,
|
||||
"outputChannels": 2,
|
||||
"ttsEnabled": false,
|
||||
"defaultEngine": "flite",
|
||||
"defaultVoice": "rms",
|
||||
@@ -96,7 +95,6 @@
|
||||
"volume": 0.25,
|
||||
"sampleRate": 48000,
|
||||
"channels": 1,
|
||||
"device": "",
|
||||
"sineGain": 1,
|
||||
"sawGain": 0.7,
|
||||
"maxDuration": "1.2s"
|
||||
|
||||
+8
-10
@@ -53,13 +53,9 @@
|
||||
"maxWheelSpeed": 350,
|
||||
"media": {
|
||||
"rtspPort": 8554,
|
||||
"manage": true,
|
||||
"healthUrl": "",
|
||||
"healthInterval": "30s",
|
||||
"video": {
|
||||
"profile": "v4l2",
|
||||
"enabled": true,
|
||||
"service": "debian-laptop-video-publisher.service",
|
||||
"publisher": "debian-laptop-v4l2",
|
||||
"device": "/dev/video0",
|
||||
"inputFormat": "mjpeg",
|
||||
"width": 640,
|
||||
@@ -70,22 +66,25 @@
|
||||
"sensorMode": "1296:972"
|
||||
},
|
||||
"audioCapture": {
|
||||
"profile": "alsa",
|
||||
"enabled": true,
|
||||
"service": "audio-only-publisher.service",
|
||||
"device": "default",
|
||||
"sampleRate": 48000,
|
||||
"channels": 2,
|
||||
"bitrate": 510000
|
||||
},
|
||||
"audioPlayback": {
|
||||
"profile": "alsa",
|
||||
"enabled": true,
|
||||
"service": "audio-forward-listener.service",
|
||||
"device": "forward",
|
||||
"normalize": true,
|
||||
"normalizeFilter": "dynaudnorm=f=75:g=15:m=10:p=0.9,alimiter=limit=0.85:level=disabled"
|
||||
}
|
||||
},
|
||||
"audio": {
|
||||
"inputDevice": "hw:0,0",
|
||||
"outputDevice": "hw:0,0",
|
||||
"mixerCard": "0",
|
||||
"outputSampleRate": 48000,
|
||||
"outputChannels": 2,
|
||||
"ttsEnabled": true,
|
||||
"defaultEngine": "flite",
|
||||
"defaultVoice": "rms",
|
||||
@@ -96,7 +95,6 @@
|
||||
"volume": 0.25,
|
||||
"sampleRate": 48000,
|
||||
"channels": 1,
|
||||
"device": "",
|
||||
"sineGain": 1,
|
||||
"sawGain": 0.7,
|
||||
"maxDuration": "10s"
|
||||
Reference in New Issue
Block a user