Sunshine master
Self-hosted game stream host for Moonlight.
pipewire::pipewire_display_t Class Referenceabstract

Display capture backend that consumes frames from a PipeWire stream. More...

Inheritance diagram for pipewire::pipewire_display_t:
[legend]
Collaboration diagram for pipewire::pipewire_display_t:
[legend]

Public Member Functions

std::shared_ptr< platf::img_talloc_img () override
 Allocate an image buffer compatible with this display backend.
 
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 a frame.
 
virtual bool check_stream_dead (platf::capture_e &out_status)
 Check stream dead.
 
virtual int configure_stream (const std::string &display_name, int &out_pipewire_fd, uint32_t &out_pipewire_node, uint64_t &out_pipewire_objectserial)=0
 Configure the pipewire stream.
 
int dummy_img (platf::img_t *img) override
 Populate a fallback image when real capture data is unavailable.
 
bool get_hdr_metadata (SS_HDR_METADATA &metadata) override
 Read HDR metadata for the active display mode.
 
int init (platf::mem_type_e hwdevice_type, const std::string &display_name, const ::video::config_t &config)
 Initialize the PipeWire display backend for a selected stream.
 
bool is_hdr () override
 Report whether the active display mode is HDR.
 
std::unique_ptr< platf::avcodec_encode_device_tmake_avcodec_encode_device (platf::pix_fmt_e pix_fmt) override
 Create AVCodec encode device.
 
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 show_cursor)
 Capture a display frame into the provided image object.
 
virtual void verify_and_update_display_parameters ()
 Verify and update display parameters for logical dimensions, desktop dimensions and logical desktop dimensions (default is adapted from wlgrab)
 
- Public Member Functions inherited from platf::display_t
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< nvenc_encode_device_tmake_nvenc_encode_device (pix_fmt_e pix_fmt)
 Create NVENC encode device.
 

Static Public Member Functions

static bool init_pipewire_and_check_hwdevice_type (platf::mem_type_e hwdevice_type)
 Initialize pipewire and check hwdevice type.
 

Protected Attributes

pipewire_t pipewire
 Pipewire.
 
std::shared_ptr< shared_state_tshared_state
 Shared state.
 
- 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.
 

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

Detailed Description

Display capture backend that consumes frames from a PipeWire stream.

Member Function Documentation

◆ alloc_img()

std::shared_ptr< platf::img_t > pipewire::pipewire_display_t::alloc_img ( )
inlineoverridevirtual

Allocate an image buffer compatible with this display backend.

Returns
Allocated img object, or null when unavailable.

Implements platf::display_t.

◆ capture()

platf::capture_e pipewire::pipewire_display_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 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.

◆ check_stream_dead()

virtual bool pipewire::pipewire_display_t::check_stream_dead ( platf::capture_e & out_status)
inlinevirtual

Check stream dead.

Parameters
out_statusOut status.
Returns
True when the PipeWire stream can no longer produce frames.

Reimplemented in portal::portal_t.

◆ configure_stream()

virtual int pipewire::pipewire_display_t::configure_stream ( const std::string & display_name,
int & out_pipewire_fd,
uint32_t & out_pipewire_node,
uint64_t & out_pipewire_objectserial )
pure virtual

Configure the pipewire stream.

Parameters
display_nameprovide a stream for this display_name
out_pipewire_fdset to the pipewire fd for the stream during function call (or -1 for using the local context)
out_pipewire_nodeset to the pipewire node of the stream during function call (or PW_ID_ANY to refer to object_serial)
out_pipewire_objectserialset the pipewire object serial of the stream during function call
Returns
0 if the stream successfully configured

Implemented in kwin::kwin_t, and portal::portal_t.

◆ dummy_img()

int pipewire::pipewire_display_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
Capture status reported to the streaming pipeline.

Implements platf::display_t.

◆ get_hdr_metadata()

bool pipewire::pipewire_display_t::get_hdr_metadata ( SS_HDR_METADATA & metadata)
inlineoverridevirtual

Read HDR metadata for the active display mode.

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

Reimplemented from platf::display_t.

◆ init()

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

Initialize the PipeWire display backend for a selected stream.

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.

◆ init_pipewire_and_check_hwdevice_type()

static bool pipewire::pipewire_display_t::init_pipewire_and_check_hwdevice_type ( platf::mem_type_e hwdevice_type)
inlinestatic

Initialize pipewire and check hwdevice type.

Parameters
hwdevice_typeHardware device type requested for capture or encode.
Returns
True when PipeWire is initialized and the hardware device type is supported.

◆ is_hdr()

bool pipewire::pipewire_display_t::is_hdr ( )
inlineoverridevirtual

Report whether the active display mode is HDR.

Returns
True when the active display mode is HDR.

Reimplemented from platf::display_t.

◆ make_avcodec_encode_device()

std::unique_ptr< platf::avcodec_encode_device_t > pipewire::pipewire_display_t::make_avcodec_encode_device ( platf::pix_fmt_e pix_fmt)
inlineoverridevirtual

Create AVCodec encode device.

Parameters
pix_fmtSunshine pixel format to convert or allocate for.
Returns
Constructed AVCodec encode device object.

Reimplemented from platf::display_t.

◆ snapshot()

platf::capture_e pipewire::pipewire_display_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 show_cursor )
inline

Capture a display frame into the provided image object.

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

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