Sunshine master
Self-hosted game stream host for Moonlight.
platf::dxgi::display_base_t Class Referenceabstract

Shared D3D11/DXGI state used by Windows display capture backends. More...

#include <src/platform/windows/display.h>

Inheritance diagram for platf::dxgi::display_base_t:
[legend]
Collaboration diagram for platf::dxgi::display_base_t:
[legend]

Classes

struct  _D3DKMT_CLOSEADAPTER
 Win32 D3DKMT adapter-close request structure. More...
 
struct  _D3DKMT_OPENADAPTERFROMLUID
 Win32 D3DKMT adapter-open request structure. More...
 
struct  _D3DKMT_QUERYADAPTERINFO
 Win32 D3DKMT adapter information query. More...
 
struct  _D3DKMT_WDDM_2_7_CAPS
 Win32 D3DKMT WDDM 2.7 capability flags. More...
 

Public Types

enum  _D3DKMT_SCHEDULINGPRIORITYCLASS {
  D3DKMT_SCHEDULINGPRIORITYCLASS_IDLE , D3DKMT_SCHEDULINGPRIORITYCLASS_BELOW_NORMAL , D3DKMT_SCHEDULINGPRIORITYCLASS_NORMAL , D3DKMT_SCHEDULINGPRIORITYCLASS_ABOVE_NORMAL ,
  D3DKMT_SCHEDULINGPRIORITYCLASS_HIGH , D3DKMT_SCHEDULINGPRIORITYCLASS_REALTIME
}
 Enumerates supported d3 DKMT SCHEDULINGPRIORITYCLASS options. More...
 
typedef struct platf::dxgi::display_base_t::_D3DKMT_CLOSEADAPTER D3DKMT_CLOSEADAPTER
 Win32 D3DKMT adapter-close request structure.
 
typedef UINT D3DKMT_HANDLE
 Kernel-mode D3DKMT adapter handle.
 
typedef struct platf::dxgi::display_base_t::_D3DKMT_OPENADAPTERFROMLUID D3DKMT_OPENADAPTERFROMLUID
 Win32 D3DKMT adapter-open request structure.
 
typedef struct platf::dxgi::display_base_t::_D3DKMT_QUERYADAPTERINFO D3DKMT_QUERYADAPTERINFO
 Win32 D3DKMT adapter information query.
 
typedef enum platf::dxgi::display_base_t::_D3DKMT_SCHEDULINGPRIORITYCLASS D3DKMT_SCHEDULINGPRIORITYCLASS
 Enumerates supported d3 DKMT SCHEDULINGPRIORITYCLASS options.
 
typedef struct platf::dxgi::display_base_t::_D3DKMT_WDDM_2_7_CAPS D3DKMT_WDDM_2_7_CAPS
 Win32 D3DKMT WDDM 2.7 capability flags.
 
typedef NTSTATUS(WINAPI *) PD3DKMTCloseAdapter(D3DKMT_CLOSEADAPTER *)
 Function pointer for closing a D3DKMT adapter handle.
 
typedef NTSTATUS(WINAPI *) PD3DKMTOpenAdapterFromLuid(D3DKMT_OPENADAPTERFROMLUID *)
 Function pointer for opening a D3DKMT adapter by LUID.
 
typedef NTSTATUS(WINAPI *) PD3DKMTQueryAdapterInfo(D3DKMT_QUERYADAPTERINFO *)
 Function pointer for querying D3DKMT adapter information.
 
typedef NTSTATUS(WINAPI *) PD3DKMTSetProcessSchedulingPriorityClass(HANDLE, D3DKMT_SCHEDULINGPRIORITYCLASS)
 Function pointer for setting D3DKMT process scheduling priority.
 
- Public Types inherited from platf::display_t
using pull_free_image_cb_t = std::function<bool(std::shared_ptr<img_t> &img_out)>
 Get free image from pool. Calls must be synchronized. Blocks until there is free image in the pool or capture is interrupted.
 
using push_captured_image_cb_t = std::function<bool(std::shared_ptr<img_t> &&img, bool frame_captured)>
 Callback for when a new image is ready. When display has a new image ready or a timeout occurs, this callback will be called with the image. If a frame was captured, frame_captured will be true. If a timeout occurred, it will be false.
 

Public Member Functions

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.
 
const char * colorspace_to_string (DXGI_COLOR_SPACE_TYPE type)
 Convert a DXGI colorspace enum to a diagnostic string.
 
const char * dxgi_format_to_string (DXGI_FORMAT format)
 Convert a DXGI format enum to a diagnostic string.
 
virtual bool get_hdr_metadata (SS_HDR_METADATA &metadata) override
 Read HDR metadata for the active display mode.
 
virtual std::vector< DXGI_FORMAT > get_supported_capture_formats ()=0
 Get supported capture formats.
 
