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(capture): resize native video after Qt completes its new window extent
Veyra Goal Agent2a8bed2aa75f
diff --git a/apps/veyra-qml/main.cpp b/apps/veyra-qml/main.cppindex 4f6462ff..eacef48a 100644--- a/apps/veyra-qml/main.cpp+++ b/apps/veyra-qml/main.cpp@@ -20,6 +20,7 @@#include <QQmlContext>#include <QQuickItem>#include <QQuickWindow>+#include "veyra/gfx/ObsQtFrameGate.h"#include <QSGRendererInterface>#include <QKeyEvent>#include <QTimer>@@ -756,6 +757,19 @@ static int runApplication(int argc, char** argv, QString& restartProgram, QStrinreturn 1;}if (testSize.isValid()) window->resize(testSize);+ if(!softwareUi){+ auto windows=window->findChildren<QQuickWindow*>();windows.prepend(window);+ for(auto* quick:windows){+ auto gate=veyra::gfx::registerObsQtFrameGate(reinterpret_cast<HWND>(quick->winId()));+ QObject::connect(quick,&QQuickWindow::beforeFrameBegin,quick,[gate]{+ gate->beginFrame(GetModuleHandleW(L"graphics-hook64.dll")!=nullptr);+ },Qt::DirectConnection);+ QObject::connect(quick,&QQuickWindow::frameSwapped,quick,[gate]{gate->presented();},Qt::DirectConnection);+ QObject::connect(quick,&QQuickWindow::afterFrameEnd,quick,[gate]{gate->endFrame();},Qt::DirectConnection);+ QObject::connect(quick,&QQuickWindow::sceneGraphInvalidated,quick,[gate]{gate->abortFrame();},Qt::DirectConnection);+ }+ veyra::log::info("qml-window",std::format("OBS resize frame gates registered windows={}",windows.size()));+ }// Fullscreen must own the whole monitor. Without telling the shell, the taskbar// stayed above the fullscreen picture on some systems (field report with thediff --git a/include/veyra/gfx/ObsQtFrameGate.h b/include/veyra/gfx/ObsQtFrameGate.hnew file mode 100644index 00000000..9efab184--- /dev/null+++ b/include/veyra/gfx/ObsQtFrameGate.h@@ -0,0 +1,77 @@+#pragma once+#include <Windows.h>+#include <atomic>+#include <cstdint>+#include <memory>+#include <mutex>+#include <vector>++namespace veyra::gfx {+// Qt 6.8.3 resizes BEFORE beforeFrameBegin; OBS 32.1.2 clears its single+// process-wide capture on ANY ResizeBuffers. Require a completed Qt frame+// at the current window extent, then keep Qt Presents outside native resize.+class ObsQtFrameGate {+public:+ explicit ObsQtFrameGate(HWND window):window_(window){}+ void beginFrame(bool hookActive){+ if(hookActive&&!held_){+ mutex_.lock();held_=true;presented_=false;frameExtent_=clientExtent();+ }+ }+ void presented(){if(held_)presented_=true;}+ void endFrame(){+ if(held_){+ if(presented_)completedExtent_.store(frameExtent_,std::memory_order_release);+ abortFrame();+ }+ }+ void abortFrame(){if(held_){held_=false;mutex_.unlock();}}+ bool readyForCurrentWindow()const{+ if(!IsWindow(window_)||!IsWindowVisible(window_)||IsIconic(window_))return true;+ const auto extent=clientExtent();+ return extent!=0&&completedExtent_.load(std::memory_order_acquire)==extent;+ }+ std::mutex& mutex(){return mutex_;}+private:+ uint64_t clientExtent()const{+ RECT rc{};+ if(!GetClientRect(window_,&rc)||rc.right<1||rc.bottom<1)return 0;+ return (uint64_t(uint32_t(rc.right))<<32)|uint32_t(rc.bottom);+ }+ HWND window_=nullptr;+ std::mutex mutex_;+ std::atomic<uint64_t> completedExtent_{0};+ uint64_t frameExtent_=0;+ bool held_=false,presented_=false; // this window's render thread only+};+inline std::mutex obsQtRegistryMutex;+inline std::vector<std::weak_ptr<ObsQtFrameGate>> obsQtFrameGates;+inline std::shared_ptr<ObsQtFrameGate> registerObsQtFrameGate(HWND window){+ auto gate=std::make_shared<ObsQtFrameGate>(window);+ const std::lock_guard lock(obsQtRegistryMutex);+ std::erase_if(obsQtFrameGates,[](const auto& existing){return existing.expired();});+ obsQtFrameGates.push_back(gate);+ return gate;+}+class ObsNativeResizeHold {+public:+ ObsNativeResizeHold(){+ {+ const std::lock_guard lock(obsQtRegistryMutex);+ for(auto& entry:obsQtFrameGates)if(auto gate=entry.lock())gates_.push_back(std::move(gate));+ }+ for(auto& gate:gates_){+ locks_.emplace_back(gate->mutex(),std::try_to_lock);+ if(!locks_.back().owns_lock()||!gate->readyForCurrentWindow()){+ locks_.clear();ready_=false;break;+ }+ }+ }+ bool ready()const{return ready_;}+ size_t windows()const{return gates_.size();}+private:+ std::vector<std::shared_ptr<ObsQtFrameGate>> gates_;+ std::vector<std::unique_lock<std::mutex>> locks_;+ bool ready_=true;+};+}diff --git a/src/engine/VideoPresenter.cpp b/src/engine/VideoPresenter.cppindex bd38b54f..e993c7f7 100644--- a/src/engine/VideoPresenter.cpp+++ b/src/engine/VideoPresenter.cpp@@ -3,6 +3,7 @@#include "veyra/pipeline/EnhanceGraph.h"#include "veyra/gfx/D3D12DeviceContext.h"#include "veyra/gfx/CommandSlotRing.h"+#include "veyra/gfx/ObsQtFrameGate.h"#include "veyra/sink/ImageExportSink.h"namespace veyra::engine {bool VideoPresenter::beginSourceInput(){@@ -137,7 +138,14 @@ bool VideoPresenter::present(gfx::D3D12DeviceContext& ctx,gfx::CommandSlotRing&SUCCEEDED(ctx.device()->GetDeviceRemovedReason())&&!GetEnvironmentVariableW(L"VEYRA_TEST_DISABLE_PAUSED_PRESENT_REUSE",nullptr,0))return true;retainedFrame_.reset(); // A failed present never seeds an idle cache.- if(!windowChanging&&(targetWidth!=sink_.width()||targetHeight!=sink_.height())&&GetTickCount64()>=deferUntil&&now-lastResize_>=std::chrono::milliseconds(100)&&sink_.resizeDue()) {+ bool resizeReady=!windowChanging&&(targetWidth!=sink_.width()||targetHeight!=sink_.height())&&GetTickCount64()>=deferUntil&&now-lastResize_>=std::chrono::milliseconds(100)&&sink_.resizeDue();+ std::optional<gfx::ObsNativeResizeHold> captureResizeHold;+ if(resizeReady&&GetModuleHandleW(L"graphics-hook64.dll")){+ captureResizeHold.emplace();resizeReady=captureResizeHold->ready();+ if(!resizeReady)captureResizeHold.reset(); // no native wait; retry next frame+ else veyra::log::info("capture-resize",std::format("Qt current extent complete; native resize target={}x{} qtWindows={}",targetWidth,targetHeight,captureResizeHold->windows()));+ }+ if(resizeReady) {resized=true;if(!ring.drainQueue())return false;sink_.resize(targetWidth,targetHeight);// A capture hook may temporarily retain a DXGI buffer. Keep the old@@ -275,6 +283,7 @@ bool VideoPresenter::present(gfx::D3D12DeviceContext& ctx,gfx::CommandSlotRing&const auto dxgiStart=std::chrono::steady_clock::now();reflex_.mark(reflexFrame_,3);reflex_.mark(reflexFrame_,4);const bool presented=sink_.present(st);+ captureResizeHold.reset();reflex_.mark(reflexFrame_,5);reflexFrame_=0;const auto presentEnd=std::chrono::steady_clock::now();const auto ms=[](auto d){return std::chrono::duration<double,std::milli>(d).count();};