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 *******************************************************************************/
16 #include <sys/types.h>
17 #include <sys/uio.h> /* for input.h */
22 #include "vlc_thread.h"
25 #include "interface.h"
27 #include "intf_console.h"
30 #include "video_output.h"
34 /*******************************************************************************
35 * intf_Create: prepare interface before main loop
36 *******************************************************************************
37 * This function opens output devices and create specific interfaces. It send
38 * it's own error messages.
39 *******************************************************************************/
40 intf_thread_t* intf_Create( void )
42 intf_thread_t *p_intf;
44 /* Allocate structure */
45 p_intf = malloc( sizeof( intf_thread_t ) );
48 intf_ErrMsg("error: %s\n", strerror( ENOMEM ) );
52 /* Initialize structure */
54 p_intf->p_vout = NULL;
55 p_intf->p_input = NULL;
57 /* Start interfaces */
58 p_intf->p_console = intf_ConsoleCreate();
59 if( p_intf->p_console == NULL )
61 intf_ErrMsg("error: can't create control console\n");
65 if( intf_SysCreate( p_intf ) )
67 intf_ErrMsg("error: can't create interface\n");
68 intf_ConsoleDestroy( p_intf->p_console );
73 intf_Msg("Interface initialized\n");
77 /*******************************************************************************
79 *******************************************************************************
80 * Initialization script and main interface loop.
81 *******************************************************************************/
82 void intf_Run( intf_thread_t *p_intf )
84 /* Execute the initialization script - if a positive number is returned,
85 * the script could be executed but failed */
86 if( intf_ExecScript( main_GetPszVariable( INTF_INIT_SCRIPT_VAR, INTF_INIT_SCRIPT_DEFAULT ) ) > 0 )
88 intf_ErrMsg("warning: error(s) during startup script\n");
94 /* Flush waiting messages */
97 /* Manage specific interface */
98 intf_SysManage( p_intf );
100 /* Check attached threads status */
101 if( (p_intf->p_vout != NULL) && p_intf->p_vout->b_error )
103 //?? add aout error detection
106 if( (p_intf->p_input != NULL) && p_intf->p_input->b_error )
108 input_DestroyThread( p_intf->p_input, NULL );
109 p_intf->p_input = NULL;
110 intf_DbgMsg("Input thread destroyed\n");
113 /* Sleep to avoid using all CPU - since some interfaces needs to access
114 * keyboard events, a 100ms delay is a good compromise */
115 msleep( INTF_IDLE_SLEEP );
119 /*******************************************************************************
120 * intf_Destroy: clean interface after main loop
121 *******************************************************************************
122 * This function destroys specific interfaces and close output devices.
123 *******************************************************************************/
124 void intf_Destroy( intf_thread_t *p_intf )
126 /* Destroy interfaces */
127 intf_SysDestroy( p_intf );
128 intf_ConsoleDestroy( p_intf->p_console );
134 /*******************************************************************************
135 * intf_SelectInput: change input stream
136 *******************************************************************************
137 * Kill existing input, if any, and try to open a new one, using an input
138 * configuration table.
139 *******************************************************************************/
140 int intf_SelectInput( intf_thread_t * p_intf, int i_index )
144 /* If VLANs are not active, return with an error */
145 if( !p_main->b_vlans )
147 intf_ErrMsg("error: VLANs are not activated\n");
151 /* Kill existing input, if any */
152 if( p_intf->p_input != NULL )
154 input_DestroyThread( p_intf->p_input, NULL );
157 /* Open a new input */
158 intf_Msg("Switching to channel %d\n", i_index );
159 p_intf->p_input = input_CreateThread( INPUT_METHOD_TS_VLAN_BCAST, NULL, 0, i_index,
160 p_intf->p_vout, p_main->p_aout, NULL );
161 return( p_intf->p_input == NULL );
164 /*******************************************************************************
165 * intf_ProcessKey: process standard keys
166 *******************************************************************************
167 * This function will process standard keys and return non 0 if the key was
169 *******************************************************************************/
170 int intf_ProcessKey( intf_thread_t *p_intf, int i_key )
174 case 'Q': /* quit order */
176 case 27: /* escape key */
179 case '0': /* source change */
189 if( intf_SelectInput( p_intf, i_key - '0' ) )
191 intf_ErrMsg("error: can not open channel %d\n", i_key - '0');
194 case '+': /* volume + */
197 case '-': /* volume - */
200 case 'M': /* toggle mute */
204 case 'g': /* gamma - */
205 if( (p_intf->p_vout != NULL) && (p_intf->p_vout->f_gamma > -INTF_GAMMA_LIMIT) )
207 vlc_mutex_lock( &p_intf->p_vout->change_lock );
208 p_intf->p_vout->f_gamma -= INTF_GAMMA_STEP;
209 p_intf->p_vout->i_changes |= VOUT_GAMMA_CHANGE;
210 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
213 case 'G': /* gamma + */
214 if( (p_intf->p_vout != NULL) && (p_intf->p_vout->f_gamma < INTF_GAMMA_LIMIT) )
216 vlc_mutex_lock( &p_intf->p_vout->change_lock );
217 p_intf->p_vout->f_gamma += INTF_GAMMA_STEP;
218 p_intf->p_vout->i_changes |= VOUT_GAMMA_CHANGE;
219 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
222 case 'c': /* toggle grayscale */
223 if( p_intf->p_vout != NULL )
225 vlc_mutex_lock( &p_intf->p_vout->change_lock );
226 p_intf->p_vout->b_grayscale = !p_intf->p_vout->b_grayscale;
227 p_intf->p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
228 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
231 case ' ': /* toggle interface */
232 if( p_intf->p_vout != NULL )
234 vlc_mutex_lock( &p_intf->p_vout->change_lock );
235 p_intf->p_vout->b_interface = !p_intf->p_vout->b_interface;
236 p_intf->p_vout->i_changes |= VOUT_INTF_CHANGE;
237 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
240 case 'i': /* toggle info */
241 if( p_intf->p_vout != NULL )
243 vlc_mutex_lock( &p_intf->p_vout->change_lock );
244 p_intf->p_vout->b_info = !p_intf->p_vout->b_info;
245 p_intf->p_vout->i_changes |= VOUT_INFO_CHANGE;
246 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
249 case 's': /* toggle scaling */
250 if( p_intf->p_vout != NULL )
252 vlc_mutex_lock( &p_intf->p_vout->change_lock );
253 p_intf->p_vout->b_scale = !p_intf->p_vout->b_scale;
254 p_intf->p_vout->i_changes |= VOUT_SCALE_CHANGE;
255 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
258 default: /* unknown key */