From 456d33cf77e6a32294512c96d1eafec1a4aad7d6 Mon Sep 17 00:00:00 2001 From: loki Date: Tue, 31 Mar 2020 23:46:41 +0200 Subject: [PATCH] Add abillity to supply options for specific encoders --- sunshine/video.cpp | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/sunshine/video.cpp b/sunshine/video.cpp index 080ce1d1..f7a1e92f 100644 --- a/sunshine/video.cpp +++ b/sunshine/video.cpp @@ -48,7 +48,7 @@ void nv_d3d_img_to_frame(sws_t &sws, platf::img_t &img, frame_t &frame); struct encoder_t { struct option_t { std::string name; - util::Either value; + std::variant value; }; struct { @@ -109,10 +109,17 @@ static encoder_t software { // kicked to the 2nd packet in the frame, breaking Moonlight's parsing logic. // It also looks like gop_size isn't passed on to x265, so we have to set // 'keyint=-1' in the parameters ourselves. - {{ "x265-params"s, "info=0:keyint=-1"s }}, "libx265"s + { + { "x265-params"s, "info=0:keyint=-1"s }, + { "preset"s, &config::video.preset }, + { "tune"s, &config::video.tune } + }, "libx265"s }, { - {{}}, "libx264"s + { + { "preset"s, &config::video.preset }, + { "tune"s, &config::video.tune } + }, "libx264"s }, true, @@ -286,7 +293,6 @@ util::Either hwdevice_ctx(AVHWDeviceType type) { AVBufferRef *ref; auto err = av_hwdevice_ctx_create(&ref, type, nullptr, nullptr, 0); -// auto err = av_hwdevice_ctx_create(&ref, type, "/dev/dri/renderD129", nullptr, 0); ctx.reset(ref); if(err < 0) { @@ -484,12 +490,12 @@ std::optional make_session(const encoder_t &encoder, const config_t AVDictionary *options {nullptr}; for(auto &option : video_format.options) { - if(option.value.has_left()) { - av_dict_set_int(&options, option.name.c_str(), option.value.left(), 0); - } - else { - av_dict_set(&options, option.name.c_str(), option.value.right().c_str(), 0); - } + std::visit(util::overloaded { + [&](int v) { av_dict_set_int(&options, option.name.c_str(), v, 0); }, + [&](int *v) { av_dict_set_int(&options, option.name.c_str(), *v, 0); }, + [&](const std::string &v) { av_dict_set(&options, option.name.c_str(), v.c_str(), 0); }, + [&](std::string *v) { av_dict_set(&options, option.name.c_str(), v->c_str(), 0); } + }, option.value); } if(config.bitrate > 500) {