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"
35 /*******************************************************************************
36 * intf_Create: prepare interface before main loop
37 *******************************************************************************
38 * This function opens output devices and create specific interfaces. It send
39 * it's own error messages.
40 *******************************************************************************/
41 intf_thread_t* intf_Create( void )
43 intf_thread_t *p_intf;
45 /* Allocate structure */
46 p_intf = malloc( sizeof( intf_thread_t ) );
49 intf_ErrMsg("error: %s\n", strerror( ENOMEM ) );
53 /* Initialize structure */
55 p_intf->p_vout = NULL;
56 p_intf->p_input = NULL;
58 /* Start interfaces */
59 p_intf->p_console = intf_ConsoleCreate();
60 if( p_intf->p_console == NULL )
62 intf_ErrMsg("error: can't create control console\n");
66 if( intf_SysCreate( p_intf ) )
68 intf_ErrMsg("error: can't create interface\n");
69 intf_ConsoleDestroy( p_intf->p_console );
74 intf_Msg("Interface initialized\n");
78 /*******************************************************************************
80 *******************************************************************************
81 * Initialization script and main interface loop.
82 *******************************************************************************/
83 void intf_Run( intf_thread_t *p_intf )
85 /* Execute the initialization script - if a positive number is returned,
86 * the script could be executed but failed */
87 if( intf_ExecScript( main_GetPszVariable( INTF_INIT_SCRIPT_VAR, INTF_INIT_SCRIPT_DEFAULT ) ) > 0 )
89 intf_ErrMsg("warning: error(s) during startup script\n");
95 /* Flush waiting messages */
98 /* Manage specific interface */
99 intf_SysManage( p_intf );
101 /* Check attached threads status */
102 if( (p_intf->p_vout != NULL) && p_intf->p_vout->b_error )
104 //?? add aout error detection
107 if( (p_intf->p_input != NULL) && p_intf->p_input->b_error )
109 input_DestroyThread( p_intf->p_input /*, NULL */ );
110 p_intf->p_input = NULL;
111 intf_DbgMsg("Input thread destroyed\n");
114 /* Sleep to avoid using all CPU - since some interfaces needs to access
115 * keyboard events, a 100ms delay is a good compromise */
116 msleep( INTF_IDLE_SLEEP );
120 /*******************************************************************************
121 * intf_Destroy: clean interface after main loop
122 *******************************************************************************
123 * This function destroys specific interfaces and close output devices.
124 *******************************************************************************/
125 void intf_Destroy( intf_thread_t *p_intf )
127 /* Destroy interfaces */
128 intf_SysDestroy( p_intf );
129 intf_ConsoleDestroy( p_intf->p_console );
135 /*******************************************************************************
136 * intf_SelectInput: change input stream
137 *******************************************************************************
138 * Kill existing input, if any, and try to open a new one. If p_cfg is NULL,
139 * no new input will be openned.
140 *******************************************************************************/
141 int intf_SelectInput( intf_thread_t * p_intf, input_cfg_t *p_cfg )
143 intf_DbgMsg("0x%x\n", p_intf );
145 /* Kill existing input, if any */
146 if( p_intf->p_input != NULL )
148 input_DestroyThread( p_intf->p_input /*??, NULL*/ );
149 p_intf->p_input = NULL;
155 p_intf->p_input = input_CreateThread( p_cfg /*??, NULL*/ );
158 return( (p_cfg != NULL) && (p_intf->p_input == NULL) );
161 /*******************************************************************************
162 * intf_ProcessKey: process standard keys
163 *******************************************************************************
164 * This function will process standard keys and return non 0 if the key was
166 *******************************************************************************/
167 int intf_ProcessKey( intf_thread_t *p_intf, int i_key )
171 case 'Q': /* quit order */
176 case '0': /* source change */
188 case '+': /* volume + */
191 case '-': /* volume - */
194 case 'M': /* toggle mute */
198 case 'g': /* gamma - */
199 if( (p_intf->p_vout != NULL) && (p_intf->p_vout->f_gamma > -INTF_GAMMA_LIMIT) )
201 vlc_mutex_lock( &p_intf->p_vout->change_lock );
202 p_intf->p_vout->f_gamma -= INTF_GAMMA_STEP;
203 p_intf->p_vout->i_changes |= VOUT_GAMMA_CHANGE;
204 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
207 case 'G': /* gamma + */
208 if( (p_intf->p_vout != NULL) && (p_intf->p_vout->f_gamma < INTF_GAMMA_LIMIT) )
210 vlc_mutex_lock( &p_intf->p_vout->change_lock );
211 p_intf->p_vout->f_gamma += INTF_GAMMA_STEP;
212 p_intf->p_vout->i_changes |= VOUT_GAMMA_CHANGE;
213 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
216 case 'c': /* toggle grayscale */
217 if( p_intf->p_vout != NULL )
219 vlc_mutex_lock( &p_intf->p_vout->change_lock );
220 p_intf->p_vout->b_grayscale = !p_intf->p_vout->b_grayscale;
221 p_intf->p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
222 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
225 case 'x': /* horizontal aspect ratio - */
226 if( (p_intf->p_vout != NULL) && (p_intf->p_vout->i_horizontal_scale > -INTF_SCALE_LIMIT) )
228 vlc_mutex_lock( &p_intf->p_vout->change_lock );
229 p_intf->p_vout->i_horizontal_scale--;
230 p_intf->p_vout->i_changes |= VOUT_RATIO_CHANGE;
231 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
234 case 'X': /* horizontal aspect ratio + */
235 if( (p_intf->p_vout != NULL) && (p_intf->p_vout->i_horizontal_scale < INTF_SCALE_LIMIT) )
237 vlc_mutex_lock( &p_intf->p_vout->change_lock );
238 p_intf->p_vout->i_horizontal_scale++;
239 p_intf->p_vout->i_changes |= VOUT_RATIO_CHANGE;
240 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
243 case 'y': /* vertical aspect ratio - */
244 if( (p_intf->p_vout != NULL) && (p_intf->p_vout->i_vertical_scale > -INTF_SCALE_LIMIT) )
246 vlc_mutex_lock( &p_intf->p_vout->change_lock );
247 p_intf->p_vout->i_vertical_scale--;
248 p_intf->p_vout->i_changes |= VOUT_RATIO_CHANGE;
249 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
252 case 'Y': /* horizontal aspect ratio + */
253 if( (p_intf->p_vout != NULL) && (p_intf->p_vout->i_vertical_scale < INTF_SCALE_LIMIT) )
255 vlc_mutex_lock( &p_intf->p_vout->change_lock );
256 p_intf->p_vout->i_vertical_scale++;
257 p_intf->p_vout->i_changes |= VOUT_RATIO_CHANGE;
258 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
261 case 'f': /* toggle fullscreen */
264 case ' ': /* toggle info */
265 if( p_intf->p_vout != NULL )
267 vlc_mutex_lock( &p_intf->p_vout->change_lock );
268 p_intf->p_vout->b_info = !p_intf->p_vout->b_info;
269 p_intf->p_vout->i_changes |= VOUT_INFO_CHANGE;
270 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
273 default: /* unknown key */