r/FlutterDev • u/TungDA87 • 2h ago
Article How Android WifiLock cut flutter_webrtc jitter from 85–150 ms to 10–20 ms (and open-sourcing robot_stream, a modular Flutter/Dart suite for ROS 2 robots)
https://github.com/robot-stream/robot_streamGitHub (BSD-3-Clause, includes demo video at the top of the README): https://github.com/robot-stream/robot_stream
pub.dev: https://pub.dev/packages/robot_stream
I just open-sourced robot_stream — a modular Flutter/Dart package suite (+ ROS 2 Humble robot gateway) for controlling mobile robots with low-latency WebRTC/WHEP video, telemetry, Nav2 navigation, and deadman-protected teleop.
Wanted to share one subtle Flutter/Android WebRTC issue that cost me days of debugging, in case anyone else is building low-latency video streaming apps with flutter_webrtc:
The problem: 85–150 ms jitter buffer on Android over a 2–5 ms LAN
Streaming 640×480 @ ~30 fps H.264 (~1.3–1.5 Mbps) over WebRTC/WHEP from a Jetson Orin Nano robot on 5 GHz Wi-Fi (2–5 ms ping):
• macOS Chrome: ~11 ms receiver jitter buffer (66–69 ms p50 driver-to-display).
• iPad 5th gen (iPadOS 16.7): 17 ms p50 / 19 ms p95 jitter buffer.
• Samsung A33 (Android 15, flutter_webrtc): receiver jitter buffer stayed stuck at 85–150 ms, even on the exact same LAN and stream.
Trying ForcePlayoutDelay(0, 0) lowered delay slightly but caused frame drops.
The root cause and fix
Android's Wi-Fi power-saving mode was quietly batching incoming UDP packets before handing them up to libwebrtc, so libwebrtc's adaptive jitter buffer saw bursty arrivals and expanded to 85–150 ms.
Adding a small Kotlin plugin inside robot_stream_webrtc that acquires WifiManager.WIFI_MODE_FULL_LOW_LATENCY (WifiLock) while a WebRTC stream is active immediately brought the Android jitter buffer down to 10–20 ms at 29–30 fps (~33–43 ms p50 decode latency) with zero extra frame drops. (iOS/macOS use no-op stubs so cross-platform builds stay clean.)
Modular Dart/Flutter package layout
You can install everything via "flutter pub add robot_stream", or depend only on individual packages (core and rosbridge are pure Dart, so they also work in CLI tools):
• robot_stream_core — pure-Dart models, interfaces, and SHA-256 TLS certificate pinning for self-signed robot certs.
• robot_stream_webrtc — standard WHEP signaling (HTTP POST SDP offer -> 201 Created, DELETE teardown), WhepSource, RobotVideoView, and the Android low-latency WifiLock plugin.
• robot_stream_mjpeg — MJPEG fallback with JPEG marker framing and stall detection.
• robot_stream_rosbridge — pure-Dart rosbridge v2 WebSocket client with SE(2) map+odom pose fusion, non-blocking STOP over a dedicated action WebSocket, Nav2 goals, teleop, and deadman heartbeats.
In the README demo (Wheeltec R550 driving to a Nav2 waypoint at 0.20 m/s), cutting the phone's Wi-Fi causes the robot-side deadman to cancel the Nav2 goal in ~0.7 s (1.0 s heartbeat timeout, ~20–25 cm coast); during hold-to-drive teleop, the velocity gate zeroes /cmd_vel after 0.3 s without commands.
Happy to hear feedback on the Dart API / package split, or if anyone else here is using Flutter for WebRTC video or robotics/IoT operator UIs!
1
u/dawedev 1h ago
Which lock mode did you end up with? WIFI_MODE_FULL_LOW_LATENCY only applies while the app is in the foreground with the screen on, and HIGH_PERF is deprecated on newer Android, so it might be worth checking jitter again after the screen dims during a long teleop session.