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: honor render endpoint changes during capture audio

GeT-LeFt51591bc8afbe
diff --git a/docs/CAPTURE_AUDIO_ENDPOINT_SWITCH_PLAN_2026-10-09.md b/docs/CAPTURE_AUDIO_ENDPOINT_SWITCH_PLAN_2026-10-09.md
new file mode 100644
index 00000000..df276c69
--- /dev/null
+++ b/docs/CAPTURE_AUDIO_ENDPOINT_SWITCH_PLAN_2026-10-09.md
@@ -0,0 +1,59 @@
+# Capture audio output switching
+
+Scope: the user reported that changing the audio output in the 2.0.6 Windows
+capture session only takes effect after restarting Veyra. The user authorized
+a local repair and an upstream pull request after successful verification.
+
+Baseline: main `96a7c8d`; isolated branch `fix/capture-audio-output-switch`.
+The official portable installation and its runtime files remain intact.
+Build dependencies, original source copies, test output and candidate binaries
+are kept outside Git in a dedicated local development directory.
+
+The preference setter increments the render endpoint generation, and
+`AudioRenderer::lastError()` exposes a generation mismatch as device
+invalidation. File playback polls that state, but `CaptureAudioSession` does
+not. The capture owner must observe the same state and reuse its existing
+bounded endpoint recovery path. It must not restart the capture graph or
+recreate the video engine.
+
+Changes are limited to the capture audio owner, the existing capture audio
+integration test, and this plan/work log. Runtime DLLs, shaders, drivers, GPU
+algorithms, display settings and unrelated source modules are outside scope.
+
+Validation:
+
+- Feed continuous muted PCM through the real WASAPI capture audio session.
+- Select two distinct active endpoints, switch A -> B -> A in the same
+ session, and assert the actual opened endpoint and continued input/output.
+- Assert selecting the same endpoint again does not rebuild the renderer.
+- Select system default in the same session and verify the actual default
+ endpoint. For a live capture, change the Windows default while that mode
+ is selected and verify the notification reopens the new default.
+- Show the unmodified owner fails the switch regression, then run the fixed
+ owner and existing relevant capture audio recovery checks.
+- Build and launch a side-by-side local candidate and verify a live capture
+ output change without restarting the process before claiming a local fix.
+- Keep each test within 300 seconds and each build within 900 seconds.
+
+Submit only source changes and summarized validation after successful local
+verification. No capture media, user endpoint IDs, local logs, proprietary
+SDKs or runtime binaries are included in the public contribution.
+
+Results: the unmodified capture owner failed A -> B with the original output
+still active. The fixed real WASAPI test passed A -> B -> A, the same-endpoint
+no-op and selection of system default. Existing endpoint-loss, slow-start and
+44.1 kHz transient conversion checks also passed.
+
+A side-by-side MSVC/Qt candidate was verified with live NS2 3840x2160/60
+capture. Explicit output changes reopened in 0.526 and 0.515 seconds. The user
+then selected system default and changed the Windows output; the existing
+default-device notification was consumed and the renderer followed the new
+default in 0.517 seconds. The process stayed unchanged, with one capture
+configuration and one input start. Video stayed at 60 real frames/s with
+XeSS reporting 240 submissions/s (not measured panel scanout). The user
+initially reported not hearing the USB speaker, then reported that a manual
+retry seemed to work; no microphone or physical speaker measurement was made.
+
+The local candidate enables the NVIDIA capture enhancement chain but was
+built without PS5/Moonlight/Xbox source modules or libass. Those paths were
+not tested. The original complete official portable installation is retained.
diff --git a/docs/WORKLOG.md b/docs/WORKLOG.md
index 8a4d60c6..f3a48b9f 100644
--- a/docs/WORKLOG.md
+++ b/docs/WORKLOG.md
@@ -8869,3 +8869,48 @@ py -3.11 -B E:/项目/Veyra/reports/subtitle-formats-20261009/video-smoke.py:H
打包与收尾命令 py -3.11 -B E:/项目/Veyra/reports/subtitle-formats-20261009/package-overlay.py、py -3.11 -B scripts/acceptance/subtitle-formats-control.py final。覆盖包/source两个内层ZIP CRC及逐文件SHA核对,源码排除既有两个MP4宣传文件与一个旧pyc,不移除仓库原文件。候选不替换原完整package-manifest,另附subtitle-fix-manifest.json列明变更。单份共享app恢复最终EXE/新FFmpeg/原Main.qml,母包1614文件SHA保持。提交仅本轮23个白名单源码/文档/脚本,main与39原树保持;独立checkpoint与source-after.bundle在archives目录,未冒称独立Reviewer。
用户随后明确“不用打测试包”。立即停止后续打包与测试包交付;此前已经生成的73,394,839字节覆盖ZIP仅为内部中间证据,不作为交付物,未覆盖用户播放器。产品提交 a29243c1753ca75a63ad1d9e7051ff35178f9a11 已完成,之后只修改方案/报告/本记录中的交付决定,不重跑已通过测试或改动产品。当前交付为代码与排查结果;main仍为0e7018ad,未合并/推送/发布。最终保全重新核对并记入reports/.../final.json。
+
+## 2026-10-09 Capture audio output switching
+
+User report: selecting a new output during capture required an application
+restart. Required behavior also includes following Windows output changes
+when system default is selected. Isolated from main 96a7c8d on
+`fix/capture-audio-output-switch`, with original source copies, runtime,
+user-data backup, native dependencies and logs retained outside Git. Scope
+and validation are in CAPTURE_AUDIO_ENDPOINT_SWITCH_PLAN_2026-10-09.md.
+
+The preference setter already advances the endpoint generation; default
+device notifications already invalidate AudioRenderer. CaptureAudioSession
+did not poll lastError(), while event waits and buffer writes could still
+succeed on the old endpoint. Added that poll on the capture audio owner and
+reused its existing bounded recovery. No video graph, SDK or runtime changes.
+
+Added `veyra_capture_audio_tests --endpoint-switch`: continuous muted real
+WASAPI PCM, actual opened A -> B -> A, no reopen for the same preference,
+and selecting system default in the same session. Fewer than two active
+outputs returns explicit skip 77. Unmodified owner failed A -> B; fixed
+product test passed all phases, 221 input blocks, 10 ms buffered at the
+same-endpoint check. Existing --endpoint-loss, --slow-start and --transient
+checks passed. MSVC 14.44 / Windows SDK 10.0.26100 / Qt 6.8.3 Release product
+and integration targets built successfully; git diff --check passed. Each
+test stayed below 300 seconds and each build below 900 seconds. The final
+test's first launch lacked the portable FFmpeg DLL search path and exited
+0xC0000135; rerun with the official package on child-process PATH passed.
+
+Live side-by-side candidate: NS2 3840x2160/60 MJPEG + WASAPI input, explicit
+output changes took 0.526/0.515 seconds without restarting the process or
+capture input. The user selected system default and changed the Windows
+default output; notification-to-open was 0.517 seconds, preference remained
+system default. One capture configuration and one input start across these
+changes; 60 real frames/s and XeSS 240 SDK submissions/s continued. These
+are local API/log observations, not panel scanout or physical speaker
+measurement. User initially reported no USB-speaker sound, then reported
+that a manual retry seemed to work. No claim of measured audible latency.
+
+The local candidate reuses official 2.0.6 runtime files and has only its
+player executable replaced. Its build disables PS5/Moonlight/Xbox source
+modules and libass; those paths and other hardware were not verified. Only
+documented user-data was migrated, with a separate rollback copy; the
+complete official application remains available. Public contribution is
+source/test/documentation only, with no user data, endpoint IDs, logs,
+media, SDK files or runtime binaries.
diff --git a/src/sink/CaptureAudioSession.cpp b/src/sink/CaptureAudioSession.cpp
index 9b241690..0706d8a1 100644
--- a/src/sink/CaptureAudioSession.cpp
+++ b/src/sink/CaptureAudioSession.cpp
@@ -151,6 +151,11 @@ struct CaptureAudioSession::Impl : AudioPcmSource {
lastUnderrunFrames=renderer.underrunFrames();lastSilenceFrames=renderer.silenceFrames();starvationSince=0;
{std::lock_guard lock(mutex);state.error.clear();state.outputRecovering=false;state.inputChannels=layout.channels;state.inputChannelMask=layout.mask;const auto output=renderer.outputFormat();state.outputChannels=output.channels;state.outputChannelMask=output.mask;pendingReset=true;}
}
+ // Preference changes invalidate the renderer's endpoint generation
+ // without making WASAPI event waits or buffer fills fail. Observe
+ // that state on the audio owner, just as file playback does, so
+ // capture/streaming can reopen the selected output without a restart.
+ if(FAILED(renderer.lastError())){if(!recoverEndpoint())break;continue;}
renderer.setGain(gain);
// Wait before collecting callbacks, so PCM arriving during the
// endpoint wait is available for this fill instead of padded silence.
diff --git a/tests/integration/CaptureAudioTests.cpp b/tests/integration/CaptureAudioTests.cpp
index afe2fa87..4814c76d 100644
--- a/tests/integration/CaptureAudioTests.cpp
+++ b/tests/integration/CaptureAudioTests.cpp
@@ -1,4 +1,5 @@
#include "veyra/sink/CaptureAudioSession.h"
+#include "veyra/sink/WasapiAudioSink.h"
#include "veyra/sink/AudioFormat.h"
#include "veyra/source/AudioInputRecovery.h"
#include <chrono>
@@ -21,6 +22,77 @@ int main(int argc,char** argv){
else std::this_thread::sleep_until(due);
}
} pacer;
+ if(argc>=2&&std::string_view(argv[1])=="--endpoint-switch"){
+ // Exercise real endpoint selection while the same capture session
+ // continues receiving PCM. Muted output avoids playing test tones.
+ const auto endpoints=enumerateRenderEndpoints();
+ if(endpoints.size()<2){
+ std::cout<<"SKIP endpoint switch: two active render endpoints required\n";
+ return 77;
+ }
+ struct RestorePreference {
+ std::wstring id=preferredRenderEndpoint();
+ ~RestorePreference(){setPreferredRenderEndpoint(std::move(id));}
+ } restore;
+ CaptureAudioSession output;
+ const auto wave=floatWave({2,SPEAKER_FRONT_LEFT|SPEAKER_FRONT_RIGHT});
+ output.setGain(0);
+ output.setSync(2,0);
+ setPreferredRenderEndpoint(endpoints[0].id);
+ if(!output.configure(wave.Format,sizeof(wave))||!output.start())return 2;
+ std::vector<float> block(480*2,0.05f);
+ auto next=Clock::now();
+ uint64_t sequence=0;
+ auto feed=[&]{
+ pacer.until(next);next+=std::chrono::milliseconds(10);
+ const double pts=double(sequence++)*10;
+ if(!output.push(block.data(),block.size()*sizeof(float),pts,sequence==1))return false;
+ const auto host=std::chrono::duration_cast<std::chrono::nanoseconds>(Clock::now().time_since_epoch()).count()/100;
+ output.videoPresented(pts,host,host);
+ return true;
+ };
+ auto awaitEndpoint=[&](const std::wstring& id,const char* phase,uint64_t previousRetries=0){
+ const auto deadline=Clock::now()+std::chrono::seconds(2);
+ while(Clock::now()<deadline){
+ if(!feed())return false;
+ const auto active=activeRenderEndpoint();const auto s=output.snapshot();
+ if(active.valid&&active.id==id&&s.running&&!s.outputRecovering&&s.endpointRetries>previousRetries){
+ std::cout<<"PASS "<<phase<<" inputBlocks="<<s.inputBlocks
+ <<" endpointRetries="<<s.endpointRetries<<std::endl;
+ return true;
+ }
+ }
+ std::cout<<"FAIL "<<phase<<": active endpoint did not follow preference\n";
+ return false;
+ };
+ if(!awaitEndpoint(endpoints[0].id,"open A"))return 1;
+ const auto opened=output.snapshot();
+ setPreferredRenderEndpoint(endpoints[1].id);
+ if(!awaitEndpoint(endpoints[1].id,"switch A -> B"))return 1;
+ const auto switched=output.snapshot();
+ if(switched.endpointRetries<=opened.endpointRetries)return 1;
+ setPreferredRenderEndpoint(endpoints[0].id);
+ if(!awaitEndpoint(endpoints[0].id,"switch B -> A"))return 1;
+ const auto returned=output.snapshot();const auto generation=renderEndpointGeneration();
+ setPreferredRenderEndpoint(endpoints[0].id);
+ for(unsigned i=0;i<40;++i)if(!feed())return 3;
+ const auto stable=output.snapshot();const auto active=activeRenderEndpoint();
+ const bool pass=stable.running&&!stable.outputRecovering&&active.valid&&active.id==endpoints[0].id
+ &&stable.endpointRetries==returned.endpointRetries&&renderEndpointGeneration()==generation
+ &&stable.inputBlocks>returned.inputBlocks&&stable.bufferedMs<200;
+ std::cout<<(pass?"PASS ":"FAIL ")<<"same endpoint does not reopen; continuous inputBlocks="
+ <<stable.inputBlocks<<" bufferedMs="<<stable.bufferedMs<<'\n';
+ if(!pass)return 1;
+ const auto currentEndpoints=enumerateRenderEndpoints();
+ const auto defaultEndpoint=std::find_if(currentEndpoints.begin(),currentEndpoints.end(),
+ [](const auto& endpoint){return endpoint.isDefault;});
+ if(defaultEndpoint==currentEndpoints.end())return 2;
+ setPreferredRenderEndpoint({});
+ if(!awaitEndpoint(defaultEndpoint->id,"select system default",stable.endpointRetries))return 1;
+ const auto following=output.snapshot();
+ output.stop();
+ return preferredRenderEndpoint().empty()&&following.endpointRetries>stable.endpointRetries?0:1;
+ }
if(argc>=2&&std::string_view(argv[1])=="--xbox-float-rtp"){
// Xbox's stereo float PCM and independent audio/video RTP origins,
// through the real shared resampler and muted WASAPI endpoint.