Skip to content

Bring PS5 GTA6 to 120FPS with DLSS 5. An advanced Windows video player and capture enhancement tool featuring real-time preview for videos, images, and capture card sources. Combine AI-powered Super Resolution, DLSS5 image enhancement, and Frame Generation to deliver a next-generation visual experience.

C++

fix(remoteplay): preserve controller events and add gyro calibration

Veyra Goal Agent30694da6bae9
diff --git a/apps/veyra/ui/AppShell.cpp b/apps/veyra/ui/AppShell.cpp
index fe4a92d9..832aabb0 100644
--- a/apps/veyra/ui/AppShell.cpp
+++ b/apps/veyra/ui/AppShell.cpp
@@ -39,6 +39,7 @@ enum {Open=101,Play,Stop,Save,Nr,Sr,Fg,Seek,Info,Capture,Export,Realtime,Recent,
veyra::engine::EngineController engine;
#ifdef VEYRA_ENABLE_REMOTEPLAY
veyra::remoteplay::ControllerInput remoteController;
+bool remoteViewOnly=false;
#endif
veyra::engine::ExportJobManager exportJob;
veyra::ui::UiSessionState uiState;
@@ -324,10 +325,16 @@ case Split:compareMode=compareMode==2?0:2;updateComparison();break;
case Reference:referenceBase=SendDlgItemMessageW(hwnd,Reference,CB_GETCURSEL,0,0)==1;updateComparison();break;
case Settings:if(uiState.mode==veyra::ui::Mode::Daily)switchMode();selectInspector(0);break;
#ifdef VEYRA_ENABLE_REMOTEPLAY
-case RemotePlay:veyra::ui::showRemotePlayPanel(hwnd,[](veyra::source::RemotePlayConnectDesc desc){cancelProtection();if(!desc.request.viewOnly){if(!remoteController.start())veyra::log::warn("remoteplay-input","SDL gamepad initialization failed");startShellTimer(mainWindow,ControllerTimer,8);}else{KillTimer(mainWindow,ControllerTimer);remoteController.stop();}currentFile=L"remoteplay:";subtitles.clear();paused=false;engine.previewView({});engine.openRemotePlay(video,std::move(desc),options());SetWindowTextW(mainWindow,L"Veyra — PS5 Remote Play");layout();},[](std::string pin){engine.remotePlayLoginPin(std::move(pin));},[]{auto s=engine.snapshot();veyra::ui::RemotePlayPanelStatus result;
+case RemotePlay:veyra::ui::showRemotePlayPanel(hwnd,[](veyra::source::RemotePlayConnectDesc desc){cancelProtection();remoteViewOnly=desc.request.viewOnly;if(!desc.request.viewOnly){if(!remoteController.start())veyra::log::warn("remoteplay-input","SDL gamepad initialization failed");startShellTimer(mainWindow,ControllerTimer,8);}else{KillTimer(mainWindow,ControllerTimer);remoteController.stop();}currentFile=L"remoteplay:";subtitles.clear();paused=false;engine.previewView({});engine.openRemotePlay(video,std::move(desc),options());SetWindowTextW(mainWindow,L"Veyra — PS5 Remote Play");layout();},[](std::string pin){engine.remotePlayLoginPin(std::move(pin));},[]{auto s=engine.snapshot();veyra::ui::RemotePlayPanelStatus result;
result.active=s.remotePlay&&(s.running||s.transport==veyra::engine::TransportState::Opening||s.transport==veyra::engine::TransportState::Stopping);
- result.message=s.failed?s.status:s.remotePlay&&s.running?L"PS5 画面已进入播放。点击播放器窗口后手柄生效;关闭此面板不停止串流。":result.active?s.status:L"PS5 串流已停止,可以重新连接。";return result;
-},[]{engine.stop();});break;
+ result.message=s.failed?s.status:s.remotePlay&&s.running?L"PS5 画面已进入播放;关闭此面板不停止串流。":result.active?s.status:L"PS5 串流已停止,可以重新连接。";
+ if(s.remotePlay&&s.running){
+ const auto c=remoteController.capabilities();
+ if(remoteViewOnly)result.message+=L"\n仅观看:电脑输入已关闭,手柄由 PS5 处理。";
+ else if(!c.connected)result.message+=L"\n未检测到电脑手柄。";
+ else result.message+=std::format(L"\n陀螺仪 {} · 触摸板 {} · 扳机 {} · 触觉 {}{}",c.gyro&&c.accel?L"已启用":L"不可用",c.touch?L"可用":L"不可用",c.triggers?L"已接入":L"不可用",c.haptics?L"端点已打开":L"未打开",c.calibrating?L" · 校准中(返回播放器静置)":L"");
+ }return result;
+},[]{engine.stop();},[]{return remoteController.calibrate();});break;
#endif
case Capture:case ProRailCapture:veyra::ui::showCapturePanel(hwnd,[](const std::wstring& path){openFile(path);layout();});break;
case Export:if(uiState.mode==veyra::ui::Mode::Professional)startVideoExport(false);break;
diff --git a/apps/veyra/ui/RemotePlayPanel.cpp b/apps/veyra/ui/RemotePlayPanel.cpp
index 512a778d..ddad62bb 100644
--- a/apps/veyra/ui/RemotePlayPanel.cpp
+++ b/apps/veyra/ui/RemotePlayPanel.cpp
@@ -11,7 +11,8 @@
namespace veyra::ui {
namespace {
HWND window=nullptr;HFONT font=nullptr;
-enum {Host=1,Account,PairPin,Quality,CodecChoice,Pair,Connect,Cancel,Scan,Wake,LoginPin,SendPin,StatusText,Help,Bitrate,Forget,ViewOnly};
+enum {Host=1,Account,PairPin,Quality,CodecChoice,Pair,Connect,Cancel,Scan,Wake,LoginPin,SendPin,StatusText,Help,Bitrate,Forget,ViewOnly,Calibrate};
+std::function<bool()> calibrate;
std::function<void(source::RemotePlayConnectDesc)> connect;
std::function<void(std::string)> login;
std::function<RemotePlayPanelStatus()> connectionStatus;std::function<void()> disconnect;bool watching=false;
@@ -77,7 +78,7 @@ void arrange(){
move(Quality,160,150,220,150);move(CodecChoice,392,150,160,150);
move(Connect,160,199,180,36);move(Wake,352,199,200,36);
move(LoginPin,160,250,180,28);move(SendPin,352,250,200,30);
- move(Bitrate,160,295,180,180);move(Forget,352,295,80,32);move(Cancel,440,295,112,32);move(StatusText,20,341,530,64);move(ViewOnly,20,408,530,28);move(Help,20,442,530,86);
+ move(Bitrate,160,295,180,180);move(Forget,352,295,80,32);move(Cancel,440,295,112,32);move(StatusText,20,341,530,64);move(ViewOnly,20,408,400,28);move(Calibrate,432,408,120,28);move(Help,20,442,530,86);
}
LRESULT CALLBACK proc(HWND h,UINT msg,WPARAM wp,LPARAM lp){switch(msg){
case WM_CREATE:{window=h;closing=false;font=makeFont(h);titleTheme(h);
@@ -86,6 +87,7 @@ case WM_CREATE:{window=h;closing=false;font=makeFont(h);titleTheme(h);
SendMessageW(c,WM_SETFONT,WPARAM(font),TRUE);themeControl(c);return c;
};
add(L"BUTTON",L"仅观看(手柄连接 PS5;更改后需重新连接)",ViewOnly,BS_AUTOCHECKBOX|WS_TABSTOP);
+ add(L"BUTTON",L"校准陀螺仪",Calibrate,BS_PUSHBUTTON|WS_TABSTOP);
add(L"STATIC",L"PS5 地址",100,0,20,21,130,25);add(L"STATIC",L"PSN Account ID",101,0,20,65,130,25);
add(L"STATIC",L"8 位配对码",102,0,20,109,130,25);add(L"STATIC",L"串流格式",103,0,20,153,130,25);add(L"STATIC",L"登录 PIN(可选)",104,0,20,253,135,25);
add(L"STATIC",L"码率",105,0,20,298,130,25);add(L"COMBOBOX",L"",Host,CBS_DROPDOWN|CBS_AUTOHSCROLL|WS_TABSTOP);SendDlgItemMessageW(h,Host,CB_LIMITTEXT,253,0);
@@ -103,6 +105,7 @@ case WM_CREATE:{window=h;closing=false;font=makeFont(h);titleTheme(h);
case WM_TIMER:if(busy&&done){if(worker.joinable())worker.join();busy=false;Outcome result;{std::lock_guard lock(mutex);result=std::move(outcome);}if(!result.savedPath.empty()){currentProfile=result.savedPath;refreshProfiles();}buttons();SetDlgItemTextW(h,StatusText,result.message.c_str());if(!result.hosts.empty())SetDlgItemTextW(h,Host,std::wstring(result.hosts[0].host.begin(),result.hosts[0].host.end()).c_str());if(closing)DestroyWindow(h);}
if(window&&watching&&!busy){auto state=connectionStatus();SetDlgItemTextW(h,StatusText,state.message.c_str());SetDlgItemTextW(h,Cancel,state.active?L"断开连接":L"取消操作");EnableWindow(GetDlgItem(h,Cancel),state.active);if(!state.active)watching=false;}return 0;
case WM_COMMAND:switch(LOWORD(wp)){
+ case Calibrate:if(calibrate&&calibrate())MessageBoxW(h,L"将手柄平放并保持静止,关闭此提示后返回播放器。\n采集 120 个稳定样本完成校准;10 秒内不稳定则保留原校准。",L"陀螺仪校准",MB_OK);else MessageBoxW(h,L"请先连接串流及带陀螺仪的电脑手柄。仅观看模式不使用电脑手柄。",L"无法校准",MB_OK);break;
case Host:if(HIWORD(wp)==CBN_SELCHANGE&&!busy){const auto index=SendDlgItemMessageW(h,Host,CB_GETCURSEL,0,0);if(index>=0&&size_t(index)<profiles.size()){currentProfile=profiles[size_t(index)].path;loadSelection();}}break;
case Forget:if(!busy&&!currentProfile.empty()){std::error_code ec;const bool removed=std::filesystem::remove(currentProfile,ec);if(removed){currentProfile.clear();refreshProfiles();if(profiles.empty()){SetDlgItemTextW(h,Account,L"");SetDlgItemTextW(h,Host,L"");}SetDlgItemTextW(h,StatusText,L"配对已删除。现有串流会保留;下次连接需选择其他主机或重新配对。");}else SetDlgItemTextW(h,StatusText,L"删除失败,请检查文件权限。");}break;
case Pair:{if(busy)break;auto host=ascii(Host),id=ascii(Account),pin=ascii(PairPin);auto account=remoteplay::accountIdFromBase64(id);if(!account)account=remoteplay::accountIdFromDecimal(id);
@@ -124,7 +127,8 @@ case WM_DESTROY:if(worker.joinable()){worker.request_stop();worker.join();}KillT
case WM_SIZE:arrange();return 0;
}return DefWindowProcW(h,msg,wp,lp);}
}
-void showRemotePlayPanel(HWND parent,std::function<void(source::RemotePlayConnectDesc)> start,std::function<void(std::string)> pin,std::function<RemotePlayPanelStatus()> status,std::function<void()> stop){
+void showRemotePlayPanel(HWND parent,std::function<void(source::RemotePlayConnectDesc)> start,std::function<void(std::string)> pin,std::function<RemotePlayPanelStatus()> status,std::function<void()> stop,std::function<bool()> calibration){
+ calibrate=std::move(calibration);
connect=std::move(start);login=std::move(pin);connectionStatus=std::move(status);disconnect=std::move(stop);if(window){SetForegroundWindow(window);return;}
WNDCLASSW wc{};wc.lpfnWndProc=proc;wc.hInstance=GetModuleHandleW(nullptr);wc.lpszClassName=L"VeyraRemotePlaySetup";wc.hbrBackground=panelBrush();wc.hCursor=LoadCursorW(nullptr,IDC_ARROW);RegisterClassW(&wc);
CreateWindowExW(WS_EX_TOOLWINDOW,wc.lpszClassName,L"PS5 · Remote Play",WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_VISIBLE,CW_USEDEFAULT,CW_USEDEFAULT,dip(parent,590),dip(parent,580),parent,nullptr,wc.hInstance,nullptr);
diff --git a/apps/veyra/ui/RemotePlayPanel.h b/apps/veyra/ui/RemotePlayPanel.h
index 80ea98ee..74eb5753 100644
--- a/apps/veyra/ui/RemotePlayPanel.h
+++ b/apps/veyra/ui/RemotePlayPanel.h
@@ -6,5 +6,5 @@ namespace veyra::ui {
struct RemotePlayPanelStatus {std::wstring message;bool active=false;};
void showRemotePlayPanel(HWND,
std::function<void(source::RemotePlayConnectDesc)>,std::function<void(std::string)>,
- std::function<RemotePlayPanelStatus()>,std::function<void()>);
+ std::function<RemotePlayPanelStatus()>,std::function<void()>,std::function<bool()>);
}
diff --git a/docs/REMOTEPLAY_COLOR_UI_CONTROLLER_REPAIR_PLAN_2026-09-12.md b/docs/REMOTEPLAY_COLOR_UI_CONTROLLER_REPAIR_PLAN_2026-09-12.md
index 60b3e093..241b9ab0 100644
--- a/docs/REMOTEPLAY_COLOR_UI_CONTROLLER_REPAIR_PLAN_2026-09-12.md
+++ b/docs/REMOTEPLAY_COLOR_UI_CONTROLLER_REPAIR_PLAN_2026-09-12.md
@@ -81,6 +81,10 @@ ControllerInput.cpp只读普通按钮/摇杆/扳机和Touchpad按钮;没有启
完成标准包含用户新要求的完整手柄路径,不能以“基础连接成功”宣布整体完成。图像发灰目前是用户观察且有可疑曲线链路,未取得根因结论;timer冲突是静态代码确定的缺陷。当前未做新的设备控制/图像抓取或产品修改。硬解/公网/HDR不是此轮先决条件;软件解码性能满意时先保颜色和游戏功能。Account ID内置获取流程另保留待办,不能为获得租赁账号信息要求密码。
+## 2026-09-12 执行结论
+
+本计划已进入修复并完成本轮交付,非仅规划。timer、真实速率、PS5显示曲线、双指/运动输入、反馈、校准与仅观看实现及测试见[施工记录](REMOTEPLAY_REPAIR_PROGRESS_2026-09-12.md)。用户反馈“可以了,我测试了没问题”;硬件覆盖边界按施工记录保留,不能扩展为所有设备全部验收。旧段落中的“尚未修改/待开始”仅表示排查时点。没有发布。
+
## 参考与复用边界
- 本地固定chiaki提交0e16950165f06e5c3291537c2eeba6e852be7120的gui/src/streamsession.cpp、controller实现及lib/include/chiaki/controller.h/session.h。复用时保留AGPL/OpenSSL exception及归因,不照抄Qt窗口/第二套播放循环。
diff --git a/docs/REMOTEPLAY_PS5_ACCEPTANCE_2026-09-11.md b/docs/REMOTEPLAY_PS5_ACCEPTANCE_2026-09-11.md
index d0707fb6..c1ab3f2f 100644
--- a/docs/REMOTEPLAY_PS5_ACCEPTANCE_2026-09-11.md
+++ b/docs/REMOTEPLAY_PS5_ACCEPTANCE_2026-09-11.md
@@ -1,5 +1,7 @@
# PS5 串流实机验收
+2026-09-12:用户已确认连接、基本增强及本轮修复测试没问题。当前修复/证据与未覆盖场景见[施工记录](REMOTEPLAY_REPAIR_PROGRESS_2026-09-12.md)。PS5面板支持仅观看与陀螺仪校准;校准时平放手柄并返回播放器,等待120个稳定样本。仅观看需要重新连接,不承诺绕过PS5账号占用规则。
+
开发分支 `agent/remoteplay-integration` 的本机测试版;不是已发布的0.0.4便携包。
## 打开哪个程序
diff --git a/docs/REMOTEPLAY_REPAIR_PROGRESS_2026-09-12.md b/docs/REMOTEPLAY_REPAIR_PROGRESS_2026-09-12.md
index 70d4ccd6..36b9a283 100644
--- a/docs/REMOTEPLAY_REPAIR_PROGRESS_2026-09-12.md
+++ b/docs/REMOTEPLAY_REPAIR_PROGRESS_2026-09-12.md
@@ -1,5 +1,9 @@
# PS5 目标模式施工进度
+## 当前结论(2026-09-12,节点二)
+
+用户在收到《羊蹄山之魂》实测请求后反馈:“可以了,我测试了没问题”。记录为本轮用户实机验收通过,不推断为蓝牙/多设备/仅观看账号共存逐项通过。以下节点一的待办是当时状态;本节与末尾节点二记录优先。未发布、未推送。
+
基线计划提交325b9e9,tag checkpoint/ps5-full-repair-2026-09-12。用户指定《羊蹄山之魂》实测。目标仍active,未发布。
## 节点一实现
@@ -30,3 +34,29 @@
真实游戏反馈、仅观看主机直连、USB/蓝牙拔插与完整效果路由、gyro静止偏移校准、触摸短边沿与传感器事件采样、设备能力显示、同源视觉对照、暂停与网络恢复。不能声称全部手柄功能实机通过。用户已收到测试请求,需打开新测试版供测试;没有发布。
UI已通过但完整控制器仍需上述收口。后续修改不要基于本页把未验收项误标完成。外部SDK/runtime不入Git。
+
+## 节点二:输入事件、校准与交付存档
+
+- SDL事件保留双指down/move/up,16项有界触点队列;同次UI采样内的按下/抬起分次传出。动作与触摸按键独立。
+- gyro/accel使用SDL事件时间与最多16项批次;Chiaki跳过重复时间戳,防止同一快照重复积分。时间断点重置姿态。单位仍为rad/s与g。
+- PS5面板增加陀螺仪校准:返回播放器后开始计时,120个稳定样本估计静止偏移;运动样本清空积累,10秒超时保留原值。换设备清理校准。能力状态显示传感器、触摸板、扳机路径和真实触觉端点打开状态;仅观看不再提示电脑手柄生效。
+- UI至解码owner不再只覆盖最新ControllerState:16项有界队列保留边沿和传感器批次,4ms发送机会,100ms过期上限。失焦/断开使用独立inputActive状态立即清空排队动作;正常抬指不被误判为失焦。溢出先释放再发最新状态,记录警告。
+- 修复手柄重连时重复初始化SDL音频子系统导致引用计数累加。
+- 最终校准超时修正在用户实测版本之后,仅改变校准计时起点;最终二进制另经自动回归,不冒充用户重新测试过该二进制。
+
+### 本节点实际执行
+
+命令脚本均在out/remoteplay/audit-20260911(忽略目录);测试使用scripts/run-short-test.ps1的30秒单项上限。
+
+- build-product.cmd -> logs/ps5-input-accepted-build.log:成功。此前ps5-input-events/queue/calibration-build发生LNK1104,因为正在运行的veyra.exe被锁;正常关闭已结束测试的窗口后链接成功,没有强杀。
+- build-native-source.cmd -> logs/ps5-input-accepted-native-build.log:20/20;build-off-check.cmd -> logs/ps5-input-accepted-off-build.log:成功。
+- boundary默认/--virtual -> logs/ps5-input-accepted-boundary.stdout.log、ps5-input-accepted-virtual.stdout.log:exit0。覆盖输入跨线程边沿、失焦清队、过期/容量、双指短触、传感器单位及静止校准、反馈容量;虚拟输入不连接PS5。
+- ctest --test-dir out/remoteplay/audit-20260911/native-source-repair --output-on-failure --timeout 30 -> logs/ps5-input-accepted-ctest.log:69/69,0.50秒。
+- veyra_remoteplay_source_tests(single、reorder.h264、hevc三个夹具)-> logs/ps5-input-accepted-source.stdout.log:exit0。
+- scripts/remoteplay/test-ui.ps1 -> logs/ps5-input-accepted-ui:20次模式动画及20次全屏切换、面板开关和无效配对拒绝通过,截图复查布局正常。
+- 最终out/remoteplay/product-repair/veyra.exe SHA256:BCF9A2E98BD0E5553FE9A9772FEAC7F4226360A41127B4A573C3B5E4ACF3B86A。
+- 本节点未改颜色/GPU增强。节点一真实D3D12颜色夹具与47.45秒delivery证据仍单独保留,没有重复运行或冒充当前实机逐项验证。
+
+### 验证边界
+
+用户确认本次测试没问题。本轮修复交付收尾;不把未报告的场景列为已通过。蓝牙完整触觉、多手柄与多音频端点、中文端点命名、仅观看同账号/第二账号共存、网络断续/休眠恢复和同源视觉定量对照仍需对应设备/场景验证。当前触觉只自动选择唯一手柄及唯一匹配名称的四声道端点;歧义不自动路由,不能承诺多设备或蓝牙与USB等价。后续唯一优先任务:若用户在其他连接方式复现问题,按设备及日志补对应能力适配;不重新改已验收链路,不自动发布。
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index b2bf0056..af8d0fe3 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -1648,3 +1648,9 @@ FRUC候选bSkipWarp/延后重建/时间归零/首对预热均未通过新增rese
## 2026-09-12 目标模式施工节点一
用户已授权施工。timer/真实FPS、PS5显示曲线、sensor/touch/反馈与仅观看初步实现已构建,ON/OFF、69项native、SDL虚拟输入、20+20实际UI切换、GPU灰阶色块及完整delivery47.45秒通过。命令、真实失败、日志、哈希与剩余问题见 docs/REMOTEPLAY_REPAIR_PROGRESS_2026-09-12.md。完整实机、校准/事件与设备路由仍在继续,目标未完成,无发布。
+
+## 2026-09-12 PS5修复收尾与用户验收
+
+补齐SDL触摸事件/传感器批次、120样本静止校准、16项/100ms跨线程输入队列、失焦立即释放、能力状态与音频子系统引用计数修复。用户反馈“可以了,我测试了没问题”;未逐项覆盖的蓝牙/多设备/主机直连账号共存等如实保留。最终校准超时起点修正另经自动测试。
+
+build-product/native-source/off-check成功;boundary默认与virtual、H264/H265 source成功,CTest69/69(0.50s),实际20+20 UI切换通过。运行中的EXE导致LNK1104,正常关闭后重建成功。完整命令、日志、SHA256、用户验收与自动验证边界见 docs/REMOTEPLAY_REPAIR_PROGRESS_2026-09-12.md 节点二。本地Git存档,不push/release;源码无SDK/DLL/模型/凭据。
diff --git a/docs/remoteplay/NEXT_AGENT.md b/docs/remoteplay/NEXT_AGENT.md
index ce3f2d06..18752a01 100644
--- a/docs/remoteplay/NEXT_AGENT.md
+++ b/docs/remoteplay/NEXT_AGENT.md
@@ -1,5 +1,7 @@
# Remote Play 接续入口
+2026-09-12最新:[PS5颜色/UI/手柄修复记录](../REMOTEPLAY_REPAIR_PROGRESS_2026-09-12.md)。真实PS5连接和基本增强已由用户确认;本轮修复后用户再次反馈“测试了没问题”。下方“下一步首次连接”是历史状态,不要重新当阻塞。保留蓝牙、多设备、仅观看账号共存等未逐项验证边界;本次不发布。
+
最新实现与测试证据见 [修复执行记录](../REMOTEPLAY_REPAIR_EXECUTION_2026-09-11.md),用户操作见 [PS5实机验收](../REMOTEPLAY_PS5_ACCEPTANCE_2026-09-11.md)。
本机分支 `agent/remoteplay-integration`。修复前存档 `bf21bef`;源层修复 `8827721`;产品集成节点 `9e5c034` / `checkpoint/remoteplay-product-integrated-2026-09-11`。最终验收文档提交之后以 `git log -5` 为准。
diff --git a/include/veyra/remoteplay/ControllerInput.h b/include/veyra/remoteplay/ControllerInput.h
index 1c386440..8d182e38 100644
--- a/include/veyra/remoteplay/ControllerInput.h
+++ b/include/veyra/remoteplay/ControllerInput.h
@@ -1,5 +1,6 @@
#pragma once
#include "Types.h"
+#include <deque>
struct SDL_Gamepad;
struct SDL_AudioStream;
namespace veyra::remoteplay {
@@ -12,7 +13,10 @@ public:
ControllerState poll(bool focused);
void feedback(ControllerFeedback,bool focused);
void releaseEffects();
+ bool calibrate();
bool connected()const{return gamepad_!=nullptr;}
+ struct Capabilities {bool connected=false,gyro=false,accel=false,touch=false,triggers=false,haptics=false,calibrating=false;};
+ Capabilities capabilities()const;
private:
SDL_Gamepad* gamepad_=nullptr;
bool initialized_=false;
@@ -20,6 +24,12 @@ private:
std::array<int8_t,2> touchIds_{-1,-1};uint8_t nextTouchId_=0;
bool gyro_=false,accel_=false,effectsActive_=false,audioInitialized_=false,hapticAttempted_=false;
SDL_AudioStream* hapticStream_=nullptr;
+ std::array<ControllerState::Touch,2> touchState_{};
+ std::deque<std::array<ControllerState::Touch,2>> touchQueue_;
+ std::array<float,3> gyroBias_{},biasSum_{},sensorGyro_{},sensorAccel_{0,1,0};
+ unsigned calibrationSamples_=0;bool calibrating_=false,haveGyro_=false,haveAccel_=false;
+ HostTime calibrationStart_=0;uint64_t sensorStamp_=0;
+
};
}
diff --git a/include/veyra/remoteplay/Types.h b/include/veyra/remoteplay/Types.h
index 3a03b1ed..66a01f23 100644
--- a/include/veyra/remoteplay/Types.h
+++ b/include/veyra/remoteplay/Types.h
@@ -89,6 +89,7 @@ struct ControllerFeedback {
}
};
struct ControllerState {
+ bool inputActive=false; // Distinguishes a released button/touch from focus/device loss.
// Semantic buttons; translated explicitly to Chiaki in the native bridge.
enum Button : std::uint32_t { Cross=1u<<0, Circle=1u<<1, Square=1u<<2, Triangle=1u<<3,
Left=1u<<4, Right=1u<<5, Up=1u<<6, Down=1u<<7, L1=1u<<8, R1=1u<<9,
@@ -101,6 +102,8 @@ struct ControllerState {
// SDL coordinate frame: angular velocity rad/s, acceleration in g.
std::array<float,3> gyro{},accel{0,1,0};
uint64_t motionTimestampUs=0;bool motionValid=false;
+ struct MotionSample {std::array<float,3> gyro{},accel{0,1,0};uint64_t timestampUs=0;bool operator==(const MotionSample&)const=default;};
+ std::array<MotionSample,16> motionSamples{};uint8_t motionSampleCount=0;
bool operator==(const ControllerState&) const = default;
};
} // namespace veyra::remoteplay
diff --git a/include/veyra/source/RemotePlaySessionSource.h b/include/veyra/source/RemotePlaySessionSource.h
index 336ca640..0855aec7 100644
--- a/include/veyra/source/RemotePlaySessionSource.h
+++ b/include/veyra/source/RemotePlaySessionSource.h
@@ -2,6 +2,7 @@
#include "RemotePlaySource.h"
#include "veyra/sink/CaptureAudioSession.h"
#include <condition_variable>
+#include <deque>
#include <mutex>
#include <thread>
@@ -33,6 +34,7 @@ private:
friend struct RemotePlaySessionSourceTestAccess;
void publishDecoded(const AVFrame*,pipeline::FramePacket,const SourceInfo&);
void run(std::stop_token, RemotePlayConnectDesc);
+ remoteplay::ControllerState takeControllerLocked(remoteplay::HostTime now);
struct Frame { std::shared_ptr<AVFrame> frame; pipeline::FramePacket packet; SourceInfo info; };
mutable std::mutex mutex_;
std::condition_variable ready_;
@@ -43,6 +45,7 @@ private:
SourceInfo info_, publishedInfo_;
remoteplay::SessionInbox::Snapshot snapshot_;
remoteplay::ControllerState controller_;
+ std::deque<std::pair<remoteplay::HostTime,remoteplay::ControllerState>> pendingControllers_;
remoteplay::HostTime controllerStamp_=0;
std::string pin_;
uint64_t skipped_=0;
diff --git a/src/remoteplay/ChiakiBackend.cpp b/src/remoteplay/ChiakiBackend.cpp
index a984617e..3b6c0767 100644
--- a/src/remoteplay/ChiakiBackend.cpp
+++ b/src/remoteplay/ChiakiBackend.cpp
@@ -230,15 +230,16 @@ BackendResult ChiakiBackend::submitController(const ControllerState& state){
{ControllerState::Touchpad,CHIAKI_CONTROLLER_BUTTON_TOUCHPAD},{ControllerState::PS,CHIAKI_CONTROLLER_BUTTON_PS}};
for(auto b:buttons)if(state.buttons&b.semantic)c.buttons|=static_cast<std::uint32_t>(b.target);
for(size_t i=0;i<state.touches.size();++i){c.touches[i].id=state.touches[i].id;c.touches[i].x=state.touches[i].x;c.touches[i].y=state.touches[i].y;}
- const bool validMotion=state.motionValid&&std::all_of(state.gyro.begin(),state.gyro.end(),[](float v){return std::isfinite(v);})&&std::all_of(state.accel.begin(),state.accel.end(),[](float v){return std::isfinite(v);});
- if(validMotion){
- if(!p_->lastMotion||state.motionTimestampUs<p_->lastMotion||state.motionTimestampUs-p_->lastMotion>100000){
- chiaki_orientation_tracker_init(&p_->orientation);chiaki_accel_new_zero_set_inactive(&p_->accelZero,false);
- }
- if(state.motionTimestampUs!=p_->lastMotion){
- chiaki_orientation_tracker_update(&p_->orientation,state.gyro[0],state.gyro[1],state.gyro[2],state.accel[0],state.accel[1],state.accel[2],&p_->accelZero,false,uint32_t(state.motionTimestampUs));
- p_->lastMotion=state.motionTimestampUs;
- }
+ const auto applyMotion=[&](const std::array<float,3>& gyro,const std::array<float,3>& accel,uint64_t timestamp){
+ if(!timestamp||!std::all_of(gyro.begin(),gyro.end(),[](float v){return std::isfinite(v);})||!std::all_of(accel.begin(),accel.end(),[](float v){return std::isfinite(v);}))return;
+ // Repeated state snapshots contain the same batch; never integrate twice.
+ if(p_->lastMotion&&timestamp<=p_->lastMotion)return;
+ if(!p_->lastMotion||timestamp-p_->lastMotion>100000){chiaki_orientation_tracker_init(&p_->orientation);chiaki_accel_new_zero_set_inactive(&p_->accelZero,false);}
+ chiaki_orientation_tracker_update(&p_->orientation,gyro[0],gyro[1],gyro[2],accel[0],accel[1],accel[2],&p_->accelZero,false,uint32_t(timestamp));p_->lastMotion=timestamp;
+ };
+ if(state.motionValid){
+ for(size_t i=0;i<std::min(size_t(state.motionSampleCount),state.motionSamples.size());++i){const auto& sample=state.motionSamples[i];applyMotion(sample.gyro,sample.accel,sample.timestampUs);}
+ applyMotion(state.gyro,state.accel,state.motionTimestampUs);
chiaki_orientation_tracker_apply_to_controller_state(&p_->orientation,&c);
}else p_->lastMotion=0;
c.l2_state=state.l2;c.r2_state=state.r2;c.left_x=state.leftX;c.left_y=state.leftY;c.right_x=state.rightX;c.right_y=state.rightY;
diff --git a/src/remoteplay/ControllerInput.cpp b/src/remoteplay/ControllerInput.cpp
index 437fbd58..d11aa608 100644
--- a/src/remoteplay/ControllerInput.cpp
+++ b/src/remoteplay/ControllerInput.cpp
@@ -21,6 +21,7 @@ bool ControllerInput::start(uint32_t preferredDevice){
void ControllerInput::stop(){
releaseEffects();if(hapticStream_){SDL_DestroyAudioStream(hapticStream_);hapticStream_=nullptr;}
if(audioInitialized_){SDL_QuitSubSystem(SDL_INIT_AUDIO);audioInitialized_=false;}hapticAttempted_=false;
+ touchQueue_.clear();touchState_={};haveGyro_=haveAccel_=false;calibrating_=false;gyroBias_={};enumerateAt_=0;
if(gamepad_){SDL_CloseGamepad(gamepad_);gamepad_=nullptr;}
if(initialized_){SDL_QuitSubSystem(SDL_INIT_GAMEPAD);initialized_=false;}
}
@@ -29,20 +30,58 @@ ControllerState ControllerInput::poll(bool focused){
SDL_PumpEvents();SDL_UpdateGamepads();
// Only this module initializes SDL; drain its input events rather than
// accumulating an unconsumed second application event queue.
- SDL_Event event;while(SDL_PollEvent(&event)){} // state queries below consume current sensor/touch state
+
if(gamepad_&&!SDL_GamepadConnected(gamepad_)){releaseEffects();if(hapticStream_){SDL_DestroyAudioStream(hapticStream_);hapticStream_=nullptr;}hapticAttempted_=false;SDL_CloseGamepad(gamepad_);gamepad_=nullptr;enumerateAt_=0;}
const auto now=monotonic100ns();
if(!gamepad_&&now>=enumerateAt_){
int count=0;auto* ids=SDL_GetGamepads(&count);
for(int i=0;i<count&&!gamepad_;++i)if(!preferredDevice_||ids[i]==preferredDevice_)gamepad_=SDL_OpenGamepad(ids[i]);
if(gamepad_){
- touchIds_={-1,-1};gyro_=SDL_GamepadHasSensor(gamepad_,SDL_SENSOR_GYRO)&&SDL_SetGamepadSensorEnabled(gamepad_,SDL_SENSOR_GYRO,true);
+ touchQueue_.clear();touchState_={};sensorStamp_=0;haveGyro_=haveAccel_=false;gyroBias_={};calibrating_=false;touchIds_={-1,-1};gyro_=SDL_GamepadHasSensor(gamepad_,SDL_SENSOR_GYRO)&&SDL_SetGamepadSensorEnabled(gamepad_,SDL_SENSOR_GYRO,true);
accel_=SDL_GamepadHasSensor(gamepad_,SDL_SENSOR_ACCEL)&&SDL_SetGamepadSensorEnabled(gamepad_,SDL_SENSOR_ACCEL,true);
veyra::log::info("remoteplay-input",std::string("device opened gyro=")+(gyro_?"1":"0")+" accel="+(accel_?"1":"0")+" touchpads="+std::to_string(SDL_GetNumGamepadTouchpads(gamepad_)));
}
SDL_free(ids);enumerateAt_=now+10000000;
}
- if(!focused||!gamepad_){touchIds_={-1,-1};releaseEffects();return state;}
+ if(calibrating_&&focused&&gamepad_){
+ if(!calibrationStart_)calibrationStart_=now;
+ else if(now-calibrationStart_>100000000){calibrating_=false;veyra::log::warn("remoteplay-input","Calibration timed out; prior bias retained");}
+ }
+ SDL_Event event;
+ while(SDL_PollEvent(&event)){
+ if(!focused||!gamepad_)continue;
+ if((event.type==SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN||event.type==SDL_EVENT_GAMEPAD_TOUCHPAD_UP||event.type==SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION)&&event.gtouchpad.which==SDL_GetGamepadID(gamepad_)){
+ const auto& touch=event.gtouchpad;
+ if(touch.touchpad!=0||touch.finger<0||touch.finger>=2||!std::isfinite(touch.x)||!std::isfinite(touch.y))continue;
+ auto& value=touchState_[touch.finger];
+ if(event.type==SDL_EVENT_GAMEPAD_TOUCHPAD_UP)value={};
+ else{if(value.id<0)value.id=int8_t(nextTouchId_++&0x7f);value.x=uint16_t(std::clamp(touch.x,0.f,1.f)*1919);value.y=uint16_t(std::clamp(touch.y,0.f,1.f)*1079);}
+ if(!touchQueue_.empty()&&touchQueue_.back()[0].id==touchState_[0].id&&touchQueue_.back()[1].id==touchState_[1].id)touchQueue_.back()=touchState_;
+ else if(touchQueue_.size()<16)touchQueue_.push_back(touchState_);
+ else{touchQueue_.clear();touchState_={};touchQueue_.push_back(touchState_);veyra::log::warn("remoteplay-input","Touch edge queue overflow; releasing touches");}
+ }
+ if(event.type==SDL_EVENT_GAMEPAD_SENSOR_UPDATE&&event.gsensor.which==SDL_GetGamepadID(gamepad_)){
+ const auto& sample=event.gsensor;if(!std::all_of(std::begin(sample.data),std::end(sample.data),[](float v){return std::isfinite(v);}))continue;
+ if(sample.sensor==SDL_SENSOR_ACCEL){for(int i=0;i<3;++i)sensorAccel_[i]=sample.data[i]/SDL_STANDARD_GRAVITY;haveAccel_=true;}
+ else if(sample.sensor==SDL_SENSOR_GYRO){std::copy_n(sample.data,3,sensorGyro_.begin());haveGyro_=true;}
+ else continue;
+ sensorStamp_=sample.timestamp/1000;
+ if(haveAccel_&&haveGyro_){
+ if(calibrating_&&sample.sensor==SDL_SENSOR_GYRO){
+ float g2=0,a2=0;for(int i=0;i<3;++i){g2+=sensorGyro_[i]*sensorGyro_[i];a2+=sensorAccel_[i]*sensorAccel_[i];}
+ if(g2<.01f&&std::abs(a2-1)<.1f){for(int i=0;i<3;++i)biasSum_[i]+=sensorGyro_[i];++calibrationSamples_;}
+ else{calibrationSamples_=0;biasSum_={};}
+ if(calibrationSamples_>=120){for(int i=0;i<3;++i)gyroBias_[i]=biasSum_[i]/float(calibrationSamples_);calibrating_=false;veyra::log::info("remoteplay-input","Stationary gyro calibration completed");}
+ }
+ ControllerState::MotionSample reading;reading.accel=sensorAccel_;reading.timestampUs=sensorStamp_;
+ for(int i=0;i<3;++i)reading.gyro[i]=sensorGyro_[i]-gyroBias_[i];
+ if(state.motionSampleCount<state.motionSamples.size())state.motionSamples[state.motionSampleCount++]=reading;
+ else{std::move(state.motionSamples.begin()+1,state.motionSamples.end(),state.motionSamples.begin());state.motionSamples.back()=reading;}
+ }
+ }
+ }
+ if(!focused||!gamepad_){touchQueue_.clear();touchState_={};touchIds_={-1,-1};haveGyro_=haveAccel_=false;releaseEffects();return state;}
+ state.inputActive=true;
struct Button{SDL_GamepadButton input;ControllerState::Button output;};
constexpr Button buttons[]={
{SDL_GAMEPAD_BUTTON_SOUTH,ControllerState::Cross},{SDL_GAMEPAD_BUTTON_EAST,ControllerState::Circle},
@@ -58,18 +97,16 @@ ControllerState ControllerInput::poll(bool focused){
state.rightX=SDL_GetGamepadAxis(gamepad_,SDL_GAMEPAD_AXIS_RIGHTX);state.rightY=SDL_GetGamepadAxis(gamepad_,SDL_GAMEPAD_AXIS_RIGHTY);
state.l2=uint8_t(std::max(0,int(SDL_GetGamepadAxis(gamepad_,SDL_GAMEPAD_AXIS_LEFT_TRIGGER)))*255/32767);
state.r2=uint8_t(std::max(0,int(SDL_GetGamepadAxis(gamepad_,SDL_GAMEPAD_AXIS_RIGHT_TRIGGER)))*255/32767);
- for(int finger=0;finger<2;++finger){
- bool down=false;float x=0,y=0,pressure=0;
- if(SDL_GetNumGamepadTouchpads(gamepad_)>0&&SDL_GetGamepadTouchpadFinger(gamepad_,0,finger,&down,&x,&y,&pressure)&&down&&std::isfinite(x)&&std::isfinite(y)){
- if(touchIds_[finger]<0)touchIds_[finger]=int8_t(nextTouchId_++&0x7f);
- state.touches[finger]={touchIds_[finger],uint16_t(std::clamp(x,0.f,1.f)*1919),uint16_t(std::clamp(y,0.f,1.f)*1079)};
- }else touchIds_[finger]=-1;
- }
- if(gyro_&&accel_&&SDL_GetGamepadSensorData(gamepad_,SDL_SENSOR_GYRO,state.gyro.data(),3)&&SDL_GetGamepadSensorData(gamepad_,SDL_SENSOR_ACCEL,state.accel.data(),3)){
- for(auto& value:state.accel)value/=SDL_STANDARD_GRAVITY;
- state.motionValid=std::all_of(state.gyro.begin(),state.gyro.end(),[](float v){return std::isfinite(v);})&&std::all_of(state.accel.begin(),state.accel.end(),[](float v){return std::isfinite(v);});
- state.motionTimestampUs=SDL_GetTicksNS()/1000;
+ if(!touchQueue_.empty()){state.touches=touchQueue_.front();touchQueue_.pop_front();}
+ else{
+ for(int finger=0;finger<2;++finger){bool down=false;float x=0,y=0,pressure=0;
+ if(SDL_GetNumGamepadTouchpads(gamepad_)>0&&SDL_GetGamepadTouchpadFinger(gamepad_,0,finger,&down,&x,&y,&pressure)&&down&&std::isfinite(x)&&std::isfinite(y)){
+ auto& touch=touchState_[finger];if(touch.id<0)touch.id=int8_t(nextTouchId_++&0x7f);touch.x=uint16_t(std::clamp(x,0.f,1.f)*1919);touch.y=uint16_t(std::clamp(y,0.f,1.f)*1079);
+ }else touchState_[finger]={};
+ }
+ state.touches=touchState_;
}
+ if(gyro_&&accel_&&haveGyro_&&haveAccel_){state.motionValid=true;state.motionTimestampUs=sensorStamp_;state.accel=sensorAccel_;for(int i=0;i<3;++i)state.gyro[i]=sensorGyro_[i]-gyroBias_[i];}
return state;
}
void ControllerInput::releaseEffects(){
@@ -98,7 +135,7 @@ void ControllerInput::feedback(ControllerFeedback f,bool focused){
if(f.haptics.empty()||SDL_GetGamepadType(gamepad_)!=SDL_GAMEPAD_TYPE_PS5)return;
if(!hapticAttempted_){
hapticAttempted_=true;
- audioInitialized_=SDL_InitSubSystem(SDL_INIT_AUDIO);
+ if(!audioInitialized_)audioInitialized_=SDL_InitSubSystem(SDL_INIT_AUDIO);
if(!audioInitialized_){veyra::log::error("remoteplay-haptics",SDL_GetError());return;}
// Never use the default speakers or a stereo endpoint. Ambiguity fails closed.
int count=0;auto* devices=SDL_GetAudioPlaybackDevices(&count);SDL_AudioDeviceID selected=0;int matches=0;
@@ -121,4 +158,14 @@ void ControllerInput::feedback(ControllerFeedback f,bool focused){
if(!SDL_PutAudioStreamData(hapticStream_,quad.data(),int(quad.size()*sizeof(int16_t))))veyra::log::warn("remoteplay-haptics",SDL_GetError());
}
+bool ControllerInput::calibrate(){
+ if(!gamepad_||!gyro_||!accel_)return false;
+ biasSum_={};calibrationSamples_=0;calibrationStart_=0;calibrating_=true;return true;
+}
+ControllerInput::Capabilities ControllerInput::capabilities()const{
+ if(!gamepad_)return {};
+ return {true,gyro_,accel_,SDL_GetNumGamepadTouchpads(gamepad_)>0,
+ SDL_GetGamepadType(gamepad_)==SDL_GAMEPAD_TYPE_PS5,hapticStream_!=nullptr,calibrating_};
+}
+
}
diff --git a/src/source/RemotePlaySessionSource.cpp b/src/source/RemotePlaySessionSource.cpp
index e524a103..f12f9b29 100644
--- a/src/source/RemotePlaySessionSource.cpp
+++ b/src/source/RemotePlaySessionSource.cpp
@@ -8,7 +8,7 @@ extern "C" {
namespace veyra::source {
bool RemotePlaySessionSource::connect(RemotePlayConnectDesc desc) {
close();
- { std::lock_guard lock(mutex_); initialized_=started_=failed_=false; skipped_=0; rates_={}; feedback_={}; controller_={}; snapshot_={}; }
+ { std::lock_guard lock(mutex_); initialized_=started_=failed_=false; skipped_=0; rates_={}; feedback_={}; controller_={}; pendingControllers_.clear(); snapshot_={}; }
owner_=std::jthread([this, request=std::move(desc)](std::stop_token stop) mutable { run(stop,std::move(request)); });
std::unique_lock lock(mutex_);
ready_.wait(lock,[&]{return initialized_;});
@@ -48,14 +48,16 @@ void RemotePlaySessionSource::run(std::stop_token stop, RemotePlayConnectDesc de
auto nextController=lastFrame;
auto rateStart=lastFrame;uint64_t previousReceived=0,previousDecoded=0;
while(!stop.stop_requested()) {
- std::string pin; remoteplay::ControllerState controller;
- {std::lock_guard lock(mutex_);pin.swap(pin_);controller=remoteplay::monotonic100ns()-controllerStamp_<=1000000?controller_:remoteplay::ControllerState{};}
+ std::string pin;
+ {std::lock_guard lock(mutex_);pin.swap(pin_);}
if(!pin.empty()) {
const auto r=source.submitLoginPin(pin);SecureZeroMemory(pin.data(),pin.size());
if(!r.ok)log::warn("remoteplay",std::format("{} code={}",r.operation,r.code));
}
const auto now=std::chrono::steady_clock::now();
if(!desc.request.viewOnly&&now>=nextController) {
+ remoteplay::ControllerState controller;
+ {std::lock_guard lock(mutex_);controller=takeControllerLocked(remoteplay::monotonic100ns());}
const auto r=source.submitController(controller);
if(!r.ok)log::warn("remoteplay",std::format("{} code={}",r.operation,r.code));
nextController=now+std::chrono::milliseconds(4);
@@ -118,7 +120,25 @@ void RemotePlaySessionSource::close() noexcept {
std::lock_guard lock(mutex_);latest_.reset();view_.reset();info_={};started_=false;
SecureZeroMemory(pin_.data(),pin_.size());pin_.clear();
}
-void RemotePlaySessionSource::controller(remoteplay::ControllerState state){std::lock_guard lock(mutex_);controller_=state;controllerStamp_=remoteplay::monotonic100ns();}
+void RemotePlaySessionSource::controller(remoteplay::ControllerState state){
+ std::lock_guard lock(mutex_);controllerStamp_=remoteplay::monotonic100ns();
+ // A neutral input (focus/device loss) cancels queued actions immediately.
+ if(!state.inputActive)pendingControllers_.clear();
+ if(pendingControllers_.size()>=16){
+ pendingControllers_.clear();pendingControllers_.push_back({controllerStamp_,{}});
+ log::warn("remoteplay-input","Controller queue overflow; releasing before latest state");
+ }
+ pendingControllers_.push_back({controllerStamp_,std::move(state)});
+}
+remoteplay::ControllerState RemotePlaySessionSource::takeControllerLocked(remoteplay::HostTime now){
+ if(now-controllerStamp_>1000000){pendingControllers_.clear();controller_={};return controller_;}
+ if(!pendingControllers_.empty()&&now-pendingControllers_.front().first>1000000){
+ while(!pendingControllers_.empty()&&now-pendingControllers_.front().first>1000000)pendingControllers_.pop_front();
+ controller_={};return controller_;
+ }
+ if(!pendingControllers_.empty()){controller_=std::move(pendingControllers_.front().second);pendingControllers_.pop_front();}
+ return controller_;
+}
void RemotePlaySessionSource::loginPin(std::string pin){std::lock_guard lock(mutex_);SecureZeroMemory(pin_.data(),pin_.size());pin_=std::move(pin);}
remoteplay::SessionInbox::Snapshot RemotePlaySessionSource::sessionSnapshot()const{std::lock_guard lock(mutex_);return snapshot_;}
RemotePlaySessionSource::Rates RemotePlaySessionSource::rates()const{std::lock_guard lock(mutex_);return rates_;}
diff --git a/tests/remoteplay/ProductBoundaryTests.cpp b/tests/remoteplay/ProductBoundaryTests.cpp
index 38c4b483..55a8b051 100644
--- a/tests/remoteplay/ProductBoundaryTests.cpp
+++ b/tests/remoteplay/ProductBoundaryTests.cpp
@@ -14,6 +14,14 @@ namespace veyra::source {
struct RemotePlaySessionSourceTestAccess {
static void mailbox(){
RemotePlaySessionSource s;s.started_=true;
+ const auto now=remoteplay::monotonic100ns();
+ remoteplay::ControllerState down;down.inputActive=true;down.touches[0].id=1;
+ s.controller(down);s.controller({});
+ if(s.takeControllerLocked(now)!=remoteplay::ControllerState{})throw std::runtime_error("focus loss must cancel pending actions");
+ s.controller(down);auto up=down;up.touches[0].id=-1;s.controller(up);
+ if(s.takeControllerLocked(now).touches[0].id!=1||s.takeControllerLocked(now).touches[0].id!=-1)throw std::runtime_error("input edges overwritten by decoder owner");
+ for(int i=0;i<40;++i)s.controller(down);
+ if(s.pendingControllers_.size()>16||s.takeControllerLocked(now+2000000)!=remoteplay::ControllerState{})throw std::runtime_error("input queue bound or stale release");
AVFrame* raw=av_frame_alloc();raw->width=16;raw->height=16;raw->format=AV_PIX_FMT_YUV420P;
if(av_frame_get_buffer(raw,32)<0)throw std::bad_alloc();
pipeline::FramePacket packet;SourceInfo info;info.width=16;info.height=16;
@@ -48,9 +56,19 @@ int virtualInput(){
SDL_SetJoystickVirtualTouchpad(joystick,0,0,true,.25f,.75f,1);
SDL_SetJoystickVirtualTouchpad(joystick,0,1,true,1,0,1);
auto first=input.poll(true);bool ok=first.motionValid&&std::abs(first.accel[1]-1)<1e-5&&std::abs(first.gyro[2]-.3f)<1e-5;
+ ok&=first.motionSampleCount>0;
+ first=input.poll(true);
ok&=first.touches[0].id>=0&&first.touches[1].id>=0&&first.touches[0].id!=first.touches[1].id&&first.touches[0].x==479&&first.touches[0].y==809;
SDL_SetJoystickVirtualTouchpad(joystick,0,0,true,.5f,.5f,1);auto moved=input.poll(true);ok&=moved.touches[0].id==first.touches[0].id&&moved.touches[0].x==959;
SDL_SetJoystickVirtualTouchpad(joystick,0,0,false,0,0,0);auto up=input.poll(true);ok&=up.touches[0].id==-1;
+ // Both edges arrive between UI ticks: a tap must still produce down then up.
+ SDL_SetJoystickVirtualTouchpad(joystick,0,0,true,.4f,.4f,1);SDL_UpdateGamepads();
+ SDL_SetJoystickVirtualTouchpad(joystick,0,0,false,.4f,.4f,0);SDL_UpdateGamepads();
+ auto tapDown=input.poll(true),tapUp=input.poll(true);ok&=tapDown.touches[0].id>=0&&tapUp.touches[0].id<0;
+ ok&=input.calibrate();
+ gyro[0]=.01f;gyro[1]=.02f;gyro[2]=.03f;
+ for(int i=0;i<121;++i){SDL_SendJoystickVirtualSensorData(joystick,SDL_SENSOR_GYRO,20000000+i*1000000,gyro,3);input.poll(true);}
+ auto calibrated=input.poll(true);ok&=std::abs(calibrated.gyro[0])<1e-5&&std::abs(calibrated.gyro[2])<1e-5;
ControllerFeedback f;f.rumble=true;f.left=5;input.feedback(f,true);ok&=rumbleCalls>0;
const auto before=rumbleCalls;ok&=input.poll(false)==ControllerState{};ok&=rumbleCalls>before;
ControllerFeedback bounded;for(int i=0;i<20;++i){ControllerFeedback packet;packet.haptics.resize(120,1);bounded.merge(std::move(packet));ok&=bounded.haptics.size()<=600;}