The car is sent a keyframe every fifteen seconds at most rather than every five, unless it needs one sooner

Two timers each forced a keyframe every five seconds: the encoder's own
interval and the safety net in the stats loop. On a SOOEMAKA over Wi-Fi each
one came to 87-99 KB, against about 14 KB for the frames between, and the car
must take all of it in before it can show the next frame. Gearslip already
asks for a keyframe whenever one is owed: after a stall, a reset window, and
each time the car hands its screen back.

The encoder's own interval is now a minute, and the safety net, for a
glitch in the car's decoder that Gearslip never hears of, fifteen seconds.

The stats line counts the keyframes sent in each window (keys=), so windows
with one can be compared against windows without.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
HawkandClaude Opus 5.5 committed 2026-11-23 10:52:36 -08:00
1 parent 4e3f8e6657
commit 0118b4e881
2 files changed
+10 -4

No files matched your search

@@ -123,6 +123,8 @@ class GearslipRunner(
@Volatile private var acksSeen = 0
@Volatile private var lastAckAt = 0L
@Volatile private var splitMessages = 0
/** Keyframes sent since the last stats line, to tell its windows with one from those without. */
@Volatile private var keyframesInWindow = 0
@Volatile private var resyncRequested = false
@Volatile private var resyncAttempts = 0
@Volatile private var lastKeyframeSentAt = 0L
@@ -1315,6 +1317,7 @@ class GearslipRunner(
resyncRequested = false
resyncAttempts = 0
lastKeyframeSentAt = System.currentTimeMillis()
keyframesInWindow++
}
// Counted before it's queued: the writer may send it and the ack come back before this
// thread runs again, and an ack counted ahead of its frame would leave the window full.
@@ -1612,10 +1615,12 @@ class GearslipRunner(
// head unit's acks, not the phone, set the frame rate.
val waited = ackWaitMs
ackWaitMs = 0
val keys = keyframesInWindow
keyframesInWindow = 0
SessionReport.stream("${"%.1f".format(fps)} fps, sent=$sent acked=$acksSeen")
log.i(
"video: ${"%.1f".format(fps)} fps over 5s | sent=$sent waited=${waited}ms " +
"acked=$acksSeen inFlight=$inFlight split=$splitMessages " +
"acked=$acksSeen inFlight=$inFlight split=$splitMessages keys=$keys " +
"kbps=${(videoSource?.bitRate ?: 0) / 1000}",
)
adaptBitRate(fps, waited)
@@ -1755,6 +1760,6 @@ class GearslipRunner(
const val WITHHELD_SCREEN_MS = 5_000L
const val AUDIO_TRACE_MESSAGES = 6
const val GUIDANCE_SESSION_ID = 1
const val PERIODIC_KEYFRAME_MS = 5_000L
const val PERIODIC_KEYFRAME_MS = 15_000L
}
}
@@ -79,7 +79,8 @@ class VideoSource(
setInteger(MediaFormat.KEY_BIT_RATE, bitRate)
setInteger(MediaFormat.KEY_FRAME_RATE, frameRate)
// Drops already ask for a fresh keyframe, so a long interval costs nothing in recovery
// and spares the link a big frame every second.
// and spares the link a big frame: a SOOEMAKA's came to 87-99 KB, against about 14 KB
// for the frames between.
setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, I_FRAME_INTERVAL_S)
if (mode == Mode.SURFACE) {
// A surface encoder only makes a frame when the screen changes, and many decoders
@@ -316,7 +317,7 @@ class VideoSource(
*/
const val WIRELESS_SHARE = 0.35
const val WIRELESS_MAX_BIT_RATE = 8_000_000
const val I_FRAME_INTERVAL_S = 5
const val I_FRAME_INTERVAL_S = 60
private const val REPEAT_AFTER_US = 100_000L
/** (Y, Cb, Cr) - white, yellow, cyan, green, magenta, red, blue. */