1 /*******************************************************************************
2 * interface.c: interface access for other threads
4 *******************************************************************************
5 * This library provides basic functions for threads to interact with user
6 * interface, such as command line.
7 *******************************************************************************/
9 /*******************************************************************************
11 *******************************************************************************/
14 #include <netinet/in.h>
15 #include <sys/soundcard.h>
18 #include <X11/extensions/XShm.h>
20 #include <sys/types.h>
27 #include "vlc_thread.h"
34 #include "input_netlist.h"
35 #include "input_vlan.h"
36 #include "decoder_fifo.h"
38 #include "audio_output.h"
39 #include "audio_decoder.h"
42 #include "video_output.h"
43 #include "video_decoder.h"
46 #include "interface.h"
50 /* ?? remove useless headers */
55 static int StartInterface ( intf_thread_t *p_intf );
56 static void EndInterface ( intf_thread_t *p_intf );
58 /*******************************************************************************
60 *******************************************************************************
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 )
70 /* When it is started, interface won't die immediatly */
72 if( StartInterface( p_intf ) ) /* error */
80 /* Flush waiting messages */
84 /* Manage specific interfaces */
85 intf_ManageXConsole( &p_intf->xconsole ); /* X11 console */
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 );
93 /* End of interface thread - the main() function will close all remaining
95 EndInterface( p_intf );
99 /* following functions are local */
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 )
109 int i_thread; /* thread index */
114 /* Empty all threads array */
115 for( i_thread = 0; i_thread < VOUT_MAX_THREADS; i_thread++ )
117 p_intf->pp_vout[i_thread] = NULL;
119 for( i_thread = 0; i_thread < INPUT_MAX_THREADS; i_thread++ )
121 p_intf->pp_input[i_thread] = NULL;
125 intf_DbgMsg("intf debug: not opening X11 console\n");
127 /* Start X11 Console*/
128 if( intf_OpenXConsole( &p_intf->xconsole ) )
130 intf_ErrMsg("intf error: can't open X11 console\n");
136 /* Execute the initialization script (typically spawn an input thread) */
137 if ( (fd = open( INIT_SCRIPT, O_RDONLY )) != -1 )
139 /* Startup script does exist */
141 intf_ExecScript( INIT_SCRIPT );
148 /*******************************************************************************
149 * EndInterface: clean interface after main loop
150 *******************************************************************************
151 * This function destroys specific interfaces and close output devices.
152 *******************************************************************************/
153 static void EndInterface( intf_thread_t *p_intf )
155 int i_thread; /* thread index */
156 boolean_t b_thread; /* flag for remaing threads */
157 int pi_vout_status[VOUT_MAX_THREADS]; /* vout threads status */
161 /* Close X11 console */
162 intf_CloseXConsole( &p_intf->xconsole );
165 /* Destroy all remaining input threads */
166 for( i_thread = 0; i_thread < INPUT_MAX_THREADS; i_thread++ )
168 if( p_intf->pp_input[i_thread] != NULL )
170 input_DestroyThread( p_intf->pp_input[i_thread] );
174 /* Destroy all remaining video output threads - all destruction orders are send,
175 * then all THREAD_OVER status are received */
176 for( i_thread = 0, b_thread = 0; i_thread < VOUT_MAX_THREADS; i_thread++ )
178 if( p_intf->pp_vout[i_thread] != NULL )
180 vout_DestroyThread( p_intf->pp_vout[i_thread], &pi_vout_status[i_thread] );
186 msleep( INTF_IDLE_SLEEP );
188 for( i_thread = 0; i_thread < VOUT_MAX_THREADS; i_thread++ )
190 if( (p_intf->pp_vout[i_thread] != NULL)
191 && (pi_vout_status[i_thread] != THREAD_OVER) )