]> git.sesse.net Git - vlc/blob - src/interface/interface.c
Changement de chaine. Delicat encore, mais il marche. Quelques corrections
[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  * 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 )
41 {    
42     intf_thread_t *p_intf;                                        
43
44     /* Allocate structure */
45     p_intf = malloc( sizeof( intf_thread_t ) );
46     if( !p_intf )
47     {
48         intf_ErrMsg("error: %s\n", strerror( ENOMEM ) );        
49         return( NULL );
50     }
51
52     /* Initialize structure */
53     p_intf->b_die =     0;    
54     p_intf->p_vout =    NULL;
55     p_intf->p_input =   NULL;   
56
57     /* Start interfaces */
58     p_intf->p_console = intf_ConsoleCreate();
59     if( p_intf->p_console == NULL )
60     {
61         intf_ErrMsg("error: can't create control console\n");
62         free( p_intf );
63         return( NULL );
64     }
65     if( intf_SysCreate( p_intf ) )
66     {
67         intf_ErrMsg("error: can't create interface\n");
68         intf_ConsoleDestroy( p_intf->p_console );
69         free( p_intf );
70         return( NULL );
71     }   
72
73     intf_Msg("Interface initialized\n");    
74     return( p_intf );
75 }
76
77 /*******************************************************************************
78  * intf_Run
79  *******************************************************************************
80  * Initialization script and main interface loop.
81  *******************************************************************************/
82 void intf_Run( intf_thread_t *p_intf )
83
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 )
87     {
88         intf_ErrMsg("warning: error(s) during startup script\n");
89     }
90
91     /* Main loop */
92     while(!p_intf->b_die)
93     {
94         /* Flush waiting messages */
95         intf_FlushMsg();
96
97         /* Manage specific interface */
98         intf_SysManage( p_intf );
99
100         /* Check attached threads status */
101         if( (p_intf->p_vout != NULL) && p_intf->p_vout->b_error )
102         {
103             //?? add aout error detection
104             p_intf->b_die = 1;            
105         }    
106         if( (p_intf->p_input != NULL) && p_intf->p_input->b_error )
107         {
108             input_DestroyThread( p_intf->p_input, NULL );            
109             p_intf->p_input = NULL;            
110             intf_DbgMsg("Input thread destroyed\n");            
111         }
112
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 );
116     }
117 }
118
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 )
125 {
126     /* Destroy interfaces */
127     intf_SysDestroy( p_intf );
128     intf_ConsoleDestroy( p_intf->p_console );
129
130     /* Free structure */
131     free( p_intf );
132 }
133
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 )
141 {
142     intf_DbgMsg("\n");
143     
144     /* Kill existing input, if any */
145     if( p_intf->p_input != NULL )
146     {        
147         input_DestroyThread( p_intf->p_input, NULL );
148     }
149
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 );    
155 }
156
157 /*******************************************************************************
158  * intf_ProcessKey: process standard keys
159  *******************************************************************************
160  * This function will process standard keys and return non 0 if the key was
161  * unknown.
162  *******************************************************************************/
163 int intf_ProcessKey( intf_thread_t *p_intf, int i_key )
164 {
165     switch( i_key )
166     {
167     case 'Q':                                                    /* quit order */
168     case 'q':
169     case 27: /* escape key */
170         p_intf->b_die = 1;
171         break;  
172     case '0':                                                 /* source change */
173     case '1':
174     case '2':
175     case '3':
176     case '4':
177     case '5':
178     case '6':
179     case '7':
180     case '8':
181     case '9':                    
182         if( intf_SelectInput( p_intf, i_key - '0' ) )
183         {
184             intf_ErrMsg("error: can not open channel %d\n", i_key - '0');            
185         }        
186         break;
187     case '+':                                                      /* volume + */
188         // ??
189         break;
190     case '-':                                                      /* volume - */
191         // ??
192         break;
193     case 'M':                                                   /* toggle mute */
194     case 'm':                    
195         // ??
196         break;      
197     case 'g':                                                       /* gamma - */
198         if( (p_intf->p_vout != NULL) && (p_intf->p_vout->f_gamma > -INTF_GAMMA_LIMIT) )
199         {
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 );
204         }                    
205         break;                                        
206     case 'G':                                                       /* gamma + */
207         if( (p_intf->p_vout != NULL) && (p_intf->p_vout->f_gamma < INTF_GAMMA_LIMIT) )
208         {       
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 );
213         }                    
214         break;  
215     case 'c':                                              /* toggle grayscale */
216         if( p_intf->p_vout != NULL )
217         {
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 );      
222         }
223         break;  
224     case ' ':                                                   /* toggle info */
225         if( p_intf->p_vout != NULL )
226         {
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 );      
231         }
232         break;                                
233     default:                                                    /* unknown key */
234         return( 1 );        
235     }
236
237     return( 0 );    
238 }
239
240     
241