int init (const ::video::config_t &config, const std::string &display_name)
 Initialize D3D11 desktop duplication for the selected output.
 
virtual bool is_hdr () override
 Report whether the active display mode is HDR.
 
- Public Member Functions inherited from platf::display_t
virtual std::shared_ptr< img_talloc_img ()=0
 Allocate an image buffer compatible with this display backend.
 
virtual int dummy_img (img_t *img)=0
 Populate a fallback image when real capture data is unavailable.
 
virtual bool is_codec_supported (std::string_view name, const ::video::config_t &config)
 Check that a given codec is supported by the display device.
 
virtual std::unique_ptr< avcodec_encode_device_tmake_avcodec_encode_device (pix_fmt_e pix_fmt)
 Create AVCodec encode device.
 
virtual std::unique_ptr< nvenc_encode_device_tmake_nvenc_encode_device (pix_fmt_e pix_fmt)
 Create NVENC encode device.
 

Public Attributes

adapter_t adapter
 DXGI adapter containing the selected output.
 
DXGI_FORMAT capture_format
 Capture format.
 
int client_frame_rate
 Client frame rate.
 
DXGI_RATIONAL client_frame_rate_strict
 Client frame rate strict.
 
device_t device
 D3D11 device used for desktop duplication capture.
 
device_ctx_t device_ctx
 D3D11 device context used for copy and render operations.
 
DXGI_RATIONAL display_refresh_rate
 Display refresh rate.
 
int display_refresh_rate_rounded
 Display refresh rate rounded.
 
DXGI_MODE_ROTATION display_rotation = DXGI_MODE_ROTATION_UNSPECIFIED
 Display rotation.
 
factory1_t factory
 DXGI factory used to enumerate adapters and outputs.
 
D3D_FEATURE_LEVEL feature_level
 Feature level.
 
int height_before_rotation
 Height before rotation.
 
const UINT KMTQAITYPE_WDDM_2_7_CAPS = 70
 Protocol or platform constant for kmtqaitype wddm 2 7 caps.
 
output_t output
 DXGI output duplicated for capture.
 
std::unique_ptr< high_precision_timertimer = create_high_precision_timer()
 Timer.
 
int width_before_rotation
 Width before rotation.
 
- Public Attributes inherited from platf::display_t
int env_height {0}
 Height of the full capture environment in physical pixels.
 
int env_logical_height {0}
 Height of the full capture environment after display scaling.
 
int env_logical_width {0}
 Width of the full capture environment after display scaling.
 
int env_width {0}
 Width of the full capture environment in physical pixels.
 
int height {0}
 Height of the captured display in physical pixels.
 
int logical_height {0}
 Height of the captured display after display scaling.
 
int logical_width {0}
 Width of the captured display after display scaling.
 
int offset_x {0}
 Horizontal capture offset in physical pixels.
 
int offset_y {0}
 Vertical capture offset in physical pixels.
 
int width {0}
 Width of the captured display in physical pixels.
 

Protected Member Functions

virtual int complete_img (img_t *img, bool dummy)=0
 Finish cursor composition into a RAM-backed image.
 
int get_pixel_pitch ()
 Get pixel pitch.
 
virtual capture_e release_snapshot ()=0
 Release resources associated with the last captured snapshot.
 
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.
 

Additional Inherited Members

- Protected Attributes inherited from platf::display_t
logging::time_delta_periodic_logger sleep_overshoot_logger = {debug, "Frame capture sleep overshoot"}
 Periodic logger for capture sleep overshoot measurements.
 

Detailed Description

Shared D3D11/DXGI state used by Windows display capture backends.

Member Typedef Documentation

◆ D3DKMT_CLOSEADAPTER

Win32 D3DKMT adapter-close request structure.

Alias for D3 DKMT CLOSEADAPTER.

◆ D3DKMT_OPENADAPTERFROMLUID

Win32 D3DKMT adapter-open request structure.

Alias for D3 DKMT OPENADAPTERFROMLUID.

◆ D3DKMT_QUERYADAPTERINFO

Win32 D3DKMT adapter information query.

Alias for D3 DKMT QUERYADAPTERINFO.

◆ D3DKMT_SCHEDULINGPRIORITYCLASS

Enumerates supported d3 DKMT SCHEDULINGPRIORITYCLASS options.

Alias for D3 DKMT SCHEDULINGPRIORITYCLASS.

◆ D3DKMT_WDDM_2_7_CAPS

Win32 D3DKMT WDDM 2.7 capability flags.

Alias for D3 DKMT WDDM 2 7 CAPS.

Member Enumeration Documentation

◆ _D3DKMT_SCHEDULINGPRIORITYCLASS

Enumerates supported d3 DKMT SCHEDULINGPRIORITYCLASS options.

Enumerator
D3DKMT_SCHEDULINGPRIORITYCLASS_IDLE 

Idle priority class.

