From 7d3f4f4434da68c430a55453ce387febdb69fb1e Mon Sep 17 00:00:00 2001 From: Johns Date: Thu, 8 Mar 2012 15:25:10 +0100 Subject: Disable and reenable screen saver and DPMS. --- ChangeLog | 1 + Todo | 2 - video.c | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 155 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 026b736..c6b1e2b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ User johns Date: + Disable and reenable screen saver and DPMS. Video source code cleanup. Fix fast backward with some h264 streams. Make soft start sync setup menu configurable. diff --git a/Todo b/Todo index c6aa762..1caf468 100644 --- a/Todo +++ b/Todo @@ -26,7 +26,6 @@ missing: Option deinterlace off / deinterlace force! ColorSpace aren't configurable with the gui. Replay of old vdr 1.6 recordings. - svdrp support for hot-keys. Remote learning support. restart vdr not working, when started x11 was killed. @@ -75,7 +74,6 @@ libva-vdpau-driver: libva-xvba-driver: x11: - disable screensaver skip multiple configure-notify, handle only the last one. support embedded mode diff --git a/video.c b/video.c index ad6ef4b..a7ffe87 100644 --- a/video.c +++ b/video.c @@ -37,6 +37,7 @@ /// #define USE_XLIB_XCB ///< use xlib/xcb backend +#define USE_SCREENSAVER ///< support disable screensaver #define USE_AUTOCROP ///< compile auto-crop support #define USE_GRAB ///< experimental grab code #define noUSE_GLX ///< outdated GLX code @@ -87,16 +88,18 @@ #include #include -#include -#include -#include -#include +//#include +//#include +//#include +#ifdef USE_SCREENSAVER #include -#include -#include +#include +#endif +//#include +//#include -#include -#include +//#include +//#include #include #include #ifdef XCB_ICCCM_NUM_WM_SIZE_HINTS_ELEMENTS @@ -116,7 +119,6 @@ typedef enum XCB_EWMH_WM_STATE_TOGGLE = 2 } xcb_ewmh_wm_state_action_t; #endif -#include #endif #ifdef USE_GLX @@ -8938,6 +8940,137 @@ uint8_t *VideoGrab(int *size, int *width, int *height, int write_header) return NULL; } +#ifdef USE_SCREENSAVER + +//---------------------------------------------------------------------------- +// DPMS / Screensaver +//---------------------------------------------------------------------------- + +static char DPMSDisabled; ///< flag we have disabled dpms + +/// +/// Suspend X11 screen saver. +/// +/// @param connection X11 connection to enable/disable screensaver +/// @param suspend True suspend screensaver, +/// false enable screensaver +/// +static void X11SuspendScreenSaver(xcb_connection_t * connection, int suspend) +{ + const xcb_query_extension_reply_t *query_extension_reply; + + query_extension_reply = + xcb_get_extension_data(connection, &xcb_screensaver_id); + if (query_extension_reply && query_extension_reply->present) { + xcb_screensaver_query_version_cookie_t cookie; + xcb_screensaver_query_version_reply_t *reply; + + Debug(3, "video: screen saver extension present\n"); + + cookie = + xcb_screensaver_query_version_unchecked(connection, + XCB_SCREENSAVER_MAJOR_VERSION, XCB_SCREENSAVER_MINOR_VERSION); + reply = xcb_screensaver_query_version_reply(connection, cookie, NULL); + if (reply + && (reply->server_major_version >= XCB_SCREENSAVER_MAJOR_VERSION) + && (reply->server_minor_version >= XCB_SCREENSAVER_MINOR_VERSION) + ) { + xcb_screensaver_suspend(connection, suspend); + } + free(reply); + } +} + +/// +/// DPMS (Display Power Management Signaling) extension available. +/// +/// @param connection X11 connection to check for DPMS +/// +static int X11HaveDPMS(xcb_connection_t * connection) +{ + static int have_dpms = -1; + const xcb_query_extension_reply_t *query_extension_reply; + + if (have_dpms != -1) { // already checked + return have_dpms; + } + + have_dpms = 0; + query_extension_reply = xcb_get_extension_data(connection, &xcb_dpms_id); + if (query_extension_reply && query_extension_reply->present) { + xcb_dpms_get_version_cookie_t cookie; + xcb_dpms_get_version_reply_t *reply; + int major; + int minor; + + Debug(3, "video: dpms extension present\n"); + + cookie = + xcb_dpms_get_version_unchecked(connection, XCB_DPMS_MAJOR_VERSION, + XCB_DPMS_MINOR_VERSION); + reply = xcb_dpms_get_version_reply(connection, cookie, NULL); + // use locals to avoid gcc warning + major = XCB_DPMS_MAJOR_VERSION; + minor = XCB_DPMS_MINOR_VERSION; + if (reply && (reply->server_major_version >= major) + && (reply->server_minor_version >= minor) + ) { + have_dpms = 1; + } + free(reply); + } + return have_dpms; +} + +/// +/// Disable DPMS (Display Power Management Signaling) +/// +/// @param connection X11 connection to disable DPMS +/// +static void X11DPMSDisable(xcb_connection_t * connection) +{ + if (X11HaveDPMS(connection)) { + xcb_dpms_info_cookie_t cookie; + xcb_dpms_info_reply_t *reply; + + cookie = xcb_dpms_info_unchecked(connection); + reply = xcb_dpms_info_reply(connection, cookie, NULL); + if (reply) { + if (reply->state) { + Debug(3, "video: dpms was enabled\n"); + DPMSDisabled = 1; + xcb_dpms_disable(connection); // monitor powersave off + } + free(reply); + } + } +} + +/// +/// Reenable DPMS (Display Power Management Signaling) +/// +/// @param connection X11 connection to enable DPMS +/// +static void X11DPMSReenable(xcb_connection_t * connection) +{ + if (DPMSDisabled && X11HaveDPMS(connection)) { + xcb_dpms_enable(connection); // monitor powersave on + xcb_dpms_force_level(connection, XCB_DPMS_DPMS_MODE_ON); + DPMSDisabled = 0; + } +} + +#else + + /// dummy function: Suspend X11 screen saver. +#define X11SuspendScreenSaver(connection, suspend) + /// dummy function: Disable X11 DPMS. +#define X11DPMSDisable(connection) + /// dummy function: Reenable X11 DPMS. +#define X11DPMSReenable(connection) + +#endif + //---------------------------------------------------------------------------- // Setup //---------------------------------------------------------------------------- @@ -9402,10 +9535,12 @@ void VideoInit(const char *display_name) } // prefetch extensions //xcb_prefetch_extension_data(Connection, &xcb_big_requests_id); - //xcb_prefetch_extension_data(Connection, &xcb_dpms_id); //xcb_prefetch_extension_data(Connection, &xcb_glx_id); //xcb_prefetch_extension_data(Connection, &xcb_randr_id); - //xcb_prefetch_extension_data(Connection, &xcb_screensaver_id); +#ifdef USE_SCREENSAVER + xcb_prefetch_extension_data(Connection, &xcb_screensaver_id); + xcb_prefetch_extension_data(Connection, &xcb_dpms_id); +#endif //xcb_prefetch_extension_data(Connection, &xcb_shm_id); //xcb_prefetch_extension_data(Connection, &xcb_xv_id); @@ -9488,6 +9623,10 @@ void VideoInit(const char *display_name) if (getenv("STUDIO_LEVELS")) { VideoStudioLevels = 1; } + // disable x11 screensaver + X11SuspendScreenSaver(Connection, 1); + X11DPMSDisable(Connection); + //xcb_prefetch_maximum_request_length(Connection); xcb_flush(Connection); @@ -9507,6 +9646,10 @@ void VideoExit(void) if (!XlibDisplay) { // no init or failed return; } + // reenable x11 screensaver + X11DPMSReenable(Connection); + X11SuspendScreenSaver(Connection, 0); + #ifdef USE_VIDEO_THREAD VideoThreadExit(); // VDPAU cleanup hangs in XLockDisplay every 100 exits -- cgit v1.2.3