Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,20 @@ class NativeVideoDecoderTest {
val latch = java.util.concurrent.CountDownLatch(3)
val frames = java.util.concurrent.LinkedBlockingQueue<ByteArray>()
val errors = java.util.concurrent.LinkedBlockingQueue<Throwable>()
val screen = com.shilapi.xcertplay.airplay.ScreenStream(key, {}, { NativeVideoDecoder(it, platform = true) })
val loopback = java.net.InetAddress.getByName("127.0.0.1")
val screen = com.shilapi.xcertplay.airplay.ScreenStream(
key = key,
expectedPeer = loopback,
decoderFactory = { NativeVideoDecoder(it, platform = true) },
)
val port = screen.listen(object : com.shilapi.xcertplay.airplay.ScreenStream.Listener {
override fun onFrame(frame: com.shilapi.xcertplay.media.CompressedVideoFrame, pts: Long, receivedAtNs: Long, decryptNs: Long) {
frames.offer(frame.toByteArray()); latch.countDown()
}
override fun onClosed(cause: Throwable?) { if (cause != null) errors.offer(cause) }
})
try {
java.net.Socket("127.0.0.1", port).use { socket ->
java.net.Socket(loopback, port).use { socket ->
val expected = listOf(plaintext(8192), plaintext(128), plaintext(16384))
expected.forEachIndexed { index, plain ->
val length = plain.size + 16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ internal class CarPlaySourceSession(private val status: () -> String?) : Project
override val mediaOutput get() = sink
override fun touch(contacts: List<ProjectionContact>): Boolean {
if (contacts.any { it.id !in 0..1 }) return false
// The CarPlay HID device has fixed slots, even when the first finger is released.
return controller?.sendTouch((0..1).map { id ->
contacts.find { it.id == id } ?: ProjectionContact(id, 0.0, 0.0, false)
}) ?: false
// The controller preserves pointer identity and releases missing fingers at their last position.
return controller?.sendTouch(contacts) ?: false
}
override fun cancelInput(reason: ProjectionCancelReason) = touch(emptyList())
override fun setNightMode(night: Boolean) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,9 @@ class CarPlayHostActivity : ComponentActivity() {
}
}

// DiagnosticRedactor discards protocol traces; do not build them on the send path.
override val wantsTrace: Boolean get() = false

override fun onDebugLog(message: String) {
if (DiagnosticRedactor.redact(message) == null) return
runOnUiThread {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.shilapi.xcertplay.projection

import com.shilapi.xcertplay.airplay.*
import com.shilapi.xcertplay.orchestration.*
import com.shilapi.xcertplay.transport.Iap2IdentificationConfig
import java.io.ByteArrayOutputStream
import java.io.OutputStream
import java.net.Socket
import java.util.concurrent.CountDownLatch
import java.util.concurrent.ExecutorService
import java.util.concurrent.TimeUnit
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config

/** Exercise the production projection adapter as well as its controller/HID serialization. */
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [29], manifest = Config.NONE)
class CarPlayTouchPipelineTest {
@Test fun singleFingerDragCoalescesAndCancelReleasesAtItsLastPosition() {
val entered = CountDownLatch(1)
val release = CountDownLatch(1)
val bytes = ByteArrayOutputStream()
val wire = object : OutputStream() {
override fun write(b: Int) = throw UnsupportedOperationException()
override fun write(b: ByteArray, off: Int, len: Int) {
entered.countDown()
check(release.await(5, TimeUnit.SECONDS))
bytes.write(b, off, len)
}
}
val config = AirPlayConfig("test", "test", "", "1", AirPlayDisplayConfig(800, 480))
val session = AirPlaySession(Socket(), config, AirPlayIdentity.generate(), PairingStore(), null,
object : AirPlaySessionListener {}, object : AirPlayMediaHandler {})
val controller = CarPlayController(
RuntimeEnvironment.getApplication(),
CarPlayRuntimeConfig(mfiTarget = MfiTarget.LOCAL, transport = CarPlayTransport.WIRED,
identification = Iap2IdentificationConfig(name = "test", modelIdentifier = "test", manufacturer = "test",
serialNumber = "test", firmwareVersion = "1", hardwareVersion = "1", carPlayUsbInterfaceNumber = 3)),
config, AirPlayIdentity.generate(), PairingStore(), object : AirPlaySessionListener {}, object : AirPlayMediaHandler {}, {},
)
set(session, "eventSocket", object : Socket() { override fun getOutputStream() = wire })
set(session, "eventCipher", ControlCipher(ByteArray(32) { 1 }, ByteArray(32) { 2 }))
set(controller, "activeSession", session)
val projection = CarPlaySourceSession { null }.apply { bind(controller, null) }
try {
// Pointer 1 arriving by itself also verifies that the adapter does not fill pointer 0 with an up.
assertTrue(projection.touch(listOf(ProjectionContact(1, .1, .2, true))))
assertTrue(entered.await(5, TimeUnit.SECONDS))
repeat(300) { index ->
assertTrue(projection.touch(listOf(ProjectionContact(1, .2 + index * .001, .3, true))))
}
assertTrue(projection.touch(emptyList()))
release.countDown()
val executor = controller.javaClass.getDeclaredField("touchExecutor").apply { isAccessible = true }
.get(controller) as ExecutorService
executor.submit {}.get(5, TimeUnit.SECONDS)
val cipher = ControlCipher(ByteArray(32) { 2 }, ByteArray(32) { 1 })
val requests = RtspMessage.parseMessages(cipher.decrypt(bytes.toByteArray()).data).messages
assertEquals("adapter prevented move coalescing", 3, requests.size)
val reports = requests.map { (BplistCodec.decode(it.body) as Map<*, *>)["hidReport"] as ByteArray }
assertEquals(1, reports[0][1].toInt())
assertEquals(1, reports[1][1].toInt())
assertEquals(0, reports[2][1].toInt())
assertEquals(399, coordinate(reports[1], 2))
assertEquals(144, coordinate(reports[1], 4))
assertArrayEquals("cancel moved the finger to the origin", reports[1].copyOfRange(2, 6), reports[2].copyOfRange(2, 6))
} finally {
release.countDown()
session.close()
controller.close()
controller.awaitClosed(2_000)
}
}

private fun coordinate(report: ByteArray, offset: Int) =
(report[offset].toInt() and 0xff) or ((report[offset + 1].toInt() and 0xff) shl 8)

private fun set(target: Any, name: String, value: Any) {
target.javaClass.getDeclaredField(name).apply { isAccessible = true }.set(target, value)
}
}
13 changes: 13 additions & 0 deletions docs/UPSTREAM.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,16 @@ Material Components for Android 1.13.0(Apache-2.0),使用官方 Material 3
WheelPlay 实现固定 1:1 选区、图片平移/双指缩放、无障碍移动与缩放、横竖屏布局及重置;
原图坐标与窗口尺寸解耦,加载和保存由 ViewModel 管理。仅输出车厂图标所需的
1024 × 1024 PNG,不引入 crop-kit/JitPack 运行时依赖。

## CarPlay 协议首批同步(2026-11-15)

基于 WheelPlay `1c0c2b88`,对照 [DiPlay `615b32ce`](https://github.com/shihabal3amri/DiPlay/tree/615b32ce0b40cd0b99ce94ba23a512001553684f) 选择性移植以下修复。这里只表示列出的补丁已适配,不表示已经合并 DiPlay 的全部协议或媒体实现。

| 范围 | 上游提交 | WheelPlay 适配 |
| --- | --- | --- |
| 麦克风 | [`c2afb171`](https://github.com/shihabal3amri/DiPlay/commit/c2afb171)、[`9647d689`](https://github.com/shihabal3amri/DiPlay/commit/9647d689)、[`8d5fd4b2`](https://github.com/shihabal3amri/DiPlay/commit/8d5fd4b2) | 按手机的 input/上行端口识别 App 录音;非通话输入流在没有下行时等待 500 ms 开麦;未明确协商 framesPerPacket 的 PCM 采用适合 1500 字节 IPv6 MTU 的包长。保留原有 Opus RTP 时钟及浏览器麦克风路由。 |
| 触控 | [`4b5e0bb7`](https://github.com/shihabal3amri/DiPlay/commit/4b5e0bb7)、[`48c97171`](https://github.com/shihabal3amri/DiPlay/commit/48c97171)、[`ad03bf44`](https://github.com/shihabal3amri/DiPlay/commit/ad03bf44)、[`47b39a5c`](https://github.com/shihabal3amri/DiPlay/commit/47b39a5c)、[`50957d41`](https://github.com/shihabal3amri/DiPlay/commit/50957d41) | 事件 TCP_NODELAY、固定手指槽位和原位释放、合并同组手指的待发 MOVE、延迟构造 TRACE。投影适配器直接传递触点,由会话分配槽位并补发原位释放;复制输入列表并在执行时检查会话归属;实际界面声明不接收会被 DiagnosticRedactor 丢弃的 TRACE。 |
| 对端校验 | [`aeb1d733`](https://github.com/shihabal3amri/DiPlay/commit/aeb1d733) | 视频、事件和 iAP TCP 连接仅接受控制连接的同一 IP;NTP 响应仅由指定对端调整时钟;拒绝缺少认证标签的视频帧。保留原生视频解密/帧对象接口。 |
| 解析边界 | [`1759a981`](https://github.com/shihabal3amri/DiPlay/commit/1759a981)、[`a83284c5`](https://github.com/shihabal3amri/DiPlay/commit/a83284c5) 中的 iAP 包长修复 | NTB16 限制条目数、累计复制字节及 NDP 重访;iAP 非法包长立即报错。沿用 WheelPlay 既有增量 RTSP 解码器、读取期限、认证门禁和 bplist 展开预算。 |

延迟开麦使用每流独立的启动门闩,启动与替换、TEARDOWN、会话关闭串行化;取消时移除计时任务,避免旧回调重新打开麦克风。通话仍等待首个下行包,明确的 input=false 不启动 App 录音。音频流 audioType 隔离、有线启动恢复和 type-103 buffered audio 留待后续批次。
37 changes: 37 additions & 0 deletions docs/VALIDATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,3 +557,40 @@ run-1 捕获的第 12 个访问单元(索引 11)为:
- `npm run test:browser:media`:真实 Chromium 在生产 CSP 下通过 seek 能力切换、最后一次拖动位置(42.123 秒 → 42123 毫秒)、暂停状态保持、切歌后的旧 seek 回调隔离,以及既有画面/触控/重连检查。回调由测试脚本触发,未验证车机的实体按键或系统进度条 UI。
- `:mobile:lintDebug`:0 错误、18 警告;`git diff --check` 通过。
- 未安装或操作真实车机/iPhone。手机音乐应用是否执行跳转、进度回报及本地/浏览器输出的声音连续性仍需实机验收。本次复用现有 CarPlay 音频链路,未根据猜测注入 AirPlay 缓冲清空命令。

## DiPlay CarPlay 协议首批同步(2026-11-15)

从 WheelPlay `1c0c2b88` 新建 `feat/sync-diplay-carplay-batch1`,按 [来源记录](UPSTREAM.md#carplay-协议首批同步2026-11-15) 选择性同步麦克风、触控、对端校验和解析边界修复。

回归覆盖:

- App 录音按 input/上行端口启用;无下行时启动一次,通话仍等待下行;替换、TEARDOWN、会话关闭取消延迟开麦。PCM 默认包长连同 IPv6/UDP 头不超过 1500 字节;显式 framesPerPacket 及 Opus RTP 时钟继续按协商值处理。
- 阻塞事件 socket 下合并 500 次 MOVE,保留按下/抬起及多指边界;切换会话丢弃旧待发输入,拒绝执行器关闭后的提交,复制调用方触点列表。生产投影适配器直接进入同一链路,300 次拖动在阻塞解除后只产生按下、最终移动、原位释放三份加密 HID 报文。
- 视频、事件和 iAP TCP 拒绝其他 IP,拒绝者不占用正常对端连接;覆盖 IPv4、IPv6 及映射地址。NTP 只接受指定对端的时钟响应;视频帧缺少认证标签时不进入解码器。
- NTB16 拒绝 NDP 循环、过多条目及超预算重复复制,保留正常 NDP 链与非零缓冲偏移;iAP 拒绝非法长度并保留跨加密帧的增量重组。既有 pair-verify、RTSP 读取期限、bplist 展开预算和浏览器媒体路由测试继续参与全量回归。

验证命令:

```sh
./gradlew :mobile:assembleDebug :mobile:lintDebug
./gradlew :shared:testDebugUnitTest :common:testDebugUnitTest
```

结果:shared 全量 556 项、common 全量 545 项测试全部通过,均无失败、错误或跳过。Debug APK 构建通过;`lintDebug` 为 0 errors、24 warnings;`git diff --check` 通过。

本轮未连接 iPhone 或车机,未测量实际触控延迟或验证真实 App 录音;上游设备报告不作为 WheelPlay 真机验证结果。

## 首批同步的 CI 仪器测试编译补验(2026-11-15)

[PR #61 首次构建](https://github.com/fython/wheelplay/actions/runs/43681265193/job/132712212254) 在 `:common:compileDebugAndroidTestKotlin` 失败:`ScreenStream` 增加必填的 `expectedPeer` 后,`NativeVideoDecoderTest` 仍使用旧的位置参数,导致两个 lambda 分别被解析为错误的参数类型。此前的 APK/lint 和 JVM 单元测试验证没有包含仪器测试 APK 的编译。

测试现在通过命名参数提供预期的 IPv4 loopback 对端和原生解码器工厂,并使用同一个地址建立发送 socket。先在本地运行 `:common:compileDebugAndroidTestKotlin` 复现两处类型错误,再按 `.github/workflows/debug-build.yml` 的完整构建任务补验,全部通过:

```sh
./gradlew --build-cache :projection-plugin-api:assembleRelease \
:projection-plugin-sample:lintDebug :projection-plugin-sample:assembleDebug \
:common:assembleDebugAndroidTest :mobile:lintDebug :mobile:assembleDebug \
:mobile:assembleDebugAndroidTest
```

结果包含插件 SDK、示例 APK、mobile APK、common/mobile 仪器测试 APK 及两项 lint;这是编译和打包验证,仪器测试的 Android 运行结果由远端 CI 单独记录。
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object AirPlayHid {
const val MEDIA_HID_UID = 0x2a2a2a2c
const val TELEPHONY_HID_UID = 0x2a2a2a2d

private const val TOUCH_CONTACTS = 2
internal const val TOUCH_CONTACTS = 2
private const val BYTES_PER_FINGER = 6

fun touchHidDevice(xMax: Int, yMax: Int, displayUuid: String): Map<String, Any?> =
Expand All @@ -35,12 +35,13 @@ object AirPlayHid {
fun telephonyHidDevice(displayUuid: String): Map<String, Any?> =
hidDeviceEntry(TELEPHONY_HID_UID, "xcertplay Telephony", telephonyDescriptor, displayUuid)

/** Contacts use the stable slot ids assigned by AirPlayTouchSlots. */
fun touchReport(contacts: List<AirPlayContact>): ByteArray {
val report = ByteArray(BYTES_PER_FINGER * TOUCH_CONTACTS)
for (slot in 0 until TOUCH_CONTACTS) {
val offset = slot * BYTES_PER_FINGER
report[offset] = slot.toByte()
val contact = contacts.getOrNull(slot) ?: continue
val contact = contacts.firstOrNull { it.id == slot } ?: continue
report[offset + 1] = if (contact.down) 0x01 else 0x00
writeU16Le(report, offset + 2, Math.round(contact.x.coerceAtLeast(0.0)).toInt())
writeU16Le(report, offset + 4, Math.round(contact.y.coerceAtLeast(0.0)).toInt())
Expand Down
Loading
Loading