Skip to content
Open
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
5 changes: 3 additions & 2 deletions src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ namespace audio {
}

auto frame_size = config.packetDuration * stream.sampleRate / 1000;
auto mic = control->microphone(stream.mapping, stream.channelCount, stream.sampleRate, frame_size);
bool continuous_audio = config.flags[config_t::CONTINUOUS_AUDIO];
auto mic = control->microphone(stream.mapping, stream.channelCount, stream.sampleRate, frame_size, continuous_audio);
if (!mic) {
BOOST_LOG(error) << "Audio capture: failed to initialize microphone";
return;
Expand Down Expand Up @@ -270,7 +271,7 @@ namespace audio {
BOOST_LOG(info) << "Reinitializing audio capture"sv;
mic.reset();
do {
mic = control->microphone(stream.mapping, stream.channelCount, stream.sampleRate, frame_size);
mic = control->microphone(stream.mapping, stream.channelCount, stream.sampleRate, frame_size, continuous_audio);
if (!mic) {
BOOST_LOG(warning) << "Couldn't re-initialize audio input"sv;
}
Expand Down
1 change: 1 addition & 0 deletions src/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace audio {
HIGH_QUALITY, ///< High quality audio
HOST_AUDIO, ///< Host audio
CUSTOM_SURROUND_PARAMS, ///< Custom surround parameters
CONTINUOUS_AUDIO, ///< Continuous audio
MAX_FLAGS ///< Maximum number of flags
};

Expand Down
7 changes: 6 additions & 1 deletion src/confighttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,12 @@ namespace confighttp {
// TODO: Input Validation
pt::read_json(ss, inputTree);
std::string uuid = inputTree.get<std::string>("uuid");
outputTree.put("status", nvhttp::unpair_client(uuid));
const bool removed = nvhttp::unpair_client(uuid);
outputTree.put("status", removed);

if (removed && nvhttp::get_all_clients().empty()) {
proc::proc.terminate();
}
}
catch (std::exception &e) {
BOOST_LOG(warning) << "Unpair: "sv << e.what();
Expand Down
1 change: 1 addition & 0 deletions src/nvhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ namespace nvhttp {
launch_session->enable_sops = util::from_view(get_arg(args, "sops", "0"));
launch_session->surround_info = util::from_view(get_arg(args, "surroundAudioInfo", "196610"));
launch_session->surround_params = (get_arg(args, "surroundParams", ""));
launch_session->continuous_audio = util::from_view(get_arg(args, "continuousAudio", "0"));
launch_session->gcmap = util::from_view(get_arg(args, "gcmap", "0"));
launch_session->enable_hdr = util::from_view(get_arg(args, "hdrMode", "0"));
launch_session->use_vdd = util::from_view(get_arg(args, "useVdd", "0"));
Expand Down
5 changes: 4 additions & 1 deletion src/platform/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ namespace platf {
set_sink(const std::string &sink) = 0;

virtual std::unique_ptr<mic_t>
microphone(const std::uint8_t *mapping, int channels, std::uint32_t sample_rate, std::uint32_t frame_size) = 0;
microphone(const std::uint8_t *mapping, int channels, std::uint32_t sample_rate, std::uint32_t frame_size, bool continuous) = 0;

/**
* @brief Check if the audio sink is available in the system.
Expand Down Expand Up @@ -715,6 +715,9 @@ namespace platf {
void
adjust_thread_priority(thread_priority_e priority);

void
enable_mouse_keys();

// Allow OS-specific actions to be taken to prepare for streaming
void
streaming_will_start();
Expand Down
2 changes: 1 addition & 1 deletion src/platform/linux/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ namespace platf {
}

std::unique_ptr<mic_t>
microphone(const std::uint8_t *mapping, int channels, std::uint32_t sample_rate, std::uint32_t frame_size) override {
microphone(const std::uint8_t *mapping, int channels, std::uint32_t sample_rate, std::uint32_t frame_size, bool continuous_audio) override {
// Sink choice priority:
// 1. Config sink
// 2. Last sink swapped to (Usually virtual in this case)
Expand Down
5 changes: 5 additions & 0 deletions src/platform/linux/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ namespace platf {
// Unimplemented
}

void
enable_mouse_keys() {
// Unimplemented
}

void
streaming_will_start() {
// Nothing to do
Expand Down
2 changes: 1 addition & 1 deletion src/platform/macos/microphone.mm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
}

std::unique_ptr<mic_t>
microphone(const std::uint8_t *mapping, int channels, std::uint32_t sample_rate, std::uint32_t frame_size) override {
microphone(const std::uint8_t *mapping, int channels, std::uint32_t sample_rate, std::uint32_t frame_size, bool continuous_audio) override {
auto mic = std::make_unique<av_mic_t>();
const char *audio_sink = "";

Expand Down
5 changes: 5 additions & 0 deletions src/platform/macos/misc.mm
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,11 @@
// Unimplemented
}

void
enable_mouse_keys() {
// Unimplemented
}

void
streaming_will_start() {
// Nothing to do
Expand Down
14 changes: 10 additions & 4 deletions src/platform/windows/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,11 @@ namespace platf::audio {
// Refill the sample buffer if needed
while (sample_buf_pos - std::begin(sample_buf) < sample_size) {
auto capture_result = _fill_buffer();
if (capture_result != capture_e::ok) {
if (capture_result == capture_e::timeout && continuous_audio) {
// Write silence to sample_buf
std::fill_n(sample_buf_pos, sample_size, 0.0f);
sample_buf_pos += sample_size;
} else if (capture_result != capture_e::ok) {
return capture_result;
}
}
Expand All @@ -486,7 +490,7 @@ namespace platf::audio {
}

int
init(std::uint32_t sample_rate, std::uint32_t frame_size, std::uint32_t channels_out) {
init(std::uint32_t sample_rate, std::uint32_t frame_size, std::uint32_t channels_out, bool continuous) {
audio_event.reset(CreateEventA(nullptr, FALSE, FALSE, nullptr));
if (!audio_event) {
BOOST_LOG(error) << "Couldn't create Event handle"sv;
Expand Down Expand Up @@ -546,6 +550,7 @@ namespace platf::audio {
REFERENCE_TIME default_latency;
audio_client->GetDevicePeriod(&default_latency, nullptr);
default_latency_ms = default_latency / 1000;
continuous_audio = continuous;

std::uint32_t frames;
status = audio_client->GetBufferSize(&frames);
Expand Down Expand Up @@ -716,6 +721,7 @@ namespace platf::audio {
util::buffer_t<float> sample_buf;
float *sample_buf_pos;
int channels;
bool continuous_audio;

HANDLE mmcss_task_handle = NULL;
};
Expand Down Expand Up @@ -808,10 +814,10 @@ namespace platf::audio {
}

std::unique_ptr<mic_t>
microphone(const std::uint8_t *mapping, int channels, std::uint32_t sample_rate, std::uint32_t frame_size) override {
microphone(const std::uint8_t *mapping, int channels, std::uint32_t sample_rate, std::uint32_t frame_size, bool continuous_audio) override {
auto mic = std::make_unique<mic_wasapi_t>();

if (mic->init(sample_rate, frame_size, channels)) {
if (mic->init(sample_rate, frame_size, channels, continuous_audio)) {
return nullptr;
}

Expand Down
10 changes: 6 additions & 4 deletions src/platform/windows/display_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1160,8 +1160,9 @@ namespace platf {
return {};
}

dxgi::adapter_t adapter;
for (int x = 0; factory->EnumAdapters1(x, &adapter) != DXGI_ERROR_NOT_FOUND; ++x) {
dxgi::adapter_t::pointer adapter_p;
for (int x = 0; factory->EnumAdapters1(x, &adapter_p) != DXGI_ERROR_NOT_FOUND; ++x) {
dxgi::adapter_t adapter { adapter_p };
DXGI_ADAPTER_DESC1 adapter_desc;
adapter->GetDesc1(&adapter_desc);

Expand Down Expand Up @@ -1242,8 +1243,9 @@ namespace platf {
return {};
}

dxgi::adapter_t adapter;
for (int x = 0; factory->EnumAdapters1(x, &adapter) != DXGI_ERROR_NOT_FOUND; ++x) {
dxgi::adapter_t::pointer adapter_p;
for (int x = 0; factory->EnumAdapters1(x, &adapter_p) != DXGI_ERROR_NOT_FOUND; ++x) {
dxgi::adapter_t adapter { adapter_p };
DXGI_ADAPTER_DESC1 adapter_desc;
adapter->GetDesc1(&adapter_desc);

Expand Down
5 changes: 5 additions & 0 deletions src/platform/windows/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1324,6 +1324,11 @@ namespace platf {
}
}

enable_mouse_keys();
}

void
enable_mouse_keys() {
// If there is no mouse connected, enable Mouse Keys to force the cursor to appear
if (!GetSystemMetrics(SM_MOUSEPRESENT)) {
BOOST_LOG(info) << "A mouse was not detected. Sunshine will enable Mouse Keys while streaming to force the mouse cursor to appear.";
Expand Down
4 changes: 4 additions & 0 deletions src/rtsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,10 @@ namespace rtsp_stream {
std::copy_n(std::begin(platf::speaker::map_surround714), 12, std::begin(config.audio.customStreamParams.mapping));
config.audio.flags[audio::config_t::CUSTOM_SURROUND_PARAMS] = true;
}
if (session.continuous_audio) {
BOOST_LOG(info) << "Client requested continuous audio"sv;
config.audio.flags[audio::config_t::CONTINUOUS_AUDIO] = true;
}

// If the client sent a configured bitrate, we will choose the actual bitrate ourselves
// by using FEC percentage and audio quality settings. If the calculated bitrate ends up
Expand Down
1 change: 1 addition & 0 deletions src/rtsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace rtsp_stream {
int appid;
int surround_info;
std::string surround_params;
bool continuous_audio;
bool enable_hdr;
bool enable_sops;
bool enable_mic;
Expand Down
4 changes: 4 additions & 0 deletions src/video.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2736,6 +2736,10 @@ namespace video {
}

session->request_normal_frame();

// While streaming check to see if the mouse is present and enable Mouse Keys to force the cursor to appear
// This is useful for KVM switch scenarios where mouse may disappear during streaming
platf::enable_mouse_keys();
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct AudioTest: PlatformTestSuite, testing::WithParamInterface<std::tuple<std:
};

constexpr std::bitset<config_t::MAX_FLAGS> config_flags(const int flag = -1) {
std::bitset<3> result = std::bitset<config_t::MAX_FLAGS>();
auto result = std::bitset<config_t::MAX_FLAGS>();
if (flag >= 0) {
result.set(flag);
}
Expand Down
Loading