]> git.sesse.net Git - vlc/blob - include/modules.h
* ./src/interface/main.c: we no longer segfault if argc == 0.
[vlc] / include / modules.h
1 /*****************************************************************************
2  * modules.h : Module management functions.
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: modules.h,v 1.48 2002/04/24 00:36:24 sam Exp $
6  *
7  * Authors: Samuel Hocevar <sam@zoy.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Module #defines.
26  *****************************************************************************/
27
28 /* Number of tries before we unload an unused module */
29 #define MODULE_HIDE_DELAY 10000
30 #define MODULE_SHORTCUT_MAX 10
31
32 /* The module handle type. */
33 #ifdef SYS_BEOS
34 typedef int     module_handle_t;
35 #else
36 typedef void *  module_handle_t;
37 #endif
38
39 /*****************************************************************************
40  * Module capabilities.
41  *****************************************************************************/
42 static __inline__ char *GetCapabilityName( unsigned int i_capa )
43 {
44     /* The sole purpose of this inline function and the ugly #defines
45      * around it is to avoid having two places to modify when adding a
46      * new capability. */
47     static char *pp_capa[] =
48     {
49         "main",
50 #define MODULE_CAPABILITY_MAIN      0  /* Main */
51         "interface",
52 #define MODULE_CAPABILITY_INTF      1  /* Interface */
53         "access",
54 #define MODULE_CAPABILITY_ACCESS    2  /* Input */
55         "demux",
56 #define MODULE_CAPABILITY_DEMUX     3  /* Input */
57         "network",
58 #define MODULE_CAPABILITY_NETWORK   4  /* Network */
59         "decoder",
60 #define MODULE_CAPABILITY_DECODER   5  /* Audio or video decoder */
61         "motion",
62 #define MODULE_CAPABILITY_MOTION    6  /* Motion compensation */
63         "iDCT",
64 #define MODULE_CAPABILITY_IDCT      7  /* IDCT transformation */
65         "audio output",
66 #define MODULE_CAPABILITY_AOUT      8  /* Audio output */
67         "video output",
68 #define MODULE_CAPABILITY_VOUT      9  /* Video output */
69         "chroma transformation",
70 #define MODULE_CAPABILITY_CHROMA   10  /* colorspace conversion */
71         "iMDCT",
72 #define MODULE_CAPABILITY_IMDCT    11  /* IMDCT transformation */
73         "downmix",
74 #define MODULE_CAPABILITY_DOWNMIX  12  /* AC3 downmix */
75         "memcpy",
76 #define MODULE_CAPABILITY_MEMCPY   13  /* memcpy */
77         "unknown"
78 #define MODULE_CAPABILITY_MAX      14  /* Total number of capabilities */
79     };
80
81     return pp_capa[ (i_capa) > MODULE_CAPABILITY_MAX ? MODULE_CAPABILITY_MAX :
82                     (i_capa) ];
83 }
84
85 /*****************************************************************************
86  * module_bank_t, p_module_bank (global variable)
87  *****************************************************************************
88  * This global variable is accessed by any function using modules.
89  *****************************************************************************/
90 typedef struct module_bank_s
91 {
92     struct module_s *   first;                   /* First module in the bank */
93     int                 i_count;              /* Number of allocated modules */
94
95     vlc_mutex_t         lock;  /* Global lock -- you can't imagine how awful *
96                                     it is to design thread-safe linked lists */
97 } module_bank_t;
98
99 #ifndef __PLUGIN__
100 extern module_bank_t *p_module_bank;
101 #else
102 #   define p_module_bank (p_symbols->p_module_bank)
103 #endif
104
105 /*****************************************************************************
106  * Module description structure
107  *****************************************************************************/
108 typedef struct module_s
109 {
110     /*
111      * Variables set by the module to identify itself
112      */
113     char *psz_name;                                  /* Module _unique_ name */
114     char *psz_longname;                           /* Module descriptive name */
115
116     /*
117      * Variables set by the module to tell us what it can do
118      */
119     char *psz_program;        /* Program name which will activate the module */
120     char *pp_shortcuts[ MODULE_SHORTCUT_MAX ];    /* Shortcuts to the module */
121
122     u32   i_capabilities;                                 /* Capability list */
123     int   pi_score[ MODULE_CAPABILITY_MAX ];    /* Score for each capability */
124
125     u32   i_cpu_capabilities;                   /* Required CPU capabilities */
126
127     struct module_functions_s *p_functions;          /* Capability functions */
128
129     /*
130      * Variables set by the module to store its config options
131      */
132     struct module_config_s *p_config;      /* Module configuration structure */
133     vlc_mutex_t            config_lock;    /* lock used to modify the config */
134     unsigned int           i_config_items;  /* number of configuration items */
135
136     /*
137      * Variables used internally by the module manager
138      */
139     boolean_t           b_builtin;  /* Set to true if the module is built in */
140
141     union
142     {
143         struct
144         {
145             module_handle_t     handle;                     /* Unique handle */
146             char *              psz_filename;             /* Module filename */
147
148         } plugin;
149
150         struct
151         {
152             int ( *pf_deactivate ) ( struct module_s * );
153
154         } builtin;
155
156     } is;
157
158     int   i_usage;                                      /* Reference counter */
159     int   i_unused_delay;                  /* Delay until module is unloaded */
160
161     struct module_s *next;                                    /* Next module */
162     struct module_s *prev;                                /* Previous module */
163
164     /*
165      * Symbol table we send to the module so that it can access vlc symbols
166      */
167     struct module_symbols_s *p_symbols;
168
169 } module_t;
170
171 /*****************************************************************************
172  * Module functions description structure
173  *****************************************************************************/
174 typedef struct function_list_s
175 {
176     union
177     {
178         /* Interface plugin */
179         struct
180         {
181             int  ( * pf_open ) ( struct intf_thread_s * );
182             void ( * pf_close )( struct intf_thread_s * );
183             void ( * pf_run )  ( struct intf_thread_s * );
184         } intf;
185
186         /* Access plugin */
187         struct
188         {
189             int  ( * pf_open ) ( struct input_thread_s * );
190             void ( * pf_close )( struct input_thread_s * );
191             ssize_t ( * pf_read ) ( struct input_thread_s *, byte_t *, size_t );
192             void ( * pf_seek ) ( struct input_thread_s *, off_t );
193             int  ( * pf_set_program ) ( struct input_thread_s *,
194                                         struct pgrm_descriptor_s * );
195             int  ( * pf_set_area ) ( struct input_thread_s *,
196                                      struct input_area_s * );
197         } access;
198
199         /* Demux plugin */
200         struct
201         {
202             int  ( * pf_init ) ( struct input_thread_s * );
203             void ( * pf_end )  ( struct input_thread_s * );
204             int  ( * pf_demux )( struct input_thread_s * );
205             int  ( * pf_rewind )   ( struct input_thread_s * );
206         } demux;
207
208         /* Network plugin */
209         struct
210         {
211             int  ( * pf_open )( struct network_socket_s * );
212         } network;
213
214         /* Audio output plugin */
215         struct
216         {
217             int  ( * pf_open )       ( struct aout_thread_s * );
218             int  ( * pf_setformat )  ( struct aout_thread_s * );
219             int  ( * pf_getbufinfo ) ( struct aout_thread_s *, int );
220             void ( * pf_play )       ( struct aout_thread_s *, byte_t *, int );
221             void ( * pf_close )      ( struct aout_thread_s * );
222         } aout;
223
224         /* Video output plugin */
225         struct
226         {
227             int  ( * pf_create )     ( struct vout_thread_s * );
228             int  ( * pf_init )       ( struct vout_thread_s * );
229             void ( * pf_end )        ( struct vout_thread_s * );
230             void ( * pf_destroy )    ( struct vout_thread_s * );
231             int  ( * pf_manage )     ( struct vout_thread_s * );
232             void ( * pf_render )     ( struct vout_thread_s *,
233                                        struct picture_s * );
234             void ( * pf_display )    ( struct vout_thread_s *,
235                                        struct picture_s * );
236         } vout;
237
238         /* Motion compensation plugin */
239         struct
240         {
241             void ( * ppppf_motion[2][2][4] ) ( yuv_data_t *, yuv_data_t *,
242                                                int, int );
243         } motion;
244
245         /* IDCT plugin */
246         struct
247         {
248             void ( * pf_idct_init )    ( void ** );
249             void ( * pf_sparse_idct_add )( dctelem_t *, yuv_data_t *, int,
250                                          void *, int );
251             void ( * pf_idct_add )     ( dctelem_t *, yuv_data_t *, int,
252                                          void *, int );
253             void ( * pf_sparse_idct_copy )( dctelem_t *, yuv_data_t *, int,
254                                          void *, int );
255             void ( * pf_idct_copy )    ( dctelem_t *, yuv_data_t *, int,
256                                          void *, int );
257             void ( * pf_norm_scan )    ( u8 ppi_scan[2][64] );
258         } idct;
259
260         /* Chroma transformation plugin */
261         struct
262         {
263             int  ( * pf_init )         ( struct vout_thread_s * );
264             void ( * pf_end )          ( struct vout_thread_s * );
265         } chroma;
266
267         /* IMDCT plugin */
268         struct
269         {
270             void ( * pf_imdct_init )   ( struct imdct_s * );
271             void ( * pf_imdct_256 )    ( struct imdct_s *,
272                                          float data[], float delay[] );
273             void ( * pf_imdct_256_nol )( struct imdct_s *,
274                                          float data[], float delay[] );
275             void ( * pf_imdct_512 )    ( struct imdct_s *,
276                                          float data[], float delay[] );
277             void ( * pf_imdct_512_nol )( struct imdct_s *,
278                                          float data[], float delay[] );
279 //            void ( * pf_fft_64p )      ( struct complex_s * );
280
281         } imdct;
282
283         /* AC3 downmix plugin */
284         struct
285         {
286             void ( * pf_downmix_3f_2r_to_2ch ) ( float *, struct dm_par_s * );
287             void ( * pf_downmix_3f_1r_to_2ch ) ( float *, struct dm_par_s * );
288             void ( * pf_downmix_2f_2r_to_2ch ) ( float *, struct dm_par_s * );
289             void ( * pf_downmix_2f_1r_to_2ch ) ( float *, struct dm_par_s * );
290             void ( * pf_downmix_3f_0r_to_2ch ) ( float *, struct dm_par_s * );
291             void ( * pf_stream_sample_2ch_to_s16 ) ( s16 *, float *, float * );
292             void ( * pf_stream_sample_1ch_to_s16 ) ( s16 *, float * );
293
294         } downmix;
295
296         /* Decoder plugins */
297         struct
298         {
299             int  ( * pf_probe)( u8 * p_es );
300             int  ( * pf_run ) ( struct decoder_config_s * p_config );
301         } dec;
302
303         /* memcpy plugins */
304         struct
305         {
306             void* ( * pf_memcpy ) ( void *, const void *, size_t );
307             void* ( * pf_memset ) ( void *, int, size_t );
308         } memcpy;
309
310     } functions;
311
312 } function_list_t;
313
314 typedef struct module_functions_s
315 {
316     /* XXX: The order here has to be the same as above for the #defines */
317     function_list_t intf;
318     function_list_t access;
319     function_list_t demux;
320     function_list_t network;
321     function_list_t dec;
322     function_list_t motion;
323     function_list_t idct;
324     function_list_t aout;
325     function_list_t vout;
326     function_list_t chroma;
327     function_list_t imdct;
328     function_list_t downmix;
329     function_list_t memcpy;
330
331 } module_functions_t;
332
333 typedef struct module_functions_s * p_module_functions_t;
334
335 /*****************************************************************************
336  * Exported functions.
337  *****************************************************************************/
338 #ifndef __PLUGIN__
339 void            module_InitBank     ( void );
340 void            module_LoadMain     ( void );
341 void            module_LoadBuiltins ( void );
342 void            module_LoadPlugins  ( void );
343 void            module_EndBank      ( void );
344 void            module_ResetBank    ( void );
345 void            module_ManageBank   ( void );
346 module_t *      module_Need         ( int, char *, void * );
347 void            module_Unneed       ( module_t * );
348
349 #else
350 #   define module_Need p_symbols->module_Need
351 #   define module_Unneed p_symbols->module_Unneed
352 #endif