1 /*****************************************************************************
2 * intf.c: Video CD interface to handle user interaction and still time
3 *****************************************************************************
4 * Copyright (C) 2002,2003 VideoLAN
5 * $Id: intf.c,v 1.7 2003/11/26 01:28:52 rocky Exp $
7 * Authors: Rocky Bernstein <rocky@panix.com>
8 * from DVD code by Stéphane Borel <stef@via.ecp.fr>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
31 #include "stream_control.h"
32 #include "input_ext-intf.h"
33 #include "input_ext-dec.h"
37 #include "vcdplayer.h"
39 /*****************************************************************************
40 * intf_sys_t: description and status of interface
41 *****************************************************************************/
44 input_thread_t * p_input;
45 thread_vcd_data_t * p_vcd;
48 vlc_bool_t b_inf_still;
52 vcdplay_ctrl_t control;
56 vlc_bool_t b_click, b_move, b_key_pressed;
59 /*****************************************************************************
61 *****************************************************************************/
62 static int InitThread ( intf_thread_t *p_intf );
63 static int MouseEvent ( vlc_object_t *, char const *,
64 vlc_value_t, vlc_value_t, void * );
65 static int KeyEvent ( vlc_object_t *, char const *,
66 vlc_value_t, vlc_value_t, void * );
68 /* Exported functions */
69 static void RunIntf ( intf_thread_t *p_intf );
71 /*****************************************************************************
72 * OpenIntf: initialize dummy interface
73 *****************************************************************************/
74 int E_(VCDOpenIntf) ( vlc_object_t *p_this )
76 intf_thread_t *p_intf = (intf_thread_t *)p_this;
78 msg_Dbg( p_intf, "VCDOpenIntf" );
80 /* Allocate instance and initialize some members */
81 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
82 if( p_intf->p_sys == NULL )
87 p_intf->pf_run = RunIntf;
89 var_AddCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
90 p_intf->p_sys->m_still_time = 0;
91 p_intf->p_sys->b_inf_still = 0;
92 p_intf->p_sys->b_still = 0;
97 /*****************************************************************************
98 * CloseIntf: destroy dummy interface
99 *****************************************************************************/
100 void E_(VCDCloseIntf) ( vlc_object_t *p_this )
102 intf_thread_t *p_intf = (intf_thread_t *)p_this;
104 /* Destroy structure */
105 free( p_intf->p_sys );
109 /*****************************************************************************
111 *****************************************************************************/
112 static void RunIntf( intf_thread_t *p_intf )
114 vlc_object_t * p_vout = NULL;
115 thread_vcd_data_t * p_vcd;
116 input_thread_t * p_input;
118 /* What you add to the last input number entry. It accumulates all of
119 the 10_ADD keypresses */
120 int number_addend = 0;
122 if( InitThread( p_intf ) < 0 )
124 msg_Err( p_intf, "can't initialize intf" );
128 p_input = p_intf->p_sys->p_input;
129 p_vcd = p_intf->p_sys->p_vcd =
130 (thread_vcd_data_t *) p_input->p_access_data;
132 dbg_print( INPUT_DBG_CALL, "intf initialized" );
135 while( !p_intf->b_die )
137 vlc_mutex_lock( &p_intf->change_lock );
142 if( p_vout && p_intf->p_sys->b_key_pressed )
145 int i, i_action = -1;
146 struct hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
148 p_intf->p_sys->b_key_pressed = VLC_FALSE;
150 /* Find action triggered by hotkey (if any) */
151 var_Get( p_intf->p_vlc, "key-pressed", &val );
153 dbg_print( INPUT_DBG_EVENT, "Key pressed %d", val.i_int );
155 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
157 if( p_hotkeys[i].i_key == val.i_int )
159 i_action = p_hotkeys[i].i_action;
163 if( i_action != -1) {
166 case ACTIONID_NAV_LEFT:
167 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_LEFT - prev (%d)",
170 vcdplayer_play_prev( p_input );
171 } while (number_addend-- > 0);
174 case ACTIONID_NAV_RIGHT:
175 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_RIGHT - next (%d)",
178 vcdplayer_play_next( p_input );
179 } while (number_addend-- > 0);
182 case ACTIONID_NAV_UP:
183 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_UP - return" );
185 vcdplayer_play_return( p_input );
186 } while (number_addend-- > 0);
189 case ACTIONID_NAV_DOWN:
190 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_DOWN - default" );
191 vcdplayer_play_default( p_input );
194 case ACTIONID_NAV_ACTIVATE:
196 vcdinfo_itemid_t itemid;
197 itemid.type=p_vcd->play_item.type;
199 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_ACTIVATE" );
201 if ( vcdplayer_pbc_is_on( p_vcd ) && number_addend != 0 ) {
202 lid_t next_num=vcdinfo_selection_get_lid(p_vcd->vcd,
205 if (VCDINFO_INVALID_LID != next_num) {
206 itemid.num = next_num;
207 itemid.type = VCDINFO_ITEM_TYPE_LID;
208 VCDPlay( p_input, itemid );
211 itemid.num = number_addend;
212 VCDPlay( p_input, itemid );
219 unsigned int digit_entered=0;
243 number_addend += digit_entered;
244 dbg_print( INPUT_DBG_EVENT,
245 "Added %d. Number is now: %d\n",
246 digit_entered, number_addend);
254 vlc_mutex_unlock( &p_intf->change_lock );
258 p_vout = vlc_object_find( p_intf->p_sys->p_input,
259 VLC_OBJECT_VOUT, FIND_CHILD );
262 var_AddCallback( p_vout, "mouse-moved", MouseEvent, p_intf );
263 var_AddCallback( p_vout, "mouse-clicked", MouseEvent, p_intf );
264 var_AddCallback( p_vout, "key-pressed", KeyEvent, p_intf );
270 msleep( INTF_IDLE_SLEEP );
275 var_DelCallback( p_vout, "mouse-moved", MouseEvent, p_intf );
276 var_DelCallback( p_vout, "mouse-clicked", MouseEvent, p_intf );
277 var_DelCallback( p_vout, "key-pressed", KeyEvent, p_intf );
278 vlc_object_release( p_vout );
281 vlc_object_release( p_intf->p_sys->p_input );
284 /*****************************************************************************
286 *****************************************************************************/
287 static int InitThread( intf_thread_t * p_intf )
289 /* We might need some locking here */
292 input_thread_t * p_input;
294 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_PARENT );
296 /* Maybe the input just died */
297 if( p_input == NULL )
302 vlc_mutex_lock( &p_intf->change_lock );
304 p_intf->p_sys->p_input = p_input;
306 p_intf->p_sys->b_move = VLC_FALSE;
307 p_intf->p_sys->b_click = VLC_FALSE;
308 p_intf->p_sys->b_key_pressed = VLC_FALSE;
310 vlc_mutex_unlock( &p_intf->change_lock );
320 /*****************************************************************************
321 * MouseEvent: callback for mouse events
322 *****************************************************************************/
323 static int MouseEvent( vlc_object_t *p_this, char const *psz_var,
324 vlc_value_t oldval, vlc_value_t newval, void *p_data )
326 intf_thread_t *p_intf = (intf_thread_t *)p_data;
328 vlc_mutex_lock( &p_intf->change_lock );
330 if( psz_var[6] == 'c' ) /* "mouse-clicked" */
332 p_intf->p_sys->b_click = VLC_TRUE;
334 else if( psz_var[6] == 'm' ) /* "mouse-moved" */
336 p_intf->p_sys->b_move = VLC_TRUE;
339 vlc_mutex_unlock( &p_intf->change_lock );
344 /*****************************************************************************
345 * KeyEvent: callback for keyboard events
346 *****************************************************************************/
347 static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
348 vlc_value_t oldval, vlc_value_t newval, void *p_data )
350 intf_thread_t *p_intf = (intf_thread_t *)p_data;
351 vlc_mutex_lock( &p_intf->change_lock );
353 p_intf->p_sys->b_key_pressed = VLC_TRUE;
355 vlc_mutex_unlock( &p_intf->change_lock );
360 /*****************************************************************************
361 * dvdIntfStillTime: function provided to demux plugin to request
363 *****************************************************************************/
364 int vcdIntfStillTime( intf_thread_t *p_intf, int i_sec )
366 vlc_mutex_lock( &p_intf->change_lock );
370 p_intf->p_sys->b_still = 1;
371 p_intf->p_sys->b_inf_still = 1;
375 p_intf->p_sys->b_still = 1;
376 p_intf->p_sys->m_still_time = 1000000 * i_sec;
378 vlc_mutex_unlock( &p_intf->change_lock );
383 /*****************************************************************************
384 * vcdIntfStillTime: function provided to reset still image
385 *****************************************************************************/
386 int vcdIntfResetStillTime( intf_thread_t *p_intf )
388 vlc_mutex_lock( &p_intf->change_lock );
389 p_intf->p_sys->m_still_time = 0;
390 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
391 vlc_mutex_unlock( &p_intf->change_lock );