3 * @brief Maemo screen unblanking for VLC media player
5 /*****************************************************************************
6 * Copyright © 2009 Rémi Denis-Courmont
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; either version 2.1
11 * of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU 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 02110-1301 USA
21 ****************************************************************************/
27 #include <vlc_common.h>
28 #include <vlc_plugin.h>
29 #include <vlc_inhibit.h>
33 static int Open (vlc_object_t *);
34 static void Close (vlc_object_t *);
40 set_shortname (N_("OSSO"))
41 set_description (N_("OSSO screen unblanking"))
42 set_category (CAT_ADVANCED)
43 set_subcategory (SUBCAT_ADVANCED_MISC)
44 set_capability ("inhibit", 20)
45 set_callbacks (Open, Close)
48 static void Inhibit (vlc_inhibit_t *, bool);
50 /* We keep a single context per process */
59 .lock = VLC_STATIC_MUTEX,
64 static void vlc_osso_unblank (void *dummy)
68 vlc_mutex_lock (&osso.lock);
69 osso_display_blanking_pause (osso.ctx);
70 vlc_mutex_unlock (&osso.lock);
73 #define BLANKING (NULL)
74 #define UNBLANKING ((vlc_inhibit_sys_t *)ih)
76 static int Open (vlc_object_t *obj)
78 vlc_inhibit_t *ih = (vlc_inhibit_t *)obj;
79 int ret = VLC_EGENERIC;
81 vlc_mutex_lock (&osso.lock);
84 if (vlc_timer_create (&osso.timer, vlc_osso_unblank, NULL))
87 osso.ctx = osso_initialize (PACKAGE, VERSION, 0, NULL);
90 vlc_timer_destroy (osso.timer);
94 msg_Dbg (obj, "initialized OSSO context");
98 vlc_mutex_unlock (&osso.lock);
100 ih->p_sys = BLANKING;
101 ih->inhibit = Inhibit;
105 static void Close (vlc_object_t *obj)
107 Inhibit ((vlc_inhibit_t *)obj, false);
109 vlc_mutex_lock (&osso.lock);
110 if (--osso.refs == 0)
112 msg_Dbg (obj, "deinitializing OSSO context");
113 vlc_timer_destroy (osso.timer);
114 osso_deinitialize (osso.ctx);
116 vlc_mutex_unlock (&osso.lock);
119 static void Inhibit (vlc_inhibit_t *ih, bool unblank)
121 if (unblank == (ih->p_sys != BLANKING))
122 return; /* already in right state */
124 vlc_mutex_lock (&osso.lock);
127 /* 10 seconds is the shortest blanking interval */
128 mtime_t start = (mdate() / CLOCK_FREQ + 8) * CLOCK_FREQ;
129 mtime_t interval = 9 * CLOCK_FREQ;
131 osso_display_state_on (osso.ctx);
132 if (osso.suspensions++ == 0) /* arm timer */
133 vlc_timer_schedule (osso.timer, true, start, interval);
134 ih->p_sys = UNBLANKING;
138 if (--osso.suspensions == 0) /* disarm timer */
139 vlc_timer_schedule (osso.timer, false, 0, 0);
140 ih->p_sys = BLANKING;
142 vlc_mutex_unlock (&osso.lock);