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 *******************************************************************************/
15 #include <netinet/in.h>
16 #include <sys/soundcard.h>
19 #include <X11/extensions/XShm.h>
21 #include <sys/types.h>
31 #include "input_vlan.h"
32 #include "decoder_fifo.h"
34 #include "audio_output.h"
35 #include "audio_decoder.h"
38 #include "video_output.h"
39 #include "video_decoder.h"
42 #include "interface.h"
47 /* ?? remove useless headers */
52 static int StartInterface ( intf_thread_t *p_intf );
53 static void EndInterface ( intf_thread_t *p_intf );
55 /*******************************************************************************
57 *******************************************************************************
59 * - Create an X11 console
60 * - wait for a command and try to execute it
61 * - interpret the order returned after the command execution
62 * - print the messages of the message queue (intf_FlushMsg)
63 * return value: 0 if successful, < 0 otherwise
64 *******************************************************************************/
65 int intf_Run( intf_thread_t *p_intf )
67 /* When it is started, interface won't die immediatly */
69 if( StartInterface( p_intf ) ) /* error */
77 /* Flush waiting messages */
80 /* Manage specific interfaces */
81 intf_ManageXConsole( &p_intf->xconsole ); /* X11 console */
83 /* Sleep to avoid using all CPU - since some interfaces needs to access
84 * keyboard events, a 100ms delay is a good compromise */
85 msleep( INTF_IDLE_SLEEP );
88 /* End of interface thread - the main() function will close all remaining
90 EndInterface( p_intf );
94 /* following functions are local */
96 /*******************************************************************************
97 * StartInterface: prepare interface before main loop
98 *******************************************************************************
99 * This function opens output devices and create specific interfaces. It send
100 * it's own error messages.
101 *******************************************************************************/
102 static int StartInterface( intf_thread_t *p_intf )
104 int i_thread; /* thread index */
109 /* Empty all threads array */
110 for( i_thread = 0; i_thread < VOUT_MAX_THREADS; i_thread++ )
112 p_intf->pp_vout[i_thread] = NULL;
114 for( i_thread = 0; i_thread < INPUT_MAX_THREADS; i_thread++ )
116 p_intf->pp_input[i_thread] = NULL;
119 /* Start X11 Console*/
120 if( intf_OpenXConsole( &p_intf->xconsole ) )
122 intf_ErrMsg("intf error: can't open X11 console\n");
127 /* Execute the initialization script (typically spawn an input thread) */
128 if ( (fd = open( INIT_SCRIPT, O_RDONLY )) != -1 )
130 /* Startup script does exist */
132 intf_ExecScript( "vlc.init" );
139 /*******************************************************************************
140 * EndInterface: clean interface after main loop
141 *******************************************************************************
142 * This function destroys specific interfaces and close output devices.
143 *******************************************************************************/
144 static void EndInterface( intf_thread_t *p_intf )
146 int i_thread; /* thread index */
147 boolean_t b_thread; /* flag for remaing threads */
148 int pi_vout_status[VOUT_MAX_THREADS]; /* vout threads status */
152 /* Close X11 console */
153 intf_CloseXConsole( &p_intf->xconsole );
155 /* Destroy all remaining input threads */
156 for( i_thread = 0; i_thread < INPUT_MAX_THREADS; i_thread++ )
158 if( p_intf->pp_input[i_thread] != NULL )
160 input_DestroyThread( p_intf->pp_input[i_thread] );
164 /* Destroy all remaining video output threads - all destruction orders are send,
165 * then all THREAD_OVER status are received */
166 for( i_thread = 0, b_thread = 0; i_thread < VOUT_MAX_THREADS; i_thread++ )
168 if( p_intf->pp_vout[i_thread] != NULL )
170 vout_DestroyThread( p_intf->pp_vout[i_thread], &pi_vout_status[i_thread] );
176 msleep( INTF_IDLE_SLEEP );
178 for( i_thread = 0; i_thread < VOUT_MAX_THREADS; i_thread++ )
180 if( (p_intf->pp_vout[i_thread] != NULL)
181 && (pi_vout_status[i_thread] != THREAD_OVER) )