From bd9c6834b75858c40c1e8c5a62dc966c081659b6 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Fri, 19 Sep 2014 22:04:48 -0700 Subject: [PATCH] Add support for adaptive resolution changes --- .../com/limelight/nvstream/StreamConfiguration.java | 9 ++++++++- .../nvstream/av/video/VideoDecoderRenderer.java | 3 +++ .../com/limelight/nvstream/rtsp/SdpGenerator.java | 13 ++++++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/moonlight-common/src/com/limelight/nvstream/StreamConfiguration.java b/moonlight-common/src/com/limelight/nvstream/StreamConfiguration.java index bc21e28e..51c75416 100644 --- a/moonlight-common/src/com/limelight/nvstream/StreamConfiguration.java +++ b/moonlight-common/src/com/limelight/nvstream/StreamConfiguration.java @@ -6,6 +6,7 @@ public class StreamConfiguration { private int refreshRate; private int bitrate; private boolean sops; + private boolean enableAdaptiveResolution; public StreamConfiguration(String app, int width, int height, int refreshRate, int bitrate) { this.app = app; @@ -16,13 +17,15 @@ public class StreamConfiguration { this.sops = true; } - public StreamConfiguration(String app, int width, int height, int refreshRate, int bitrate, boolean sops) { + public StreamConfiguration(String app, int width, int height, int refreshRate, int bitrate, boolean sops, + boolean enableAdaptiveResolution) { this.app = app; this.width = width; this.height = height; this.refreshRate = refreshRate; this.bitrate = bitrate; this.sops = sops; + this.enableAdaptiveResolution = enableAdaptiveResolution; } public int getWidth() { @@ -52,4 +55,8 @@ public class StreamConfiguration { public boolean getSops() { return sops; } + + public boolean getAdaptiveResolutionEnabled() { + return enableAdaptiveResolution; + } } diff --git a/moonlight-common/src/com/limelight/nvstream/av/video/VideoDecoderRenderer.java b/moonlight-common/src/com/limelight/nvstream/av/video/VideoDecoderRenderer.java index 1bcaaaf2..70dd1c46 100644 --- a/moonlight-common/src/com/limelight/nvstream/av/video/VideoDecoderRenderer.java +++ b/moonlight-common/src/com/limelight/nvstream/av/video/VideoDecoderRenderer.java @@ -6,6 +6,9 @@ public interface VideoDecoderRenderer { public static final int FLAG_FORCE_SOFTWARE_DECODING = 0x4; public static final int FLAG_FILL_SCREEN = 0x8; + // Allows the resolution to dynamically change mid-stream + public static final int CAPABILITY_ADAPTIVE_RESOLUTION = 0x1; + public int getCapabilities(); public int getAverageEndToEndLatency(); diff --git a/moonlight-common/src/com/limelight/nvstream/rtsp/SdpGenerator.java b/moonlight-common/src/com/limelight/nvstream/rtsp/SdpGenerator.java index 1d0e2ff1..caff4aa9 100644 --- a/moonlight-common/src/com/limelight/nvstream/rtsp/SdpGenerator.java +++ b/moonlight-common/src/com/limelight/nvstream/rtsp/SdpGenerator.java @@ -64,9 +64,16 @@ public class SdpGenerator { addSessionAttribute(config, "x-nv-video[0].timeoutLengthMs", "7000"); addSessionAttribute(config, "x-nv-video[0].framesWithInvalidRefThreshold", "0"); - // It should be 16183 but adding 100 but causes resolution to scale in the beginning - // The bit 0x80 enables video scaling on packet loss which we can't support (for now) - addSessionAttribute(config, "x-nv-vqos[0].bw.flags", "16083"); + + if (sc.getAdaptiveResolutionEnabled()) { + addSessionAttribute(config, "x-nv-vqos[0].bw.flags", "16183"); + } + else { + addSessionAttribute(config, "x-nv-vqos[0].bw.flags", "16083"); + + // Lock the bitrate if we're not scaling resolution so the picture doesn't get too bad + addSessionAttribute(config, "x-nv-vqos[0].bw.minimumBitrate", ""+sc.getBitrate()); + } addSessionAttribute(config, "x-nv-vqos[0].bw.maximumBitrate", ""+sc.getBitrate());