Sunshine icon indicating copy to clipboard operation
Sunshine copied to clipboard

Sunshine Reads Incorrect Monitor Index

Open JustPlainGarak opened this issue 2 years ago • 29 comments

Describe the Bug

When running Sunshine, even though my primary display shows as index 0, if I leave the Monitor Number blank or input index number 0, Sunshine always picks my HDMI connected display, which is not my primary. I have to cycle through index numbers and restart the service until I find the correct monitor even though the index number for my primary DisplayPort connected display still shows as monitor 0 in xrandr.

Expected Behavior

Sunshine should select the monitor at index 0 by default.

Additional Context

I am running 4 connected displays, 1 HDMI and 3 DisplayPort. The index number for my primary display always shows index 0 even though Sunshine picks the HDMI display, which can be any index number from 1-3 in xrandr.

Sunshine Host Operating System and Version

Fedora 36 KDE Plasma

Architecture

x86_64

Sunshine Version

0.14.0

GPU Type

AMD

GPU Model

Radeon RX 6700XT

GPU Driver/Mesa Version

Mesa 23.0.0-git (using gloriousegroll copr repo)

Capture Method (Linux Only)

Not sure, whatever the default for a Fedora/Wayland install would be

JustPlainGarak avatar Jun 22 '22 16:06 JustPlainGarak

What is the output of xrandr --listmonitors?

And please paste your config file as well.

ReenigneArcher avatar Jun 22 '22 22:06 ReenigneArcher

Hey, thanks for the reply! I will include that info for you now. I took some logs as well (one left at default which picks the wrong monitor and one with the "wrong" monitor index selected, 3, outputting to the correct monitor).

xrandr output

xrandr --listmonitors
Monitors: 4
 0: +*XWAYLAND0 2560/700x1440/400+2560+1080  XWAYLAND0
 1: +XWAYLAND1 2560/600x1440/340+0+1080  XWAYLAND1
 2: +XWAYLAND2 2560/600x1440/340+5120+1080  XWAYLAND2
 3: +XWAYLAND3 1920/600x1080/340+640+0  XWAYLAND3

Config file

cat /usr/local/sunshine/config/sunshine.conf 
sunshine_name = EmpokNor
nv_preset = default
amd_coder = auto
upnp = disabled
gamepad = x360
qp = 22
nv_rc = auto
hevc_mode = 0
dwmflush = enabled
min_log_level = 2
amd_quality = default
origin_web_ui_allowed = lan
vt_software = auto
vt_realtime = enabled
key_rightalt_to_key_win = disabled
origin_pin_allowed = pc
resolutions = [
    352x240,
    480x360,
    858x480,
    1280x720,
    1920x1080,
    2560x1080,
    3440x1440,
    1920x1200,
    3860x2160,
    3840x1600,
    2560x1440
]
nv_coder = auto
fps = [10,30,60,90,120]
vt_coder = auto
amd_rc = auto
output_name = 3

JustPlainGarak avatar Jun 23 '22 02:06 JustPlainGarak

output_name = 3 this is telling it to select this monitor 3: +XWAYLAND3 1920/600x1080/340+640+0 XWAYLAND3

ReenigneArcher avatar Jun 23 '22 02:06 ReenigneArcher

output_name = 3 this is telling it to select this monitor 3: +XWAYLAND3 1920/600x1080/340+640+0 XWAYLAND3

Yeah, that is what it's supposed to do, I agree. But when I set output to 3, it selects 0 and streams that screen. Conversely, if I select monitor 0 (or leave the field in the web UI blank not specifying a monitor) Sunshine streams monitor 3, the HDMI connected 1080p monitor.

JustPlainGarak avatar Jun 23 '22 02:06 JustPlainGarak

Can confirm the issue on an Arch host, I have 2 monitors and Sunshine is swapping their indexes. xrandr --listmonitors shows this:

Monitors: 2
 0: +*DP-0 1920/531x1080/298+0+0  DP-0
 1: +HDMI-0 1920/160x1080/90+1920+0  HDMI-0

By default (index 0), Sunshine streams the HDMI monitor.

