1 /*****************************************************************************
2 * intf.c: interface for DVD video manager
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: intf.c,v 1.9 2003/10/29 01:33:27 gbazin 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"
42 /*****************************************************************************
43 * intf_sys_t: description and status of interface
44 *****************************************************************************/
47 input_thread_t * p_input;
51 vlc_bool_t b_inf_still;
54 dvdplay_ctrl_t control;
55 vlc_bool_t b_click, b_move, b_key_pressed;
58 /*****************************************************************************
60 *****************************************************************************/
61 static int InitThread ( intf_thread_t *p_intf );
62 static int MouseEvent ( vlc_object_t *, char const *,
63 vlc_value_t, vlc_value_t, void * );
64 static int KeyEvent ( vlc_object_t *, char const *,
65 vlc_value_t, vlc_value_t, void * );
67 /* Exported functions */
68 static void RunIntf ( intf_thread_t *p_intf );
70 /*****************************************************************************
71 * OpenIntf: initialize dummy interface
72 *****************************************************************************/
73 int E_(OpenIntf) ( vlc_object_t *p_this )
75 intf_thread_t *p_intf = (intf_thread_t *)p_this;
77 /* Allocate instance and initialize some members */
78 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
79 if( p_intf->p_sys == NULL )
84 p_intf->pf_run = RunIntf;
86 var_AddCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
87 p_intf->p_sys->m_still_time = 0;
88 p_intf->p_sys->b_inf_still = 0;
89 p_intf->p_sys->b_still = 0;
94 /*****************************************************************************
95 * CloseIntf: destroy dummy interface
96 *****************************************************************************/
97 void E_(CloseIntf) ( vlc_object_t *p_this )
99 intf_thread_t *p_intf = (intf_thread_t *)p_this;
100 var_DelCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
101 /* Destroy structure */
102 free( p_intf->p_sys );
106 /*****************************************************************************
108 *****************************************************************************/
109 static void RunIntf( intf_thread_t *p_intf )
111 vlc_object_t * p_vout = NULL;
115 if( InitThread( p_intf ) < 0 )
117 msg_Err( p_intf, "can't initialize intf" );
120 msg_Dbg( p_intf, "intf initialized" );
123 while( !p_intf->b_die )
125 vlc_mutex_lock( &p_intf->change_lock );
131 if( p_intf->p_sys->b_still && !p_intf->p_sys->b_inf_still )
133 if( p_intf->p_sys->m_still_time > 0 )
135 /* update remaining still time */
139 p_intf->p_sys->m_still_time -= mtime - mlast;
146 /* still time elasped */
147 input_SetStatus( p_intf->p_sys->p_input,
149 p_intf->p_sys->m_still_time = 0;
150 p_intf->p_sys->b_still = 0;
155 if( p_intf->p_sys->m_still_time != (mtime_t)(-1) )
157 if( p_intf->p_sys->m_still_time )
162 p_intf->p_sys->m_still_time -= mtime - mlast;
164 if( !p_intf->p_sys->m_still_time )
166 input_SetStatus( p_intf->p_sys->p_input,
178 if( p_vout && ( p_intf->p_sys->b_click || p_intf->p_sys->b_move ) )
183 var_Get( p_vout, "mouse-x", &val );
184 p_intf->p_sys->control.mouse.i_x = val.i_int;
185 var_Get( p_vout, "mouse-y", &val );
186 p_intf->p_sys->control.mouse.i_y = val.i_int;
188 if( p_intf->p_sys->b_click )
190 p_intf->p_sys->control.type = DVDCtrlMouseActivate;
191 p_intf->p_sys->b_click = VLC_FALSE;
195 p_intf->p_sys->control.type = DVDCtrlMouseSelect;
196 p_intf->p_sys->b_move = VLC_FALSE;
199 /* we can safely interact with libdvdplay
200 * with the stream lock */
201 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
203 i_activate = dvdplay_button( p_intf->p_sys->p_dvd->vmg,
204 &p_intf->p_sys->control );
206 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
208 if( i_activate && p_intf->p_sys->b_still )
210 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
211 p_intf->p_sys->b_still = 0;
212 p_intf->p_sys->b_inf_still = 0;
213 p_intf->p_sys->m_still_time = 0;
220 if( p_intf->p_sys->b_key_pressed )
223 int i, i_activate, i_action = -1;
224 struct hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
226 p_intf->p_sys->b_key_pressed = VLC_FALSE;
228 /* Find action triggered by hotkey (if any) */
229 var_Get( p_intf->p_vlc, "key-pressed", &val );
230 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
232 if( p_hotkeys[i].i_key == val.i_int )
234 i_action = p_hotkeys[i].i_action;
240 if( i_action == ACTIONID_NAV_LEFT )
242 p_intf->p_sys->control.type = DVDCtrlLeftButtonSelect;
244 else if( i_action == ACTIONID_NAV_RIGHT )
246 p_intf->p_sys->control.type = DVDCtrlRightButtonSelect;
248 else if( i_action == ACTIONID_NAV_UP )
250 p_intf->p_sys->control.type = DVDCtrlUpperButtonSelect;
252 else if( i_action == ACTIONID_NAV_DOWN )
254 p_intf->p_sys->control.type = DVDCtrlLowerButtonSelect;
256 else if( i_action == ACTIONID_NAV_ACTIVATE )
258 p_intf->p_sys->control.type = DVDCtrlButtonActivate;
260 /* we can safely interact with libdvdplay
261 * with the stream lock */
262 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
264 i_activate = dvdplay_button( p_intf->p_sys->p_dvd->vmg,
265 &p_intf->p_sys->control );
267 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
269 if( i_activate && p_intf->p_sys->b_still )
271 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
272 p_intf->p_sys->b_still = 0;
273 p_intf->p_sys->b_inf_still = 0;
274 p_intf->p_sys->m_still_time = 0;
280 vlc_mutex_unlock( &p_intf->change_lock );
285 if( p_vout && p_vout->b_die )
287 var_DelCallback( p_vout, "mouse-moved", MouseEvent, p_intf );
288 var_DelCallback( p_vout, "mouse-clicked", MouseEvent, p_intf );
289 vlc_object_release( p_vout );
295 p_vout = vlc_object_find( p_intf->p_sys->p_input,
296 VLC_OBJECT_VOUT, FIND_CHILD );
299 var_AddCallback( p_vout, "mouse-moved", MouseEvent, p_intf );
300 var_AddCallback( p_vout, "mouse-clicked", MouseEvent, p_intf );
305 msleep( INTF_IDLE_SLEEP );
310 var_DelCallback( p_vout, "mouse-moved", MouseEvent, p_intf );
311 var_DelCallback( p_vout, "mouse-clicked", MouseEvent, p_intf );
312 vlc_object_release( p_vout );
315 vlc_object_release( p_intf->p_sys->p_input );
318 /*****************************************************************************
320 *****************************************************************************/
321 static int InitThread( intf_thread_t * p_intf )
323 /* We might need some locking here */
326 input_thread_t * p_input;
329 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_PARENT );
331 /* Maybe the input just died */
332 if( p_input == NULL )
337 p_dvd = (dvd_data_t*)p_input->p_access_data;
338 p_dvd->p_intf = p_intf;
340 vlc_mutex_lock( &p_intf->change_lock );
342 p_intf->p_sys->p_input = p_input;
343 p_intf->p_sys->p_dvd = p_dvd;
345 p_intf->p_sys->b_move = VLC_FALSE;
346 p_intf->p_sys->b_click = VLC_FALSE;
347 p_intf->p_sys->b_key_pressed = VLC_FALSE;
349 vlc_mutex_unlock( &p_intf->change_lock );
359 /*****************************************************************************
360 * MouseEvent: callback for mouse events
361 *****************************************************************************/
362 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
363 vlc_value_t oldval, vlc_value_t newval, void *p_data )
365 intf_thread_t *p_intf = (intf_thread_t *)p_data;
367 vlc_mutex_lock( &p_intf->change_lock );
369 if( psz_var[6] == 'c' ) /* "mouse-clicked" */
371 p_intf->p_sys->b_click = VLC_TRUE;
373 else if( psz_var[6] == 'm' ) /* "mouse-moved" */
375 p_intf->p_sys->b_move = VLC_TRUE;
378 vlc_mutex_unlock( &p_intf->change_lock );
383 /*****************************************************************************
384 * KeyEvent: callback for keyboard events
385 *****************************************************************************/
386 static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
387 vlc_value_t oldval, vlc_value_t newval, void *p_data )
389 intf_thread_t *p_intf = (intf_thread_t *)p_data;
390 vlc_mutex_lock( &p_intf->change_lock );
392 p_intf->p_sys->b_key_pressed = VLC_TRUE;
394 vlc_mutex_unlock( &p_intf->change_lock );
399 /*****************************************************************************
400 * dvdIntfStillTime: function provided to demux plugin to request
402 *****************************************************************************/
403 int dvdIntfStillTime( intf_thread_t *p_intf, int i_sec )
405 vlc_mutex_lock( &p_intf->change_lock );
410 p_intf->p_sys->b_still = 1;
411 p_intf->p_sys->b_inf_still = 1;
415 p_intf->p_sys->b_still = 1;
416 p_intf->p_sys->m_still_time = 1000000 * i_sec;
423 p_intf->p_sys->m_still_time = (mtime_t)(-1);
424 msg_Warn( p_intf, I64Fd, p_intf->p_sys->m_still_time );
428 p_intf->p_sys->m_still_time = 1000000 * i_sec;
432 vlc_mutex_unlock( &p_intf->change_lock );
437 /*****************************************************************************
438 * dvdIntfStillTime: function provided to reset still image
439 *****************************************************************************/
440 int dvdIntfResetStillTime( intf_thread_t *p_intf )
442 vlc_mutex_lock( &p_intf->change_lock );
443 p_intf->p_sys->m_still_time = 0;
444 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
445 vlc_mutex_unlock( &p_intf->change_lock );