1 /*****************************************************************************
2 * intf.c: Video CD interface to handle user interaction and still time
3 *****************************************************************************
4 * Copyright (C) 2003 VideoLAN
5 * $Id: intf.c,v 1.1 2003/11/26 03:35:26 rocky Exp $
7 * Authors: Rocky Bernstein <rocky@panix.com>
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 *****************************************************************************/
30 #include "stream_control.h"
31 #include "input_ext-intf.h"
32 #include "input_ext-dec.h"
37 /*****************************************************************************
38 * intf_sys_t: description and status of interface
39 *****************************************************************************/
42 input_thread_t * p_input;
44 vlc_bool_t b_click, b_move, b_key_pressed;
47 /*****************************************************************************
49 *****************************************************************************/
50 static int InitThread ( intf_thread_t *p_intf );
51 static int KeyEvent ( vlc_object_t *, char const *,
52 vlc_value_t, vlc_value_t, void * );
54 /* Exported functions */
55 static void RunIntf ( intf_thread_t *p_intf );
57 /*****************************************************************************
58 * OpenIntf: initialize dummy interface
59 *****************************************************************************/
60 int E_(OpenIntf) ( vlc_object_t *p_this )
62 intf_thread_t *p_intf = (intf_thread_t *)p_this;
64 /* Allocate instance and initialize some members */
65 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
66 if( p_intf->p_sys == NULL )
71 p_intf->pf_run = RunIntf;
73 var_AddCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
78 /*****************************************************************************
79 * CloseIntf: destroy dummy interface
80 *****************************************************************************/
81 void E_(CloseIntf) ( vlc_object_t *p_this )
83 intf_thread_t *p_intf = (intf_thread_t *)p_this;
85 /* Destroy structure */
86 free( p_intf->p_sys );
89 /*****************************************************************************
91 *****************************************************************************/
92 static void RunIntf( intf_thread_t *p_intf )
94 vlc_object_t * p_vout = NULL;
96 input_thread_t * p_input;
98 /* What you add to the last input number entry. It accumulates all of
99 the 10_ADD keypresses */
100 int number_addend = 0;
102 if( InitThread( p_intf ) < 0 )
104 msg_Err( p_intf, "can't initialize intf" );
108 p_input = p_intf->p_sys->p_input;
109 p_cdda = p_intf->p_sys->p_cdda =
110 (cdda_data_t *) p_input->p_access_data;
112 dbg_print( INPUT_DBG_CALL, "intf initialized" );
115 while( !p_intf->b_die )
117 vlc_mutex_lock( &p_intf->change_lock );
122 if( p_vout && p_intf->p_sys->b_key_pressed )
125 int i, i_action = -1;
126 struct hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
128 p_intf->p_sys->b_key_pressed = VLC_FALSE;
130 /* Find action triggered by hotkey (if any) */
131 var_Get( p_intf->p_vlc, "key-pressed", &val );
133 dbg_print( INPUT_DBG_EVENT, "Key pressed %d", val.i_int );
135 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
137 if( p_hotkeys[i].i_key == val.i_int )
139 i_action = p_hotkeys[i].i_action;
143 if( i_action != -1) {
146 case ACTIONID_NAV_LEFT:
147 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_LEFT (%d)",
150 if ( CDDAPlay( p_input, p_cdda->i_track-1 ) ) {
155 } while (number_addend-- > 0);
158 case ACTIONID_NAV_RIGHT:
159 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_RIGHT (%d)",
162 if ( CDDAPlay( p_input, p_cdda->i_track+1 ) ) {
167 } while (number_addend-- > 0);
170 case ACTIONID_NAV_UP:
171 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_UP" );
174 } while (number_addend-- > 0);
177 case ACTIONID_NAV_DOWN:
178 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_DOWN" );
181 case ACTIONID_NAV_ACTIVATE:
183 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_ACTIVATE" );
184 if ( CDDAPlay( p_input, number_addend ) ) {
185 p_cdda->i_track = number_addend;
194 unsigned int digit_entered=0;
218 number_addend += digit_entered;
219 dbg_print( INPUT_DBG_EVENT,
220 "Added %d. Number is now: %d\n",
221 digit_entered, number_addend);
229 vlc_mutex_unlock( &p_intf->change_lock );
233 p_vout = vlc_object_find( p_intf->p_sys->p_input,
234 VLC_OBJECT_VOUT, FIND_ANYWHERE );
237 var_AddCallback( p_vout, "key-pressed", KeyEvent, p_intf );
243 msleep( INTF_IDLE_SLEEP );
248 var_DelCallback( p_vout, "key-pressed", KeyEvent, p_intf );
249 vlc_object_release( p_vout );
252 vlc_object_release( p_intf->p_sys->p_input );
255 /*****************************************************************************
257 *****************************************************************************/
258 static int InitThread( intf_thread_t * p_intf )
260 /* We might need some locking here */
263 input_thread_t * p_input;
265 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_PARENT );
267 /* Maybe the input just died */
268 if( p_input == NULL )
273 vlc_mutex_lock( &p_intf->change_lock );
275 p_intf->p_sys->p_input = p_input;
277 p_intf->p_sys->b_move = VLC_FALSE;
278 p_intf->p_sys->b_click = VLC_FALSE;
279 p_intf->p_sys->b_key_pressed = VLC_FALSE;
281 vlc_mutex_unlock( &p_intf->change_lock );
291 /*****************************************************************************
292 * KeyEvent: callback for keyboard events
293 *****************************************************************************/
294 static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
295 vlc_value_t oldval, vlc_value_t newval, void *p_data )
297 intf_thread_t *p_intf = (intf_thread_t *)p_data;
298 vlc_mutex_lock( &p_intf->change_lock );
300 p_intf->p_sys->b_key_pressed = VLC_TRUE;
302 vlc_mutex_unlock( &p_intf->change_lock );