Grabs the desktop as pixels, using the OS's own capture API. More...
#include <Malena/Screen/ScreenSource.h>
Public Member Functions | |
| ScreenSource () | |
| ScreenSource (const ScreenSource &)=delete | |
| ~ScreenSource () | |
| int | displayIndex () const |
| std::optional< sf::Image > | grab () |
| const std::string & | lastError () const |
| ScreenSource & | operator= (const ScreenSource &)=delete |
| void | setDisplayIndex (int index) |
| void | setMaxDimension (unsigned int pixels) |
Static Public Member Functions | |
| static std::optional< sf::Image > | decode (const std::uint8_t *data, std::size_t size) |
| static std::optional< std::vector< std::uint8_t > > | encodeJpeg (const sf::Image &frame) |
| static bool | isSupported () |
Grabs the desktop as pixels, using the OS's own capture API.
This is the capture half of screen sharing with no third-party media runtime: no GStreamer, nothing for the user to install. Each platform uses its native call (CGDisplayCreateImage on macOS, BitBlt on Windows, XGetImage on X11), and the result is handed back as a plain sf::Image so the rest of the pipeline is platform-agnostic.
Deliberately a pull API: the caller decides the frame rate by how often it calls grab(). A shared screen only needs a handful of frames per second, and pulling keeps the cost proportional to what is actually sent.
Definition at line 38 of file ScreenSource.h.
| ml::ScreenSource::ScreenSource | ( | ) |
| ml::ScreenSource::~ScreenSource | ( | ) |
|
delete |
|
static |
Decode a frame produced by encodeJpeg (or any format SFML reads).
| int ml::ScreenSource::displayIndex | ( | ) | const |
|
static |
Encode to JPEG in memory. Uses SFML's own encoder, so it needs no extra dependency; quality is fixed by SFML. Returns nullopt on failure.
| std::optional< sf::Image > ml::ScreenSource::grab | ( | ) |
Grab one frame, or nullopt if capture failed / is unavailable here.
|
static |
True when this platform has a capture backend compiled in.
| const std::string & ml::ScreenSource::lastError | ( | ) | const |
Human-readable reason capture is unavailable, or "" when it works.
|
delete |
| void ml::ScreenSource::setDisplayIndex | ( | int | index | ) |
Which display to capture (0 = main). Out-of-range falls back to main.
| void ml::ScreenSource::setMaxDimension | ( | unsigned int | pixels | ) |
Cap the long edge of captured frames, preserving aspect (0 = no scaling). A Retina desktop is enormous; downscaling before encoding is the single biggest win for both bandwidth and encode time.