D3DKMT_SCHEDULINGPRIORITYCLASS_BELOW_NORMAL 

Below normal priority class.

D3DKMT_SCHEDULINGPRIORITYCLASS_NORMAL 

Normal priority class.

D3DKMT_SCHEDULINGPRIORITYCLASS_ABOVE_NORMAL 

Above normal priority class.

D3DKMT_SCHEDULINGPRIORITYCLASS_HIGH 

High priority class.

D3DKMT_SCHEDULINGPRIORITYCLASS_REALTIME 

Realtime priority class.

Member Function Documentation

◆ capture()

capture_e platf::dxgi::display_base_t::capture ( const push_captured_image_cb_t & push_captured_image_cb,
const pull_free_image_cb_t & pull_free_image_cb,
bool * cursor )
overridevirtual

Capture a frame.

Parameters
push_captured_image_cbThe callback that is called with captured image, must be called from the same thread as capture()
pull_free_image_cbCapture backends call this callback to get empty image from the pool. If backend uses multiple threads, calls to this callback must be synchronized. Calls to this callback and push_captured_image_cb must be synchronized as well.
cursorA pointer to the flag that indicates whether the cursor should be captured as well.
Return values
capture_e::okWhen stopping
capture_e::errorOn error
capture_e::reinitWhen need of reinitialization

Implements platf::display_t.

◆ colorspace_to_string()

const char * platf::dxgi::display_base_t::colorspace_to_string ( DXGI_COLOR_SPACE_TYPE type)

Convert a DXGI colorspace enum to a diagnostic string.

Parameters
typeDXGI colorspace value reported by the output.
Returns
Static string describing the colorspace.

◆ complete_img()

virtual int platf::dxgi::display_base_t::complete_img ( img_t * img,
bool dummy )
protectedpure virtual

Finish cursor composition into a RAM-backed image.

Parameters
imgImage or frame object to read from or populate.
dummyUnused placeholder required by the interface signature.
Returns
Capture status after finalizing the captured image.

Implemented in platf::dxgi::display_ram_t, and platf::dxgi::display_vram_t.

◆ dxgi_format_to_string()

const char * platf::dxgi::display_base_t::dxgi_format_to_string ( DXGI_FORMAT format)

Convert a DXGI format enum to a diagnostic string.

Parameters
formatPixel, audio, or protocol format being converted.
Returns
Static string describing the DXGI format.

◆ get_hdr_metadata()

bool platf::dxgi::display_base_t::get_hdr_metadata ( SS_HDR_METADATA & metadata)
overridevirtual

Read HDR metadata for the active display mode.

Parameters
metadataOutput structure populated with HDR metadata.
Returns
True when HDR metadata was written to metadata.

Reimplemented from platf::display_t.

◆ get_pixel_pitch()

int platf::dxgi::display_base_t::get_pixel_pitch ( )
inlineprotected

Get pixel pitch.

Returns
Bytes per pixel for the active capture format.

◆ get_supported_capture_formats()

virtual std::vector< DXGI_FORMAT > platf::dxgi::display_base_t::get_supported_capture_formats ( )
pure virtual

Get supported capture formats.

Returns
Capture formats supported by this display backend.

Implemented in platf::dxgi::display_ram_t, and platf::dxgi::display_vram_t.

◆ init()

int platf::dxgi::display_base_t::init ( const ::video::config_t & config,
const std::string & display_name )

Initialize D3D11 desktop duplication for the selected output.

Parameters
configConfiguration values to apply.
display_nameDisplay name.
Returns
0 on success; nonzero or negative platform status on failure.

◆ is_hdr()

bool platf::dxgi::display_base_t::is_hdr ( )
overridevirtual

Report whether the active display mode is HDR.

Returns
True when the active display mode is HDR.

Reimplemented from platf::display_t.

◆ release_snapshot()

virtual capture_e platf::dxgi::display_base_t::release_snapshot ( )
protectedpure virtual

Release resources associated with the last captured snapshot.

Returns
Capture status after releasing the current snapshot.

Implemented in platf::dxgi::display_ddup_ram_t, platf::dxgi::display_ddup_vram_t, platf::dxgi::display_wgc_ram_t, and platf::dxgi::display_wgc_vram_t.

◆ snapshot()

virtual capture_e platf::dxgi::display_base_t::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 )
protectedpure virtual

Capture a display frame into the provided image object.

Parameters
pull_free_image_cbCallback that provides an available image buffer.
img_outCaptured image buffer returned to the streaming pipeline.
timeoutMaximum time to wait for the operation.
cursor_visibleCursor visible.
Returns
Capture status reported to the streaming pipeline.

Implemented in platf::dxgi::display_ddup_ram_t, platf::dxgi::display_ddup_vram_t, platf::dxgi::display_wgc_ram_t, and platf::dxgi::display_wgc_vram_t.


The documentation for this class was generated from the following files: