1 /*****************************************************************************
2 * intf.c: interface for DVD video manager
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: intf.c,v 1.1 2002/07/23 19:56:19 stef Exp $
7 * Authors: Stéphane Borel <stef@via.ecp.fr>
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 *****************************************************************************/
27 #include <stdlib.h> /* malloc(), free() */
34 #include "stream_control.h"
35 #include "input_ext-intf.h"
38 #include "video_output.h"
42 /*****************************************************************************
43 * intf_sys_t: description and status of interface
44 *****************************************************************************/
47 input_thread_t * p_input;
51 vlc_bool_t b_inf_still;
56 /*****************************************************************************
58 *****************************************************************************/
59 static int InitThread ( intf_thread_t *p_intf );
61 /* Exported functions */
62 static int intf_Open ( intf_thread_t *p_intf );
63 static void intf_Close ( intf_thread_t *p_intf );
64 static void intf_Run ( intf_thread_t *p_intf );
67 /*****************************************************************************
68 * Functions exported as capabilities. They are declared as static so that
69 * we don't pollute the namespace too much.
70 *****************************************************************************/
71 void _M( intf_getfunctions )( function_list_t * p_function_list )
73 p_function_list->functions.intf.pf_open = intf_Open;
74 p_function_list->functions.intf.pf_close = intf_Close;
75 p_function_list->functions.intf.pf_run = intf_Run;
78 /*****************************************************************************
79 * intf_Open: initialize dummy interface
80 *****************************************************************************/
81 static int intf_Open( intf_thread_t *p_intf )
83 /* Allocate instance and initialize some members */
84 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
85 if( p_intf->p_sys == NULL )
90 p_intf->p_sys->m_still_time = 0;
91 p_intf->p_sys->b_inf_still = 0;
92 p_intf->p_sys->b_still = 0;
97 /*****************************************************************************
98 * intf_Close: destroy dummy interface
99 *****************************************************************************/
100 static void intf_Close( intf_thread_t *p_intf )
102 /* Destroy structure */
103 free( p_intf->p_sys );
107 /*****************************************************************************
108 * intf_Run: main loop
109 *****************************************************************************/
110 static void intf_Run( intf_thread_t *p_intf )
112 vout_thread_t * p_vout;
113 dvdplay_ctrl_t control;
117 if( InitThread( p_intf ) < 0 )
119 msg_Err( p_intf, "can't initialize intf" );
122 msg_Dbg( p_intf, "intf initialized" );
125 control.mouse.i_x = 0;
126 control.mouse.i_y = 0;
129 while( !p_intf->b_die )
131 vlc_mutex_lock( &p_intf->change_lock );
137 if( p_intf->p_sys->b_still && !p_intf->p_sys->b_inf_still )
139 if( p_intf->p_sys->m_still_time > 0 )
141 /* update remaining still time */
145 p_intf->p_sys->m_still_time -= mtime - mlast;
152 /* still time elasped */
153 input_SetStatus( p_intf->p_sys->p_input,
155 p_intf->p_sys->m_still_time = 0;
156 p_intf->p_sys->b_still = 0;
161 if( p_intf->p_sys->m_still_time != (mtime_t)(-1) )
163 if( p_intf->p_sys->m_still_time )
168 p_intf->p_sys->m_still_time -= mtime - mlast;
170 if( !p_intf->p_sys->m_still_time )
172 input_SetStatus( p_intf->p_sys->p_input,
184 p_vout = vlc_object_find( p_intf->p_sys->p_input,
185 VLC_OBJECT_VOUT, FIND_CHILD );
188 vlc_mutex_lock( &p_vout->change_lock );
190 if( control.mouse.i_x != p_vout->i_mouse_x ||
191 control.mouse.i_y != p_vout->i_mouse_y ||
192 p_vout->i_mouse_button )
196 control.mouse.i_x = p_vout->i_mouse_x;
197 control.mouse.i_y = p_vout->i_mouse_y;
199 if( p_vout->i_mouse_button )
201 control.type = DVDCtrlMouseActivate;
203 msg_Dbg( p_intf, "Activate coordinates: %dx%d",
204 p_vout->i_mouse_x, p_vout->i_mouse_y );
208 control.type = DVDCtrlMouseSelect;
210 msg_Dbg( p_intf, "Select coordinates: %dx%d",
211 p_vout->i_mouse_x, p_vout->i_mouse_y );
213 p_vout->i_mouse_button = 0;
214 vlc_mutex_unlock( &p_vout->change_lock );
216 msg_Dbg( p_intf, "send button" );
218 /* we can safely interact with libdvdplay
219 * with the stream lock */
220 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
223 dvdplay_button( p_intf->p_sys->p_dvd->vmg, &control );
225 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
228 if( i_activate && p_intf->p_sys->b_still )
230 input_SetStatus( p_intf->p_sys->p_input,
232 p_intf->p_sys->b_still = 0;
233 p_intf->p_sys->b_inf_still = 0;
234 p_intf->p_sys->m_still_time = 0;
239 vlc_mutex_unlock( &p_vout->change_lock );
243 vlc_object_release( p_vout );
246 vlc_mutex_unlock( &p_intf->change_lock );
249 msleep( INTF_IDLE_SLEEP );
252 vlc_object_release( p_intf->p_sys->p_input );
256 /*****************************************************************************
258 *****************************************************************************/
259 static int InitThread( intf_thread_t * p_intf )
261 /* we might need some locking here */
264 input_thread_t * p_input;
267 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_PARENT );
268 p_dvd = (dvd_data_t*)p_input->p_access_data;
270 p_dvd->p_intf = p_intf;
272 vlc_mutex_lock( &p_intf->change_lock );
274 p_intf->p_sys->p_input = p_input;
275 p_intf->p_sys->p_dvd = p_dvd;
277 vlc_mutex_unlock( &p_intf->change_lock );
287 /*****************************************************************************
288 * dvdIntfStillTime: function provided to demux plugin to request
290 *****************************************************************************/
291 int dvdIntfStillTime( intf_thread_t *p_intf, int i_sec )
293 vlc_mutex_lock( &p_intf->change_lock );
298 p_intf->p_sys->b_still = 1;
299 p_intf->p_sys->b_inf_still = 1;
303 p_intf->p_sys->b_still = 1;
304 p_intf->p_sys->m_still_time = 1000000 * i_sec;
311 p_intf->p_sys->m_still_time = (mtime_t)(-1);
312 msg_Warn( p_intf, "%lld", p_intf->p_sys->m_still_time );
316 p_intf->p_sys->m_still_time = 1000000 * i_sec;
321 vlc_mutex_unlock( &p_intf->change_lock );