1 /*****************************************************************************
2 * intf.c: interface for DVD video manager
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: intf.c,v 1.4 2002/11/08 10:26:52 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"
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;
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 * );
63 /* Exported functions */
64 static void RunIntf ( intf_thread_t *p_intf );
66 /*****************************************************************************
67 * OpenIntf: initialize dummy interface
68 *****************************************************************************/
69 int E_(OpenIntf) ( vlc_object_t *p_this )
71 intf_thread_t *p_intf = (intf_thread_t *)p_this;
73 /* Allocate instance and initialize some members */
74 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
75 if( p_intf->p_sys == NULL )
80 p_intf->pf_run = RunIntf;
82 p_intf->p_sys->m_still_time = 0;
83 p_intf->p_sys->b_inf_still = 0;
84 p_intf->p_sys->b_still = 0;
89 /*****************************************************************************
90 * CloseIntf: destroy dummy interface
91 *****************************************************************************/
92 void E_(CloseIntf) ( vlc_object_t *p_this )
94 intf_thread_t *p_intf = (intf_thread_t *)p_this;
96 /* Destroy structure */
97 free( p_intf->p_sys );
101 /*****************************************************************************
103 *****************************************************************************/
104 static void RunIntf( intf_thread_t *p_intf )
106 vlc_object_t * p_vout = NULL;
110 if( InitThread( p_intf ) < 0 )
112 msg_Err( p_intf, "can't initialize intf" );
115 msg_Dbg( p_intf, "intf initialized" );
118 while( !p_intf->b_die )
120 vlc_mutex_lock( &p_intf->change_lock );
126 if( p_intf->p_sys->b_still && !p_intf->p_sys->b_inf_still )
128 if( p_intf->p_sys->m_still_time > 0 )
130 /* update remaining still time */
134 p_intf->p_sys->m_still_time -= mtime - mlast;
141 /* still time elasped */
142 input_SetStatus( p_intf->p_sys->p_input,
144 p_intf->p_sys->m_still_time = 0;
145 p_intf->p_sys->b_still = 0;
150 if( p_intf->p_sys->m_still_time != (mtime_t)(-1) )
152 if( p_intf->p_sys->m_still_time )
157 p_intf->p_sys->m_still_time -= mtime - mlast;
159 if( !p_intf->p_sys->m_still_time )
161 input_SetStatus( p_intf->p_sys->p_input,
173 if( p_vout && ( p_intf->p_sys->b_click || p_intf->p_sys->b_move ) )
178 var_Get( p_vout, "mouse-x", &val );
179 p_intf->p_sys->control.mouse.i_x = val.i_int;
180 var_Get( p_vout, "mouse-y", &val );
181 p_intf->p_sys->control.mouse.i_y = val.i_int;
183 if( p_intf->p_sys->b_click )
185 p_intf->p_sys->control.type = DVDCtrlMouseActivate;
186 p_intf->p_sys->b_click = VLC_FALSE;
190 p_intf->p_sys->control.type = DVDCtrlMouseSelect;
191 p_intf->p_sys->b_move = VLC_FALSE;
194 /* we can safely interact with libdvdplay
195 * with the stream lock */
196 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
198 i_activate = dvdplay_button( p_intf->p_sys->p_dvd->vmg,
199 &p_intf->p_sys->control );
201 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
203 if( i_activate && p_intf->p_sys->b_still )
205 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
206 p_intf->p_sys->b_still = 0;
207 p_intf->p_sys->b_inf_still = 0;
208 p_intf->p_sys->m_still_time = 0;
212 vlc_mutex_unlock( &p_intf->change_lock );
217 if( p_vout && p_vout->b_die )
219 var_DelCallback( p_vout, "mouse-moved", MouseEvent, p_intf );
220 var_DelCallback( p_vout, "mouse-clicked", MouseEvent, p_intf );
221 vlc_object_release( p_vout );
227 p_vout = vlc_object_find( p_intf->p_sys->p_input,
228 VLC_OBJECT_VOUT, FIND_CHILD );
231 var_AddCallback( p_vout, "mouse-moved", MouseEvent, p_intf );
232 var_AddCallback( p_vout, "mouse-clicked", MouseEvent, p_intf );
237 msleep( INTF_IDLE_SLEEP );
242 var_DelCallback( p_vout, "mouse-moved", MouseEvent, p_intf );
243 var_DelCallback( p_vout, "mouse-clicked", MouseEvent, p_intf );
244 vlc_object_release( p_vout );
247 vlc_object_release( p_intf->p_sys->p_input );
250 /*****************************************************************************
252 *****************************************************************************/
253 static int InitThread( intf_thread_t * p_intf )
255 /* we might need some locking here */
258 input_thread_t * p_input;
261 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_PARENT );
262 p_dvd = (dvd_data_t*)p_input->p_access_data;
264 p_dvd->p_intf = p_intf;
266 vlc_mutex_lock( &p_intf->change_lock );
268 p_intf->p_sys->p_input = p_input;
269 p_intf->p_sys->p_dvd = p_dvd;
271 p_intf->p_sys->b_move = VLC_FALSE;
272 p_intf->p_sys->b_click = VLC_FALSE;
274 vlc_mutex_unlock( &p_intf->change_lock );
284 /*****************************************************************************
285 * MouseEvent: callback for mouse events
286 *****************************************************************************/
287 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
288 vlc_value_t oldval, vlc_value_t newval, void *p_data )
290 intf_thread_t *p_intf = (intf_thread_t *)p_data;
292 vlc_mutex_lock( &p_intf->change_lock );
294 if( psz_var[6] == 'c' ) /* "mouse-clicked" */
296 p_intf->p_sys->b_click = VLC_TRUE;
298 else if( psz_var[6] == 'm' ) /* "mouse-moved" */
300 p_intf->p_sys->b_move = VLC_TRUE;
303 vlc_mutex_unlock( &p_intf->change_lock );
308 /*****************************************************************************
309 * dvdIntfStillTime: function provided to demux plugin to request
311 *****************************************************************************/
312 int dvdIntfStillTime( intf_thread_t *p_intf, int i_sec )
314 vlc_mutex_lock( &p_intf->change_lock );
319 p_intf->p_sys->b_still = 1;
320 p_intf->p_sys->b_inf_still = 1;
324 p_intf->p_sys->b_still = 1;
325 p_intf->p_sys->m_still_time = 1000000 * i_sec;
332 p_intf->p_sys->m_still_time = (mtime_t)(-1);
333 msg_Warn( p_intf, I64Fd, p_intf->p_sys->m_still_time );
337 p_intf->p_sys->m_still_time = 1000000 * i_sec;
341 vlc_mutex_unlock( &p_intf->change_lock );