1 /*****************************************************************************
2 * intf.c: Video CD interface to handle user interaction and still time
3 *****************************************************************************
4 * Copyright (C) 2002,2003 the VideoLAN team
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, 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;
96 vcdplayer_t * p_vcdplayer;
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_vcdplayer )
114 msleep( INTF_IDLE_SLEEP );
117 p_vcdplayer = p_intf->p_sys->p_vcdplayer;
118 p_access = p_vcdplayer->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_vcdplayer->play_item.type;
215 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_ACTIVATE" );
217 if ( vcdplayer_pbc_is_on( p_vcdplayer )
218 && number_addend != 0 ) {
219 lid_t next_num=vcdinfo_selection_get_lid(p_vcdplayer->vcd,
222 if (VCDINFO_INVALID_LID != next_num) {
223 itemid.num = next_num;
224 itemid.type = VCDINFO_ITEM_TYPE_LID;
225 vcdplayer_play( p_access, itemid );
228 itemid.num = number_addend;
229 vcdplayer_play( p_access, itemid );
236 /* Any keypress gets rid of still frame waiting.
237 FIXME - should handle just the ones that cause an action.
239 if( p_intf->p_sys->b_still )
241 dbg_print(INPUT_DBG_STILL, "Playing still after activate");
242 var_SetInteger( p_intf->p_sys->p_input, "state", PLAYING_S );
243 p_intf->p_sys->b_still = 0;
244 p_intf->p_sys->b_infinite_still = 0;
245 p_intf->p_sys->m_still_time = 0;
249 unsigned int digit_entered=0;
273 number_addend += digit_entered;
274 dbg_print( INPUT_DBG_EVENT,
275 "Added %d. Number is now: %d\n",
276 digit_entered, number_addend);
284 vlc_mutex_unlock( &p_intf->change_lock );
288 p_vout = vlc_object_find( p_intf->p_sys->p_input,
289 VLC_OBJECT_VOUT, FIND_CHILD );
292 var_AddCallback( p_vout, "key-pressed", KeyEvent, p_intf );
298 msleep( INTF_IDLE_SLEEP );
303 var_DelCallback( p_vout, "key-pressed", KeyEvent, p_intf );
304 vlc_object_release( p_vout );
307 vlc_object_release( p_intf->p_sys->p_input );
310 /*****************************************************************************
312 *****************************************************************************/
313 static int InitThread( intf_thread_t * p_intf )
315 /* We might need some locking here */
318 input_thread_t * p_input;
320 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_PARENT );
322 /* Maybe the input just died */
323 if( p_input == NULL )
328 vlc_mutex_lock( &p_intf->change_lock );
330 p_intf->p_sys->p_input = p_input;
331 p_intf->p_sys->p_vcdplayer = NULL;
333 p_intf->p_sys->b_move = VLC_FALSE;
334 p_intf->p_sys->b_click = VLC_FALSE;
335 p_intf->p_sys->b_key_pressed = VLC_FALSE;
337 vlc_mutex_unlock( &p_intf->change_lock );
347 /*****************************************************************************
348 * KeyEvent: callback for keyboard events
349 *****************************************************************************/
350 static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
351 vlc_value_t oldval, vlc_value_t newval, void *p_data )
353 intf_thread_t *p_intf = (intf_thread_t *)p_data;
354 vlc_mutex_lock( &p_intf->change_lock );
356 p_intf->p_sys->b_key_pressed = VLC_TRUE;
358 vlc_mutex_unlock( &p_intf->change_lock );
363 /*****************************************************************************
364 * vcdIntfStillTime: function provided to demux plugin to request
366 *****************************************************************************/
367 int vcdIntfStillTime( intf_thread_t *p_intf, uint8_t i_sec )
369 vlc_mutex_lock( &p_intf->change_lock );
371 p_intf->p_sys->b_still = 1;
374 p_intf->p_sys->b_infinite_still = VLC_TRUE;
378 p_intf->p_sys->m_still_time = MILLISECONDS_PER_SEC * i_sec;
380 vlc_mutex_unlock( &p_intf->change_lock );
385 /*****************************************************************************
386 * vcdIntfStillTime: function provided to reset still image
387 *****************************************************************************/
388 int vcdIntfResetStillTime( intf_thread_t *p_intf )
390 vlc_mutex_lock( &p_intf->change_lock );
391 p_intf->p_sys->m_still_time = 0;
392 var_SetInteger( p_intf->p_sys->p_input, "state", PLAYING_S );
393 vlc_mutex_unlock( &p_intf->change_lock );