1 /*****************************************************************************
2 * intf.c: interface for DVD video manager
3 *****************************************************************************
4 * Copyright (C) 2002 VideoLAN
5 * $Id: intf.c,v 1.1 2002/08/04 17:23:42 sam 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 void RunIntf ( intf_thread_t *p_intf );
64 /*****************************************************************************
65 * OpenIntf: initialize dummy interface
66 *****************************************************************************/
67 int E_(OpenIntf) ( vlc_object_t *p_this )
69 intf_thread_t *p_intf = (intf_thread_t *)p_this;
71 /* Allocate instance and initialize some members */
72 p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
73 if( p_intf->p_sys == NULL )
78 p_intf->pf_run = RunIntf;
80 p_intf->p_sys->m_still_time = 0;
81 p_intf->p_sys->b_inf_still = 0;
82 p_intf->p_sys->b_still = 0;
87 /*****************************************************************************
88 * CloseIntf: destroy dummy interface
89 *****************************************************************************/
90 void E_(CloseIntf) ( vlc_object_t *p_this )
92 intf_thread_t *p_intf = (intf_thread_t *)p_this;
94 /* Destroy structure */
95 free( p_intf->p_sys );
99 /*****************************************************************************
101 *****************************************************************************/
102 static void RunIntf( intf_thread_t *p_intf )
104 vout_thread_t * p_vout;
105 dvdplay_ctrl_t control;
109 if( InitThread( p_intf ) < 0 )
111 msg_Err( p_intf, "can't initialize intf" );
114 msg_Dbg( p_intf, "intf initialized" );
117 control.mouse.i_x = 0;
118 control.mouse.i_y = 0;
121 while( !p_intf->b_die )
123 vlc_mutex_lock( &p_intf->change_lock );
129 if( p_intf->p_sys->b_still && !p_intf->p_sys->b_inf_still )
131 if( p_intf->p_sys->m_still_time > 0 )
133 /* update remaining still time */
137 p_intf->p_sys->m_still_time -= mtime - mlast;
144 /* still time elasped */
145 input_SetStatus( p_intf->p_sys->p_input,
147 p_intf->p_sys->m_still_time = 0;
148 p_intf->p_sys->b_still = 0;
153 if( p_intf->p_sys->m_still_time != (mtime_t)(-1) )
155 if( p_intf->p_sys->m_still_time )
160 p_intf->p_sys->m_still_time -= mtime - mlast;
162 if( !p_intf->p_sys->m_still_time )
164 input_SetStatus( p_intf->p_sys->p_input,
176 p_vout = vlc_object_find( p_intf->p_sys->p_input,
177 VLC_OBJECT_VOUT, FIND_CHILD );
180 vlc_mutex_lock( &p_vout->change_lock );
182 if( control.mouse.i_x != p_vout->i_mouse_x ||
183 control.mouse.i_y != p_vout->i_mouse_y ||
184 p_vout->i_mouse_button )
188 control.mouse.i_x = p_vout->i_mouse_x;
189 control.mouse.i_y = p_vout->i_mouse_y;
191 if( p_vout->i_mouse_button )
193 control.type = DVDCtrlMouseActivate;
195 msg_Dbg( p_intf, "Activate coordinates: %dx%d",
196 p_vout->i_mouse_x, p_vout->i_mouse_y );
200 control.type = DVDCtrlMouseSelect;
202 msg_Dbg( p_intf, "Select coordinates: %dx%d",
203 p_vout->i_mouse_x, p_vout->i_mouse_y );
205 p_vout->i_mouse_button = 0;
206 vlc_mutex_unlock( &p_vout->change_lock );
208 msg_Dbg( p_intf, "send button" );
210 /* we can safely interact with libdvdplay
211 * with the stream lock */
212 vlc_mutex_lock( &p_intf->p_sys->p_input->stream.stream_lock );
215 dvdplay_button( p_intf->p_sys->p_dvd->vmg, &control );
217 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
220 if( i_activate && p_intf->p_sys->b_still )
222 input_SetStatus( p_intf->p_sys->p_input,
224 p_intf->p_sys->b_still = 0;
225 p_intf->p_sys->b_inf_still = 0;
226 p_intf->p_sys->m_still_time = 0;
231 vlc_mutex_unlock( &p_vout->change_lock );
235 vlc_object_release( p_vout );
238 vlc_mutex_unlock( &p_intf->change_lock );
241 msleep( INTF_IDLE_SLEEP );
244 vlc_object_release( p_intf->p_sys->p_input );
248 /*****************************************************************************
250 *****************************************************************************/
251 static int InitThread( intf_thread_t * p_intf )
253 /* we might need some locking here */
256 input_thread_t * p_input;
259 p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_PARENT );
260 p_dvd = (dvd_data_t*)p_input->p_access_data;
262 p_dvd->p_intf = p_intf;
264 vlc_mutex_lock( &p_intf->change_lock );
266 p_intf->p_sys->p_input = p_input;
267 p_intf->p_sys->p_dvd = p_dvd;
269 vlc_mutex_unlock( &p_intf->change_lock );
279 /*****************************************************************************
280 * dvdIntfStillTime: function provided to demux plugin to request
282 *****************************************************************************/
283 int dvdIntfStillTime( intf_thread_t *p_intf, int i_sec )
285 vlc_mutex_lock( &p_intf->change_lock );
290 p_intf->p_sys->b_still = 1;
291 p_intf->p_sys->b_inf_still = 1;
295 p_intf->p_sys->b_still = 1;
296 p_intf->p_sys->m_still_time = 1000000 * i_sec;
303 p_intf->p_sys->m_still_time = (mtime_t)(-1);
304 msg_Warn( p_intf, "%lld", p_intf->p_sys->m_still_time );
308 p_intf->p_sys->m_still_time = 1000000 * i_sec;
313 vlc_mutex_unlock( &p_intf->change_lock );