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 *****************************************************************************/
30 #include <vlc/input.h>
35 #include "vcdplayer.h"
38 /*****************************************************************************
40 *****************************************************************************/
41 static int InitThread ( intf_thread_t *p_intf );
42 static int KeyEvent ( vlc_object_t *, char const *,
43 vlc_value_t, vlc_value_t, void * );
45 /* Exported functions */
46 static void RunIntf ( intf_thread_t *p_intf );
48 /*****************************************************************************
49 * OpenIntf: initialize dummy interface
50 *****************************************************************************/
51 int VCDOpenIntf ( vlc_object_t *p_this )
53 intf_thread_t *p_intf = (intf_thread_t *)p_this;
55 msg_Dbg( p_intf, "VCDOpenIntf" );
57 /* Allocate instance and initialize some members */
58 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
59 if( p_intf->p_sys == NULL )
61 return( VLC_EGENERIC );
64 p_intf->pf_run = RunIntf;
66 var_AddCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
67 p_intf->p_sys->m_still_time = 0;
68 p_intf->p_sys->b_infinite_still = 0;
69 p_intf->p_sys->b_still = 0;
71 return( VLC_SUCCESS );
74 /*****************************************************************************
75 * CloseIntf: destroy dummy interface
76 *****************************************************************************/
77 void VCDCloseIntf ( vlc_object_t *p_this )
79 intf_thread_t *p_intf = (intf_thread_t *)p_this;
80 var_DelCallback( p_intf->p_vlc, "key-pressed", KeyEvent, p_intf );
82 /* Destroy structure */
83 free( p_intf->p_sys );
87 /*****************************************************************************
89 *****************************************************************************/
91 RunIntf( intf_thread_t *p_intf )
93 vlc_object_t * p_vout = NULL;
97 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;
112 while ( !p_intf->p_sys->p_vcd )
114 msleep( INTF_IDLE_SLEEP );
117 p_vcd = p_intf->p_sys->p_vcd;
118 p_access = p_vcd->p_access;
120 dbg_print( INPUT_DBG_CALL, "intf initialized" );
123 while( !p_intf->b_die )
125 vlc_mutex_lock( &p_intf->change_lock );
128 * Have we timed-out in showing a still frame?
130 if( p_intf->p_sys->b_still && !p_intf->p_sys->b_infinite_still )
132 if( p_intf->p_sys->m_still_time > 0 )
134 /* Update remaining still time */
135 dbg_print(INPUT_DBG_STILL, "updating still time");
139 p_intf->p_sys->m_still_time -= mtime - mlast;
146 /* Still time has elapsed; set to continue playing. */
147 dbg_print(INPUT_DBG_STILL, "wait time done - setting play");
148 var_SetInteger( p_intf->p_sys->p_input, "state", PLAYING_S );
149 p_intf->p_sys->m_still_time = 0;
150 p_intf->p_sys->b_still = 0;
156 * Do we have a keyboard event?
158 if( p_vout && p_intf->p_sys->b_key_pressed )
161 int i, i_action = -1;
162 struct hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
164 p_intf->p_sys->b_key_pressed = VLC_FALSE;
166 /* Find action triggered by hotkey (if any) */
167 var_Get( p_intf->p_vlc, "key-pressed", &val );
169 dbg_print( INPUT_DBG_EVENT, "Key pressed %d", val.i_int );
171 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
173 if( p_hotkeys[i].i_key == val.i_int )
175 i_action = p_hotkeys[i].i_action;
179 if( i_action != -1) {
182 case ACTIONID_NAV_LEFT:
183 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_LEFT - prev (%d)",
186 vcdplayer_play_prev( p_access );
187 } while (number_addend-- > 0);
190 case ACTIONID_NAV_RIGHT:
191 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_RIGHT - next (%d)",
194 vcdplayer_play_next( p_access );
195 } while (number_addend-- > 0);
198 case ACTIONID_NAV_UP:
199 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_UP - return" );
201 vcdplayer_play_return( p_access );
202 } while (number_addend-- > 0);
205 case ACTIONID_NAV_DOWN:
206 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_DOWN - default" );
207 vcdplayer_play_default( p_access );
210 case ACTIONID_NAV_ACTIVATE:
212 vcdinfo_itemid_t itemid;
213 itemid.type=p_vcd->play_item.type;
215 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_ACTIVATE" );
217 if ( vcdplayer_pbc_is_on( p_vcd ) && number_addend != 0 ) {
218 lid_t next_num=vcdinfo_selection_get_lid(p_vcd->vcd,
221 if (VCDINFO_INVALID_LID != next_num) {
222 itemid.num = next_num;
223 itemid.type = VCDINFO_ITEM_TYPE_LID;
224 vcdplayer_play( p_access, itemid );
227 itemid.num = number_addend;
228 vcdplayer_play( p_access, itemid );
235 /* Any keypress gets rid of still frame waiting.
236 FIXME - should handle just the ones that cause an action.
238 if( p_intf->p_sys->b_still )
240 dbg_print(INPUT_DBG_STILL, "Playing still after activate");
241 var_SetInteger( p_intf->p_sys->p_input, "state", PLAYING_S );
242 p_intf->p_sys->b_still = 0;
243 p_intf->p_sys->b_infinite_still = 0;
244 p_intf->p_sys->m_still_time = 0;
248 unsigned int digit_entered=0;
272 number_addend += digit_entered;
273 dbg_print( INPUT_DBG_EVENT,
274 "Added %d. Number is now: %d\n",
275 digit_entered, number_addend);
283 vlc_mutex_unlock( &p_intf->change_lock );
287 p_vout = vlc_object_find( p_intf->p_sys->p_input,
288 VLC_OBJECT_VOUT, FIND_CHILD );
291 var_AddCallback( p_vout, "key-pressed", KeyEvent, p_intf );
297 msleep( INTF_IDLE_SLEEP );
302 var_DelCallback( p_vout, "key-pressed", KeyEvent, p_intf );
303 vlc_object_release( p_vout );
306 vlc_object_release( p_intf->p_sys->p_input );
309 /*****************************************************************************
311 *****************************************************************************/
312 static int InitThread( intf_thread_t * p_intf )
314 /* We might need some locking here */
317 input_thread_t * p_input;
319 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_PARENT );
321 /* Maybe the input just died */
322 if( p_input == NULL )
327 vlc_mutex_lock( &p_intf->change_lock );
329 p_intf->p_sys->p_input = p_input;
330 p_intf->p_sys->p_vcd = NULL;
332 p_intf->p_sys->b_move = VLC_FALSE;
333 p_intf->p_sys->b_click = VLC_FALSE;
334 p_intf->p_sys->b_key_pressed = VLC_FALSE;
336 vlc_mutex_unlock( &p_intf->change_lock );
346 /*****************************************************************************
347 * KeyEvent: callback for keyboard events
348 *****************************************************************************/
349 static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
350 vlc_value_t oldval, vlc_value_t newval, void *p_data )
352 intf_thread_t *p_intf = (intf_thread_t *)p_data;
353 vlc_mutex_lock( &p_intf->change_lock );
355 p_intf->p_sys->b_key_pressed = VLC_TRUE;
357 vlc_mutex_unlock( &p_intf->change_lock );
362 /*****************************************************************************
363 * vcdIntfStillTime: function provided to demux plugin to request
365 *****************************************************************************/
366 int vcdIntfStillTime( intf_thread_t *p_intf, uint8_t i_sec )
368 vlc_mutex_lock( &p_intf->change_lock );
370 p_intf->p_sys->b_still = 1;
373 p_intf->p_sys->b_infinite_still = VLC_TRUE;
377 p_intf->p_sys->m_still_time = MILLISECONDS_PER_SEC * i_sec;
379 vlc_mutex_unlock( &p_intf->change_lock );
384 /*****************************************************************************
385 * vcdIntfStillTime: function provided to reset still image
386 *****************************************************************************/
387 int vcdIntfResetStillTime( intf_thread_t *p_intf )
389 vlc_mutex_lock( &p_intf->change_lock );
390 p_intf->p_sys->m_still_time = 0;
391 var_SetInteger( p_intf->p_sys->p_input, "state", PLAYING_S );
392 vlc_mutex_unlock( &p_intf->change_lock );