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

[REQ] Prevent automatic idle mode during active video playback #265

Open
neolorn opened this issue Jan 23, 2025 · 4 comments
Open

[REQ] Prevent automatic idle mode during active video playback #265

neolorn opened this issue Jan 23, 2025 · 4 comments

Comments

@neolorn
Copy link

neolorn commented Jan 23, 2025

Is your feature request related to a problem? Please describe.

When using automatic idle mode, TV will idle during active video playback in the foreground (e.g. watching a movie or a video that exceeds configured idle time).

Describe the solution you'd like

An option to prevent idle mode during active video playback in the foreground.

Describe alternatives you've considered

Get the processes requesting Video Wake Lock from powercfg (aka. "powercfg -requests" in PowerShell) check if any of it is in the foreground. If true, then disable automatic idle mode.

Additional context

I used IMFMediaSession API to get a list of processes requesting "Video Wake Lock".

@dechamps
Copy link
Contributor

The solution is to not use the idle mode feature. Instead, set your screen power off time out in the Windows power settings. LGTVCompanion notices when Windows attempts to turn off the screen and will send the corresponding signal to shut down the TV. The Windows screen timeout is smarter and will not trigger on full screen apps.

@JPersson77
Copy link
Owner

JPersson77 commented Jan 23, 2025

Hi thanks for the request! @dechamps is correct that the user idle mode is configured to be different than the mechanisms in windows. I e it was designed to always trigger in absence of user input (mouse, keyboard, controller) regardless of whatever logic was applied in windows to avoid situations where the PC inadvertently shows static HUD elements a full night, f e because someone fell asleep in front of the keyboard. Still the functionality was extended with user configurable whitelists and fullscreen detection on user request.

This request (detection of playing videos) has also been requested several times earlier, with some variations. Your suggestion is interesting @neolorn because you also hint at a practical solution. And incidentally I wonder if this or a similar method can potentially also solve an old issue where Valve's steam input does not trigger GetLastInputInfo() properly. I know that Steam, because of this, need to set SetThreadExecutionState() to prevent the PC shutting down mid-game. It seems possible to work a bit on this and investigate more

Edit: this reverse powercfg and illustrate how to enumerate the power request objects. Unfortunately it seem to require admin rights according to documentation. @neolorn can you detail your approach to using the IMFMediaSession API

@neolorn
Copy link
Author

neolorn commented Jan 24, 2025

Yes, it is true I can set screen off in power management instead of using the idle mode. But the problem is, I can't restrict the power management detection method to only video playback, meaning that any application using SetThreadExecutionState(ES_DISPLAY_REQUIRED) will also prevent display from turning off. And now that I think about it, IMFMediaSession isn't a reliable solution to detect video playback exclusively. Let me research further for a precise detection method in case you're interested.

Regarding PowerEnumerate, requiring admin privileges, there's no going around that. The only possible way I could poll requests from a user-mode app is through a signed driver.

As for the problem with steam controllers, AV flagging raw input detection can also be mitigated by a signed driver, but why not just use Steam Input API directly to detect inputs? Maybe then use Steamworks API to run detections only during gameplay sessions or big picture mode. Here's a simple method I tested:

#include <steam/steam_api.h>
#include <steam/isteaminput.h>
#include <iostream>
#include <thread>
#include <chrono>

bool InitializeSteamInput() {
    if (SteamAPI_Init()) {
        if (SteamInput()->Init(true)) {
            std::cout << "Steam Input initialized successfully.\n";
            return true;
        } else {
            std::cerr << "Failed to initialize Steam Input.\n";
        }
    } else {
        std::cerr << "Failed to initialize Steam API.\n";
    }
    return false;
}

bool CheckForInput() {
    InputHandle_t controllers[STEAM_INPUT_MAX_COUNT];
    int numControllers = SteamInput()->GetConnectedControllers(controllers);
    bool inputDetected = false;

    for (int i = 0; i < numControllers; ++i) {
        InputHandle_t controller = controllers[i];

        InputAnalogActionData_t analogData = SteamInput()->GetAnalogActionData(controller, 0);
        if (analogData.bActive && (analogData.x != 0.1f || analogData.y != 0.1f)) {
            inputDetected = true;
            break;
        }

        InputDigitalActionData_t digitalData = SteamInput()->GetDigitalActionData(controller, 0);
        if (digitalData.bActive && digitalData.bState) {
            inputDetected = true;
            break;
        }
    }

    return inputDetected;
}

int main() {
    if (!InitializeSteamInput()) {
        return -1;
    }

    while (true) {
        SteamInput()->RunFrame();

        if (CheckForInput()) {
            std::cout << "Keeping the display on.\n";
        }

        std::this_thread::sleep_for(std::chrono::milliseconds(10));
    }

    SteamInput()->Shutdown();
    SteamAPI_Shutdown();

    return 0;
}

@JPersson77
Copy link
Owner

Yes I'd be interested in the findings. Not having to use admin rights is definitely preferrable.

Thanks also for the steam input boilerplate code. Was meaning to look into if your suggestion was feasible so I'll have a look starting with this

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

3 participants