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.11 2003/12/05 05:01:17 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"
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 input_SetStatus( p_intf->p_sys->p_input,
144 p_intf->p_sys->m_still_time = 0;
145 p_intf->p_sys->b_still = 0;
151 * Do we have a keyboard event?
153 if( p_vout && p_intf->p_sys->b_key_pressed )
156 int i, i_action = -1;
157 struct hotkey *p_hotkeys = p_intf->p_vlc->p_hotkeys;
159 p_intf->p_sys->b_key_pressed = VLC_FALSE;
161 /* Find action triggered by hotkey (if any) */
162 var_Get( p_intf->p_vlc, "key-pressed", &val );
164 dbg_print( INPUT_DBG_EVENT, "Key pressed %d", val.i_int );
166 for( i = 0; p_hotkeys[i].psz_action != NULL; i++ )
168 if( p_hotkeys[i].i_key == val.i_int )
170 i_action = p_hotkeys[i].i_action;
174 if( i_action != -1) {
177 case ACTIONID_NAV_LEFT:
178 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_LEFT - prev (%d)",
181 vcdplayer_play_prev( p_input );
182 } while (number_addend-- > 0);
185 case ACTIONID_NAV_RIGHT:
186 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_RIGHT - next (%d)",
189 vcdplayer_play_next( p_input );
190 } while (number_addend-- > 0);
193 case ACTIONID_NAV_UP:
194 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_UP - return" );
196 vcdplayer_play_return( p_input );
197 } while (number_addend-- > 0);
200 case ACTIONID_NAV_DOWN:
201 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_DOWN - default" );
202 vcdplayer_play_default( p_input );
205 case ACTIONID_NAV_ACTIVATE:
207 vcdinfo_itemid_t itemid;
208 itemid.type=p_vcd->play_item.type;
210 dbg_print( INPUT_DBG_EVENT, "ACTIONID_NAV_ACTIVATE" );
212 if ( vcdplayer_pbc_is_on( p_vcd ) && number_addend != 0 ) {
213 lid_t next_num=vcdinfo_selection_get_lid(p_vcd->vcd,
216 if (VCDINFO_INVALID_LID != next_num) {
217 itemid.num = next_num;
218 itemid.type = VCDINFO_ITEM_TYPE_LID;
219 VCDPlay( p_input, itemid );
222 itemid.num = number_addend;
223 VCDPlay( p_input, itemid );
230 /* Any keypress gets rid of still frame waiting.
231 FIXME - should handle just the ones that cause an action.
233 if( p_intf->p_sys->b_still )
235 dbg_print(INPUT_DBG_STILL, "Playing still after activate");
236 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
237 p_intf->p_sys->b_still = 0;
238 p_intf->p_sys->b_inf_still = 0;
239 p_intf->p_sys->m_still_time = 0;
243 unsigned int digit_entered=0;
267 number_addend += digit_entered;
268 dbg_print( INPUT_DBG_EVENT,
269 "Added %d. Number is now: %d\n",
270 digit_entered, number_addend);
278 vlc_mutex_unlock( &p_intf->change_lock );
282 p_vout = vlc_object_find( p_intf->p_sys->p_input,
283 VLC_OBJECT_VOUT, FIND_CHILD );
286 var_AddCallback( p_vout, "key-pressed", KeyEvent, p_intf );
292 msleep( INTF_IDLE_SLEEP );
297 var_DelCallback( p_vout, "key-pressed", KeyEvent, p_intf );
298 vlc_object_release( p_vout );
301 vlc_object_release( p_intf->p_sys->p_input );
304 /*****************************************************************************
306 *****************************************************************************/
307 static int InitThread( intf_thread_t * p_intf )
309 /* We might need some locking here */
312 input_thread_t * p_input;
314 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_PARENT );
316 /* Maybe the input just died */
317 if( p_input == NULL )
322 vlc_mutex_lock( &p_intf->change_lock );
324 p_intf->p_sys->p_input = p_input;
326 p_intf->p_sys->b_move = VLC_FALSE;
327 p_intf->p_sys->b_click = VLC_FALSE;
328 p_intf->p_sys->b_key_pressed = VLC_FALSE;
330 vlc_mutex_unlock( &p_intf->change_lock );
340 /*****************************************************************************
341 * KeyEvent: callback for keyboard events
342 *****************************************************************************/
343 static int KeyEvent( vlc_object_t *p_this, char const *psz_var,
344 vlc_value_t oldval, vlc_value_t newval, void *p_data )
346 intf_thread_t *p_intf = (intf_thread_t *)p_data;
347 vlc_mutex_lock( &p_intf->change_lock );
349 p_intf->p_sys->b_key_pressed = VLC_TRUE;
351 vlc_mutex_unlock( &p_intf->change_lock );
356 /*****************************************************************************
357 * vcdIntfStillTime: function provided to demux plugin to request
359 *****************************************************************************/
360 int vcdIntfStillTime( intf_thread_t *p_intf, int i_sec )
362 vlc_mutex_lock( &p_intf->change_lock );
366 p_intf->p_sys->b_still = 1;
367 p_intf->p_sys->b_inf_still = 1;
371 p_intf->p_sys->b_still = 1;
372 p_intf->p_sys->m_still_time = 1000000 * i_sec;
374 vlc_mutex_unlock( &p_intf->change_lock );
379 /*****************************************************************************
380 * vcdIntfStillTime: function provided to reset still image
381 *****************************************************************************/
382 int vcdIntfResetStillTime( intf_thread_t *p_intf )
384 vlc_mutex_lock( &p_intf->change_lock );
385 p_intf->p_sys->m_still_time = 0;
386 input_SetStatus( p_intf->p_sys->p_input, INPUT_STATUS_PLAY );
387 vlc_mutex_unlock( &p_intf->change_lock );