Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Core/Api/StreamSessionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1538,7 +1538,7 @@ private static RdpDisplayOptions DisplayOptions(StreamSession session) =>
new(session.RdpDisplayScale, session.RdpComposition);

private static int NormalizeRdpFrameRate(int frameRate) =>
Math.Clamp(frameRate > 0 ? frameRate : 60, 1, 240);
Math.Clamp(frameRate > 0 ? frameRate : 60, 1, RdpSessionCreator.MaxFrameRate);

private static int NormalizeRdpColorDepth(int colorDepth) => colorDepth switch
{
Expand Down
17 changes: 14 additions & 3 deletions Core/Helpers/RdpSessionCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,10 @@ static void ApplyFrameRatePolicy(int frameRate, RdpCompositionMode mode)
/// frame al llegar con tope de fps (display_base.cpp). Cada frame del juego sale en el
/// siguiente tic de composicion: con 8 ms (125 Hz) salian a 16/24 ms y Moonlight
/// descartaba hasta un 10 % por jitter; con 4 ms el desfase maximo es la mitad. No se
/// baja de 4 ms (500 Hz con 120 fps): el coste de componer y de RDP crece con el ritmo.
/// Windows ignora intervalos por debajo de 2 ms.
/// baja de 4 ms (250 Hz) mientras eso alcance a los fps: el coste de componer y de RDP crece
/// con el ritmo. Por encima de 250 fps se compone al intervalo entero que no se quede por
/// debajo de los fps (300 -> 3 ms, 334 Hz; 400 -> 2 ms, 500 Hz). Windows ignora intervalos
/// por debajo de 2 ms, así que 500 Hz es el techo.
/// </para>
/// <para>
/// <see cref="RdpCompositionMode.Efficient"/> compone a los fps, redondeando al ms mas
Expand All @@ -834,6 +836,8 @@ internal static int CompositionIntervalMs(int frameRate, RdpCompositionMode mode
return Math.Max(2, 1000 / frameRate);
if (mode == RdpCompositionMode.Efficient)
return Math.Max(2, (int)Math.Round(1000.0 / frameRate, MidpointRounding.AwayFromZero));
if (frameRate > 250)
return Math.Max(2, 1000 / frameRate);
return Math.Max(4, 1000 / (4 * frameRate));
}

Expand Down Expand Up @@ -1565,8 +1569,15 @@ static string NormalizeDomain(string? domain) =>
? Environment.MachineName
: domain.Trim();

/// <summary>
/// Tope de fps de la sesión (y de Hz de RemoteIdd, que son los mismos). Windows no compone
/// una sesión RDP por debajo de 2 ms (<see cref="CompositionIntervalMs"/>): 500 es lo más
/// que puede llegar a salir.
/// </summary>
internal const int MaxFrameRate = 500;

static int NormalizeFrameRate(int frameRate) =>
Math.Clamp(frameRate > 0 ? frameRate : 60, 1, 240);
Math.Clamp(frameRate > 0 ? frameRate : 60, 1, MaxFrameRate);

static int NormalizeColorDepth(int colorDepth) => colorDepth switch
{
Expand Down
2 changes: 1 addition & 1 deletion Core/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ <h5 class="form-subtitle" data-i18n="ux.advRdp">Sesión RDP</h5>
<div class="form-grid">
<div class="form-row">
<label for="sess-fps" data-i18n="ux.fpsLabel">Fotogramas por segundo</label>
<input type="number" id="sess-fps" value="60" min="1" max="240" step="1">
<input type="number" id="sess-fps" value="60" min="1" max="500" step="1">
<div class="hint" data-i18n="ux.fpsHint">60 es lo recomendado. Más solo si el cliente y la red lo aguantan.</div>
</div>
<div class="form-row">
Expand Down
10 changes: 8 additions & 2 deletions Native/RemoteIdd/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ static void KeepSharedObjects(UINT32 session)
// va también partido como los puestos en pantalla dividida: mitades (vertical: ancho/2;
// horizontal: alto/2) y cuartos (ancho/2 y alto/2). Ver AllModes.
struct ModeDef { DWORD Width, Height, VSync; };

// Hz que se aceptan del registro (OsmsRefreshHz) o del IOCTL. OpenStreamMS no pasa de 500 (en
// una sesión RDP Windows no compone más rápido), pero el driver admite hasta 1000 para probar
// un monitor a 1000 Hz que saque cada fotograma del juego en cuanto se presenta.
constexpr DWORD kMinHz = 24;
constexpr DWORD kMaxHz = 1000;
static const ModeDef kBaseModes[] = {
{ 3840, 2160, 60 }, { 3840, 2160, 120 },
{ 2560, 1440, 60 }, { 2560, 1440, 120 }, { 2560, 1440, 144 },
Expand Down Expand Up @@ -195,7 +201,7 @@ static void SeatFromDevice(WDFDEVICE device)
DWORD scale = read(L"OsmsScalePercent");

AcquireSRWLockExclusive(&g_modeLock);
if (hz >= 24 && hz <= 500)
if (hz >= kMinHz && hz <= kMaxHz)
g_seatMode.VSync = hz;
if (width >= 640 && width <= 7680 && height >= 360 && height <= 4320)
{
Expand Down Expand Up @@ -632,7 +638,7 @@ void EvtDeviceIoControl(WDFDEVICE, WDFREQUEST request, size_t, size_t inputLengt
g_seatMode.Width = in->Width;
g_seatMode.Height = in->Height;
}
if (in->RefreshHz >= 24 && in->RefreshHz <= 500)
if (in->RefreshHz >= kMinHz && in->RefreshHz <= kMaxHz)
g_seatMode.VSync = in->RefreshHz;
ReleaseSRWLockExclusive(&g_modeLock);
}
Expand Down
2 changes: 1 addition & 1 deletion Native/RemoteIdd/Provider/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
param(
[string] $Bin,
[string] $Package,
[ValidateRange(24, 500)] [int] $RefreshHz = 60,
[ValidateRange(24, 1000)] [int] $RefreshHz = 60,
[switch] $AllConnections,
[switch] $RestartTermService,
[switch] $SkipTestSigningCheck
Expand Down
23 changes: 23 additions & 0 deletions tests/OpenStreamMS.Tests/CompositionIntervalTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using OpenStreamMS.Core.Helpers;
using Xunit;

namespace OpenStreamMS.Tests;

public class CompositionIntervalTests
{
[Theory]
[InlineData(60, 4)] // 250 Hz: Sunshine marca el ritmo
[InlineData(120, 4)]
[InlineData(240, 4)] // 250 Hz alcanza a 240 fps
[InlineData(250, 4)]
[InlineData(300, 3)] // 334 Hz
[InlineData(400, 2)] // 500 Hz
[InlineData(500, 2)] // techo de Windows
[InlineData(100, 10)] // 1000/fps entero: compone a los fps
public void Smooth(int fps, int expectedMs) =>
Assert.Equal(expectedMs, RdpSessionCreator.CompositionIntervalMs(fps));

[Fact]
public void FpsAboveCeilingIsClamped() =>
Assert.Equal(2, RdpSessionCreator.CompositionIntervalMs(1000));
}