2 * This file is a part of MAFW
4 * Copyright (C) 2007, 2008, 2009 Nokia Corporation, all rights reserved.
6 * Contact: Visa Smolander <visa.smolander@nokia.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; version 2.1 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
33 #define G_LOG_DOMAIN "mafw-gst-renderer-blanking"
36 #define VIDEO_BLANKING_TIMER_INTERVAL 45
38 static guint blanking_timeout_id = 0;
39 static osso_context_t *osso_ctx = NULL;
40 static gboolean can_control_blanking = TRUE;
41 static gboolean is_blanking_prohibited = FALSE;
43 static void remove_blanking_timeout(void)
45 if (blanking_timeout_id) {
46 g_source_remove(blanking_timeout_id);
47 blanking_timeout_id = 0;
52 * Re-enables screen blanking.
54 void blanking_allow(void)
56 is_blanking_prohibited = FALSE;
57 remove_blanking_timeout();
60 static gboolean no_blanking_timeout(void)
62 /* Stop trying if it fails. */
63 return osso_display_blanking_pause(osso_ctx) == OSSO_OK;
67 * Adds a timeout to periodically disable screen blanking.
69 void blanking_prohibit(void)
71 is_blanking_prohibited = TRUE;
72 if ((!osso_ctx) || (!can_control_blanking))
74 osso_display_state_on(osso_ctx);
75 osso_display_blanking_pause(osso_ctx);
76 if (blanking_timeout_id == 0) {
78 g_timeout_add_seconds(VIDEO_BLANKING_TIMER_INTERVAL,
79 (gpointer)no_blanking_timeout,
84 void blanking_init(void)
86 /* It's enough to initialize it once for a process. */
89 osso_ctx = osso_initialize(PACKAGE, VERSION, 0, NULL);
91 g_warning("osso_initialize failed, screen may go black");
92 is_blanking_prohibited = FALSE;
93 /* Default policy is to allow user to control blanking */
94 blanking_control(TRUE);
97 void blanking_deinit(void)
101 blanking_control(FALSE);
102 osso_deinitialize(osso_ctx);
106 void blanking_control(gboolean activate)
108 can_control_blanking = activate;
109 if (!can_control_blanking) {
110 remove_blanking_timeout();
112 /* Restore the last state */
113 if (is_blanking_prohibited) {