15#include <winrt/windows.graphics.capture.h>
22namespace platf::dxgi {
35 void Release(T *dxgi) {
248 case DXGI_MODE_ROTATION_UNSPECIFIED:
249 case DXGI_MODE_ROTATION_IDENTITY:
256 case DXGI_MODE_ROTATION_ROTATE90:
263 case DXGI_MODE_ROTATION_ROTATE180:
270 case DXGI_MODE_ROTATION_ROTATE270:
309 int init(const ::video::config_t &config,
const std::string &display_name);
365 UINT HwSchSupported : 1;
366 UINT HwSchEnabled : 1;
367 UINT HwSchEnabledByDefault : 1;
368 UINT IndependentVidPnVSyncControl : 1;
417 virtual bool is_hdr()
override;
454 return (
capture_format == DXGI_FORMAT_R16G16B16A16_FLOAT) ? 8 : 4;
493 std::shared_ptr<img_t>
alloc_img()
override;
538 std::shared_ptr<img_t>
alloc_img()
override;
561 bool is_codec_supported(std::string_view name, const ::video::config_t &config)
override;
598 int init(
display_base_t *display, const ::video::config_t &config);
637 int init(const ::video::config_t &config,
const std::string &display_name);
671 int init(const ::video::config_t &config,
const std::string &display_name);
711 winrt::Windows::Graphics::DirectX::Direct3D11::IDirect3DDevice uwp_device {
nullptr};
712 winrt::Windows::Graphics::Capture::GraphicsCaptureItem item {
nullptr};
713 winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool frame_pool {
nullptr};
714 winrt::Windows::Graphics::Capture::GraphicsCaptureSession capture_session {
nullptr};
715 winrt::Windows::Graphics::Capture::Direct3D11CaptureFrame produced_frame {
nullptr};
716 winrt::Windows::Graphics::Capture::Direct3D11CaptureFrame consumed_frame {
nullptr};
717 SRWLOCK frame_lock = SRWLOCK_INIT;
718 CONDITION_VARIABLE frame_present_cv;
720 void on_frame_arrived(winrt::Windows::Graphics::Capture::Direct3D11CaptureFramePool
const &sender, winrt::Windows::Foundation::IInspectable
const &);
772 int init(const ::video::config_t &config,
const std::string &display_name);
805 int init(const ::video::config_t &config,
const std::string &display_name);
Abstract display capture backend used by the streaming pipeline.
Definition common.h:658
std::function< bool(std::shared_ptr< img_t > &&img, bool frame_captured)> push_captured_image_cb_t
Callback for when a new image is ready. When display has a new image ready or a timeout occurs,...
Definition common.h:667
std::function< bool(std::shared_ptr< img_t > &img_out)> pull_free_image_cb_t
Get free image from pool. Calls must be synchronized. Blocks until there is free image in the pool or...
Definition common.h:676
Shared D3D11/DXGI state used by Windows display capture backends.
Definition display.h:300
DXGI_MODE_ROTATION display_rotation
Display rotation.
Definition display.h:321
device_t device
D3D11 device used for desktop duplication capture.
Definition display.h:316
NTSTATUS(WINAPI *) PD3DKMTCloseAdapter(D3DKMT_CLOSEADAPTER *)
Function pointer for closing a D3DKMT adapter handle.
Definition display.h:410
output_t output
DXGI output duplicated for capture.
Definition display.h:315
const char * colorspace_to_string(DXGI_COLOR_SPACE_TYPE type)
Convert a DXGI colorspace enum to a diagnostic string.
Definition display_base.cpp:973
const UINT KMTQAITYPE_WDDM_2_7_CAPS
Protocol or platform constant for kmtqaitype wddm 2 7 caps.
Definition display.h:386
D3D_FEATURE_LEVEL feature_level
Feature level.
Definition display.h:329
enum platf::dxgi::display_base_t::_D3DKMT_SCHEDULINGPRIORITYCLASS D3DKMT_SCHEDULINGPRIORITYCLASS
Enumerates supported d3 DKMT SCHEDULINGPRIORITYCLASS options.
int client_frame_rate
Client frame rate.
Definition display.h:325
int display_refresh_rate_rounded
Display refresh rate rounded.
Definition display.h:319
virtual bool is_hdr() override
Report whether the active display mode is HDR.
Definition display_base.cpp:760
NTSTATUS(WINAPI *) PD3DKMTSetProcessSchedulingPriorityClass(HANDLE, D3DKMT_SCHEDULINGPRIORITYCLASS)
Function pointer for setting D3DKMT process scheduling priority.
Definition display.h:398
virtual std::vector< DXGI_FORMAT > get_supported_capture_formats()=0
Get supported capture formats.
std::unique_ptr< high_precision_timer > timer
Timer.
Definition display.h:331
const char * dxgi_format_to_string(DXGI_FORMAT format)
Convert a DXGI format enum to a diagnostic string.
Definition display_base.cpp:969
struct platf::dxgi::display_base_t::_D3DKMT_OPENADAPTERFROMLUID D3DKMT_OPENADAPTERFROMLUID
Win32 D3DKMT adapter-open request structure.
virtual int complete_img(img_t *img, bool dummy)=0
Finish cursor composition into a RAM-backed image.
virtual bool get_hdr_metadata(SS_HDR_METADATA &metadata) override
Read HDR metadata for the active display mode.
Definition display_base.cpp:775
capture_e capture(const push_captured_image_cb_t &push_captured_image_cb, const pull_free_image_cb_t &pull_free_image_cb, bool *cursor) override
Capture a frame.
Definition display_base.cpp:212
int init(const ::video::config_t &config, const std::string &display_name)
Initialize D3D11 desktop duplication for the selected output.
Definition display_base.cpp:450
struct platf::dxgi::display_base_t::_D3DKMT_QUERYADAPTERINFO D3DKMT_QUERYADAPTERINFO
Win32 D3DKMT adapter information query.
int width_before_rotation
Width before rotation.
Definition display.h:322
NTSTATUS(WINAPI *) PD3DKMTQueryAdapterInfo(D3DKMT_QUERYADAPTERINFO *)
Function pointer for querying D3DKMT adapter information.
Definition display.h:406
DXGI_FORMAT capture_format
Capture format.
Definition display.h:328
_D3DKMT_SCHEDULINGPRIORITYCLASS
Enumerates supported d3 DKMT SCHEDULINGPRIORITYCLASS options.
Definition display.h:336
@ D3DKMT_SCHEDULINGPRIORITYCLASS_NORMAL
Normal priority class.
Definition display.h:339
@ D3DKMT_SCHEDULINGPRIORITYCLASS_BELOW_NORMAL
Below normal priority class.
Definition display.h:338
@ D3DKMT_SCHEDULINGPRIORITYCLASS_HIGH
High priority class.
Definition display.h:341
@ D3DKMT_SCHEDULINGPRIORITYCLASS_IDLE
Idle priority class.
Definition display.h:337
@ D3DKMT_SCHEDULINGPRIORITYCLASS_REALTIME
Realtime priority class.
Definition display.h:342
@ D3DKMT_SCHEDULINGPRIORITYCLASS_ABOVE_NORMAL
Above normal priority class.
Definition display.h:340
adapter_t adapter
DXGI adapter containing the selected output.
Definition display.h:314
DXGI_RATIONAL client_frame_rate_strict
Client frame rate strict.
Definition display.h:326
int height_before_rotation
Height before rotation.
Definition display.h:323
struct platf::dxgi::display_base_t::_D3DKMT_CLOSEADAPTER D3DKMT_CLOSEADAPTER
Win32 D3DKMT adapter-close request structure.
struct platf::dxgi::display_base_t::_D3DKMT_WDDM_2_7_CAPS D3DKMT_WDDM_2_7_CAPS
Win32 D3DKMT WDDM 2.7 capability flags.
virtual capture_e release_snapshot()=0
Release resources associated with the last captured snapshot.
factory1_t factory
DXGI factory used to enumerate adapters and outputs.
Definition display.h:313
int get_pixel_pitch()
Get pixel pitch.
Definition display.h:453
device_ctx_t device_ctx
D3D11 device context used for copy and render operations.
Definition display.h:317
UINT D3DKMT_HANDLE
Kernel-mode D3DKMT adapter handle.
Definition display.h:348
DXGI_RATIONAL display_refresh_rate
Display refresh rate.
Definition display.h:318
virtual capture_e snapshot(const pull_free_image_cb_t &pull_free_image_cb, std::shared_ptr< platf::img_t > &img_out, std::chrono::milliseconds timeout, bool cursor_visible)=0
Capture a display frame into the provided image object.
NTSTATUS(WINAPI *) PD3DKMTOpenAdapterFromLuid(D3DKMT_OPENADAPTERFROMLUID *)
Function pointer for opening a D3DKMT adapter by LUID.
Definition display.h:402
int init(const ::video::config_t &config, const std::string &display_name)
Initialize shared D3D capture resources for a RAM frame.
Definition display_ram.cpp:413
capture_e release_snapshot() override
Release resources associated with the last captured snapshot.
Definition display_ram.cpp:355
duplication_t dup
Desktop Duplication session used to acquire frames.
Definition display.h:655
cursor_t cursor
Cursor.
Definition display.h:656
capture_e snapshot(const pull_free_image_cb_t &pull_free_image_cb, std::shared_ptr< platf::img_t > &img_out, std::chrono::milliseconds timeout, bool cursor_visible) override
Capture a display frame into the provided image object.
Definition display_ram.cpp:208
capture_e snapshot(const pull_free_image_cb_t &pull_free_image_cb, std::shared_ptr< platf::img_t > &img_out, std::chrono::milliseconds timeout, bool cursor_visible) override
Capture a display frame into the provided image object.
Definition display_vram.cpp:1353
duplication_t dup
Desktop Duplication session used to acquire frames.
Definition display.h:689
std::variant< std::monostate, texture2d_t, std::shared_ptr< platf::img_t > > last_frame_variant
Last frame variant.
Definition display.h:704
blend_t blend_alpha
Blend alpha.
Definition display.h:692
capture_e release_snapshot() override
Release resources associated with the last captured snapshot.
Definition display_vram.cpp:1762
int init(const ::video::config_t &config, const std::string &display_name)
Initialize D3D cursor rendering resources for RAM capture.
Definition display_vram.cpp:1766
gpu_cursor_t cursor_xor
Cursor xor.
Definition display.h:700
std::chrono::steady_clock::time_point old_surface_timestamp
Old surface timestamp.
Definition display.h:703
texture2d_t old_surface_delayed_destruction
Old surface delayed destruction.
Definition display.h:702
ps_t cursor_ps
Cursor ps.
Definition display.h:696
blend_t blend_invert
Blend invert.
Definition display.h:693
vs_t cursor_vs
Cursor vs.
Definition display.h:697
sampler_state_t sampler_linear
Sampler linear.
Definition display.h:690
gpu_cursor_t cursor_alpha
Cursor alpha.
Definition display.h:699
blend_t blend_disable
Blend disable.
Definition display.h:694
std::shared_ptr< img_t > alloc_img() override
Allocate an image buffer compatible with this display backend.
Definition display_ram.cpp:359
std::unique_ptr< avcodec_encode_device_t > make_avcodec_encode_device(pix_fmt_e pix_fmt) override
Create AVCodec encode device.
Definition display_ram.cpp:421
D3D11_MAPPED_SUBRESOURCE img_info
CPU mapping information for the captured texture.
Definition display.h:524
int complete_img(img_t *img, bool dummy) override
Finish cursor composition into a GPU-backed image.
Definition display_ram.cpp:369
texture2d_t texture
D3D11 texture backing the captured frame.
Definition display.h:525
int dummy_img(img_t *img) override
Populate a fallback image when real capture data is unavailable.
std::vector< DXGI_FORMAT > get_supported_capture_formats() override
Get supported capture formats.
Definition display_ram.cpp:409
std::vector< DXGI_FORMAT > get_supported_capture_formats() override
Get supported capture formats.
Definition display_vram.cpp:2013
std::unique_ptr< nvenc_encode_device_t > make_nvenc_encode_device(pix_fmt_e pix_fmt) override
Create NVENC encode device.
Definition display_vram.cpp:2135
bool is_codec_supported(std::string_view name, const ::video::config_t &config) override
Check that a given codec is supported by the display device.
Definition display_vram.cpp:2043
int dummy_img(img_t *img_base) override
Populate a fallback image when real capture data is unavailable.
std::shared_ptr< img_t > alloc_img() override
Allocate an image buffer compatible with this display backend.
Definition display_vram.cpp:1913
std::atomic< uint32_t > next_image_id
Next image ID.
Definition display.h:579
int complete_img(img_t *img_base, bool dummy) override
Finalize a VRAM image after capture or dummy-frame generation.
Definition display_vram.cpp:1926
std::unique_ptr< avcodec_encode_device_t > make_avcodec_encode_device(pix_fmt_e pix_fmt) override
Create AVCodec encode device.
Definition display_vram.cpp:2127
int init(const ::video::config_t &config, const std::string &display_name)
Initialize shared D3D capture resources for a GPU frame.
Definition display_wgc.cpp:256
capture_e snapshot(const pull_free_image_cb_t &pull_free_image_cb, std::shared_ptr< platf::img_t > &img_out, std::chrono::milliseconds timeout, bool cursor_visible) override
Capture a display frame into the provided image object.
Definition display_wgc.cpp:268
capture_e release_snapshot() override
Release resources associated with the last captured snapshot.
Definition display_wgc.cpp:353
capture_e release_snapshot() override
Release resources associated with the last captured snapshot.
Definition display_vram.cpp:1901
capture_e snapshot(const pull_free_image_cb_t &pull_free_image_cb, std::shared_ptr< platf::img_t > &img_out, std::chrono::milliseconds timeout, bool cursor_visible) override
Capture a display frame into the provided image object.
Definition display_vram.cpp:1848
int init(const ::video::config_t &config, const std::string &display_name)
Initialize Windows Graphics Capture frame-pool resources.
Definition display_vram.cpp:1905
dup_t dup
Desktop Duplication capture session.
Definition display.h:587
capture_e next_frame(DXGI_OUTDUPL_FRAME_INFO &frame_info, std::chrono::milliseconds timeout, resource_t::pointer *res_p)
Acquire the next frame from the Windows capture backend.
Definition display_base.cpp:144
bool has_frame
Whether a frame is currently held by the duplication object.
Definition display.h:588
capture_e release_frame()
Release resources associated with frame.
Definition display_base.cpp:184
std::chrono::steady_clock::time_point last_protected_content_warning_time
Last protected content warning time.
Definition display.h:589
capture_e reset(dup_t::pointer dup_p=dup_t::pointer())
Reset the object to its initial empty state.
Definition display_base.cpp:176
GPU resources used to render a captured cursor shape.
Definition display.h:204
LONG topleft_y
Topleft y.
Definition display.h:284
LONG display_height
Display height.
Definition display.h:287
LONG texture_width
Texture width.
Definition display.h:280
shader_res_t input_res
Input res.
Definition display.h:290
LONG display_width
Display width.
Definition display.h:286
void set_pos(LONG topleft_x, LONG topleft_y, LONG display_width, LONG display_height, DXGI_MODE_ROTATION display_rotation, bool visible)
Update the cursor position and display geometry used for rendering.
Definition display.h:219
void set_texture(LONG texture_width, LONG texture_height, texture2d_t &&texture)
Replace the cursor texture and update its render viewport.
Definition display.h:236
LONG texture_height
Texture height.
Definition display.h:281
DXGI_MODE_ROTATION display_rotation
Display rotation.
Definition display.h:288
void update_viewport()
Recalculate the D3D viewport for the cursor texture.
Definition display.h:246
D3D11_VIEWPORT cursor_view
Cursor view.
Definition display.h:292
bool visible
Whether the cursor is visible.
Definition display.h:294
LONG topleft_x
Topleft x.
Definition display.h:283
texture2d_t texture
D3D11 texture backing the captured frame.
Definition display.h:279
capture_e next_frame(std::chrono::milliseconds timeout, ID3D11Texture2D **out, uint64_t &out_time)
Acquire the next frame from the Windows capture backend.
Definition display_wgc.cpp:206
capture_e release_frame()
Release resources associated with frame.
Definition display_wgc.cpp:237
int set_cursor_visible(bool cursor_visible)
Enable or disable cursor composition in Windows.Graphics.Capture frames.
Definition display_wgc.cpp:245
int init(display_base_t *display, const ::video::config_t &config)
Initialize D3D cursor rendering resources for GPU capture.
Definition display_wgc.cpp:103
Unique pointer wrapper with customizable pointer and deleter types.
Definition utility.h:820
element_type * pointer
Pointer type stored by the unique pointer wrapper.
Definition utility.h:829
Declarations for common platform specific utilities.
std::shared_ptr< display_t > display(mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config)
Get the display_t instance for the given hwdevice_type. If display_name is empty, use the first monit...
Definition misc.cpp:1254
pix_fmt_e
Enumerates supported pix fmt options.
Definition common.h:316
std::unique_ptr< high_precision_timer > create_high_precision_timer()
Create platform-specific timer capable of high-precision sleep.
Definition misc.cpp:1394
capture_e
Enumerates supported capture options.
Definition common.h:647
const char * format_str[]
Names for DXGI_FORMAT values used in diagnostic logging.
Definition display_base.cpp:831
auto constexpr D3D11_CREATE_DEVICE_FLAGS
Protocol or platform constant for d3 d11 create device flags.
Definition display.h:27
long NTSTATUS
Windows NT status code returned by native APIs.
Definition display_base.cpp:25
Cursor position and visibility for the current capture frame.
Definition display.h:192
bool visible
Whether the cursor is visible.
Definition display.h:198
std::vector< std::uint8_t > img_data
Raw pointer-shape bytes from DXGI output duplication.
Definition display.h:193
DXGI_OUTDUPL_POINTER_SHAPE_INFO shape_info
Shape info.
Definition display.h:195
int x
X.
Definition display.h:196
int y
Y.
Definition display.h:197
Win32 D3DKMT adapter-close request structure.
Definition display.h:391
D3DKMT_HANDLE hAdapter
D3DKMT adapter handle used for low-level display queries.
Definition display.h:392
Win32 D3DKMT adapter-open request structure.
Definition display.h:353
D3DKMT_HANDLE hAdapter
D3DKMT adapter handle used for low-level display queries.
Definition display.h:355
LUID AdapterLuid
Adapter luid.
Definition display.h:354
Win32 D3DKMT adapter information query.
Definition display.h:379
UINT Type
Type.
Definition display.h:381
D3DKMT_HANDLE hAdapter
D3DKMT adapter handle used for low-level display queries.
Definition display.h:380
VOID * pPrivateDriverData
P private driver data.
Definition display.h:382
UINT PrivateDriverDataSize
Private driver data size.
Definition display.h:383
Win32 D3DKMT WDDM 2.7 capability flags.
Definition display.h:361
Captured frame buffer shared between capture and encode stages.
Definition display_ram.cpp:18
Declarations for utility functions.