]> git.sesse.net Git - vlc/blob - src/interface/control.c
Fin du remplacement des pthread + ajout du frame rate dans display.c.
[vlc] / src / interface / control.c
1 /*******************************************************************************
2  * control.c: user control functions
3  * (c)1999 VideoLAN
4  *******************************************************************************
5  * Library of functions common to all threads, allowing access to various
6  * structures and settings. Interfaces should only use those functions
7  * to read or write informations from other threads.
8  *******************************************************************************/
9
10 /*******************************************************************************
11  * Preamble
12  *******************************************************************************/
13 #include <stdio.h>
14 #include <netinet/in.h>
15 #include <sys/soundcard.h>
16 #include <sys/uio.h>
17 #include <X11/Xlib.h> 
18 #include <X11/extensions/XShm.h>
19
20 #include "config.h"
21 #include "common.h"
22 #include "mtime.h"
23 #include "vlc_thread.h"
24
25 #include "input.h"
26 #include "input_vlan.h"
27
28 #include "audio_output.h"
29
30 #include "video.h"
31 #include "video_output.h"
32
33 #include "xconsole.h"
34 #include "interface.h"
35 #include "intf_msg.h"
36 #include "control.h"
37
38 #include "pgm_data.h"
39
40 /*******************************************************************************
41  * intf_CreateVoutThread: create video output thread in interface
42  *******************************************************************************
43  * This function creates - if possible - a new video output thread in the
44  * interface registery, using interface default settings. It returns the
45  * thread number for the interface, or a negative number.
46  * If video is desactivated, nothing will be done. If psz_title is not NULL, it
47  * will be used as window's title, and width and height will also be used if
48  * they are positive.
49  *******************************************************************************/
50 int intf_CreateVoutThread( intf_thread_t *p_intf, char *psz_title, int i_width, int i_height )
51 {
52     int             i_thread;                                  /* thread index */
53     video_cfg_t     cfg;                               /* thread configuration */    
54
55     /* Verify that video is enabled */
56     if( !p_program_data->cfg.b_video )
57     {
58         return( -1 );
59     }
60
61     /* Set configuration */
62     memcpy( &cfg, &p_program_data->vout_cfg, sizeof( cfg ) );
63     if( psz_title != NULL )
64     {
65         cfg.i_properties |= VIDEO_CFG_TITLE;
66         cfg.psz_title = psz_title;        
67     }
68     if( i_width > 0 )
69     {
70         cfg.i_properties |= VIDEO_CFG_WIDTH;
71         cfg.i_width = i_width;        
72     }
73     if( i_height > 0 )
74     {
75         cfg.i_properties |= VIDEO_CFG_HEIGHT;
76         cfg.i_height = i_height;
77     }
78
79     /* Find an empty place */
80     for( i_thread = 0; i_thread < VOUT_MAX_THREADS; i_thread++ )
81     {
82         if( p_intf->pp_vout[i_thread] == NULL )
83         {
84             /* The current place is empty: create a thread */
85             p_intf->pp_vout[i_thread] = vout_CreateThread( &cfg, NULL );
86             if( p_intf->pp_vout[i_thread] == NULL )                   /* error */
87             {                    
88                 return( -1 );
89             }
90         }
91     }
92
93     /* No empty place has been found */
94     return( -1 );
95 }
96
97
98 /*******************************************************************************
99  * intf_DestroyVoutThread: destroy video output thread in interface
100  *******************************************************************************
101  * This function destroy a video output thread created with
102  * intf_CreateVoutThread().
103  *******************************************************************************/
104 void intf_DestroyVoutThread( intf_thread_t *p_intf, int i_thread )
105 {
106 #ifdef DEBUG
107     /* Check if thread still exists */
108     if( p_intf->pp_vout[i_thread] == NULL )
109     {
110         intf_DbgMsg("intf error: destruction of an inexistant vout thread\n");
111         return;
112     }
113 #endif
114
115     /* Destroy thread and marks its place as empty */
116     vout_DestroyThread( p_intf->pp_vout[i_thread], NULL );
117     p_intf->pp_vout[i_thread] = NULL;
118 }
119
120
121 /*******************************************************************************
122  * intf_CreateInputThread: create input thread in interface
123  *******************************************************************************
124  * This function creates - if possible - a new input thread in the
125  * interface registery, using interface default settings. It returns the
126  * thread number for the interface, or a negative number.
127  *******************************************************************************/
128 int intf_CreateInputThread( intf_thread_t *p_intf, input_cfg_t* p_cfg )
129 {
130     int             i_thread;                                  /* thread index */
131
132     /* Find an empty place */
133     for( i_thread = 0; i_thread < INPUT_MAX_THREADS; i_thread++ )
134     {
135         if( p_intf->pp_input[i_thread] == NULL )
136         {
137             /* The current place is empty: create a thread and return */
138             p_intf->pp_input[i_thread] = input_CreateThread( p_cfg );
139             return( (p_intf->pp_input[i_thread] != NULL) ? i_thread : -1 );
140         }
141     }
142
143     /* No empty place has been found */
144     return( -1 );    
145 }
146
147 /*******************************************************************************
148  * intf_DestroyInputThread: destroy input thread in interface
149  *******************************************************************************
150  * This function destroy aa input thread created with
151  * intf_CreateInputThread().
152  *******************************************************************************/
153 void intf_DestroyInputThread( intf_thread_t *p_intf, int i_thread )
154 {
155 #ifdef DEBUG
156     /* Check if thread still exists */
157     if( p_intf->pp_input[i_thread] == NULL )
158     {
159         intf_DbgMsg("intf error: destruction of an inexistant input thread\n");
160         return;        
161     }
162 #endif
163
164     /* Destroy thread and marks its place as empty */
165     input_DestroyThread( p_intf->pp_input[i_thread] );
166     p_intf->pp_input[i_thread] = NULL;
167 }