]> git.sesse.net Git - vlc/blob - src/interface/interface.c
Resize qui fonctionne.
[vlc] / src / interface / interface.c
1 /*******************************************************************************
2  * interface.c: interface access for other threads
3  * (c)1998 VideoLAN
4  *******************************************************************************
5  * This library provides basic functions for threads to interact with user
6  * interface, such as command line.
7  *******************************************************************************/
8
9 /*******************************************************************************
10  * Preamble
11  *******************************************************************************/
12 #include <errno.h>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <sys/types.h>
17 #include <sys/uio.h>                                        /* for input.h */
18
19 #include "config.h"
20 #include "common.h"
21 #include "mtime.h"
22 #include "vlc_thread.h"
23 #include "input.h"
24 #include "intf_msg.h"
25 #include "interface.h"
26 #include "intf_cmd.h"
27 #include "intf_console.h"
28 #include "main.h"
29 #include "video.h"
30 #include "video_output.h"
31
32 #include "intf_sys.h"
33
34
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 )
42 {    
43     intf_thread_t *p_intf;                                        
44
45     /* Allocate structure */
46     p_intf = malloc( sizeof( intf_thread_t ) );
47     if( !p_intf )
48     {
49         intf_ErrMsg("error: %s\n", strerror( ENOMEM ) );        
50         return( NULL );
51     }
52
53     /* Initialize structure */
54     p_intf->b_die =     0;    
55     p_intf->p_vout =    NULL;
56     p_intf->p_input =   NULL;   
57
58     /* Start interfaces */
59     p_intf->p_console = intf_ConsoleCreate();
60     if( p_intf->p_console == NULL )
61     {
62         intf_ErrMsg("error: can't create control console\n");
63         free( p_intf );
64         return( NULL );
65     }
66     if( intf_SysCreate( p_intf ) )
67     {
68         intf_ErrMsg("error: can't create interface\n");
69         intf_ConsoleDestroy( p_intf->p_console );
70         free( p_intf );
71         return( NULL );
72     }   
73
74     intf_Msg("Interface initialized\n");    
75     return( p_intf );
76 }
77
78 /*******************************************************************************
79  * intf_Run
80  *******************************************************************************
81  * Initialization script and main interface loop.
82  *******************************************************************************/
83 void intf_Run( intf_thread_t *p_intf )
84
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 )
88     {
89         intf_ErrMsg("warning: error(s) during startup script\n");
90     }
91
92     /* Main loop */
93     while(!p_intf->b_die)
94     {
95         /* Flush waiting messages */
96         intf_FlushMsg();
97
98         /* Manage specific interface */
99         intf_SysManage( p_intf );
100
101         /* Check attached threads status */
102         if( (p_intf->p_vout != NULL) && p_intf->p_vout->b_error )
103         {
104             //?? add aout error detection
105             p_intf->b_die = 1;            
106         }    
107         if( (p_intf->p_input != NULL) && p_intf->p_input->b_error )
108         {
109             input_DestroyThread( p_intf->p_input /*, NULL */ );            
110             p_intf->p_input = NULL;            
111             intf_DbgMsg("Input thread destroyed\n");            
112         }
113
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 );
117     }
118 }
119
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 )
126 {
127     /* Destroy interfaces */
128     intf_SysDestroy( p_intf );
129     intf_ConsoleDestroy( p_intf->p_console );
130
131     /* Free structure */
132     free( p_intf );
133 }
134
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 )
142 {
143     intf_DbgMsg("0x%x\n", p_intf );
144     
145     /* Kill existing input, if any */
146     if( p_intf->p_input != NULL )
147     {        
148         input_DestroyThread( p_intf->p_input /*??, NULL*/ );
149         p_intf->p_input = NULL;        
150     }
151     
152     /* Open new one */
153     if( p_cfg != NULL )
154     {        
155         p_intf->p_input = input_CreateThread( p_cfg /*??, NULL*/ );    
156     }
157     
158     return( (p_cfg != NULL) && (p_intf->p_input == NULL) );    
159 }
160
161 /*******************************************************************************
162  * intf_ProcessKey: process standard keys
163  *******************************************************************************
164  * This function will process standard keys and return non 0 if the key was
165  * unknown.
166  *******************************************************************************/
167 int intf_ProcessKey( intf_thread_t *p_intf, int i_key )
168 {
169     switch( i_key )
170     {
171     case 'Q':                                                    /* quit order */
172     case 'q':
173     case 27:
174         p_intf->b_die = 1;
175         break;  
176     case '0':                                                 /* source change */
177     case '1':
178     case '2':
179     case '3':
180     case '4':
181     case '5':
182     case '6':
183     case '7':
184     case '8':
185     case '9':                    
186         // ??
187         break;
188     case '+':                                                      /* volume + */
189         // ??
190         break;
191     case '-':                                                      /* volume - */
192         // ??
193         break;
194     case 'M':                                                   /* toggle mute */
195     case 'm':                    
196         // ??
197         break;      
198     case 'g':                                                       /* gamma - */
199         if( (p_intf->p_vout != NULL) && (p_intf->p_vout->f_gamma > -INTF_GAMMA_LIMIT) )
200         {
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 );
205         }                    
206         break;                                        
207     case 'G':                                                       /* gamma + */
208         if( (p_intf->p_vout != NULL) && (p_intf->p_vout->f_gamma < INTF_GAMMA_LIMIT) )
209         {       
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 );
214         }                    
215         break;  
216     case 'c':                                              /* toggle grayscale */
217         if( p_intf->p_vout != NULL )
218         {
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 );      
223         }
224         break;  
225     case ' ':                                                   /* toggle info */
226         if( p_intf->p_vout != NULL )
227         {
228             vlc_mutex_lock( &p_intf->p_vout->change_lock );                        
229             p_intf->p_vout->b_info     = !p_intf->p_vout->b_info;                    
230             p_intf->p_vout->i_changes |= VOUT_INFO_CHANGE;                        
231             vlc_mutex_unlock( &p_intf->p_vout->change_lock );      
232         }
233         break;                                
234     default:                                                    /* unknown key */
235         return( 1 );        
236     }
237
238     return( 0 );    
239 }
240
241     
242