clang-format

This commit is contained in:
loki 2021-05-17 21:21:57 +02:00
commit 3d8a99f541
43 changed files with 1917 additions and 1872 deletions

67
.clang-format Normal file
View file

@ -0,0 +1,67 @@
# Generated from CLion C/C++ Code Style settings
BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: AcrossComments
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterUnion: false
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 0
CompactNamespaces: false
ContinuationIndentWidth: 2
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 2
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PointerAlignment: Right
ReflowComments: false
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
TabWidth: 2
Cpp11BracedListStyle: false
UseTab: Never

View file

@ -4,10 +4,10 @@
#include "platform/common.h"
#include "utility.h"
#include "thread_safe.h"
#include "audio.h"
#include "main.h"
#include "thread_safe.h"
#include "utility.h"
namespace audio {
using namespace std::literals;
@ -60,8 +60,7 @@ void encodeThread(packet_queue_t packets, sample_queue_t samples, config_t confi
stream->coupledStreams,
stream->mapping,
OPUS_APPLICATION_AUDIO,
nullptr)
};
nullptr) };
auto frame_size = config.packetDuration * stream->sampleRate / 1000;
while(auto sample = samples->pop()) {
@ -130,4 +129,4 @@ void capture(safe::signal_t *shutdown_event, packet_queue_t packets, config_t co
samples->raise(std::move(sample_buffer));
}
}
}
} // namespace audio

View file

