[confirm] Powersaving kicks in if videos run too long (1 Viewer)

Flaamwing

New Member
March 5, 2010
3
0
Windows power saving has turned off my monitors and TV while I'm in the middle of watching a video. I suggest, and have tested, the following patch. I ask that you please implement it or a variant to let windows know that something is happening, so it doesn't stop the system.

Thanks

Index: g_player.cs
===================================================================
--- g_player.cs (revision 25174)
+++ g_player.cs (working copy)
@@ -24,6 +24,7 @@
using System.Globalization;
using System.IO;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using MediaPortal.Configuration;
@@ -39,8 +40,27 @@
{
public class g_Player
{
+ [DllImport("Kernel32.DLL", CharSet = CharSet.Auto, SetLastError = true)]
+ private extern static EXECUTION_STATE SetThreadExecutionState(EXECUTION_STATE state);
+
#region enums

+ [FlagsAttribute]
+ public enum EXECUTION_STATE : uint
+ {
+ ES_SYSTEM_REQUIRED = 0x00000001,
+ ES_DISPLAY_REQUIRED = 0x00000002,
+ // Legacy flag, should not be used.
+ // ES_USER_PRESENT = 0x00000004,
+ ES_CONTINUOUS = 0x80000000,
+ }
+
+ public enum SPI : uint
+ {
+ SPI_GETPOWEROFFACTIVE = 0x0054,
+ SPI_SETPOWEROFFACTIVE = 0x0056
+ }
+
public enum MediaType
{
Video,
@@ -484,6 +504,7 @@
currentFileName = String.Empty;
_mediaInfo = null;
}
+ SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
}
}

@@ -499,6 +520,7 @@
RefreshRateChanger.AdaptRefreshRate();
currentFileName = String.Empty;
_mediaInfo = null;
+ SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS);
}
}

@@ -538,6 +560,13 @@
{
PlayBackStarted(_currentMedia, _currentFilePlaying);
}
+
+ // If we have Video of some sort
+ if(HasVideo || HasViz)
+ {
+ // Disable the screensaver/powersaving
+ SetThreadExecutionState(EXECUTION_STATE.ES_CONTINUOUS | EXECUTION_STATE.ES_SYSTEM_REQUIRED | EXECUTION_STATE.ES_DISPLAY_REQUIRED);
+ }
}
}




MediaPortal Version: 1.1 rc1
MediaPortal Skin: Blue Wide
Windows Version: 7
CPU Type: Intel i7
HDD: 2
Memory: 12 gb
Motherboard: dont remember
Video Card: nVidia
Video Card Driver: nVidia
Sound Card: built into motherboard
Sound Card AC3: no idea
Sound Card Driver: no idea
1. TV Card: none
1. TV Card Type:
1. TV Card Driver:
2. TV Card:
2. TV Card Type:
2. TV Card Driver:
3. TV Card:
3. TV Card Type:
3. TV Card Driver:
4. TV Card:
4. TV Card Type:
4. TV Card Driver:
MPEG2 Video Codec: ffmpg
MPEG2 Audio Codec: ffmpg
h.264 Video Codec: ffmpg
Satelite/CableTV Provider: none
HTPC Case:
Cooling: yes?
Power Supply: yes?
Remote: usbuirt
TV: none
TV - HTPC Connection: none
 

bugmenot

Portal Pro
January 13, 2007
130
2
have not tried this out yet with MP. But i had the problem with a friends app. (believe but havent checked that screen stays on in older versions)
but for win 7: SC_MONITORPOWER in Windows 7?

agree that SetThreadExecutionState() would be nice
 

Terra

Portal Pro
August 25, 2009
230
57
Home Country
Austria Austria
Maybe my problem is related to this. After watching a video, the monitor/beamer instantly looses the video signal at the end and goes into standby. A click on the remote brings the signal back but it's really annoying.
 

jameson_uk

Retired Team Member
  • Premium Supporter
  • January 27, 2005
    7,258
    2,528
    Birmingham
    Home Country
    United Kingdom United Kingdom
    I am not at home to check but IIRC the issue with that code is it will not work under XP (Win32 power code changed a lot between XP and Vista)

    Do you have the PowerScheduler plugin enabled? I think you need to have this enabled to prevent standby
     

    bugmenot

    Portal Pro
    January 13, 2007
    130
    2
    Maybe my problem is related to this. After watching a video, the monitor/beamer instantly looses the video signal at the end and goes into standby. A click on the remote brings the signal back but it's really annoying.
    That sounds like it keeps the screen away for the time Video is running, but the counter is not reset at the end so windows turns screen off.

    => sounds like a different problem. But i think with Flaamwings code it would be solved as well.

    with that code is it will not work under XP
    i disagree. would work for win 2000 and up
    Code:
    SetThreadExecutionState:
    Minimum supported client:	Windows 2000 Professional
     

    jameson_uk

    Retired Team Member
  • Premium Supporter
  • January 27, 2005
    7,258
    2,528
    Birmingham
    Home Country
    United Kingdom United Kingdom
    with that code is it will not work under XP
    i disagree. would work for win 2000 and up
    Code:
    SetThreadExecutionState:
    Minimum supported client:	Windows 2000 Professional

    I think it was more the integration into the Powerscheduler code which for XP still intercepts requests to standby and then tries to block them. I seem to recall getting some very odd unexpected results combining this (good code) with the XP powerscheduler code

    Also as I said above, I belive the MP design is for power to be controlled via PowerScheduler. I guess some peope might want it to time out and go to sleep if they fall asleep whilst watching TV (indeed I would imagine this code will break the plugin which acts as a sleep timer)
     

    infinite.loop

    Retired Team Member
  • Premium Supporter
  • December 26, 2004
    16,163
    4,133
    127.0.0.1
    Home Country
    Austria Austria
    Flaamwing

    Can you please post this in the "submit patches" section?
    That would be the right way to get patches evaluated by our devs. :)
     

    bobbyd87

    Portal Pro
    January 28, 2007
    61
    5
    Home Country
    United States of America United States of America
    Maybe my problem is related to this. After watching a video, the monitor/beamer instantly looses the video signal at the end and goes into standby. A click on the remote brings the signal back but it's really annoying.

    I have this issue as well. I have monitor blanking at 5 minutes. If i do not touch my keyboard/mouse for the last 5 or more minutes of a video, it will immediately blank when it is finished.
     

    Users who are viewing this thread

    Top Bottom