Sunshine0.0.5917
Sunshine 0.0.5917
Self-hosted game stream host for Moonlight.
Loading...
Searching...
No Matches
wl::wlr_t Class Referenceabstract

Wayland screencopy capture backend shared by RAM and VRAM paths. More...

Inheritance diagram for wl::wlr_t:
Collaboration diagram for wl::wlr_t:

Public Member Functions

platf::capture_e acquire_frame (const pull_free_image_cb_t &pull_free_image_cb, std::shared_ptr< platf::img_t > &img_out, std::chrono::milliseconds timeout, bool cursor, const std::map< std::uint32_t, std::vector< std::uint64_t > > *encoder_modifiers=nullptr)
 Capture a display frame into the provided image object.
platf::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 frames until the stream stops or the display has to be set up again.
int dummy_img (platf::img_t *img) override
 Populate a fallback image when real capture data is unavailable.
int init (platf::mem_type_e hwdevice_type, const std::string &display_name, const ::video::config_t &config)
 Initialize Wayland screencopy capture for the selected output.
virtual platf::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)=0
 Capture a display frame into the provided image object.
void wait_for_next_request (std::chrono::steady_clock::time_point &next_frame)
 Wait until the next frame may be asked for.
Public Member Functions inherited from platf::display_t
virtual std::shared_ptr< img_t > alloc_img ()=0
 Allocate an image buffer compatible with this display backend.
virtual bool get_hdr_metadata (SS_HDR_METADATA &metadata)
 Read HDR metadata for the active display mode.
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 bool is_hdr ()
 Report whether the active display mode is HDR.
virtual std::unique_ptr< avcodec_encode_device_t > make_avcodec_encode_device (pix_fmt_e pix_fmt)
 Create AVCodec encode device.
virtual std::unique_ptr< nvenc_encode_device_t > make_nvenc_encode_device (pix_fmt_e pix_fmt)
 Create NVENC encode device.

Public Attributes

std::chrono::nanoseconds delay
 Delay before the timer task becomes eligible to run.
wl::display_t display
 Wayland display connection used for capture.
dmabuf_t dmabuf
 DMA-BUF feedback and format state advertised by the compositor.
bool event_driven {false}
 Whether frames are requested with copy_with_damage.
bool have_frame {false}
 Whether this capture has delivered a frame yet.
interface_t interface
 Wayland registry interfaces required by screencopy.
platf::mem_type_e mem_type
 Mem type.
std::chrono::steady_clock::time_point next_request {}
 Earliest time the next frame may be asked for when event-driven.
wl_output * output
 Wayland output selected for capture.
bool requested_cursor {false}
 Cursor setting the last screencopy request was made with.
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_offset_x {0}
 Horizontal origin of the full capture environment in native desktop coordinates.
int env_offset_y {0}
 Vertical origin of the full capture environment in native desktop coordinates.
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.

Additional Inherited Members

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.
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

Wayland screencopy capture backend shared by RAM and VRAM paths.

Member Function Documentation

◆ acquire_frame()

platf::capture_e wl::wlr_t::acquire_frame ( const pull_free_image_cb_t & pull_free_image_cb,
std::shared_ptr< platf::img_t > & img_out,
std::chrono::milliseconds timeout,
bool cursor,
const std::map< std::uint32_t, std::vector< std::uint64_t > > * encoder_modifiers = nullptr )
inline

Capture a display frame into the provided image object.

Parameters
pull_free_image_cbCallback that provides an available image buffer.
img_outCaptured wlroots image returned to the streaming pipeline.
timeoutMaximum time to wait for the operation.
cursorCursor image or visibility state to composite.
encoder_modifiersOptional encoder modifiers to intersect with compositor modifiers.
Returns
Capture status reported to the streaming pipeline.

◆ capture()

platf::capture_e wl::wlr_t::capture ( const push_captured_image_cb_t & push_captured_image_cb,
const pull_free_image_cb_t & pull_free_image_cb,
bool * cursor )
inlineoverridevirtual

Capture frames until the stream stops or the display has to be set up again.

Parameters
push_captured_image_cbCallback that takes a captured image, or a timeout without one.
pull_free_image_cbCallback that provides an available image buffer.
cursorWhether the cursor is to be part of the picture, read anew for every frame.
Returns
Capture status reported to the streaming pipeline.

Implements platf::display_t.

◆ dummy_img()

int wl::wlr_t::dummy_img ( platf::img_t * img)
inlineoverridevirtual

Populate a fallback image when real capture data is unavailable.

Parameters
imgImage or frame object to read from or populate.
Returns
Final capture status when callbacks stop capture or the display needs reinitialization.

Implements platf::display_t.

Reimplemented in wl::wlr_vram_t.

◆ init()

int wl::wlr_t::init ( platf::mem_type_e hwdevice_type,
const std::string & display_name,
const ::video::config_t & config )
inline

Initialize Wayland screencopy capture for the selected output.

Parameters
hwdevice_typeHardware device type requested for capture or encode.
display_nameDisplay name.
configConfiguration values to apply.
Returns
0 on success; nonzero or negative platform status on failure.

◆ snapshot()

virtual platf::capture_e wl::wlr_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 )
pure virtual

Capture a display frame into the provided image object.

Parameters
pull_free_image_cbCallback that provides an available image buffer.
img_outCaptured wlroots image returned to the streaming pipeline.
timeoutMaximum time to wait for the operation.
cursorCursor image or visibility state to composite.
Returns
Capture status reported to the streaming pipeline.

Implemented in wl::wlr_ram_t, and wl::wlr_vram_t.

◆ wait_for_next_request()

void wl::wlr_t::wait_for_next_request ( std::chrono::steady_clock::time_point & next_frame)
inline

Wait until the next frame may be asked for.

Paced capture sleeps to a clock of its own and then asks for a frame. That request makes the compositor commit at a time Sunshine chose, and the same picture can be captured twice while another is never seen.

Event-driven capture has no clock. The request is answered by the next commit that changed the picture, so a frame is captured once, when it exists. What is left to do here is keep an output that changes faster than the stream from being captured at its own rate, and that is a budget rather than a clock: every captured frame moves the earliest time of the next request on by one frame interval. A frame that arrives late resets the budget to a quarter interval before its own time, so a source running at the stream's rate is asked for with room to spare, while a faster one is held to the stream's rate on average.

Parameters
next_frameNext deadline of the paced clock, unused when event-driven.

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