diff --git a/dist/roverd-linux-amd64 b/dist/roverd-linux-amd64 index a195c861..f566e273 100755 Binary files a/dist/roverd-linux-amd64 and b/dist/roverd-linux-amd64 differ diff --git a/dist/roverd-linux-arm64 b/dist/roverd-linux-arm64 index 99c35f67..53fa020a 100755 Binary files a/dist/roverd-linux-arm64 and b/dist/roverd-linux-arm64 differ diff --git a/dist/roverd-linux-armv6 b/dist/roverd-linux-armv6 index 69570e52..2b63ada1 100755 Binary files a/dist/roverd-linux-armv6 and b/dist/roverd-linux-armv6 differ diff --git a/dist/roverd-linux-armv7 b/dist/roverd-linux-armv7 index 8f2efdaf..6969efe5 100755 Binary files a/dist/roverd-linux-armv7 and b/dist/roverd-linux-armv7 differ diff --git a/rover/profiles/audioCapture.yaml b/rover/profiles/audioCapture.yaml index ed2f1c1d..030b2932 100644 --- a/rover/profiles/audioCapture.yaml +++ b/rover/profiles/audioCapture.yaml @@ -9,7 +9,7 @@ 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" - id: aiy name: Google AIY Voice HAT microphone - description: Same configurable ALSA route; setup enables the HAT overlay. Reboot once after first enabling its hardware. + description: HAT capture with S32_LE input, 20 dB microphone boost, and low-latency Opus settings. Reboot once after first enabling its hardware. setup: | set -euo pipefail # Capture/playback setup may run concurrently; serialize edits to boot config. @@ -30,8 +30,19 @@ if [[ "$changed" == 1 ]]; then echo 'AIY hardware enabled. Reboot the host once before using this sound card.' fi - if ! command -v ffmpeg >/dev/null || ! command -v aplay >/dev/null; then + if ! command -v ffmpeg >/dev/null || ! command -v arecord >/dev/null; then 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" + # 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 | + 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" \ + -application audio -frame_duration 20 -compression_level 0 \ + -flush_packets 1 -muxdelay 0 -muxpreload 0 \ + -f rtsp -rtsp_transport tcp "$ROVER_AUDIO_PUBLISH_URL" diff --git a/rover/profiles/audioPlayback.yaml b/rover/profiles/audioPlayback.yaml index b0404d73..02934fdc 100644 --- a/rover/profiles/audioPlayback.yaml +++ b/rover/profiles/audioPlayback.yaml @@ -11,7 +11,7 @@ exec ffmpeg -nostdin -rtsp_transport tcp -i "$ROVER_AUDIO_PLAYBACK_URL" -vn "${filters[@]}" -f alsa "$ROVER_AUDIO_OUTPUT_DEVICE" - id: aiy name: Google AIY Voice HAT speaker - description: Enables the HAT hardware; uses the same configured ALSA routing as other devices. Reboot once after initial setup. + description: HAT playback with low-latency decoding and 16 kHz mono output through the configured audio route. Reboot once after initial setup. setup: | set -euo pipefail # Capture/playback setup may run concurrently; serialize edits to boot config. @@ -38,4 +38,9 @@ run: | 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" + # Decode to the same explicit HAT playback format as the previous listener. + 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 diff --git a/rover/profiles/video.yaml b/rover/profiles/video.yaml index f36369ea..66bbbea6 100644 --- a/rover/profiles/video.yaml +++ b/rover/profiles/video.yaml @@ -19,7 +19,15 @@ run: | camera=$(command -v rpicam-vid || command -v libcamera-vid) options=() - if [ "$ROVER_VIDEO_INVERTED" = true ]; then options+=(--hflip --vflip); fi + if [ "$ROVER_VIDEO_INVERTED" = true ]; then options+=(--rotation 180); fi if [ -n "$ROVER_VIDEO_SENSOR_MODE" ]; then options+=(--mode "$ROVER_VIDEO_SENSOR_MODE"); fi - "$camera" --timeout 0 --nopreview --inline --codec h264 --width "$ROVER_VIDEO_WIDTH" --height "$ROVER_VIDEO_HEIGHT" --framerate "$ROVER_VIDEO_FPS" --bitrate "$ROVER_VIDEO_BITRATE" "${options[@]}" -o - | - ffmpeg -nostdin -fflags +genpts -f h264 -i pipe:0 -c:v copy -an -f rtsp -rtsp_transport tcp "$ROVER_VIDEO_PUBLISH_URL" + # 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" \ + --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 \ + -use_wallclock_as_timestamps 1 -f h264 -i pipe:0 -c:v copy -an \ + -flush_packets 1 -muxdelay 0 -muxpreload 0 \ + -f rtsp -rtsp_transport tcp "$ROVER_VIDEO_PUBLISH_URL" diff --git a/rover/roverd/audio_routing.go b/rover/roverd/audio_routing.go index 6b74faaa..4b0fbca2 100644 --- a/rover/roverd/audio_routing.go +++ b/rover/roverd/audio_routing.go @@ -28,7 +28,13 @@ pcm.rover_mix { type dmix ipc_key 70601 ipc_key_add_uid true - slave { pcm %s format S16_LE rate %d channels %d } + # Preserve the previous mixer's explicit ALSA buffer geometry. + slave { + pcm %s format S16_LE rate %d channels %d + period_time 0 + period_size 1024 + buffer_size 4096 + } } `, strconv.Quote(cfg.InputDevice), strconv.Quote(cfg.OutputDevice), cfg.OutputSampleRate, cfg.OutputChannels) for _, pair := range [][2]string{{"tts", "TTSMaster"}, {"horn", "HornMaster"}, {"forward", "ForwardMaster"}} {