diff options
author | Jøger Hansegård <joger.hansegard@qt.io> | 2023-05-24 13:34:05 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-05-30 15:56:41 +0000 |
commit | c5313d0996ef8a48337d4f0fa22d82ee0cf1a9ea (patch) | |
tree | fb321f970eba4eaa241e1c7ff59c9d05ec8d229d | |
parent | ed3803ed55e39b9a636ef184da1fd7c6304de85e (diff) |
Make getNextFrame function part of DXGI grabber
Moving the function inside the grabber class will allow us to keep some
state around.
This will be used for example to improve the grabber performance by
avoiding releasing the grabbed frame too frequently.
Task-number: QTBUG-113460
Change-Id: If883071926b8e7ec9d8a4a156aabcaee8d3370cc
Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Reviewed-by: Lars Knoll <lars@knoll.priv.no>
(cherry picked from commit 9b38bc514c658117a4ee0cb3bfbe6010ff864914)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi.cpp | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi.cpp b/src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi.cpp index 16730ca06..057fa700f 100644 --- a/src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi.cpp +++ b/src/plugins/multimedia/ffmpeg/qffmpegscreencapture_dxgi.cpp @@ -117,42 +117,6 @@ private: QVideoFrame::MapMode m_mapMode = QVideoFrame::NotMapped; }; -static QMaybe<QComPtr<ID3D11Texture2D>> getNextFrame(ID3D11Device *dev, IDXGIOutputDuplication *dup) -{ - QComPtr<IDXGIResource> frame; - DXGI_OUTDUPL_FRAME_INFO info; - HRESULT hr = dup->AcquireNextFrame(0, &info, frame.address()); - if (FAILED(hr)) - return hr == DXGI_ERROR_WAIT_TIMEOUT ? QString{} - : "Failed to grab the screen content" + errorString(hr); - - QComPtr<ID3D11Texture2D> tex; - hr = frame->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void **>(tex.address())); - if (FAILED(hr)) { - dup->ReleaseFrame(); - return "Failed to obtain D3D11 texture" + errorString(hr); - } - - D3D11_TEXTURE2D_DESC texDesc = {}; - tex->GetDesc(&texDesc); - texDesc.MiscFlags = 0; - texDesc.BindFlags = 0; - QComPtr<ID3D11Texture2D> texCopy; - hr = dev->CreateTexture2D(&texDesc, nullptr, texCopy.address()); - if (FAILED(hr)) { - dup->ReleaseFrame(); - return "Failed to create texture with CPU access" + errorString(hr); - } - - QComPtr<ID3D11DeviceContext> ctx; - dev->GetImmediateContext(ctx.address()); - ctx->CopyResource(texCopy.get(), tex.get()); - - dup->ReleaseFrame(); - - return texCopy; -} - class QFFmpegScreenCaptureDxgi::Grabber : public QFFmpegScreenCaptureThread { public: @@ -198,7 +162,7 @@ public: QVideoFrame grabFrame() override { m_ctxMutex->lock(); - auto maybeTex = getNextFrame(m_device.get(), m_duplication.get()); + auto maybeTex = getNextFrame(); m_ctxMutex->unlock(); if (maybeTex) { @@ -213,6 +177,42 @@ public: }; private: + QMaybe<QComPtr<ID3D11Texture2D>> getNextFrame() + { + QComPtr<IDXGIResource> frame; + DXGI_OUTDUPL_FRAME_INFO info; + HRESULT hr = m_duplication->AcquireNextFrame(0, &info, frame.address()); + if (FAILED(hr)) + return hr == DXGI_ERROR_WAIT_TIMEOUT ? QString{} + : "Failed to grab the screen content" + ::errorString(hr); + + QComPtr<ID3D11Texture2D> tex; + hr = frame->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void **>(tex.address())); + if (FAILED(hr)) { + m_duplication->ReleaseFrame(); + return "Failed to obtain D3D11 texture" + ::errorString(hr); + } + + D3D11_TEXTURE2D_DESC texDesc = {}; + tex->GetDesc(&texDesc); + texDesc.MiscFlags = 0; + texDesc.BindFlags = 0; + QComPtr<ID3D11Texture2D> texCopy; + hr = m_device->CreateTexture2D(&texDesc, nullptr, texCopy.address()); + if (FAILED(hr)) { + m_duplication->ReleaseFrame(); + return "Failed to create texture with CPU access" + ::errorString(hr); + } + + QComPtr<ID3D11DeviceContext> ctx; + m_device->GetImmediateContext(ctx.address()); + ctx->CopyResource(texCopy.get(), tex.get()); + + m_duplication->ReleaseFrame(); + + return texCopy; + } + QComPtr<IDXGIOutputDuplication> m_duplication; QComPtr<ID3D11Device> m_device; QWaitCondition m_waitForFormat; |