1 /*****************************************************************************
2 * intf.c: Video CD interface to handle user interaction and still time
3 *****************************************************************************
4 * Copyright (C) 2002,2003 VideoLAN
7 * Author: 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"
40 /*****************************************************************************
42 *****************************************************************************/
43 static int InitThread ( intf_thread_t *p_intf );
44 static int KeyEvent ( vlc_object_t *, char const *,
45 vlc_value_t, vlc_value_t, void * );
47 /* Exported functions */
48 static void RunIntf ( intf_thread_t *p_intf );
50 /*****************************************************************************
51 * OpenIntf: initialize dummy interface
52 *****************************************************************************/
53 int E_(OpenIntf) ( vlc_object_t *p_this )
55 intf_thread_t *p_intf = (intf_thread_t *)p_this;
57 msg_Dbg( p_intf, "VCDOpenIntf" );
59 /* Allocate instance and initialize some members */
60 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
61 if( p_intf->p_sys == NULL )
66 p_intf->pf_run = RunIntf;
68 var_AddCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
69 p_intf->p_sys->m_still_time = 0;
70 p_intf->p_sys->b_inf_still = 0;
71 p_intf->p_sys->b_still = 0;
76 /*****************************************************************************
77 * CloseIntf: destroy dummy interface
78 *****************************************************************************/
79 void E_(CloseIntf) ( vlc_object_t *p_this )
81 intf_thread_t *p_intf = (intf_thread_t *)p_this;
82 var_DelCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
84 /* Destroy structure */
85 free( p_intf->p_sys );
89 /*****************************************************************************
91 *****************************************************************************/
92 static void RunIntf( intf_thread_t *p_intf )
94 vlc_object_t * p_vout = NULL;
97 thread_vcd_data_t * p_vcd;
98 input_thread_t * p_input;
100 /* What you add to the last input number entry. It accumulates all of
101 the 10_ADD keypresses */
102 int number_addend = 0;
104 if( InitThread( p_intf ) < 0 )
106 msg_Err( p_intf, "can't initialize intf" );
110 p_input = p_intf->p_sys->p_input;
111 p_vcd = p_intf->p_sys->p_vcd =
112 (thread_vcd_data_t *) p_input->p_access_data;
114 dbg_print( INPUT_DBG_CALL, "intf initialized" );
117 while( !p_intf->b_die )
119 vlc_mutex_lock( &p_intf->change_lock );
122 * Have we timed-out in showing a still frame?
124 if( p_intf->p_sys->b_still && !p_intf->p_sys->b_inf_still )
126 if( p_intf->p_sys->m_still_time > 0 )
128 /* Update remaining still time */
129 dbg_print(INPUT_DBG_STILL, "updating still time");
133 p_intf->p_sys->m_still_time -= mtime - mlast;
140 /* Still time has elasped; set to continue playing. */
141 dbg_print(INPUT_DBG_STILL, "wait time done - setting play");
142 var_SetInteger( p_intf->p_sys->p_input, "state", PLAYING_S );
143 p_intf->p_sys->m_still_time = 0;
144 p_intf->p_sys->b_still = 0;
150 * Do we have a keyboard event?
152 if( p_vout && p_intf->p_sys->b_key_pressed )
155 int i, i_action = -1;
156 struct hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
158 p_intf->p_sys->b_key_pressed = VLC_FALSE;
160 /* Find action triggered by hotkey (if any) */
161 var_Get( p_intf->p_vlc, "key-pressed", &val );
163 dbg_print( INPUT_DBG_EVENT, "Key pressed %d", val.i_int );
165 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
167 if( p_hotkeys[i].i_key == val.i_int )
169 i_action = p_hotkeys[i].i_action;
173 if( i_action != -1) {
176 case ACTIONID_NAV_LEFT:
177 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_LEFT - prev (%d)",
180 vcdplayer_play_prev( p_input );
181 } while (number_addend-- > 0);
184 case ACTIONID_NAV_RIGHT:
185 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_RIGHT - next (%d)",
188 vcdplayer_play_next( p_input );
189 } while (number_addend-- > 0);
192 case ACTIONID_NAV_UP:
193 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_UP - return" );
195 vcdplayer_play_return( p_input );
196 } while (number_addend-- > 0);
199 case ACTIONID_NAV_DOWN:
200 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_DOWN - default" );
201 vcdplayer_play_default( p_input );
204 case ACTIONID_NAV_ACTIVATE:
206 vcdinfo_itemid_t itemid;
207 itemid.type=p_vcd->play_item.type;
209 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_ACTIVATE" );
211 if ( vcdplayer_pbc_is_on( p_vcd ) && number_addend != 0 ) {
212 lid_t next_num=vcdinfo_selection_get_lid(p_vcd->vcd,
215 if (VCDINFO_INVALID_LID != next_num) {
216 itemid.num = next_num;
217 itemid.type = VCDINFO_ITEM_TYPE_LID;
218 VCDPlay( p_input, itemid );
221 itemid.num = number_addend;
222 VCDPlay( p_input, itemid );
229 /* Any keypress gets rid of still frame waiting.
230 FIXME - should handle just the ones that cause an action.
232 if( p_intf->p_sys->b_still )
234 dbg_print(INPUT_DBG_STILL, "Playing still after activate");
235 var_SetInteger( p_intf->p_sys->p_input, "state", PLAYING_S );
236 p_intf->p_sys->b_still = 0;
237 p_intf->p_sys->b_inf_still = 0;
238 p_intf->p_sys->m_still_time = 0;
242 unsigned int digit_entered=0;
266 number_addend += digit_entered;
267 dbg_print( INPUT_DBG_EVENT,
268 "Added %d. Number is now: %d\n",
269 digit_entered, number_addend);
277 vlc_mutex_unlock( &p_intf->change_lock );
281 p_vout = vlc_object_find( p_intf->p_sys->p_input,
282 VLC_OBJECT_VOUT, FIND_CHILD );
285 var_AddCallback( p_vout, "key-pressed", KeyEvent, p_intf );
291 msleep( INTF_IDLE_SLEEP );
296 var_DelCallback( p_vout, "key-pressed", KeyEvent, p_intf );
297 vlc_object_release( p_vout );
300 vlc_object_release( p_intf->p_sys->p_input );
303 /*****************************************************************************
305 *****************************************************************************/
306 static int InitThread( intf_thread_t * p_intf )
308 /* We might need some locking here */
311 input_thread_t * p_input;
313 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_PARENT );
315 /* Maybe the input just died */
316 if( p_input == NULL )
321 vlc_mutex_lock( &p_intf->change_lock );
323 p_intf->p_sys->p_input = p_input;
325 p_intf->p_sys->b_move = VLC_FALSE;
326 p_intf->p_sys->b_click = VLC_FALSE;
327 p_intf->p_sys->b_key_pressed = VLC_FALSE;
329 vlc_mutex_unlock( &p_intf->change_lock );
339 /*****************************************************************************
340 * KeyEvent: callback for keyboard events
341 *****************************************************************************/
342 static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
343 vlc_value_t oldval, vlc_value_t newval, void *p_data )
345 intf_thread_t *p_intf = (intf_thread_t *)p_data;
346 vlc_mutex_lock( &p_intf->change_lock );
348 p_intf->p_sys->b_key_pressed = VLC_TRUE;
350 vlc_mutex_unlock( &p_intf->change_lock );
355 /*****************************************************************************
356 * vcdIntfStillTime: function provided to demux plugin to request
358 *****************************************************************************/
359 int vcdIntfStillTime( intf_thread_t *p_intf, int i_sec )
361 vlc_mutex_lock( &p_intf->change_lock );
365 p_intf->p_sys->b_still = 1;
366 p_intf->p_sys->b_inf_still = 1;
370 p_intf->p_sys->b_still = 1;
371 p_intf->p_sys->m_still_time = 1000000 * i_sec;
373 vlc_mutex_unlock( &p_intf->change_lock );
378 /*****************************************************************************
379 * vcdIntfStillTime: function provided to reset still image
380 *****************************************************************************/
381 int vcdIntfResetStillTime( intf_thread_t *p_intf )
383 vlc_mutex_lock( &p_intf->change_lock );
384 p_intf->p_sys->m_still_time = 0;
385 var_SetInteger( p_intf->p_sys->p_input, "state", PLAYING_S );
386 vlc_mutex_unlock( &p_intf->change_lock );