Modern Apps git

← Modern-Apps.git

maauto: fix video rate, now-playing card and ch8 input

Commit
24db5ee611e7133966d598b07b288b7bc5a0a0ef
Author
vayun-mathur <[email protected]>
When
2026-09-13 18:29 UTC (2 months ago)
Parents
f9f897f

Diff

auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalControlSession.kt
diff --git a/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalControlSession.kt b/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalControlSession.ktindex bd752f78c9..daec8d046c 100644--- a/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalControlSession.kt+++ b/auto/protocol/src/main/java/com/vayunmathur/auto/protocol/GalControlSession.kt@@ -15,6 +15,7 @@ import com.vayunmathur.auto.protocol.gal.PingResponse import com.vayunmathur.auto.protocol.gal.Service import com.vayunmathur.auto.protocol.gal.ServiceDiscoveryRequest import com.vayunmathur.auto.protocol.gal.ServiceDiscoveryResponse+import com.vayunmathur.auto.protocol.gal.ServiceDiscoveryUpdate import com.vayunmathur.auto.protocol.gal.VideoFocusIndication import com.vayunmathur.auto.protocol.gal.VideoFocusMode import java.nio.ByteBuffer@@ -141,13 +142,17 @@ class GalControlSession(             state = SessionState.CLOSED             emptyList()         }-        // Call availability and discovery updates are observed by higher layers;-        // the control channel itself has nothing to answer. Focus notifications-        // feed [focus] instead (see below).+        // Call availability is observed by higher layers; the control channel+        // itself has nothing to answer. Focus notifications feed [focus]+        // instead (see below).         GalMessage.Control.CALL_AVAILABILITY_STATUS,-        GalMessage.Control.SERVICE_DISCOVERY_UPDATE,         GalMessage.Control.PING_RESPONSE,         -> emptyList()+        // Hot-add/update of one service after the initial discovery (FINDINGS.md+        // control table, id 26): merged into [services] so the driver's+        // wire-order open loop picks it up without a reconnect. This is how an+        // input source that was absent from the initial 0x6 can still appear.+        GalMessage.Control.SERVICE_DISCOVERY_UPDATE -> onServiceDiscoveryUpdate(payload)         GalMessage.Control.AUDIO_FOCUS_NOTIFICATION -> onAudioFocusNotification(payload)         GalMessage.Control.NAVIGATION_FOCUS_NOTIFICATION -> onNavigationFocusNotification(payload) @@ -317,6 +322,22 @@ class GalControlSession(         return emptyList()     } +    /**+     * Merges one hot-added (or replaced) service into [services].+     *+     * Same-id entries are replaced, not duplicated: an update may restate a+     * service with new payloads (e.g. input source gains a touchscreen), and+     * the driver's open loop keys on id membership. A payload without a+     * service is ignored -- an absent field is "no update", never a removal.+     */+    private fun onServiceDiscoveryUpdate(payload: ByteArray): List<OutboundMessage> {+        val update = ServiceDiscoveryUpdate.parseFrom(payload)+        if (!update.hasService()) return emptyList()+        val incoming = update.service+        services = services.filter { it.id != incoming.id } + incoming+        return emptyList()+    }+     /**      * Records the head unit's answer to [openChannel].      *
auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalControlSessionTest.kt
diff --git a/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalControlSessionTest.kt b/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalControlSessionTest.ktindex 60f14f7a22..3a09f6c3c6 100644--- a/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalControlSessionTest.kt+++ b/auto/protocol/src/test/java/com/vayunmathur/auto/protocol/GalControlSessionTest.kt@@ -10,6 +10,7 @@ import com.vayunmathur.auto.protocol.gal.PingResponse import com.vayunmathur.auto.protocol.gal.Service import com.vayunmathur.auto.protocol.gal.ServiceDiscoveryRequest import com.vayunmathur.auto.protocol.gal.ServiceDiscoveryResponse+import com.vayunmathur.auto.protocol.gal.ServiceDiscoveryUpdate import java.io.File import java.nio.ByteBuffer import javax.net.ssl.SSLEngine@@ -176,6 +177,80 @@ class GalControlSessionTest {         )     } +    @Test+    fun `a discovery update hot-adds a service absent from the initial list`() {+        // The DHU offers services 1-7 with no input source; a later control-26+        // update may add service 8, which the driver's open loop then picks up+        // without a reconnect (FINDINGS.md control table, id 26).+        val session = session(GalCredential.serverEngine(context()))+        session.onMessage(+            GalMessage.Control.SERVICE_DISCOVERY_RESPONSE,+            ServiceDiscoveryResponse.newBuilder()+                .addServices(Service.newBuilder().setId(GalService.VIDEO_SINK.id))+                .build()+                .toByteArray(),+        )+        assertEquals(listOf(GalService.VIDEO_SINK.id), session.services.map { it.id })++        val outputs = session.onMessage(+            GalMessage.Control.SERVICE_DISCOVERY_UPDATE,+            ServiceDiscoveryUpdate.newBuilder()+                .setService(Service.newBuilder().setId(GalService.INPUT_SOURCE.id))+                .build()+                .toByteArray(),+        )+        assertTrue(outputs.isEmpty(), "discovery update needs no reply")+        assertEquals(+            listOf(GalService.VIDEO_SINK.id, GalService.INPUT_SOURCE.id),+            session.services.map { it.id },+        )+        assertNull(session.failure)+    }++    @Test+    fun `a discovery update replaces the same-id service instead of duplicating`() {+        val session = session(GalCredential.serverEngine(context()))+        session.onMessage(+            GalMessage.Control.SERVICE_DISCOVERY_RESPONSE,+            headUnitServices().toByteArray(),+        )+        val before = session.services.size++        session.onMessage(+            GalMessage.Control.SERVICE_DISCOVERY_UPDATE,+            ServiceDiscoveryUpdate.newBuilder()+                .setService(+                    Service.newBuilder()+                        .setId(GalService.VIDEO_SINK.id)+                        .setMediaSink(+                            MediaSinkService.newBuilder()+                                .setAvailableType(MediaCodecType.MEDIA_CODEC_VIDEO_H264_BP),+                        ),+                )+                .build()+                .toByteArray(),+        )+        assertEquals(before, session.services.size)+        assertEquals(1, session.services.count { it.id == GalService.VIDEO_SINK.id })+    }++    @Test+    fun `a discovery update without a service is ignored`() {+        val session = session(GalCredential.serverEngine(context()))+        session.onMessage(+            GalMessage.Control.SERVICE_DISCOVERY_RESPONSE,+            headUnitServices().toByteArray(),+        )+        val before = session.services.map { it.id }++        val outputs = session.onMessage(+            GalMessage.Control.SERVICE_DISCOVERY_UPDATE,+            ServiceDiscoveryUpdate.newBuilder().build().toByteArray(),+        )+        assertTrue(outputs.isEmpty())+        assertEquals(before, session.services.map { it.id })+    }+     @Test     fun `a ping is answered with the same timestamp`() {         val session = session(GalCredential.serverEngine(context()))
auto/src/main/java/com/vayunmathur/auto/platform/CarDisplay.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/platform/CarDisplay.kt b/auto/src/main/java/com/vayunmathur/auto/platform/CarDisplay.ktindex 8cf704d613..4e4fd535ca 100644--- a/auto/src/main/java/com/vayunmathur/auto/platform/CarDisplay.kt+++ b/auto/src/main/java/com/vayunmathur/auto/platform/CarDisplay.kt@@ -115,20 +115,50 @@ class CarDisplay(     /**      * Refreshes the car now-playing card. Safe from any thread: the snapshot is      * cached for presentations created later, and the view update hops to main.+     *+     * The snapshot is always cached, even when the card hides: a pause still+     * pushes `playing=false`, which is what clears a stale "Playing" label.      */     fun setNowPlaying(info: NowPlayingInfo) {         nowPlaying = info         mainHandler.post { presentation?.updateNowPlaying(info) }     } +    /**+     * Hides the car now-playing card without touching the cached snapshot.+     * Safe from any thread; the card re-shows on the next visible snapshot.+     */+    fun hideNowPlaying() {+        mainHandler.post { presentation?.hideNowPlaying() }+    }++    /**+     * Starts continuously invalidating the car UI at [fps] frames per second.+     * Safe from any thread; hops to main like [setNowPlaying].+     *+     * Without this the virtual display only re-composites when a view changes+     * on its own (the 1Hz clock tick), so the encoder sees ~1fps. Invalidating+     * the decor view at the negotiated rate keeps pixels flowing; the encoder+     * still paces output to its configured rate.+     */+    fun startFrameInvalidation(fps: Int) {+        mainHandler.post { presentation?.startFrameInvalidation(fps) }+    }++    /** Stops the continuous invalidation started by [startFrameInvalidation]. */+    fun stopFrameInvalidation() {+        mainHandler.post { presentation?.stopFrameInvalidation() }+    }+     /**      * Routes a head-unit tap at the now-playing card.      *      * [x] and [y] are display pixels (what ch8 scales to), compared against the      * card's on-screen bounds on the virtual display. Returns whether the tap      * hit the card; a hit posts the toggle to the main thread because views may-     * only be touched there. The ch8 owner calls this after scaling -- see the-     * Phase 4 handoff to input-dev.+     * only be touched there. Called from [dispatchTouch] for single-pointer+     * DOWN inside the card bounds -- previously zero callers, now the card-tap+     * path for ch8 touch.      */     fun handleCarTap(x: Float, y: Float): Boolean {         val bounds = mediaCardBounds ?: return false@@ -203,6 +233,14 @@ class CarDisplay(         actionIndex: Int,     ) {         val view = presentation?.window?.decorView ?: return+        // A tap on the now-playing card toggles playback directly: the tap+        // coordinates are display pixels and the card bounds are too, so a+        // DOWN inside them is an unambiguous card hit. Other gestures (and+        // taps elsewhere) still dispatch normally so app tiles stay tappable.+        if (action == android.view.MotionEvent.ACTION_DOWN && pointers.size == 1) {+            val (x, y, _) = pointers[0]+            if (handleCarTap(x, y)) return+        }         val now = android.os.SystemClock.uptimeMillis()         val downTime = if (action == android.view.MotionEvent.ACTION_DOWN) {             gestureDownTime = now@@ -328,6 +366,36 @@ class CarDisplay(             }         } +        /**+         * Continuous re-render at [fps] so the encoder surface produces frames+         * even when no view changes on its own. Main thread only. Backs off to+         * a Choreographer-frame chain when [fps] is at/above display cadence.+         */+        private var invalidator: Runnable? = null+        private var invalidatorFps = 0++        fun startFrameInvalidation(fps: Int) {+            stopFrameInvalidation()+            val decor = window?.decorView ?: return+            val intervalMs = (1000L / fps.coerceIn(1, MAX_INVALIDATE_FPS)).coerceAtLeast(0)+            invalidatorFps = fps+            val tick = object : Runnable {+                override fun run() {+                    decor.invalidate()+                    decor.postDelayed(this, intervalMs)+                }+            }+            invalidator = tick+            decor.post(tick)+        }++        fun stopFrameInvalidation() {+            val decor = window?.decorView+            invalidator?.let { decor?.removeCallbacks(it) }+            invalidator = null+            invalidatorFps = 0+        }+         override fun onCreate(savedInstanceState: Bundle?) {             super.onCreate(savedInstanceState)             val root = LinearLayout(context).apply {@@ -351,8 +419,14 @@ class CarDisplay(             }         } +        /** Hides the now-playing card; the cached snapshot is untouched. Main thread only. */+        fun hideNowPlaying() {+            mediaCard?.visibility = View.GONE+        }+         override fun onStop() {             clockView?.removeCallbacks(ticker)+            stopFrameInvalidation()             clockView = null             mediaTitle = null             mediaSubtitle = null@@ -366,8 +440,16 @@ class CarDisplay(          * Applies a snapshot to the now-playing card. Main thread only: called          * from the posted update in [setNowPlaying], or from `onCreate` above          * for a snapshot that arrived before the views existed.+         *+         * Also owns the card's visibility: `GONE` when idle (not playing and+         * no title to show) so the car display shows no card with nothing+         * playing; `VISIBLE` while playing, and while paused with a title so+         * resume keeps its context. GAL 11/12 stay unspoken by design, so no+         * head-unit contract drives this -- it is purely phone-side.          */         fun updateNowPlaying(info: NowPlayingInfo) {+            val card = mediaCard ?: return+            card.visibility = if (info.shouldShowCard()) View.VISIBLE else View.GONE             val title = mediaTitle ?: return             val subtitle = mediaSubtitle ?: return             val state = mediaState ?: return@@ -406,6 +488,9 @@ class CarDisplay(                 layoutParams = LinearLayout.LayoutParams(MATCH, WRAP)                 isClickable = true                 isFocusable = true+                // Starts hidden: the first snapshot decides, and with nothing+                // playing there is nothing to show.+                visibility = View.GONE             }             card.addView(                 TextView(context).apply {@@ -570,6 +655,13 @@ class CarDisplay(             const val UNDEFINED_COLUMN = GridLayout.UNDEFINED             val FILL: GridLayout.Alignment = GridLayout.FILL +            /**+             * Ceiling for the continuous frame invalidator: the encoder paces+             * output to its own configured rate, so invalidating faster only+             * burns CPU compositing frames the encoder drops.+             */+            const val MAX_INVALIDATE_FPS = 60+             /** Progress fraction in [0,1]; half (indeterminate-ish) with no duration. */             fun progressFraction(positionMs: Long, durationMs: Long?): Float {                 val duration = durationMs?.takeIf { it > 0 } ?: return 0.5f
auto/src/main/java/com/vayunmathur/auto/platform/InputChannel.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/platform/InputChannel.kt b/auto/src/main/java/com/vayunmathur/auto/platform/InputChannel.ktindex b91207bdb7..46cbcda183 100644--- a/auto/src/main/java/com/vayunmathur/auto/platform/InputChannel.kt+++ b/auto/src/main/java/com/vayunmathur/auto/platform/InputChannel.kt@@ -62,14 +62,26 @@ class InputChannel(         service.inputSource.touchscreenList.firstOrNull()?.let { it.width to it.height }             ?: (InputCodec.DEFAULT_HU_WIDTH to InputCodec.DEFAULT_HU_HEIGHT) +    /**+     * Whether the binding echo has gone out. Set in [requestBinding], read in+     * [onMessage] to log (not crash on) traffic that arrives with no owner+     * bound yet -- e.g. a head unit that sends before the grant path runs.+     */+    @Volatile+    private var bound = false+     /**      * The grant arrived: echo the discovery-advertised keycodes back so the-     * head unit knows which keys we handle. Called once per channel open.+     * head unit knows which keys we handle. Called once per channel open, and+     * again when video focus flaps back to PROJECTED with input (a head unit+     * that parked input may need the re-bind to resume sending reports).+     * Idempotent: re-sending the same echo is harmless.      */     fun requestBinding() {         val keycodes = service.inputSource.keycodesSupportedList         val (type, payload) = InputCodec.encodeKeyBinding(keycodes)         connection.send(channelId, type, payload)+        bound = true         Log.i(TAG, "input channel open; bound ${keycodes.size} keycodes")         onEvent(InputEvent.BindingRequested(keycodes.size))     }@@ -80,6 +92,15 @@ class InputChannel(             Log.w(TAG, "ignoring 0x${type.toString(16)} for channel $channelId")             return         }+        if (!bound) {+            // Traffic before the grant's binding echo: the head unit is+            // talking on a channel we never bound (or the grant path never+            // ran). Log, don't crash -- the binding goes out on the grant and+            // on the focus flap back to input-allowed.+            Log.w(TAG, "ch8 traffic before binding (0x${type.toString(16)}); dropping")+            onEvent(InputEvent.DroppedNoFocus)+            return+        }         if (type == GalMessage.Input.KEY_BINDING_RESPONSE) {             val status = runCatching { InputCodec.decodeKeyBindingResponse(payload) }.getOrNull()             Log.i(TAG, "key binding response: ${status?.status}")
auto/src/main/java/com/vayunmathur/auto/platform/MediaNowPlaying.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/platform/MediaNowPlaying.kt b/auto/src/main/java/com/vayunmathur/auto/platform/MediaNowPlaying.ktindex db466c4bfa..848e814e70 100644--- a/auto/src/main/java/com/vayunmathur/auto/platform/MediaNowPlaying.kt+++ b/auto/src/main/java/com/vayunmathur/auto/platform/MediaNowPlaying.kt@@ -20,7 +20,14 @@ data class NowPlayingInfo(     val positionMs: Long,     /** Track length in millis, or null when the session does not know it. */     val durationMs: Long?,-)+) {+    /**+     * Whether the car card shows for this snapshot: playing always shows, and+     * paused-with-a-title stays for instant resume. Idle (not playing, no+     * title) hides so the car display never shows an empty card.+     */+    fun shouldShowCard(): Boolean = playing || !title.isNullOrBlank()+}  /**  * Something the media monitor observed, forwarded to [AutoSessionState] for the phone UI.
auto/src/main/java/com/vayunmathur/auto/platform/VideoSinkChannel.kt
diff --git a/auto/src/main/java/com/vayunmathur/auto/platform/VideoSinkChannel.kt b/auto/src/main/java/com/vayunmathur/auto/platform/VideoSinkChannel.ktindex acfc17fb72..c737555d72 100644--- a/auto/src/main/java/com/vayunmathur/auto/platform/VideoSinkChannel.kt+++ b/auto/src/main/java/com/vayunmathur/auto/platform/VideoSinkChannel.kt@@ -85,10 +85,24 @@ class VideoSinkChannel(      */     private var framesOutSinceDrain = 0 -    /** Chosen from what the head unit advertised in discovery. */-    private val configuration: VideoConfiguration? =+    /**+     * Chosen from what the head unit advertised in discovery. Starts at entry 0+     * and is re-indexed by the head unit's answer in [onSetupResponse]: the+     * accepted `configurationIndicesList` entry selects into `videoConfigsList`,+     * and the head unit may pick any index -- entry 0 is only the pre-answer+     * placeholder. Written on the pump thread, read on the input thread.+     */+    @Volatile+    private var configuration: VideoConfiguration? =         service.mediaSink.videoConfigsList.firstOrNull() +    /**+     * The frame rate the stream runs at, set in [startStreaming] from the+     * accepted config (forced to 30 when the entry reports none). Restarting+     * the frame invalidator on a focus flap reuses this, never re-reads discovery.+     */+    private var negotiatedFps = DEFAULT_FRAME_RATE+     val channelId: Int get() = service.id      /**@@ -104,22 +118,38 @@ class VideoSinkChannel(     /** Wires the now-playing feed from the media monitor; see [nowPlayingSource]. */     fun setNowPlayingSource(get: () -> NowPlayingInfo?, onTap: () -> Unit) {         nowPlayingSource = NowPlayingSource(get, onTap)-        nowPlayingSource?.get()?.let { display?.setNowPlaying(it) }+        nowPlayingSource?.get()?.let { info ->+            if (info.shouldShowCard()) display?.setNowPlaying(info)+        }     }      /**      * Pushes one snapshot to the car card, if the render pair is up. The      * service calls this on every media-monitor update so the card tracks      * playback without waiting for the encoder pump.+     *+     * The [NowPlayingInfo.shouldShowCard] gate lives in the card itself; this+     * forwards unconditionally so a pause still clears a stale "Playing".      */     fun setNowPlaying(info: NowPlayingInfo) {-        display?.setNowPlaying(info)+        if (info.shouldShowCard()) {+            display?.setNowPlaying(info)+        } else {+            // Second gate: never hand an idle snapshot to a render pair that+            // came up later via [setNowPlayingSource] either. The cached source+            // still updates so resume re-shows instantly.+            display?.hideNowPlaying()+        }     }      /**      * Injects one scaled head-unit touch frame into the car UI, if the render      * pair is up. The ch8 owner scales first; this only forwards. False means      * "no display yet", and the frame is dropped rather than queued.+     *+     * Single-pointer DOWN on the now-playing card is consumed as a media+     * toggle via [handleCarTap]; everything else dispatches into the view+     * tree (app tiles, scroll) like before.      */     fun injectTouch(touch: ScaledTouch): Boolean =         display?.injectTouch(@@ -170,6 +200,21 @@ class VideoSinkChannel(     private fun onSetupResponse(payload: ByteArray) {         val response = MediaSetupResponse.parseFrom(payload)         configurationIndex = response.configurationIndicesList.firstOrNull() ?: 0+        // The answer selects INTO the offered list: re-index so geometry and+        // rate come from the entry the head unit actually accepted, not entry 0.+        // Out-of-range answers keep the discovery placeholder (entry 0).+        val offered = service.mediaSink.videoConfigsList+        logOfferedConfigs(offered, configurationIndex)+        val accepted = offered.getOrNull(configurationIndex)+        if (accepted != null) {+            configuration = accepted+        } else {+            Log.w(+                TAG,+                "head unit accepted video config index $configurationIndex " ++                    "of ${offered.size}; keeping entry 0",+            )+        }         Log.i(TAG, "head unit accepted video, config index $configurationIndex")          // Step 3: ask for the screen before starting the stream.@@ -224,7 +269,11 @@ class VideoSinkChannel(     private fun startStreaming() {         val config = configuration         val (width, height) = config?.codecResolution.dimensions()-        val frameRate = config?.frameRate?.takeIf { it > 0 } ?: DEFAULT_FRAME_RATE+        // Prefer a 30fps entry when the head unit offers one: several HUs+        // advertise 60 but only ack ~30, and the negotiated rate caps the frame+        // invalidator below. A non-positive entry falls back to 30.+        val frameRate = negotiateFrameRate(config)+        negotiatedFps = frameRate         val density = config?.density?.takeIf { it > 0 } ?: DEFAULT_DENSITY          Log.i(TAG, "starting video ${width}x$height @${frameRate} dpi $density")@@ -245,8 +294,11 @@ class VideoSinkChannel(         display = CarDisplay(context, width, height, density, trusted = trusted).also {             val source = nowPlayingSource             it.onMediaTap = source?.onTap-            source?.get()?.let(it::setNowPlaying)+            source?.get()?.let { info ->+                if (info.shouldShowCard()) it.setNowPlaying(info)+            }             it.show(surface)+            it.startFrameInvalidation(frameRate)         }         // The render pair is up: a private virtual display compositing straight into         // the encoder's input surface. Validity dump for the Phase 0 probe.@@ -366,6 +418,7 @@ class VideoSinkChannel(         mainHandler.post {             choreographer?.removeFrameCallback(vsyncCallback)             choreographer = null+            display?.stopFrameInvalidation()             display?.release()             display = null             encoder?.stop()@@ -374,6 +427,48 @@ class VideoSinkChannel(         }     } +    /**+     * Rate selection for the accepted config: its own rate wins when sane;+     * otherwise a 30fps sibling from the same offered list wins over the+     * flat 30 fallback, so a rate-less entry still streams at a sane cadence.+     * Wire truth: `VideoConfiguration.frame_rate = 2` (gal/services.proto).+     *+     * The sanity floor matters: DHU 2.0 offers `VIDEO_800x480 @1`, a bogus+     * rate it does not actually ack at. Honoring it paces both the encoder+     * hint and the frame invalidator to 1fps -- the ~1fps bug by negotiation+     * rather than starvation. Anything below [MIN_SANE_FPS] is treated as+     * "no usable rate" and overridden to 30 with a log.+     */+    private fun negotiateFrameRate(accepted: VideoConfiguration?): Int {+        accepted?.frameRate?.takeIf { it >= MIN_SANE_FPS }?.let { return it }+        val sibling = service.mediaSink.videoConfigsList.firstOrNull { it.frameRate == 30 }+        if (sibling != null) {+            Log.i(TAG, "accepted config reports no usable rate; using offered 30fps entry")+            configuration = sibling+            return 30+        }+        Log.i(+            TAG,+            "accepted config reports rate ${accepted?.frameRate}; forcing 30fps " ++                "(no 30fps sibling offered)",+        )+        return DEFAULT_FRAME_RATE+    }++    /**+     * One-line dump of every offered `video_configs[]` entry for the Phase 0+     * probe: resolution enum, rate, density, and which index the head unit+     * picked. Dev builds only; release logcat stays quiet like [dumpSurfaces].+     */+    private fun logOfferedConfigs(offered: List<VideoConfiguration>, accepted: Int) {+        if (!BuildConfig.DEV_BUILD) return+        val entries = offered.mapIndexed { index, config ->+            "$index:${config.codecResolution}:@${config.frameRate}:dpi${config.density}" ++                if (index == accepted) "*" else ""+        }+        Log.i(TAG, "offered video configs [${entries.joinToString(", ")}]")+    }+     private fun VideoResolution?.dimensions(): Pair<Int, Int> = when (this) {         VideoResolution.VIDEO_1280x720 -> 1280 to 720         VideoResolution.VIDEO_1920x1080 -> 1920 to 1080@@ -394,6 +489,13 @@ class VideoSinkChannel(         const val MEDIA_TYPE_VIDEO = 3         const val DEFAULT_FRAME_RATE = 30         const val DEFAULT_DENSITY = 160++        /**+         * Floor for an offered rate we will honor. Below this the head unit+         * is not telling the truth about its cadence (DHU 2.0 offers @1fps+         * and acks far faster), so the stream forces 30 instead.+         */+        const val MIN_SANE_FPS = 15     } }