Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ MAIL(switch_display);
MAIL(touch_port);
MAIL(idr);
MAIL(rumble);
MAIL(hdr);
#undef MAIL
} // namespace mail
#endif // SUNSHINE_MAIN_H
20 changes: 18 additions & 2 deletions src/platform/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#include "src/thread_safe.h"
#include "src/utility.h"

extern "C" {
#include <moonlight-common-c/src/Limelight.h>
}

struct sockaddr;
struct AVFrame;
struct AVBufferRef;
Expand All @@ -39,6 +43,9 @@ class basic_environment;
typedef basic_environment<char> environment;
} // namespace process
} // namespace boost
namespace video {
struct config_t;
}

namespace platf {
constexpr auto MAX_GAMEPADS = 32;
Expand Down Expand Up @@ -270,6 +277,15 @@ class display_t {
return std::make_shared<hwdevice_t>();
}

virtual bool is_hdr() {
return false;
}

virtual bool get_hdr_metadata(SS_HDR_METADATA &metadata) {
std::memset(&metadata, 0, sizeof(metadata));
return false;
}

virtual ~display_t() = default;

// Offsets for when streaming a specific monitor. By default, they are 0.
Expand Down Expand Up @@ -315,11 +331,11 @@ std::unique_ptr<audio_control_t> audio_control();
* If display_name is empty --> Use the first monitor that's compatible you can find
* If you require to use this parameter in a seperate thread --> make a copy of it.
*
* framerate --> The peak number of images per second
* config --> Stream configuration
*
* Returns display_t based on hwdevice_type
*/
std::shared_ptr<display_t> display(mem_type_e hwdevice_type, const std::string &display_name, int framerate);
std::shared_ptr<display_t> display(mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config);

// A list of names of displays accepted as display_name with the mem_type_e
std::vector<std::string> display_names(mem_type_e hwdevice_type);
Expand Down
11 changes: 6 additions & 5 deletions src/platform/linux/cuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ extern "C" {
#include "graphics.h"
#include "src/main.h"
#include "src/utility.h"
#include "src/video.h"
#include "wayland.h"

#define SUNSHINE_STRINGVIEW_HELPER(x) x##sv
Expand Down Expand Up @@ -414,7 +415,7 @@ class handle_t {

class display_t : public platf::display_t {
public:
int init(const std::string_view &display_name, int framerate) {
int init(const std::string_view &display_name, const ::video::config_t &config) {
auto handle = handle_t::make();
if(!handle) {
return -1;
Expand Down Expand Up @@ -444,14 +445,14 @@ class display_t : public platf::display_t {
}
}

delay = std::chrono::nanoseconds { 1s } / framerate;
delay = std::chrono::nanoseconds { 1s } / config.framerate;

capture_params = NVFBC_CREATE_CAPTURE_SESSION_PARAMS { NVFBC_CREATE_CAPTURE_SESSION_PARAMS_VER };

capture_params.eCaptureType = NVFBC_CAPTURE_SHARED_CUDA;
capture_params.bDisableAutoModesetRecovery = nv_bool(true);

capture_params.dwSamplingRateMs = 1000 /* ms */ / framerate;
capture_params.dwSamplingRateMs = 1000 /* ms */ / config.framerate;

if(streamedMonitor != -1) {
auto &output = status_params->outputs[streamedMonitor];
Expand Down Expand Up @@ -663,15 +664,15 @@ class display_t : public platf::display_t {
} // namespace cuda

namespace platf {
std::shared_ptr<display_t> nvfbc_display(mem_type_e hwdevice_type, const std::string &display_name, int framerate) {
std::shared_ptr<display_t> nvfbc_display(mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config) {
if(hwdevice_type != mem_type_e::cuda) {
BOOST_LOG(error) << "Could not initialize nvfbc display with the given hw device type"sv;
return nullptr;
}

auto display = std::make_shared<cuda::nvfbc::display_t>();

if(display->init(display_name, framerate)) {
if(display->init(display_name, config)) {
return nullptr;
}

Expand Down
19 changes: 10 additions & 9 deletions src/platform/linux/kmsgrab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "src/platform/common.h"
#include "src/round_robin.h"
#include "src/utility.h"
#include "src/video.h"

// Cursor rendering support through x11
#include "graphics.h"
Expand Down Expand Up @@ -444,8 +445,8 @@ class display_t : public platf::display_t {
public:
display_t(mem_type_e mem_type) : platf::display_t(), mem_type { mem_type } {}

int init(const std::string &display_name, int framerate) {
delay = std::chrono::nanoseconds { 1s } / framerate;
int init(const std::string &display_name, const ::video::config_t &config) {
delay = std::chrono::nanoseconds { 1s } / config.framerate;

int monitor_index = util::from_view(display_name);
int monitor = 0;
Expand Down Expand Up @@ -632,13 +633,13 @@ class display_ram_t : public display_t {
public:
display_ram_t(mem_type_e mem_type) : display_t(mem_type) {}

int init(const std::string &display_name, int framerate) {
int init(const std::string &display_name, const ::video::config_t &config) {
if(!gbm::create_device) {
BOOST_LOG(warning) << "libgbm not initialized"sv;
return -1;
}

if(display_t::init(display_name, framerate)) {
if(display_t::init(display_name, config)) {
return -1;
}

Expand Down Expand Up @@ -852,8 +853,8 @@ class display_vram_t : public display_t {
return capture_e::ok;
}

int init(const std::string &display_name, int framerate) {
if(display_t::init(display_name, framerate)) {
int init(const std::string &display_name, const ::video::config_t &config) {
if(display_t::init(display_name, config)) {
return -1;
}

Expand All @@ -872,11 +873,11 @@ class display_vram_t : public display_t {

} // namespace kms

std::shared_ptr<display_t> kms_display(mem_type_e hwdevice_type, const std::string &display_name, int framerate) {
std::shared_ptr<display_t> kms_display(mem_type_e hwdevice_type, const std::string &display_name, const ::video::config_t &config) {
if(hwdevice_type == mem_type_e::vaapi) {
auto disp = std::make_shared<kms::display_vram_t>(hwdevice_type);

if(!disp->init(display_name, framerate)) {
if(!disp->init(display_name, config)) {
return disp;
}

Expand All @@ -885,7 +886,7 @@ std::shared_ptr<display_t> kms_display(mem_type_e hwdevice_type, const std::stri

auto disp = std::make_shared<kms::display_ram_t>(hwdevice_type);

if(disp->init(display_name, framerate)) {
if(disp->init(display_name, config)) {
return nullptr;
}

Expand Down
18 changes: 9 additions & 9 deletions src/platform/linux/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ static std::bitset<source::MAX_FLAGS> sources;

#ifdef SUNSHINE_BUILD_CUDA
std::vector<std::string> nvfbc_display_names();
std::shared_ptr<display_t> nvfbc_display(mem_type_e hwdevice_type, const std::string &display_name, int framerate);
std::shared_ptr<display_t> nvfbc_display(mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config);

bool verify_nvfbc() {
return !nvfbc_display_names().empty();
Expand All @@ -427,7 +427,7 @@ bool verify_nvfbc() {

#ifdef SUNSHINE_BUILD_WAYLAND
std::vector<std::string> wl_display_names();
std::shared_ptr<display_t> wl_display(mem_type_e hwdevice_type, const std::string &display_name, int framerate);
std::shared_ptr<display_t> wl_display(mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config);

bool verify_wl() {
return window_system == window_system_e::WAYLAND && !wl_display_names().empty();
Expand All @@ -436,7 +436,7 @@ bool verify_wl() {

#ifdef SUNSHINE_BUILD_DRM
std::vector<std::string> kms_display_names();
std::shared_ptr<display_t> kms_display(mem_type_e hwdevice_type, const std::string &display_name, int framerate);
std::shared_ptr<display_t> kms_display(mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config);

bool verify_kms() {
return !kms_display_names().empty();
Expand All @@ -445,7 +445,7 @@ bool verify_kms() {

#ifdef SUNSHINE_BUILD_X11
std::vector<std::string> x11_display_names();
std::shared_ptr<display_t> x11_display(mem_type_e hwdevice_type, const std::string &display_name, int framerate);
std::shared_ptr<display_t> x11_display(mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config);

bool verify_x11() {
return window_system == window_system_e::X11 && !x11_display_names().empty();
Expand All @@ -469,29 +469,29 @@ std::vector<std::string> display_names(mem_type_e hwdevice_type) {
return {};
}

std::shared_ptr<display_t> display(mem_type_e hwdevice_type, const std::string &display_name, int framerate) {
std::shared_ptr<display_t> display(mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config) {
#ifdef SUNSHINE_BUILD_CUDA
if(sources[source::NVFBC] && hwdevice_type == mem_type_e::cuda) {
BOOST_LOG(info) << "Screencasting with NvFBC"sv;
return nvfbc_display(hwdevice_type, display_name, framerate);
return nvfbc_display(hwdevice_type, display_name, config);
}
#endif
#ifdef SUNSHINE_BUILD_WAYLAND
if(sources[source::WAYLAND]) {
BOOST_LOG(info) << "Screencasting with Wayland's protocol"sv;
return wl_display(hwdevice_type, display_name, framerate);
return wl_display(hwdevice_type, display_name, config);
}
#endif
#ifdef SUNSHINE_BUILD_DRM
if(sources[source::KMS]) {
BOOST_LOG(info) << "Screencasting with KMS"sv;
return kms_display(hwdevice_type, display_name, framerate);
return kms_display(hwdevice_type, display_name, config);
}
#endif
#ifdef SUNSHINE_BUILD_X11
if(sources[source::X11]) {
BOOST_LOG(info) << "Screencasting with X11"sv;
return x11_display(hwdevice_type, display_name, framerate);
return x11_display(hwdevice_type, display_name, config);
}
#endif

Expand Down
15 changes: 8 additions & 7 deletions src/platform/linux/wlgrab.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "src/platform/common.h"

#include "src/main.h"
#include "src/video.h"
#include "vaapi.h"
#include "wayland.h"

Expand All @@ -18,8 +19,8 @@ struct img_t : public platf::img_t {

class wlr_t : public platf::display_t {
public:
int init(platf::mem_type_e hwdevice_type, const std::string &display_name, int framerate) {
delay = std::chrono::nanoseconds { 1s } / framerate;
int init(platf::mem_type_e hwdevice_type, const std::string &display_name, const ::video::config_t &config) {
delay = std::chrono::nanoseconds { 1s } / config.framerate;
mem_type = hwdevice_type;

if(display.init()) {
Expand Down Expand Up @@ -175,8 +176,8 @@ class wlr_ram_t : public wlr_t {
return platf::capture_e::ok;
}

int init(platf::mem_type_e hwdevice_type, const std::string &display_name, int framerate) {
if(wlr_t::init(hwdevice_type, display_name, framerate)) {
int init(platf::mem_type_e hwdevice_type, const std::string &display_name, const ::video::config_t &config) {
if(wlr_t::init(hwdevice_type, display_name, config)) {
return -1;
}

Expand Down Expand Up @@ -307,23 +308,23 @@ class wlr_vram_t : public wlr_t {
} // namespace wl

namespace platf {
std::shared_ptr<display_t> wl_display(mem_type_e hwdevice_type, const std::string &display_name, int framerate) {
std::shared_ptr<display_t> wl_display(mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config) {
if(hwdevice_type != platf::mem_type_e::system && hwdevice_type != platf::mem_type_e::vaapi && hwdevice_type != platf::mem_type_e::cuda) {
BOOST_LOG(error) << "Could not initialize display with the given hw device type."sv;
return nullptr;
}

if(hwdevice_type == platf::mem_type_e::vaapi) {
auto wlr = std::make_shared<wl::wlr_vram_t>();
if(wlr->init(hwdevice_type, display_name, framerate)) {
if(wlr->init(hwdevice_type, display_name, config)) {
return nullptr;
}

return wlr;
}

auto wlr = std::make_shared<wl::wlr_ram_t>();
if(wlr->init(hwdevice_type, display_name, framerate)) {
if(wlr->init(hwdevice_type, display_name, config)) {
return nullptr;
}

Expand Down
15 changes: 8 additions & 7 deletions src/platform/linux/x11grab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "src/config.h"
#include "src/main.h"
#include "src/task_pool.h"
#include "src/video.h"

#include "cuda.h"
#include "graphics.h"
Expand Down Expand Up @@ -382,13 +383,13 @@ struct x11_attr_t : public display_t {
x11::InitThreads();
}

int init(const std::string &display_name, int framerate) {
int init(const std::string &display_name, const ::video::config_t &config) {
if(!xdisplay) {
BOOST_LOG(error) << "Could not open X11 display"sv;
return -1;
}

delay = std::chrono::nanoseconds { 1s } / framerate;
delay = std::chrono::nanoseconds { 1s } / config.framerate;

xwindow = DefaultRootWindow(xdisplay.get());

Expand Down Expand Up @@ -641,8 +642,8 @@ struct shm_attr_t : public x11_attr_t {
return 0;
}

int init(const std::string &display_name, int framerate) {
if(x11_attr_t::init(display_name, framerate)) {
int init(const std::string &display_name, const ::video::config_t &config) {
if(x11_attr_t::init(display_name, config)) {
return 1;
}

Expand Down Expand Up @@ -685,7 +686,7 @@ struct shm_attr_t : public x11_attr_t {
}
};

std::shared_ptr<display_t> x11_display(platf::mem_type_e hwdevice_type, const std::string &display_name, int framerate) {
std::shared_ptr<display_t> x11_display(platf::mem_type_e hwdevice_type, const std::string &display_name, const ::video::config_t &config) {
if(hwdevice_type != platf::mem_type_e::system && hwdevice_type != platf::mem_type_e::vaapi && hwdevice_type != platf::mem_type_e::cuda) {
BOOST_LOG(error) << "Could not initialize x11 display with the given hw device type"sv;
return nullptr;
Expand All @@ -700,7 +701,7 @@ std::shared_ptr<display_t> x11_display(platf::mem_type_e hwdevice_type, const st
// Attempt to use shared memory X11 to avoid copying the frame
auto shm_disp = std::make_shared<shm_attr_t>(hwdevice_type);

auto status = shm_disp->init(display_name, framerate);
auto status = shm_disp->init(display_name, config);
if(status > 0) {
// x11_attr_t::init() failed, don't bother trying again.
return nullptr;
Expand All @@ -712,7 +713,7 @@ std::shared_ptr<display_t> x11_display(platf::mem_type_e hwdevice_type, const st

// Fallback
auto x11_disp = std::make_shared<x11_attr_t>(hwdevice_type);
if(x11_disp->init(display_name, framerate)) {
if(x11_disp->init(display_name, config)) {
return nullptr;
}

Expand Down
9 changes: 7 additions & 2 deletions src/platform/macos/display.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#include "src/config.h"
#include "src/main.h"

// Avoid conflict between AVFoundation and libavutil both defining AVMediaType
#define AVMediaType AVMediaType_FFmpeg
#include "src/video.h"
#undef AVMediaType

namespace fs = std::filesystem;

namespace platf {
Expand Down Expand Up @@ -147,7 +152,7 @@ static void setPixelFormat(void *display, OSType pixelFormat) {
}
};

std::shared_ptr<display_t> display(platf::mem_type_e hwdevice_type, const std::string &display_name, int framerate) {
std::shared_ptr<display_t> display(platf::mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config) {
if(hwdevice_type != platf::mem_type_e::system) {
BOOST_LOG(error) << "Could not initialize display with the given hw device type."sv;
return nullptr;
Expand All @@ -168,7 +173,7 @@ static void setPixelFormat(void *display, OSType pixelFormat) {
}
}

display->av_capture = [[AVVideo alloc] initWithDisplay:display->display_id frameRate:framerate];
display->av_capture = [[AVVideo alloc] initWithDisplay:display->display_id frameRate:config.framerate];

if(!display->av_capture) {
BOOST_LOG(error) << "Video setup failed."sv;
Expand Down
Loading