diff --git a/config.cpp b/config.cpp index 7aacd40e..a39a9376 100644 --- a/config.cpp +++ b/config.cpp @@ -19,6 +19,10 @@ video_t video { 16, // max_b_frames 24, // gop_size 35, // crf + + "baseline"s, // profile + "superfast"s, // preset + "zerolatency"s // tune }; stream_t stream { @@ -114,6 +118,9 @@ void parse_file(const char *file) { int_f(vars, "max_b_frames", video.max_b_frames); int_f(vars, "gop_size", video.gop_size); int_f(vars, "crf", video.crf); + string_f(vars, "profile", video.profile); + string_f(vars, "preset", video.preset); + string_f(vars, "tune", video.tune); string_f(vars, "pkey", nvhttp.pkey); string_f(vars, "cert", nvhttp.cert); diff --git a/config.h b/config.h index b4a89c22..58338185 100644 --- a/config.h +++ b/config.h @@ -10,6 +10,10 @@ struct video_t { int max_b_frames; int gop_size; int crf; // higher == more compression and less quality + + std::string profile; + std::string preset; + std::string tune; }; struct stream_t { diff --git a/stream.cpp b/stream.cpp index 39724a13..a28e7767 100644 --- a/stream.cpp +++ b/stream.cpp @@ -452,7 +452,7 @@ void controlThread() { session.client_state = 0; } - server.iterate(2s); + server.iterate(500ms); } } @@ -609,7 +609,7 @@ void videoThread() { payload = {(char *) payload_new.data(), payload_new.size()}; - auto shards = fec::encode(payload, blocksize, 25); + auto shards = fec::encode(payload, blocksize, fecpercentage); for (auto x = shards.data_shards; x < shards.size(); ++x) { video_packet_raw_t *inspect = (video_packet_raw_t *)shards[x].data(); @@ -781,18 +781,18 @@ void cmd_announce(tcp::socket &&sock, msg_t &&req) { } auto &config = session.config; - config.monitor.height = util::from_view(args.at("x-nv-video[0].clientViewportHt"sv)); - config.monitor.width = util::from_view(args.at("x-nv-video[0].clientViewportWd"sv)); - config.monitor.framerate = util::from_view(args.at("x-nv-video[0].maxFPS"sv)); - config.monitor.bitrate = util::from_view(args.at("x-nv-video[0].initialBitrateKbps"sv)); - config.monitor.slicesPerFrame = util::from_view(args.at("x-nv-video[0].videoEncoderSlicesPerFrame"sv)); - config.audio.channels = util::from_view(args.at("x-nv-audio.surround.numChannels"sv)); config.audio.mask = util::from_view(args.at("x-nv-audio.surround.channelMask"sv)); config.audio.packetDuration = util::from_view(args.at("x-nv-aqos.packetDuration"sv)); config.packetsize = util::from_view(args.at("x-nv-video[0].packetSize"sv)); + config.monitor.height = util::from_view(args.at("x-nv-video[0].clientViewportHt"sv)); + config.monitor.width = util::from_view(args.at("x-nv-video[0].clientViewportWd"sv)); + config.monitor.framerate = util::from_view(args.at("x-nv-video[0].maxFPS"sv)); + config.monitor.bitrate = util::from_view(args.at("x-nv-video[0].initialBitrateKbps"sv)); + config.monitor.slicesPerFrame = util::from_view(args.at("x-nv-video[0].videoEncoderSlicesPerFrame"sv)); + std::copy(std::begin(gcm_key), std::end(gcm_key), std::begin(session.gcm_key)); std::copy(std::begin(iv), std::end(iv), std::begin(session.iv)); diff --git a/sunshine.conf.example b/sunshine.conf.example index 7b9991fe..e8c8603c 100644 --- a/sunshine.conf.example +++ b/sunshine.conf.example @@ -26,4 +26,9 @@ gop_size = 24 # Constant Rate Factor. Between 1 and 52. # Higher value means more compression, but less quality -crf = 35 +crf = 28 + +# See x264 --fullhelp for the different presets +# profile = baseline +# preset = superfast +# tune = zerolatency diff --git a/video.cpp b/video.cpp index 51706995..7ed9c86b 100644 --- a/video.cpp +++ b/video.cpp @@ -106,10 +106,11 @@ void encodeThread( ctx->thread_type = FF_THREAD_SLICE; ctx->thread_count = std::min(config.slicesPerFrame, 4); + AVDictionary *options {nullptr}; - av_dict_set(&options, "preset", "ultrafast", 0); - // av_dict_set(&options, "tune", "fastdecode", 0); - av_dict_set(&options, "profile", "baseline", 0); + av_dict_set(&options, "profile", config::video.profile.c_str(), 0); + av_dict_set(&options, "preset", config::video.preset.c_str(), 0); + av_dict_set(&options, "tune", config::video.tune.c_str(), 0); av_dict_set_int(&options, "crf", config::video.crf, 0);