]> git.sesse.net Git - vlc/blob - modules/access/dvdplay/intf.c
* ./modules/*: moved plugins to the new tree. Yet untested builds include
[vlc] / modules / access / 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/08/04 17:23:42 sam 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 void RunIntf        ( intf_thread_t *p_intf );
63
64 /*****************************************************************************
65  * OpenIntf: initialize dummy interface
66  *****************************************************************************/
67 int E_(OpenIntf) ( vlc_object_t *p_this )
68 {
69     intf_thread_t *p_intf = (intf_thread_t *)p_this;
70
71     /* Allocate instance and initialize some members */
72     p_intf->p_sys = malloc( sizeof( intf_sys_t ) );
73     if( p_intf->p_sys == NULL )
74     {
75         return( 1 );
76     };
77
78     p_intf->pf_run = RunIntf;
79
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;
83
84     return( 0 );
85 }
86
87 /*****************************************************************************
88  * CloseIntf: destroy dummy interface
89  *****************************************************************************/
90 void E_(CloseIntf) ( vlc_object_t *p_this )
91 {
92     intf_thread_t *p_intf = (intf_thread_t *)p_this;
93
94     /* Destroy structure */
95     free( p_intf->p_sys );
96 }
97
98
99 /*****************************************************************************
100  * RunIntf: main loop
101  *****************************************************************************/
102 static void RunIntf( intf_thread_t *p_intf )
103 {
104     vout_thread_t *     p_vout;
105     dvdplay_ctrl_t      control;
106     mtime_t             mtime = 0;
107     mtime_t             mlast = 0;
108     
109     if( InitThread( p_intf ) < 0 )
110     {
111         msg_Err( p_intf, "can't initialize intf" );
112         return;
113     }
114     msg_Dbg( p_intf, "intf initialized" );
115
116     p_vout = NULL;
117     control.mouse.i_x = 0;
118     control.mouse.i_y = 0;
119     
120     /* Main loop */
121     while( !p_intf->b_die )
122     {
123         vlc_mutex_lock( &p_intf->change_lock );
124
125         /*
126          * still images
127          */
128 #if 1
129         if( p_intf->p_sys->b_still && !p_intf->p_sys->b_inf_still )
130         {
131             if( p_intf->p_sys->m_still_time > 0 )
132             {
133                 /* update remaining still time */
134                 mtime = mdate();
135                 if( mlast )
136                 {
137                     p_intf->p_sys->m_still_time -= mtime - mlast;
138                 }
139
140                 mlast = mtime;
141             }
142             else
143             {
144                 /* still time elasped */
145                 input_SetStatus( p_intf->p_sys->p_input,
146                                  INPUT_STATUS_PLAY );
147                 p_intf->p_sys->m_still_time = 0;
148                 p_intf->p_sys->b_still = 0;
149                 mlast = 0;
150             }
151         }
152 #else
153         if( p_intf->p_sys->m_still_time != (mtime_t)(-1) )
154         {
155             if( p_intf->p_sys->m_still_time )
156             {
157                 mtime = mdate();
158                 if( mlast )
159                 {
160                     p_intf->p_sys->m_still_time -= mtime - mlast;
161                 }
162                 if( !p_intf->p_sys->m_still_time )
163                 {
164                     input_SetStatus( p_intf->p_sys->p_input,
165                                      INPUT_STATUS_PLAY );
166                 }
167                 mlast = mtime;
168             }
169
170         }
171 #endif
172
173         /* 
174          * mouse cursor
175          */
176         p_vout = vlc_object_find( p_intf->p_sys->p_input,
177                                   VLC_OBJECT_VOUT, FIND_CHILD );
178         if( p_vout != NULL )
179         {
180             vlc_mutex_lock( &p_vout->change_lock );
181
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 )
185             {
186                 int i_activate = 0;
187                 
188                 control.mouse.i_x = p_vout->i_mouse_x;
189                 control.mouse.i_y = p_vout->i_mouse_y;
190
191                 if( p_vout->i_mouse_button )
192                 {
193                     control.type = DVDCtrlMouseActivate;
194                     
195                     msg_Dbg( p_intf, "Activate coordinates: %dx%d",
196                                  p_vout->i_mouse_x, p_vout->i_mouse_y );
197                 }
198                 else
199                 {
200                     control.type = DVDCtrlMouseSelect;
201                     
202                     msg_Dbg( p_intf, "Select coordinates: %dx%d",
203                                  p_vout->i_mouse_x, p_vout->i_mouse_y );
204                 }
205                 p_vout->i_mouse_button = 0;
206                 vlc_mutex_unlock( &p_vout->change_lock );
207                 
208                 msg_Dbg( p_intf, "send button" );
209                 
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 );
213                 
214                 i_activate =
215                     dvdplay_button( p_intf->p_sys->p_dvd->vmg, &control );
216                   
217                 vlc_mutex_unlock( &p_intf->p_sys->p_input->stream.stream_lock );
218                 
219
220                 if( i_activate && p_intf->p_sys->b_still )
221                 {
222                     input_SetStatus( p_intf->p_sys->p_input,
223                                      INPUT_STATUS_PLAY );
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;
227                 }
228             }
229             else
230             {
231                 vlc_mutex_unlock( &p_vout->change_lock );
232             }
233             
234
235             vlc_object_release( p_vout );
236         }
237             
238         vlc_mutex_unlock( &p_intf->change_lock );
239           
240         /* Wait a bit */
241         msleep( INTF_IDLE_SLEEP );
242     }
243     
244     vlc_object_release( p_intf->p_sys->p_input );
245
246 }
247
248 /*****************************************************************************
249  * InitThread:
250  *****************************************************************************/
251 static int InitThread( intf_thread_t * p_intf )
252 {
253     /* we might need some locking here */
254     if( !p_intf->b_die )
255     {
256         input_thread_t * p_input;
257         dvd_data_t * p_dvd;
258         
259         p_input = vlc_object_find( p_intf, VLC_OBJECT_INPUT, FIND_PARENT );
260         p_dvd = (dvd_data_t*)p_input->p_access_data;
261
262         p_dvd->p_intf = p_intf;
263                     
264         vlc_mutex_lock( &p_intf->change_lock );
265     
266         p_intf->p_sys->p_input = p_input;
267         p_intf->p_sys->p_dvd = p_dvd;
268
269         vlc_mutex_unlock( &p_intf->change_lock );
270
271         return 0;
272     }
273     else
274     {
275         return -1;
276     }
277 }
278
279 /*****************************************************************************
280  * dvdIntfStillTime: function provided to demux plugin to request
281  * still images
282  *****************************************************************************/
283 int dvdIntfStillTime( intf_thread_t *p_intf, int i_sec )
284 {
285     vlc_mutex_lock( &p_intf->change_lock );
286 #if 1
287     
288     if( i_sec == 0xff )
289     {
290         p_intf->p_sys->b_still = 1;
291         p_intf->p_sys->b_inf_still = 1;
292     }
293     else if( i_sec > 0 )
294     {
295         p_intf->p_sys->b_still = 1;
296         p_intf->p_sys->m_still_time = 1000000 * i_sec;
297     }
298 #else
299     if( i_sec > 0 )
300     {
301         if( i_sec == 0xff )
302         {
303             p_intf->p_sys->m_still_time = (mtime_t)(-1);
304             msg_Warn( p_intf, "%lld", p_intf->p_sys->m_still_time );
305         }
306         else
307         {
308             p_intf->p_sys->m_still_time = 1000000 * i_sec;
309         }
310         
311     }
312 #endif
313     vlc_mutex_unlock( &p_intf->change_lock );
314
315     return 0;
316 }
317
318