Firokat avatar Aug 16 '22 17:08 Firokat

This issue is stale because it has been open for 90 days with no activity. Comment or remove the stale label, otherwise this will be closed in 10 days.

LizardByte-bot avatar Nov 15 '22 00:11 LizardByte-bot

This issue was closed because it has been stalled for 10 days with no activity.

LizardByte-bot avatar Nov 26 '22 00:11 LizardByte-bot

Can confirm that there is something off:

xrandr --list-monitors
 0: +*DP-4 2560/598x1440/336+1080+260  DP-4
 1: +HDMI-0 1080/531x1920/299+0+0  HDMI-0
 2: +DP-0 2560/597x1440/336+3640+260  DP-0

Choosing 0 results in streaming 1, 1 results in monitor 2 and specifying 2 streams monitor 0.

maxanier avatar Feb 13 '23 11:02 maxanier

I have exactly the same issue with 2 monitors. Selecting monitor 0 in Sunshine actually streams monitor 1 and vice versa.

Monitors: 2
 0: +*DP-1 3840/597x2160/336+0+0  DP-1
 1: +DP-2 3840/597x2160/336+3840+0  DP-2

xrandr reports monitor order as seen by X11, while Sunshine uses KMS instead of X11. Is it possible that KMS and X11 use different monitor order?

kodemeister avatar Mar 27 '23 11:03 kodemeister

It would be nice if the ID was used instead of a number. With a dummy + a desktop monitor that can be on or off, the output number can change.

KuleRucket avatar Mar 27 '23 12:03 KuleRucket

Agree. Using some unique ID would be better than monitor index.

Unfortunately port names like DP-1 or DP-2 also don't seem to be stable. They can change when monitors are plugged on and off. In addition, they can differ in X11 and Wayland sessions.

https://unix.stackexchange.com/questions/584088/how-can-i-get-stable-video-output-names https://bugs.kde.org/show_bug.cgi?id=385135

Probably the best way would be to use monitor identifiers (serial numbers) from EDID. For instance, they are displayed in KDE Plasma settings. On my system they are:

BenQ PD2700U ETR3K01703SL0
BenQ PD2700U ETR3K01702SL0

kodemeister avatar Mar 27 '23 22:03 kodemeister

Do you know if there is any workaround for now? It's uncomfortable changing the monitor from my smartphone while I'm gaming away from my home pc

If I can be of any help, I'm here with the same bug

  • sunshine 19.1
  • AMD 7900 XT
  • arch 6.2.9-zen1-1-zen
  • mesa 23.0.1-2
  • Wayland 1.21.0-2

guilty-p01nt3r avatar Apr 04 '23 21:04 guilty-p01nt3r

Same issue, arch linux host Monitors: 2 0: +*DisplayPort-0 1920/521x1080/293+0+0 DisplayPort-0 1: +HDMI-A-0 1920/527x1080/296+1920+0 HDMI-A-0 sunshine use hdmi monitor if i set 0 index, but if i set index 1 it use dp-0 :)

BadKiko avatar May 31 '23 19:05 BadKiko

I don't think you can guarantee that monitors detected by all capture methods use the index as reported by xrandr --list-monitors. This is just the x11 order.

KuleRucket avatar May 31 '23 20:05 KuleRucket

Also, xrandr --list-monitors only gives you connected monitors but since #1071 the index covers all ports not just connected

KuleRucket avatar May 31 '23 20:05 KuleRucket

I encountered this as well. The order change coincided with switching from X11/VAAPI to NVFBC/NVENC. The nvidia based setup's order is inconsistent with xrandr.

I've been having fun battling my streaming setup. My goal is a virtual KVM setup for my work laptop, where it's just a window on my personal workstation. Originally my laptop was set to "discrete graphics" in the BIOS, and sunshine would only do X11 with software encoding despite running the NVIDIA driver. I switched to "hybrid graphics", and then sunshine would do KMS/NVENC on the built-in display. I wanted higher resolution, though, so I got an HDMI EDID dummy plug and attached it to a dock. Sunshine would then only do X11/VAAPI on the external dummy display. Today I just found a driver patch to enable NVFBC, and now NVFBC/NVENC is working on my dummy external display.

