1 /*****************************************************************************
2 * intf.c: interface for DVD video manager
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: intf.c,v 1.8 2003/10/26 13:10:05 sigmunau Exp $
7 * Authors: Stéphane Borel <stef@via.ecp.fr>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
22 *****************************************************************************/
24 /*****************************************************************************
26 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
34 #include "stream_control.h"
35 #include "input_ext-intf.h"
36 #include "input_ext-dec.h"
40 /*****************************************************************************
41 * intf_sys_t: description and status of interface
42 *****************************************************************************/
45 input_thread_t * p_input;
49 vlc_bool_t b_inf_still;
52 dvdplay_ctrl_t control;
53 vlc_bool_t b_click, b_move, b_key_pressed;
56 /*****************************************************************************
58 *****************************************************************************/
59 static int InitThread ( intf_thread_t *p_intf );
60 static int MouseEvent ( vlc_object_t *, char const *,
61 vlc_value_t, vlc_value_t, void * );
62 static int KeyEvent ( vlc_object_t *, char const *,
63 vlc_value_t, vlc_value_t, void * );
65 /* Exported functions */
66 static void RunIntf ( intf_thread_t *p_intf );
68 /*****************************************************************************
69 * OpenIntf: initialize dummy interface
70 *****************************************************************************/
71 int E_(OpenIntf) ( vlc_object_t *p_this )
73 intf_thread_t *p_intf = (intf_thread_t *)p_this;
75 /* Allocate instance and initialize some members */
76 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
77 if( p_intf->p_sys == NULL )
82 p_intf->pf_run = RunIntf;
84 var_AddCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
85 p_intf->p_sys->m_still_time = 0;
86 p_intf->p_sys->b_inf_still = 0;
87 p_intf->p_sys->b_still = 0;
92 /*****************************************************************************
93 * CloseIntf: destroy dummy interface
94 *****************************************************************************/
95 void E_(CloseIntf) ( vlc_object_t *p_this )
97 intf_thread_t *p_intf = (intf_thread_t *)p_this;
98 var_DelCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
99 /* Destroy structure */
100 free( p_intf->p_sys );
104 /*****************************************************************************
106 *****************************************************************************/
107 static void RunIntf( intf_thread_t *p_intf )
109 vlc_object_t * p_vout = NULL;
112 int i_nav_up = config_GetInt( p_intf, "nav-up-key" );
113 int i_nav_down = config_GetInt( p_intf, "nav-down-key" );
114 int i_nav_left = config_GetInt( p_intf, "nav-left-key" );
115 int i_nav_right = config_GetInt( p_intf, "nav-right-key" );
116 int i_nav_activate = config_GetInt( p_intf, "nav-activate-key" );
118 if( InitThread( p_intf ) < 0 )
120 msg_Err( p_intf, "can't initialize intf" );
123 msg_Dbg( p_intf, "intf initialized" );
126 while( !p_intf->b_die )
128 vlc_mutex_lock( &p_intf->change_lock );
134 if( p_intf->p_sys->b_still && !p_intf->p_sys->b_inf_still )
136 if( p_intf->p_sys->m_still_time > 0 )
138 /* update remaining still time */
142 p_intf->p_sys->m_still_time -= mtime - mlast;
149 /* still time elasped */
150 input_SetStatus( p_intf->p_sys->p_input,
152 p_intf->p_sys->m_still_time = 0;
153 p_intf->p_sys->b_still = 0;
158 if( p_intf->p_sys->m_still_time != (mtime_t)(-1) )
160 if( p_intf->p_sys->m_still_time )
165 p_intf->p_sys->m_still_time -= mtime - mlast;
167 if( !p_intf->p_sys->m_still_time )
169 input_SetStatus( p_intf->p_sys->p_input,
181 if( p_vout && ( p_intf->p_sys->b_click || p_intf->p_sys->b_move ) )
186 var_Get( p_vout, "mouse-x", &val );
187 p_intf->p_sys->control.mouse.i_x = val.i_int;
188 var_Get( p_vout, "mouse-y", &val );
189 p_intf->p_sys->control.mouse.i_y = val.i_int;
191 if( p_intf->p_sys->b_click )
193 p_intf->p_sys->control.type = DVDCtrlMouseActivate;
194 p_intf->p_sys->b_click = VLC_FALSE;
198 p_intf->p_sys->control.type = DVDCtrlMouseSelect;
199 p_intf->p_sys->b_move = VLC_FALSE;
202 /* we can safely interact with libdvdplay
203 * with the stream lock */
204 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
206 i_activate = dvdplay_button( p_intf->p_sys->p_dvd->vmg,
207 &p_intf->p_sys->control );
209 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
211 if( i_activate && p_intf->p_sys->b_still )
213 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
214 p_intf->p_sys->b_still = 0;
215 p_intf->p_sys->b_inf_still = 0;
216 p_intf->p_sys->m_still_time = 0;
223 if( p_intf->p_sys->b_key_pressed )
228 p_intf->p_sys->b_key_pressed = VLC_FALSE;
230 var_Get( p_intf->p_vlc, "key-pressed", &val );
233 if( val.i_int == i_nav_left )
235 p_intf->p_sys->control.type = DVDCtrlLeftButtonSelect;
237 else if( val.i_int == i_nav_right )
239 p_intf->p_sys->control.type = DVDCtrlRightButtonSelect;
241 else if( val.i_int == i_nav_up )
243 p_intf->p_sys->control.type = DVDCtrlUpperButtonSelect;
245 else if( val.i_int == i_nav_down )
247 p_intf->p_sys->control.type = DVDCtrlLowerButtonSelect;
249 else if( val.i_int == i_nav_activate )
251 p_intf->p_sys->control.type = DVDCtrlButtonActivate;
253 /* we can safely interact with libdvdplay
254 * with the stream lock */
255 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
257 i_activate = dvdplay_button( p_intf->p_sys->p_dvd->vmg,
258 &p_intf->p_sys->control );
260 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
262 if( i_activate && p_intf->p_sys->b_still )
264 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
265 p_intf->p_sys->b_still = 0;
266 p_intf->p_sys->b_inf_still = 0;
267 p_intf->p_sys->m_still_time = 0;
273 vlc_mutex_unlock( &p_intf->change_lock );
278 if( p_vout && p_vout->b_die )
280 var_DelCallback( p_vout, "mouse-moved", MouseEvent, p_intf );
281 var_DelCallback( p_vout, "mouse-clicked", MouseEvent, p_intf );
282 vlc_object_release( p_vout );
288 p_vout = vlc_object_find( p_intf->p_sys->p_input,
289 VLC_OBJECT_VOUT, FIND_CHILD );
292 var_AddCallback( p_vout, "mouse-moved", MouseEvent, p_intf );
293 var_AddCallback( p_vout, "mouse-clicked", MouseEvent, p_intf );
298 msleep( INTF_IDLE_SLEEP );
303 var_DelCallback( p_vout, "mouse-moved", MouseEvent, p_intf );
304 var_DelCallback( p_vout, "mouse-clicked", MouseEvent, p_intf );
305 vlc_object_release( p_vout );
308 vlc_object_release( p_intf->p_sys->p_input );
311 /*****************************************************************************
313 *****************************************************************************/
314 static int InitThread( intf_thread_t * p_intf )
316 /* We might need some locking here */
319 input_thread_t * p_input;
322 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_PARENT );
324 /* Maybe the input just died */
325 if( p_input == NULL )
330 p_dvd = (dvd_data_t*)p_input->p_access_data;
331 p_dvd->p_intf = p_intf;
333 vlc_mutex_lock( &p_intf->change_lock );
335 p_intf->p_sys->p_input = p_input;
336 p_intf->p_sys->p_dvd = p_dvd;
338 p_intf->p_sys->b_move = VLC_FALSE;
339 p_intf->p_sys->b_click = VLC_FALSE;
340 p_intf->p_sys->b_key_pressed = VLC_FALSE;
342 vlc_mutex_unlock( &p_intf->change_lock );
352 /*****************************************************************************
353 * MouseEvent: callback for mouse events
354 *****************************************************************************/
355 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
356 vlc_value_t oldval, vlc_value_t newval, void *p_data )
358 intf_thread_t *p_intf = (intf_thread_t *)p_data;
360 vlc_mutex_lock( &p_intf->change_lock );
362 if( psz_var[6] == 'c' ) /* "mouse-clicked" */
364 p_intf->p_sys->b_click = VLC_TRUE;
366 else if( psz_var[6] == 'm' ) /* "mouse-moved" */
368 p_intf->p_sys->b_move = VLC_TRUE;
371 vlc_mutex_unlock( &p_intf->change_lock );
376 /*****************************************************************************
377 * KeyEvent: callback for keyboard events
378 *****************************************************************************/
379 static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
380 vlc_value_t oldval, vlc_value_t newval, void *p_data )
382 intf_thread_t *p_intf = (intf_thread_t *)p_data;
383 vlc_mutex_lock( &p_intf->change_lock );
385 p_intf->p_sys->b_key_pressed = VLC_TRUE;
387 vlc_mutex_unlock( &p_intf->change_lock );
392 /*****************************************************************************
393 * dvdIntfStillTime: function provided to demux plugin to request
395 *****************************************************************************/
396 int dvdIntfStillTime( intf_thread_t *p_intf, int i_sec )
398 vlc_mutex_lock( &p_intf->change_lock );
403 p_intf->p_sys->b_still = 1;
404 p_intf->p_sys->b_inf_still = 1;
408 p_intf->p_sys->b_still = 1;
409 p_intf->p_sys->m_still_time = 1000000 * i_sec;
416 p_intf->p_sys->m_still_time = (mtime_t)(-1);
417 msg_Warn( p_intf, I64Fd, p_intf->p_sys->m_still_time );
421 p_intf->p_sys->m_still_time = 1000000 * i_sec;
425 vlc_mutex_unlock( &p_intf->change_lock );
430 /*****************************************************************************
431 * dvdIntfStillTime: function provided to reset still image
432 *****************************************************************************/
433 int dvdIntfResetStillTime( intf_thread_t *p_intf )
435 vlc_mutex_lock( &p_intf->change_lock );
436 p_intf->p_sys->m_still_time = 0;
437 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
438 vlc_mutex_unlock( &p_intf->change_lock );