]> git.sesse.net Git - vlc/blob - plugins/dvdplay/intf.c
a3c4165c8b863dd64923e1f62d445c837bc7cbb7
[vlc] / plugins / dvdplay / intf.c
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 $
6  *
7  * Authors: Stéphane Borel <stef@via.ecp.fr>
8  *
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.
13  * 
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.
18  *
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  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>                                      /* malloc(), free() */
28 #include <string.h>
29 #include <unistd.h>
30
31 #include <vlc/vlc.h>
32 #include <vlc/intf.h>
33
34 #include "stream_control.h"
35 #include "input_ext-intf.h"
36
37 #include "video.h"
38 #include "video_output.h"
39
40 #include "dvd.h"
41
42 /*****************************************************************************
43  * intf_sys_t: description and status of interface
44  *****************************************************************************/
45 struct intf_sys_t
46 {
47     input_thread_t *    p_input;
48     dvd_data_t *        p_dvd;
49
50     vlc_bool_t          b_still;
51     vlc_bool_t          b_inf_still;
52     mtime_t             m_still_time;
53
54 };
55
56 /*****************************************************************************
57  * Local prototypes.
58  *****************************************************************************/
59 static int  InitThread     ( intf_thread_t *p_intf );
60
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 );
65
66
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 )
72 {
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;
76 }
77
78 /*****************************************************************************
79  * intf_Open: initialize dummy interface
80  *****************************************************************************/
81 static int intf_Open( intf_thread_t *p_intf )
82 {
83     /* Allocate instance and initialize some members */
84     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
85     if( p_intf->p_sys == NULL )
86     {
87         return( 1 );
88     };
89
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;
93
94     return( 0 );
95 }
96
97 /*****************************************************************************
98  * intf_Close: destroy dummy interface
99  *****************************************************************************/
100 static void intf_Close( intf_thread_t *p_intf )
101 {
102     /* Destroy structure */
103     free( p_intf->p_sys );
104 }
105
106
107 /*****************************************************************************
108  * intf_Run: main loop
109  *****************************************************************************/
110 static void intf_Run( intf_thread_t *p_intf )
111 {
112     vout_thread_t *     p_vout;
113     dvdplay_ctrl_t      control;
114     mtime_t             mtime = 0;
115     mtime_t             mlast = 0;
116     
117     if( InitThread( p_intf ) < 0 )
118     {
119         msg_Err( p_intf, "can't initialize intf" );
120         return;
121     }
122     msg_Dbg( p_intf, "intf initialized" );
123
124     p_vout = NULL;
125     control.mouse.i_x = 0;
126     control.mouse.i_y = 0;
127     
128     /* Main loop */
129     while( !p_intf->b_die )
130     {
131         vlc_mutex_lock( &p_intf->change_lock );
132
133         /*
134          * still images
135          */
136 #if 1
137         if( p_intf->p_sys->b_still && !p_intf->p_sys->b_inf_still )
138         {
139             if( p_intf->p_sys->m_still_time > 0 )
140             {
141                 /* update remaining still time */
142                 mtime = mdate();
143                 if( mlast )
144                 {
145                     p_intf->p_sys->m_still_time -= mtime - mlast;
146                 }
147
148                 mlast = mtime;
149             }
150             else
151             {
152                 /* still time elasped */
153                 input_SetStatus( p_intf->p_sys->p_input,
154                                  INPUT_STATUS_PLAY );
155                 p_intf->p_sys->m_still_time = 0;
156                 p_intf->p_sys->b_still = 0;
157                 mlast = 0;
158             }
159         }
160 #else
161         if( p_intf->p_sys->m_still_time != (mtime_t)(-1) )
162         {
163             if( p_intf->p_sys->m_still_time )
164             {
165                 mtime = mdate();
166                 if( mlast )
167                 {
168                     p_intf->p_sys->m_still_time -= mtime - mlast;
169                 }
170                 if( !p_intf->p_sys->m_still_time )
171                 {
172                     input_SetStatus( p_intf->p_sys->p_input,
173                                      INPUT_STATUS_PLAY );
174                 }
175                 mlast = mtime;
176             }
177
178         }
179 #endif
180
181         /* 
182          * mouse cursor
183          */
184         p_vout = vlc_object_find( p_intf->p_sys->p_input,
185                                   VLC_OBJECT_VOUT, FIND_CHILD );
186         if( p_vout != NULL )
187         {
188             vlc_mutex_lock( &p_vout->change_lock );
189
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 )
193             {
194                 int i_activate = 0;
195                 
196                 control.mouse.i_x = p_vout->i_mouse_x;
197                 control.mouse.i_y = p_vout->i_mouse_y;
198
199                 if( p_vout->i_mouse_button )
200                 {
201                     control.type = DVDCtrlMouseActivate;
202                     
203                     msg_Dbg( p_intf, "Activate coordinates: %dx%d",
204                                  p_vout->i_mouse_x, p_vout->i_mouse_y );
205                 }
206                 else
207                 {
208                     control.type = DVDCtrlMouseSelect;
209                     
210                     msg_Dbg( p_intf, "Select coordinates: %dx%d",
211                                  p_vout->i_mouse_x, p_vout->i_mouse_y );
212                 }
213                 p_vout->i_mouse_button = 0;
214                 vlc_mutex_unlock( &p_vout->change_lock );
215                 
216                 msg_Dbg( p_intf, "send button" );
217                 
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 );
221                 
222                 i_activate =
223                     dvdplay_button( p_intf->p_sys->p_dvd->vmg, &control );
224                   
225                 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
226                 
227
228                 if( i_activate && p_intf->p_sys->b_still )
229                 {
230                     input_SetStatus( p_intf->p_sys->p_input,
231                                      INPUT_STATUS_PLAY );
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;
235                 }
236             }
237             else
238             {
239                 vlc_mutex_unlock( &p_vout->change_lock );
240             }
241             
242
243             vlc_object_release( p_vout );
244         }
245             
246         vlc_mutex_unlock( &p_intf->change_lock );
247           
248         /* Wait a bit */
249         msleep( INTF_IDLE_SLEEP );
250     }
251     
252     vlc_object_release( p_intf->p_sys->p_input );
253
254 }
255
256 /*****************************************************************************
257  * InitThread:
258  *****************************************************************************/
259 static int InitThread( intf_thread_t * p_intf )
260 {
261     /* we might need some locking here */
262     if( !p_intf->b_die )
263     {
264         input_thread_t * p_input;
265         dvd_data_t * p_dvd;
266         
267         p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_PARENT );
268         p_dvd = (dvd_data_t*)p_input->p_access_data;
269
270         p_dvd->p_intf = p_intf;
271                     
272         vlc_mutex_lock( &p_intf->change_lock );
273     
274         p_intf->p_sys->p_input = p_input;
275         p_intf->p_sys->p_dvd = p_dvd;
276
277         vlc_mutex_unlock( &p_intf->change_lock );
278
279         return 0;
280     }
281     else
282     {
283         return -1;
284     }
285 }
286
287 /*****************************************************************************
288  * dvdIntfStillTime: function provided to demux plugin to request
289  * still images
290  *****************************************************************************/
291 int dvdIntfStillTime( intf_thread_t *p_intf, int i_sec )
292 {
293     vlc_mutex_lock( &p_intf->change_lock );
294 #if 1
295     
296     if( i_sec == 0xff )
297     {
298         p_intf->p_sys->b_still = 1;
299         p_intf->p_sys->b_inf_still = 1;
300     }
301     else if( i_sec > 0 )
302     {
303         p_intf->p_sys->b_still = 1;
304         p_intf->p_sys->m_still_time = 1000000 * i_sec;
305     }
306 #else
307     if( i_sec > 0 )
308     {
309         if( i_sec == 0xff )
310         {
311             p_intf->p_sys->m_still_time = (mtime_t)(-1);
312             msg_Warn( p_intf, "%lld", p_intf->p_sys->m_still_time );
313         }
314         else
315         {
316             p_intf->p_sys->m_still_time = 1000000 * i_sec;
317         }
318         
319     }
320 #endif
321     vlc_mutex_unlock( &p_intf->change_lock );
322
323     return 0;
324 }
325
326