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>
30 #include "input_vlan.h"
31 #include "decoder_fifo.h"
33 #include "audio_output.h"
34 #include "audio_decoder.h"
37 #include "video_output.h"
38 #include "video_decoder.h"
41 #include "interface.h"
46 /* ?? remove useless headers */
51 static int StartInterface ( intf_thread_t *p_intf );
52 static void EndInterface ( intf_thread_t *p_intf );
54 /*******************************************************************************
56 *******************************************************************************
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 )
66 /* When it is started, interface won't die immediatly */
68 if( StartInterface( p_intf ) ) /* error */
76 /* Flush waiting messages */
79 /* Manage specific interfaces */
80 intf_ManageXConsole( &p_intf->xconsole ); /* X11 console */
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 );
87 /* End of interface thread - the main() function will close all remaining
89 EndInterface( p_intf );
93 /* following functions are local */
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 )
103 int i_thread; /* thread index */
108 /* Empty all threads array */
109 for( i_thread = 0; i_thread < VOUT_MAX_THREADS; i_thread++ )
111 p_intf->pp_vout[i_thread] = NULL;
113 for( i_thread = 0; i_thread < INPUT_MAX_THREADS; i_thread++ )
115 p_intf->pp_input[i_thread] = NULL;
118 /* Start X11 Console*/
119 if( intf_OpenXConsole( &p_intf->xconsole ) )
121 intf_ErrMsg("intf error: can't open X11 console\n");
126 /* Execute the initialization script (typically spawn an input thread) */
127 if ( (fd = open( INIT_SCRIPT, O_RDONLY )) != -1 )
129 /* Startup script does exist */
131 intf_ExecScript( "vlc.init" );
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 )
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 */
151 /* Close X11 console */
152 intf_CloseXConsole( &p_intf->xconsole );
154 /* Destroy all remaining input threads */
155 for( i_thread = 0; i_thread < INPUT_MAX_THREADS; i_thread++ )
157 if( p_intf->pp_input[i_thread] != NULL )
159 input_DestroyThread( p_intf->pp_input[i_thread] );
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++ )
167 if( p_intf->pp_vout[i_thread] != NULL )
169 vout_DestroyThread( p_intf->pp_vout[i_thread], &pi_vout_status[i_thread] );
175 msleep( INTF_IDLE_SLEEP );
177 for( i_thread = 0; i_thread < VOUT_MAX_THREADS; i_thread++ )
179 if( (p_intf->pp_vout[i_thread] != NULL)
180 && (pi_vout_status[i_thread] != THREAD_OVER) )