mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-11-18 04:32:23 -05:00
no config only profiles
This commit is contained in:
@@ -6,7 +6,15 @@
|
||||
apt-get update && apt-get install -y ffmpeg alsa-utils
|
||||
fi
|
||||
run: |
|
||||
exec ffmpeg -nostdin -f alsa -ar "$ROVER_AUDIO_SAMPLE_RATE" -ac "$ROVER_AUDIO_CHANNELS" -i "$ROVER_AUDIO_INPUT_DEVICE" -c:a libopus -b:a "$ROVER_AUDIO_BITRATE" -f rtsp -rtsp_transport tcp "$ROVER_AUDIO_PUBLISH_URL"
|
||||
sample_rate=48000
|
||||
channels=2
|
||||
bitrate=510000
|
||||
arecord -D "$ROVER_AUDIO_INPUT_DEVICE" -f S32_LE -c "$channels" -r "$sample_rate" -B 16384 -F 1024 -q -t raw |
|
||||
ffmpeg -nostdin -hide_banner -loglevel warning -fflags nobuffer \
|
||||
-rtbufsize 0 -thread_queue_size 4096 -f s32le -ar "$sample_rate" -ac "$channels" -i pipe:0 \
|
||||
-af "volume=20dB" -c:a libopus -b:a "$bitrate" -ar:a "$sample_rate" -ac:a "$channels" \
|
||||
-application audio -frame_duration 20 -compression_level 0 \
|
||||
-flush_packets 1 -muxdelay 0 -muxpreload 0 -f rtsp -rtsp_transport tcp "$ROVER_AUDIO_PUBLISH_URL"
|
||||
- id: aiy
|
||||
name: Google AIY Voice HAT microphone
|
||||
description: HAT capture with S32_LE input, 20 dB microphone boost, and low-latency Opus settings. Reboot once after first enabling its hardware.
|
||||
@@ -34,15 +42,12 @@
|
||||
apt-get update && apt-get install -y ffmpeg alsa-utils
|
||||
fi
|
||||
run: |
|
||||
# Preserve the HAT capture format, gain, and low-cost Opus settings.
|
||||
arecord -D "$ROVER_AUDIO_INPUT_DEVICE" -f S32_LE \
|
||||
-c "$ROVER_AUDIO_CHANNELS" -r "$ROVER_AUDIO_SAMPLE_RATE" \
|
||||
-B "${AUDIO_ALSA_BUFFER_BYTES:-16384}" -F "${AUDIO_ALSA_PERIOD_BYTES:-1024}" -q -t raw |
|
||||
sample_rate=48000
|
||||
channels=2
|
||||
bitrate=510000
|
||||
arecord -D "$ROVER_AUDIO_INPUT_DEVICE" -f S32_LE -c "$channels" -r "$sample_rate" -B 16384 -F 1024 -q -t raw |
|
||||
ffmpeg -nostdin -hide_banner -loglevel warning -fflags nobuffer \
|
||||
-rtbufsize 0 -thread_queue_size 4096 -f s32le \
|
||||
-ar "$ROVER_AUDIO_SAMPLE_RATE" -ac "$ROVER_AUDIO_CHANNELS" -i pipe:0 \
|
||||
-af "volume=20dB" -c:a libopus -b:a "$ROVER_AUDIO_BITRATE" \
|
||||
-ar:a "$ROVER_AUDIO_SAMPLE_RATE" -ac:a "$ROVER_AUDIO_CHANNELS" \
|
||||
-rtbufsize 0 -thread_queue_size 4096 -f s32le -ar "$sample_rate" -ac "$channels" -i pipe:0 \
|
||||
-af "volume=20dB" -c:a libopus -b:a "$bitrate" -ar:a "$sample_rate" -ac:a "$channels" \
|
||||
-application audio -frame_duration 20 -compression_level 0 \
|
||||
-flush_packets 1 -muxdelay 0 -muxpreload 0 \
|
||||
-f rtsp -rtsp_transport tcp "$ROVER_AUDIO_PUBLISH_URL"
|
||||
-flush_packets 1 -muxdelay 0 -muxpreload 0 -f rtsp -rtsp_transport tcp "$ROVER_AUDIO_PUBLISH_URL"
|
||||
|
||||
@@ -6,9 +6,14 @@
|
||||
apt-get update && apt-get install -y ffmpeg alsa-utils
|
||||
fi
|
||||
run: |
|
||||
normalize=true
|
||||
normalize_filter='dynaudnorm=f=75:g=15:m=10:p=0.9,alimiter=limit=0.85:level=disabled'
|
||||
filters=()
|
||||
if [ "$ROVER_AUDIO_NORMALIZE" = true ]; then filters=(-af "$ROVER_AUDIO_NORMALIZE_FILTER"); fi
|
||||
exec ffmpeg -nostdin -rtsp_transport tcp -i "$ROVER_AUDIO_PLAYBACK_URL" -vn "${filters[@]}" -f alsa "$ROVER_AUDIO_OUTPUT_DEVICE"
|
||||
if [ "$normalize" = true ]; then filters=(-af "$normalize_filter"); fi
|
||||
ffmpeg -nostdin -hide_banner -loglevel warning -fflags nobuffer -flags low_delay \
|
||||
-analyzeduration 200k -probesize 32k -rtsp_transport tcp -i "$ROVER_AUDIO_PLAYBACK_URL" \
|
||||
-vn "${filters[@]}" -ac 1 -ar 16000 -f s16le pipe:1 |
|
||||
aplay -q -D "$ROVER_AUDIO_OUTPUT_DEVICE" -t raw -f S16_LE -r 16000 -c 1
|
||||
- id: aiy
|
||||
name: Google AIY Voice HAT speaker
|
||||
description: HAT playback with low-latency decoding and 16 kHz mono output through the configured audio route. Reboot once after initial setup.
|
||||
@@ -36,11 +41,11 @@
|
||||
apt-get update && apt-get install -y ffmpeg alsa-utils
|
||||
fi
|
||||
run: |
|
||||
normalize=true
|
||||
normalize_filter='dynaudnorm=f=75:g=15:m=10:p=0.9,alimiter=limit=0.85:level=disabled'
|
||||
filters=()
|
||||
if [ "$ROVER_AUDIO_NORMALIZE" = true ]; then filters=(-af "$ROVER_AUDIO_NORMALIZE_FILTER"); fi
|
||||
# Decode to the same explicit HAT playback format as the previous listener.
|
||||
if [ "$normalize" = true ]; then filters=(-af "$normalize_filter"); fi
|
||||
ffmpeg -nostdin -hide_banner -loglevel warning -fflags nobuffer -flags low_delay \
|
||||
-analyzeduration 200k -probesize 32k -rtsp_transport tcp \
|
||||
-i "$ROVER_AUDIO_PLAYBACK_URL" -vn "${filters[@]}" \
|
||||
-ac 1 -ar 16000 -f s16le pipe:1 |
|
||||
-analyzeduration 200k -probesize 32k -rtsp_transport tcp -i "$ROVER_AUDIO_PLAYBACK_URL" \
|
||||
-vn "${filters[@]}" -ac 1 -ar 16000 -f s16le pipe:1 |
|
||||
aplay -q -D "$ROVER_AUDIO_OUTPUT_DEVICE" -t raw -f S16_LE -r 16000 -c 1
|
||||
|
||||
@@ -4,9 +4,24 @@
|
||||
setup: |
|
||||
command -v ffmpeg >/dev/null || { apt-get update && apt-get install -y ffmpeg; }
|
||||
run: |
|
||||
device=/dev/video0
|
||||
input_format=mjpeg
|
||||
width=640
|
||||
height=480
|
||||
fps=30
|
||||
bitrate=2000000
|
||||
inverted=false
|
||||
input_options=()
|
||||
if [ -n "$input_format" ]; then input_options=(-input_format "$input_format"); fi
|
||||
filters=()
|
||||
if [ "$ROVER_VIDEO_INVERTED" = true ]; then filters=(-vf hflip,vflip); fi
|
||||
exec ffmpeg -nostdin -f v4l2 -input_format "$ROVER_VIDEO_INPUT_FORMAT" -video_size "${ROVER_VIDEO_WIDTH}x${ROVER_VIDEO_HEIGHT}" -framerate "$ROVER_VIDEO_FPS" -i "$ROVER_VIDEO_DEVICE" "${filters[@]}" -an -c:v libx264 -preset ultrafast -tune zerolatency -pix_fmt yuv420p -b:v "$ROVER_VIDEO_BITRATE" -f rtsp -rtsp_transport tcp "$ROVER_VIDEO_PUBLISH_URL"
|
||||
if [ "$inverted" = true ]; then filters=(-vf "transpose=2,transpose=2"); fi
|
||||
exec ffmpeg -nostdin -hide_banner -loglevel warning -fflags nobuffer -flags low_delay \
|
||||
-thread_queue_size 4096 -f v4l2 "${input_options[@]}" -framerate "$fps" \
|
||||
-video_size "${width}x${height}" -i "$device" "${filters[@]}" -an \
|
||||
-c:v libx264 -preset veryfast -tune zerolatency -profile:v baseline -pix_fmt yuv420p \
|
||||
-b:v "$bitrate" -maxrate "$bitrate" -bufsize "$((bitrate / 2))" \
|
||||
-g "$fps" -keyint_min "$fps" -sc_threshold 0 -flush_packets 1 -muxdelay 0 -muxpreload 0 \
|
||||
-f rtsp -rtsp_transport tcp "$ROVER_VIDEO_PUBLISH_URL"
|
||||
- id: rpicam
|
||||
name: Raspberry Pi CSI camera
|
||||
description: rpicam/libcamera H.264 output, republished through ffmpeg.
|
||||
@@ -17,14 +32,20 @@
|
||||
apt-get install -y rpicam-apps
|
||||
fi
|
||||
run: |
|
||||
width=640
|
||||
height=480
|
||||
fps=30
|
||||
bitrate=2000000
|
||||
inverted=true
|
||||
sensor_mode=1296:972
|
||||
camera=$(command -v rpicam-vid || command -v libcamera-vid)
|
||||
options=()
|
||||
if [ "$ROVER_VIDEO_INVERTED" = true ]; then options+=(--rotation 180); fi
|
||||
if [ -n "$ROVER_VIDEO_SENSOR_MODE" ]; then options+=(--mode "$ROVER_VIDEO_SENSOR_MODE"); fi
|
||||
if [ "$inverted" = true ]; then options+=(--rotation 180); fi
|
||||
if [ -n "$sensor_mode" ]; then options+=(--mode "$sensor_mode"); fi
|
||||
# Preserve the previous Pi publisher's camera tuning and packet timing.
|
||||
"$camera" --inline --timeout 0 "${options[@]}" \
|
||||
--width "$ROVER_VIDEO_WIDTH" --height "$ROVER_VIDEO_HEIGHT" \
|
||||
--framerate "$ROVER_VIDEO_FPS" --bitrate "$ROVER_VIDEO_BITRATE" \
|
||||
--width "$width" --height "$height" \
|
||||
--framerate "$fps" --bitrate "$bitrate" \
|
||||
--codec h264 --intra 120 --profile baseline --denoise auto --nopreview \
|
||||
--metering centre --ev 0.1 --awb auto --saturation 0.6 --brightness 0 --output - |
|
||||
ffmpeg -nostdin -hide_banner -loglevel warning -fflags nobuffer \
|
||||
|
||||
+5
-77
@@ -91,15 +91,7 @@ type VideoMediaConfig struct {
|
||||
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:"-"`
|
||||
Device string `json:"device"`
|
||||
InputFormat string `json:"inputFormat"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
FPS int `json:"fps"`
|
||||
Bitrate int `json:"bitrate"`
|
||||
Inverted bool `json:"inverted"`
|
||||
SensorMode string `json:"sensorMode"`
|
||||
PublishURL string `json:"-"`
|
||||
}
|
||||
|
||||
type AudioCaptureConfig struct {
|
||||
@@ -110,10 +102,6 @@ type AudioCaptureConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
// PublishURL follows the same derived-only contract as the video path.
|
||||
PublishURL string `json:"-"`
|
||||
|
||||
SampleRate int `json:"sampleRate"`
|
||||
Channels int `json:"channels"`
|
||||
Bitrate int `json:"bitrate"`
|
||||
}
|
||||
|
||||
type AudioPlaybackConfig struct {
|
||||
@@ -125,9 +113,6 @@ type AudioPlaybackConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
// ForwardURL is derived because the server and rover must agree on the exact -fwd path.
|
||||
ForwardURL string `json:"-"`
|
||||
|
||||
Normalize bool `json:"normalize"`
|
||||
NormalizeFilter string `json:"normalizeFilter"`
|
||||
}
|
||||
|
||||
type CameraServoConfig struct {
|
||||
@@ -261,35 +246,10 @@ func DefaultConfig() Config {
|
||||
},
|
||||
MaxWheelMMs: 500,
|
||||
Media: MediaConfig{
|
||||
RTSPPort: 8554,
|
||||
|
||||
Video: VideoMediaConfig{
|
||||
Profile: "v4l2",
|
||||
Enabled: true,
|
||||
Device: "/dev/video0", InputFormat: "mjpeg",
|
||||
|
||||
Width: 640,
|
||||
Height: 480,
|
||||
FPS: 30,
|
||||
Bitrate: 2000000,
|
||||
Inverted: false,
|
||||
SensorMode: "",
|
||||
},
|
||||
AudioCapture: AudioCaptureConfig{
|
||||
Profile: "alsa",
|
||||
Enabled: true,
|
||||
|
||||
SampleRate: 48000,
|
||||
Channels: 2,
|
||||
Bitrate: 510000,
|
||||
},
|
||||
AudioPlayback: AudioPlaybackConfig{
|
||||
Profile: "alsa",
|
||||
Enabled: true,
|
||||
|
||||
Normalize: true,
|
||||
NormalizeFilter: "dynaudnorm=f=75:g=15:m=10:p=0.9,alimiter=limit=0.85:level=disabled",
|
||||
},
|
||||
RTSPPort: 8554,
|
||||
Video: VideoMediaConfig{Profile: "v4l2", Enabled: true},
|
||||
AudioCapture: AudioCaptureConfig{Profile: "alsa", Enabled: true},
|
||||
AudioPlayback: AudioPlaybackConfig{Profile: "alsa", Enabled: true},
|
||||
},
|
||||
Audio: AudioConfig{
|
||||
InputDevice: "hw:0,0", OutputDevice: "hw:0,0", MixerCard: "0", OutputSampleRate: 48000, OutputChannels: 2,
|
||||
@@ -488,26 +448,6 @@ func validateMediaConfig(cfg *MediaConfig, serverURL string, roverName string) e
|
||||
}
|
||||
|
||||
func validateVideoMediaConfig(cfg *VideoMediaConfig, serverURL string, roverName string, rtspPort int) error {
|
||||
// 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.
|
||||
cfg.InputFormat = strings.ToLower(strings.TrimSpace(cfg.InputFormat))
|
||||
if cfg.Width <= 0 {
|
||||
cfg.Width = 640
|
||||
}
|
||||
if cfg.Height <= 0 {
|
||||
cfg.Height = 480
|
||||
}
|
||||
if cfg.FPS <= 0 {
|
||||
cfg.FPS = 30
|
||||
}
|
||||
if cfg.Bitrate <= 0 {
|
||||
cfg.Bitrate = 2000000
|
||||
}
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
derived, err := derivePublishURL(serverURL, roverName, rtspPort)
|
||||
if err != nil {
|
||||
return fmt.Errorf("derive publishUrl: %w", err)
|
||||
@@ -517,15 +457,6 @@ func validateVideoMediaConfig(cfg *VideoMediaConfig, serverURL string, roverName
|
||||
}
|
||||
|
||||
func validateAudioCaptureConfig(cfg *AudioCaptureConfig, serverURL string, roverName string, rtspPort int) error {
|
||||
if cfg.SampleRate <= 0 {
|
||||
cfg.SampleRate = 48000
|
||||
}
|
||||
if cfg.Channels <= 0 {
|
||||
cfg.Channels = 2
|
||||
}
|
||||
if cfg.Bitrate <= 0 {
|
||||
cfg.Bitrate = 510000
|
||||
}
|
||||
derived, err := derivePublishURL(serverURL, roverName+"-audio", rtspPort)
|
||||
if err != nil {
|
||||
return fmt.Errorf("derive publishUrl: %w", err)
|
||||
@@ -535,9 +466,6 @@ func validateAudioCaptureConfig(cfg *AudioCaptureConfig, serverURL string, rover
|
||||
}
|
||||
|
||||
func validateAudioPlaybackConfig(cfg *AudioPlaybackConfig, serverURL string, roverName string, rtspPort int) error {
|
||||
if cfg.NormalizeFilter == "" {
|
||||
cfg.NormalizeFilter = "dynaudnorm=f=75:g=15:m=10:p=0.9,alimiter=limit=0.85:level=disabled"
|
||||
}
|
||||
derived, err := deriveReadURL(serverURL, roverName+"-fwd", rtspPort)
|
||||
if err != nil {
|
||||
return fmt.Errorf("derive forwardUrl: %w", err)
|
||||
|
||||
@@ -153,9 +153,22 @@ func (m *ManagementClient) execute(ctx context.Context, command managementComman
|
||||
if command.Profile == nil {
|
||||
return nil, fmt.Errorf("profile required")
|
||||
}
|
||||
var config *Config
|
||||
if len(command.Config) > 0 {
|
||||
var err error
|
||||
config, err = DecodeConfig(command.Config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err := SaveCustomProfile(command.Category, *command.Profile); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if config != nil {
|
||||
if err := SaveConfig(m.configPath, config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
m.stopping = true
|
||||
if m.runtime != nil {
|
||||
_ = m.runtime.PrepareShutdown()
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
@@ -176,15 +175,8 @@ func (m *MediaSupervisor) environment(dir string) []string {
|
||||
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,
|
||||
}
|
||||
env := os.Environ()
|
||||
for key, value := range values {
|
||||
|
||||
Reference in New Issue
Block a user