1 /*****************************************************************************
2 * intf.c: interface for DVD video manager
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: intf.c,v 1.5 2003/01/12 15:38:35 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 p_intf->p_sys->m_still_time = 0;
85 p_intf->p_sys->b_inf_still = 0;
86 p_intf->p_sys->b_still = 0;
91 /*****************************************************************************
92 * CloseIntf: destroy dummy interface
93 *****************************************************************************/
94 void E_(CloseIntf) ( vlc_object_t *p_this )
96 intf_thread_t *p_intf = (intf_thread_t *)p_this;
98 /* Destroy structure */
99 free( p_intf->p_sys );
103 /*****************************************************************************
105 *****************************************************************************/
106 static void RunIntf( intf_thread_t *p_intf )
108 vlc_object_t * p_vout = NULL;
112 if( InitThread( p_intf ) < 0 )
114 msg_Err( p_intf, "can't initialize intf" );
117 msg_Dbg( p_intf, "intf initialized" );
120 while( !p_intf->b_die )
122 vlc_mutex_lock( &p_intf->change_lock );
128 if( p_intf->p_sys->b_still && !p_intf->p_sys->b_inf_still )
130 if( p_intf->p_sys->m_still_time > 0 )
132 /* update remaining still time */
136 p_intf->p_sys->m_still_time -= mtime - mlast;
143 /* still time elasped */
144 input_SetStatus( p_intf->p_sys->p_input,
146 p_intf->p_sys->m_still_time = 0;
147 p_intf->p_sys->b_still = 0;
152 if( p_intf->p_sys->m_still_time != (mtime_t)(-1) )
154 if( p_intf->p_sys->m_still_time )
159 p_intf->p_sys->m_still_time -= mtime - mlast;
161 if( !p_intf->p_sys->m_still_time )
163 input_SetStatus( p_intf->p_sys->p_input,
175 if( p_vout && ( p_intf->p_sys->b_click || p_intf->p_sys->b_move ) )
180 var_Get( p_vout, "mouse-x", &val );
181 p_intf->p_sys->control.mouse.i_x = val.i_int;
182 var_Get( p_vout, "mouse-y", &val );
183 p_intf->p_sys->control.mouse.i_y = val.i_int;
185 if( p_intf->p_sys->b_click )
187 p_intf->p_sys->control.type = DVDCtrlMouseActivate;
188 p_intf->p_sys->b_click = VLC_FALSE;
192 p_intf->p_sys->control.type = DVDCtrlMouseSelect;
193 p_intf->p_sys->b_move = VLC_FALSE;
196 /* we can safely interact with libdvdplay
197 * with the stream lock */
198 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
200 i_activate = dvdplay_button( p_intf->p_sys->p_dvd->vmg,
201 &p_intf->p_sys->control );
203 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
205 if( i_activate && p_intf->p_sys->b_still )
207 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
208 p_intf->p_sys->b_still = 0;
209 p_intf->p_sys->b_inf_still = 0;
210 p_intf->p_sys->m_still_time = 0;
217 if( p_vout && p_intf->p_sys->b_key_pressed )
222 p_intf->p_sys->b_key_pressed = VLC_FALSE;
224 var_Get( p_vout, "key-pressed", &val );
225 if ( val.psz_string )
227 if( !strcmp( val.psz_string, "LEFT" ) )
229 p_intf->p_sys->control.type = DVDCtrlLeftButtonSelect;
231 else if( !strcmp( val.psz_string, "RIGHT" ) )
233 p_intf->p_sys->control.type = DVDCtrlRightButtonSelect;
235 else if( !strcmp( val.psz_string, "UP" ) )
237 p_intf->p_sys->control.type = DVDCtrlUpperButtonSelect;
239 else if( !strcmp( val.psz_string, "DOWN" ) )
241 p_intf->p_sys->control.type = DVDCtrlLowerButtonSelect;
243 else if( !strcmp( val.psz_string, "ENTER" ) )
245 p_intf->p_sys->control.type = DVDCtrlButtonActivate;
247 /* we can safely interact with libdvdplay
248 * with the stream lock */
249 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
251 i_activate = dvdplay_button( p_intf->p_sys->p_dvd->vmg,
252 &p_intf->p_sys->control );
254 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
256 if( i_activate && p_intf->p_sys->b_still )
258 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
259 p_intf->p_sys->b_still = 0;
260 p_intf->p_sys->b_inf_still = 0;
261 p_intf->p_sys->m_still_time = 0;
267 vlc_mutex_unlock( &p_intf->change_lock );
272 if( p_vout && p_vout->b_die )
274 var_DelCallback( p_vout, "mouse-moved", MouseEvent, p_intf );
275 var_DelCallback( p_vout, "mouse-clicked", MouseEvent, p_intf );
276 var_DelCallback( p_vout, "key-pressed", KeyEvent, p_intf );
277 vlc_object_release( p_vout );
283 p_vout = vlc_object_find( p_intf->p_sys->p_input,
284 VLC_OBJECT_VOUT, FIND_CHILD );
287 var_AddCallback( p_vout, "mouse-moved", MouseEvent, p_intf );
288 var_AddCallback( p_vout, "mouse-clicked", MouseEvent, p_intf );
289 var_AddCallback( p_vout, "key-pressed", KeyEvent, p_intf );
294 msleep( INTF_IDLE_SLEEP );
299 var_DelCallback( p_vout, "mouse-moved", MouseEvent, p_intf );
300 var_DelCallback( p_vout, "mouse-clicked", MouseEvent, p_intf );
301 var_DelCallback( p_vout, "key-pressed", KeyEvent, p_intf );
302 vlc_object_release( p_vout );
305 vlc_object_release( p_intf->p_sys->p_input );
308 /*****************************************************************************
310 *****************************************************************************/
311 static int InitThread( intf_thread_t * p_intf )
313 /* we might need some locking here */
316 input_thread_t * p_input;
319 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_PARENT );
320 p_dvd = (dvd_data_t*)p_input->p_access_data;
322 p_dvd->p_intf = p_intf;
324 vlc_mutex_lock( &p_intf->change_lock );
326 p_intf->p_sys->p_input = p_input;
327 p_intf->p_sys->p_dvd = p_dvd;
329 p_intf->p_sys->b_move = VLC_FALSE;
330 p_intf->p_sys->b_click = VLC_FALSE;
331 p_intf->p_sys->b_key_pressed = VLC_FALSE;
333 vlc_mutex_unlock( &p_intf->change_lock );
343 /*****************************************************************************
344 * MouseEvent: callback for mouse events
345 *****************************************************************************/
346 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
347 vlc_value_t oldval, vlc_value_t newval, void *p_data )
349 intf_thread_t *p_intf = (intf_thread_t *)p_data;
351 vlc_mutex_lock( &p_intf->change_lock );
353 if( psz_var[6] == 'c' ) /* "mouse-clicked" */
355 p_intf->p_sys->b_click = VLC_TRUE;
357 else if( psz_var[6] == 'm' ) /* "mouse-moved" */
359 p_intf->p_sys->b_move = VLC_TRUE;
362 vlc_mutex_unlock( &p_intf->change_lock );
367 /*****************************************************************************
368 * KeyEvent: callback for keyboard events
369 *****************************************************************************/
370 static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
371 vlc_value_t oldval, vlc_value_t newval, void *p_data )
373 intf_thread_t *p_intf = (intf_thread_t *)p_data;
374 vlc_mutex_lock( &p_intf->change_lock );
376 p_intf->p_sys->b_key_pressed = VLC_TRUE;
378 vlc_mutex_unlock( &p_intf->change_lock );
383 /*****************************************************************************
384 * dvdIntfStillTime: function provided to demux plugin to request
386 *****************************************************************************/
387 int dvdIntfStillTime( intf_thread_t *p_intf, int i_sec )
389 vlc_mutex_lock( &p_intf->change_lock );
394 p_intf->p_sys->b_still = 1;
395 p_intf->p_sys->b_inf_still = 1;
399 p_intf->p_sys->b_still = 1;
400 p_intf->p_sys->m_still_time = 1000000 * i_sec;
407 p_intf->p_sys->m_still_time = (mtime_t)(-1);
408 msg_Warn( p_intf, I64Fd, p_intf->p_sys->m_still_time );
412 p_intf->p_sys->m_still_time = 1000000 * i_sec;
416 vlc_mutex_unlock( &p_intf->change_lock );