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: retry transient PS5 session occupancy and preserve reconnect diagnostics
Veyra Goal Agentaad8ce408718
diff --git a/apps/veyra/main.cpp b/apps/veyra/main.cppindex 225520c7..395df30f 100644--- a/apps/veyra/main.cpp+++ b/apps/veyra/main.cpp@@ -3,9 +3,17 @@#include "veyra/RuntimePaths.h"int runVeyraApp(HINSTANCE,int);int WINAPI wWinMain(HINSTANCE instance,HINSTANCE,LPWSTR,int show){- const auto logPath=(veyra::runtime::logsDirectory()/L"veyra-app.log").wstring();- (void)veyra::Logger::instance().openFile(logPath);+ wchar_t logOverride[32768]{};+ const auto length=GetEnvironmentVariableW(L"VEYRA_LOG_FILE",logOverride,32768);+ auto logPath=length>0&&length<32768?std::filesystem::path(logOverride):veyra::runtime::logsDirectory()/L"veyra-app.log";+ // Preserve the failure preceding a restart. Concurrent GUI/test instances+ // must not truncate the active log or silently lose their own diagnostics.+ if(!veyra::Logger::instance().openFile(logPath.wstring(),true)){+ logPath=logPath.parent_path()/(L"veyra-app-"+std::to_wstring(GetCurrentProcessId())+L".log");+ (void)veyra::Logger::instance().openFile(logPath.wstring(),true);+ }veyra::log::info("app", "Veyra GUI session started");+ veyra::Logger::instance().flush();const int result=runVeyraApp(instance,show);veyra::log::info("app", "Veyra GUI session stopped");veyra::Logger::instance().flush();diff --git a/apps/veyra/ui/AppShell.cpp b/apps/veyra/ui/AppShell.cppindex 591004c3..382501f0 100644--- a/apps/veyra/ui/AppShell.cpp+++ b/apps/veyra/ui/AppShell.cpp@@ -512,7 +512,6 @@ int runVeyraApp(HINSTANCE instance,int show){Gdiplus::GdiplusStartupInput graphicsInput;ULONG_PTR graphicsToken=0;Gdiplus::GdiplusStartup(&graphicsToken,&graphicsInput,nullptr);struct GraphicsCleanup{ULONG_PTR token;~GraphicsCleanup(){Gdiplus::GdiplusShutdown(token);}} graphicsCleanup{graphicsToken};SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);INITCOMMONCONTROLSEX controls{sizeof(controls),ICC_BAR_CLASSES};InitCommonControlsEx(&controls);CoInitializeEx(nullptr,COINIT_APARTMENTTHREADED);-std::filesystem::create_directories(veyra::runtime::logsDirectory());wchar_t logOverride[32768]{};GetEnvironmentVariableW(L"VEYRA_LOG_FILE",logOverride,32768);veyra::Logger::instance().openFile(logOverride[0]?std::wstring(logOverride):(veyra::runtime::logsDirectory()/"veyra-app.log").wstring());initialOptions=veyra::engine::PlayerOptions::from(veyra::ui::defaultSettings());int argc=0;auto argv=CommandLineToArgvW(GetCommandLineW(),&argc);for(int i=1;i<argc;++i){const std::wstring arg=argv[i];if(arg==L"--export-worker"&&i+1<argc)workerMapping=reinterpret_cast<HANDLE>(_wcstoui64(argv[++i],nullptr,10));else if(arg==L"--smoke-view"&&i+1<argc)smokeView=argv[++i];else if(arg==L"--smoke-repair-ui")smokeRepair=true;else if(arg==L"--smoke-repair-ui-reject")smokeRepair=smokeRepairReject=true;else if(arg==L"--smoke-hover")smokeZoom=smokeHover=true;else if(arg==L"--smoke-protection")smokeProtection=true;else if(arg==L"--smoke-zoom")smokeZoom=true;else if(arg==L"--smoke-empty")smokeEmpty=true;else if(arg==L"--smoke-dual")smokeDual=true;else if(arg==L"--smoke-dual-pause"){smokeDual=smokeDualPause=true;}else if(arg==L"--smoke-master-reject")smokeMaster=smokeMasterReject=true;else if(arg==L"--smoke-master")smokeMaster=true;else if(arg==L"--smoke-audio")smokeAudio=true;else if(arg==L"--smoke-job-cancel")smokeJobCancel=true;else if(arg==L"--smoke-job-exit")smokeJobExit=true;else if(arg==L"--smoke-job")smokeJob=true;else if(arg==L"--smoke-dual-export"&&i+1<argc)smokeDualOutput=argv[++i];else if(arg==L"--smoke-seconds"&&i+1<argc)smokeSeconds=std::clamp(_wtoi(argv[++i]),1,240);else if(arg==L"--export-out"&&i+1<argc)exportOutput=argv[++i];else if(arg==L"--max-frames"&&i+1<argc)exportFrames=std::max(1,_wtoi(argv[++i]));else if(arg==L"--cancel-after-ms"&&i+1<argc)cancelAfterMs=std::clamp(_wtoi(argv[++i]),1,240000);else if(arg==L"--hevc")exportHevc=true;else if(arg==L"--smoke-rollback-flow"){smokeRollback=true;smokeRollbackFlow=true;}else if(arg==L"--smoke-rollback")smokeRollback=true;else if(arg==L"--smoke-ui")smokeUi=true;else if(arg==L"--no-fg")initialOptions.fg=false;else if(arg==L"--smoke-settings")smokeSettings=true;else if(arg==L"--smoke-screenshot")smokeScreenshot=true;else if(arg==L"--smoke-controls")smokeControls=true;else if(arg==L"--smoke-save"&&i+1<argc)smokeSave=argv[++i];else if(arg==L"--native")initialOptions.realtime=false;else if(arg==L"--realtime")initialOptions.realtime=true;else if(arg==L"--fg")initialOptions.fg=true;else if(arg==L"--fg-multiplier"&&i+1<argc){initialOptions.fgMultiplier=std::clamp(_wtoi(argv[++i]),2,4);initialOptions.fg=true;}else if(arg==L"--video-sr"&&i+1<argc){initialOptions.settings.videoSrQuality=std::clamp(_wtoi(argv[++i]),1,4);initialOptions.sr=true;}else if(arg==L"--nr-community")initialOptions.settings.nrRuntime=veyra::engine::NrRuntime::Community;else if(arg==L"--nr-original")initialOptions.settings.nrRuntime=veyra::engine::NrRuntime::Original;else if(arg==L"--sr")initialOptions.sr=true;else if(arg==L"--no-nr")initialOptions.nr=false;else if(arg==L"--nr")initialOptions.nr=true;else if(arg==L"--no-sr")initialOptions.sr=false;else autoInput=arg;}LocalFree(argv);diff --git a/docs/PS5_RECONNECT_REPAIR_2026-09-13.md b/docs/PS5_RECONNECT_REPAIR_2026-09-13.mdnew file mode 100644index 00000000..89d7b500--- /dev/null+++ b/docs/PS5_RECONNECT_REPAIR_2026-09-13.md@@ -0,0 +1,38 @@+# PS5 断流后自动及手动重连修复++基线e3d6c3c(已发布1.0.1后的文档提交),存档checkpoint/ps5-reconnect-20260913,施工codex/ps5-reconnect-repair。用户描述自然停帧后自动重连失败、手动连接报“未返回可解码画面”,重启进程可恢复。用户授权使用已保存的配对进行连接测试,不重新配对、不改主机电源、不发布新版本。++## 事实与范围++- 原现场logs/veyra-app.log已在22:57重新启动后被清空,没有这次自然断流证据。GUI main和AppShell重复openFile(wb),每次重启覆写;重复打开只能确定丢启动行,不能据此宣称整份空日志或断流根因。此前监测程序先打开默认日志再采用override,亦会触碰默认日志。+- 已有恢复策略把everVideo用于重连首帧截止时间:第一次等30秒,后续会话只等6秒。它可能过早终止握手,不证明本次现场就是这个原因。+- 初次会话一旦RP_IN_USE立即失败;用户手动重连创建新的StreamRecovery,因此即使此前播放过,也不等待PS5释放旧占用。+- 初帧失败由EngineController覆盖成通用“重新配对”提示,丢失owner保存的终止原因。+- 用户停流后运行旧版live presentation测试 --last-paired-ps5 logs/ps5-reconnect-20260913/before --reconnect(75秒外部上限):50秒观察,PASS。一次自动重连、713次恢复后健康采样、退出idle=1。可控停止传输与自然故障不同,不声称已复现自然卡死。++## 实施++1. 每个新会话均给予30秒握手/首帧时间,已经出帧后仍按1/3秒IDR、6秒重连;最多3次重连和1/2/4秒退避不变。首次只放行明确RP_IN_USE占用错误的有限重试;认证拒绝、主动结束仍立即失败,不强制抢占主机。+2. 初帧失败显示owner原因及固定数字终止码/错误码,不提示无依据重新配对。teardown开始/完成加入日志,辨别join卡住与主机拒绝。+3. GUI仅在main初始化日志,启动时尊重override;追加保留重启前记录,独占写失败时用PID日志分流,启动边界立即flush。其他测试默认截断独立文件不变。日志不包含配对密钥或原始Chiaki报文。+4. 回归覆盖新会话首帧超6秒、首次占用有限重试、拒绝不重试、旧预算不被偶发帧刷新、日志重开保留及竞争写不截断。真实PS5测试增加同一EngineController取消恢复后连续手动重连两轮;仍复用现有产品引擎。++## 验证与交付++日志统一logs/ps5-reconnect-20260913。自然故障根因未确定;禁止把有限恢复策略改善称为长期断流问题全部根除。SDK、运行文件、配对、测试日志不进入Git。++### 最终结果++- `cmd.exe /c out\ps5-reconnect-build.cmd`:产品相关库、live presentation、repair contract、remoteplay boundary及core-windows构建成功。随后正常关闭用户已停止串流的旧GUI(CloseMainWindow,无强杀),`cmd.exe /c out\gpu-dis-build-all.cmd`完整99步构建成功;原有FFmpeg头文件/未使用局部变量警告保留。日志build.log、full-build.log。+- 使用`scripts/run-short-test.ps1 -Exe <目标> -TimeoutSeconds <上限> -LogPrefix logs/ps5-reconnect-20260913/<名称>`:core-windows/veyra_remoteplay_core_tests.exe 75/75,product-repair/veyra_repair_contract_tests.exe 107检查/0失败,veyra_remoteplay_boundary_tests.exe PASS;每项30秒外部上限。新增日志测试确认重开追加保留两段内容、第二写者不能截断活跃日志;独立的无效连接重开3次和邮箱/手柄边界通过,不冒充网络实机。+- `veyra_live_presentation_tests.exe --last-paired-ps5 logs/ps5-reconnect-20260913/manual --manual-reconnect`(210秒上限):取消可控断流恢复后,同一个EngineController/进程手动重连两轮,每轮至少180实际处理帧、100生成帧及音频running,停止后idle=1;整体PASS,实际约40秒。+- **这次实机确认了占用问题**:第一轮手动重连attempt0收到quitReason=4,attempt1在15:09:56.895Z恢复首帧;第二轮attempt0/1/2均收到quitReason=4,attempt3在15:10:13.654Z恢复首帧。前者旧策略必然立即失败,因为本次新owner还没有任何画面;新版保留同一进程/配对,等待主机释放后恢复。未强制抢占,也未修改PS5设置。+- `veyra_live_presentation_tests.exe --last-paired-ps5 logs/ps5-reconnect-20260913/automatic --reconnect`(100秒上限):50秒观察PASS,自动恢复attempt2(attempt1收到占用),463次恢复后健康采样,画面/NR/SR/FG/音频重新推进,idle=1。真实NR CreateFeature18 result=0x1、handle非空、seh=0;DLSSG 3840x2160 Create=0x1、Release=0x1、evaluates=907。构建与此轮有重叠,呈现速率45–118不作为稳态性能验收,不声称固定120fps或手柄/声音主观体验。+- 新GUI两次运行`--smoke-empty --no-nr --no-sr --no-fg --smoke-seconds 2`,各20秒上限,指定VEYRA_LOG_FILE=本轮gui-restart.log;两次started/stopped均保留,原默认日志哈希不变。验证了main尊重override、AppShell不再二次截断。GUI不自动连接PS5。+- EXE SHA256:23791CE1A316A4CFDAA9D292502E4620CB9E74BAA07E5310F82D843A53FAE326;FFmpeg avcodec仍0710F0D87A7FFCC9F998F1A35D0500345F6C66EB9A5A39C51D60D293142BD84F。桌面“Veyra PS5 测试版”仍指向out/remoteplay/product-repair/veyra.exe,已更新为本地修复版(资源版本暂仍1.0.1),没有改GitHub的1.0.1包。++### 交付边界++此次确认并修复“暂时占用导致新手动连接立即放弃”,并修正新会话首帧等待过短、提示与日志覆盖。没有原自然卡死日志,不能认定网络/解码/驱动哪个最先停住,也不能保证此后不再断流。下一步用户长时游玩;若再停住,新的日志会保留跨重启的记录,检查最后完整视频回调、解码时间、quitReason和teardown完成标记。永久阻塞的驱动/join不能安全强杀线程,仍不detach或释放存活回调资源。++修改文件:apps/veyra/main.cpp、apps/veyra/ui/AppShell.cpp、include/veyra/Log.h、src/base/Log.cpp;StreamRecovery.h、ChiakiBackend.h/.cpp、RemotePlaySessionSource.cpp、EngineController.cpp;CoreTests.cpp、RepairContractTests.cpp、LivePresentationTests.cpp及本记录/WORKLOG。git diff --check通过。初次误用run-short-test.ps1 -Help只产生参数错误,未启动产品;真实测试命令及输出按上述记录。未push、未发布。diff --git a/docs/WORKLOG.md b/docs/WORKLOG.mdindex e2231c0c..17e7db7a 100644--- a/docs/WORKLOG.md+++ b/docs/WORKLOG.md@@ -1882,3 +1882,11 @@ GitHub Release https://github.com/Likely7/Veyra-NRVideo/releases/tag/v1.0.0 于完整便携包与两份对应源码包制作成功,六个发布资产;七个已批准运行组件与PS5 patched FFmpeg不变,无SDK/运行时加入源码。便携ZIP逐文件清单校验及源码扫描通过,FFmpeg六个.mp4后缀文件确认是上游ASCII测试参考文本。新EXE解压后独立启动/实际增强5/5 PASS,最长7.92秒,社区/原版/Video SR组合均有NR执行和FG真实输出;此前产品代码delivery 23/23仍单独记录为版本资源更新前验证。具体命令、失败与恢复、资产哈希、运行码见docs/RELEASE_1.0.1_EXECUTION.md,日志logs/release-1.0.1。反馈者实卡音频改善仍待其新版测试,未声称10ms端到端。下一步推送源码及六资产并核验公开Release。发布完成:main及v1.0.1(c0cba4b)已推送,六资产服务器大小/摘要与本地一致,2026-09-13T14:53:27Z正式公开为latest,非草稿/非预发布,Release ID 387931939。链接https://github.com/Likely7/Veyra-NRVideo/releases/tag/v1.0.1 。未修改1.0.0资产,未关闭用户正在运行的程序。发布后仅补记文档,不重打包、不移动tag;待反馈者下载新版进行实卡音频验收。++## 2026-09-13 PS5 断流后重连修复(本地)++用户反馈长时串流卡住、自动及手动连接均不能恢复,必须重启。存档checkpoint/ps5-reconnect-20260913,分支codex/ps5-reconnect-repair,基线e3d6c3c。旧现场日志被启动截断,自然断流根因不明;修改GUI仅初始化一次日志、追加保留跨重启记录并独立处理override/多进程。新会话首帧统一30秒,已有画面的断流仍6秒恢复;初次仅RP_IN_USE允许最多3次退避重试,拒绝认证不重试。失败保留具体原因/终止码,增加资源结束前后日志,不无依据提示重新配对。++用户明确停流授权实机:旧可控自动恢复PASS,未复现自然停帧;新版同一进程取消恢复后手动重连两轮PASS,真实捕获占用码4,第二轮3次占用后恢复,画面/FG/音频均推进且idle=1。新版可控自动恢复PASS(attempt2,463健康采样),真实NR/4K DLSSG Create=0x1、SEH=0。core75/75、contract107/0、boundary通过,完整99步构建通过;双GUI日志重启检查PASS。每次测试210秒以内上限。详细命令、修改清单、证据及限制见docs/PS5_RECONNECT_REPAIR_2026-09-13.md,logs/ps5-reconnect-20260913/。++已正常关闭用户空闲旧GUI,更新桌面快捷方式的同一EXE,SHA256 23791CE1A316A4CFDAA9D292502E4620CB9E74BAA07E5310F82D843A53FAE326;FFmpeg切片补丁不变。无SDK/二进制/配对进入Git,不改已发布1.0.1,不push。下一步用户长时游玩确认;最初自然停帧原因仍需新日志,不能宣称全部断流根除。diff --git a/include/veyra/Log.h b/include/veyra/Log.hindex a0134c01..cf098b0d 100644--- a/include/veyra/Log.h+++ b/include/veyra/Log.h@@ -31,7 +31,7 @@ public:Logger& operator=(const Logger&) = delete;// Creates parent directories; returns false and logs to console on failure.- bool openFile(const std::wstring& path);+ bool openFile(const std::wstring& path, bool append = false);void closeFile();void setConsoleEnabled(bool enabled);diff --git a/include/veyra/remoteplay/ChiakiBackend.h b/include/veyra/remoteplay/ChiakiBackend.hindex 3ad47a43..a569b5e7 100644--- a/include/veyra/remoteplay/ChiakiBackend.h+++ b/include/veyra/remoteplay/ChiakiBackend.h@@ -41,6 +41,7 @@ struct NativeSnapshot {uint64_t callbackRejected=0,packetReceived=0,packetLost=0;uint64_t transportErrors=0,assemblyErrors=0;bool automaticRetryAllowed=true;+ bool startupRetryAllowed=false; // Only transient RP_IN_USE, never an auth rejection.int64_t serverTargetBitrate=-1; // Raw upstream field; diagnostic opt-in only.uint64_t qualityReports=0;};diff --git a/include/veyra/remoteplay/StreamRecovery.h b/include/veyra/remoteplay/StreamRecovery.hindex 7f98408d..f49bde38 100644--- a/include/veyra/remoteplay/StreamRecovery.h+++ b/include/veyra/remoteplay/StreamRecovery.h@@ -8,12 +8,14 @@ public:enum class Action {Wait,Keyframe,Reconnect,Fail};void beginAttempt(int64_t now){lastProgress_=now;keyframes_=0;currentVideo_=false;}void frame(int64_t now){lastProgress_=now;keyframes_=0;everVideo_=currentVideo_=true;}- Action poll(int64_t now,bool loginPin,bool failed,bool retryAllowed=true){+ Action poll(int64_t now,bool loginPin,bool failed,bool retryAllowed=true,bool startupRetryAllowed=false){const auto silent=now-lastProgress_;if(loginPin)return silent>=120000?Action::Fail:Action::Wait;if(failed&&!retryAllowed)return Action::Fail;- if(failed||silent>=(everVideo_?6000:30000)){- if(!everVideo_||reconnects_>=3)return Action::Fail;+ // Each rebuilt session needs its own handshake/first-frame allowance.+ // A previous session having video must not shorten a new handshake.+ if(failed||silent>=(currentVideo_?6000:30000)){+ if((!everVideo_&&!(failed&&startupRetryAllowed))||reconnects_>=3)return Action::Fail;++reconnects_;return Action::Reconnect;}if(currentVideo_&&keyframes_<2&&silent>=1000+int64_t(keyframes_)*2000){++keyframes_;return Action::Keyframe;}diff --git a/src/base/Log.cpp b/src/base/Log.cppindex 0a28edfc..04276054 100644--- a/src/base/Log.cpp+++ b/src/base/Log.cpp@@ -51,7 +51,7 @@ Logger::~Logger()closeFile();}-bool Logger::openFile(const std::wstring& path)+bool Logger::openFile(const std::wstring& path, bool append){std::error_code ec;const std::filesystem::path fsPath(path);@@ -68,7 +68,7 @@ bool Logger::openFile(const std::wstring& path)}// Diagnostics may read a running session without stopping capture. Keep// concurrent writers excluded so another instance cannot truncate this log.- file_ = _wfsopen(path.c_str(), L"wb", _SH_DENYWR);+ file_ = _wfsopen(path.c_str(), append ? L"ab" : L"wb", _SH_DENYWR);if (file_ == nullptr) {return false;}diff --git a/src/engine/EngineController.cpp b/src/engine/EngineController.cppindex b5d113dd..8dedcc7c 100644--- a/src/engine/EngineController.cpp+++ b/src/engine/EngineController.cpp@@ -170,7 +170,7 @@ void EngineController::run(HWND window,std::wstring path,PlayerOptions options,sconst auto state=remote->sessionSnapshot().state;{std::lock_guard lock(mutex_);snapshot_.remotePlayState=int(state);}if(result==source::SourceReadStatus::Frame){cachedFrame=av_frame_clone(first);break;}- if(result==source::SourceReadStatus::Error){status(L"PS5 未返回可解码画面,请检查连接或重新配对",true);break;}+ if(result==source::SourceReadStatus::Error){const auto recovery=remote->recoveryStatus();status(recovery.message.empty()?L"PS5 未返回可解码画面,请检查主机及网络后重新连接。":recovery.message,true);break;}if(state==remoteplay::SessionState::LoginPinRequired)status(L"PS5 要求登录 PIN,请在串流面板输入");std::this_thread::sleep_for(std::chrono::milliseconds(2));}diff --git a/src/remoteplay/ChiakiBackend.cpp b/src/remoteplay/ChiakiBackend.cppindex 583d80aa..1584414b 100644--- a/src/remoteplay/ChiakiBackend.cpp+++ b/src/remoteplay/ChiakiBackend.cpp@@ -281,8 +281,10 @@ NativeSnapshot ChiakiBackend::snapshot()const{if(s.initialized)chiaki_packet_stats_get(&s.session.stream_connection.packet_stats,false,&out.packetReceived,&out.packetLost);// After a stopped session the PS5 may briefly still report RP_IN_USE.// Retrying this request cannot evict it; the console remains authoritative.- // StreamRecovery retries only after this user-started run had real video.+ // A manual reconnect may race the console releasing our previous session.+ // Retry RP_IN_USE within the same bounded budget; never force eviction.out.automaticRetryAllowed=out.lastQuitReason==CHIAKI_QUIT_REASON_NONE||out.lastQuitReason==CHIAKI_QUIT_REASON_CTRL_UNKNOWN||out.lastQuitReason==CHIAKI_QUIT_REASON_CTRL_CONNECT_FAILED||out.lastQuitReason==CHIAKI_QUIT_REASON_STREAM_CONNECTION_UNKNOWN||out.lastQuitReason==CHIAKI_QUIT_REASON_SESSION_REQUEST_RP_IN_USE;+ out.startupRetryAllowed=out.lastQuitReason==CHIAKI_QUIT_REASON_SESSION_REQUEST_RP_IN_USE;return out;}} // namespace veyra::remoteplaydiff --git a/src/source/RemotePlaySessionSource.cpp b/src/source/RemotePlaySessionSource.cppindex cef56c57..60eeb44a 100644--- a/src/source/RemotePlaySessionSource.cpp+++ b/src/source/RemotePlaySessionSource.cpp@@ -115,7 +115,7 @@ void RemotePlaySessionSource::run(std::stop_token stop, RemotePlayConnectDesc delog::warn("remoteplay-recovery-test",std::format("injected owned transport stop ok={} code={} (no console power command)",r.ok,r.code));}} else {- const auto action=recovery.poll(milliseconds(),snapshot.state==remoteplay::SessionState::LoginPinRequired,result==SourceReadStatus::Error,native.automaticRetryAllowed);+ const auto action=recovery.poll(milliseconds(),snapshot.state==remoteplay::SessionState::LoginPinRequired,result==SourceReadStatus::Error,native.automaticRetryAllowed,native.startupRetryAllowed);if(action==remoteplay::StreamRecovery::Action::Keyframe){source.recoverVideo();log::warn("remoteplay-recovery",std::format("request keyframe; received={} decoded={} videoCallbacks={} rejected={} packetReceived={} packetLost={}",snapshot.video.accessUnits,snapshot.decodedFrames,native.videoCallbacks,native.callbackRejected,native.packetReceived,native.packetLost));std::lock_guard lock(mutex_);recovery_.active=true;recovery_.message=L"画面中断,正在请求关键帧恢复…";@@ -123,7 +123,8 @@ void RemotePlaySessionSource::run(std::stop_token stop, RemotePlayConnectDesc deelse if(action==remoteplay::StreamRecovery::Action::Fail){log::error("remoteplay-recovery",std::format("recovery stopped attempts={} quitReason={} error={}",recovery.reconnects(),native.lastQuitReason,snapshot.errorCode));std::lock_guard lock(mutex_);failed_=true;recovery_.active=false;- recovery_.message=snapshot.state==remoteplay::SessionState::LoginPinRequired?L"等待 PS5 登录 PIN 超时,请重新连接。":!native.automaticRetryAllowed?L"PS5 已结束或拒绝串流,请检查主机状态后重新连接。":L"PS5 串流未恢复,请检查主机及网络后点击连接;无需重新配对。";break;+ recovery_.message=snapshot.state==remoteplay::SessionState::LoginPinRequired?L"等待 PS5 登录 PIN 超时,请重新连接。":native.startupRetryAllowed?L"PS5 仍被串流会话占用,请结束其他串流或稍后重试;无需重新配对。":!native.automaticRetryAllowed?L"PS5 已结束或拒绝串流,请检查主机状态后重新连接。":L"PS5 串流未恢复,请检查主机及网络后点击连接;无需重新配对。";+ recovery_.message+=std::format(L"(终止码 {} / 错误 {})",native.lastQuitReason,snapshot.errorCode);break;}std::this_thread::sleep_for(std::chrono::milliseconds(1));}@@ -139,10 +140,12 @@ void RemotePlaySessionSource::run(std::stop_token stop, RemotePlayConnectDesc destd::lock_guard lock(mutex_);recovery_={true,recovery.reconnects(),std::format(L"串流中断,正在重新连接({}/3)…",recovery.reconnects())};latest_.reset();pendingControllers_.clear();controller_={};feedback_={};}+ log::info("remoteplay-recovery",std::format("teardown begin attempt={} retry={} cancelled={}",recovery.reconnects(),retry,stop.stop_requested()));if(monitor.joinable()){monitor.request_stop();monitor.join();}if(feeder.joinable()){feeder.request_stop();feeder.join();}audio_.stop();source.close();+ log::info("remoteplay-recovery",std::format("teardown complete attempt={}",recovery.reconnects()));if(!retry||stop.stop_requested())break;log::warn("remoteplay-recovery",std::format("old session joined; reconnect={} using existing in-memory pairing",recovery.reconnects()));// Interruptible 1/2/4 second backoff; manual Stop prevents the next start.diff --git a/tests/integration/LivePresentationTests.cpp b/tests/integration/LivePresentationTests.cppindex 706f415a..a403e84e 100644--- a/tests/integration/LivePresentationTests.cpp+++ b/tests/integration/LivePresentationTests.cpp@@ -17,8 +17,9 @@ int wmain(int argc,wchar_t**argv){#ifdef VEYRA_ENABLE_REMOTEPLAY// Explicit opt-in; uses existing local pairing without changing it. Runs// the actual shared engine, audio endpoint, GPU admission and presenter.- if((argc==3||(argc==4&&(std::wstring_view(argv[3])==L"--reconnect"||std::wstring_view(argv[3])==L"--cancel-reconnect")))&&std::wstring_view(argv[1])==L"--last-paired-ps5"){- const bool reconnect=argc==4,cancelReconnect=reconnect&&std::wstring_view(argv[3])==L"--cancel-reconnect";+ if((argc==3||(argc==4&&(std::wstring_view(argv[3])==L"--reconnect"||std::wstring_view(argv[3])==L"--cancel-reconnect"||std::wstring_view(argv[3])==L"--manual-reconnect")))&&std::wstring_view(argv[1])==L"--last-paired-ps5"){+ const bool manualReconnect=argc==4&&std::wstring_view(argv[3])==L"--manual-reconnect";+ const bool reconnect=argc==4,cancelReconnect=reconnect&&(std::wstring_view(argv[3])==L"--cancel-reconnect"||manualReconnect);const auto dir=remoteplay::profileDirectory();wchar_t name[80]{};GetPrivateProfileStringW(L"RemotePlay",L"LastProfile",L"",name,80,(dir/L"settings.ini").c_str());const std::wstring profile=name;if(profile.empty()||profile.find_first_of(L"/\\:")!=profile.npos)return 3;@@ -56,6 +57,30 @@ int wmain(int argc,wchar_t**argv){const auto final=engine.snapshot();engine.stop();const auto stopDeadline=std::chrono::steady_clock::now()+10s;while(!engine.idle()&&std::chrono::steady_clock::now()<stopDeadline)std::this_thread::sleep_for(10ms);if(reconnect){+ if(manualReconnect){+ bool manualOk=!failed&&cancelled&&engine.idle();+ // Reuse the same process/engine after cancelling recovery, then+ // immediately reopen again. No global reset or new pairing.+ for(int cycle=0;cycle<2&&manualOk;++cycle){+ auto again=remoteplay::loadProfile(dir/profile);if(!again){manualOk=false;break;}+ source::RemotePlayConnectDesc next;next.request=std::move(*again);+ next.request.video={1920,1080,60,80000,remoteplay::Codec::H264};next.decodeMode=source::RemotePlayConnectDesc::DecodeMode::Hardware;+ engine.openRemotePlay(window,std::move(next),options);+ const auto deadline=std::chrono::steady_clock::now()+55s;bool played=false;+ while(std::chrono::steady_clock::now()<deadline){+ MSG msg;while(PeekMessageW(&msg,nullptr,0,0,PM_REMOVE)){TranslateMessage(&msg);DispatchMessageW(&msg);}+ const auto snap=engine.snapshot();if(snap.failed)break;+ if(snap.frames>=180&&snap.generated>=100&&snap.captureAudio.running){played=true;break;}+ std::this_thread::sleep_for(20ms);+ }+ engine.stop();const auto end=std::chrono::steady_clock::now()+10s;+ while(!engine.idle()&&std::chrono::steady_clock::now()<end)std::this_thread::sleep_for(10ms);+ manualOk=played&&engine.idle();+ std::cout<<"MANUAL cycle="<<cycle<<" played="<<played<<" idle="<<engine.idle()<<std::endl;+ }+ std::cout<<(manualOk?"PASS ":"FAIL ")<<"same-process manual reconnect after cancelling recovery"<<std::endl;+ DestroyWindow(window);CoUninitialize();return manualOk?0:1;+ }// Observe beyond the first retry backoff: Stop must not reopen the session.if(cancelReconnect)std::this_thread::sleep_for(2s);const bool ok=!failed&&engine.idle()&&sawRecovery&&attempts>=1&&attempts<=3&&(cancelReconnect?cancelled:playedBefore&&resumed&&postHealthySamples>=250&&final.captureAudio.compensationMs<150);diff --git a/tests/remoteplay/CoreTests.cpp b/tests/remoteplay/CoreTests.cppindex b4f9bc57..24e18067 100644--- a/tests/remoteplay/CoreTests.cpp+++ b/tests/remoteplay/CoreTests.cpp@@ -154,7 +154,7 @@ TEST(recovery_progress_and_terminal_quit){CHECK(r.poll(1100,false,false)==A::Keyframe);r.frame(1500);CHECK(r.poll(2000,false,false)==A::Wait);CHECK(r.poll(2200,false,true,false)==A::Fail);CHECK(r.reconnects()==0);CHECK(r.poll(2200,false,true,true)==A::Reconnect);r.beginAttempt(5000);- CHECK(r.poll(10999,false,false)==A::Wait);CHECK(r.poll(11000,false,false)==A::Reconnect);+ CHECK(r.poll(11000,false,false)==A::Wait);CHECK(r.poll(34999,false,false)==A::Wait);CHECK(r.poll(35000,false,false)==A::Reconnect);}TEST(recovery_retryable_busy_requires_prior_video){StreamRecovery r;using A=StreamRecovery::Action;r.beginAttempt(0);@@ -162,6 +162,20 @@ TEST(recovery_retryable_busy_requires_prior_video){r.frame(1000);CHECK(r.poll(7000,false,false)==A::Reconnect);r.beginAttempt(8000);CHECK(r.poll(8500,false,true,true)==A::Reconnect);CHECK(r.reconnects()==2);}+TEST(recovery_manual_busy_retry_is_bounded){+ StreamRecovery r;using A=StreamRecovery::Action;r.beginAttempt(0);+ for(int i=0;i<3;++i){CHECK(r.poll(i*2000+500,false,true,true,true)==A::Reconnect);r.beginAttempt((i+1)*2000);}+ CHECK(r.poll(6500,false,true,true,true)==A::Fail);CHECK(r.reconnects()==3);+ StreamRecovery denied;denied.beginAttempt(0);+ CHECK(denied.poll(500,false,true,false,true)==A::Fail);CHECK(denied.reconnects()==0);+}+TEST(recovery_busy_then_slow_handshake){+ StreamRecovery r;using A=StreamRecovery::Action;r.beginAttempt(0);+ CHECK(r.poll(500,false,true,true,true)==A::Reconnect);r.beginAttempt(2000);+ CHECK(r.poll(8000,false,false)==A::Wait);CHECK(r.poll(31999,false,false)==A::Wait);+ r.frame(31999);CHECK(r.poll(32999,false,false)==A::Keyframe);+ CHECK(r.poll(37999,false,false)==A::Reconnect);+}int main(int argc,char**argv){std::string filter;if(argc==2&&std::string_view(argv[1])=="--list"){for(auto [name,f]:tests()){(void)f;std::cout<<name<<'\n';}return 0;}diff --git a/tests/unit/RepairContractTests.cpp b/tests/unit/RepairContractTests.cppindex 705e5ff7..0fa18bec 100644--- a/tests/unit/RepairContractTests.cpp+++ b/tests/unit/RepairContractTests.cpp@@ -7,6 +7,9 @@#include "veyra/engine/FrameFlowWindow.h"#include "veyra/engine/EnhancementDelayEstimate.h"#include <iostream>+#include <filesystem>+#include <fstream>+#include <windows.h>#include "veyra/engine/ContentCadence.h"#include "veyra/diagnostics/Redaction.h"#include <limits>@@ -18,6 +21,20 @@int main(){using namespace veyra;int failures=0,checks=0;auto check=[&](bool ok,const char* name){++checks;if(!ok)++failures;std::cout<<(ok?"PASS ":"FAIL ")<<name<<'\n';};+ const auto logPath=std::filesystem::temp_directory_path()/(L"veyra-log-reopen-"+std::to_wstring(GetCurrentProcessId())+L".log");+ {+ auto logger=std::make_unique<Logger>();logger->setConsoleEnabled(false);+ check(logger->openFile(logPath.wstring()),"open isolated diagnostic log");+ logger->write(LogLevel::Info,"test","before-restart");logger->closeFile();+ check(logger->openFile(logPath.wstring(),true),"append diagnostic log after restart");+ logger->write(LogLevel::Info,"test","after-restart");logger->flush();+ auto other=std::make_unique<Logger>();other->setConsoleEnabled(false);+ check(!other->openFile(logPath.wstring()),"second writer cannot truncate active diagnostic log");+ logger->closeFile();+ std::ifstream file(logPath);std::string content((std::istreambuf_iterator<char>(file)),{});+ check(content.find("before-restart")!=content.npos&&content.find("after-restart")!=content.npos,"both sessions survive reopen and rejected concurrent writer");+ }+ std::filesystem::remove(logPath);sink::ArrivalClockMapping ingressClock;double mapping=0;for(int i=0;i<60000;++i)mapping=ingressClock.observe(1000+i*10.01+(i%13==5?4:0),i*10.0);