将 otg_swift OTG 引擎迁入 Core/CameraOTG,并接入旅拍有线传图与历史导入。

恢复 USB 相机连接、边拍边传、三品牌驱动与 SwiftUI 历史导入页,通过适配层对接现有本地上传与 OSS 管道。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-06 11:22:07 +08:00
parent d7fec35715
commit be9c844bd3
50 changed files with 5721 additions and 20 deletions

View File

@ -0,0 +1,55 @@
# CameraOTG
## 模块职责
提供 USB OTG 相机有线连接能力,支持 Sony / Canon / Nikon 三品牌:
- USB 设备发现、授权、Session 管理与设备缓存重连
- 边拍边传Sony PTP、Canon EOS GetEvent、Nikon catalog 轮询)
- 相机历史照片枚举与下载(供旅拍相册历史导入页使用)
不包含 OSS 上传与后端 API上传由 `Features/TravelAlbum``WiredCameraTransferPipeline` 负责。
## 核心类型
| 类型 | 职责 |
| --- | --- |
| `ConnectionManager` | 单例ImageCaptureCore 设备发现与会话编排 |
| `ConnectionState` | 连接状态机 |
| `CameraDriver` | 品牌无关的枚举/下载协议 |
| `CameraFactory` / `PlatformDetector` | 品牌识别与 Driver 创建 |
| `OTGPhotoSink` | 照片落盘协议,由旅拍模块实现 |
| `OTGPhotoFileWriter` | scoped 本地文件写入 |
## 品牌实现
| 品牌 | 边拍边传 | 历史导入 |
| --- | --- | --- |
| Sony | `SonyRemoteCaptureService` + SDIO PTP | `SonyCameraDriver`(需 MTP 模式) |
| Canon | `CanonRemoteCaptureService` + EOS GetEvent | `CanonCameraDriver` |
| Nikon | `NikonCatalogLiveCaptureService` + catalog 监听 | `NikonCameraDriver` |
## 连接流程
1. 有线传图页 `start``ConnectionManager.configureLiveTransfer` + `start`
2. `ICDeviceBrowser` 发现相机 → 申请 contents/control 授权 → `requestOpenSession`
3. `PlatformDetector` 识别品牌 → `CameraFactory.makeDriver`
4. Sony 立即初始化 SDIO 远程会话Canon/Nikon 边拍边传在 content catalog 就绪后启动
5. 页面离开 `detach`:仅解绑 delegate保留设备缓存App 终止时 `disconnect`
## 与旅拍相册集成
- `OTGLiveTransferCoordinator` 实现 `ConnectionManagerDelegate``TravelAlbumOTGPhotoSink`
- 边拍边传落盘 → `WiredCameraTransferPipeline.ingestDownloadedAsset` → OSS 上传(边拍边传模式)
- 历史导入由 `CameraHistoryImportView` 独立 Sheet 呈现
## 依赖
- `ImageCaptureCore`(系统框架)
- `PTPUtilities` 通用 PTP 容器编解码
## 注意事项
- Sony 历史导入需 MTP 模式;边拍边传使用 PC Remote 模式(见 `SonyMTPHelpContent`
- Canon 远程模式在 catalog 就绪后初始化,避免打断 SD 卡枚举
- 不使用 ExternalAccessory / MFi仅 ImageCaptureCore