@ -1,8 +1,8 @@
#ifndef SUNSHINE_AUDIO_H
#define SUNSHINE_AUDIO_H
#include "utility.h"
#include "thread_safe.h"
#include "utility.h"
namespace audio {
struct config_t {
int packetDuration;
@ -13,6 +13,6 @@ struct config_t {
using packet_t = util::buffer_t<std::uint8_t>;
using packet_queue_t = std::shared_ptr<safe::queue_t<std::pair<void *, packet_t>>>;
void capture(safe::signal_t *shutdown_event, packet_queue_t packets, config_t config, void *channel_data);
}
} // namespace audio
#endif

View file

@ -1,12 +1,12 @@
#include <fstream>
#include <iostream>
#include <functional>
#include <iostream>
#include <unordered_map>
#include <boost/asio.hpp>
#include "utility.h"
#include "config.h"
#include "utility.h"
#define CA_DIR "credentials"
#define PRIVATE_KEY_FILE CA_DIR "/cakey.pem"
@ -48,7 +48,8 @@ enum coder_e : int {
};
std::optional<preset_e> preset_from_view(const std::string_view &preset) {
#define _CONVERT_(x) if(preset == #x##sv) return x
#define _CONVERT_(x) \
if(preset == #x##sv) return x
_CONVERT_(slow);
_CONVERT_(medium);
_CONVERT_(fast);
@ -65,7 +66,8 @@ std::optional<preset_e> preset_from_view(const std::string_view &preset) {
}
std::optional<rc_e> rc_from_view(const std::string_view &rc) {
#define _CONVERT_(x) if(rc == #x##sv) return x
#define _CONVERT_(x) \
if(rc == #x##sv) return x
_CONVERT_(constqp);
_CONVERT_(vbr);
_CONVERT_(cbr);
@ -83,7 +85,7 @@ int coder_from_view(const std::string_view &coder) {
return -1;
}
}
} // namespace nv
namespace amd {
enum quality_e : int {
@ -107,7 +109,8 @@ enum coder_e : int {
};
std::optional<quality_e> quality_from_view(const std::string_view &quality) {
#define _CONVERT_(x) if(quality == #x##sv) return x
#define _CONVERT_(x) \
if(quality == #x##sv) return x
_CONVERT_(speed);
_CONVERT_(balanced);
//_CONVERT_(quality2);
@ -117,7 +120,8 @@ std::optional<quality_e> quality_from_view(const std::string_view &quality) {
}
std::optional<rc_e> rc_from_view(const std::string_view &rc) {
#define _CONVERT_(x) if(rc == #x##sv) return x
#define _CONVERT_(x) \
if(rc == #x##sv) return x
_CONVERT_(constqp);
_CONVERT_(vbr_latency);
_CONVERT_(vbr_peak);
@ -133,7 +137,7 @@ int coder_from_view(const std::string_view &coder) {
return -1;
}
}
} // namespace amd
video_t video {
0, // crf
@ -150,14 +154,12 @@ video_t video {
{
nv::llhq,
std::nullopt,
-1
}, // nv
-1 }, // nv
{
amd::balanced,
std::nullopt,
-1
}, // amd
-1 }, // amd
{}, // encoder
{}, // adapter_name
@ -321,8 +323,7 @@ void int_between_f(std::unordered_map<std::string, std::string> &vars, const std
bool to_bool(std::string &boolean) {
std::for_each(std::begin(boolean), std::end(boolean), [](char ch) { return (char)std::tolower(ch); });
return
boolean == "true"sv ||
return boolean == "true"sv ||
boolean == "yes"sv ||
boolean == "enable"sv ||
(std::find(std::begin(boolean), std::end(boolean), '1') != std::end(boolean));
@ -368,14 +369,15 @@ void double_between_f(std::unordered_map<std::string, std::string> &vars, const
}
void print_help(const char *name) {
std::cout <<
"Usage: "sv << name << " [options] [/path/to/configuration_file]"sv << std::endl <<
" Any configurable option can be overwritten with: \"name=value\""sv << std::endl << std::endl <<
" --help | print help"sv << std::endl << std::endl <<
" flags"sv << std::endl <<
" -0 | Read PIN from stdin"sv << std::endl <<
" -1 | Do not load previously saved state and do retain any state after shutdown"sv << std::endl <<
" | Effectively starting as if for the first time without overwriting any pairings with your devices"sv;
std::cout << "Usage: "sv << name << " [options] [/path/to/configuration_file]"sv << std::endl
<< " Any configurable option can be overwritten with: \"name=value\""sv << std::endl
<< std::endl
<< " --help | print help"sv << std::endl
<< std::endl
<< " flags"sv << std::endl
<< " -0 | Read PIN from stdin"sv << std::endl
<< " -1 | Do not load previously saved state and do retain any state after shutdown"sv << std::endl
<< " | Effectively starting as if for the first time without overwriting any pairings with your devices"sv;
}
int apply_flags(const char *line) {
@ -410,9 +412,7 @@ void apply_config(std::unordered_map<std::string, std::string> &&vars) {
int_f(vars, "crf", video.crf);
int_f(vars, "qp", video.qp);
int_f(vars, "min_threads", video.min_threads);
int_between_f(vars, "hevc_mode", video.hevc_mode, {
0, 3
});
int_between_f(vars, "hevc_mode", video.hevc_mode, { 0, 3 });
string_f(vars, "sw_preset", video.sw.preset);
string_f(vars, "sw_tune", video.sw.tune);
int_f(vars, "nv_preset", video.nv.preset, nv::preset_from_view);
@ -435,26 +435,18 @@ void apply_config(std::unordered_map<std::string, std::string> &&vars) {
string_f(vars, "audio_sink", audio.sink);
string_restricted_f(vars, "origin_pin_allowed", nvhttp.origin_pin_allowed, {
"pc"sv, "lan"sv, "wan"sv
});
string_restricted_f(vars, "origin_pin_allowed", nvhttp.origin_pin_allowed, { "pc"sv, "lan"sv, "wan"sv });
int to = -1;
int_between_f(vars, "ping_timeout", to, {
-1, std::numeric_limits<int>::max()
});
int_between_f(vars, "ping_timeout", to, { -1, std::numeric_limits<int>::max() });
if(to != -1) {
stream.ping_timeout = std::chrono::milliseconds(to);
}
int_between_f(vars, "channels", stream.channels, {
1, std::numeric_limits<int>::max()
});
int_between_f(vars, "channels", stream.channels, { 1, std::numeric_limits<int>::max() });
string_f(vars, "file_apps", stream.file_apps);
int_between_f(vars, "fec_percentage", stream.fec_percentage, {
1, 100
});
int_between_f(vars, "fec_percentage", stream.fec_percentage, { 1, 100 });
to = std::numeric_limits<int>::min();
int_f(vars, "back_button_timeout", to);
@ -464,9 +456,7 @@ void apply_config(std::unordered_map<std::string, std::string> &&vars) {
}
double repeat_frequency { 0 };
double_between_f(vars, "key_repeat_frequency", repeat_frequency, {
0, std::numeric_limits<double>::max()
});
double_between_f(vars, "key_repeat_frequency", repeat_frequency, { 0, std::numeric_limits<double>::max() });
if(repeat_frequency > 0) {
config::input.key_repeat_period = std::chrono::duration<double> { 1 / repeat_frequency };
@ -479,9 +469,7 @@ void apply_config(std::unordered_map<std::string, std::string> &&vars) {
}
std::string log_level_string;
string_restricted_f(vars, "min_log_level", log_level_string, {
"verbose"sv, "debug"sv, "info"sv, "warning"sv, "error"sv, "fatal"sv, "none"sv
});
string_restricted_f(vars, "min_log_level", log_level_string, { "verbose"sv, "debug"sv, "info"sv, "warning"sv, "error"sv, "fatal"sv, "none"sv });
if(!log_level_string.empty()) {
if(log_level_string == "verbose"sv) {
@ -569,8 +557,7 @@ int parse(int argc, char *argv[]) {
auto vars = parse_config(std::string {
// Quick and dirty
std::istreambuf_iterator<char>(in),
std::istreambuf_iterator<char>()
});
std::istreambuf_iterator<char>() });
for(auto &[name, value] : cmd_vars) {
vars.insert_or_assign(std::move(name), std::move(value));
@ -580,4 +567,4 @@ int parse(int argc, char *argv[]) {
return 0;
}
}
} // namespace config

View file

@ -1,10 +1,10 @@
#ifndef SUNSHINE_CONFIG_H
#define SUNSHINE_CONFIG_H
#include <chrono>
#include <string>
#include <bitset>
#include <chrono>
#include <optional>
#include <string>
namespace config {
struct video_t {
@ -96,6 +96,6 @@ extern input_t input;
extern sunshine_t sunshine;
int parse(int argc, char *argv[]);
}
} // namespace config
#endif

View file

@ -2,8 +2,8 @@
// Created by loki on 5/31/19.
//
#include <openssl/pem.h>
#include "crypto.h"
#include <openssl/pem.h>
namespace crypto {
using big_num_t = util::safe_ptr<BIGNUM, BN_free>;
//using rsa_t = util::safe_ptr<RSA, RSA_free>;
@ -338,4 +338,4 @@ bool verify256(const x509_t &x509, const std::string_view &data, const std::stri
void md_ctx_destroy(EVP_MD_CTX *ctx) {
EVP_MD_CTX_destroy(ctx);
}
}
} // namespace crypto

View file

@ -5,12 +5,12 @@
#ifndef SUNSHINE_CRYPTO_H
#define SUNSHINE_CRYPTO_H
#include <cassert>
#include <array>
#include <cassert>
#include <openssl/evp.h>
#include <openssl/rand.h>
#include <openssl/sha.h>
#include <openssl/x509.h>
#include <openssl/rand.h>
#include "utility.h"
@ -58,6 +58,7 @@ public:
void add(x509_t &&cert);
const char *verify(x509_t::element_type *cert);
private:
std::vector<std::pair<x509_t, x509_store_t>> _certs;
x509_store_ctx_t _cert_ctx;
@ -73,6 +74,7 @@ public:
int decrypt_gcm(aes_t &iv, const std::string_view &cipher, std::vector<std::uint8_t> &plaintext);
int decrypt(const std::string_view &cipher, std::vector<std::uint8_t> &plaintext);
private:
cipher_ctx_t ctx;
aes_t key;
@ -80,6 +82,6 @@ private:
public:
bool padding;
};
}
} // namespace crypto
#endif //SUNSHINE_CRYPTO_H

View file

@ -10,12 +10,12 @@ extern "C" {
#include <bitset>
#include "main.h"
#include "config.h"
#include "utility.h"
#include "thread_pool.h"
#include "input.h"
#include "main.h"
#include "platform/common.h"
#include "thread_pool.h"
#include "utility.h"
namespace input {
@ -170,8 +170,7 @@ void print(void *input) {
case PACKET_TYPE_MOUSE_BUTTON:
print((PNV_MOUSE_BUTTON_PACKET)input);
break;
case PACKET_TYPE_SCROLL_OR_KEYBOARD:
{
case PACKET_TYPE_SCROLL_OR_KEYBOARD: {
char *tmp_input = (char *)input + 4;
if(tmp_input[0] == 0x0A) {
print((PNV_SCROLL_PACKET)input);
@ -261,7 +260,7 @@ void passthrough(std::shared_ptr<input_t> &input, PNV_MOUSE_BUTTON_PACKET packet
* when the last mouse coordinates were absolute
/*/
if(button == BUTTON_LEFT && release && !input->mouse_left_button_timeout) {
input->mouse_left_button_timeout = task_pool.pushDelayed([=]() {
auto f = [=]() {
auto left_released = mouse_press[BUTTON_LEFT];
if(left_released) {
// Already released left button
@ -271,14 +270,15 @@ void passthrough(std::shared_ptr<input_t> &input, PNV_MOUSE_BUTTON_PACKET packet
mouse_press[BUTTON_LEFT] = false;
input->mouse_left_button_timeout = nullptr;
}, 10ms).task_id;
};
input->mouse_left_button_timeout = task_pool.pushDelayed(std::move(f), 10ms).task_id;
return;
}
if(
button == BUTTON_RIGHT && !release &&
input->mouse_left_button_timeout > DISABLE_LEFT_BUTTON_DELAY
) {
input->mouse_left_button_timeout > DISABLE_LEFT_BUTTON_DELAY) {
platf::button_mouse(platf_input, BUTTON_RIGHT, false);
platf::button_mouse(platf_input, BUTTON_RIGHT, true);
@ -445,7 +445,7 @@ void passthrough(std::shared_ptr<input_t> &input, PNV_MULTI_CONTROLLER_PACKET pa
if(platf::BACK & bf_new) {
// Don't emulate home button if timeout < 0
if(config::input.back_button_timeout >= 0ms) {
gamepad.back_timeout_id = task_pool.pushDelayed([input, controller=packet->controllerNumber]() {
auto f = [input, controller = packet->controllerNumber]() {
auto &gamepad = input->gamepads[controller];
auto &state = gamepad.gamepad_state;
@ -464,7 +464,9 @@ void passthrough(std::shared_ptr<input_t> &input, PNV_MULTI_CONTROLLER_PACKET pa
platf::gamepad(platf_input, gamepad.id, state);
gamepad.back_timeout_id = nullptr;
}, config::input.back_button_timeout).task_id;
};
gamepad.back_timeout_id = task_pool.pushDelayed(std::move(f), config::input.back_button_timeout).task_id;
}
}
else if(gamepad.back_timeout_id) {
@ -493,8 +495,7 @@ void passthrough_helper(std::shared_ptr<input_t> input, std::vector<std::uint8_t
case PACKET_TYPE_MOUSE_BUTTON:
passthrough(input, (PNV_MOUSE_BUTTON_PACKET)payload);
break;
case PACKET_TYPE_SCROLL_OR_KEYBOARD:
{
case PACKET_TYPE_SCROLL_OR_KEYBOARD: {
char *tmp_input = (char *)payload + 4;
if(tmp_input[0] == 0x0A) {
passthrough((PNV_SCROLL_PACKET)payload);
@ -547,8 +548,9 @@ std::shared_ptr<input_t> alloc() {
task_pool.pushDelayed([]() {
platf::move_mouse(platf_input, 1, 1);
platf::move_mouse(platf_input, -1, -1);
}, 100ms);
},
100ms);
return input;
}
}
} // namespace input

View file

@ -5,8 +5,8 @@
#ifndef SUNSHINE_INPUT_H
#define SUNSHINE_INPUT_H
#include "thread_safe.h"
#include "platform/common.h"
#include "thread_safe.h"
namespace input {
struct input_t;
@ -22,6 +22,6 @@ std::shared_ptr<input_t> alloc();
using touch_port_event_t = std::unique_ptr<safe::event_t<platf::touch_port_t>>;
extern touch_port_event_t touch_port_event;
}
} // namespace input
#endif //SUNSHINE_INPUT_H

View file

@ -4,26 +4,26 @@
#include "process.h"
#include <thread>
#include <iostream>
#include <csignal>
#include <iostream>
#include <thread>
#include <boost/log/common.hpp>
#include <boost/log/sinks.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/attributes/clock.hpp>
#include <boost/log/common.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include "video.h"
#include "config.h"
#include "nvhttp.h"
#include "rtsp.h"
#include "config.h"
#include "thread_pool.h"
#include "video.h"
#include "platform/common.h"
extern "C" {
#include <rs.h>
#include <libavutil/log.h>
#include <rs.h>
}
using namespace std::literals;

View file

@ -5,8 +5,8 @@
#ifndef SUNSHINE_MAIN_H
#define SUNSHINE_MAIN_H
#include <boost/log/common.hpp>
#include "thread_pool.h"
#include <boost/log/common.hpp>
extern util::ThreadPool task_pool;
extern bool display_cursor;

View file

@ -11,10 +11,11 @@ template<class T>
class MoveByCopy {
public:
typedef T move_type;
private:
move_type _to_move;
public:
public:
explicit MoveByCopy(move_type &&to_move) : _to_move(std::move(to_move)) {}
MoveByCopy(MoveByCopy &&other) = default;
@ -46,5 +47,5 @@ template<class T>
MoveByCopy<T> const_cmove(const T &movable) {
return MoveByCopy<T>(std::move(const_cast<T &>(movable)));
}
}
} // namespace util
#endif

View file

@ -2,9 +2,9 @@
// Created by loki on 12/27/19.
//
#include <algorithm>
#include "network.h"
#include "utility.h"
#include <algorithm>
namespace net {
using namespace std::literals;
@ -112,4 +112,4 @@ void free_host(ENetHost *host) {
enet_host_destroy(host);
}
}
} // namespace net

View file

@ -30,6 +30,6 @@ std::string_view to_enum_string(net_e net);
net_e from_address(const std::string_view &view);
host_t host_create(ENetAddress &addr, std::size_t peers, std::uint16_t port);
}
} // namespace net
#endif //SUNSHINE_NETWORK_H

View file

@ -6,9 +6,9 @@
#include <filesystem>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/asio/ssl/context.hpp>
@ -17,14 +17,14 @@
#include <boost/asio/ssl/context_base.hpp>
#include "config.h"
#include "utility.h"
#include "rtsp.h"
#include "crypto.h"
#include "main.h"
#include "network.h"
#include "nvhttp.h"
#include "platform/common.h"
#include "network.h"
#include "rtsp.h"
#include "utility.h"
#include "uuid.h"
#include "main.h"
namespace nvhttp {
@ -69,8 +69,8 @@ struct pair_session_t {
struct {
util::Either<
std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTP>::Response>,
std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTPS>::Response>
> response;
std::shared_ptr<typename SimpleWeb::ServerBase<SimpleWeb::HTTPS>::Response>>
response;
std::string salt;
} async_insert_pin;
};
@ -127,7 +127,8 @@ void load_state() {
pt::ptree root;
try {
pt::read_json(config::nvhttp.file_state, root);
} catch (std::exception &e) {
}
catch(std::exception &e) {
BOOST_LOG(warning) << e.what();
return;
@ -150,13 +151,11 @@ void load_state() {
void update_id_client(const std::string &uniqueID, std::string &&cert, op_e op) {
switch(op) {
case op_e::ADD:
{
case op_e::ADD: {
auto &client = map_id_client[uniqueID];
client.certs.emplace_back(std::move(cert));
client.uniqueID = uniqueID;
}
break;
} break;
case op_e::REMOVE:
map_id_client.erase(uniqueID);
break;
@ -334,7 +333,8 @@ void not_found(std::shared_ptr<typename SimpleWeb::ServerBase<T>::Response> resp
pt::write_xml(data, tree);
response->write(data.str());
*response << "HTTP/1.1 404 NOT FOUND\r\n" << data.str();
*response << "HTTP/1.1 404 NOT FOUND\r\n"
<< data.str();
}
template<class T>
@ -839,7 +839,8 @@ void start(std::shared_ptr<safe::signal_t> shutdown_event) {
try {
https_server.bind();
http_server.bind();
} catch(boost::system::system_error &err) {
}
catch(boost::system::system_error &err) {
BOOST_LOG(fatal) << "Couldn't bind http server to ports ["sv << PORT_HTTPS << ", "sv << PORT_HTTP << "]: "sv << err.what();
shutdown_event->raise(true);
@ -849,7 +850,8 @@ void start(std::shared_ptr<safe::signal_t> shutdown_event) {
auto accept_and_run = [&](auto *http_server) {
try {
http_server->accept_and_run();
} catch(boost::system::system_error &err) {
}
catch(boost::system::system_error &err) {
// It's possible the exception gets thrown after calling http_server->stop() from a different thread
if(shutdown_event->peek()) {
return;
@ -899,4 +901,4 @@ std::string read_file(const char *path) {
return base64_cert;
}
}
} // namespace nvhttp

View file

@ -5,9 +5,9 @@
#ifndef SUNSHINE_COMMON_H
#define SUNSHINE_COMMON_H
#include <string>
#include <mutex>
#include "sunshine/utility.h"
#include <mutex>
#include <string>
struct sockaddr;
namespace platf {
@ -45,7 +45,9 @@ enum class pix_fmt_e {
inline std::string_view from_pix_fmt(pix_fmt_e pix_fmt) {
using namespace std::literals;
#define _CONVERT(x) case pix_fmt_e:: x : return #x ## sv
#define _CONVERT(x) \
case pix_fmt_e::x: \
return #x##sv
switch(pix_fmt) {
_CONVERT(yuv420p);
_CONVERT(yuv420p10);
@ -65,8 +67,7 @@ struct touch_port_t {
constexpr touch_port_t(
std::uint32_t offset_x, std::uint32_t offset_y,
std::uint32_t width, std::uint32_t height) noexcept :
offset_x { offset_x }, offset_y { offset_y },
std::uint32_t width, std::uint32_t height) noexcept : offset_x { offset_x }, offset_y { offset_y },
width { width }, height { height } {};
};
@ -172,6 +173,6 @@ int alloc_gamepad(input_t &input, int nr);
void free_gamepad(input_t &input, int nr);
[[nodiscard]] std::unique_ptr<deinit_t> init();
}
} // namespace platf
#endif //SUNSHINE_COMMON_H

View file

@ -4,8 +4,8 @@
#include "sunshine/platform/common.h"
#include <fstream>
#include <bitset>
#include <fstream>
#include <arpa/inet.h>
#include <ifaddrs.h>
@ -15,20 +15,19 @@
#include <X11/Xutil.h>
#include <X11/extensions/Xfixes.h>
#include <X11/extensions/Xrandr.h>
#include <xcb/shm.h>
#include <xcb/xfixes.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <xcb/shm.h>
#include <xcb/xfixes.h>
#include <pulse/simple.h>
#include <pulse/error.h>
#include <pulse/simple.h>
#include "sunshine/task_pool.h"
#include "sunshine/config.h"
#include "sunshine/main.h"
#include "sunshine/task_pool.h"
namespace platf
{
namespace platf {
using namespace std::literals;
void freeImage(XImage *);
@ -141,8 +140,7 @@ void blend_cursor(Display *display, img_t &img, int offsetX, int offsetY) {
});
}
}
struct x11_attr_t: public display_t
{
struct x11_attr_t : public display_t {
xdisplay_t xdisplay;
Window xwindow;
XWindowAttributes xattr;
@ -273,7 +271,8 @@ struct shm_attr_t: public x11_attr_t {
}
~shm_attr_t() override {
while(!task_pool.cancel(refresh_task_id));
while(!task_pool.cancel(refresh_task_id))
;
}
capture_e snapshot(img_t *img, std::chrono::milliseconds timeout, bool cursor) override {
@ -504,4 +503,4 @@ void freeImage(XImage *p) {
void freeX(XFixesCursorImage *p) {
XFree(p);
}
}
} // namespace platf

View file

@ -1,5 +1,5 @@
#include <libevdev/libevdev.h>
#include <libevdev/libevdev-uinput.h>
#include <libevdev/libevdev.h>
#include <X11/X.h>
#include <X11/Xlib.h>
@ -10,8 +10,8 @@
#include <cstring>
#include <filesystem>
#include "sunshine/platform/common.h"
#include "sunshine/main.h"
#include "sunshine/platform/common.h"
#include "sunshine/utility.h"
// Support older versions
@ -586,4 +586,4 @@ void freeInput(void *p) {
}
std::unique_ptr<deinit_t> init() { return std::make_unique<deinit_t>(); }
}
} // namespace platf

View file

@ -2,9 +2,9 @@
// Created by loki on 1/12/20.
//
#include <roapi.h>
#include <mmdeviceapi.h>
#include <audioclient.h>
#include <mmdeviceapi.h>
#include <roapi.h>
#include <codecvt>
@ -54,26 +54,20 @@ struct format_t {
int channels;
int channel_mask;
} formats[] {
{
"Stereo"sv,
{ "Stereo"sv,
2,
SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT
},
{
"Mono"sv,
SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT },
{ "Mono"sv,
1,
SPEAKER_FRONT_CENTER
},
{
"Surround 5.1"sv,
SPEAKER_FRONT_CENTER },
{ "Surround 5.1"sv,
6,
SPEAKER_FRONT_LEFT |
SPEAKER_FRONT_RIGHT |
SPEAKER_FRONT_CENTER |
SPEAKER_LOW_FREQUENCY |
SPEAKER_BACK_LEFT |
SPEAKER_BACK_RIGHT
}
SPEAKER_BACK_RIGHT }
};
void set_wave_format(audio::wave_format_t &wave_format, const format_t &format) {
@ -113,7 +107,8 @@ void surround51_to_stereo(std::vector<std::int16_t> &sample_in, const util::buff
right += sample_out_p[front_center] * 90 / 100;
right += sample_out_p[low_frequency] * 30 / 100;
right += sample_out_p[back_left] * 30 / 100;
right += sample_out_p[back_right] * 70 / 100;;
right += sample_out_p[back_right] * 70 / 100;
;
*sample_in_pos++ = (std::uint16_t)left;
*sample_in_pos++ = (std::uint16_t)right;
@ -331,6 +326,7 @@ public:
audio_client->Stop();
}
}
private:
capture_e _fill_buffer() {
HRESULT status;
@ -361,8 +357,7 @@ private:
for(
status = audio_capture->GetNextPacketSize(&packet_size);
SUCCEEDED(status) && packet_size > 0;
status = audio_capture->GetNextPacketSize(&packet_size)
) {
status = audio_capture->GetNextPacketSize(&packet_size)) {
DWORD buffer_flags;
status = audio_capture->GetBuffer(
(BYTE **)&sample_aligned.samples,
@ -385,7 +380,8 @@ private:
if(buffer_flags & AUDCLNT_BUFFERFLAGS_SILENT) {
std::fill_n(sample_buf_pos, n, 0);
} else {
}
else {
std::copy_n(sample_aligned.samples, n, sample_buf_pos);
}
@ -404,6 +400,7 @@ private:
return capture_e::ok;
}
public:
handle_t audio_event;
@ -419,7 +416,7 @@ public:
format_t *format;
};
}
} // namespace platf::audio
namespace platf {
@ -444,4 +441,4 @@ std::unique_ptr<deinit_t> init() {
}
return std::make_unique<platf::audio::co_init_t>();
}
}
} // namespace platf

View file

@ -5,14 +5,14 @@
#ifndef SUNSHINE_DISPLAY_H
#define SUNSHINE_DISPLAY_H
#include <dxgi.h>
#include <d3d11.h>
#include <d3d11_4.h>
#include <d3dcommon.h>
#include <dxgi.h>
#include <dxgi1_2.h>
#include "sunshine/utility.h"
#include "sunshine/platform/common.h"
#include "sunshine/utility.h"
namespace platf::dxgi {
extern const char *format_str[];
@ -43,7 +43,7 @@ using processor_t = util::safe_ptr<ID3D11VideoProcessor, Release<ID3D11Vide
using processor_out_t = util::safe_ptr<ID3D11VideoProcessorOutputView, Release<ID3D11VideoProcessorOutputView>>;
using processor_in_t = util::safe_ptr<ID3D11VideoProcessorInputView, Release<ID3D11VideoProcessorInputView>>;
using processor_enum_t = util::safe_ptr<ID3D11VideoProcessorEnumerator, Release<ID3D11VideoProcessorEnumerator>>;
}
} // namespace video
class hwdevice_t;
struct cursor_t {
@ -86,16 +86,14 @@ public:
DXGI_FORMAT format;
D3D_FEATURE_LEVEL feature_level;
typedef enum _D3DKMT_SCHEDULINGPRIORITYCLASS
{
typedef enum _D3DKMT_SCHEDULINGPRIORITYCLASS {
D3DKMT_SCHEDULINGPRIORITYCLASS_IDLE,
D3DKMT_SCHEDULINGPRIORITYCLASS_BELOW_NORMAL,
D3DKMT_SCHEDULINGPRIORITYCLASS_NORMAL,
D3DKMT_SCHEDULINGPRIORITYCLASS_ABOVE_NORMAL,
D3DKMT_SCHEDULINGPRIORITYCLASS_HIGH,
D3DKMT_SCHEDULINGPRIORITYCLASS_REALTIME
}
D3DKMT_SCHEDULINGPRIORITYCLASS;
} D3DKMT_SCHEDULINGPRIORITYCLASS;
typedef NTSTATUS WINAPI (*PD3DKMTSetProcessSchedulingPriorityClass)(HANDLE, D3DKMT_SCHEDULINGPRIORITYCLASS);
};
@ -125,6 +123,6 @@ public:
gpu_cursor_t cursor;
std::vector<hwdevice_t *> hwdevices;
};
}
} // namespace platf::dxgi
#endif

View file

@ -414,7 +414,7 @@ const char *format_str[] = {
"DXGI_FORMAT_V408"
};
}
} // namespace platf::dxgi
namespace platf {
std::shared_ptr<display_t> display(dev_type_e hwdevice_type) {
@ -435,4 +435,4 @@ std::shared_ptr<display_t> display(dev_type_e hwdevice_type) {
return nullptr;
}
}
} // namespace platf

View file

@ -1,5 +1,5 @@
#include "sunshine/main.h"
#include "display.h"
#include "sunshine/main.h"
namespace platf {
using namespace std::literals;
@ -294,4 +294,4 @@ int display_ram_t::init() {
return 0;
}
}
} // namespace platf::dxgi

View file

@ -3,8 +3,8 @@
#include <d3dcompiler.h>
#include <directxmath.h>
#include "sunshine/main.h"
#include "display.h"
#include "sunshine/main.h"
#define SUNSHINE_SHADERS_DIR SUNSHINE_ASSETS_DIR "/shaders"
namespace platf {
@ -378,8 +378,7 @@ public:
int init(
std::shared_ptr<platf::display_t> display, device_t::pointer device_p, device_ctx_t::pointer device_ctx_p,
int in_width, int in_height, int out_width, int out_height,
pix_fmt_e pix_fmt
) {
pix_fmt_e pix_fmt) {
HRESULT status;
device_p->AddRef();
@ -535,6 +534,7 @@ public:
hwdevices_p->erase(it);
}
}
private:
void _init_view_port(float x, float y, float width, float height) {
D3D11_VIEWPORT view {
@ -864,4 +864,4 @@ int init() {
return 0;
}
}
} // namespace platf::dxgi

View file

@ -1,12 +1,12 @@
#include <sstream>
#include <iomanip>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <ws2tcpip.h>
#include <winsock2.h>
#include <windows.h>
#include <winuser.h>
#include <iphlpapi.h>
#include <windows.h>
#include <winsock2.h>
#include <winuser.h>
#include <ws2tcpip.h>
#include <ViGEm/Client.h>
@ -365,7 +365,8 @@ HDESK pairInputDesktop() {
BOOST_LOG(error) << "Failed to OpenInputDesktop [0x"sv << util::hex(err).to_string_view() << ']';
}
else {
BOOST_LOG(info) << std::endl << "Opened desktop [0x"sv << util::hex(hDesk).to_string_view() << ']';
BOOST_LOG(info) << std::endl
<< "Opened desktop [0x"sv << util::hex(hDesk).to_string_view() << ']';
if(!SetThreadDesktop(hDesk)) {
auto err = GetLastError();
BOOST_LOG(error) << "Failed to SetThreadDesktop [0x"sv << util::hex(err).to_string_view() << ']';
@ -381,4 +382,4 @@ void freeInput(void *p) {
delete vigem;
}
}
} // namespace platf

View file

@ -4,14 +4,14 @@
#include "process.h"
#include <vector>
#include <string>
#include <vector>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include "utility.h"
#include "main.h"
#include "utility.h"
namespace proc {
using namespace std::literals;
@ -192,9 +192,11 @@ std::string_view::iterator find_match(std::string_view::iterator begin, std::str
do {
++begin;
switch(*begin) {
case '(': ++stack;
case '(':
++stack;
break;
case ')': --stack;
case ')':
--stack;
}
} while(begin != end && stack != 0);
@ -316,7 +318,8 @@ std::optional<proc::proc_t> parse(const std::string& file_name) {
return proc::proc_t {
std::move(this_env), std::move(apps)
};
} catch (std::exception &e) {
}
catch(std::exception &e) {
BOOST_LOG(error) << e.what();
}
@ -330,4 +333,4 @@ void refresh(const std::string &file_name) {
proc = std::move(*proc_opt);
}
}
}
} // namespace proc

View file

@ -9,8 +9,8 @@
#define __kernel_entry
#endif
#include <unordered_map>
#include <optional>
#include <unordered_map>
#include <boost/process.hpp>
@ -61,8 +61,7 @@ public:
proc_t(
boost::process::environment &&env,
std::vector<ctx_t> &&apps) :
_app_id(-1),
std::vector<ctx_t> &&apps) : _app_id(-1),
_env(std::move(env)),
_apps(std::move(apps)) {}
@ -101,5 +100,5 @@ void refresh(const std::string &file_name);
std::optional<proc::proc_t> parse(const std::string &file_name);
extern proc_t proc;
}
} // namespace proc
#endif //SUNSHINE_PROCESS_H

View file

@ -53,8 +53,14 @@ public:
return step;
}
iterator operator++() { _this().inc(); return _this(); }
iterator operator--() { _this().dec(); return _this(); }
iterator operator++() {
_this().inc();
return _this();
}
iterator operator--() {
_this().dec();
return _this();
}
iterator operator++(int) {
iterator new_ = _this();
@ -96,8 +102,8 @@ public:
bool operator==(const iterator &other) const { return _this().eq(other); };
bool operator>(const iterator &other) const { return _this().gt(other); }
private:
private:
iterator &_this() { return *static_cast<iterator *>(this); }
const iterator &_this() const { return *static_cast<const iterator *>(this); }
};
@ -133,6 +139,7 @@ public:
pointer get() const {
return &*_pos;
}
private:
It _begin;
It _end;
@ -144,6 +151,6 @@ template<class V, class It>
round_robin_t<V, It> make_round_robin(It begin, It end) {
return round_robin_t<V, It>(begin, end);
}
}
} // namespace util
#endif

View file

@ -7,10 +7,10 @@ extern "C" {
}
#include "config.h"
#include "input.h"
#include "main.h"
#include "network.h"
#include "rtsp.h"
#include "input.h"
#include "stream.h"
#include "sync.h"
@ -194,7 +194,6 @@ public:
safe::event_t<launch_session_t> launch_event;
private:
// named _queue_packet because I want to make it an actual queue
// It's like this for convenience sake
std::pair<net::peer_t, net::packet_t> _queue_packet;
@ -418,8 +417,8 @@ void cmd_announce(rtsp_server_t *server, net::peer_t peer, msg_t &&req) {
config.monitor.encoderCscMode = util::from_view(args.at("x-nv-video[0].encoderCscMode"sv));
config.monitor.videoFormat = util::from_view(args.at("x-nv-vqos[0].bitStreamFormat"sv));
config.monitor.dynamicRange = util::from_view(args.at("x-nv-video[0].dynamicRangeMode"sv));
} catch(std::out_of_range &) {
}
catch(std::out_of_range &) {
respond(server->host(), peer, &option, 400, "BAD REQUEST", req->sequenceNumber, {});
return;
@ -534,6 +533,8 @@ void print_msg(PRTSP_MESSAGE msg) {
BOOST_LOG(debug) << name << " :: "sv << content;
}
BOOST_LOG(debug) << "---Begin MessageBuffer---"sv << std::endl << messageBuffer << std::endl << "---End MessageBuffer---"sv << std::endl;
}
BOOST_LOG(debug) << "---Begin MessageBuffer---"sv << std::endl
<< messageBuffer << std::endl
<< "---End MessageBuffer---"sv << std::endl;
}
} // namespace stream

View file

@ -21,6 +21,6 @@ int session_count();
void rtpThread(std::shared_ptr<safe::signal_t> shutdown_event);
}
} // namespace stream
#endif //SUNSHINE_RTSP_H

View file

@ -4,8 +4,8 @@
#include "process.h"
#include <queue>
#include <future>
#include <queue>
#include <fstream>
#include <openssl/err.h>
@ -15,14 +15,14 @@ extern "C" {
#include <rs.h>
}
#include "network.h"
#include "config.h"
#include "utility.h"
#include "stream.h"
#include "thread_safe.h"
#include "sync.h"
#include "input.h"
#include "main.h"
#include "network.h"
#include "stream.h"
#include "sync.h"
#include "thread_safe.h"
#include "utility.h"
#define IDX_START_A 0
#define IDX_REQUEST_IDR_FRAME 0
@ -255,8 +255,7 @@ void control_server_t::iterate(std::chrono::milliseconds timeout) {
session->pingTimeout = std::chrono::steady_clock::now() + config::stream.ping_timeout;
switch(event.type) {
case ENET_EVENT_TYPE_RECEIVE:
{
case ENET_EVENT_TYPE_RECEIVE: {
net::packet_t packet { event.packet };
auto type = (std::uint16_t *)packet->data;
@ -266,14 +265,15 @@ void control_server_t::iterate(std::chrono::milliseconds timeout) {
if(cb == std::end(_map_type_cb)) {
BOOST_LOG(warning)
<< "type [Unknown] { "sv << util::hex(*type).to_string_view() << " }"sv << std::endl
<< "---data---"sv << std::endl << util::hex_vec(payload) << std::endl << "---end data---"sv;
<< "---data---"sv << std::endl
<< util::hex_vec(payload) << std::endl
<< "---end data---"sv;
}
else {
cb->second(session, payload);
}
}
break;
} break;
case ENET_EVENT_TYPE_CONNECT:
BOOST_LOG(info) << "CLIENT CONNECTED"sv;
break;
@ -355,7 +355,7 @@ fec_t encode(const std::string_view &payload, size_t blocksize, size_t fecpercen
std::move(shards)
};
}
}
} // namespace fec
template<class F>
std::vector<uint8_t> insert(uint64_t insert_size, uint64_t slice_size, const std::string_view &data, F &&f) {
@ -640,11 +640,9 @@ void videoBroadcastThread(safe::signal_t *shutdown_event, udp::socket &sock, vid
video_packet->packet.flags = FLAG_CONTAINS_PIC_DATA;
video_packet->packet.frameIndex = packet->pts;
video_packet->packet.streamPacketIndex = ((uint32_t)lowseq + fecIndex) << 8;
video_packet->packet.fecInfo = (
fecIndex << 12 |
video_packet->packet.fecInfo = (fecIndex << 12 |
end << 22 |
fecPercentage << 4
);
fecPercentage << 4);
if(fecIndex == 0) {
video_packet->packet.flags |= FLAG_SOF;
@ -670,11 +668,9 @@ void videoBroadcastThread(safe::signal_t *shutdown_event, udp::socket &sock, vid
auto *inspect = (video_packet_raw_t *)shards.data(x);
inspect->packet.frameIndex = packet->pts;
inspect->packet.fecInfo = (
x << 12 |
inspect->packet.fecInfo = (x << 12 |
shards.data_shards << 22 |
fecPercentage << 4
);
fecPercentage << 4);
inspect->rtp.header = FLAG_EXTENSION;
inspect->rtp.sequenceNumber = util::endian::big<uint16_t>(lowseq + x);
@ -943,5 +939,5 @@ std::shared_ptr<session_t> alloc(config_t &config, crypto::aes_t &gcm_key, crypt
return session;
}
}
}
} // namespace session
} // namespace stream

View file

@ -7,9 +7,9 @@
#include <boost/asio.hpp>
#include "video.h"
#include "audio.h"
#include "crypto.h"
#include "video.h"
namespace stream {
struct session_t;
@ -35,9 +35,9 @@ int start(session_t &session, const std::string &addr_string);
void stop(session_t &session);
void join(session_t &session);
state_e state(session_t &session);
}
} // namespace session
extern safe::signal_t broadcast_shutdown_event;
}
} // namespace stream
#endif //SUNSHINE_STREAM_H

View file

@ -5,9 +5,9 @@
#ifndef SUNSHINE_SYNC_H
#define SUNSHINE_SYNC_H
#include <utility>
#include <mutex>
#include <array>
#include <mutex>
#include <utility>
namespace util {
@ -84,11 +84,12 @@ public:
}
value_t raw;
private:
mutex_t _lock;
};
}
} // namespace util
#endif //T_MAN_SYNC_H

View file

@ -1,18 +1,18 @@
#ifndef KITTY_TASK_POOL_H
#define KITTY_TASK_POOL_H
#include <deque>
#include <vector>
#include <future>
#include <chrono>
#include <utility>
#include <deque>
#include <functional>
#include <future>
#include <mutex>
#include <type_traits>
#include <optional>
#include <type_traits>
#include <utility>
#include <vector>
#include "utility.h"
#include "move_by_copy.h"
#include "utility.h"
namespace util {
class _ImplBase {
@ -29,7 +29,6 @@ class _Impl : public _ImplBase {
Function _func;
public:
_Impl(Function &&f) : _func(std::forward<Function>(f)) {}
void run() override {
@ -53,6 +52,7 @@ public:
timer_task_t(task_id_t task_id, std::future<R> &future) : task_id { task_id }, future { std::move(future) } {}
};
protected:
std::deque<__task> _tasks;
std::vector<std::pair<__time_point, __task>> _timer_tasks;
@ -166,7 +166,8 @@ public:
std::swap(*it, *prev);
}
--prev; --it;
--prev;
--it;
}
}
@ -233,12 +234,12 @@ public:
return std::get<0>(_timer_tasks.back());
}
private:
private:
template<class Function>
std::unique_ptr<_ImplBase> toRunnable(Function &&f) {
return std::make_unique<_Impl<Function>>(std::forward<Function &&>(f));
}
};
}
} // namespace util
#endif

View file

@ -1,8 +1,8 @@
#ifndef KITTY_THREAD_POOL_H
#define KITTY_THREAD_POOL_H
#include <thread>
#include "task_pool.h"
#include <thread>
namespace util {
/*
@ -20,6 +20,7 @@ private:
std::mutex _lock;
bool _continue;
public:
ThreadPool() : _continue { false } {}
@ -85,7 +86,6 @@ public:
}
public:
void _main() {
while(_continue) {
if(auto task = this->pop()) {
@ -117,5 +117,5 @@ public:
}
}
};
}
} // namespace util
#endif

View file

@ -5,11 +5,11 @@
#ifndef SUNSHINE_THREAD_SAFE_H
#define SUNSHINE_THREAD_SAFE_H
#include <vector>
#include <mutex>
#include <condition_variable>
#include <atomic>
#include <condition_variable>
#include <functional>
#include <mutex>
#include <vector>
#include "utility.h"
@ -121,8 +121,8 @@ public:
[[nodiscard]] bool running() const {
return _continue;
}
private:
private:
bool _continue { true };
status_t _status { util::false_v<status_t> };
@ -219,7 +219,6 @@ public:
}
private:
bool _continue { true };
std::uint32_t _max_elements;
@ -322,6 +321,7 @@ public:
return ptr_t { this };
}
private:
construct_f _construct;
destruct_f _destruct;
@ -340,6 +340,6 @@ auto make_shared(F_Construct &&fc, F_Destruct &&fd) {
}
using signal_t = event_t<bool>;
}
} // namespace safe
#endif //SUNSHINE_THREAD_SAFE_H

View file

@ -1,17 +1,21 @@
#ifndef UTILITY_H
#define UTILITY_H
#include <algorithm>
#include <condition_variable>
#include <memory>
#include <mutex>
#include <optional>
#include <string_view>
#include <type_traits>
#include <variant>
#include <vector>
#include <memory>
#include <type_traits>
#include <algorithm>
#include <optional>
#include <mutex>
#include <condition_variable>
#include <string_view>
#define KITTY_WHILE_LOOP(x, y, z) { x;while(y) z }
#define KITTY_WHILE_LOOP(x, y, z) \
{ \
x; \
while(y) z \
}
#define KITTY_DECL_CONSTR(x) \
x(x &&) noexcept = default; \
x &operator=(x &&) noexcept = default; \
@ -76,8 +80,10 @@ struct __either<false, X, Y> {
template<bool V, class X, class Y>
using either_t = typename __either<V, X, Y>::type;
template<class... Ts> struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts> overloaded(Ts...) -> overloaded<Ts...>;
template<class... Ts>
struct overloaded : Ts... { using Ts::operator()...; };
template<class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;
template<class T>
class FailGuard {
@ -103,6 +109,7 @@ public:
void disable() { failure = false; }
bool failure { true };
private:
T _func;
};
@ -129,12 +136,14 @@ template<class T>
class Hex {
public:
typedef T elem_type;
private:
const char _bits[16] {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
char _hex[sizeof(elem_type) * 2];
public:
Hex(const elem_type &elem, bool rev) {
if(!rev) {
@ -479,6 +488,7 @@ public:
explicit operator bool() const {
return _p != nullptr;
}
protected:
pointer _p;
deleter_type _deleter;
@ -621,9 +631,7 @@ struct __false_v<T, std::enable_if_t<
std::is_pointer_v<T> ||
instantiation_of_v<std::unique_ptr, T> ||
instantiation_of_v<std::shared_ptr, T> ||
instantiation_of_v<uniq_ptr, T>
)
>> {
instantiation_of_v<uniq_ptr, T>)>> {
static constexpr std::nullptr_t value = nullptr;
};
@ -765,8 +773,7 @@ struct endian_helper { };
template<class T>
struct endian_helper<T, std::enable_if_t<
!(instantiation_of_v<std::optional, T>)
>> {
!(instantiation_of_v<std::optional, T>)>> {
static inline T big(T x) {
if constexpr(endianness<T>::little) {
uint8_t *data = reinterpret_cast<uint8_t *>(&x);
@ -790,8 +797,7 @@ struct endian_helper<T, std::enable_if_t<
template<class T>
struct endian_helper<T, std::enable_if_t<
instantiation_of_v<std::optional, T>
>> {
instantiation_of_v<std::optional, T>>> {
static inline T little(T x) {
if(!x) return x;
@ -823,7 +829,7 @@ inline auto little(T x) { return endian_helper<T>::little(x); }
template<class T>
inline auto big(T x) { return endian_helper<T>::big(x); }
} /* endian */
} // namespace endian
} /* util */
} // namespace util
#endif

View file

@ -75,5 +75,5 @@ union uuid_t {
return (b64[0] > other.b64[0] || (b64[0] == other.b64[0] && b64[1] > other.b64[1]));
}
};
}
} // namespace util
#endif //T_MAN_UUID_H

View file

@ -3,19 +3,19 @@
//
#include <atomic>
#include <thread>
#include <bitset>
#include <thread>
extern "C" {
#include <libswscale/swscale.h>
}
#include "config.h"
#include "main.h"
#include "platform/common.h"
#include "round_robin.h"
#include "sync.h"
#include "config.h"
#include "video.h"
#include "main.h"
#ifdef _WIN32
extern "C" {
@ -52,7 +52,7 @@ enum class profile_hevc_e : int {
main_10,
rext,
};
}
} // namespace nv
using ctx_t = util::safe_ptr<AVCodecContext, free_ctx>;
using frame_t = util::safe_ptr<AVFrame, free_frame>;
@ -95,8 +95,7 @@ public:
sws_setColorspaceDetails(sws.get(),
sws_getCoefficients(SWS_CS_DEFAULT), 0,
sws_getCoefficients(colorspace), color_range - 1,
0, 1 << 16, 1 << 16
);
0, 1 << 16, 1 << 16);
}
int init(int in_width, int in_height, int out_width, int out_height, AVFrame *frame, AVPixelFormat format) {
@ -104,8 +103,7 @@ public:
in_width, in_height, AV_PIX_FMT_BGR0,
out_width, out_height, format,
SWS_LANCZOS | SWS_ACCURATE_RND,
nullptr, nullptr, nullptr
));
nullptr, nullptr, nullptr));
data = frame;
return sws ? 0 : -1;
@ -174,11 +172,9 @@ struct encoder_t {
class session_t {
public:
session_t() = default;
session_t(ctx_t &&ctx, frame_t &&frame, util::wrap_ptr<platf::hwdevice_t> &&device) :
ctx { std::move(ctx) }, frame { std::move(frame) }, device { std::move(device) } {}
session_t(ctx_t &&ctx, frame_t &&frame, util::wrap_ptr<platf::hwdevice_t> &&device) : ctx { std::move(ctx) }, frame { std::move(frame) }, device { std::move(device) } {}
session_t(session_t &&other) noexcept :
ctx { std::move(other.ctx) }, frame { std::move(other.frame) }, device { std::move(other.device) } {}
session_t(session_t &&other) noexcept : ctx { std::move(other.ctx) }, frame { std::move(other.frame) }, device { std::move(other.device) } {}
// Ensure objects are destroyed in the correct order
session_t &operator=(session_t &&other) {
@ -254,26 +250,21 @@ static encoder_t nvenc {
AV_PIX_FMT_D3D11,
AV_PIX_FMT_NV12, AV_PIX_FMT_P010,
{
{
{ "forced-idr"s, 1 },
{ { "forced-idr"s, 1 },
{ "zerolatency"s, 1 },
{ "preset"s, &config::video.nv.preset },
{ "rc"s, &config::video.nv.rc }
},
std::nullopt, std::nullopt,
{ "rc"s, &config::video.nv.rc } },
std::nullopt,
std::nullopt,
"hevc_nvenc"s,
},
{
{
{ "forced-idr"s, 1 },
{ { { "forced-idr"s, 1 },
{ "zerolatency"s, 1 },
{ "preset"s, &config::video.nv.preset },
{ "rc"s, &config::video.nv.rc },
{ "coder"s, &config::video.nv.coder }
},
{ "coder"s, &config::video.nv.coder } },
std::nullopt, std::make_optional<encoder_t::option_t>({ "qp"s, &config::video.qp }),
"h264_nvenc"s
},
"h264_nvenc"s },
false,
true,
@ -288,26 +279,23 @@ static encoder_t amdvce {
AV_PIX_FMT_D3D11,
AV_PIX_FMT_NV12, AV_PIX_FMT_P010,
{
{
{ "header_insertion_mode"s, "idr"s },
{ { "header_insertion_mode"s, "idr"s },
{ "gops_per_idr"s, 30 },
{ "usage"s, "ultralowlatency"s },
{ "quality"s, &config::video.amd.quality },
{ "rc"s, &config::video.amd.rc }
},
std::nullopt, std::make_optional<encoder_t::option_t>({"qp"s, &config::video.qp}),
{ "rc"s, &config::video.amd.rc } },
std::nullopt,
std::make_optional<encoder_t::option_t>({ "qp"s, &config::video.qp }),
"hevc_amf"s,
},
{
{
{ {
{ "usage"s, "ultralowlatency"s },
{ "quality"s, &config::video.amd.quality },
{ "rc"s, &config::video.amd.rc },
{ "log_to_dbg"s, "1"s },
},
std::nullopt, std::make_optional<encoder_t::option_t>({ "qp"s, &config::video.qp }),
"h264_amf"s
},
"h264_amf"s },
false,
true,
@ -322,27 +310,20 @@ static encoder_t software {
AV_HWDEVICE_TYPE_NONE,
AV_PIX_FMT_NONE,
AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P10,
{
// x265's Info SEI is so long that it causes the IDR picture data to be
{ // x265's Info SEI is so long that it causes the IDR picture data to be
// 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 },
{ "preset"s, &config::video.sw.preset },
{ "tune"s, &config::video.sw.tune }
},
{ "tune"s, &config::video.sw.tune } },
std::make_optional<encoder_t::option_t>("crf"s, &config::video.crf), std::make_optional<encoder_t::option_t>("qp"s, &config::video.qp),
"libx265"s
},
{
{
{ "preset"s, &config::video.sw.preset },
{ "tune"s, &config::video.sw.tune }
},
"libx265"s },
{ { { "preset"s, &config::video.sw.preset },
{ "tune"s, &config::video.sw.tune } },
std::make_optional<encoder_t::option_t>("crf"s, &config::video.crf), std::make_optional<encoder_t::option_t>("qp"s, &config::video.qp),
"libx264"s
},
"libx264"s },
true,
false,
@ -375,8 +356,7 @@ void captureThread(
std::shared_ptr<safe::queue_t<capture_ctx_t>> capture_ctx_queue,
util::sync_t<std::weak_ptr<platf::display_t>> &display_wp,
safe::signal_t &reinit_event,
const encoder_t &encoder
) {
const encoder_t &encoder) {
std::vector<capture_ctx_t> capture_ctxs;
auto fg = util::fail_guard([&]() {
@ -665,13 +645,14 @@ std::optional<session_t> make_session(const encoder_t &encoder, const config_t &
AVDictionary *options { nullptr };
auto handle_option = [&options](const encoder_t::option_t &option) {
std::visit(util::overloaded {
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); },
[&](std::optional<int> *v) { if(*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) { if(!v->empty()) av_dict_set(&options, option.name.c_str(), v->c_str(), 0); }
}, option.value);
[&](std::string *v) { if(!v->empty()) av_dict_set(&options, option.name.c_str(), v->c_str(), 0); } },
option.value);
};
for(auto &option : video_format.options) {
@ -730,8 +711,7 @@ std::optional<session_t> make_session(const encoder_t &encoder, const config_t &
return std::make_optional(session_t {
std::move(ctx),
std::move(frame),
std::move(device)
});
std::move(device) });
}
void encode_run(
@ -1006,7 +986,8 @@ void captureThreadSync() {
}
});
while(encode_run_sync(synced_session_ctxs, ctx) == encode_e::reinit);
while(encode_run_sync(synced_session_ctxs, ctx) == encode_e::reinit)
;
}
void capture_async(
@ -1029,8 +1010,7 @@ void capture_async(
auto delay = std::chrono::floor<std::chrono::nanoseconds>(1s) / config.framerate;
ref->capture_ctx_queue->raise(capture_ctx_t {
images, delay
});
images, delay });
if(!ref->capture_ctx_queue->running()) {
return;
@ -1098,8 +1078,7 @@ void capture(
safe::signal_t join_event;
auto ref = capture_thread_sync.ref();
ref->encode_session_ctx_queue.raise(sync_session_ctx_t {
shutdown_event, &join_event, packets, idr_events, config, 1, 1, channel_data
});
shutdown_event, &join_event, packets, idr_events, config, 1, 1, channel_data });
// Wait for join signal
join_event.view();
@ -1224,8 +1203,7 @@ int init() {
if(
(!config::video.encoder.empty() && pos->name != config::video.encoder) ||
!validate_encoder(*pos) ||
(config::video.hevc_mode == 3 && !pos->hevc[encoder_t::DYNAMIC_RANGE])
) {
(config::video.hevc_mode == 3 && !pos->hevc[encoder_t::DYNAMIC_RANGE])) {
pos = encoders.erase(pos);
continue;
@ -1319,7 +1297,7 @@ void sw_img_to_frame(const platf::img_t &img, frame_t &frame) {}
namespace platf::dxgi {
void lock(void *hwdevice);
void unlock(void *hwdevice);
}
} // namespace platf::dxgi
void do_nothing(void *) {}
namespace video {
void dxgi_img_to_frame(const platf::img_t &img, frame_t &frame) {

View file

@ -5,9 +5,9 @@
#ifndef SUNSHINE_VIDEO_H
#define SUNSHINE_VIDEO_H
#include "thread_safe.h"
#include "input.h"
#include "platform/common.h"
#include "thread_safe.h"
extern "C" {
#include <libavcodec/avcodec.h>
@ -70,6 +70,6 @@ void capture(
void *channel_data);
int init();
}
} // namespace video
#endif //SUNSHINE_VIDEO_H

View file

@ -2,9 +2,9 @@
// Created by loki on 1/24/20.
//
#include <roapi.h>
#include <mmdeviceapi.h>
#include <audioclient.h>
#include <mmdeviceapi.h>
#include <roapi.h>
#include <synchapi.h>
@ -74,26 +74,20 @@ struct format_t {
int channels;
int channel_mask;
} formats[] {
{
"Mono"sv,
{ "Mono"sv,
1,
SPEAKER_FRONT_CENTER
},
{
"Stereo"sv,
SPEAKER_FRONT_CENTER },
{ "Stereo"sv,
2,
SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT
},
{
"Surround 5.1"sv,
SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT },
{ "Surround 5.1"sv,
6,
SPEAKER_FRONT_LEFT |
SPEAKER_FRONT_RIGHT |
SPEAKER_FRONT_CENTER |
SPEAKER_LOW_FREQUENCY |
SPEAKER_BACK_LEFT |
SPEAKER_BACK_RIGHT
}
SPEAKER_BACK_RIGHT }
};
void set_wave_format(audio::wave_format_t &wave_format, const format_t &format) {
@ -211,7 +205,8 @@ void print_device(device_t &device) {
<< L"Device name : "sv << no_null((LPWSTR)device_friendly_name.prop.pszVal) << std::endl
<< L"Adapter name : "sv << no_null((LPWSTR)adapter_friendly_name.prop.pszVal) << std::endl
<< L"Device description : "sv << no_null((LPWSTR)device_desc.prop.pszVal) << std::endl
<< L"Device state : "sv << device_state_string << std::endl << std::endl;
<< L"Device state : "sv << device_state_string << std::endl
<< std::endl;
if(device_state != DEVICE_STATE_ACTIVE) {
return;
@ -224,7 +219,7 @@ void print_device(device_t &device) {
std::cout << format.name << ": "sv << (!audio_client ? "unsupported"sv : "supported"sv) << std::endl;
}
}
}
} // namespace audio
void print_help() {
std::cout

View file

@ -2,8 +2,8 @@
// Created by loki on 1/23/20.
//
#include <dxgi.h>
#include <d3dcommon.h>
#include <dxgi.h>
#include <iostream>
@ -20,7 +20,7 @@ using factory1_t = util::safe_ptr<IDXGIFactory1, Release<IDXGIFactory1>>;
using adapter_t = util::safe_ptr<IDXGIAdapter1, Release<IDXGIAdapter1>>;
using output_t = util::safe_ptr<IDXGIOutput, Release<IDXGIOutput>>;
}
} // namespace dxgi
int main(int argc, char *argv[]) {
HRESULT status;
@ -49,7 +49,8 @@ int main(int argc, char *argv[]) {
<< "Device Device ID : 0x"sv << util::hex(adapter_desc.DeviceId).to_string_view() << std::endl
<< "Device Video Mem : "sv << adapter_desc.DedicatedVideoMemory / 1048576 << " MiB"sv << std::endl
<< "Device Sys Mem : "sv << adapter_desc.DedicatedSystemMemory / 1048576 << " MiB"sv << std::endl
<< "Share Sys Mem : "sv << adapter_desc.SharedSystemMemory / 1048576 << " MiB"sv << std::endl << std::endl
<< "Share Sys Mem : "sv << adapter_desc.SharedSystemMemory / 1048576 << " MiB"sv << std::endl
<< std::endl
<< " ====== OUTPUT ======"sv << std::endl;
dxgi::output_t::pointer output_p {};
@ -66,7 +67,8 @@ int main(int argc, char *argv[]) {
<< L" Output Name : "sv << desc.DeviceName << std::endl;
std::cout
<< " AttachedToDesktop : "sv << (desc.AttachedToDesktop ? "yes"sv : "no"sv) << std::endl
<< " Resolution : "sv << width << 'x' << height << std::endl << std::endl;
<< " Resolution : "sv << width << 'x' << height << std::endl
<< std::endl;
}
}