Skip to content
Draft
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
79 changes: 79 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2124,6 +2124,85 @@ editing the `conf` file in a text editor. Use the examples as reference.
</tr>
</table>

### mpeg2_mode

<table>
<tr>
<td>Description</td>
<td colspan="2">
Allows compatibility clients to request MPEG-2/H.262 video streams. Automatic mode keeps this legacy codec
below H.264, HEVC, and AV1 by not advertising it unless explicitly forced. When forced, Sunshine may use a
legacy-capable fallback encoder for MPEG-2 streams without changing the encoder used for modern codecs.
@warning{MPEG-2 may be more CPU-intensive to encode than modern hardware-accelerated codecs when hardware
encoding is unavailable.}
</td>
</tr>
<tr>
<td>Default</td>
<td colspan="2">@code{}
0
@endcode</td>
</tr>
<tr>
<td>Example</td>
<td colspan="2">@code{}
mpeg2_mode = 2
@endcode</td>
</tr>
<tr>
<td rowspan="3">Choices</td>
<td>0</td>
<td>preserve modern codec automatic selection and keep MPEG-2 unadvertised</td>
</tr>
<tr>
<td>1</td>
<td>do not advertise support for MPEG-2</td>
</tr>
<tr>
<td>2</td>
<td>advertise support for MPEG-2/H.262 video</td>
</tr>
</table>

### h263p_mode

<table>
<tr>
<td>Description</td>
<td colspan="2">
Allows compatibility clients to request H.263+ video streams. Automatic mode keeps this legacy codec below
H.264, HEVC, and AV1 by not advertising it unless explicitly forced. When forced, Sunshine may use a
legacy-capable fallback encoder for H.263+ streams without changing the encoder used for modern codecs.
@warning{H.263+ uses software encoding in Sunshine and may reduce host performance.}
</td>
</tr>
<tr>
<td>Default</td>
<td colspan="2">@code{}
0
@endcode</td>
</tr>
<tr>
<td>Example</td>
<td colspan="2">@code{}
h263p_mode = 2
@endcode</td>
</tr>
<tr>
<td rowspan="3">Choices</td>
<td>0</td>
<td>preserve modern codec automatic selection and keep H.263+ unadvertised</td>
</tr>
<tr>
<td>1</td>
<td>do not advertise support for H.263+</td>
</tr>
<tr>
<td>2</td>
<td>advertise support for H.263+ video</td>
</tr>
</table>

### capture

<table>
Expand Down
4 changes: 4 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ namespace config {

0, // hevc_mode
0, // av1_mode
0, // mpeg2_mode
0, // h263p_mode

2, // min_threads
{
Expand Down Expand Up @@ -1101,6 +1103,8 @@ namespace config {
int_f(vars, "qp", video.qp);
int_between_f(vars, "hevc_mode", video.hevc_mode, {0, 3});
int_between_f(vars, "av1_mode", video.av1_mode, {0, 3});
int_between_f(vars, "mpeg2_mode", video.mpeg2_mode, {0, 2});
int_between_f(vars, "h263p_mode", video.h263p_mode, {0, 2});
int_f(vars, "min_threads", video.min_threads);
string_f(vars, "sw_preset", video.sw.sw_preset);
if (!video.sw.sw_preset.empty()) {
Expand Down
6 changes: 4 additions & 2 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ namespace config {
// ffmpeg params
int qp; // higher == more compression and less quality

int hevc_mode;
int av1_mode;
int hevc_mode; ///< HEVC codec advertisement mode.
int av1_mode; ///< AV1 codec advertisement mode.
int mpeg2_mode; ///< MPEG-2 codec advertisement mode.
int h263p_mode; ///< H.263+ codec advertisement mode.

int min_threads; // Minimum number of threads/slices for CPU encoding

Expand Down
6 changes: 6 additions & 0 deletions src/nvhttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@
}

template<class T>
void serverinfo(std::shared_ptr<typename SimpleWeb::ServerBase<T>::Response> response, std::shared_ptr<typename SimpleWeb::ServerBase<T>::Request> request) {

Check failure on line 688 in src/nvhttp.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this function to reduce its Cognitive Complexity from 26 to the 25 allowed.

See more on https://sonarcloud.io/project/issues?id=LizardByte_Sunshine&issues=AZ5gBTntOcYDVOXjq4X0&open=AZ5gBTntOcYDVOXjq4X0&pullRequest=5194
print_req<T>(request);

int pair_status = 0;
Expand Down Expand Up @@ -763,6 +763,12 @@
codec_mode_flags |= SCM_AV1_HIGH10_444;
}
}
if (video::active_mpeg2_mode >= 2) {
codec_mode_flags |= SCM_MPEG2;
}
if (video::active_h263p_mode == 2) {
codec_mode_flags |= SCM_H263P;
}
tree.put("root.ServerCodecModeSupport", codec_mode_flags);

if (!config::nvhttp.external_ip.empty()) {
Expand Down
26 changes: 24 additions & 2 deletions src/rtsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,14 @@ namespace rtsp_stream {
ss << "a=rtpmap:98 AV1/90000"sv << std::endl;
}

if (video::active_mpeg2_mode >= 2) {
ss << "a=rtpmap:98 MPV/90000"sv << std::endl;
}

if (video::active_h263p_mode == 2) {
ss << "a=rtpmap:98 H263-1998/90000"sv << std::endl;
}

if (!session.surround_params.empty()) {
// If we have our own surround parameters, advertise them twice first
ss << "a=fmtp:97 surround-params="sv << session.surround_params << std::endl;
Expand Down Expand Up @@ -1115,20 +1123,34 @@ namespace rtsp_stream {
config.monitor.bitrate = (int) configuredBitrateKbps;
}

if (config.monitor.videoFormat == 1 && video::active_hevc_mode == 1) {
if (config.monitor.videoFormat == video::format_hevc && video::active_hevc_mode == 1) {
BOOST_LOG(warning) << "HEVC is disabled, yet the client requested HEVC"sv;

respond(sock, session, &option, 400, "BAD REQUEST", req->sequenceNumber, {});
return;
}

if (config.monitor.videoFormat == 2 && video::active_av1_mode == 1) {
if (config.monitor.videoFormat == video::format_av1 && video::active_av1_mode == 1) {
BOOST_LOG(warning) << "AV1 is disabled, yet the client requested AV1"sv;

respond(sock, session, &option, 400, "BAD REQUEST", req->sequenceNumber, {});
return;
}

if (config.monitor.videoFormat == video::format_mpeg2 && video::active_mpeg2_mode < 2) {
BOOST_LOG(warning) << "MPEG-2 is disabled, yet the client requested MPEG-2"sv;

respond(sock, session, &option, 400, "BAD REQUEST", req->sequenceNumber, {});
return;
}

if (config.monitor.videoFormat == video::format_h263p && video::active_h263p_mode != 2) {
BOOST_LOG(warning) << "H.263+ is disabled, yet the client requested H.263+"sv;

respond(sock, session, &option, 400, "BAD REQUEST", req->sequenceNumber, {});
return;
}

// Check that any required encryption is enabled
auto encryption_mode = net::encryption_mode_for_address(sock.remote_endpoint().address());
if (encryption_mode == config::ENCRYPTION_MODE_MANDATORY &&
Expand Down
Loading
Loading