]> git.sesse.net Git - vlc/blob - src/interface/interface.c
* Makefile : ajout du nouveau d�codeur (comment�) ;
[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 <stdio.h>
13 #include <unistd.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 "vlc_thread.h"
28 #include "thread.h"
29 #include "debug.h"
30
31 #include "intf_msg.h"
32
33 #include "input.h"
34 #include "input_netlist.h"
35 #include "input_vlan.h"
36 #include "decoder_fifo.h"
37
38 #include "audio_output.h"
39 #include "audio_decoder.h"
40
41 #include "video.h"
42 #include "video_output.h"
43 #include "video_decoder.h"
44
45 #include "xconsole.h"
46 #include "interface.h"
47 #include "intf_cmd.h"
48
49 #include "pgm_data.h"
50 /* ?? remove useless headers */
51
52 /*
53  * Local prototypes
54  */
55 static int  StartInterface  ( intf_thread_t *p_intf );
56 static void EndInterface    ( intf_thread_t *p_intf );
57
58 /*******************************************************************************
59  * intf_Run
60  *******************************************************************************
61  * what it does:
62  *     - Create an X11 console
63  *     - wait for a command and try to execute it
64  *     - interpret the order returned after the command execution
65  *     - print the messages of the message queue (intf_FlushMsg)
66  * return value: 0 if successful, < 0 otherwise
67  *******************************************************************************/
68 int intf_Run( intf_thread_t *p_intf )
69 {
70     /* When it is started, interface won't die immediatly */
71     p_intf->b_die = 0;
72     if( StartInterface( p_intf ) )                                    /* error */
73     {
74         return( 1 );
75     }
76     
77     /* Main loop */
78     while(!p_intf->b_die)
79     {
80         /* Flush waiting messages */
81         intf_FlushMsg();
82
83 #ifndef FRAMEBUFFER
84         /* Manage specific interfaces */
85         intf_ManageXConsole( &p_intf->xconsole );               /* X11 console */
86 #endif
87
88         /* Sleep to avoid using all CPU - since some interfaces needs to access 
89          * keyboard events, a 100ms delay is a good compromise */
90         msleep( INTF_IDLE_SLEEP );
91     }
92
93     /* End of interface thread - the main() function will close all remaining
94      * output threads */
95     EndInterface( p_intf );
96     return ( 0 );
97 }
98
99 /* following functions are local */
100
101 /*******************************************************************************
102  * StartInterface: prepare interface before main loop
103  *******************************************************************************
104  * This function opens output devices and create specific interfaces. It send
105  * it's own error messages.
106  *******************************************************************************/
107 static int StartInterface( intf_thread_t *p_intf )
108 {
109     int i_thread;                                              /* thread index */
110 #ifdef INIT_SCRIPT
111     int fd;
112 #endif
113
114 #if 0
115     /* Empty all threads array */
116     for( i_thread = 0; i_thread < VOUT_MAX_THREADS; i_thread++ )
117     {
118         p_intf->pp_vout[i_thread] = NULL;        
119     }
120 #endif
121     for( i_thread = 0; i_thread < INPUT_MAX_THREADS; i_thread++ )
122     {
123         p_intf->pp_input[i_thread] = NULL;        
124     }    
125
126 #ifdef FRAMEBUFFER
127     intf_DbgMsg("intf debug: not opening X11 console\n");
128 #else
129     /* Start X11 Console*/
130     if( intf_OpenXConsole( &p_intf->xconsole ) )
131     {
132         intf_ErrMsg("intf error: can't open X11 console\n");
133         return( 1 );
134     }
135 #endif
136
137 #ifdef INIT_SCRIPT
138     /* Execute the initialization script (typically spawn an input thread) */
139     if ( (fd = open( INIT_SCRIPT, O_RDONLY )) != -1 )
140     {
141         /* Startup script does exist */
142         close( fd );
143         intf_ExecScript( INIT_SCRIPT );
144     }
145 #endif
146
147     return( 0 );
148 }
149
150 /*******************************************************************************
151  * EndInterface: clean interface after main loop
152  *******************************************************************************
153  * This function destroys specific interfaces and close output devices.
154  *******************************************************************************/
155 static void EndInterface( intf_thread_t *p_intf )
156 {
157     int         i_thread;                                      /* thread index */
158     boolean_t   b_thread;                          /* flag for remaing threads */
159     int         pi_vout_status[VOUT_MAX_THREADS];       /* vout threads status */
160     
161     
162 #ifndef FRAMEBUFFER    
163     /* Close X11 console */
164     intf_CloseXConsole( &p_intf->xconsole );        
165 #endif
166
167     /* Destroy all remaining input threads */
168     for( i_thread = 0; i_thread < INPUT_MAX_THREADS; i_thread++ )
169     {
170         if( p_intf->pp_input[i_thread] != NULL )
171         {
172             input_DestroyThread( p_intf->pp_input[i_thread] );
173         }        
174     }
175
176 #if 0
177     /* Destroy all remaining video output threads - all destruction orders are send,
178      * then all THREAD_OVER status are received */
179     for( i_thread = 0, b_thread = 0; i_thread < VOUT_MAX_THREADS; i_thread++ )
180     {
181         if( p_intf->pp_vout[i_thread] != NULL )
182         {
183             vout_DestroyThread( p_intf->pp_vout[i_thread], &pi_vout_status[i_thread] );
184             b_thread = 1;            
185         }
186     }
187     while( b_thread )
188     {
189         msleep( INTF_IDLE_SLEEP );        
190         b_thread = 0;        
191         for( i_thread = 0; i_thread < VOUT_MAX_THREADS; i_thread++ )
192         {
193             if( (p_intf->pp_vout[i_thread] != NULL) 
194                 && (pi_vout_status[i_thread] != THREAD_OVER) )
195             {
196                 b_thread = 1;
197             }     
198         }
199     }
200 #endif
201
202 }