As painful as it was to get working, the NVENC experience is buttery smooth with no CPU load.

sgtnoodle avatar Jun 05 '23 18:06 sgtnoodle

this issue remains. I have monitors in the following configuration:

image

and sunshine reports that they are numbered like this:

[2024:01:26:00:07:38]: Info: Detected monitor 0: DP-1, connected: true
[2024:01:26:00:07:38]: Info: Detected monitor 1: DP-2, connected: false
[2024:01:26:00:07:38]: Info: Detected monitor 2: HDMI-1, connected: true
[2024:01:26:00:07:38]: Info: Detected monitor 3: HDMI-2, connected: true

but this doesn't match the numbers I need to use in the sunshine config at all – there, the mapping is:

  • 0: HDMI-1
  • 1: HDMI-2
  • 2: DP-1

and xrandr --listmonitors produces an entirely different ordering again:

Monitors: 3
 0: +*HDMI-2 2560/597x1440/336+1920+1440  HDMI-2
 1: +DP-1 1920/527x1080/296+0+1440  DP-1
 2: +HDMI-1 2560/597x1440/336+1920+0  HDMI-1

I'm using NixOS 24.05.20240121.612f972 (Uakari) with X11.

sersorrel avatar Jan 26 '24 00:01 sersorrel

@sersorrel The monitor numbers come from different capture subsystems (X11 vs Wayland vs NvFBC vs KMS). The intent is for them to be the same but it is not always possible.

What capture method is being used on your system?

cgutman avatar Jan 26 '24 06:01 cgutman

KMS, I think.

sersorrel avatar Jan 27 '24 00:01 sersorrel

I have an issue where it only shows 2 monitors connected but there are 3.

The numbers are swapped around, and selecting 0 and 2 give the wrong monitor when connected. (It says that 0 is disconnected in Sunshine GUI, see code below)

And when I select monitor 1, 3, or 4, and connect from moonlight it displays all 3 displays in a zoomed out view. (See screenshot)

Running Ubuntu 22.04 LTS.

Monitors: 3
 0: +*DP-5 1920/598x1080/336+1920+0  DP-5
 1: +DP-1 1920/531x1080/299+3840+0  DP-1
 2: +HDMI-0 1920/1600x1080/900+0+0  HDMI-0
Info: Detecting connected monitors
            Info: Detected monitor 0: DVI-D-0, connected: false
            Info: Detected monitor 1: HDMI-0, connected: true
            Info: Detected monitor 2: DP-0, connected: true
            Info: Detected monitor 3: DP-1, connected: false
            Info: Detected monitor 4: DVI-D-1, connected: false

Screenshot_20240316-121631

KnoBuddy avatar Mar 16 '24 19:03 KnoBuddy

I have a laptop with intel+nvidia with an extra monitor. Using Kubuntu 22.04. Adapter name: /dev/dri/renderD129 Force NVENC Encoder.

$ xrandr --listmonitors
Monitors: 2
 0: +*eDP-1 1920/336x1200/210+0+0  eDP-1
 1: +DP-3 1920/480x1080/270+1920+0  DP-3

In Shunsine GUI:

Info: Detecting connected monitors
Info: Detected monitor 0: DVI-D-0, connected: false
Info: Detected monitor 1: HDMI-0, connected: true
Info: Detected monitor 2: DP-0, connected: true
Info: Detected monitor 3: DP-1, connected: false
Info: Detected monitor 4: DVI-D-1, connected: false

I can only see one screen, always the main one (that's the laptop panel) if I set the "Monitor number" field to empty or 0.

I was trying to cast the secondary screen only, but entering other value in the "Monitor number" field (1,2...) results in casting all displays in a zoomed out view, just like in @KnoBuddy comment.

PhiSYS avatar Apr 09 '24 16:04 PhiSYS

Regarding to my previous comment, I kept incrementing the index just for testing, and the second screen (only) was casted using index 4, which makes no sense to me.

PhiSYS avatar Apr 09 '24 17:04 PhiSYS