Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolution swapping back to dummy plug config resolution mid stream. #44

Open
Rummyster opened this issue Aug 1, 2024 · 20 comments
Open

Comments

@Rummyster
Copy link

I'm using this with resolution automation and virtual display driver. Everything works as expected when starting the stream but eventually, it will revert back to the resolution set in the dummy plug config.
This seems to happen when my physical monitor wakes up and checks for a connection which happens around the 5 to 10 minute mark.

I've set the enableStrictRestoration in the json file to true but no luck.

@Nonary
Copy link
Owner

Nonary commented Aug 14, 2024

upload the logs

@KetchupBomb
Copy link

I was having a similar issue, but it happened seconds after the monitor swaps and resolution changes.

Logs from monitor swap
**********************
Windows PowerShell transcript start
Start time: 20240509001933
Username: AMBIDEX\Chase
RunAs User: AMBIDEX\Chase
Configuration Name: 
Machine: AMBIDEX (Microsoft Windows NT 10.0.22631.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 68864
PSVersion: 5.1.22621.2506
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.22621.2506
BuildVersion: 10.0.22621.2506
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is .\log.txt

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
--     ----            -------------   -----         -----------     --------             -------
1      SunshineScri... BackgroundJob   Running       True            localhost            ...
3      SunshineScri... BackgroundJob   Running       True            localhost            ...
Waiting for the next event to be called... (for starting/ending stream)
Processing event: Start
Stream started!
Processing event: SunshineScriptInstaller-Terminated
INFO: Stream has ended, now invoking code
INFO: Ending Stream!
INFO: This is an example of retrieving parameters in the future
**********************
Windows PowerShell transcript end
End time: 20240509002019
**********************
Logs from resolution automation
**********************
Windows PowerShell transcript start
Start time: 20240821000048
Username: STEIGER\kingm
RunAs User: STEIGER\kingm
Configuration Name: 
Machine: STEIGER (Microsoft Windows NT 10.0.22631.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File C:\Program Files\Github\Nonary\ResolutionAutomation\ResolutionMatcher.ps1 -async True
Process ID: 37312
PSVersion: 5.1.22621.3958
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.22621.3958
BuildVersion: 10.0.22621.3958
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is .\log.txt

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
--     ----            -------------   -----         -----------     --------             -------
1      ResolutionMa... BackgroundJob   Running       True            localhost            ...
3      ResolutionMa... BackgroundJob   Running       True            localhost            ...
Waiting for the next event to be called... (for starting/ending stream)
Processing event: Start End
Before Override: 2560 x 1600 x 60
After Override: 2560 x 1600 x 60
Setting screen resolution to 2560 x 1600 x 60
Resolution changed successfully.
Current Resolution: 1920 x 1080 x 60
Expected Requested Resolution: 2560 x 1600 x 60
Setting screen resolution to 2560 x 1600 x 60
Resolution changed successfully.
Current Resolution: 1920 x 1080 x 60
Expected Requested Resolution: 2560 x 1600 x 60
Setting screen resolution to 2560 x 1600 x 60
Resolution changed successfully.
Current Resolution: 1920 x 1080 x 60
Expected Requested Resolution: 2560 x 1600 x 60
Setting screen resolution to 2560 x 1600 x 60
Resolution changed successfully.
PS>TerminatingError(Remove-Event): "Cannot convert 'System.Object[]' to the type 'System.Int32' required by parameter 'EventIdentifier'. Specified method is not supported."
**********************
Windows PowerShell transcript end
End time: 20240821000056
**********************
primary.cfg
[Monitor0]
Name=\\.\DISPLAY1
MonitorID=MONITOR\DELA1E4\{4d36e96e-e325-11ce-bfc1-08002be10318}\0005
SerialNumber=
BitsPerPixel=32
Width=3440
Height=1440
DisplayFlags=0
DisplayFrequency=175
DisplayOrientation=0
PositionX=0
PositionY=0
[Monitor1]
Name=\\.\DISPLAY2
MonitorID=MONITOR\TSB8888\{4d36e96e-e325-11ce-bfc1-08002be10318}\0004
SerialNumber=
BitsPerPixel=0
Width=0
Height=0
DisplayFlags=0
DisplayFrequency=0
DisplayOrientation=0
PositionX=0
PositionY=0
[Monitor2]
Name=\\.\DISPLAY15
MonitorID=MONITOR\LNX0000\{4d36e96e-e325-11ce-bfc1-08002be10318}\0003
SerialNumber=
BitsPerPixel=0
Width=0
Height=0
DisplayFlags=0
DisplayFrequency=0
DisplayOrientation=0
PositionX=0
PositionY=0
dummy.cfg
[Monitor0]
Name=\\.\DISPLAY1
MonitorID=MONITOR\DELA1E4\{4d36e96e-e325-11ce-bfc1-08002be10318}\0005
SerialNumber=
BitsPerPixel=0
Width=0
Height=0
DisplayFlags=0
DisplayFrequency=0
DisplayOrientation=0
PositionX=0
PositionY=0
[Monitor1]
Name=\\.\DISPLAY2
MonitorID=MONITOR\TSB8888\{4d36e96e-e325-11ce-bfc1-08002be10318}\0004
SerialNumber=
BitsPerPixel=0
Width=0
Height=0
DisplayFlags=0
DisplayFrequency=0
DisplayOrientation=0
PositionX=0
PositionY=0
[Monitor2]
Name=\\.\DISPLAY15
MonitorID=MONITOR\LNX0000\{4d36e96e-e325-11ce-bfc1-08002be10318}\0003
SerialNumber=
BitsPerPixel=32
Width=1920
Height=1080
DisplayFlags=0
DisplayFrequency=60
DisplayOrientation=0
PositionX=0
PositionY=0
settings.json
{
    "debug": false,
    "startDelay": 4, // In order to prevent the Sunshine stream from freezing, this will wait 4 seconds before starting the next prep command in Sunshine. Feel free to reduce this number if you are not experiencing any issues.
    "gracePeriod": 900,
    "configSaveLocation": "%TEMP%",
    "dummyMonitorId": "MONITOR\\LNX0000\\{4d36e96e-e325-11ce-bfc1-08002be10318}\\0003", // Insert Monitor ID Here, don't forget to double slash to escape; e.g. "MONITOR\\XMD009A\\{4d36e96e-e325-11ce-bfc1-08002be10318}\\0010",
    "enableStrictRestoration": false, // If true, the script will adjust how it verifies the primary monitor is active, reducing false positives, but may cause issues on some setups.
    "installationOrderPreferences": {
        "enabled": true,
        // Set the order which the scripts are installed in, if the scripts are currently out of order, they will be reinstalled in the order specified here.
        // All of these scripts are optional and will not impact your experience if they are not installed.
        // However, I am shamelessly plugging in links to the scripts here, so you can easily find them.
        "scriptNames": [
            "MonitorSwapper", // https://github.com/Nonary/MonitorSwapAutomation/releases/latest  (Swaps the primary monitor to a dummy plug and then back when finished.)
            "ResolutionMatcher", // https://github.com/Nonary/ResolutionAutomation/releases/latest (Automatically sets the resolution to the same as the client streaming.)
            "AutoHDR", // https://github.com/Nonary/AutoHDRSwitch/releases/latest (Automatically enables HDR if the client is streaming HDR content.)
            "RTSSLimiter", // https://github.com/Nonary/RTSSLimiter/releases/latest (Limits the host framerate to the client's streaming framerate to reduce microstuttering)
            "PlayNiteWatcher" // https://github.com/Nonary/PlayniteWatcher/releases/latest (Export any game with the box art in Playnite to the Moonlight client. Enables automatic stream termination and ability to close games from Moonlight.)
        ]
    }
}

For me, the issue was that I git pulld for an update and must've missed any warnings about local changes being overridden by incoming changes. The dummy Monitor ID reset to what is committed into this repo by default. Perhaps the committed code could be zeroed out and have logic which logs the fact that the dummy Monitor ID is blank and that users need to specify one?

@KetchupBomb
Copy link

Ahh, haha. Right as I had finished writing and posting the above, the exact behavior @Rummyster mentioned occurred -- after about 5-10 minutes the dummy plug's original resolution was restored, and I think I caught a glimpse of an LED on my monitor having changed color as if it detected a video signal.

The resolution automation log has the same pattern, but is shorter
**********************
Windows PowerShell transcript start
Start time: 20240821002425
Username: STEIGER\kingm
RunAs User: STEIGER\kingm
Configuration Name: 
Machine: STEIGER (Microsoft Windows NT 10.0.22631.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File C:\Program Files\Github\Nonary\ResolutionAutomation\ResolutionMatcher.ps1 -async True
Process ID: 30508
PSVersion: 5.1.22621.3958
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.22621.3958
BuildVersion: 10.0.22621.3958
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is .\log.txt

Id     Name            PSJobTypeName   State         HasMoreData     Location             Command
--     ----            -------------   -----         -----------     --------             -------
1      ResolutionMa... BackgroundJob   Running       True            localhost            ...
3      ResolutionMa... BackgroundJob   Running       True            localhost            ...
Waiting for the next event to be called... (for starting/ending stream)
Processing event: Start End
Before Override: 2560 x 1600 x 60
After Override: 2560 x 1600 x 60
Setting screen resolution to 2560 x 1600 x 60
Resolution changed successfully.
Current Resolution: 1920 x 1080 x 60
Expected Requested Resolution: 2560 x 1600 x 60
Setting screen resolution to 2560 x 1600 x 60
Resolution changed successfully.
PS>TerminatingError(Remove-Event): "Cannot convert 'System.Object[]' to the type 'System.Int32' required by parameter 'EventIdentifier'. Specified method is not supported."
**********************
Windows PowerShell transcript end
End time: 20240821002433
**********************

@Nonary
Copy link
Owner

Nonary commented Aug 21, 2024

@KetchupBomb You uploaded my example log file instead of the one contained in logs folder on the monitor swapper one

@KetchupBomb
Copy link

Hmm. I don't have any other logs for monitor swapper. I am wondering if Windows permissions are getting in the way due to it being installed in C:\Program Files\. I can consider moving to an alternate directory.

However, I am suspicious of the resolution automation log line:

Processing event: Start End

The code that handles EventIdentifier is being handed "Start End" which doesn't have a case statement. 🤔

Write-Host "Processing event: $eventName"
if ($eventName -eq "Start") {
OnStreamStart
}
elseif ($eventName -eq "NewSession") {
Write-Host "A new session of this script has been started. To avoid conflicts, this session will now terminate. This is a normal process and not an error."
break;
}
elseif ($eventName -eq "GracePeriodExpired") {
Write-Host "Stream has been suspended beyond the defined grace period. We will now treat this as if you ended the stream. If this was unintentional or if you wish to extend the grace period, please adjust the grace period timeout in the settings.json file."
Wait-ForStreamEndJobToComplete
break;
}
else {
Wait-ForStreamEndJobToComplete
break;
}
Remove-Event -EventIdentifier $eventFired.EventIdentifier

Would a "Start End" event be caused by a monitor "coming online" if it detects a video signal?

@Rummyster
Copy link
Author

Rummyster commented Aug 21, 2024

I was also unable to get any new logs for this behavior. I moved the install folders around and reinstalled everything from scratch twice. Made sure everything was writable but still no logs.

I eventually just decided to manually change the dummy plug resolution to whatever I was streaming on so that when it resets it keeps the resolution. Not a great work around but it works.

Edit:
I do have a suspicion that windows is actually trying to turn my physical monitor back on. This may result in no logs being generated if monitorswap isn't at fault.

@Nonary
Copy link
Owner

Nonary commented Aug 21, 2024

The scripts won’t be able to generate logs if you moved it to program files because program files is write locked and the script by default doesn’t run elevated.

also, can you try the pre-release version of the resolution script to see if runs any better?

@KetchupBomb
Copy link

KetchupBomb commented Aug 22, 2024

What I've done:

  • While still installed to C:\Program Files\, I've ensured that un-elevated writes succeed.
  • Updated resolution automation to tag v3.0.
  • Uninstalled and reinstalled the three tools (monitor swap, resolution automation, HDR) in the proper order.

I continue to have the same behavior: after about 5-10 minutes of streaming just fine, the dummy resets to the default resolution. I have yet to 100% confirm that my monitor's LED changes ("wakes up") at the same time, but I am very suspicious they're related.

I have captured log files for a single Moonlight session during which this resetting occurred.

Monitor swap
**********************
Windows PowerShell transcript start
Start time: 20240821173441
Username: STEIGER\kingm
RunAs User: STEIGER\kingm
Configuration Name: 
Machine: STEIGER (Microsoft Windows NT 10.0.22631.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -Command & 'C:\Program Files\Github\Nonary\MonitorSwapAutomation\StreamMonitor.ps1' -scriptName MonitorSwapper -sib 1
Process ID: 3476
PSVersion: 5.1.22621.3958
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.22621.3958
BuildVersion: 10.0.22621.3958
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is .\logs\log_1724261682.txt
Waiting for the next event to be called... (for starting/ending stream)
Processing event: Start
Dummy plug activated
Processing event: Terminate
INFO: System.Collections.Hashtable
INFO: Stream has ended, now invoking code
INFO: Primary monitor(s) have been successfully restored!
**********************
Windows PowerShell transcript end
End time: 20240821174702
**********************
Resolution automation
**********************
Windows PowerShell transcript start
Start time: 20240821173446
Username: STEIGER\kingm
RunAs User: STEIGER\kingm
Configuration Name: 
Machine: STEIGER (Microsoft Windows NT 10.0.22631.0)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -Command & 'C:\Program Files\Github\Nonary\ResolutionAutomation\StreamMonitor.ps1' -scriptName ResolutionMatcher -sib 1
Process ID: 19784
PSVersion: 5.1.22621.3958
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.22621.3958
BuildVersion: 10.0.22621.3958
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is .\logs\log_2024_08_21_17_34_46.txt
Waiting for the next event to be called... (for starting/ending stream)
Processing event: Start
Before Overriding: 2560 x 1600 x 60
After Overriding: 2560 x 1600 x 60
Setting screen resolution to 2560 x 1600 x 60
Resolution changed successfully.
Processing event: ResolutionMatcher-Terminated
INFO: Stream has ended, now invoking code
INFO: Setting screen resolution to 1920 x 1080 x 60
INFO: Resolution changed successfully.
**********************
Windows PowerShell transcript end
End time: 20240821174654
**********************

A few comments about the logs:

  • Thoughts on removing and not committing logs to the repo? Do they serve a purpose by committing them?
  • Neither log seems to have any entry at the time when my monitor purportedly "wakes up".
  • Thoughts on adding timestamps to each line to see when things occur?

Thanks for your help, @Nonary. I still have some separate issues to raise, but your tools are slowly getting me to my preferred setup. 🙏

Is there a Discord or are Github issues the right way to go for communication like this?

@Nonary
Copy link
Owner

Nonary commented Aug 22, 2024

Both logs show that the stream ended after 12 minutes and somewhere between 8 and 20 seconds.

These events usually happen when the undo command is executed, which Sunshine often uses to end a stream.

The resolution matcher script is currently on the wrong branch. You should be using the 3.0 branch instead, as the script installer branch is outdated, though I haven’t deleted it yet.

The monitor swap log isn’t revealing much either. It triggered the terminate event, meaning the script closed because another session of the monitor swap script was started. However, this is a bug—it should notify you that it’s gracefully closing due to a new session. I'm working on fixing that now.

It's possible you might have duplicate installations, which could be causing them to cancel each other out after 5-10 minutes, but I'm not certain yet.

@Nonary
Copy link
Owner

Nonary commented Aug 22, 2024

Actually nevermind, there wasn't a bug there it is closing out properly on both script logs.

Are you saying you didnt end the stream after 12 minutes?

@Rummyster
Copy link
Author

I don't actually think anything is wrong woth the scripts. I'm almost 100% certain it is windows trying to re-enable the disabled monitor it detects. It can be seen lighting up at the same time the dummy plug config get re-enabled. It may be a Nvidia only thing as that's the type of gpu I have.

The only work around to this would be to write the resolution of the current display to the dummy plug at the start of a stream.

I have confirmed that manually changing the dummy plug to match my clients resolution even while streaming prevents this behavior.

@jacinpoz
Copy link

jacinpoz commented Sep 2, 2024

@Rummyster I have the same issue too on an AMD card just for the record. I have resorted to changing the dummy config manually for now even if it is not ideal.

@miles47
Copy link

miles47 commented Sep 8, 2024

Similar issue here. I am using this tool to disable all 3 of my monitors while streaming to my Steam Deck via Sunshine/Moonlight. It works for about 10 minutes then all of my monitors suddenly turn back on. Something is causing them to re enable I am just not quite sure what that is.

@vizzual123
Copy link

Same issue here, something causes my original monitor to detect a signal for a brief second, and the dummy monitors resolution changes

@KetchupBomb
Copy link

For what it's worth, I got a smart switch and put it on the outlet my monitor connects to. When I want to remote play, I just power off the monitor. That way it never sends a "heartbeat" check that messes with Windows swapping around primary monitors and what not. The smart switch hooks into Home Assistant, so when I begin remote play I can trigger all of this through automation. It's been working well.

@nbriffa
Copy link

nbriffa commented Nov 23, 2024

Having the same issue, except it only works for 15 seconds

@nbriffa
Copy link

nbriffa commented Nov 24, 2024

Tonight I spent some time playing around with the MultiMonitorTool commandline options executed as global do and undo commands in Sunshine. Enabling / Disabling the monitors individually worked, and my desktop monitors did not re-enable themselves. Simply loading the dummy / primary configs (as these scripts would) continuously ended in my monitors re-enabling themselves almost instantly.

@nbriffa
Copy link

nbriffa commented Nov 25, 2024

I can reliably solve this issue by setting the dummy / virtual monitor as the primary prior to loading the dummy config.

@Nonary
Copy link
Owner

Nonary commented Dec 13, 2024

Might be resolved in new version which no longer uses MultiMonitorTool

https://github.com/Nonary/MonitorSwapAutomation/releases/tag/v2.0.1

@KetchupBomb
Copy link

KetchupBomb commented Jan 10, 2025

I updated to v2.0.3 (latest as of writing) and the problems remains.

As I think we're all coming to realize, there are some monitors that seem to "heartbeat" some signal to the PC, even when the monitor is disabled in Windows. This heartbeat causes windows to not re-enable the display, but it does cause some reset action on the resolution being used in the swapped-to display(s).

One way to address this would be to have this MonitorSwapAutomation observe any events to the resolution caused to the swapped-to display(s) and, once detected, forcibly set it back to match the client that initially connected. I don't like this idea, though. Not only is it feature creep, but there are legitimately some use cases where manually changing the resolution after the client has connected is desirable.

The way I deal with my monitor's heartbeat is by using a smart plug. One of Sunshine's pre-script makes an API call to the smart plug to turn it off before the stream starts. With the monitor being off, no heartbeat occurs, and the resolution is stable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants