]> git.sesse.net Git - vlc/blob - include/modules.h
ad06b770a7841b3a16d48484a322b82ebd00dc7d
[vlc] / include / modules.h
1 /*****************************************************************************
2  * modules.h : Module management functions.
3  *****************************************************************************
4  * Copyright (C) 2001 VideoLAN
5  * $Id: modules.h,v 1.38 2001/12/30 07:09:54 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         "interface",
50 #define MODULE_CAPABILITY_INTF      0  /* Interface */
51         "access",
52 #define MODULE_CAPABILITY_ACCESS    1  /* Input */
53         "input",
54 #define MODULE_CAPABILITY_INPUT     2  /* Input */
55         "decaps",
56 #define MODULE_CAPABILITY_DECAPS    3  /* Decaps */
57         "decoder",
58 #define MODULE_CAPABILITY_DECODER   4  /* Audio or video decoder */
59         "motion",
60 #define MODULE_CAPABILITY_MOTION    5  /* Motion compensation */
61         "iDCT",
62 #define MODULE_CAPABILITY_IDCT      6  /* IDCT transformation */
63         "audio output",
64 #define MODULE_CAPABILITY_AOUT      7  /* Audio output */
65         "video output",
66 #define MODULE_CAPABILITY_VOUT      8  /* Video output */
67         "chroma transformation",
68 #define MODULE_CAPABILITY_CHROMA    9  /* colorspace conversion */
69         "iMDCT",
70 #define MODULE_CAPABILITY_IMDCT    10  /* IMDCT transformation */
71         "downmix",
72 #define MODULE_CAPABILITY_DOWNMIX  11  /* AC3 downmix */
73         "memcpy",
74 #define MODULE_CAPABILITY_MEMCPY   12  /* memcpy */
75         "unknown"
76 #define MODULE_CAPABILITY_MAX      13  /* Total number of capabilities */
77     };
78
79     return pp_capa[ (i_capa) > MODULE_CAPABILITY_MAX ? MODULE_CAPABILITY_MAX :
80                     (i_capa) ];
81 }
82
83 /*****************************************************************************
84  * module_bank_t, p_module_bank (global variable)
85  *****************************************************************************
86  * This global variable is accessed by any function using modules.
87  *****************************************************************************/
88 typedef struct
89 {
90     struct module_s *   first;                   /* First module in the bank */
91     int                 i_count;              /* Number of allocated modules */
92
93     vlc_mutex_t         lock;  /* Global lock -- you can't imagine how awful *
94                                     it is to design thread-safe linked lists */
95 } module_bank_t;
96
97 extern module_bank_t *p_module_bank;
98
99 /*****************************************************************************
100  * Module description structure
101  *****************************************************************************/
102 typedef struct module_s
103 {
104     /*
105      * Variables set by the module to identify itself
106      */
107     char *psz_name;                                  /* Module _unique_ name */
108     char *psz_longname;                           /* Module descriptive name */
109
110     /*
111      * Variables set by the module to tell us what it can do
112      */
113     char *psz_program;        /* Program name which will activate the module */
114     char *pp_shortcuts[ MODULE_SHORTCUT_MAX ];    /* Shortcuts to the module */
115
116     u32   i_capabilities;                                 /* Capability list */
117     int   pi_score[ MODULE_CAPABILITY_MAX ];    /* Score for each capability */
118
119     u32   i_cpu_capabilities;                   /* Required CPU capabilities */
120
121     struct module_functions_s *p_functions;          /* Capability functions */
122     struct module_config_s  *p_config;     /* Module configuration structure */
123
124     /*
125      * Variables used internally by the module manager
126      */
127     boolean_t           b_builtin;  /* Set to true if the module is built in */
128
129     union
130     {
131         struct
132         {
133             module_handle_t     handle;                     /* Unique handle */
134             char *              psz_filename;             /* Module filename */
135
136         } plugin;
137
138         struct
139         {
140             int ( *pf_deactivate ) ( struct module_s * );
141
142         } builtin;
143
144     } is;
145
146     int   i_usage;                                      /* Reference counter */
147     int   i_unused_delay;                  /* Delay until module is unloaded */
148
149     struct module_s *next;                                    /* Next module */
150     struct module_s *prev;                                /* Previous module */
151
152     /*
153      * Symbol table we send to the module so that it can access vlc symbols
154      */
155     struct module_symbols_s *p_symbols;
156
157 } module_t;
158
159 /*****************************************
160  * FIXME
161  * FIXME    Capabilities
162  * FIXME
163  *******************************************/
164 typedef struct memcpy_module_s
165 {
166     struct module_s *p_module;
167
168     void* ( *pf_memcpy ) ( void *, const void *, size_t );
169
170 } memcpy_module_t;
171
172 /* FIXME: not yet used */
173 typedef struct probedata_s
174 {
175     u8  i_type;
176     struct
177     {
178         char * psz_data;
179     } aout;
180
181     struct
182     {
183         struct picture_heap_s* p_output;
184         struct picture_heap_s* p_render;
185     } chroma;
186
187 } probedata_t;
188
189 /* FIXME: find a nicer way to do this. */
190 typedef struct function_list_s
191 {
192     int ( * pf_probe ) ( probedata_t * p_data );
193
194     union
195     {
196         /* Interface plugin */
197         struct
198         {
199             int  ( * pf_open ) ( struct intf_thread_s * );
200             void ( * pf_close )( struct intf_thread_s * );
201             void ( * pf_run )  ( struct intf_thread_s * );
202         } intf;
203
204         /* Input plugin */
205         struct
206         {
207             void ( * pf_init ) ( struct input_thread_s * );
208             void ( * pf_open ) ( struct input_thread_s * );
209             void ( * pf_close )( struct input_thread_s * );
210             void ( * pf_end )  ( struct input_thread_s * );
211             void ( * pf_init_bit_stream ) ( struct bit_stream_s *,
212                                             struct decoder_fifo_s *,
213                       void (* pf_bitstream_callback)( struct bit_stream_s *,
214                                                       boolean_t ),
215                                            void * );
216
217             int  ( * pf_read ) ( struct input_thread_s *,
218                                  struct data_packet_s ** );
219             void ( * pf_demux )( struct input_thread_s *,
220                                  struct data_packet_s * );
221
222             struct data_packet_s * ( * pf_new_packet ) ( void *, size_t );
223             struct pes_packet_s *  ( * pf_new_pes )    ( void * );
224             void ( * pf_delete_packet )  ( void *, struct data_packet_s * );
225             void ( * pf_delete_pes )     ( void *, struct pes_packet_s * );
226
227             int  ( * pf_set_program ) ( struct input_thread_s *,
228                                      struct pgrm_descriptor_s * );
229
230             int  ( * pf_set_area ) ( struct input_thread_s *,
231                                      struct input_area_s * );
232             int  ( * pf_rewind )   ( struct input_thread_s * );
233             void ( * pf_seek )     ( struct input_thread_s *, off_t );
234         } input;
235
236         /* Audio output plugin */
237         struct
238         {
239             int  ( * pf_open )       ( struct aout_thread_s * );
240             int  ( * pf_setformat )  ( struct aout_thread_s * );
241             long ( * pf_getbufinfo ) ( struct aout_thread_s *, long );
242             void ( * pf_play )       ( struct aout_thread_s *, byte_t *, int );
243             void ( * pf_close )      ( struct aout_thread_s * );
244         } aout;
245
246         /* Video output plugin */
247         struct
248         {
249             int  ( * pf_create )     ( struct vout_thread_s * );
250             int  ( * pf_init )       ( struct vout_thread_s * );
251             void ( * pf_end )        ( struct vout_thread_s * );
252             void ( * pf_destroy )    ( struct vout_thread_s * );
253             int  ( * pf_manage )     ( struct vout_thread_s * );
254             void ( * pf_display )    ( struct vout_thread_s *,
255                                        struct picture_s * );
256             void ( * pf_setpalette ) ( struct vout_thread_s *,
257                                        u16 *, u16 *, u16 * );
258         } vout;
259
260         /* Motion compensation plugin */
261         struct
262         {
263             void ( * ppppf_motion[2][2][4] ) ( yuv_data_t *, yuv_data_t *,
264                                                int, int );
265         } motion;
266
267         /* IDCT plugin */
268         struct
269         {
270             void ( * pf_idct_init )    ( void ** );
271             void ( * pf_sparse_idct_add )( dctelem_t *, yuv_data_t *, int,
272                                          void *, int );
273             void ( * pf_idct_add )     ( dctelem_t *, yuv_data_t *, int,
274                                          void *, int );
275             void ( * pf_sparse_idct_copy )( dctelem_t *, yuv_data_t *, int,
276                                          void *, int );
277             void ( * pf_idct_copy )    ( dctelem_t *, yuv_data_t *, int,
278                                          void *, int );
279             void ( * pf_norm_scan )    ( u8 ppi_scan[2][64] );
280         } idct;
281
282         /* Chroma transformation plugin */
283         struct
284         {
285             int  ( * pf_init )         ( struct vout_thread_s * );
286             void ( * pf_end )          ( struct vout_thread_s * );
287         } chroma;
288
289         /* IMDCT plugin */
290         struct
291         {
292             void ( * pf_imdct_init )   ( struct imdct_s * );
293             void ( * pf_imdct_256 )    ( struct imdct_s *,
294                                          float data[], float delay[] );
295             void ( * pf_imdct_256_nol )( struct imdct_s *,
296                                          float data[], float delay[] );
297             void ( * pf_imdct_512 )    ( struct imdct_s *,
298                                          float data[], float delay[] );
299             void ( * pf_imdct_512_nol )( struct imdct_s *,
300                                          float data[], float delay[] );
301 //            void ( * pf_fft_64p )      ( struct complex_s * );
302
303         } imdct;
304
305         /* AC3 downmix plugin */
306         struct
307         {
308             void ( * pf_downmix_3f_2r_to_2ch ) ( float *, struct dm_par_s * );
309             void ( * pf_downmix_3f_1r_to_2ch ) ( float *, struct dm_par_s * );
310             void ( * pf_downmix_2f_2r_to_2ch ) ( float *, struct dm_par_s * );
311             void ( * pf_downmix_2f_1r_to_2ch ) ( float *, struct dm_par_s * );
312             void ( * pf_downmix_3f_0r_to_2ch ) ( float *, struct dm_par_s * );
313             void ( * pf_stream_sample_2ch_to_s16 ) ( s16 *, float *, float * );
314             void ( * pf_stream_sample_1ch_to_s16 ) ( s16 *, float * );
315
316         } downmix;
317
318         /* Decoder plugins */
319         struct
320         {
321             int  ( * pf_run ) ( struct decoder_config_s * p_config );
322         } dec;
323
324         /* memcpy plugins */
325         struct
326         {
327             void* ( * fast_memcpy ) ( void *, const void *, size_t );
328         } memcpy;
329
330     } functions;
331
332 } function_list_t;
333
334 typedef struct module_functions_s
335 {
336     /* XXX: The order here has to be the same as above for the #defines */
337     function_list_t intf;
338     function_list_t access;
339     function_list_t input;
340     function_list_t decaps;
341     function_list_t dec;
342     function_list_t motion;
343     function_list_t idct;
344     function_list_t aout;
345     function_list_t vout;
346     function_list_t chroma;
347     function_list_t imdct;
348     function_list_t downmix;
349     function_list_t memcpy;
350
351 } module_functions_t;
352
353 typedef struct module_functions_s * p_module_functions_t;
354
355 /*****************************************************************************
356  * Macros used to build the configuration structure.
357  *****************************************************************************/
358
359 /* Mandatory first and last parts of the structure */
360 #define MODULE_CONFIG_ITEM_START       0xdead  /* The main window */
361 #define MODULE_CONFIG_ITEM_END         0xbeef  /* End of the window */
362
363 /* Configuration widgets */
364 #define MODULE_CONFIG_ITEM_WINDOW      0x0001  /* The main window */
365 #define MODULE_CONFIG_ITEM_PANE        0x0002  /* A notebook pane */
366 #define MODULE_CONFIG_ITEM_FRAME       0x0003  /* A frame */
367 #define MODULE_CONFIG_ITEM_COMMENT     0x0004  /* A comment text */
368 #define MODULE_CONFIG_ITEM_STRING      0x0005  /* A string */
369 #define MODULE_CONFIG_ITEM_FILE        0x0006  /* A file selector */
370 #define MODULE_CONFIG_ITEM_CHECK       0x0007  /* A checkbox */
371 #define MODULE_CONFIG_ITEM_CHOOSE      0x0008  /* A choose box */
372 #define MODULE_CONFIG_ITEM_RADIO       0x0009  /* A radio box */
373 #define MODULE_CONFIG_ITEM_SCALE       0x000a  /* A horizontal ruler */
374 #define MODULE_CONFIG_ITEM_SPIN        0x000b  /* A numerical selector */
375
376 typedef struct module_config_s
377 {
378     int         i_type;                         /* Configuration widget type */
379     char *      psz_text;        /* Text commenting or describing the widget */
380     char *      psz_name;                                   /* Variable name */
381     void *      p_getlist;          /* Function to call to get a choice list */
382     void *      p_change;        /* Function to call when commiting a change */
383 } module_config_t;
384
385 /*****************************************************************************
386  * Exported functions.
387  *****************************************************************************/
388 #ifndef PLUGIN
389 void            module_InitBank     ( void );
390 void            module_EndBank      ( void );
391 void            module_ResetBank    ( void );
392 void            module_ManageBank   ( void );
393 module_t *      module_Need         ( int, char *, probedata_t * );
394 void            module_Unneed       ( module_t * p_module );
395
396 int module_NeedMemcpy( memcpy_module_t * );
397 void module_UnneedMemcpy( memcpy_module_t * );
398
399 #else
400 #   define module_Need p_symbols->module_Need
401 #   define module_Unneed p_symbols->module_Unneed
402 #endif
403