]> git.sesse.net Git - vlc/blob - src/interface/interface.c
* Ajout d'un .cvsignore ;
[vlc] / src / interface / interface.c
1 /*******************************************************************************
2  * interface.c: interface access for other threads
3  * (c)1998 VideoLAN
4  *******************************************************************************
5  * This library provides basic functions for threads to interact with user
6  * interface, such as command line.
7  *******************************************************************************/
8
9 /*******************************************************************************
10  * Preamble
11  *******************************************************************************/
12 #include <pthread.h>
13 #include <stdio.h>
14 #include <netinet/in.h>
15 #include <sys/soundcard.h>
16 #include <sys/uio.h>
17 #include <X11/Xlib.h>
18 #include <X11/extensions/XShm.h>
19
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <fcntl.h>
23
24 #include "config.h"
25 #include "common.h"
26 #include "mtime.h"
27 #include "thread.h"
28
29 #include "input.h"
30 #include "input_vlan.h"
31 #include "decoder_fifo.h"
32
33 #include "audio_output.h"
34 #include "audio_decoder.h"
35
36 #include "video.h"
37 #include "video_output.h"
38 #include "video_decoder.h"
39
40 #include "xconsole.h"
41 #include "interface.h"
42 #include "intf_msg.h"
43 #include "intf_cmd.h"
44
45 #include "pgm_data.h"
46 /* ?? remove useless headers */
47
48 /*
49  * Local prototypes
50  */
51 static int  StartInterface  ( intf_thread_t *p_intf );
52 static void EndInterface    ( intf_thread_t *p_intf );
53
54 /*******************************************************************************
55  * intf_Run
56  *******************************************************************************
57  * what it does:
58  *     - Create an X11 console
59  *     - wait for a command and try to execute it
60  *     - interpret the order returned after the command execution
61  *     - print the messages of the message queue (intf_FlushMsg)
62  * return value: 0 if successful, < 0 otherwise
63  *******************************************************************************/
64 int intf_Run( intf_thread_t *p_intf )
65 {
66     /* When it is started, interface won't die immediatly */
67     p_intf->b_die = 0;
68     if( StartInterface( p_intf ) )                                    /* error */
69     {
70         return( 1 );
71     }
72     
73     /* Main loop */
74     while(!p_intf->b_die)
75     {
76         /* Flush waiting messages */
77         intf_FlushMsg();
78
79         /* Manage specific interfaces */
80         intf_ManageXConsole( &p_intf->xconsole );               /* X11 console */
81
82         /* Sleep to avoid using all CPU - since some interfaces needs to access 
83          * keyboard events, a 100ms delay is a good compromise */
84         msleep( INTF_IDLE_SLEEP );
85     }
86
87     /* End of interface thread - the main() function will close all remaining
88      * output threads */
89     EndInterface( p_intf );
90     return ( 0 );
91 }
92
93 /* following functions are local */
94
95 /*******************************************************************************
96  * StartInterface: prepare interface before main loop
97  *******************************************************************************
98  * This function opens output devices and create specific interfaces. It send
99  * it's own error messages.
100  *******************************************************************************/
101 static int StartInterface( intf_thread_t *p_intf )
102 {
103     int i_thread;                                              /* thread index */
104 #ifdef AUTO_SPAWN
105     int fd;
106 #endif
107
108     /* Empty all threads array */
109     for( i_thread = 0; i_thread < VOUT_MAX_THREADS; i_thread++ )
110     {
111         p_intf->pp_vout[i_thread] = NULL;        
112     }
113     for( i_thread = 0; i_thread < INPUT_MAX_THREADS; i_thread++ )
114     {
115         p_intf->pp_input[i_thread] = NULL;        
116     }    
117
118     /* Start X11 Console*/
119     if( intf_OpenXConsole( &p_intf->xconsole ) )
120     {
121         intf_ErrMsg("intf error: can't open X11 console\n");
122         return( 1 );
123     }
124
125 #ifdef AUTO_SPAWN
126     /* Execute the initialization script (typically spawn an input thread) */
127     if ( (fd = open( INIT_SCRIPT, O_RDONLY )) != -1 )
128     {
129         /* Startup script does exist */
130         close( fd );
131         intf_ExecScript( "vlc.init" );
132     }
133 #endif
134
135     return( 0 );
136 }
137
138 /*******************************************************************************
139  * EndInterface: clean interface after main loop
140  *******************************************************************************
141  * This function destroys specific interfaces and close output devices.
142  *******************************************************************************/
143 static void EndInterface( intf_thread_t *p_intf )
144 {
145     int         i_thread;                                      /* thread index */
146     boolean_t   b_thread;                          /* flag for remaing threads */
147     int         pi_vout_status[VOUT_MAX_THREADS];       /* vout threads status */
148     
149     
150     
151     /* Close X11 console */
152     intf_CloseXConsole( &p_intf->xconsole );        
153
154     /* Destroy all remaining input threads */
155     for( i_thread = 0; i_thread < INPUT_MAX_THREADS; i_thread++ )
156     {
157         if( p_intf->pp_input[i_thread] != NULL )
158         {
159             input_DestroyThread( p_intf->pp_input[i_thread] );
160         }        
161     }
162
163     /* Destroy all remaining video output threads - all destruction orders are send,
164      * then all THREAD_OVER status are received */
165     for( i_thread = 0, b_thread = 0; i_thread < VOUT_MAX_THREADS; i_thread++ )
166     {
167         if( p_intf->pp_vout[i_thread] != NULL )
168         {
169             vout_DestroyThread( p_intf->pp_vout[i_thread], &pi_vout_status[i_thread] );
170             b_thread = 1;            
171         }
172     }
173     while( b_thread )
174     {
175         msleep( INTF_IDLE_SLEEP );        
176         b_thread = 0;        
177         for( i_thread = 0; i_thread < VOUT_MAX_THREADS; i_thread++ )
178         {
179             if( (p_intf->pp_vout[i_thread] != NULL) 
180                 && (pi_vout_status[i_thread] != THREAD_OVER) )
181             {
182                 b_thread = 1;
183             }     
184         }
185     }
186     
187
188 }