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 /* Kill existing input, if any */
145 if( p_intf->p_input != NULL )
147 input_DestroyThread( p_intf->p_input, NULL );
150 /* Open a new input */
151 intf_Msg("Switching to channel %d\n", i_index );
152 p_intf->p_input = input_CreateThread( INPUT_METHOD_TS_VLAN_BCAST, NULL, 0, i_index,
153 p_intf->p_vout, p_main->p_aout, NULL );
154 return( p_intf->p_input == NULL );
157 /*******************************************************************************
158 * intf_ProcessKey: process standard keys
159 *******************************************************************************
160 * This function will process standard keys and return non 0 if the key was
162 *******************************************************************************/
163 int intf_ProcessKey( intf_thread_t *p_intf, int i_key )
167 case 'Q': /* quit order */
169 case 27: /* escape key */
172 case '0': /* source change */
182 if( intf_SelectInput( p_intf, i_key - '0' ) )
184 intf_ErrMsg("error: can not open channel %d\n", i_key - '0');
187 case '+': /* volume + */
190 case '-': /* volume - */
193 case 'M': /* toggle mute */
197 case 'g': /* gamma - */
198 if( (p_intf->p_vout != NULL) && (p_intf->p_vout->f_gamma > -INTF_GAMMA_LIMIT) )
200 vlc_mutex_lock( &p_intf->p_vout->change_lock );
201 p_intf->p_vout->f_gamma -= INTF_GAMMA_STEP;
202 p_intf->p_vout->i_changes |= VOUT_GAMMA_CHANGE;
203 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
206 case 'G': /* gamma + */
207 if( (p_intf->p_vout != NULL) && (p_intf->p_vout->f_gamma < INTF_GAMMA_LIMIT) )
209 vlc_mutex_lock( &p_intf->p_vout->change_lock );
210 p_intf->p_vout->f_gamma += INTF_GAMMA_STEP;
211 p_intf->p_vout->i_changes |= VOUT_GAMMA_CHANGE;
212 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
215 case 'c': /* toggle grayscale */
216 if( p_intf->p_vout != NULL )
218 vlc_mutex_lock( &p_intf->p_vout->change_lock );
219 p_intf->p_vout->b_grayscale = !p_intf->p_vout->b_grayscale;
220 p_intf->p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE;
221 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
224 case ' ': /* toggle info */
225 if( p_intf->p_vout != NULL )
227 vlc_mutex_lock( &p_intf->p_vout->change_lock );
228 p_intf->p_vout->b_info = !p_intf->p_vout->b_info;
229 p_intf->p_vout->i_changes |= VOUT_INFO_CHANGE;
230 vlc_mutex_unlock( &p_intf->p_vout->change_lock );
233 default: /* unknown key */